Browse Source

LA: Matrix pointwise power, exponential and natural logarithm #205

provider
Christoph Ruegg 13 years ago
parent
commit
636920cca0
  1. 30
      src/Numerics/LinearAlgebra/Complex/Matrix.cs
  2. 28
      src/Numerics/LinearAlgebra/Complex32/Matrix.cs
  3. 28
      src/Numerics/LinearAlgebra/Double/Matrix.cs
  4. 95
      src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs
  5. 28
      src/Numerics/LinearAlgebra/Single/Matrix.cs

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

@ -108,7 +108,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// <summary> /// <summary>
/// Returns the conjugate transpose of this matrix. /// Returns the conjugate transpose of this matrix.
/// </summary> /// </summary>
/// <returns>The conjugate transpose of this matrix.</returns> /// <returns>The conjugate transpose of this matrix.</returns>
public override Matrix<Complex> ConjugateTranspose() public override Matrix<Complex> ConjugateTranspose()
{ {
@ -454,6 +454,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
} }
} }
/// <summary>
/// Pointwise raise this matrix to an exponent and store the result into the result vector.
/// </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(Complex exponent, Matrix<Complex> result)
{
Map(x => x.Power(exponent), result, forceMapZeros: false);
}
/// <summary> /// <summary>
/// Pointwise canonical modulus, where the result has the sign of the divisor, /// Pointwise canonical modulus, where the result has the sign of the divisor,
/// of this matrix with another matrix and stores the result into the result matrix. /// of this matrix with another matrix and stores the result into the result matrix.
@ -520,6 +530,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
throw new NotSupportedException(); throw new NotSupportedException();
} }
/// <summary>
/// Pointwise applies the exponential function to each value and stores the result into the result matrix.
/// </summary>
/// <param name="result">The matrix to store the result.</param>
protected override void DoPointwiseExp(Matrix<Complex> result)
{
Map(Complex.Exp, result, forceMapZeros: true);
}
/// <summary>
/// Pointwise applies the natural logarithm function to each value and stores the result into the result matrix.
/// </summary>
/// <param name="result">The matrix to store the result.</param>
protected override void DoPointwiseLog(Matrix<Complex> result)
{
Map(Complex.Log, result, forceMapZeros: true);
}
/// <summary> /// <summary>
/// Computes the trace of this matrix. /// Computes the trace of this matrix.
/// </summary> /// </summary>

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

@ -448,6 +448,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
} }
} }
/// <summary>
/// Pointwise raise this matrix to an exponent and store the result into the result vector.
/// </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(Complex32 exponent, Matrix<Complex32> result)
{
Map(x => x.Power(exponent), result, forceMapZeros: false);
}
/// <summary> /// <summary>
/// Pointwise canonical modulus, where the result has the sign of the divisor, /// Pointwise canonical modulus, where the result has the sign of the divisor,
/// of this matrix with another matrix and stores the result into the result matrix. /// of this matrix with another matrix and stores the result into the result matrix.
@ -514,6 +524,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
throw new NotSupportedException(); throw new NotSupportedException();
} }
/// <summary>
/// Pointwise applies the exponential function to each value and stores the result into the result matrix.
/// </summary>
/// <param name="result">The matrix to store the result.</param>
protected override void DoPointwiseExp(Matrix<Complex32> result)
{
Map(Complex32.Exp, result, forceMapZeros: true);
}
/// <summary>
/// Pointwise applies the natural logarithm function to each value and stores the result into the result matrix.
/// </summary>
/// <param name="result">The matrix to store the result.</param>
protected override void DoPointwiseLog(Matrix<Complex32> result)
{
Map(Complex32.Log, result, forceMapZeros: true);
}
/// <summary> /// <summary>
/// Computes the trace of this matrix. /// Computes the trace of this matrix.
/// </summary> /// </summary>

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

@ -475,6 +475,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double
} }
} }
/// <summary>
/// Pointwise raise this matrix to an exponent and store the result into the result vector.
/// </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(double exponent, Matrix<double> result)
{
Map(x => Math.Pow(x, exponent), result, forceMapZeros: false);
}
/// <summary> /// <summary>
/// Pointwise canonical modulus, where the result has the sign of the divisor, /// Pointwise canonical modulus, where the result has the sign of the divisor,
/// of this matrix with another matrix and stores the result into the result matrix. /// of this matrix with another matrix and stores the result into the result matrix.
@ -509,6 +519,24 @@ namespace MathNet.Numerics.LinearAlgebra.Double
} }
} }
/// <summary>
/// Pointwise applies the exponential function to each value and stores the result into the result matrix.
/// </summary>
/// <param name="result">The matrix to store the result.</param>
protected override void DoPointwiseExp(Matrix<double> result)
{
Map(Math.Exp, result, forceMapZeros: true);
}
/// <summary>
/// Pointwise applies the natural logarithm function to each value and stores the result into the result matrix.
/// </summary>
/// <param name="result">The matrix to store the result.</param>
protected override void DoPointwiseLog(Matrix<double> result)
{
Map(Math.Log, result, forceMapZeros: true);
}
/// <summary> /// <summary>
/// Computes the trace of this matrix. /// Computes the trace of this matrix.
/// </summary> /// </summary>

95
src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs

@ -224,6 +224,13 @@ namespace MathNet.Numerics.LinearAlgebra
/// <param name="result">The matrix to store the result of the pointwise division.</param> /// <param name="result">The matrix to store the result of the pointwise division.</param>
protected abstract void DoPointwiseDivide(Matrix<T> divisor, Matrix<T> result); protected abstract void DoPointwiseDivide(Matrix<T> divisor, Matrix<T> result);
/// <summary>
/// Pointwise raise this matrix to an exponent and store the result into the result vector.
/// </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 abstract void DoPointwisePower(T exponent, Matrix<T> result);
/// <summary> /// <summary>
/// Pointwise canonical modulus, where the result has the sign of the divisor, /// Pointwise canonical modulus, where the result has the sign of the divisor,
/// of this matrix with another matrix and stores the result into the result matrix. /// of this matrix with another matrix and stores the result into the result matrix.
@ -240,6 +247,18 @@ namespace MathNet.Numerics.LinearAlgebra
/// <param name="result">The result of the modulus.</param> /// <param name="result">The result of the modulus.</param>
protected abstract void DoPointwiseRemainder(Matrix<T> divisor, Matrix<T> result); protected abstract void DoPointwiseRemainder(Matrix<T> divisor, Matrix<T> result);
/// <summary>
/// Pointwise applies the exponential function to each value and stores the result into the result matrix.
/// </summary>
/// <param name="result">The matrix to store the result.</param>
protected abstract void DoPointwiseExp(Matrix<T> result);
/// <summary>
/// Pointwise applies the natural logarithm function to each value and stores the result into the result matrix.
/// </summary>
/// <param name="result">The matrix to store the result.</param>
protected abstract void DoPointwiseLog(Matrix<T> result);
/// <summary> /// <summary>
/// Adds a scalar to each element of the matrix. /// Adds a scalar to each element of the matrix.
/// </summary> /// </summary>
@ -1233,6 +1252,32 @@ namespace MathNet.Numerics.LinearAlgebra
DoPointwiseDivide(divisor, result); DoPointwiseDivide(divisor, result);
} }
/// <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>
public Matrix<T> PointwisePower(T exponent)
{
var result = Build.SameAs(this);
DoPointwisePower(exponent, result);
return result;
}
/// <summary>
/// Pointwise raise this matrix to an exponent.
/// </summary>
/// <param name="exponent">The exponent to raise this matrix values to.</param>
/// <exception cref="ArgumentException">If this matrix and <paramref name="result"/> are not the same size.</exception>
public void PointwisePower(T exponent, Matrix<T> result)
{
if (ColumnCount != result.ColumnCount || RowCount != result.RowCount)
{
throw DimensionsDontMatch<ArgumentException>(this, result);
}
DoPointwisePower(exponent, result);
}
/// <summary> /// <summary>
/// Pointwise canonical modulus, where the result has the sign of the divisor, /// Pointwise canonical modulus, where the result has the sign of the divisor,
/// of this matrix by another matrix. /// of this matrix by another matrix.
@ -1305,6 +1350,56 @@ namespace MathNet.Numerics.LinearAlgebra
DoPointwiseRemainder(divisor, result); DoPointwiseRemainder(divisor, result);
} }
/// <summary>
/// Pointwise applies the exponent function to each value.
/// </summary>
public Matrix<T> PointwiseExp()
{
var result = Build.SameAs(this);
DoPointwiseExp(result);
return result;
}
/// <summary>
/// Pointwise applies the exponent function to each value.
/// </summary>
/// <param name="result">The matrix to store the result.</param>
/// <exception cref="ArgumentException">If this matrix and <paramref name="result"/> are not the same size.</exception>
public void PointwiseExp(Matrix<T> result)
{
if (ColumnCount != result.ColumnCount || RowCount != result.RowCount)
{
throw DimensionsDontMatch<ArgumentException>(this, result);
}
DoPointwiseExp(result);
}
/// <summary>
/// Pointwise applies the natural logarithm function to each value.
/// </summary>
public Matrix<T> PointwiseLog()
{
var result = Build.SameAs(this);
DoPointwiseLog(result);
return result;
}
/// <summary>
/// Pointwise applies the natural logarithm function to each value.
/// </summary>
/// <param name="result">The matrix to store the result.</param>
/// <exception cref="ArgumentException">If this matrix and <paramref name="result"/> are not the same size.</exception>
public void PointwiseLog(Matrix<T> result)
{
if (ColumnCount != result.ColumnCount || RowCount != result.RowCount)
{
throw DimensionsDontMatch<ArgumentException>(this, result);
}
DoPointwiseLog(result);
}
/// <summary> /// <summary>
/// Computes the trace of this matrix. /// Computes the trace of this matrix.
/// </summary> /// </summary>

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

@ -475,6 +475,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single
} }
} }
/// <summary>
/// Pointwise raise this matrix to an exponent and store the result into the result vector.
/// </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(float exponent, Matrix<float> result)
{
Map(x => (float)Math.Pow(x, exponent), result, forceMapZeros: false);
}
/// <summary> /// <summary>
/// Pointwise canonical modulus, where the result has the sign of the divisor, /// Pointwise canonical modulus, where the result has the sign of the divisor,
/// of this matrix with another matrix and stores the result into the result matrix. /// of this matrix with another matrix and stores the result into the result matrix.
@ -509,6 +519,24 @@ namespace MathNet.Numerics.LinearAlgebra.Single
} }
} }
/// <summary>
/// Pointwise applies the exponential function to each value and stores the result into the result matrix.
/// </summary>
/// <param name="result">The matrix to store the result.</param>
protected override void DoPointwiseExp(Matrix<float> result)
{
Map(x => (float)Math.Exp(x), result, forceMapZeros: true);
}
/// <summary>
/// Pointwise applies the natural logarithm function to each value and stores the result into the result matrix.
/// </summary>
/// <param name="result">The matrix to store the result.</param>
protected override void DoPointwiseLog(Matrix<float> result)
{
Map(x => (float)Math.Log(x), result, forceMapZeros: true);
}
/// <summary> /// <summary>
/// Computes the trace of this matrix. /// Computes the trace of this matrix.
/// </summary> /// </summary>

Loading…
Cancel
Save