Browse Source

LA Storage: drop redundant accessors and overrides

pull/47/head
Christoph Ruegg 14 years ago
parent
commit
b3dd68f358
  1. 60
      src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
  2. 65
      src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
  3. 60
      src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
  4. 60
      src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
  5. 65
      src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
  6. 60
      src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
  7. 60
      src/Numerics/LinearAlgebra/Double/DenseMatrix.cs
  8. 65
      src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
  9. 60
      src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
  10. 76
      src/Numerics/LinearAlgebra/Generic/Matrix.cs
  11. 60
      src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
  12. 65
      src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
  13. 60
      src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
  14. 3
      src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs
  15. 35
      src/Numerics/LinearAlgebra/Storage/MatrixStorage.Validation.cs
  16. 35
      src/Numerics/LinearAlgebra/Storage/MatrixStorage.cs
  17. 6
      src/Numerics/LinearAlgebra/Storage/SparseDiagonalMatrixStorage.cs
  18. 2
      src/Numerics/Numerics.csproj
  19. 6
      src/Portable/Portable.csproj
  20. 22
      src/UnitTests/LinearAlgebraTests/Complex/UserDefinedMatrix.cs
  21. 22
      src/UnitTests/LinearAlgebraTests/Complex32/UserDefinedMatrix.cs
  22. 22
      src/UnitTests/LinearAlgebraTests/Double/UserDefinedMatrix.cs
  23. 22
      src/UnitTests/LinearAlgebraTests/Single/UserDefinedMatrix.cs

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

@ -264,66 +264,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
base.SetSubMatrix(rowIndex, rowCount, columnIndex, columnCount, subMatrix);
}
/// <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>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <returns>
/// The requested element.
/// </returns>
public override Complex At(int row, int column)
{
return _storage.At(row, column);
}
/// <summary>
/// Sets the value of the given element.
/// </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>
public override void At(int row, int column, Complex value)
{
_storage.At(row, column, value);
}
/// <summary>
/// Sets all values to zero.
/// </summary>
public override void Clear()
{
_storage.Clear();
}
/// <summary>
/// Returns the transpose of this matrix.
/// </summary>

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

@ -149,63 +149,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
}
/// <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>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <returns>
/// The requested element.
/// </returns>
/// <exception cref="IndexOutOfRangeException">Depending on the implementation, an <see cref="IndexOutOfRangeException"/>
/// 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.At(row, column);
}
/// <summary>
/// Sets the value of the given element.
/// </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>
/// <exception cref="IndexOutOfRangeException">When trying to set an off diagonal element.</exception>
/// <exception cref="IndexOutOfRangeException">Depending on the implementation, an <see cref="IndexOutOfRangeException"/>
/// 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.At(row, column, value);
}
/// <summary>
/// Creates a <c>DiagonalMatrix</c> for the given number of rows and columns.
/// </summary>
@ -235,14 +178,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return new SparseVector(size);
}
/// <summary>
/// Sets all values to zero.
/// </summary>
public override void Clear()
{
_storage.Clear();
}
/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
/// </summary>

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

@ -613,66 +613,6 @@ 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>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <returns>
/// The requested element.
/// </returns>
public override Complex At(int row, int column)
{
return _storage.At(row, column);
}
/// <summary>
/// Sets the value of the given element.
/// </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>
public override void At(int row, int column, Complex value)
{
_storage.At(row, column, value);
}
/// <summary>
/// Sets all values to zero.
/// </summary>
public override void Clear()
{
_storage.Clear();
}
/// <summary>
/// Copies the elements of this matrix to the given matrix.
/// </summary>

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

@ -264,66 +264,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
base.SetSubMatrix(rowIndex, rowCount, columnIndex, columnCount, subMatrix);
}
/// <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>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <returns>
/// The requested element.
/// </returns>
public override Complex32 At(int row, int column)
{
return _storage.At(row, column);
}
/// <summary>
/// Sets the value of the given element.
/// </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>
public override void At(int row, int column, Complex32 value)
{
_storage.At(row, column, value);
}
/// <summary>
/// Sets all values to zero.
/// </summary>
public override void Clear()
{
_storage.Clear();
}
/// <summary>
/// Returns the transpose of this matrix.
/// </summary>

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

