Skip to content

Commit f616bf4

Browse files
committed
Code Maintenance
1 parent 2647084 commit f616bf4

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

src/Numerics/Integration/NewtonCotesTrapeziumRule.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ public static double IntegrateAdaptiveTransformedOdd(
268268
// First Level
269269
abcissasIterator.MoveNext();
270270
weightsIterator.MoveNext();
271-
double[] abcissasL1 = abcissasIterator.Current;
272-
double[] weightsL1 = weightsIterator.Current;
271+
double[] abcissasL1 = abcissasIterator.Current ?? throw new ArgumentNullException(nameof(levelAbscissas));
272+
double[] weightsL1 = weightsIterator.Current ?? throw new ArgumentNullException(nameof(levelWeights));
273273

274274
double sum = f(linearOffset)*weightsL1[0];
275275
for (int i = 1; i < abcissasL1.Length; i++)
@@ -283,8 +283,8 @@ public static double IntegrateAdaptiveTransformedOdd(
283283
double previousDelta = double.MaxValue;
284284
for (int level = 1; abcissasIterator.MoveNext() && weightsIterator.MoveNext(); level++)
285285
{
286-
double[] abcissas = abcissasIterator.Current;
287-
double[] weights = weightsIterator.Current;
286+
double[] abcissas = abcissasIterator.Current ?? throw new ArgumentNullException(nameof(levelAbscissas));
287+
double[] weights = weightsIterator.Current ?? throw new ArgumentNullException(nameof(levelWeights));
288288

289289
double midpointsum = 0;
290290
for (int i = 0; i < abcissas.Length; i++)
@@ -367,8 +367,8 @@ public static Complex ContourIntegrateAdaptiveTransformedOdd(
367367
// First Level
368368
abcissasIterator.MoveNext();
369369
weightsIterator.MoveNext();
370-
double[] abcissasL1 = abcissasIterator.Current;
371-
double[] weightsL1 = weightsIterator.Current;
370+
double[] abcissasL1 = abcissasIterator.Current ?? throw new ArgumentNullException(nameof(levelAbscissas));
371+
double[] weightsL1 = weightsIterator.Current ?? throw new ArgumentNullException(nameof(levelWeights));
372372

373373
Complex sum = f(linearOffset) * weightsL1[0];
374374
for (int i = 1; i < abcissasL1.Length; i++)
@@ -382,8 +382,8 @@ public static Complex ContourIntegrateAdaptiveTransformedOdd(
382382
double previousDelta = double.MaxValue;
383383
for (int level = 1; abcissasIterator.MoveNext() && weightsIterator.MoveNext(); level++)
384384
{
385-
double[] abcissas = abcissasIterator.Current;
386-
double[] weights = weightsIterator.Current;
385+
double[] abcissas = abcissasIterator.Current ?? throw new ArgumentNullException(nameof(levelAbscissas));
386+
double[] weights = weightsIterator.Current ?? throw new ArgumentNullException(nameof(levelWeights));
387387

388388
Complex midpointsum = 0;
389389
for (int i = 0; i < abcissas.Length; i++)

src/Numerics/Optimization/MinimizerBase.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ protected MinimizerBase(double gradientTolerance, double parameterTolerance, dou
5959

6060
protected ExitCondition ExitCriteriaSatisfied(IObjectiveFunctionEvaluation candidatePoint, IObjectiveFunctionEvaluation lastPoint, int iterations)
6161
{
62-
Vector<double> relGrad = new DenseVector(candidatePoint.Point.Count);
62+
var candidatePointPoint = candidatePoint.Point;
6363
double relativeGradient = 0.0;
6464
double normalizer = Math.Max(Math.Abs(candidatePoint.Value), 1.0);
65-
for (int ii = 0; ii < relGrad.Count; ++ii)
65+
for (int ii = 0; ii < candidatePointPoint.Count; ++ii)
6666
{
6767
double projectedGradient = GetProjectedGradient(candidatePoint, ii);
6868

6969
double tmp = projectedGradient *
70-
Math.Max(Math.Abs(candidatePoint.Point[ii]), 1.0) / normalizer;
70+
Math.Max(Math.Abs(candidatePointPoint[ii]), 1.0) / normalizer;
7171
relativeGradient = Math.Max(relativeGradient, Math.Abs(tmp));
7272
}
7373
if (relativeGradient < GradientTolerance)
@@ -77,11 +77,12 @@ protected ExitCondition ExitCriteriaSatisfied(IObjectiveFunctionEvaluation candi
7777

7878
if (lastPoint != null)
7979
{
80+
var lastPointPoint = lastPoint.Point;
8081
double mostProgress = 0.0;
81-
for (int ii = 0; ii < candidatePoint.Point.Count; ++ii)
82+
for (int ii = 0; ii < candidatePointPoint.Count; ++ii)
8283
{
83-
var tmp = Math.Abs(candidatePoint.Point[ii] - lastPoint.Point[ii]) /
84-
Math.Max(Math.Abs(lastPoint.Point[ii]), 1.0);
84+
var tmp = Math.Abs(candidatePointPoint[ii] - lastPointPoint[ii]) /
85+
Math.Max(Math.Abs(lastPointPoint[ii]), 1.0);
8586
mostProgress = Math.Max(mostProgress, tmp);
8687
}
8788
if (mostProgress < ParameterTolerance)

0 commit comments

Comments
 (0)