Browse Source

Code Style & Inspections

pull/222/head
Christoph Ruegg 12 years ago
parent
commit
719f0dcad3
  1. 3
      MathNet.Numerics.sln.DotSettings
  2. 2
      src/Numerics/Distributions/Cauchy.cs
  3. 14
      src/Numerics/Distributions/Dirichlet.cs
  4. 58
      src/Numerics/Exceptions.cs
  5. 4
      src/Numerics/Generate.cs
  6. 6
      src/Numerics/Interpolate.cs
  7. 4
      src/Numerics/LinearAlgebra/Complex/DenseVector.cs
  8. 5
      src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
  9. 4
      src/Numerics/LinearAlgebra/Complex/Solvers/BiCgStab.cs
  10. 4
      src/Numerics/LinearAlgebra/Complex/Solvers/MILU0Preconditioner.cs
  11. 6
      src/Numerics/LinearAlgebra/Complex/Solvers/MlkBiCgStab.cs
  12. 4
      src/Numerics/LinearAlgebra/Complex32/DenseVector.cs
  13. 5
      src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
  14. 4
      src/Numerics/LinearAlgebra/Complex32/Solvers/BiCgStab.cs
  15. 4
      src/Numerics/LinearAlgebra/Complex32/Solvers/MILU0Preconditioner.cs
  16. 6
      src/Numerics/LinearAlgebra/Complex32/Solvers/MlkBiCgStab.cs
  17. 4
      src/Numerics/LinearAlgebra/Double/DenseVector.cs
  18. 5
      src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
  19. 6
      src/Numerics/LinearAlgebra/Double/Solvers/BiCgStab.cs
  20. 4
      src/Numerics/LinearAlgebra/Double/Solvers/MILU0Preconditioner.cs
  21. 6
      src/Numerics/LinearAlgebra/Double/Solvers/MlkBiCgStab.cs
  22. 4
      src/Numerics/LinearAlgebra/Single/DenseVector.cs
  23. 5
      src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
  24. 4
      src/Numerics/LinearAlgebra/Single/Solvers/BiCgStab.cs
  25. 4
      src/Numerics/LinearAlgebra/Single/Solvers/MILU0Preconditioner.cs
  26. 6
      src/Numerics/LinearAlgebra/Single/Solvers/MlkBiCgStab.cs
  27. 2
      src/Numerics/LinearAlgebra/Storage/DiagonalMatrixStorage.cs
  28. 6
      src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs
  29. 29
      src/Numerics/NonConvergenceException.cs
  30. 2
      src/Numerics/Numerics.csproj
  31. 37
      src/Numerics/Properties/Resources.Designer.cs
  32. 13
      src/Numerics/Properties/Resources.resx
  33. 2
      src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.cs
  34. 16
      src/Numerics/Providers/LinearAlgebra/Mkl/SafeNativeMethods.cs
  35. 13
      src/Numerics/Random/CryptoRandomSource.cs
  36. 2
      src/Numerics/Random/Palf.cs
  37. 8
      src/Numerics/Statistics/DescriptiveStatistics.cs
  38. 2
      src/Numerics/Statistics/Histogram.cs
  39. 5
      src/Numerics/Statistics/MCMC/MCMCDiagnostics.cs
  40. 2
      src/Numerics/Statistics/MCMC/MCMCSampler.cs
  41. 12
      src/UnitTests/DistributionTests/Continuous/BetaTests.cs
  42. 10
      src/UnitTests/DistributionTests/Continuous/CauchyTests.cs
  43. 6
      src/UnitTests/DistributionTests/Continuous/ChiSquareTests.cs
  44. 6
      src/UnitTests/DistributionTests/Continuous/ChiTests.cs
  45. 12
      src/UnitTests/DistributionTests/Continuous/ContinuousUniformTests.cs
  46. 14
      src/UnitTests/DistributionTests/Continuous/ErlangTests.cs
  47. 6
      src/UnitTests/DistributionTests/Continuous/ExponentialTests.cs
  48. 10
      src/UnitTests/DistributionTests/Continuous/FisherSnedecorTests.cs
  49. 16
      src/UnitTests/DistributionTests/Continuous/GammaTests.cs
  50. 10
      src/UnitTests/DistributionTests/Continuous/InverseGammaTests.cs
  51. 10
      src/UnitTests/DistributionTests/Continuous/LaplaceTests.cs
  52. 12
      src/UnitTests/DistributionTests/Continuous/LogNormalTests.cs
  53. 12
      src/UnitTests/DistributionTests/Continuous/NormalTests.cs
  54. 10
      src/UnitTests/DistributionTests/Continuous/ParetoTests.cs
  55. 6
      src/UnitTests/DistributionTests/Continuous/RayleighTests.cs
  56. 18
      src/UnitTests/DistributionTests/Continuous/StableTests.cs
  57. 16
      src/UnitTests/DistributionTests/Continuous/StudentTTests.cs
  58. 10
      src/UnitTests/DistributionTests/Continuous/TriangularTests.cs
  59. 12
      src/UnitTests/DistributionTests/Continuous/WeibullTests.cs
  60. 8
      src/UnitTests/DistributionTests/Discrete/BernoulliTests.cs
  61. 8
      src/UnitTests/DistributionTests/Discrete/BinomialTests.cs
  62. 42
      src/UnitTests/DistributionTests/Discrete/CategoricalTests.cs
  63. 10
      src/UnitTests/DistributionTests/Discrete/ConwayMaxwellPoissonTests.cs
  64. 12
      src/UnitTests/DistributionTests/Discrete/DiscreteUniformTests.cs
  65. 6
      src/UnitTests/DistributionTests/Discrete/GeometricTests.cs
  66. 26
      src/UnitTests/DistributionTests/Discrete/HypergeometricTests.cs
  67. 10
      src/UnitTests/DistributionTests/Discrete/NegativeBinomialTests.cs
  68. 6
      src/UnitTests/DistributionTests/Discrete/PoissonTests.cs
  69. 8
      src/UnitTests/DistributionTests/Discrete/ZipfTests.cs
  70. 4
      src/UnitTests/DistributionTests/Multivariate/DirichletTests.cs
  71. 12
      src/UnitTests/DistributionTests/Multivariate/InverseWishartTests.cs
  72. 16
      src/UnitTests/DistributionTests/Multivariate/MatrixNormalTests.cs
  73. 6
      src/UnitTests/DistributionTests/Multivariate/MultinomialTests.cs
  74. 4
      src/UnitTests/DistributionTests/Multivariate/NormalGammaTests.cs
  75. 12
      src/UnitTests/DistributionTests/Multivariate/WishartTests.cs
  76. 6
      src/UnitTests/FinancialTests/CompoundMonthlyReturnTests.cs
  77. 2
      src/UnitTests/FinancialTests/DownsideDeviationTests.cs
  78. 2
      src/UnitTests/FinancialTests/GainLossRatioTests.cs
  79. 5
      src/UnitTests/FinancialTests/GainMeanTests.cs
  80. 4
      src/UnitTests/FinancialTests/GainStandardDeviationTests.cs
  81. 2
      src/UnitTests/FinancialTests/LossMeanTests.cs
  82. 2
      src/UnitTests/FinancialTests/LossStandardDeviationTests.cs
  83. 2
      src/UnitTests/FinancialTests/SemiDeviationTests.cs
  84. 11
      src/UnitTests/GenericMath.cs
  85. 37
      src/UnitTests/GoodnessOfFit/RSquaredTest.cs
  86. 4
      src/UnitTests/LinearAlgebraProviderTests/Single/LinearAlgebraProviderTests.cs
  87. 1
      src/UnitTests/LinearAlgebraTests/Complex/Factorization/CholeskyTests.cs
  88. 28
      src/UnitTests/LinearAlgebraTests/Complex/Factorization/GramSchmidtTests.cs
  89. 1
      src/UnitTests/LinearAlgebraTests/Complex/Factorization/LUTests.cs
  90. 1
      src/UnitTests/LinearAlgebraTests/Complex/Factorization/QRTests.cs
  91. 1
      src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserCholeskyTests.cs
  92. 28
      src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserGramSchmidtTests.cs
  93. 1
      src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserLUTests.cs
  94. 1
      src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserQRTests.cs
  95. 4
      src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs
  96. 1
      src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/PreConditionerTest.cs
  97. 1
      src/UnitTests/LinearAlgebraTests/Complex32/Factorization/CholeskyTests.cs
  98. 19
      src/UnitTests/LinearAlgebraTests/Complex32/Factorization/GramSchmidtTests.cs
  99. 1
      src/UnitTests/LinearAlgebraTests/Complex32/Factorization/LUTests.cs
  100. 1
      src/UnitTests/LinearAlgebraTests/Complex32/Factorization/QRTests.cs

