Browse Source

LA: Modulus between matrix and scalar; pointwise modulus; improved naming

optimization-1
Christoph Ruegg 13 years ago
parent
commit
1e9ca30c74
  1. 16
      src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
  2. 8
      src/Numerics/LinearAlgebra/Complex/DenseVector.cs
  3. 42
      src/Numerics/LinearAlgebra/Complex/Matrix.cs
  4. 6
      src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
  5. 8
      src/Numerics/LinearAlgebra/Complex/SparseVector.cs
  6. 28
      src/Numerics/LinearAlgebra/Complex/Vector.cs
  7. 16
      src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
  8. 8
      src/Numerics/LinearAlgebra/Complex32/DenseVector.cs
  9. 42
      src/Numerics/LinearAlgebra/Complex32/Matrix.cs
  10. 6
      src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
  11. 8
      src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
  12. 28
      src/Numerics/LinearAlgebra/Complex32/Vector.cs
  13. 40
      src/Numerics/LinearAlgebra/Double/DenseMatrix.cs
  14. 8
      src/Numerics/LinearAlgebra/Double/DenseVector.cs
  15. 66
      src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
  16. 66
      src/Numerics/LinearAlgebra/Double/Matrix.cs
  17. 6
      src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
  18. 8
      src/Numerics/LinearAlgebra/Double/SparseVector.cs
  19. 52
      src/Numerics/LinearAlgebra/Double/Vector.cs
  20. 173
      src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs
  21. 91
      src/Numerics/LinearAlgebra/Generic/Matrix.Operators.cs
  22. 120
      src/Numerics/LinearAlgebra/Generic/Vector.Arithmetic.cs
  23. 98
      src/Numerics/LinearAlgebra/Generic/Vector.Operators.cs
  24. 40
      src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
  25. 8
      src/Numerics/LinearAlgebra/Single/DenseVector.cs
  26. 66
      src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
  27. 54
      src/Numerics/LinearAlgebra/Single/Matrix.cs
  28. 6
      src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
  29. 8
      src/Numerics/LinearAlgebra/Single/SparseVector.cs
  30. 32
      src/Numerics/LinearAlgebra/Single/Vector.cs

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

