Skip to content

Commit

Permalink
Avoid redundant computations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilles Sadowski committed Oct 28, 2020
1 parent 43b77ff commit bb02fad
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/org/apache/commons/math4/util/MathArrays.java
Original file line number Diff line number Diff line change
Expand Up @@ -912,11 +912,12 @@ public static double[] normalizeArray(double[] values, double normalizedSum)
if (sum == 0) {
throw new MathArithmeticException(LocalizedFormats.ARRAY_SUMS_TO_ZERO);
}
final double scale = normalizedSum / sum;
for (int i = 0; i < len; i++) {
if (Double.isNaN(values[i])) {
out[i] = Double.NaN;
} else {
out[i] = values[i] * normalizedSum / sum;
out[i] = values[i] * scale;
}
}
return out;
Expand Down

0 comments on commit bb02fad

Please sign in to comment.