Skip to content

Commit ad98661

Browse files
committed
MatrixIeration2D will now put a warning in log if NaN encountered
If it encounters an NaN, MatrixIteration2D will put a warning in the log. Unless it throws an exception, that is.
1 parent 1453363 commit ad98661

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

src/main/java/org/optimizationBenchmarking/utils/math/matrix/processing/iterator2D/EIterationDirection.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,9 @@ final boolean _setNextXCoordinateDouble(
320320
for (position = impl.m_indexes[index]; position < max; position++) {
321321
current = matrix.getDouble(position, impl.m_xDimension);
322322
if (Double.isNaN(current)) {
323-
if (Double.isNaN(current)) {
324-
throw new IllegalStateException(//
325-
"Encountered unexpected NaN on x axis during matrix iteration in matrix "//$NON-NLS-1$
326-
+ index + " in row " + position + '.'); //$NON-NLS-1$
327-
}
323+
throw new IllegalStateException(//
324+
"Encountered unexpected NaN on x axis during matrix iteration in matrix "//$NON-NLS-1$
325+
+ index + " in row " + position + '.'); //$NON-NLS-1$
328326
}
329327
if (increasing ? (current > forbidden) : (current < forbidden)) {
330328
if (hasNot || //

src/main/java/org/optimizationBenchmarking/utils/math/matrix/processing/iterator2D/MatrixIteration2DState.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.optimizationBenchmarking.utils.math.matrix.processing.iterator2D;
22

3+
import java.util.logging.Level;
4+
35
import org.optimizationBenchmarking.utils.math.BasicNumber;
46
import org.optimizationBenchmarking.utils.math.matrix.AbstractMatrix;
57
import org.optimizationBenchmarking.utils.math.matrix.IMatrix;
@@ -144,6 +146,7 @@ private final void __setupStartAndEnd() {
144146
final IMatrix[] matrices;
145147
IMatrix matrix;
146148
int index, useStart, useEnd;
149+
boolean changedStart, changedEnd;
147150

148151
matrices = this.m_matrices;
149152
start = this.m_start;
@@ -152,6 +155,7 @@ private final void __setupStartAndEnd() {
152155
matrix = matrices[index];
153156
useStart = 0;
154157
useEnd = matrix.m();
158+
changedStart = changedEnd = false;
155159

156160
while ((useStart < useEnd) && //
157161
((this.m_skipLeadingAndTrailingXNaNs
@@ -161,6 +165,7 @@ private final void __setupStartAndEnd() {
161165
&& (Double.isNaN(matrix.getDouble(//
162166
useStart, this.m_yDimension)))))) {
163167
useStart++;
168+
changedStart = true;
164169
}
165170

166171
while ((useEnd > useStart) && //
@@ -171,6 +176,18 @@ private final void __setupStartAndEnd() {
171176
&& (Double.isNaN(matrix.getDouble(//
172177
useEnd - 1, this.m_yDimension)))))) {
173178
useEnd--;
179+
changedEnd = true;
180+
}
181+
182+
if ((changedStart || changedEnd) && //
183+
(this.m_logger != null)
184+
&& this.m_logger.isLoggable(Level.WARNING)) {
185+
this.m_logger.warning(
186+
"Encountered NaN values in data during matrix iteration at " //$NON-NLS-1$
187+
+ ((changedStart && changedEnd) ? "start and end" //$NON-NLS-1$
188+
: (changedStart ? "start" : "end")) //$NON-NLS-1$ //$NON-NLS-2$
189+
+ " in matrix at index " + index + //$NON-NLS-1$
190+
" and silently skipped them."); //$NON-NLS-1$
174191
}
175192

176193
start[index] = useStart;
@@ -289,6 +306,15 @@ final void _setYCoordinateFromMatrix(final int index,
289306
if (Double.isNaN(value)) {
290307
if (this.m_useYNaNReplacement) {
291308
value = this.m_yNaNReplacement;
309+
if ((this.m_logger != null)
310+
&& this.m_logger.isLoggable(Level.WARNING)) {
311+
this.m_logger.warning(
312+
"Encountered NaN in y dimension during matrix iteration in matrix " //$NON-NLS-1$
313+
+ index + " in row " + position + //$NON-NLS-1$
314+
" for x value " //$NON-NLS-1$
315+
+ sourceMatrix.getDouble(position, this.m_xDimension)
316+
+ " and replaced it with " + value + '.');//$NON-NLS-1$
317+
}
292318
} else {
293319
throw new IllegalStateException(//
294320
"Encountered unexpected NaN in y dimension during matrix iteration in matrix " //$NON-NLS-1$

0 commit comments

Comments
 (0)