|
|
|
@ -560,31 +560,67 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 |
|
|
|
public override Complex32 Sum() |
|
|
|
{ |
|
|
|
var sum = Complex32.Zero; |
|
|
|
|
|
|
|
for (var i = 0; i < _length; i++) |
|
|
|
{ |
|
|
|
sum += _values[i]; |
|
|
|
} |
|
|
|
|
|
|
|
return sum; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Computes the sum of the absolute value of the vector's elements.
|
|
|
|
/// Calculates the L1 norm of the vector, also known as Manhattan norm.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The sum of the absolute value of the vector's elements.</returns>
|
|
|
|
public override Complex32 SumMagnitudes() |
|
|
|
/// <returns>The sum of the absolute values.</returns>
|
|
|
|
public override Complex32 L1Norm() |
|
|
|
{ |
|
|
|
var sum = Complex32.Zero; |
|
|
|
|
|
|
|
for (var i = 0; i < _length; i++) |
|
|
|
{ |
|
|
|
sum += _values[i].Magnitude; |
|
|
|
} |
|
|
|
|
|
|
|
return sum; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Calculates the L2 norm of the vector, also known as Euclidean norm.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The square root of the sum of the squared values.</returns>
|
|
|
|
public override Complex32 L2Norm() |
|
|
|
{ |
|
|
|
// TODO: native provider
|
|
|
|
return _values.Aggregate(Complex32.Zero, SpecialFunctions.Hypotenuse).Magnitude; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Calculates the infinity norm of the vector.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The square root of the sum of the squared values.</returns>
|
|
|
|
public override Complex32 InfinityNorm() |
|
|
|
{ |
|
|
|
return CommonParallel.Aggregate(_values, (i, v) => v.Magnitude, Math.Max, 0f); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Computes the p-Norm.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="p">The p value.</param>
|
|
|
|
/// <returns>Scalar <c>ret = (sum(abs(this[i])^p))^(1/p)</c></returns>
|
|
|
|
public override Complex32 Norm(double p) |
|
|
|
{ |
|
|
|
if (p < 0d) throw new ArgumentOutOfRangeException("p"); |
|
|
|
|
|
|
|
if (p == 1d) return L1Norm(); |
|
|
|
if (p == 2d) return L2Norm(); |
|
|
|
if (double.IsPositiveInfinity(p)) return InfinityNorm(); |
|
|
|
|
|
|
|
var sum = 0d; |
|
|
|
for (var i = 0; i < _length; i++) |
|
|
|
{ |
|
|
|
sum += Math.Pow(_values[i].Magnitude, p); |
|
|
|
} |
|
|
|
return (float)Math.Pow(sum, 1.0 / p); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Pointwise divide this vector with another vector and stores the result into the result vector.
|
|
|
|
/// </summary>
|
|
|
|
@ -673,43 +709,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 |
|
|
|
return OuterProduct(this, v); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Computes the p-Norm.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="p">The p value.</param>
|
|
|
|
/// <returns>Scalar <c>ret = (sum(abs(this[i])^p))^(1/p)</c></returns>
|
|
|
|
public override Complex32 Norm(double p) |
|
|
|
{ |
|
|
|
if (p < 0.0) |
|
|
|
{ |
|
|
|
throw new ArgumentOutOfRangeException("p"); |
|
|
|
} |
|
|
|
|
|
|
|
if (1.0 == p) |
|
|
|
{ |
|
|
|
return SumMagnitudes(); |
|
|
|
} |
|
|
|
|
|
|
|
if (2.0 == p) |
|
|
|
{ |
|
|
|
return _values.Aggregate(Complex32.Zero, SpecialFunctions.Hypotenuse).Magnitude; |
|
|
|
} |
|
|
|
|
|
|
|
if (double.IsPositiveInfinity(p)) |
|
|
|
{ |
|
|
|
return CommonParallel.Aggregate(_values, (i, v) => v.Magnitude, Math.Max, 0f); |
|
|
|
} |
|
|
|
|
|
|
|
var sum = 0.0; |
|
|
|
|
|
|
|
for (var i = 0; i < _length; i++) |
|
|
|
{ |
|
|
|
sum += Math.Pow(_values[i].Magnitude, p); |
|
|
|
} |
|
|
|
|
|
|
|
return (float)Math.Pow(sum, 1.0 / p); |
|
|
|
} |
|
|
|
|
|
|
|
#region Parse Functions
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|