Browse Source

LA Storage: this = range checked, At = not checked

pull/47/head
Christoph Ruegg 14 years ago
parent
commit
29471df102
  1. 37
      src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
  2. 22
      src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
  3. 34
      src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
  4. 37
      src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
  5. 22
      src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
  6. 34
      src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
  7. 37
      src/Numerics/LinearAlgebra/Double/DenseMatrix.cs
  8. 22
      src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
  9. 34
      src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
  10. 37
      src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
  11. 22
      src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
  12. 34
      src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
  13. 59
      src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs
  14. 62
      src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs
  15. 59
      src/Numerics/LinearAlgebra/Storage/SparseDiagonalMatrixStorage.cs

37
src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs

@ -283,7 +283,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
/// <summary>
/// Gets or sets the value at the given row and column.
/// Gets or sets the value at the given row and column, with range checking.
/// </summary>
/// <param name="row">
/// The row of the element.
@ -296,35 +296,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// to get and set values without range checking.</remarks>
public override Complex this[int row, int column]
{
get
{
if (row < 0 || row >= _rowCount)
{
throw new ArgumentOutOfRangeException("row");
}
if (column < 0 || column >= _columnCount)
{
throw new ArgumentOutOfRangeException("column");
}
return _data[(column * _rowCount) + row];
}
set
{
if (row < 0 || row >= _rowCount)
{
throw new ArgumentOutOfRangeException("row");
}
if (column < 0 || column >= _columnCount)
{
throw new ArgumentOutOfRangeException("column");
}
_data[(column * _rowCount) + row] = value;
}
get { return _storage[row, column]; }
set { _storage[row, column] = value; }
}
/// <summary>
@ -341,7 +314,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// </returns>
public override Complex At(int row, int column)
{
return _storage[row, column];
return _storage.At(row, column);
}
/// <summary>
@ -358,7 +331,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// </param>
public override void At(int row, int column, Complex value)
{
_storage[row, column] = value;
_storage.At(row, column, value);
}
/// <summary>

22
src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs

@ -149,6 +149,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
get { return _storage; }
}
/// <summary>
/// Gets or sets the value at the given row and column, with range checking.
/// </summary>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <value>The value to get or set.</value>
/// <remarks>This method is ranged checked. <see cref="At(int,int)"/> and <see cref="At(int,int,Complex)"/>
/// to get and set values without range checking.</remarks>
public override Complex this[int row, int column]
{
get { return _storage[row, column]; }
set { _storage[row, column] = value; }
}
/// <summary>
/// Retrieves the requested element without range checking.
/// </summary>
@ -165,7 +183,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// may be thrown if one of the indices is outside the dimensions of the matrix.</exception>
public override Complex At(int row, int column)
{
return _storage[row, column];
return _storage.At(row, column);
}
/// <summary>
@ -185,7 +203,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// may be thrown if one of the indices is outside the dimensions of the matrix.</exception>
public override void At(int row, int column, Complex value)
{
_storage[row, column] = value;
_storage.At(row, column, value);
}
/// <summary>

34
src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs

