diff --git a/src/Numerics/LinearAlgebra/Complex/Vector.cs b/src/Numerics/LinearAlgebra/Complex/Vector.cs index f98f7447..85b41309 100644 --- a/src/Numerics/LinearAlgebra/Complex/Vector.cs +++ b/src/Numerics/LinearAlgebra/Complex/Vector.cs @@ -48,7 +48,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex public abstract class Vector : Vector { /// - /// Initializes a new instance of the Vector class. + /// Initializes a new instance of the Vector class. /// protected Vector(VectorStorage storage) : base(storage) @@ -190,6 +190,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex } } + /// + /// Pointwise raise this vector to an exponent and store the result into the result vector. + /// + /// The exponent to raise this vector values to. + /// The vector to store the result of the pointwise power. + protected override void DoPointwisePower(Complex exponent, Vector result) + { + Map(x => x.Power(exponent), result, forceMapZeros: false); + } + /// /// Pointwise canonical modulus, where the result has the sign of the divisor, /// of this vector with another vector and stores the result into the result vector. @@ -212,6 +222,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex throw new NotSupportedException(); } + /// + /// Pointwise applies the exponential function to each value and stores the result into the result vector. + /// + /// The vector to store the result. + protected override void DoPointwiseExp(Vector result) + { + Map(Complex.Exp, result, forceMapZeros: true); + } + + /// + /// Pointwise applies the natural logarithm function to each value and stores the result into the result vector. + /// + /// The vector to store the result. + protected override void DoPointwiseLog(Vector result) + { + Map(Complex.Log, result, forceMapZeros: true); + } + /// /// Computes the dot product between this vector and another vector. /// @@ -298,7 +326,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// /// Returns the index of the absolute minimum element. /// - /// The index of absolute minimum element. + /// The index of absolute minimum element. public override int AbsoluteMinimumIndex() { var index = 0; @@ -328,7 +356,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// /// Returns the index of the absolute maximum element. /// - /// The index of absolute maximum element. + /// The index of absolute maximum element. public override int AbsoluteMaximumIndex() { var index = 0; @@ -444,7 +472,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// /// Returns the index of the absolute maximum element. /// - /// The index of absolute maximum element. + /// The index of absolute maximum element. public override int MaximumIndex() { throw new NotSupportedException(); @@ -453,7 +481,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// /// Returns the index of the minimum element. /// - /// The index of minimum element. + /// The index of minimum element. public override int MinimumIndex() { throw new NotSupportedException(); diff --git a/src/Numerics/LinearAlgebra/Complex32/Vector.cs b/src/Numerics/LinearAlgebra/Complex32/Vector.cs index 5879840f..9d9840c3 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Vector.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Vector.cs @@ -28,6 +28,7 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System.Security.Cryptography.X509Certificates; using MathNet.Numerics.LinearAlgebra.Storage; using MathNet.Numerics.Threading; using System; @@ -185,6 +186,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 } } + /// + /// Pointwise raise this vector to an exponent and store the result into the result vector. + /// + /// The exponent to raise this vector values to. + /// The vector to store the result of the pointwise power. + protected override void DoPointwisePower(Complex32 exponent, Vector result) + { + Map(x => x.Power(exponent), result, forceMapZeros: false); + } + /// /// Pointwise canonical modulus, where the result has the sign of the divisor, /// of this vector with another vector and stores the result into the result vector. @@ -207,6 +218,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 throw new NotSupportedException(); } + /// + /// Pointwise applies the exponential function to each value and stores the result into the result vector. + /// + /// The vector to store the result. + protected override void DoPointwiseExp(Vector result) + { + Map(Complex32.Exp, result, forceMapZeros: true); + } + + /// + /// Pointwise applies the natural logarithm function to each value and stores the result into the result vector. + /// + /// The vector to store the result. + protected override void DoPointwiseLog(Vector result) + { + Map(Complex32.Log, result, forceMapZeros: true); + } + /// /// Computes the dot product between this vector and another vector. /// diff --git a/src/Numerics/LinearAlgebra/Double/Vector.cs b/src/Numerics/LinearAlgebra/Double/Vector.cs index b92421f2..34358d62 100644 --- a/src/Numerics/LinearAlgebra/Double/Vector.cs +++ b/src/Numerics/LinearAlgebra/Double/Vector.cs @@ -183,6 +183,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double } } + /// + /// Pointwise raise this vector to an exponent and store the result into the result vector. + /// + /// The exponent to raise this vector values to. + /// The vector to store the result of the pointwise power. + protected override void DoPointwisePower(double exponent, Vector result) + { + Map(x => Math.Pow(x, exponent), result, forceMapZeros: false); + } + /// /// Pointwise canonical modulus, where the result has the sign of the divisor, /// of this vector with another vector and stores the result into the result vector. @@ -211,6 +221,24 @@ namespace MathNet.Numerics.LinearAlgebra.Double } } + /// + /// Pointwise applies the exponential function to each value and stores the result into the result vector. + /// + /// The vector to store the result. + protected override void DoPointwiseExp(Vector result) + { + Map(Math.Exp, result, forceMapZeros: true); + } + + /// + /// Pointwise applies the natural logarithm function to each value and stores the result into the result vector. + /// + /// The vector to store the result. + protected override void DoPointwiseLog(Vector result) + { + Map(Math.Log, result, forceMapZeros: true); + } + /// /// Computes the dot product between this vector and another vector. /// diff --git a/src/Numerics/LinearAlgebra/Single/Vector.cs b/src/Numerics/LinearAlgebra/Single/Vector.cs index edff9cfe..3b6c11e0 100644 --- a/src/Numerics/LinearAlgebra/Single/Vector.cs +++ b/src/Numerics/LinearAlgebra/Single/Vector.cs @@ -183,6 +183,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single } } + /// + /// Pointwise raise this vector to an exponent and store the result into the result vector. + /// + /// The exponent to raise this vector values to. + /// The vector to store the result of the pointwise power. + protected override void DoPointwisePower(float exponent, Vector 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 vector with another vector and stores the result into the result vector. @@ -211,6 +221,24 @@ namespace MathNet.Numerics.LinearAlgebra.Single } } + /// + /// Pointwise applies the exponential function to each value and stores the result into the result vector. + /// + /// The vector to store the result. + protected override void DoPointwiseExp(Vector 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 vector. + /// + /// The vector to store the result. + protected override void DoPointwiseLog(Vector result) + { + Map(x => (float)Math.Log(x), result, forceMapZeros: true); + } + /// /// Computes the dot product between this vector and another vector. /// diff --git a/src/Numerics/LinearAlgebra/Vector.Arithmetic.cs b/src/Numerics/LinearAlgebra/Vector.Arithmetic.cs index e2eee541..2ed73596 100644 --- a/src/Numerics/LinearAlgebra/Vector.Arithmetic.cs +++ b/src/Numerics/LinearAlgebra/Vector.Arithmetic.cs @@ -177,6 +177,13 @@ namespace MathNet.Numerics.LinearAlgebra /// The result of the division. protected abstract void DoPointwiseDivide(Vector divisor, Vector result); + /// + /// Pointwise raise this vector to an exponent and store the result into the result vector. + /// + /// The exponent to raise this vector values to. + /// The vector to store the result of the pointwise power. + protected abstract void DoPointwisePower(T exponent, Vector result); + /// /// Pointwise canonical modulus, where the result has the sign of the divisor, /// of this vector with another vector and stores the result into the result vector. @@ -193,6 +200,18 @@ namespace MathNet.Numerics.LinearAlgebra /// The result of the modulus. protected abstract void DoPointwiseRemainder(Vector divisor, Vector result); + /// + /// Pointwise applies the exponential function to each value and stores the result into the result vector. + /// + /// The vector to store the result. + protected abstract void DoPointwiseExp(Vector result); + + /// + /// Pointwise applies the natural logarithm function to each value and stores the result into the result vector. + /// + /// The vector to store the result. + protected abstract void DoPointwiseLog(Vector result); + /// /// Adds a scalar to each element of the vector. /// @@ -762,6 +781,32 @@ namespace MathNet.Numerics.LinearAlgebra DoPointwiseDivide(divisor, result); } + /// + /// Pointwise raise this vector to an exponent. + /// + /// The exponent to raise this vector values to. + public Vector PointwisePower(T exponent) + { + var result = Build.SameAs(this); + DoPointwisePower(exponent, result); + return result; + } + + /// + /// Pointwise raise this vector to an exponent and store the result into the result vector. + /// + /// The exponent to raise this vector values to. + /// If this vector and are not the same size. + public void PointwisePower(T exponent, Vector result) + { + if (Count != result.Count) + { + throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result"); + } + + DoPointwisePower(exponent, result); + } + /// /// Pointwise canonical modulus, where the result has the sign of the divisor, /// of this vector with another vector. @@ -843,6 +888,56 @@ namespace MathNet.Numerics.LinearAlgebra DoPointwiseRemainder(divisor, result); } + /// + /// Pointwise applies the exponent function to each value. + /// + public Vector PointwiseExp() + { + var result = Build.SameAs(this); + DoPointwiseExp(result); + return result; + } + + /// + /// Pointwise applies the exponent function to each value. + /// + /// The vector to store the result. + /// If this vector and are not the same size. + public void PointwiseExp(Vector result) + { + if (Count != result.Count) + { + throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result"); + } + + DoPointwiseExp(result); + } + + /// + /// Pointwise applies the natural logarithm function to each value. + /// + public Vector PointwiseLog() + { + var result = Build.SameAs(this); + DoPointwiseLog(result); + return result; + } + + /// + /// Pointwise applies the natural logarithm function to each value. + /// + /// The vector to store the result. + /// If this vector and are not the same size. + public void PointwiseLog(Vector result) + { + if (Count != result.Count) + { + throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result"); + } + + DoPointwiseLog(result); + } + /// /// Outer product of two vectors ///