diff --git a/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/ExtendedFieldElementAbstractTest.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/ExtendedFieldElementAbstractTest.java index 5f6ab7df8..d09323a7e 100644 --- a/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/ExtendedFieldElementAbstractTest.java +++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/ExtendedFieldElementAbstractTest.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.core; import org.junit.Assert; import org.junit.Test; -import org.apache.commons.numbers.core.LinearCombination; +import org.apache.commons.numbers.core.Sum; import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.simple.RandomSource; import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; @@ -397,7 +397,7 @@ public abstract class ExtendedFieldElementAbstractTest, Seriali /** {@inheritDoc} */ @Override public SparseGradient linearCombination(final SparseGradient[] a, - final SparseGradient[] b) - throws DimensionMismatchException { - + final SparseGradient[] b) { // compute a simple value, with all partial derivatives SparseGradient out = a[0].getField().getZero(); for (int i = 0; i < a.length; ++i) { @@ -751,10 +749,9 @@ public class SparseGradient implements RealFieldElement, Seriali for (int i = 0; i < b.length; ++i) { bDouble[i] = b[i].getValue(); } - out.value = LinearCombination.value(aDouble, bDouble); + out.value = Sum.ofProducts(aDouble, bDouble).getAsDouble(); return out; - } /** {@inheritDoc} */ @@ -772,73 +769,75 @@ public class SparseGradient implements RealFieldElement, Seriali for (int i = 0; i < b.length; ++i) { bDouble[i] = b[i].getValue(); } - out.value = LinearCombination.value(a, bDouble); + out.value = Sum.ofProducts(a, bDouble).getAsDouble(); return out; - } /** {@inheritDoc} */ @Override public SparseGradient linearCombination(final SparseGradient a1, final SparseGradient b1, - final SparseGradient a2, final SparseGradient b2) { + final SparseGradient a2, final SparseGradient b2) { // compute a simple value, with all partial derivatives SparseGradient out = a1.multiply(b1).add(a2.multiply(b2)); // recompute an accurate value, taking care of cancellations - out.value = LinearCombination.value(a1.value, b1.value, a2.value, b2.value); + out.value = Sum.create() + .addProduct(a1.value, b1.value) + .addProduct(a2.value, b2.value).getAsDouble(); return out; - } /** {@inheritDoc} */ @Override public SparseGradient linearCombination(final double a1, final SparseGradient b1, - final double a2, final SparseGradient b2) { + final double a2, final SparseGradient b2) { // compute a simple value, with all partial derivatives SparseGradient out = b1.multiply(a1).add(b2.multiply(a2)); // recompute an accurate value, taking care of cancellations - out.value = LinearCombination.value(a1, b1.value, a2, b2.value); + out.value = Sum.create() + .addProduct(a1, b1.value) + .addProduct(a2, b2.value).getAsDouble(); return out; - } /** {@inheritDoc} */ @Override public SparseGradient linearCombination(final SparseGradient a1, final SparseGradient b1, - final SparseGradient a2, final SparseGradient b2, - final SparseGradient a3, final SparseGradient b3) { + final SparseGradient a2, final SparseGradient b2, + final SparseGradient a3, final SparseGradient b3) { // compute a simple value, with all partial derivatives SparseGradient out = a1.multiply(b1).add(a2.multiply(b2)).add(a3.multiply(b3)); // recompute an accurate value, taking care of cancellations - out.value = LinearCombination.value(a1.value, b1.value, - a2.value, b2.value, - a3.value, b3.value); + out.value = Sum.create() + .addProduct(a1.value, b1.value) + .addProduct(a2.value, b2.value) + .addProduct(a3.value, b3.value).getAsDouble(); return out; - } /** {@inheritDoc} */ @Override public SparseGradient linearCombination(final double a1, final SparseGradient b1, - final double a2, final SparseGradient b2, - final double a3, final SparseGradient b3) { + final double a2, final SparseGradient b2, + final double a3, final SparseGradient b3) { // compute a simple value, with all partial derivatives SparseGradient out = b1.multiply(a1).add(b2.multiply(a2)).add(b3.multiply(a3)); // recompute an accurate value, taking care of cancellations - out.value = LinearCombination.value(a1, b1.value, - a2, b2.value, - a3, b3.value); + out.value = Sum.create() + .addProduct(a1, b1.value) + .addProduct(a2, b2.value) + .addProduct(a3, b3.value).getAsDouble(); return out; @@ -847,21 +846,21 @@ public class SparseGradient implements RealFieldElement, Seriali /** {@inheritDoc} */ @Override public SparseGradient linearCombination(final SparseGradient a1, final SparseGradient b1, - final SparseGradient a2, final SparseGradient b2, - final SparseGradient a3, final SparseGradient b3, - final SparseGradient a4, final SparseGradient b4) { + final SparseGradient a2, final SparseGradient b2, + final SparseGradient a3, final SparseGradient b3, + final SparseGradient a4, final SparseGradient b4) { // compute a simple value, with all partial derivatives SparseGradient out = a1.multiply(b1).add(a2.multiply(b2)).add(a3.multiply(b3)).add(a4.multiply(b4)); // recompute an accurate value, taking care of cancellations - out.value = LinearCombination.value(a1.value, b1.value, - a2.value, b2.value, - a3.value, b3.value, - a4.value, b4.value); + out.value = Sum.create() + .addProduct(a1.value, b1.value) + .addProduct(a2.value, b2.value) + .addProduct(a3.value, b3.value) + .addProduct(a4.value, b4.value).getAsDouble(); return out; - } /** {@inheritDoc} */ @@ -875,13 +874,13 @@ public class SparseGradient implements RealFieldElement, Seriali SparseGradient out = b1.multiply(a1).add(b2.multiply(a2)).add(b3.multiply(a3)).add(b4.multiply(a4)); // recompute an accurate value, taking care of cancellations - out.value = LinearCombination.value(a1, b1.value, - a2, b2.value, - a3, b3.value, - a4, b4.value); + out.value = Sum.create() + .addProduct(a1, b1.value) + .addProduct(a2, b2.value) + .addProduct(a3, b3.value) + .addProduct(a4, b4.value).getAsDouble(); return out; - } /** @@ -932,5 +931,4 @@ public class SparseGradient implements RealFieldElement, Seriali public int hashCode() { return 743 + 809 * Double.hashCode(value) + 167 * derivatives.hashCode(); } - } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/BicubicInterpolatingFunction.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/BicubicInterpolatingFunction.java index 7ceb2888d..7e493f73c 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/BicubicInterpolatingFunction.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/BicubicInterpolatingFunction.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.interpolation; import java.util.Arrays; -import org.apache.commons.numbers.core.LinearCombination; +import org.apache.commons.numbers.core.Sum; import org.apache.commons.math4.legacy.analysis.BivariateFunction; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NoDataException; @@ -320,7 +320,7 @@ class BicubicFunction implements BivariateFunction { private double apply(double[] pX, double[] pY, double[][] coeff) { double result = 0; for (int i = 0; i < N; i++) { - final double r = LinearCombination.value(coeff[i], pY); + final double r = Sum.ofProducts(coeff[i], pY).getAsDouble(); result += r * pX[i]; } diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/field/ExtendedFieldElementAbstractTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/field/ExtendedFieldElementAbstractTest.java index 64e2ae30c..5c111ed55 100644 --- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/field/ExtendedFieldElementAbstractTest.java +++ b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/field/ExtendedFieldElementAbstractTest.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.field; import org.junit.Assert; import org.junit.Test; -import org.apache.commons.numbers.core.LinearCombination; +import org.apache.commons.numbers.core.Sum; import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.simple.RandomSource; import org.apache.commons.math4.legacy.core.RealFieldElement; @@ -399,7 +399,7 @@ public abstract class ExtendedFieldElementAbstractTest