@ -150,7 +150,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
{
for (var j = 0; j < columns; j++)
{
_storage.SetValueAt(i, j, array[i + (j * rows)]);
_storage.At(i, j, array[i + (j * rows)]);
}
}
}
@ -168,7 +168,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
{
for (var j = 0; j < _storage.ColumnCount; j++)
{
_storage.SetValueAt(i, j, array[i, j]);
_storage.At(i, j, array[i, j]);
}
}
}
@ -194,7 +194,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
{
for (var j = 0; j < columns; j++)
{
_storage.SetValueAt(i, j, matrix.At(i, j));
_storage.At(i, j, matrix.At(i, j));
}
}
}
@ -448,7 +448,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
if ((columnIndices[j] >= columnIndex) && (columnIndices[j] < columnIndex + columnCount))
{
var column = columnIndices[j] - columnIndex;
result._storage.SetValueAt(row, column, values[j]);
result._storage.At(row, column, values[j]);
}
}
}
@ -617,6 +617,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return ret;
}
/// <summary>
/// Gets or sets the value at the given row and column, with range checking.
/// </summary>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <value>The value to get or set.</value>
/// <remarks>This method is ranged checked. <see cref="At(int,int)"/> and <see cref="At(int,int,Complex)"/>
/// to get and set values without range checking.</remarks>
public override Complex this[int row, int column]
{
get { return _storage[row, column]; }
set { _storage[row, column] = value; }
}
/// <summary>
/// Retrieves the requested element without range checking.
/// </summary>
@ -631,7 +649,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// </returns>
public override Complex At(int row, int column)
{
return _storage.GetValueAt(row, column);
return _storage.At(row, column);
}
/// <summary>
@ -648,7 +666,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// </param>
public override void At(int row, int column, Complex value)
{
_storage.SetValueAt(row, column, value);
_storage.At(row, column, value);
}
/// <summary>
@ -760,7 +778,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
for (var j = startIndex; j < endIndex; j++)
{
retStorage.SetValueAt(columnIndices[j], i, values[j]);
retStorage.At(columnIndices[j], i, values[j]);
}
}
@ -1354,7 +1372,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
}
resultSparse.Storage.SetValueAt(i, j, sum + result.At(i, j));
resultSparse.Storage.At(i, j, sum + result.At(i, j));
}
}
}

37
src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs

@ -283,7 +283,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
/// <summary>
/// Gets or sets the value at the given row and column.
/// Gets or sets the value at the given row and column, with range checking.
/// </summary>
/// <param name="row">
/// The row of the element.
@ -296,35 +296,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// to get and set values without range checking.</remarks>
public override Complex32 this[int row, int column]
{
get
{
if (row < 0 || row >= _rowCount)
{
throw new ArgumentOutOfRangeException("row");
}
if (column < 0 || column >= _columnCount)
{
throw new ArgumentOutOfRangeException("column");
}
return _data[(column * _rowCount) + row];
}
set
{
if (row < 0 || row >= _rowCount)
{
throw new ArgumentOutOfRangeException("row");
}
if (column < 0 || column >= _columnCount)
{
throw new ArgumentOutOfRangeException("column");
}
_data[(column * _rowCount) + row] = value;
}
get { return _storage[row, column]; }
set { _storage[row, column] = value; }
}
/// <summary>
@ -341,7 +314,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// </returns>
public override Complex32 At(int row, int column)
{
return _storage[row, column];
return _storage.At(row, column);
}
/// <summary>
@ -358,7 +331,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// </param>
public override void At(int row, int column, Complex32 value)
{
_storage[row, column] = value;
_storage.At(row, column, value);
}
/// <summary>

22
src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs

@ -154,6 +154,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
get { return _storage; }
}
/// <summary>
/// Gets or sets the value at the given row and column, with range checking.
/// </summary>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <value>The value to get or set.</value>
/// <remarks>This method is ranged checked. <see cref="At(int,int)"/> and <see cref="At(int,int,Complex32)"/>
/// to get and set values without range checking.</remarks>
public override Complex32 this[int row, int column]
{
get { return _storage[row, column]; }
set { _storage[row, column] = value; }
}
/// <summary>
/// Retrieves the requested element without range checking.
/// </summary>
@ -170,7 +188,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// may be thrown if one of the indices is outside the dimensions of the matrix.</exception>
public override Complex32 At(int row, int column)
{
return _storage[row, column];
return _storage.At(row, column);
}
/// <summary>
@ -190,7 +208,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// may be thrown if one of the indices is outside the dimensions of the matrix.</exception>
public override void At(int row, int column, Complex32 value)
{
_storage[row, column] = value;
_storage.At(row, column, value);
}
/// <summary>

34
src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs

@ -150,7 +150,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
{
for (var j = 0; j < columns; j++)
{
_storage.SetValueAt(i, j, array[i + (j * rows)]);
_storage.At(i, j, array[i + (j * rows)]);
}
}
}
@ -168,7 +168,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
{
for (var j = 0; j < _storage.ColumnCount; j++)
{
_storage.SetValueAt(i, j, array[i, j]);
_storage.At(i, j, array[i, j]);
}
}
}
@ -194,7 +194,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
{
for (var j = 0; j < columns; j++)
{
_storage.SetValueAt(i, j, matrix.At(i, j));
_storage.At(i, j, matrix.At(i, j));
}
}
}
@ -448,7 +448,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
if ((columnIndices[j] >= columnIndex) && (columnIndices[j] < columnIndex + columnCount))
{
var column = columnIndices[j] - columnIndex;
result._storage.SetValueAt(row, column, values[j]);
result._storage.At(row, column, values[j]);
}
}
}
@ -617,6 +617,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return ret;
}
/// <summary>
/// Gets or sets the value at the given row and column, with range checking.
/// </summary>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <value>The value to get or set.</value>
/// <remarks>This method is ranged checked. <see cref="At(int,int)"/> and <see cref="At(int,int,Complex32)"/>
/// to get and set values without range checking.</remarks>
public override Complex32 this[int row, int column]
{
get { return _storage[row, column]; }
set { _storage[row, column] = value; }
}
/// <summary>
/// Retrieves the requested element without range checking.
/// </summary>
@ -631,7 +649,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// </returns>
public override Complex32 At(int row, int column)
{
return _storage.GetValueAt(row, column);
return _storage.At(row, column);
}
/// <summary>
@ -648,7 +666,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// </param>
public override void At(int row, int column, Complex32 value)
{
_storage.SetValueAt(row, column, value);
_storage.At(row, column, value);
}
/// <summary>
@ -761,7 +779,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
for (var j = startIndex; j < endIndex; j++)
{
retStorage.SetValueAt(columnIndices[j], i, values[j]);
retStorage.At(columnIndices[j], i, values[j]);
}
}
@ -1354,7 +1372,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
}
resultSparse.Storage.SetValueAt(i, j, sum + result.At(i, j));
resultSparse.Storage.At(i, j, sum + result.At(i, j));
}
}
}

37
src/Numerics/LinearAlgebra/Double/DenseMatrix.cs

@ -283,7 +283,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
/// <summary>
/// Gets or sets the value at the given row and column.
/// Gets or sets the value at the given row and column, with range checking.
/// </summary>
/// <param name="row">
/// The row of the element.
@ -296,35 +296,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// to get and set values without range checking.</remarks>
public override double this[int row, int column]
{
get
{
if (row < 0 || row >= _rowCount)
{
throw new ArgumentOutOfRangeException("row");
}
if (column < 0 || column >= _columnCount)
{
throw new ArgumentOutOfRangeException("column");
}
return _data[(column * _rowCount) + row];
}
set
{
if (row < 0 || row >= _rowCount)
{
throw new ArgumentOutOfRangeException("row");
}
if (column < 0 || column >= _columnCount)
{
throw new ArgumentOutOfRangeException("column");
}
_data[(column * _rowCount) + row] = value;
}
get { return _storage[row, column]; }
set { _storage[row, column] = value; }
}
/// <summary>
@ -341,7 +314,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// </returns>
public override double At(int row, int column)
{
return _storage[row, column];
return _storage.At(row, column);
}
/// <summary>
@ -358,7 +331,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// </param>
public override void At(int row, int column, double value)
{
_storage[row, column] = value;
_storage.At(row, column, value);
}
/// <summary>

22
src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs

@ -148,6 +148,24 @@ namespace MathNet.Numerics.LinearAlgebra.Double
get { return _storage; }
}
/// <summary>
/// Gets or sets the value at the given row and column, with range checking.
/// </summary>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <value>The value to get or set.</value>
/// <remarks>This method is ranged checked. <see cref="At(int,int)"/> and <see cref="At(int,int,double)"/>
/// to get and set values without range checking.</remarks>
public override double this[int row, int column]
{
get { return _storage[row, column]; }
set { _storage[row, column] = value; }
}
/// <summary>
/// Retrieves the requested element without range checking.
/// </summary>
@ -164,7 +182,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// may be thrown if one of the indices is outside the dimensions of the matrix.</exception>
public override double At(int row, int column)
{
return _storage[row, column];
return _storage.At(row, column);
}
/// <summary>
@ -184,7 +202,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// may be thrown if one of the indices is outside the dimensions of the matrix.</exception>
public override void At(int row, int column, double value)
{
_storage[row, column] = value;
_storage.At(row, column, value);
}
/// <summary>

