Browse Source

LA: CoerceZero for matrices and vectors (via MapInplace)

provider
Christoph Ruegg 12 years ago
parent
commit
848874e1b7
  1. 9
      src/Numerics/LinearAlgebra/Complex/Matrix.cs
  2. 8
      src/Numerics/LinearAlgebra/Complex/Vector.cs
  3. 8
      src/Numerics/LinearAlgebra/Complex32/Matrix.cs
  4. 8
      src/Numerics/LinearAlgebra/Complex32/Vector.cs
  5. 8
      src/Numerics/LinearAlgebra/Double/Matrix.cs
  6. 8
      src/Numerics/LinearAlgebra/Double/Vector.cs
  7. 13
      src/Numerics/LinearAlgebra/Matrix.cs
  8. 8
      src/Numerics/LinearAlgebra/Single/Matrix.cs
  9. 8
      src/Numerics/LinearAlgebra/Single/Vector.cs
  10. 13
      src/Numerics/LinearAlgebra/Vector.cs

9
src/Numerics/LinearAlgebra/Complex/Matrix.cs

@ -41,7 +41,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
using Complex = Numerics.Complex;
#else
using Complex = System.Numerics.Complex;
#endif
/// <summary>
@ -58,6 +57,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
{
}
/// <summary>
/// Set all values whose absolute value is smaller than the threshold to zero.
/// </summary>
public override void CoerceZero(double threshold)
{
MapInplace(x => x.Magnitude < threshold ? Complex.Zero : x, Zeros.AllowSkip);
}
/// <summary>Calculates the induced L1 norm of this matrix.</summary>
/// <returns>The maximum absolute column sum of the matrix.</returns>
public override double L1Norm()

8
src/Numerics/LinearAlgebra/Complex/Vector.cs

@ -55,6 +55,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
{
}
/// <summary>
/// Set all values whose absolute value is smaller than the threshold to zero.
/// </summary>
public override void CoerceZero(double threshold)
{
MapInplace(x => x.Magnitude < threshold ? Complex.Zero : x, Zeros.AllowSkip);
}
/// <summary>
/// Adds a scalar to each element of the vector and stores the result in the result vector.
/// </summary>

8
src/Numerics/LinearAlgebra/Complex32/Matrix.cs

@ -52,6 +52,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
{
}
/// <summary>
/// Set all values whose absolute value is smaller than the threshold to zero.
/// </summary>
public override void CoerceZero(double threshold)
{
MapInplace(x => x.Magnitude < threshold ? Complex32.Zero : x, Zeros.AllowSkip);
}
/// <summary>Calculates the induced L1 norm of this matrix.</summary>
/// <returns>The maximum absolute column sum of the matrix.</returns>
public override double L1Norm()

8
src/Numerics/LinearAlgebra/Complex32/Vector.cs

@ -50,6 +50,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
{
}
/// <summary>
/// Set all values whose absolute value is smaller than the threshold to zero.
/// </summary>
public override void CoerceZero(double threshold)
{
MapInplace(x => x.Magnitude < threshold ? Complex32.Zero : x, Zeros.AllowSkip);
}
/// <summary>
/// Adds a scalar to each element of the vector and stores the result in the result vector.
/// </summary>

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

@ -50,6 +50,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double
{
}
/// <summary>
/// Set all values whose absolute value is smaller than the threshold to zero.
/// </summary>
public override void CoerceZero(double threshold)
{
MapInplace(x => Math.Abs(x) < threshold ? 0d : x, Zeros.AllowSkip);
}
/// <summary>Calculates the induced L1 norm of this matrix.</summary>
/// <returns>The maximum absolute column sum of the matrix.</returns>
public override double L1Norm()

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

@ -48,6 +48,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double
{
}
/// <summary>
/// Set all values whose absolute value is smaller than the threshold to zero.
/// </summary>
public override void CoerceZero(double threshold)
{
MapInplace(x => Math.Abs(x) < threshold ? 0d : x, Zeros.AllowSkip);
}
/// <summary>
/// Adds a scalar to each element of the vector and stores the result in the result vector.
/// </summary>

13
src/Numerics/LinearAlgebra/Matrix.cs

@ -240,6 +240,19 @@ namespace MathNet.Numerics.LinearAlgebra
Storage.Clear(rowIndex, rowCount, columnIndex, columnCount);
}
/// <summary>
/// Set all values whose absolute value is smaller than the threshold to zero, in-place.
/// </summary>
public abstract void CoerceZero(double threshold);
/// <summary>
/// Set all values that meet the predicate to zero, in-place.
/// </summary>
public void CoerceZero(Func<T, bool> zeroPredicate)
{
MapInplace(x => zeroPredicate(x) ? Zero : x, Zeros.AllowSkip);
}
/// <summary>
/// Creates a clone of this instance.
/// </summary>

8
src/Numerics/LinearAlgebra/Single/Matrix.cs

@ -50,6 +50,14 @@ namespace MathNet.Numerics.LinearAlgebra.Single
{
}
/// <summary>
/// Set all values whose absolute value is smaller than the threshold to zero.
/// </summary>
public override void CoerceZero(double threshold)
{
MapInplace(x => Math.Abs(x) < threshold ? 0f : x, Zeros.AllowSkip);
}
/// <summary>Calculates the induced L1 norm of this matrix.</summary>
/// <returns>The maximum absolute column sum of the matrix.</returns>
public override double L1Norm()

8
src/Numerics/LinearAlgebra/Single/Vector.cs

@ -48,6 +48,14 @@ namespace MathNet.Numerics.LinearAlgebra.Single
{
}
/// <summary>
/// Set all values whose absolute value is smaller than the threshold to zero.
/// </summary>
public override void CoerceZero(double threshold)
{
MapInplace(x => Math.Abs(x) < threshold ? 0f : x, Zeros.AllowSkip);
}
/// <summary>
/// Adds a scalar to each element of the vector and stores the result in the result vector.
/// </summary>

13
src/Numerics/LinearAlgebra/Vector.cs

@ -132,6 +132,19 @@ namespace MathNet.Numerics.LinearAlgebra
Storage.Clear(index, count);
}
/// <summary>
/// Set all values whose absolute value is smaller than the threshold to zero, in-place.
/// </summary>
public abstract void CoerceZero(double threshold);
/// <summary>
/// Set all values that meet the predicate to zero, in-place.
/// </summary>
public void CoerceZero(Func<T, bool> zeroPredicate)
{
MapInplace(x => zeroPredicate(x) ? Zero : x, Zeros.AllowSkip);
}
/// <summary>
/// Returns a deep-copy clone of the vector.
/// </summary>

Loading…
Cancel
Save