3
MathNet.Numerics.sln.DotSettings

@ -1,5 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/ExcludedFiles/FileMasksToSkip/=_002A_002Ecshtml/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ForCanBeConvertedToForeach/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LoopCanBeConvertedToQuery/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=Full_0020Cleanup_0020_0028Math_002ENET_0029/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="Full Cleanup (Math.NET)"&gt;&lt;CSArrangeThisQualifier&gt;True&lt;/CSArrangeThisQualifier&gt;&lt;CSRemoveCodeRedundancies&gt;True&lt;/CSRemoveCodeRedundancies&gt;&lt;CSUseAutoProperty&gt;True&lt;/CSUseAutoProperty&gt;&lt;CSMakeFieldReadonly&gt;True&lt;/CSMakeFieldReadonly&gt;&lt;CSUpdateFileHeader&gt;True&lt;/CSUpdateFileHeader&gt;&lt;CSOptimizeUsings&gt;&lt;OptimizeUsings&gt;True&lt;/OptimizeUsings&gt;&lt;EmbraceInRegion&gt;False&lt;/EmbraceInRegion&gt;&lt;RegionName&gt;&lt;/RegionName&gt;&lt;/CSOptimizeUsings&gt;&lt;CSShortenReferences&gt;True&lt;/CSShortenReferences&gt;&lt;CSReformatCode&gt;True&lt;/CSReformatCode&gt;&lt;XMLReformatCode&gt;True&lt;/XMLReformatCode&gt;&lt;CssAlphabetizeProperties&gt;True&lt;/CssAlphabetizeProperties&gt;&lt;CssReformatCode&gt;True&lt;/CssReformatCode&gt;&lt;JsReformatCode&gt;True&lt;/JsReformatCode&gt;&lt;JsInsertSemicolon&gt;True&lt;/JsInsertSemicolon&gt;&lt;VBFormatDocComments&gt;True&lt;/VBFormatDocComments&gt;&lt;VBReformatCode&gt;True&lt;/VBReformatCode&gt;&lt;VBShortenReferences&gt;True&lt;/VBShortenReferences&gt;&lt;VBOptimizeImports&gt;True&lt;/VBOptimizeImports&gt;&lt;HtmlReformatCode&gt;True&lt;/HtmlReformatCode&gt;&lt;AspOptimizeRegisterDirectives&gt;True&lt;/AspOptimizeRegisterDirectives&gt;&lt;CSReorderTypeMembers&gt;True&lt;/CSReorderTypeMembers&gt;&lt;CSUseVar&gt;&lt;BehavourStyle&gt;CAN_CHANGE_BOTH&lt;/BehavourStyle&gt;&lt;LocalVariableStyle&gt;IMPLICIT_WHEN_INITIALIZER_HAS_TYPE&lt;/LocalVariableStyle&gt;&lt;ForeachVariableStyle&gt;ALWAYS_EXPLICIT&lt;/ForeachVariableStyle&gt;&lt;/CSUseVar&gt;&lt;/Profile&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/RecentlyUsedProfile/@EntryValue">Full Cleanup (Math.NET)</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_LINQ_QUERY/@EntryValue">False</s:Boolean>
@ -65,6 +67,7 @@ OTHER DEALINGS IN THE SOFTWARE.&#xD;
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MKL/@EntryIndexedValue">MKL</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MSE/@EntryIndexedValue">MSE</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=PDF/@EntryIndexedValue">PDF</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=PMF/@EntryIndexedValue">PMF</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=QR/@EntryIndexedValue">QR</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SAD/@EntryIndexedValue">SAD</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SAS/@EntryIndexedValue">SAS</s:String>