34
src/Numerics/LinearAlgebra/Double/SparseMatrix.cs

@ -149,7 +149,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
{
for (var j = 0; j < columns; j++)
{
_storage.SetValueAt(i, j, array[i + (j * rows)]);
_storage.At(i, j, array[i + (j * rows)]);
}
}
}
@ -167,7 +167,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
{
for (var j = 0; j < _storage.ColumnCount; j++)
{
_storage.SetValueAt(i, j, array[i, j]);
_storage.At(i, j, array[i, j]);
}
}
}
@ -193,7 +193,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
{
for (var j = 0; j < columns; j++)
{
_storage.SetValueAt(i, j, matrix.At(i, j));
_storage.At(i, j, matrix.At(i, j));
}
}
}
@ -447,7 +447,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
if ((columnIndices[j] >= columnIndex) && (columnIndices[j] < columnIndex + columnCount))
{
var column = columnIndices[j] - columnIndex;
result._storage.SetValueAt(row, column, values[j]);
result._storage.At(row, column, values[j]);
}
}
}
@ -616,6 +616,24 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return ret;
}
/// <summary>
/// Gets or sets the value at the given row and column, with range checking.
/// </summary>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <value>The value to get or set.</value>
/// <remarks>This method is ranged checked. <see cref="At(int,int)"/> and <see cref="At(int,int,double)"/>
/// to get and set values without range checking.</remarks>
public override double this[int row, int column]
{
get { return _storage[row, column]; }
set { _storage[row, column] = value; }
}
/// <summary>
/// Retrieves the requested element without range checking.
/// </summary>
@ -630,7 +648,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// </returns>
public override double At(int row, int column)
{
return _storage.GetValueAt(row, column);
return _storage.At(row, column);
}
/// <summary>
@ -647,7 +665,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// </param>
public override void At(int row, int column, double value)
{
_storage.SetValueAt(row, column, value);
_storage.At(row, column, value);
}
/// <summary>
@ -759,7 +777,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
for (var j = startIndex; j < endIndex; j++)
{
retStorage.SetValueAt(columnIndices[j], i, values[j]);
retStorage.At(columnIndices[j], i, values[j]);
}
}
@ -1352,7 +1370,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
}
resultSparse.Storage.SetValueAt(i, j, sum + result.At(i, j));
resultSparse.Storage.At(i, j, sum + result.At(i, j));
}
}
}

37
src/Numerics/LinearAlgebra/Single/DenseMatrix.cs

@ -283,7 +283,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
/// <summary>
/// Gets or sets the value at the given row and column.
/// Gets or sets the value at the given row and column, with range checking.
/// </summary>
/// <param name="row">
/// The row of the element.
@ -296,35 +296,8 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// to get and set values without range checking.</remarks>
public override float this[int row, int column]
{
get
{
if (row < 0 || row >= _rowCount)
{
throw new ArgumentOutOfRangeException("row");
}
if (column < 0 || column >= _columnCount)
{
throw new ArgumentOutOfRangeException("column");
}
return _data[(column * _rowCount) + row];
}
set
{
if (row < 0 || row >= _rowCount)
{
throw new ArgumentOutOfRangeException("row");
}
if (column < 0 || column >= _columnCount)
{
throw new ArgumentOutOfRangeException("column");
}
_data[(column * _rowCount) + row] = value;
}
get { return _storage[row, column]; }
set { _storage[row, column] = value; }
}
/// <summary>
@ -341,7 +314,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// </returns>
public override float At(int row, int column)
{
return _storage[row, column];
return _storage.At(row, column);
}
/// <summary>
@ -358,7 +331,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// </param>
public override void At(int row, int column, float value)
{
_storage[row, column] = value;
_storage.At(row, column, value);
}
/// <summary>

22
src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs

@ -153,6 +153,24 @@ namespace MathNet.Numerics.LinearAlgebra.Single
get { return _storage; }
}
/// <summary>
/// Gets or sets the value at the given row and column, with range checking.
/// </summary>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <value>The value to get or set.</value>
/// <remarks>This method is ranged checked. <see cref="At(int,int)"/> and <see cref="At(int,int,float)"/>
/// to get and set values without range checking.</remarks>
public override float this[int row, int column]
{
get { return _storage[row, column]; }
set { _storage[row, column] = value; }
}
/// <summary>
/// Retrieves the requested element without range checking.
/// </summary>
@ -169,7 +187,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// may be thrown if one of the indices is outside the dimensions of the matrix.</exception>
public override float At(int row, int column)
{
return _storage[row, column];
return _storage.At(row, column);
}
/// <summary>
@ -189,7 +207,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// may be thrown if one of the indices is outside the dimensions of the matrix.</exception>
public override void At(int row, int column, float value)
{
_storage[row, column] = value;
_storage.At(row, column, value);
}
/// <summary>

34
src/Numerics/LinearAlgebra/Single/SparseMatrix.cs

@ -149,7 +149,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
{
for (var j = 0; j < columns; j++)
{
_storage.SetValueAt(i, j, array[i + (j * rows)]);
_storage.At(i, j, array[i + (j * rows)]);
}
}
}
@ -167,7 +167,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
{
for (var j = 0; j < _storage.ColumnCount; j++)
{
_storage.SetValueAt(i, j, array[i, j]);
_storage.At(i, j, array[i, j]);
}
}
}
@ -193,7 +193,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
{
for (var j = 0; j < columns; j++)
{
_storage.SetValueAt(i, j, matrix.At(i, j));
_storage.At(i, j, matrix.At(i, j));
}
}
}
@ -447,7 +447,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
if ((columnIndices[j] >= columnIndex) && (columnIndices[j] < columnIndex + columnCount))
{
var column = columnIndices[j] - columnIndex;
result._storage.SetValueAt(row, column, values[j]);
result._storage.At(row, column, values[j]);
}
}
}
@ -616,6 +616,24 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return ret;
}
/// <summary>
/// Gets or sets the value at the given row and column, with range checking.
/// </summary>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <value>The value to get or set.</value>
/// <remarks>This method is ranged checked. <see cref="At(int,int)"/> and <see cref="At(int,int,float)"/>
/// to get and set values without range checking.</remarks>
public override float this[int row, int column]
{
get { return _storage[row, column]; }
set { _storage[row, column] = value; }
}
/// <summary>
/// Retrieves the requested element without range checking.
/// </summary>
@ -630,7 +648,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// </returns>
public override float At(int row, int column)
{
return _storage.GetValueAt(row, column);
return _storage.At(row, column);
}
/// <summary>
@ -647,7 +665,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// </param>
public override void At(int row, int column, float value)
{
_storage.SetValueAt(row, column, value);
_storage.At(row, column, value);
}
/// <summary>
@ -759,7 +777,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
for (var j = startIndex; j < endIndex; j++)
{
retStorage.SetValueAt(columnIndices[j], i, values[j]);
retStorage.At(columnIndices[j], i, values[j]);
}
}
@ -1351,7 +1369,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
}
resultSparse.Storage.SetValueAt(i, j, sum + result.At(i, j));
resultSparse.Storage.At(i, j, sum + result.At(i, j));
}
}
}

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

@ -29,10 +29,65 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
Data = data;
}
/// <summary>
/// Gets or sets the value at the given row and column, with range checking.
/// </summary>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <value>The value to get or set.</value>
/// <remarks>This method is ranged checked. <see cref="At(int,int)"/> and <see cref="At(int,int,T)"/>
/// to get and set values without range checking.</remarks>
public T this[int row, int column]
{
get { return Data[(column*RowCount) + row]; }
set { Data[(column*RowCount) + row] = value; }
get
{
if (row < 0 || row >= RowCount)
{
throw new ArgumentOutOfRangeException("row");
}
if (column < 0 || column >= ColumnCount)
{
throw new ArgumentOutOfRangeException("column");
}
return At(row, column);
}
set
{
if (row < 0 || row >= RowCount)
{
throw new ArgumentOutOfRangeException("row");
}
if (column < 0 || column >= ColumnCount)
{
throw new ArgumentOutOfRangeException("column");
}
At(row, column, value);
}
}
/// <summary>
/// Retrieves the requested element without range checking.
/// </summary>
public T At(int row, int column)
{
return Data[(column * RowCount) + row];
}
/// <summary>
/// Sets the element without range checking.
/// </summary>
public void At(int row, int column, T value)
{
Data[(column * RowCount) + row] = value;
}
public void Clear()

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

