Browse Source

Added Matrix.Clear method.

la-knuth
Jurgen Van Gael 17 years ago
parent
commit
41ab904c7f
  1. 8
      src/Numerics/LinearAlgebra/Double/DenseMatrix.cs
  2. 14
      src/Numerics/LinearAlgebra/Double/Matrix.cs
  3. 14
      src/UnitTests/LinearAlgebraTests/Double/MatrixTests.cs

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

@ -182,6 +182,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double
Data[column * RowCount + row] = value; Data[column * RowCount + row] = value;
} }
/// <summary>
/// Sets all values to zero.
/// </summary>
public override void Clear()
{
Array.Clear(Data, 0, Data.Length);
}
#region Elementary operations #region Elementary operations
/// <summary> /// <summary>
/// Adds another matrix to this matrix. The result will be written into this matrix. /// Adds another matrix to this matrix. The result will be written into this matrix.

14
src/Numerics/LinearAlgebra/Double/Matrix.cs

@ -412,6 +412,20 @@ namespace MathNet.Numerics.LinearAlgebra.Double
} }
#endregion #endregion
/// <summary>
/// Sets all values to zero.
/// </summary>
public virtual void Clear()
{
for (int i = 0; i < RowCount; i++)
{
for (int j = 0; j < ColumnCount; j++)
{
At(i, j, 0);
}
}
}
#region Elementary operations #region Elementary operations
/// <summary> /// <summary>

14
src/UnitTests/LinearAlgebraTests/Double/MatrixTests.cs

@ -162,6 +162,20 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
{ {
} }
[Test]
public void CanClearMatrix()
{
Matrix matrix = (Matrix) testMatrices["Singular3x3"].Clone();
matrix.Clear();
for (int i = 0; i < matrix.RowCount; i++)
{
for (int j = 0; j < matrix.ColumnCount; j++)
{
Assert.AreEqual(0, matrix[i, j]);
}
}
}
#region Elementary operations #region Elementary operations
[Test] [Test]
[Row("Singular3x3", "Square3x3")] [Row("Singular3x3", "Square3x3")]

Loading…
Cancel
Save