@ -549,18 +549,18 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// <summary>
/// Divides each element of the matrix by a scalar and places results into the result matrix.
/// </summary>
/// <param name="scalar">The scalar to divide the matrix with.</param>
/// <param name="divisor">The scalar to divide the matrix with.</param>
/// <param name="result">The matrix to store the result of the division.</param>
protected override void DoDivide(Complex scalar, Matrix<Complex> result)
protected override void DoDivide(Complex divisor, Matrix<Complex> result)
{
var denseResult = result as DenseMatrix;
if (denseResult == null)
{
base.DoDivide(scalar, result);
base.DoDivide(divisor, result);
}
else
{
Control.LinearAlgebraProvider.ScaleArray(1.0/scalar, _values, denseResult._values);
Control.LinearAlgebraProvider.ScaleArray(1.0/divisor, _values, denseResult._values);
}
}
@ -587,16 +587,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// <summary>
/// Pointwise divide this matrix by another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="other">The matrix to pointwise divide this one by.</param>
/// <param name="divisor">The matrix to pointwise divide this one by.</param>
/// <param name="result">The matrix to store the result of the pointwise division.</param>
protected override void DoPointwiseDivide(Matrix<Complex> other, Matrix<Complex> result)
protected override void DoPointwiseDivide(Matrix<Complex> divisor, Matrix<Complex> result)
{
var denseOther = other as DenseMatrix;
var denseOther = divisor as DenseMatrix;
var denseResult = result as DenseMatrix;
if (denseOther == null || denseResult == null)
{
base.DoPointwiseDivide(other, result);
base.DoPointwiseDivide(divisor, result);
}
else
{

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

@ -594,17 +594,17 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// <summary>
/// Pointwise divide this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise divide this one by.</param>
/// <param name="divisor">The vector to pointwise divide this one by.</param>
/// <param name="result">The vector to store the result of the pointwise division.</param>
/// <remarks></remarks>
protected override void DoPointwiseDivide(Vector<Complex> other, Vector<Complex> result)
protected override void DoPointwiseDivide(Vector<Complex> divisor, Vector<Complex> result)
{
var denseOther = other as DenseVector;
var denseOther = divisor as DenseVector;
var denseResult = result as DenseVector;
if (denseOther == null || denseResult == null)
{
base.DoPointwiseDivide(other, result);
base.DoPointwiseDivide(divisor, result);
}
else
{

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

@ -257,25 +257,25 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// <summary>
/// Divides each element of the matrix by a scalar and places results into the result matrix.
/// </summary>
/// <param name="scalar">The scalar to divide the matrix with.</param>
/// <param name="divisor">The scalar to divide the matrix with.</param>
/// <param name="result">The matrix to store the result of the division.</param>
protected override void DoDivide(Complex scalar, Matrix<Complex> result)
protected override void DoDivide(Complex divisor, Matrix<Complex> result)
{
DoMultiply(1.0 / scalar, result);
DoMultiply(1.0 / divisor, result);
}
/// <summary>
/// Divides a scalar by each element of the matrix and stores the result in the result matrix.
/// </summary>
/// <param name="scalar">The scalar to add.</param>
/// <param name="dividend">The scalar to add.</param>
/// <param name="result">The matrix to store the result of the division.</param>
protected override void DoDivideByThis(Complex scalar, Matrix<Complex> result)
protected override void DoDivideByThis(Complex dividend, Matrix<Complex> result)
{
for (var i = 0; i < RowCount; i++)
{
for (var j = 0; j < ColumnCount; j++)
{
result.At(i, j, scalar / At(i, j));
result.At(i, j, dividend / At(i, j));
}
}
}
@ -392,27 +392,47 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// <summary>
/// Pointwise divide this matrix by another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="other">The matrix to pointwise divide this one by.</param>
/// <param name="divisor">The matrix to pointwise divide this one by.</param>
/// <param name="result">The matrix to store the result of the pointwise division.</param>
protected override void DoPointwiseDivide(Matrix<Complex> other, Matrix<Complex> result)
protected override void DoPointwiseDivide(Matrix<Complex> divisor, Matrix<Complex> result)
{
for (var j = 0; j < ColumnCount; j++)
{
for (var i = 0; i < RowCount; i++)
{
result.At(i, j, At(i, j) / other.At(i, j));
result.At(i, j, At(i, j) / divisor.At(i, j));
}
}
}
/// <summary>
/// Pointwise modulus this matrix with another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="divisor">The pointwise denominator matrix to use</param>
/// <param name="result">The result of the modulus.</param>
protected override void DoPointwiseModulus(Matrix<Complex> divisor, Matrix<Complex> result)
{
throw new NotSupportedException();
}
/// <summary>
/// Computes the modulus for each element of the matrix.
/// </summary>
/// <param name="divisor">The divisor to use.</param>
/// <param name="divisor">The scalar denominator to use.</param>
/// <param name="result">Matrix to store the results in.</param>
protected override void DoModulus(Complex divisor, Matrix<Complex> result)
{
throw new NotImplementedException();
throw new NotSupportedException();
}
/// <summary>
/// Computes the modulus for each element of the matrix.
/// </summary>
/// <param name="dividend">The scalar numerator to use.</param>
/// <param name="result">Matrix to store the results in.</param>
protected override void DoModulusByThis(Complex dividend, Matrix<Complex> result)
{
throw new NotSupportedException();
}
/// <summary>

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

@ -1005,9 +1005,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// <summary>
/// Pointwise divide this matrix by another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="other">The matrix to pointwise divide this one by.</param>
/// <param name="divisor">The matrix to pointwise divide this one by.</param>
/// <param name="result">The matrix to store the result of the pointwise division.</param>
protected override void DoPointwiseDivide(Matrix<Complex> other, Matrix<Complex> result)
protected override void DoPointwiseDivide(Matrix<Complex> divisor, Matrix<Complex> result)
{
result.Clear();
@ -1026,7 +1026,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
{
if (!values[j].IsZero())
{
result.At(i, columnIndices[j], values[j]/other.At(i, columnIndices[j]));
result.At(i, columnIndices[j], values[j]/divisor.At(i, columnIndices[j]));
}
}
}

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

@ -756,11 +756,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// <summary>
/// Pointwise multiplies this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise multiply with this one.</param>
/// <param name="divisor">The vector to pointwise multiply with this one.</param>
/// <param name="result">The vector to store the result of the pointwise multiplication.</param>
protected override void DoPointwiseDivide(Vector<Complex> other, Vector<Complex> result)
protected override void DoPointwiseDivide(Vector<Complex> divisor, Vector<Complex> result)
{
if (ReferenceEquals(this, other))
if (ReferenceEquals(this, divisor))
{
for (var i = 0; i < _storage.ValueCount; i++)
{
@ -772,7 +772,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
for (var i = 0; i < _storage.ValueCount; i++)
{
var index = _storage.Indices[i];
result.At(index, _storage.Values[i] / other.At(index));
result.At(index, _storage.Values[i] / divisor.At(index));
}
}
}

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

@ -140,27 +140,27 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// <summary>
/// Divides each element of the vector by a scalar and stores the result in the result vector.
/// </summary>
/// <param name="scalar">
/// <param name="divisor">
/// The scalar to divide with.
/// </param>
/// <param name="result">
/// The vector to store the result of the division.
/// </param>
protected override void DoDivide(Complex scalar, Vector<Complex> result)
protected override void DoDivide(Complex divisor, Vector<Complex> result)
{
DoMultiply(1 / scalar, result);
DoMultiply(1 / divisor, result);
}
/// <summary>
/// Divides a scalar by each element of the vector and stores the result in the result vector.
/// </summary>
/// <param name="scalar">The scalar to divide.</param>
/// <param name="dividend">The scalar to divide.</param>
/// <param name="result">The vector to store the result of the division.</param>
protected override void DoDivideByThis(Complex scalar, Vector<Complex> result)
protected override void DoDivideByThis(Complex dividend, Vector<Complex> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, scalar / At(index));
result.At(index, dividend / At(index));
}
}
@ -180,22 +180,22 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// <summary>
/// Pointwise divide this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise divide this one by.</param>
/// <param name="divisor">The vector to pointwise divide this one by.</param>
/// <param name="result">The vector to store the result of the pointwise division.</param>
protected override void DoPointwiseDivide(Vector<Complex> other, Vector<Complex> result)
protected override void DoPointwiseDivide(Vector<Complex> divisor, Vector<Complex> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, At(index) / other.At(index));
result.At(index, At(index) / divisor.At(index));
}
}
/// <summary>
/// Pointwise modulus this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise modulus this one by.</param>
/// <param name="divisor">The vector to pointwise modulus this one by.</param>
/// <param name="result">The result of the modulus.</param>
protected override void DoPointwiseModulus(Vector<Complex> other, Vector<Complex> result)
protected override void DoPointwiseModulus(Vector<Complex> divisor, Vector<Complex> result)
{
throw new NotSupportedException();
}
@ -224,7 +224,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// <summary>
/// Computes the modulus for each element of the vector for the given divisor.
/// </summary>
/// <param name="divisor">The divisor to use.</param>
/// <param name="divisor">The scalar denominator to use.</param>
/// <param name="result">A vector to store the results in.</param>
protected override void DoModulus(Complex divisor, Vector<Complex> result)
{
@ -234,9 +234,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// <summary>
/// Computes the modulus for the given dividend for each element of the vector.
/// </summary>
/// <param name="scalar">The dividend to use.</param>
/// <param name="dividend">The scalar numerator to use.</param>
/// <param name="result">A vector to store the results in.</param>
protected override void DoModulusByThis(Complex scalar, Vector<Complex> result)
protected override void DoModulusByThis(Complex dividend, Vector<Complex> result)
{
throw new NotSupportedException();
}

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

@ -544,18 +544,18 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// <summary>
/// Divides each element of the matrix by a scalar and places results into the result matrix.
/// </summary>
/// <param name="scalar">The scalar to divide the matrix with.</param>
/// <param name="divisor">The scalar to divide the matrix with.</param>
/// <param name="result">The matrix to store the result of the division.</param>
protected override void DoDivide(Complex32 scalar, Matrix<Complex32> result)
protected override void DoDivide(Complex32 divisor, Matrix<Complex32> result)
{
var denseResult = result as DenseMatrix;
if (denseResult == null)
{
base.DoDivide(scalar, result);
base.DoDivide(divisor, result);
}
else
{
Control.LinearAlgebraProvider.ScaleArray(1.0f/scalar, _values, denseResult._values);
Control.LinearAlgebraProvider.ScaleArray(1.0f/divisor, _values, denseResult._values);
}
}
@ -582,16 +582,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// <summary>
/// Pointwise divide this matrix by another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="other">The matrix to pointwise divide this one by.</param>
/// <param name="divisor">The matrix to pointwise divide this one by.</param>
/// <param name="result">The matrix to store the result of the pointwise division.</param>
protected override void DoPointwiseDivide(Matrix<Complex32> other, Matrix<Complex32> result)
protected override void DoPointwiseDivide(Matrix<Complex32> divisor, Matrix<Complex32> result)
{
var denseOther = other as DenseMatrix;
var denseOther = divisor as DenseMatrix;
var denseResult = result as DenseMatrix;
if (denseOther == null || denseResult == null)
{
base.DoPointwiseDivide(other, result);
base.DoPointwiseDivide(divisor, result);
}
else
{

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

@ -589,17 +589,17 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// <summary>
/// Pointwise divide this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise divide this one by.</param>
/// <param name="divisor">The vector to pointwise divide this one by.</param>
/// <param name="result">The vector to store the result of the pointwise division.</param>
/// <remarks></remarks>
protected override void DoPointwiseDivide(Vector<Complex32> other, Vector<Complex32> result)
protected override void DoPointwiseDivide(Vector<Complex32> divisor, Vector<Complex32> result)
{
var denseOther = other as DenseVector;
var denseOther = divisor as DenseVector;
var denseResult = result as DenseVector;
if (denseOther == null || denseResult == null)
{
base.DoPointwiseDivide(other, result);
base.DoPointwiseDivide(divisor, result);
}
else
{

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

@ -230,25 +230,25 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// <summary>
/// Divides each element of the matrix by a scalar and places results into the result matrix.
/// </summary>
/// <param name="scalar">The scalar to divide the matrix with.</param>
/// <param name="divisor">The scalar to divide the matrix with.</param>
/// <param name="result">The matrix to store the result of the division.</param>
protected override void DoDivide(Complex32 scalar, Matrix<Complex32> result)
protected override void DoDivide(Complex32 divisor, Matrix<Complex32> result)
{
DoMultiply(1.0f / scalar, result);
DoMultiply(1.0f / divisor, result);
}
/// <summary>
/// Divides a scalar by each element of the matrix and stores the result in the result matrix.
/// </summary>
/// <param name="scalar">The scalar to add.</param>
/// <param name="dividend">The scalar to add.</param>
/// <param name="result">The matrix to store the result of the division.</param>
protected override void DoDivideByThis(Complex32 scalar, Matrix<Complex32> result)
protected override void DoDivideByThis(Complex32 dividend, Matrix<Complex32> result)
{
for (var i = 0; i < RowCount; i++)
{
for (var j = 0; j < ColumnCount; j++)
{
result.At(i, j, scalar / At(i, j));
result.At(i, j, dividend / At(i, j));
}
}
}
@ -387,27 +387,47 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// <summary>
/// Pointwise divide this matrix by another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="other">The matrix to pointwise divide this one by.</param>
/// <param name="divisor">The matrix to pointwise divide this one by.</param>
/// <param name="result">The matrix to store the result of the pointwise division.</param>
protected override void DoPointwiseDivide(Matrix<Complex32> other, Matrix<Complex32> result)
protected override void DoPointwiseDivide(Matrix<Complex32> divisor, Matrix<Complex32> result)
{
for (var j = 0; j < ColumnCount; j++)
{
for (var i = 0; i < RowCount; i++)
{
result.At(i, j, At(i, j) / other.At(i, j));
result.At(i, j, At(i, j) / divisor.At(i, j));
}
}
}
/// <summary>
/// Pointwise modulus this matrix with another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="divisor">The pointwise denominator matrix to use</param>
/// <param name="result">The result of the modulus.</param>
protected override void DoPointwiseModulus(Matrix<Complex32> divisor, Matrix<Complex32> result)
{
throw new NotSupportedException();
}
/// <summary>
/// Computes the modulus for each element of the matrix.
/// </summary>
/// <param name="divisor">The divisor to use.</param>
/// <param name="divisor">The scalar denominator to use.</param>
/// <param name="result">Matrix to store the results in.</param>
protected override void DoModulus(Complex32 divisor, Matrix<Complex32> result)
{
throw new NotImplementedException();
throw new NotSupportedException();
}
/// <summary>
/// Computes the modulus for each element of the matrix.
/// </summary>
/// <param name="dividend">The scalar numerator to use.</param>
/// <param name="result">Matrix to store the results in.</param>
protected override void DoModulusByThis(Complex32 dividend, Matrix<Complex32> result)
{
throw new NotSupportedException();
}
/// <summary>

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

@ -999,9 +999,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// <summary>
/// Pointwise divide this matrix by another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="other">The matrix to pointwise divide this one by.</param>
/// <param name="divisor">The matrix to pointwise divide this one by.</param>
/// <param name="result">The matrix to store the result of the pointwise division.</param>
protected override void DoPointwiseDivide(Matrix<Complex32> other, Matrix<Complex32> result)
protected override void DoPointwiseDivide(Matrix<Complex32> divisor, Matrix<Complex32> result)
{
result.Clear();
@ -1020,7 +1020,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
{
if (!values[j].IsZero())
{
result.At(i, columnIndices[j], values[j]/other.At(i, columnIndices[j]));
result.At(i, columnIndices[j], values[j]/divisor.At(i, columnIndices[j]));
}
}
}

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

@ -751,11 +751,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// <summary>
/// Pointwise multiplies this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise multiply with this one.</param>
/// <param name="divisor">The vector to pointwise multiply with this one.</param>
/// <param name="result">The vector to store the result of the pointwise multiplication.</param>
protected override void DoPointwiseDivide(Vector<Complex32> other, Vector<Complex32> result)
protected override void DoPointwiseDivide(Vector<Complex32> divisor, Vector<Complex32> result)
{
if (ReferenceEquals(this, other))
if (ReferenceEquals(this, divisor))
{
for (var i = 0; i < _storage.ValueCount; i++)
{
@ -767,7 +767,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
for (var i = 0; i < _storage.ValueCount; i++)
{
var index = _storage.Indices[i];
result.At(index, _storage.Values[i] / other.At(index));
result.At(index, _storage.Values[i] / divisor.At(index));
}
}
}

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

@ -135,27 +135,27 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// <summary>
/// Divides each element of the vector by a scalar and stores the result in the result vector.
/// </summary>
/// <param name="scalar">
/// <param name="divisor">
/// The scalar to divide with.
/// </param>
/// <param name="result">
/// The vector to store the result of the division.
/// </param>
protected override void DoDivide(Complex32 scalar, Vector<Complex32> result)
protected override void DoDivide(Complex32 divisor, Vector<Complex32> result)
{
DoMultiply(1 / scalar, result);
DoMultiply(1 / divisor, result);
}
/// <summary>
/// Divides a scalar by each element of the vector and stores the result in the result vector.
/// </summary>
/// <param name="scalar">The scalar to divide.</param>
/// <param name="dividend">The scalar to divide.</param>
/// <param name="result">The vector to store the result of the division.</param>
protected override void DoDivideByThis(Complex32 scalar, Vector<Complex32> result)
protected override void DoDivideByThis(Complex32 dividend, Vector<Complex32> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, scalar / At(index));
result.At(index, dividend / At(index));
}
}
@ -175,22 +175,22 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// <summary>
/// Pointwise divide this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise divide this one by.</param>
/// <param name="divisor">The vector to pointwise divide this one by.</param>
/// <param name="result">The vector to store the result of the pointwise division.</param>
protected override void DoPointwiseDivide(Vector<Complex32> other, Vector<Complex32> result)
protected override void DoPointwiseDivide(Vector<Complex32> divisor, Vector<Complex32> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, At(index) / other.At(index));
result.At(index, At(index) / divisor.At(index));
}
}
/// <summary>
/// Pointwise modulus this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise modulus this one by.</param>
/// <param name="divisor">The vector to pointwise modulus this one by.</param>
/// <param name="result">The result of the modulus.</param>
protected override void DoPointwiseModulus(Vector<Complex32> other, Vector<Complex32> result)
protected override void DoPointwiseModulus(Vector<Complex32> divisor, Vector<Complex32> result)
{
throw new NotSupportedException();
}
@ -219,7 +219,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// <summary>
/// Computes the modulus for each element of the vector for the given divisor.
/// </summary>
/// <param name="divisor">The divisor to use.</param>
/// <param name="divisor">The scalar denominator to use.</param>
/// <param name="result">A vector to store the results in.</param>
protected override void DoModulus(Complex32 divisor, Vector<Complex32> result)
{
@ -229,9 +229,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// <summary>
/// Computes the modulus for the given dividend for each element of the vector.
/// </summary>
/// <param name="scalar">The dividend to use.</param>
/// <param name="dividend">The scalar numerator to use.</param>
/// <param name="result">A vector to store the results in.</param>
protected override void DoModulusByThis(Complex32 scalar, Vector<Complex32> result)
protected override void DoModulusByThis(Complex32 dividend, Vector<Complex32> result)
{
throw new NotSupportedException();
}

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

@ -630,18 +630,18 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// <summary>
/// Divides each element of the matrix by a scalar and places results into the result matrix.
/// </summary>
/// <param name="scalar">The scalar to divide the matrix with.</param>
/// <param name="divisor">The scalar to divide the matrix with.</param>
/// <param name="result">The matrix to store the result of the division.</param>
protected override void DoDivide(double scalar, Matrix<double> result)
protected override void DoDivide(double divisor, Matrix<double> result)
{
var denseResult = result as DenseMatrix;
if (denseResult == null)
{
base.DoDivide(scalar, result);
base.DoDivide(divisor, result);
}
else
{
Control.LinearAlgebraProvider.ScaleArray(1.0/scalar, _values, denseResult._values);
Control.LinearAlgebraProvider.ScaleArray(1.0/divisor, _values, denseResult._values);
}
}
@ -668,16 +668,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// <summary>
/// Pointwise divide this matrix by another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="other">The matrix to pointwise divide this one by.</param>
/// <param name="divisor">The matrix to pointwise divide this one by.</param>
/// <param name="result">The matrix to store the result of the pointwise division.</param>
protected override void DoPointwiseDivide(Matrix<double> other, Matrix<double> result)
protected override void DoPointwiseDivide(Matrix<double> divisor, Matrix<double> result)
{
var denseOther = other as DenseMatrix;
var denseOther = divisor as DenseMatrix;
var denseResult = result as DenseMatrix;
if (denseOther == null || denseResult == null)
{
base.DoPointwiseDivide(other, result);
base.DoPointwiseDivide(divisor, result);
}
else
{
@ -714,6 +714,30 @@ namespace MathNet.Numerics.LinearAlgebra.Double
});
}
/// <summary>
/// Computes the modulus for each element of the matrix.
/// </summary>
/// <param name="dividend">The scalar numerator to use.</param>
/// <param name="result">Matrix to store the results in.</param>
protected override void DoModulusByThis(double dividend, Matrix<double> result)
{
var denseResult = result as DenseMatrix;
if (denseResult == null)
{
base.DoModulusByThis(dividend, result);
return;
}
CommonParallel.For(0, _values.Length, 4096, (a, b) =>
{
var v = denseResult._values;
for (int i = a; i < b; i++)
{
v[i] = dividend%_values[i];
}
});
}
/// <summary>
/// Computes the trace of this matrix.
/// </summary>

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

@ -681,17 +681,17 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// <summary>
/// Pointwise divide this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise divide this one by.</param>
/// <param name="divisor">The vector to pointwise divide this one by.</param>
/// <param name="result">The vector to store the result of the pointwise division.</param>
/// <remarks></remarks>
protected override void DoPointwiseDivide(Vector<double> other, Vector<double> result)
protected override void DoPointwiseDivide(Vector<double> divisor, Vector<double> result)
{
var denseOther = other as DenseVector;
var denseOther = divisor as DenseVector;
var denseResult = result as DenseVector;
if (denseOther == null || denseResult == null)
{
base.DoPointwiseDivide(other, result);
base.DoPointwiseDivide(divisor, result);
}
else
{

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

@ -28,17 +28,18 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using MathNet.Numerics.Distributions;
using MathNet.Numerics.LinearAlgebra.Generic;
using MathNet.Numerics.LinearAlgebra.Storage;
using MathNet.Numerics.Properties;
using MathNet.Numerics.Threading;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace MathNet.Numerics.LinearAlgebra.Double
{
using Distributions;
using Generic;
using Properties;
using Storage;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
/// <summary>
/// A matrix type for diagonal matrices.
/// </summary>
@ -1020,28 +1021,49 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// <summary>
/// Computes the modulus for each element of the matrix.
/// </summary>
/// <param name="divisor">The divisor to use.</param>
/// <param name="divisor">The scalar denominator to use.</param>
/// <param name="result">Matrix to store the results in.</param>
protected override void DoModulus(double divisor, Matrix<double> result)
{
var denseResult = result as DiagonalMatrix;
if (denseResult == null)
var diagonalResult = result as DiagonalMatrix;
if (diagonalResult == null)
{
base.DoModulus(divisor, result);
return;
}
else
{
if (!ReferenceEquals(this, result))
{
CopyTo(result);
}
for (var index = 0; index < _data.Length; index++)
CommonParallel.For(0, _data.Length, 4096, (a, b) =>
{
denseResult._data[index] %= divisor;
}
var r = diagonalResult._data;
for (var i = a; i < b; i++)
{
r[i] = _data[i]%divisor;
}
});
}
/// <summary>
/// Computes the modulus for each element of the matrix.
/// </summary>
/// <param name="dividend">The scalar numerator to use.</param>
/// <param name="result">Matrix to store the results in.</param>
protected override void DoModulusByThis(double dividend, Matrix<double> result)
{
var diagonalResult = result as DiagonalMatrix;
if (diagonalResult == null)
{
base.DoModulusByThis(dividend, result);
return;
}
CommonParallel.For(0, _data.Length, 4096, (a, b) =>
{
var r = diagonalResult._data;
for (var i = a; i < b; i++)
{
r[i] = dividend%_data[i];
}
});
}
#region Static constructors for special matrices.

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

@ -220,25 +220,25 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// <summary>
/// Divides each element of the matrix by a scalar and places results into the result matrix.
/// </summary>
/// <param name="scalar">The scalar to divide the matrix with.</param>
/// <param name="divisor">The scalar to divide the matrix with.</param>
/// <param name="result">The matrix to store the result of the division.</param>
protected override void DoDivide(double scalar, Matrix<double> result)
protected override void DoDivide(double divisor, Matrix<double> result)
{
DoMultiply(1.0 / scalar, result);
DoMultiply(1.0 / divisor, result);
}
/// <summary>
/// Divides a scalar by each element of the matrix and stores the result in the result matrix.
/// </summary>
/// <param name="scalar">The scalar to add.</param>
/// <param name="dividend">The scalar to add.</param>
/// <param name="result">The matrix to store the result of the division.</param>
protected override void DoDivideByThis(double scalar, Matrix<double> result)
protected override void DoDivideByThis(double dividend, Matrix<double> result)
{
for (var i = 0; i < RowCount; i++)
{
for (var j = 0; j < ColumnCount; j++)
{
result.At(i, j, scalar / At(i, j));
result.At(i, j, dividend / At(i, j));
}
}
}
@ -357,6 +357,38 @@ namespace MathNet.Numerics.LinearAlgebra.Double
CopyTo(result);
}
/// <summary>
/// Computes the modulus for each element of the matrix.
/// </summary>
/// <param name="divisor">The scalar denominator to use.</param>
/// <param name="result">Matrix to store the results in.</param>
protected override void DoModulus(double divisor, Matrix<double> result)
{
for (var row = 0; row < RowCount; row++)
{
for (var column = 0; column < ColumnCount; column++)
{
result.At(row, column, At(row, column)%divisor);
}
}
}
/// <summary>
/// Computes the modulus for each element of the matrix.
/// </summary>
/// <param name="dividend">The scalar numerator to use.</param>
/// <param name="result">Matrix to store the results in.</param>
protected override void DoModulusByThis(double dividend, Matrix<double> result)
{
for (var row = 0; row < RowCount; row++)
{
for (var column = 0; column < ColumnCount; column++)
{
result.At(row, column, dividend%At(row, column));
}
}
}
/// <summary>
/// Pointwise multiplies this matrix with another matrix and stores the result into the result matrix.
/// </summary>
@ -368,7 +400,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
{
for (var i = 0; i < RowCount; i++)
{
result.At(i, j, At(i, j) * other.At(i, j));
result.At(i, j, At(i, j)*other.At(i, j));
}
}
}
@ -376,31 +408,31 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// <summary>
/// Pointwise divide this matrix by another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="other">The matrix to pointwise divide this one by.</param>
/// <param name="divisor">The matrix to pointwise divide this one by.</param>
/// <param name="result">The matrix to store the result of the pointwise division.</param>
protected override void DoPointwiseDivide(Matrix<double> other, Matrix<double> result)
protected override void DoPointwiseDivide(Matrix<double> divisor, Matrix<double> result)
{
for (var j = 0; j < ColumnCount; j++)
{
for (var i = 0; i < RowCount; i++)
{
result.At(i, j, At(i, j) / other.At(i, j));
result.At(i, j, At(i, j)/divisor.At(i, j));
}
}
}
/// <summary>
/// Computes the modulus for each element of the matrix.
/// Pointwise modulus this matrix with another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="divisor">The divisor to use.</param>
/// <param name="result">Matrix to store the results in.</param>
protected override void DoModulus(double divisor, Matrix<double> result)
/// <param name="divisor">The pointwise denominator matrix to use</param>
/// <param name="result">The result of the modulus.</param>
protected override void DoPointwiseModulus(Matrix<double> divisor, Matrix<double> result)
{
for (var row = 0; row < RowCount; row++)
for (var j = 0; j < ColumnCount; j++)
{
for (var column = 0; column < ColumnCount; column++)
for (var i = 0; i < RowCount; i++)
{
result.At(row, column, At(row, column) % divisor);
result.At(i, j, At(i, j)%divisor.At(i, j));
}
}
}

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

@ -998,9 +998,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// <summary>
/// Pointwise divide this matrix by another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="other">The matrix to pointwise divide this one by.</param>
/// <param name="divisor">The matrix to pointwise divide this one by.</param>
/// <param name="result">The matrix to store the result of the pointwise division.</param>
protected override void DoPointwiseDivide(Matrix<double> other, Matrix<double> result)
protected override void DoPointwiseDivide(Matrix<double> divisor, Matrix<double> result)
{
result.Clear();
@ -1019,7 +1019,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
{
if (values[j] != 0d)
{
result.At(i, columnIndices[j], values[j]/other.At(i, columnIndices[j]));
result.At(i, columnIndices[j], values[j]/divisor.At(i, columnIndices[j]));
}
}
}

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

@ -787,11 +787,11 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// <summary>
/// Pointwise multiplies this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise multiply with this one.</param>
/// <param name="divisor">The vector to pointwise multiply with this one.</param>
/// <param name="result">The vector to store the result of the pointwise multiplication.</param>
protected override void DoPointwiseDivide(Vector<double> other, Vector<double> result)
protected override void DoPointwiseDivide(Vector<double> divisor, Vector<double> result)
{
if (ReferenceEquals(this, other))
if (ReferenceEquals(this, divisor))
{
for (var i = 0; i < _storage.ValueCount; i++)
{
@ -803,7 +803,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
for (var i = 0; i < _storage.ValueCount; i++)
{
var index = _storage.Indices[i];
result.At(index, _storage.Values[i] / other.At(index));
result.At(index, _storage.Values[i] / divisor.At(index));
}
}
}

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

@ -134,27 +134,27 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// <summary>
/// Divides each element of the vector by a scalar and stores the result in the result vector.
/// </summary>
/// <param name="scalar">
/// <param name="divisor">
/// The scalar to divide with.
/// </param>
/// <param name="result">
/// The vector to store the result of the division.
/// </param>
protected override void DoDivide(double scalar, Vector<double> result)
protected override void DoDivide(double divisor, Vector<double> result)
{
DoMultiply(1 / scalar, result);
DoMultiply(1 / divisor, result);
}
/// <summary>
/// Divides a scalar by each element of the vector and stores the result in the result vector.
/// </summary>
/// <param name="scalar">The scalar to divide.</param>
/// <param name="dividend">The scalar to divide.</param>
/// <param name="result">The vector to store the result of the division.</param>
protected override void DoDivideByThis(double scalar, Vector<double> result)
protected override void DoDivideByThis(double dividend, Vector<double> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, scalar / At(index));
result.At(index, dividend / At(index));
}
}
@ -174,39 +174,26 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// <summary>
/// Pointwise divide this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise divide this one by.</param>
/// <param name="divisor">The vector to pointwise divide this one by.</param>
/// <param name="result">The vector to store the result of the pointwise division.</param>
protected override void DoPointwiseDivide(Vector<double> other, Vector<double> result)
protected override void DoPointwiseDivide(Vector<double> divisor, Vector<double> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, At(index) / other.At(index));
result.At(index, At(index) / divisor.At(index));
}
}
/// <summary>
/// Pointwise modulus this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise modulus this one by.</param>
/// <param name="divisor">The vector to pointwise modulus this one by.</param>
/// <param name="result">The result of the modulus.</param>
protected override void DoPointwiseModulus(Vector<double> other, Vector<double> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, At(index) % other.At(index));
}
}
/// <summary>
/// Computes the modulus for the given dividend for each element of the vector.
/// </summary>
/// <param name="scalar">The dividend to use.</param>
/// <param name="result">A vector to store the results in.</param>
protected override void DoModulusByThis(double scalar, Vector<double> result)
protected override void DoPointwiseModulus(Vector<double> divisor, Vector<double> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, scalar % At(index));
result.At(index, At(index) % divisor.At(index));
}
}
@ -234,7 +221,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// <summary>
/// Computes the modulus for each element of the vector for the given divisor.
/// </summary>
/// <param name="divisor">The divisor to use.</param>
/// <param name="divisor">The scalar denominator to use.</param>
/// <param name="result">A vector to store the results in.</param>
protected override void DoModulus(double divisor, Vector<double> result)
{
@ -244,6 +231,19 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
}
/// <summary>
/// Computes the modulus for the given dividend for each element of the vector.
/// </summary>
/// <param name="dividend">The scalar numerator to use.</param>
/// <param name="result">A vector to store the results in.</param>
protected override void DoModulusByThis(double dividend, Vector<double> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, dividend%At(index));
}
}
/// <summary>
/// Returns the value of the absolute minimum element.
/// </summary>