@ -48,16 +48,49 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
ValueCount = 0;
}
/// <summary>
/// Gets or sets the value at the given row and column, with range checking.
/// </summary>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <value>The value to get or set.</value>
/// <remarks>This method is ranged checked. <see cref="At(int,int)"/> and <see cref="At(int,int,T)"/>
/// to get and set values without range checking.</remarks>
public T this[int row, int column]
{
get { return GetValueAt(row, column); }
set { SetValueAt(row, column, value); }
}
get
{
if (row < 0 || row >= RowCount)
{
throw new ArgumentOutOfRangeException("row");
}
public void Clear()
{
ValueCount = 0;
Array.Clear(RowPointers, 0, RowPointers.Length);
if (column < 0 || column >= ColumnCount)
{
throw new ArgumentOutOfRangeException("column");
}
return At(row, column);
}
set
{
if (row < 0 || row >= RowCount)
{
throw new ArgumentOutOfRangeException("row");
}
if (column < 0 || column >= ColumnCount)
{
throw new ArgumentOutOfRangeException("column");
}
At(row, column, value);
}
}
/// <summary>
@ -72,20 +105,21 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
/// <returns>
/// The requested element.
/// </returns>
public T GetValueAt(int row, int column)
/// <remarks>Not range-checked.</remarks>
public T At(int row, int column)
{
var index = FindItem(row, column);
return index >= 0 ? Values[index] : _zero;
}
/// <summary>
/// Created this method because we cannot call "virtual At" in constructor of the class, but we need to do it
/// Sets the element without range checking.
/// </summary>
/// <param name="row"> The row of the element. </param>
/// <param name="column"> The column of the element. </param>
/// <param name="value"> The value to set the element to. </param>
/// <remarks>WARNING: This method is not thread safe. Use "lock" with it and be sure to avoid deadlocks</remarks>
public void SetValueAt(int row, int column, T value)
/// <remarks>WARNING: This method is not thread safe. Use "lock" with it and be sure to avoid deadlocks.</remarks>
public void At(int row, int column, T value)
{
var index = FindItem(row, column);
if (index >= 0)
@ -151,6 +185,12 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
}
}
public void Clear()
{
ValueCount = 0;
Array.Clear(RowPointers, 0, RowPointers.Length);
}
/// <summary>
/// Delete value from internal storage
/// </summary>

59
src/Numerics/LinearAlgebra/Storage/SparseDiagonalMatrixStorage.cs

@ -32,22 +32,71 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
Data = data;
}
/// <summary>
/// Gets or sets the value at the given row and column, with range checking.
/// </summary>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <value>The value to get or set.</value>
/// <remarks>This method is ranged checked. <see cref="At(int,int)"/> and <see cref="At(int,int,T)"/>
/// to get and set values without range checking.</remarks>
public T this[int row, int column]
{
get
{
return row == column ? Data[row] : _zero;
if (row < 0 || row >= RowCount)
{
throw new ArgumentOutOfRangeException("row");
}
if (column < 0 || column >= ColumnCount)
{
throw new ArgumentOutOfRangeException("column");
}
return At(row, column);
}
set
{
if (row == column)
if (row < 0 || row >= RowCount)
{
Data[row] = value;
throw new ArgumentOutOfRangeException("row");
}
else if (!_zero.Equals(value))
if (column < 0 || column >= ColumnCount)
{
throw new IndexOutOfRangeException("Cannot set an off-diagonal element in a diagonal matrix.");
throw new ArgumentOutOfRangeException("column");
}
At(row, column, value);
}
}
/// <summary>
/// Retrieves the requested element without range checking.
/// </summary>
public T At(int row, int column)
{
return row == column ? Data[row] : _zero;
}
/// <summary>
/// Sets the element without range checking.
/// </summary>
public void At(int row, int column, T value)
{
if (row == column)
{
Data[row] = value;
}
else if (!_zero.Equals(value))
{
throw new IndexOutOfRangeException("Cannot set an off-diagonal element in a diagonal matrix.");
}
}

Loading…
Cancel
Save