From 8d36fb4ce6e7a0b1223b1e99869f58d20948afa4 Mon Sep 17 00:00:00 2001 From: Albert Pang Date: Sun, 20 Nov 2016 16:47:24 +0800 Subject: [PATCH] LA: pointwise trigonometric functions, static functions (F#, usability) * Added abstract functions for a bunch of pointwise functions (mainly those defined as operators in F#) in Matrix and Vector and also added implementations for all the subtypes * Exposed some of the pointwise functions as static members in the Matrix and Vector generic types, so that these can be called from F# as if they are normal mathematical operators * Removing Sign from static member as it won't work for F# which expects it to return an integer and is different from the pointwise definition. * Exposed PointwiseLog() and PointwiseExp() as static members Log() and Exp() respectively so that they work with F# mathematical operator syntax * Looks like op_DotHat is already in. Reverting to original so as not to overwrite other people's work * Changing all the newly added pointwise functions with f(0)=0 to use the AllowSkip option in Map so that its more efficient for sparse matrices. * Fixed one of the PointwiseBinary helpers so that it has protected access * Filled in comments for all public functions. Fixed PointwiseBinary to consider both matrices when replicating so that a dense or sparse matrix is created accordingly --- src/Numerics/LinearAlgebra/Complex/Matrix.cs | 69 +++ src/Numerics/LinearAlgebra/Complex/Vector.cs | 73 +++ .../LinearAlgebra/Complex32/Matrix.cs | 69 +++ .../LinearAlgebra/Complex32/Vector.cs | 73 +++ src/Numerics/LinearAlgebra/Double/Matrix.cs | 69 +++ src/Numerics/LinearAlgebra/Double/Vector.cs | 73 +++ .../LinearAlgebra/Matrix.Arithmetic.cs | 402 +++++++++++++++- .../LinearAlgebra/Matrix.Operators.cs | 170 +++++++ src/Numerics/LinearAlgebra/Single/Matrix.cs | 70 +++ src/Numerics/LinearAlgebra/Single/Vector.cs | 73 +++ .../LinearAlgebra/Vector.Arithmetic.cs | 436 +++++++++++++++++- .../LinearAlgebra/Vector.Operators.cs | 170 +++++++ 12 files changed, 1717 insertions(+), 30 deletions(-) diff --git a/src/Numerics/LinearAlgebra/Complex/Matrix.cs b/src/Numerics/LinearAlgebra/Complex/Matrix.cs index 29493d45..39d648d3 100644 --- a/src/Numerics/LinearAlgebra/Complex/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Complex/Matrix.cs @@ -459,6 +459,75 @@ namespace MathNet.Numerics.LinearAlgebra.Complex Map(Complex.Log, result, Zeros.Include); } + protected override void DoPointwiseAbs(Matrix result) + { + Map(x => (Complex)Complex.Abs(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseAcos(Matrix result) + { + Map(Complex.Acos, result, Zeros.Include); + } + protected override void DoPointwiseAsin(Matrix result) + { + Map(Complex.Asin, result, Zeros.AllowSkip); + } + protected override void DoPointwiseAtan(Matrix result) + { + Map(Complex.Atan, result, Zeros.AllowSkip); + } + protected override void DoPointwiseAtan2(Matrix other, Matrix result) + { + throw new NotSupportedException(); + } + protected override void DoPointwiseCeiling(Matrix result) + { + throw new NotSupportedException(); + } + protected override void DoPointwiseCos(Matrix result) + { + Map(Complex.Cos, result, Zeros.Include); + } + protected override void DoPointwiseCosh(Matrix result) + { + Map(Complex.Cosh, result, Zeros.Include); + } + protected override void DoPointwiseFloor(Matrix result) + { + throw new NotSupportedException(); + } + protected override void DoPointwiseLog10(Matrix result) + { + Map(Complex.Log10, result, Zeros.Include); + } + protected override void DoPointwiseRound(Matrix result) + { + throw new NotSupportedException(); + } + protected override void DoPointwiseSign(Matrix result) + { + throw new NotSupportedException(); + } + protected override void DoPointwiseSin(Matrix result) + { + Map(Complex.Sin, result, Zeros.AllowSkip); + } + protected override void DoPointwiseSinh(Matrix result) + { + Map(Complex.Sinh, result, Zeros.AllowSkip); + } + protected override void DoPointwiseSqrt(Matrix result) + { + Map(Complex.Sqrt, result, Zeros.AllowSkip); + } + protected override void DoPointwiseTan(Matrix result) + { + Map(Complex.Tan, result, Zeros.AllowSkip); + } + protected override void DoPointwiseTanh(Matrix result) + { + Map(Complex.Tanh, result, Zeros.AllowSkip); + } + /// /// Computes the Moore-Penrose Pseudo-Inverse of this matrix. /// diff --git a/src/Numerics/LinearAlgebra/Complex/Vector.cs b/src/Numerics/LinearAlgebra/Complex/Vector.cs index 675cbea8..afcf0674 100644 --- a/src/Numerics/LinearAlgebra/Complex/Vector.cs +++ b/src/Numerics/LinearAlgebra/Complex/Vector.cs @@ -254,6 +254,79 @@ namespace MathNet.Numerics.LinearAlgebra.Complex Map(Complex.Log, result, Zeros.Include); } + protected override void DoPointwiseAbs(Vector result) + { + Map(x => (Complex)Complex.Abs(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseAcos(Vector result) + { + Map(Complex.Acos, result, Zeros.Include); + } + protected override void DoPointwiseAsin(Vector result) + { + Map(Complex.Asin, result, Zeros.AllowSkip); + } + protected override void DoPointwiseAtan(Vector result) + { + Map(Complex.Atan, result, Zeros.AllowSkip); + } + protected override void DoPointwiseAtan2(Vector other, Vector result) + { + throw new NotSupportedException(); + } + protected override void DoPointwiseAtan2(Complex scalar, Vector result) + { + throw new NotSupportedException(); + } + protected override void DoPointwiseCeiling(Vector result) + { + throw new NotSupportedException(); + } + protected override void DoPointwiseCos(Vector result) + { + Map(Complex.Cos, result, Zeros.Include); + } + protected override void DoPointwiseCosh(Vector result) + { + Map(Complex.Cosh, result, Zeros.Include); + } + protected override void DoPointwiseFloor(Vector result) + { + throw new NotSupportedException(); + } + protected override void DoPointwiseLog10(Vector result) + { + Map(Complex.Log10, result, Zeros.Include); + } + protected override void DoPointwiseRound(Vector result) + { + throw new NotSupportedException(); + } + protected override void DoPointwiseSign(Vector result) + { + throw new NotSupportedException(); + } + protected override void DoPointwiseSin(Vector result) + { + Map(Complex.Sin, result, Zeros.AllowSkip); + } + protected override void DoPointwiseSinh(Vector result) + { + Map(Complex.Sinh, result, Zeros.AllowSkip); + } + protected override void DoPointwiseSqrt(Vector result) + { + Map(Complex.Sqrt, result, Zeros.AllowSkip); + } + protected override void DoPointwiseTan(Vector result) + { + Map(Complex.Tan, result, Zeros.AllowSkip); + } + protected override void DoPointwiseTanh(Vector result) + { + Map(Complex.Tanh, result, Zeros.AllowSkip); + } + /// /// Computes the dot product between this vector and another vector. /// diff --git a/src/Numerics/LinearAlgebra/Complex32/Matrix.cs b/src/Numerics/LinearAlgebra/Complex32/Matrix.cs index 60cdf11b..c44ea42f 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Matrix.cs @@ -454,6 +454,75 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 Map(Complex32.Log, result, Zeros.Include); } + protected override void DoPointwiseAbs(Matrix result) + { + Map(x => (Complex32)Complex32.Abs(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseAcos(Matrix result) + { + Map(Complex32.Acos, result, Zeros.Include); + } + protected override void DoPointwiseAsin(Matrix result) + { + Map(Complex32.Asin, result, Zeros.AllowSkip); + } + protected override void DoPointwiseAtan(Matrix result) + { + Map(Complex32.Atan, result, Zeros.AllowSkip); + } + protected override void DoPointwiseAtan2(Matrix other, Matrix result) + { + throw new NotSupportedException(); + } + protected override void DoPointwiseCeiling(Matrix result) + { + throw new NotSupportedException(); + } + protected override void DoPointwiseCos(Matrix result) + { + Map(Complex32.Cos, result, Zeros.Include); + } + protected override void DoPointwiseCosh(Matrix result) + { + Map(Complex32.Cosh, result, Zeros.Include); + } + protected override void DoPointwiseFloor(Matrix result) + { + throw new NotSupportedException(); + } + protected override void DoPointwiseLog10(Matrix result) + { + Map(Complex32.Log10, result, Zeros.Include); + } + protected override void DoPointwiseRound(Matrix result) + { + throw new NotSupportedException(); + } + protected override void DoPointwiseSign(Matrix result) + { + throw new NotSupportedException(); + } + protected override void DoPointwiseSin(Matrix result) + { + Map(Complex32.Sin, result, Zeros.AllowSkip); + } + protected override void DoPointwiseSinh(Matrix result) + { + Map(Complex32.Sinh, result, Zeros.AllowSkip); + } + protected override void DoPointwiseSqrt(Matrix result) + { + Map(Complex32.Sqrt, result, Zeros.AllowSkip); + } + protected override void DoPointwiseTan(Matrix result) + { + Map(Complex32.Tan, result, Zeros.AllowSkip); + } + protected override void DoPointwiseTanh(Matrix result) + { + Map(Complex32.Tanh, result, Zeros.AllowSkip); + } + /// /// Computes the Moore-Penrose Pseudo-Inverse of this matrix. /// diff --git a/src/Numerics/LinearAlgebra/Complex32/Vector.cs b/src/Numerics/LinearAlgebra/Complex32/Vector.cs index 6ce516ee..d6b4556d 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Vector.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Vector.cs @@ -249,6 +249,79 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 Map(Complex32.Log, result, Zeros.Include); } + protected override void DoPointwiseAbs(Vector result) + { + Map(x => (Complex32)Complex32.Abs(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseAcos(Vector result) + { + Map(Complex32.Acos, result, Zeros.Include); + } + protected override void DoPointwiseAsin(Vector result) + { + Map(Complex32.Asin, result, Zeros.AllowSkip); + } + protected override void DoPointwiseAtan(Vector result) + { + Map(Complex32.Atan, result, Zeros.AllowSkip); + } + protected override void DoPointwiseAtan2(Vector other, Vector result) + { + throw new NotSupportedException(); + } + protected override void DoPointwiseAtan2(Complex32 scalar, Vector result) + { + throw new NotSupportedException(); + } + protected override void DoPointwiseCeiling(Vector result) + { + throw new NotSupportedException(); + } + protected override void DoPointwiseCos(Vector result) + { + Map(Complex32.Cos, result, Zeros.Include); + } + protected override void DoPointwiseCosh(Vector result) + { + Map(Complex32.Cosh, result, Zeros.Include); + } + protected override void DoPointwiseFloor(Vector result) + { + throw new NotSupportedException(); + } + protected override void DoPointwiseLog10(Vector result) + { + Map(Complex32.Log10, result, Zeros.Include); + } + protected override void DoPointwiseRound(Vector result) + { + throw new NotSupportedException(); + } + protected override void DoPointwiseSign(Vector result) + { + throw new NotSupportedException(); + } + protected override void DoPointwiseSin(Vector result) + { + Map(Complex32.Sin, result, Zeros.AllowSkip); + } + protected override void DoPointwiseSinh(Vector result) + { + Map(Complex32.Sinh, result, Zeros.AllowSkip); + } + protected override void DoPointwiseSqrt(Vector result) + { + Map(Complex32.Sqrt, result, Zeros.AllowSkip); + } + protected override void DoPointwiseTan(Vector result) + { + Map(Complex32.Tan, result, Zeros.AllowSkip); + } + protected override void DoPointwiseTanh(Vector result) + { + Map(Complex32.Tanh, result, Zeros.AllowSkip); + } + /// /// Computes the dot product between this vector and another vector. /// diff --git a/src/Numerics/LinearAlgebra/Double/Matrix.cs b/src/Numerics/LinearAlgebra/Double/Matrix.cs index daae0822..c85a8052 100644 --- a/src/Numerics/LinearAlgebra/Double/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Double/Matrix.cs @@ -424,6 +424,75 @@ namespace MathNet.Numerics.LinearAlgebra.Double Map(Math.Log, result, Zeros.Include); } + protected override void DoPointwiseAbs(Matrix result) + { + Map(Math.Abs, result, Zeros.AllowSkip); + } + protected override void DoPointwiseAcos(Matrix result) + { + Map(Math.Acos, result, Zeros.Include); + } + protected override void DoPointwiseAsin(Matrix result) + { + Map(Math.Asin, result, Zeros.AllowSkip); + } + protected override void DoPointwiseAtan(Matrix result) + { + Map(Math.Atan, result, Zeros.AllowSkip); + } + protected override void DoPointwiseAtan2(Matrix other, Matrix result) + { + Map2(Math.Atan2, other, result, Zeros.Include); + } + protected override void DoPointwiseCeiling(Matrix result) + { + Map(Math.Ceiling, result, Zeros.AllowSkip); + } + protected override void DoPointwiseCos(Matrix result) + { + Map(Math.Cos, result, Zeros.Include); + } + protected override void DoPointwiseCosh(Matrix result) + { + Map(Math.Cosh, result, Zeros.Include); + } + protected override void DoPointwiseFloor(Matrix result) + { + Map(Math.Floor, result, Zeros.AllowSkip); + } + protected override void DoPointwiseLog10(Matrix result) + { + Map(Math.Log10, result, Zeros.Include); + } + protected override void DoPointwiseRound(Matrix result) + { + Map(Math.Round, result, Zeros.AllowSkip); + } + protected override void DoPointwiseSign(Matrix result) + { + Map(x => (double)Math.Sign(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseSin(Matrix result) + { + Map(Math.Sin, result, Zeros.AllowSkip); + } + protected override void DoPointwiseSinh(Matrix result) + { + Map(Math.Sinh, result, Zeros.AllowSkip); + } + protected override void DoPointwiseSqrt(Matrix result) + { + Map(Math.Sqrt, result, Zeros.AllowSkip); + } + protected override void DoPointwiseTan(Matrix result) + { + Map(Math.Tan, result, Zeros.AllowSkip); + } + protected override void DoPointwiseTanh(Matrix result) + { + Map(Math.Tanh, result, Zeros.AllowSkip); + } + /// /// Computes the Moore-Penrose Pseudo-Inverse of this matrix. /// diff --git a/src/Numerics/LinearAlgebra/Double/Vector.cs b/src/Numerics/LinearAlgebra/Double/Vector.cs index 787bd57b..14dabcb5 100644 --- a/src/Numerics/LinearAlgebra/Double/Vector.cs +++ b/src/Numerics/LinearAlgebra/Double/Vector.cs @@ -252,6 +252,79 @@ namespace MathNet.Numerics.LinearAlgebra.Double Map(Math.Log, result, Zeros.Include); } + protected override void DoPointwiseAbs(Vector result) + { + Map(Math.Abs, result, Zeros.AllowSkip); + } + protected override void DoPointwiseAcos(Vector result) + { + Map(Math.Acos, result, Zeros.Include); + } + protected override void DoPointwiseAsin(Vector result) + { + Map(Math.Asin, result, Zeros.AllowSkip); + } + protected override void DoPointwiseAtan(Vector result) + { + Map(Math.Atan, result, Zeros.AllowSkip); + } + protected override void DoPointwiseAtan2(Vector other, Vector result) + { + Map2(Math.Atan2, other, result, Zeros.Include); + } + protected override void DoPointwiseAtan2(double scalar, Vector result) + { + Map(x => Math.Atan2(x, scalar), result, Zeros.Include); + } + protected override void DoPointwiseCeiling(Vector result) + { + Map(Math.Ceiling, result, Zeros.AllowSkip); + } + protected override void DoPointwiseCos(Vector result) + { + Map(Math.Cos, result, Zeros.Include); + } + protected override void DoPointwiseCosh(Vector result) + { + Map(Math.Cosh, result, Zeros.Include); + } + protected override void DoPointwiseFloor(Vector result) + { + Map(Math.Floor, result, Zeros.AllowSkip); + } + protected override void DoPointwiseLog10(Vector result) + { + Map(Math.Log10, result, Zeros.Include); + } + protected override void DoPointwiseRound(Vector result) + { + Map(Math.Round, result, Zeros.AllowSkip); + } + protected override void DoPointwiseSign(Vector result) + { + Map(x => (double)Math.Sign(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseSin(Vector result) + { + Map(Math.Sin, result, Zeros.AllowSkip); + } + protected override void DoPointwiseSinh(Vector result) + { + Map(Math.Sinh, result, Zeros.AllowSkip); + } + protected override void DoPointwiseSqrt(Vector result) + { + Map(Math.Sqrt, result, Zeros.AllowSkip); + } + protected override void DoPointwiseTan(Vector result) + { + Map(Math.Tan, result, Zeros.AllowSkip); + } + protected override void DoPointwiseTanh(Vector result) + { + Map(Math.Tanh, result, Zeros.AllowSkip); + } + /// /// Computes the dot product between this vector and another vector. /// diff --git a/src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs b/src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs index 91b26527..c63ce233 100644 --- a/src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs +++ b/src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs @@ -265,6 +265,23 @@ namespace MathNet.Numerics.LinearAlgebra /// The matrix to store the result. protected abstract void DoPointwiseLog(Matrix result); + protected abstract void DoPointwiseAbs(Matrix result); + protected abstract void DoPointwiseAcos(Matrix result); + protected abstract void DoPointwiseAsin(Matrix result); + protected abstract void DoPointwiseAtan(Matrix result); + protected abstract void DoPointwiseCeiling(Matrix result); + protected abstract void DoPointwiseCos(Matrix result); + protected abstract void DoPointwiseCosh(Matrix result); + protected abstract void DoPointwiseFloor(Matrix result); + protected abstract void DoPointwiseLog10(Matrix result); + protected abstract void DoPointwiseRound(Matrix result); + protected abstract void DoPointwiseSign(Matrix result); + protected abstract void DoPointwiseSin(Matrix result); + protected abstract void DoPointwiseSinh(Matrix result); + protected abstract void DoPointwiseSqrt(Matrix result); + protected abstract void DoPointwiseTan(Matrix result); + protected abstract void DoPointwiseTanh(Matrix result); + protected abstract void DoPointwiseAtan2(Matrix other, Matrix result); protected abstract void DoPointwiseMinimum(T scalar, Matrix result); protected abstract void DoPointwiseMinimum(Matrix other, Matrix result); protected abstract void DoPointwiseMaximum(T scalar, Matrix result); @@ -1512,28 +1529,92 @@ namespace MathNet.Numerics.LinearAlgebra } /// - /// Pointwise applies the exponent function to each value. + /// Helper function to apply a unary function to a matrix. The function + /// f modifies the matrix given to it in place. Before its + /// called, a copy of the 'this' matrix is first created, then passed to + /// f. The copy is then returned as the result /// - public Matrix PointwiseExp() + /// Function which takes a matrix, modifies it in place and returns void + /// New instance of matrix which is the result + protected Matrix PointwiseUnary(Action> f) { var result = Build.SameAs(this); - DoPointwiseExp(result); + f(result); return result; } /// - /// Pointwise applies the exponent function to each value. + /// Helper function to apply a unary function which modifies a matrix + /// in place. /// - /// The matrix to store the result. - /// If this matrix and are not the same size. - public void PointwiseExp(Matrix result) + /// Function which takes a matrix, modifies it in place and returns void + /// The matrix to be passed to f and where the result is to be stored + /// If this vector and are not the same size. + protected void PointwiseUnary(Action> f, Matrix result) { if (ColumnCount != result.ColumnCount || RowCount != result.RowCount) { throw DimensionsDontMatch(this, result); } + f(result); + } + + /// + /// Helper function to apply a binary function which takes two matrices + /// and modifies the latter in place. A copy of the "this" matrix is + /// first made and then passed to f together with the other matrix. The + /// copy is then returned as the result + /// + /// Function which takes two matrices, modifies the second in place and returns void + /// The other matrix to be passed to the function as argument. It is not modified + /// The resulting matrix + /// If this amtrix and are not the same dimension. + protected Matrix PointwiseBinary(Action, Matrix> f, Matrix other) + { + if (ColumnCount != other.ColumnCount || RowCount != other.RowCount) + { + throw DimensionsDontMatch(this, other); + } + + var result = Build.SameAs(this, other); + f(other, result); + return result; + } + + /// + /// Helper function to apply a binary function which takes two matrices + /// and modifies the second one in place + /// + /// Function which takes two matrices, modifies the second in place and returns void + /// The other matrix to be passed to the function as argument. It is not modified + /// The resulting matrix + /// If this matrix and are not the same dimension. + protected void PointwiseBinary(Action,Matrix> f, Matrix other, Matrix result) + { + if (ColumnCount != result.ColumnCount || RowCount != result.RowCount || ColumnCount != other.ColumnCount || RowCount != other.RowCount) + { + throw DimensionsDontMatch(this, other, result); + } - DoPointwiseExp(result); + f(other, result); + } + + /// + /// Pointwise applies the exponent function to each value. + /// + public Matrix PointwiseExp() + { + return PointwiseUnary(DoPointwiseExp); + } + + /// + /// 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) + { + PointwiseUnary(DoPointwiseExp, result); } /// @@ -1541,9 +1622,7 @@ namespace MathNet.Numerics.LinearAlgebra /// public Matrix PointwiseLog() { - var result = Build.SameAs(this); - DoPointwiseLog(result); - return result; + return PointwiseUnary(DoPointwiseLog); } /// @@ -1553,12 +1632,303 @@ namespace MathNet.Numerics.LinearAlgebra /// 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); - } + PointwiseUnary(DoPointwiseLog, result); + } + + /// + /// Pointwise applies the abs function to each value + /// + public Matrix PointwiseAbs() + { + return PointwiseUnary(DoPointwiseAbs); + } + + /// + /// Pointwise applies the abs function to each value + /// + /// The vector to store the result + public void PointwiseAbs(Matrix result) + { + PointwiseUnary(DoPointwiseAbs, result); + } + + /// + /// Pointwise applies the acos function to each value + /// + public Matrix PointwiseAcos() + { + return PointwiseUnary(DoPointwiseAcos); + } + + /// + /// Pointwise applies the acos function to each value + /// + /// The vector to store the result + public void PointwiseAcos(Matrix result) + { + PointwiseUnary(DoPointwiseAcos, result); + } + + /// + /// Pointwise applies the asin function to each value + /// + public Matrix PointwiseAsin() + { + return PointwiseUnary(DoPointwiseAsin); + } - DoPointwiseLog(result); + /// + /// Pointwise applies the asin function to each value + /// + /// The vector to store the result + public void PointwiseAsin(Matrix result) + { + PointwiseUnary(DoPointwiseAsin, result); + } + + /// + /// Pointwise applies the atan function to each value + /// + public Matrix PointwiseAtan() + { + return PointwiseUnary(DoPointwiseAtan); + } + + /// + /// Pointwise applies the atan function to each value + /// + /// The vector to store the result + public void PointwiseAtan(Matrix result) + { + PointwiseUnary(DoPointwiseAtan, result); + } + + /// + /// Pointwise applies the atan2 function to each value of the current + /// matrix and a given other matrix being the 'x' of atan2 and the + /// 'this' matrix being the 'y' + /// + /// + /// + public Matrix PointwiseAtan2(Matrix other) + { + return PointwiseBinary(DoPointwiseAtan2, other); + } + + /// + /// Pointwise applies the atan2 function to each value of the current + /// matrix and a given other matrix being the 'x' of atan2 and the + /// 'this' matrix being the 'y' + /// + /// + /// + public void PointwiseAtan2(Matrix other, Matrix result) + { + PointwiseBinary(DoPointwiseAtan2, other, result); + } + + /// + /// Pointwise applies the ceiling function to each value + /// + public Matrix PointwiseCeiling() + { + return PointwiseUnary(DoPointwiseCeiling); + } + + /// + /// Pointwise applies the ceiling function to each value + /// + /// The vector to store the result + public void PointwiseCeiling(Matrix result) + { + PointwiseUnary(DoPointwiseCeiling, result); + } + + /// + /// Pointwise applies the cos function to each value + /// + public Matrix PointwiseCos() + { + return PointwiseUnary(DoPointwiseCos); + } + + /// + /// Pointwise applies the cos function to each value + /// + /// The vector to store the result + public void PointwiseCos(Matrix result) + { + PointwiseUnary(DoPointwiseCos, result); + } + + /// + /// Pointwise applies the cosh function to each value + /// + public Matrix PointwiseCosh() + { + return PointwiseUnary(DoPointwiseCosh); + } + + /// + /// Pointwise applies the cosh function to each value + /// + /// The vector to store the result + public void PointwiseCosh(Matrix result) + { + PointwiseUnary(DoPointwiseCosh, result); + } + + /// + /// Pointwise applies the floor function to each value + /// + public Matrix PointwiseFloor() + { + return PointwiseUnary(DoPointwiseFloor); + } + + /// + /// Pointwise applies the floor function to each value + /// + /// The vector to store the result + public void PointwiseFloor(Matrix result) + { + PointwiseUnary(DoPointwiseFloor, result); + } + + /// + /// Pointwise applies the log10 function to each value + /// + public Matrix PointwiseLog10() + { + return PointwiseUnary(DoPointwiseLog10); + } + + /// + /// Pointwise applies the log10 function to each value + /// + /// The vector to store the result + public void PointwiseLog10(Matrix result) + { + PointwiseUnary(DoPointwiseLog10, result); + } + + /// + /// Pointwise applies the round function to each value + /// + public Matrix PointwiseRound() + { + return PointwiseUnary(DoPointwiseRound); + } + + /// + /// Pointwise applies the round function to each value + /// + /// The vector to store the result + public void PointwiseRound(Matrix result) + { + PointwiseUnary(DoPointwiseRound, result); + } + + /// + /// Pointwise applies the sign function to each value + /// + public Matrix PointwiseSign() + { + return PointwiseUnary(DoPointwiseSign); + } + + /// + /// Pointwise applies the sign function to each value + /// + /// The vector to store the result + public void PointwiseSign(Matrix result) + { + PointwiseUnary(DoPointwiseSign, result); + } + + /// + /// Pointwise applies the sin function to each value + /// + public Matrix PointwiseSin() + { + return PointwiseUnary(DoPointwiseSin); + } + + /// + /// Pointwise applies the sin function to each value + /// + /// The vector to store the result + public void PointwiseSin(Matrix result) + { + PointwiseUnary(DoPointwiseSin, result); + } + + /// + /// Pointwise applies the sinh function to each value + /// + public Matrix PointwiseSinh() + { + return PointwiseUnary(DoPointwiseSinh); + } + + /// + /// Pointwise applies the sinh function to each value + /// + /// The vector to store the result + public void PointwiseSinh(Matrix result) + { + PointwiseUnary(DoPointwiseSinh, result); + } + + /// + /// Pointwise applies the sqrt function to each value + /// + public Matrix PointwiseSqrt() + { + return PointwiseUnary(DoPointwiseSqrt); + } + + /// + /// Pointwise applies the sqrt function to each value + /// + /// The vector to store the result + public void PointwiseSqrt(Matrix result) + { + PointwiseUnary(DoPointwiseSqrt, result); + } + + /// + /// Pointwise applies the tan function to each value + /// + public Matrix PointwiseTan() + { + return PointwiseUnary(DoPointwiseTan); + } + + /// + /// Pointwise applies the tan function to each value + /// + /// The vector to store the result + public void PointwiseTan(Matrix result) + { + PointwiseUnary(DoPointwiseTan, result); + } + + /// + /// Pointwise applies the tanh function to each value + /// + public Matrix PointwiseTanh() + { + return PointwiseUnary(DoPointwiseTanh); + } + + /// + /// Pointwise applies the tanh function to each value + /// + /// The vector to store the result + public void PointwiseTanh(Matrix result) + { + PointwiseUnary(DoPointwiseTanh, result); } /// diff --git a/src/Numerics/LinearAlgebra/Matrix.Operators.cs b/src/Numerics/LinearAlgebra/Matrix.Operators.cs index f326e5d7..55fe4503 100644 --- a/src/Numerics/LinearAlgebra/Matrix.Operators.cs +++ b/src/Numerics/LinearAlgebra/Matrix.Operators.cs @@ -305,5 +305,175 @@ namespace MathNet.Numerics.LinearAlgebra { return matrix.PointwisePower(exponent); } + + /// + /// Computes the log of a matrix pointwise + /// + /// The input matrix + /// + public static Matrix Log(Matrix x) + { + return x.PointwiseLog(); + } + + /// + /// Computes the exponential of a matrix pointwise + /// + /// The input matrix + /// + public static Matrix Exp(Matrix x) + { + return x.PointwiseExp(); + } + + /// + /// Computes the absolute value of a matrix pointwise + /// + /// The input matrix + /// + public static Matrix Abs(Matrix x) + { + return x.PointwiseAbs(); + } + + /// + /// Computes the acos of a matrix pointwise + /// + /// The input matrix + /// + public static Matrix Acos(Matrix x) + { + return x.PointwiseAcos(); + } + + /// + /// Computes the asin of a matrix pointwise + /// + /// The input matrix + /// + public static Matrix Asin(Matrix x) + { + return x.PointwiseAsin(); + } + + /// + /// Computes the atan of a matrix pointwise + /// + /// The input matrix + /// + public static Matrix Atan(Matrix x) + { + return x.PointwiseAtan(); + } + + /// + /// Computes the ceiling of a matrix pointwise + /// + /// The input matrix + /// + public static Matrix Ceiling(Matrix x) + { + return x.PointwiseCeiling(); + } + + /// + /// Computes the cos of a matrix pointwise + /// + /// The input matrix + /// + public static Matrix Cos(Matrix x) + { + return x.PointwiseCos(); + } + + /// + /// Computes the cosh of a matrix pointwise + /// + /// The input matrix + /// + public static Matrix Cosh(Matrix x) + { + return x.PointwiseCosh(); + } + + /// + /// Computes the floor of a matrix pointwise + /// + /// The input matrix + /// + public static Matrix Floor(Matrix x) + { + return x.PointwiseFloor(); + } + + /// + /// Computes the log10 of a matrix pointwise + /// + /// The input matrix + /// + public static Matrix Log10(Matrix x) + { + return x.PointwiseLog10(); + } + + /// + /// Computes the rounded value of a matrix pointwise + /// + /// The input matrix + /// + public static Matrix Round(Matrix x) + { + return x.PointwiseRound(); + } + + /// + /// Computes the sin of a matrix pointwise + /// + /// The input matrix + /// + public static Matrix Sin(Matrix x) + { + return x.PointwiseSin(); + } + + /// + /// Computes the sinh of a matrix pointwise + /// + /// The input matrix + /// + public static Matrix Sinh(Matrix x) + { + return x.PointwiseSinh(); + } + + /// + /// Computes the sqrt of a matrix pointwise + /// + /// The input matrix + /// + public static Matrix Sqrt(Matrix x) + { + return x.PointwiseSqrt(); + } + + /// + /// Computes the tan of a matrix pointwise + /// + /// The input matrix + /// + public static Matrix Tan(Matrix x) + { + return x.PointwiseTan(); + } + + /// + /// Computes the tanh of a matrix pointwise + /// + /// The input matrix + /// + public static Matrix Tanh(Matrix x) + { + return x.PointwiseTanh(); + } } } diff --git a/src/Numerics/LinearAlgebra/Single/Matrix.cs b/src/Numerics/LinearAlgebra/Single/Matrix.cs index 29179f33..32896be7 100644 --- a/src/Numerics/LinearAlgebra/Single/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Single/Matrix.cs @@ -424,6 +424,76 @@ namespace MathNet.Numerics.LinearAlgebra.Single Map(x => (float)Math.Log(x), result, Zeros.Include); } + protected override void DoPointwiseAbs(Matrix result) + { + Map(x => (float)Math.Abs(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseAcos(Matrix result) + { + Map(x => (float)Math.Acos(x), result, Zeros.Include); + } + protected override void DoPointwiseAsin(Matrix result) + { + Map(x => (float)Math.Asin(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseAtan(Matrix result) + { + Map(x => (float)Math.Atan(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseAtan2(Matrix other, Matrix result) + { + Map2((x, y) => (float)Math.Atan2((double)x, (double)y), other, result, Zeros.Include); + } + protected override void DoPointwiseCeiling(Matrix result) + { + Map(x => (float)Math.Ceiling(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseCos(Matrix result) + { + Map(x => (float)Math.Cos(x), result, Zeros.Include); + } + protected override void DoPointwiseCosh(Matrix result) + { + Map(x => (float)Math.Cosh(x), result, Zeros.Include); + } + protected override void DoPointwiseFloor(Matrix result) + { + Map(x => (float)Math.Floor(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseLog10(Matrix result) + { + Map(x => (float)Math.Log10(x), result, Zeros.Include); + } + protected override void DoPointwiseRound(Matrix result) + { + Map(x => (float)Math.Round(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseSign(Matrix result) + { + Map(x => (float)Math.Sign(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseSin(Matrix result) + { + Map(x => (float)Math.Sin(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseSinh(Matrix result) + { + Map(x => (float)Math.Sinh(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseSqrt(Matrix result) + { + Map(x => (float)Math.Sqrt(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseTan(Matrix result) + { + Map(x => (float)Math.Tan(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseTanh(Matrix result) + { + Map(x => (float)Math.Tanh(x), result, Zeros.AllowSkip); + } + + /// /// Computes the Moore-Penrose Pseudo-Inverse of this matrix. /// diff --git a/src/Numerics/LinearAlgebra/Single/Vector.cs b/src/Numerics/LinearAlgebra/Single/Vector.cs index 4a860dff..1eeb5122 100644 --- a/src/Numerics/LinearAlgebra/Single/Vector.cs +++ b/src/Numerics/LinearAlgebra/Single/Vector.cs @@ -252,6 +252,79 @@ namespace MathNet.Numerics.LinearAlgebra.Single Map(x => (float)Math.Log(x), result, Zeros.Include); } + protected override void DoPointwiseAbs(Vector result) + { + Map(x => (float)Math.Abs(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseAcos(Vector result) + { + Map(x => (float)Math.Acos(x), result, Zeros.Include); + } + protected override void DoPointwiseAsin(Vector result) + { + Map(x => (float)Math.Asin(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseAtan(Vector result) + { + Map(x => (float)Math.Atan(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseAtan2(Vector other, Vector result) + { + Map2((x, y) => (float)Math.Atan2((double)x, (double)y), other, result, Zeros.Include); + } + protected override void DoPointwiseAtan2(float scalar, Vector result) + { + Map(x => (float)Math.Atan2((double)x, (double)scalar), result, Zeros.Include); + } + protected override void DoPointwiseCeiling(Vector result) + { + Map(x => (float)Math.Ceiling(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseCos(Vector result) + { + Map(x => (float)Math.Cos(x), result, Zeros.Include); + } + protected override void DoPointwiseCosh(Vector result) + { + Map(x => (float)Math.Cosh(x), result, Zeros.Include); + } + protected override void DoPointwiseFloor(Vector result) + { + Map(x => (float)Math.Floor(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseLog10(Vector result) + { + Map(x => (float)Math.Log10(x), result, Zeros.Include); + } + protected override void DoPointwiseRound(Vector result) + { + Map(x => (float)Math.Round(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseSign(Vector result) + { + Map(x => (float)Math.Sign(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseSin(Vector result) + { + Map(x => (float)Math.Sin(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseSinh(Vector result) + { + Map(x => (float)Math.Sinh(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseSqrt(Vector result) + { + Map(x => (float)Math.Sqrt(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseTan(Vector result) + { + Map(x => (float)Math.Tan(x), result, Zeros.AllowSkip); + } + protected override void DoPointwiseTanh(Vector result) + { + Map(x => (float)Math.Tanh(x), result, Zeros.AllowSkip); + } + /// /// 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 4aea4c2b..95774131 100644 --- a/src/Numerics/LinearAlgebra/Vector.Arithmetic.cs +++ b/src/Numerics/LinearAlgebra/Vector.Arithmetic.cs @@ -233,6 +233,24 @@ namespace MathNet.Numerics.LinearAlgebra /// The vector to store the result. protected abstract void DoPointwiseLog(Vector result); + protected abstract void DoPointwiseAbs(Vector result); + protected abstract void DoPointwiseAcos(Vector result); + protected abstract void DoPointwiseAsin(Vector result); + protected abstract void DoPointwiseAtan(Vector result); + protected abstract void DoPointwiseCeiling(Vector result); + protected abstract void DoPointwiseCos(Vector result); + protected abstract void DoPointwiseCosh(Vector result); + protected abstract void DoPointwiseFloor(Vector result); + protected abstract void DoPointwiseLog10(Vector result); + protected abstract void DoPointwiseRound(Vector result); + protected abstract void DoPointwiseSign(Vector result); + protected abstract void DoPointwiseSin(Vector result); + protected abstract void DoPointwiseSinh(Vector result); + protected abstract void DoPointwiseSqrt(Vector result); + protected abstract void DoPointwiseTan(Vector result); + protected abstract void DoPointwiseTanh(Vector result); + protected abstract void DoPointwiseAtan2(Vector other, Vector result); + protected abstract void DoPointwiseAtan2(T scalar, Vector result); protected abstract void DoPointwiseMinimum(T scalar, Vector result); protected abstract void DoPointwiseMinimum(Vector other, Vector result); protected abstract void DoPointwiseMaximum(T scalar, Vector result); @@ -957,53 +975,443 @@ namespace MathNet.Numerics.LinearAlgebra } /// - /// Pointwise applies the exponent function to each value. + /// Helper function to apply a unary function to a vector. The function + /// f modifies the vector given to it in place. Before its + /// called, a copy of the 'this' vector with the same dimension is + /// first created, then passed to f. The copy is returned as the result /// - public Vector PointwiseExp() + /// Function which takes a vector, modifies it in place and returns void + /// New instance of vector which is the result + protected Vector PointwiseUnary(Action> f) { var result = Build.SameAs(this); - DoPointwiseExp(result); + f(result); return result; } /// - /// Pointwise applies the exponent function to each value. + /// Helper function to apply a unary function which modifies a vector + /// in place. /// - /// The vector to store the result. + /// Function which takes a vector, modifies it in place and returns void + /// The vector where the result is to be stored /// If this vector and are not the same size. - public void PointwiseExp(Vector result) + protected void PointwiseUnary(Action> f, Vector result) { if (Count != result.Count) { throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result"); } - DoPointwiseExp(result); + f(result); } /// - /// Pointwise applies the natural logarithm function to each value. + /// Helper function to apply a binary function which takes a scalar and + /// a vector and modifies the latter in place. A copy of the "this" + /// vector is therefore first made and then passed to f together with + /// the scalar argument. The copy is then returned as the result /// - public Vector PointwiseLog() + /// Function which takes a scalar and a vector, modifies the vector in place and returns void + /// The scalar to be passed to the function + /// The resulting vector + protected Vector PointwiseBinary(Action> f, T other) { var result = Build.SameAs(this); - DoPointwiseLog(result); + f(other, result); return result; } /// - /// Pointwise applies the natural logarithm function to each value. + /// Helper function to apply a binary function which takes a scalar and + /// a vector, modifies the latter in place and returns void. /// - /// The vector to store the result. + /// Function which takes a scalar and a vector, modifies the vector in place and returns void + /// The scalar to be passed to the function /// If this vector and are not the same size. - public void PointwiseLog(Vector result) + protected void PointwiseBinary(Action> f, T x, Vector result) + { + if (Count != result.Count) + { + throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result"); + } + f(x, result); + } + + /// + /// Helper function to apply a binary function which takes two vectors + /// and modifies the latter in place. A copy of the "this" vector is + /// first made and then passed to f together with the other vector. The + /// copy is then returned as the result + /// + /// Function which takes two vectors, modifies the second in place and returns void + /// The other vector to be passed to the function as argument. It is not modified + /// The resulting vector + /// If this vector and are not the same size. + protected Vector PointwiseBinary(Action, Vector> f, Vector other) + { + if (Count != other.Count) + { + throw new ArgumentException(Resources.ArgumentVectorsSameLength, "other"); + } + + var result = Build.SameAs(this, other); + f(other, result); + return result; + } + + /// + /// Helper function to apply a binary function which takes two vectors + /// and modifies the second one in place + /// + /// Function which takes two vectors, modifies the second in place and returns void + /// The other vector to be passed to the function as argument. It is not modified + /// The resulting vector + /// If this vector and are not the same size. + protected void PointwiseBinary(Action, Vector> f, Vector other, Vector result) { + if (Count != other.Count) + { + throw new ArgumentException(Resources.ArgumentVectorsSameLength, "other"); + } + if (Count != result.Count) { throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result"); } + f(other, result); + } + + /// + /// Pointwise applies the exponent function to each value. + /// + public Vector PointwiseExp() + { + return PointwiseUnary(DoPointwiseExp); + } + + /// + /// 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) + { + PointwiseUnary(DoPointwiseExp, result); + } + + /// + /// Pointwise applies the natural logarithm function to each value. + /// + public Vector PointwiseLog() + { + return PointwiseUnary(DoPointwiseLog); + } + + /// + /// 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) + { + PointwiseUnary(DoPointwiseLog, result); + } + + /// + /// Pointwise applies the abs function to each value + /// + public Vector PointwiseAbs() + { + return PointwiseUnary(DoPointwiseAbs); + } + + /// + /// Pointwise applies the abs function to each value + /// + /// The vector to store the result + public void PointwiseAbs(Vector result) + { + PointwiseUnary(DoPointwiseAbs, result); + } + + /// + /// Pointwise applies the acos function to each value + /// + public Vector PointwiseAcos() + { + return PointwiseUnary(DoPointwiseAcos); + } + + /// + /// Pointwise applies the acos function to each value + /// + /// The vector to store the result + public void PointwiseAcos(Vector result) + { + PointwiseUnary(DoPointwiseAcos, result); + } + + /// + /// Pointwise applies the asin function to each value + /// + public Vector PointwiseAsin() + { + return PointwiseUnary(DoPointwiseAsin); + } + + /// + /// Pointwise applies the asin function to each value + /// + /// The vector to store the result + public void PointwiseAsin(Vector result) + { + PointwiseUnary(DoPointwiseAsin, result); + } + + /// + /// Pointwise applies the atan function to each value + /// + public Vector PointwiseAtan() + { + return PointwiseUnary(DoPointwiseAtan); + } + + /// + /// Pointwise applies the atan function to each value + /// + /// The vector to store the result + public void PointwiseAtan(Vector result) + { + PointwiseUnary(DoPointwiseAtan, result); + } - DoPointwiseLog(result); + /// + /// Pointwise applies the atan2 function to each value of the current + /// vector and a given other vector being the 'x' of atan2 and the + /// 'this' vector being the 'y' + /// + /// + /// + public Vector PointwiseAtan2(Vector other) + { + return PointwiseBinary(DoPointwiseAtan2, other); + } + + /// + /// Pointwise applies the atan2 function to each value of the current + /// vector and a given other vector being the 'x' of atan2 and the + /// 'this' vector being the 'y' + /// + /// + /// + public void PointwiseAtan2(Vector other, Vector result) + { + PointwiseBinary(DoPointwiseAtan2, other, result); + } + + /// + /// Pointwise applies the ceiling function to each value + /// + public Vector PointwiseCeiling() + { + return PointwiseUnary(DoPointwiseCeiling); + } + + /// + /// Pointwise applies the ceiling function to each value + /// + /// The vector to store the result + public void PointwiseCeiling(Vector result) + { + PointwiseUnary(DoPointwiseCeiling, result); + } + + /// + /// Pointwise applies the cos function to each value + /// + public Vector PointwiseCos() + { + return PointwiseUnary(DoPointwiseCos); + } + + /// + /// Pointwise applies the cos function to each value + /// + /// The vector to store the result + public void PointwiseCos(Vector result) + { + PointwiseUnary(DoPointwiseCos, result); + } + + /// + /// Pointwise applies the cosh function to each value + /// + public Vector PointwiseCosh() + { + return PointwiseUnary(DoPointwiseCosh); + } + + /// + /// Pointwise applies the cosh function to each value + /// + /// The vector to store the result + public void PointwiseCosh(Vector result) + { + PointwiseUnary(DoPointwiseCosh, result); + } + + /// + /// Pointwise applies the floor function to each value + /// + public Vector PointwiseFloor() + { + return PointwiseUnary(DoPointwiseFloor); + } + + /// + /// Pointwise applies the floor function to each value + /// + /// The vector to store the result + public void PointwiseFloor(Vector result) + { + PointwiseUnary(DoPointwiseFloor, result); + } + + /// + /// Pointwise applies the log10 function to each value + /// + public Vector PointwiseLog10() + { + return PointwiseUnary(DoPointwiseLog10); + } + + /// + /// Pointwise applies the log10 function to each value + /// + /// The vector to store the result + public void PointwiseLog10(Vector result) + { + PointwiseUnary(DoPointwiseLog10, result); + } + + /// + /// Pointwise applies the round function to each value + /// + public Vector PointwiseRound() + { + return PointwiseUnary(DoPointwiseRound); + } + + /// + /// Pointwise applies the round function to each value + /// + /// The vector to store the result + public void PointwiseRound(Vector result) + { + PointwiseUnary(DoPointwiseRound, result); + } + + /// + /// Pointwise applies the sign function to each value + /// + public Vector PointwiseSign() + { + return PointwiseUnary(DoPointwiseSign); + } + + /// + /// Pointwise applies the sign function to each value + /// + /// The vector to store the result + public void PointwiseSign(Vector result) + { + PointwiseUnary(DoPointwiseSign, result); + } + + /// + /// Pointwise applies the sin function to each value + /// + public Vector PointwiseSin() + { + return PointwiseUnary(DoPointwiseSin); + } + + /// + /// Pointwise applies the sin function to each value + /// + /// The vector to store the result + public void PointwiseSin(Vector result) + { + PointwiseUnary(DoPointwiseSin, result); + } + + /// + /// Pointwise applies the sinh function to each value + /// + public Vector PointwiseSinh() + { + return PointwiseUnary(DoPointwiseSinh); + } + + /// + /// Pointwise applies the sinh function to each value + /// + /// The vector to store the result + public void PointwiseSinh(Vector result) + { + PointwiseUnary(DoPointwiseSinh, result); + } + + /// + /// Pointwise applies the sqrt function to each value + /// + public Vector PointwiseSqrt() + { + return PointwiseUnary(DoPointwiseSqrt); + } + + /// + /// Pointwise applies the sqrt function to each value + /// + /// The vector to store the result + public void PointwiseSqrt(Vector result) + { + PointwiseUnary(DoPointwiseSqrt, result); + } + + /// + /// Pointwise applies the tan function to each value + /// + public Vector PointwiseTan() + { + return PointwiseUnary(DoPointwiseTan); + } + + /// + /// Pointwise applies the tan function to each value + /// + /// The vector to store the result + public void PointwiseTan(Vector result) + { + PointwiseUnary(DoPointwiseTan, result); + } + + /// + /// Pointwise applies the tanh function to each value + /// + public Vector PointwiseTanh() + { + return PointwiseUnary(DoPointwiseTanh); + } + + /// + /// Pointwise applies the tanh function to each value + /// + /// The vector to store the result + public void PointwiseTanh(Vector result) + { + PointwiseUnary(DoPointwiseTanh, result); } /// diff --git a/src/Numerics/LinearAlgebra/Vector.Operators.cs b/src/Numerics/LinearAlgebra/Vector.Operators.cs index d773eaa0..ee579cb9 100644 --- a/src/Numerics/LinearAlgebra/Vector.Operators.cs +++ b/src/Numerics/LinearAlgebra/Vector.Operators.cs @@ -271,5 +271,175 @@ namespace MathNet.Numerics.LinearAlgebra { return vector.PointwisePower(exponent); } + + /// + /// Computes the log of a vector pointwise + /// + /// The input vector + /// + public static Vector Log(Vector x) + { + return x.PointwiseUnary(x.PointwiseLog); + } + + /// + /// Computes the exponential of a vector pointwise + /// + /// The input vector + /// + public static Vector Exp(Vector x) + { + return x.PointwiseUnary(x.DoPointwiseExp); + } + + /// + /// Computes the absolute value of a vector pointwise + /// + /// The input vector + /// + public static Vector Abs(Vector x) + { + return x.PointwiseAbs(); + } + + /// + /// Computes the acos of a vector pointwise + /// + /// The input vector + /// + public static Vector Acos(Vector x) + { + return x.PointwiseAcos(); + } + + /// + /// Computes the asin of a vector pointwise + /// + /// The input vector + /// + public static Vector Asin(Vector x) + { + return x.PointwiseAsin(); + } + + /// + /// Computes the atan of a vector pointwise + /// + /// The input vector + /// + public static Vector Atan(Vector x) + { + return x.PointwiseAtan(); + } + + /// + /// Computes the ceiling of a vector pointwise + /// + /// The input vector + /// + public static Vector Ceiling(Vector x) + { + return x.PointwiseCeiling(); + } + + /// + /// Computes the cos of a vector pointwise + /// + /// The input vector + /// + public static Vector Cos(Vector x) + { + return x.PointwiseCos(); + } + + /// + /// Computes the cosh of a vector pointwise + /// + /// The input vector + /// + public static Vector Cosh(Vector x) + { + return x.PointwiseCosh(); + } + + /// + /// Computes the floor of a vector pointwise + /// + /// The input vector + /// + public static Vector Floor(Vector x) + { + return x.PointwiseFloor(); + } + + /// + /// Computes the log10 of a vector pointwise + /// + /// The input vector + /// + public static Vector Log10(Vector x) + { + return x.PointwiseLog10(); + } + + /// + /// Computes the rounded value of a vector pointwise + /// + /// The input vector + /// + public static Vector Round(Vector x) + { + return x.PointwiseRound(); + } + + /// + /// Computes the sin of a vector pointwise + /// + /// The input vector + /// + public static Vector Sin(Vector x) + { + return x.PointwiseSin(); + } + + /// + /// Computes the sinh of a vector pointwise + /// + /// The input vector + /// + public static Vector Sinh(Vector x) + { + return x.PointwiseSinh(); + } + + /// + /// Computes the sqrt of a vector pointwise + /// + /// The input vector + /// + public static Vector Sqrt(Vector x) + { + return x.PointwiseSqrt(); + } + + /// + /// Computes the tan of a vector pointwise + /// + /// The input vector + /// + public static Vector Tan(Vector x) + { + return x.PointwiseTan(); + } + + /// + /// Computes the tanh of a vector pointwise + /// + /// The input vector + /// + public static Vector Tanh(Vector x) + { + return x.PointwiseTanh(); + } } }