173
src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs

@ -147,24 +147,31 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <summary>
/// Divides each element of the matrix by a scalar and places results into the result matrix.
/// </summary>
/// <param name="scalar">The scalar to divide the matrix with.</param>
/// <param name="divisor">The scalar denominator to use.</param>
/// <param name="result">The matrix to store the result of the division.</param>
protected abstract void DoDivide(T scalar, Matrix<T> result);
protected abstract void DoDivide(T divisor, Matrix<T> result);
/// <summary>
/// Divides a scalar by each element of the matrix and stores the result in the result matrix.
/// </summary>
/// <param name="scalar">The scalar to divide.</param>
/// <param name="dividend">The scalar numerator to use.</param>
/// <param name="result">The matrix to store the result of the division.</param>
protected abstract void DoDivideByThis(T scalar, Matrix<T> result);
protected abstract void DoDivideByThis(T dividend, Matrix<T> result);
/// <summary>
/// Computes the modulus for each element of the matrix.
/// Computes the modulus for the given divisor each element of the matrix.
/// </summary>
/// <param name="divisor">The divisor to use.</param>
/// <param name="divisor">The scalar denominator to use.</param>
/// <param name="result">Matrix to store the results in.</param>
protected abstract void DoModulus(T divisor, Matrix<T> result);
/// <summary>
/// Computes the modulus for the given dividend for each element of the matrix.
/// </summary>
/// <param name="dividend">The scalar numerator to use.</param>
/// <param name="result">A vector to store the results in.</param>
protected abstract void DoModulusByThis(T dividend, Matrix<T> result);
/// <summary>
/// Pointwise multiplies this matrix with another matrix and stores the result into the result matrix.
/// </summary>
@ -175,9 +182,16 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <summary>
/// Pointwise divide this matrix by another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="other">The matrix to pointwise divide this one by.</param>
/// <param name="divisor">The pointwise denominator matrix to use.</param>
/// <param name="result">The matrix to store the result of the pointwise division.</param>
protected abstract void DoPointwiseDivide(Matrix<T> other, Matrix<T> result);
protected abstract void DoPointwiseDivide(Matrix<T> divisor, Matrix<T> result);
/// <summary>
/// Pointwise modulus this matrix with another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="divisor">The pointwise denominator matrix to use</param>
/// <param name="result">The result of the modulus.</param>
protected abstract void DoPointwiseModulus(Matrix<T> divisor, Matrix<T> result);
/// <summary>
/// Adds a scalar to each element of the matrix.
@ -1038,6 +1052,70 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
DoConjugate(result);
}
/// <summary>
/// Computes the modulus (matrix % divisor) for each element of the matrix.
/// </summary>
/// <param name="divisor">The scalar denominator to use.</param>
/// <returns>A matrix containing the results.</returns>
public Matrix<T> Modulus(T divisor)
{
var result = CreateMatrix(RowCount, ColumnCount);
DoModulus(divisor, result);
return result;
}
/// <summary>
/// Computes the modulus (matrix % divisor) for each element of the matrix.
/// </summary>
/// <param name="divisor">The scalar denominator to use.</param>
/// <param name="result">Matrix to store the results in.</param>
public void Modulus(T divisor, Matrix<T> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (ColumnCount != result.ColumnCount || RowCount != result.RowCount)
{
throw DimensionsDontMatch<ArgumentException>(this, result);
}
DoModulus(divisor, result);
}
/// <summary>
/// Computes the modulus (dividend % matrix) for each element of the matrix.
/// </summary>
/// <param name="dividend">The scalar numerator to use.</param>
/// <returns>A matrix containing the results.</returns>
public Matrix<T> ModulusByThis(T dividend)
{
var result = CreateMatrix(RowCount, ColumnCount);
DoModulusByThis(dividend, result);
return result;
}
/// <summary>
/// Computes the modulus (dividend % matrix) for each element of the matrix.
/// </summary>
/// <param name="dividend">The scalar numerator to use.</param>
/// <param name="result">Matrix to store the results in.</param>
public void ModulusByThis(T dividend, Matrix<T> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (ColumnCount != result.ColumnCount || RowCount != result.RowCount)
{
throw DimensionsDontMatch<ArgumentException>(this, result);
}
DoModulusByThis(dividend, result);
}
/// <summary>
/// Pointwise multiplies this matrix with another matrix.
/// </summary>
@ -1094,41 +1172,41 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <summary>
/// Pointwise divide this matrix by another matrix.
/// </summary>
/// <param name="other">The matrix to pointwise subtract this one by.</param>
/// <param name="divisor">The pointwise denominator matrix to use.</param>
/// <exception cref="ArgumentNullException">If the other matrix is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If this matrix and <paramref name="other"/> are not the same size.</exception>
/// <returns>A new matrix that is the pointwise division of this matrix and <paramref name="other"/>.</returns>
public Matrix<T> PointwiseDivide(Matrix<T> other)
/// <exception cref="ArgumentException">If this matrix and <paramref name="divisor"/> are not the same size.</exception>
/// <returns>A new matrix that is the pointwise division of this matrix and <paramref name="divisor"/>.</returns>
public Matrix<T> PointwiseDivide(Matrix<T> divisor)
{
if (other == null)
if (divisor == null)
{
throw new ArgumentNullException("other");
throw new ArgumentNullException("divisor");
}
if (ColumnCount != other.ColumnCount || RowCount != other.RowCount)
if (ColumnCount != divisor.ColumnCount || RowCount != divisor.RowCount)
{
throw DimensionsDontMatch<ArgumentException>(this, other);
throw DimensionsDontMatch<ArgumentException>(this, divisor);
}
var result = CreateMatrix(RowCount, ColumnCount);
DoPointwiseDivide(other, result);
DoPointwiseDivide(divisor, result);
return result;
}
/// <summary>
/// Pointwise divide this matrix by another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="other">The matrix to pointwise divide this one by.</param>
/// <param name="divisor">The pointwise denominator matrix to use.</param>
/// <param name="result">The matrix to store the result of the pointwise division.</param>
/// <exception cref="ArgumentNullException">If the other matrix is <see langword="null" />.</exception>
/// <exception cref="ArgumentNullException">If the result matrix is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If this matrix and <paramref name="other"/> are not the same size.</exception>
/// <exception cref="ArgumentException">If this matrix and <paramref name="divisor"/> are not the same size.</exception>
/// <exception cref="ArgumentException">If this matrix and <paramref name="result"/> are not the same size.</exception>
public void PointwiseDivide(Matrix<T> other, Matrix<T> result)
public void PointwiseDivide(Matrix<T> divisor, Matrix<T> result)
{
if (other == null)
if (divisor == null)
{
throw new ArgumentNullException("other");
throw new ArgumentNullException("divisor");
}
if (result == null)
@ -1136,44 +1214,65 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
throw new ArgumentNullException("result");
}
if (ColumnCount != result.ColumnCount || RowCount != result.RowCount || ColumnCount != other.ColumnCount || RowCount != other.RowCount)
if (ColumnCount != result.ColumnCount || RowCount != result.RowCount || ColumnCount != divisor.ColumnCount || RowCount != divisor.RowCount)
{
throw DimensionsDontMatch<ArgumentException>(this, other, result);
throw DimensionsDontMatch<ArgumentException>(this, divisor, result);
}
DoPointwiseDivide(other, result);
DoPointwiseDivide(divisor, result);
}
/// <summary>
/// Computes the modulus for each element of the matrix.
/// Pointwise modulus this matrix by another matrix.
/// </summary>
/// <param name="divisor">The divisor to use.</param>
/// <returns>A matrix containing the results.</returns>
public Matrix<T> Modulus(T divisor)
/// <param name="divisor">The pointwise denominator matrix to use.</param>
/// <exception cref="ArgumentNullException">If the other matrix is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If this matrix and <paramref name="divisor"/> are not the same size.</exception>
/// <returns>A new matrix that is the pointwise modulus of this matrix and <paramref name="divisor"/>.</returns>
public Matrix<T> PointwiseModulus(Matrix<T> divisor)
{
if (divisor == null)
{
throw new ArgumentNullException("divisor");
}
if (ColumnCount != divisor.ColumnCount || RowCount != divisor.RowCount)
{
throw DimensionsDontMatch<ArgumentException>(this, divisor);
}
var result = CreateMatrix(RowCount, ColumnCount);
DoModulus(divisor, result);
DoPointwiseModulus(divisor, result);
return result;
}
/// <summary>
/// Computes the modulus for each element of the matrix.
/// Pointwise modulus this matrix by another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="divisor">The divisor to use.</param>
/// <param name="result">Matrix to store the results in.</param>
public void Modulus(T divisor, Matrix<T> result)
/// <param name="divisor">The pointwise denominator matrix to use.</param>
/// <param name="result">The matrix to store the result of the pointwise modulus.</param>
/// <exception cref="ArgumentNullException">If the other matrix is <see langword="null" />.</exception>
/// <exception cref="ArgumentNullException">If the result matrix is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If this matrix and <paramref name="divisor"/> are not the same size.</exception>
/// <exception cref="ArgumentException">If this matrix and <paramref name="result"/> are not the same size.</exception>
public void PointwiseModulus(Matrix<T> divisor, Matrix<T> result)
{
if (divisor == null)
{
throw new ArgumentNullException("divisor");
}
if (result == null)
{
throw new ArgumentNullException("result");
}
if (ColumnCount != result.ColumnCount || RowCount != result.RowCount)
if (ColumnCount != result.ColumnCount || RowCount != result.RowCount || ColumnCount != divisor.ColumnCount || RowCount != divisor.RowCount)
{
throw DimensionsDontMatch<ArgumentException>(this, result);
throw DimensionsDontMatch<ArgumentException>(this, divisor, result);
}
DoModulus(divisor, result);
DoPointwiseModulus(divisor, result);
}
/// <summary>