@ -149,63 +149,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
}
/// <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>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <returns>
/// The requested element.
/// </returns>
/// <exception cref="IndexOutOfRangeException">Depending on the implementation, an <see cref="IndexOutOfRangeException"/>
/// 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.At(row, column);
}
/// <summary>
/// Sets the value of the given element.
/// </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>
/// <exception cref="IndexOutOfRangeException">When trying to set an off diagonal element.</exception>
/// <exception cref="IndexOutOfRangeException">Depending on the implementation, an <see cref="IndexOutOfRangeException"/>
/// 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.At(row, column, value);
}
/// <summary>
/// Creates a <c>DiagonalMatrix</c> for the given number of rows and columns.
/// </summary>
@ -235,14 +178,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return new SparseVector(size);
}
/// <summary>
/// Sets all values to zero.
/// </summary>
public override void Clear()
{
_storage.Clear();
}
/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
/// </summary>

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

@ -613,66 +613,6 @@ 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>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <returns>
/// The requested element.
/// </returns>
public override Complex32 At(int row, int column)
{
return _storage.At(row, column);
}
/// <summary>
/// Sets the value of the given element.
/// </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>
public override void At(int row, int column, Complex32 value)
{
_storage.At(row, column, value);
}
/// <summary>
/// Sets all values to zero.
/// </summary>
public override void Clear()
{
_storage.Clear();
}
/// <summary>
/// Copies the elements of this matrix to the given matrix.
/// </summary>

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

@ -264,66 +264,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
base.SetSubMatrix(rowIndex, rowCount, columnIndex, columnCount, subMatrix);
}
/// <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>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <returns>
/// The requested element.
/// </returns>
public override double At(int row, int column)
{
return _storage.At(row, column);
}
/// <summary>
/// Sets the value of the given element.
/// </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>
public override void At(int row, int column, double value)
{
_storage.At(row, column, value);
}
/// <summary>
/// Sets all values to zero.
/// </summary>
public override void Clear()
{
_storage.Clear();
}
/// <summary>
/// Returns the transpose of this matrix.
/// </summary>

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

@ -148,63 +148,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
}
/// <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>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <returns>
/// The requested element.
/// </returns>
/// <exception cref="IndexOutOfRangeException">Depending on the implementation, an <see cref="IndexOutOfRangeException"/>
/// 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.At(row, column);
}
/// <summary>
/// Sets the value of the given element.
/// </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>
/// <exception cref="IndexOutOfRangeException">When trying to set an off diagonal element.</exception>
/// <exception cref="IndexOutOfRangeException">Depending on the implementation, an <see cref="IndexOutOfRangeException"/>
/// 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.At(row, column, value);
}
/// <summary>
/// Creates a <c>DiagonalMatrix</c> for the given number of rows and columns.
/// </summary>
@ -234,14 +177,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return new SparseVector(size);
}
/// <summary>
/// Sets all values to zero.
/// </summary>
public override void Clear()
{
_storage.Clear();
}
/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
/// </summary>

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

@ -612,66 +612,6 @@ 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>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <returns>
/// The requested element.
/// </returns>
public override double At(int row, int column)
{
return _storage.At(row, column);
}
/// <summary>
/// Sets the value of the given element.
/// </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>
public override void At(int row, int column, double value)
{
_storage.At(row, column, value);
}
/// <summary>
/// Sets all values to zero.
/// </summary>
public override void Clear()
{
_storage.Clear();
}
/// <summary>
/// Copies the elements of this matrix to the given matrix.
/// </summary>

76
src/Numerics/LinearAlgebra/Generic/Matrix.cs

@ -24,8 +24,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using MathNet.Numerics.LinearAlgebra.Storage;
namespace MathNet.Numerics.LinearAlgebra.Generic
{
using System;
@ -35,6 +33,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
using Factorization;
using Numerics;
using Properties;
using Storage;
using Threading;
/// <summary>
@ -154,7 +153,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
}
/// <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.
@ -165,19 +164,10 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <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 virtual T this[int row, int column]
public T this[int row, int column]
{
get
{
RangeCheck(row, column);
return At(row, column);
}
set
{
RangeCheck(row, column);
At(row, column, value);
}
get { return Storage[row, column]; }
set { Storage[row, column] = value; }
}
/// <summary>
@ -192,10 +182,13 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <returns>
/// The requested element.
/// </returns>
public abstract T At(int row, int column);
public T At(int row, int column)
{
return Storage.At(row, column);
}
/// <summary>
/// Sets the value of the given element.
/// Sets the value of the given element without range checking.
/// </summary>
/// <param name="row">
/// The row of the element.
@ -206,7 +199,18 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <param name="value">
/// The value to set the element to.
/// </param>
public abstract void At(int row, int column, T value);
public void At(int row, int column, T value)
{
Storage.At(row, column, value);
}
/// <summary>
/// Sets all values to zero.
/// </summary>
public void Clear()
{
Storage.Clear();
}
/// <summary>
/// Creates a clone of this instance.
@ -1412,28 +1416,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
#endregion
/// <summary>
/// Checks the range of the requested row, column.
/// </summary>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
private void RangeCheck(int row, int column)
{
if (row < 0 || row >= RowCount)
{
throw new ArgumentOutOfRangeException("row");
}
if (column < 0 || column >= ColumnCount)
{
throw new ArgumentOutOfRangeException("column");
}
}
#region System.Object overrides
/// <summary>
@ -1475,20 +1457,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
#endregion
/// <summary>
/// Sets all values to zero.
/// </summary>
public virtual void Clear()
{
for (var i = 0; i < RowCount; i++)
{
for (var j = 0; j < ColumnCount; j++)
{
At(i, j, default(T));
}
}
}
/// <summary>
/// Returns the transpose of this matrix.
/// </summary>

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

