Browse Source

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

provider
Christoph Ruegg 13 years ago
parent
commit
b44ed23efa
  1. 38
      src/Numerics/LinearAlgebra/Complex/Vector.cs
  2. 29
      src/Numerics/LinearAlgebra/Complex32/Vector.cs
  3. 28
      src/Numerics/LinearAlgebra/Double/Vector.cs
  4. 28
      src/Numerics/LinearAlgebra/Single/Vector.cs
  5. 95
      src/Numerics/LinearAlgebra/Vector.Arithmetic.cs

38
src/Numerics/LinearAlgebra/Complex/Vector.cs

@ -48,7 +48,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
public abstract class Vector : Vector<Complex>
{
/// <summary>
/// Initializes a new instance of the Vector class.
/// Initializes a new instance of the Vector class.
/// </summary>
protected Vector(VectorStorage<Complex> storage)
: base(storage)
@ -190,6 +190,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
}
/// <summary>
/// Pointwise raise this vector to an exponent and store the result into the result vector.
/// </summary>
/// <param name="exponent">The exponent to raise this vector values to.</param>
/// <param name="result">The vector to store the result of the pointwise power.</param>
protected override void DoPointwisePower(Complex exponent, Vector<Complex> result)
{
Map(x => x.Power(exponent), result, forceMapZeros: false);
}
/// <summary>
/// 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();
}
/// <summary>
/// Pointwise applies the exponential function to each value and stores the result into the result vector.
/// </summary>
/// <param name="result">The vector to store the result.</param>
protected override void DoPointwiseExp(Vector<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 vector.
/// </summary>
/// <param name="result">The vector to store the result.</param>
protected override void DoPointwiseLog(Vector<Complex> result)
{
Map(Complex.Log, result, forceMapZeros: true);
}
/// <summary>
/// Computes the dot product between this vector and another vector.
/// </summary>
@ -298,7 +326,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// <summary>
/// Returns the index of the absolute minimum element.
/// </summary>
/// <returns>The index of absolute minimum element.</returns>
/// <returns>The index of absolute minimum element.</returns>
public override int AbsoluteMinimumIndex()
{
var index = 0;
@ -328,7 +356,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// <summary>
/// Returns the index of the absolute maximum element.
/// </summary>
/// <returns>The index of absolute maximum element.</returns>
/// <returns>The index of absolute maximum element.</returns>
public override int AbsoluteMaximumIndex()
{
var index = 0;
@ -444,7 +472,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// <summary>
/// Returns the index of the absolute maximum element.
/// </summary>
/// <returns>The index of absolute maximum element.</returns>
/// <returns>The index of absolute maximum element.</returns>
public override int MaximumIndex()
{
throw new NotSupportedException();
@ -453,7 +481,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// <summary>
/// Returns the index of the minimum element.
/// </summary>
/// <returns>The index of minimum element.</returns>
/// <returns>The index of minimum element.</returns>
public override int MinimumIndex()
{
throw new NotSupportedException();

29
src/Numerics/LinearAlgebra/Complex32/Vector.cs

@ -28,6 +28,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
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
}
}
/// <summary>
/// Pointwise raise this vector to an exponent and store the result into the result vector.
/// </summary>
/// <param name="exponent">The exponent to raise this vector values to.</param>
/// <param name="result">The vector to store the result of the pointwise power.</param>
protected override void DoPointwisePower(Complex32 exponent, Vector<Complex32> result)
{
Map(x => x.Power(exponent), result, forceMapZeros: false);
}
/// <summary>
/// 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();
}
/// <summary>
/// Pointwise applies the exponential function to each value and stores the result into the result vector.
/// </summary>
/// <param name="result">The vector to store the result.</param>
protected override void DoPointwiseExp(Vector<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 vector.
/// </summary>
/// <param name="result">The vector to store the result.</param>
protected override void DoPointwiseLog(Vector<Complex32> result)
{
Map(Complex32.Log, result, forceMapZeros: true);
}
/// <summary>
/// Computes the dot product between this vector and another vector.
/// </summary>

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

@ -183,6 +183,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
}
/// <summary>
/// Pointwise raise this vector to an exponent and store the result into the result vector.
/// </summary>
/// <param name="exponent">The exponent to raise this vector values to.</param>
/// <param name="result">The vector to store the result of the pointwise power.</param>
protected override void DoPointwisePower(double exponent, Vector<double> result)
{
Map(x => Math.Pow(x, exponent), result, forceMapZeros: false);
}
/// <summary>
/// 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
}
}
/// <summary>
/// Pointwise applies the exponential function to each value and stores the result into the result vector.
/// </summary>
/// <param name="result">The vector to store the result.</param>
protected override void DoPointwiseExp(Vector<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 vector.
/// </summary>
/// <param name="result">The vector to store the result.</param>
protected override void DoPointwiseLog(Vector<double> result)
{
Map(Math.Log, result, forceMapZeros: true);
}
/// <summary>
/// Computes the dot product between this vector and another vector.
/// </summary>

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

@ -183,6 +183,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
}
/// <summary>
/// Pointwise raise this vector to an exponent and store the result into the result vector.
/// </summary>
/// <param name="exponent">The exponent to raise this vector values to.</param>
/// <param name="result">The vector to store the result of the pointwise power.</param>
protected override void DoPointwisePower(float exponent, Vector<float> result)
{
Map(x => (float)Math.Pow(x, exponent), result, forceMapZeros: false);
}
/// <summary>
/// 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
}
}
/// <summary>
/// Pointwise applies the exponential function to each value and stores the result into the result vector.
/// </summary>
/// <param name="result">The vector to store the result.</param>
protected override void DoPointwiseExp(Vector<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 vector.
/// </summary>
/// <param name="result">The vector to store the result.</param>
protected override void DoPointwiseLog(Vector<float> result)
{
Map(x => (float)Math.Log(x), result, forceMapZeros: true);
}
/// <summary>
/// Computes the dot product between this vector and another vector.
/// </summary>

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

@ -177,6 +177,13 @@ namespace MathNet.Numerics.LinearAlgebra
/// <param name="result">The result of the division.</param>
protected abstract void DoPointwiseDivide(Vector<T> divisor, Vector<T> result);
/// <summary>
/// Pointwise raise this vector to an exponent and store the result into the result vector.
/// </summary>
/// <param name="exponent">The exponent to raise this vector values to.</param>
/// <param name="result">The vector to store the result of the pointwise power.</param>
protected abstract void DoPointwisePower(T exponent, Vector<T> result);
/// <summary>
/// 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
/// <param name="result">The result of the modulus.</param>
protected abstract void DoPointwiseRemainder(Vector<T> divisor, Vector<T> result);
/// <summary>
/// Pointwise applies the exponential function to each value and stores the result into the result vector.
/// </summary>
/// <param name="result">The vector to store the result.</param>
protected abstract void DoPointwiseExp(Vector<T> result);
/// <summary>
/// Pointwise applies the natural logarithm function to each value and stores the result into the result vector.
/// </summary>
/// <param name="result">The vector to store the result.</param>
protected abstract void DoPointwiseLog(Vector<T> result);
/// <summary>
/// Adds a scalar to each element of the vector.
/// </summary>
@ -762,6 +781,32 @@ namespace MathNet.Numerics.LinearAlgebra
DoPointwiseDivide(divisor, result);
}
/// <summary>
/// Pointwise raise this vector to an exponent.
/// </summary>
/// <param name="exponent">The exponent to raise this vector values to.</param>
public Vector<T> PointwisePower(T exponent)
{
var result = Build.SameAs(this);
DoPointwisePower(exponent, result);
return result;
}
/// <summary>
/// Pointwise raise this vector to an exponent and store the result into the result vector.
/// </summary>
/// <param name="exponent">The exponent to raise this vector values to.</param>
/// <exception cref="ArgumentException">If this vector and <paramref name="result"/> are not the same size.</exception>
public void PointwisePower(T exponent, Vector<T> result)
{
if (Count != result.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
}
DoPointwisePower(exponent, result);
}
/// <summary>
/// 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);
}
/// <summary>
/// Pointwise applies the exponent function to each value.
/// </summary>
public Vector<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 vector to store the result.</param>
/// <exception cref="ArgumentException">If this vector and <paramref name="result"/> are not the same size.</exception>
public void PointwiseExp(Vector<T> result)
{
if (Count != result.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
}
DoPointwiseExp(result);
}
/// <summary>
/// Pointwise applies the natural logarithm function to each value.
/// </summary>
public Vector<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 vector to store the result.</param>
/// <exception cref="ArgumentException">If this vector and <paramref name="result"/> are not the same size.</exception>
public void PointwiseLog(Vector<T> result)
{
if (Count != result.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
}
DoPointwiseLog(result);
}
/// <summary>
/// Outer product of two vectors
/// </summary>

Loading…
Cancel
Save