91
src/Numerics/LinearAlgebra/Generic/Matrix.Operators.cs

@ -282,52 +282,87 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <summary>
/// Divides a scalar with a matrix.
/// </summary>
/// <param name="leftSide">The scalar to divide.</param>
/// <param name="rightSide">The matrix.</param>
/// <param name="dividend">The scalar to divide.</param>
/// <param name="divisor">The matrix.</param>
/// <returns>The result of the division.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="rightSide"/> is <see langword="null" />.</exception>
public static Matrix<T> operator /(T leftSide, Matrix<T> rightSide)
/// <exception cref="ArgumentNullException">If <paramref name="divisor"/> is <see langword="null" />.</exception>
public static Matrix<T> operator /(T dividend, Matrix<T> divisor)
{
if (rightSide == null)
if (divisor == null)
{
throw new ArgumentNullException("rightSide");
throw new ArgumentNullException("divisor");
}
return rightSide.DivideByThis(leftSide);
return divisor.DivideByThis(dividend);
}
/// <summary>
/// Divides a matrix with a scalar.
/// </summary>
/// <param name="leftSide">The matrix to divide.</param>
/// <param name="rightSide">The scalar value.</param>
/// <param name="dividend">The matrix to divide.</param>
/// <param name="divisor">The scalar value.</param>
/// <returns>The result of the division.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> is <see langword="null" />.</exception>
public static Matrix<T> operator /(Matrix<T> leftSide, T rightSide)
/// <exception cref="ArgumentNullException">If <paramref name="dividend"/> is <see langword="null" />.</exception>
public static Matrix<T> operator /(Matrix<T> dividend, T divisor)
{
if (leftSide == null)
if (dividend == null)
{
throw new ArgumentNullException("leftSide");
throw new ArgumentNullException("dividend");
}
return leftSide.Divide(rightSide);
return dividend.Divide(divisor);
}
/// <summary>
/// Multiplies a <strong>Matrix</strong> by a constant and returns the result.
/// Computes the modulus of each element of the matrix of the given divisor.
/// </summary>
/// <param name="leftSide">The matrix to multiply.</param>
/// <param name="rightSide">The constant to multiply the matrix by.</param>
/// <returns>The result of the multiplication.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> is <see langword="null" />.</exception>
public static Matrix<T> operator %(Matrix<T> leftSide, T rightSide)
/// <param name="dividend">The matrix whose elements we want to compute the modulus of.</param>
/// <param name="divisor">The divisor to use.</param>
/// <returns>The result of the calculation</returns>
/// <exception cref="ArgumentNullException">If <paramref name="dividend"/> is <see langword="null" />.</exception>
public static Matrix<T> operator %(Matrix<T> dividend, T divisor)
{
if (leftSide == null)
if (dividend == null)
{
throw new ArgumentNullException("leftSide");
throw new ArgumentNullException("dividend");
}
return leftSide.Modulus(rightSide);
return dividend.Modulus(divisor);
}
/// <summary>
/// Computes the modulus of the given dividend of each element of the matrix.
/// </summary>
/// <param name="dividend">The dividend we want to compute the modulus of.</param>
/// <param name="divisor">The matrix whose elements we want to use as divisor.</param>
/// <returns>The result of the calculation</returns>
/// <exception cref="ArgumentNullException">If <paramref name="divisor"/> is <see langword="null" />.</exception>
public static Matrix<T> operator %(T dividend, Matrix<T> divisor)
{
if (divisor == null)
{
throw new ArgumentNullException("dividend");
}
return divisor.ModulusByThis(dividend);
}
/// <summary>
/// Computes the pointwise modulus of each element of two matrices.
/// </summary>
/// <param name="dividend">The matrix whose elements we want to compute the modulus of.</param>
/// <param name="divisor">The divisor to use.</param>
/// <returns>The result of the calculation</returns>
/// <exception cref="ArgumentException">If <paramref name="dividend"/> and <paramref name="divisor"/> are not the same size.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="dividend"/> is <see langword="null" />.</exception>
public static Matrix<T> operator %(Matrix<T> dividend, Matrix<T> divisor)
{
if (dividend == null)
{
throw new ArgumentNullException("dividend");
}
return dividend.PointwiseModulus(divisor);
}
[SpecialName]
@ -337,9 +372,15 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
}
[SpecialName]
public static Matrix<T> op_DotDivide(Matrix<T> x, Matrix<T> y)
public static Matrix<T> op_DotDivide(Matrix<T> dividend, Matrix<T> divisor)
{
return dividend.PointwiseDivide(divisor);
}
[SpecialName]
public static Vector<T> op_DotPercent(Vector<T> dividend, Vector<T> divisor)
{
return x.PointwiseDivide(y);
return dividend.PointwiseModulus(divisor);
}
}
}

