Browse Source

Merge pull request #125 from tibel/vector_modulus

LA: add missing vector modulus operators
pull/130/head
Christoph Ruegg 13 years ago
parent
commit
f55cc8b928
  1. 20
      src/Numerics/LinearAlgebra/Complex/Vector.cs
  2. 20
      src/Numerics/LinearAlgebra/Complex32/Vector.cs
  3. 26
      src/Numerics/LinearAlgebra/Double/Vector.cs
  4. 157
      src/Numerics/LinearAlgebra/Generic/Vector.cs
  5. 26
      src/Numerics/LinearAlgebra/Single/Vector.cs

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

@ -185,6 +185,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
}
/// <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="result">The result of the modulus.</param>
protected override void DoPointwiseModulus(Vector<Complex> other, Vector<Complex> result)
{
throw new NotSupportedException();
}
/// <summary>
/// Computes the dot product between this vector and another vector.
/// </summary>
@ -216,6 +226,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
throw new NotSupportedException();
}
/// <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(Complex scalar, Vector<Complex> result)
{
throw new NotSupportedException();
}
/// <summary>
/// Returns the value of the absolute minimum element.
/// </summary>

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

@ -185,6 +185,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
}
/// <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="result">The result of the modulus.</param>
protected override void DoPointwiseModulus(Vector<Complex32> other, Vector<Complex32> result)
{
throw new NotSupportedException();
}
/// <summary>
/// Computes the dot product between this vector and another vector.
/// </summary>
@ -216,6 +226,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
throw new NotSupportedException();
}
/// <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(Complex32 scalar, Vector<Complex32> result)
{
throw new NotSupportedException();
}
/// <summary>
/// Returns the value of the absolute minimum element.
/// </summary>

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

@ -184,6 +184,32 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
}
/// <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="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)
{
for (var index = 0; index < Count; index++)
{
result.At(index, scalar % At(index));
}
}
/// <summary>
/// Computes the dot product between this vector and another vector.
/// </summary>

157
src/Numerics/LinearAlgebra/Generic/Vector.cs

@ -240,9 +240,16 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <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="scalar">The divisor to use.</param>
/// <param name="result">A vector to store the results in.</param>
protected abstract void DoModulus(T divisor, Vector<T> result);
protected abstract void DoModulus(T scalar, 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="result">A vector to store the results in.</param>
protected abstract void DoModulusByThis(T scalar, Vector<T> result);
/// <summary>
/// Pointwise multiplies this vector with another vector and stores the result into the result vector.
@ -258,6 +265,13 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <param name="result">The result of the division.</param>
protected abstract void DoPointwiseDivide(Vector<T> other, 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="result">The result of the modulus.</param>
protected abstract void DoPointwiseModulus(Vector<T> other, Vector<T> result);
/// <summary>
/// Adds a scalar to each element of the vector.
/// </summary>
@ -712,21 +726,21 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <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="scalar">The divisor to use.</param>
/// <returns>A vector containing the result.</returns>
public Vector<T> Modulus(T divisor)
public Vector<T> Modulus(T scalar)
{
var result = CreateVector(Count);
DoModulus(divisor, result);
DoModulus(scalar, result);
return result;
}
/// <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="scalar">The divisor to use.</param>
/// <param name="result">A vector to store the results in.</param>
public void Modulus(T divisor, Vector<T> result)
public void Modulus(T scalar, Vector<T> result)
{
if (result == null)
{
@ -738,7 +752,39 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
}
DoModulus(divisor, result);
DoModulus(scalar, result);
}
/// <summary>
/// Computes the modulus for the given dividend for each element of the vector.
/// </summary>
/// <param name="scalar">The dividend to use.</param>
/// <returns>A vector containing the result.</returns>
public Vector<T> ModulusByThis(T scalar)
{
var result = CreateVector(Count);
DoModulusByThis(scalar, result);
return 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="result">A vector to store the results in.</param>
public void ModulusByThis(T scalar, Vector<T> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (Count != result.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
}
DoModulusByThis(scalar, result);
}
/// <summary>
@ -857,6 +903,64 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
DoPointwiseDivide(other, result);
}
/// <summary>
/// Pointwise modulus this vector with another vector.
/// </summary>
/// <param name="other">The vector to pointwise modulus this one by.</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)
{
if (other == null)
{
throw new ArgumentNullException("other");
}
if (Count != other.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "other");
}
var result = CreateVector(Count);
DoPointwiseModulus(other, 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="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="result"/> are not the same size.</exception>
public void PointwiseModulus(Vector<T> other, Vector<T> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (other == null)
{
throw new ArgumentNullException("other");
}
if (Count != other.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "other");
}
if (Count != result.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
}
DoPointwiseModulus(other, result);
}
/// <summary>
/// Outer product of two vectors
/// </summary>
@ -1145,7 +1249,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// 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="rightSide">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)
@ -1158,6 +1262,41 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
return leftSide.Modulus(rightSide);
}
/// <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>
/// <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)
{
if (rightSide == null)
{
throw new ArgumentNullException("rightSide");
}
return rightSide.ModulusByThis(leftSide);
}
/// <summary>
/// Computes the pointwise modulus of each element of two <strong>vectors</strong>.
/// </summary>
/// <param name="leftSide">The vector whose elements we want to compute the modulus of.</param>
/// <param name="rightSide">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)
{
if (leftSide == null)
{
throw new ArgumentNullException("leftSide");
}
return leftSide.PointwiseModulus(rightSide);
}
/// <summary>
/// Computes the p-Norm.
/// </summary>

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

@ -184,6 +184,19 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
}
/// <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="result">The result of the modulus.</param>
protected override void DoPointwiseModulus(Vector<float> other, Vector<float> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, At(index) % other.At(index));
}
}
/// <summary>
/// Computes the dot product between this vector and another vector.
/// </summary>
@ -218,6 +231,19 @@ 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="result">A vector to store the results in.</param>
protected override void DoModulusByThis(float scalar, Vector<float> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, scalar % At(index));
}
}
/// <summary>
/// Returns the value of the absolute minimum element.
/// </summary>

Loading…
Cancel
Save