Browse Source

added the 'optimized' version of Multiply(scale) from Double.SparseVector to the other three SparseVectors

la-knuth
Marcus Cuda 14 years ago
committed by Christoph Ruegg
parent
commit
0c1b688a62
  1. 22
      src/Numerics/LinearAlgebra/Complex/SparseVector.cs
  2. 22
      src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
  3. 22
      src/Numerics/LinearAlgebra/Single/SparseVector.cs

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

@ -706,6 +706,28 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return result; return result;
} }
/// <summary>
/// Multiplies a scalar to each element of the vector.
/// </summary>
/// <param name="scalar">The scalar to multiply.</param>
/// <returns>A new vector that is the multiplication of the vector and the scalar.</returns>
public override Vector<Complex> Multiply(Complex scalar)
{
if (scalar == Complex.One)
{
return Clone();
}
if (scalar == Complex.Zero)
{
return new SparseVector(Count);
}
var copy = new SparseVector(this);
Control.LinearAlgebraProvider.ScaleArray(scalar, copy._nonZeroValues, copy._nonZeroValues);
return copy;
}
/// <summary> /// <summary>
/// Multiplies a scalar to each element of the vector and stores the result in the result vector. /// Multiplies a scalar to each element of the vector and stores the result in the result vector.
/// </summary> /// </summary>

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

@ -736,6 +736,28 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return result; return result;
} }
/// <summary>
/// Multiplies a scalar to each element of the vector.
/// </summary>
/// <param name="scalar">The scalar to multiply.</param>
/// <returns>A new vector that is the multiplication of the vector and the scalar.</returns>
public override Vector<Complex32> Multiply(Complex32 scalar)
{
if (scalar == Complex32.One)
{
return Clone();
}
if (scalar == Complex32.Zero)
{
return new SparseVector(Count);
}
var copy = new SparseVector(this);
Control.LinearAlgebraProvider.ScaleArray(scalar, copy._nonZeroValues, copy._nonZeroValues);
return copy;
}
/// <summary> /// <summary>
/// Multiplies a scalar to each element of the vector and stores the result in the result vector. /// Multiplies a scalar to each element of the vector and stores the result in the result vector.
/// </summary> /// </summary>

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

@ -688,6 +688,28 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return result; return result;
} }
/// <summary>
/// Multiplies a scalar to each element of the vector.
/// </summary>
/// <param name="scalar">The scalar to multiply.</param>
/// <returns>A new vector that is the multiplication of the vector and the scalar.</returns>
public override Vector<float> Multiply(float scalar)
{
if (scalar == 1.0f)
{
return Clone();
}
if (scalar == 0f)
{
return new SparseVector(Count);
}
var copy = new SparseVector(this);
Control.LinearAlgebraProvider.ScaleArray(scalar, copy._nonZeroValues, copy._nonZeroValues);
return copy;
}
/// <summary> /// <summary>
/// Multiplies a scalar to each element of the vector and stores the result in the result vector. /// Multiplies a scalar to each element of the vector and stores the result in the result vector.
/// </summary> /// </summary>

Loading…
Cancel
Save