120
src/Numerics/LinearAlgebra/Generic/Vector.Arithmetic.cs

@ -103,30 +103,30 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <summary>
/// Divides each element of the vector by a scalar and stores the result in the result vector.
/// </summary>
/// <param name="scalar">The scalar to divide with.</param>
/// <param name="divisor">The scalar denominator to use.</param>
/// <param name="result">The vector to store the result of the division.</param>
protected abstract void DoDivide(T scalar, Vector<T> result);
protected abstract void DoDivide(T divisor, Vector<T> result);
/// <summary>
/// Divides a scalar by each element of the vector and stores the result in the result vector.
/// </summary>
/// <param name="scalar">The scalar to divide.</param>
/// <param name="dividend">The scalar numerator to use.</param>
/// <param name="result">The vector to store the result of the division.</param>
protected abstract void DoDivideByThis(T scalar, Vector<T> result);
protected abstract void DoDivideByThis(T dividend, Vector<T> result);
/// <summary>
/// Computes the modulus for each element of the vector for the given divisor.
/// </summary>
/// <param name="scalar">The divisor to use.</param>
/// <param name="divisor">The scalar denominator to use.</param>
/// <param name="result">A vector to store the results in.</param>
protected abstract void DoModulus(T scalar, Vector<T> result);
protected abstract void DoModulus(T divisor, Vector<T> result);
/// <summary>
/// Computes the modulus for the given dividend for each element of the vector.
/// </summary>
/// <param name="scalar">The dividend to use.</param>
/// <param name="dividend">The scalar numerator to use.</param>
/// <param name="result">A vector to store the results in.</param>
protected abstract void DoModulusByThis(T scalar, Vector<T> result);
protected abstract void DoModulusByThis(T dividend, Vector<T> result);
/// <summary>
/// Pointwise multiplies this vector with another vector and stores the result into the result vector.
@ -138,16 +138,16 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <summary>
/// Pointwise divide this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise divide this one by.</param>
/// <param name="divisor">The pointwise denominator vector to use.</param>
/// <param name="result">The result of the division.</param>
protected abstract void DoPointwiseDivide(Vector<T> other, Vector<T> result);
protected abstract void DoPointwiseDivide(Vector<T> divisor, Vector<T> result);
/// <summary>
/// Pointwise modulus this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise modulus this one by.</param>
/// <param name="divisor">The pointwise denominator vector to use.</param>
/// <param name="result">The result of the modulus.</param>
protected abstract void DoPointwiseModulus(Vector<T> other, Vector<T> result);
protected abstract void DoPointwiseModulus(Vector<T> divisor, Vector<T> result);
/// <summary>
/// Adds a scalar to each element of the vector.
@ -588,23 +588,23 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
}
/// <summary>
/// Computes the modulus for each element of the vector for the given divisor.
/// Computes the modulus (vector % divisor) for each element of the vector for the given divisor.
/// </summary>
/// <param name="scalar">The divisor to use.</param>
/// <param name="divisor">The scalar denominator to use.</param>
/// <returns>A vector containing the result.</returns>
public Vector<T> Modulus(T scalar)
public Vector<T> Modulus(T divisor)
{
var result = CreateVector(Count);
DoModulus(scalar, result);
DoModulus(divisor, result);
return result;
}
/// <summary>
/// Computes the modulus for each element of the vector for the given divisor.
/// Computes the modulus (vector % divisor) for each element of the vector for the given divisor.
/// </summary>
/// <param name="scalar">The divisor to use.</param>
/// <param name="divisor">The scalar denominator to use.</param>
/// <param name="result">A vector to store the results in.</param>
public void Modulus(T scalar, Vector<T> result)
public void Modulus(T divisor, Vector<T> result)
{
if (result == null)
{
@ -616,27 +616,27 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
}
DoModulus(scalar, result);
DoModulus(divisor, result);
}
/// <summary>
/// Computes the modulus for the given dividend for each element of the vector.
/// Computes the modulus (dividend % vector) for the given dividend for each element of the vector.
/// </summary>
/// <param name="scalar">The dividend to use.</param>
/// <param name="dividend">The scalar numerator to use.</param>
/// <returns>A vector containing the result.</returns>
public Vector<T> ModulusByThis(T scalar)
public Vector<T> ModulusByThis(T dividend)
{
var result = CreateVector(Count);
DoModulusByThis(scalar, result);
DoModulusByThis(dividend, result);
return result;
}
/// <summary>
/// Computes the modulus for the given dividend for each element of the vector.
/// Computes the modulus (dividend % vector) for the given dividend for each element of the vector.
/// </summary>
/// <param name="scalar">The dividend to use.</param>
/// <param name="dividend">The scalar numerator to use.</param>
/// <param name="result">A vector to store the results in.</param>
public void ModulusByThis(T scalar, Vector<T> result)
public void ModulusByThis(T dividend, Vector<T> result)
{
if (result == null)
{
@ -648,7 +648,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
}
DoModulusByThis(scalar, result);
DoModulusByThis(dividend, result);
}
/// <summary>
@ -712,51 +712,51 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <summary>
/// Pointwise divide this vector with another vector.
/// </summary>
/// <param name="other">The vector to pointwise divide this one by.</param>
/// <param name="divisor">The pointwise denominator vector to use.</param>
/// <returns>A new vector which is the pointwise division of the two vectors.</returns>
/// <exception cref="ArgumentNullException">If the other vector is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If this vector and <paramref name="other"/> are not the same size.</exception>
public Vector<T> PointwiseDivide(Vector<T> other)
/// <exception cref="ArgumentException">If this vector and <paramref name="divisor"/> are not the same size.</exception>
public Vector<T> PointwiseDivide(Vector<T> divisor)
{
if (other == null)
if (divisor == null)
{
throw new ArgumentNullException("other");
throw new ArgumentNullException("divisor");
}
if (Count != other.Count)
if (Count != divisor.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "other");
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "divisor");
}
var result = CreateVector(Count);
DoPointwiseDivide(other, result);
DoPointwiseDivide(divisor, result);
return result;
}
/// <summary>
/// Pointwise divide this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise divide this one by.</param>
/// <param name="divisor">The pointwise denominator vector to use.</param>
/// <param name="result">The vector to store the result of the pointwise division.</param>
/// <exception cref="ArgumentNullException">If the other vector is <see langword="null" />.</exception>
/// <exception cref="ArgumentNullException">If the result vector is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If this vector and <paramref name="other"/> are not the same size.</exception>
/// <exception cref="ArgumentException">If this vector and <paramref name="divisor"/> are not the same size.</exception>
/// <exception cref="ArgumentException">If this vector and <paramref name="result"/> are not the same size.</exception>
public void PointwiseDivide(Vector<T> other, Vector<T> result)
public void PointwiseDivide(Vector<T> divisor, Vector<T> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (other == null)
if (divisor == null)
{
throw new ArgumentNullException("other");
throw new ArgumentNullException("divisor");
}
if (Count != other.Count)
if (Count != divisor.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "other");
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "divisor");
}
if (Count != result.Count)
@ -764,57 +764,57 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
}
DoPointwiseDivide(other, result);
DoPointwiseDivide(divisor, result);
}
/// <summary>
/// Pointwise modulus this vector with another vector.
/// </summary>
/// <param name="other">The vector to pointwise modulus this one by.</param>
/// <param name="divisor">The pointwise denominator vector to use.</param>
/// <returns>A new vector which is the pointwise modulus of the two vectors.</returns>
/// <exception cref="ArgumentNullException">If the other vector is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If this vector and <paramref name="other"/> are not the same size.</exception>
public Vector<T> PointwiseModulus(Vector<T> other)
/// <exception cref="ArgumentException">If this vector and <paramref name="divisor"/> are not the same size.</exception>
public Vector<T> PointwiseModulus(Vector<T> divisor)
{
if (other == null)
if (divisor == null)
{
throw new ArgumentNullException("other");
throw new ArgumentNullException("divisor");
}
if (Count != other.Count)
if (Count != divisor.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "other");
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "divisor");
}
var result = CreateVector(Count);
DoPointwiseModulus(other, result);
DoPointwiseModulus(divisor, result);
return result;
}
/// <summary>
/// Pointwise modulus this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise modulus this one by.</param>
/// <param name="divisor">The pointwise denominator vector to use.</param>
/// <param name="result">The vector to store the result of the pointwise modulus.</param>
/// <exception cref="ArgumentNullException">If the other vector is <see langword="null" />.</exception>
/// <exception cref="ArgumentNullException">If the result vector is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If this vector and <paramref name="other"/> are not the same size.</exception>
/// <exception cref="ArgumentException">If this vector and <paramref name="divisor"/> are not the same size.</exception>
/// <exception cref="ArgumentException">If this vector and <paramref name="result"/> are not the same size.</exception>
public void PointwiseModulus(Vector<T> other, Vector<T> result)
public void PointwiseModulus(Vector<T> divisor, Vector<T> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (other == null)
if (divisor == null)
{
throw new ArgumentNullException("other");
throw new ArgumentNullException("divisor");
}
if (Count != other.Count)
if (Count != divisor.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "other");
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "divisor");
}
if (Count != result.Count)
@ -822,7 +822,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
}
DoPointwiseModulus(other, result);
DoPointwiseModulus(divisor, result);
}
/// <summary>

