From 6360e77a22cacdded10d75eb4b529eaa070e0b0e Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Wed, 25 Sep 2013 22:51:57 +0200 Subject: [PATCH] LA: fix return type of Norms to double (instead of T) --- src/Numerics/Distance.cs | 22 ++++++++--------- .../LinearAlgebra/Complex/DenseVector.cs | 12 +++++----- .../Solvers/DivergenceStopCriterium.cs | 2 +- .../Complex/Solvers/FailureStopCriterium.cs | 6 ++--- .../Complex/Solvers/ILUTPPreconditioner.cs | 2 +- .../Complex/Solvers/ResidualStopCriterium.cs | 6 ++--- .../LinearAlgebra/Complex/Solvers/TFQMR.cs | 4 ++-- .../LinearAlgebra/Complex/SparseVector.cs | 12 +++++----- src/Numerics/LinearAlgebra/Complex/Vector.cs | 24 +++++++++---------- .../LinearAlgebra/Complex32/DenseVector.cs | 14 +++++------ .../Factorization/UserGramSchmidt.cs | 6 ++--- .../Solvers/DivergenceStopCriterium.cs | 2 +- .../Complex32/Solvers/FailureStopCriterium.cs | 6 ++--- .../Complex32/Solvers/ILUTPPreconditioner.cs | 2 +- .../Complex32/Solvers/MlkBiCgStab.cs | 2 +- .../Solvers/ResidualStopCriterium.cs | 8 +++---- .../LinearAlgebra/Complex32/Solvers/TFQMR.cs | 4 ++-- .../LinearAlgebra/Complex32/SparseVector.cs | 14 +++++------ .../LinearAlgebra/Complex32/Vector.cs | 24 +++++++++---------- .../Double/Solvers/FailureStopCriterium.cs | 4 ++-- src/Numerics/LinearAlgebra/Double/Vector.cs | 8 +++---- .../LinearAlgebra/Single/DenseVector.cs | 14 +++++------ .../Single/Factorization/UserGramSchmidt.cs | 4 ++-- .../Single/Solvers/FailureStopCriterium.cs | 6 ++--- .../Single/Solvers/MlkBiCgStab.cs | 2 +- .../Single/Solvers/ResidualStopCriterium.cs | 4 ++-- .../LinearAlgebra/Single/Solvers/TFQMR.cs | 4 ++-- .../LinearAlgebra/Single/SparseVector.cs | 14 +++++------ src/Numerics/LinearAlgebra/Single/Vector.cs | 24 +++++++++---------- .../LinearAlgebra/Vector.Arithmetic.cs | 10 ++++---- .../LinearAlgebraTests/Complex/VectorTests.cs | 2 +- .../Complex32/MatrixTests.Arithmetic.cs | 4 ++-- .../Complex32/VectorTests.Norm.cs | 6 ++--- .../Complex32/VectorTests.cs | 2 +- 34 files changed, 140 insertions(+), 140 deletions(-) diff --git a/src/Numerics/Distance.cs b/src/Numerics/Distance.cs index 61eeb5c6..4f9433e9 100644 --- a/src/Numerics/Distance.cs +++ b/src/Numerics/Distance.cs @@ -47,7 +47,7 @@ namespace MathNet.Numerics /// /// Sum of Absolute Difference (SAD), i.e. the L1-norm (Manhattan) of the difference. /// - public static float SAD(Vector a, Vector b) + public static double SAD(Vector a, Vector b) { return (a - b).L1Norm(); } @@ -59,7 +59,7 @@ namespace MathNet.Numerics { if (a.Length != b.Length) throw new ArgumentException(Resources.ArgumentVectorsSameLength); - var sum = 0d; + double sum = 0d; for (var i = 0; i < a.Length; i++) { sum += Math.Abs(a[i] - b[i]); @@ -74,7 +74,7 @@ namespace MathNet.Numerics { if (a.Length != b.Length) throw new ArgumentException(Resources.ArgumentVectorsSameLength); - var sum = 0f; + float sum = 0f; for (var i = 0; i < a.Length; i++) { sum += Math.Abs(a[i] - b[i]); @@ -93,7 +93,7 @@ namespace MathNet.Numerics /// /// Mean-Absolute Error (MAE), i.e. the normalized L1-norm (Manhattan) of the difference. /// - public static float MAE(Vector a, Vector b) + public static double MAE(Vector a, Vector b) { return (a - b).L1Norm()/a.Count; } @@ -126,7 +126,7 @@ namespace MathNet.Numerics /// /// Sum of Squared Difference (SSD), i.e. the squared L2-norm (Euclidean) of the difference. /// - public static float SSD(Vector a, Vector b) + public static double SSD(Vector a, Vector b) { var norm = (a - b).L2Norm(); return norm*norm; @@ -164,7 +164,7 @@ namespace MathNet.Numerics /// /// Mean-Squared Error (MSE), i.e. the normalized squared L2-norm (Euclidean) of the difference. /// - public static float MSE(Vector a, Vector b) + public static double MSE(Vector a, Vector b) { var norm = (a - b).L2Norm(); return norm*norm/a.Count; @@ -197,7 +197,7 @@ namespace MathNet.Numerics /// /// Euclidean Distance, i.e. the L2-norm of the difference. /// - public static float Euclidean(Vector a, Vector b) + public static double Euclidean(Vector a, Vector b) { return (a - b).L2Norm(); } @@ -229,7 +229,7 @@ namespace MathNet.Numerics /// /// Manhattan Distance, i.e. the L1-norm of the difference. /// - public static float Manhattan(Vector a, Vector b) + public static double Manhattan(Vector a, Vector b) { return (a - b).L1Norm(); } @@ -261,7 +261,7 @@ namespace MathNet.Numerics /// /// Chebyshev Distance, i.e. the Infinity-norm of the difference. /// - public static float Chebyshev(Vector a, Vector b) + public static double Chebyshev(Vector a, Vector b) { return (a - b).InfinityNorm(); } @@ -272,7 +272,7 @@ namespace MathNet.Numerics public static double Chebyshev(double[] a, double[] b) { if (a.Length != b.Length) throw new ArgumentOutOfRangeException("b"); - var max = Math.Abs(a[0] - b[0]); + double max = Math.Abs(a[0] - b[0]); for (int i = 1; i < a.Length; i++) { var next = Math.Abs(a[i] - b[i]); @@ -290,7 +290,7 @@ namespace MathNet.Numerics public static float Chebyshev(float[] a, float[] b) { if (a.Length != b.Length) throw new ArgumentOutOfRangeException("b"); - var max = Math.Abs(a[0] - b[0]); + float max = Math.Abs(a[0] - b[0]); for (int i = 1; i < a.Length; i++) { var next = Math.Abs(a[i] - b[i]); diff --git a/src/Numerics/LinearAlgebra/Complex/DenseVector.cs b/src/Numerics/LinearAlgebra/Complex/DenseVector.cs index ee7178cb..25d89b4e 100644 --- a/src/Numerics/LinearAlgebra/Complex/DenseVector.cs +++ b/src/Numerics/LinearAlgebra/Complex/DenseVector.cs @@ -552,9 +552,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// Calculates the L1 norm of the vector, also known as Manhattan norm. /// /// The sum of the absolute values. - public override Complex L1Norm() + public override double L1Norm() { - var sum = Complex.Zero; + double sum = 0d; for (var i = 0; i < _length; i++) { sum += _values[i].Magnitude; @@ -566,7 +566,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// Calculates the L2 norm of the vector, also known as Euclidean norm. /// /// The square root of the sum of the squared values. - public override Complex L2Norm() + public override double L2Norm() { // TODO: native provider return _values.Aggregate(Complex.Zero, SpecialFunctions.Hypotenuse).Magnitude; @@ -576,7 +576,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// Calculates the infinity norm of the vector. /// /// The square root of the sum of the squared values. - public override Complex InfinityNorm() + public override double InfinityNorm() { return CommonParallel.Aggregate(_values, (i, v) => v.Magnitude, Math.Max, 0d); } @@ -586,7 +586,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// /// The p value. /// Scalar ret = ( ∑|this[i]|^p )^(1/p) - public override Complex Norm(double p) + public override double Norm(double p) { if (p < 0d) throw new ArgumentOutOfRangeException("p"); @@ -594,7 +594,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (p == 2d) return L2Norm(); if (double.IsPositiveInfinity(p)) return InfinityNorm(); - var sum = 0d; + double sum = 0d; for (var i = 0; i < _length; i++) { sum += Math.Pow(_values[i].Magnitude, p); diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/DivergenceStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/DivergenceStopCriterium.cs index 407bbd2e..81090eb1 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/DivergenceStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/DivergenceStopCriterium.cs @@ -220,7 +220,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers // Store the infinity norms of both the solution and residual vectors // These values will be used to calculate the relative drop in residuals later on. - _residualHistory[_residualHistory.Length - 1] = residualVector.InfinityNorm().Real; + _residualHistory[_residualHistory.Length - 1] = residualVector.InfinityNorm(); // Check if we have NaN's. If so we've gone way beyond normal divergence. // Stop the iteration. diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/FailureStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/FailureStopCriterium.cs index af1b05dd..81deed2c 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/FailureStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/FailureStopCriterium.cs @@ -96,10 +96,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers } // Store the infinity norms of both the solution and residual vectors - var residualNorm = residualVector.InfinityNorm(); - var solutionNorm = solutionVector.InfinityNorm(); + double residualNorm = residualVector.InfinityNorm(); + double solutionNorm = solutionVector.InfinityNorm(); - _status = double.IsNaN(solutionNorm.Real) || double.IsNaN(residualNorm.Real) ? IterationStatus.Failure : IterationStatus.Continue; + _status = double.IsNaN(solutionNorm) || double.IsNaN(residualNorm) ? IterationStatus.Failure : IterationStatus.Continue; _lastIteration = iterationNumber; return _status; diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/ILUTPPreconditioner.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/ILUTPPreconditioner.cs index a166c9f2..f9499eb3 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/ILUTPPreconditioner.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/ILUTPPreconditioner.cs @@ -435,7 +435,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers // { // w(j) = 0 // } - if (workVector[j].Magnitude <= _dropTolerance*vectorNorm.Real) + if (workVector[j].Magnitude <= _dropTolerance*vectorNorm) { workVector[j] = 0.0; } diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/ResidualStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/ResidualStopCriterium.cs index 75d13b16..38854692 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/ResidualStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/ResidualStopCriterium.cs @@ -218,12 +218,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers // Check the residuals by calculating: // ||r_i|| <= stop_tol * ||b|| - var stopCriterium = ComputeStopCriterium(sourceVector.InfinityNorm().Real); + var stopCriterium = ComputeStopCriterium(sourceVector.InfinityNorm()); // First check that we have real numbers not NaN's. // NaN's can occur when the iterative process diverges so we // stop if that is the case. - if (double.IsNaN(stopCriterium) || double.IsNaN(residualNorm.Real)) + if (double.IsNaN(stopCriterium) || double.IsNaN(residualNorm)) { _iterationCount = 0; _status = IterationStatus.Diverged; @@ -233,7 +233,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers // ||r_i|| <= stop_tol * ||b|| // Stop the calculation if it's clearly smaller than the tolerance var decimalMagnitude = Math.Abs(stopCriterium.Magnitude()) + 1; - if (residualNorm.Real.IsSmallerWithDecimalPlaces(stopCriterium, decimalMagnitude)) + if (residualNorm.IsSmallerWithDecimalPlaces(stopCriterium, decimalMagnitude)) { if (_lastIteration <= iterationNumber) { diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/TFQMR.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/TFQMR.cs index 2b5f324c..fe11bb58 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/TFQMR.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/TFQMR.cs @@ -145,7 +145,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers double theta = 0; // Initialize - var tau = input.L2Norm().Real; + var tau = input.L2Norm(); Complex rho = tau*tau; // Calculate the initial values for v @@ -204,7 +204,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers yinternal.Add(temp, d); // theta = ||pseudoResiduals||_2 / tau - theta = pseudoResiduals.L2Norm().Real/tau; + theta = pseudoResiduals.L2Norm()/tau; var c = 1/Math.Sqrt(1 + (theta*theta)); // tau = tau * theta * c diff --git a/src/Numerics/LinearAlgebra/Complex/SparseVector.cs b/src/Numerics/LinearAlgebra/Complex/SparseVector.cs index d1980c50..48e02636 100644 --- a/src/Numerics/LinearAlgebra/Complex/SparseVector.cs +++ b/src/Numerics/LinearAlgebra/Complex/SparseVector.cs @@ -711,9 +711,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// Calculates the L1 norm of the vector, also known as Manhattan norm. /// /// The sum of the absolute values. - public override Complex L1Norm() + public override double L1Norm() { - double result = 0; + double result = 0d; for (var i = 0; i < _storage.ValueCount; i++) { result += _storage.Values[i].Magnitude; @@ -725,7 +725,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// Calculates the infinity norm of the vector. /// /// The square root of the sum of the squared values. - public override Complex InfinityNorm() + public override double InfinityNorm() { return CommonParallel.Aggregate(0, _storage.ValueCount, i => _storage.Values[i].Magnitude, Math.Max, 0d); } @@ -735,20 +735,20 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// /// The p value. /// Scalar ret = ( ∑|this[i]|^p )^(1/p) - public override Complex Norm(double p) + public override double Norm(double p) { if (p < 0d) throw new ArgumentOutOfRangeException("p"); if (_storage.ValueCount == 0) { - return Complex.Zero; + return 0d; } if (p == 1d) return L1Norm(); if (p == 2d) return L2Norm(); if (double.IsPositiveInfinity(p)) return InfinityNorm(); - var sum = 0d; + double sum = 0d; for (var index = 0; index < _storage.ValueCount; index++) { sum += Math.Pow(_storage.Values[index].Magnitude, p); diff --git a/src/Numerics/LinearAlgebra/Complex/Vector.cs b/src/Numerics/LinearAlgebra/Complex/Vector.cs index a60e7b5d..7e3f7bbe 100644 --- a/src/Numerics/LinearAlgebra/Complex/Vector.cs +++ b/src/Numerics/LinearAlgebra/Complex/Vector.cs @@ -328,9 +328,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// Calculates the L1 norm of the vector, also known as Manhattan norm. /// /// The sum of the absolute values. - public override Complex L1Norm() + public override double L1Norm() { - var sum = Complex.Zero; + double sum = 0d; for (var i = 0; i < Count; i++) { sum += At(i).Magnitude; @@ -342,16 +342,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// Calculates the L2 norm of the vector, also known as Euclidean norm. /// /// The square root of the sum of the squared values. - public override Complex L2Norm() + public override double L2Norm() { - return DoConjugateDotProduct(this).SquareRoot(); + return DoConjugateDotProduct(this).SquareRoot().Real; } /// /// Calculates the infinity norm of the vector. /// /// The square root of the sum of the squared values. - public override Complex InfinityNorm() + public override double InfinityNorm() { return CommonParallel.Aggregate(0, Count, i => At(i).Magnitude, Math.Max, 0d); } @@ -365,7 +365,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// /// Scalar ret = ( ∑|At(i)|^p )^(1/p) /// - public override Complex Norm(double p) + public override double Norm(double p) { if (p < 0d) throw new ArgumentOutOfRangeException("p"); @@ -373,12 +373,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (p == 2d) return L2Norm(); if (double.IsPositiveInfinity(p)) return InfinityNorm(); - var sum = 0d; + double sum = 0d; for (var index = 0; index < Count; index++) { sum += Math.Pow(At(index).Magnitude, p); } - return Math.Pow(sum, 1.0 / p); + return Math.Pow(sum, 1.0/p); } /// @@ -434,19 +434,19 @@ namespace MathNet.Numerics.LinearAlgebra.Complex /// public override Vector Normalize(double p) { - if (p < 0.0) + if (p < 0d) { throw new ArgumentOutOfRangeException("p"); } - var norm = Norm(p); + double norm = Norm(p); var clone = Clone(); - if (norm.Real == 0.0) + if (norm == 0d) { return clone; } - clone.Multiply(1.0 / norm, clone); + clone.Multiply(1d / norm, clone); return clone; } diff --git a/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs b/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs index d62a6280..d6b9603a 100644 --- a/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs +++ b/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs @@ -547,9 +547,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 /// Calculates the L1 norm of the vector, also known as Manhattan norm. /// /// The sum of the absolute values. - public override Complex32 L1Norm() + public override double L1Norm() { - var sum = Complex32.Zero; + double sum = 0d; for (var i = 0; i < _length; i++) { sum += _values[i].Magnitude; @@ -561,7 +561,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 /// Calculates the L2 norm of the vector, also known as Euclidean norm. /// /// The square root of the sum of the squared values. - public override Complex32 L2Norm() + public override double L2Norm() { // TODO: native provider return _values.Aggregate(Complex32.Zero, SpecialFunctions.Hypotenuse).Magnitude; @@ -571,7 +571,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 /// Calculates the infinity norm of the vector. /// /// The square root of the sum of the squared values. - public override Complex32 InfinityNorm() + public override double InfinityNorm() { return CommonParallel.Aggregate(_values, (i, v) => v.Magnitude, Math.Max, 0f); } @@ -581,7 +581,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 /// /// The p value. /// Scalar ret = ( ∑|this[i]|^p )^(1/p) - public override Complex32 Norm(double p) + public override double Norm(double p) { if (p < 0d) throw new ArgumentOutOfRangeException("p"); @@ -589,12 +589,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (p == 2d) return L2Norm(); if (double.IsPositiveInfinity(p)) return InfinityNorm(); - var sum = 0d; + double sum = 0d; for (var i = 0; i < _length; i++) { sum += Math.Pow(_values[i].Magnitude, p); } - return (float)Math.Pow(sum, 1.0 / p); + return Math.Pow(sum, 1.0 / p); } /// diff --git a/src/Numerics/LinearAlgebra/Complex32/Factorization/UserGramSchmidt.cs b/src/Numerics/LinearAlgebra/Complex32/Factorization/UserGramSchmidt.cs index d726621d..e1dac658 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Factorization/UserGramSchmidt.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Factorization/UserGramSchmidt.cs @@ -64,8 +64,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization for (var k = 0; k < q.ColumnCount; k++) { - var norm = q.Column(k).L2Norm().Real; - if (norm == 0.0f) + var norm = (float) q.Column(k).L2Norm(); + if (norm == 0f) { throw new ArgumentException(Resources.ArgumentMatrixNotRankDeficient); } @@ -73,7 +73,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization r.At(k, k, norm); for (var i = 0; i < q.RowCount; i++) { - q.At(i, k, q.At(i, k) / norm); + q.At(i, k, (q.At(i, k) / norm)); } for (var j = k + 1; j < q.ColumnCount; j++) diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/DivergenceStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/DivergenceStopCriterium.cs index 1778478a..aed4a659 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/DivergenceStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/DivergenceStopCriterium.cs @@ -215,7 +215,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers // Store the infinity norms of both the solution and residual vectors // These values will be used to calculate the relative drop in residuals later on. - _residualHistory[_residualHistory.Length - 1] = residualVector.InfinityNorm().Real; + _residualHistory[_residualHistory.Length - 1] = residualVector.InfinityNorm(); // Check if we have NaN's. If so we've gone way beyond normal divergence. // Stop the iteration. diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/FailureStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/FailureStopCriterium.cs index d5971f72..d2fbc925 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/FailureStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/FailureStopCriterium.cs @@ -91,10 +91,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers } // Store the infinity norms of both the solution and residual vectors - var residualNorm = residualVector.InfinityNorm(); - var solutionNorm = solutionVector.InfinityNorm(); + double residualNorm = residualVector.InfinityNorm(); + double solutionNorm = solutionVector.InfinityNorm(); - _status = float.IsNaN(solutionNorm.Real) || float.IsNaN(residualNorm.Real) ? IterationStatus.Failure : IterationStatus.Continue; + _status = double.IsNaN(solutionNorm) || double.IsNaN(residualNorm) ? IterationStatus.Failure : IterationStatus.Continue; _lastIteration = iterationNumber; return _status; diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/ILUTPPreconditioner.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/ILUTPPreconditioner.cs index d4c74425..b12d6158 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/ILUTPPreconditioner.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/ILUTPPreconditioner.cs @@ -430,7 +430,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers // { // w(j) = 0 // } - if (workVector[j].Magnitude <= _dropTolerance*vectorNorm.Real) + if (workVector[j].Magnitude <= _dropTolerance*vectorNorm) { workVector[j] = 0.0f; } diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/MlkBiCgStab.cs index cfebe47e..181c50dd 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/MlkBiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/MlkBiCgStab.cs @@ -193,7 +193,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers result.Add(orthogonalMatrix.Column(i)); // Normalize the result vector - result[i].Multiply(1 / result[i].L2Norm().Real, result[i]); + result[i].Multiply(1/(float) result[i].L2Norm(), result[i]); } return result; diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/ResidualStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/ResidualStopCriterium.cs index e2993a84..d174ce8d 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/ResidualStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/ResidualStopCriterium.cs @@ -209,16 +209,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers // Store the infinity norms of both the solution and residual vectors // These values will be used to calculate the relative drop in residuals // later on. - var residualNorm = residualVector.InfinityNorm(); + var residualNorm = (float) residualVector.InfinityNorm(); // Check the residuals by calculating: // ||r_i|| <= stop_tol * ||b|| - var stopCriterium = ComputeStopCriterium(sourceVector.InfinityNorm().Real); + var stopCriterium = ComputeStopCriterium((float) sourceVector.InfinityNorm()); // First check that we have real numbers not NaN's. // NaN's can occur when the iterative process diverges so we // stop if that is the case. - if (float.IsNaN(stopCriterium) || float.IsNaN(residualNorm.Real)) + if (float.IsNaN(stopCriterium) || float.IsNaN(residualNorm)) { _iterationCount = 0; _status = IterationStatus.Diverged; @@ -228,7 +228,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers // ||r_i|| <= stop_tol * ||b|| // Stop the calculation if it's clearly smaller than the tolerance var decimalMagnitude = Math.Abs(stopCriterium.Magnitude()) + 1; - if (residualNorm.Real.IsSmallerWithDecimalPlaces(stopCriterium, decimalMagnitude)) + if (residualNorm.IsSmallerWithDecimalPlaces(stopCriterium, decimalMagnitude)) { if (_lastIteration <= iterationNumber) { diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/TFQMR.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/TFQMR.cs index dd71d37b..3608f74a 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/TFQMR.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/TFQMR.cs @@ -142,7 +142,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers float theta = 0; // Initialize - var tau = input.L2Norm().Real; + var tau = (float) input.L2Norm(); Numerics.Complex32 rho = tau*tau; // Calculate the initial values for v @@ -201,7 +201,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers yinternal.Add(temp, d); // theta = ||pseudoResiduals||_2 / tau - theta = pseudoResiduals.L2Norm().Real/tau; + theta = (float) pseudoResiduals.L2Norm()/tau; var c = 1/(float) Math.Sqrt(1 + (theta*theta)); // tau = tau * theta * c diff --git a/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs b/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs index e886410a..86bc894f 100644 --- a/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs +++ b/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs @@ -706,9 +706,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 /// Calculates the L1 norm of the vector, also known as Manhattan norm. /// /// The sum of the absolute values. - public override Complex32 L1Norm() + public override double L1Norm() { - var result = 0f; + double result = 0d; for (var i = 0; i < _storage.ValueCount; i++) { result += _storage.Values[i].Magnitude; @@ -720,7 +720,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 /// Calculates the infinity norm of the vector. /// /// The square root of the sum of the squared values. - public override Complex32 InfinityNorm() + public override double InfinityNorm() { return CommonParallel.Aggregate(0, _storage.ValueCount, i => _storage.Values[i].Magnitude, Math.Max, 0f); } @@ -730,25 +730,25 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 /// /// The p value. /// Scalar ret = ( ∑|this[i]|^p )^(1/p) - public override Complex32 Norm(double p) + public override double Norm(double p) { if (p < 0d) throw new ArgumentOutOfRangeException("p"); if (_storage.ValueCount == 0) { - return Complex32.Zero; + return 0d; } if (p == 1d) return L1Norm(); if (p == 2d) return L2Norm(); if (double.IsPositiveInfinity(p)) return InfinityNorm(); - var sum = 0d; + double sum = 0d; for (var index = 0; index < _storage.ValueCount; index++) { sum += Math.Pow(_storage.Values[index].Magnitude, p); } - return (float)Math.Pow(sum, 1.0 / p); + return Math.Pow(sum, 1.0 / p); } /// diff --git a/src/Numerics/LinearAlgebra/Complex32/Vector.cs b/src/Numerics/LinearAlgebra/Complex32/Vector.cs index 437035f0..310c1d68 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Vector.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Vector.cs @@ -323,9 +323,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 /// Calculates the L1 norm of the vector, also known as Manhattan norm. /// /// The sum of the absolute values. - public override Complex32 L1Norm() + public override double L1Norm() { - var sum = Complex32.Zero; + double sum = 0d; for (var i = 0; i < Count; i++) { sum += At(i).Magnitude; @@ -337,16 +337,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 /// Calculates the L2 norm of the vector, also known as Euclidean norm. /// /// The square root of the sum of the squared values. - public override Complex32 L2Norm() + public override double L2Norm() { - return DoConjugateDotProduct(this).SquareRoot(); + return DoConjugateDotProduct(this).SquareRoot().Real; } /// /// Calculates the infinity norm of the vector. /// /// The square root of the sum of the squared values. - public override Complex32 InfinityNorm() + public override double InfinityNorm() { return CommonParallel.Aggregate(0, Count, i => At(i).Magnitude, Math.Max, 0f); } @@ -360,7 +360,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 /// /// Scalar ret = ( ∑|At(i)|^p )^(1/p) /// - public override Complex32 Norm(double p) + public override double Norm(double p) { if (p < 0d) throw new ArgumentOutOfRangeException("p"); @@ -368,12 +368,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (p == 2d) return L2Norm(); if (double.IsPositiveInfinity(p)) return InfinityNorm(); - var sum = 0d; + double sum = 0d; for (var index = 0; index < Count; index++) { sum += Math.Pow(At(index).Magnitude, p); } - return (float) Math.Pow(sum, 1.0/p); + return Math.Pow(sum, 1.0/p); } /// @@ -429,19 +429,19 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 /// public override Vector Normalize(double p) { - if (p < 0.0) + if (p < 0d) { throw new ArgumentOutOfRangeException("p"); } - var norm = Norm(p); + double norm = Norm(p); var clone = Clone(); - if (norm.Real == 0.0f) + if (norm == 0d) { return clone; } - clone.Multiply(1.0f / norm, clone); + clone.Multiply((float)(1d / norm), clone); return clone; } diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/FailureStopCriterium.cs b/src/Numerics/LinearAlgebra/Double/Solvers/FailureStopCriterium.cs index 8a68a3b3..4876aa9a 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/FailureStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/FailureStopCriterium.cs @@ -89,8 +89,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers } // Store the infinity norms of both the solution and residual vectors - var residualNorm = residualVector.InfinityNorm(); - var solutionNorm = solutionVector.InfinityNorm(); + double residualNorm = residualVector.InfinityNorm(); + double solutionNorm = solutionVector.InfinityNorm(); _status = double.IsNaN(solutionNorm) || double.IsNaN(residualNorm) ? IterationStatus.Failure : IterationStatus.Continue; diff --git a/src/Numerics/LinearAlgebra/Double/Vector.cs b/src/Numerics/LinearAlgebra/Double/Vector.cs index e7ba82b6..13370e19 100644 --- a/src/Numerics/LinearAlgebra/Double/Vector.cs +++ b/src/Numerics/LinearAlgebra/Double/Vector.cs @@ -457,19 +457,19 @@ namespace MathNet.Numerics.LinearAlgebra.Double /// public override Vector Normalize(double p) { - if (p < 0.0) + if (p < 0d) { throw new ArgumentOutOfRangeException("p"); } - var norm = Norm(p); + double norm = Norm(p); var clone = Clone(); - if (norm == 0.0) + if (norm == 0d) { return clone; } - clone.Multiply(1.0 / norm, clone); + clone.Multiply(1d / norm, clone); return clone; } diff --git a/src/Numerics/LinearAlgebra/Single/DenseVector.cs b/src/Numerics/LinearAlgebra/Single/DenseVector.cs index b49411b7..61458d44 100644 --- a/src/Numerics/LinearAlgebra/Single/DenseVector.cs +++ b/src/Numerics/LinearAlgebra/Single/DenseVector.cs @@ -608,9 +608,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single /// Calculates the L1 norm of the vector, also known as Manhattan norm. /// /// The sum of the absolute values. - public override float L1Norm() + public override double L1Norm() { - var sum = 0f; + double sum = 0d; for (var i = 0; i < _length; i++) { sum += Math.Abs(_values[i]); @@ -622,7 +622,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single /// Calculates the L2 norm of the vector, also known as Euclidean norm. /// /// The square root of the sum of the squared values. - public override float L2Norm() + public override double L2Norm() { // TODO: native provider return _values.Aggregate(0f, SpecialFunctions.Hypotenuse); @@ -632,7 +632,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single /// Calculates the infinity norm of the vector. /// /// The square root of the sum of the squared values. - public override float InfinityNorm() + public override double InfinityNorm() { return CommonParallel.Aggregate(_values, (i, v) => Math.Abs(v), Math.Max, 0f); } @@ -642,7 +642,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single /// /// The p value. /// Scalar ret = ( ∑|this[i]|^p )^(1/p) - public override float Norm(double p) + public override double Norm(double p) { if (p < 0d) throw new ArgumentOutOfRangeException("p"); @@ -650,12 +650,12 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (p == 2d) return L2Norm(); if (double.IsPositiveInfinity(p)) return InfinityNorm(); - var sum = 0d; + double sum = 0d; for (var index = 0; index < _length; index++) { sum += Math.Pow(Math.Abs(_values[index]), p); } - return (float)Math.Pow(sum, 1.0 / p); + return Math.Pow(sum, 1.0 / p); } /// diff --git a/src/Numerics/LinearAlgebra/Single/Factorization/UserGramSchmidt.cs b/src/Numerics/LinearAlgebra/Single/Factorization/UserGramSchmidt.cs index a5d70333..63f7f242 100644 --- a/src/Numerics/LinearAlgebra/Single/Factorization/UserGramSchmidt.cs +++ b/src/Numerics/LinearAlgebra/Single/Factorization/UserGramSchmidt.cs @@ -62,8 +62,8 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization for (var k = 0; k < q.ColumnCount; k++) { - var norm = q.Column(k).L2Norm(); - if (norm == 0.0) + var norm = (float) q.Column(k).L2Norm(); + if (norm == 0f) { throw new ArgumentException(Resources.ArgumentMatrixNotRankDeficient); } diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/FailureStopCriterium.cs b/src/Numerics/LinearAlgebra/Single/Solvers/FailureStopCriterium.cs index 4e19c78d..4d25ac57 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/FailureStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/FailureStopCriterium.cs @@ -89,10 +89,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers } // Store the infinity norms of both the solution and residual vectors - var residualNorm = residualVector.InfinityNorm(); - var solutionNorm = solutionVector.InfinityNorm(); + double residualNorm = residualVector.InfinityNorm(); + double solutionNorm = solutionVector.InfinityNorm(); - _status = float.IsNaN(solutionNorm) || float.IsNaN(residualNorm) ? IterationStatus.Failure : IterationStatus.Continue; + _status = double.IsNaN(solutionNorm) || double.IsNaN(residualNorm) ? IterationStatus.Failure : IterationStatus.Continue; _lastIteration = iterationNumber; return _status; diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Single/Solvers/MlkBiCgStab.cs index c1a0f2a2..c0f5555a 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/MlkBiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/MlkBiCgStab.cs @@ -196,7 +196,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers result.Add(orthogonalMatrix.Column(i)); // Normalize the result vector - result[i].Multiply(1 / result[i].L2Norm(), result[i]); + result[i].Multiply(1/(float) result[i].L2Norm(), result[i]); } return result; diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/ResidualStopCriterium.cs b/src/Numerics/LinearAlgebra/Single/Solvers/ResidualStopCriterium.cs index 37e9f37d..e55391cd 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/ResidualStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/ResidualStopCriterium.cs @@ -207,11 +207,11 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers // Store the infinity norms of both the solution and residual vectors // These values will be used to calculate the relative drop in residuals // later on. - var residualNorm = residualVector.InfinityNorm(); + var residualNorm = (float) residualVector.InfinityNorm(); // Check the residuals by calculating: // ||r_i|| <= stop_tol * ||b|| - var stopCriterium = ComputeStopCriterium(sourceVector.InfinityNorm()); + var stopCriterium = ComputeStopCriterium((float) sourceVector.InfinityNorm()); // First check that we have real numbers not NaN's. // NaN's can occur when the iterative process diverges so we diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/TFQMR.cs b/src/Numerics/LinearAlgebra/Single/Solvers/TFQMR.cs index 4faa7648..efc774e3 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/TFQMR.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/TFQMR.cs @@ -142,7 +142,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers float theta = 0; // Initialize - var tau = input.L2Norm(); + var tau = (float) input.L2Norm(); var rho = tau*tau; // Calculate the initial values for v @@ -201,7 +201,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers yinternal.Add(temp, d); // theta = ||pseudoResiduals||_2 / tau - theta = pseudoResiduals.L2Norm()/tau; + theta = (float) pseudoResiduals.L2Norm()/tau; var c = 1/(float) Math.Sqrt(1 + (theta*theta)); // tau = tau * theta * c diff --git a/src/Numerics/LinearAlgebra/Single/SparseVector.cs b/src/Numerics/LinearAlgebra/Single/SparseVector.cs index 3a70decd..e367bc55 100644 --- a/src/Numerics/LinearAlgebra/Single/SparseVector.cs +++ b/src/Numerics/LinearAlgebra/Single/SparseVector.cs @@ -718,9 +718,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single /// Calculates the L1 norm of the vector, also known as Manhattan norm. /// /// The sum of the absolute values. - public override float L1Norm() + public override double L1Norm() { - var result = 0f; + double result = 0d; for (var i = 0; i < _storage.ValueCount; i++) { result += Math.Abs(_storage.Values[i]); @@ -732,7 +732,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single /// Calculates the infinity norm of the vector. /// /// The square root of the sum of the squared values. - public override float InfinityNorm() + public override double InfinityNorm() { return CommonParallel.Aggregate(0, _storage.ValueCount, i => Math.Abs(_storage.Values[i]), Math.Max, 0f); } @@ -742,25 +742,25 @@ namespace MathNet.Numerics.LinearAlgebra.Single /// /// The p value. /// Scalar ret = ( ∑|this[i]|^p )^(1/p) - public override float Norm(double p) + public override double Norm(double p) { if (p < 0d) throw new ArgumentOutOfRangeException("p"); if (_storage.ValueCount == 0) { - return 0f; + return 0d; } if (p == 1d) return L1Norm(); if (p == 2d) return L2Norm(); if (double.IsPositiveInfinity(p)) return InfinityNorm(); - var sum = 0d; + double sum = 0d; for (var index = 0; index < _storage.ValueCount; index++) { sum += Math.Pow(Math.Abs(_storage.Values[index]), p); } - return (float)Math.Pow(sum, 1.0 / p); + return Math.Pow(sum, 1.0 / p); } /// diff --git a/src/Numerics/LinearAlgebra/Single/Vector.cs b/src/Numerics/LinearAlgebra/Single/Vector.cs index 3c1d5645..00bf0351 100644 --- a/src/Numerics/LinearAlgebra/Single/Vector.cs +++ b/src/Numerics/LinearAlgebra/Single/Vector.cs @@ -325,9 +325,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single /// Calculates the L1 norm of the vector, also known as Manhattan norm. /// /// The sum of the absolute values. - public override float L1Norm() + public override double L1Norm() { - var sum = 0.0f; + double sum = 0d; for (var i = 0; i < Count; i++) { sum += Math.Abs(At(i)); @@ -339,16 +339,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single /// Calculates the L2 norm of the vector, also known as Euclidean norm. /// /// The square root of the sum of the squared values. - public override float L2Norm() + public override double L2Norm() { - return (float)Math.Sqrt(DoDotProduct(this)); + return Math.Sqrt(DoDotProduct(this)); } /// /// Calculates the infinity norm of the vector. /// /// The square root of the sum of the squared values. - public override float InfinityNorm() + public override double InfinityNorm() { return CommonParallel.Aggregate(0, Count, i => Math.Abs(At(i)), Math.Max, 0f); } @@ -362,7 +362,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single /// /// Scalar ret = ( ∑|At(i)|^p )^(1/p) /// - public override float Norm(double p) + public override double Norm(double p) { if (p < 0d) throw new ArgumentOutOfRangeException("p"); @@ -370,12 +370,12 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (p == 2d) return L2Norm(); if (double.IsPositiveInfinity(p)) return InfinityNorm(); - var sum = 0d; + double sum = 0d; for (var index = 0; index < Count; index++) { sum += Math.Pow(Math.Abs(At(index)), p); } - return (float) Math.Pow(sum, 1.0/p); + return Math.Pow(sum, 1.0/p); } /// @@ -457,19 +457,19 @@ namespace MathNet.Numerics.LinearAlgebra.Single /// public override Vector Normalize(double p) { - if (p < 0.0) + if (p < 0d) { throw new ArgumentOutOfRangeException("p"); } - var norm = Norm(p); + double norm = Norm(p); var clone = Clone(); - if (norm == 0.0) + if (norm == 0d) { return clone; } - clone.Multiply(1.0f / norm, clone); + clone.Multiply((float)(1d / norm), clone); return clone; } diff --git a/src/Numerics/LinearAlgebra/Vector.Arithmetic.cs b/src/Numerics/LinearAlgebra/Vector.Arithmetic.cs index 75f5aa3d..35de213d 100644 --- a/src/Numerics/LinearAlgebra/Vector.Arithmetic.cs +++ b/src/Numerics/LinearAlgebra/Vector.Arithmetic.cs @@ -748,26 +748,26 @@ namespace MathNet.Numerics.LinearAlgebra /// Calculates the L1 norm of the vector, also known as Manhattan norm. /// /// The sum of the absolute values. - public abstract T L1Norm(); + public abstract double L1Norm(); /// /// Calculates the L2 norm of the vector, also known as Euclidean norm. /// /// The square root of the sum of the squared values. - public abstract T L2Norm(); + public abstract double L2Norm(); /// /// Calculates the infinity norm of the vector. /// /// The square root of the sum of the squared values. - public abstract T InfinityNorm(); + public abstract double InfinityNorm(); /// /// Computes the p-Norm. /// /// The p value. /// Scalar ret = (sum(abs(this[i])^p))^(1/p) - public abstract T Norm(double p); + public abstract double Norm(double p); /// /// Normalizes this vector to a unit vector with respect to the p-norm. @@ -840,7 +840,7 @@ namespace MathNet.Numerics.LinearAlgebra /// Computes the sum of the absolute value of the vector's elements. /// /// The sum of the absolute value of the vector's elements. - public T SumMagnitudes() + public double SumMagnitudes() { return L1Norm(); } diff --git a/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs index 89993f60..72daca2e 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs @@ -466,7 +466,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex var vector = CreateVector(testData); var actual = vector.SumMagnitudes(); var expected = testData.Sum(complex => complex.Magnitude); - Assert.AreEqual(expected, actual.Real); + Assert.AreEqual(expected, actual); } /// diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixTests.Arithmetic.cs b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixTests.Arithmetic.cs index 23e03903..16e9609f 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixTests.Arithmetic.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixTests.Arithmetic.cs @@ -839,7 +839,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 for (var j = 0; j < result.ColumnCount; j++) { var col = result.Column(j); - AssertHelpers.AlmostEqual(Complex32.One, col.Norm(p), 6); + AssertHelpers.AlmostEqual(1d, col.Norm(p), 6); } } @@ -864,7 +864,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 for (var i = 0; i < matrix.RowCount; i++) { var row = matrix.Row(i); - AssertHelpers.AlmostEqual(Complex32.One, row.Norm(p), 6); + AssertHelpers.AlmostEqual(1d, row.Norm(p), 6); } } diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.Norm.cs b/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.Norm.cs index 1a84355c..e2e523b9 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.Norm.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.Norm.cs @@ -80,7 +80,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 public void CanComputeNormP(int p, float expected) { var vector = CreateVector(Data); - AssertHelpers.AlmostEqual(expected, vector.Norm(p).Real, 5); + AssertHelpers.AlmostEqual(expected, (float) vector.Norm(p), 5); } /// @@ -90,8 +90,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 public void CanComputeNormInfinity() { var vector = CreateVector(Data); - AssertHelpers.AlmostEqual(5.0990195, vector.InfinityNorm().Real, 7); - AssertHelpers.AlmostEqual(5.0990195, vector.Norm(Single.PositiveInfinity).Real, 7); + AssertHelpers.AlmostEqual(5.0990195, vector.InfinityNorm(), 7); + AssertHelpers.AlmostEqual(5.0990195, vector.Norm(Single.PositiveInfinity), 7); } /// diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs index e40daf5d..049dfbe3 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs @@ -466,7 +466,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 var vector = CreateVector(testData); var actual = vector.SumMagnitudes(); var expected = testData.Sum(complex => complex.Magnitude); - Assert.AreEqual(expected, actual.Real); + Assert.AreEqual(expected, (float) actual); } ///