diff --git a/src/Numerics/Distributions/Normal.cs b/src/Numerics/Distributions/Normal.cs index a2f436c8..6cb56024 100644 --- a/src/Numerics/Distributions/Normal.cs +++ b/src/Numerics/Distributions/Normal.cs @@ -347,9 +347,9 @@ namespace MathNet.Numerics.Distributions internal static IEnumerable SamplesUnchecked(System.Random rnd, double mean, double stddev) { - double x, y; while (true) { + double x, y; if (!PolarTransform(rnd.NextDouble(), rnd.NextDouble(), out x, out y)) { continue; diff --git a/src/Numerics/GlobalizationHelper.cs b/src/Numerics/GlobalizationHelper.cs index 21571e65..719f4727 100644 --- a/src/Numerics/GlobalizationHelper.cs +++ b/src/Numerics/GlobalizationHelper.cs @@ -28,12 +28,12 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using System.Globalization; + namespace MathNet.Numerics { - using System; - using System.Collections.Generic; - using System.Globalization; - /// /// Globalized String Handling Helpers /// @@ -105,7 +105,7 @@ namespace MathNet.Numerics { var keyword = keywords[i]; int indexOfKeyword; - while ((indexOfKeyword = node.Value.IndexOf(keyword)) >= 0) + while ((indexOfKeyword = node.Value.IndexOf(keyword, StringComparison.Ordinal)) >= 0) { if (indexOfKeyword != 0) { @@ -269,4 +269,4 @@ namespace MathNet.Numerics } #endif } -} \ No newline at end of file +} diff --git a/src/Numerics/Statistics/MCMC/HybridMCGeneric.cs b/src/Numerics/Statistics/MCMC/HybridMCGeneric.cs index e97f864f..03bf86dd 100644 --- a/src/Numerics/Statistics/MCMC/HybridMCGeneric.cs +++ b/src/Numerics/Statistics/MCMC/HybridMCGeneric.cs @@ -35,7 +35,7 @@ namespace MathNet.Numerics.Statistics.Mcmc using Properties; /// - /// The Hybrid (also called Hamiltonian) Monte Carlo produces samples from distribition P using a set + /// The Hybrid (also called Hamiltonian) Monte Carlo produces samples from distribution P using a set /// of Hamiltonian equations to guide the sampling process. It uses the negative of the log density as /// a potential energy, and a randomly generated momentum to set up a Hamiltonian system, which is then used /// to sample the distribution. This can result in a faster convergence than the random walk Metropolis sampler diff --git a/src/Numerics/Statistics/MCMC/MCMCDiagnostics.cs b/src/Numerics/Statistics/MCMC/MCMCDiagnostics.cs index 4c9efd8b..ae0caf60 100644 --- a/src/Numerics/Statistics/MCMC/MCMCDiagnostics.cs +++ b/src/Numerics/Statistics/MCMC/MCMCDiagnostics.cs @@ -32,7 +32,7 @@ using System; using System.Collections.Generic; using System.Linq; -namespace MathNet.Numerics.Statistics.Mcmc.Diagnostics +namespace MathNet.Numerics.Statistics.Mcmc { /// /// Provides utilities to analysis the convergence of a set of samples from diff --git a/src/UnitTests/ComplexTests/Complex32Test.TextHandling.cs b/src/UnitTests/ComplexTests/Complex32Test.TextHandling.cs index 3a071262..04620b2a 100644 --- a/src/UnitTests/ComplexTests/Complex32Test.TextHandling.cs +++ b/src/UnitTests/ComplexTests/Complex32Test.TextHandling.cs @@ -75,8 +75,6 @@ namespace MathNet.Numerics.UnitTests.ComplexTests /// Can format complex to string with culture. /// /// Culture ID. - /// Not a number name. - /// Infinity name. /// Complex Number. [TestCase("en-US", "1.1")] [TestCase("tr-TR", "1,1")] diff --git a/src/UnitTests/EuclidTests/IntegerTheoryTest.cs b/src/UnitTests/EuclidTests/IntegerTheoryTest.cs index d8e2007a..25add592 100644 --- a/src/UnitTests/EuclidTests/IntegerTheoryTest.cs +++ b/src/UnitTests/EuclidTests/IntegerTheoryTest.cs @@ -25,6 +25,7 @@ // using System; +using System.Globalization; using NUnit.Framework; namespace MathNet.Numerics.UnitTests.EuclidTests @@ -253,7 +254,7 @@ namespace MathNet.Numerics.UnitTests.EuclidTests for (var i = 2; i < 31; i++) { var x = 1 << i; - Assert.AreEqual(x, x.CeilingToPowerOfTwo(), x.ToString()); + Assert.AreEqual(x, x.CeilingToPowerOfTwo(), x.ToString(CultureInfo.InvariantCulture)); Assert.AreEqual(x, (x - 1).CeilingToPowerOfTwo(), x + "-1"); Assert.AreEqual(x, ((x >> 1) + 1).CeilingToPowerOfTwo(), x + "/2+1"); Assert.AreEqual(0, (-x).CeilingToPowerOfTwo(), "-" + x); @@ -279,7 +280,7 @@ namespace MathNet.Numerics.UnitTests.EuclidTests for (var i = 2; i < 63; i++) { var x = ((long)1) << i; - Assert.AreEqual(x, x.CeilingToPowerOfTwo(), x.ToString()); + Assert.AreEqual(x, x.CeilingToPowerOfTwo(), x.ToString(CultureInfo.InvariantCulture)); Assert.AreEqual(x, (x - 1).CeilingToPowerOfTwo(), x + "-1"); Assert.AreEqual(x, ((x >> 1) + 1).CeilingToPowerOfTwo(), x + "/2+1"); Assert.AreEqual(0, (-x).CeilingToPowerOfTwo(), "-" + x); diff --git a/src/UnitTests/LinearAlgebraTests/MatrixHelpers.cs b/src/UnitTests/LinearAlgebraTests/MatrixHelpers.cs index 8f7e9834..4fbfac7a 100644 --- a/src/UnitTests/LinearAlgebraTests/MatrixHelpers.cs +++ b/src/UnitTests/LinearAlgebraTests/MatrixHelpers.cs @@ -27,12 +27,12 @@ using System; using MathNet.Numerics.LinearAlgebra; -namespace MathNet.Numerics.UnitTests +namespace MathNet.Numerics.UnitTests.LinearAlgebraTests { #if NOSYSNUMERICS - using Complex = Numerics.Complex; + using Complex64 = Numerics.Complex; #else - using Complex = System.Numerics.Complex; + using Complex64 = System.Numerics.Complex; #endif /// @@ -65,7 +65,7 @@ namespace MathNet.Numerics.UnitTests /// from the lower triangle to the upper triangle. /// /// The matrix to make conjugate symmetric. - static public void ForceConjugateSymmetric(Matrix matrix) + static public void ForceConjugateSymmetric(Matrix matrix) { if (matrix.RowCount != matrix.ColumnCount) { @@ -85,7 +85,7 @@ namespace MathNet.Numerics.UnitTests /// from the lower triangle to the upper triangle. /// /// The matrix to make conjugate symmetric. - public static void ForceConjugateSymmetric(Matrix matrix) + public static void ForceConjugateSymmetric(Matrix matrix) { if (matrix.RowCount != matrix.ColumnCount) { diff --git a/src/UnitTests/LinearAlgebraTests/VectorArithmeticTheory.cs b/src/UnitTests/LinearAlgebraTests/VectorArithmeticTheory.cs index fbfc8b4b..23e97597 100644 --- a/src/UnitTests/LinearAlgebraTests/VectorArithmeticTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/VectorArithmeticTheory.cs @@ -28,6 +28,7 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System.Globalization; using MathNet.Numerics.LinearAlgebra; using NUnit.Framework; using System; @@ -92,8 +93,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests for (var i = 0; i < Math.Min(vector.Count, 20); i++) { - Assert.That(result1[i], Is.EqualTo(Minus(vector[i])), i.ToString()); - Assert.That(result2[i], Is.EqualTo(Minus(vector[i])), i.ToString()); + Assert.That(result1[i], Is.EqualTo(Minus(vector[i])), i.ToString(CultureInfo.InvariantCulture)); + Assert.That(result2[i], Is.EqualTo(Minus(vector[i])), i.ToString(CultureInfo.InvariantCulture)); } } @@ -123,9 +124,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests for (var i = 0; i < Math.Min(a.Count, 20); i++) { - Assert.That(result1[i], Is.EqualTo(Add(a[i], b[i])), i.ToString()); - Assert.That(result2[i], Is.EqualTo(Add(a[i], b[i])), i.ToString()); - Assert.That(result3[i], Is.EqualTo(Add(a[i], b[i])), i.ToString()); + Assert.That(result1[i], Is.EqualTo(Add(a[i], b[i])), i.ToString(CultureInfo.InvariantCulture)); + Assert.That(result2[i], Is.EqualTo(Add(a[i], b[i])), i.ToString(CultureInfo.InvariantCulture)); + Assert.That(result3[i], Is.EqualTo(Add(a[i], b[i])), i.ToString(CultureInfo.InvariantCulture)); } } @@ -147,8 +148,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests for (var i = 0; i < Math.Min(vector.Count, 20); i++) { - Assert.That(result1[i], Is.EqualTo(Add(vector[i], scalar)), i.ToString()); - Assert.That(result2[i], Is.EqualTo(Add(vector[i], scalar)), i.ToString()); + Assert.That(result1[i], Is.EqualTo(Add(vector[i], scalar)), i.ToString(CultureInfo.InvariantCulture)); + Assert.That(result2[i], Is.EqualTo(Add(vector[i], scalar)), i.ToString(CultureInfo.InvariantCulture)); } } @@ -178,9 +179,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests for (var i = 0; i < Math.Min(a.Count, 20); i++) { - Assert.That(result1[i], Is.EqualTo(Subtract(a[i], b[i])), i.ToString()); - Assert.That(result2[i], Is.EqualTo(Subtract(a[i], b[i])), i.ToString()); - Assert.That(result3[i], Is.EqualTo(Subtract(a[i], b[i])), i.ToString()); + Assert.That(result1[i], Is.EqualTo(Subtract(a[i], b[i])), i.ToString(CultureInfo.InvariantCulture)); + Assert.That(result2[i], Is.EqualTo(Subtract(a[i], b[i])), i.ToString(CultureInfo.InvariantCulture)); + Assert.That(result3[i], Is.EqualTo(Subtract(a[i], b[i])), i.ToString(CultureInfo.InvariantCulture)); } } @@ -202,8 +203,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests for (var i = 0; i < Math.Min(vector.Count, 20); i++) { - Assert.That(result1[i], Is.EqualTo(Subtract(vector[i], scalar)), i.ToString()); - Assert.That(result2[i], Is.EqualTo(Subtract(vector[i], scalar)), i.ToString()); + Assert.That(result1[i], Is.EqualTo(Subtract(vector[i], scalar)), i.ToString(CultureInfo.InvariantCulture)); + Assert.That(result2[i], Is.EqualTo(Subtract(vector[i], scalar)), i.ToString(CultureInfo.InvariantCulture)); } } } diff --git a/src/UnitTests/RootFindingTests/BisectionTest.cs b/src/UnitTests/RootFindingTests/BisectionTest.cs index b095729e..7a7edc97 100644 --- a/src/UnitTests/RootFindingTests/BisectionTest.cs +++ b/src/UnitTests/RootFindingTests/BisectionTest.cs @@ -96,8 +96,8 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests const double G21 = 0.30175355; double P2 = Math.Pow(10, 6.87776 - 1171.53 / (224.366 + T)); double P1 = Math.Pow(10, 8.04494 - 1554.3 / (222.65 + T)); - double t1 = x1 + x2 * G12; - double t2 = x2 + x1 * G21; + const double t1 = x1 + x2 * G12; + const double t2 = x2 + x1 * G21; double gamma2 = Math.Exp(-Math.Log(t2) - (x1 * (G12 * t2 - G21 * t1)) / (t1 * t2)); double gamma1 = Math.Exp(-Math.Log(t1) + (x2 * (G12 * t2 - G21 * t1)) / (t1 * t2)); double k1 = gamma1 * P1 / 760; @@ -462,7 +462,7 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests const double gam = -4.3 * CH4 - 11.049 * C2H6 - 3.545 * COtwo + 0.283 * H2O - 0.001 * N2 - 0.923 * O2; const double H0 = alp * 298 + bet * 0.001 * 298 * 298 / 2 + gam * 1e-6 * 298 * 298 * 298 / 3; double Hf = alp * T + bet * 0.001 * T * T / 2 + gam * 1e-6 * T * T * T / 3; - double xx = 1; + const double xx = 1; return 212798 * y * xx + 372820 * z * xx + H0 - Hf; }; diff --git a/src/UnitTests/RootFindingTests/BrentTest.cs b/src/UnitTests/RootFindingTests/BrentTest.cs index 5ac9a8ad..6824bd74 100644 --- a/src/UnitTests/RootFindingTests/BrentTest.cs +++ b/src/UnitTests/RootFindingTests/BrentTest.cs @@ -109,8 +109,8 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests const double G21 = 0.30175355; double P2 = Math.Pow(10, 6.87776 - 1171.53 / (224.366 + T)); double P1 = Math.Pow(10, 8.04494 - 1554.3 / (222.65 + T)); - double t1 = x1 + x2 * G12; - double t2 = x2 + x1 * G21; + const double t1 = x1 + x2 * G12; + const double t2 = x2 + x1 * G21; double gamma2 = Math.Exp(-Math.Log(t2) - (x1 * (G12 * t2 - G21 * t1)) / (t1 * t2)); double gamma1 = Math.Exp(-Math.Log(t1) + (x2 * (G12 * t2 - G21 * t1)) / (t1 * t2)); double k1 = gamma1 * P1 / 760; @@ -472,7 +472,7 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests const double gam = -4.3 * CH4 - 11.049 * C2H6 - 3.545 * COtwo + 0.283 * H2O - 0.001 * N2 - 0.923 * O2; const double H0 = alp * 298 + bet * 0.001 * 298 * 298 / 2 + gam * 1e-6 * 298 * 298 * 298 / 3; double Hf = alp * T + bet * 0.001 * T * T / 2 + gam * 1e-6 * T * T * T / 3; - double xx = 1; + const double xx = 1; return 212798 * y * xx + 372820 * z * xx + H0 - Hf; }; diff --git a/src/UnitTests/RootFindingTests/BroydenTest.cs b/src/UnitTests/RootFindingTests/BroydenTest.cs index c2c846e4..8d25cec3 100644 --- a/src/UnitTests/RootFindingTests/BroydenTest.cs +++ b/src/UnitTests/RootFindingTests/BroydenTest.cs @@ -97,8 +97,8 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests const double G21 = 0.30175355; double P2 = Math.Pow(10, 6.87776 - 1171.53 / (224.366 + T)); double P1 = Math.Pow(10, 8.04494 - 1554.3 / (222.65 + T)); - double t1 = x1 + x2 * G12; - double t2 = x2 + x1 * G21; + const double t1 = x1 + x2 * G12; + const double t2 = x2 + x1 * G21; double gamma2 = Math.Exp(-Math.Log(t2) - (x1 * (G12 * t2 - G21 * t1)) / (t1 * t2)); double gamma1 = Math.Exp(-Math.Log(t1) + (x2 * (G12 * t2 - G21 * t1)) / (t1 * t2)); double k1 = gamma1 * P1 / 760; @@ -463,7 +463,7 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests const double gam = -4.3 * CH4 - 11.049 * C2H6 - 3.545 * COtwo + 0.283 * H2O - 0.001 * N2 - 0.923 * O2; const double H0 = alp * 298 + bet * 0.001 * 298 * 298 / 2 + gam * 1e-6 * 298 * 298 * 298 / 3; double Hf = alp * T + bet * 0.001 * T * T / 2 + gam * 1e-6 * T * T * T / 3; - double xx = 1; + const double xx = 1; return 212798 * y * xx + 372820 * z * xx + H0 - Hf; }; diff --git a/src/UnitTests/RootFindingTests/CubicTest.cs b/src/UnitTests/RootFindingTests/CubicTest.cs index b0e66abf..5268b0d7 100644 --- a/src/UnitTests/RootFindingTests/CubicTest.cs +++ b/src/UnitTests/RootFindingTests/CubicTest.cs @@ -9,9 +9,9 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests [Test] public void RealRoots_SingleReal() { - var a0 = 1d; - var a1 = 5d; - var a2 = 2d; + const double a0 = 1d; + const double a1 = 5d; + const double a2 = 2d; var roots = Cubic.RealRoots(a0, a1, a2); var root = roots.Item1; var funcValue = root * (root * (root + a2) + a1) + a0; @@ -23,9 +23,9 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests [Test] public void RealRoots_DoubleReal1() { - var a0 = -2d; - var a1 = 5d; - var a2 = -4d; + const double a0 = -2d; + const double a1 = 5d; + const double a2 = -4d; var roots = Cubic.RealRoots(a0, a1, a2); Assert.That(roots.Item1, Is.EqualTo(2).Within(1e-14)); Assert.That(roots.Item2, Is.EqualTo(1).Within(1e-14)); @@ -35,9 +35,9 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests [Test] public void RealRoots_DoubleReal2() { - var a0 = -4d; - var a1 = 8d; - var a2 = -5d; + const double a0 = -4d; + const double a1 = 8d; + const double a2 = -5d; var roots = Cubic.RealRoots(a0, a1, a2); Assert.That(roots.Item1, Is.EqualTo(1).Within(1e-14)); Assert.That(roots.Item2, Is.EqualTo(2).Within(1e-14)); @@ -47,9 +47,9 @@ namespace MathNet.Numerics.UnitTests.RootFindingTests [Test] public void RealRoots_TripleReal() { - var a0 = 6d; - var a1 = -5d; - var a2 = -2d; + const double a0 = 6d; + const double a1 = -5d; + const double a2 = -2d; var roots = Cubic.RealRoots(a0, a1, a2); Assert.That(roots.Item1, Is.EqualTo(3).Within(1e-14)); Assert.That(roots.Item2, Is.EqualTo(-2).Within(1e-14)); diff --git a/src/UnitTests/StatisticsTests/MCMCTests/HybridMCTest.cs b/src/UnitTests/StatisticsTests/MCMCTests/HybridMCTest.cs index 304245f2..e4d84109 100644 --- a/src/UnitTests/StatisticsTests/MCMCTests/HybridMCTest.cs +++ b/src/UnitTests/StatisticsTests/MCMCTests/HybridMCTest.cs @@ -29,6 +29,7 @@ // using System; +using System.Globalization; using MathNet.Numerics.Distributions; using MathNet.Numerics.Statistics; using MathNet.Numerics.Statistics.Mcmc; @@ -151,7 +152,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests for (int i = 0; i < 2; i++) { - string index = i.ToString(); + string index = i.ToString(CultureInfo.InvariantCulture); Assert.AreEqual(mean[i], sampleMean[i], 10*convergence[i], index + "Mean"); Assert.AreEqual(sampleSdv[i]*sampleSdv[i], sdv[i]*sdv[i], 10*convergence[i], index + "Standard Deviation"); } diff --git a/src/UnitTests/StatisticsTests/MCMCTests/MCMCDiagnosticsTest.cs b/src/UnitTests/StatisticsTests/MCMCTests/MCMCDiagnosticsTest.cs index 69cf31f6..a2fab832 100644 --- a/src/UnitTests/StatisticsTests/MCMCTests/MCMCDiagnosticsTest.cs +++ b/src/UnitTests/StatisticsTests/MCMCTests/MCMCDiagnosticsTest.cs @@ -31,7 +31,7 @@ using System; using MathNet.Numerics.Distributions; using MathNet.Numerics.Statistics; -using MathNet.Numerics.Statistics.Mcmc.Diagnostics; +using MathNet.Numerics.Statistics.Mcmc; using NUnit.Framework; namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests diff --git a/src/UnitTests/StatisticsTests/MCMCTests/UnivariateHybridMCTest.cs b/src/UnitTests/StatisticsTests/MCMCTests/UnivariateHybridMCTest.cs index c142edfa..b49dfc6f 100644 --- a/src/UnitTests/StatisticsTests/MCMCTests/UnivariateHybridMCTest.cs +++ b/src/UnitTests/StatisticsTests/MCMCTests/UnivariateHybridMCTest.cs @@ -32,7 +32,6 @@ using System; 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 @@ -142,7 +141,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests //Approximating chi-square with normal distribution. (Degree of freedom is large) double deviationConvergence = 3*Constants.Sqrt2/Math.Sqrt(effective); - Assert.AreEqual(deviationRation, 1, deviationConvergence, "Standard Deivation"); + Assert.AreEqual(deviationRation, 1, deviationConvergence, "Standard Deviation"); } } } diff --git a/src/UnitTests/StatisticsTests/StatTestData.cs b/src/UnitTests/StatisticsTests/StatTestData.cs index 4a1d9434..eac3e898 100644 --- a/src/UnitTests/StatisticsTests/StatTestData.cs +++ b/src/UnitTests/StatisticsTests/StatTestData.cs @@ -28,6 +28,7 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; using System.Globalization; namespace MathNet.Numerics.UnitTests.StatisticsTests @@ -116,7 +117,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests /// Parameter value. static double GetValue(string str) { - var start = str.IndexOf(":"); + var start = str.IndexOf(":", StringComparison.Ordinal); var value = str.Substring(start + 1).Trim(); if (value.Equals("NaN")) {