98
src/Numerics/LinearAlgebra/Generic/Vector.Operators.cs

@ -227,105 +227,105 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <summary>
/// Divides a scalar with a vector.
/// </summary>
/// <param name="leftSide">The scalar to divide.</param>
/// <param name="rightSide">The vector.</param>
/// <param name="dividend">The scalar to divide.</param>
/// <param name="divisor">The vector.</param>
/// <returns>The result of the division.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="rightSide"/> is <see langword="null" />.</exception>
public static Vector<T> operator /(T leftSide, Vector<T> rightSide)
/// <exception cref="ArgumentNullException">If <paramref name="divisor"/> is <see langword="null" />.</exception>
public static Vector<T> operator /(T dividend, Vector<T> divisor)
{
if (rightSide == null)
if (divisor == null)
{
throw new ArgumentNullException("rightSide");
throw new ArgumentNullException("divisor");
}
return rightSide.DevideByThis(leftSide);
return divisor.DevideByThis(dividend);
}
/// <summary>
/// Divides a vector with a scalar.
/// </summary>
/// <param name="leftSide">The vector to divide.</param>
/// <param name="rightSide">The scalar value.</param>
/// <param name="dividend">The vector to divide.</param>
/// <param name="divisor">The scalar value.</param>
/// <returns>The result of the division.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> is <see langword="null" />.</exception>
public static Vector<T> operator /(Vector<T> leftSide, T rightSide)
/// <exception cref="ArgumentNullException">If <paramref name="dividend"/> is <see langword="null" />.</exception>
public static Vector<T> operator /(Vector<T> dividend, T divisor)
{
if (leftSide == null)
if (dividend == null)
{
throw new ArgumentNullException("leftSide");
throw new ArgumentNullException("dividend");
}
return leftSide.Divide(rightSide);
return dividend.Divide(divisor);
}
/// <summary>
/// Pointwise divides two <strong>Vectors</strong>.
/// </summary>
/// <param name="leftSide">The vector to divide.</param>
/// <param name="rightSide">The other vector.</param>
/// <param name="dividend">The vector to divide.</param>
/// <param name="divisor">The other vector.</param>
/// <returns>The result of the division.</returns>
/// <exception cref="ArgumentException">If <paramref name="leftSide"/> and <paramref name="rightSide"/> are not the same size.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> is <see langword="null" />.</exception>
public static Vector<T> operator /(Vector<T> leftSide, Vector<T> rightSide)
/// <exception cref="ArgumentException">If <paramref name="dividend"/> and <paramref name="divisor"/> are not the same size.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="dividend"/> is <see langword="null" />.</exception>
public static Vector<T> operator /(Vector<T> dividend, Vector<T> divisor)
{
if (leftSide == null)
if (dividend == null)
{
throw new ArgumentNullException("leftSide");
throw new ArgumentNullException("dividend");
}
return leftSide.PointwiseDivide(rightSide);
return dividend.PointwiseDivide(divisor);
}
/// <summary>
/// Computes the modulus of each element of the vector of the given divisor.
/// </summary>
/// <param name="leftSide">The vector whose elements we want to compute the modulus of.</param>
/// <param name="rightSide">The divisor to use.</param>
/// <param name="dividend">The vector whose elements we want to compute the modulus of.</param>
/// <param name="divisor">The divisor to use.</param>
/// <returns>The result of the calculation</returns>
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> is <see langword="null" />.</exception>
public static Vector<T> operator %(Vector<T> leftSide, T rightSide)
/// <exception cref="ArgumentNullException">If <paramref name="dividend"/> is <see langword="null" />.</exception>
public static Vector<T> operator %(Vector<T> dividend, T divisor)
{
if (leftSide == null)
if (dividend == null)
{
throw new ArgumentNullException("leftSide");
throw new ArgumentNullException("dividend");
}
return leftSide.Modulus(rightSide);
return dividend.Modulus(divisor);
}
/// <summary>
/// Computes the modulus of the given dividend of each element of the vector.
/// </summary>
/// <param name="leftSide">The dividend we want to compute the modulus of.</param>
/// <param name="rightSide">The vector whose elements we want to use as divisor.</param>
/// <param name="dividend">The dividend we want to compute the modulus of.</param>
/// <param name="divisor">The vector whose elements we want to use as divisor.</param>
/// <returns>The result of the calculation</returns>
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> is <see langword="null" />.</exception>
public static Vector<T> operator %(T leftSide, Vector<T> rightSide)
/// <exception cref="ArgumentNullException">If <paramref name="dividend"/> is <see langword="null" />.</exception>
public static Vector<T> operator %(T dividend, Vector<T> divisor)
{
if (rightSide == null)
if (divisor == null)
{
throw new ArgumentNullException("rightSide");
throw new ArgumentNullException("divisor");
}
return rightSide.ModulusByThis(leftSide);
return divisor.ModulusByThis(dividend);
}
/// <summary>
/// Computes the pointwise modulus of each element of two <strong>vectors</strong>.
/// Computes the pointwise modulus of each element of two vectors.
/// </summary>
/// <param name="leftSide">The vector whose elements we want to compute the modulus of.</param>
/// <param name="rightSide">The divisor to use.</param>
/// <param name="dividend">The vector whose elements we want to compute the modulus of.</param>
/// <param name="divisor">The divisor to use.</param>
/// <returns>The result of the calculation</returns>
/// <exception cref="ArgumentException">If <paramref name="leftSide"/> and <paramref name="rightSide"/> are not the same size.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> is <see langword="null" />.</exception>
public static Vector<T> operator %(Vector<T> leftSide, Vector<T> rightSide)
/// <exception cref="ArgumentException">If <paramref name="dividend"/> and <paramref name="divisor"/> are not the same size.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="dividend"/> is <see langword="null" />.</exception>
public static Vector<T> operator %(Vector<T> dividend, Vector<T> divisor)
{
if (leftSide == null)
if (dividend == null)
{
throw new ArgumentNullException("leftSide");
throw new ArgumentNullException("dividend");
}
return leftSide.PointwiseModulus(rightSide);
return dividend.PointwiseModulus(divisor);
}
[SpecialName]
@ -335,15 +335,15 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
}
[SpecialName]
public static Vector<T> op_DotDivide(Vector<T> x, Vector<T> y)
public static Vector<T> op_DotDivide(Vector<T> dividend, Vector<T> divisor)
{
return x.PointwiseDivide(y);
return dividend.PointwiseDivide(divisor);
}
[SpecialName]
public static Vector<T> op_DotPercent(Vector<T> x, Vector<T> y)
public static Vector<T> op_DotPercent(Vector<T> dividend, Vector<T> divisor)
{
return x.PointwiseModulus(y);
return dividend.PointwiseModulus(divisor);
}
}
}

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

