diff --git a/src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs b/src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs index 265d12e1..6ce1045a 100644 --- a/src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs +++ b/src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs @@ -228,6 +228,11 @@ namespace MathNet.Numerics.LinearAlgebra.Storage public static DenseColumnMajorMatrixStorage OfColumnArrays(T[][] data) { + if (data.Length <= 0) + { + throw new ArgumentOutOfRangeException("data", Resources.MatrixCanNotBeEmpty); + } + int columns = data.Length; int rows = data[0].Length; var array = new T[rows*columns]; @@ -240,6 +245,11 @@ namespace MathNet.Numerics.LinearAlgebra.Storage public static DenseColumnMajorMatrixStorage OfRowArrays(T[][] data) { + if (data.Length <= 0) + { + throw new ArgumentOutOfRangeException("data", Resources.MatrixCanNotBeEmpty); + } + int rows = data.Length; int columns = data[0].Length; var array = new T[rows*columns]; @@ -256,6 +266,11 @@ namespace MathNet.Numerics.LinearAlgebra.Storage public static DenseColumnMajorMatrixStorage OfColumnVectors(VectorStorage[] data) { + if (data.Length <= 0) + { + throw new ArgumentOutOfRangeException("data", Resources.MatrixCanNotBeEmpty); + } + int columns = data.Length; int rows = data[0].Length; var array = new T[rows*columns]; @@ -282,6 +297,11 @@ namespace MathNet.Numerics.LinearAlgebra.Storage public static DenseColumnMajorMatrixStorage OfRowVectors(VectorStorage[] data) { + if (data.Length <= 0) + { + throw new ArgumentOutOfRangeException("data", Resources.MatrixCanNotBeEmpty); + } + int rows = data.Length; int columns = data[0].Length; var array = new T[rows*columns]; diff --git a/src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs b/src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs index 83e3cd92..d839ebb7 100644 --- a/src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs +++ b/src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs @@ -516,6 +516,11 @@ namespace MathNet.Numerics.LinearAlgebra.Storage public static SparseCompressedRowMatrixStorage OfRowArrays(T[][] data) { + if (data.Length <= 0) + { + throw new ArgumentOutOfRangeException("data", Resources.MatrixCanNotBeEmpty); + } + var storage = new SparseCompressedRowMatrixStorage(data.Length, data[0].Length); var rowPointers = storage.RowPointers; var columnIndices = new List(); @@ -543,6 +548,11 @@ namespace MathNet.Numerics.LinearAlgebra.Storage public static SparseCompressedRowMatrixStorage OfColumnArrays(T[][] data) { + if (data.Length <= 0) + { + throw new ArgumentOutOfRangeException("data", Resources.MatrixCanNotBeEmpty); + } + var storage = new SparseCompressedRowMatrixStorage(data[0].Length, data.Length); var rowPointers = storage.RowPointers; var columnIndices = new List(); @@ -570,6 +580,11 @@ namespace MathNet.Numerics.LinearAlgebra.Storage public static SparseCompressedRowMatrixStorage OfRowVectors(VectorStorage[] data) { + if (data.Length <= 0) + { + throw new ArgumentOutOfRangeException("data", Resources.MatrixCanNotBeEmpty); + } + var storage = new SparseCompressedRowMatrixStorage(data.Length, data[0].Length); var rowPointers = storage.RowPointers; var columnIndices = new List(); @@ -599,6 +614,11 @@ namespace MathNet.Numerics.LinearAlgebra.Storage public static SparseCompressedRowMatrixStorage OfColumnVectors(VectorStorage[] data) { + if (data.Length <= 0) + { + throw new ArgumentOutOfRangeException("data", Resources.MatrixCanNotBeEmpty); + } + var storage = new SparseCompressedRowMatrixStorage(data[0].Length, data.Length); var rowPointers = storage.RowPointers; var columnIndices = new List(); diff --git a/src/Numerics/Properties/Resources.Designer.cs b/src/Numerics/Properties/Resources.Designer.cs index 6cd31155..0c7fae4d 100644 --- a/src/Numerics/Properties/Resources.Designer.cs +++ b/src/Numerics/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.34014 +// Runtime Version:4.0.30319.34209 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -700,6 +700,15 @@ namespace MathNet.Numerics.Properties { } } + /// + /// Looks up a localized string similar to Matrices can not be empty and must have at least one row and column.. + /// + public static string MatrixCanNotBeEmpty { + get { + return ResourceManager.GetString("MatrixCanNotBeEmpty", resourceCulture); + } + } + /// /// Looks up a localized string similar to The number of columns of a matrix must be positive.. /// @@ -926,6 +935,15 @@ namespace MathNet.Numerics.Properties { } } + /// + /// Looks up a localized string similar to Vectors can not be empty and must have at least one element.. + /// + public static string VectorCanNotBeEmpty { + get { + return ResourceManager.GetString("VectorCanNotBeEmpty", resourceCulture); + } + } + /// /// Looks up a localized string similar to The given work array is too small. Check work[0] for the corret size.. /// diff --git a/src/Numerics/Properties/Resources.resx b/src/Numerics/Properties/Resources.resx index 6645b02e..d46d44c8 100644 --- a/src/Numerics/Properties/Resources.resx +++ b/src/Numerics/Properties/Resources.resx @@ -406,4 +406,10 @@ The upper bound must be strictly larger than the lower bound. + + Matrices can not be empty and must have at least one row and column. + + + Vectors can not be empty and must have at least one element. + \ No newline at end of file