Browse Source

add Vector.DivideByThis(scalar)

pull/124/head
tibel 13 years ago
parent
commit
62f745884b
  1. 13
      src/Numerics/LinearAlgebra/Complex/Vector.cs
  2. 13
      src/Numerics/LinearAlgebra/Complex32/Vector.cs
  3. 13
      src/Numerics/LinearAlgebra/Double/Vector.cs
  4. 76
      src/Numerics/LinearAlgebra/Generic/Vector.cs
  5. 13
      src/Numerics/LinearAlgebra/Single/Vector.cs

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

@ -146,6 +146,19 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
DoMultiply(1 / scalar, 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="result">The vector to store the result of the division.</param>
protected override void DoDivideByThis(Complex scalar, Vector<Complex> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, scalar / At(index));
}
}
/// <summary>
/// Pointwise multiplies this vector with another vector and stores the result into the result vector.
/// </summary>

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

@ -146,6 +146,19 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
DoMultiply(1 / scalar, 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="result">The vector to store the result of the division.</param>
protected override void DoDivideByThis(Complex32 scalar, Vector<Complex32> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, scalar / At(index));
}
}
/// <summary>
/// Pointwise multiplies this vector with another vector and stores the result into the result vector.
/// </summary>

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

@ -145,6 +145,19 @@ namespace MathNet.Numerics.LinearAlgebra.Double
DoMultiply(1 / scalar, 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="result">The vector to store the result of the division.</param>
protected override void DoDivideByThis(double scalar, Vector<double> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, scalar / At(index));
}
}
/// <summary>
/// Pointwise multiplies this vector with another vector and stores the result into the result vector.
/// </summary>

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

@ -230,6 +230,13 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <param name="result">The vector to store the result of the division.</param>
protected abstract void DoDivide(T scalar, 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="result">The vector to store the result of the division.</param>
protected abstract void DoDivideByThis(T scalar, Vector<T> result);
/// <summary>
/// Computes the modulus for each element of the vector for the given divisor.
/// </summary>
@ -668,6 +675,40 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
DoDivide(scalar, result);
}
/// <summary>
/// Divides a scalar by each element of the vector.
/// </summary>
/// <param name="scalar">The scalar to divide.</param>
/// <returns>A new vector that is the division of the vector and the scalar.</returns>
public Vector<T> DevideByThis(T scalar)
{
var result = CreateVector(Count);
DoDivideByThis(scalar, result);
return 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="result">The vector to store the result of the division.</param>
/// <exception cref="ArgumentNullException">If the result vector is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException">If this vector and <paramref name="result"/> are not the same size.</exception>
public void DivideByThis(T scalar, Vector<T> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (Count != result.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
}
DoDivideByThis(scalar, result);
}
/// <summary>
/// Computes the modulus for each element of the vector for the given divisor.
/// </summary>
@ -1048,6 +1089,23 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
return leftSide.DotProduct(rightSide);
}
/// <summary>
/// Divides a scalar with a vector.
/// </summary>
/// <param name="leftSide">The scalar to divide.</param>
/// <param name="rightSide">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)
{
if (rightSide == null)
{
throw new ArgumentNullException("rightSide");
}
return rightSide.DevideByThis(leftSide);
}
/// <summary>
/// Divides a vector with a scalar.
/// </summary>
@ -1065,6 +1123,24 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
return leftSide.Divide(rightSide);
}
/// <summary>
/// Pointwise divides two <strong>Vectors</strong>.
/// </summary>
/// <param name="leftSide">The vector to divide.</param>
/// <param name="rightSide">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)
{
if (leftSide == null)
{
throw new ArgumentNullException("leftSide");
}
return leftSide.PointwiseDivide(rightSide);
}
/// <summary>
/// Computes the modulus of each element of the vector of the given divisor.
/// </summary>

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

@ -145,6 +145,19 @@ namespace MathNet.Numerics.LinearAlgebra.Single
DoMultiply(1 / scalar, 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="result">The vector to store the result of the division.</param>
protected override void DoDivideByThis(float scalar, Vector<float> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, scalar / At(index));
}
}
/// <summary>
/// Pointwise multiplies this vector with another vector and stores the result into the result vector.
/// </summary>

Loading…
Cancel
Save