@ -630,18 +630,18 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// <summary>
/// Divides each element of the matrix by a scalar and places results into the result matrix.
/// </summary>
/// <param name="scalar">The scalar to divide the matrix with.</param>
/// <param name="divisor">The scalar to divide the matrix with.</param>
/// <param name="result">The matrix to store the result of the division.</param>
protected override void DoDivide(float scalar, Matrix<float> result)
protected override void DoDivide(float divisor, Matrix<float> result)
{
var denseResult = result as DenseMatrix;
if (denseResult == null)
{
base.DoDivide(scalar, result);
base.DoDivide(divisor, result);
}
else
{
Control.LinearAlgebraProvider.ScaleArray(1.0f/scalar, _values, denseResult._values);
Control.LinearAlgebraProvider.ScaleArray(1.0f/divisor, _values, denseResult._values);
}
}
@ -668,16 +668,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// <summary>
/// Pointwise divide this matrix by another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="other">The matrix to pointwise divide this one by.</param>
/// <param name="divisor">The matrix to pointwise divide this one by.</param>
/// <param name="result">The matrix to store the result of the pointwise division.</param>
protected override void DoPointwiseDivide(Matrix<float> other, Matrix<float> result)
protected override void DoPointwiseDivide(Matrix<float> divisor, Matrix<float> result)
{
var denseOther = other as DenseMatrix;
var denseOther = divisor as DenseMatrix;
var denseResult = result as DenseMatrix;
if (denseOther == null || denseResult == null)
{
base.DoPointwiseDivide(other, result);
base.DoPointwiseDivide(divisor, result);
}
else
{
@ -714,6 +714,30 @@ namespace MathNet.Numerics.LinearAlgebra.Single
});
}
/// <summary>
/// Computes the modulus for each element of the matrix.
/// </summary>
/// <param name="dividend">The scalar numerator to use.</param>
/// <param name="result">Matrix to store the results in.</param>
protected override void DoModulusByThis(float dividend, Matrix<float> result)
{
var denseResult = result as DenseMatrix;
if (denseResult == null)
{
base.DoModulusByThis(dividend, result);
return;
}
CommonParallel.For(0, _values.Length, 4096, (a, b) =>
{
var v = denseResult._values;
for (int i = a; i < b; i++)
{
v[i] = dividend%_values[i];
}
});
}
/// <summary>
/// Computes the trace of this matrix.
/// </summary>

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

