Browse Source

LA: bind matrix dot-power with matrix exponent to provider

benchmark-la
Christoph Ruegg 10 years ago
parent
commit
f8012bca55
  1. 26
      src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
  2. 26
      src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
  3. 26
      src/Numerics/LinearAlgebra/Double/DenseMatrix.cs
  4. 20
      src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
  5. 12
      src/Numerics/Providers/LinearAlgebra/ILinearAlgebraProvider.cs
  6. 41
      src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs
  7. 41
      src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs
  8. 41
      src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs
  9. 41
      src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs

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

@ -974,16 +974,36 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// <param name="result">The matrix to store the result of the pointwise division.</param>
protected override void DoPointwiseDivide(Matrix<Complex> divisor, Matrix<Complex> result)
{
var denseOther = divisor as DenseMatrix;
var denseDivisor = divisor as DenseMatrix;
var denseResult = result as DenseMatrix;
if (denseOther == null || denseResult == null)
if (denseDivisor == null || denseResult == null)
{
base.DoPointwiseDivide(divisor, result);
}
else
{
Control.LinearAlgebraProvider.PointWiseDivideArrays(_values, denseOther._values, denseResult._values);
Control.LinearAlgebraProvider.PointWiseDivideArrays(_values, denseDivisor._values, denseResult._values);
}
}
/// <summary>
/// Pointwise raise this matrix to an exponent and store the result into the result matrix.
/// </summary>
/// <param name="exponent">The exponent to raise this matrix values to.</param>
/// <param name="result">The vector to store the result of the pointwise power.</param>
protected override void DoPointwisePower(Matrix<Complex> exponent, Matrix<Complex> result)
{
var denseExponent = exponent as DenseMatrix;
var denseResult = result as DenseMatrix;
if (denseExponent == null || denseResult == null)
{
base.DoPointwisePower(exponent, result);
}
else
{
Control.LinearAlgebraProvider.PointWisePowerArrays(_values, denseExponent._values, denseResult._values);
}
}

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

@ -971,16 +971,36 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// <param name="result">The matrix to store the result of the pointwise division.</param>
protected override void DoPointwiseDivide(Matrix<Complex32> divisor, Matrix<Complex32> result)
{
var denseOther = divisor as DenseMatrix;
var denseDivisor = divisor as DenseMatrix;
var denseResult = result as DenseMatrix;
if (denseOther == null || denseResult == null)
if (denseDivisor == null || denseResult == null)
{
base.DoPointwiseDivide(divisor, result);
}
else
{
Control.LinearAlgebraProvider.PointWiseDivideArrays(_values, denseOther._values, denseResult._values);
Control.LinearAlgebraProvider.PointWiseDivideArrays(_values, denseDivisor._values, denseResult._values);
}
}
/// <summary>
/// Pointwise raise this matrix to an exponent and store the result into the result matrix.
/// </summary>
/// <param name="exponent">The exponent to raise this matrix values to.</param>
/// <param name="result">The vector to store the result of the pointwise power.</param>
protected override void DoPointwisePower(Matrix<Complex32> exponent, Matrix<Complex32> result)
{
var denseExponent = exponent as DenseMatrix;
var denseResult = result as DenseMatrix;
if (denseExponent == null || denseResult == null)
{
base.DoPointwisePower(exponent, result);
}
else
{
Control.LinearAlgebraProvider.PointWisePowerArrays(_values, denseExponent._values, denseResult._values);
}
}

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

@ -817,16 +817,36 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// <param name="result">The matrix to store the result of the pointwise division.</param>
protected override void DoPointwiseDivide(Matrix<double> divisor, Matrix<double> result)
{
var denseOther = divisor as DenseMatrix;
var denseDivisor = divisor as DenseMatrix;
var denseResult = result as DenseMatrix;
if (denseOther == null || denseResult == null)
if (denseDivisor == null || denseResult == null)
{
base.DoPointwiseDivide(divisor, result);
}
else
{
Control.LinearAlgebraProvider.PointWiseDivideArrays(_values, denseOther._values, denseResult._values);
Control.LinearAlgebraProvider.PointWiseDivideArrays(_values, denseDivisor._values, denseResult._values);
}
}
/// <summary>
/// Pointwise raise this matrix to an exponent and store the result into the result matrix.
/// </summary>
/// <param name="exponent">The exponent to raise this matrix values to.</param>
/// <param name="result">The vector to store the result of the pointwise power.</param>
protected override void DoPointwisePower(Matrix<double> exponent, Matrix<double> result)
{
var denseExponent = exponent as DenseMatrix;
var denseResult = result as DenseMatrix;
if (denseExponent == null || denseResult == null)
{
base.DoPointwisePower(exponent, result);
}
else
{
Control.LinearAlgebraProvider.PointWisePowerArrays(_values, denseExponent._values, denseResult._values);
}
}

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

@ -830,6 +830,26 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
}
/// <summary>
/// Pointwise raise this matrix to an exponent and store the result into the result matrix.
/// </summary>
/// <param name="exponent">The exponent to raise this matrix values to.</param>
/// <param name="result">The vector to store the result of the pointwise power.</param>
protected override void DoPointwisePower(Matrix<float> exponent, Matrix<float> result)
{
var denseExponent = exponent as DenseMatrix;
var denseResult = result as DenseMatrix;
if (denseExponent == null || denseResult == null)
{
base.DoPointwisePower(exponent, result);
}
else
{
Control.LinearAlgebraProvider.PointWisePowerArrays(_values, denseExponent._values, denseResult._values);
}
}
/// <summary>
/// Computes the canonical modulus, where the result has the sign of the divisor,
/// for the given divisor each element of the matrix.