2
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);
}
/// <summary>

14
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;

58
src/Numerics/Exceptions.cs

@ -0,0 +1,58 @@
using System;
using MathNet.Numerics.Properties;
namespace MathNet.Numerics
{
/// <summary>
/// An algorithm failed to converge.
/// </summary>
[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
}
/// <summary>
/// An algorithm failed to converge due to a numerical breakdown.
/// </summary>
[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
}
}

4
src/Numerics/Generate.cs

@ -223,7 +223,7 @@ namespace MathNet.Numerics
/// </summary>
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
/// </summary>
public static T[] LinearRangeMap<T>(double start, double step, double stop, Func<double, T> 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];

6
src/Numerics/Interpolate.cs

@ -50,7 +50,7 @@ namespace MathNet.Numerics
/// </returns>
public static IInterpolation Common(IEnumerable<double> points, IEnumerable<double> values)
{
return Interpolation.Barycentric.InterpolateRationalFloaterHormann(points, values);
return Barycentric.InterpolateRationalFloaterHormann(points, values);
}
/// <summary>
@ -65,7 +65,7 @@ namespace MathNet.Numerics
/// </returns>
public static IInterpolation RationalWithoutPoles(IEnumerable<double> points, IEnumerable<double> values)
{
return Interpolation.Barycentric.InterpolateRationalFloaterHormann(points, values);
return Barycentric.InterpolateRationalFloaterHormann(points, values);
}
/// <summary>
@ -99,7 +99,7 @@ namespace MathNet.Numerics
/// </remarks>
public static IInterpolation PolynomialEquidistant(IEnumerable<double> points, IEnumerable<double> values)
{
return Interpolation.Barycentric.InterpolatePolynomialEquidistant(points, values);
return Barycentric.InterpolatePolynomialEquidistant(points, values);
}
/// <summary>

