diff --git a/src/Numerics.Tests/StatisticsTests/MCMCTests/MetropolisHastingsSamplerTests.cs b/src/Numerics.Tests/StatisticsTests/MCMCTests/MetropolisHastingsSamplerTests.cs
index ac8ee947..7eb03b00 100644
--- a/src/Numerics.Tests/StatisticsTests/MCMCTests/MetropolisHastingsSamplerTests.cs
+++ b/src/Numerics.Tests/StatisticsTests/MCMCTests/MetropolisHastingsSamplerTests.cs
@@ -93,17 +93,5 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests
ms.Sample(5);
}
-
- ///
- /// Set null RNG throws ArgumentNullException.
- ///
- [Test]
- public void NullRandomNumberGenerator()
- {
- var random = MersenneTwister.Default;
- var normal = new Normal(0.0, 1.0, random);
- var ms = new MetropolisHastingsSampler(0.2, normal.Density, (x, y) => Normal.PDF(x, 0.1, y), x => Normal.Sample(random, x, 0.1), 10);
- Assert.That(() => ms.RandomSource = null, Throws.TypeOf());
- }
}
}
diff --git a/src/Numerics.Tests/StatisticsTests/MCMCTests/MetropolisSamplerTests.cs b/src/Numerics.Tests/StatisticsTests/MCMCTests/MetropolisSamplerTests.cs
index 709c6a93..3b5607d2 100644
--- a/src/Numerics.Tests/StatisticsTests/MCMCTests/MetropolisSamplerTests.cs
+++ b/src/Numerics.Tests/StatisticsTests/MCMCTests/MetropolisSamplerTests.cs
@@ -92,16 +92,5 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests
ms.Sample(5);
}
-
- ///
- /// Set null RNG throws ArgumentNullException.
- ///
- [Test]
- public void NullRandomNumberGenerator()
- {
- var normal = new Normal(0.0, 1.0);
- var ms = new MetropolisSampler(0.2, normal.Density, x => Normal.Sample(new Random(0), x, 0.1), 10);
- Assert.That(() => ms.RandomSource = null, Throws.TypeOf());
- }
}
}
diff --git a/src/Numerics.Tests/StatisticsTests/MCMCTests/RejectionSamplerTests.cs b/src/Numerics.Tests/StatisticsTests/MCMCTests/RejectionSamplerTests.cs
index c2ac07eb..8e772eb7 100644
--- a/src/Numerics.Tests/StatisticsTests/MCMCTests/RejectionSamplerTests.cs
+++ b/src/Numerics.Tests/StatisticsTests/MCMCTests/RejectionSamplerTests.cs
@@ -97,16 +97,5 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests
var rs = new RejectionSampler(x => Math.Pow(x, 1.7)*Math.Pow(1.0 - x, 5.3), x => Double.NegativeInfinity, uniform.Sample);
Assert.That(() => rs.Sample(), Throws.ArgumentException);
}
-
- ///
- /// Set null RNG throws ArgumentNullException.
- ///
- [Test]
- public void NullRandomNumberGenerator()
- {
- var uniform = new ContinuousUniform(0.0, 1.0, new SystemRandomSource(1));
- var rs = new RejectionSampler(x => Math.Pow(x, 1.7)*Math.Pow(1.0 - x, 5.3), x => Double.NegativeInfinity, uniform.Sample);
- Assert.That(() => rs.RandomSource = null, Throws.TypeOf());
- }
}
}
diff --git a/src/Numerics/Compatibility.cs b/src/Numerics/Compatibility.cs
index 3cb5fd38..7c638e37 100644
--- a/src/Numerics/Compatibility.cs
+++ b/src/Numerics/Compatibility.cs
@@ -1,4 +1,6 @@
-#if NETSTANDARD1_3
+using System.Globalization;
+
+#if NETSTANDARD1_3
namespace MathNet.Numerics
{
using System;
@@ -156,3 +158,46 @@ namespace MathNet.Numerics
}
}
#endif
+
+#if NET40
+namespace System.Runtime.CompilerServices
+{
+ internal class FormattableStringFactory
+ {
+ public static FormattableString Create(string format, params object[] args)
+ {
+ return new FormattableString(format, args);
+ }
+ }
+}
+
+namespace System
+{
+ internal class FormattableString
+ {
+ private readonly string format;
+ private readonly object[] args;
+
+ public FormattableString(string format, object[] args)
+ {
+ this.format = format;
+ this.args = args;
+ }
+
+ public static string Invariant(FormattableString messageFormat)
+ {
+ return messageFormat.ToString(CultureInfo.InvariantCulture);
+ }
+
+ public string ToString(IFormatProvider formatProvider)
+ {
+ return string.Format(formatProvider, format, args);
+ }
+
+ public override string ToString()
+ {
+ return string.Format(format, args);
+ }
+ }
+}
+#endif
diff --git a/src/Numerics/Complex32.cs b/src/Numerics/Complex32.cs
index d2f8894f..29b41aec 100644
--- a/src/Numerics/Complex32.cs
+++ b/src/Numerics/Complex32.cs
@@ -145,7 +145,7 @@ namespace MathNet.Numerics
public float Real
{
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get { return _real; }
+ get => _real;
}
///
@@ -155,7 +155,7 @@ namespace MathNet.Numerics
public float Imaginary
{
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get { return _imag; }
+ get => _imag;
}
///
@@ -171,7 +171,7 @@ namespace MathNet.Numerics
{
// NOTE: the special case for negative real numbers fixes negative-zero value behavior. Do not remove.
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get { return _imag == 0f && _real < 0f ? (float)Constants.Pi : (float)Math.Atan2(_imag, _real); }
+ get => _imag == 0f && _real < 0f ? (float)Constants.Pi : (float)Math.Atan2(_imag, _real);
}
///
@@ -212,10 +212,7 @@ namespace MathNet.Numerics
/// Gets the squared magnitude (or squared absolute value) of a complex number.
///
/// The squared magnitude of the current instance.
- public float MagnitudeSquared
- {
- get { return (_real * _real) + (_imag * _imag); }
- }
+ public float MagnitudeSquared => _real * _real + _imag * _imag;
///
/// Gets the unity of this complex (same argument, but on the unit circle; exp(I*arg))
diff --git a/src/Numerics/Differentiation/FiniteDifferenceCoefficients.cs b/src/Numerics/Differentiation/FiniteDifferenceCoefficients.cs
index c2889c9d..53ae178d 100644
--- a/src/Numerics/Differentiation/FiniteDifferenceCoefficients.cs
+++ b/src/Numerics/Differentiation/FiniteDifferenceCoefficients.cs
@@ -49,7 +49,7 @@ namespace MathNet.Numerics.Differentiation
///
public int Points
{
- get { return _points; }
+ get => _points;
set
{
CalculateCoefficients(value);
diff --git a/src/Numerics/Differentiation/NumericalDerivative.cs b/src/Numerics/Differentiation/NumericalDerivative.cs
index 8745570a..b3a4d6c3 100644
--- a/src/Numerics/Differentiation/NumericalDerivative.cs
+++ b/src/Numerics/Differentiation/NumericalDerivative.cs
@@ -72,7 +72,6 @@ namespace MathNet.Numerics.Differentiation
double _stepSize = Math.Pow(2, -10);
double _epsilon = Precision.PositiveMachineEpsilon;
double _baseStepSize = Math.Pow(2, -26);
- StepType _stepType = StepType.Relative;
readonly FiniteDifferenceCoefficients _coefficients;
///
@@ -110,7 +109,7 @@ namespace MathNet.Numerics.Differentiation
///
public double StepSize
{
- get { return _stepSize; }
+ get => _stepSize;
set
{
//Base 2 yields more accurate results...
@@ -125,7 +124,7 @@ namespace MathNet.Numerics.Differentiation
///
public double BaseStepSize
{
- get { return _baseStepSize; }
+ get => _baseStepSize;
set
{
//Base 2 yields more accurate results...
@@ -140,7 +139,7 @@ namespace MathNet.Numerics.Differentiation
///
public double Epsilon
{
- get { return _epsilon; }
+ get => _epsilon;
set
{
//Base 2 yields more accurate results...
@@ -154,7 +153,7 @@ namespace MathNet.Numerics.Differentiation
///
public int Center
{
- get { return _center; }
+ get => _center;
set
{
if (value >= _points || value < 0)
@@ -173,11 +172,7 @@ namespace MathNet.Numerics.Differentiation
/// If set to relative, dx = (1+abs(x))*h^(2/(order+1)). This provides accurate results when
/// h is approximately equal to the square-root of machine accuracy, epsilon.
///
- public StepType StepType
- {
- get { return _stepType; }
- set { _stepType = value; }
- }
+ public StepType StepType { get; set; } = StepType.Relative;
///
/// Evaluates the derivative of equidistant points using the finite difference method.
diff --git a/src/Numerics/Differentiation/NumericalHessian.cs b/src/Numerics/Differentiation/NumericalHessian.cs
index 7b7f0f82..073d03d6 100644
--- a/src/Numerics/Differentiation/NumericalHessian.cs
+++ b/src/Numerics/Differentiation/NumericalHessian.cs
@@ -40,10 +40,7 @@ namespace MathNet.Numerics.Differentiation
///
/// Number of function evaluations.
///
- public int FunctionEvaluations
- {
- get { return _df.Evaluations; }
- }
+ public int FunctionEvaluations => _df.Evaluations;
private readonly NumericalDerivative _df;
diff --git a/src/Numerics/Differentiation/NumericalJacobian.cs b/src/Numerics/Differentiation/NumericalJacobian.cs
index a8327656..6d3b271c 100644
--- a/src/Numerics/Differentiation/NumericalJacobian.cs
+++ b/src/Numerics/Differentiation/NumericalJacobian.cs
@@ -40,10 +40,7 @@ namespace MathNet.Numerics.Differentiation
///
/// Number of function evaluations.
///
- public int FunctionEvaluations
- {
- get { return _df.Evaluations; }
- }
+ public int FunctionEvaluations => _df.Evaluations;
private readonly NumericalDerivative _df;
diff --git a/src/Numerics/Distributions/SkewedGeneralizedError.cs b/src/Numerics/Distributions/SkewedGeneralizedError.cs
index 700fd10f..05683941 100644
--- a/src/Numerics/Distributions/SkewedGeneralizedError.cs
+++ b/src/Numerics/Distributions/SkewedGeneralizedError.cs
@@ -102,8 +102,8 @@ namespace MathNet.Numerics.Distributions
///
public System.Random RandomSource
{
- get { return _random; }
- set { _random = value ?? SystemRandomSource.Default; }
+ get => _random;
+ set => _random = value ?? SystemRandomSource.Default;
}
///
diff --git a/src/Numerics/Integration/GaussKronrodRule.cs b/src/Numerics/Integration/GaussKronrodRule.cs
index 467dc076..e5394d3a 100644
--- a/src/Numerics/Integration/GaussKronrodRule.cs
+++ b/src/Numerics/Integration/GaussKronrodRule.cs
@@ -48,46 +48,22 @@ namespace MathNet.Numerics.Integration
///
/// Getter for the order.
///
- public int Order
- {
- get
- {
- return gaussKronrodPoint.Order;
- }
- }
+ public int Order => gaussKronrodPoint.Order;
///
/// Getter that returns a clone of the array containing the Kronrod abscissas.
///
- public double[] KronrodAbscissas
- {
- get
- {
- return gaussKronrodPoint.Abscissas.Clone() as double[];
- }
- }
+ public double[] KronrodAbscissas => gaussKronrodPoint.Abscissas.Clone() as double[];
///
/// Getter that returns a clone of the array containing the Kronrod weights.
///
- public double[] KronrodWeights
- {
- get
- {
- return gaussKronrodPoint.Weights.Clone() as double[];
- }
- }
+ public double[] KronrodWeights => gaussKronrodPoint.Weights.Clone() as double[];
///
/// Getter that returns a clone of the array containing the Gauss weights.
///
- public double[] GaussWeights
- {
- get
- {
- return gaussKronrodPoint.SecondWeights.Clone() as double[];
- }
- }
+ public double[] GaussWeights => gaussKronrodPoint.SecondWeights.Clone() as double[];
public GaussKronrodRule(int order)
{
@@ -107,7 +83,7 @@ namespace MathNet.Numerics.Integration
/// The number of Gauss-Kronrod points. Pre-computed for 15, 21, 31, 41, 51 and 61 points
public static double Integrate(Func f, double intervalBegin, double intervalEnd, out double error, out double L1Norm, double targetRelativeError = 1E-10, int maximumDepth = 15, int order = 15)
{
- // Formula used for variable subsitution from
+ // Formula used for variable subsitution from
// 1. Shampine, L. F. (2008). Vectorized adaptive quadrature in MATLAB. Journal of Computational and Applied Mathematics, 211(2), 131-140.
// 2. quadgk.m, GNU Octave
@@ -193,7 +169,7 @@ namespace MathNet.Numerics.Integration
///
public static Complex ContourIntegrate(Func f, double intervalBegin, double intervalEnd, out double error, out double L1Norm, double targetRelativeError = 1E-10, int maximumDepth = 15, int order = 15)
{
- // Formula used for variable subsitution from
+ // Formula used for variable subsitution from
// 1. Shampine, L. F. (2008). Vectorized adaptive quadrature in MATLAB. Journal of Computational and Applied Mathematics, 211(2), 131-140.
// 2. quadgk.m, GNU Octave
diff --git a/src/Numerics/Integration/GaussLegendreRule.cs b/src/Numerics/Integration/GaussLegendreRule.cs
index fab03a4e..cf723424 100644
--- a/src/Numerics/Integration/GaussLegendreRule.cs
+++ b/src/Numerics/Integration/GaussLegendreRule.cs
@@ -64,13 +64,7 @@ namespace MathNet.Numerics.Integration
///
/// Getter that returns a clone of the array containing the abscissas.
///
- public double[] Abscissas
- {
- get
- {
- return _gaussLegendrePoint.Abscissas.Clone() as double[];
- }
- }
+ public double[] Abscissas => _gaussLegendrePoint.Abscissas.Clone() as double[];
///
/// Getter for the ith weight.
@@ -85,46 +79,22 @@ namespace MathNet.Numerics.Integration
///
/// Getter that returns a clone of the array containing the weights.
///
- public double[] Weights
- {
- get
- {
- return _gaussLegendrePoint.Weights.Clone() as double[];
- }
- }
+ public double[] Weights => _gaussLegendrePoint.Weights.Clone() as double[];
///
/// Getter for the order.
///
- public int Order
- {
- get
- {
- return _gaussLegendrePoint.Order;
- }
- }
+ public int Order => _gaussLegendrePoint.Order;
///
/// Getter for the InvervalBegin.
///
- public double IntervalBegin
- {
- get
- {
- return _gaussLegendrePoint.IntervalBegin;
- }
- }
+ public double IntervalBegin => _gaussLegendrePoint.IntervalBegin;
///
/// Getter for the InvervalEnd.
///
- public double IntervalEnd
- {
- get
- {
- return _gaussLegendrePoint.IntervalEnd;
- }
- }
+ public double IntervalEnd => _gaussLegendrePoint.IntervalEnd;
///
/// Approximates a definite integral using an Nth order Gauss-Legendre rule.
diff --git a/src/Numerics/Interpolation/Barycentric.cs b/src/Numerics/Interpolation/Barycentric.cs
index 2995d12d..a9c6c972 100644
--- a/src/Numerics/Interpolation/Barycentric.cs
+++ b/src/Numerics/Interpolation/Barycentric.cs
@@ -254,18 +254,12 @@ namespace MathNet.Numerics.Interpolation
///
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
///
- bool IInterpolation.SupportsDifferentiation
- {
- get { return false; }
- }
+ bool IInterpolation.SupportsDifferentiation => false;
///
/// Gets a value indicating whether the algorithm supports integration (interpolated quadrature).
///
- bool IInterpolation.SupportsIntegration
- {
- get { return false; }
- }
+ bool IInterpolation.SupportsIntegration => false;
///
/// Interpolate at point t.
diff --git a/src/Numerics/Interpolation/BulirschStoerRationalInterpolation.cs b/src/Numerics/Interpolation/BulirschStoerRationalInterpolation.cs
index 8195a1ed..84b95367 100644
--- a/src/Numerics/Interpolation/BulirschStoerRationalInterpolation.cs
+++ b/src/Numerics/Interpolation/BulirschStoerRationalInterpolation.cs
@@ -100,18 +100,12 @@ namespace MathNet.Numerics.Interpolation
///
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
///
- bool IInterpolation.SupportsDifferentiation
- {
- get { return false; }
- }
+ bool IInterpolation.SupportsDifferentiation => false;
///
/// Gets a value indicating whether the algorithm supports integration (interpolated quadrature).
///
- bool IInterpolation.SupportsIntegration
- {
- get { return false; }
- }
+ bool IInterpolation.SupportsIntegration => false;
///
/// Interpolate at point t.
diff --git a/src/Numerics/Interpolation/CubicSpline.cs b/src/Numerics/Interpolation/CubicSpline.cs
index f9e048db..d03f9682 100644
--- a/src/Numerics/Interpolation/CubicSpline.cs
+++ b/src/Numerics/Interpolation/CubicSpline.cs
@@ -434,18 +434,12 @@ namespace MathNet.Numerics.Interpolation
///
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
///
- bool IInterpolation.SupportsDifferentiation
- {
- get { return true; }
- }
+ bool IInterpolation.SupportsDifferentiation => true;
///
/// Gets a value indicating whether the algorithm supports integration (interpolated quadrature).
///
- bool IInterpolation.SupportsIntegration
- {
- get { return true; }
- }
+ bool IInterpolation.SupportsIntegration => true;
///
/// Interpolate at point t.
diff --git a/src/Numerics/Interpolation/LinearSpline.cs b/src/Numerics/Interpolation/LinearSpline.cs
index 59cbd4c5..4761fabc 100644
--- a/src/Numerics/Interpolation/LinearSpline.cs
+++ b/src/Numerics/Interpolation/LinearSpline.cs
@@ -117,18 +117,12 @@ namespace MathNet.Numerics.Interpolation
///
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
///
- bool IInterpolation.SupportsDifferentiation
- {
- get { return true; }
- }
+ bool IInterpolation.SupportsDifferentiation => true;
///
/// Gets a value indicating whether the algorithm supports integration (interpolated quadrature).
///
- bool IInterpolation.SupportsIntegration
- {
- get { return true; }
- }
+ bool IInterpolation.SupportsIntegration => true;
///
/// Interpolate at point t.
diff --git a/src/Numerics/Interpolation/LogLinear.cs b/src/Numerics/Interpolation/LogLinear.cs
index 422e53fd..88f82e74 100644
--- a/src/Numerics/Interpolation/LogLinear.cs
+++ b/src/Numerics/Interpolation/LogLinear.cs
@@ -110,18 +110,12 @@ namespace MathNet.Numerics.Interpolation
///
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
///
- bool IInterpolation.SupportsDifferentiation
- {
- get { return true; }
- }
+ bool IInterpolation.SupportsDifferentiation => true;
///
/// Gets a value indicating whether the algorithm supports integration (interpolated quadrature).
///
- bool IInterpolation.SupportsIntegration
- {
- get { return false; }
- }
+ bool IInterpolation.SupportsIntegration => false;
///
/// Interpolate at point t.
diff --git a/src/Numerics/Interpolation/NevillePolynomialInterpolation.cs b/src/Numerics/Interpolation/NevillePolynomialInterpolation.cs
index c045e192..e0d932d9 100644
--- a/src/Numerics/Interpolation/NevillePolynomialInterpolation.cs
+++ b/src/Numerics/Interpolation/NevillePolynomialInterpolation.cs
@@ -113,18 +113,12 @@ namespace MathNet.Numerics.Interpolation
///
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
///
- bool IInterpolation.SupportsDifferentiation
- {
- get { return true; }
- }
+ bool IInterpolation.SupportsDifferentiation => true;
///
/// Gets a value indicating whether the algorithm supports integration (interpolated quadrature).
///
- bool IInterpolation.SupportsIntegration
- {
- get { return false; }
- }
+ bool IInterpolation.SupportsIntegration => false;
///
/// Interpolate at point t.
diff --git a/src/Numerics/Interpolation/QuadraticSpline.cs b/src/Numerics/Interpolation/QuadraticSpline.cs
index 52fa91df..3cd8eca0 100644
--- a/src/Numerics/Interpolation/QuadraticSpline.cs
+++ b/src/Numerics/Interpolation/QuadraticSpline.cs
@@ -70,18 +70,12 @@ namespace MathNet.Numerics.Interpolation
///
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
///
- bool IInterpolation.SupportsDifferentiation
- {
- get { return true; }
- }
+ bool IInterpolation.SupportsDifferentiation => true;
///
/// Gets a value indicating whether the algorithm supports integration (interpolated quadrature).
///
- bool IInterpolation.SupportsIntegration
- {
- get { return true; }
- }
+ bool IInterpolation.SupportsIntegration => true;
///
/// Interpolate at point t.
diff --git a/src/Numerics/Interpolation/StepInterpolation.cs b/src/Numerics/Interpolation/StepInterpolation.cs
index 739fbb2a..81eeb842 100644
--- a/src/Numerics/Interpolation/StepInterpolation.cs
+++ b/src/Numerics/Interpolation/StepInterpolation.cs
@@ -97,15 +97,9 @@ namespace MathNet.Numerics.Interpolation
return InterpolateInplace(x.ToArray(), y.ToArray());
}
- bool IInterpolation.SupportsDifferentiation
- {
- get { return true; }
- }
+ bool IInterpolation.SupportsDifferentiation => true;
- bool IInterpolation.SupportsIntegration
- {
- get { return true; }
- }
+ bool IInterpolation.SupportsIntegration => true;
///
/// Interpolate at point t.
diff --git a/src/Numerics/Interpolation/TransformedInterpolation.cs b/src/Numerics/Interpolation/TransformedInterpolation.cs
index 29cfc5ba..b9d0de9b 100644
--- a/src/Numerics/Interpolation/TransformedInterpolation.cs
+++ b/src/Numerics/Interpolation/TransformedInterpolation.cs
@@ -119,18 +119,12 @@ namespace MathNet.Numerics.Interpolation
///
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
///
- bool IInterpolation.SupportsDifferentiation
- {
- get { return false; }
- }
+ bool IInterpolation.SupportsDifferentiation => false;
///
/// Gets a value indicating whether the algorithm supports integration (interpolated quadrature).
///
- bool IInterpolation.SupportsIntegration
- {
- get { return false; }
- }
+ bool IInterpolation.SupportsIntegration => false;
///
/// Interpolate at point t.
diff --git a/src/Numerics/LinearAlgebra/Builder.cs b/src/Numerics/LinearAlgebra/Builder.cs
index dd89f4ba..b5a58900 100644
--- a/src/Numerics/LinearAlgebra/Builder.cs
+++ b/src/Numerics/LinearAlgebra/Builder.cs
@@ -39,15 +39,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double
{
internal class MatrixBuilder : MatrixBuilder
{
- public override double Zero
- {
- get { return 0d; }
- }
+ public override double Zero => 0d;
- public override double One
- {
- get { return 1d; }
- }
+ public override double One => 1d;
public override Matrix Dense(DenseColumnMajorMatrixStorage storage)
{
@@ -83,15 +77,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double
internal class VectorBuilder : VectorBuilder
{
- public override double Zero
- {
- get { return 0d; }
- }
+ public override double Zero => 0d;
- public override double One
- {
- get { return 1d; }
- }
+ public override double One => 1d;
public override Vector Dense(DenseVectorStorage storage)
{
@@ -114,15 +102,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single
{
internal class MatrixBuilder : MatrixBuilder
{
- public override float Zero
- {
- get { return 0f; }
- }
+ public override float Zero => 0f;
- public override float One
- {
- get { return 1f; }
- }
+ public override float One => 1f;
public override Matrix Dense(DenseColumnMajorMatrixStorage storage)
{
@@ -158,15 +140,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single
internal class VectorBuilder : VectorBuilder
{
- public override float Zero
- {
- get { return 0f; }
- }
+ public override float Zero => 0f;
- public override float One
- {
- get { return 1f; }
- }
+ public override float One => 1f;
public override Vector Dense(DenseVectorStorage storage)
{
@@ -191,15 +167,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
internal class MatrixBuilder : MatrixBuilder
{
- public override Complex Zero
- {
- get { return Complex.Zero; }
- }
+ public override Complex Zero => Complex.Zero;
- public override Complex One
- {
- get { return Complex.One; }
- }
+ public override Complex One => Complex.One;
public override Matrix Dense(DenseColumnMajorMatrixStorage storage)
{
@@ -235,15 +205,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
internal class VectorBuilder : VectorBuilder
{
- public override Complex Zero
- {
- get { return Complex.Zero; }
- }
+ public override Complex Zero => Complex.Zero;
- public override Complex One
- {
- get { return Complex.One; }
- }
+ public override Complex One => Complex.One;
public override Vector Dense(DenseVectorStorage storage)
{
@@ -266,15 +230,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
{
internal class MatrixBuilder : MatrixBuilder
{
- public override Numerics.Complex32 Zero
- {
- get { return Numerics.Complex32.Zero; }
- }
+ public override Numerics.Complex32 Zero => Numerics.Complex32.Zero;
- public override Numerics.Complex32 One
- {
- get { return Numerics.Complex32.One; }
- }
+ public override Numerics.Complex32 One => Numerics.Complex32.One;
public override Matrix Dense(DenseColumnMajorMatrixStorage storage)
{
@@ -310,15 +268,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
internal class VectorBuilder : VectorBuilder
{
- public override Numerics.Complex32 Zero
- {
- get { return Numerics.Complex32.Zero; }
- }
+ public override Numerics.Complex32 Zero => Numerics.Complex32.Zero;
- public override Numerics.Complex32 One
- {
- get { return Numerics.Complex32.One; }
- }
+ public override Numerics.Complex32 One => Numerics.Complex32.One;
public override Vector Dense(DenseVectorStorage storage)
{
@@ -364,16 +316,11 @@ namespace MathNet.Numerics.LinearAlgebra
{
if (storage == null) throw new ArgumentNullException(nameof(storage));
- var dense = storage as DenseColumnMajorMatrixStorage;
- if (dense != null) return Dense(dense);
-
- var sparse = storage as SparseCompressedRowMatrixStorage;
- if (sparse != null) return Sparse(sparse);
+ if (storage is DenseColumnMajorMatrixStorage dense) return Dense(dense);
+ if (storage is SparseCompressedRowMatrixStorage sparse) return Sparse(sparse);
+ if (storage is DiagonalMatrixStorage diagonal) return Diagonal(diagonal);
- var diagonal = storage as DiagonalMatrixStorage;
- if (diagonal != null) return Diagonal(diagonal);
-
- throw new NotSupportedException(string.Format("Matrix storage type '{0}' is not supported. Only DenseColumnMajorMatrixStorage, SparseCompressedRowMatrixStorage and DiagonalMatrixStorage are supported as this point.", storage.GetType().Name));
+ throw new NotSupportedException(FormattableString.Invariant($"Matrix storage type '{storage.GetType().Name}' is not supported. Only DenseColumnMajorMatrixStorage, SparseCompressedRowMatrixStorage and DiagonalMatrixStorage are supported as this point."));
}
///
@@ -1329,13 +1276,10 @@ namespace MathNet.Numerics.LinearAlgebra
{
if (storage == null) throw new ArgumentNullException(nameof(storage));
- var dense = storage as DenseVectorStorage;
- if (dense != null) return Dense(dense);
-
- var sparse = storage as SparseVectorStorage;
- if (sparse != null) return Sparse(sparse);
+ if (storage is DenseVectorStorage dense) return Dense(dense);
+ if (storage is SparseVectorStorage sparse) return Sparse(sparse);
- throw new NotSupportedException(string.Format("Vector storage type '{0}' is not supported. Only DenseVectorStorage and SparseVectorStorage are supported as this point.", storage.GetType().Name));
+ throw new NotSupportedException(FormattableString.Invariant($"Vector storage type '{storage.GetType().Name}' is not supported. Only DenseVectorStorage and SparseVectorStorage are supported as this point."));
}
///
@@ -1603,7 +1547,7 @@ namespace MathNet.Numerics.LinearAlgebra
(VectorBuilder)(object)new Single.VectorBuilder());
}
- throw new NotSupportedException(string.Format("Matrices and vectors of type '{0}' are not supported. Only Double, Single, Complex or Complex32 are supported at this point.", typeof(T).Name));
+ throw new NotSupportedException(FormattableString.Invariant($"Matrices and vectors of type '{typeof(T).Name}' are not supported. Only Double, Single, Complex or Complex32 are supported at this point."));
}
public static void Register(MatrixBuilder matrixBuilder, VectorBuilder vectorBuilder)
@@ -1611,14 +1555,8 @@ namespace MathNet.Numerics.LinearAlgebra
_singleton = new Lazy, VectorBuilder>>(() => new Tuple, VectorBuilder>(matrixBuilder, vectorBuilder));
}
- public static MatrixBuilder Matrix
- {
- get { return _singleton.Value.Item1; }
- }
+ public static MatrixBuilder Matrix => _singleton.Value.Item1;
- public static VectorBuilder Vector
- {
- get { return _singleton.Value.Item2; }
- }
+ public static VectorBuilder Vector => _singleton.Value.Item2;
}
}
diff --git a/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
index 65656af7..6105bee5 100644
--- a/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
@@ -395,10 +395,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// Gets the matrix's data.
///
/// The matrix's data.
- public Complex[] Values
- {
- get { return _values; }
- }
+ public Complex[] Values => _values;
/// Calculates the induced L1 norm of this matrix.
/// The maximum absolute column sum of the matrix.
@@ -427,8 +424,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// The result of the negation.
protected override void DoNegate(Matrix result)
{
- var denseResult = result as DenseMatrix;
- if (denseResult != null)
+ if (result is DenseMatrix denseResult)
{
LinearAlgebraControl.Provider.ScaleArray(-1, _values, denseResult._values);
return;
@@ -443,8 +439,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// The result of the conjugation.
protected override void DoConjugate(Matrix result)
{
- var denseResult = result as DenseMatrix;
- if (denseResult != null)
+ if (result is DenseMatrix denseResult)
{
LinearAlgebraControl.Provider.ConjugateArray(_values, denseResult._values);
return;
@@ -487,17 +482,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
protected override void DoAdd(Matrix other, Matrix result)
{
// dense + dense = dense
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- var denseResult = result.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null && denseResult != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther && result.Storage is DenseColumnMajorMatrixStorage denseResult)
{
LinearAlgebraControl.Provider.AddArrays(_values, denseOther.Data, denseResult.Data);
return;
}
// dense + diagonal = any
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
Storage.CopyToUnchecked(result.Storage, ExistingData.Clear);
var diagonal = diagonalOther.Data;
@@ -543,17 +535,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
protected override void DoSubtract(Matrix other, Matrix result)
{
// dense + dense = dense
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- var denseResult = result.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null && denseResult != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther && result.Storage is DenseColumnMajorMatrixStorage denseResult)
{
LinearAlgebraControl.Provider.SubtractArrays(_values, denseOther.Data, denseResult.Data);
return;
}
// dense + diagonal = matrix
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
CopyTo(result);
var diagonal = diagonalOther.Data;
@@ -619,9 +608,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// The result of the multiplication.
protected override void DoMultiply(Matrix other, Matrix result)
{
- var denseOther = other as DenseMatrix;
- var denseResult = result as DenseMatrix;
- if (denseOther != null && denseResult != null)
+ if (other is DenseMatrix denseOther && result is DenseMatrix denseResult)
{
LinearAlgebraControl.Provider.MatrixMultiply(
_values,
@@ -634,8 +621,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return;
}
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
var diagonal = diagonalOther.Data;
var d = Math.Min(ColumnCount, other.ColumnCount);
@@ -665,9 +651,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// The result of the multiplication.
protected override void DoTransposeAndMultiply(Matrix other, Matrix result)
{
- var denseOther = other as DenseMatrix;
- var denseResult = result as DenseMatrix;
- if (denseOther != null && denseResult != null)
+ if (other is DenseMatrix denseOther && result is DenseMatrix denseResult)
{
LinearAlgebraControl.Provider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.DontTranspose,
@@ -684,8 +668,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return;
}
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
var diagonal = diagonalOther.Data;
var d = Math.Min(ColumnCount, other.RowCount);
@@ -715,9 +698,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// The result of the multiplication.
protected override void DoConjugateTransposeAndMultiply(Matrix other, Matrix result)
{
- var denseOther = other as DenseMatrix;
- var denseResult = result as DenseMatrix;
- if (denseOther != null && denseResult != null)
+ if (other is DenseMatrix denseOther && result is DenseMatrix denseResult)
{
LinearAlgebraControl.Provider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.DontTranspose,
@@ -734,8 +715,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return;
}
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
var diagonal = diagonalOther.Data;
var conjugateDiagonal = new Complex[diagonal.Length];
@@ -771,9 +751,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// The result of the multiplication.
protected override void DoTransposeThisAndMultiply(Vector rightSide, Vector result)
{
- var denseRight = rightSide as DenseVector;
- var denseResult = result as DenseVector;
- if (denseRight != null && denseResult != null)
+ if (rightSide is DenseVector denseRight && result is DenseVector denseResult)
{
LinearAlgebraControl.Provider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.Transpose,
@@ -800,9 +778,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// The result of the multiplication.
protected override void DoConjugateTransposeThisAndMultiply(Vector rightSide, Vector result)
{
- var denseRight = rightSide as DenseVector;
- var denseResult = result as DenseVector;
- if (denseRight != null && denseResult != null)
+ if (rightSide is DenseVector denseRight && result is DenseVector denseResult)
{
LinearAlgebraControl.Provider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.ConjugateTranspose,
@@ -829,9 +805,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// The result of the multiplication.
protected override void DoTransposeThisAndMultiply(Matrix other, Matrix result)
{
- var denseOther = other as DenseMatrix;
- var denseResult = result as DenseMatrix;
- if (denseOther != null && denseResult != null)
+ if (other is DenseMatrix denseOther && result is DenseMatrix denseResult)
{
LinearAlgebraControl.Provider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.Transpose,
@@ -848,8 +822,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return;
}
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
var diagonal = diagonalOther.Data;
var d = Math.Min(RowCount, other.ColumnCount);
@@ -880,9 +853,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// The result of the multiplication.
protected override void DoConjugateTransposeThisAndMultiply(Matrix other, Matrix result)
{
- var denseOther = other as DenseMatrix;
- var denseResult = result as DenseMatrix;
- if (denseOther != null && denseResult != null)
+ if (other is DenseMatrix denseOther && result is DenseMatrix denseResult)
{
LinearAlgebraControl.Provider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.ConjugateTranspose,
@@ -899,8 +870,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return;
}
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
var diagonal = diagonalOther.Data;
var d = Math.Min(RowCount, other.ColumnCount);
diff --git a/src/Numerics/LinearAlgebra/Complex/DenseVector.cs b/src/Numerics/LinearAlgebra/Complex/DenseVector.cs
index 67500ca6..335fcc57 100644
--- a/src/Numerics/LinearAlgebra/Complex/DenseVector.cs
+++ b/src/Numerics/LinearAlgebra/Complex/DenseVector.cs
@@ -162,10 +162,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// Gets the vector's data.
///
/// The vector's data.
- public Complex[] Values
- {
- get { return _values; }
- }
+ public Complex[] Values => _values;
///
/// Returns a reference to the internal data structure.
diff --git a/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
index 02f01386..2fff31e8 100644
--- a/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
@@ -192,8 +192,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// The result of the negation.
protected override void DoNegate(Matrix result)
{
- var diagResult = result as DiagonalMatrix;
- if (diagResult != null)
+ if (result is DiagonalMatrix diagResult)
{
LinearAlgebraControl.Provider.ScaleArray(-1, _data, diagResult._data);
return;
@@ -212,8 +211,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// The result of the conjugation.
protected override void DoConjugate(Matrix result)
{
- var diagResult = result as DiagonalMatrix;
- if (diagResult != null)
+ if (result is DiagonalMatrix diagResult)
{
LinearAlgebraControl.Provider.ConjugateArray(_data, diagResult._data);
return;
@@ -235,9 +233,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
protected override void DoAdd(Matrix other, Matrix result)
{
// diagonal + diagonal = diagonal
- var diagOther = other as DiagonalMatrix;
- var diagResult = result as DiagonalMatrix;
- if (diagOther != null && diagResult != null)
+ if (other is DiagonalMatrix diagOther && result is DiagonalMatrix diagResult)
{
LinearAlgebraControl.Provider.AddArrays(_data, diagOther._data, diagResult._data);
return;
@@ -259,9 +255,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
protected override void DoSubtract(Matrix other, Matrix result)
{
// diagonal - diagonal = diagonal
- var diagOther = other as DiagonalMatrix;
- var diagResult = result as DiagonalMatrix;
- if (diagOther != null && diagResult != null)
+ if (other is DiagonalMatrix diagOther && result is DiagonalMatrix diagResult)
{
LinearAlgebraControl.Provider.SubtractArrays(_data, diagOther._data, diagResult._data);
return;
@@ -320,9 +314,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
if (d == ColumnCount)
{
- var denseOther = rightSide.Storage as DenseVectorStorage;
- var denseResult = result.Storage as DenseVectorStorage;
- if (denseOther != null && denseResult != null)
+ if (rightSide.Storage is DenseVectorStorage denseOther && result.Storage is DenseVectorStorage denseResult)
{
LinearAlgebraControl.Provider.PointWiseMultiplyArrays(_data, denseOther.Data, denseResult.Data);
return;
@@ -342,9 +334,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// The result of the multiplication.
protected override void DoMultiply(Matrix other, Matrix result)
{
- var diagonalOther = other as DiagonalMatrix;
- var diagonalResult = result as DiagonalMatrix;
- if (diagonalOther != null && diagonalResult != null)
+ if (other is DiagonalMatrix diagonalOther && result is DiagonalMatrix diagonalResult)
{
var thisDataCopy = new Complex[diagonalResult._data.Length];
var otherDataCopy = new Complex[diagonalResult._data.Length];
@@ -354,8 +344,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return;
}
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther)
{
var dense = denseOther.Data;
var diagonal = _data;
@@ -395,9 +384,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// The result of the multiplication.
protected override void DoTransposeAndMultiply(Matrix other, Matrix result)
{
- var diagonalOther = other as DiagonalMatrix;
- var diagonalResult = result as DiagonalMatrix;
- if (diagonalOther != null && diagonalResult != null)
+ if (other is DiagonalMatrix diagonalOther && result is DiagonalMatrix diagonalResult)
{
var thisDataCopy = new Complex[diagonalResult._data.Length];
var otherDataCopy = new Complex[diagonalResult._data.Length];
@@ -407,8 +394,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return;
}
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther)
{
var dense = denseOther.Data;
var diagonal = _data;
@@ -439,9 +425,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// The result of the multiplication.
protected override void DoConjugateTransposeAndMultiply(Matrix other, Matrix result)
{
- var diagonalOther = other as DiagonalMatrix;
- var diagonalResult = result as DiagonalMatrix;
- if (diagonalOther != null && diagonalResult != null)
+ if (other is DiagonalMatrix diagonalOther && result is DiagonalMatrix diagonalResult)
{
var thisDataCopy = new Complex[diagonalResult._data.Length];
var otherDataCopy = new Complex[diagonalResult._data.Length];
@@ -453,8 +437,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return;
}
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther)
{
var dense = denseOther.Data;
var diagonal = _data;
@@ -485,9 +468,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// The result of the multiplication.
protected override void DoTransposeThisAndMultiply(Matrix other, Matrix result)
{
- var diagonalOther = other as DiagonalMatrix;
- var diagonalResult = result as DiagonalMatrix;
- if (diagonalOther != null && diagonalResult != null)
+ if (other is DiagonalMatrix diagonalOther && result is DiagonalMatrix diagonalResult)
{
var thisDataCopy = new Complex[diagonalResult._data.Length];
var otherDataCopy = new Complex[diagonalResult._data.Length];
@@ -497,8 +478,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return;
}
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther)
{
var dense = denseOther.Data;
var diagonal = _data;
@@ -538,9 +518,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// The result of the multiplication.
protected override void DoConjugateTransposeThisAndMultiply(Matrix other, Matrix result)
{
- var diagonalOther = other as DiagonalMatrix;
- var diagonalResult = result as DiagonalMatrix;
- if (diagonalOther != null && diagonalResult != null)
+ if (other is DiagonalMatrix diagonalOther && result is DiagonalMatrix diagonalResult)
{
var thisDataCopy = new Complex[diagonalResult._data.Length];
var otherDataCopy = new Complex[diagonalResult._data.Length];
@@ -552,8 +530,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return;
}
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther)
{
var dense = denseOther.Data;
var conjugateDiagonal = new Complex[_data.Length];
@@ -598,9 +575,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
if (d == RowCount)
{
- var denseOther = rightSide.Storage as DenseVectorStorage;
- var denseResult = result.Storage as DenseVectorStorage;
- if (denseOther != null && denseResult != null)
+ if (rightSide.Storage is DenseVectorStorage denseOther && result.Storage is DenseVectorStorage denseResult)
{
LinearAlgebraControl.Provider.PointWiseMultiplyArrays(_data, denseOther.Data, denseResult.Data);
return;
@@ -628,9 +603,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
if (d == RowCount)
{
- var denseOther = rightSide.Storage as DenseVectorStorage;
- var denseResult = result.Storage as DenseVectorStorage;
- if (denseOther != null && denseResult != null)
+ if (rightSide.Storage is DenseVectorStorage denseOther && result.Storage is DenseVectorStorage denseResult)
{
// TODO: merge/MulByConj
LinearAlgebraControl.Provider.ConjugateArray(_data, denseResult.Data);
@@ -658,8 +631,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return;
}
- var diagResult = result as DiagonalMatrix;
- if (diagResult != null)
+ if (result is DiagonalMatrix diagResult)
{
LinearAlgebraControl.Provider.ScaleArray(1.0/divisor, _data, diagResult._data);
return;
@@ -679,8 +651,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// The matrix to store the result of the division.
protected override void DoDivideByThis(Complex dividend, Matrix result)
{
- var diagResult = result as DiagonalMatrix;
- if (diagResult != null)
+ if (result is DiagonalMatrix diagResult)
{
var resultData = diagResult._data;
CommonParallel.For(0, _data.Length, 4096, (a, b) =>
diff --git a/src/Numerics/LinearAlgebra/Complex/Factorization/Svd.cs b/src/Numerics/LinearAlgebra/Complex/Factorization/Svd.cs
index 8ba7ea13..79877a2d 100644
--- a/src/Numerics/LinearAlgebra/Complex/Factorization/Svd.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Factorization/Svd.cs
@@ -74,13 +74,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization
/// Gets the two norm of the .
///
/// The 2-norm of the .
- public override double L2Norm
- {
- get
- {
- return S[0].Magnitude;
- }
- }
+ public override double L2Norm => S[0].Magnitude;
///
/// Gets the condition number max(S) / min(S)
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/GpBiCg.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/GpBiCg.cs
index 4a09bff6..f8c1da22 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/GpBiCg.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/GpBiCg.cs
@@ -82,7 +82,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
///
public int NumberOfBiCgStabSteps
{
- get { return _numberOfBiCgStabSteps; }
+ get => _numberOfBiCgStabSteps;
set
{
@@ -101,7 +101,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
///
public int NumberOfGpBiCgSteps
{
- get { return _numberOfGpbiCgSteps; }
+ get => _numberOfGpbiCgSteps;
set
{
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/ILUTPPreconditioner.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/ILUTPPreconditioner.cs
index 7eb6e1e4..78328347 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/ILUTPPreconditioner.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/ILUTPPreconditioner.cs
@@ -162,7 +162,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
/// Thrown if a negative value is provided.
public double FillLevel
{
- get { return _fillLevel; }
+ get => _fillLevel;
set
{
if (value < 0)
@@ -193,7 +193,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
/// Thrown if a negative value is provided.
public double DropTolerance
{
- get { return _dropTolerance; }
+ get => _dropTolerance;
set
{
if (value < 0)
@@ -226,7 +226,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
/// Thrown if a negative value is provided.
public double PivotTolerance
{
- get { return _pivotTolerance; }
+ get => _pivotTolerance;
set
{
if (value < 0)
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/MlkBiCgStab.cs
index 5361c241..eb5f9348 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/MlkBiCgStab.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/MlkBiCgStab.cs
@@ -89,7 +89,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
public int NumberOfStartingVectors
{
[DebuggerStepThrough]
- get { return _numberOfStartingVectors; }
+ get => _numberOfStartingVectors;
[DebuggerStepThrough]
set
@@ -118,7 +118,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
public IList> StartingVectors
{
[DebuggerStepThrough]
- get { return _startingVectors; }
+ get => _startingVectors;
[DebuggerStepThrough]
set
diff --git a/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
index add8a477..1224f077 100644
--- a/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
@@ -53,10 +53,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// Gets the number of non zero elements in the matrix.
///
/// The number of non zero elements.
- public int NonZerosCount
- {
- get { return _storage.ValueCount; }
- }
+ public int NonZerosCount => _storage.ValueCount;
///
/// Create a new sparse matrix straight from an initialized matrix storage instance.
@@ -890,8 +887,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return;
}
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null && sparseResult != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther && sparseResult != null)
{
var diagonal = diagonalOther.Data;
if (other.ColumnCount == other.RowCount)
@@ -912,8 +908,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
var rowPointers = _storage.RowPointers;
var columnIndices = _storage.ColumnIndices;
var values = _storage.Values;
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther)
{
// in this case we can directly address the underlying data-array
for (var row = 0; row < RowCount; row++)
@@ -1547,7 +1542,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
public override string ToTypeString()
{
- return string.Format("SparseMatrix {0}x{1}-Complex {2:P2} Filled", RowCount, ColumnCount, NonZerosCount / (RowCount * (double)ColumnCount));
+ return FormattableString.Invariant($"SparseMatrix {RowCount}x{ColumnCount}-Complex {NonZerosCount / (RowCount * (double) ColumnCount):P2} Filled");
}
}
}
diff --git a/src/Numerics/LinearAlgebra/Complex/SparseVector.cs b/src/Numerics/LinearAlgebra/Complex/SparseVector.cs
index ee82bf96..5bd7e35f 100644
--- a/src/Numerics/LinearAlgebra/Complex/SparseVector.cs
+++ b/src/Numerics/LinearAlgebra/Complex/SparseVector.cs
@@ -52,10 +52,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// Gets the number of non zero elements in the vector.
///
/// The number of non zero elements.
- public int NonZerosCount
- {
- get { return _storage.ValueCount; }
- }
+ public int NonZerosCount => _storage.ValueCount;
///
/// Create a new sparse vector straight from an initialized vector storage instance.
@@ -404,8 +401,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// Target vector
protected override void DoConjugate(Vector result)
{
- var sparseResult = result as SparseVector;
- if (sparseResult != null)
+ if (result is SparseVector sparseResult)
{
if (!ReferenceEquals(this, result))
{
@@ -931,7 +927,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
public override string ToTypeString()
{
- return string.Format("SparseVector {0}-Complex {1:P2} Filled", Count, NonZerosCount / (double)Count);
+ return FormattableString.Invariant($"SparseVector {Count}-Complex {NonZerosCount / (double) Count:P2} Filled");
}
}
}
diff --git a/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
index c058ed60..08c89197 100644
--- a/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
@@ -395,10 +395,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// Gets the matrix's data.
///
/// The matrix's data.
- public Complex32[] Values
- {
- get { return _values; }
- }
+ public Complex32[] Values => _values;
/// Calculates the induced L1 norm of this matrix.
/// The maximum absolute column sum of the matrix.
@@ -427,8 +424,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// The result of the negation.
protected override void DoNegate(Matrix result)
{
- var denseResult = result as DenseMatrix;
- if (denseResult != null)
+ if (result is DenseMatrix denseResult)
{
LinearAlgebraControl.Provider.ScaleArray(-1, _values, denseResult._values);
return;
@@ -443,8 +439,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// The result of the conjugation.
protected override void DoConjugate(Matrix result)
{
- var denseResult = result as DenseMatrix;
- if (denseResult != null)
+ if (result is DenseMatrix denseResult)
{
LinearAlgebraControl.Provider.ConjugateArray(_values, denseResult._values);
return;
@@ -487,17 +482,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
protected override void DoAdd(Matrix other, Matrix result)
{
// dense + dense = dense
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- var denseResult = result.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null && denseResult != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther && result.Storage is DenseColumnMajorMatrixStorage denseResult)
{
LinearAlgebraControl.Provider.AddArrays(_values, denseOther.Data, denseResult.Data);
return;
}
// dense + diagonal = any
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
Storage.CopyToUnchecked(result.Storage, ExistingData.Clear);
var diagonal = diagonalOther.Data;
@@ -543,17 +535,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
protected override void DoSubtract(Matrix other, Matrix result)
{
// dense + dense = dense
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- var denseResult = result.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null && denseResult != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther && result.Storage is DenseColumnMajorMatrixStorage denseResult)
{
LinearAlgebraControl.Provider.SubtractArrays(_values, denseOther.Data, denseResult.Data);
return;
}
// dense + diagonal = matrix
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
CopyTo(result);
var diagonal = diagonalOther.Data;
@@ -619,9 +608,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// The result of the multiplication.
protected override void DoMultiply(Matrix other, Matrix result)
{
- var denseOther = other as DenseMatrix;
- var denseResult = result as DenseMatrix;
- if (denseOther != null && denseResult != null)
+ if (other is DenseMatrix denseOther && result is DenseMatrix denseResult)
{
LinearAlgebraControl.Provider.MatrixMultiply(
_values,
@@ -634,8 +621,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return;
}
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
var diagonal = diagonalOther.Data;
var d = Math.Min(ColumnCount, other.ColumnCount);
@@ -665,9 +651,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// The result of the multiplication.
protected override void DoTransposeAndMultiply(Matrix other, Matrix result)
{
- var denseOther = other as DenseMatrix;
- var denseResult = result as DenseMatrix;
- if (denseOther != null && denseResult != null)
+ if (other is DenseMatrix denseOther && result is DenseMatrix denseResult)
{
LinearAlgebraControl.Provider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.DontTranspose,
@@ -684,8 +668,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return;
}
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
var diagonal = diagonalOther.Data;
var d = Math.Min(ColumnCount, other.RowCount);
@@ -715,9 +698,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// The result of the multiplication.
protected override void DoConjugateTransposeAndMultiply(Matrix other, Matrix result)
{
- var denseOther = other as DenseMatrix;
- var denseResult = result as DenseMatrix;
- if (denseOther != null && denseResult != null)
+ if (other is DenseMatrix denseOther && result is DenseMatrix denseResult)
{
LinearAlgebraControl.Provider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.DontTranspose,
@@ -734,8 +715,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return;
}
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
var diagonal = diagonalOther.Data;
var conjugateDiagonal = new Complex32[diagonal.Length];
@@ -802,9 +782,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// The result of the multiplication.
protected override void DoConjugateTransposeThisAndMultiply(Vector rightSide, Vector result)
{
- var denseRight = rightSide as DenseVector;
- var denseResult = result as DenseVector;
- if (denseRight != null && denseResult != null)
+ if (rightSide is DenseVector denseRight && result is DenseVector denseResult)
{
LinearAlgebraControl.Provider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.ConjugateTranspose,
@@ -831,9 +809,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// The result of the multiplication.
protected override void DoTransposeThisAndMultiply(Matrix other, Matrix result)
{
- var denseOther = other as DenseMatrix;
- var denseResult = result as DenseMatrix;
- if (denseOther != null && denseResult != null)
+ if (other is DenseMatrix denseOther && result is DenseMatrix denseResult)
{
LinearAlgebraControl.Provider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.Transpose,
@@ -850,8 +826,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return;
}
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
var diagonal = diagonalOther.Data;
var d = Math.Min(RowCount, other.ColumnCount);
@@ -882,9 +857,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// The result of the multiplication.
protected override void DoConjugateTransposeThisAndMultiply(Matrix other, Matrix result)
{
- var denseOther = other as DenseMatrix;
- var denseResult = result as DenseMatrix;
- if (denseOther != null && denseResult != null)
+ if (other is DenseMatrix denseOther && result is DenseMatrix denseResult)
{
LinearAlgebraControl.Provider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.ConjugateTranspose,
@@ -901,8 +874,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return;
}
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
var diagonal = diagonalOther.Data;
var d = Math.Min(RowCount, other.ColumnCount);
diff --git a/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs b/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs
index a687c641..5644df8b 100644
--- a/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs
@@ -162,10 +162,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// Gets the vector's data.
///
/// The vector's data.
- public Complex32[] Values
- {
- get { return _values; }
- }
+ public Complex32[] Values => _values;
///
/// Returns a reference to the internal data structure.
diff --git a/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
index c8c93e00..6f866966 100644
--- a/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
@@ -192,8 +192,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// The result of the negation.
protected override void DoNegate(Matrix result)
{
- var diagResult = result as DiagonalMatrix;
- if (diagResult != null)
+ if (result is DiagonalMatrix diagResult)
{
LinearAlgebraControl.Provider.ScaleArray(-1, _data, diagResult._data);
return;
@@ -212,8 +211,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// The result of the conjugation.
protected override void DoConjugate(Matrix result)
{
- var diagResult = result as DiagonalMatrix;
- if (diagResult != null)
+ if (result is DiagonalMatrix diagResult)
{
LinearAlgebraControl.Provider.ConjugateArray(_data, diagResult._data);
return;
@@ -235,9 +233,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
protected override void DoAdd(Matrix other, Matrix result)
{
// diagonal + diagonal = diagonal
- var diagOther = other as DiagonalMatrix;
- var diagResult = result as DiagonalMatrix;
- if (diagOther != null && diagResult != null)
+ if (other is DiagonalMatrix diagOther && result is DiagonalMatrix diagResult)
{
LinearAlgebraControl.Provider.AddArrays(_data, diagOther._data, diagResult._data);
return;
@@ -259,9 +255,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
protected override void DoSubtract(Matrix other, Matrix result)
{
// diagonal - diagonal = diagonal
- var diagOther = other as DiagonalMatrix;
- var diagResult = result as DiagonalMatrix;
- if (diagOther != null && diagResult != null)
+ if (other is DiagonalMatrix diagOther && result is DiagonalMatrix diagResult)
{
LinearAlgebraControl.Provider.SubtractArrays(_data, diagOther._data, diagResult._data);
return;
@@ -319,9 +313,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
if (d == ColumnCount)
{
- var denseOther = rightSide.Storage as DenseVectorStorage;
- var denseResult = result.Storage as DenseVectorStorage;
- if (denseOther != null && denseResult != null)
+ if (rightSide.Storage is DenseVectorStorage denseOther && result.Storage is DenseVectorStorage denseResult)
{
LinearAlgebraControl.Provider.PointWiseMultiplyArrays(_data, denseOther.Data, denseResult.Data);
return;
@@ -341,9 +333,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// The result of the multiplication.
protected override void DoMultiply(Matrix other, Matrix result)
{
- var diagonalOther = other as DiagonalMatrix;
- var diagonalResult = result as DiagonalMatrix;
- if (diagonalOther != null && diagonalResult != null)
+ if (other is DiagonalMatrix diagonalOther && result is DiagonalMatrix diagonalResult)
{
var thisDataCopy = new Complex32[diagonalResult._data.Length];
var otherDataCopy = new Complex32[diagonalResult._data.Length];
@@ -353,8 +343,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return;
}
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther)
{
var dense = denseOther.Data;
var diagonal = _data;
@@ -394,9 +383,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// The result of the multiplication.
protected override void DoTransposeAndMultiply(Matrix other, Matrix result)
{
- var diagonalOther = other as DiagonalMatrix;
- var diagonalResult = result as DiagonalMatrix;
- if (diagonalOther != null && diagonalResult != null)
+ if (other is DiagonalMatrix diagonalOther && result is DiagonalMatrix diagonalResult)
{
var thisDataCopy = new Complex32[diagonalResult._data.Length];
var otherDataCopy = new Complex32[diagonalResult._data.Length];
@@ -406,8 +393,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return;
}
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther)
{
var dense = denseOther.Data;
var diagonal = _data;
@@ -438,9 +424,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// The result of the multiplication.
protected override void DoConjugateTransposeAndMultiply(Matrix other, Matrix result)
{
- var diagonalOther = other as DiagonalMatrix;
- var diagonalResult = result as DiagonalMatrix;
- if (diagonalOther != null && diagonalResult != null)
+ if (other is DiagonalMatrix diagonalOther && result is DiagonalMatrix diagonalResult)
{
var thisDataCopy = new Complex32[diagonalResult._data.Length];
var otherDataCopy = new Complex32[diagonalResult._data.Length];
@@ -452,8 +436,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return;
}
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther)
{
var dense = denseOther.Data;
var diagonal = _data;
@@ -484,9 +467,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// The result of the multiplication.
protected override void DoTransposeThisAndMultiply(Matrix other, Matrix result)
{
- var diagonalOther = other as DiagonalMatrix;
- var diagonalResult = result as DiagonalMatrix;
- if (diagonalOther != null && diagonalResult != null)
+ if (other is DiagonalMatrix diagonalOther && result is DiagonalMatrix diagonalResult)
{
var thisDataCopy = new Complex32[diagonalResult._data.Length];
var otherDataCopy = new Complex32[diagonalResult._data.Length];
@@ -496,8 +477,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return;
}
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther)
{
var dense = denseOther.Data;
var diagonal = _data;
@@ -537,9 +517,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// The result of the multiplication.
protected override void DoConjugateTransposeThisAndMultiply(Matrix other, Matrix result)
{
- var diagonalOther = other as DiagonalMatrix;
- var diagonalResult = result as DiagonalMatrix;
- if (diagonalOther != null && diagonalResult != null)
+ if (other is DiagonalMatrix diagonalOther && result is DiagonalMatrix diagonalResult)
{
var thisDataCopy = new Complex32[diagonalResult._data.Length];
var otherDataCopy = new Complex32[diagonalResult._data.Length];
@@ -551,8 +529,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return;
}
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther)
{
var dense = denseOther.Data;
var conjugateDiagonal = new Complex32[_data.Length];
@@ -597,9 +574,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
if (d == RowCount)
{
- var denseOther = rightSide.Storage as DenseVectorStorage;
- var denseResult = result.Storage as DenseVectorStorage;
- if (denseOther != null && denseResult != null)
+ if (rightSide.Storage is DenseVectorStorage denseOther && result.Storage is DenseVectorStorage denseResult)
{
LinearAlgebraControl.Provider.PointWiseMultiplyArrays(_data, denseOther.Data, denseResult.Data);
return;
@@ -627,9 +602,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
if (d == RowCount)
{
- var denseOther = rightSide.Storage as DenseVectorStorage;
- var denseResult = result.Storage as DenseVectorStorage;
- if (denseOther != null && denseResult != null)
+ if (rightSide.Storage is DenseVectorStorage denseOther && result.Storage is DenseVectorStorage denseResult)
{
// TODO: merge/MulByConj
LinearAlgebraControl.Provider.ConjugateArray(_data, denseResult.Data);
@@ -657,8 +630,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return;
}
- var diagResult = result as DiagonalMatrix;
- if (diagResult != null)
+ if (result is DiagonalMatrix diagResult)
{
LinearAlgebraControl.Provider.ScaleArray(1.0f/divisor, _data, diagResult._data);
return;
@@ -678,8 +650,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// The matrix to store the result of the division.
protected override void DoDivideByThis(Complex32 dividend, Matrix result)
{
- var diagResult = result as DiagonalMatrix;
- if (diagResult != null)
+ if (result is DiagonalMatrix diagResult)
{
var resultData = diagResult._data;
CommonParallel.For(0, _data.Length, 4096, (a, b) =>
diff --git a/src/Numerics/LinearAlgebra/Complex32/Factorization/Svd.cs b/src/Numerics/LinearAlgebra/Complex32/Factorization/Svd.cs
index 56814811..688c847e 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Factorization/Svd.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Factorization/Svd.cs
@@ -74,13 +74,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization
/// Gets the two norm of the .
///
/// The 2-norm of the .
- public override double L2Norm
- {
- get
- {
- return S[0].Magnitude;
- }
- }
+ public override double L2Norm => S[0].Magnitude;
///
/// Gets the condition number max(S) / min(S)
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/GpBiCg.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/GpBiCg.cs
index 996d2f42..2cc8ada4 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/GpBiCg.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/GpBiCg.cs
@@ -80,7 +80,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
///
public int NumberOfBiCgStabSteps
{
- get { return _numberOfBiCgStabSteps; }
+ get => _numberOfBiCgStabSteps;
set
{
@@ -99,7 +99,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
///
public int NumberOfGpBiCgSteps
{
- get { return _numberOfGpbiCgSteps; }
+ get => _numberOfGpbiCgSteps;
set
{
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/ILUTPPreconditioner.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/ILUTPPreconditioner.cs
index fe0a008c..713f7179 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/ILUTPPreconditioner.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/ILUTPPreconditioner.cs
@@ -162,7 +162,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
/// Thrown if a negative value is provided.
public double FillLevel
{
- get { return _fillLevel; }
+ get => _fillLevel;
set
{
if (value < 0)
@@ -193,7 +193,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
/// Thrown if a negative value is provided.
public double DropTolerance
{
- get { return _dropTolerance; }
+ get => _dropTolerance;
set
{
if (value < 0)
@@ -226,7 +226,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
/// Thrown if a negative value is provided.
public double PivotTolerance
{
- get { return _pivotTolerance; }
+ get => _pivotTolerance;
set
{
if (value < 0)
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/MlkBiCgStab.cs
index 87b7abae..4046864c 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/MlkBiCgStab.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/MlkBiCgStab.cs
@@ -87,7 +87,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
public int NumberOfStartingVectors
{
[DebuggerStepThrough]
- get { return _numberOfStartingVectors; }
+ get => _numberOfStartingVectors;
[DebuggerStepThrough]
set
@@ -116,7 +116,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
public IList> StartingVectors
{
[DebuggerStepThrough]
- get { return _startingVectors; }
+ get => _startingVectors;
[DebuggerStepThrough]
set
diff --git a/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
index 717c6610..3902f255 100644
--- a/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
@@ -53,10 +53,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// Gets the number of non zero elements in the matrix.
///
/// The number of non zero elements.
- public int NonZerosCount
- {
- get { return _storage.ValueCount; }
- }
+ public int NonZerosCount => _storage.ValueCount;
///
/// Create a new sparse matrix straight from an initialized matrix storage instance.
@@ -889,8 +886,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return;
}
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null && sparseResult != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther && sparseResult != null)
{
var diagonal = diagonalOther.Data;
if (other.ColumnCount == other.RowCount)
@@ -911,8 +907,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
var rowPointers = _storage.RowPointers;
var columnIndices = _storage.ColumnIndices;
var values = _storage.Values;
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther)
{
// in this case we can directly address the underlying data-array
for (var row = 0; row < RowCount; row++)
diff --git a/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs b/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
index 9f947149..bcf89326 100644
--- a/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
@@ -52,10 +52,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// Gets the number of non zero elements in the vector.
///
/// The number of non zero elements.
- public int NonZerosCount
- {
- get { return _storage.ValueCount; }
- }
+ public int NonZerosCount => _storage.ValueCount;
///
/// Create a new sparse vector straight from an initialized vector storage instance.
@@ -404,8 +401,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// Target vector
protected override void DoConjugate(Vector result)
{
- var sparseResult = result as SparseVector;
- if (sparseResult != null)
+ if (result is SparseVector sparseResult)
{
if (!ReferenceEquals(this, result))
{
@@ -931,7 +927,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
public override string ToTypeString()
{
- return string.Format("SparseVector {0}-Complex32 {1:P2} Filled", Count, NonZerosCount / (double)Count);
+ return FormattableString.Invariant($"SparseVector {Count}-Complex32 {NonZerosCount / (double) Count:P2} Filled");
}
}
}
diff --git a/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs
index 8aef79c3..bbf65c08 100644
--- a/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs
@@ -393,10 +393,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// Gets the matrix's data.
///
/// The matrix's data.
- public double[] Values
- {
- get { return _values; }
- }
+ public double[] Values => _values;
/// Calculates the induced L1 norm of this matrix.
/// The maximum absolute column sum of the matrix.
@@ -425,8 +422,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// The result of the negation.
protected override void DoNegate(Matrix result)
{
- var denseResult = result as DenseMatrix;
- if (denseResult != null)
+ if (result is DenseMatrix denseResult)
{
LinearAlgebraControl.Provider.ScaleArray(-1, _values, denseResult._values);
return;
@@ -469,17 +465,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double
protected override void DoAdd(Matrix other, Matrix result)
{
// dense + dense = dense
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- var denseResult = result.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null && denseResult != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther && result.Storage is DenseColumnMajorMatrixStorage denseResult)
{
LinearAlgebraControl.Provider.AddArrays(_values, denseOther.Data, denseResult.Data);
return;
}
// dense + diagonal = any
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
Storage.CopyToUnchecked(result.Storage, ExistingData.Clear);
var diagonal = diagonalOther.Data;
@@ -525,17 +518,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double
protected override void DoSubtract(Matrix other, Matrix result)
{
// dense + dense = dense
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- var denseResult = result.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null && denseResult != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther && result.Storage is DenseColumnMajorMatrixStorage denseResult)
{
LinearAlgebraControl.Provider.SubtractArrays(_values, denseOther.Data, denseResult.Data);
return;
}
// dense + diagonal = matrix
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
CopyTo(result);
var diagonal = diagonalOther.Data;
@@ -601,9 +591,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// The result of the multiplication.
protected override void DoMultiply(Matrix other, Matrix result)
{
- var denseOther = other as DenseMatrix;
- var denseResult = result as DenseMatrix;
- if (denseOther != null && denseResult != null)
+ if (other is DenseMatrix denseOther && result is DenseMatrix denseResult)
{
LinearAlgebraControl.Provider.MatrixMultiply(
_values,
@@ -616,8 +604,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return;
}
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
var diagonal = diagonalOther.Data;
var d = Math.Min(ColumnCount, other.ColumnCount);
@@ -647,9 +634,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// The result of the multiplication.
protected override void DoTransposeAndMultiply(Matrix other, Matrix result)
{
- var denseOther = other as DenseMatrix;
- var denseResult = result as DenseMatrix;
- if (denseOther != null && denseResult != null)
+ if (other is DenseMatrix denseOther && result is DenseMatrix denseResult)
{
LinearAlgebraControl.Provider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.DontTranspose,
@@ -666,8 +651,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return;
}
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
var diagonal = diagonalOther.Data;
var d = Math.Min(ColumnCount, other.RowCount);
@@ -728,9 +712,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// The result of the multiplication.
protected override void DoTransposeThisAndMultiply(Matrix other, Matrix result)
{
- var denseOther = other as DenseMatrix;
- var denseResult = result as DenseMatrix;
- if (denseOther != null && denseResult != null)
+ if (other is DenseMatrix denseOther && result is DenseMatrix denseResult)
{
LinearAlgebraControl.Provider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.Transpose,
@@ -747,8 +729,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return;
}
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
var diagonal = diagonalOther.Data;
var d = Math.Min(RowCount, other.ColumnCount);
diff --git a/src/Numerics/LinearAlgebra/Double/DenseVector.cs b/src/Numerics/LinearAlgebra/Double/DenseVector.cs
index 71a10c1f..fa1cec37 100644
--- a/src/Numerics/LinearAlgebra/Double/DenseVector.cs
+++ b/src/Numerics/LinearAlgebra/Double/DenseVector.cs
@@ -162,10 +162,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// Gets the vector's data.
///
/// The vector's data.
- public double[] Values
- {
- get { return _values; }
- }
+ public double[] Values => _values;
///
/// Returns a reference to the internal data structure.
diff --git a/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
index 4c5e6463..eea86d64 100644
--- a/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
@@ -190,8 +190,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// The result of the negation.
protected override void DoNegate(Matrix result)
{
- var diagResult = result as DiagonalMatrix;
- if (diagResult != null)
+ if (result is DiagonalMatrix diagResult)
{
LinearAlgebraControl.Provider.ScaleArray(-1, _data, diagResult._data);
return;
@@ -213,9 +212,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
protected override void DoAdd(Matrix other, Matrix result)
{
// diagonal + diagonal = diagonal
- var diagOther = other as DiagonalMatrix;
- var diagResult = result as DiagonalMatrix;
- if (diagOther != null && diagResult != null)
+ if (other is DiagonalMatrix diagOther && result is DiagonalMatrix diagResult)
{
LinearAlgebraControl.Provider.AddArrays(_data, diagOther._data, diagResult._data);
return;
@@ -237,9 +234,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
protected override void DoSubtract(Matrix other, Matrix result)
{
// diagonal - diagonal = diagonal
- var diagOther = other as DiagonalMatrix;
- var diagResult = result as DiagonalMatrix;
- if (diagOther != null && diagResult != null)
+ if (other is DiagonalMatrix diagOther && result is DiagonalMatrix diagResult)
{
LinearAlgebraControl.Provider.SubtractArrays(_data, diagOther._data, diagResult._data);
return;
@@ -298,9 +293,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
if (d == ColumnCount)
{
- var denseOther = rightSide.Storage as DenseVectorStorage;
- var denseResult = result.Storage as DenseVectorStorage;
- if (denseOther != null && denseResult != null)
+ if (rightSide.Storage is DenseVectorStorage denseOther && result.Storage is DenseVectorStorage denseResult)
{
LinearAlgebraControl.Provider.PointWiseMultiplyArrays(_data, denseOther.Data, denseResult.Data);
return;
@@ -320,9 +313,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// The result of the multiplication.
protected override void DoMultiply(Matrix other, Matrix result)
{
- var diagonalOther = other as DiagonalMatrix;
- var diagonalResult = result as DiagonalMatrix;
- if (diagonalOther != null && diagonalResult != null)
+ if (other is DiagonalMatrix diagonalOther && result is DiagonalMatrix diagonalResult)
{
var thisDataCopy = new double[diagonalResult._data.Length];
var otherDataCopy = new double[diagonalResult._data.Length];
@@ -332,8 +323,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return;
}
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther)
{
var dense = denseOther.Data;
var diagonal = _data;
@@ -373,9 +363,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// The result of the multiplication.
protected override void DoTransposeAndMultiply(Matrix other, Matrix result)
{
- var diagonalOther = other as DiagonalMatrix;
- var diagonalResult = result as DiagonalMatrix;
- if (diagonalOther != null && diagonalResult != null)
+ if (other is DiagonalMatrix diagonalOther && result is DiagonalMatrix diagonalResult)
{
var thisDataCopy = new double[diagonalResult._data.Length];
var otherDataCopy = new double[diagonalResult._data.Length];
@@ -385,8 +373,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return;
}
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther)
{
var dense = denseOther.Data;
var diagonal = _data;
@@ -417,9 +404,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// The result of the multiplication.
protected override void DoTransposeThisAndMultiply(Matrix other, Matrix result)
{
- var diagonalOther = other as DiagonalMatrix;
- var diagonalResult = result as DiagonalMatrix;
- if (diagonalOther != null && diagonalResult != null)
+ if (other is DiagonalMatrix diagonalOther && result is DiagonalMatrix diagonalResult)
{
var thisDataCopy = new double[diagonalResult._data.Length];
var otherDataCopy = new double[diagonalResult._data.Length];
@@ -429,8 +414,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return;
}
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther)
{
var dense = denseOther.Data;
var diagonal = _data;
@@ -478,9 +462,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
if (d == RowCount)
{
- var denseOther = rightSide.Storage as DenseVectorStorage;
- var denseResult = result.Storage as DenseVectorStorage;
- if (denseOther != null && denseResult != null)
+ if (rightSide.Storage is DenseVectorStorage denseOther && result.Storage is DenseVectorStorage denseResult)
{
LinearAlgebraControl.Provider.PointWiseMultiplyArrays(_data, denseOther.Data, denseResult.Data);
return;
@@ -506,8 +488,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return;
}
- var diagResult = result as DiagonalMatrix;
- if (diagResult != null)
+ if (result is DiagonalMatrix diagResult)
{
LinearAlgebraControl.Provider.ScaleArray(1.0/divisor, _data, diagResult._data);
return;
@@ -527,8 +508,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// The matrix to store the result of the division.
protected override void DoDivideByThis(double dividend, Matrix result)
{
- var diagResult = result as DiagonalMatrix;
- if (diagResult != null)
+ if (result is DiagonalMatrix diagResult)
{
var resultData = diagResult._data;
CommonParallel.For(0, _data.Length, 4096, (a, b) =>
diff --git a/src/Numerics/LinearAlgebra/Double/Factorization/Svd.cs b/src/Numerics/LinearAlgebra/Double/Factorization/Svd.cs
index 24287a50..aab6fd73 100644
--- a/src/Numerics/LinearAlgebra/Double/Factorization/Svd.cs
+++ b/src/Numerics/LinearAlgebra/Double/Factorization/Svd.cs
@@ -72,13 +72,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization
/// Gets the two norm of the .
///
/// The 2-norm of the .
- public override double L2Norm
- {
- get
- {
- return Math.Abs(S[0]);
- }
- }
+ public override double L2Norm => Math.Abs(S[0]);
///
/// Gets the condition number max(S) / min(S)
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/GpBiCg.cs b/src/Numerics/LinearAlgebra/Double/Solvers/GpBiCg.cs
index 30e6063b..824d11b6 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/GpBiCg.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/GpBiCg.cs
@@ -80,10 +80,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
///
public int NumberOfBiCgStabSteps
{
- get
- {
- return _numberOfBiCgStabSteps;
- }
+ get => _numberOfBiCgStabSteps;
set
{
@@ -102,10 +99,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
///
public int NumberOfGpBiCgSteps
{
- get
- {
- return _numberOfGpbiCgSteps;
- }
+ get => _numberOfGpbiCgSteps;
set
{
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/ILUTPPreconditioner.cs b/src/Numerics/LinearAlgebra/Double/Solvers/ILUTPPreconditioner.cs
index b3ebd827..40d3e53f 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/ILUTPPreconditioner.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/ILUTPPreconditioner.cs
@@ -160,7 +160,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
/// Thrown if a negative value is provided.
public double FillLevel
{
- get { return _fillLevel; }
+ get => _fillLevel;
set
{
if (value < 0)
@@ -191,7 +191,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
/// Thrown if a negative value is provided.
public double DropTolerance
{
- get { return _dropTolerance; }
+ get => _dropTolerance;
set
{
if (value < 0)
@@ -224,7 +224,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
/// Thrown if a negative value is provided.
public double PivotTolerance
{
- get { return _pivotTolerance; }
+ get => _pivotTolerance;
set
{
if (value < 0)
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Double/Solvers/MlkBiCgStab.cs
index 3a7b7a89..3e6dead2 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/MlkBiCgStab.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/MlkBiCgStab.cs
@@ -87,10 +87,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
public int NumberOfStartingVectors
{
[DebuggerStepThrough]
- get
- {
- return _numberOfStartingVectors;
- }
+ get => _numberOfStartingVectors;
[DebuggerStepThrough]
set
@@ -119,10 +116,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
public IList> StartingVectors
{
[DebuggerStepThrough]
- get
- {
- return _startingVectors;
- }
+ get => _startingVectors;
[DebuggerStepThrough]
set
diff --git a/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
index 9ba6d093..f2b3d1cd 100644
--- a/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
@@ -51,10 +51,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// Gets the number of non zero elements in the matrix.
///
/// The number of non zero elements.
- public int NonZerosCount
- {
- get { return _storage.ValueCount; }
- }
+ public int NonZerosCount => _storage.ValueCount;
///
/// Create a new sparse matrix straight from an initialized matrix storage instance.
@@ -890,8 +887,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return;
}
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null && sparseResult != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther && sparseResult != null)
{
var diagonal = diagonalOther.Data;
if (other.ColumnCount == other.RowCount)
@@ -911,8 +907,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
var columnIndices = _storage.ColumnIndices;
var values = _storage.Values;
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther)
{
// in this case we can directly address the underlying data-array
for (var row = 0; row < RowCount; row++)
@@ -1561,7 +1556,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
public override string ToTypeString()
{
- return string.Format("SparseMatrix {0}x{1}-Double {2:P2} Filled", RowCount, ColumnCount, NonZerosCount / (RowCount * (double)ColumnCount));
+ return FormattableString.Invariant($"SparseMatrix {RowCount}x{ColumnCount}-Double {NonZerosCount / (RowCount * (double) ColumnCount):P2} Filled");
}
}
}
diff --git a/src/Numerics/LinearAlgebra/Double/SparseVector.cs b/src/Numerics/LinearAlgebra/Double/SparseVector.cs
index 63b88b5e..7cf97629 100644
--- a/src/Numerics/LinearAlgebra/Double/SparseVector.cs
+++ b/src/Numerics/LinearAlgebra/Double/SparseVector.cs
@@ -52,10 +52,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// Gets the number of non zero elements in the vector.
///
/// The number of non zero elements.
- public int NonZerosCount
- {
- get { return _storage.ValueCount; }
- }
+ public int NonZerosCount => _storage.ValueCount;
///
/// Create a new sparse vector straight from an initialized vector storage instance.
@@ -952,7 +949,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
public override string ToTypeString()
{
- return string.Format("SparseVector {0}-Double {1:P2} Filled", Count, NonZerosCount / (double)Count);
+ return FormattableString.Invariant($"SparseVector {Count}-Double {NonZerosCount / (double) Count:P2} Filled");
}
}
}
diff --git a/src/Numerics/LinearAlgebra/Factorization/LU.cs b/src/Numerics/LinearAlgebra/Factorization/LU.cs
index 3c6956e7..20e10da2 100644
--- a/src/Numerics/LinearAlgebra/Factorization/LU.cs
+++ b/src/Numerics/LinearAlgebra/Factorization/LU.cs
@@ -77,26 +77,17 @@ namespace MathNet.Numerics.LinearAlgebra.Factorization
///
/// Gets the lower triangular factor.
///
- public Matrix L
- {
- get { return _lazyL.Value; }
- }
+ public Matrix L => _lazyL.Value;
///
/// Gets the upper triangular factor.
///
- public Matrix U
- {
- get { return _lazyU.Value; }
- }
+ public Matrix U => _lazyU.Value;
///
/// Gets the permutation applied to LU factorization.
///
- public Permutation P
- {
- get { return _lazyP.Value; }
- }
+ public Permutation P => _lazyP.Value;
///
/// Gets the determinant of the matrix for which the LU factorization was computed.
diff --git a/src/Numerics/LinearAlgebra/Factorization/QR.cs b/src/Numerics/LinearAlgebra/Factorization/QR.cs
index e8ff0df4..25dfc895 100644
--- a/src/Numerics/LinearAlgebra/Factorization/QR.cs
+++ b/src/Numerics/LinearAlgebra/Factorization/QR.cs
@@ -80,15 +80,12 @@ namespace MathNet.Numerics.LinearAlgebra.Factorization
///
/// Gets or sets orthogonal Q matrix
///
- public Matrix Q { get; private set; }
+ public Matrix Q { get; }
///
/// Gets the upper triangular factor R.
///
- public Matrix R
- {
- get { return _lazyR.Value; }
- }
+ public Matrix R => _lazyR.Value;
///
/// Gets the absolute determinant value of the matrix for which the QR matrix was computed.
diff --git a/src/Numerics/LinearAlgebra/Factorization/Svd.cs b/src/Numerics/LinearAlgebra/Factorization/Svd.cs
index 58d513dd..6e38f1e2 100644
--- a/src/Numerics/LinearAlgebra/Factorization/Svd.cs
+++ b/src/Numerics/LinearAlgebra/Factorization/Svd.cs
@@ -88,26 +88,23 @@ namespace MathNet.Numerics.LinearAlgebra.Factorization
///
/// Gets the singular values (Σ) of matrix in ascending value.
///
- public Vector S { get; private set; }
+ public Vector S { get; }
///
/// Gets the left singular vectors (U - m-by-m unitary matrix)
///
- public Matrix U { get; private set; }
+ public Matrix U { get; }
///
/// Gets the transpose right singular vectors (transpose of V, an n-by-n unitary matrix)
///
- public Matrix VT { get; private set; }
+ public Matrix VT { get; }
///
/// Returns the singular values as a diagonal .
///
/// The singular values as a diagonal .
- public Matrix W
- {
- get { return _lazyW.Value; }
- }
+ public Matrix W => _lazyW.Value;
///
/// Gets the effective numerical matrix rank.
diff --git a/src/Numerics/LinearAlgebra/Matrix.BCL.cs b/src/Numerics/LinearAlgebra/Matrix.BCL.cs
index 7ff14089..e1e0613c 100644
--- a/src/Numerics/LinearAlgebra/Matrix.BCL.cs
+++ b/src/Numerics/LinearAlgebra/Matrix.BCL.cs
@@ -62,8 +62,7 @@ namespace MathNet.Numerics.LinearAlgebra
///
public override bool Equals(object obj)
{
- var other = obj as Matrix;
- return other != null && Storage.Equals(other.Storage);
+ return obj is Matrix other && Storage.Equals(other.Storage);
}
///
@@ -97,7 +96,7 @@ namespace MathNet.Numerics.LinearAlgebra
///
public virtual string ToTypeString()
{
- return string.Format("{0} {1}x{2}-{3}", GetType().Name, RowCount, ColumnCount, typeof (T).Name);
+ return FormattableString.Invariant($"{GetType().Name} {RowCount}x{ColumnCount}-{typeof(T).Name}");
}
///
diff --git a/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
index 607e0d16..5e5f5964 100644
--- a/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
@@ -393,10 +393,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// Gets the matrix's data.
///
/// The matrix's data.
- public float[] Values
- {
- get { return _values; }
- }
+ public float[] Values => _values;
/// Calculates the induced L1 norm of this matrix.
/// The maximum absolute column sum of the matrix.
@@ -425,8 +422,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// The result of the negation.
protected override void DoNegate(Matrix result)
{
- var denseResult = result as DenseMatrix;
- if (denseResult != null)
+ if (result is DenseMatrix denseResult)
{
LinearAlgebraControl.Provider.ScaleArray(-1, _values, denseResult._values);
return;
@@ -469,17 +465,14 @@ namespace MathNet.Numerics.LinearAlgebra.Single
protected override void DoAdd(Matrix other, Matrix result)
{
// dense + dense = dense
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- var denseResult = result.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null && denseResult != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther && result.Storage is DenseColumnMajorMatrixStorage denseResult)
{
LinearAlgebraControl.Provider.AddArrays(_values, denseOther.Data, denseResult.Data);
return;
}
// dense + diagonal = any
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
Storage.CopyToUnchecked(result.Storage, ExistingData.Clear);
var diagonal = diagonalOther.Data;
@@ -525,17 +518,14 @@ namespace MathNet.Numerics.LinearAlgebra.Single
protected override void DoSubtract(Matrix other, Matrix result)
{
// dense + dense = dense
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- var denseResult = result.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null && denseResult != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther && result.Storage is DenseColumnMajorMatrixStorage denseResult)
{
LinearAlgebraControl.Provider.SubtractArrays(_values, denseOther.Data, denseResult.Data);
return;
}
// dense + diagonal = matrix
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
CopyTo(result);
var diagonal = diagonalOther.Data;
@@ -601,9 +591,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// The result of the multiplication.
protected override void DoMultiply(Matrix other, Matrix result)
{
- var denseOther = other as DenseMatrix;
- var denseResult = result as DenseMatrix;
- if (denseOther != null && denseResult != null)
+ if (other is DenseMatrix denseOther && result is DenseMatrix denseResult)
{
LinearAlgebraControl.Provider.MatrixMultiply(
_values,
@@ -616,8 +604,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return;
}
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
var diagonal = diagonalOther.Data;
var d = Math.Min(ColumnCount, other.ColumnCount);
@@ -647,9 +634,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// The result of the multiplication.
protected override void DoTransposeAndMultiply(Matrix other, Matrix result)
{
- var denseOther = other as DenseMatrix;
- var denseResult = result as DenseMatrix;
- if (denseOther != null && denseResult != null)
+ if (other is DenseMatrix denseOther && result is DenseMatrix denseResult)
{
LinearAlgebraControl.Provider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.DontTranspose,
@@ -666,8 +651,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return;
}
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
var diagonal = diagonalOther.Data;
var d = Math.Min(ColumnCount, other.RowCount);
@@ -697,14 +681,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// The result of the multiplication.
protected override void DoTransposeThisAndMultiply(Vector rightSide, Vector result)
{
- var denseRight = rightSide as DenseVector;
- var denseResult = result as DenseVector;
-
- if (denseRight == null || denseResult == null)
- {
- base.DoTransposeThisAndMultiply(rightSide, result);
- }
- else
+ if (rightSide is DenseVector denseRight && result is DenseVector denseResult)
{
LinearAlgebraControl.Provider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.Transpose,
@@ -719,6 +696,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single
0.0f,
denseResult.Values);
}
+ else
+ {
+ base.DoTransposeThisAndMultiply(rightSide, result);
+ }
}
///
@@ -728,9 +709,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// The result of the multiplication.
protected override void DoTransposeThisAndMultiply(Matrix other, Matrix result)
{
- var denseOther = other as DenseMatrix;
- var denseResult = result as DenseMatrix;
- if (denseOther != null && denseResult != null)
+ if (other is DenseMatrix denseOther && result is DenseMatrix denseResult)
{
LinearAlgebraControl.Provider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.Transpose,
@@ -747,8 +726,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return;
}
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther)
{
var diagonal = diagonalOther.Data;
var d = Math.Min(RowCount, other.ColumnCount);
diff --git a/src/Numerics/LinearAlgebra/Single/DenseVector.cs b/src/Numerics/LinearAlgebra/Single/DenseVector.cs
index dc1c91a4..a8a789f6 100644
--- a/src/Numerics/LinearAlgebra/Single/DenseVector.cs
+++ b/src/Numerics/LinearAlgebra/Single/DenseVector.cs
@@ -162,10 +162,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// Gets the vector's data.
///
/// The vector's data.
- public float[] Values
- {
- get { return _values; }
- }
+ public float[] Values => _values;
///
/// Returns a reference to the internal data structure.
diff --git a/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
index 99a547d6..e16dce4a 100644
--- a/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
@@ -190,8 +190,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// The result of the negation.
protected override void DoNegate(Matrix result)
{
- var diagResult = result as DiagonalMatrix;
- if (diagResult != null)
+ if (result is DiagonalMatrix diagResult)
{
LinearAlgebraControl.Provider.ScaleArray(-1, _data, diagResult._data);
return;
@@ -213,9 +212,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
protected override void DoAdd(Matrix other, Matrix result)
{
// diagonal + diagonal = diagonal
- var diagOther = other as DiagonalMatrix;
- var diagResult = result as DiagonalMatrix;
- if (diagOther != null && diagResult != null)
+ if (other is DiagonalMatrix diagOther && result is DiagonalMatrix diagResult)
{
LinearAlgebraControl.Provider.AddArrays(_data, diagOther._data, diagResult._data);
return;
@@ -237,9 +234,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
protected override void DoSubtract(Matrix other, Matrix result)
{
// diagonal - diagonal = diagonal
- var diagOther = other as DiagonalMatrix;
- var diagResult = result as DiagonalMatrix;
- if (diagOther != null && diagResult != null)
+ if (other is DiagonalMatrix diagOther && result is DiagonalMatrix diagResult)
{
LinearAlgebraControl.Provider.SubtractArrays(_data, diagOther._data, diagResult._data);
return;
@@ -298,9 +293,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
if (d == ColumnCount)
{
- var denseOther = rightSide.Storage as DenseVectorStorage;
- var denseResult = result.Storage as DenseVectorStorage;
- if (denseOther != null && denseResult != null)
+ if (rightSide.Storage is DenseVectorStorage denseOther && result.Storage is DenseVectorStorage denseResult)
{
LinearAlgebraControl.Provider.PointWiseMultiplyArrays(_data, denseOther.Data, denseResult.Data);
return;
@@ -320,9 +313,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// The result of the multiplication.
protected override void DoMultiply(Matrix other, Matrix result)
{
- var diagonalOther = other as DiagonalMatrix;
- var diagonalResult = result as DiagonalMatrix;
- if (diagonalOther != null && diagonalResult != null)
+ if (other is DiagonalMatrix diagonalOther && result is DiagonalMatrix diagonalResult)
{
var thisDataCopy = new float[diagonalResult._data.Length];
var otherDataCopy = new float[diagonalResult._data.Length];
@@ -332,8 +323,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return;
}
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther)
{
var dense = denseOther.Data;
var diagonal = _data;
@@ -373,9 +363,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// The result of the multiplication.
protected override void DoTransposeAndMultiply(Matrix other, Matrix result)
{
- var diagonalOther = other as DiagonalMatrix;
- var diagonalResult = result as DiagonalMatrix;
- if (diagonalOther != null && diagonalResult != null)
+ if (other is DiagonalMatrix diagonalOther && result is DiagonalMatrix diagonalResult)
{
var thisDataCopy = new float[diagonalResult._data.Length];
var otherDataCopy = new float[diagonalResult._data.Length];
@@ -385,8 +373,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return;
}
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther)
{
var dense = denseOther.Data;
var diagonal = _data;
@@ -417,9 +404,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// The result of the multiplication.
protected override void DoTransposeThisAndMultiply(Matrix other, Matrix result)
{
- var diagonalOther = other as DiagonalMatrix;
- var diagonalResult = result as DiagonalMatrix;
- if (diagonalOther != null && diagonalResult != null)
+ if (other is DiagonalMatrix diagonalOther && result is DiagonalMatrix diagonalResult)
{
var thisDataCopy = new float[diagonalResult._data.Length];
var otherDataCopy = new float[diagonalResult._data.Length];
@@ -429,8 +414,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return;
}
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther)
{
var dense = denseOther.Data;
var diagonal = _data;
@@ -478,9 +462,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
if (d == RowCount)
{
- var denseOther = rightSide.Storage as DenseVectorStorage;
- var denseResult = result.Storage as DenseVectorStorage;
- if (denseOther != null && denseResult != null)
+ if (rightSide.Storage is DenseVectorStorage denseOther && result.Storage is DenseVectorStorage denseResult)
{
LinearAlgebraControl.Provider.PointWiseMultiplyArrays(_data, denseOther.Data, denseResult.Data);
return;
@@ -506,8 +488,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return;
}
- var diagResult = result as DiagonalMatrix;
- if (diagResult != null)
+ if (result is DiagonalMatrix diagResult)
{
LinearAlgebraControl.Provider.ScaleArray(1.0f/divisor, _data, diagResult._data);
return;
@@ -527,8 +508,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// The matrix to store the result of the division.
protected override void DoDivideByThis(float dividend, Matrix result)
{
- var diagResult = result as DiagonalMatrix;
- if (diagResult != null)
+ if (result is DiagonalMatrix diagResult)
{
var resultData = diagResult._data;
CommonParallel.For(0, _data.Length, 4096, (a, b) =>
diff --git a/src/Numerics/LinearAlgebra/Single/Factorization/Svd.cs b/src/Numerics/LinearAlgebra/Single/Factorization/Svd.cs
index 19687317..da14c79e 100644
--- a/src/Numerics/LinearAlgebra/Single/Factorization/Svd.cs
+++ b/src/Numerics/LinearAlgebra/Single/Factorization/Svd.cs
@@ -72,13 +72,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization
/// Gets the two norm of the .
///
/// The 2-norm of the .
- public override double L2Norm
- {
- get
- {
- return Math.Abs(S[0]);
- }
- }
+ public override double L2Norm => Math.Abs(S[0]);
///
/// Gets the condition number max(S) / min(S)
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/GpBiCg.cs b/src/Numerics/LinearAlgebra/Single/Solvers/GpBiCg.cs
index 27222852..20864c30 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/GpBiCg.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/GpBiCg.cs
@@ -80,7 +80,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
///
public int NumberOfBiCgStabSteps
{
- get { return _numberOfBiCgStabSteps; }
+ get => _numberOfBiCgStabSteps;
set
{
@@ -99,7 +99,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
///
public int NumberOfGpBiCgSteps
{
- get { return _numberOfGpbiCgSteps; }
+ get => _numberOfGpbiCgSteps;
set
{
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/ILUTPPreconditioner.cs b/src/Numerics/LinearAlgebra/Single/Solvers/ILUTPPreconditioner.cs
index 723f9722..fc4b403e 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/ILUTPPreconditioner.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/ILUTPPreconditioner.cs
@@ -160,7 +160,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
/// Thrown if a negative value is provided.
public double FillLevel
{
- get { return _fillLevel; }
+ get => _fillLevel;
set
{
if (value < 0)
@@ -191,7 +191,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
/// Thrown if a negative value is provided.
public double DropTolerance
{
- get { return _dropTolerance; }
+ get => _dropTolerance;
set
{
if (value < 0)
@@ -224,7 +224,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
/// Thrown if a negative value is provided.
public double PivotTolerance
{
- get { return _pivotTolerance; }
+ get => _pivotTolerance;
set
{
if (value < 0)
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Single/Solvers/MlkBiCgStab.cs
index 51c3b72f..2c89b1bc 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/MlkBiCgStab.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/MlkBiCgStab.cs
@@ -86,10 +86,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
public int NumberOfStartingVectors
{
[DebuggerStepThrough]
- get
- {
- return _numberOfStartingVectors;
- }
+ get => _numberOfStartingVectors;
[DebuggerStepThrough]
set
@@ -118,10 +115,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
public IList> StartingVectors
{
[DebuggerStepThrough]
- get
- {
- return _startingVectors;
- }
+ get => _startingVectors;
[DebuggerStepThrough]
set
diff --git a/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
index 1318f9e1..e0f92453 100644
--- a/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
@@ -52,10 +52,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// Gets the number of non zero elements in the matrix.
///
/// The number of non zero elements.
- public int NonZerosCount
- {
- get { return _storage.ValueCount; }
- }
+ public int NonZerosCount => _storage.ValueCount;
///
/// Create a new sparse matrix straight from an initialized matrix storage instance.
@@ -894,8 +891,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return;
}
- var diagonalOther = other.Storage as DiagonalMatrixStorage;
- if (diagonalOther != null && sparseResult != null)
+ if (other.Storage is DiagonalMatrixStorage diagonalOther && sparseResult != null)
{
var diagonal = diagonalOther.Data;
if (other.ColumnCount == other.RowCount)
@@ -914,8 +910,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
var rowPointers = _storage.RowPointers;
var columnIndices = _storage.ColumnIndices;
var values = _storage.Values;
- var denseOther = other.Storage as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other.Storage is DenseColumnMajorMatrixStorage denseOther)
{
// in this case we can directly address the underlying data-array
for (var row = 0; row < RowCount; row++)
@@ -1568,7 +1563,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
public override string ToTypeString()
{
- return string.Format("SparseMatrix {0}x{1}-Single {2:P2} Filled", RowCount, ColumnCount, NonZerosCount / (RowCount * (double)ColumnCount));
+ return FormattableString.Invariant($"SparseMatrix {RowCount}x{ColumnCount}-Single {NonZerosCount / (RowCount * (double) ColumnCount):P2} Filled");
}
}
}
diff --git a/src/Numerics/LinearAlgebra/Single/SparseVector.cs b/src/Numerics/LinearAlgebra/Single/SparseVector.cs
index 384e29a2..6105a1e0 100644
--- a/src/Numerics/LinearAlgebra/Single/SparseVector.cs
+++ b/src/Numerics/LinearAlgebra/Single/SparseVector.cs
@@ -52,10 +52,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// Gets the number of non zero elements in the vector.
///
/// The number of non zero elements.
- public int NonZerosCount
- {
- get { return _storage.ValueCount; }
- }
+ public int NonZerosCount => _storage.ValueCount;
///
/// Create a new sparse vector straight from an initialized vector storage instance.
@@ -953,7 +950,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
public override string ToTypeString()
{
- return string.Format("SparseVector {0}-Single {1:P2} Filled", Count, NonZerosCount / (double)Count);
+ return FormattableString.Invariant($"SparseVector {Count}-Single {NonZerosCount / (double) Count:P2} Filled");
}
}
}
diff --git a/src/Numerics/LinearAlgebra/Solvers/CancellationStopCriterion.cs b/src/Numerics/LinearAlgebra/Solvers/CancellationStopCriterion.cs
index b8d05d19..75b27155 100644
--- a/src/Numerics/LinearAlgebra/Solvers/CancellationStopCriterion.cs
+++ b/src/Numerics/LinearAlgebra/Solvers/CancellationStopCriterion.cs
@@ -83,7 +83,7 @@ namespace MathNet.Numerics.LinearAlgebra.Solvers
public IterationStatus Status
{
[DebuggerStepThrough]
- get { return _currentTcs.Token.IsCancellationRequested ? IterationStatus.Cancelled : IterationStatus.Continue; }
+ get => _currentTcs.Token.IsCancellationRequested ? IterationStatus.Cancelled : IterationStatus.Continue;
}
public void Cancel()
diff --git a/src/Numerics/LinearAlgebra/Solvers/DelegateStopCriterion.cs b/src/Numerics/LinearAlgebra/Solvers/DelegateStopCriterion.cs
index 73f650db..72572c31 100644
--- a/src/Numerics/LinearAlgebra/Solvers/DelegateStopCriterion.cs
+++ b/src/Numerics/LinearAlgebra/Solvers/DelegateStopCriterion.cs
@@ -70,10 +70,7 @@ namespace MathNet.Numerics.LinearAlgebra.Solvers
///
/// Gets the current calculation status.
///
- public IterationStatus Status
- {
- get { return _status; }
- }
+ public IterationStatus Status => _status;
///
/// Resets the IIterationStopCriterion to the pre-calculation state.
diff --git a/src/Numerics/LinearAlgebra/Solvers/DivergenceStopCriterion.cs b/src/Numerics/LinearAlgebra/Solvers/DivergenceStopCriterion.cs
index 35f8fc78..e385fcc0 100644
--- a/src/Numerics/LinearAlgebra/Solvers/DivergenceStopCriterion.cs
+++ b/src/Numerics/LinearAlgebra/Solvers/DivergenceStopCriterion.cs
@@ -92,7 +92,7 @@ namespace MathNet.Numerics.LinearAlgebra.Solvers
public double MaximumRelativeIncrease
{
[DebuggerStepThrough]
- get { return _maximumRelativeIncrease; }
+ get => _maximumRelativeIncrease;
[DebuggerStepThrough]
set
@@ -114,7 +114,7 @@ namespace MathNet.Numerics.LinearAlgebra.Solvers
public int MinimumNumberOfIterations
{
[DebuggerStepThrough]
- get { return _minimumNumberOfIterations; }
+ get => _minimumNumberOfIterations;
[DebuggerStepThrough]
set
@@ -220,7 +220,7 @@ namespace MathNet.Numerics.LinearAlgebra.Solvers
int RequiredHistoryLength
{
[DebuggerStepThrough]
- get { return _minimumNumberOfIterations + 1; }
+ get => _minimumNumberOfIterations + 1;
}
///
@@ -229,7 +229,7 @@ namespace MathNet.Numerics.LinearAlgebra.Solvers
public IterationStatus Status
{
[DebuggerStepThrough]
- get { return _status; }
+ get => _status;
}
///
diff --git a/src/Numerics/LinearAlgebra/Solvers/FailureStopCriterion.cs b/src/Numerics/LinearAlgebra/Solvers/FailureStopCriterion.cs
index b4a534cf..ef626fcc 100644
--- a/src/Numerics/LinearAlgebra/Solvers/FailureStopCriterion.cs
+++ b/src/Numerics/LinearAlgebra/Solvers/FailureStopCriterion.cs
@@ -96,7 +96,7 @@ namespace MathNet.Numerics.LinearAlgebra.Solvers
public IterationStatus Status
{
[DebuggerStepThrough]
- get { return _status; }
+ get => _status;
}
///
diff --git a/src/Numerics/LinearAlgebra/Solvers/IterationCountStopCriterion.cs b/src/Numerics/LinearAlgebra/Solvers/IterationCountStopCriterion.cs
index d9598379..87d46fd1 100644
--- a/src/Numerics/LinearAlgebra/Solvers/IterationCountStopCriterion.cs
+++ b/src/Numerics/LinearAlgebra/Solvers/IterationCountStopCriterion.cs
@@ -84,7 +84,7 @@ namespace MathNet.Numerics.LinearAlgebra.Solvers
public int MaximumNumberOfIterations
{
[DebuggerStepThrough]
- get { return _maximumNumberOfIterations; }
+ get => _maximumNumberOfIterations;
[DebuggerStepThrough]
set
@@ -137,7 +137,7 @@ namespace MathNet.Numerics.LinearAlgebra.Solvers
public IterationStatus Status
{
[DebuggerStepThrough]
- get { return _status; }
+ get => _status;
}
///
diff --git a/src/Numerics/LinearAlgebra/Solvers/Iterator.cs b/src/Numerics/LinearAlgebra/Solvers/Iterator.cs
index 2325aad8..6f4c4c7c 100644
--- a/src/Numerics/LinearAlgebra/Solvers/Iterator.cs
+++ b/src/Numerics/LinearAlgebra/Solvers/Iterator.cs
@@ -85,10 +85,7 @@ namespace MathNet.Numerics.LinearAlgebra.Solvers
///
/// Gets the current calculation status.
///
- public IterationStatus Status
- {
- get { return _status; }
- }
+ public IterationStatus Status => _status;
///
/// Determines the status of the iterative calculation based on the stop criteria stored
diff --git a/src/Numerics/LinearAlgebra/Solvers/ResidualStopCriterion.cs b/src/Numerics/LinearAlgebra/Solvers/ResidualStopCriterion.cs
index 12bedf87..9abf0f68 100644
--- a/src/Numerics/LinearAlgebra/Solvers/ResidualStopCriterion.cs
+++ b/src/Numerics/LinearAlgebra/Solvers/ResidualStopCriterion.cs
@@ -99,7 +99,7 @@ namespace MathNet.Numerics.LinearAlgebra.Solvers
public double Maximum
{
[DebuggerStepThrough]
- get { return _maximum; }
+ get => _maximum;
[DebuggerStepThrough]
set
@@ -121,7 +121,7 @@ namespace MathNet.Numerics.LinearAlgebra.Solvers
public int MinimumIterationsBelowMaximum
{
[DebuggerStepThrough]
- get { return _minimumIterationsBelowMaximum; }
+ get => _minimumIterationsBelowMaximum;
[DebuggerStepThrough]
set
@@ -220,7 +220,7 @@ namespace MathNet.Numerics.LinearAlgebra.Solvers
public IterationStatus Status
{
[DebuggerStepThrough]
- get { return _status; }
+ get => _status;
}
///
diff --git a/src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs b/src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs
index 8056aab6..1fe7108c 100644
--- a/src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs
+++ b/src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs
@@ -71,19 +71,13 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
///
/// True if the matrix storage format is dense.
///
- public override bool IsDense
- {
- get { return true; }
- }
+ public override bool IsDense => true;
///
/// True if all fields of this matrix can be set to any value.
/// False if some fields are fixed, like on a diagonal matrix.
///
- public override bool IsFullyMutable
- {
- get { return true; }
- }
+ public override bool IsFullyMutable => true;
///
/// True if the specified field can be set to any value.
@@ -300,8 +294,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
for (int j = 0; j < data.Length; j++)
{
var column = data[j];
- var denseColumn = column as DenseVectorStorage;
- if (denseColumn != null)
+ if (column is DenseVectorStorage denseColumn)
{
Array.Copy(denseColumn.Data, 0, array, j*rows, rows);
}
@@ -351,8 +344,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
public static DenseColumnMajorMatrixStorage OfColumnMajorEnumerable(int rows, int columns, IEnumerable data)
{
- var arrayData = data as T[];
- if (arrayData != null)
+ if (data is T[] arrayData)
{
return OfColumnMajorArray(rows, columns, arrayData);
}
@@ -373,8 +365,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
for (int column = 0; column < columns; column++)
{
if (!columnIterator.MoveNext()) throw new ArgumentOutOfRangeException(nameof(data), string.Format(Resources.ArgumentArrayWrongLength, columns));
- var arrayColumn = columnIterator.Current as T[];
- if (arrayColumn != null)
+ if (columnIterator.Current is T[] arrayColumn)
{
Array.Copy(arrayColumn, 0, array, column*rows, rows);
}
@@ -424,8 +415,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override void CopyToUnchecked(MatrixStorage target, ExistingData existingData)
{
- var denseTarget = target as DenseColumnMajorMatrixStorage;
- if (denseTarget != null)
+ if (target is DenseColumnMajorMatrixStorage denseTarget)
{
CopyToUnchecked(denseTarget);
return;
@@ -453,8 +443,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
int sourceColumnIndex, int targetColumnIndex, int columnCount,
ExistingData existingData)
{
- var denseTarget = target as DenseColumnMajorMatrixStorage;
- if (denseTarget != null)
+ if (target is DenseColumnMajorMatrixStorage denseTarget)
{
CopySubMatrixToUnchecked(denseTarget, sourceRowIndex, targetRowIndex, rowCount, sourceColumnIndex, targetColumnIndex, columnCount);
return;
@@ -490,8 +479,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override void CopySubRowToUnchecked(VectorStorage target, int rowIndex, int sourceColumnIndex, int targetColumnIndex, int columnCount,
ExistingData existingData)
{
- var targetDense = target as DenseVectorStorage;
- if (targetDense != null)
+ if (target is DenseVectorStorage targetDense)
{
for (int j = 0; j < columnCount; j++)
{
@@ -513,8 +501,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override void CopySubColumnToUnchecked(VectorStorage target, int columnIndex, int sourceRowIndex, int targetRowIndex, int rowCount,
ExistingData existingData)
{
- var targetDense = target as DenseVectorStorage;
- if (targetDense != null)
+ if (target is DenseVectorStorage targetDense)
{
Array.Copy(Data, columnIndex*RowCount + sourceRowIndex, targetDense.Data, targetRowIndex, rowCount);
return;
@@ -533,15 +520,13 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override void TransposeToUnchecked(MatrixStorage target, ExistingData existingData)
{
- var denseTarget = target as DenseColumnMajorMatrixStorage;
- if (denseTarget != null)
+ if (target is DenseColumnMajorMatrixStorage denseTarget)
{
TransposeToUnchecked(denseTarget);
return;
}
- var sparseTarget = target as SparseCompressedRowMatrixStorage;
- if (sparseTarget != null)
+ if (target is SparseCompressedRowMatrixStorage sparseTarget)
{
TransposeToUnchecked(sparseTarget);
return;
@@ -743,8 +728,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override Tuple Find2Unchecked(MatrixStorage other, Func predicate, Zeros zeros)
{
- var denseOther = other as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other is DenseColumnMajorMatrixStorage denseOther)
{
TOther[] otherData = denseOther.Data;
for (int i = 0; i < Data.Length; i++)
@@ -760,8 +744,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return null;
}
- var diagonalOther = other as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other is DiagonalMatrixStorage diagonalOther)
{
TOther[] otherData = diagonalOther.Data;
TOther otherZero = BuilderInstance.Matrix.Zero;
@@ -780,8 +763,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return null;
}
- var sparseOther = other as SparseCompressedRowMatrixStorage;
- if (sparseOther != null)
+ if (other is SparseCompressedRowMatrixStorage sparseOther)
{
int[] otherRowPointers = sparseOther.RowPointers;
int[] otherColumnIndices = sparseOther.ColumnIndices;
@@ -849,8 +831,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override void MapToUnchecked(MatrixStorage target, Func f,
Zeros zeros, ExistingData existingData)
{
- var denseTarget = target as DenseColumnMajorMatrixStorage;
- if (denseTarget != null)
+ if (target is DenseColumnMajorMatrixStorage denseTarget)
{
CommonParallel.For(0, Data.Length, 4096, (a, b) =>
{
@@ -877,8 +858,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override void MapIndexedToUnchecked(MatrixStorage target, Func f,
Zeros zeros, ExistingData existingData)
{
- var denseTarget = target as DenseColumnMajorMatrixStorage;
- if (denseTarget != null)
+ if (target is DenseColumnMajorMatrixStorage denseTarget)
{
CommonParallel.For(0, ColumnCount, Math.Max(4096/RowCount, 32), (a, b) =>
{
@@ -912,8 +892,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
int sourceColumnIndex, int targetColumnIndex, int columnCount,
Zeros zeros, ExistingData existingData)
{
- var denseTarget = target as DenseColumnMajorMatrixStorage;
- if (denseTarget != null)
+ if (target is DenseColumnMajorMatrixStorage denseTarget)
{
CommonParallel.For(0, columnCount, Math.Max(4096/rowCount, 32), (a, b) =>
{
@@ -975,8 +954,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override TState Fold2Unchecked(MatrixStorage other, Func f, TState state, Zeros zeros)
{
- var denseOther = other as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other is DenseColumnMajorMatrixStorage denseOther)
{
TOther[] otherData = denseOther.Data;
for (int i = 0; i < Data.Length; i++)
@@ -986,8 +964,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return state;
}
- var diagonalOther = other as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other is DiagonalMatrixStorage diagonalOther)
{
TOther[] otherData = diagonalOther.Data;
TOther otherZero = BuilderInstance.Matrix.Zero;
@@ -1003,8 +980,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return state;
}
- var sparseOther = other as SparseCompressedRowMatrixStorage;
- if (sparseOther != null)
+ if (other is SparseCompressedRowMatrixStorage sparseOther)
{
int[] otherRowPointers = sparseOther.RowPointers;
int[] otherColumnIndices = sparseOther.ColumnIndices;
diff --git a/src/Numerics/LinearAlgebra/Storage/DenseVectorStorage.cs b/src/Numerics/LinearAlgebra/Storage/DenseVectorStorage.cs
index 9a3a9df9..97050b6d 100644
--- a/src/Numerics/LinearAlgebra/Storage/DenseVectorStorage.cs
+++ b/src/Numerics/LinearAlgebra/Storage/DenseVectorStorage.cs
@@ -71,10 +71,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
///
/// True if the vector storage format is dense.
///
- public override bool IsDense
- {
- get { return true; }
- }
+ public override bool IsDense => true;
///
/// Retrieves the requested element without range checking.
@@ -156,8 +153,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
throw new ArgumentNullException(nameof(data));
}
- var arrayData = data as T[];
- if (arrayData != null)
+ if (data is T[] arrayData)
{
var copy = new T[arrayData.Length];
Array.Copy(arrayData, 0, copy, 0, arrayData.Length);
@@ -187,8 +183,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override void CopyToUnchecked(VectorStorage target, ExistingData existingData)
{
- var denseTarget = target as DenseVectorStorage;
- if (denseTarget != null)
+ if (target is DenseVectorStorage denseTarget)
{
if (!ReferenceEquals(this, denseTarget))
{
@@ -198,8 +193,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return;
}
- var sparseTarget = target as SparseVectorStorage;
- if (sparseTarget != null)
+ if (target is SparseVectorStorage sparseTarget)
{
var indices = new List();
var values = new List();
@@ -232,8 +226,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override void CopyToRowUnchecked(MatrixStorage target, int rowIndex, ExistingData existingData)
{
- var denseTarget = target as DenseColumnMajorMatrixStorage;
- if (denseTarget != null)
+ if (target is DenseColumnMajorMatrixStorage denseTarget)
{
for (int j = 0; j < Data.Length; j++)
{
@@ -254,8 +247,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override void CopyToColumnUnchecked(MatrixStorage target, int columnIndex, ExistingData existingData)
{
- var denseTarget = target as DenseColumnMajorMatrixStorage;
- if (denseTarget != null)
+ if (target is DenseColumnMajorMatrixStorage denseTarget)
{
Array.Copy(Data, 0, denseTarget.Data, columnIndex*denseTarget.RowCount, Data.Length);
return;
@@ -274,8 +266,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override void CopySubVectorToUnchecked(VectorStorage target,
int sourceIndex, int targetIndex, int count, ExistingData existingData)
{
- var denseTarget = target as DenseVectorStorage;
- if (denseTarget != null)
+ if (target is DenseVectorStorage denseTarget)
{
Array.Copy(Data, sourceIndex, denseTarget.Data, targetIndex, count);
return;
@@ -291,8 +282,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override void CopyToSubRowUnchecked(MatrixStorage target, int rowIndex,
int sourceColumnIndex, int targetColumnIndex, int columnCount, ExistingData existingData)
{
- var denseTarget = target as DenseColumnMajorMatrixStorage;
- if (denseTarget != null)
+ if (target is DenseColumnMajorMatrixStorage denseTarget)
{
for (int j = 0; j < Data.Length; j++)
{
@@ -314,8 +304,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override void CopyToSubColumnUnchecked(MatrixStorage target, int columnIndex,
int sourceRowIndex, int targetRowIndex, int rowCount, ExistingData existingData)
{
- var denseTarget = target as DenseColumnMajorMatrixStorage;
- if (denseTarget != null)
+ if (target is DenseColumnMajorMatrixStorage denseTarget)
{
Array.Copy(Data, sourceRowIndex, denseTarget.Data, columnIndex*denseTarget.RowCount + targetRowIndex, rowCount);
return;
@@ -387,8 +376,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override Tuple Find2Unchecked(VectorStorage other, Func predicate, Zeros zeros)
{
- var denseOther = other as DenseVectorStorage;
- if (denseOther != null)
+ if (other is DenseVectorStorage denseOther)
{
TOther[] otherData = denseOther.Data;
for (int i = 0; i < Data.Length; i++)
@@ -402,8 +390,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return null;
}
- var sparseOther = other as SparseVectorStorage;
- if (sparseOther != null)
+ if (other is SparseVectorStorage sparseOther)
{
int[] otherIndices = sparseOther.Indices;
TOther[] otherValues = sparseOther.Values;
@@ -462,8 +449,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override void MapToUnchecked(VectorStorage target, Func f, Zeros zeros, ExistingData existingData)
{
- var denseTarget = target as DenseVectorStorage;
- if (denseTarget != null)
+ if (target is DenseVectorStorage denseTarget)
{
CommonParallel.For(0, Data.Length, 4096, (a, b) =>
{
@@ -485,8 +471,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override void MapIndexedToUnchecked(VectorStorage target, Func f, Zeros zeros, ExistingData existingData)
{
- var denseTarget = target as DenseVectorStorage;
- if (denseTarget != null)
+ if (target is DenseVectorStorage denseTarget)
{
CommonParallel.For(0, Data.Length, 4096, (a, b) =>
{
@@ -519,8 +504,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
}
var denseTarget = target as DenseVectorStorage;
- var denseOther = other as DenseVectorStorage;
- if (denseTarget != null && denseOther != null)
+ if (denseTarget != null && other is DenseVectorStorage denseOther)
{
CommonParallel.For(0, Data.Length, 4096, (a, b) =>
{
@@ -533,8 +517,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return;
}
- var sparseOther = other as SparseVectorStorage;
- if (denseTarget != null && sparseOther != null)
+ if (denseTarget != null && other is SparseVectorStorage sparseOther)
{
T[] targetData = denseTarget.Data;
int[] otherIndices = sparseOther.Indices;
@@ -565,8 +548,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override TState Fold2Unchecked(VectorStorage other, Func f, TState state, Zeros zeros)
{
- var denseOther = other as DenseVectorStorage;
- if (denseOther != null)
+ if (other is DenseVectorStorage denseOther)
{
var otherData = denseOther.Data;
for (int i = 0; i < Data.Length; i++)
@@ -577,8 +559,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return state;
}
- var sparseOther = other as SparseVectorStorage;
- if (sparseOther != null)
+ if (other is SparseVectorStorage sparseOther)
{
int[] otherIndices = sparseOther.Indices;
TOther[] otherValues = sparseOther.Values;
diff --git a/src/Numerics/LinearAlgebra/Storage/DiagonalMatrixStorage.cs b/src/Numerics/LinearAlgebra/Storage/DiagonalMatrixStorage.cs
index b834e0be..b4e75806 100644
--- a/src/Numerics/LinearAlgebra/Storage/DiagonalMatrixStorage.cs
+++ b/src/Numerics/LinearAlgebra/Storage/DiagonalMatrixStorage.cs
@@ -71,19 +71,13 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
///
/// True if the matrix storage format is dense.
///
- public override bool IsDense
- {
- get { return false; }
- }
+ public override bool IsDense => false;
///
/// True if all fields of this matrix can be set to any value.
/// False if some fields are fixed, like on a diagonal matrix.
///
- public override bool IsFullyMutable
- {
- get { return false; }
- }
+ public override bool IsFullyMutable => false;
///
/// True if the specified field can be set to any value.
@@ -226,8 +220,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
throw new ArgumentNullException(nameof(data));
}
- var arrayData = data as T[];
- if (arrayData != null)
+ if (data is T[] arrayData)
{
var copy = new T[arrayData.Length];
Array.Copy(arrayData, 0, copy, 0, arrayData.Length);
@@ -256,22 +249,19 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override void CopyToUnchecked(MatrixStorage target, ExistingData existingData)
{
- var diagonalTarget = target as DiagonalMatrixStorage;
- if (diagonalTarget != null)
+ if (target is DiagonalMatrixStorage diagonalTarget)
{
CopyToUnchecked(diagonalTarget);
return;
}
- var denseTarget = target as DenseColumnMajorMatrixStorage;
- if (denseTarget != null)
+ if (target is DenseColumnMajorMatrixStorage denseTarget)
{
CopyToUnchecked(denseTarget, existingData);
return;
}
- var sparseTarget = target as SparseCompressedRowMatrixStorage;
- if (sparseTarget != null)
+ if (target is SparseCompressedRowMatrixStorage sparseTarget)
{
CopyToUnchecked(sparseTarget, existingData);
return;
@@ -327,15 +317,13 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
int sourceColumnIndex, int targetColumnIndex, int columnCount,
ExistingData existingData)
{
- var denseTarget = target as DenseColumnMajorMatrixStorage;
- if (denseTarget != null)
+ if (target is DenseColumnMajorMatrixStorage denseTarget)
{
CopySubMatrixToUnchecked(denseTarget, sourceRowIndex, targetRowIndex, rowCount, sourceColumnIndex, targetColumnIndex, columnCount, existingData);
return;
}
- var diagonalTarget = target as DiagonalMatrixStorage;
- if (diagonalTarget != null)
+ if (target is DiagonalMatrixStorage diagonalTarget)
{
CopySubMatrixToUnchecked(diagonalTarget, sourceRowIndex, targetRowIndex, rowCount, sourceColumnIndex, targetColumnIndex, columnCount);
return;
@@ -625,8 +613,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override Tuple Find2Unchecked(MatrixStorage other, Func predicate, Zeros zeros)
{
- var denseOther = other as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other is DenseColumnMajorMatrixStorage denseOther)
{
TOther[] otherData = denseOther.Data;
int k = 0;
@@ -644,8 +631,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return null;
}
- var diagonalOther = other as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other is DiagonalMatrixStorage diagonalOther)
{
TOther[] otherData = diagonalOther.Data;
for (int i = 0; i < Data.Length; i++)
@@ -666,8 +652,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return null;
}
- var sparseOther = other as SparseCompressedRowMatrixStorage;
- if (sparseOther != null)
+ if (other is SparseCompressedRowMatrixStorage sparseOther)
{
int[] otherRowPointers = sparseOther.RowPointers;
int[] otherColumnIndices = sparseOther.ColumnIndices;
@@ -772,8 +757,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
{
var processZeros = zeros == Zeros.Include || !Zero.Equals(f(Zero));
- var diagonalTarget = target as DiagonalMatrixStorage;
- if (diagonalTarget != null)
+ if (target is DiagonalMatrixStorage diagonalTarget)
{
if (processZeros)
{
@@ -821,8 +805,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
{
var processZeros = zeros == Zeros.Include || !Zero.Equals(f(0, 1, Zero));
- var diagonalTarget = target as DiagonalMatrixStorage;
- if (diagonalTarget != null)
+ if (target is DiagonalMatrixStorage diagonalTarget)
{
if (processZeros)
{
@@ -870,15 +853,13 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
int sourceColumnIndex, int targetColumnIndex, int columnCount,
Zeros zeros, ExistingData existingData)
{
- var diagonalTarget = target as DiagonalMatrixStorage;
- if (diagonalTarget != null)
+ if (target is DiagonalMatrixStorage diagonalTarget)
{
MapSubMatrixIndexedToUnchecked(diagonalTarget, f, sourceRowIndex, targetRowIndex, rowCount, sourceColumnIndex, targetColumnIndex, columnCount, zeros);
return;
}
- var denseTarget = target as DenseColumnMajorMatrixStorage;
- if (denseTarget != null)
+ if (target is DenseColumnMajorMatrixStorage denseTarget)
{
MapSubMatrixIndexedToUnchecked(denseTarget, f, sourceRowIndex, targetRowIndex, rowCount, sourceColumnIndex, targetColumnIndex, columnCount, zeros, existingData);
return;
@@ -1097,8 +1078,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override TState Fold2Unchecked(MatrixStorage other, Func f, TState state, Zeros zeros)
{
- var denseOther = other as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other is DenseColumnMajorMatrixStorage denseOther)
{
TOther[] otherData = denseOther.Data;
int k = 0;
@@ -1113,8 +1093,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return state;
}
- var diagonalOther = other as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other is DiagonalMatrixStorage diagonalOther)
{
TOther[] otherData = diagonalOther.Data;
for (int i = 0; i < Data.Length; i++)
@@ -1136,8 +1115,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return state;
}
- var sparseOther = other as SparseCompressedRowMatrixStorage;
- if (sparseOther != null)
+ if (other is SparseCompressedRowMatrixStorage sparseOther)
{
int[] otherRowPointers = sparseOther.RowPointers;
int[] otherColumnIndices = sparseOther.ColumnIndices;
diff --git a/src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs b/src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs
index e2c45167..d65d7968 100644
--- a/src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs
+++ b/src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs
@@ -69,10 +69,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
/// Gets the number of non zero elements in the matrix.
///
/// The number of non zero elements.
- public int ValueCount
- {
- get { return RowPointers[RowCount]; }
- }
+ public int ValueCount => RowPointers[RowCount];
internal SparseCompressedRowMatrixStorage(int rows, int columns)
: base(rows, columns)
@@ -85,19 +82,13 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
///
/// True if the matrix storage format is dense.
///
- public override bool IsDense
- {
- get { return false; }
- }
+ public override bool IsDense => false;
///
/// True if all fields of this matrix can be set to any value.
/// False if some fields are fixed, like on a diagonal matrix.
///
- public override bool IsFullyMutable
- {
- get { return true; }
- }
+ public override bool IsFullyMutable => true;
///
/// True if the specified field can be set to any value.
@@ -842,15 +833,13 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override void CopyToUnchecked(MatrixStorage target, ExistingData existingData)
{
- var sparseTarget = target as SparseCompressedRowMatrixStorage;
- if (sparseTarget != null)
+ if (target is SparseCompressedRowMatrixStorage sparseTarget)
{
CopyToUnchecked(sparseTarget);
return;
}
- var denseTarget = target as DenseColumnMajorMatrixStorage;
- if (denseTarget != null)
+ if (target is DenseColumnMajorMatrixStorage denseTarget)
{
CopyToUnchecked(denseTarget, existingData);
return;
@@ -923,8 +912,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
throw new ArgumentNullException(nameof(target));
}
- var sparseTarget = target as SparseCompressedRowMatrixStorage;
- if (sparseTarget != null)
+ if (target is SparseCompressedRowMatrixStorage sparseTarget)
{
CopySubMatrixToUnchecked(sparseTarget,
sourceRowIndex, targetRowIndex, rowCount,
@@ -1046,8 +1034,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return;
}
- var targetSparse = target as SparseVectorStorage;
- if (targetSparse != null)
+ if (target is SparseVectorStorage targetSparse)
{
if ((sourceColumnIndex == 0) && (targetColumnIndex == 0) && (columnCount == ColumnCount) && (ColumnCount == targetSparse.Length))
{
@@ -1132,15 +1119,13 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override void TransposeToUnchecked(MatrixStorage target, ExistingData existingData)
{
- var sparseTarget = target as SparseCompressedRowMatrixStorage;
- if (sparseTarget != null)
+ if (target is SparseCompressedRowMatrixStorage sparseTarget)
{
TransposeToUnchecked(sparseTarget);
return;
}
- var denseTarget = target as DenseColumnMajorMatrixStorage;
- if (denseTarget != null)
+ if (target is DenseColumnMajorMatrixStorage denseTarget)
{
TransposeToUnchecked(denseTarget, existingData);
return;
@@ -1459,8 +1444,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override Tuple Find2Unchecked(MatrixStorage other, Func predicate, Zeros zeros)
{
- var denseOther = other as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other is DenseColumnMajorMatrixStorage denseOther)
{
TOther[] otherData = denseOther.Data;
int k = 0;
@@ -1478,8 +1462,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return null;
}
- var diagonalOther = other as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other is DiagonalMatrixStorage diagonalOther)
{
TOther[] otherData = diagonalOther.Data;
TOther otherZero = BuilderInstance.Matrix.Zero;
@@ -1537,8 +1520,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return null;
}
- var sparseOther = other as SparseCompressedRowMatrixStorage;
- if (sparseOther != null)
+ if (other is SparseCompressedRowMatrixStorage sparseOther)
{
int[] otherRowPointers = sparseOther.RowPointers;
int[] otherColumnIndices = sparseOther.ColumnIndices;
@@ -1714,8 +1696,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
{
var processZeros = zeros == Zeros.Include || !Zero.Equals(f(Zero));
- var sparseTarget = target as SparseCompressedRowMatrixStorage;
- if (sparseTarget != null)
+ if (target is SparseCompressedRowMatrixStorage sparseTarget)
{
var newRowPointers = sparseTarget.RowPointers;
var newColumnIndices = new List(ColumnIndices.Length);
@@ -1808,8 +1789,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
{
var processZeros = zeros == Zeros.Include || !Zero.Equals(f(0, 1, Zero));
- var sparseTarget = target as SparseCompressedRowMatrixStorage;
- if (sparseTarget != null)
+ if (target is SparseCompressedRowMatrixStorage sparseTarget)
{
var newRowPointers = sparseTarget.RowPointers;
var newColumnIndices = new List(ColumnIndices.Length);
@@ -1903,8 +1883,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
int sourceColumnIndex, int targetColumnIndex, int columnCount,
Zeros zeros, ExistingData existingData)
{
- var sparseTarget = target as SparseCompressedRowMatrixStorage;
- if (sparseTarget != null)
+ if (target is SparseCompressedRowMatrixStorage sparseTarget)
{
MapSubMatrixIndexedToUnchecked(sparseTarget, f, sourceRowIndex, targetRowIndex, rowCount, sourceColumnIndex, targetColumnIndex, columnCount, zeros, existingData);
return;
@@ -2203,8 +2182,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override TState Fold2Unchecked(MatrixStorage other, Func f, TState state, Zeros zeros)
{
- var denseOther = other as DenseColumnMajorMatrixStorage;
- if (denseOther != null)
+ if (other is DenseColumnMajorMatrixStorage denseOther)
{
TOther[] otherData = denseOther.Data;
int k = 0;
@@ -2219,8 +2197,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return state;
}
- var diagonalOther = other as DiagonalMatrixStorage;
- if (diagonalOther != null)
+ if (other is DiagonalMatrixStorage diagonalOther)
{
TOther[] otherData = diagonalOther.Data;
TOther otherZero = BuilderInstance.Matrix.Zero;
@@ -2266,8 +2243,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return state;
}
- var sparseOther = other as SparseCompressedRowMatrixStorage;
- if (sparseOther != null)
+ if (other is SparseCompressedRowMatrixStorage sparseOther)
{
int[] otherRowPointers = sparseOther.RowPointers;
int[] otherColumnIndices = sparseOther.ColumnIndices;
diff --git a/src/Numerics/LinearAlgebra/Storage/SparseVectorStorage.cs b/src/Numerics/LinearAlgebra/Storage/SparseVectorStorage.cs
index bd8da317..f8c19a3e 100644
--- a/src/Numerics/LinearAlgebra/Storage/SparseVectorStorage.cs
+++ b/src/Numerics/LinearAlgebra/Storage/SparseVectorStorage.cs
@@ -73,10 +73,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
///
/// True if the vector storage format is dense.
///
- public override bool IsDense
- {
- get { return false; }
- }
+ public override bool IsDense => false;
///
/// Retrieves the requested element without range checking.
@@ -425,8 +422,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override void CopyToUnchecked(VectorStorage target, ExistingData existingData)
{
- var sparseTarget = target as SparseVectorStorage;
- if (sparseTarget != null)
+ if (target is SparseVectorStorage sparseTarget)
{
CopyToUnchecked(sparseTarget);
return;
@@ -517,8 +513,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override void CopySubVectorToUnchecked(VectorStorage target,
int sourceIndex, int targetIndex, int count, ExistingData existingData)
{
- var sparseTarget = target as SparseVectorStorage;
- if (sparseTarget != null)
+ if (target is SparseVectorStorage sparseTarget)
{
CopySubVectorToUnchecked(sparseTarget, sourceIndex, targetIndex, count, existingData);
return;
@@ -689,8 +684,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override Tuple Find2Unchecked(VectorStorage other, Func predicate, Zeros zeros)
{
- var denseOther = other as DenseVectorStorage;
- if (denseOther != null)
+ if (other is DenseVectorStorage denseOther)
{
TOther[] otherData = denseOther.Data;
int k = 0;
@@ -715,8 +709,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return null;
}
- var sparseOther = other as SparseVectorStorage;
- if (sparseOther != null)
+ if (other is SparseVectorStorage sparseOther)
{
int[] otherIndices = sparseOther.Indices;
TOther[] otherValues = sparseOther.Values;
@@ -846,8 +839,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override void MapToUnchecked(VectorStorage target, Func f, Zeros zeros, ExistingData existingData)
{
- var sparseTarget = target as SparseVectorStorage;
- if (sparseTarget != null)
+ if (target is SparseVectorStorage sparseTarget)
{
var indices = new List();
var values = new List();
@@ -882,8 +874,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return;
}
- var denseTarget = target as DenseVectorStorage;
- if (denseTarget != null)
+ if (target is DenseVectorStorage denseTarget)
{
if (existingData == ExistingData.Clear)
{
@@ -920,8 +911,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override void MapIndexedToUnchecked(VectorStorage target, Func f, Zeros zeros, ExistingData existingData)
{
- var sparseTarget = target as SparseVectorStorage;
- if (sparseTarget != null)
+ if (target is SparseVectorStorage sparseTarget)
{
var indices = new List();
var values = new List();
@@ -956,8 +946,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return;
}
- var denseTarget = target as DenseVectorStorage;
- if (denseTarget != null)
+ if (target is DenseVectorStorage denseTarget)
{
if (existingData == ExistingData.Clear)
{
@@ -1083,8 +1072,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return;
}
- var sparseTarget = target as SparseVectorStorage;
- if (sparseOther != null && sparseTarget != null)
+ if (sparseOther != null && target is SparseVectorStorage sparseTarget)
{
var indices = new List();
var values = new List();
@@ -1146,8 +1134,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
internal override TState Fold2Unchecked(VectorStorage other, Func f, TState state, Zeros zeros)
{
- var sparseOther = other as SparseVectorStorage;
- if (sparseOther != null)
+ if (other is SparseVectorStorage sparseOther)
{
int[] otherIndices = sparseOther.Indices;
TOther[] otherValues = sparseOther.Values;
@@ -1192,8 +1179,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return state;
}
- var denseOther = other as DenseVectorStorage;
- if (denseOther != null)
+ if (other is DenseVectorStorage denseOther)
{
TOther[] otherData = denseOther.Data;
diff --git a/src/Numerics/LinearAlgebra/Vector.BCL.cs b/src/Numerics/LinearAlgebra/Vector.BCL.cs
index de7574f1..464ea553 100644
--- a/src/Numerics/LinearAlgebra/Vector.BCL.cs
+++ b/src/Numerics/LinearAlgebra/Vector.BCL.cs
@@ -62,8 +62,7 @@ namespace MathNet.Numerics.LinearAlgebra
///
public sealed override bool Equals(object obj)
{
- var other = obj as Vector;
- return other != null && Storage.Equals(other.Storage);
+ return obj is Vector other && Storage.Equals(other.Storage);
}
///
@@ -112,10 +111,7 @@ namespace MathNet.Numerics.LinearAlgebra
throw new NotSupportedException();
}
- bool ICollection.IsReadOnly
- {
- get { return false; }
- }
+ bool ICollection.IsReadOnly => false;
void ICollection.Add(T item)
{
@@ -148,20 +144,14 @@ namespace MathNet.Numerics.LinearAlgebra
Storage.CopySubVectorTo(new DenseVectorStorage(array.Length, array), 0, arrayIndex, Count);
}
- bool IList.IsReadOnly
- {
- get { return false; }
- }
+ bool IList.IsReadOnly => false;
- bool IList.IsFixedSize
- {
- get { return true; }
- }
+ bool IList.IsFixedSize => true;
object IList.this[int index]
{
- get { return Storage[index]; }
- set { Storage[index] = (T) value; }
+ get => Storage[index];
+ set => Storage[index] = (T) value;
}
int IList.IndexOf(object value)
@@ -204,15 +194,9 @@ namespace MathNet.Numerics.LinearAlgebra
throw new NotSupportedException();
}
- bool ICollection.IsSynchronized
- {
- get { return false; }
- }
+ bool ICollection.IsSynchronized => false;
- object ICollection.SyncRoot
- {
- get { return Storage; }
- }
+ object ICollection.SyncRoot => Storage;
void ICollection.CopyTo(Array array, int index)
{
@@ -255,7 +239,7 @@ namespace MathNet.Numerics.LinearAlgebra
///
public virtual string ToTypeString()
{
- return string.Format("{0} {1}-{2}", GetType().Name, Count, typeof (T).Name);
+ return FormattableString.Invariant($"{GetType().Name} {Count}-{typeof(T).Name}");
}
public string[,] ToVectorStringArray(int maxPerColumn, int maxCharactersWidth, int padding, string ellipsis, Func formatValue)
diff --git a/src/Numerics/Optimization/BfgsBMinimizer.cs b/src/Numerics/Optimization/BfgsBMinimizer.cs
index 773f1b02..e9f8034c 100644
--- a/src/Numerics/Optimization/BfgsBMinimizer.cs
+++ b/src/Numerics/Optimization/BfgsBMinimizer.cs
@@ -157,7 +157,7 @@ namespace MathNet.Numerics.Optimization
int iterations = DoBfgsUpdate(ref currentExitCondition, lineSearcher, ref pseudoHessian, ref lineSearchDirection, ref previousPoint, ref lineSearchResult, ref candidatePoint, ref step, ref totalLineSearchSteps, ref iterationsWithNontrivialLineSearch);
if (iterations == MaximumIterations && currentExitCondition == ExitCondition.None)
- throw new MaximumIterationsException(string.Format("Maximum iterations ({0}) reached.", MaximumIterations));
+ throw new MaximumIterationsException(FormattableString.Invariant($"Maximum iterations ({MaximumIterations}) reached."));
return new MinimizationWithLineSearchResult(candidatePoint, iterations, currentExitCondition, totalLineSearchSteps, iterationsWithNontrivialLineSearch);
}
diff --git a/src/Numerics/Optimization/BfgsMinimizer.cs b/src/Numerics/Optimization/BfgsMinimizer.cs
index cd4df010..a1a53891 100644
--- a/src/Numerics/Optimization/BfgsMinimizer.cs
+++ b/src/Numerics/Optimization/BfgsMinimizer.cs
@@ -107,7 +107,7 @@ namespace MathNet.Numerics.Optimization
iterations = DoBfgsUpdate(ref currentExitCondition, lineSearcher, ref inversePseudoHessian, ref lineSearchDirection, ref previousPoint, ref lineSearchResult, ref candidate, ref step, ref totalLineSearchSteps, ref iterationsWithNontrivialLineSearch);
if (iterations == MaximumIterations && currentExitCondition == ExitCondition.None)
- throw new MaximumIterationsException(String.Format("Maximum iterations ({0}) reached.", MaximumIterations));
+ throw new MaximumIterationsException(FormattableString.Invariant($"Maximum iterations ({MaximumIterations}) reached."));
return new MinimizationWithLineSearchResult(candidate, iterations, ExitCondition.AbsoluteGradient, totalLineSearchSteps, iterationsWithNontrivialLineSearch);
}
diff --git a/src/Numerics/Optimization/ConjugateGradientMinimizer.cs b/src/Numerics/Optimization/ConjugateGradientMinimizer.cs
index faffa17b..16460e3f 100644
--- a/src/Numerics/Optimization/ConjugateGradientMinimizer.cs
+++ b/src/Numerics/Optimization/ConjugateGradientMinimizer.cs
@@ -124,7 +124,7 @@ namespace MathNet.Numerics.Optimization
if (iterations == maxIterations)
{
- throw new MaximumIterationsException(String.Format("Maximum iterations ({0}) reached.", maxIterations));
+ throw new MaximumIterationsException(FormattableString.Invariant($"Maximum iterations ({maxIterations}) reached."));
}
return new MinimizationWithLineSearchResult(objective, iterations, ExitCondition.AbsoluteGradient, totalLineSearchSteps, iterationsWithNontrivialLineSearch);
diff --git a/src/Numerics/Optimization/LimitedMemoryBfgsMinimizer.cs b/src/Numerics/Optimization/LimitedMemoryBfgsMinimizer.cs
index 0c1ac53e..c907fc35 100644
--- a/src/Numerics/Optimization/LimitedMemoryBfgsMinimizer.cs
+++ b/src/Numerics/Optimization/LimitedMemoryBfgsMinimizer.cs
@@ -150,7 +150,7 @@ namespace MathNet.Numerics.Optimization
}
if (iterations == MaximumIterations && currentExitCondition == ExitCondition.None)
- throw new MaximumIterationsException(String.Format("Maximum iterations ({0}) reached.", MaximumIterations));
+ throw new MaximumIterationsException(FormattableString.Invariant($"Maximum iterations ({MaximumIterations}) reached."));
return new MinimizationWithLineSearchResult(candidate, iterations, ExitCondition.AbsoluteGradient, totalLineSearchSteps, iterationsWithNontrivialLineSearch);
}
diff --git a/src/Numerics/Optimization/LineSearch/StrongWolfeLineSearch.cs b/src/Numerics/Optimization/LineSearch/StrongWolfeLineSearch.cs
index 17de657a..cc06f244 100644
--- a/src/Numerics/Optimization/LineSearch/StrongWolfeLineSearch.cs
+++ b/src/Numerics/Optimization/LineSearch/StrongWolfeLineSearch.cs
@@ -39,10 +39,7 @@ namespace MathNet.Numerics.Optimization.LineSearch
// Argument validation in base class
}
- protected override ExitCondition WolfeExitCondition
- {
- get { return ExitCondition.StrongWolfeCriteria; }
- }
+ protected override ExitCondition WolfeExitCondition => ExitCondition.StrongWolfeCriteria;
protected override bool WolfeCondition(double stepDd, double initialDd)
{
diff --git a/src/Numerics/Optimization/LineSearch/WeakWolfeLineSearch.cs b/src/Numerics/Optimization/LineSearch/WeakWolfeLineSearch.cs
index a0df6761..f1d39ba6 100644
--- a/src/Numerics/Optimization/LineSearch/WeakWolfeLineSearch.cs
+++ b/src/Numerics/Optimization/LineSearch/WeakWolfeLineSearch.cs
@@ -53,10 +53,7 @@ namespace MathNet.Numerics.Optimization.LineSearch
// Validation in base class
}
- protected override ExitCondition WolfeExitCondition
- {
- get { return ExitCondition.WeakWolfeCriteria; }
- }
+ protected override ExitCondition WolfeExitCondition => ExitCondition.WeakWolfeCriteria;
protected override bool WolfeCondition(double stepDd, double initialDd)
{
@@ -67,7 +64,7 @@ namespace MathNet.Numerics.Optimization.LineSearch
{
if (!IsFinite(eval.Value))
{
- throw new EvaluationException(String.Format("Non-finite value returned by objective function: {0}", eval.Value), eval);
+ throw new EvaluationException(FormattableString.Invariant($"Non-finite value returned by objective function: {eval.Value}"), eval);
}
}
@@ -83,7 +80,7 @@ namespace MathNet.Numerics.Optimization.LineSearch
{
if (!IsFinite(x))
{
- throw new EvaluationException(string.Format("Non-finite value returned by gradient: {0}", x), eval);
+ throw new EvaluationException(FormattableString.Invariant($"Non-finite value returned by gradient: {x}"), eval);
}
}
}
diff --git a/src/Numerics/Optimization/LineSearch/WolfeLineSearch.cs b/src/Numerics/Optimization/LineSearch/WolfeLineSearch.cs
index 11bc757d..644b9cc5 100644
--- a/src/Numerics/Optimization/LineSearch/WolfeLineSearch.cs
+++ b/src/Numerics/Optimization/LineSearch/WolfeLineSearch.cs
@@ -29,6 +29,7 @@
using System;
using MathNet.Numerics.LinearAlgebra;
+using static System.FormattableString;
namespace MathNet.Numerics.Optimization.LineSearch
{
@@ -42,11 +43,11 @@ namespace MathNet.Numerics.Optimization.LineSearch
public WolfeLineSearch(double c1, double c2, double parameterTolerance, int maxIterations = 10)
{
if (c1 <= 0)
- throw new ArgumentException(string.Format("c1 {0} should be greater than 0", c1));
+ throw new ArgumentException(Invariant($"c1 {c1} should be greater than 0"));
if (c2 <= c1)
- throw new ArgumentException(string.Format("c1 {0} should be less than c2 {1}", c1, c2));
+ throw new ArgumentException(Invariant($"c1 {c1} should be less than c2 {c2}"));
if (c2 >= 1)
- throw new ArgumentException(string.Format("c2 {0} should be less than 1", c2));
+ throw new ArgumentException(Invariant($"c2 {c2} should be less than 1"));
C1 = c1;
C2 = c2;
@@ -125,12 +126,12 @@ namespace MathNet.Numerics.Optimization.LineSearch
if (ii == MaximumIterations && Double.IsPositiveInfinity(upperBound))
{
- throw new MaximumIterationsException(String.Format("Maximum iterations ({0}) reached. Function appears to be unbounded in search direction.", MaximumIterations));
+ throw new MaximumIterationsException(Invariant($"Maximum iterations ({MaximumIterations}) reached. Function appears to be unbounded in search direction."));
}
if (ii == MaximumIterations)
{
- throw new MaximumIterationsException(String.Format("Maximum iterations ({0}) reached.", MaximumIterations));
+ throw new MaximumIterationsException(Invariant($"Maximum iterations ({MaximumIterations}) reached."));
}
return new LineSearchResult(objective, ii, step, reasonForExit);
diff --git a/src/Numerics/Optimization/MinimizationResult.cs b/src/Numerics/Optimization/MinimizationResult.cs
index ead9c371..e98cc206 100644
--- a/src/Numerics/Optimization/MinimizationResult.cs
+++ b/src/Numerics/Optimization/MinimizationResult.cs
@@ -33,10 +33,10 @@ namespace MathNet.Numerics.Optimization
{
public class MinimizationResult
{
- public Vector MinimizingPoint { get { return FunctionInfoAtMinimum.Point; } }
- public IObjectiveFunction FunctionInfoAtMinimum { get; private set; }
- public int Iterations { get; private set; }
- public ExitCondition ReasonForExit { get; private set; }
+ public Vector MinimizingPoint => FunctionInfoAtMinimum.Point;
+ public IObjectiveFunction FunctionInfoAtMinimum { get; }
+ public int Iterations { get; }
+ public ExitCondition ReasonForExit { get; }
public MinimizationResult(IObjectiveFunction functionInfo, int iterations, ExitCondition reasonForExit)
{
diff --git a/src/Numerics/Optimization/NelderMeadSimplex.cs b/src/Numerics/Optimization/NelderMeadSimplex.cs
index 2b2c278a..ef5b1a9a 100644
--- a/src/Numerics/Optimization/NelderMeadSimplex.cs
+++ b/src/Numerics/Optimization/NelderMeadSimplex.cs
@@ -180,7 +180,7 @@ namespace MathNet.Numerics.Optimization
// check to see if we have exceeded our alloted number of evaluations
if (evaluationCount >= maximumIterations)
{
- throw new MaximumIterationsException(String.Format("Maximum iterations ({0}) reached.", maximumIterations));
+ throw new MaximumIterationsException(FormattableString.Invariant($"Maximum iterations ({maximumIterations}) reached."));
}
}
objectiveFunction.EvaluateAt(vertices[errorProfile.LowestIndex]);
diff --git a/src/Numerics/Optimization/NewtonMinimizer.cs b/src/Numerics/Optimization/NewtonMinimizer.cs
index 571981a6..366ae62a 100644
--- a/src/Numerics/Optimization/NewtonMinimizer.cs
+++ b/src/Numerics/Optimization/NewtonMinimizer.cs
@@ -119,7 +119,7 @@ namespace MathNet.Numerics.Optimization
if (iterations == maxIterations)
{
- throw new MaximumIterationsException(String.Format("Maximum iterations ({0}) reached.", maxIterations));
+ throw new MaximumIterationsException(FormattableString.Invariant($"Maximum iterations ({maxIterations}) reached."));
}
return new MinimizationWithLineSearchResult(objective, iterations, ExitCondition.AbsoluteGradient, totalLineSearchSteps, iterationsWithNontrivialLineSearch);
diff --git a/src/Numerics/Optimization/NonlinearMinimizationResult.cs b/src/Numerics/Optimization/NonlinearMinimizationResult.cs
index a67d3c85..d2a0c029 100644
--- a/src/Numerics/Optimization/NonlinearMinimizationResult.cs
+++ b/src/Numerics/Optimization/NonlinearMinimizationResult.cs
@@ -4,22 +4,22 @@ namespace MathNet.Numerics.Optimization
{
public class NonlinearMinimizationResult
{
- public IObjectiveModel ModelInfoAtMinimum { get; private set; }
+ public IObjectiveModel ModelInfoAtMinimum { get; }
///
/// Returns the best fit parameters.
///
- public Vector MinimizingPoint { get { return ModelInfoAtMinimum.Point; } }
+ public Vector MinimizingPoint => ModelInfoAtMinimum.Point;
///
- /// Returns the standard errors of the corresponding parameters
+ /// Returns the standard errors of the corresponding parameters
///
public Vector StandardErrors { get; private set; }
///
/// Returns the y-values of the fitted model that correspond to the independent values.
///
- public Vector MinimizedValues { get { return ModelInfoAtMinimum.ModelValues; } }
+ public Vector MinimizedValues => ModelInfoAtMinimum.ModelValues;
///
/// Returns the covariance matrix at minimizing point.
@@ -31,9 +31,9 @@ namespace MathNet.Numerics.Optimization
///
public Matrix Correlation { get; private set; }
- public int Iterations { get; private set; }
+ public int Iterations { get; }
- public ExitCondition ReasonForExit { get; private set; }
+ public ExitCondition ReasonForExit { get; }
public NonlinearMinimizationResult(IObjectiveModel modelInfo, int iterations, ExitCondition reasonForExit)
{
@@ -72,7 +72,7 @@ namespace MathNet.Numerics.Optimization
{
StandardErrors = null;
Correlation = null;
- }
+ }
}
}
}
diff --git a/src/Numerics/Optimization/NonlinearMinimizerBase.cs b/src/Numerics/Optimization/NonlinearMinimizerBase.cs
index 1ff68382..94206596 100644
--- a/src/Numerics/Optimization/NonlinearMinimizerBase.cs
+++ b/src/Numerics/Optimization/NonlinearMinimizerBase.cs
@@ -19,8 +19,8 @@ namespace MathNet.Numerics.Optimization
///
/// The stopping threshold for infinity norm of the gradient.
///
- public static double GradientTolerance { get; set; }
-
+ public static double GradientTolerance { get; set; }
+
///
/// The maximum number of iterations.
///
@@ -41,7 +41,7 @@ namespace MathNet.Numerics.Optimization
///
public static Vector Scales { get; private set; }
- private static bool IsBounded { get { return LowerBound != null || UpperBound != null || Scales != null; } }
+ private static bool IsBounded => LowerBound != null || UpperBound != null || Scales != null;
protected NonlinearMinimizerBase(double gradientTolerance = 1E-18, double stepTolerance = 1E-18, double functionTolerance = 1E-18, int maximumIterations = -1)
{
diff --git a/src/Numerics/Optimization/ObjectiveFunctions/ForwardDifferenceGradientObjectiveFunction.cs b/src/Numerics/Optimization/ObjectiveFunctions/ForwardDifferenceGradientObjectiveFunction.cs
index f43349d2..32218859 100644
--- a/src/Numerics/Optimization/ObjectiveFunctions/ForwardDifferenceGradientObjectiveFunction.cs
+++ b/src/Numerics/Optimization/ObjectiveFunctions/ForwardDifferenceGradientObjectiveFunction.cs
@@ -104,32 +104,14 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
EvaluateGradient();
return _gradient;
}
- protected set { _gradient = value; }
+ protected set => _gradient = value;
}
- public Matrix Hessian
- {
- get
- {
- throw new NotImplementedException();
- }
- }
+ public Matrix Hessian => throw new NotImplementedException();
- public bool IsGradientSupported
- {
- get
- {
- return true;
- }
- }
+ public bool IsGradientSupported => true;
- public bool IsHessianSupported
- {
- get
- {
- return false;
- }
- }
+ public bool IsHessianSupported => false;
public Vector Point { get; protected set; }
@@ -145,7 +127,7 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
public IObjectiveFunction CreateNew()
{
- var tmp = new ForwardDifferenceGradientObjectiveFunction(this.InnerObjectiveFunction.CreateNew(), LowerBound, UpperBound, this.RelativeIncrement, this.MinimumIncrement);
+ var tmp = new ForwardDifferenceGradientObjectiveFunction(InnerObjectiveFunction.CreateNew(), LowerBound, UpperBound, this.RelativeIncrement, this.MinimumIncrement);
return tmp;
}
@@ -159,7 +141,7 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
public IObjectiveFunction Fork()
{
- return new ForwardDifferenceGradientObjectiveFunction(this.InnerObjectiveFunction.Fork(), LowerBound, UpperBound, this.RelativeIncrement, this.MinimumIncrement)
+ return new ForwardDifferenceGradientObjectiveFunction(InnerObjectiveFunction.Fork(), LowerBound, UpperBound, this.RelativeIncrement, this.MinimumIncrement)
{
Point = Point?.Clone(),
GradientEvaluated = GradientEvaluated,
diff --git a/src/Numerics/Optimization/ObjectiveFunctions/GradientHessianObjectiveFunction.cs b/src/Numerics/Optimization/ObjectiveFunctions/GradientHessianObjectiveFunction.cs
index 860d39ec..3a96efeb 100644
--- a/src/Numerics/Optimization/ObjectiveFunctions/GradientHessianObjectiveFunction.cs
+++ b/src/Numerics/Optimization/ObjectiveFunctions/GradientHessianObjectiveFunction.cs
@@ -58,15 +58,9 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
};
}
- public bool IsGradientSupported
- {
- get { return true; }
- }
+ public bool IsGradientSupported => true;
- public bool IsHessianSupported
- {
- get { return true; }
- }
+ public bool IsHessianSupported => true;
public void EvaluateAt(Vector point)
{
diff --git a/src/Numerics/Optimization/ObjectiveFunctions/GradientObjectiveFunction.cs b/src/Numerics/Optimization/ObjectiveFunctions/GradientObjectiveFunction.cs
index 019b7f99..f5f48123 100644
--- a/src/Numerics/Optimization/ObjectiveFunctions/GradientObjectiveFunction.cs
+++ b/src/Numerics/Optimization/ObjectiveFunctions/GradientObjectiveFunction.cs
@@ -57,15 +57,9 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
};
}
- public bool IsGradientSupported
- {
- get { return true; }
- }
+ public bool IsGradientSupported => true;
- public bool IsHessianSupported
- {
- get { return false; }
- }
+ public bool IsHessianSupported => false;
public void EvaluateAt(Vector point)
{
@@ -80,9 +74,6 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
public double Value { get; private set; }
public Vector Gradient { get; private set; }
- public Matrix Hessian
- {
- get { throw new NotSupportedException(); }
- }
+ public Matrix Hessian => throw new NotSupportedException();
}
}
diff --git a/src/Numerics/Optimization/ObjectiveFunctions/HessianObjectiveFunction.cs b/src/Numerics/Optimization/ObjectiveFunctions/HessianObjectiveFunction.cs
index 5a3c711b..c014e7a4 100644
--- a/src/Numerics/Optimization/ObjectiveFunctions/HessianObjectiveFunction.cs
+++ b/src/Numerics/Optimization/ObjectiveFunctions/HessianObjectiveFunction.cs
@@ -57,15 +57,9 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
};
}
- public bool IsGradientSupported
- {
- get { return false; }
- }
+ public bool IsGradientSupported => false;
- public bool IsHessianSupported
- {
- get { return true; }
- }
+ public bool IsHessianSupported => true;
public void EvaluateAt(Vector point)
{
@@ -80,9 +74,6 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
public double Value { get; private set; }
public Matrix Hessian { get; private set; }
- public Vector Gradient
- {
- get { throw new NotSupportedException(); }
- }
+ public Vector Gradient => throw new NotSupportedException();
}
}
diff --git a/src/Numerics/Optimization/ObjectiveFunctions/LazyObjectiveFunction.cs b/src/Numerics/Optimization/ObjectiveFunctions/LazyObjectiveFunction.cs
index 23d9c268..827d00ff 100644
--- a/src/Numerics/Optimization/ObjectiveFunctions/LazyObjectiveFunction.cs
+++ b/src/Numerics/Optimization/ObjectiveFunctions/LazyObjectiveFunction.cs
@@ -94,10 +94,7 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
_hessianValue = null;
}
- public Vector Point
- {
- get { return _point; }
- }
+ public Vector Point => _point;
public double Value
{
diff --git a/src/Numerics/Optimization/ObjectiveFunctions/LazyObjectiveFunctionBase.cs b/src/Numerics/Optimization/ObjectiveFunctions/LazyObjectiveFunctionBase.cs
index 7da40d50..b2de9544 100644
--- a/src/Numerics/Optimization/ObjectiveFunctions/LazyObjectiveFunctionBase.cs
+++ b/src/Numerics/Optimization/ObjectiveFunctions/LazyObjectiveFunctionBase.cs
@@ -89,10 +89,7 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
Hessian = null;
}
- public Vector Point
- {
- get { return _point; }
- }
+ public Vector Point => _point;
public double Value
{
diff --git a/src/Numerics/Optimization/ObjectiveFunctions/NonlinearObjectiveFunction.cs b/src/Numerics/Optimization/ObjectiveFunctions/NonlinearObjectiveFunction.cs
index 3994673b..a892069d 100644
--- a/src/Numerics/Optimization/ObjectiveFunctions/NonlinearObjectiveFunction.cs
+++ b/src/Numerics/Optimization/ObjectiveFunctions/NonlinearObjectiveFunction.cs
@@ -23,7 +23,7 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
Matrix jacobianValue; // the Jacobian matrix.
Vector gradientValue; // the Gradient vector.
Matrix hessianValue; // the Hessian matrix.
-
+
#endregion Private Variables
#region Public Variables
@@ -37,7 +37,7 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
/// Set or get the values of the observations.
///
public Vector ObservedY { get; private set; }
-
+
///
/// Set or get the values of the weights for the observations.
///
@@ -52,12 +52,12 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
///
/// Get the number of observations.
///
- public int NumberOfObservations { get { return (ObservedY == null) ? 0 : ObservedY.Count; } }
-
+ public int NumberOfObservations => ObservedY?.Count ?? 0;
+
///
/// Get the number of unknown parameters.
///
- public int NumberOfParameters { get { return (Point == null) ? 0 : Point.Count; } }
+ public int NumberOfParameters => Point?.Count ?? 0;
///
/// Get the degree of freedom
@@ -123,7 +123,7 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
///
/// Set or get the values of the parameters.
///
- public Vector Point { get { return coefficients; } }
+ public Vector Point => coefficients;
///
/// Get the y-values of the fitted model that correspond to the independent values.
@@ -178,8 +178,8 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
}
}
- public bool IsGradientSupported { get { return true; } }
- public bool IsHessianSupported { get { return true; } }
+ public bool IsGradientSupported => true;
+ public bool IsHessianSupported => true;
///
/// Set observed data to fit.
@@ -235,7 +235,7 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
throw new ArgumentNullException("initialGuess");
}
coefficients = initialGuess;
-
+
if (isFixed != null && isFixed.Count != initialGuess.Count)
{
throw new ArgumentException("The isFixed can't have different size from the initial guess.");
@@ -342,11 +342,11 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
// approximated Hessian, H = J'WJ + ∑LRiHi ~ J'WJ near the minimum
hessianValue = jacobianValue.Transpose() * jacobianValue;
}
-
+
private Matrix NumericalJacobian(Vector parameters, Vector currentValues, int accuracyOrder = 2)
- {
+ {
const double sqrtEpsilon = 1.4901161193847656250E-8; // sqrt(machineEpsilon)
-
+
Matrix derivertives = Matrix.Build.Dense(NumberOfObservations, NumberOfParameters);
var d = 0.000003 * parameters.PointwiseAbs().PointwiseMaximum(sqrtEpsilon);
diff --git a/src/Numerics/Optimization/ObjectiveFunctions/ScalarObjectiveFunction.cs b/src/Numerics/Optimization/ObjectiveFunctions/ScalarObjectiveFunction.cs
index c11de220..7ff74681 100644
--- a/src/Numerics/Optimization/ObjectiveFunctions/ScalarObjectiveFunction.cs
+++ b/src/Numerics/Optimization/ObjectiveFunctions/ScalarObjectiveFunction.cs
@@ -63,17 +63,17 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
return _secondDerivative.Value;
}
- public double Point { get { return _point; } }
- public double Value { get { return _value ?? SetValue(); } }
- public double Derivative { get { return _derivative ?? SetDerivative(); } }
- public double SecondDerivative { get { return _secondDerivative ?? SetSecondDerivative(); } }
+ public double Point => _point;
+ public double Value => _value ?? SetValue();
+ public double Derivative => _derivative ?? SetDerivative();
+ public double SecondDerivative => _secondDerivative ?? SetSecondDerivative();
}
internal class ScalarObjectiveFunction : IScalarObjectiveFunction
{
- public Func Objective { get; private set; }
- public Func Derivative { get; private set; }
- public Func SecondDerivative { get; private set; }
+ public Func Objective { get; }
+ public Func Derivative { get; }
+ public Func SecondDerivative { get; }
public ScalarObjectiveFunction(Func objective)
{
@@ -96,15 +96,9 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
SecondDerivative = secondDerivative;
}
- public bool IsDerivativeSupported
- {
- get { return Derivative != null; }
- }
+ public bool IsDerivativeSupported => Derivative != null;
- public bool IsSecondDerivativeSupported
- {
- get { return SecondDerivative != null; }
- }
+ public bool IsSecondDerivativeSupported => SecondDerivative != null;
public IScalarObjectiveFunctionEvaluation Evaluate(double point)
{
diff --git a/src/Numerics/Optimization/ObjectiveFunctions/ScalarValueObjectiveFunction.cs b/src/Numerics/Optimization/ObjectiveFunctions/ScalarValueObjectiveFunction.cs
index 81ef07c9..9cc5484d 100644
--- a/src/Numerics/Optimization/ObjectiveFunctions/ScalarValueObjectiveFunction.cs
+++ b/src/Numerics/Optimization/ObjectiveFunctions/ScalarValueObjectiveFunction.cs
@@ -42,35 +42,23 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
public double Point { get; }
public double Value { get; }
- public double Derivative
- {
- get { throw new NotSupportedException(); }
- }
+ public double Derivative => throw new NotSupportedException();
- public double SecondDerivative
- {
- get { throw new NotSupportedException(); }
- }
+ public double SecondDerivative => throw new NotSupportedException();
}
internal class ScalarValueObjectiveFunction : IScalarObjectiveFunction
{
- public Func Objective { get; private set; }
+ public Func Objective { get; }
public ScalarValueObjectiveFunction(Func objective)
{
Objective = objective;
}
- public bool IsDerivativeSupported
- {
- get { return false; }
- }
+ public bool IsDerivativeSupported => false;
- public bool IsSecondDerivativeSupported
- {
- get { return false; }
- }
+ public bool IsSecondDerivativeSupported => false;
public IScalarObjectiveFunctionEvaluation Evaluate(double point)
{
diff --git a/src/Numerics/Optimization/ObjectiveFunctions/ValueObjectiveFunction.cs b/src/Numerics/Optimization/ObjectiveFunctions/ValueObjectiveFunction.cs
index c6836130..1276a08e 100644
--- a/src/Numerics/Optimization/ObjectiveFunctions/ValueObjectiveFunction.cs
+++ b/src/Numerics/Optimization/ObjectiveFunctions/ValueObjectiveFunction.cs
@@ -56,15 +56,9 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
};
}
- public bool IsGradientSupported
- {
- get { return false; }
- }
+ public bool IsGradientSupported => false;
- public bool IsHessianSupported
- {
- get { return false; }
- }
+ public bool IsHessianSupported => false;
public void EvaluateAt(Vector point)
{
@@ -75,14 +69,8 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
public Vector Point { get; private set; }
public double Value { get; private set; }
- public Matrix Hessian
- {
- get { throw new NotSupportedException(); }
- }
+ public Matrix Hessian => throw new NotSupportedException();
- public Vector Gradient
- {
- get { throw new NotSupportedException(); }
- }
+ public Vector Gradient => throw new NotSupportedException();
}
}
diff --git a/src/Numerics/Optimization/ScalarMinimizationResult.cs b/src/Numerics/Optimization/ScalarMinimizationResult.cs
index 8fd69e19..00ee8344 100644
--- a/src/Numerics/Optimization/ScalarMinimizationResult.cs
+++ b/src/Numerics/Optimization/ScalarMinimizationResult.cs
@@ -31,10 +31,10 @@ namespace MathNet.Numerics.Optimization
{
public class ScalarMinimizationResult
{
- public double MinimizingPoint { get { return FunctionInfoAtMinimum.Point; } }
- public IScalarObjectiveFunctionEvaluation FunctionInfoAtMinimum { get; private set; }
- public int Iterations { get; private set; }
- public ExitCondition ReasonForExit { get; private set; }
+ public double MinimizingPoint => FunctionInfoAtMinimum.Point;
+ public IScalarObjectiveFunctionEvaluation FunctionInfoAtMinimum { get; }
+ public int Iterations { get; }
+ public ExitCondition ReasonForExit { get; }
public ScalarMinimizationResult(IScalarObjectiveFunctionEvaluation functionInfo, int iterations, ExitCondition reasonForExit)
{
diff --git a/src/Numerics/Permutation.cs b/src/Numerics/Permutation.cs
index c2a144c8..331c61f4 100644
--- a/src/Numerics/Permutation.cs
+++ b/src/Numerics/Permutation.cs
@@ -69,23 +69,14 @@ namespace MathNet.Numerics
///
/// Gets the number of elements this permutation is over.
///
- public int Dimension
- {
- get { return _indices.Length; }
- }
+ public int Dimension => _indices.Length;
///
/// Computes where permutes too.
///
/// The index to permute from.
/// The index which is permuted to.
- public int this[int idx]
- {
- get
- {
- return _indices[idx];
- }
- }
+ public int this[int idx] => _indices[idx];
///
/// Computes the inverse of the permutation.
diff --git a/src/Numerics/Providers/Common/Cuda/SafeNativeMethods.cs b/src/Numerics/Providers/Common/Cuda/SafeNativeMethods.cs
index f9aad3bb..a072b997 100644
--- a/src/Numerics/Providers/Common/Cuda/SafeNativeMethods.cs
+++ b/src/Numerics/Providers/Common/Cuda/SafeNativeMethods.cs
@@ -49,7 +49,7 @@ namespace MathNet.Numerics.Providers.Common.Cuda
/// Name of the native DLL.
///
const string _DllName = "MathNet.Numerics.CUDA.dll";
- internal static string DllName { get { return _DllName; } }
+ internal static string DllName => _DllName;
[DllImport(_DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern int query_capability(int capability);
diff --git a/src/Numerics/Providers/Common/Mkl/SafeNativeMethods.cs b/src/Numerics/Providers/Common/Mkl/SafeNativeMethods.cs
index 5128379a..0bd306e6 100644
--- a/src/Numerics/Providers/Common/Mkl/SafeNativeMethods.cs
+++ b/src/Numerics/Providers/Common/Mkl/SafeNativeMethods.cs
@@ -49,7 +49,7 @@ namespace MathNet.Numerics.Providers.Common.Mkl
/// Name of the native DLL.
///
const string _DllName = "MathNet.Numerics.MKL.dll";
- internal static string DllName { get { return _DllName; } }
+ internal static string DllName => _DllName;
[DllImport(_DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern int query_capability(int capability);
diff --git a/src/Numerics/Providers/Common/OpenBlas/SafeNativeMethods.cs b/src/Numerics/Providers/Common/OpenBlas/SafeNativeMethods.cs
index 28878bd7..cbea5a6a 100644
--- a/src/Numerics/Providers/Common/OpenBlas/SafeNativeMethods.cs
+++ b/src/Numerics/Providers/Common/OpenBlas/SafeNativeMethods.cs
@@ -47,7 +47,7 @@ namespace MathNet.Numerics.Providers.Common.OpenBlas
/// Name of the native DLL.
///
const string _DllName = "MathNET.Numerics.OpenBLAS.dll";
- internal static string DllName { get { return _DllName; } }
+ internal static string DllName => _DllName;
[DllImport(_DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern int query_capability(int capability);
diff --git a/src/Numerics/Providers/FourierTransform/Mkl/MklFourierTransformProvider.cs b/src/Numerics/Providers/FourierTransform/Mkl/MklFourierTransformProvider.cs
index 11733a1b..611af5a7 100644
--- a/src/Numerics/Providers/FourierTransform/Mkl/MklFourierTransformProvider.cs
+++ b/src/Numerics/Providers/FourierTransform/Mkl/MklFourierTransformProvider.cs
@@ -74,7 +74,7 @@ namespace MathNet.Numerics.Providers.FourierTransform.Mkl
int revision = MklProvider.Load(hintPath: _hintPath);
if (revision < MinimumCompatibleRevision)
{
- throw new NotSupportedException($"MKL Native Provider revision r{revision} is too old. Consider upgrading to a newer version. Revision r{MinimumCompatibleRevision} and newer are supported.");
+ throw new NotSupportedException(FormattableString.Invariant($"MKL Native Provider revision r{revision} is too old. Consider upgrading to a newer version. Revision r{MinimumCompatibleRevision} and newer are supported."));
}
// we only support exactly one major version, since major version changes imply a breaking change.
@@ -82,7 +82,7 @@ namespace MathNet.Numerics.Providers.FourierTransform.Mkl
int fftMinor = SafeNativeMethods.query_capability((int) ProviderCapability.FourierTransformMinor);
if (!(fftMajor == 1 && fftMinor >= 0))
{
- throw new NotSupportedException(string.Format("MKL Native Provider not compatible. Expecting Fourier transform v1 but provider implements v{0}.", fftMajor));
+ throw new NotSupportedException(FormattableString.Invariant($"MKL Native Provider not compatible. Expecting Fourier transform v1 but provider implements v{fftMajor}."));
}
}
diff --git a/src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.cs b/src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.cs
index 32b79649..864c30d0 100644
--- a/src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.cs
+++ b/src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.cs
@@ -69,7 +69,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda
int revision = CudaProvider.Load(hintPath: _hintPath);
if (revision < MinimumCompatibleRevision)
{
- throw new NotSupportedException($"Cuda Native Provider revision r{revision} is too old. Consider upgrading to a newer version. Revision r{MinimumCompatibleRevision} and newer are supported.");
+ throw new NotSupportedException(FormattableString.Invariant($"Cuda Native Provider revision r{revision} is too old. Consider upgrading to a newer version. Revision r{MinimumCompatibleRevision} and newer are supported."));
}
int linearAlgebra = SafeNativeMethods.query_capability((int)ProviderCapability.LinearAlgebraMajor);
@@ -77,7 +77,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda
// we only support exactly one major version, since major version changes imply a breaking change.
if (linearAlgebra != 1)
{
- throw new NotSupportedException(string.Format("Cuda Native Provider not compatible. Expecting linear algebra v1 but provider implements v{0}.", linearAlgebra));
+ throw new NotSupportedException(FormattableString.Invariant($"Cuda Native Provider not compatible. Expecting linear algebra v1 but provider implements v{linearAlgebra}."));
}
BLAS(SafeNativeMethods.createBLASHandle(ref _blasHandle));
diff --git a/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex.cs b/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex.cs
index 17d3a3c7..16043450 100644
--- a/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex.cs
+++ b/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex.cs
@@ -32,6 +32,7 @@ using MathNet.Numerics.Properties;
using MathNet.Numerics.Threading;
using Complex = System.Numerics.Complex;
using QRMethod = MathNet.Numerics.LinearAlgebra.Factorization.QRMethod;
+using static System.FormattableString;
namespace MathNet.Numerics.Providers.LinearAlgebra.Managed
{
@@ -463,22 +464,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Managed
if (columnsX != rowsY)
{
- throw new ArgumentOutOfRangeException(string.Format("columnsA ({0}) != rowsB ({1})", columnsX, rowsY));
+ throw new ArgumentOutOfRangeException(Invariant($"columnsA ({columnsX}) != rowsB ({rowsY})"));
}
if (rowsX * columnsX != x.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsA ({0}) * columnsA ({1}) != a.Length ({2})", rowsX, columnsX, x.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsA ({rowsX}) * columnsA ({columnsX}) != a.Length ({x.Length})"));
}
if (rowsY * columnsY != y.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsB ({0}) * columnsB ({1}) != b.Length ({2})", rowsY, columnsY, y.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsB ({rowsY}) * columnsB ({columnsY}) != b.Length ({y.Length})"));
}
if (rowsX * columnsY != result.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsA ({0}) * columnsB ({1}) != c.Length ({2})", rowsX, columnsY, result.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsA ({rowsX}) * columnsB ({columnsY}) != c.Length ({result.Length})"));
}
// handle degenerate cases
@@ -584,22 +585,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Managed
if (columnsA != rowsB)
{
- throw new ArgumentOutOfRangeException(string.Format("columnsA ({0}) != rowsB ({1})", columnsA, rowsB));
+ throw new ArgumentOutOfRangeException(Invariant($"columnsA ({columnsA}) != rowsB ({rowsB})"));
}
if (rowsA * columnsA != a.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsA ({0}) * columnsA ({1}) != a.Length ({2})", rowsA, columnsA, a.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsA ({rowsA}) * columnsA ({columnsA}) != a.Length ({a.Length})"));
}
if (rowsB * columnsB != b.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsB ({0}) * columnsB ({1}) != b.Length ({2})", rowsB, columnsB, b.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsB ({rowsB}) * columnsB ({columnsB}) != b.Length ({b.Length})"));
}
if (rowsA * columnsB != c.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsA ({0}) * columnsB ({1}) != c.Length ({2})", rowsA, columnsB, c.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsA ({rowsA}) * columnsB ({columnsB}) != c.Length ({c.Length})"));
}
// handle degenerate cases
diff --git a/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex32.cs b/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex32.cs
index d2c8d351..e952a900 100644
--- a/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex32.cs
+++ b/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex32.cs
@@ -32,6 +32,7 @@ using MathNet.Numerics.Properties;
using MathNet.Numerics.Threading;
using Complex = System.Numerics.Complex;
using QRMethod = MathNet.Numerics.LinearAlgebra.Factorization.QRMethod;
+using static System.FormattableString;
namespace MathNet.Numerics.Providers.LinearAlgebra.Managed
{
@@ -463,22 +464,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Managed
if (columnsX != rowsY)
{
- throw new ArgumentOutOfRangeException(string.Format("columnsA ({0}) != rowsB ({1})", columnsX, rowsY));
+ throw new ArgumentOutOfRangeException(Invariant($"columnsA ({columnsX}) != rowsB ({rowsY})"));
}
if (rowsX * columnsX != x.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsA ({0}) * columnsA ({1}) != a.Length ({2})", rowsX, columnsX, x.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsA ({rowsX}) * columnsA ({columnsX}) != a.Length ({x.Length})"));
}
if (rowsY * columnsY != y.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsB ({0}) * columnsB ({1}) != b.Length ({2})", rowsY, columnsY, y.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsB ({rowsY}) * columnsB ({columnsY}) != b.Length ({y.Length})"));
}
if (rowsX * columnsY != result.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsA ({0}) * columnsB ({1}) != c.Length ({2})", rowsX, columnsY, result.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsA ({rowsX}) * columnsB ({columnsY}) != c.Length ({result.Length})"));
}
// handle degenerate cases
@@ -584,22 +585,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Managed
if (columnsA != rowsB)
{
- throw new ArgumentOutOfRangeException(string.Format("columnsA ({0}) != rowsB ({1})", columnsA, rowsB));
+ throw new ArgumentOutOfRangeException(Invariant($"columnsA ({columnsA}) != rowsB ({rowsB})"));
}
if (rowsA * columnsA != a.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsA ({0}) * columnsA ({1}) != a.Length ({2})", rowsA, columnsA, a.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsA ({rowsA}) * columnsA ({columnsA}) != a.Length ({a.Length})"));
}
if (rowsB * columnsB != b.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsB ({0}) * columnsB ({1}) != b.Length ({2})", rowsB, columnsB, b.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsB ({rowsB}) * columnsB ({columnsB}) != b.Length ({b.Length})"));
}
if (rowsA * columnsB != c.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsA ({0}) * columnsB ({1}) != c.Length ({2})", rowsA, columnsB, c.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsA ({rowsA}) * columnsB ({columnsB}) != c.Length ({c.Length})"));
}
// handle degenerate cases
diff --git a/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Double.cs b/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Double.cs
index fa628798..8b57082e 100644
--- a/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Double.cs
+++ b/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Double.cs
@@ -32,6 +32,7 @@ using MathNet.Numerics.Properties;
using MathNet.Numerics.Threading;
using Complex = System.Numerics.Complex;
using QRMethod = MathNet.Numerics.LinearAlgebra.Factorization.QRMethod;
+using static System.FormattableString;
namespace MathNet.Numerics.Providers.LinearAlgebra.Managed
{
@@ -463,22 +464,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Managed
if (columnsX != rowsY)
{
- throw new ArgumentOutOfRangeException(string.Format("columnsA ({0}) != rowsB ({1})", columnsX, rowsY));
+ throw new ArgumentOutOfRangeException(Invariant($"columnsA ({columnsX}) != rowsB ({rowsY})"));
}
if (rowsX * columnsX != x.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsA ({0}) * columnsA ({1}) != a.Length ({2})", rowsX, columnsX, x.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsA ({rowsX}) * columnsA ({columnsX}) != a.Length ({x.Length})"));
}
if (rowsY * columnsY != y.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsB ({0}) * columnsB ({1}) != b.Length ({2})", rowsY, columnsY, y.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsB ({rowsY}) * columnsB ({columnsY}) != b.Length ({y.Length})"));
}
if (rowsX * columnsY != result.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsA ({0}) * columnsB ({1}) != c.Length ({2})", rowsX, columnsY, result.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsA ({rowsX}) * columnsB ({columnsY}) != c.Length ({result.Length})"));
}
// handle degenerate cases
@@ -584,22 +585,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Managed
if (columnsA != rowsB)
{
- throw new ArgumentOutOfRangeException(string.Format("columnsA ({0}) != rowsB ({1})", columnsA, rowsB));
+ throw new ArgumentOutOfRangeException(Invariant($"columnsA ({columnsA}) != rowsB ({rowsB})"));
}
if (rowsA * columnsA != a.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsA ({0}) * columnsA ({1}) != a.Length ({2})", rowsA, columnsA, a.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsA ({rowsA}) * columnsA ({columnsA}) != a.Length ({a.Length})"));
}
if (rowsB * columnsB != b.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsB ({0}) * columnsB ({1}) != b.Length ({2})", rowsB, columnsB, b.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsB ({rowsB}) * columnsB ({columnsB}) != b.Length ({b.Length})"));
}
if (rowsA * columnsB != c.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsA ({0}) * columnsB ({1}) != c.Length ({2})", rowsA, columnsB, c.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsA ({rowsA}) * columnsB ({columnsB}) != c.Length ({c.Length})"));
}
// handle degenerate cases
diff --git a/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Single.cs b/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Single.cs
index 2258a484..d4785091 100644
--- a/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Single.cs
+++ b/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Single.cs
@@ -32,6 +32,7 @@ using MathNet.Numerics.Properties;
using MathNet.Numerics.Threading;
using Complex = System.Numerics.Complex;
using QRMethod = MathNet.Numerics.LinearAlgebra.Factorization.QRMethod;
+using static System.FormattableString;
namespace MathNet.Numerics.Providers.LinearAlgebra.Managed
{
@@ -463,22 +464,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Managed
if (columnsX != rowsY)
{
- throw new ArgumentOutOfRangeException(string.Format("columnsA ({0}) != rowsB ({1})", columnsX, rowsY));
+ throw new ArgumentOutOfRangeException(Invariant($"columnsA ({columnsX}) != rowsB ({rowsY})"));
}
if (rowsX * columnsX != x.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsA ({0}) * columnsA ({1}) != a.Length ({2})", rowsX, columnsX, x.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsA ({rowsX}) * columnsA ({columnsX}) != a.Length ({x.Length})"));
}
if (rowsY * columnsY != y.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsB ({0}) * columnsB ({1}) != b.Length ({2})", rowsY, columnsY, y.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsB ({rowsY}) * columnsB ({columnsY}) != b.Length ({y.Length})"));
}
if (rowsX * columnsY != result.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsA ({0}) * columnsB ({1}) != c.Length ({2})", rowsX, columnsY, result.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsA ({rowsX}) * columnsB ({columnsY}) != c.Length ({result.Length})"));
}
// handle degenerate cases
@@ -584,22 +585,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Managed
if (columnsA != rowsB)
{
- throw new ArgumentOutOfRangeException(string.Format("columnsA ({0}) != rowsB ({1})", columnsA, rowsB));
+ throw new ArgumentOutOfRangeException(Invariant($"columnsA ({columnsA}) != rowsB ({rowsB})"));
}
if (rowsA * columnsA != a.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsA ({0}) * columnsA ({1}) != a.Length ({2})", rowsA, columnsA, a.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsA ({rowsA}) * columnsA ({columnsA}) != a.Length ({a.Length})"));
}
if (rowsB * columnsB != b.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsB ({0}) * columnsB ({1}) != b.Length ({2})", rowsB, columnsB, b.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsB ({rowsB}) * columnsB ({columnsB}) != b.Length ({b.Length})"));
}
if (rowsA * columnsB != c.Length)
{
- throw new ArgumentOutOfRangeException(string.Format("rowsA ({0}) * columnsB ({1}) != c.Length ({2})", rowsA, columnsB, c.Length));
+ throw new ArgumentOutOfRangeException(Invariant($"rowsA ({rowsA}) * columnsB ({columnsB}) != c.Length ({c.Length})"));
}
// handle degenerate cases
diff --git a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs b/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs
index 04ac735b..7bd81b48 100644
--- a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs
+++ b/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs
@@ -95,7 +95,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
int revision = MklProvider.Load(_hintPath, _consistency, _precision, _accuracy);
if (revision < MinimumCompatibleRevision)
{
- throw new NotSupportedException($"MKL Native Provider revision r{revision} is too old. Consider upgrading to a newer version. Revision r{MinimumCompatibleRevision} and newer are supported.");
+ throw new NotSupportedException(FormattableString.Invariant($"MKL Native Provider revision r{revision} is too old. Consider upgrading to a newer version. Revision r{MinimumCompatibleRevision} and newer are supported."));
}
_linearAlgebraMajor = SafeNativeMethods.query_capability((int)ProviderCapability.LinearAlgebraMajor);
@@ -106,7 +106,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
// we only support exactly one major version, since major version changes imply a breaking change.
if (_linearAlgebraMajor != 2)
{
- throw new NotSupportedException(string.Format("MKL Native Provider not compatible. Expecting linear algebra v2 but provider implements v{0}.", _linearAlgebraMajor));
+ throw new NotSupportedException(FormattableString.Invariant($"MKL Native Provider not compatible. Expecting linear algebra v2 but provider implements v{_linearAlgebraMajor}."));
}
}
diff --git a/src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.cs b/src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.cs
index 639ed806..949e9234 100644
--- a/src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.cs
+++ b/src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.cs
@@ -85,7 +85,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
int revision = OpenBlasProvider.Load(hintPath: _hintPath);
if (revision < MinimumCompatibleRevision)
{
- throw new NotSupportedException($"OpenBLAS Native Provider revision r{revision} is too old. Consider upgrading to a newer version. Revision r{MinimumCompatibleRevision} and newer are supported.");
+ throw new NotSupportedException(FormattableString.Invariant($"OpenBLAS Native Provider revision r{revision} is too old. Consider upgrading to a newer version. Revision r{MinimumCompatibleRevision} and newer are supported."));
}
int linearAlgebra = SafeNativeMethods.query_capability((int)ProviderCapability.LinearAlgebraMajor);
@@ -93,7 +93,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
// we only support exactly one major version, since major version changes imply a breaking change.
if (linearAlgebra != 1)
{
- throw new NotSupportedException(string.Format("OpenBLAS Native Provider not compatible. Expecting linear algebra v1 but provider implements v{0}.", linearAlgebra));
+ throw new NotSupportedException(FormattableString.Invariant($"OpenBLAS Native Provider not compatible. Expecting linear algebra v1 but provider implements v{linearAlgebra}."));
}
}
diff --git a/src/Numerics/Random/MersenneTwister.cs b/src/Numerics/Random/MersenneTwister.cs
index 742e89de..d91c50a2 100644
--- a/src/Numerics/Random/MersenneTwister.cs
+++ b/src/Numerics/Random/MersenneTwister.cs
@@ -176,10 +176,7 @@ namespace MathNet.Numerics.Random
///
/// Default instance, thread-safe.
///
- public static MersenneTwister Default
- {
- get { return DefaultInstance.Value; }
- }
+ public static MersenneTwister Default => DefaultInstance.Value;
/*///
/// Initializes a new instance of the class.
diff --git a/src/Numerics/Random/RandomExtensions.cs b/src/Numerics/Random/RandomExtensions.cs
index 5f543998..c351e3d8 100644
--- a/src/Numerics/Random/RandomExtensions.cs
+++ b/src/Numerics/Random/RandomExtensions.cs
@@ -49,8 +49,7 @@ namespace MathNet.Numerics.Random
///
public static void NextDoubles(this System.Random rnd, double[] values)
{
- var rs = rnd as RandomSource;
- if (rs != null)
+ if (rnd is RandomSource rs)
{
rs.NextDoubles(values);
return;
@@ -87,8 +86,7 @@ namespace MathNet.Numerics.Random
///
public static IEnumerable NextDoubleSequence(this System.Random rnd)
{
- var rs = rnd as RandomSource;
- if (rs != null)
+ if (rnd is RandomSource rs)
{
return rs.NextDoubleSequence();
}
@@ -131,8 +129,7 @@ namespace MathNet.Numerics.Random
///
public static void NextInt32s(this System.Random rnd, int[] values)
{
- var rs = rnd as RandomSource;
- if (rs != null)
+ if (rnd is RandomSource rs)
{
rs.NextInt32s(values);
return;
@@ -157,8 +154,7 @@ namespace MathNet.Numerics.Random
///
public static void NextInt32s(this System.Random rnd, int[] values, int minInclusive, int maxExclusive)
{
- var rs = rnd as RandomSource;
- if (rs != null)
+ if (rnd is RandomSource rs)
{
rs.NextInt32s(values, minInclusive, maxExclusive);
return;
@@ -179,8 +175,7 @@ namespace MathNet.Numerics.Random
///
public static IEnumerable NextInt32Sequence(this System.Random rnd, int minInclusive, int maxExclusive)
{
- var rs = rnd as RandomSource;
- if (rs != null)
+ if (rnd is RandomSource rs)
{
return rs.NextInt32Sequence(minInclusive, maxExclusive);
}
diff --git a/src/Numerics/Random/SystemRandomSource.cs b/src/Numerics/Random/SystemRandomSource.cs
index edda8b8f..3b22d105 100644
--- a/src/Numerics/Random/SystemRandomSource.cs
+++ b/src/Numerics/Random/SystemRandomSource.cs
@@ -88,10 +88,7 @@ namespace MathNet.Numerics.Random
///
/// Default instance, thread-safe.
///
- public static SystemRandomSource Default
- {
- get { return DefaultInstance.Value; }
- }
+ public static SystemRandomSource Default => DefaultInstance.Value;
///
/// Returns a random double-precision floating point number greater than or equal to 0.0, and less than 1.0.
diff --git a/src/Numerics/Sorting.cs b/src/Numerics/Sorting.cs
index 98161adc..13475410 100644
--- a/src/Numerics/Sorting.cs
+++ b/src/Numerics/Sorting.cs
@@ -83,16 +83,14 @@ namespace MathNet.Numerics
}
// array case
- var keysArray = keys as T[];
- if (null != keysArray)
+ if (keys is T[] keysArray)
{
Array.Sort(keysArray, comparer);
return;
}
// generic list case
- var keysList = keys as List;
- if (null != keysList)
+ if (keys is List keysList)
{
keysList.Sort(comparer);
return;
@@ -154,9 +152,7 @@ namespace MathNet.Numerics
}
// array case
- var keysArray = keys as TKey[];
- var itemsArray = items as TItem[];
- if ((null != keysArray) && (null != itemsArray))
+ if (keys is TKey[] keysArray && items is TItem[] itemsArray)
{
Array.Sort(keysArray, itemsArray, comparer);
return;
@@ -285,16 +281,14 @@ namespace MathNet.Numerics
}
// array case
- var keysArray = keys as T[];
- if (null != keysArray)
+ if (keys is T[] keysArray)
{
Array.Sort(keysArray, index, count, comparer);
return;
}
// generic list case
- var keysList = keys as List;
- if (null != keysList)
+ if (keys is List keysList)
{
keysList.Sort(index, count, comparer);
return;
@@ -368,9 +362,7 @@ namespace MathNet.Numerics
}
// array case
- var keysArray = keys as TKey[];
- var itemsArray = items as TItem[];
- if ((null != keysArray) && (null != itemsArray))
+ if (keys is TKey[] keysArray && items is TItem[] itemsArray)
{
Array.Sort(keysArray, itemsArray, index, count, comparer);
return;
diff --git a/src/Numerics/SpecialFunctions/ExponentialIntegral.cs b/src/Numerics/SpecialFunctions/ExponentialIntegral.cs
index 1fafd11e..0c19e7ca 100644
--- a/src/Numerics/SpecialFunctions/ExponentialIntegral.cs
+++ b/src/Numerics/SpecialFunctions/ExponentialIntegral.cs
@@ -63,7 +63,7 @@ namespace MathNet.Numerics
//parameter validation
if (n < 0 || x < 0.0)
{
- throw new ArgumentOutOfRangeException(string.Format("x and n must be positive: x={0}, n={1}", x, n));
+ throw new ArgumentOutOfRangeException(FormattableString.Invariant($"x and n must be positive: x={x}, n={n}"));
}
const double epsilon = 0.00000000000000001;
@@ -107,7 +107,7 @@ namespace MathNet.Numerics
return h*Math.Exp(-x);
}
}
- throw new ArithmeticException(string.Format("continued fraction failed to converge for x={0}, n={1})", x, n));
+ throw new ArithmeticException(FormattableString.Invariant($"Continued fraction failed to converge for x={x}, n={n})"));
}
//series computation for small x
else
@@ -135,7 +135,7 @@ namespace MathNet.Numerics
return result;
}
}
- throw new ArithmeticException(string.Format("series failed to converge for x={0}, n={1})", x, n));
+ throw new ArithmeticException(FormattableString.Invariant($"Series failed to converge for x={x}, n={n})"));
}
}
}
diff --git a/src/Numerics/Statistics/Histogram.cs b/src/Numerics/Statistics/Histogram.cs
index 64d260ba..0a655fbf 100644
--- a/src/Numerics/Statistics/Histogram.cs
+++ b/src/Numerics/Statistics/Histogram.cs
@@ -138,27 +138,18 @@ namespace MathNet.Numerics.Statistics
///
/// Width of the Bucket.
///
- public double Width
- {
- get { return UpperBound - LowerBound; }
- }
+ public double Width => UpperBound - LowerBound;
///
/// True if this is a single point argument for
/// when performing a Binary search.
///
- private bool IsSinglePoint
- {
- get { return double.IsNaN(Count); }
- }
+ private bool IsSinglePoint => double.IsNaN(Count);
///
/// Default comparer.
///
- public static IComparer DefaultPointComparer
- {
- get { return Comparer; }
- }
+ public static IComparer DefaultPointComparer => Comparer;
///
/// This method check whether a point is contained within this bucket.
@@ -479,10 +470,7 @@ namespace MathNet.Numerics.Statistics
///
/// Gets the number of buckets.
///
- public int BucketCount
- {
- get { return _buckets.Count; }
- }
+ public int BucketCount => _buckets.Count;
///
/// Gets the total number of datapoints in the histogram.
diff --git a/src/Numerics/Statistics/MCMC/HybridMC.cs b/src/Numerics/Statistics/MCMC/HybridMC.cs
index cd6d5485..925eec19 100644
--- a/src/Numerics/Statistics/MCMC/HybridMC.cs
+++ b/src/Numerics/Statistics/MCMC/HybridMC.cs
@@ -62,7 +62,7 @@ namespace MathNet.Numerics.Statistics.Mcmc
/// When the length of pSdv is not the same as Length.
public double[] MomentumStdDev
{
- get { return (double[])_mpSdv.Clone(); }
+ get => (double[])_mpSdv.Clone();
set
{
CheckVariance(value);
diff --git a/src/Numerics/Statistics/MCMC/HybridMCGeneric.cs b/src/Numerics/Statistics/MCMC/HybridMCGeneric.cs
index b5f5ddb2..c46123a6 100644
--- a/src/Numerics/Statistics/MCMC/HybridMCGeneric.cs
+++ b/src/Numerics/Statistics/MCMC/HybridMCGeneric.cs
@@ -86,11 +86,8 @@ namespace MathNet.Numerics.Statistics.Mcmc
/// When burn interval is negative.
public int BurnInterval
{
- get { return _burnInterval; }
- set
- {
- _burnInterval = SetNonNegative(value);
- }
+ get => _burnInterval;
+ set => _burnInterval = SetNonNegative(value);
}
///
@@ -99,11 +96,8 @@ namespace MathNet.Numerics.Statistics.Mcmc
/// When frog leap steps is negative or zero.
public int FrogLeapSteps
{
- get { return _frogLeapSteps; }
- set
- {
- _frogLeapSteps = SetPositive(value);
- }
+ get => _frogLeapSteps;
+ set => _frogLeapSteps = SetPositive(value);
}
///
@@ -112,11 +106,8 @@ namespace MathNet.Numerics.Statistics.Mcmc
/// When step size is negative or zero.
public double StepSize
{
- get { return _stepSize; }
- set
- {
- _stepSize = SetPositive(value);
- }
+ get => _stepSize;
+ set => _stepSize = SetPositive(value);
}
///
diff --git a/src/Numerics/Statistics/MCMC/MCMCSampler.cs b/src/Numerics/Statistics/MCMC/MCMCSampler.cs
index 2fc5e2fc..314e2480 100644
--- a/src/Numerics/Statistics/MCMC/MCMCSampler.cs
+++ b/src/Numerics/Statistics/MCMC/MCMCSampler.cs
@@ -115,15 +115,8 @@ namespace MathNet.Numerics.Statistics.Mcmc
/// When the random number generator is null.
public System.Random RandomSource
{
- get { return _randomNumberGenerator; }
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
- _randomNumberGenerator = value;
- }
+ get => _randomNumberGenerator;
+ set => _randomNumberGenerator = value ?? SystemRandomSource.Default;
}
///
@@ -149,9 +142,6 @@ namespace MathNet.Numerics.Statistics.Mcmc
///
/// Gets the acceptance rate of the sampler.
///
- public double AcceptanceRate
- {
- get { return Accepts / (double)Samples; }
- }
+ public double AcceptanceRate => Accepts / (double)Samples;
}
-}
\ No newline at end of file
+}
diff --git a/src/Numerics/Statistics/MCMC/MetropolisHastingsSampler.cs b/src/Numerics/Statistics/MCMC/MetropolisHastingsSampler.cs
index e428be47..7997440d 100644
--- a/src/Numerics/Statistics/MCMC/MetropolisHastingsSampler.cs
+++ b/src/Numerics/Statistics/MCMC/MetropolisHastingsSampler.cs
@@ -103,7 +103,7 @@ namespace MathNet.Numerics.Statistics.Mcmc
/// When burn interval is negative.
public int BurnInterval
{
- get { return _burnInterval; }
+ get => _burnInterval;
set
{
if (value < 0)
diff --git a/src/Numerics/Statistics/MCMC/MetropolisSampler.cs b/src/Numerics/Statistics/MCMC/MetropolisSampler.cs
index 16b1d72c..55f9ab80 100644
--- a/src/Numerics/Statistics/MCMC/MetropolisSampler.cs
+++ b/src/Numerics/Statistics/MCMC/MetropolisSampler.cs
@@ -94,7 +94,7 @@ namespace MathNet.Numerics.Statistics.Mcmc
/// When burn interval is negative.
public int BurnInterval
{
- get { return _burnInterval; }
+ get => _burnInterval;
set
{
if (value < 0)
diff --git a/src/Numerics/Statistics/MCMC/UnivariateHybridMC.cs b/src/Numerics/Statistics/MCMC/UnivariateHybridMC.cs
index 30bd5e27..ca97a1f6 100644
--- a/src/Numerics/Statistics/MCMC/UnivariateHybridMC.cs
+++ b/src/Numerics/Statistics/MCMC/UnivariateHybridMC.cs
@@ -56,7 +56,7 @@ namespace MathNet.Numerics.Statistics.Mcmc
/// When standard deviation is negative.
public double MomentumStdDev
{
- get { return _sdv; }
+ get => _sdv;
set
{
if (_sdv != value)
diff --git a/src/Numerics/Statistics/MCMC/UnivariateSliceSampler.cs b/src/Numerics/Statistics/MCMC/UnivariateSliceSampler.cs
index 0e466837..6e8f5e32 100644
--- a/src/Numerics/Statistics/MCMC/UnivariateSliceSampler.cs
+++ b/src/Numerics/Statistics/MCMC/UnivariateSliceSampler.cs
@@ -106,7 +106,7 @@ namespace MathNet.Numerics.Statistics.Mcmc
/// When burn interval is negative.
public int BurnInterval
{
- get { return _burnInterval; }
+ get => _burnInterval;
set
{
if (value < 0)
@@ -122,7 +122,7 @@ namespace MathNet.Numerics.Statistics.Mcmc
///
public double Scale
{
- get { return _scale; }
+ get => _scale;
set
{
if (value <= 0.0)
diff --git a/src/Numerics/Statistics/MovingStatistics.cs b/src/Numerics/Statistics/MovingStatistics.cs
index 02656e21..a845544c 100644
--- a/src/Numerics/Statistics/MovingStatistics.cs
+++ b/src/Numerics/Statistics/MovingStatistics.cs
@@ -69,18 +69,12 @@ namespace MathNet.Numerics.Statistics
PushRange(values);
}
- public int WindowSize
- {
- get { return _windowSize; }
- }
+ public int WindowSize => _windowSize;
///
/// Gets the total number of samples.
///
- public long Count
- {
- get { return _totalCountOffset + _count; }
- }
+ public long Count => _totalCountOffset + _count;
///
/// Returns the minimum value in the sample data.
diff --git a/src/Numerics/Statistics/RunningStatistics.cs b/src/Numerics/Statistics/RunningStatistics.cs
index 1d5fa371..ebde1f5b 100644
--- a/src/Numerics/Statistics/RunningStatistics.cs
+++ b/src/Numerics/Statistics/RunningStatistics.cs
@@ -82,117 +82,81 @@ namespace MathNet.Numerics.Statistics
///
/// Gets the total number of samples.
///
- public long Count
- {
- get { return _n; }
- }
+ public long Count => _n;
///
/// Returns the minimum value in the sample data.
/// Returns NaN if data is empty or if any entry is NaN.
///
- public double Minimum
- {
- get { return _n > 0 ? _min : double.NaN; }
- }
+ public double Minimum => _n > 0 ? _min : double.NaN;
///
/// Returns the maximum value in the sample data.
/// Returns NaN if data is empty or if any entry is NaN.
///
- public double Maximum
- {
- get { return _n > 0 ? _max : double.NaN; }
- }
+ public double Maximum => _n > 0 ? _max : double.NaN;
///
/// Evaluates the sample mean, an estimate of the population mean.
/// Returns NaN if data is empty or if any entry is NaN.
///
- public double Mean
- {
- get { return _n > 0 ? _m1 : double.NaN; }
- }
+ public double Mean => _n > 0 ? _m1 : double.NaN;
///
/// Estimates the unbiased population variance from the provided samples.
/// On a dataset of size N will use an N-1 normalizer (Bessel's correction).
/// Returns NaN if data has less than two entries or if any entry is NaN.
///
- public double Variance
- {
- get { return _n < 2 ? double.NaN : _m2/(_n - 1); }
- }
+ public double Variance => _n < 2 ? double.NaN : _m2/(_n - 1);
///
/// Evaluates the variance from the provided full population.
/// On a dataset of size N will use an N normalizer and would thus be biased if applied to a subset.
/// Returns NaN if data is empty or if any entry is NaN.
///
- public double PopulationVariance
- {
- get { return _n < 2 ? double.NaN : _m2/_n; }
- }
+ public double PopulationVariance => _n < 2 ? double.NaN : _m2/_n;
///
/// Estimates the unbiased population standard deviation from the provided samples.
/// On a dataset of size N will use an N-1 normalizer (Bessel's correction).
/// Returns NaN if data has less than two entries or if any entry is NaN.
///
- public double StandardDeviation
- {
- get { return _n < 2 ? double.NaN : Math.Sqrt(_m2/(_n - 1)); }
- }
+ public double StandardDeviation => _n < 2 ? double.NaN : Math.Sqrt(_m2/(_n - 1));
///
/// Evaluates the standard deviation from the provided full population.
/// On a dataset of size N will use an N normalizer and would thus be biased if applied to a subset.
/// Returns NaN if data is empty or if any entry is NaN.
///
- public double PopulationStandardDeviation
- {
- get { return _n < 2 ? double.NaN : Math.Sqrt(_m2/_n); }
- }
+ public double PopulationStandardDeviation => _n < 2 ? double.NaN : Math.Sqrt(_m2/_n);
///
/// Estimates the unbiased population skewness from the provided samples.
/// Uses a normalizer (Bessel's correction; type 2).
/// Returns NaN if data has less than three entries or if any entry is NaN.
///
- public double Skewness
- {
- get { return _n < 3 ? double.NaN : (_n*_m3*Math.Sqrt(_m2/(_n - 1))/(_m2*_m2*(_n - 2)))*(_n - 1); }
- }
+ public double Skewness => _n < 3 ? double.NaN : (_n*_m3*Math.Sqrt(_m2/(_n - 1))/(_m2*_m2*(_n - 2)))*(_n - 1);
///
/// Evaluates the population skewness from the full population.
/// Does not use a normalizer and would thus be biased if applied to a subset (type 1).
/// Returns NaN if data has less than two entries or if any entry is NaN.
///
- public double PopulationSkewness
- {
- get { return _n < 2 ? double.NaN : Math.Sqrt(_n)*_m3/Math.Pow(_m2, 1.5); }
- }
+ public double PopulationSkewness => _n < 2 ? double.NaN : Math.Sqrt(_n)*_m3/Math.Pow(_m2, 1.5);
///
/// Estimates the unbiased population kurtosis from the provided samples.
/// Uses a normalizer (Bessel's correction; type 2).
/// Returns NaN if data has less than four entries or if any entry is NaN.
///
- public double Kurtosis
- {
- get { return _n < 4 ? double.NaN : ((double)_n*_n - 1)/((_n - 2)*(_n - 3))*(_n*_m4/(_m2*_m2) - 3 + 6.0/(_n + 1)); }
- }
+ public double Kurtosis => _n < 4 ? double.NaN : ((double)_n*_n - 1)/((_n - 2)*(_n - 3))*(_n*_m4/(_m2*_m2) - 3 + 6.0/(_n + 1));
///
/// Evaluates the population kurtosis from the full population.
/// Does not use a normalizer and would thus be biased if applied to a subset (type 1).
/// Returns NaN if data has less than three entries or if any entry is NaN.
///
- public double PopulationKurtosis
- {
- get { return _n < 3 ? double.NaN : _n*_m4/(_m2*_m2) - 3.0; }
- }
+ public double PopulationKurtosis => _n < 3 ? double.NaN : _n*_m4/(_m2*_m2) - 3.0;
///
/// Update the running statistics by adding another observed sample (in-place).
diff --git a/src/Numerics/Statistics/Statistics.cs b/src/Numerics/Statistics/Statistics.cs
index d4c73481..862d9548 100644
--- a/src/Numerics/Statistics/Statistics.cs
+++ b/src/Numerics/Statistics/Statistics.cs
@@ -47,8 +47,7 @@ namespace MathNet.Numerics.Statistics
/// The minimum value in the sample data.
public static double Minimum(this IEnumerable data)
{
- var array = data as double[];
- return array != null
+ return data is double[] array
? ArrayStatistics.Minimum(array)
: StreamingStatistics.Minimum(data);
}
@@ -61,8 +60,7 @@ namespace MathNet.Numerics.Statistics
/// The minimum value in the sample data.
public static float Minimum(this IEnumerable data)
{
- var array = data as float[];
- return array != null
+ return data is float[] array
? ArrayStatistics.Minimum(array)
: StreamingStatistics.Minimum(data);
}
@@ -88,8 +86,7 @@ namespace MathNet.Numerics.Statistics
/// The maximum value in the sample data.
public static double Maximum(this IEnumerable data)
{
- var array = data as double[];
- return array != null
+ return data is double[] array
? ArrayStatistics.Maximum(array)
: StreamingStatistics.Maximum(data);
}
@@ -102,8 +99,7 @@ namespace MathNet.Numerics.Statistics
/// The maximum value in the sample data.
public static float Maximum(this IEnumerable data)
{
- var array = data as float[];
- return array != null
+ return data is float[] array
? ArrayStatistics.Maximum(array)
: StreamingStatistics.Maximum(data);
}
@@ -128,8 +124,7 @@ namespace MathNet.Numerics.Statistics
/// The minimum value in the sample data.
public static double MinimumAbsolute(this IEnumerable data)
{
- var array = data as double[];
- return array != null
+ return data is double[] array
? ArrayStatistics.MinimumAbsolute(array)
: StreamingStatistics.MinimumAbsolute(data);
}
@@ -142,8 +137,7 @@ namespace MathNet.Numerics.Statistics
/// The minimum value in the sample data.
public static float MinimumAbsolute(this IEnumerable data)
{
- var array = data as float[];
- return array != null
+ return data is float[] array
? ArrayStatistics.MinimumAbsolute(array)
: StreamingStatistics.MinimumAbsolute(data);
}
@@ -156,8 +150,7 @@ namespace MathNet.Numerics.Statistics
/// The maximum value in the sample data.
public static double MaximumAbsolute(this IEnumerable data)
{
- var array = data as double[];
- return array != null
+ return data is double[] array
? ArrayStatistics.MaximumAbsolute(array)
: StreamingStatistics.MaximumAbsolute(data);
}
@@ -170,8 +163,7 @@ namespace MathNet.Numerics.Statistics
/// The maximum value in the sample data.
public static float MaximumAbsolute(this IEnumerable data)
{
- var array = data as float[];
- return array != null
+ return data is float[] array
? ArrayStatistics.MaximumAbsolute(array)
: StreamingStatistics.MaximumAbsolute(data);
}
@@ -184,8 +176,7 @@ namespace MathNet.Numerics.Statistics
/// The minimum value in the sample data.
public static Complex MinimumMagnitudePhase(this IEnumerable data)
{
- var array = data as Complex[];
- return array != null
+ return data is Complex[] array
? ArrayStatistics.MinimumMagnitudePhase(array)
: StreamingStatistics.MinimumMagnitudePhase(data);
}
@@ -198,8 +189,7 @@ namespace MathNet.Numerics.Statistics
/// The minimum value in the sample data.
public static Complex32 MinimumMagnitudePhase(this IEnumerable data)
{
- var array = data as Complex32[];
- return array != null
+ return data is Complex32[] array
? ArrayStatistics.MinimumMagnitudePhase(array)
: StreamingStatistics.MinimumMagnitudePhase(data);
}
@@ -212,8 +202,7 @@ namespace MathNet.Numerics.Statistics
/// The minimum value in the sample data.
public static Complex MaximumMagnitudePhase(this IEnumerable data)
{
- var array = data as Complex[];
- return array != null
+ return data is Complex[] array
? ArrayStatistics.MaximumMagnitudePhase(array)
: StreamingStatistics.MaximumMagnitudePhase(data);
}
@@ -226,8 +215,7 @@ namespace MathNet.Numerics.Statistics
/// The minimum value in the sample data.
public static Complex32 MaximumMagnitudePhase(this IEnumerable data)
{
- var array = data as Complex32[];
- return array != null
+ return data is Complex32[] array
? ArrayStatistics.MaximumMagnitudePhase(array)
: StreamingStatistics.MaximumMagnitudePhase(data);
}
@@ -240,8 +228,7 @@ namespace MathNet.Numerics.Statistics
/// The mean of the sample.
public static double Mean(this IEnumerable data)
{
- var array = data as double[];
- return array != null
+ return data is double[] array
? ArrayStatistics.Mean(array)
: StreamingStatistics.Mean(data);
}
@@ -254,8 +241,7 @@ namespace MathNet.Numerics.Statistics
/// The mean of the sample.
public static double Mean(this IEnumerable data)
{
- var array = data as float[];
- return array != null
+ return data is float[] array
? ArrayStatistics.Mean(array)
: StreamingStatistics.Mean(data);
}
@@ -280,8 +266,7 @@ namespace MathNet.Numerics.Statistics
/// The geometric mean of the sample.
public static double GeometricMean(this IEnumerable data)
{
- var array = data as double[];
- return array != null
+ return data is double[] array
? ArrayStatistics.GeometricMean(array)
: StreamingStatistics.GeometricMean(data);
}
@@ -294,8 +279,7 @@ namespace MathNet.Numerics.Statistics
/// The geometric mean of the sample.
public static double GeometricMean(this IEnumerable data)
{
- var array = data as float[];
- return array != null
+ return data is float[] array
? ArrayStatistics.GeometricMean(array)
: StreamingStatistics.GeometricMean(data);
}
@@ -308,8 +292,7 @@ namespace MathNet.Numerics.Statistics
/// The harmonic mean of the sample.
public static double HarmonicMean(this IEnumerable data)
{
- var array = data as double[];
- return array != null
+ return data is double[] array
? ArrayStatistics.HarmonicMean(array)
: StreamingStatistics.HarmonicMean(data);
}
@@ -322,8 +305,7 @@ namespace MathNet.Numerics.Statistics
/// The harmonic mean of the sample.
public static double HarmonicMean(this IEnumerable data)
{
- var array = data as float[];
- return array != null
+ return data is float[] array
? ArrayStatistics.HarmonicMean(array)
: StreamingStatistics.HarmonicMean(data);
}
@@ -336,8 +318,7 @@ namespace MathNet.Numerics.Statistics
/// A subset of samples, sampled from the full population.
public static double Variance(this IEnumerable samples)
{
- var array = samples as double[];
- return array != null
+ return samples is double[] array
? ArrayStatistics.Variance(array)
: StreamingStatistics.Variance(samples);
}
@@ -350,8 +331,7 @@ namespace MathNet.Numerics.Statistics
/// A subset of samples, sampled from the full population.
public static double Variance(this IEnumerable samples)
{
- var array = samples as float[];
- return array != null
+ return samples is float[] array
? ArrayStatistics.Variance(array)
: StreamingStatistics.Variance(samples);
}
@@ -376,8 +356,7 @@ namespace MathNet.Numerics.Statistics
/// The full population data.
public static double PopulationVariance(this IEnumerable population)
{
- var array = population as double[];
- return array != null
+ return population is double[] array
? ArrayStatistics.PopulationVariance(array)
: StreamingStatistics.PopulationVariance(population);
}
@@ -390,8 +369,7 @@ namespace MathNet.Numerics.Statistics
/// The full population data.
public static double PopulationVariance(this IEnumerable population)
{
- var array = population as float[];
- return array != null
+ return population is float[] array
? ArrayStatistics.PopulationVariance(array)
: StreamingStatistics.PopulationVariance(population);
}
@@ -416,8 +394,7 @@ namespace MathNet.Numerics.Statistics
/// A subset of samples, sampled from the full population.
public static double StandardDeviation(this IEnumerable samples)
{
- var array = samples as double[];
- return array != null
+ return samples is double[] array
? ArrayStatistics.StandardDeviation(array)
: StreamingStatistics.StandardDeviation(samples);
}
@@ -430,8 +407,7 @@ namespace MathNet.Numerics.Statistics
/// A subset of samples, sampled from the full population.
public static double StandardDeviation(this IEnumerable samples)
{
- var array = samples as float[];
- return array != null
+ return samples is float[] array
? ArrayStatistics.StandardDeviation(array)
: StreamingStatistics.StandardDeviation(samples);
}
@@ -456,8 +432,7 @@ namespace MathNet.Numerics.Statistics
/// The full population data.
public static double PopulationStandardDeviation(this IEnumerable population)
{
- var array = population as double[];
- return array != null
+ return population is double[] array
? ArrayStatistics.PopulationStandardDeviation(array)
: StreamingStatistics.PopulationStandardDeviation(population);
}
@@ -470,8 +445,7 @@ namespace MathNet.Numerics.Statistics
/// The full population data.
public static double PopulationStandardDeviation(this IEnumerable population)
{
- var array = population as float[];
- return array != null
+ return population is float[] array
? ArrayStatistics.PopulationStandardDeviation(array)
: StreamingStatistics.PopulationStandardDeviation(population);
}
@@ -589,8 +563,7 @@ namespace MathNet.Numerics.Statistics
/// The mean of the sample.
public static Tuple MeanVariance(this IEnumerable samples)
{
- var array = samples as double[];
- return array != null
+ return samples is double[] array
? ArrayStatistics.MeanVariance(array)
: StreamingStatistics.MeanVariance(samples);
}
@@ -604,8 +577,7 @@ namespace MathNet.Numerics.Statistics
/// The mean of the sample.
public static Tuple MeanVariance(this IEnumerable samples)
{
- var array = samples as float[];
- return array != null
+ return samples is float[] array
? ArrayStatistics.MeanVariance(array)
: StreamingStatistics.MeanVariance(samples);
}
@@ -619,8 +591,7 @@ namespace MathNet.Numerics.Statistics
/// The mean of the sample.
public static Tuple MeanStandardDeviation(this IEnumerable samples)
{
- var array = samples as double[];
- return array != null
+ return samples is double[] array
? ArrayStatistics.MeanStandardDeviation(array)
: StreamingStatistics.MeanStandardDeviation(samples);
}
@@ -634,8 +605,7 @@ namespace MathNet.Numerics.Statistics
/// The mean of the sample.
public static Tuple MeanStandardDeviation(this IEnumerable samples)
{
- var array = samples as float[];
- return array != null
+ return samples is float[] array
? ArrayStatistics.MeanStandardDeviation(array)
: StreamingStatistics.MeanStandardDeviation(samples);
}
@@ -671,9 +641,7 @@ namespace MathNet.Numerics.Statistics
/// A subset of samples, sampled from the full population.
public static double Covariance(this IEnumerable samples1, IEnumerable samples2)
{
- var array1 = samples1 as double[];
- var array2 = samples2 as double[];
- return array1 != null && array2 != null
+ return samples1 is double[] array1 && samples2 is double[] array2
? ArrayStatistics.Covariance(array1, array2)
: StreamingStatistics.Covariance(samples1, samples2);
}
@@ -687,9 +655,7 @@ namespace MathNet.Numerics.Statistics
/// A subset of samples, sampled from the full population.
public static double Covariance(this IEnumerable samples1, IEnumerable samples2)
{
- var array1 = samples1 as float[];
- var array2 = samples2 as float[];
- return array1 != null && array2 != null
+ return samples1 is float[] array1 && samples2 is float[] array2
? ArrayStatistics.Covariance(array1, array2)
: StreamingStatistics.Covariance(samples1, samples2);
}
@@ -716,9 +682,7 @@ namespace MathNet.Numerics.Statistics
/// The full population data.
public static double PopulationCovariance(this IEnumerable population1, IEnumerable population2)
{
- var array1 = population1 as double[];
- var array2 = population2 as double[];
- return array1 != null && array2 != null
+ return population1 is double[] array1 && population2 is double[] array2
? ArrayStatistics.PopulationCovariance(array1, array2)
: StreamingStatistics.PopulationCovariance(population1, population2);
}
@@ -732,9 +696,7 @@ namespace MathNet.Numerics.Statistics
/// The full population data.
public static double PopulationCovariance(this IEnumerable population1, IEnumerable population2)
{
- var array1 = population1 as float[];
- var array2 = population2 as float[];
- return array1 != null && array2 != null
+ return population1 is float[] array1 && population2 is float[] array2
? ArrayStatistics.PopulationCovariance(array1, array2)
: StreamingStatistics.PopulationCovariance(population1, population2);
}
@@ -759,8 +721,7 @@ namespace MathNet.Numerics.Statistics
/// The data to calculate the RMS of.
public static double RootMeanSquare(this IEnumerable data)
{
- var array = data as double[];
- return array != null
+ return data is double[] array
? ArrayStatistics.RootMeanSquare(array)
: StreamingStatistics.RootMeanSquare(data);
}
@@ -772,8 +733,7 @@ namespace MathNet.Numerics.Statistics
/// The data to calculate the RMS of.
public static double RootMeanSquare(this IEnumerable data)
{
- var array = data as float[];
- return array != null
+ return data is float[] array
? ArrayStatistics.RootMeanSquare(array)
: StreamingStatistics.RootMeanSquare(data);
}