12
src/Numerics/Providers/LinearAlgebra/ILinearAlgebraProvider.cs

@ -204,6 +204,18 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
/// routine.</remarks>
void PointWiseDivideArrays(T[] x, T[] y, T[] result);
/// <summary>
/// Does a point wise power of two arrays <c>z = x ^ y</c>. This can be used
/// to raise elements of vectors or matrices to the powers of another vector or matrix.
/// </summary>
/// <param name="x">The array x.</param>
/// <param name="y">The array y.</param>
/// <param name="result">The result of the point wise power.</param>
/// <remarks>There is no equivalent BLAS routine, but many libraries
/// provide optimized (parallel and/or vectorized) versions of this
/// routine.</remarks>
void PointWisePowerArrays(T[] x, T[] y, T[] result);
/// <summary>
/// Computes the requested <see cref="Norm"/> of the matrix.
/// </summary>

41
src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs

@ -353,6 +353,47 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
});
}
/// <summary>
/// Does a point wise power of two arrays <c>z = x ^ y</c>. This can be used
/// to raise elements of vectors or matrices to the powers of another vector or matrix.
/// </summary>
/// <param name="x">The array x.</param>
/// <param name="y">The array y.</param>
/// <param name="result">The result of the point wise power.</param>
/// <remarks>There is no equivalent BLAS routine, but many libraries
/// provide optimized (parallel and/or vectorized) versions of this
/// routine.</remarks>
public virtual void PointWisePowerArrays(Complex[] x, Complex[] y, Complex[] result)
{
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (result == null)
{
throw new ArgumentNullException("result");
}
if (y.Length != x.Length || y.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength);
}
CommonParallel.For(0, y.Length, 4096, (a, b) =>
{
for (int i = a; i < b; i++)
{
result[i] = Complex.Pow(x[i], y[i]);
}
});
}
/// <summary>
/// Computes the requested <see cref="Norm"/> of the matrix.
/// </summary>

41
src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs

@ -351,6 +351,47 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
});
}
/// <summary>
/// Does a point wise power of two arrays <c>z = x ^ y</c>. This can be used
/// to raise elements of vectors or matrices to the powers of another vector or matrix.
/// </summary>
/// <param name="x">The array x.</param>
/// <param name="y">The array y.</param>
/// <param name="result">The result of the point wise power.</param>
/// <remarks>There is no equivalent BLAS routine, but many libraries
/// provide optimized (parallel and/or vectorized) versions of this
/// routine.</remarks>
public virtual void PointWisePowerArrays(Complex32[] x, Complex32[] y, Complex32[] result)
{
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (result == null)
{
throw new ArgumentNullException("result");
}
if (y.Length != x.Length || y.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength);
}
CommonParallel.For(0, y.Length, 4096, (a, b) =>
{
for (int i = a; i < b; i++)
{
result[i] = Complex32.Pow(x[i], y[i]);
}
});
}
/// <summary>
/// Computes the requested <see cref="Norm"/> of the matrix.
/// </summary>

41
src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs

@ -345,6 +345,47 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
});
}
/// <summary>
/// Does a point wise power of two arrays <c>z = x ^ y</c>. This can be used
/// to raise elements of vectors or matrices to the powers of another vector or matrix.
/// </summary>
/// <param name="x">The array x.</param>
/// <param name="y">The array y.</param>
/// <param name="result">The result of the point wise power.</param>
/// <remarks>There is no equivalent BLAS routine, but many libraries
/// provide optimized (parallel and/or vectorized) versions of this
/// routine.</remarks>
public virtual void PointWisePowerArrays(double[] x, double[] y, double[] result)
{
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (result == null)
{
throw new ArgumentNullException("result");
}
if (y.Length != x.Length || y.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength);
}
CommonParallel.For(0, y.Length, 4096, (a, b) =>
{
for (int i = a; i < b; i++)
{
result[i] = Math.Pow(x[i], y[i]);
}
});
}
/// <summary>
/// Computes the requested <see cref="Norm"/> of the matrix.
/// </summary>

41
src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs

@ -345,6 +345,47 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
});
}
/// <summary>
/// Does a point wise power of two arrays <c>z = x ^ y</c>. This can be used
/// to raise elements of vectors or matrices to the powers of another vector or matrix.
/// </summary>
/// <param name="x">The array x.</param>
/// <param name="y">The array y.</param>
/// <param name="result">The result of the point wise power.</param>
/// <remarks>There is no equivalent BLAS routine, but many libraries
/// provide optimized (parallel and/or vectorized) versions of this
/// routine.</remarks>
public virtual void PointWisePowerArrays(float[] x, float[] y, float[] result)
{
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (result == null)
{
throw new ArgumentNullException("result");
}
if (y.Length != x.Length || y.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength);
}
CommonParallel.For(0, y.Length, 4096, (a, b) =>
{
for (int i = a; i < b; i++)
{
result[i] = (float)Math.Pow(x[i], y[i]);
}
});
}
/// <summary>
/// Computes the requested <see cref="Norm"/> of the matrix.
/// </summary>

Loading…
Cancel
Save