4
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);

5
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<Complex> _storage;
/// <summary>
/// Gets the matrix's data.
/// </summary>
@ -75,8 +73,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
public DiagonalMatrix(DiagonalMatrixStorage<Complex> storage)
: base(storage)
{
_storage = storage;
_data = _storage.Data;
_data = storage.Data;
}
/// <summary>

4
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)

4
src/Numerics/LinearAlgebra/Complex/Solvers/MILU0Preconditioner.cs

@ -92,7 +92,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
var csr = matrix.Storage as SparseCompressedRowMatrixStorage<Complex>;
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;

6
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)

4
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);

5
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<Complex32> _storage;
/// <summary>
/// Gets the matrix's data.
/// </summary>
@ -70,8 +68,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
public DiagonalMatrix(DiagonalMatrixStorage<Complex32> storage)
: base(storage)
{
_storage = storage;
_data = _storage.Data;
_data = storage.Data;
}
/// <summary>

4
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)

4
src/Numerics/LinearAlgebra/Complex32/Solvers/MILU0Preconditioner.cs

@ -87,7 +87,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
var csr = matrix.Storage as SparseCompressedRowMatrixStorage<Complex32>;
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;

6
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)

4
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);

5
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<double> _storage;
/// <summary>
/// Gets the matrix's data.
/// </summary>
@ -69,8 +67,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
public DiagonalMatrix(DiagonalMatrixStorage<double> storage)
: base(storage)
{
_storage = storage;
_data = _storage.Data;
_data = storage.Data;
}
/// <summary>

6
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)

4
src/Numerics/LinearAlgebra/Double/Solvers/MILU0Preconditioner.cs

@ -85,7 +85,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
var csr = matrix.Storage as SparseCompressedRowMatrixStorage<double>;
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;

6
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)

4
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);

5
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<float> _storage;
/// <summary>
/// Gets the matrix's data.
/// </summary>
@ -69,8 +67,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
public DiagonalMatrix(DiagonalMatrixStorage<float> storage)
: base(storage)
{
_storage = storage;
_data = _storage.Data;
_data = storage.Data;
}
/// <summary>

4
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)

4
src/Numerics/LinearAlgebra/Single/Solvers/MILU0Preconditioner.cs

@ -85,7 +85,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
var csr = matrix.Storage as SparseCompressedRowMatrixStorage<float>;
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;

6
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)

2
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.");
}
}
}

6
src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs

@ -1799,11 +1799,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override void FoldColumnsUnchecked<TU>(VectorStorage<TU> target, Func<TU, T, TU> f, Func<TU, int, TU> finalize, VectorStorage<TU> state, Zeros zeros = Zeros.AllowSkip)
{
var denseResult = target as DenseVectorStorage<TU>;
if (denseResult == null)
{
denseResult = new DenseVectorStorage<TU>(ColumnCount);
}
var denseResult = target as DenseVectorStorage<TU> ?? new DenseVectorStorage<TU>(ColumnCount);
state.CopyTo(denseResult);
TU[] result = denseResult.Data;

29
src/Numerics/NonConvergenceException.cs

@ -1,29 +0,0 @@
using System;
using MathNet.Numerics.Properties;
namespace MathNet.Numerics
{
/// <summary>
/// An algorithm failed to converge.
/// </summary>
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
}
}

2
src/Numerics/Numerics.csproj

