Browse Source

LA: proper exception when trying to create a matrix of an empty vector array #294

cuda
Christoph Ruegg 12 years ago
parent
commit
1f26138b59
  1. 20
      src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs
  2. 20
      src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs
  3. 20
      src/Numerics/Properties/Resources.Designer.cs
  4. 6
      src/Numerics/Properties/Resources.resx

20
src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs

@ -228,6 +228,11 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
public static DenseColumnMajorMatrixStorage<T> 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<T> 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<T> OfColumnVectors(VectorStorage<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];
@ -282,6 +297,11 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
public static DenseColumnMajorMatrixStorage<T> OfRowVectors(VectorStorage<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];

20
src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs

@ -516,6 +516,11 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
public static SparseCompressedRowMatrixStorage<T> OfRowArrays(T[][] data)
{
if (data.Length <= 0)
{
throw new ArgumentOutOfRangeException("data", Resources.MatrixCanNotBeEmpty);
}
var storage = new SparseCompressedRowMatrixStorage<T>(data.Length, data[0].Length);
var rowPointers = storage.RowPointers;
var columnIndices = new List<int>();
@ -543,6 +548,11 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
public static SparseCompressedRowMatrixStorage<T> OfColumnArrays(T[][] data)
{
if (data.Length <= 0)
{
throw new ArgumentOutOfRangeException("data", Resources.MatrixCanNotBeEmpty);
}
var storage = new SparseCompressedRowMatrixStorage<T>(data[0].Length, data.Length);
var rowPointers = storage.RowPointers;
var columnIndices = new List<int>();
@ -570,6 +580,11 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
public static SparseCompressedRowMatrixStorage<T> OfRowVectors(VectorStorage<T>[] data)
{
if (data.Length <= 0)
{
throw new ArgumentOutOfRangeException("data", Resources.MatrixCanNotBeEmpty);
}
var storage = new SparseCompressedRowMatrixStorage<T>(data.Length, data[0].Length);
var rowPointers = storage.RowPointers;
var columnIndices = new List<int>();
@ -599,6 +614,11 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
public static SparseCompressedRowMatrixStorage<T> OfColumnVectors(VectorStorage<T>[] data)
{
if (data.Length <= 0)
{
throw new ArgumentOutOfRangeException("data", Resources.MatrixCanNotBeEmpty);
}
var storage = new SparseCompressedRowMatrixStorage<T>(data[0].Length, data.Length);
var rowPointers = storage.RowPointers;
var columnIndices = new List<int>();

20
src/Numerics/Properties/Resources.Designer.cs

@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 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 {
}
}
/// <summary>
/// Looks up a localized string similar to Matrices can not be empty and must have at least one row and column..
/// </summary>
public static string MatrixCanNotBeEmpty {
get {
return ResourceManager.GetString("MatrixCanNotBeEmpty", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The number of columns of a matrix must be positive..
/// </summary>
@ -926,6 +935,15 @@ namespace MathNet.Numerics.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Vectors can not be empty and must have at least one element..
/// </summary>
public static string VectorCanNotBeEmpty {
get {
return ResourceManager.GetString("VectorCanNotBeEmpty", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The given work array is too small. Check work[0] for the corret size..
/// </summary>

6
src/Numerics/Properties/Resources.resx

@ -406,4 +406,10 @@
<data name="ArgumentUpperBoundMustBeLargerThanLowerBound" xml:space="preserve">
<value>The upper bound must be strictly larger than the lower bound.</value>
</data>
<data name="MatrixCanNotBeEmpty" xml:space="preserve">
<value>Matrices can not be empty and must have at least one row and column.</value>
</data>
<data name="VectorCanNotBeEmpty" xml:space="preserve">
<value>Vectors can not be empty and must have at least one element.</value>
</data>
</root>
Loading…
Cancel
Save