@@ -1403,9 +1401,8 @@ namespace MathNet.Numerics.LinearAlgebra
}
///
- /// 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.
+ /// Returns the internal row by row (row major) array of this matrix if, and only if, this matrix is stored by such arrays internally.
+ /// Otherwise returns null. Changes to the returned arrays and the matrix will affect each other.
/// Use ToRowMajorArray instead if you always need an independent array.
///
///
@@ -1422,9 +1419,8 @@ namespace MathNet.Numerics.LinearAlgebra
}
///
- /// 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.
+ /// Returns the internal row arrays of this matrix if, and only if, this matrix is stored by such arrays internally.
+ /// Otherwise returns null. Changes to the returned arrays and the matrix will affect each other.
/// Use ToRowArrays instead if you always need an independent array.
///
public T[][] AsRowArrays()
@@ -1433,9 +1429,8 @@ namespace MathNet.Numerics.LinearAlgebra
}
///
- /// 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.
+ /// Returns the internal column arrays of this matrix if, and only if, this matrix is stored by such arrays internally.
+ /// Otherwise returns null. Changes to the returned arrays and the matrix will affect each other.
/// Use ToColumnArrays instead if you always need an independent array.
///
public T[][] AsColumnArrays()
diff --git a/src/Numerics/LinearAlgebra/Storage/MatrixStorage.cs b/src/Numerics/LinearAlgebra/Storage/MatrixStorage.cs
index b8c65143..a7470dc3 100644
--- a/src/Numerics/LinearAlgebra/Storage/MatrixStorage.cs
+++ b/src/Numerics/LinearAlgebra/Storage/MatrixStorage.cs
@@ -581,27 +581,27 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
public virtual T[] AsRowMajorArray()
{
- return ToRowMajorArray();
+ return null;
}
public virtual T[] AsColumnMajorArray()
{
- return ToColumnMajorArray();
+ return null;
}
public virtual T[][] AsRowArrays()
{
- return ToRowArrays();
+ return null;
}
public virtual T[][] AsColumnArrays()
{
- return ToColumnArrays();
+ return null;
}
public virtual T[,] AsArray()
{
- return ToArray();
+ return null;
}
// ENUMERATION
diff --git a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs
index 8ad6a925..c8fdc112 100644
--- a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs
+++ b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs
@@ -307,6 +307,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
{
Matrix matrix = Get(testMatrix);
var array = matrix.AsArray();
+ if (array == null)
+ {
+ return;
+ }
+
+ Assert.That(array, Is.SameAs(matrix.AsArray()));
Assert.That(array, Is.Not.SameAs(matrix.ToArray()));
Assert.That(array.GetLength(0), Is.EqualTo(matrix.RowCount));
Assert.That(array.GetLength(1), Is.EqualTo(matrix.ColumnCount));
@@ -324,6 +330,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
{
Matrix matrix = Get(testMatrix);
var columnArrays = matrix.AsColumnArrays();
+ if (columnArrays == null)
+ {
+ return;
+ }
+
+ Assert.That(columnArrays, Is.SameAs(matrix.AsColumnArrays()));
Assert.That(columnArrays, Is.Not.SameAs(matrix.ToColumnArrays()));
Assert.That(columnArrays.Length, Is.EqualTo(matrix.ColumnCount));
Assert.That(columnArrays[0].Length, Is.EqualTo(matrix.RowCount));
@@ -341,6 +353,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
{
Matrix matrix = Get(testMatrix);
var rowArrays = matrix.AsRowArrays();
+ if (rowArrays == null)
+ {
+ return;
+ }
+
+ Assert.That(rowArrays, Is.SameAs(matrix.AsRowArrays()));
Assert.That(rowArrays, Is.Not.SameAs(matrix.ToRowArrays()));
Assert.That(rowArrays.Length, Is.EqualTo(matrix.RowCount));
Assert.That(rowArrays[0].Length, Is.EqualTo(matrix.ColumnCount));
@@ -358,6 +376,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
{
Matrix matrix = Get(testMatrix);
var array = matrix.AsColumnMajorArray();
+ if (array == null)
+ {
+ return;
+ }
+
+ Assert.That(array, Is.SameAs(matrix.AsColumnMajorArray()));
Assert.That(array, Is.Not.SameAs(matrix.ToColumnMajorArray()));
Assert.That(array.Length, Is.EqualTo(matrix.RowCount * matrix.ColumnCount));
for (int i = 0; i < array.Length; i++)
@@ -371,6 +395,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
{
Matrix matrix = Get(testMatrix);
var array = matrix.AsRowMajorArray();
+ if (array == null)
+ {
+ return;
+ }
+
+ Assert.That(array, Is.SameAs(matrix.AsRowMajorArray()));
Assert.That(array, Is.Not.SameAs(matrix.ToRowMajorArray()));
Assert.That(array.Length, Is.EqualTo(matrix.RowCount * matrix.ColumnCount));
for (int i = 0; i < array.Length; i++)