@ -191,7 +191,7 @@
<Compile Include="LinearAlgebra\Vector.Arithmetic.cs" />
<Compile Include="LinearAlgebra\Vector.BCL.cs" />
<Compile Include="LinearAlgebra\Vector.Operators.cs" />
<Compile Include="NonConvergenceException.cs" />
<Compile Include="Exceptions.cs" />
<Compile Include="Random\SystemRandomSource.cs" />
<Compile Include="Random\RandomSeed.cs" />
<Compile Include="RootFinding\Broyden.cs" />

37
src/Numerics/Properties/Resources.Designer.cs

@ -654,6 +654,24 @@ namespace MathNet.Numerics.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Lag must be positive.
/// </summary>
public static string LagMustBePositive {
get {
return ResourceManager.GetString("LagMustBePositive", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Lag must be smaller than the sample size.
/// </summary>
public static string LagMustBeSmallerThanTheSampleSize {
get {
return ResourceManager.GetString("LagMustBeSmallerThanTheSampleSize", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to ddd MMM dd HH:mm:ss yyyy.
/// </summary>
@ -672,6 +690,15 @@ namespace MathNet.Numerics.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Matrix must be in sparse storage format.
/// </summary>
public static string MatrixMustBeSparse {
get {
return ResourceManager.GetString("MatrixMustBeSparse", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The number of rows of a matrix must be positive..
/// </summary>
@ -726,6 +753,16 @@ namespace MathNet.Numerics.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Algorithm experience a numerical break down
///.
/// </summary>
public static string NumericalBreakdown {
get {
return ResourceManager.GetString("NumericalBreakdown", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The two arguments can&apos;t be compared (maybe they are part of a partial ordering?).
/// </summary>

13
src/Numerics/Properties/Resources.resx

@ -390,4 +390,17 @@
<data name="RootFindingFailedRecommendRobustNewtonRaphson" xml:space="preserve">
<value>The algorithm has failed, exceeded the number of iterations allowed or there is no root within the provided bounds. Consider to use RobustNewtonRaphson instead.</value>
</data>
<data name="NumericalBreakdown" xml:space="preserve">
<value>Algorithm experience a numerical break down
</value>
</data>
<data name="LagMustBePositive" xml:space="preserve">
<value>Lag must be positive</value>
</data>
<data name="LagMustBeSmallerThanTheSampleSize" xml:space="preserve">
<value>Lag must be smaller than the sample size</value>
</data>
<data name="MatrixMustBeSparse" xml:space="preserve">
<value>Matrix must be in sparse storage format</value>
</data>
</root>

2
src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.cs

@ -36,7 +36,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
public partial class ManagedLinearAlgebraProvider : ILinearAlgebraProvider
{
/// <summary>
/// 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
/// </summary>
public virtual void InitializeVerify()
{

16
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

13
src/Numerics/Random/CryptoRandomSource.cs

@ -40,7 +40,7 @@ namespace MathNet.Numerics.Random
/// <summary>
/// A random number generator based on the <see cref="System.Security.Cryptography.RandomNumberGenerator"/> class in the .NET library.
/// </summary>
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
/// <remarks>Supports being called in parallel from multiple threads.</remarks>
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;

2
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)

8
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)
{

2
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)

5
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);

2
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;
}

12
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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>
@ -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());
}
/// <summary>
@ -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());
}
/// <summary>

10
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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>
@ -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());
}
/// <summary>

6
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
};
});
}
/// <summary>
@ -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());
}
/// <summary>

6
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
};
});
}
/// <summary>
@ -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());
}
/// <summary>

12
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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>
@ -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());
}
/// <summary>
@ -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());
}
/// <summary>

14
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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>
@ -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());
}
/// <summary>

6
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
};
});
}
/// <summary>
@ -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());
}
/// <summary>

10
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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>
@ -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)]

16
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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>
@ -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());
}
/// <summary>
@ -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());
}
/// <summary>

10
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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>
@ -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());
}
/// <summary>

10
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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>
@ -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());
}
/// <summary>

12
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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>
@ -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());
}
/// <summary>
@ -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());
}
/// <summary>

12
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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>
@ -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());
}
/// <summary>
@ -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());
}
/// <summary>

10
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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>
@ -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());
}
}
}

6
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
};
});
}
/// <summary>
@ -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());
}
}
}

18
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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>
@ -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());
}
/// <summary>

16
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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>
@ -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());
}
/// <summary>
@ -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)]

10
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
};
});
}
/// <summary>
@ -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());
}
/// <summary>
@ -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:

12
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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>
@ -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());
}
/// <summary>
@ -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());
}
/// <summary>

8
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
};
});
}
/// <summary>
@ -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());
}
/// <summary>
@ -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());
}
/// <summary>

8
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
};
});
}
/// <summary>
@ -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());
}
/// <summary>
@ -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());
}
}
}

42
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));
}
/// <summary>
@ -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<ArgumentNullException>());
// ReSharper restore ExpressionIsAlwaysNull
}
/// <summary>
@ -143,10 +145,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[Test]
public void CanSetProbability()
{
new Categorical(_largeP)
GC.KeepAlive(new Categorical(_largeP)
{
P = _smallP
};
});
}
/// <summary>
@ -164,10 +166,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// </summary>
/// <param name="p">An array of nonnegative ratios.</param>
/// <param name="mean">Expected value.</param>
[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
/// </summary>
/// <param name="p">An array of nonnegative ratios.</param>
/// <param name="stdDev">Standard deviation.</param>
[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
/// </summary>
/// <param name="p">An array of nonnegative ratios.</param>
/// <param name="variance">Variance.</param>
[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
/// </summary>
/// <param name="p">An array of nonnegative ratios.</param>
/// <param name="median">Median.</param>
[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 }, ???)]

10
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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>
@ -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());
}
/// <summary>

12
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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>
@ -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());
}
/// <summary>
@ -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());
}
/// <summary>

6
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
};
});
}
/// <summary>
@ -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());
}
/// <summary>

26
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
});
}
/// <summary>
@ -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
});
}
/// <summary>
@ -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
});
}
/// <summary>
@ -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());
}
/// <summary>

10
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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>
@ -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());
}
}
}

6
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
};
});
}
/// <summary>
@ -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());
}
/// <summary>

8
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
};
});
}
/// <summary>
@ -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
};
});
}
/// <summary>

4
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]

12
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<double>.Build.RandomPositiveDefinite(2, 1))
GC.KeepAlive(new InverseWishart(1.0, Matrix<double>.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<double>.Build.RandomPositiveDefinite(2, 1))
GC.KeepAlive(new InverseWishart(1.0, Matrix<double>.Build.RandomPositiveDefinite(2, 1))
{
DegreesOfFreedom = nu
};
});
}
/// <summary>
@ -192,10 +192,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
[Test]
public void CanSetS()
{
new InverseWishart(1.0, Matrix<double>.Build.RandomPositiveDefinite(2, 1))
GC.KeepAlive(new InverseWishart(1.0, Matrix<double>.Build.RandomPositiveDefinite(2, 1))
{
Scale = Matrix<double>.Build.RandomPositiveDefinite(2, 1)
};
});
}
/// <summary>

16
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<double>.Build.Random(N, P, 1), Matrix<double>.Build.RandomPositiveDefinite(N, 1), Matrix<double>.Build.RandomPositiveDefinite(P, 1))
GC.KeepAlive(new MatrixNormal(Matrix<double>.Build.Random(N, P, 1), Matrix<double>.Build.RandomPositiveDefinite(N, 1), Matrix<double>.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<double>.Build.Random(n, p, 1), Matrix<double>.Build.RandomPositiveDefinite(n, 1), Matrix<double>.Build.RandomPositiveDefinite(p, 1))
GC.KeepAlive(new MatrixNormal(Matrix<double>.Build.Random(n, p, 1), Matrix<double>.Build.RandomPositiveDefinite(n, 1), Matrix<double>.Build.RandomPositiveDefinite(p, 1))
{
Mean = Matrix<double>.Build.Random(n, p, 1)
};
});
}
/// <summary>
@ -220,10 +220,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
[TestCase(10, 10)]
public void CanSetV(int n, int p)
{
new MatrixNormal(Matrix<double>.Build.Random(n, p, 1), Matrix<double>.Build.RandomPositiveDefinite(n, 1), Matrix<double>.Build.RandomPositiveDefinite(p, 1))
GC.KeepAlive(new MatrixNormal(Matrix<double>.Build.Random(n, p, 1), Matrix<double>.Build.RandomPositiveDefinite(n, 1), Matrix<double>.Build.RandomPositiveDefinite(p, 1))
{
RowCovariance = Matrix<double>.Build.RandomPositiveDefinite(n, 1)
};
});
}
/// <summary>
@ -257,10 +257,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
[TestCase(10, 10)]
public void CanSetK(int n, int p)
{
new MatrixNormal(Matrix<double>.Build.Random(n, p, 1), Matrix<double>.Build.RandomPositiveDefinite(n, 1), Matrix<double>.Build.RandomPositiveDefinite(p, 1))
GC.KeepAlive(new MatrixNormal(Matrix<double>.Build.Random(n, p, 1), Matrix<double>.Build.RandomPositiveDefinite(n, 1), Matrix<double>.Build.RandomPositiveDefinite(p, 1))
{
ColumnCovariance = Matrix<double>.Build.RandomPositiveDefinite(p, 1)
};
});
}
/// <summary>

