From 719f0dcad351f83321d577af99843d01700353f9 Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Sun, 18 May 2014 23:08:23 +0200 Subject: [PATCH] Code Style & Inspections --- MathNet.Numerics.sln.DotSettings | 3 + src/Numerics/Distributions/Cauchy.cs | 2 +- src/Numerics/Distributions/Dirichlet.cs | 14 +- src/Numerics/Exceptions.cs | 58 ++++++ src/Numerics/Generate.cs | 4 +- src/Numerics/Interpolate.cs | 6 +- .../LinearAlgebra/Complex/DenseVector.cs | 4 +- .../LinearAlgebra/Complex/DiagonalMatrix.cs | 5 +- .../LinearAlgebra/Complex/Solvers/BiCgStab.cs | 4 +- .../Complex/Solvers/MILU0Preconditioner.cs | 4 +- .../Complex/Solvers/MlkBiCgStab.cs | 6 +- .../LinearAlgebra/Complex32/DenseVector.cs | 4 +- .../LinearAlgebra/Complex32/DiagonalMatrix.cs | 5 +- .../Complex32/Solvers/BiCgStab.cs | 4 +- .../Complex32/Solvers/MILU0Preconditioner.cs | 4 +- .../Complex32/Solvers/MlkBiCgStab.cs | 6 +- .../LinearAlgebra/Double/DenseVector.cs | 4 +- .../LinearAlgebra/Double/DiagonalMatrix.cs | 5 +- .../LinearAlgebra/Double/Solvers/BiCgStab.cs | 6 +- .../Double/Solvers/MILU0Preconditioner.cs | 4 +- .../Double/Solvers/MlkBiCgStab.cs | 6 +- .../LinearAlgebra/Single/DenseVector.cs | 4 +- .../LinearAlgebra/Single/DiagonalMatrix.cs | 5 +- .../LinearAlgebra/Single/Solvers/BiCgStab.cs | 4 +- .../Single/Solvers/MILU0Preconditioner.cs | 4 +- .../Single/Solvers/MlkBiCgStab.cs | 6 +- .../Storage/DiagonalMatrixStorage.cs | 2 +- .../SparseCompressedRowMatrixStorage.cs | 6 +- src/Numerics/NonConvergenceException.cs | 29 --- src/Numerics/Numerics.csproj | 2 +- src/Numerics/Properties/Resources.Designer.cs | 37 ++++ src/Numerics/Properties/Resources.resx | 13 ++ .../ManagedLinearAlgebraProvider.cs | 2 +- .../LinearAlgebra/Mkl/SafeNativeMethods.cs | 16 +- src/Numerics/Random/CryptoRandomSource.cs | 13 +- src/Numerics/Random/Palf.cs | 2 +- .../Statistics/DescriptiveStatistics.cs | 8 +- src/Numerics/Statistics/Histogram.cs | 2 +- .../Statistics/MCMC/MCMCDiagnostics.cs | 5 +- src/Numerics/Statistics/MCMC/MCMCSampler.cs | 2 +- .../DistributionTests/Continuous/BetaTests.cs | 12 +- .../Continuous/CauchyTests.cs | 10 +- .../Continuous/ChiSquareTests.cs | 6 +- .../DistributionTests/Continuous/ChiTests.cs | 6 +- .../Continuous/ContinuousUniformTests.cs | 12 +- .../Continuous/ErlangTests.cs | 14 +- .../Continuous/ExponentialTests.cs | 6 +- .../Continuous/FisherSnedecorTests.cs | 10 +- .../Continuous/GammaTests.cs | 16 +- .../Continuous/InverseGammaTests.cs | 10 +- .../Continuous/LaplaceTests.cs | 10 +- .../Continuous/LogNormalTests.cs | 12 +- .../Continuous/NormalTests.cs | 12 +- .../Continuous/ParetoTests.cs | 10 +- .../Continuous/RayleighTests.cs | 6 +- .../Continuous/StableTests.cs | 18 +- .../Continuous/StudentTTests.cs | 16 +- .../Continuous/TriangularTests.cs | 10 +- .../Continuous/WeibullTests.cs | 12 +- .../Discrete/BernoulliTests.cs | 8 +- .../Discrete/BinomialTests.cs | 8 +- .../Discrete/CategoricalTests.cs | 42 ++-- .../Discrete/ConwayMaxwellPoissonTests.cs | 10 +- .../Discrete/DiscreteUniformTests.cs | 12 +- .../Discrete/GeometricTests.cs | 6 +- .../Discrete/HypergeometricTests.cs | 26 +-- .../Discrete/NegativeBinomialTests.cs | 10 +- .../Discrete/PoissonTests.cs | 6 +- .../DistributionTests/Discrete/ZipfTests.cs | 8 +- .../Multivariate/DirichletTests.cs | 4 +- .../Multivariate/InverseWishartTests.cs | 12 +- .../Multivariate/MatrixNormalTests.cs | 16 +- .../Multivariate/MultinomialTests.cs | 6 +- .../Multivariate/NormalGammaTests.cs | 4 +- .../Multivariate/WishartTests.cs | 12 +- .../CompoundMonthlyReturnTests.cs | 6 +- .../FinancialTests/DownsideDeviationTests.cs | 2 + .../FinancialTests/GainLossRatioTests.cs | 2 + src/UnitTests/FinancialTests/GainMeanTests.cs | 5 +- .../GainStandardDeviationTests.cs | 4 +- src/UnitTests/FinancialTests/LossMeanTests.cs | 2 + .../LossStandardDeviationTests.cs | 2 + .../FinancialTests/SemiDeviationTests.cs | 2 + src/UnitTests/GenericMath.cs | 11 +- src/UnitTests/GoodnessOfFit/RSquaredTest.cs | 37 +--- .../Single/LinearAlgebraProviderTests.cs | 4 +- .../Complex/Factorization/CholeskyTests.cs | 1 - .../Complex/Factorization/GramSchmidtTests.cs | 28 +-- .../Complex/Factorization/LUTests.cs | 1 - .../Complex/Factorization/QRTests.cs | 1 - .../Factorization/UserCholeskyTests.cs | 1 - .../Factorization/UserGramSchmidtTests.cs | 28 +-- .../Complex/Factorization/UserLUTests.cs | 1 - .../Complex/Factorization/UserQRTests.cs | 1 - .../Complex/MatrixStructureTheory.cs | 4 +- .../Preconditioners/PreConditionerTest.cs | 1 - .../Complex32/Factorization/CholeskyTests.cs | 1 - .../Factorization/GramSchmidtTests.cs | 19 +- .../Complex32/Factorization/LUTests.cs | 1 - .../Complex32/Factorization/QRTests.cs | 1 - .../Factorization/UserCholeskyTests.cs | 1 - .../Factorization/UserGramSchmidtTests.cs | 19 +- .../Complex32/Factorization/UserLUTests.cs | 1 - .../Complex32/Factorization/UserQRTests.cs | 1 - .../Complex32/MatrixStructureTheory.cs | 4 +- .../Preconditioners/PreConditionerTest.cs | 1 - .../Double/DenseVectorArithmeticTheory.cs | 2 +- .../Double/Factorization/CholeskyTests.cs | 1 - .../Double/Factorization/GramSchmidtTests.cs | 19 +- .../Double/Factorization/LUTests.cs | 1 - .../Double/Factorization/QRTests.cs | 18 +- .../Double/Factorization/UserCholeskyTests.cs | 1 - .../Factorization/UserGramSchmidtTests.cs | 19 +- .../Double/Factorization/UserLUTests.cs | 1 - .../Double/Factorization/UserQRTests.cs | 1 - .../Double/MatrixStructureTheory.cs | 4 +- .../Preconditioners/PreConditionerTest.cs | 1 - .../LinearAlgebraTests/Double/VectorTests.cs | 7 +- .../MatrixStructureTheory.cs | 88 ++++---- .../Single/DenseVectorArithmeticTheory.cs | 2 +- .../Single/Factorization/CholeskyTests.cs | 1 - .../Single/Factorization/GramSchmidtTests.cs | 19 +- .../Single/Factorization/LUTests.cs | 1 - .../Single/Factorization/QRTests.cs | 18 +- .../Single/Factorization/UserCholeskyTests.cs | 1 - .../Factorization/UserGramSchmidtTests.cs | 19 +- .../Single/Factorization/UserLUTests.cs | 1 - .../Single/Factorization/UserQRTests.cs | 1 - .../Single/MatrixStructureTheory.cs | 4 +- .../Preconditioners/PreConditionerTest.cs | 1 - .../Single/SparseMatrixTests.cs | 21 -- .../LinearAlgebraTests/Single/VectorTests.cs | 6 +- src/UnitTests/PermutationTest.cs | 2 +- src/UnitTests/Random/PalfTests.cs | 1 - src/UnitTests/RootFindingTests/BroydenTest.cs | 192 +++++++++--------- .../StatisticsTests/CorrelationTests.cs | 4 +- .../StatisticsTests/MCMCTests/HybridMCTest.cs | 30 +-- .../MCMCTests/UnivariateSliceSamplerTests.cs | 2 +- .../StatisticsTests/StatisticsTests.cs | 8 +- 139 files changed, 630 insertions(+), 778 deletions(-) create mode 100644 src/Numerics/Exceptions.cs delete mode 100644 src/Numerics/NonConvergenceException.cs diff --git a/MathNet.Numerics.sln.DotSettings b/MathNet.Numerics.sln.DotSettings index 213f7deb..104d6356 100644 --- a/MathNet.Numerics.sln.DotSettings +++ b/MathNet.Numerics.sln.DotSettings @@ -1,5 +1,7 @@  True + HINT + HINT <?xml version="1.0" encoding="utf-16"?><Profile name="Full Cleanup (Math.NET)"><CSArrangeThisQualifier>True</CSArrangeThisQualifier><CSRemoveCodeRedundancies>True</CSRemoveCodeRedundancies><CSUseAutoProperty>True</CSUseAutoProperty><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSUpdateFileHeader>True</CSUpdateFileHeader><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSShortenReferences>True</CSShortenReferences><CSReformatCode>True</CSReformatCode><XMLReformatCode>True</XMLReformatCode><CssAlphabetizeProperties>True</CssAlphabetizeProperties><CssReformatCode>True</CssReformatCode><JsReformatCode>True</JsReformatCode><JsInsertSemicolon>True</JsInsertSemicolon><VBFormatDocComments>True</VBFormatDocComments><VBReformatCode>True</VBReformatCode><VBShortenReferences>True</VBShortenReferences><VBOptimizeImports>True</VBOptimizeImports><HtmlReformatCode>True</HtmlReformatCode><AspOptimizeRegisterDirectives>True</AspOptimizeRegisterDirectives><CSReorderTypeMembers>True</CSReorderTypeMembers><CSUseVar><BehavourStyle>CAN_CHANGE_BOTH</BehavourStyle><LocalVariableStyle>IMPLICIT_WHEN_INITIALIZER_HAS_TYPE</LocalVariableStyle><ForeachVariableStyle>ALWAYS_EXPLICIT</ForeachVariableStyle></CSUseVar></Profile> Full Cleanup (Math.NET) False @@ -65,6 +67,7 @@ OTHER DEALINGS IN THE SOFTWARE. MKL MSE PDF + PMF QR SAD SAS diff --git a/src/Numerics/Distributions/Cauchy.cs b/src/Numerics/Distributions/Cauchy.cs index 045b38d9..7a58c789 100644 --- a/src/Numerics/Distributions/Cauchy.cs +++ b/src/Numerics/Distributions/Cauchy.cs @@ -365,7 +365,7 @@ namespace MathNet.Numerics.Distributions { if (scale <= 0.0) throw new ArgumentException(Resources.InvalidDistributionParameters); - return SampleUnchecked(SystemRandomSource.Default, location, scale); + return SampleUnchecked(rnd, location, scale); } /// diff --git a/src/Numerics/Distributions/Dirichlet.cs b/src/Numerics/Distributions/Dirichlet.cs index 420713a5..bd401c2a 100644 --- a/src/Numerics/Distributions/Dirichlet.cs +++ b/src/Numerics/Distributions/Dirichlet.cs @@ -129,17 +129,11 @@ namespace MathNet.Numerics.Distributions { var allzero = true; - foreach (var t in alpha) + for (int i = 0; i < alpha.Length; i++) { - if (t < 0.0) - { - return false; - } - - if (t > 0.0) - { - allzero = false; - } + var t = alpha[i]; + if (t < 0.0) return false; + if (t > 0.0) allzero = false; } return !allzero; diff --git a/src/Numerics/Exceptions.cs b/src/Numerics/Exceptions.cs new file mode 100644 index 00000000..ddee11f5 --- /dev/null +++ b/src/Numerics/Exceptions.cs @@ -0,0 +1,58 @@ +using System; +using MathNet.Numerics.Properties; + +namespace MathNet.Numerics +{ + /// + /// An algorithm failed to converge. + /// + [Serializable] + public class NonConvergenceException : Exception + { + public NonConvergenceException() : base(Resources.ConvergenceFailed) + { + } + + public NonConvergenceException(string message) : base(message) + { + } + + public NonConvergenceException(string message, Exception innerException) : base(message, innerException) + { + } +#if !PORTABLE + protected NonConvergenceException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) + : base(info, context) + { + } +#endif + } + + /// + /// An algorithm failed to converge due to a numerical breakdown. + /// + [Serializable] + public class NumericalBreakdownException : NonConvergenceException + { + public NumericalBreakdownException() + : base(Resources.NumericalBreakdown) + { + } + + public NumericalBreakdownException(string message) + : base(message) + { + } + + public NumericalBreakdownException(string message, Exception innerException) + : base(message, innerException) + { + } +#if !PORTABLE + protected NumericalBreakdownException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) + : base(info, context) + { + } +#endif + } +} diff --git a/src/Numerics/Generate.cs b/src/Numerics/Generate.cs index 5ff9cfa5..74c552f3 100644 --- a/src/Numerics/Generate.cs +++ b/src/Numerics/Generate.cs @@ -223,7 +223,7 @@ namespace MathNet.Numerics /// public static double[] LinearRange(double start, double step, double stop) { - if (start == stop) return new double[] { start }; + if (start == stop) return new[] { start }; if (start < stop && step < 0 || start > stop && step > 0 || step == 0d) { return new double[0]; @@ -243,7 +243,7 @@ namespace MathNet.Numerics /// public static T[] LinearRangeMap(double start, double step, double stop, Func map) { - if (start == stop) return new T[] { map(start) }; + if (start == stop) return new[] { map(start) }; if (start < stop && step < 0 || start > stop && step > 0 || step == 0d) { return new T[0]; diff --git a/src/Numerics/Interpolate.cs b/src/Numerics/Interpolate.cs index 988dd055..f3c4250b 100644 --- a/src/Numerics/Interpolate.cs +++ b/src/Numerics/Interpolate.cs @@ -50,7 +50,7 @@ namespace MathNet.Numerics /// public static IInterpolation Common(IEnumerable points, IEnumerable values) { - return Interpolation.Barycentric.InterpolateRationalFloaterHormann(points, values); + return Barycentric.InterpolateRationalFloaterHormann(points, values); } /// @@ -65,7 +65,7 @@ namespace MathNet.Numerics /// public static IInterpolation RationalWithoutPoles(IEnumerable points, IEnumerable values) { - return Interpolation.Barycentric.InterpolateRationalFloaterHormann(points, values); + return Barycentric.InterpolateRationalFloaterHormann(points, values); } /// @@ -99,7 +99,7 @@ namespace MathNet.Numerics /// public static IInterpolation PolynomialEquidistant(IEnumerable points, IEnumerable values) { - return Interpolation.Barycentric.InterpolatePolynomialEquidistant(points, values); + return Barycentric.InterpolatePolynomialEquidistant(points, values); } /// diff --git a/src/Numerics/LinearAlgebra/Complex/DenseVector.cs b/src/Numerics/LinearAlgebra/Complex/DenseVector.cs index 0499b8c4..967606a4 100644 --- a/src/Numerics/LinearAlgebra/Complex/DenseVector.cs +++ b/src/Numerics/LinearAlgebra/Complex/DenseVector.cs @@ -184,7 +184,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex { if (vector == null) { - throw new ArgumentNullException(); + throw new ArgumentNullException("vector"); } return vector.Values; @@ -201,7 +201,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex { if (array == null) { - throw new ArgumentNullException(); + throw new ArgumentNullException("array"); } return new DenseVector(array); diff --git a/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs index afc840ad..84fb114d 100644 --- a/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs +++ b/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs @@ -58,8 +58,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex [DebuggerDisplay("DiagonalMatrix {RowCount}x{ColumnCount}-Complex")] public class DiagonalMatrix : Matrix { - readonly DiagonalMatrixStorage _storage; - /// /// Gets the matrix's data. /// @@ -75,8 +73,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex public DiagonalMatrix(DiagonalMatrixStorage storage) : base(storage) { - _storage = storage; - _data = _storage.Data; + _data = storage.Data; } /// diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/BiCgStab.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/BiCgStab.cs index 8ec28c16..b32b15d7 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/BiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/BiCgStab.cs @@ -167,7 +167,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers if (currentRho.Real.AlmostEqualNumbersBetween(0, 1) && currentRho.Imaginary.AlmostEqualNumbersBetween(0, 1)) { // Rho-type breakdown - throw new Exception("Iterative solver experience a numerical break down"); + throw new NumericalBreakdownException(); } if (iterationNumber != 0) @@ -261,7 +261,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers if (omega.Real.AlmostEqualNumbersBetween(0, 1) && omega.Imaginary.AlmostEqualNumbersBetween(0, 1)) { // Omega-type breakdown - throw new Exception("Iterative solver experience a numerical break down"); + throw new NumericalBreakdownException(); } if (iterator.DetermineStatus(iterationNumber, result, input, residuals) != IterationStatus.Continue) diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/MILU0Preconditioner.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/MILU0Preconditioner.cs index bdfef1c7..45350384 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/MILU0Preconditioner.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/MILU0Preconditioner.cs @@ -92,7 +92,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers var csr = matrix.Storage as SparseCompressedRowMatrixStorage; if (csr == null) { - throw new ArgumentException("Matrix must be in sparse storage format", "matrix"); + throw new ArgumentException(Resources.MatrixMustBeSparse, "matrix"); } // Dimension of matrix @@ -114,7 +114,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers int code = Compute(n, a, ja, ia, _alu, _jlu, _diag, UseModified); if (code > -1) { - throw new Exception("Zero pivot encountered on row " + code + " during ILU process"); + throw new NumericalBreakdownException("Zero pivot encountered on row " + code + " during ILU process"); } IsInitialized = true; diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/MlkBiCgStab.cs index 1339c6db..3964ff1e 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/MlkBiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/MlkBiCgStab.cs @@ -345,7 +345,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers c[k - 1] = _startingVectors[0].ConjugateDotProduct(w[k - 1]); if (c[k - 1].Real.AlmostEqualNumbersBetween(0, 1) && c[k - 1].Imaginary.AlmostEqualNumbersBetween(0, 1)) { - throw new Exception("Iterative solver experience a numerical break down"); + throw new NumericalBreakdownException(); } // alpha_(jk+1) = q^T_1 r_((j-1)k+k) / c_((j-1)k+k) @@ -446,7 +446,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers beta = rho*c[k - 1]; if (beta.Real.AlmostEqualNumbersBetween(0, 1) && beta.Imaginary.AlmostEqualNumbersBetween(0, 1)) { - throw new Exception("Iterative solver experience a numerical break down"); + throw new NumericalBreakdownException(); } // beta^(jk+i)_((j-1)k+k) = -(q^T_1 (r_(jk+1) + rho_(j+1) z_w)) / (rho_(j+1) c_((j-1)k+k)) @@ -498,7 +498,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers c[i] = _startingVectors[i + 1].ConjugateDotProduct(d[i]); if (c[i].Real.AlmostEqualNumbersBetween(0, 1) && c[i].Imaginary.AlmostEqualNumbersBetween(0, 1)) { - throw new Exception("Iterative solver experience a numerical break down"); + throw new NumericalBreakdownException(); } // alpha_(jk+i+1) = q^T_(i+1) u_(jk+i) / c_(jk+i) diff --git a/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs b/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs index d0b77387..6f88ebdf 100644 --- a/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs +++ b/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs @@ -179,7 +179,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 { if (vector == null) { - throw new ArgumentNullException(); + throw new ArgumentNullException("vector"); } return vector.Values; @@ -196,7 +196,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 { if (array == null) { - throw new ArgumentNullException(); + throw new ArgumentNullException("array"); } return new DenseVector(array); diff --git a/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs index b5341fbd..6aa3b62a 100644 --- a/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs +++ b/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs @@ -53,8 +53,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 [DebuggerDisplay("DiagonalMatrix {RowCount}x{ColumnCount}-Complex32")] public class DiagonalMatrix : Matrix { - readonly DiagonalMatrixStorage _storage; - /// /// Gets the matrix's data. /// @@ -70,8 +68,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 public DiagonalMatrix(DiagonalMatrixStorage storage) : base(storage) { - _storage = storage; - _data = _storage.Data; + _data = storage.Data; } /// diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/BiCgStab.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/BiCgStab.cs index 756a076d..bd04e961 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/BiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/BiCgStab.cs @@ -160,7 +160,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers if (currentRho.Real.AlmostEqualNumbersBetween(0, 1) && currentRho.Imaginary.AlmostEqualNumbersBetween(0, 1)) { // Rho-type breakdown - throw new Exception("Iterative solver experience a numerical break down"); + throw new NumericalBreakdownException(); } if (iterationNumber != 0) @@ -254,7 +254,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers if (omega.Real.AlmostEqualNumbersBetween(0, 1) && omega.Imaginary.AlmostEqualNumbersBetween(0, 1)) { // Omega-type breakdown - throw new Exception("Iterative solver experience a numerical break down"); + throw new NumericalBreakdownException(); } if (iterator.DetermineStatus(iterationNumber, result, input, residuals) != IterationStatus.Continue) diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/MILU0Preconditioner.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/MILU0Preconditioner.cs index bfabc36d..6c005e0a 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/MILU0Preconditioner.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/MILU0Preconditioner.cs @@ -87,7 +87,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers var csr = matrix.Storage as SparseCompressedRowMatrixStorage; if (csr == null) { - throw new ArgumentException("Matrix must be in sparse storage format", "matrix"); + throw new ArgumentException(Resources.MatrixMustBeSparse, "matrix"); } // Dimension of matrix @@ -109,7 +109,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers int code = Compute(n, a, ja, ia, _alu, _jlu, _diag, UseModified); if (code > -1) { - throw new Exception("Zero pivot encountered on row " + code + " during ILU process"); + throw new NumericalBreakdownException("Zero pivot encountered on row " + code + " during ILU process"); } IsInitialized = true; diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/MlkBiCgStab.cs index 8fba9de9..e8ad86b5 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/MlkBiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/MlkBiCgStab.cs @@ -343,7 +343,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers c[k - 1] = _startingVectors[0].ConjugateDotProduct(w[k - 1]); if (c[k - 1].Real.AlmostEqualNumbersBetween(0, 1) && c[k - 1].Imaginary.AlmostEqualNumbersBetween(0, 1)) { - throw new Exception("Iterative solver experience a numerical break down"); + throw new NumericalBreakdownException(); } // alpha_(jk+1) = q^T_1 r_((j-1)k+k) / c_((j-1)k+k) @@ -444,7 +444,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers beta = rho*c[k - 1]; if (beta.Real.AlmostEqualNumbersBetween(0, 1) && beta.Imaginary.AlmostEqualNumbersBetween(0, 1)) { - throw new Exception("Iterative solver experience a numerical break down"); + throw new NumericalBreakdownException(); } // beta^(jk+i)_((j-1)k+k) = -(q^T_1 (r_(jk+1) + rho_(j+1) z_w)) / (rho_(j+1) c_((j-1)k+k)) @@ -496,7 +496,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers c[i] = _startingVectors[i + 1].ConjugateDotProduct(d[i]); if (c[i].Real.AlmostEqualNumbersBetween(0, 1) && c[i].Imaginary.AlmostEqualNumbersBetween(0, 1)) { - throw new Exception("Iterative solver experience a numerical break down"); + throw new NumericalBreakdownException(); } // alpha_(jk+i+1) = q^T_(i+1) u_(jk+i) / c_(jk+i) diff --git a/src/Numerics/LinearAlgebra/Double/DenseVector.cs b/src/Numerics/LinearAlgebra/Double/DenseVector.cs index 0c12ad99..ab7548ef 100644 --- a/src/Numerics/LinearAlgebra/Double/DenseVector.cs +++ b/src/Numerics/LinearAlgebra/Double/DenseVector.cs @@ -179,7 +179,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double { if (vector == null) { - throw new ArgumentNullException(); + throw new ArgumentNullException("vector"); } return vector.Values; @@ -196,7 +196,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double { if (array == null) { - throw new ArgumentNullException(); + throw new ArgumentNullException("array"); } return new DenseVector(array); diff --git a/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs index 0b9dad62..bed0524a 100644 --- a/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs +++ b/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs @@ -52,8 +52,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double [DebuggerDisplay("DiagonalMatrix {RowCount}x{ColumnCount}-Double")] public class DiagonalMatrix : Matrix { - readonly DiagonalMatrixStorage _storage; - /// /// Gets the matrix's data. /// @@ -69,8 +67,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double public DiagonalMatrix(DiagonalMatrixStorage storage) : base(storage) { - _storage = storage; - _data = _storage.Data; + _data = storage.Data; } /// diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/BiCgStab.cs b/src/Numerics/LinearAlgebra/Double/Solvers/BiCgStab.cs index 50ca954c..977ceb43 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/BiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/BiCgStab.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2013 Math.NET +// Copyright (c) 2009-2014 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -160,7 +160,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers if (currentRho.AlmostEqualNumbersBetween(0, 1)) { // Rho-type breakdown - throw new Exception("Iterative solver experience a numerical break down"); + throw new NumericalBreakdownException(); } if (iterationNumber != 0) @@ -254,7 +254,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers if (omega.AlmostEqualNumbersBetween(0, 1)) { // Omega-type breakdown - throw new Exception("Iterative solver experience a numerical break down"); + throw new NumericalBreakdownException(); } if (iterator.DetermineStatus(iterationNumber, result, input, residuals) != IterationStatus.Continue) diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/MILU0Preconditioner.cs b/src/Numerics/LinearAlgebra/Double/Solvers/MILU0Preconditioner.cs index 5f9683af..17ffe73a 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/MILU0Preconditioner.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/MILU0Preconditioner.cs @@ -85,7 +85,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers var csr = matrix.Storage as SparseCompressedRowMatrixStorage; if (csr == null) { - throw new ArgumentException("Matrix must be in sparse storage format", "matrix"); + throw new ArgumentException(Resources.MatrixMustBeSparse, "matrix"); } // Dimension of matrix @@ -107,7 +107,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers int code = Compute(n, a, ja, ia, _alu, _jlu, _diag, UseModified); if (code > -1) { - throw new Exception("Zero pivot encountered on row " + code + " during ILU process"); + throw new NumericalBreakdownException("Zero pivot encountered on row " + code + " during ILU process"); } IsInitialized = true; diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Double/Solvers/MlkBiCgStab.cs index 446ba02a..4b819916 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/MlkBiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/MlkBiCgStab.cs @@ -343,7 +343,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers c[k - 1] = _startingVectors[0].DotProduct(w[k - 1]); if (c[k - 1].AlmostEqualNumbersBetween(0, 1)) { - throw new Exception("Iterative solver experience a numerical break down"); + throw new NumericalBreakdownException(); } // alpha_(jk+1) = q^T_1 r_((j-1)k+k) / c_((j-1)k+k) @@ -444,7 +444,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers beta = rho*c[k - 1]; if (beta.AlmostEqualNumbersBetween(0, 1)) { - throw new Exception("Iterative solver experience a numerical break down"); + throw new NumericalBreakdownException(); } // beta^(jk+i)_((j-1)k+k) = -(q^T_1 (r_(jk+1) + rho_(j+1) z_w)) / (rho_(j+1) c_((j-1)k+k)) @@ -496,7 +496,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers c[i] = _startingVectors[i + 1].DotProduct(d[i]); if (c[i].AlmostEqualNumbersBetween(0, 1)) { - throw new Exception("Iterative solver experience a numerical break down"); + throw new NumericalBreakdownException(); } // alpha_(jk+i+1) = q^T_(i+1) u_(jk+i) / c_(jk+i) diff --git a/src/Numerics/LinearAlgebra/Single/DenseVector.cs b/src/Numerics/LinearAlgebra/Single/DenseVector.cs index d71b34c2..a35581f9 100644 --- a/src/Numerics/LinearAlgebra/Single/DenseVector.cs +++ b/src/Numerics/LinearAlgebra/Single/DenseVector.cs @@ -178,7 +178,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single { if (vector == null) { - throw new ArgumentNullException(); + throw new ArgumentNullException("vector"); } return vector.Values; @@ -195,7 +195,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single { if (array == null) { - throw new ArgumentNullException(); + throw new ArgumentNullException("array"); } return new DenseVector(array); diff --git a/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs index 13622d4d..7b07623c 100644 --- a/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs +++ b/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs @@ -52,8 +52,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single [DebuggerDisplay("DiagonalMatrix {RowCount}x{ColumnCount}-Single")] public class DiagonalMatrix : Matrix { - readonly DiagonalMatrixStorage _storage; - /// /// Gets the matrix's data. /// @@ -69,8 +67,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single public DiagonalMatrix(DiagonalMatrixStorage storage) : base(storage) { - _storage = storage; - _data = _storage.Data; + _data = storage.Data; } /// diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/BiCgStab.cs b/src/Numerics/LinearAlgebra/Single/Solvers/BiCgStab.cs index 5874afc9..dcf28008 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/BiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/BiCgStab.cs @@ -160,7 +160,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers if (currentRho.AlmostEqualNumbersBetween(0, 1)) { // Rho-type breakdown - throw new Exception("Iterative solver experience a numerical break down"); + throw new NumericalBreakdownException(); } if (iterationNumber != 0) @@ -254,7 +254,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers if (omega.AlmostEqualNumbersBetween(0, 1)) { // Omega-type breakdown - throw new Exception("Iterative solver experience a numerical break down"); + throw new NumericalBreakdownException(); } if (iterator.DetermineStatus(iterationNumber, result, input, residuals) != IterationStatus.Continue) diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/MILU0Preconditioner.cs b/src/Numerics/LinearAlgebra/Single/Solvers/MILU0Preconditioner.cs index 2e26e4dd..308005e1 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/MILU0Preconditioner.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/MILU0Preconditioner.cs @@ -85,7 +85,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers var csr = matrix.Storage as SparseCompressedRowMatrixStorage; if (csr == null) { - throw new ArgumentException("Matrix must be in sparse storage format", "matrix"); + throw new ArgumentException(Resources.MatrixMustBeSparse, "matrix"); } // Dimension of matrix @@ -107,7 +107,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers int code = Compute(n, a, ja, ia, _alu, _jlu, _diag, UseModified); if (code > -1) { - throw new Exception("Zero pivot encountered on row " + code + " during ILU process"); + throw new NumericalBreakdownException("Zero pivot encountered on row " + code + " during ILU process"); } IsInitialized = true; diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Single/Solvers/MlkBiCgStab.cs index 25fa5230..db4450d1 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/MlkBiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/MlkBiCgStab.cs @@ -346,7 +346,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers c[k - 1] = _startingVectors[0].DotProduct(w[k - 1]); if (c[k - 1].AlmostEqualNumbersBetween(0, 1)) { - throw new Exception("Iterative solver experience a numerical break down"); + throw new NumericalBreakdownException(); } // alpha_(jk+1) = q^T_1 r_((j-1)k+k) / c_((j-1)k+k) @@ -447,7 +447,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers beta = rho*c[k - 1]; if (beta.AlmostEqualNumbersBetween(0, 1)) { - throw new Exception("Iterative solver experience a numerical break down"); + throw new NumericalBreakdownException(); } // beta^(jk+i)_((j-1)k+k) = -(q^T_1 (r_(jk+1) + rho_(j+1) z_w)) / (rho_(j+1) c_((j-1)k+k)) @@ -499,7 +499,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers c[i] = _startingVectors[i + 1].DotProduct(d[i]); if (c[i].AlmostEqualNumbersBetween(0, 1)) { - throw new Exception("Iterative solver experience a numerical break down"); + throw new NumericalBreakdownException(); } // alpha_(jk+i+1) = q^T_(i+1) u_(jk+i) / c_(jk+i) diff --git a/src/Numerics/LinearAlgebra/Storage/DiagonalMatrixStorage.cs b/src/Numerics/LinearAlgebra/Storage/DiagonalMatrixStorage.cs index 389a0cf6..d0d47290 100644 --- a/src/Numerics/LinearAlgebra/Storage/DiagonalMatrixStorage.cs +++ b/src/Numerics/LinearAlgebra/Storage/DiagonalMatrixStorage.cs @@ -226,7 +226,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage } else if (!Zero.Equals(array[i, j])) { - throw new IndexOutOfRangeException("Cannot set an off-diagonal element in a diagonal matrix."); + throw new ArgumentException("Cannot set an off-diagonal element in a diagonal matrix."); } } } diff --git a/src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs b/src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs index 7f328689..f1ed149a 100644 --- a/src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs +++ b/src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs @@ -1799,11 +1799,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage internal override void FoldColumnsUnchecked(VectorStorage target, Func f, Func finalize, VectorStorage state, Zeros zeros = Zeros.AllowSkip) { - var denseResult = target as DenseVectorStorage; - if (denseResult == null) - { - denseResult = new DenseVectorStorage(ColumnCount); - } + var denseResult = target as DenseVectorStorage ?? new DenseVectorStorage(ColumnCount); state.CopyTo(denseResult); TU[] result = denseResult.Data; diff --git a/src/Numerics/NonConvergenceException.cs b/src/Numerics/NonConvergenceException.cs deleted file mode 100644 index 9e873726..00000000 --- a/src/Numerics/NonConvergenceException.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using MathNet.Numerics.Properties; - -namespace MathNet.Numerics -{ - /// - /// An algorithm failed to converge. - /// - public class NonConvergenceException : Exception - { - public NonConvergenceException() : base(Resources.ConvergenceFailed) - { - } - - public NonConvergenceException(string message) : base(message) - { - } - - public NonConvergenceException(string message, Exception innerException) : base(message, innerException) - { - } -#if !PORTABLE - protected NonConvergenceException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) - : base(info, context) - { - } -#endif - } -} diff --git a/src/Numerics/Numerics.csproj b/src/Numerics/Numerics.csproj index fc7af786..0d49265e 100644 --- a/src/Numerics/Numerics.csproj +++ b/src/Numerics/Numerics.csproj @@ -191,7 +191,7 @@ - + diff --git a/src/Numerics/Properties/Resources.Designer.cs b/src/Numerics/Properties/Resources.Designer.cs index dfec22f9..6022fe78 100644 --- a/src/Numerics/Properties/Resources.Designer.cs +++ b/src/Numerics/Properties/Resources.Designer.cs @@ -654,6 +654,24 @@ namespace MathNet.Numerics.Properties { } } + /// + /// Looks up a localized string similar to Lag must be positive. + /// + public static string LagMustBePositive { + get { + return ResourceManager.GetString("LagMustBePositive", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Lag must be smaller than the sample size. + /// + public static string LagMustBeSmallerThanTheSampleSize { + get { + return ResourceManager.GetString("LagMustBeSmallerThanTheSampleSize", resourceCulture); + } + } + /// /// Looks up a localized string similar to ddd MMM dd HH:mm:ss yyyy. /// @@ -672,6 +690,15 @@ namespace MathNet.Numerics.Properties { } } + /// + /// Looks up a localized string similar to Matrix must be in sparse storage format. + /// + public static string MatrixMustBeSparse { + get { + return ResourceManager.GetString("MatrixMustBeSparse", resourceCulture); + } + } + /// /// Looks up a localized string similar to The number of rows of a matrix must be positive.. /// @@ -726,6 +753,16 @@ namespace MathNet.Numerics.Properties { } } + /// + /// Looks up a localized string similar to Algorithm experience a numerical break down + ///. + /// + public static string NumericalBreakdown { + get { + return ResourceManager.GetString("NumericalBreakdown", resourceCulture); + } + } + /// /// Looks up a localized string similar to The two arguments can't be compared (maybe they are part of a partial ordering?). /// diff --git a/src/Numerics/Properties/Resources.resx b/src/Numerics/Properties/Resources.resx index 094445fd..16672f5f 100644 --- a/src/Numerics/Properties/Resources.resx +++ b/src/Numerics/Properties/Resources.resx @@ -390,4 +390,17 @@ The algorithm has failed, exceeded the number of iterations allowed or there is no root within the provided bounds. Consider to use RobustNewtonRaphson instead. + + Algorithm experience a numerical break down + + + + Lag must be positive + + + Lag must be smaller than the sample size + + + Matrix must be in sparse storage format + \ No newline at end of file diff --git a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.cs b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.cs index c92a2ca0..280e1872 100644 --- a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.cs +++ b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.cs @@ -36,7 +36,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra public partial class ManagedLinearAlgebraProvider : ILinearAlgebraProvider { /// - /// Initialize and verify that the provided is indeed available. If not, fall back to alernatives like the managed provider + /// Initialize and verify that the provided is indeed available. If not, fall back to alternatives like the managed provider /// public virtual void InitializeVerify() { diff --git a/src/Numerics/Providers/LinearAlgebra/Mkl/SafeNativeMethods.cs b/src/Numerics/Providers/LinearAlgebra/Mkl/SafeNativeMethods.cs index 02f9531f..663c92e6 100644 --- a/src/Numerics/Providers/LinearAlgebra/Mkl/SafeNativeMethods.cs +++ b/src/Numerics/Providers/LinearAlgebra/Mkl/SafeNativeMethods.cs @@ -266,28 +266,28 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl internal static extern int z_qr_solve_factored(int m, int n, int bn, Complex[] r, Complex[] b, Complex[] tau, [In, Out] Complex[] x, [In, Out] Complex[] work, int len); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern int s_svd_factor(bool computeVectors, int m, int n, [In, Out] float[] a, [In, Out] float[] s, [In, Out] float[] u, [In, Out] float[] v, [In, Out] float[] work, int len); + internal static extern int s_svd_factor([MarshalAs(UnmanagedType.U1)] bool computeVectors, int m, int n, [In, Out] float[] a, [In, Out] float[] s, [In, Out] float[] u, [In, Out] float[] v, [In, Out] float[] work, int len); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern int d_svd_factor(bool computeVectors, int m, int n, [In, Out] double[] a, [In, Out] double[] s, [In, Out] double[] u, [In, Out] double[] v, [In, Out] double[] work, int len); + internal static extern int d_svd_factor([MarshalAs(UnmanagedType.U1)] bool computeVectors, int m, int n, [In, Out] double[] a, [In, Out] double[] s, [In, Out] double[] u, [In, Out] double[] v, [In, Out] double[] work, int len); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern int c_svd_factor(bool computeVectors, int m, int n, [In, Out] Complex32[] a, [In, Out] Complex32[] s, [In, Out] Complex32[] u, [In, Out] Complex32[] v, [In, Out] Complex32[] work, int len); + internal static extern int c_svd_factor([MarshalAs(UnmanagedType.U1)] bool computeVectors, int m, int n, [In, Out] Complex32[] a, [In, Out] Complex32[] s, [In, Out] Complex32[] u, [In, Out] Complex32[] v, [In, Out] Complex32[] work, int len); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern int z_svd_factor(bool computeVectors, int m, int n, [In, Out] Complex[] a, [In, Out] Complex[] s, [In, Out] Complex[] u, [In, Out] Complex[] v, [In, Out] Complex[] work, int len); + internal static extern int z_svd_factor([MarshalAs(UnmanagedType.U1)] bool computeVectors, int m, int n, [In, Out] Complex[] a, [In, Out] Complex[] s, [In, Out] Complex[] u, [In, Out] Complex[] v, [In, Out] Complex[] work, int len); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern int s_eigen(bool isSymmetric, int n, [In] float[] a, [In, Out] float[] vectors, [In, Out] Complex[] values, [In, Out] float[] d); + internal static extern int s_eigen([MarshalAs(UnmanagedType.U1)] bool isSymmetric, int n, [In] float[] a, [In, Out] float[] vectors, [In, Out] Complex[] values, [In, Out] float[] d); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern int d_eigen(bool isSymmetric, int n, [In] double[] a, [In, Out] double[] vectors, [In, Out] Complex[] values, [In, Out] double[] d); + internal static extern int d_eigen([MarshalAs(UnmanagedType.U1)] bool isSymmetric, int n, [In] double[] a, [In, Out] double[] vectors, [In, Out] Complex[] values, [In, Out] double[] d); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern int c_eigen(bool isSymmetric, int n, [In] Complex32[] a, [In, Out] Complex32[] vectors, [In, Out] Complex[] values, [In, Out] Complex32[] d); + internal static extern int c_eigen([MarshalAs(UnmanagedType.U1)] bool isSymmetric, int n, [In] Complex32[] a, [In, Out] Complex32[] vectors, [In, Out] Complex[] values, [In, Out] Complex32[] d); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern int z_eigen(bool isSymmetric, int n, [In] Complex[] a, [In, Out] Complex[] vectors, [In, Out] Complex[] values, [In, Out] Complex[] d); + internal static extern int z_eigen([MarshalAs(UnmanagedType.U1)] bool isSymmetric, int n, [In] Complex[] a, [In, Out] Complex[] vectors, [In, Out] Complex[] values, [In, Out] Complex[] d); #endregion LAPACK diff --git a/src/Numerics/Random/CryptoRandomSource.cs b/src/Numerics/Random/CryptoRandomSource.cs index 871f672f..50964986 100644 --- a/src/Numerics/Random/CryptoRandomSource.cs +++ b/src/Numerics/Random/CryptoRandomSource.cs @@ -40,7 +40,7 @@ namespace MathNet.Numerics.Random /// /// A random number generator based on the class in the .NET library. /// - public class CryptoRandomSource : RandomSource, IDisposable + public sealed class CryptoRandomSource : RandomSource, IDisposable { const double Reciprocal = 1.0/uint.MaxValue; readonly RandomNumberGenerator _crypto; @@ -112,9 +112,18 @@ namespace MathNet.Numerics.Random /// Supports being called in parallel from multiple threads. public static void Doubles(double[] values) { - var rnd = new RNGCryptoServiceProvider(); var bytes = new byte[values.Length*4]; + +#if !NET35 + using (var rnd = new RNGCryptoServiceProvider()) + { + rnd.GetBytes(bytes); + } +#else + var rnd = new RNGCryptoServiceProvider(); rnd.GetBytes(bytes); +#endif + for (int i = 0; i < values.Length; i++) { values[i] = BitConverter.ToUInt32(bytes, i*4)*Reciprocal; diff --git a/src/Numerics/Random/Palf.cs b/src/Numerics/Random/Palf.cs index 08495bc9..c05d2650 100644 --- a/src/Numerics/Random/Palf.cs +++ b/src/Numerics/Random/Palf.cs @@ -120,7 +120,7 @@ namespace MathNet.Numerics.Random if (longLag <= shortLag) { - throw new ArgumentException("longLag"); + throw new ArgumentException(Resources.ArgumentLowerBoundLargerThanUpperBound, "longLag"); } if (seed == 0) diff --git a/src/Numerics/Statistics/DescriptiveStatistics.cs b/src/Numerics/Statistics/DescriptiveStatistics.cs index e49c8444..5a6c294a 100644 --- a/src/Numerics/Statistics/DescriptiveStatistics.cs +++ b/src/Numerics/Statistics/DescriptiveStatistics.cs @@ -250,15 +250,15 @@ namespace MathNet.Numerics.Statistics decimal xi = (decimal)x; decimal delta = xi - mean; decimal scaleDelta = delta/++n; - decimal scaleDeltaSQR = scaleDelta*scaleDelta; + decimal scaleDelta2 = scaleDelta*scaleDelta; decimal tmpDelta = delta*(n - 1); mean += scaleDelta; - kurtosis += tmpDelta*scaleDelta*scaleDeltaSQR*(n*n - 3*n + 3) - + 6*scaleDeltaSQR*variance - 4*scaleDelta*skewness; + kurtosis += tmpDelta*scaleDelta*scaleDelta2*(n*n - 3*n + 3) + + 6*scaleDelta2*variance - 4*scaleDelta*skewness; - skewness += tmpDelta*scaleDeltaSQR*(n - 2) - 3*scaleDelta*variance; + skewness += tmpDelta*scaleDelta2*(n - 2) - 3*scaleDelta*variance; variance += tmpDelta*scaleDelta; if (minimum > xi) { diff --git a/src/Numerics/Statistics/Histogram.cs b/src/Numerics/Statistics/Histogram.cs index 2bd44058..78dbb130 100644 --- a/src/Numerics/Statistics/Histogram.cs +++ b/src/Numerics/Statistics/Histogram.cs @@ -278,7 +278,7 @@ namespace MathNet.Numerics.Statistics { if (lower > upper) { - throw new ArgumentOutOfRangeException("upper", "The histogram lowerbound must be smaller than the upper bound."); + throw new ArgumentOutOfRangeException("upper", "The histogram lower bound must be smaller than the upper bound."); } if (nbuckets < 1) diff --git a/src/Numerics/Statistics/MCMC/MCMCDiagnostics.cs b/src/Numerics/Statistics/MCMC/MCMCDiagnostics.cs index ae0caf60..6f95b741 100644 --- a/src/Numerics/Statistics/MCMC/MCMCDiagnostics.cs +++ b/src/Numerics/Statistics/MCMC/MCMCDiagnostics.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using System.Linq; +using MathNet.Numerics.Properties; namespace MathNet.Numerics.Statistics.Mcmc { @@ -53,13 +54,13 @@ namespace MathNet.Numerics.Statistics.Mcmc { if (lag < 0) { - throw new ArgumentOutOfRangeException("lag", "Lag must be positive"); + throw new ArgumentOutOfRangeException("lag", Resources.LagMustBePositive); } int length = series.Count(); if (lag >= length) { - throw new ArgumentOutOfRangeException("lag", "Lag must be smaller than the sample size"); + throw new ArgumentOutOfRangeException("lag", Resources.LagMustBeSmallerThanTheSampleSize); } var transformedSeries = series.Select(f); diff --git a/src/Numerics/Statistics/MCMC/MCMCSampler.cs b/src/Numerics/Statistics/MCMC/MCMCSampler.cs index 017a0ac8..fe473022 100644 --- a/src/Numerics/Statistics/MCMC/MCMCSampler.cs +++ b/src/Numerics/Statistics/MCMC/MCMCSampler.cs @@ -121,7 +121,7 @@ namespace MathNet.Numerics.Statistics.Mcmc { if (value == null) { - throw new ArgumentNullException(); + throw new ArgumentNullException("value"); } _randomNumberGenerator = value; } diff --git a/src/UnitTests/DistributionTests/Continuous/BetaTests.cs b/src/UnitTests/DistributionTests/Continuous/BetaTests.cs index e204cfdf..78563865 100644 --- a/src/UnitTests/DistributionTests/Continuous/BetaTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/BetaTests.cs @@ -101,10 +101,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetShapeA(double a) { - new Beta(1.0, 1.0) + GC.KeepAlive(new Beta(1.0, 1.0) { A = a - }; + }); } /// @@ -129,10 +129,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetShapeB(double b) { - new Beta(1.0, 1.0) + GC.KeepAlive(new Beta(1.0, 1.0) { B = b - }; + }); } /// @@ -279,7 +279,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous public void CanSampleSequenceStatic() { var ied = Beta.Samples(new Random(0), 2.0, 3.0); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// @@ -318,7 +318,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { var n = new Beta(2.0, 3.0); var ied = n.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/CauchyTests.cs b/src/UnitTests/DistributionTests/Continuous/CauchyTests.cs index 8f070cc2..8cf44c75 100644 --- a/src/UnitTests/DistributionTests/Continuous/CauchyTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/CauchyTests.cs @@ -105,10 +105,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(1.0)] public void CanSetLocation(double location) { - new Cauchy + GC.KeepAlive(new Cauchy { Location = location - }; + }); } /// @@ -130,10 +130,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(12.0)] public void CanSetScale(double scale) { - new Cauchy + GC.KeepAlive(new Cauchy { Scale = scale - }; + }); } /// @@ -304,7 +304,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { var n = new Cauchy(); var ied = n.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/ChiSquareTests.cs b/src/UnitTests/DistributionTests/Continuous/ChiSquareTests.cs index 7b32c286..f976c538 100644 --- a/src/UnitTests/DistributionTests/Continuous/ChiSquareTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/ChiSquareTests.cs @@ -90,10 +90,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetDoF(double dof) { - new ChiSquared(1.0) + GC.KeepAlive(new ChiSquared(1.0) { DegreesOfFreedom = dof - }; + }); } /// @@ -314,7 +314,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { var n = new ChiSquared(1.0); var ied = n.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/ChiTests.cs b/src/UnitTests/DistributionTests/Continuous/ChiTests.cs index 6324a5f8..99c73f56 100644 --- a/src/UnitTests/DistributionTests/Continuous/ChiTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/ChiTests.cs @@ -88,10 +88,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetDoF(double dof) { - new Chi(1.0) + GC.KeepAlive(new Chi(1.0) { DegreesOfFreedom = dof - }; + }); } /// @@ -292,7 +292,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { var n = new Chi(1.0); var ied = n.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/ContinuousUniformTests.cs b/src/UnitTests/DistributionTests/Continuous/ContinuousUniformTests.cs index 4cfad897..18db10c4 100644 --- a/src/UnitTests/DistributionTests/Continuous/ContinuousUniformTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/ContinuousUniformTests.cs @@ -108,10 +108,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(1.0)] public void CanSetLower(double lower) { - new ContinuousUniform + GC.KeepAlive(new ContinuousUniform { LowerBound = lower - }; + }); } /// @@ -133,10 +133,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(12.0)] public void CanSetUpper(double upper) { - new ContinuousUniform + GC.KeepAlive(new ContinuousUniform { UpperBound = upper - }; + }); } /// @@ -327,7 +327,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous public void CanSampleSequenceStatic() { var ied = ContinuousUniform.Samples(new Random(0), 0.0, 1.0); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// @@ -366,7 +366,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { var n = new ContinuousUniform(); var ied = n.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/ErlangTests.cs b/src/UnitTests/DistributionTests/Continuous/ErlangTests.cs index b0db58ce..47c8e76e 100644 --- a/src/UnitTests/DistributionTests/Continuous/ErlangTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/ErlangTests.cs @@ -130,10 +130,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(10)] public void CanSetShape(int shape) { - new Erlang(1, 1.0) + GC.KeepAlive(new Erlang(1, 1.0) { Shape = shape - }; + }); } /// @@ -158,10 +158,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetScale(double scale) { - new Erlang(1, 1.0) + GC.KeepAlive(new Erlang(1, 1.0) { Scale = scale - }; + }); } /// @@ -186,10 +186,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetInvScale(double invScale) { - new Erlang(1, 1.0) + GC.KeepAlive(new Erlang(1, 1.0) { Rate = invScale - }; + }); } /// @@ -421,7 +421,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { var n = new Erlang(1, 2.0); var ied = n.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/ExponentialTests.cs b/src/UnitTests/DistributionTests/Continuous/ExponentialTests.cs index a2ca8f55..012af382 100644 --- a/src/UnitTests/DistributionTests/Continuous/ExponentialTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/ExponentialTests.cs @@ -90,10 +90,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetLambda(double lambda) { - new Exponential(1.0) + GC.KeepAlive(new Exponential(1.0) { Rate = lambda - }; + }); } /// @@ -321,7 +321,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { var n = new Exponential(1.0); var ied = n.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/FisherSnedecorTests.cs b/src/UnitTests/DistributionTests/Continuous/FisherSnedecorTests.cs index 32444971..82c3fc4e 100644 --- a/src/UnitTests/DistributionTests/Continuous/FisherSnedecorTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/FisherSnedecorTests.cs @@ -111,10 +111,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetDegreesOfFreedom1(double d1) { - new FisherSnedecor(1.0, 2.0) + GC.KeepAlive(new FisherSnedecor(1.0, 2.0) { DegreesOfFreedom1 = d1 - }; + }); } /// @@ -137,10 +137,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetDegreesOfFreedom2(double d2) { - new FisherSnedecor(1.0, 2.0) + GC.KeepAlive(new FisherSnedecor(1.0, 2.0) { DegreesOfFreedom2 = d2 - }; + }); } /// @@ -417,7 +417,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { var n = new FisherSnedecor(1.0, 2.0); var ied = n.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } [TestCase(0.1, 0.1, 1.0)] diff --git a/src/UnitTests/DistributionTests/Continuous/GammaTests.cs b/src/UnitTests/DistributionTests/Continuous/GammaTests.cs index 4565bc17..f93d7b1d 100644 --- a/src/UnitTests/DistributionTests/Continuous/GammaTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/GammaTests.cs @@ -134,10 +134,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetShape(double shape) { - new Gamma(1.0, 1.0) + GC.KeepAlive(new Gamma(1.0, 1.0) { Shape = shape - }; + }); } /// @@ -162,10 +162,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetScale(double scale) { - new Gamma(1.0, 1.0) + GC.KeepAlive(new Gamma(1.0, 1.0) { Scale = scale - }; + }); } /// @@ -190,10 +190,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetInvScale(double invScale) { - new Gamma(1.0, 1.0) + GC.KeepAlive(new Gamma(1.0, 1.0) { Rate = invScale - }; + }); } /// @@ -424,7 +424,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous public void CanSampleSequenceStatic() { var ied = Gamma.Samples(new Random(0), 1.0, 1.0); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// @@ -463,7 +463,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { var n = new Normal(); var ied = n.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/InverseGammaTests.cs b/src/UnitTests/DistributionTests/Continuous/InverseGammaTests.cs index beac231b..ee5be676 100644 --- a/src/UnitTests/DistributionTests/Continuous/InverseGammaTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/InverseGammaTests.cs @@ -96,10 +96,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetA(double a) { - new InverseGamma(1.0, 1.0) + GC.KeepAlive(new InverseGamma(1.0, 1.0) { Shape = a - }; + }); } /// @@ -125,10 +125,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetB(double b) { - new InverseGamma(1.0, 1.0) + GC.KeepAlive(new InverseGamma(1.0, 1.0) { Scale = b - }; + }); } /// @@ -303,7 +303,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { var n = new InverseGamma(1.0, 1.0); var ied = n.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/LaplaceTests.cs b/src/UnitTests/DistributionTests/Continuous/LaplaceTests.cs index 23ffba3b..0a144e68 100644 --- a/src/UnitTests/DistributionTests/Continuous/LaplaceTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/LaplaceTests.cs @@ -92,10 +92,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetLocation(double location) { - new Laplace + GC.KeepAlive(new Laplace { Location = location - }; + }); } /// @@ -118,10 +118,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetScale(double scale) { - new Laplace + GC.KeepAlive(new Laplace { Scale = scale - }; + }); } /// @@ -366,7 +366,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { var n = new Laplace(); var ied = n.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/LogNormalTests.cs b/src/UnitTests/DistributionTests/Continuous/LogNormalTests.cs index 57f5c98d..014058c0 100644 --- a/src/UnitTests/DistributionTests/Continuous/LogNormalTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/LogNormalTests.cs @@ -97,10 +97,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetSigma(double sigma) { - new LogNormal(1.0, 2.0) + GC.KeepAlive(new LogNormal(1.0, 2.0) { Sigma = sigma - }; + }); } /// @@ -127,10 +127,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetMu(double mu) { - new LogNormal(1.0, 2.0) + GC.KeepAlive(new LogNormal(1.0, 2.0) { Mu = mu - }; + }); } /// @@ -434,7 +434,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous public void CanSampleSequenceStatic() { var ied = LogNormal.Samples(new Random(0), 0.0, 1.0); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// @@ -473,7 +473,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { var n = new LogNormal(1.0, 2.0); var ied = n.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/NormalTests.cs b/src/UnitTests/DistributionTests/Continuous/NormalTests.cs index 2b2b4e20..dfa8c0c5 100644 --- a/src/UnitTests/DistributionTests/Continuous/NormalTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/NormalTests.cs @@ -162,10 +162,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetPrecision(double prec) { - new Normal + GC.KeepAlive(new Normal { Precision = prec - }; + }); } /// @@ -251,10 +251,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetMean(double mean) { - new Normal + GC.KeepAlive(new Normal { Mean = mean - }; + }); } /// @@ -407,7 +407,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous public void CanSampleSequenceStatic() { var ied = Normal.Samples(new Random(0), 0.0, 1.0); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// @@ -446,7 +446,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { var n = new Normal(); var ied = n.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/ParetoTests.cs b/src/UnitTests/DistributionTests/Continuous/ParetoTests.cs index b4973bf9..39262537 100644 --- a/src/UnitTests/DistributionTests/Continuous/ParetoTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/ParetoTests.cs @@ -96,10 +96,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetScale(double scale) { - new Pareto(1.0, 1.0) + GC.KeepAlive(new Pareto(1.0, 1.0) { Scale = scale - }; + }); } /// @@ -122,10 +122,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetShape(double shape) { - new Pareto(1.0, 1.0) + GC.KeepAlive(new Pareto(1.0, 1.0) { Shape = shape - }; + }); } /// @@ -344,7 +344,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { var n = new Pareto(1.0, 1.0); var ied = n.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } } } diff --git a/src/UnitTests/DistributionTests/Continuous/RayleighTests.cs b/src/UnitTests/DistributionTests/Continuous/RayleighTests.cs index 24d4c624..ea131915 100644 --- a/src/UnitTests/DistributionTests/Continuous/RayleighTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/RayleighTests.cs @@ -88,10 +88,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetScale(double scale) { - new Rayleigh(1.0) + GC.KeepAlive(new Rayleigh(1.0) { Scale = scale - }; + }); } /// @@ -289,7 +289,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { var n = new Rayleigh(1.0); var ied = n.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } } } diff --git a/src/UnitTests/DistributionTests/Continuous/StableTests.cs b/src/UnitTests/DistributionTests/Continuous/StableTests.cs index d9543db9..9bd9fe6e 100644 --- a/src/UnitTests/DistributionTests/Continuous/StableTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/StableTests.cs @@ -111,10 +111,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(2.0)] public void CanSetAlpha(double alpha) { - new Stable(1.0, 1.0, 1.0, 1.0) + GC.KeepAlive(new Stable(1.0, 1.0, 1.0, 1.0) { Alpha = alpha - }; + }); } /// @@ -145,10 +145,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(1.0)] public void CanSetBeta(double beta) { - new Stable(1.0, 1.0, 1.0, 1.0) + GC.KeepAlive(new Stable(1.0, 1.0, 1.0, 1.0) { Beta = beta - }; + }); } /// @@ -176,10 +176,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetScale(double scale) { - new Stable(1.0, 1.0, 1.0, 1.0) + GC.KeepAlive(new Stable(1.0, 1.0, 1.0, 1.0) { Scale = scale - }; + }); } /// @@ -208,10 +208,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetLocation(double location) { - new Stable(1.0, 1.0, 1.0, 1.0) + GC.KeepAlive(new Stable(1.0, 1.0, 1.0, 1.0) { Location = location - }; + }); } /// @@ -381,7 +381,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { var n = new Stable(1.0, 1.0, 1.0, 1.0); var ied = n.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/StudentTTests.cs b/src/UnitTests/DistributionTests/Continuous/StudentTTests.cs index 7773244e..64a0e933 100644 --- a/src/UnitTests/DistributionTests/Continuous/StudentTTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/StudentTTests.cs @@ -112,10 +112,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetLocation(double loc) { - new StudentT + GC.KeepAlive(new StudentT { Location = loc - }; + }); } /// @@ -128,10 +128,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetScale(double scale) { - new StudentT + GC.KeepAlive(new StudentT { Scale = scale - }; + }); } /// @@ -157,10 +157,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetDoF(double dof) { - new StudentT + GC.KeepAlive(new StudentT { DegreesOfFreedom = dof - }; + }); } /// @@ -382,7 +382,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous public void CanSampleSequenceStatic() { var ied = StudentT.Samples(new Random(0), 0.0, 1.0, 3.0); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// @@ -403,7 +403,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { var n = new StudentT(); var ied = n.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } [TestCase(0.0, 1.0, 1.0, 0.0, 0.5)] diff --git a/src/UnitTests/DistributionTests/Continuous/TriangularTests.cs b/src/UnitTests/DistributionTests/Continuous/TriangularTests.cs index ef51df55..aa3da64f 100644 --- a/src/UnitTests/DistributionTests/Continuous/TriangularTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/TriangularTests.cs @@ -104,10 +104,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(10.0)] public void CanSetLowerBound(double lower) { - new Triangular(0.0, 20.0, 10.0) + GC.KeepAlive(new Triangular(0.0, 20.0, 10.0) { LowerBound = lower - }; + }); } /// @@ -149,9 +149,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous public void CanSampleSequenceStatic() { var ied = Triangular.Samples(new Random(0), 2.0, 3.0, 2.5); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); ied = Triangular.Samples(10.0, 100.0, 30.0); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// @@ -190,7 +190,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { var n = new Triangular(0.1, 0.3, 0.2); var ied = n.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } // Todo: Add tests for: diff --git a/src/UnitTests/DistributionTests/Continuous/WeibullTests.cs b/src/UnitTests/DistributionTests/Continuous/WeibullTests.cs index f7364947..b203e4f3 100644 --- a/src/UnitTests/DistributionTests/Continuous/WeibullTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/WeibullTests.cs @@ -98,10 +98,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetShape(double shape) { - new Weibull(1.0, 1.0) + GC.KeepAlive(new Weibull(1.0, 1.0) { Shape = shape - }; + }); } /// @@ -127,10 +127,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(Double.PositiveInfinity)] public void CanSetScale(double scale) { - new Weibull(1.0, 1.0) + GC.KeepAlive(new Weibull(1.0, 1.0) { Scale = scale - }; + }); } /// @@ -328,7 +328,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous public void CanSampleSequenceStatic() { var ied = Weibull.Samples(new Random(0), 1.0, 1.0); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// @@ -367,7 +367,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { var n = new Normal(); var ied = n.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// diff --git a/src/UnitTests/DistributionTests/Discrete/BernoulliTests.cs b/src/UnitTests/DistributionTests/Discrete/BernoulliTests.cs index 0a0e77cd..9b2c073c 100644 --- a/src/UnitTests/DistributionTests/Discrete/BernoulliTests.cs +++ b/src/UnitTests/DistributionTests/Discrete/BernoulliTests.cs @@ -85,10 +85,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete [TestCase(1.0)] public void CanSetProbabilityOfOne(double p) { - new Bernoulli(0.3) + GC.KeepAlive(new Bernoulli(0.3) { P = p - }; + }); } /// @@ -238,7 +238,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete public void CanSampleSequenceStatic() { var ied = Bernoulli.Samples(new Random(0), 0.3); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// @@ -277,7 +277,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete { var n = new Bernoulli(0.3); var ied = n.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// diff --git a/src/UnitTests/DistributionTests/Discrete/BinomialTests.cs b/src/UnitTests/DistributionTests/Discrete/BinomialTests.cs index 917d164d..d2fb6a4e 100644 --- a/src/UnitTests/DistributionTests/Discrete/BinomialTests.cs +++ b/src/UnitTests/DistributionTests/Discrete/BinomialTests.cs @@ -89,10 +89,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete [TestCase(1.0, 2)] public void CanSetSuccessProbability(double p, int n) { - new Binomial(0.3, n) + GC.KeepAlive(new Binomial(0.3, n) { P = p - }; + }); } /// @@ -262,7 +262,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete public void CanSampleSequenceStatic() { var ied = Binomial.Samples(new Random(0), 0.3, 5); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// @@ -301,7 +301,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete { var n = new Binomial(0.3, 5); var ied = n.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } } } diff --git a/src/UnitTests/DistributionTests/Discrete/CategoricalTests.cs b/src/UnitTests/DistributionTests/Discrete/CategoricalTests.cs index 9b805c24..dea380fa 100644 --- a/src/UnitTests/DistributionTests/Discrete/CategoricalTests.cs +++ b/src/UnitTests/DistributionTests/Discrete/CategoricalTests.cs @@ -80,7 +80,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete [Test] public void CanCreateCategorical() { - new Categorical(_largeP); + GC.KeepAlive(new Categorical(_largeP)); } /// @@ -106,7 +106,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete public void CategoricalCreateFailsWithNullHistogram() { Histogram h = null; +// ReSharper disable ExpressionIsAlwaysNull Assert.That(() => new Categorical(h), Throws.TypeOf()); +// ReSharper restore ExpressionIsAlwaysNull } /// @@ -143,10 +145,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete [Test] public void CanSetProbability() { - new Categorical(_largeP) + GC.KeepAlive(new Categorical(_largeP) { P = _smallP - }; + }); } /// @@ -164,10 +166,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete /// /// An array of nonnegative ratios. /// Expected value. - [TestCase(new double[] { 0, 0.25, 0.5, 0.25 }, 2)] - [TestCase(new double[] { 0, 1, 2, 1 }, 2)] - [TestCase(new double[] { 0, 0.5, 0.5 }, 1.5)] - [TestCase(new double[] { 0.75, 0.25 }, 0.25)] + [TestCase(new[] { 0.0, 0.25, 0.5, 0.25 }, 2)] + [TestCase(new[] { 0.0, 1, 2, 1 }, 2)] + [TestCase(new[] { 0.0, 0.5, 0.5 }, 1.5)] + [TestCase(new[] { 0.75, 0.25 }, 0.25)] [TestCase(new double[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 5)] public void ValidateMean(double[] p, double mean) { @@ -179,10 +181,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete /// /// An array of nonnegative ratios. /// Standard deviation. - [TestCase(new double[] { 0, 0.25, 0.5, 0.25 }, 0.70710678118654752440084436210485)] - [TestCase(new double[] { 0, 1, 2, 1 }, 0.70710678118654752440084436210485)] - [TestCase(new double[] { 0, 0.5, 0.5 }, 0.5)] - [TestCase(new double[] { 0.75, 0.25 }, 0.43301270189221932338186158537647)] //Sqrt((0.25*0.25)*.75+(.75*.75)*.25) + [TestCase(new[] { 0.0, 0.25, 0.5, 0.25 }, 0.70710678118654752440084436210485)] + [TestCase(new[] { 0.0, 1, 2, 1 }, 0.70710678118654752440084436210485)] + [TestCase(new[] { 0.0, 0.5, 0.5 }, 0.5)] + [TestCase(new[] { 0.75, 0.25 }, 0.43301270189221932338186158537647)] //Sqrt((0.25*0.25)*.75+(.75*.75)*.25) [TestCase(new double[] { 1, 0, 1 }, 1)] public void ValidateStdDev(double[] p, double stdDev) { @@ -194,11 +196,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete /// /// An array of nonnegative ratios. /// Variance. - [TestCase(new double[] { 0, 0.25, 0.5, 0.25 }, 0.5)] - [TestCase(new double[] { 0, 1, 2, 1 }, 0.5)] - [TestCase(new double[] { 0, 0.5, 0.5 }, 0.25)] - [TestCase(new double[] { 0.75, 0.25 }, 0.1875)] //(0.25*0.25)*.75+(.75*.75)*.25) - [TestCase(new double[] { 1, 0, 1 }, 1)] + [TestCase(new[] { 0.0, 0.25, 0.5, 0.25 }, 0.5)] + [TestCase(new[] { 0.0, 1, 2, 1 }, 0.5)] + [TestCase(new[] { 0.0, 0.5, 0.5 }, 0.25)] + [TestCase(new[] { 0.75, 0.25 }, 0.1875)] //(0.25*0.25)*.75+(.75*.75)*.25) + [TestCase(new[] { 1.0, 0, 1 }, 1)] public void ValidateVariance(double[] p, double variance) { Assert.That(new Categorical(p).Variance, Is.EqualTo(variance).Within(1e-14)); @@ -209,13 +211,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete /// /// An array of nonnegative ratios. /// Median. - [TestCase(new double[] { 0, 0.25, 0.5, 0.25 }, 2)] - [TestCase(new double[] { 0, 1, 2, 1 }, 2)] - [TestCase(new double[] { 0.75, 0.25 }, 0)] + [TestCase(new[] { 0.0, 0.25, 0.5, 0.25 }, 2)] + [TestCase(new[] { 0.0, 1, 2, 1 }, 2)] + [TestCase(new[] { 0.75, 0.25 }, 0)] // The following test case has median of 5, because: // P(X < 5) = (1+2+6+3+2)/29 = 14/29 < 0.5. // P(X <= 5) = 19/29 > 0.5. - [TestCase(new double[] { 1, 2, 6, 3, 2, 5, 1, 1, 0, 1, 7 }, 5)] + [TestCase(new[] { 1.0, 2, 6, 3, 2, 5, 1, 1, 0, 1, 7 }, 5)] // TODO: Find out the expected behavior of Median in ambiguous cases like the following: //[TestCase(new double[] { 0, 0.5, 0.5 }, ???)] //[TestCase(new double[] { 1, 0, 1 }, ???)] diff --git a/src/UnitTests/DistributionTests/Discrete/ConwayMaxwellPoissonTests.cs b/src/UnitTests/DistributionTests/Discrete/ConwayMaxwellPoissonTests.cs index 99742db3..1aebd006 100644 --- a/src/UnitTests/DistributionTests/Discrete/ConwayMaxwellPoissonTests.cs +++ b/src/UnitTests/DistributionTests/Discrete/ConwayMaxwellPoissonTests.cs @@ -87,10 +87,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete [TestCase(Double.PositiveInfinity)] public void CanSetLambda(double lambda) { - new ConwayMaxwellPoisson(1.0, 2.0) + GC.KeepAlive(new ConwayMaxwellPoisson(1.0, 2.0) { Lambda = lambda - }; + }); } /// @@ -103,10 +103,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete [TestCase(Double.PositiveInfinity)] public void CanSetNu(double nu) { - new ConwayMaxwellPoisson(1.0, 2.0) + GC.KeepAlive(new ConwayMaxwellPoisson(1.0, 2.0) { Nu = nu - }; + }); } /// @@ -271,7 +271,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete { var d = new ConwayMaxwellPoisson(1.0, 2.0); var ied = d.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// diff --git a/src/UnitTests/DistributionTests/Discrete/DiscreteUniformTests.cs b/src/UnitTests/DistributionTests/Discrete/DiscreteUniformTests.cs index 0a5852da..313bf0b5 100644 --- a/src/UnitTests/DistributionTests/Discrete/DiscreteUniformTests.cs +++ b/src/UnitTests/DistributionTests/Discrete/DiscreteUniformTests.cs @@ -88,10 +88,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete [TestCase(10)] public void CanSetLowerBound(int p) { - new DiscreteUniform(0, 10) + GC.KeepAlive(new DiscreteUniform(0, 10) { LowerBound = p - }; + }); } /// @@ -103,10 +103,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete [TestCase(10)] public void CanSetUpperBound(int p) { - new DiscreteUniform(0, 10) + GC.KeepAlive(new DiscreteUniform(0, 10) { UpperBound = p - }; + }); } /// @@ -284,7 +284,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete public void CanSampleSequenceStatic() { var ied = DiscreteUniform.Samples(new Random(0), 0, 10); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// @@ -323,7 +323,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete { var n = new DiscreteUniform(0, 10); var ied = n.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// diff --git a/src/UnitTests/DistributionTests/Discrete/GeometricTests.cs b/src/UnitTests/DistributionTests/Discrete/GeometricTests.cs index 9b62a4d2..d2e8a4ce 100644 --- a/src/UnitTests/DistributionTests/Discrete/GeometricTests.cs +++ b/src/UnitTests/DistributionTests/Discrete/GeometricTests.cs @@ -85,10 +85,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete [TestCase(1.0)] public void CanSetProbabilityOfOne(double p) { - new Geometric(0.3) + GC.KeepAlive(new Geometric(0.3) { P = p - }; + }); } /// @@ -245,7 +245,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete { var d = new Geometric(0.3); var ied = d.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// diff --git a/src/UnitTests/DistributionTests/Discrete/HypergeometricTests.cs b/src/UnitTests/DistributionTests/Discrete/HypergeometricTests.cs index f7bda643..eda4e36f 100644 --- a/src/UnitTests/DistributionTests/Discrete/HypergeometricTests.cs +++ b/src/UnitTests/DistributionTests/Discrete/HypergeometricTests.cs @@ -95,10 +95,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete [TestCase(20)] public void CanSetPopulation(int population) { - new Hypergeometric(10, 1, 1) - { - Population = population - }; + GC.KeepAlive(new Hypergeometric(10, 1, 1) + { + Population = population + }); } /// @@ -123,10 +123,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete [TestCase(5)] public void CanSetSuccess(int success) { - new Hypergeometric(10, 1, 1) - { - Success = success - }; + GC.KeepAlive(new Hypergeometric(10, 1, 1) + { + Success = success + }); } /// @@ -151,10 +151,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete [TestCase(5)] public void CanSetDraws(int draws) { - new Hypergeometric(10, 1, 1) - { - Draws = draws - }; + GC.KeepAlive(new Hypergeometric(10, 1, 1) + { + Draws = draws + }); } /// @@ -323,7 +323,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete { var d = new Hypergeometric(10, 1, 1); var ied = d.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// diff --git a/src/UnitTests/DistributionTests/Discrete/NegativeBinomialTests.cs b/src/UnitTests/DistributionTests/Discrete/NegativeBinomialTests.cs index 3490c4da..9e0172df 100644 --- a/src/UnitTests/DistributionTests/Discrete/NegativeBinomialTests.cs +++ b/src/UnitTests/DistributionTests/Discrete/NegativeBinomialTests.cs @@ -93,10 +93,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete [TestCase(1.0)] public void CanSetR(double r) { - new NegativeBinomial(1.0, 0.5) + GC.KeepAlive(new NegativeBinomial(1.0, 0.5) { R = r - }; + }); } /// @@ -121,10 +121,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete [TestCase(1.0)] public void CanSetProbabilityOfOne(double p) { - new NegativeBinomial(1.0, 0.5) + GC.KeepAlive(new NegativeBinomial(1.0, 0.5) { P = p - }; + }); } /// @@ -284,7 +284,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete { var d = new NegativeBinomial(1.0, 0.5); var ied = d.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } } } diff --git a/src/UnitTests/DistributionTests/Discrete/PoissonTests.cs b/src/UnitTests/DistributionTests/Discrete/PoissonTests.cs index 86e64332..959aa604 100644 --- a/src/UnitTests/DistributionTests/Discrete/PoissonTests.cs +++ b/src/UnitTests/DistributionTests/Discrete/PoissonTests.cs @@ -85,10 +85,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete [TestCase(10.8)] public void CanSetProbabilityOfOne(double lambda) { - new Poisson(0.3) + GC.KeepAlive(new Poisson(0.3) { Lambda = lambda - }; + }); } /// @@ -236,7 +236,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete { var d = new Poisson(0.3); var ied = d.Samples(); - ied.Take(5).ToArray(); + GC.KeepAlive(ied.Take(5).ToArray()); } /// diff --git a/src/UnitTests/DistributionTests/Discrete/ZipfTests.cs b/src/UnitTests/DistributionTests/Discrete/ZipfTests.cs index 0e28eeaf..fff416d8 100644 --- a/src/UnitTests/DistributionTests/Discrete/ZipfTests.cs +++ b/src/UnitTests/DistributionTests/Discrete/ZipfTests.cs @@ -87,10 +87,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete [TestCase(5.0)] public void CanSetS(double s) { - new Zipf(1.0, 5) + GC.KeepAlive(new Zipf(1.0, 5) { S = s - }; + }); } /// @@ -115,10 +115,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete [TestCase(50)] public void CanSetN(int n) { - new Zipf(1.0, 5) + GC.KeepAlive(new Zipf(1.0, 5) { N = n - }; + }); } /// diff --git a/src/UnitTests/DistributionTests/Multivariate/DirichletTests.cs b/src/UnitTests/DistributionTests/Multivariate/DirichletTests.cs index 98ba5196..f180040d 100644 --- a/src/UnitTests/DistributionTests/Multivariate/DirichletTests.cs +++ b/src/UnitTests/DistributionTests/Multivariate/DirichletTests.cs @@ -108,10 +108,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate [Test] public void CanSetRandomSource() { - new Dirichlet(0.3, 5) + GC.KeepAlive(new Dirichlet(0.3, 5) { RandomSource = new Random(0) - }; + }); } [Test] diff --git a/src/UnitTests/DistributionTests/Multivariate/InverseWishartTests.cs b/src/UnitTests/DistributionTests/Multivariate/InverseWishartTests.cs index b728c74a..a4da69fd 100644 --- a/src/UnitTests/DistributionTests/Multivariate/InverseWishartTests.cs +++ b/src/UnitTests/DistributionTests/Multivariate/InverseWishartTests.cs @@ -115,10 +115,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate [Test] public void CanSetRandomSource() { - new InverseWishart(1.0, Matrix.Build.RandomPositiveDefinite(2, 1)) + GC.KeepAlive(new InverseWishart(1.0, Matrix.Build.RandomPositiveDefinite(2, 1)) { RandomSource = new System.Random(0) - }; + }); } [Test] @@ -161,10 +161,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate [TestCase(5.0)] public void CanSetNu(double nu) { - new InverseWishart(1.0, Matrix.Build.RandomPositiveDefinite(2, 1)) + GC.KeepAlive(new InverseWishart(1.0, Matrix.Build.RandomPositiveDefinite(2, 1)) { DegreesOfFreedom = nu - }; + }); } /// @@ -192,10 +192,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate [Test] public void CanSetS() { - new InverseWishart(1.0, Matrix.Build.RandomPositiveDefinite(2, 1)) + GC.KeepAlive(new InverseWishart(1.0, Matrix.Build.RandomPositiveDefinite(2, 1)) { Scale = Matrix.Build.RandomPositiveDefinite(2, 1) - }; + }); } /// diff --git a/src/UnitTests/DistributionTests/Multivariate/MatrixNormalTests.cs b/src/UnitTests/DistributionTests/Multivariate/MatrixNormalTests.cs index 57802d8d..0fc4d340 100644 --- a/src/UnitTests/DistributionTests/Multivariate/MatrixNormalTests.cs +++ b/src/UnitTests/DistributionTests/Multivariate/MatrixNormalTests.cs @@ -124,10 +124,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate { const int N = 2; const int P = 3; - new MatrixNormal(Matrix.Build.Random(N, P, 1), Matrix.Build.RandomPositiveDefinite(N, 1), Matrix.Build.RandomPositiveDefinite(P, 1)) + GC.KeepAlive(new MatrixNormal(Matrix.Build.Random(N, P, 1), Matrix.Build.RandomPositiveDefinite(N, 1), Matrix.Build.RandomPositiveDefinite(P, 1)) { RandomSource = new System.Random(0) - }; + }); } [Test] @@ -183,10 +183,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate [TestCase(10, 10)] public void CanSetM(int n, int p) { - new MatrixNormal(Matrix.Build.Random(n, p, 1), Matrix.Build.RandomPositiveDefinite(n, 1), Matrix.Build.RandomPositiveDefinite(p, 1)) + GC.KeepAlive(new MatrixNormal(Matrix.Build.Random(n, p, 1), Matrix.Build.RandomPositiveDefinite(n, 1), Matrix.Build.RandomPositiveDefinite(p, 1)) { Mean = Matrix.Build.Random(n, p, 1) - }; + }); } /// @@ -220,10 +220,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate [TestCase(10, 10)] public void CanSetV(int n, int p) { - new MatrixNormal(Matrix.Build.Random(n, p, 1), Matrix.Build.RandomPositiveDefinite(n, 1), Matrix.Build.RandomPositiveDefinite(p, 1)) + GC.KeepAlive(new MatrixNormal(Matrix.Build.Random(n, p, 1), Matrix.Build.RandomPositiveDefinite(n, 1), Matrix.Build.RandomPositiveDefinite(p, 1)) { RowCovariance = Matrix.Build.RandomPositiveDefinite(n, 1) - }; + }); } /// @@ -257,10 +257,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate [TestCase(10, 10)] public void CanSetK(int n, int p) { - new MatrixNormal(Matrix.Build.Random(n, p, 1), Matrix.Build.RandomPositiveDefinite(n, 1), Matrix.Build.RandomPositiveDefinite(p, 1)) + GC.KeepAlive(new MatrixNormal(Matrix.Build.Random(n, p, 1), Matrix.Build.RandomPositiveDefinite(n, 1), Matrix.Build.RandomPositiveDefinite(p, 1)) { ColumnCovariance = Matrix.Build.RandomPositiveDefinite(p, 1) - }; + }); } /// diff --git a/src/UnitTests/DistributionTests/Multivariate/MultinomialTests.cs b/src/UnitTests/DistributionTests/Multivariate/MultinomialTests.cs index 6faa2645..36c50040 100644 --- a/src/UnitTests/DistributionTests/Multivariate/MultinomialTests.cs +++ b/src/UnitTests/DistributionTests/Multivariate/MultinomialTests.cs @@ -104,7 +104,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate public void MultinomialCreateFailsWithNullHistogram() { Histogram h = null; +// ReSharper disable ExpressionIsAlwaysNull Assert.That(() => new Categorical(h), Throws.TypeOf()); +// ReSharper restore ExpressionIsAlwaysNull } /// @@ -223,10 +225,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate [Test] public void CanSetProbability() { - new Multinomial(_largeP, 4) + GC.KeepAlive(new Multinomial(_largeP, 4) { P = _smallP - }; + }); } /// diff --git a/src/UnitTests/DistributionTests/Multivariate/NormalGammaTests.cs b/src/UnitTests/DistributionTests/Multivariate/NormalGammaTests.cs index 7bf821d7..cf64ac27 100644 --- a/src/UnitTests/DistributionTests/Multivariate/NormalGammaTests.cs +++ b/src/UnitTests/DistributionTests/Multivariate/NormalGammaTests.cs @@ -302,10 +302,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate [Test] public void CanSetRandomSource() { - new NormalGamma(0.0, 1.0, 1.0, 1.0) + GC.KeepAlive(new NormalGamma(0.0, 1.0, 1.0, 1.0) { RandomSource = new Random(0) - }; + }); } /// diff --git a/src/UnitTests/DistributionTests/Multivariate/WishartTests.cs b/src/UnitTests/DistributionTests/Multivariate/WishartTests.cs index 45c36262..83305e9d 100644 --- a/src/UnitTests/DistributionTests/Multivariate/WishartTests.cs +++ b/src/UnitTests/DistributionTests/Multivariate/WishartTests.cs @@ -117,10 +117,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate [Test] public void CanSetRandomSource() { - new Wishart(1.0, Matrix.Build.RandomPositiveDefinite(2, 1)) + GC.KeepAlive(new Wishart(1.0, Matrix.Build.RandomPositiveDefinite(2, 1)) { RandomSource = new System.Random(0) - }; + }); } /// @@ -155,10 +155,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate [TestCase(5.0)] public void CanSetNu(double nu) { - new Wishart(1.0, Matrix.Build.RandomPositiveDefinite(2, 1)) + GC.KeepAlive(new Wishart(1.0, Matrix.Build.RandomPositiveDefinite(2, 1)) { DegreesOfFreedom = nu - }; + }); } /// @@ -186,10 +186,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate [Test] public void CanSetS() { - new Wishart(1.0, Matrix.Build.RandomPositiveDefinite(2, 1)) + GC.KeepAlive(new Wishart(1.0, Matrix.Build.RandomPositiveDefinite(2, 1)) { Scale = Matrix.Build.RandomPositiveDefinite(2, 1) - }; + }); } /// diff --git a/src/UnitTests/FinancialTests/CompoundMonthlyReturnTests.cs b/src/UnitTests/FinancialTests/CompoundMonthlyReturnTests.cs index fb000220..8b7fc7ca 100644 --- a/src/UnitTests/FinancialTests/CompoundMonthlyReturnTests.cs +++ b/src/UnitTests/FinancialTests/CompoundMonthlyReturnTests.cs @@ -45,14 +45,16 @@ namespace MathNet.Numerics.UnitTests.FinancialTests //arrange List inputData = null; //act +// ReSharper disable ExpressionIsAlwaysNull inputData.CompoundMonthlyReturn(); +// ReSharper restore ExpressionIsAlwaysNull } [Test] public void returns_undefined_with_empty_input_data() { //arrange - List inputData = new List(); + var inputData = new List(); //act var cmpdReturn = inputData.CompoundMonthlyReturn(); //assert @@ -70,7 +72,7 @@ namespace MathNet.Numerics.UnitTests.FinancialTests AssertHelpers.AlmostEqualRelative(0.0870999982199265, cmpdReturn, 14); } - //Definitly need more tests here. Would love to find test data for these stats similar to the .dat files used for other tests. + //Definitely need more tests here. Would love to find test data for these stats similar to the .dat files used for other tests. } } \ No newline at end of file diff --git a/src/UnitTests/FinancialTests/DownsideDeviationTests.cs b/src/UnitTests/FinancialTests/DownsideDeviationTests.cs index 8b7258ea..88758bf1 100644 --- a/src/UnitTests/FinancialTests/DownsideDeviationTests.cs +++ b/src/UnitTests/FinancialTests/DownsideDeviationTests.cs @@ -110,7 +110,9 @@ namespace MathNet.Numerics.UnitTests.FinancialTests const double minimumAcceptableReturn = 0.05; List inputData = null; //act +// ReSharper disable ExpressionIsAlwaysNull inputData.DownsideDeviation(minimumAcceptableReturn); +// ReSharper restore ExpressionIsAlwaysNull } } diff --git a/src/UnitTests/FinancialTests/GainLossRatioTests.cs b/src/UnitTests/FinancialTests/GainLossRatioTests.cs index 09c1f893..09b60edb 100644 --- a/src/UnitTests/FinancialTests/GainLossRatioTests.cs +++ b/src/UnitTests/FinancialTests/GainLossRatioTests.cs @@ -47,7 +47,9 @@ namespace MathNet.Numerics.UnitTests.FinancialTests //arrange List inputData = null; //act +// ReSharper disable ExpressionIsAlwaysNull inputData.GainLossRatio(); +// ReSharper restore ExpressionIsAlwaysNull } [Test] diff --git a/src/UnitTests/FinancialTests/GainMeanTests.cs b/src/UnitTests/FinancialTests/GainMeanTests.cs index d5667799..af9840eb 100644 --- a/src/UnitTests/FinancialTests/GainMeanTests.cs +++ b/src/UnitTests/FinancialTests/GainMeanTests.cs @@ -88,10 +88,11 @@ namespace MathNet.Numerics.UnitTests.FinancialTests public void throws_when_input_data_is_null() //assert { //arrange - var inputData = new[] { 1.0 }; - inputData = null; + double[] inputData = null; //act +// ReSharper disable ExpressionIsAlwaysNull inputData.GainMean(); +// ReSharper restore ExpressionIsAlwaysNull } [Test] diff --git a/src/UnitTests/FinancialTests/GainStandardDeviationTests.cs b/src/UnitTests/FinancialTests/GainStandardDeviationTests.cs index 73a55d94..853130fb 100644 --- a/src/UnitTests/FinancialTests/GainStandardDeviationTests.cs +++ b/src/UnitTests/FinancialTests/GainStandardDeviationTests.cs @@ -115,9 +115,9 @@ namespace MathNet.Numerics.UnitTests.FinancialTests //arrange List inputData = null; //act +// ReSharper disable ExpressionIsAlwaysNull inputData.GainStandardDeviation(); +// ReSharper restore ExpressionIsAlwaysNull } - - public double gainStdDev { get; set; } } } diff --git a/src/UnitTests/FinancialTests/LossMeanTests.cs b/src/UnitTests/FinancialTests/LossMeanTests.cs index 01340cbe..1b8886e2 100644 --- a/src/UnitTests/FinancialTests/LossMeanTests.cs +++ b/src/UnitTests/FinancialTests/LossMeanTests.cs @@ -92,7 +92,9 @@ namespace MathNet.Numerics.UnitTests.FinancialTests //arrange List inputData = null; //act +// ReSharper disable ExpressionIsAlwaysNull inputData.LossMean(); +// ReSharper restore ExpressionIsAlwaysNull } [Test] diff --git a/src/UnitTests/FinancialTests/LossStandardDeviationTests.cs b/src/UnitTests/FinancialTests/LossStandardDeviationTests.cs index 023199ed..413d4b7d 100644 --- a/src/UnitTests/FinancialTests/LossStandardDeviationTests.cs +++ b/src/UnitTests/FinancialTests/LossStandardDeviationTests.cs @@ -115,7 +115,9 @@ namespace MathNet.Numerics.UnitTests.FinancialTests //arrange List inputData = null; //act +// ReSharper disable ExpressionIsAlwaysNull inputData.LossStandardDeviation(); +// ReSharper restore ExpressionIsAlwaysNull } } } diff --git a/src/UnitTests/FinancialTests/SemiDeviationTests.cs b/src/UnitTests/FinancialTests/SemiDeviationTests.cs index 6f4a5cd9..693de3b2 100644 --- a/src/UnitTests/FinancialTests/SemiDeviationTests.cs +++ b/src/UnitTests/FinancialTests/SemiDeviationTests.cs @@ -106,7 +106,9 @@ namespace MathNet.Numerics.UnitTests.FinancialTests //arrange List inputData = null; //act +// ReSharper disable ExpressionIsAlwaysNull inputData.SemiDeviation(); +// ReSharper restore ExpressionIsAlwaysNull } } } diff --git a/src/UnitTests/GenericMath.cs b/src/UnitTests/GenericMath.cs index 746e2302..757a6ba9 100644 --- a/src/UnitTests/GenericMath.cs +++ b/src/UnitTests/GenericMath.cs @@ -678,17 +678,14 @@ namespace MathNet.Numerics.UnitTests { // already "TValue, TValue, TValue"... // convert both lhs and rhs to TResult (as appropriate) - Expression castLhs = typeof (TArg1) == typeof (TResult) ? - (Expression)lhs : - (Expression)Expression.Convert(lhs, typeof (TResult)); - Expression castRhs = typeof (TArg2) == typeof (TResult) ? - (Expression)rhs : - (Expression)Expression.Convert(rhs, typeof (TResult)); + Expression castLhs = typeof (TArg1) == typeof (TResult) ? (Expression)lhs : Expression.Convert(lhs, typeof (TResult)); + Expression castRhs = typeof (TArg2) == typeof (TResult) ? (Expression)rhs : Expression.Convert(rhs, typeof (TResult)); return Expression.Lambda>( body(castLhs, castRhs), lhs, rhs).Compile(); } - else throw; + + throw; } } catch (Exception ex) diff --git a/src/UnitTests/GoodnessOfFit/RSquaredTest.cs b/src/UnitTests/GoodnessOfFit/RSquaredTest.cs index a861e8fb..20fa378f 100644 --- a/src/UnitTests/GoodnessOfFit/RSquaredTest.cs +++ b/src/UnitTests/GoodnessOfFit/RSquaredTest.cs @@ -15,35 +15,19 @@ namespace MathNet.Numerics.UnitTests.GoodnessOfFit { var data = new List(); for (int i = 1; i <= 10; i++) + { data.Add(i); + } Assert.That(Numerics.GoodnessOfFit.RSquared(data, data), Is.EqualTo(1)); } [Test] - [ExpectedException(typeof(ArgumentOutOfRangeException))] + [ExpectedException(typeof (ArgumentOutOfRangeException))] public void WhenGivenTwoDatasetsOfDifferentSizeThenThrowsArgumentException() { - var observedData = new List() - { - 23 - ,9 - ,5 - ,7 - ,10 - ,5 - ,4 - ,1 - ,2 - ,1 - }; - - var modelledData = new List() - { - 8 - ,9 - ,10 - }; + var observedData = new List { 23, 9, 5, 7, 10, 5, 4, 1, 2, 1 }; + var modelledData = new List { 8, 9, 10 }; Numerics.GoodnessOfFit.RSquared(modelledData, observedData); @@ -53,15 +37,8 @@ namespace MathNet.Numerics.UnitTests.GoodnessOfFit [Test] public void WhenCalculatingRSquaredOfUnevenDistributionWithLInearDistributionThenRSquaredIsCalculated() { - var observedData = new List() - { - 1, 2.3, 3.1, 4.8, 5.6, 6.3 - }; - - var modelledData = new List() - { - 2.6, 2.8, 3.1, 4.7, 5.1, 5.3 - }; + var observedData = new List { 1, 2.3, 3.1, 4.8, 5.6, 6.3 }; + var modelledData = new List { 2.6, 2.8, 3.1, 4.7, 5.1, 5.3 }; Assert.That(Math.Round(Numerics.GoodnessOfFit.RSquared(modelledData, observedData), 11), Is.EqualTo(Math.Round(0.94878520708673d, 11))); } diff --git a/src/UnitTests/LinearAlgebraProviderTests/Single/LinearAlgebraProviderTests.cs b/src/UnitTests/LinearAlgebraProviderTests/Single/LinearAlgebraProviderTests.cs index 3a52ff78..1ed7b3f0 100644 --- a/src/UnitTests/LinearAlgebraProviderTests/Single/LinearAlgebraProviderTests.cs +++ b/src/UnitTests/LinearAlgebraProviderTests/Single/LinearAlgebraProviderTests.cs @@ -48,12 +48,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Single /// /// The Y float test vector. /// - readonly float[] _y = new[] {1.1f, 2.2f, 3.3f, 4.4f, 5.5f}; + readonly float[] _y = {1.1f, 2.2f, 3.3f, 4.4f, 5.5f}; /// /// The X float test vector. /// - readonly float[] _x = new[] {6.6f, 7.7f, 8.8f, 9.9f, 10.1f}; + readonly float[] _x = {6.6f, 7.7f, 8.8f, 9.9f, 10.1f}; static readonly IContinuousDistribution Dist = new Normal(); diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Factorization/CholeskyTests.cs b/src/UnitTests/LinearAlgebraTests/Complex/Factorization/CholeskyTests.cs index 53445c49..0d3144b0 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Factorization/CholeskyTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Factorization/CholeskyTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Complex; using NUnit.Framework; diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Factorization/GramSchmidtTests.cs b/src/UnitTests/LinearAlgebraTests/Complex/Factorization/GramSchmidtTests.cs index ad30ef73..21339bb0 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Factorization/GramSchmidtTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Factorization/GramSchmidtTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Complex; using MathNet.Numerics.LinearAlgebra.Complex.Factorization; @@ -74,14 +73,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization { for (var j = 0; j < r.ColumnCount; j++) { - if (i == j) - { - Assert.AreEqual(Complex.One, r[i, j]); - } - else - { - Assert.AreEqual(Complex.Zero, r[i, j]); - } + Assert.AreEqual(i == j ? Complex.One : Complex.Zero, r[i, j]); } } @@ -89,14 +81,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization { for (var j = 0; j < q.ColumnCount; j++) { - if (i == j) - { - Assert.AreEqual(Complex.One, q[i, j]); - } - else - { - Assert.AreEqual(Complex.Zero, q[i, j]); - } + Assert.AreEqual(i == j ? Complex.One : Complex.Zero, q[i, j]); } } } @@ -169,14 +154,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization { for (var j = 0; j < matrixQсtQ.ColumnCount; j++) { - if (i == j) - { - AssertHelpers.AlmostEqualRelative(matrixQсtQ[i, j], Complex.One, 9); - } - else - { - AssertHelpers.AlmostEqualRelative(matrixQсtQ[i, j], Complex.Zero, 9); - } + AssertHelpers.AlmostEqualRelative(matrixQсtQ[i, j], i == j ? Complex.One : Complex.Zero, 9); } } } diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Factorization/LUTests.cs b/src/UnitTests/LinearAlgebraTests/Complex/Factorization/LUTests.cs index 2862eabd..84a2adcf 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Factorization/LUTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Factorization/LUTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Complex; using NUnit.Framework; diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Factorization/QRTests.cs b/src/UnitTests/LinearAlgebraTests/Complex/Factorization/QRTests.cs index 5b428254..693a69cd 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Factorization/QRTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Factorization/QRTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Complex; using MathNet.Numerics.LinearAlgebra.Complex.Factorization; diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserCholeskyTests.cs b/src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserCholeskyTests.cs index 5192b7ef..6583f870 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserCholeskyTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserCholeskyTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using NUnit.Framework; diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserGramSchmidtTests.cs b/src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserGramSchmidtTests.cs index 6b3918e7..e560d234 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserGramSchmidtTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserGramSchmidtTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Complex.Factorization; using NUnit.Framework; @@ -73,14 +72,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization { for (var j = 0; j < r.ColumnCount; j++) { - if (i == j) - { - Assert.AreEqual(Complex.One, r[i, j]); - } - else - { - Assert.AreEqual(Complex.Zero, r[i, j]); - } + Assert.AreEqual(i == j ? Complex.One : Complex.Zero, r[i, j]); } } @@ -88,14 +80,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization { for (var j = 0; j < q.ColumnCount; j++) { - if (i == j) - { - Assert.AreEqual(Complex.One, q[i, j]); - } - else - { - Assert.AreEqual(Complex.Zero, q[i, j]); - } + Assert.AreEqual(i == j ? Complex.One : Complex.Zero, q[i, j]); } } } @@ -168,14 +153,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization { for (var j = 0; j < matrixQсtQ.ColumnCount; j++) { - if (i == j) - { - AssertHelpers.AlmostEqualRelative(matrixQсtQ[i, j], Complex.One, 9); - } - else - { - AssertHelpers.AlmostEqualRelative(matrixQсtQ[i, j], Complex.Zero, 9); - } + AssertHelpers.AlmostEqualRelative(matrixQсtQ[i, j], i == j ? Complex.One : Complex.Zero, 9); } } } diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserLUTests.cs b/src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserLUTests.cs index 9161138c..f95f23fc 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserLUTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserLUTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using NUnit.Framework; diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserQRTests.cs b/src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserQRTests.cs index 78b36daf..9fa929c8 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserQRTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserQRTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Complex.Factorization; using MathNet.Numerics.LinearAlgebra.Factorization; diff --git a/src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs index 7c7efe20..6bb899e0 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs @@ -43,7 +43,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex public class MatrixStructureTheory : MatrixStructureTheory { [Datapoints] - Matrix[] _matrices = new Matrix[] + Matrix[] _matrices = { Matrix.Build.DenseOfArray(new[,] { { 1d, new Complex(1.1d, -4d), 2d }, { 1d, 1d, 2d }, { 1d, new Complex(1d, 2d), 2d } }), Matrix.Build.DenseOfArray(new[,] { { -1.1d, -2.2d, -3.3d }, { 0d, 1.1d, new Complex(2.2d, -1.2d) }, { -4.4d, 5.5d, 6.6d } }), @@ -64,6 +64,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex }; [Datapoints] - Complex[] _scalars = new[] { new Complex(2d, 0d), new Complex(-1.5d, 3.5d), Complex.Zero }; + Complex[] _scalars = { new Complex(2d, 0d), new Complex(-1.5d, 3.5d), Complex.Zero }; } } diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/PreConditionerTest.cs b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/PreConditionerTest.cs index d0047712..5e49e811 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/PreConditionerTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/PreConditionerTest.cs @@ -28,7 +28,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Complex; using MathNet.Numerics.LinearAlgebra.Solvers; diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/CholeskyTests.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/CholeskyTests.cs index 0ff118b2..d080e0b8 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/CholeskyTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/CholeskyTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Complex32; using NUnit.Framework; diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/GramSchmidtTests.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/GramSchmidtTests.cs index a7fdf554..dd972972 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/GramSchmidtTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/GramSchmidtTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Complex32; using MathNet.Numerics.LinearAlgebra.Complex32.Factorization; @@ -70,14 +69,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Factorization { for (var j = 0; j < r.ColumnCount; j++) { - if (i == j) - { - Assert.AreEqual(Complex32.One, r[i, j]); - } - else - { - Assert.AreEqual(Complex32.Zero, r[i, j]); - } + Assert.AreEqual(i == j ? Complex32.One : Complex32.Zero, r[i, j]); } } @@ -85,14 +77,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Factorization { for (var j = 0; j < q.ColumnCount; j++) { - if (i == j) - { - Assert.AreEqual(Complex32.One, q[i, j]); - } - else - { - Assert.AreEqual(Complex32.Zero, q[i, j]); - } + Assert.AreEqual(i == j ? Complex32.One : Complex32.Zero, q[i, j]); } } } diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/LUTests.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/LUTests.cs index e6a22b1a..33ac9202 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/LUTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/LUTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Complex32; using NUnit.Framework; diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/QRTests.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/QRTests.cs index 0b3b9470..bf8eb979 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/QRTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/QRTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Complex32; using MathNet.Numerics.LinearAlgebra.Complex32.Factorization; diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/UserCholeskyTests.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/UserCholeskyTests.cs index 4827ef9e..d63a124a 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/UserCholeskyTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/UserCholeskyTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using NUnit.Framework; diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/UserGramSchmidtTests.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/UserGramSchmidtTests.cs index 0f814d5f..7a21022d 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/UserGramSchmidtTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/UserGramSchmidtTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Complex32.Factorization; using NUnit.Framework; @@ -69,14 +68,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Factorization { for (var j = 0; j < r.ColumnCount; j++) { - if (i == j) - { - Assert.AreEqual(Complex32.One, r[i, j]); - } - else - { - Assert.AreEqual(Complex32.Zero, r[i, j]); - } + Assert.AreEqual(i == j ? Complex32.One : Complex32.Zero, r[i, j]); } } @@ -84,14 +76,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Factorization { for (var j = 0; j < q.ColumnCount; j++) { - if (i == j) - { - Assert.AreEqual(Complex32.One, q[i, j]); - } - else - { - Assert.AreEqual(Complex32.Zero, q[i, j]); - } + Assert.AreEqual(i == j ? Complex32.One : Complex32.Zero, q[i, j]); } } } diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/UserLUTests.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/UserLUTests.cs index e9b7de13..688ec7f7 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/UserLUTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/UserLUTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using NUnit.Framework; diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/UserQRTests.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/UserQRTests.cs index dcc873a9..8142a6d9 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/UserQRTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/UserQRTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Complex32.Factorization; using MathNet.Numerics.LinearAlgebra.Factorization; diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixStructureTheory.cs index ea05fbe6..2061c793 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixStructureTheory.cs @@ -39,7 +39,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 public class MatrixStructureTheory : MatrixStructureTheory { [Datapoints] - Matrix[] _matrices = new Matrix[] + Matrix[] _matrices = { Matrix.Build.DenseOfArray(new[,] { { 1f, new Complex32(1.1f, -4f), 2f }, { 1f, 1f, 2f }, { 1f, new Complex32(1f, 2f), 2f } }), Matrix.Build.DenseOfArray(new[,] { { -1.1f, -2.2f, -3.3f }, { 0f, 1.1f, new Complex32(2.2f, -1.2f) }, { -4.4f, 5.5f, 6.6f } }), @@ -60,6 +60,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 }; [Datapoints] - Complex32[] scalars = new[] { new Complex32(2f, 0f), new Complex32(-1.5f, 3.5f), Complex32.Zero }; + Complex32[] scalars = { new Complex32(2f, 0f), new Complex32(-1.5f, 3.5f), Complex32.Zero }; } } diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/PreConditionerTest.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/PreConditionerTest.cs index 9f30543b..35d17395 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/PreConditionerTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/PreConditionerTest.cs @@ -28,7 +28,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Complex32; using MathNet.Numerics.LinearAlgebra.Solvers; diff --git a/src/UnitTests/LinearAlgebraTests/Double/DenseVectorArithmeticTheory.cs b/src/UnitTests/LinearAlgebraTests/Double/DenseVectorArithmeticTheory.cs index fb123bb9..8a928f86 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/DenseVectorArithmeticTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/DenseVectorArithmeticTheory.cs @@ -40,7 +40,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double Vector[] denseVectors = { Vector.Build.Dense(new double[] { 1, 2, 3, 4, 5 }), - Vector.Build.Dense(new double[] { 2, 0, 0, -5, 0 }), + Vector.Build.Dense(new double[] { 2, 0, 0, -5, 0 }) }; [Datapoints] diff --git a/src/UnitTests/LinearAlgebraTests/Double/Factorization/CholeskyTests.cs b/src/UnitTests/LinearAlgebraTests/Double/Factorization/CholeskyTests.cs index b9b6fc2b..26f0136b 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Factorization/CholeskyTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Factorization/CholeskyTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Double; using NUnit.Framework; diff --git a/src/UnitTests/LinearAlgebraTests/Double/Factorization/GramSchmidtTests.cs b/src/UnitTests/LinearAlgebraTests/Double/Factorization/GramSchmidtTests.cs index 454821ba..f6d802b4 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Factorization/GramSchmidtTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Factorization/GramSchmidtTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Double; using MathNet.Numerics.LinearAlgebra.Double.Factorization; @@ -68,14 +67,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Factorization { for (var j = 0; j < r.ColumnCount; j++) { - if (i == j) - { - Assert.AreEqual(1.0, r[i, j]); - } - else - { - Assert.AreEqual(0.0, r[i, j]); - } + Assert.AreEqual(i == j ? 1.0 : 0.0, r[i, j]); } } @@ -83,14 +75,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Factorization { for (var j = 0; j < q.ColumnCount; j++) { - if (i == j) - { - Assert.AreEqual(1.0, q[i, j]); - } - else - { - Assert.AreEqual(0.0, q[i, j]); - } + Assert.AreEqual(i == j ? 1.0 : 0.0, q[i, j]); } } } diff --git a/src/UnitTests/LinearAlgebraTests/Double/Factorization/LUTests.cs b/src/UnitTests/LinearAlgebraTests/Double/Factorization/LUTests.cs index c360e28c..7bf940eb 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Factorization/LUTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Factorization/LUTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Double; using NUnit.Framework; diff --git a/src/UnitTests/LinearAlgebraTests/Double/Factorization/QRTests.cs b/src/UnitTests/LinearAlgebraTests/Double/Factorization/QRTests.cs index a185457f..34d2b809 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Factorization/QRTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Factorization/QRTests.cs @@ -180,14 +180,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Factorization { for (var j = 0; j < matrixQtQ.ColumnCount; j++) { - if (i == j) - { - Assert.AreEqual(matrixQtQ[i, j], 1.0, 1e-3); - } - else - { - Assert.AreEqual(matrixQtQ[i, j], 0.0, 1e-3); - } + Assert.AreEqual(matrixQtQ[i, j], i == j ? 1.0 : 0.0, 1e-3); } } } @@ -246,14 +239,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Factorization { for (var j = 0; j < matrixQtQ.ColumnCount; j++) { - if (i == j) - { - Assert.AreEqual(matrixQtQ[i, j], 1.0, 1e-3); - } - else - { - Assert.AreEqual(matrixQtQ[i, j], 0.0, 1e-3); - } + Assert.AreEqual(matrixQtQ[i, j], i == j ? 1.0 : 0.0, 1e-3); } } } diff --git a/src/UnitTests/LinearAlgebraTests/Double/Factorization/UserCholeskyTests.cs b/src/UnitTests/LinearAlgebraTests/Double/Factorization/UserCholeskyTests.cs index e30af49f..a00b56c6 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Factorization/UserCholeskyTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Factorization/UserCholeskyTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using NUnit.Framework; diff --git a/src/UnitTests/LinearAlgebraTests/Double/Factorization/UserGramSchmidtTests.cs b/src/UnitTests/LinearAlgebraTests/Double/Factorization/UserGramSchmidtTests.cs index 39d108ee..3ea1fcc5 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Factorization/UserGramSchmidtTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Factorization/UserGramSchmidtTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Double.Factorization; using NUnit.Framework; @@ -67,14 +66,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Factorization { for (var j = 0; j < r.ColumnCount; j++) { - if (i == j) - { - Assert.AreEqual(1.0, r[i, j]); - } - else - { - Assert.AreEqual(0.0, r[i, j]); - } + Assert.AreEqual(i == j ? 1.0 : 0.0, r[i, j]); } } @@ -82,14 +74,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Factorization { for (var j = 0; j < q.ColumnCount; j++) { - if (i == j) - { - Assert.AreEqual(1.0, q[i, j]); - } - else - { - Assert.AreEqual(0.0, q[i, j]); - } + Assert.AreEqual(i == j ? 1.0 : 0.0, q[i, j]); } } } diff --git a/src/UnitTests/LinearAlgebraTests/Double/Factorization/UserLUTests.cs b/src/UnitTests/LinearAlgebraTests/Double/Factorization/UserLUTests.cs index ec0d5686..58226fa3 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Factorization/UserLUTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Factorization/UserLUTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using NUnit.Framework; diff --git a/src/UnitTests/LinearAlgebraTests/Double/Factorization/UserQRTests.cs b/src/UnitTests/LinearAlgebraTests/Double/Factorization/UserQRTests.cs index a35efbaa..58a60cf5 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Factorization/UserQRTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Factorization/UserQRTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Double.Factorization; using MathNet.Numerics.LinearAlgebra.Factorization; diff --git a/src/UnitTests/LinearAlgebraTests/Double/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/Double/MatrixStructureTheory.cs index 8773c183..5238d16e 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/MatrixStructureTheory.cs @@ -37,7 +37,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double public class MatrixStructureTheory : MatrixStructureTheory { [Datapoints] - Matrix[] _matrices = new Matrix[] + Matrix[] _matrices = { Matrix.Build.DenseOfArray(new[,] { { 1d, 1d, 2d }, { 1d, 1d, 2d }, { 1d, 1d, 2d } }), Matrix.Build.DenseOfArray(new[,] { { -1.1d, -2.2d, -3.3d }, { 0d, 1.1d, 2.2d }, { -4.4d, 5.5d, 6.6d } }), @@ -58,6 +58,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double }; [Datapoints] - double[] _scalars = new[] { 2d, -1.5d, 0d }; + double[] _scalars = { 2d, -1.5d, 0d }; } } diff --git a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/PreConditionerTest.cs b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/PreConditionerTest.cs index 1d2759d1..2c7f6cb0 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/PreConditionerTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/PreConditionerTest.cs @@ -28,7 +28,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Double; using MathNet.Numerics.LinearAlgebra.Solvers; diff --git a/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs index 4565067b..c07378eb 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs @@ -33,7 +33,6 @@ using System.Collections; using System.Collections.Generic; using MathNet.Numerics.Distributions; using MathNet.Numerics.LinearAlgebra; -using MathNet.Numerics.LinearAlgebra.Double; using NUnit.Framework; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double @@ -462,7 +461,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double [Test] public void CanSum() { - double[] testData = { -20, -10, 10, 20, 30, }; + double[] testData = { -20, -10, 10, 20, 30 }; var vector = CreateVector(testData); var actual = vector.Sum(); const double Expected = 30; @@ -475,7 +474,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double [Test] public void CanSumMagnitudes() { - double[] testData = { -20, -10, 10, 20, 30, }; + double[] testData = { -20, -10, 10, 20, 30 }; var vector = CreateVector(testData); var actual = vector.SumMagnitudes(); const double Expected = 90; @@ -517,7 +516,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double [Test] public void CanClearVector() { - double[] testData = { -20, -10, 10, 20, 30, }; + double[] testData = { -20, -10, 10, 20, 30 }; var vector = CreateVector(testData); vector.Clear(); foreach (var element in vector) diff --git a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs index 35536153..6a5da9b3 100644 --- a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs @@ -59,10 +59,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests { Assert.That(matrix, Is.EqualTo(matrix)); Assert.IsTrue(matrix.Equals(matrix)); - Assert.IsTrue(matrix.Equals((object) matrix)); - Assert.IsTrue(((object) matrix).Equals(matrix)); - Assert.IsTrue(matrix == (object) matrix); - Assert.IsTrue((object) matrix == matrix); + Assert.IsTrue(matrix.Equals((object)matrix)); + Assert.IsTrue(((object)matrix).Equals(matrix)); + Assert.IsTrue(matrix == (object)matrix); + Assert.IsTrue((object)matrix == matrix); } [Theory] @@ -74,10 +74,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests // THEN Assert.That(left, Is.Not.EqualTo(right)); Assert.IsFalse(left.Equals(right)); - Assert.IsFalse(left.Equals((object) right)); - Assert.IsFalse(((object) left).Equals(right)); - Assert.IsFalse(left == (object) right); - Assert.IsFalse((object) left == right); + Assert.IsFalse(left.Equals((object)right)); + Assert.IsFalse(((object)left).Equals(right)); + Assert.IsFalse(left == (object)right); + Assert.IsFalse((object)left == right); } [Theory] @@ -85,9 +85,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests { Assert.That(matrix, Is.Not.EqualTo(2)); Assert.IsFalse(matrix.Equals(2)); - Assert.IsFalse(matrix.Equals((object) 2)); - Assert.IsFalse(((object) matrix).Equals(2)); - Assert.IsFalse(matrix == (object) 2); + Assert.IsFalse(matrix.Equals((object)2)); + Assert.IsFalse(((object)matrix).Equals(2)); + Assert.IsFalse(matrix == (object)2); } [Theory] @@ -104,7 +104,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanCloneUsingICloneable(Matrix matrix) { - var clone = (Matrix) ((ICloneable) matrix).Clone(); + var clone = (Matrix)((ICloneable)matrix).Clone(); Assert.That(clone, Is.Not.SameAs(matrix)); Assert.That(clone, Is.EqualTo(matrix)); Assert.That(clone.RowCount, Is.EqualTo(matrix.RowCount)); @@ -259,12 +259,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Test] public void CanCreateDenseFromJaggedArray() { - T[][] array = new[] - { - Vector.Build.Random(4, 0).ToArray(), - Vector.Build.Random(4, 1).ToArray(), - Vector.Build.Random(4, 3).ToArray() - }; + T[][] array = + { + Vector.Build.Random(4, 0).ToArray(), + Vector.Build.Random(4, 1).ToArray(), + Vector.Build.Random(4, 3).ToArray() + }; var matrix = Matrix.Build.DenseOfRows(3, 4, array); Assert.That(matrix.GetType().Name, Is.EqualTo("DenseMatrix")); Assert.That(matrix.RowCount, Is.EqualTo(3)); @@ -277,12 +277,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Test] public void CanCreateSparseFromJaggedArray() { - T[][] array = new[] - { - Vector.Build.Random(4, 0).ToArray(), - Vector.Build.Random(4, 1).ToArray(), - Vector.Build.Random(4, 3).ToArray() - }; + T[][] array = + { + Vector.Build.Random(4, 0).ToArray(), + Vector.Build.Random(4, 1).ToArray(), + Vector.Build.Random(4, 3).ToArray() + }; var matrix = Matrix.Build.SparseOfRows(3, 4, array); Assert.That(matrix.GetType().Name, Is.EqualTo("SparseMatrix")); Assert.That(matrix.RowCount, Is.EqualTo(3)); @@ -296,11 +296,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests public void CanCreateDenseFromColumnVectors() { var columns = new[] - { - Vector.Build.Random(4, 0), - Vector.Build.Random(4, 1), - Vector.Build.Random(4, 3) - }; + { + Vector.Build.Random(4, 0), + Vector.Build.Random(4, 1), + Vector.Build.Random(4, 3) + }; var matrix = Matrix.Build.DenseOfColumns(4, 3, columns); Assert.That(matrix.GetType().Name, Is.EqualTo("DenseMatrix")); Assert.That(matrix.RowCount, Is.EqualTo(4)); @@ -314,11 +314,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests public void CanCreateSparseFromColumnVectors() { var columns = new[] - { - Vector.Build.Random(4, 0), - Vector.Build.Random(4, 1), - Vector.Build.Random(4, 3) - }; + { + Vector.Build.Random(4, 0), + Vector.Build.Random(4, 1), + Vector.Build.Random(4, 3) + }; var matrix = Matrix.Build.SparseOfColumns(4, 3, columns); Assert.That(matrix.GetType().Name, Is.EqualTo("SparseMatrix")); Assert.That(matrix.RowCount, Is.EqualTo(4)); @@ -332,11 +332,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests public void CanCreateDenseFromRowVectors() { var rows = new[] - { - Vector.Build.Random(4, 0), - Vector.Build.Random(4, 1), - Vector.Build.Random(4, 3) - }; + { + Vector.Build.Random(4, 0), + Vector.Build.Random(4, 1), + Vector.Build.Random(4, 3) + }; var matrix = Matrix.Build.DenseOfRows(3, 4, rows); Assert.That(matrix.GetType().Name, Is.EqualTo("DenseMatrix")); Assert.That(matrix.RowCount, Is.EqualTo(3)); @@ -350,11 +350,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests public void CanCreateSparseFromRowVectors() { var rows = new[] - { - Vector.Build.Random(4, 0), - Vector.Build.Random(4, 1), - Vector.Build.Random(4, 3) - }; + { + Vector.Build.Random(4, 0), + Vector.Build.Random(4, 1), + Vector.Build.Random(4, 3) + }; var matrix = Matrix.Build.SparseOfRows(3, 4, rows); Assert.That(matrix.GetType().Name, Is.EqualTo("SparseMatrix")); Assert.That(matrix.RowCount, Is.EqualTo(3)); diff --git a/src/UnitTests/LinearAlgebraTests/Single/DenseVectorArithmeticTheory.cs b/src/UnitTests/LinearAlgebraTests/Single/DenseVectorArithmeticTheory.cs index 710482ae..2ced7ab6 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/DenseVectorArithmeticTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/DenseVectorArithmeticTheory.cs @@ -40,7 +40,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single Vector[] denseVectors = { Vector.Build.Dense(new float[] { 1, 2, 3, 4, 5 }), - Vector.Build.Dense(new float[] { 2, 0, 0, -5, 0 }), + Vector.Build.Dense(new float[] { 2, 0, 0, -5, 0 }) }; [Datapoints] diff --git a/src/UnitTests/LinearAlgebraTests/Single/Factorization/CholeskyTests.cs b/src/UnitTests/LinearAlgebraTests/Single/Factorization/CholeskyTests.cs index 35a48d11..1711f1fc 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Factorization/CholeskyTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Factorization/CholeskyTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Single; using NUnit.Framework; diff --git a/src/UnitTests/LinearAlgebraTests/Single/Factorization/GramSchmidtTests.cs b/src/UnitTests/LinearAlgebraTests/Single/Factorization/GramSchmidtTests.cs index 174a32a4..19b7331f 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Factorization/GramSchmidtTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Factorization/GramSchmidtTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Single; using MathNet.Numerics.LinearAlgebra.Single.Factorization; @@ -68,14 +67,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Factorization { for (var j = 0; j < r.ColumnCount; j++) { - if (i == j) - { - Assert.AreEqual(1.0, r[i, j]); - } - else - { - Assert.AreEqual(0.0, r[i, j]); - } + Assert.AreEqual(i == j ? 1.0 : 0.0, r[i, j]); } } @@ -83,14 +75,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Factorization { for (var j = 0; j < q.ColumnCount; j++) { - if (i == j) - { - Assert.AreEqual(1.0, q[i, j]); - } - else - { - Assert.AreEqual(0.0, q[i, j]); - } + Assert.AreEqual(i == j ? 1.0 : 0.0, q[i, j]); } } } diff --git a/src/UnitTests/LinearAlgebraTests/Single/Factorization/LUTests.cs b/src/UnitTests/LinearAlgebraTests/Single/Factorization/LUTests.cs index 75189c27..f1350e3d 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Factorization/LUTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Factorization/LUTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Single; using NUnit.Framework; diff --git a/src/UnitTests/LinearAlgebraTests/Single/Factorization/QRTests.cs b/src/UnitTests/LinearAlgebraTests/Single/Factorization/QRTests.cs index 9fea9be5..112e126a 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Factorization/QRTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Factorization/QRTests.cs @@ -182,14 +182,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Factorization { for (var j = 0; j < matrixQtQ.ColumnCount; j++) { - if (i == j) - { - Assert.AreEqual(matrixQtQ[i, j], 1.0f, 1e-3f); - } - else - { - Assert.AreEqual(matrixQtQ[i, j], 0.0f, 1e-3f); - } + Assert.AreEqual(matrixQtQ[i, j], i == j ? 1.0f : 0.0f, 1e-3f); } } } @@ -248,14 +241,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Factorization { for (var j = 0; j < matrixQtQ.ColumnCount; j++) { - if (i == j) - { - Assert.AreEqual(matrixQtQ[i, j], 1.0f, 1e-3f); - } - else - { - Assert.AreEqual(matrixQtQ[i, j], 0.0f, 1e-3f); - } + Assert.AreEqual(matrixQtQ[i, j], i == j ? 1.0f : 0.0f, 1e-3f); } } } diff --git a/src/UnitTests/LinearAlgebraTests/Single/Factorization/UserCholeskyTests.cs b/src/UnitTests/LinearAlgebraTests/Single/Factorization/UserCholeskyTests.cs index 1cd5a92d..cbc0b193 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Factorization/UserCholeskyTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Factorization/UserCholeskyTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using NUnit.Framework; diff --git a/src/UnitTests/LinearAlgebraTests/Single/Factorization/UserGramSchmidtTests.cs b/src/UnitTests/LinearAlgebraTests/Single/Factorization/UserGramSchmidtTests.cs index 1bee6d19..127e9181 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Factorization/UserGramSchmidtTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Factorization/UserGramSchmidtTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Single.Factorization; using NUnit.Framework; @@ -67,14 +66,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Factorization { for (var j = 0; j < r.ColumnCount; j++) { - if (i == j) - { - Assert.AreEqual(1.0, r[i, j]); - } - else - { - Assert.AreEqual(0.0, r[i, j]); - } + Assert.AreEqual(i == j ? 1.0 : 0.0, r[i, j]); } } @@ -82,14 +74,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Factorization { for (var j = 0; j < q.ColumnCount; j++) { - if (i == j) - { - Assert.AreEqual(1.0, q[i, j]); - } - else - { - Assert.AreEqual(0.0, q[i, j]); - } + Assert.AreEqual(i == j ? 1.0 : 0.0, q[i, j]); } } } diff --git a/src/UnitTests/LinearAlgebraTests/Single/Factorization/UserLUTests.cs b/src/UnitTests/LinearAlgebraTests/Single/Factorization/UserLUTests.cs index ea8b8f1e..ef49ab79 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Factorization/UserLUTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Factorization/UserLUTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using NUnit.Framework; diff --git a/src/UnitTests/LinearAlgebraTests/Single/Factorization/UserQRTests.cs b/src/UnitTests/LinearAlgebraTests/Single/Factorization/UserQRTests.cs index 793346c0..ef304da7 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Factorization/UserQRTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Factorization/UserQRTests.cs @@ -24,7 +24,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Factorization; using MathNet.Numerics.LinearAlgebra.Single.Factorization; diff --git a/src/UnitTests/LinearAlgebraTests/Single/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/Single/MatrixStructureTheory.cs index 207928e5..57de2252 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/MatrixStructureTheory.cs @@ -37,7 +37,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single public class MatrixStructureTheory : MatrixStructureTheory { [Datapoints] - Matrix[] _matrices = new Matrix[] + Matrix[] _matrices = { Matrix.Build.DenseOfArray(new[,] { { 1f, 1f, 2f }, { 1f, 1f, 2f }, { 1f, 1f, 2f } }), Matrix.Build.DenseOfArray(new[,] { { -1.1f, -2.2f, -3.3f }, { 0f, 1.1f, 2.2f }, { -4.4f, 5.5f, 6.6f } }), @@ -58,6 +58,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single }; [Datapoints] - float[] _scalars = new[] { 2f, -1.5f, 0f }; + float[] _scalars = { 2f, -1.5f, 0f }; } } diff --git a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/PreConditionerTest.cs b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/PreConditionerTest.cs index c66a7ee0..fb3c65d0 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/PreConditionerTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/PreConditionerTest.cs @@ -28,7 +28,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Single; using MathNet.Numerics.LinearAlgebra.Solvers; diff --git a/src/UnitTests/LinearAlgebraTests/Single/SparseMatrixTests.cs b/src/UnitTests/LinearAlgebraTests/Single/SparseMatrixTests.cs index 8e2b685b..a416eb73 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/SparseMatrixTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/SparseMatrixTests.cs @@ -62,27 +62,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single return SparseMatrix.OfArray(data); } - /// - /// Creates a vector of the given size. - /// - /// The size of the vector to create. - /// - /// The new vector. - protected virtual Vector CreateVector(int size) - { - return new SparseVector(size); - } - - /// - /// Creates a vector from an array. - /// - /// The array to create this vector from. - /// The new vector. - protected virtual Vector CreateVector(float[] data) - { - return SparseVector.OfEnumerable(data); - } - /// /// Can create a matrix form array. /// diff --git a/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs index f51cee7a..b7a17fdb 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs @@ -462,7 +462,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single [Test] public void CanSum() { - float[] testData = { -20, -10, 10, 20, 30, }; + float[] testData = { -20, -10, 10, 20, 30 }; var vector = CreateVector(testData); var actual = vector.Sum(); const float Expected = 30; @@ -475,7 +475,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single [Test] public void CanSumMagnitudes() { - float[] testData = { -20, -10, 10, 20, 30, }; + float[] testData = { -20, -10, 10, 20, 30 }; var vector = CreateVector(testData); var actual = vector.SumMagnitudes(); const float Expected = 90; @@ -517,7 +517,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single [Test] public void CanClearVector() { - float[] testData = { -20, -10, 10, 20, 30, }; + float[] testData = { -20, -10, 10, 20, 30 }; var vector = CreateVector(testData); vector.Clear(); foreach (var element in vector) diff --git a/src/UnitTests/PermutationTest.cs b/src/UnitTests/PermutationTest.cs index 9a995a38..fcd5c065 100644 --- a/src/UnitTests/PermutationTest.cs +++ b/src/UnitTests/PermutationTest.cs @@ -46,7 +46,7 @@ namespace MathNet.Numerics.UnitTests [TestCase(new[] { 0, 3, 2, 1, 4, 5 })] public void CanCreatePermutation(int[] idx) { - new Permutation(idx); + GC.KeepAlive(new Permutation(idx)); } /// diff --git a/src/UnitTests/Random/PalfTests.cs b/src/UnitTests/Random/PalfTests.cs index 5f24ba59..cc89b6b8 100644 --- a/src/UnitTests/Random/PalfTests.cs +++ b/src/UnitTests/Random/PalfTests.cs @@ -28,7 +28,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System; using MathNet.Numerics.Random; using NUnit.Framework; diff --git a/src/UnitTests/RootFindingTests/BroydenTest.cs b/src/UnitTests/RootFindingTests/BroydenTest.cs index 8d25cec3..ca41243f 100644 --- a/src/UnitTests/RootFindingTests/BroydenTest.cs +++ b/src/UnitTests/RootFindingTests/BroydenTest.cs @@ -757,8 +757,8 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests private static double BroydenFindRoot(Func f, double lowerBound, double upperBound, double accuracy = 1e-8, int maxIterations = 100) { - Func fw = x => new double[1] { f(x[0]) }; - double[] initialGuess = new double[1] { (lowerBound + upperBound) * 0.5 }; + Func fw = x => new[] { f(x[0]) }; + double[] initialGuess = { (lowerBound + upperBound) * 0.5 }; return Broyden.FindRoot(fw, initialGuess, accuracy, maxIterations)[0]; } @@ -782,10 +782,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double Re = v * D / kvis; double fD = -dp / rho + 2 * fF * v * v * L / D; double ffF = (Re < 2100) ? (fF - 16 / Re) : (fF - 1 / Math.Pow(4 * Math.Log10(Re * Math.Sqrt(fF)) - 0.4, 2)); - return new double[2] { fD, ffF }; + return new[] { fD, ffF }; }; - double[] r = Broyden.FindRoot(fa1, new double[2] { 0.04, 0.001 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new[] { 0.04, 0.001 }, 1e-14); Assert.AreEqual(0.0389653029101, r[0], 1e-5); Assert.AreEqual(0.0045905347283, r[1], 1e-5); Assert.AreEqual(0, fa1(r)[0], 1e-12); @@ -804,10 +804,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double k = 0.12 * Math.Exp(12581 * (T - 298) / (298 * T)); double fx = 120 * x - 75 * k * (1 - x); double fT = -x * (873 - T) + 11.0 * (T - 300); - return new double[2] { fx, fT }; + return new[] { fx, fT }; }; - double[] r = Broyden.FindRoot(fa1, new double[2] { 1, 400 }, 1e-6); + double[] r = Broyden.FindRoot(fa1, new double[] { 1, 400 }, 1e-6); Assert.AreEqual(0.9638680512795, r[0], 1e-5); Assert.AreEqual(346.16369814640, r[1], 1e-5); Assert.AreEqual(0, fa1(r)[0], 1e-6); @@ -827,10 +827,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double Kp = Math.Exp(42300 / T - 24.2 + 0.17 * Math.Log(T)); double fx = k * Math.Sqrt(1 - x) * ((0.91 - 0.5 * x) / (9.1 - 0.5 * x) - x * x / ((1 - x) * (1 - x) * Kp)); double fT = T * (1.84 * x + 77.3) - 43260 * x - 105128; - return new double[2] { fx, fT }; + return new[] { fx, fT }; }; - double[] r = Broyden.FindRoot(fa1, new double[2] { 0.5, 1700 }, 1e-11); + double[] r = Broyden.FindRoot(fa1, new[] { 0.5, 1700 }, 1e-11); Assert.AreEqual(0.5333728995523, r[0], 1e-5); Assert.AreEqual(1637.70322946500, r[1], 1e-5); Assert.AreEqual(0, fa1(r)[0], 1e-11); @@ -859,10 +859,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double g1calc = Math.Exp(-Math.Log(t1) + x2 * (G12 * t2 - G21 * t1) / (t1 * t2)); double fG21 = Math.Log(gamma2) + Math.Log(t2) + x1 * (G12 * t2 - G21 * t1) / (t1 * t2); double fG12 = Math.Log(gamma1) + Math.Log(t1) - x2 * (G12 * t2 - G21 * t1) / (t1 * t2); - return new double[2] { fG21, fG12 }; + return new[] { fG21, fG12 }; }; - double[] r = Broyden.FindRoot(fa1, new double[2] { 0.5, 0.5 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new[] { 0.5, 0.5 }, 1e-14); Assert.AreEqual(0.3017535930592, r[0], 1e-5); Assert.AreEqual(0.0785888476379, r[1], 1e-5); Assert.AreEqual(0, fa1(r)[0], 1e-14); @@ -891,10 +891,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double g1calc = Math.Exp(-Math.Log(t1) + x2 * (G12 * t2 - G21 * t1) / (t1 * t2)); double fG21 = t1 * t2 * (Math.Log(gamma2) + Math.Log(t2)) + x1 * (G12 * t2 - G21 * t1); double fG12 = t1 * t2 * (Math.Log(gamma1) + Math.Log(t1)) - x2 * (G12 * t2 - G21 * t1); - return new double[2] { fG21, fG12 }; + return new[] { fG21, fG12 }; }; - double[] r = Broyden.FindRoot(fa1, new double[2] { 0.8, 0.8 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new[] { 0.8, 0.8 }, 1e-14); Assert.AreEqual(0.3017535528355, r[0], 1e-5); Assert.AreEqual(0.0785888934885, r[1], 1e-5); Assert.AreEqual(0, fa1(r)[0], 1e-14); @@ -921,10 +921,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double g2calc = Math.Pow(10, B * Math.Pow(x1 / (x1 + B * x2 / A), 2)); double fA = Math.Log10(gamma1) - A * Math.Pow(x2 / (A * x1 / B + x2), 2); double fB = Math.Log10(gamma2) - B * Math.Pow(x1 / (x1 + B * x2 / A), 2); - return new double[2] { fA, fB }; + return new[] { fA, fB }; }; - double[] r = Broyden.FindRoot(fa1, new double[2] { 1.0, 1.0 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new[] { 1.0, 1.0 }, 1e-14); Assert.AreEqual(0.7580768059470, r[0], 1e-5); Assert.AreEqual(1.1249034445330, r[1], 1e-5); Assert.AreEqual(0, fa1(r)[0], 1e-14); @@ -951,10 +951,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double g2calc = Math.Pow(10, B * Math.Pow(x1 / (x1 + B * x2 / A), 2)); double fA = Math.Log10(gamma1) * Math.Pow(A * x1 / B + x2, 2) - A * Math.Pow(x2, 2); double fB = Math.Log10(gamma2) * Math.Pow(x1 + B * x2 / A, 2) - B * Math.Pow(x1, 2); - return new double[2] { fA, fB }; + return new[] { fA, fB }; }; - double[] r = Broyden.FindRoot(fa1, new double[2] { 1.0, 1.0 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new[] { 1.0, 1.0 }, 1e-14); Assert.AreEqual(0.7580768919420, r[0], 1e-5); Assert.AreEqual(1.1249035089540, r[1], 1e-5); Assert.AreEqual(0, fa1(r)[0], 1e-14); @@ -971,10 +971,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double x2 = x[1]; double f1 = x1 / (1 - x1) - 5 * Math.Log(0.4 * (1 - x1) / x2) + 4.45977; double f2 = x2 - (0.4 - 0.5 * x1); - return new double[2] { f1, f2 }; + return new[] { f1, f2 }; }; - double[] r = Broyden.FindRoot(fa1, new double[2] { 0.9, 0.5 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new[] { 0.9, 0.5 }, 1e-14); Assert.AreEqual(0.7573962468236, r[0], 1e-5); Assert.AreEqual(0.0213018765882, r[1], 1e-5); Assert.AreEqual(0, fa1(r)[0], 1e-14); @@ -996,10 +996,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests const double P = 0.00243; double f1 = a - Math.Pow((c + 2 * x1) * (a + b + c - 2 * x1), 2) / (x2) - x1; double f2 = x2 - kp * P * P * Math.Pow(b - 3 * x1, 3); - return new double[2] { f1, f2 }; + return new[] { f1, f2 }; }; - double[] r = Broyden.FindRoot(fa1, new double[2] { 0, -1 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new double[] { 0, -1 }, 1e-14); Assert.AreEqual(0.6003231171445, r[0], 1e-5); Assert.AreEqual(-3.57990244801, r[1], 1e-5); Assert.AreEqual(0, fa1(r)[0], 1e-14); @@ -1016,10 +1016,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double x = xa[1]; double frp = rp - 0.327 * Math.Pow(x, 0.804) * Math.Exp(-5230 / (1.987 * (373 + 1.84e6 * rp))); double fx = x - (0.06 - 161 * rp); - return new double[2] { frp, fx }; + return new[] { frp, fx }; }; - double[] r = Broyden.FindRoot(fa1, new double[2] { 0.0001, 0.01 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new[] { 0.0001, 0.01 }, 1e-14); Assert.AreEqual(0.0003406054400, r[0], 1e-5); Assert.AreEqual(0.0051625241669, r[1], 1e-5); Assert.AreEqual(0, fa1(r)[0], 1e-14); @@ -1042,10 +1042,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double Re = rho * D * u / (13.2 * 0.000672); double ffF = fF - 1 / Math.Pow(2.28 - 4 * Math.Log10(eps / D + 4.67 / (Re * Math.Sqrt(fF))), 2); double fu = 133.7 - (2 * fF * rho * u * u * L / D + rho * g * 200) / (g * 144); - return new double[2] { ffF, fu }; + return new[] { ffF, fu }; }; - double[] r = Broyden.FindRoot(fa1, new double[2] { 0.1, 10.0 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new[] { 0.1, 10.0 }, 1e-14); Assert.AreEqual(0.006874616348157, r[0], 1e-5); Assert.AreEqual(5.6728221306731, r[1], 1e-5); Assert.AreEqual(0, fa1(r)[0], 1e-14); @@ -1070,10 +1070,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double ft12 = 1 / (x1 * x2) - 2 * t21 * c2 / Math.Pow(x1 + x2 * c1, 3) - 2 * t12 * c4 / Math.Pow(x2 + x1 * c3, 3); double ft21 = (x1 - x2) / Math.Pow(x1 * x2, 2) + 6 * t21 * c2 * (1 - c1) / Math.Pow(x1 + x2 * c1, 4) + 6 * t12 * c4 * (c3 - 1) / Math.Pow(x2 + x1 * c3, 4); - return new double[2] { ft12, ft21 }; + return new[] { ft12, ft21 }; }; - double[] r = Broyden.FindRoot(fa1, new double[2] { 0.1, 0.1 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new[] { 0.1, 0.1 }, 1e-14); Assert.AreEqual(1.6043843214350, r[0], 1e-5); Assert.AreEqual(1.6043843214350, r[1], 1e-5); Assert.AreEqual(0, fa1(r)[0], 1e-14); @@ -1102,10 +1102,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double ft = x1 + x2 - 1; double fx1 = x1 - y1 / k1; double fx2 = x2 - y2 / k2; - return new double[3] { ft, fx1, fx2 }; + return new[] { ft, fx1, fx2 }; }; - double[] r = Broyden.FindRoot(fa1, new double[3] { 100, 0.2, 0.8 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new[] { 100, 0.2, 0.8 }, 1e-14); Assert.AreEqual(93.96706523770, r[0], 1e-5); Assert.AreEqual(0.0078754574659, r[1], 1e-5); Assert.AreEqual(0.9921245425339, r[2], 1e-5); @@ -1139,10 +1139,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fx1 = x1 - z1 / (1 + alpha * (k1 - 1)); double fx2 = x2 - z2 / (1 + alpha * (k2 - 1)); double falpha = x1 + x2 - (y1 + y2); - return new double[3] { fx1, fx2, falpha }; + return new[] { fx1, fx2, falpha }; }; - double[] r = Broyden.FindRoot(fa1, new double[3] { 0, 1, 0.5 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new[] { 0, 1, 0.5 }, 1e-14); Assert.AreEqual(0.0226974766367, r[0], 1e-5); Assert.AreEqual(0.9773025233633, r[1], 1e-5); Assert.AreEqual(0.5322677863643, r[2], 1e-5); @@ -1173,10 +1173,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fT = F * (T0 - T) / V + 30000 * k * Ca / rhocp - U * A * (T - Tj) / (rhocp * V); double fCa = F * (Ca0 - Ca) / V - k * Ca; double fTj = Fj * (Tj0 - Tj) / 3.85 + U * A * (T - Tj) / (62.3 * 1.0 * 3.85); - return new double[3] { fT, fCa, fTj }; + return new[] { fT, fCa, fTj }; }; - double[] r = Broyden.FindRoot(fa1, new double[3] { 600, 0.1, 600 }, 1e-11); + double[] r = Broyden.FindRoot(fa1, new[] { 600, 0.1, 600 }, 1e-11); Assert.AreEqual(590.34979512380, r[0], 1e-5); Assert.AreEqual(0.3301868979161, r[1], 1e-5); Assert.AreEqual(585.72976766210, r[2], 1e-5); @@ -1206,10 +1206,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fCD = CC * CD / (CA * CB) - KC1; double fCX = CX * CY / (CB * CC) - KC2; double fCZ = CZ / (CA * CX) - KC3; - return new double[3] { fCD, fCX, fCZ }; + return new[] { fCD, fCX, fCZ }; }; - double[] r = Broyden.FindRoot(fa1, new double[3] { 0.7, 0.2, 0.4 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new[] { 0.7, 0.2, 0.4 }, 1e-14); Assert.AreEqual(0.7053344059695, r[0], 1e-5); Assert.AreEqual(0.1777924200537, r[1], 1e-5); Assert.AreEqual(0.3739765850146, r[2], 1e-5); @@ -1239,10 +1239,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fCD = CC * CD - KC1 * (CA * CB); double fCX = CX * CY - KC2 * (CB * CC); double fCZ = CZ - KC3 * (CA * CX); - return new double[3] { fCD, fCX, fCZ }; + return new[] { fCD, fCX, fCZ }; }; - double[] r = Broyden.FindRoot(fa1, new double[3] { 0.7, 0.2, 0.4 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new[] { 0.7, 0.2, 0.4 }, 1e-14); Assert.AreEqual(0.7053344059695, r[0], 1e-5); Assert.AreEqual(0.1777924200537, r[1], 1e-5); Assert.AreEqual(0.3739765850146, r[2], 1e-5); @@ -1267,10 +1267,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fX = -0.16 * X * F0 / h + k1 * (1 - X) - k2 * X; double fT = 0.16 * F0 * T0 / h - 0.16 * T * F0 / h + 5 * (k1 * (1 - X) - k2 * X); double fh = 0.16 * F0 - 0.4 * Math.Sqrt(h); - return new double[3] { fX, fT, fh }; + return new[] { fX, fT, fh }; }; - double[] r = Broyden.FindRoot(fa1, new double[3] { 0.5, 500, 0.5 }, 1e-13); + double[] r = Broyden.FindRoot(fa1, new[] { 0.5, 500, 0.5 }, 1e-13); Assert.AreEqual(0.0171035426725, r[0], 1e-5); Assert.AreEqual(300.08551771340, r[1], 1e-5); Assert.AreEqual(0.16, r[2], 1e-5); @@ -1294,10 +1294,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fCA = 0.1 * (1 - CA) - k1 * CA * CA; double fCB = -0.1 * CB + k1 * CA * CA - k2 * CB; double fT = 0.1 * (25 - T) - 418 * k1 * CA * CA - 418 * k2 * CB + Q * 1e-5; - return new double[3] { fCA, fCB, fT }; + return new[] { fCA, fCB, fT }; }; - double[] r = Broyden.FindRoot(fa1, new double[3] { 0.5, 0.5, 500 }, 1e-13); + double[] r = Broyden.FindRoot(fa1, new[] { 0.5, 0.5, 500 }, 1e-13); Assert.AreEqual(0.1578109142617, r[0], 1e-5); Assert.AreEqual(0.77071354919, r[1], 1e-5); Assert.AreEqual(153.09, r[2], 1e-2); @@ -1328,10 +1328,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fCA = CA0 - CA - theta * k1 * CA / (1 + KA * CB); double fCB = CB - CB0 - (theta * k1 * CA / (1 + KA * CB) - theta * k2 * CB + theta * k2p * CC); double fT = 85 * (T - T0) + 0.02 * (T * T - T0 * T0) - ((16000 + 3 * T - 0.002 * T * T) * ((CA0 - CA) / CA0) + (30000 + 4 * T - 0.003 * T * T) * CC / CA0); - return new double[3] { fCA, fCB, fT }; + return new[] { fCA, fCB, fT }; }; - double[] r = Broyden.FindRoot(fa1, new double[3] { 3, 0, 300 }, 1e-13); + double[] r = Broyden.FindRoot(fa1, new double[] { 3, 0, 300 }, 1e-13); Assert.AreEqual(2.7873203092940, r[0], 1e-5); Assert.AreEqual(0.2126796260201, r[1], 1e-5); Assert.AreEqual(310.212556340, r[2], 1e-5); @@ -1362,10 +1362,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fp4 = 70 * 32.3 - p4 * (144 * 32.2 / 62.35) + k45 * Math.Pow(Q24 + Q34, 2); double fQ24 = (p4 - p2) * (144 * 32.2 / 62.35) + k24 * Q24 * Q24; double fQ34 = (p4 - p3) * (144 * 32.2 / 62.35) + k34 * Q34 * Q34; - return new double[3] { fp4, fQ24, fQ34 }; + return new[] { fp4, fQ24, fQ34 }; }; - double[] r = Broyden.FindRoot(fa1, new double[3] { 50, 100, 100 }, 1e-11); + double[] r = Broyden.FindRoot(fa1, new double[] { 50, 100, 100 }, 1e-11); Assert.AreEqual(57.12556038475, r[0], 1e-5); Assert.AreEqual(51.75154563498, r[1], 1e-5); Assert.AreEqual(92.91811138918, r[2], 1e-5); @@ -1397,10 +1397,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fCB = CB - CB0 - (theta * k1 * CA / (1 + KA * CB) - theta * k2 * CB + theta * k2p * CC); double fCC = CC - CC0 - theta * k2 * CB + theta * k2p * CC; double fT = 85 * (T - T0) + 0.02 * (T * T - T0 * T0) - ((16000 + 3 * T - 0.002 * T * T) * ((CA0 - CA) / CA0) + (30000 + 4 * T - 0.003 * T * T) * CC / CA0); - return new double[4] { fCA, fCB, fCC, fT }; + return new[] { fCA, fCB, fCC, fT }; }; - double[] r = Broyden.FindRoot(fa1, new double[4] { 3, 0, 0, 300 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new double[] { 3, 0, 0, 300 }, 1e-14); Assert.AreEqual(2.7873203092938, r[0], 1e-5); Assert.AreEqual(0.2126796260201, r[1], 1e-5); Assert.AreEqual(6.468613E-08, r[2], 1e-14); @@ -1440,10 +1440,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double ftc = u * a * (t1 - tc) / (1.82 * 1000 * 4184) - fc * (tc - 27) / 1.82; double fb = ((t1 - 80) / 20 - b) / 20; double fy = (m - y) / taui; - return new double[5] { fca, ft1, ftc, fb, fy }; + return new[] { fca, ft1, ftc, fb, fy }; }; - double[] r = Broyden.FindRoot(fa1, new double[5] { 1, 100, 50, 0.4, 0.25 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new[] { 1, 100, 50, 0.4, 0.25 }, 1e-14); Assert.IsFalse(r[3] >= 0); Assert.IsFalse(r[4] >= 0); //Assert.AreEqual(1.1206138931808, r[0], 1e-5); @@ -1476,10 +1476,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fx4 = x1 - 0.1 * x2; double fx5 = x1 - 1e4 * x3 * x4; double fx6 = x5 - 55e14 * x3 * x6; - return new double[6] { fx1, fx2, fx3, fx4, fx5, fx6 }; + return new[] { fx1, fx2, fx3, fx4, fx5, fx6 }; }; - double[] r = Broyden.FindRoot(fa1, new double[6] { 10, 10, 10, 10, 10, 10 }, 1e-2, 1000); + double[] r = Broyden.FindRoot(fa1, new double[] { 10, 10, 10, 10, 10, 10 }, 1e-2, 1000); Assert.AreEqual(0.0000826446329, r[0], 1e-9); Assert.AreEqual(0.0008264463286, r[1], 1e-8); Assert.AreEqual(0.0000909091485, r[2], 1e-8); @@ -1517,10 +1517,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fx4 = k1 * x1 * x6 - kr1 * x4 - k3 * x4 * x5; double fx5 = 1.5 * (k2 * x2 * x6 - kr2 * x5) - k3 * x4 * x5; double fx6 = 1 - x4 - x5 - x6; - return new double[6] { fx1, fx2, fx3, fx4, fx5, fx6 }; + return new[] { fx1, fx2, fx3, fx4, fx5, fx6 }; }; - double[] r = Broyden.FindRoot(fa1, new double[6] { 0.99, 0.05, 0.05, 0.99, 0.05, 0 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new[] { 0.99, 0.05, 0.05, 0.99, 0.05, 0 }, 1e-14); Assert.AreEqual(0.9700739407529, r[0], 1e-5); Assert.AreEqual(0.9800492938353, r[1], 1e-5); Assert.AreEqual(0.0598521184942, r[2], 1e-6); @@ -1558,10 +1558,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fx4 = k1 * x1 * x6 - kr1 * x4 - k3 * x4 * x5; double fx5 = 1.5 * (k2 * x2 * x6 - kr2 * x5) - k3 * x4 * x5; double fx6 = 1 - x4 - x5 - x6; - return new double[6] { fx1, fx2, fx3, fx4, fx5, fx6 }; + return new[] { fx1, fx2, fx3, fx4, fx5, fx6 }; }; - double[] r = Broyden.FindRoot(fa1, new double[6] { 0.99, 0.05, 0.05, 0.99, 0.05, 0 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new[] { 0.99, 0.05, 0.05, 0.99, 0.05, 0 }, 1e-14); Assert.AreEqual(0.9499424500947, r[0], 1e-5); Assert.AreEqual(0.9666283000631, r[1], 1e-5); Assert.AreEqual(0.1001150998106, r[2], 1e-5); @@ -1599,10 +1599,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fx4 = k1 * x1 * x6 - kr1 * x4 - k3 * x4 * x5; double fx5 = 1.5 * (k2 * x2 * x6 - kr2 * x5) - k3 * x4 * x5; double fx6 = 1 - x4 - x5 - x6; - return new double[6] { fx1, fx2, fx3, fx4, fx5, fx6 }; + return new[] { fx1, fx2, fx3, fx4, fx5, fx6 }; }; - double[] r = Broyden.FindRoot(fa1, new double[6] { 0.99, 0.05, 0.05, 0.99, 0.05, 0 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new[] { 0.99, 0.05, 0.05, 0.99, 0.05, 0 }, 1e-14); Assert.AreEqual(0.9499356376871, r[0], 1e-5); Assert.AreEqual(0.9666237584581, r[1], 1e-5); Assert.AreEqual(0.1001150998106, r[2], 1e-4); @@ -1647,10 +1647,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fx22 = x22 - x21 * k21 / k22; double ft = x11 * (1 - k11) + x21 * (1 - k21); double fbeta1 = (x11 - x12) + (x21 - x22); - return new double[6] { fx11, fx12, fx21, fx22, ft, fbeta1 }; + return new[] { fx11, fx12, fx21, fx22, ft, fbeta1 }; }; - double[] r = Broyden.FindRoot(fa1, new double[6] { 0, 1, 1, 0, 100, 0.8 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new[] { 0, 1, 1, 0, 100, 0.8 }, 1e-14); Assert.AreEqual(0.0226982050031, r[0], 1e-7); Assert.AreEqual(0.6867475652564, r[1], 1e-6); Assert.AreEqual(0.9773017949969, r[2], 1e-6); @@ -1701,10 +1701,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fCD = V - vo * CD / rD; double fCE = V - vo * CE / rE; double fT = 5000 * (350 - T) - 25 * (20 + 40) * (T - 300) + V * SRH; - return new double[6] { fCA, fCB, fCC, fCD, fCE, fT }; + return new[] { fCA, fCB, fCC, fCD, fCE, fT }; }; - Assert.That(() => Broyden.FindRoot(fa1, new double[6] { 0.5, 0.01, 1, 0.01, 1, 420 }, 1e1), Throws.TypeOf()); + Assert.That(() => Broyden.FindRoot(fa1, new[] { 0.5, 0.01, 1, 0.01, 1, 420 }, 1e1), Throws.TypeOf()); } [Test] @@ -1742,10 +1742,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fCD = V * rD - vo * CD; double fCE = V * rE - vo * CE; double fT = 5000 * (350 - T) - 25 * (20 + 40) * (T - 300) + V * SRH; - return new double[6] { fCA, fCB, fCC, fCD, fCE, fT }; + return new[] { fCA, fCB, fCC, fCD, fCE, fT }; }; - double[] r = Broyden.FindRoot(fa1, new double[6] { 0.5, 0.01, 1, 0.01, 1, 420 }, 1e-7, 10000); + double[] r = Broyden.FindRoot(fa1, new[] { 0.5, 0.01, 1, 0.01, 1, 420 }, 1e-7, 10000); Assert.AreEqual(0.002666326911334, r[0], 1e-9); Assert.AreEqual(0.033464055791589, r[1], 1e-8); Assert.AreEqual(0.837065955800961, r[2], 1e-6); @@ -1780,10 +1780,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fx5 = x1 + x2 + x3 + x4 + x5 - 1; double fx6 = 400 * x1 * x4 * x4 * x4 - 1.7837e5 * x3 * x5; double fx7 = x1 * x3 - 2.6058 * x2 * x4; - return new double[7] { fx1, fx2, fx3, fx4, fx5, fx6, fx7 }; + return new[] { fx1, fx2, fx3, fx4, fx5, fx6, fx7 }; }; - double[] r = Broyden.FindRoot(fa1, new double[7] { 0.5, 0, 0, 0.5, 0, 0.5, 2 }, 1e-12); + double[] r = Broyden.FindRoot(fa1, new[] { 0.5, 0, 0, 0.5, 0, 0.5, 2 }, 1e-12); Assert.AreEqual(0.3228708394765, r[0], 1e-9); Assert.AreEqual(0.0092235435392, r[1], 1e-8); Assert.AreEqual(0.0460170909606, r[2], 1e-8); @@ -1820,10 +1820,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fE = 150.2 * 133.7 * 0.32 * 0.32 / (A - B - C) - D * (A - B - C) / Math.Pow(0.0986 * A - D, 2); double fF = 446.8 * 133.7 * 0.0032 * 0.0032 / (1.098 * A - B - 9 * D - E - F + G) - (A * 0.0986 - D) / (1.098 * A - B - 9 * D - E - F + G) + 0.01; double fG = 0.04 * (74.12 * (0.986 * A - 10 * D) + 222.24 * (0.0986 * A - D) + 18 * (D - B) + 278.84 * D + 98.09 * 0.0136 * A) / 98.01 - 0.0136 * A - G; - return new double[7] { fA, fB, fC, fD, fE, fF, fG }; + return new[] { fA, fB, fC, fD, fE, fF, fG }; }; - double[] r = Broyden.FindRoot(fa1, new double[7] { 80, 7, 60, 7, 0.5, 4, 0.05 }, 1e-12); + double[] r = Broyden.FindRoot(fa1, new[] { 80, 7, 60, 7, 0.5, 4, 0.05 }, 1e-12); Assert.AreEqual(80.5340430736936, r[0], 1e-9); Assert.AreEqual(6.9725465115675, r[1], 1e-8); Assert.AreEqual(61.1190817582544, r[2], 1e-8); @@ -1860,10 +1860,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fE = 2056.4 * Math.Pow(0.0986 * A - D, 2) - D * Math.Pow(A - B - C, 2); double fF = 0.61177 - (A * 0.0986 - D) + 0.01 * (1.098 * A - B - 9 * D - E - F + G); double fG = 0.04 * (74.12 * (0.986 * A - 10 * D) + 222.24 * (0.0986 * A - D) + 18 * (D - B) + 278.84 * D + 98.09 * 0.0136 * A) / 98.01 - 0.0136 * A - G; - return new double[7] { fA, fB, fC, fD, fE, fF, fG }; + return new[] { fA, fB, fC, fD, fE, fF, fG }; }; - double[] r = Broyden.FindRoot(fa1, new double[7] { 80, 7, 60, 7, 0.5, 4, 0.06 }, 1e-11); + double[] r = Broyden.FindRoot(fa1, new[] { 80, 7, 60, 7, 0.5, 4, 0.06 }, 1e-11); Assert.AreEqual(80.5396204210231, r[0], 1e-9); Assert.AreEqual(6.9730107905982, r[1], 1e-8); Assert.AreEqual(61.1233326471120, r[2], 1e-8); @@ -1914,10 +1914,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fq23 = k01 * q01 * q01 + k12 * q12 * q12 + k24 * q24 * q24 + k45 * q45 * q45 + deltaPUMP; double fq34 = k13 * q13 * q13 - k23 * q23 * q23 - k12 * q12 * q12; double fq45 = k23 * q23 * q23 + k34 * q34 * q34 - k24 * q24 * q24; - return new double[7] { fq01, fq12, fq13, fq24, fq23, fq34, fq45 }; + return new[] { fq01, fq12, fq13, fq24, fq23, fq34, fq45 }; }; - double[] r = Broyden.FindRoot(fa1, new double[7] { 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 }, 1e-9); + double[] r = Broyden.FindRoot(fa1, new[] { 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 }, 1e-9); Assert.AreEqual(0.098136927428176, r[0], 1e-8); Assert.AreEqual(0.064819554408160, r[1], 1e-8); Assert.AreEqual(0.033317373020015, r[2], 1e-8); @@ -1976,10 +1976,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fq23 = k01 * q01 * q01 + k12 * q12 * q12 + k24 * q24 * q24 + k45 * q45 * q45 + deltaPUMP; double fq34 = k13 * q13 * q13 - k23 * q23 * q23 - k12 * q12 * q12; double fq45 = k23 * q23 * q23 + k34 * q34 * q34 - k24 * q24 * q24; - return new double[7] { fq01, fq12, fq13, fq24, fq23, fq34, fq45 }; + return new[] { fq01, fq12, fq13, fq24, fq23, fq34, fq45 }; }; - double[] r = Broyden.FindRoot(fa1, new double[7] { 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 }, 1e-10); + double[] r = Broyden.FindRoot(fa1, new[] { 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 }, 1e-10); Assert.AreEqual(0.110237410418775, r[0], 1e-8); Assert.AreEqual(0.073312448014583, r[1], 1e-8); Assert.AreEqual(0.036924962404192, r[2], 1e-8); @@ -2021,10 +2021,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fq35 = q35 + q65 - 420; double fq65 = q46 - 140 - q65; double fq46 = dp43 + dp35 - fc * 0.2572 * q65 * q65 - fc * 0.1286 * q46 * q46; - return new double[7] { fq12, fq14, fq23, fq43, fq35, fq65, fq46 }; + return new[] { fq12, fq14, fq23, fq43, fq35, fq65, fq46 }; }; - double[] r = Broyden.FindRoot(fa1, new double[7] { 1000, 500, 600, 200, 300, 100, 400 }, 1e-12); + double[] r = Broyden.FindRoot(fa1, new double[] { 1000, 500, 600, 200, 300, 100, 400 }, 1e-12); Assert.AreEqual(872.751598594702, r[0], 1e-5); Assert.AreEqual(527.248401405298, r[1], 1e-5); Assert.AreEqual(452.751598594702, r[2], 1e-5); @@ -2084,10 +2084,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fV = x11 + x12 + x13 - 1; double fL1 = L1 + L2 + V - 1; double fL2 = x21 + x22 + x23 - 1; - return new double[9] { fx11, fx12, fx13, fx21, fx22, fx23, fV, fL1, fL2 }; + return new[] { fx11, fx12, fx13, fx21, fx22, fx23, fV, fL1, fL2 }; }; - double[] r = Broyden.FindRoot(fa1, new double[9] { 0.3, 0, 0.7, 0, 1, 0, 0.4, 0.55, 0.06 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new[] { 0.3, 0, 0.7, 0, 1, 0, 0.4, 0.55, 0.06 }, 1e-14); Assert.AreEqual(0.2253818399616, r[0], 1e-5); Assert.AreEqual(0.0042438488738, r[1], 1e-5); Assert.AreEqual(0.7703743111646, r[2], 1e-5); @@ -2137,11 +2137,11 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fx8 = x8 * x4 - 1.799e-5 * x2 * xs; double fx9 = x9 * x4 - 0.0002155 * x1 * Math.Sqrt(x3 * xs); double fx10 = x10 * x4 * x4 - 3.846e-5 * x4 * x4 * xs; - return new double[10] { fx1, fx2, fx3, fx4, fx5, fx6, fx7, fx8, fx9, fx10 }; + return new[] { fx1, fx2, fx3, fx4, fx5, fx6, fx7, fx8, fx9, fx10 }; }; - Assert.That(() => Broyden.FindRoot(fa1, new double[10] { 1, 1, 10, 1, 1, 1, 0, 0, 0, 0 }, 1e-1), Throws.TypeOf()); - double[] r = Broyden.FindRoot(fa1, new double[10] { 3, 4, 20, 0.1, 0.1, 0.01, 0.01, 0.01, 0.1, 0.001 }, 1e-14); + Assert.That(() => Broyden.FindRoot(fa1, new double[] { 1, 1, 10, 1, 1, 1, 0, 0, 0, 0 }, 1e-1), Throws.TypeOf()); + double[] r = Broyden.FindRoot(fa1, new[] { 3, 4, 20, 0.1, 0.1, 0.01, 0.01, 0.01, 0.1, 0.001 }, 1e-14); Assert.AreEqual(2.88010599840556, r[0], 1e-5); Assert.AreEqual(3.95067493980017, r[1], 1e-5); Assert.AreEqual(19.9841296101664, r[2], 1e-5); @@ -2193,11 +2193,11 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fx8 = x8 * x4 - 1.799e-5 * x2 * xs; double fx9 = x9 * x4 - 0.0002155 * x1 * Math.Sqrt(x3 * xs); double fx10 = x10 * x4 * x4 - 3.846e-5 * x4 * x4 * xs; - return new double[10] { fx1, fx2, fx3, fx4, fx5, fx6, fx7, fx8, fx9, fx10 }; + return new[] { fx1, fx2, fx3, fx4, fx5, fx6, fx7, fx8, fx9, fx10 }; }; - Assert.That(() => Broyden.FindRoot(fa1, new double[10] { 2, 5, 80, 1, 0, 0, 0, 0, 20, 5 }, 1e-5), Throws.TypeOf()); - double[] r = Broyden.FindRoot(fa1, new double[10] { 3, 4, 80, 0.001, 0.001, 0.001, 0.01, 4, 26, 0.01 }, 1e-14); + Assert.That(() => Broyden.FindRoot(fa1, new double[] { 2, 5, 80, 1, 0, 0, 0, 0, 20, 5 }, 1e-5), Throws.TypeOf()); + double[] r = Broyden.FindRoot(fa1, new[] { 3, 4, 80, 0.001, 0.001, 0.001, 0.01, 4, 26, 0.01 }, 1e-14); Assert.AreEqual(2.99763549788728, r[0], 1e-5); Assert.AreEqual(3.96642685827836, r[1], 1e-5); Assert.AreEqual(79.9996980829447, r[2], 1e-5); @@ -2256,11 +2256,11 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fn8 = K8 * n1 - n4 * n8 * (p / nt); double fn9 = K9 * n1 * Math.Sqrt(n3) - n4 * n9 * Math.Sqrt(p / nt); double fn10 = K10 * n1 * n1 - n4 * n4 * n10 * (p / nt); - return new double[10] { fn1, fn2, fn3, fn4, fn5, fn6, fn7, fn8, fn9, fn10 }; + return new[] { fn1, fn2, fn3, fn4, fn5, fn6, fn7, fn8, fn9, fn10 }; }; - Assert.That(() => Broyden.FindRoot(fa1, new double[10] { 1.5, 2, 35, 0.5, 0.05, 0.005, 0.04, 0.003, 0.02, 5 }, 1e-5), Throws.TypeOf()); - double[] r = Broyden.FindRoot(fa1, new double[10] { 3, 4, 20, 0.1, 0.01, 0.001, 0.04, 0.003, 0.03, 0.03 }, 1e-14); + Assert.That(() => Broyden.FindRoot(fa1, new[] { 1.5, 2, 35, 0.5, 0.05, 0.005, 0.04, 0.003, 0.02, 5 }, 1e-5), Throws.TypeOf()); + double[] r = Broyden.FindRoot(fa1, new[] { 3, 4, 20, 0.1, 0.01, 0.001, 0.04, 0.003, 0.03, 0.03 }, 1e-14); Assert.AreEqual(2.91572542389522, r[0], 1e-5); Assert.AreEqual(3.96094281080888, r[1], 1e-5); Assert.AreEqual(19.9862916465515, r[2], 1e-5); @@ -2319,11 +2319,11 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fn8 = K8 * n1 - n4 * n8 * (p / nt); double fn9 = K9 * n1 * Math.Sqrt(n3) - n4 * n9 * Math.Sqrt(p / nt); double fn10 = K10 * n1 * n1 - n4 * n4 * n10 * (p / nt); - return new double[10] { fn1, fn2, fn3, fn4, fn5, fn6, fn7, fn8, fn9, fn10 }; + return new[] { fn1, fn2, fn3, fn4, fn5, fn6, fn7, fn8, fn9, fn10 }; }; - Assert.That(() => Broyden.FindRoot(fa1, new double[10] { 1.5, 2, 35, 0.5, 0.05, 0.005, 0.04, 0.003, 0.02, 5 }, 1e-5), Throws.TypeOf()); - double[] r = Broyden.FindRoot(fa1, new double[10] { 3, 4, 80, 0.01, 0.002, 0.0006, 0.1, 0.004, 0.1, 15 }, 1e-14); + Assert.That(() => Broyden.FindRoot(fa1, new[] { 1.5, 2, 35, 0.5, 0.05, 0.005, 0.04, 0.003, 0.02, 5 }, 1e-5), Throws.TypeOf()); + double[] r = Broyden.FindRoot(fa1, new[] { 3, 4, 80, 0.01, 0.002, 0.0006, 0.1, 0.004, 0.1, 15 }, 1e-14); //Assert.AreEqual(2.91572542389522, r[0], 1e-5); //Assert.AreEqual(3.96094281080888, r[1], 1e-5); //Assert.AreEqual(19.9862916465515, r[2], 1e-5); @@ -2379,10 +2379,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fx8 = x6 - x8 - x10; double fx9 = x1 - 0.9; double fx10 = x2 - 0.1; - return new double[10] { fx1, fx2, fx3, fx4, fx5, fx6, fx7, fx8, fx9, fx10 }; + return new[] { fx1, fx2, fx3, fx4, fx5, fx6, fx7, fx8, fx9, fx10 }; }; - double[] r = Broyden.FindRoot(fa1, new double[10] { 0.9, 0.1, 1, 0.2, 0.5, 0.8, 0.2, 0.7, 0.2, 0.1 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new[] { 0.9, 0.1, 1, 0.2, 0.5, 0.8, 0.2, 0.7, 0.2, 0.1 }, 1e-14); Assert.AreEqual(0.9, r[0], 1e-5); Assert.AreEqual(0.1, r[1], 1e-5); Assert.AreEqual(1.1898916711704, r[2], 1e-5); @@ -2455,10 +2455,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fs61 = s81 + s101 + s31 - s61; double fs62 = s82 + s102 + s32 - s62; double fs63 = s83 + s103 + s33 - s63; - return new double[11] { fx1, fx2, fx3, V, L, s11, s12, s13, s61, s62, s63 }; + return new[] { fx1, fx2, fx3, V, L, s11, s12, s13, s61, s62, s63 }; }; - double[] r = Broyden.FindRoot(fa1, new double[11] { 0.1, 0.2, 0, 500, 500, 970, 30, 0, 970, 30, 0 }, 1e-14); + double[] r = Broyden.FindRoot(fa1, new[] { 0.1, 0.2, 0, 500, 500, 970, 30, 0, 970, 30, 0 }, 1e-14); //Assert.AreEqual(0.16547930319775, r[0], 1e-5); //Assert.AreEqual(0.36109556119140, r[1], 1e-5); //Assert.AreEqual(0.4734251356109, r[2], 1e-5); @@ -2516,10 +2516,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fv11 = v1 + 2 * v2 + 2 * v3 + v6 + v10 - 2; double fv12 = v4 + 2 * v5 + v6 + v7 - 1; double fv13 = v3 + v7 + v8 + 2 * v9 + v10 - 1; - return new double[13] { fv1, fv2, fv3, fv4, fv5, fv6, fv7, fv8, fv9, fv10, fv11, fv12, fv13 }; + return new[] { fv1, fv2, fv3, fv4, fv5, fv6, fv7, fv8, fv9, fv10, fv11, fv12, fv13 }; }; - double[] r = Broyden.FindRoot(fa1, new double[13] { 0.05, 0.2, 0.8,0.001, 0.5, 0.0007, 0.03, 0.02, 0.1, 0.1, 10, 10, 10 }, 1e-13); + double[] r = Broyden.FindRoot(fa1, new[] { 0.05, 0.2, 0.8,0.001, 0.5, 0.0007, 0.03, 0.02, 0.1, 0.1, 10, 10, 10 }, 1e-13); Assert.AreEqual(0.04070664967202, r[0], 1e-5); Assert.AreEqual(0.14796418434584, r[1], 1e-5); Assert.AreEqual(0.78211670254494, r[2], 1e-5); @@ -2611,10 +2611,10 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests double fV1 = -V1 * hv1 + V2 * hv2 - L1 * hl1 + L0 * h0; double fV2 = -V2 * hv2 + V3 * hv3 + hf + L1 * hl1 - L2 * hl2; double fV3 = -V3 * hv3 + Q + L2 * hl2 - L3 * hl3; - return new double[14] { fx11, fx12, fx13, fx21, fx22, fx23, ft1, ft2, ft3, ftf, ft0, fV1, fV2, fV3 }; + return new[] { fx11, fx12, fx13, fx21, fx22, fx23, ft1, ft2, ft3, ftf, ft0, fV1, fV2, fV3 }; }; - double[] r = Broyden.FindRoot(fa1, new double[14] { 0.5, 0.4, 0.3, 0.3, 0.4, 0.5, 145, 190, 210, 200, 200, 1, 1, 1 }, 1e-10); + double[] r = Broyden.FindRoot(fa1, new[] { 0.5, 0.4, 0.3, 0.3, 0.4, 0.5, 145, 190, 210, 200, 200, 1, 1, 1 }, 1e-10); Assert.AreEqual(0.57902594925514, r[0], 1e-5); Assert.AreEqual(0.39569120229748, r[1], 1e-5); Assert.AreEqual(0.27186578944464, r[2], 1e-5); diff --git a/src/UnitTests/StatisticsTests/CorrelationTests.cs b/src/UnitTests/StatisticsTests/CorrelationTests.cs index bc34cbcf..04829efe 100644 --- a/src/UnitTests/StatisticsTests/CorrelationTests.cs +++ b/src/UnitTests/StatisticsTests/CorrelationTests.cs @@ -80,8 +80,8 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests [Test] public void PearsonCorrelationConsistentWithCovariance() { - var dataA = _data["lottery"].Data.Take(200); - var dataB = _data["lew"].Data.Take(200); + var dataA = _data["lottery"].Data.Take(200).ToArray(); + var dataB = _data["lew"].Data.Take(200).ToArray(); var direct = Correlation.Pearson(dataA, dataB); var covariance = dataA.Covariance(dataB)/(dataA.StandardDeviation()*dataB.StandardDeviation()); diff --git a/src/UnitTests/StatisticsTests/MCMCTests/HybridMCTest.cs b/src/UnitTests/StatisticsTests/MCMCTests/HybridMCTest.cs index e4d84109..88bd3564 100644 --- a/src/UnitTests/StatisticsTests/MCMCTests/HybridMCTest.cs +++ b/src/UnitTests/StatisticsTests/MCMCTests/HybridMCTest.cs @@ -33,7 +33,6 @@ using System.Globalization; using MathNet.Numerics.Distributions; using MathNet.Numerics.Statistics; using MathNet.Numerics.Statistics.Mcmc; -using MathNet.Numerics.Statistics.Mcmc.Diagnostics; using NUnit.Framework; namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests @@ -44,7 +43,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests [TestFixture, Category("Statistics")] public class HybridMCTest { - private readonly Normal _normal = new Normal(0, 1); + readonly Normal _normal = new Normal(0, 1); /// /// Testing the constructor to make sure that RandomSource is @@ -120,16 +119,16 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests /// Test the sampler using a bivariate normal distribution with randomly selected mean and standard deviation. /// It is a statistical test and may not pass all the time. Note that Sdv and rho have to be between 0 and 1. /// - [TestCase(new[] {0.8, 0.2}, new[] {3.2, -4.6}, 0.77, 1000)] - [TestCase(new[] {0.5, 0.1}, new[] {-2.2, -1.3}, 0.29, 1000)] - [TestCase(new[] {0.45, 0.78}, new[] {1.34, -3.3}, 0.58, 1000)] + [TestCase(new[] { 0.8, 0.2 }, new[] { 3.2, -4.6 }, 0.77, 1000)] + [TestCase(new[] { 0.5, 0.1 }, new[] { -2.2, -1.3 }, 0.29, 1000)] + [TestCase(new[] { 0.45, 0.78 }, new[] { 1.34, -3.3 }, 0.58, 1000)] public void SampleTest(double[] sdv, double[] mean, double rho, int seed) { var pdfLn = new DensityLn(x => LogDen(x, sdv, mean, rho)); - var hybrid = new HybridMC(new double[2] {0, 0}, pdfLn, 10, 0.1, 1000, new double[] {1, 1}, new System.Random(seed)) - { - BurnInterval = 0 - }; + var hybrid = new HybridMC(new double[] { 0, 0 }, pdfLn, 10, 0.1, 1000, new double[] { 1, 1 }, new System.Random(seed)) + { + BurnInterval = 0 + }; const int sampleSize = 10000; double[][] sample = hybrid.Sample(sampleSize); @@ -141,6 +140,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests for (int i = 0; i < 2; i++) { +// ReSharper disable once AccessToModifiedClosure convergence[i] = 1/Math.Sqrt(MCMCDiagnostics.EffectiveSize(sample, x => x[i])); var stats = new DescriptiveStatistics(newSamples[i]); sampleMean[i] = stats.Mean; @@ -169,17 +169,17 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests /// Mean. /// Correlation of the two variables. /// Value of the log density. - private double LogDen(double[] x, double[] sdv, double[] mean, double rho) + double LogDen(double[] x, double[] sdv, double[] mean, double rho) { if (x.Length != 2 || sdv.Length != 2 || mean.Length != 2) - throw new ArgumentOutOfRangeException("LogDen must take a 2 dimensional array"); + throw new ArgumentException("LogDen must take a 2 dimensional array"); double xDiv = x[0] - mean[0]; double yDiv = x[1] - mean[1]; - double xVar = sdv[0] * sdv[0]; - double yVar = sdv[1] * sdv[1]; + double xVar = sdv[0]*sdv[0]; + double yVar = sdv[1]*sdv[1]; - return (-(0.5 / (1 - rho * rho)) * ((xDiv * xDiv) / xVar + (yDiv * yDiv) / yVar - 2 * rho * xDiv * yDiv / (sdv[0] * sdv[1]))); + return (-(0.5/(1 - rho*rho))*((xDiv*xDiv)/xVar + (yDiv*yDiv)/yVar - 2*rho*xDiv*yDiv/(sdv[0]*sdv[1]))); } /// @@ -189,7 +189,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests /// Sample from the HybridMC. /// An array whose first entry is the samples in the first variable and /// second entry is the samples in the second variable. - private double[][] ArrangeSamples(int sampleSize, double[][] sample) + double[][] ArrangeSamples(int sampleSize, double[][] sample) { var xSample = new double[sampleSize]; var ySample = new double[sampleSize]; diff --git a/src/UnitTests/StatisticsTests/MCMCTests/UnivariateSliceSamplerTests.cs b/src/UnitTests/StatisticsTests/MCMCTests/UnivariateSliceSamplerTests.cs index 0530b152..5a00435a 100644 --- a/src/UnitTests/StatisticsTests/MCMCTests/UnivariateSliceSamplerTests.cs +++ b/src/UnitTests/StatisticsTests/MCMCTests/UnivariateSliceSamplerTests.cs @@ -46,7 +46,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests [Test] public void ConstructorTest() { - new UnivariateSliceSampler(0.1, x => -0.5*x*x, 5, 1.0); + GC.KeepAlive(new UnivariateSliceSampler(0.1, x => -0.5*x*x, 5, 1.0)); } /// diff --git a/src/UnitTests/StatisticsTests/StatisticsTests.cs b/src/UnitTests/StatisticsTests/StatisticsTests.cs index 87a16ece..c64ab9e7 100644 --- a/src/UnitTests/StatisticsTests/StatisticsTests.cs +++ b/src/UnitTests/StatisticsTests/StatisticsTests.cs @@ -66,6 +66,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests { double[] data = null; +// ReSharper disable ExpressionIsAlwaysNull Assert.That(() => Statistics.Minimum(data), Throws.Exception); Assert.That(() => Statistics.Maximum(data), Throws.Exception); Assert.That(() => Statistics.Mean(data), Throws.Exception); @@ -117,6 +118,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests Assert.That(() => new RunningStatistics(data), Throws.Exception); Assert.That(() => new RunningStatistics().PushRange(data), Throws.Exception); +// ReSharper restore ExpressionIsAlwaysNull } [Test] @@ -819,8 +821,8 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests [Test] public void CovarianceIsSymmetric() { - var dataA = _data["lottery"].Data.Take(200); - var dataB = _data["lew"].Data.Take(200); + var dataA = _data["lottery"].Data.Take(200).ToArray(); + var dataB = _data["lew"].Data.Take(200).ToArray(); AssertHelpers.AlmostEqualRelative(Statistics.Covariance(dataA, dataB), Statistics.Covariance(dataB, dataA), 12); AssertHelpers.AlmostEqualRelative(StreamingStatistics.Covariance(dataA, dataB), StreamingStatistics.Covariance(dataB, dataA), 12); @@ -984,7 +986,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests Assert.That(ArrayStatistics.MedianInplace(new[] { double.NegativeInfinity, 2.0, double.PositiveInfinity }), Is.EqualTo(2.0)); Assert.That(ArrayStatistics.MedianInplace(new[] { double.NegativeInfinity, double.PositiveInfinity, 2.0 }), Is.EqualTo(2.0)); Assert.That(ArrayStatistics.MedianInplace(new[] { double.NegativeInfinity, 2.0, 3.0, double.PositiveInfinity }), Is.EqualTo(2.5)); - Assert.That(ArrayStatistics.MedianInplace(new[] { double.NegativeInfinity, 2.0, double.PositiveInfinity, 3.0, }), Is.EqualTo(2.5)); + Assert.That(ArrayStatistics.MedianInplace(new[] { double.NegativeInfinity, 2.0, double.PositiveInfinity, 3.0 }), Is.EqualTo(2.5)); Assert.That(SortedArrayStatistics.Median(new[] { double.NegativeInfinity, 2.0, double.PositiveInfinity }), Is.EqualTo(2.0)); Assert.That(SortedArrayStatistics.Median(new[] { double.NegativeInfinity, 2.0, 3.0, double.PositiveInfinity }), Is.EqualTo(2.5)); }