@ -264,66 +264,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
base.SetSubMatrix(rowIndex, rowCount, columnIndex, columnCount, subMatrix);
}
/// <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>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <returns>
/// The requested element.
/// </returns>
public override float At(int row, int column)
{
return _storage.At(row, column);
}
/// <summary>
/// Sets the value of the given element.
/// </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>
public override void At(int row, int column, float value)
{
_storage.At(row, column, value);
}
/// <summary>
/// Sets all values to zero.
/// </summary>
public override void Clear()
{
_storage.Clear();
}
/// <summary>
/// Returns the transpose of this matrix.
/// </summary>

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

@ -148,63 +148,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
}
/// <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>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <returns>
/// The requested element.
/// </returns>
/// <exception cref="IndexOutOfRangeException">Depending on the implementation, an <see cref="IndexOutOfRangeException"/>
/// 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.At(row, column);
}
/// <summary>
/// Sets the value of the given element.
/// </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>
/// <exception cref="IndexOutOfRangeException">When trying to set an off diagonal element.</exception>
/// <exception cref="IndexOutOfRangeException">Depending on the implementation, an <see cref="IndexOutOfRangeException"/>
/// 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.At(row, column, value);
}
/// <summary>
/// Creates a <c>DiagonalMatrix</c> for the given number of rows and columns.
/// </summary>
@ -234,14 +177,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return new SparseVector(size);
}
/// <summary>
/// Sets all values to zero.
/// </summary>
public override void Clear()
{
_storage.Clear();
}
/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
/// </summary>

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

@ -612,66 +612,6 @@ 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>
/// <param name="row">
/// The row of the element.
/// </param>
/// <param name="column">
/// The column of the element.
/// </param>
/// <returns>
/// The requested element.
/// </returns>
public override float At(int row, int column)
{
return _storage.At(row, column);
}
/// <summary>
/// Sets the value of the given element.
/// </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>
public override void At(int row, int column, float value)
{
_storage.At(row, column, value);
}
/// <summary>
/// Sets all values to zero.
/// </summary>
public override void Clear()
{
_storage.Clear();
}
/// <summary>
/// Copies the elements of this matrix to the given matrix.
/// </summary>

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

