From d1dfb51a3d38dcf4e57da4f61ad04d4eed5175dc Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Mon, 24 Oct 2016 21:07:54 +0200 Subject: [PATCH] LA: vector dot-power with vector exponent, bound to provider --- .../LinearAlgebra/Complex/DenseVector.cs | 26 +++++++++-- src/Numerics/LinearAlgebra/Complex/Vector.cs | 10 +++++ .../LinearAlgebra/Complex32/DenseVector.cs | 20 +++++++++ .../LinearAlgebra/Complex32/Vector.cs | 10 +++++ .../LinearAlgebra/Double/DenseVector.cs | 20 +++++++++ src/Numerics/LinearAlgebra/Double/Vector.cs | 10 +++++ .../LinearAlgebra/Single/DenseVector.cs | 20 +++++++++ src/Numerics/LinearAlgebra/Single/Vector.cs | 10 +++++ .../LinearAlgebra/Vector.Arithmetic.cs | 44 +++++++++++++++++++ 9 files changed, 167 insertions(+), 3 deletions(-) diff --git a/src/Numerics/LinearAlgebra/Complex/DenseVector.cs b/src/Numerics/LinearAlgebra/Complex/DenseVector.cs index a47d04dc..02fe3dfe 100644 --- a/src/Numerics/LinearAlgebra/Complex/DenseVector.cs +++ b/src/Numerics/LinearAlgebra/Complex/DenseVector.cs @@ -635,16 +635,36 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// protected override void DoPointwiseDivide(Vector divisor, Vector result) { - var denseOther = divisor as DenseVector; + var denseDivisor = divisor as DenseVector; var denseResult = result as DenseVector; - 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); + } + } + + /// + /// Pointwise raise this vector to an exponent vector and store the result into the result vector. + /// + /// The exponent vector to raise this vector values to. + /// The vector to store the result of the pointwise power. + protected override void DoPointwisePower(Vector exponent, Vector result) + { + var denseExponent = exponent as DenseVector; + var denseResult = result as DenseVector; + + if (denseExponent == null || denseResult == null) + { + base.DoPointwisePower(exponent, result); + } + else + { + Control.LinearAlgebraProvider.PointWisePowerArrays(_values, denseExponent._values, denseResult._values); } } diff --git a/src/Numerics/LinearAlgebra/Complex/Vector.cs b/src/Numerics/LinearAlgebra/Complex/Vector.cs index a9bfba42..d21f3790 100644 --- a/src/Numerics/LinearAlgebra/Complex/Vector.cs +++ b/src/Numerics/LinearAlgebra/Complex/Vector.cs @@ -204,6 +204,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex Map(x => x.Power(exponent), result, Zeros.Include); } + /// + /// Pointwise raise this vector to an exponent vector and store the result into the result vector. + /// + /// The exponent vector to raise this vector values to. + /// The vector to store the result of the pointwise power. + protected override void DoPointwisePower(Vector exponent, Vector result) + { + Map2(Complex.Pow, exponent, result, Zeros.Include); + } + /// /// 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. diff --git a/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs b/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs index 35daac37..953dfba8 100644 --- a/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs +++ b/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs @@ -643,6 +643,26 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 } } + /// + /// Pointwise raise this vector to an exponent vector and store the result into the result vector. + /// + /// The exponent vector to raise this vector values to. + /// The vector to store the result of the pointwise power. + protected override void DoPointwisePower(Vector exponent, Vector result) + { + var denseExponent = exponent as DenseVector; + var denseResult = result as DenseVector; + + if (denseExponent == null || denseResult == null) + { + base.DoPointwisePower(exponent, result); + } + else + { + Control.LinearAlgebraProvider.PointWisePowerArrays(_values, denseExponent._values, denseResult._values); + } + } + #region Parse Functions /// diff --git a/src/Numerics/LinearAlgebra/Complex32/Vector.cs b/src/Numerics/LinearAlgebra/Complex32/Vector.cs index 971177d0..224e0e02 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Vector.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Vector.cs @@ -199,6 +199,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 Map(x => x.Power(exponent), result, Zeros.Include); } + /// + /// Pointwise raise this vector to an exponent vector and store the result into the result vector. + /// + /// The exponent vector to raise this vector values to. + /// The vector to store the result of the pointwise power. + protected override void DoPointwisePower(Vector exponent, Vector result) + { + Map2(Complex32.Pow, exponent, result, Zeros.Include); + } + /// /// 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. diff --git a/src/Numerics/LinearAlgebra/Double/DenseVector.cs b/src/Numerics/LinearAlgebra/Double/DenseVector.cs index f466dbd0..0e05b3db 100644 --- a/src/Numerics/LinearAlgebra/Double/DenseVector.cs +++ b/src/Numerics/LinearAlgebra/Double/DenseVector.cs @@ -725,6 +725,26 @@ namespace MathNet.Numerics.LinearAlgebra.Double } } + /// + /// Pointwise raise this vector to an exponent vector and store the result into the result vector. + /// + /// The exponent vector to raise this vector values to. + /// The vector to store the result of the pointwise power. + protected override void DoPointwisePower(Vector exponent, Vector result) + { + var denseExponent = exponent as DenseVector; + var denseResult = result as DenseVector; + + if (denseExponent == null || denseResult == null) + { + base.DoPointwisePower(exponent, result); + } + else + { + Control.LinearAlgebraProvider.PointWisePowerArrays(_values, denseExponent._values, denseResult._values); + } + } + #region Parse Functions /// diff --git a/src/Numerics/LinearAlgebra/Double/Vector.cs b/src/Numerics/LinearAlgebra/Double/Vector.cs index b8709714..7f80555e 100644 --- a/src/Numerics/LinearAlgebra/Double/Vector.cs +++ b/src/Numerics/LinearAlgebra/Double/Vector.cs @@ -202,6 +202,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double Map(x => Math.Pow(x, exponent), result, exponent > 0.0 ? Zeros.AllowSkip : Zeros.Include); } + /// + /// Pointwise raise this vector to an exponent vector and store the result into the result vector. + /// + /// The exponent vector to raise this vector values to. + /// The vector to store the result of the pointwise power. + protected override void DoPointwisePower(Vector exponent, Vector result) + { + Map2(Math.Pow, exponent, result, Zeros.Include); + } + /// /// 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. diff --git a/src/Numerics/LinearAlgebra/Single/DenseVector.cs b/src/Numerics/LinearAlgebra/Single/DenseVector.cs index efd2f434..4beb651b 100644 --- a/src/Numerics/LinearAlgebra/Single/DenseVector.cs +++ b/src/Numerics/LinearAlgebra/Single/DenseVector.cs @@ -715,6 +715,26 @@ namespace MathNet.Numerics.LinearAlgebra.Single } } + /// + /// Pointwise raise this vector to an exponent vector and store the result into the result vector. + /// + /// The exponent vector to raise this vector values to. + /// The vector to store the result of the pointwise power. + protected override void DoPointwisePower(Vector exponent, Vector result) + { + var denseExponent = exponent as DenseVector; + var denseResult = result as DenseVector; + + if (denseExponent == null || denseResult == null) + { + base.DoPointwisePower(exponent, result); + } + else + { + Control.LinearAlgebraProvider.PointWisePowerArrays(_values, denseExponent._values, denseResult._values); + } + } + #region Parse Functions /// diff --git a/src/Numerics/LinearAlgebra/Single/Vector.cs b/src/Numerics/LinearAlgebra/Single/Vector.cs index a8903183..2eb4f7a1 100644 --- a/src/Numerics/LinearAlgebra/Single/Vector.cs +++ b/src/Numerics/LinearAlgebra/Single/Vector.cs @@ -202,6 +202,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single Map(x => (float)Math.Pow(x, exponent), result, exponent > 0.0f ? Zeros.AllowSkip : Zeros.Include); } + /// + /// Pointwise raise this vector to an exponent vector and store the result into the result vector. + /// + /// The exponent vector to raise this vector values to. + /// The vector to store the result of the pointwise power. + protected override void DoPointwisePower(Vector exponent, Vector result) + { + Map2((x, y) => (float)Math.Pow(x, y), exponent, result, Zeros.Include); + } + /// /// 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. diff --git a/src/Numerics/LinearAlgebra/Vector.Arithmetic.cs b/src/Numerics/LinearAlgebra/Vector.Arithmetic.cs index 20ed30f3..eee2af89 100644 --- a/src/Numerics/LinearAlgebra/Vector.Arithmetic.cs +++ b/src/Numerics/LinearAlgebra/Vector.Arithmetic.cs @@ -198,6 +198,13 @@ namespace MathNet.Numerics.LinearAlgebra /// The vector to store the result of the pointwise power. protected abstract void DoPointwisePower(T exponent, Vector result); + /// + /// Pointwise raise this vector to an exponent vector and store the result into the result vector. + /// + /// The exponent vector to raise this vector values to. + /// The vector to store the result of the pointwise power. + protected abstract void DoPointwisePower(Vector 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. @@ -822,6 +829,43 @@ namespace MathNet.Numerics.LinearAlgebra DoPointwisePower(exponent, result); } + /// + /// Pointwise raise this vector to an exponent and store the result into the result vector. + /// + /// The exponent to raise this vector values to. + public Vector PointwisePower(Vector exponent) + { + if (Count != exponent.Count) + { + throw new ArgumentException(Resources.ArgumentVectorsSameLength, "exponent"); + } + + var result = Build.SameAs(this); + DoPointwisePower(exponent, result); + return result; + } + + /// + /// Pointwise raise this vector to an exponent. + /// + /// The exponent to raise this vector values to. + /// The vector to store the result into. + /// If this vector and are not the same size. + public void PointwisePower(Vector exponent, Vector result) + { + if (Count != exponent.Count) + { + throw new ArgumentException(Resources.ArgumentVectorsSameLength, "exponent"); + } + + 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.