diff --git a/src/Numerics/LinearAlgebra/Complex/Matrix.cs b/src/Numerics/LinearAlgebra/Complex/Matrix.cs index ea61d027..1e16da7f 100644 --- a/src/Numerics/LinearAlgebra/Complex/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Complex/Matrix.cs @@ -108,7 +108,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// /// Returns the conjugate transpose of this matrix. - /// + /// /// The conjugate transpose of this matrix. public override Matrix ConjugateTranspose() { @@ -454,6 +454,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex } } + /// + /// Pointwise raise this matrix to an exponent and store the result into the result vector. + /// + /// The exponent to raise this matrix values to. + /// The vector to store the result of the pointwise power. + protected override void DoPointwisePower(Complex exponent, Matrix result) + { + Map(x => x.Power(exponent), result, forceMapZeros: false); + } + /// /// 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. @@ -520,6 +530,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex throw new NotSupportedException(); } + /// + /// Pointwise applies the exponential function to each value and stores the result into the result matrix. + /// + /// The matrix to store the result. + protected override void DoPointwiseExp(Matrix result) + { + Map(Complex.Exp, result, forceMapZeros: true); + } + + /// + /// Pointwise applies the natural logarithm function to each value and stores the result into the result matrix. + /// + /// The matrix to store the result. + protected override void DoPointwiseLog(Matrix result) + { + Map(Complex.Log, result, forceMapZeros: true); + } + /// /// Computes the trace of this matrix. /// diff --git a/src/Numerics/LinearAlgebra/Complex32/Matrix.cs b/src/Numerics/LinearAlgebra/Complex32/Matrix.cs index c4589e0b..78471bcb 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Matrix.cs @@ -448,6 +448,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 } } + /// + /// Pointwise raise this matrix to an exponent and store the result into the result vector. + /// + /// The exponent to raise this matrix values to. + /// The vector to store the result of the pointwise power. + protected override void DoPointwisePower(Complex32 exponent, Matrix result) + { + Map(x => x.Power(exponent), result, forceMapZeros: false); + } + /// /// 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. @@ -514,6 +524,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 throw new NotSupportedException(); } + /// + /// Pointwise applies the exponential function to each value and stores the result into the result matrix. + /// + /// The matrix to store the result. + protected override void DoPointwiseExp(Matrix result) + { + Map(Complex32.Exp, result, forceMapZeros: true); + } + + /// + /// Pointwise applies the natural logarithm function to each value and stores the result into the result matrix. + /// + /// The matrix to store the result. + protected override void DoPointwiseLog(Matrix result) + { + Map(Complex32.Log, result, forceMapZeros: true); + } + /// /// Computes the trace of this matrix. /// diff --git a/src/Numerics/LinearAlgebra/Double/Matrix.cs b/src/Numerics/LinearAlgebra/Double/Matrix.cs index 220d00f2..d61aa3a1 100644 --- a/src/Numerics/LinearAlgebra/Double/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Double/Matrix.cs @@ -475,6 +475,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double } } + /// + /// Pointwise raise this matrix to an exponent and store the result into the result vector. + /// + /// The exponent to raise this matrix values to. + /// The vector to store the result of the pointwise power. + protected override void DoPointwisePower(double exponent, Matrix result) + { + Map(x => Math.Pow(x, exponent), result, forceMapZeros: false); + } + /// /// 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. @@ -509,6 +519,24 @@ namespace MathNet.Numerics.LinearAlgebra.Double } } + /// + /// Pointwise applies the exponential function to each value and stores the result into the result matrix. + /// + /// The matrix to store the result. + protected override void DoPointwiseExp(Matrix result) + { + Map(Math.Exp, result, forceMapZeros: true); + } + + /// + /// Pointwise applies the natural logarithm function to each value and stores the result into the result matrix. + /// + /// The matrix to store the result. + protected override void DoPointwiseLog(Matrix result) + { + Map(Math.Log, result, forceMapZeros: true); + } + /// /// Computes the trace of this matrix. /// diff --git a/src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs b/src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs index 1eede533..5ef604b2 100644 --- a/src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs +++ b/src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs @@ -224,6 +224,13 @@ namespace MathNet.Numerics.LinearAlgebra /// The matrix to store the result of the pointwise division. protected abstract void DoPointwiseDivide(Matrix divisor, Matrix result); + /// + /// Pointwise raise this matrix to an exponent and store the result into the result vector. + /// + /// The exponent to raise this matrix values to. + /// The vector to store the result of the pointwise power. + protected abstract void DoPointwisePower(T exponent, Matrix result); + /// /// 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. @@ -240,6 +247,18 @@ namespace MathNet.Numerics.LinearAlgebra /// The result of the modulus. protected abstract void DoPointwiseRemainder(Matrix divisor, Matrix result); + /// + /// Pointwise applies the exponential function to each value and stores the result into the result matrix. + /// + /// The matrix to store the result. + protected abstract void DoPointwiseExp(Matrix result); + + /// + /// Pointwise applies the natural logarithm function to each value and stores the result into the result matrix. + /// + /// The matrix to store the result. + protected abstract void DoPointwiseLog(Matrix result); + /// /// Adds a scalar to each element of the matrix. /// @@ -1233,6 +1252,32 @@ namespace MathNet.Numerics.LinearAlgebra DoPointwiseDivide(divisor, result); } + /// + /// Pointwise raise this matrix to an exponent and store the result into the result matrix. + /// + /// The exponent to raise this matrix values to. + public Matrix PointwisePower(T exponent) + { + var result = Build.SameAs(this); + DoPointwisePower(exponent, result); + return result; + } + + /// + /// Pointwise raise this matrix to an exponent. + /// + /// The exponent to raise this matrix values to. + /// If this matrix and are not the same size. + public void PointwisePower(T exponent, Matrix result) + { + if (ColumnCount != result.ColumnCount || RowCount != result.RowCount) + { + throw DimensionsDontMatch(this, result); + } + + DoPointwisePower(exponent, result); + } + /// /// Pointwise canonical modulus, where the result has the sign of the divisor, /// of this matrix by another matrix. @@ -1305,6 +1350,56 @@ namespace MathNet.Numerics.LinearAlgebra DoPointwiseRemainder(divisor, result); } + /// + /// Pointwise applies the exponent function to each value. + /// + public Matrix PointwiseExp() + { + var result = Build.SameAs(this); + DoPointwiseExp(result); + return result; + } + + /// + /// Pointwise applies the exponent function to each value. + /// + /// The matrix to store the result. + /// If this matrix and are not the same size. + public void PointwiseExp(Matrix result) + { + if (ColumnCount != result.ColumnCount || RowCount != result.RowCount) + { + throw DimensionsDontMatch(this, result); + } + + DoPointwiseExp(result); + } + + /// + /// Pointwise applies the natural logarithm function to each value. + /// + public Matrix PointwiseLog() + { + var result = Build.SameAs(this); + DoPointwiseLog(result); + return result; + } + + /// + /// Pointwise applies the natural logarithm function to each value. + /// + /// The matrix to store the result. + /// If this matrix and are not the same size. + public void PointwiseLog(Matrix result) + { + if (ColumnCount != result.ColumnCount || RowCount != result.RowCount) + { + throw DimensionsDontMatch(this, result); + } + + DoPointwiseLog(result); + } + /// /// Computes the trace of this matrix. /// diff --git a/src/Numerics/LinearAlgebra/Single/Matrix.cs b/src/Numerics/LinearAlgebra/Single/Matrix.cs index bc3b8cd5..9ce57eb2 100644 --- a/src/Numerics/LinearAlgebra/Single/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Single/Matrix.cs @@ -475,6 +475,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single } } + /// + /// Pointwise raise this matrix to an exponent and store the result into the result vector. + /// + /// The exponent to raise this matrix values to. + /// The vector to store the result of the pointwise power. + protected override void DoPointwisePower(float exponent, Matrix result) + { + Map(x => (float)Math.Pow(x, exponent), result, forceMapZeros: false); + } + /// /// 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. @@ -509,6 +519,24 @@ namespace MathNet.Numerics.LinearAlgebra.Single } } + /// + /// Pointwise applies the exponential function to each value and stores the result into the result matrix. + /// + /// The matrix to store the result. + protected override void DoPointwiseExp(Matrix result) + { + Map(x => (float)Math.Exp(x), result, forceMapZeros: true); + } + + /// + /// Pointwise applies the natural logarithm function to each value and stores the result into the result matrix. + /// + /// The matrix to store the result. + protected override void DoPointwiseLog(Matrix result) + { + Map(x => (float)Math.Log(x), result, forceMapZeros: true); + } + /// /// Computes the trace of this matrix. ///