@ -115,8 +115,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
throw new NotSupportedException();
}
ArgumentValidation.CopySubMatrixTo(RowCount, ColumnCount,
target.RowCount, target.ColumnCount,
ValidateSubMatrixRange(target,
sourceRowIndex, targetRowIndex, rowCount,
sourceColumnIndex, targetColumnIndex, columnCount);

35
src/Numerics/LinearAlgebra/Storage/ArgumentValidation.cs → src/Numerics/LinearAlgebra/Storage/MatrixStorage.Validation.cs

@ -4,11 +4,22 @@ using MathNet.Numerics.Properties;
namespace MathNet.Numerics.LinearAlgebra.Storage
{
// ReSharper disable UnusedParameter.Global
internal static class ArgumentValidation
public partial class MatrixStorage<T>
{
public static void CopySubMatrixTo(
int sourceRowCount, int sourceColumnCount,
int targetRowCount, int targetColumnCount,
protected void ValidateRange(int row, int column)
{
if (row < 0 || row >= RowCount)
{
throw new ArgumentOutOfRangeException("row");
}
if (column < 0 || column >= ColumnCount)
{
throw new ArgumentOutOfRangeException("column");
}
}
protected void ValidateSubMatrixRange(MatrixStorage<T> target,
int sourceRowIndex, int targetRowIndex, int rowCount,
int sourceColumnIndex, int targetColumnIndex, int columnCount)
{
@ -24,12 +35,12 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
// Verify Source
if (sourceRowIndex >= sourceRowCount || sourceRowIndex < 0)
if (sourceRowIndex >= RowCount || sourceRowIndex < 0)
{
throw new ArgumentOutOfRangeException("sourceRowIndex");
}
if (sourceColumnIndex >= sourceColumnCount || sourceColumnIndex < 0)
if (sourceColumnIndex >= ColumnCount || sourceColumnIndex < 0)
{
throw new ArgumentOutOfRangeException("sourceColumnIndex");
}
@ -37,24 +48,24 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
var sourceRowMax = sourceRowIndex + rowCount;
var sourceColumnMax = sourceColumnIndex + columnCount;
if (sourceRowMax > sourceRowCount)
if (sourceRowMax > RowCount)
{
throw new ArgumentOutOfRangeException("rowCount");
}
if (sourceColumnMax > sourceColumnCount)
if (sourceColumnMax > ColumnCount)
{
throw new ArgumentOutOfRangeException("columnCount");
}
// Verify Target
if (targetRowIndex >= targetRowCount || targetRowIndex < 0)
if (targetRowIndex >= target.RowCount || targetRowIndex < 0)
{
throw new ArgumentOutOfRangeException("targetRowIndex");
}
if (targetColumnIndex >= targetColumnCount || targetColumnIndex < 0)
if (targetColumnIndex >= target.ColumnCount || targetColumnIndex < 0)
{
throw new ArgumentOutOfRangeException("targetColumnIndex");
}
@ -62,12 +73,12 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
var targetRowMax = targetRowIndex + rowCount;
var targetColumnMax = targetColumnIndex + columnCount;
if (targetRowMax > targetRowCount)
if (targetRowMax > target.RowCount)
{
throw new ArgumentOutOfRangeException("rowCount");
}
if (targetColumnMax > targetColumnCount)
if (targetColumnMax > target.ColumnCount)
{
throw new ArgumentOutOfRangeException("columnCount");
}

35
src/Numerics/LinearAlgebra/Storage/MatrixStorage.cs

@ -3,7 +3,7 @@ using MathNet.Numerics.Properties;
namespace MathNet.Numerics.LinearAlgebra.Storage
{
public abstract class MatrixStorage<T> where T : struct, IEquatable<T>, IFormattable
public abstract partial class MatrixStorage<T> where T : struct, IEquatable<T>, IFormattable
{
// [ruegg] public fields are OK here
@ -42,31 +42,13 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
{
get
{
if (row < 0 || row >= RowCount)
{
throw new ArgumentOutOfRangeException("row");
}
if (column < 0 || column >= ColumnCount)
{
throw new ArgumentOutOfRangeException("column");
}
ValidateRange(row, column);
return At(row, column);
}
set
{
if (row < 0 || row >= RowCount)
{
throw new ArgumentOutOfRangeException("row");
}
if (column < 0 || column >= ColumnCount)
{
throw new ArgumentOutOfRangeException("column");
}
ValidateRange(row, column);
At(row, column, value);
}
}
@ -95,6 +77,15 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
/// <remarks>WARNING: This method is not thread safe. Use "lock" with it and be sure to avoid deadlocks.</remarks>
public abstract void At(int row, int column, T value);
public abstract void Clear();
public virtual void Clear()
{
for (var i = 0; i < RowCount; i++)
{
for (var j = 0; j < ColumnCount; j++)
{
At(i, j, default(T));
}
}
}
}
}

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

@ -180,8 +180,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
throw new ArgumentNullException("target");
}
ArgumentValidation.CopySubMatrixTo(RowCount, ColumnCount,
target.RowCount, target.ColumnCount,
ValidateSubMatrixRange(target,
sourceRowIndex, targetRowIndex, rowCount,
sourceColumnIndex, targetColumnIndex, columnCount);
@ -241,8 +240,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
throw new ArgumentNullException("target");
}
ArgumentValidation.CopySubMatrixTo(RowCount, ColumnCount,
target.RowCount, target.ColumnCount,
ValidateSubMatrixRange(target,
sourceRowIndex, targetRowIndex, rowCount,
sourceColumnIndex, targetColumnIndex, columnCount);

2
src/Numerics/Numerics.csproj

@ -122,7 +122,7 @@
<Compile Include="Distributions\Multivariate\InverseWishart.cs" />
<Compile Include="Distributions\Multivariate\MatrixNormal.cs" />
<Compile Include="Distributions\Multivariate\Wishart.cs" />
<Compile Include="LinearAlgebra\Storage\ArgumentValidation.cs" />
<Compile Include="LinearAlgebra\Storage\MatrixStorage.Validation.cs" />
<Compile Include="LinearAlgebra\Complex32\ExtensionMethods.cs" />
<Compile Include="LinearAlgebra\Complex32\Factorization\Cholesky.cs" />
<Compile Include="LinearAlgebra\Complex32\DenseMatrix.cs" />

6
src/Portable/Portable.csproj

@ -888,15 +888,15 @@
<Compile Include="..\Numerics\LinearAlgebra\Single\Vector.cs">
<Link>LinearAlgebra\Single\Vector.cs</Link>
</Compile>
<Compile Include="..\Numerics\LinearAlgebra\Storage\ArgumentValidation.cs">
<Link>LinearAlgebra\Storage\ArgumentValidation.cs</Link>
</Compile>
<Compile Include="..\Numerics\LinearAlgebra\Storage\DenseColumnMajorMatrixStorage.cs">
<Link>LinearAlgebra\Storage\DenseColumnMajorMatrixStorage.cs</Link>
</Compile>
<Compile Include="..\Numerics\LinearAlgebra\Storage\MatrixStorage.cs">
<Link>LinearAlgebra\Storage\MatrixStorage.cs</Link>
</Compile>
<Compile Include="..\Numerics\LinearAlgebra\Storage\MatrixStorage.Validation.cs">
<Link>LinearAlgebra\Storage\MatrixStorage.Validation.cs</Link>
</Compile>
<Compile Include="..\Numerics\LinearAlgebra\Storage\SparseCompressedRowMatrixStorage.cs">
<Link>LinearAlgebra\Storage\SparseCompressedRowMatrixStorage.cs</Link>
</Compile>

22
src/UnitTests/LinearAlgebraTests/Complex/UserDefinedMatrix.cs

@ -108,28 +108,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
{
}
/// <summary>
/// Retrieves the requested element without range checking.
/// </summary>
/// <param name="row">The row of the element.</param>
/// <param name="column">The column of the element.</param>
/// <returns>The requested element. </returns>
public override Complex At(int row, int column)
{
return _data[row, column];
}
/// <summary>
/// Sets the value of the given element.
/// </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>
public override void At(int row, int column, Complex value)
{
_data[row, column] = value;
}
/// <summary>
/// Creates a matrix for the given number of rows and columns.
/// </summary>

22
src/UnitTests/LinearAlgebraTests/Complex32/UserDefinedMatrix.cs

@ -108,28 +108,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
{
}
/// <summary>
/// Retrieves the requested element without range checking.
/// </summary>
/// <param name="row">The row of the element.</param>
/// <param name="column">The column of the element.</param>
/// <returns>The requested element. </returns>
public override Complex32 At(int row, int column)
{
return _data[row, column];
}
/// <summary>
/// Sets the value of the given element.
/// </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>
public override void At(int row, int column, Complex32 value)
{
_data[row, column] = value;
}
/// <summary>
/// Creates a matrix for the given number of rows and columns.
/// </summary>

22
src/UnitTests/LinearAlgebraTests/Double/UserDefinedMatrix.cs

@ -107,28 +107,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
{
}
/// <summary>
/// Retrieves the requested element without range checking.
/// </summary>
/// <param name="row">The row of the element.</param>
/// <param name="column">The column of the element.</param>
/// <returns>The requested element. </returns>
public override double At(int row, int column)
{
return _data[row, column];
}
/// <summary>
/// Sets the value of the given element.
/// </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>
public override void At(int row, int column, double value)
{
_data[row, column] = value;
}
/// <summary>
/// Creates a matrix for the given number of rows and columns.
/// </summary>

22
src/UnitTests/LinearAlgebraTests/Single/UserDefinedMatrix.cs

@ -107,28 +107,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
{
}
/// <summary>
/// Retrieves the requested element without range checking.
/// </summary>
/// <param name="row">The row of the element.</param>
/// <param name="column">The column of the element.</param>
/// <returns>The requested element. </returns>
public override float At(int row, int column)
{
return _data[row, column];
}
/// <summary>
/// Sets the value of the given element.
/// </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>
public override void At(int row, int column, float value)
{
_data[row, column] = value;
}
/// <summary>
/// Creates a matrix for the given number of rows and columns.
/// </summary>

Loading…
Cancel
Save