6
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<ArgumentNullException>());
// ReSharper restore ExpressionIsAlwaysNull
}
/// <summary>
@ -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
};
});
}
/// <summary>

4
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)
};
});
}
/// <summary>

12
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<double>.Build.RandomPositiveDefinite(2, 1))
GC.KeepAlive(new Wishart(1.0, Matrix<double>.Build.RandomPositiveDefinite(2, 1))
{
RandomSource = new System.Random(0)
};
});
}
/// <summary>
@ -155,10 +155,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
[TestCase(5.0)]
public void CanSetNu(double nu)
{
new Wishart(1.0, Matrix<double>.Build.RandomPositiveDefinite(2, 1))
GC.KeepAlive(new Wishart(1.0, Matrix<double>.Build.RandomPositiveDefinite(2, 1))
{
DegreesOfFreedom = nu
};
});
}
/// <summary>
@ -186,10 +186,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
[Test]
public void CanSetS()
{
new Wishart(1.0, Matrix<double>.Build.RandomPositiveDefinite(2, 1))
GC.KeepAlive(new Wishart(1.0, Matrix<double>.Build.RandomPositiveDefinite(2, 1))
{
Scale = Matrix<double>.Build.RandomPositiveDefinite(2, 1)
};
});
}
/// <summary>

6
src/UnitTests/FinancialTests/CompoundMonthlyReturnTests.cs

@ -45,14 +45,16 @@ namespace MathNet.Numerics.UnitTests.FinancialTests
//arrange
List<double> inputData = null;
//act
// ReSharper disable ExpressionIsAlwaysNull
inputData.CompoundMonthlyReturn();
// ReSharper restore ExpressionIsAlwaysNull
}
[Test]
public void returns_undefined_with_empty_input_data()
{
//arrange
List<double> inputData = new List<double>();
var inputData = new List<double>();
//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.
}
}

2
src/UnitTests/FinancialTests/DownsideDeviationTests.cs

@ -110,7 +110,9 @@ namespace MathNet.Numerics.UnitTests.FinancialTests
const double minimumAcceptableReturn = 0.05;
List<double> inputData = null;
//act
// ReSharper disable ExpressionIsAlwaysNull
inputData.DownsideDeviation(minimumAcceptableReturn);
// ReSharper restore ExpressionIsAlwaysNull
}
}

2
src/UnitTests/FinancialTests/GainLossRatioTests.cs

@ -47,7 +47,9 @@ namespace MathNet.Numerics.UnitTests.FinancialTests
//arrange
List<double> inputData = null;
//act
// ReSharper disable ExpressionIsAlwaysNull
inputData.GainLossRatio();
// ReSharper restore ExpressionIsAlwaysNull
}
[Test]

5
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]

4
src/UnitTests/FinancialTests/GainStandardDeviationTests.cs

@ -115,9 +115,9 @@ namespace MathNet.Numerics.UnitTests.FinancialTests
//arrange
List<double> inputData = null;
//act
// ReSharper disable ExpressionIsAlwaysNull
inputData.GainStandardDeviation();
// ReSharper restore ExpressionIsAlwaysNull
}
public double gainStdDev { get; set; }
}
}

2
src/UnitTests/FinancialTests/LossMeanTests.cs

@ -92,7 +92,9 @@ namespace MathNet.Numerics.UnitTests.FinancialTests
//arrange
List<double> inputData = null;
//act
// ReSharper disable ExpressionIsAlwaysNull
inputData.LossMean();
// ReSharper restore ExpressionIsAlwaysNull
}
[Test]

2
src/UnitTests/FinancialTests/LossStandardDeviationTests.cs

@ -115,7 +115,9 @@ namespace MathNet.Numerics.UnitTests.FinancialTests
//arrange
List<double> inputData = null;
//act
// ReSharper disable ExpressionIsAlwaysNull
inputData.LossStandardDeviation();
// ReSharper restore ExpressionIsAlwaysNull
}
}
}

