diff --git a/src/Numerics/LinearAlgebra/Matrix.cs b/src/Numerics/LinearAlgebra/Matrix.cs
index c5c6004e..42d4877f 100644
--- a/src/Numerics/LinearAlgebra/Matrix.cs
+++ b/src/Numerics/LinearAlgebra/Matrix.cs
@@ -1280,6 +1280,8 @@ namespace MathNet.Numerics.LinearAlgebra
///
/// Returns this matrix as a multidimensional array.
+ /// The returned array will be independent from this matrix.
+ /// A new memory block will be allocated for the array.
///
/// A multidimensional containing the values of this matrix.
public T[,] ToArray()
@@ -1288,7 +1290,9 @@ namespace MathNet.Numerics.LinearAlgebra
}
///
- /// Returns the matrix's elements as an array with the data laid out column-wise.
+ /// Returns the matrix's elements as an array with the data laid out column by column (column major).
+ /// The returned array will be independent from this matrix.
+ /// A new memory block will be allocated for the array.
///
///
/// 1, 2, 3
@@ -1296,15 +1300,23 @@ namespace MathNet.Numerics.LinearAlgebra
/// 7, 8, 9
///
/// An array containing the matrix's elements.
- ///
+ ///
///
- public T[] ToColumnWiseArray()
+ public T[] ToColumnMajorArray()
{
return Storage.ToColumnMajorArray();
}
+ [Obsolete("Use ToColumnMajorArray instead. Will be removed in v4.")]
+ public T[] ToColumnWiseArray()
+ {
+ return ToColumnMajorArray();
+ }
+
///
- /// Returns the matrix's elements as an array with the data laid row-wise.
+ /// Returns the matrix's elements as an array with the data laid row by row (row major).
+ /// The returned array will be independent from this matrix.
+ /// A new memory block will be allocated for the array.
///
///
/// 1, 2, 3
@@ -1312,15 +1324,24 @@ namespace MathNet.Numerics.LinearAlgebra
/// 7, 8, 9
///
/// An array containing the matrix's elements.
- ///
+ ///
///
- public T[] ToRowWiseArray()
+ public T[] ToRowMajorArray()
{
return Storage.ToRowMajorArray();
}
+
+ [Obsolete("Use ToRowMajorArray instead. Will be removed in v4.")]
+ public T[] ToRowWiseArray()
+ {
+ return ToRowMajorArray();
+ }
+
///
/// Returns this matrix as array of row arrays.
+ /// The returned arrays will be independent from this matrix.
+ /// A new memory block will be allocated for the arrays.
///
public T[][] ToRowArrays()
{
@@ -1329,12 +1350,86 @@ namespace MathNet.Numerics.LinearAlgebra
///
/// Returns this matrix as array of column arrays.
+ /// The returned arrays will be independent from this matrix.
+ /// A new memory block will be allocated for the arrays.
///
public T[][] ToColumnArrays()
{
return Storage.ToColumnArrays();
}
+ ///
+ /// Returns this matrix as a multidimensional array.
+ /// If the internal data structure matches the requested shape it is returned directly, without copying.
+ /// If the internal structure is returned, changes to the array and the matrix will affect each other.
+ /// Use ToArray instead if you always need an independent array.
+ ///
+ /// A multidimensional containing the values of this matrix.
+ public T[,] AsArray()
+ {
+ return Storage.AsArray();
+ }
+
+ ///
+ /// Returns the matrix's elements as an array with the data laid out column by column (column major).
+ /// If the internal data structure matches the requested shape it is returned directly, without copying.
+ /// If the internal structure is returned, changes to the array and the matrix will affect each other.
+ /// Use ToColumnMajorArray instead if you always need an independent array.
+ ///
+ ///
+ /// 1, 2, 3
+ /// 4, 5, 6 will be returned as 1, 4, 7, 2, 5, 8, 3, 6, 9
+ /// 7, 8, 9
+ ///
+ /// An array containing the matrix's elements.
+ ///
+ ///
+ public T[] AsColumnMajorArray()
+ {
+ return Storage.AsColumnMajorArray();
+ }
+
+ ///
+ /// Returns the matrix's elements as an array with the data laid row by row (row major).
+ /// If the internal data structure matches the requested shape it is returned directly, without copying.
+ /// If the internal structure is returned, changes to the array and the matrix will affect each other.
+ /// Use ToRowMajorArray instead if you always need an independent array.
+ ///
+ ///
+ /// 1, 2, 3
+ /// 4, 5, 6 will be returned as 1, 2, 3, 4, 5, 6, 7, 8, 9
+ /// 7, 8, 9
+ ///
+ /// An array containing the matrix's elements.
+ ///
+ ///
+ public T[] AsRowMajorArray()
+ {
+ return Storage.AsRowMajorArray();
+ }
+
+ ///
+ /// Returns this matrix as array of row arrays.
+ /// If the internal data structure matches the requested shape it is returned directly, without copying.
+ /// If the internal structure is returned, changes to the array and the matrix will affect each other.
+ /// Use ToRowArrays instead if you always need an independent array.
+ ///
+ public T[][] AsRowArrays()
+ {
+ return Storage.AsRowArrays();
+ }
+
+ ///
+ /// Returns this matrix as array of column arrays.
+ /// If the internal data structure matches the requested shape it is returned directly, without copying.
+ /// If the internal structure is returned, changes to the array and the matrix will affect each other.
+ /// Use ToColumnArrays instead if you always need an independent array.
+ ///
+ public T[][] AsColumnArrays()
+ {
+ return Storage.AsColumnArrays();
+ }
+
///
/// Returns an IEnumerable that can be used to iterate through all values of the matrix.
///
@@ -1342,8 +1437,6 @@ namespace MathNet.Numerics.LinearAlgebra
/// The enumerator will include all values, even if they are zero.
/// The ordering of the values is unspecified (not necessarily column-wise or row-wise).
///
- ///
- ///
public IEnumerable Enumerate()
{
return Storage.Enumerate();
@@ -1356,8 +1449,6 @@ namespace MathNet.Numerics.LinearAlgebra
/// The enumerator will include all values, even if they are zero.
/// The ordering of the values is unspecified (not necessarily column-wise or row-wise).
///
- ///
- ///
public IEnumerable Enumerate(Zeros zeros = Zeros.Include)
{
switch (zeros)
diff --git a/src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs b/src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs
index 2bd522ca..90c6bafa 100644
--- a/src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs
+++ b/src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs
@@ -664,6 +664,11 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return ret;
}
+ public override T[] AsColumnMajorArray()
+ {
+ return Data;
+ }
+
// ENUMERATION
public override IEnumerable Enumerate()
diff --git a/src/Numerics/LinearAlgebra/Storage/MatrixStorage.cs b/src/Numerics/LinearAlgebra/Storage/MatrixStorage.cs
index e1f46e79..3f3f14e7 100644
--- a/src/Numerics/LinearAlgebra/Storage/MatrixStorage.cs
+++ b/src/Numerics/LinearAlgebra/Storage/MatrixStorage.cs
@@ -565,6 +565,31 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return ret;
}
+ public virtual T[] AsRowMajorArray()
+ {
+ return ToRowMajorArray();
+ }
+
+ public virtual T[] AsColumnMajorArray()
+ {
+ return ToColumnMajorArray();
+ }
+
+ public virtual T[][] AsRowArrays()
+ {
+ return ToRowArrays();
+ }
+
+ public virtual T[][] AsColumnArrays()
+ {
+ return ToColumnArrays();
+ }
+
+ public virtual T[,] AsArray()
+ {
+ return ToArray();
+ }
+
// ENUMERATION
public virtual IEnumerable Enumerate()
diff --git a/src/UnitTests/LinearAlgebraTests/Complex/UserDefinedMatrix.cs b/src/UnitTests/LinearAlgebraTests/Complex/UserDefinedMatrix.cs
index 30ac7d92..1480be50 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex/UserDefinedMatrix.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex/UserDefinedMatrix.cs
@@ -79,6 +79,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
{
Data[row, column] = value;
}
+
+ public override Complex[,] AsArray()
+ {
+ return Data;
+ }
}
///
diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/UserDefinedMatrix.cs b/src/UnitTests/LinearAlgebraTests/Complex32/UserDefinedMatrix.cs
index 8c088cf8..e1b4f889 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex32/UserDefinedMatrix.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex32/UserDefinedMatrix.cs
@@ -75,6 +75,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
{
Data[row, column] = value;
}
+
+ public override Complex32[,] AsArray()
+ {
+ return Data;
+ }
}
///
diff --git a/src/UnitTests/LinearAlgebraTests/Double/UserDefinedMatrix.cs b/src/UnitTests/LinearAlgebraTests/Double/UserDefinedMatrix.cs
index 099b1f60..a1659d27 100644
--- a/src/UnitTests/LinearAlgebraTests/Double/UserDefinedMatrix.cs
+++ b/src/UnitTests/LinearAlgebraTests/Double/UserDefinedMatrix.cs
@@ -73,6 +73,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
{
Data[row, column] = value;
}
+
+ public override double[,] AsArray()
+ {
+ return Data;
+ }
}
///
diff --git a/src/UnitTests/LinearAlgebraTests/Single/UserDefinedMatrix.cs b/src/UnitTests/LinearAlgebraTests/Single/UserDefinedMatrix.cs
index 7786e886..4972ddb7 100644
--- a/src/UnitTests/LinearAlgebraTests/Single/UserDefinedMatrix.cs
+++ b/src/UnitTests/LinearAlgebraTests/Single/UserDefinedMatrix.cs
@@ -73,6 +73,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
{
Data[row, column] = value;
}
+
+ public override float[,] AsArray()
+ {
+ return Data;
+ }
}
///