From 400d61641fefd6df7940efb30c294cbd4e1426bf Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Sun, 7 Apr 2013 19:40:10 +0200 Subject: [PATCH] LA: upgrade old/obsolete ctors to new implementation (deduplication) --- .../LinearAlgebra/Complex/DenseMatrix.cs | 12 ++---------- .../LinearAlgebra/Complex/DiagonalMatrix.cs | 19 ++----------------- .../LinearAlgebra/Complex/SparseMatrix.cs | 12 ++---------- .../LinearAlgebra/Complex32/DenseMatrix.cs | 12 ++---------- .../LinearAlgebra/Complex32/DiagonalMatrix.cs | 19 ++----------------- .../LinearAlgebra/Complex32/SparseMatrix.cs | 12 ++---------- .../LinearAlgebra/Double/DenseMatrix.cs | 12 ++---------- .../LinearAlgebra/Double/DiagonalMatrix.cs | 19 ++----------------- .../LinearAlgebra/Double/SparseMatrix.cs | 12 ++---------- .../LinearAlgebra/Single/DenseMatrix.cs | 12 ++---------- .../LinearAlgebra/Single/DiagonalMatrix.cs | 19 ++----------------- .../LinearAlgebra/Single/SparseMatrix.cs | 12 ++---------- 12 files changed, 24 insertions(+), 148 deletions(-) diff --git a/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs index c52e097f..d09ded08 100644 --- a/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs @@ -168,15 +168,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// [Obsolete("Use DenseMatrix.OfArray instead. Scheduled for removal in v3.0.")] public DenseMatrix(Complex[,] array) - : this(array.GetLength(0), array.GetLength(1)) + : this(DenseColumnMajorMatrixStorage.OfArray(array)) { - for (var i = 0; i < _rowCount; i++) - { - for (var j = 0; j < _columnCount; j++) - { - _values[(j * _rowCount) + i] = array[i, j]; - } - } } /// @@ -186,9 +179,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// [Obsolete("Use DenseMatrix.OfMatrix instead. Scheduled for removal in v3.0.")] public DenseMatrix(Matrix matrix) - : this(matrix.RowCount, matrix.ColumnCount) + : this(DenseColumnMajorMatrixStorage.OfMatrix(matrix.Storage)) { - matrix.Storage.CopyToUnchecked(Storage, skipClearing: true); } /// diff --git a/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs index 3a04bd4e..5bbbd3f2 100644 --- a/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs +++ b/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs @@ -149,22 +149,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// [Obsolete("Use DiagonalMatrix.OfArray instead. Scheduled for removal in v3.0.")] public DiagonalMatrix(Complex[,] array) - : this(array.GetLength(0), array.GetLength(1)) + : this(DiagonalMatrixStorage.OfArray(array)) { - for (var i = 0; i < RowCount; i++) - { - for (var j = 0; j < ColumnCount; j++) - { - if (i == j) - { - _data[i] = array[i, j]; - } - else if (((array[i, j].Real != 0.0) && !double.IsNaN(array[i, j].Real)) || ((array[i, j].Imaginary != 0.0) && !double.IsNaN(array[i, j].Imaginary))) - { - throw new IndexOutOfRangeException("Cannot set an off-diagonal element in a diagonal matrix."); - } - } - } } /// @@ -175,9 +161,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// [Obsolete("Use DiagonalMatrix.OfMatrix instead. Scheduled for removal in v3.0.")] public DiagonalMatrix(Matrix matrix) - : this(matrix.RowCount, matrix.ColumnCount) + : this(DiagonalMatrixStorage.OfMatrix(matrix.Storage)) { - matrix.Storage.CopyToUnchecked(Storage, skipClearing: true); } /// diff --git a/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs index d432a332..2cbdbe25 100644 --- a/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs @@ -220,15 +220,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// [Obsolete("Use SparseMatrix.OfArray instead. Scheduled for removal in v3.0.")] public SparseMatrix(Complex[,] array) - : this(array.GetLength(0), array.GetLength(1)) + : this(SparseCompressedRowMatrixStorage.OfArray(array)) { - for (var i = 0; i < _storage.RowCount; i++) - { - for (var j = 0; j < _storage.ColumnCount; j++) - { - _storage.At(i, j, array[i, j]); - } - } } /// @@ -238,9 +231,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// [Obsolete("Use SparseMatrix.OfMatrix instead. Scheduled for removal in v3.0.")] public SparseMatrix(Matrix matrix) - : this(matrix.RowCount, matrix.ColumnCount) + : this(SparseCompressedRowMatrixStorage.OfMatrix(matrix.Storage)) { - matrix.Storage.CopyToUnchecked(Storage, skipClearing: true); } /// diff --git a/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs index 2b564d38..74a7fec9 100644 --- a/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs @@ -168,15 +168,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 /// [Obsolete("Use DenseMatrix.OfArray instead. Scheduled for removal in v3.0.")] public DenseMatrix(Complex32[,] array) - : this(array.GetLength(0), array.GetLength(1)) + : this(DenseColumnMajorMatrixStorage.OfArray(array)) { - for (var i = 0; i < _rowCount; i++) - { - for (var j = 0; j < _columnCount; j++) - { - _values[(j * _rowCount) + i] = array[i, j]; - } - } } /// @@ -186,9 +179,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 /// [Obsolete("Use DenseMatrix.OfMatrix instead. Scheduled for removal in v3.0.")] public DenseMatrix(Matrix matrix) - : this(matrix.RowCount, matrix.ColumnCount) + : this(DenseColumnMajorMatrixStorage.OfMatrix(matrix.Storage)) { - matrix.Storage.CopyToUnchecked(Storage, skipClearing: true); } /// diff --git a/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs index ee1a4d36..ecf9d32d 100644 --- a/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs +++ b/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs @@ -149,22 +149,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 /// [Obsolete("Use DiagonalMatrix.OfArray instead. Scheduled for removal in v3.0.")] public DiagonalMatrix(Complex32[,] array) - : this(array.GetLength(0), array.GetLength(1)) + : this(DiagonalMatrixStorage.OfArray(array)) { - for (var i = 0; i < RowCount; i++) - { - for (var j = 0; j < ColumnCount; j++) - { - if (i == j) - { - _data[i] = array[i, j]; - } - else if (((array[i, j].Real != 0.0) && !double.IsNaN(array[i, j].Real)) || ((array[i, j].Imaginary != 0.0) && !double.IsNaN(array[i, j].Imaginary))) - { - throw new IndexOutOfRangeException("Cannot set an off-diagonal element in a diagonal matrix."); - } - } - } } /// @@ -175,9 +161,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 /// [Obsolete("Use DiagonalMatrix.OfMatrix instead. Scheduled for removal in v3.0.")] public DiagonalMatrix(Matrix matrix) - : this(matrix.RowCount, matrix.ColumnCount) + : this(DiagonalMatrixStorage.OfMatrix(matrix.Storage)) { - matrix.Storage.CopyToUnchecked(Storage, skipClearing: true); } /// diff --git a/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs index aed609f0..57cbeb79 100644 --- a/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs @@ -220,15 +220,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 /// [Obsolete("Use SparseMatrix.OfArray instead. Scheduled for removal in v3.0.")] public SparseMatrix(Complex32[,] array) - : this(array.GetLength(0), array.GetLength(1)) + : this(SparseCompressedRowMatrixStorage.OfArray(array)) { - for (var i = 0; i < _storage.RowCount; i++) - { - for (var j = 0; j < _storage.ColumnCount; j++) - { - _storage.At(i, j, array[i, j]); - } - } } /// @@ -238,9 +231,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 /// [Obsolete("Use SparseMatrix.OfMatrix instead. Scheduled for removal in v3.0.")] public SparseMatrix(Matrix matrix) - : this(matrix.RowCount, matrix.ColumnCount) + : this(SparseCompressedRowMatrixStorage.OfMatrix(matrix.Storage)) { - matrix.Storage.CopyToUnchecked(Storage, skipClearing: true); } /// diff --git a/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs index 24c21dc1..dd7e7590 100644 --- a/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs @@ -170,15 +170,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double /// [Obsolete("Use DenseMatrix.OfArray instead. Scheduled for removal in v3.0.")] public DenseMatrix(double[,] array) - : this(array.GetLength(0), array.GetLength(1)) + : this(DenseColumnMajorMatrixStorage.OfArray(array)) { - for (var i = 0; i < _rowCount; i++) - { - for (var j = 0; j < _columnCount; j++) - { - _values[(j * _rowCount) + i] = array[i, j]; - } - } } /// @@ -188,9 +181,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double /// [Obsolete("Use DenseMatrix.OfMatrix instead. Scheduled for removal in v3.0.")] public DenseMatrix(Matrix matrix) - : this(matrix.RowCount, matrix.ColumnCount) + : this(DenseColumnMajorMatrixStorage.OfMatrix(matrix.Storage)) { - matrix.Storage.CopyToUnchecked(Storage, skipClearing: true); } /// diff --git a/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs index 932e4eff..312dc04c 100644 --- a/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs +++ b/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs @@ -148,22 +148,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double /// [Obsolete("Use DiagonalMatrix.OfArray instead. Scheduled for removal in v3.0.")] public DiagonalMatrix(double[,] array) - : this(array.GetLength(0), array.GetLength(1)) + : this(DiagonalMatrixStorage.OfArray(array)) { - for (var i = 0; i < RowCount; i++) - { - for (var j = 0; j < ColumnCount; j++) - { - if (i == j) - { - _data[i] = array[i, j]; - } - else if (array[i, j] != 0.0 && !Double.IsNaN(array[i, j])) - { - throw new IndexOutOfRangeException("Cannot set an off-diagonal element in a diagonal matrix."); - } - } - } } /// @@ -174,9 +160,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double /// [Obsolete("Use DiagonalMatrix.OfMatrix instead. Scheduled for removal in v3.0.")] public DiagonalMatrix(Matrix matrix) - : this(matrix.RowCount, matrix.ColumnCount) + : this(DiagonalMatrixStorage.OfMatrix(matrix.Storage)) { - matrix.Storage.CopyToUnchecked(Storage, skipClearing: true); } /// diff --git a/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs index 0376f71a..49431633 100644 --- a/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs @@ -219,15 +219,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double /// [Obsolete("Use SparseMatrix.OfArray instead. Scheduled for removal in v3.0.")] public SparseMatrix(double[,] array) - : this(array.GetLength(0), array.GetLength(1)) + : this(SparseCompressedRowMatrixStorage.OfArray(array)) { - for (var i = 0; i < _storage.RowCount; i++) - { - for (var j = 0; j < _storage.ColumnCount; j++) - { - _storage.At(i, j, array[i, j]); - } - } } /// @@ -237,9 +230,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double /// [Obsolete("Use SparseMatrix.OfMatrix instead. Scheduled for removal in v3.0.")] public SparseMatrix(Matrix matrix) - : this(matrix.RowCount, matrix.ColumnCount) + : this(SparseCompressedRowMatrixStorage.OfMatrix(matrix.Storage)) { - matrix.Storage.CopyToUnchecked(Storage, skipClearing: true); } /// diff --git a/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs index 4acf29ab..22dcb7ed 100644 --- a/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs @@ -168,15 +168,8 @@ namespace MathNet.Numerics.LinearAlgebra.Single /// [Obsolete("Use DenseMatrix.OfArray instead. Scheduled for removal in v3.0.")] public DenseMatrix(float[,] array) - : this(array.GetLength(0), array.GetLength(1)) + : this(DenseColumnMajorMatrixStorage.OfArray(array)) { - for (var i = 0; i < _rowCount; i++) - { - for (var j = 0; j < _columnCount; j++) - { - _values[(j * _rowCount) + i] = array[i, j]; - } - } } /// @@ -186,9 +179,8 @@ namespace MathNet.Numerics.LinearAlgebra.Single /// [Obsolete("Use DenseMatrix.OfMatrix instead. Scheduled for removal in v3.0.")] public DenseMatrix(Matrix matrix) - : this(matrix.RowCount, matrix.ColumnCount) + : this(DenseColumnMajorMatrixStorage.OfMatrix(matrix.Storage)) { - matrix.Storage.CopyToUnchecked(Storage, skipClearing: true); } /// diff --git a/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs index cd03fee8..c5e6ad5e 100644 --- a/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs +++ b/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs @@ -148,22 +148,8 @@ namespace MathNet.Numerics.LinearAlgebra.Single /// [Obsolete("Use DiagonalMatrix.OfArray instead. Scheduled for removal in v3.0.")] public DiagonalMatrix(float[,] array) - : this(array.GetLength(0), array.GetLength(1)) + : this(DiagonalMatrixStorage.OfArray(array)) { - for (var i = 0; i < RowCount; i++) - { - for (var j = 0; j < ColumnCount; j++) - { - if (i == j) - { - _data[i] = array[i, j]; - } - else if (array[i, j] != 0.0 && !float.IsNaN(array[i, j])) - { - throw new IndexOutOfRangeException("Cannot set an off-diagonal element in a diagonal matrix."); - } - } - } } /// @@ -174,9 +160,8 @@ namespace MathNet.Numerics.LinearAlgebra.Single /// [Obsolete("Use DiagonalMatrix.OfMatrix instead. Scheduled for removal in v3.0.")] public DiagonalMatrix(Matrix matrix) - : this(matrix.RowCount, matrix.ColumnCount) + : this(DiagonalMatrixStorage.OfMatrix(matrix.Storage)) { - matrix.Storage.CopyToUnchecked(Storage, skipClearing: true); } /// diff --git a/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs index 5c3eedbb..cf42d823 100644 --- a/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs @@ -219,15 +219,8 @@ namespace MathNet.Numerics.LinearAlgebra.Single /// [Obsolete("Use SparseMatrix.OfArray instead. Scheduled for removal in v3.0.")] public SparseMatrix(float[,] array) - : this(array.GetLength(0), array.GetLength(1)) + : this(SparseCompressedRowMatrixStorage.OfArray(array)) { - for (var i = 0; i < _storage.RowCount; i++) - { - for (var j = 0; j < _storage.ColumnCount; j++) - { - _storage.At(i, j, array[i, j]); - } - } } /// @@ -237,9 +230,8 @@ namespace MathNet.Numerics.LinearAlgebra.Single /// [Obsolete("Use SparseMatrix.OfMatrix instead. Scheduled for removal in v3.0.")] public SparseMatrix(Matrix matrix) - : this(matrix.RowCount, matrix.ColumnCount) + : this(SparseCompressedRowMatrixStorage.OfMatrix(matrix.Storage)) { - matrix.Storage.CopyToUnchecked(Storage, skipClearing: true); } ///