2
src/UnitTests/FinancialTests/SemiDeviationTests.cs

@ -106,7 +106,9 @@ namespace MathNet.Numerics.UnitTests.FinancialTests
//arrange
List<double> inputData = null;
//act
// ReSharper disable ExpressionIsAlwaysNull
inputData.SemiDeviation();
// ReSharper restore ExpressionIsAlwaysNull
}
}
}

11
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<Func<TArg1, TArg2, TResult>>(
body(castLhs, castRhs), lhs, rhs).Compile();
}
else throw;
throw;
}
}
catch (Exception ex)

37
src/UnitTests/GoodnessOfFit/RSquaredTest.cs

@ -15,35 +15,19 @@ namespace MathNet.Numerics.UnitTests.GoodnessOfFit
{
var data = new List<double>();
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<double>()
{
23
,9
,5
,7
,10
,5
,4
,1
,2
,1
};
var modelledData = new List<double>()
{
8
,9
,10
};
var observedData = new List<double> { 23, 9, 5, 7, 10, 5, 4, 1, 2, 1 };
var modelledData = new List<double> { 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<double>()
{
1, 2.3, 3.1, 4.8, 5.6, 6.3
};
var modelledData = new List<double>()
{
2.6, 2.8, 3.1, 4.7, 5.1, 5.3
};
var observedData = new List<double> { 1, 2.3, 3.1, 4.8, 5.6, 6.3 };
var modelledData = new List<double> { 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)));
}

4
src/UnitTests/LinearAlgebraProviderTests/Single/LinearAlgebraProviderTests.cs

@ -48,12 +48,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Single
/// <summary>
/// The Y float test vector.
/// </summary>
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};
/// <summary>
/// The X float test vector.
/// </summary>
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();

1
src/UnitTests/LinearAlgebraTests/Complex/Factorization/CholeskyTests.cs

@ -24,7 +24,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Complex;
using NUnit.Framework;

28
src/UnitTests/LinearAlgebraTests/Complex/Factorization/GramSchmidtTests.cs

@ -24,7 +24,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
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);
}
}
}

1
src/UnitTests/LinearAlgebraTests/Complex/Factorization/LUTests.cs

@ -24,7 +24,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Complex;
using NUnit.Framework;

1
src/UnitTests/LinearAlgebraTests/Complex/Factorization/QRTests.cs

@ -24,7 +24,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Complex;
using MathNet.Numerics.LinearAlgebra.Complex.Factorization;

1
src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserCholeskyTests.cs

@ -24,7 +24,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using MathNet.Numerics.LinearAlgebra;
using NUnit.Framework;

28
src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserGramSchmidtTests.cs

@ -24,7 +24,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
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);
}
}
}

1
src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserLUTests.cs

@ -24,7 +24,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using MathNet.Numerics.LinearAlgebra;
using NUnit.Framework;

1
src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserQRTests.cs

@ -24,7 +24,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Complex.Factorization;
using MathNet.Numerics.LinearAlgebra.Factorization;

4
src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs

@ -43,7 +43,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
public class MatrixStructureTheory : MatrixStructureTheory<Complex>
{
[Datapoints]
Matrix<Complex>[] _matrices = new Matrix<Complex>[]
Matrix<Complex>[] _matrices =
{
Matrix<Complex>.Build.DenseOfArray(new[,] { { 1d, new Complex(1.1d, -4d), 2d }, { 1d, 1d, 2d }, { 1d, new Complex(1d, 2d), 2d } }),
Matrix<Complex>.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 };
}
}

1
src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/PreConditionerTest.cs

@ -28,7 +28,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Complex;
using MathNet.Numerics.LinearAlgebra.Solvers;

1
src/UnitTests/LinearAlgebraTests/Complex32/Factorization/CholeskyTests.cs

@ -24,7 +24,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Complex32;
using NUnit.Framework;

19
src/UnitTests/LinearAlgebraTests/Complex32/Factorization/GramSchmidtTests.cs

@ -24,7 +24,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
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]);
}
}
}

1
src/UnitTests/LinearAlgebraTests/Complex32/Factorization/LUTests.cs

@ -24,7 +24,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Complex32;
using NUnit.Framework;

1
src/UnitTests/LinearAlgebraTests/Complex32/Factorization/QRTests.cs

@ -24,7 +24,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Complex32;
using MathNet.Numerics.LinearAlgebra.Complex32.Factorization;

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save