@ -670,17 +670,17 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// <summary>
/// Pointwise divide this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise divide this one by.</param>
/// <param name="divisor">The vector to pointwise divide this one by.</param>
/// <param name="result">The vector to store the result of the pointwise division.</param>
/// <remarks></remarks>
protected override void DoPointwiseDivide(Vector<float> other, Vector<float> result)
protected override void DoPointwiseDivide(Vector<float> divisor, Vector<float> result)
{
var denseOther = other as DenseVector;
var denseOther = divisor as DenseVector;
var denseResult = result as DenseVector;
if (denseOther == null || denseResult == null)
{
base.DoPointwiseDivide(other, result);
base.DoPointwiseDivide(divisor, result);
}
else
{

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

@ -28,17 +28,18 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using MathNet.Numerics.Distributions;
using MathNet.Numerics.LinearAlgebra.Generic;
using MathNet.Numerics.LinearAlgebra.Storage;
using MathNet.Numerics.Properties;
using MathNet.Numerics.Threading;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace MathNet.Numerics.LinearAlgebra.Single
{
using Distributions;
using Generic;
using Properties;
using Storage;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
/// <summary>
/// A matrix type for diagonal matrices.
/// </summary>
@ -1020,28 +1021,49 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// <summary>
/// Computes the modulus for each element of the matrix.
/// </summary>
/// <param name="divisor">The divisor to use.</param>
/// <param name="divisor">The scalar denominator to use.</param>
/// <param name="result">Matrix to store the results in.</param>
protected override void DoModulus(float divisor, Matrix<float> result)
{
var denseResult = result as DiagonalMatrix;
if (denseResult == null)
var diagonalResult = result as DiagonalMatrix;
if (diagonalResult == null)
{
base.DoModulus(divisor, result);
return;
}
else
{
if (!ReferenceEquals(this, result))
{
CopyTo(result);
}
for (var index = 0; index < _data.Length; index++)
CommonParallel.For(0, _data.Length, 4096, (a, b) =>
{
denseResult._data[index] %= divisor;
}
var r = diagonalResult._data;
for (var i = a; i < b; i++)
{
r[i] = _data[i]%divisor;
}
});
}
/// <summary>
/// Computes the modulus for each element of the matrix.
/// </summary>
/// <param name="dividend">The scalar numerator to use.</param>
/// <param name="result">Matrix to store the results in.</param>
protected override void DoModulusByThis(float dividend, Matrix<float> result)
{
var diagonalResult = result as DiagonalMatrix;
if (diagonalResult == null)
{
base.DoModulusByThis(dividend, result);
return;
}
CommonParallel.For(0, _data.Length, 4096, (a, b) =>
{
var r = diagonalResult._data;
for (var i = a; i < b; i++)
{
r[i] = dividend%_data[i];
}
});
}
#region Static constructors for special matrices.

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

@ -242,25 +242,25 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// <summary>
/// Divides each element of the matrix by a scalar and places results into the result matrix.
/// </summary>
/// <param name="scalar">The scalar to divide the matrix with.</param>
/// <param name="divisor">The scalar to divide the matrix with.</param>
/// <param name="result">The matrix to store the result of the division.</param>
protected override void DoDivide(float scalar, Matrix<float> result)
protected override void DoDivide(float divisor, Matrix<float> result)
{
DoMultiply(1.0f / scalar, result);
DoMultiply(1.0f / divisor, result);
}
/// <summary>
/// Divides a scalar by each element of the matrix and stores the result in the result matrix.
/// </summary>
/// <param name="scalar">The scalar to add.</param>
/// <param name="dividend">The scalar to add.</param>
/// <param name="result">The matrix to store the result of the division.</param>
protected override void DoDivideByThis(float scalar, Matrix<float> result)
protected override void DoDivideByThis(float dividend, Matrix<float> result)
{
for (var i = 0; i < RowCount; i++)
{
for (var j = 0; j < ColumnCount; j++)
{
result.At(i, j, scalar / At(i, j));
result.At(i, j, dividend / At(i, j));
}
}
}
@ -331,7 +331,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// <summary>
/// Computes the modulus for each element of the matrix.
/// </summary>
/// <param name="divisor">The divisor to use.</param>
/// <param name="divisor">The scalar denominator to use.</param>
/// <param name="result">Matrix to store the results in.</param>
protected override void DoModulus(float divisor, Matrix<float> result)
{
@ -344,6 +344,22 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
}
/// <summary>
/// Computes the modulus for each element of the matrix.
/// </summary>
/// <param name="dividend">The scalar numerator to use.</param>
/// <param name="result">Matrix to store the results in.</param>
protected override void DoModulusByThis(float dividend, Matrix<float> result)
{
for (var row = 0; row < RowCount; row++)
{
for (var column = 0; column < ColumnCount; column++)
{
result.At(row, column, dividend % At(row, column));
}
}
}
/// <summary>
/// Negate each element of this matrix and place the results into the result matrix.
/// </summary>
@ -384,7 +400,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
{
for (var i = 0; i < RowCount; i++)
{
result.At(i, j, At(i, j) * other.At(i, j));
result.At(i, j, At(i, j)*other.At(i, j));
}
}
}
@ -392,15 +408,31 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// <summary>
/// Pointwise divide this matrix by another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="other">The matrix to pointwise divide this one by.</param>
/// <param name="divisor">The matrix to pointwise divide this one by.</param>
/// <param name="result">The matrix to store the result of the pointwise division.</param>
protected override void DoPointwiseDivide(Matrix<float> other, Matrix<float> result)
protected override void DoPointwiseDivide(Matrix<float> divisor, Matrix<float> result)
{
for (var j = 0; j < ColumnCount; j++)
{
for (var i = 0; i < RowCount; i++)
{
result.At(i, j, At(i, j)/divisor.At(i, j));
}
}
}
/// <summary>
/// Pointwise modulus this matrix with another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="divisor">The pointwise denominator matrix to use</param>
/// <param name="result">The result of the modulus.</param>
protected override void DoPointwiseModulus(Matrix<float> divisor, Matrix<float> result)
{
for (var j = 0; j < ColumnCount; j++)
{
for (var i = 0; i < RowCount; i++)
{
result.At(i, j, At(i, j) / other.At(i, j));
result.At(i, j, At(i, j)%divisor.At(i, j));
}
}
}

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

@ -997,9 +997,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// <summary>
/// Pointwise divide this matrix by another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="other">The matrix to pointwise divide this one by.</param>
/// <param name="divisor">The matrix to pointwise divide this one by.</param>
/// <param name="result">The matrix to store the result of the pointwise division.</param>
protected override void DoPointwiseDivide(Matrix<float> other, Matrix<float> result)
protected override void DoPointwiseDivide(Matrix<float> divisor, Matrix<float> result)
{
result.Clear();
@ -1018,7 +1018,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
{
if (values[j] != 0f)
{
result.At(i, columnIndices[j], values[j]/other.At(i, columnIndices[j]));
result.At(i, columnIndices[j], values[j]/divisor.At(i, columnIndices[j]));
}
}
}

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

@ -788,11 +788,11 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// <summary>
/// Pointwise multiplies this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise multiply with this one.</param>
/// <param name="divisor">The vector to pointwise multiply with this one.</param>
/// <param name="result">The vector to store the result of the pointwise multiplication.</param>
protected override void DoPointwiseDivide(Vector<float> other, Vector<float> result)
protected override void DoPointwiseDivide(Vector<float> divisor, Vector<float> result)
{
if (ReferenceEquals(this, other))
if (ReferenceEquals(this, divisor))
{
for (var i = 0; i < _storage.ValueCount; i++)
{
@ -804,7 +804,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
for (var i = 0; i < _storage.ValueCount; i++)
{
var index = _storage.Indices[i];
result.At(index, _storage.Values[i] / other.At(index));
result.At(index, _storage.Values[i] / divisor.At(index));
}
}
}

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

@ -134,27 +134,27 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// <summary>
/// Divides each element of the vector by a scalar and stores the result in the result vector.
/// </summary>
/// <param name="scalar">
/// <param name="divisor">
/// The scalar to divide with.
/// </param>
/// <param name="result">
/// The vector to store the result of the division.
/// </param>
protected override void DoDivide(float scalar, Vector<float> result)
protected override void DoDivide(float divisor, Vector<float> result)
{
DoMultiply(1 / scalar, result);
DoMultiply(1 / divisor, result);
}
/// <summary>
/// Divides a scalar by each element of the vector and stores the result in the result vector.
/// </summary>
/// <param name="scalar">The scalar to divide.</param>
/// <param name="dividend">The scalar to divide.</param>
/// <param name="result">The vector to store the result of the division.</param>
protected override void DoDivideByThis(float scalar, Vector<float> result)
protected override void DoDivideByThis(float dividend, Vector<float> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, scalar / At(index));
result.At(index, dividend / At(index));
}
}
@ -174,26 +174,26 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// <summary>
/// Pointwise divide this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise divide this one by.</param>
/// <param name="divisor">The vector to pointwise divide this one by.</param>
/// <param name="result">The vector to store the result of the pointwise division.</param>
protected override void DoPointwiseDivide(Vector<float> other, Vector<float> result)
protected override void DoPointwiseDivide(Vector<float> divisor, Vector<float> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, At(index) / other.At(index));
result.At(index, At(index) / divisor.At(index));
}
}
/// <summary>
/// Pointwise modulus this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise modulus this one by.</param>
/// <param name="divisor">The vector to pointwise modulus this one by.</param>
/// <param name="result">The result of the modulus.</param>
protected override void DoPointwiseModulus(Vector<float> other, Vector<float> result)
protected override void DoPointwiseModulus(Vector<float> divisor, Vector<float> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, At(index) % other.At(index));
result.At(index, At(index) % divisor.At(index));
}
}
@ -221,7 +221,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// <summary>
/// Computes the modulus for each element of the vector for the given divisor.
/// </summary>
/// <param name="divisor">The divisor to use.</param>
/// <param name="divisor">The scalar denominator to use.</param>
/// <param name="result">A vector to store the results in.</param>
protected override void DoModulus(float divisor, Vector<float> result)
{
@ -234,13 +234,13 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// <summary>
/// Computes the modulus for the given dividend for each element of the vector.
/// </summary>
/// <param name="scalar">The dividend to use.</param>
/// <param name="dividend">The scalar numerator to use.</param>
/// <param name="result">A vector to store the results in.</param>
protected override void DoModulusByThis(float scalar, Vector<float> result)
protected override void DoModulusByThis(float dividend, Vector<float> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, scalar % At(index));
result.At(index, dividend%At(index));
}
}

Loading…
Cancel
Save