Adapt to "Commons Numbers" API update (cf. NUMBERS-163).

This commit is contained in:
Gilles Sadowski 2021-06-23 02:09:48 +02:00
parent 0a3c4023dd
commit 03923d2b79
8 changed files with 163 additions and 125 deletions

View File

@ -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<T extends RealFieldElemen
double[] bD = generateDouble(r, 10);
T[] aF = toFieldArray(aD);
T[] bF = toFieldArray(bD);
checkRelative(LinearCombination.value(aD, bD),
checkRelative(Sum.ofProducts(aD, bD).getAsDouble(),
aF[0].linearCombination(aF, bF));
}
}
@ -409,7 +409,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
double[] aD = generateDouble(r, 10);
double[] bD = generateDouble(r, 10);
T[] bF = toFieldArray(bD);
checkRelative(LinearCombination.value(aD, bD),
checkRelative(Sum.ofProducts(aD, bD).getAsDouble(),
bF[0].linearCombination(aD, bF));
}
}
@ -422,7 +422,9 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
double[] bD = generateDouble(r, 2);
T[] aF = toFieldArray(aD);
T[] bF = toFieldArray(bD);
checkRelative(LinearCombination.value(aD[0], bD[0], aD[1], bD[1]),
checkRelative(Sum.create()
.addProduct(aD[0], bD[0])
.addProduct(aD[1], bD[1]).getAsDouble(),
aF[0].linearCombination(aF[0], bF[0], aF[1], bF[1]));
}
}
@ -434,7 +436,9 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
double[] aD = generateDouble(r, 2);
double[] bD = generateDouble(r, 2);
T[] bF = toFieldArray(bD);
checkRelative(LinearCombination.value(aD[0], bD[0], aD[1], bD[1]),
checkRelative(Sum.create()
.addProduct(aD[0], bD[0])
.addProduct(aD[1], bD[1]).getAsDouble(),
bF[0].linearCombination(aD[0], bF[0], aD[1], bF[1]));
}
}
@ -447,7 +451,10 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
double[] bD = generateDouble(r, 3);
T[] aF = toFieldArray(aD);
T[] bF = toFieldArray(bD);
checkRelative(LinearCombination.value(aD[0], bD[0], aD[1], bD[1], aD[2], bD[2]),
checkRelative(Sum.create()
.addProduct(aD[0], bD[0])
.addProduct(aD[1], bD[1])
.addProduct(aD[2], bD[2]).getAsDouble(),
aF[0].linearCombination(aF[0], bF[0], aF[1], bF[1], aF[2], bF[2]));
}
}
@ -459,7 +466,10 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
double[] aD = generateDouble(r, 3);
double[] bD = generateDouble(r, 3);
T[] bF = toFieldArray(bD);
checkRelative(LinearCombination.value(aD[0], bD[0], aD[1], bD[1], aD[2], bD[2]),
checkRelative(Sum.create()
.addProduct(aD[0], bD[0])
.addProduct(aD[1], bD[1])
.addProduct(aD[2], bD[2]).getAsDouble(),
bF[0].linearCombination(aD[0], bF[0], aD[1], bF[1], aD[2], bF[2]));
}
}
@ -472,7 +482,11 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
double[] bD = generateDouble(r, 4);
T[] aF = toFieldArray(aD);
T[] bF = toFieldArray(bD);
checkRelative(LinearCombination.value(aD[0], bD[0], aD[1], bD[1], aD[2], bD[2], aD[3], bD[3]),
checkRelative(Sum.create()
.addProduct(aD[0], bD[0])
.addProduct(aD[1], bD[1])
.addProduct(aD[2], bD[2])
.addProduct(aD[3], bD[3]).getAsDouble(),
aF[0].linearCombination(aF[0], bF[0], aF[1], bF[1], aF[2], bF[2], aF[3], bF[3]));
}
}
@ -484,7 +498,11 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
double[] aD = generateDouble(r, 4);
double[] bD = generateDouble(r, 4);
T[] bF = toFieldArray(bD);
checkRelative(LinearCombination.value(aD[0], bD[0], aD[1], bD[1], aD[2], bD[2], aD[3], bD[3]),
checkRelative(Sum.create()
.addProduct(aD[0], bD[0])
.addProduct(aD[1], bD[1])
.addProduct(aD[2], bD[2])
.addProduct(aD[3], bD[3]).getAsDouble(),
bF[0].linearCombination(aD[0], bF[0], aD[1], bF[1], aD[2], bF[2], aD[3], bF[3]));
}
}

View File

@ -17,7 +17,7 @@
package org.apache.commons.math4.legacy.analysis;
import org.apache.commons.numbers.core.LinearCombination;
import org.apache.commons.numbers.core.Sum;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.MultivariateDifferentiableFunction;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
@ -380,7 +380,7 @@ public class FunctionUtils {
* @see #derivative(MultivariateDifferentiableFunction, int[])
*/
public static MultivariateDifferentiableFunction toDifferentiable(final MultivariateFunction f,
final MultivariateVectorFunction gradient) {
final MultivariateVectorFunction gradient) {
return new MultivariateDifferentiableFunction() {
@ -427,16 +427,12 @@ public class FunctionUtils {
orders[i] = 0;
// compose partial derivatives
packed[i + 1] = LinearCombination.value(dv, partials);
packed[i + 1] = Sum.ofProducts(dv, partials).getAsDouble();
}
return new DerivativeStructure(parameters, 1, packed);
}
};
}
/** Convert an {@link UnivariateDifferentiableFunction} to an

View File

@ -21,7 +21,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.numbers.core.LinearCombination;
import org.apache.commons.numbers.core.Sum;
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.MathArithmeticException;
import org.apache.commons.math4.legacy.exception.MathInternalError;
@ -667,8 +667,9 @@ public class DSCompiler {
final double a2, final double[] c2, final int offset2,
final double[] result, final int resultOffset) {
for (int i = 0; i < getSize(); ++i) {
result[resultOffset + i] =
LinearCombination.value(a1, c1[offset1 + i], a2, c2[offset2 + i]);
result[resultOffset + i] = Sum.create()
.addProduct(a1, c1[offset1 + i])
.addProduct(a2, c2[offset2 + i]).getAsDouble();
}
}
@ -692,10 +693,10 @@ public class DSCompiler {
final double a3, final double[] c3, final int offset3,
final double[] result, final int resultOffset) {
for (int i = 0; i < getSize(); ++i) {
result[resultOffset + i] =
LinearCombination.value(a1, c1[offset1 + i],
a2, c2[offset2 + i],
a3, c3[offset3 + i]);
result[resultOffset + i] = Sum.create()
.addProduct(a1, c1[offset1 + i])
.addProduct(a2, c2[offset2 + i])
.addProduct(a3, c3[offset3 + i]).getAsDouble();
}
}
@ -723,11 +724,11 @@ public class DSCompiler {
final double a4, final double[] c4, final int offset4,
final double[] result, final int resultOffset) {
for (int i = 0; i < getSize(); ++i) {
result[resultOffset + i] =
LinearCombination.value(a1, c1[offset1 + i],
a2, c2[offset2 + i],
a3, c3[offset3 + i],
a4, c4[offset4 + i]);
result[resultOffset + i] = Sum.create()
.addProduct(a1, c1[offset1 + i])
.addProduct(a2, c2[offset2 + i])
.addProduct(a3, c3[offset3 + i])
.addProduct(a4, c4[offset4 + i]).getAsDouble();
}
}

View File

@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.differentiation;
import java.util.Arrays;
import java.io.Serializable;
import org.apache.commons.numbers.core.LinearCombination;
import org.apache.commons.numbers.core.Sum;
import org.apache.commons.math4.legacy.core.Field;
import org.apache.commons.math4.legacy.core.FieldElement;
import org.apache.commons.math4.legacy.core.RealFieldElement;
@ -966,7 +966,7 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
for (int i = 0; i < b.length; ++i) {
bDouble[i] = b[i].getValue();
}
final double accurateValue = LinearCombination.value(aDouble, bDouble);
final double accurateValue = Sum.ofProducts(aDouble, bDouble).getAsDouble();
// compute a simple value, with all partial derivatives
DerivativeStructure simpleValue = a[0].getField().getZero();
@ -995,7 +995,7 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
for (int i = 0; i < b.length; ++i) {
bDouble[i] = b[i].getValue();
}
final double accurateValue = LinearCombination.value(a, bDouble);
final double accurateValue = Sum.ofProducts(a, bDouble).getAsDouble();
// compute a simple value, with all partial derivatives
DerivativeStructure simpleValue = b[0].getField().getZero();
@ -1021,8 +1021,9 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
throws DimensionMismatchException {
// compute an accurate value, taking care of cancellations
final double accurateValue = LinearCombination.value(a1.getValue(), b1.getValue(),
a2.getValue(), b2.getValue());
final double accurateValue = Sum.create()
.addProduct(a1.getValue(), b1.getValue())
.addProduct(a2.getValue(), b2.getValue()).getAsDouble();
// compute a simple value, with all partial derivatives
final DerivativeStructure simpleValue = a1.multiply(b1).add(a2.multiply(b2));
@ -1031,7 +1032,6 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
final double[] all = simpleValue.getAllDerivatives();
all[0] = accurateValue;
return new DerivativeStructure(getFreeParameters(), getOrder(), all);
}
/** {@inheritDoc}
@ -1045,8 +1045,9 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
throws DimensionMismatchException {
// compute an accurate value, taking care of cancellations
final double accurateValue = LinearCombination.value(a1, b1.getValue(),
a2, b2.getValue());
final double accurateValue = Sum.create()
.addProduct(a1, b1.getValue())
.addProduct(a2, b2.getValue()).getAsDouble();
// compute a simple value, with all partial derivatives
final DerivativeStructure simpleValue = b1.multiply(a1).add(b2.multiply(a2));
@ -1070,9 +1071,10 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
throws DimensionMismatchException {
// compute an accurate value, taking care of cancellations
final double accurateValue = LinearCombination.value(a1.getValue(), b1.getValue(),
a2.getValue(), b2.getValue(),
a3.getValue(), b3.getValue());
final double accurateValue = Sum.create()
.addProduct(a1.getValue(), b1.getValue())
.addProduct(a2.getValue(), b2.getValue())
.addProduct(a3.getValue(), b3.getValue()).getAsDouble();
// compute a simple value, with all partial derivatives
final DerivativeStructure simpleValue = a1.multiply(b1).add(a2.multiply(b2)).add(a3.multiply(b3));
@ -1096,9 +1098,10 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
throws DimensionMismatchException {
// compute an accurate value, taking care of cancellations
final double accurateValue = LinearCombination.value(a1, b1.getValue(),
a2, b2.getValue(),
a3, b3.getValue());
final double accurateValue = Sum.create()
.addProduct(a1, b1.getValue())
.addProduct(a2, b2.getValue())
.addProduct(a3, b3.getValue()).getAsDouble();
// compute a simple value, with all partial derivatives
final DerivativeStructure simpleValue = b1.multiply(a1).add(b2.multiply(a2)).add(b3.multiply(a3));
@ -1107,7 +1110,6 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
final double[] all = simpleValue.getAllDerivatives();
all[0] = accurateValue;
return new DerivativeStructure(getFreeParameters(), getOrder(), all);
}
/** {@inheritDoc}
@ -1123,10 +1125,11 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
throws DimensionMismatchException {
// compute an accurate value, taking care of cancellations
final double accurateValue = LinearCombination.value(a1.getValue(), b1.getValue(),
a2.getValue(), b2.getValue(),
a3.getValue(), b3.getValue(),
a4.getValue(), b4.getValue());
final double accurateValue = Sum.create()
.addProduct(a1.getValue(), b1.getValue())
.addProduct(a2.getValue(), b2.getValue())
.addProduct(a3.getValue(), b3.getValue())
.addProduct(a4.getValue(), b4.getValue()).getAsDouble();
// compute a simple value, with all partial derivatives
final DerivativeStructure simpleValue = a1.multiply(b1).add(a2.multiply(b2)).add(a3.multiply(b3)).add(a4.multiply(b4));
@ -1135,7 +1138,6 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
final double[] all = simpleValue.getAllDerivatives();
all[0] = accurateValue;
return new DerivativeStructure(getFreeParameters(), getOrder(), all);
}
/** {@inheritDoc}
@ -1151,10 +1153,11 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
throws DimensionMismatchException {
// compute an accurate value, taking care of cancellations
final double accurateValue = LinearCombination.value(a1, b1.getValue(),
a2, b2.getValue(),
a3, b3.getValue(),
a4, b4.getValue());
final double accurateValue = Sum.create()
.addProduct(a1, b1.getValue())
.addProduct(a2, b2.getValue())
.addProduct(a3, b3.getValue())
.addProduct(a4, b4.getValue()).getAsDouble();
// compute a simple value, with all partial derivatives
final DerivativeStructure simpleValue = b1.multiply(a1).add(b2.multiply(a2)).add(b3.multiply(a3)).add(b4.multiply(a4));
@ -1163,7 +1166,6 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
final double[] all = simpleValue.getAllDerivatives();
all[0] = accurateValue;
return new DerivativeStructure(getFreeParameters(), getOrder(), all);
}
/**

View File

@ -21,7 +21,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.numbers.core.LinearCombination;
import org.apache.commons.numbers.core.Sum;
import org.apache.commons.numbers.core.Precision;
import org.apache.commons.math4.legacy.core.Field;
import org.apache.commons.math4.legacy.core.FieldElement;
@ -733,9 +733,7 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, 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<SparseGradient>, 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<SparseGradient>, 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<SparseGradient>, 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<SparseGradient>, 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<SparseGradient>, Seriali
public int hashCode() {
return 743 + 809 * Double.hashCode(value) + 167 * derivatives.hashCode();
}
}

View File

@ -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];
}

View File

@ -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<T extends RealFieldElemen
double[] bD = generateDouble(r, 10);
T[] aF = toFieldArray(aD);
T[] bF = toFieldArray(bD);
checkRelative(LinearCombination.value(aD, bD),
checkRelative(Sum.ofProducts(aD, bD).getAsDouble(),
aF[0].linearCombination(aF, bF));
}
}
@ -411,7 +411,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
double[] aD = generateDouble(r, 10);
double[] bD = generateDouble(r, 10);
T[] bF = toFieldArray(bD);
checkRelative(LinearCombination.value(aD, bD),
checkRelative(Sum.ofProducts(aD, bD).getAsDouble(),
bF[0].linearCombination(aD, bF));
}
}
@ -424,7 +424,9 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
double[] bD = generateDouble(r, 2);
T[] aF = toFieldArray(aD);
T[] bF = toFieldArray(bD);
checkRelative(LinearCombination.value(aD[0], bD[0], aD[1], bD[1]),
checkRelative(Sum.create()
.addProduct(aD[0], bD[0])
.addProduct(aD[1], bD[1]).getAsDouble(),
aF[0].linearCombination(aF[0], bF[0], aF[1], bF[1]));
}
}
@ -436,7 +438,9 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
double[] aD = generateDouble(r, 2);
double[] bD = generateDouble(r, 2);
T[] bF = toFieldArray(bD);
checkRelative(LinearCombination.value(aD[0], bD[0], aD[1], bD[1]),
checkRelative(Sum.create()
.addProduct(aD[0], bD[0])
.addProduct(aD[1], bD[1]).getAsDouble(),
bF[0].linearCombination(aD[0], bF[0], aD[1], bF[1]));
}
}
@ -449,7 +453,10 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
double[] bD = generateDouble(r, 3);
T[] aF = toFieldArray(aD);
T[] bF = toFieldArray(bD);
checkRelative(LinearCombination.value(aD[0], bD[0], aD[1], bD[1], aD[2], bD[2]),
checkRelative(Sum.create()
.addProduct(aD[0], bD[0])
.addProduct(aD[1], bD[1])
.addProduct(aD[2], bD[2]).getAsDouble(),
aF[0].linearCombination(aF[0], bF[0], aF[1], bF[1], aF[2], bF[2]));
}
}
@ -461,7 +468,10 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
double[] aD = generateDouble(r, 3);
double[] bD = generateDouble(r, 3);
T[] bF = toFieldArray(bD);
checkRelative(LinearCombination.value(aD[0], bD[0], aD[1], bD[1], aD[2], bD[2]),
checkRelative(Sum.create()
.addProduct(aD[0], bD[0])
.addProduct(aD[1], bD[1])
.addProduct(aD[2], bD[2]).getAsDouble(),
bF[0].linearCombination(aD[0], bF[0], aD[1], bF[1], aD[2], bF[2]));
}
}
@ -474,7 +484,11 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
double[] bD = generateDouble(r, 4);
T[] aF = toFieldArray(aD);
T[] bF = toFieldArray(bD);
checkRelative(LinearCombination.value(aD[0], bD[0], aD[1], bD[1], aD[2], bD[2], aD[3], bD[3]),
checkRelative(Sum.create()
.addProduct(aD[0], bD[0])
.addProduct(aD[1], bD[1])
.addProduct(aD[2], bD[2])
.addProduct(aD[3], bD[3]).getAsDouble(),
aF[0].linearCombination(aF[0], bF[0], aF[1], bF[1], aF[2], bF[2], aF[3], bF[3]));
}
}
@ -486,7 +500,11 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
double[] aD = generateDouble(r, 4);
double[] bD = generateDouble(r, 4);
T[] bF = toFieldArray(bD);
checkRelative(LinearCombination.value(aD[0], bD[0], aD[1], bD[1], aD[2], bD[2], aD[3], bD[3]),
checkRelative(Sum.create()
.addProduct(aD[0], bD[0])
.addProduct(aD[1], bD[1])
.addProduct(aD[2], bD[2])
.addProduct(aD[3], bD[3]).getAsDouble(),
bF[0].linearCombination(aD[0], bF[0], aD[1], bF[1], aD[2], bF[2], aD[3], bF[3]));
}
}

View File

@ -16,8 +16,8 @@
*/
package org.apache.commons.math4.legacy.ode.nonstiff;
import org.apache.commons.numbers.core.Sum;
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
import org.apache.commons.numbers.core.LinearCombination;
import org.apache.commons.math4.legacy.core.Field;
import org.apache.commons.math4.legacy.core.RealFieldElement;
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
@ -661,7 +661,7 @@ public class Decimal64 extends Number
aDouble[i] = a[i].value;
bDouble[i] = b[i].value;
}
return new Decimal64(LinearCombination.value(aDouble, bDouble));
return new Decimal64(Sum.ofProducts(aDouble, bDouble).getAsDouble());
}
/** {@inheritDoc}
@ -677,7 +677,7 @@ public class Decimal64 extends Number
for (int i = 0; i < a.length; ++i) {
bDouble[i] = b[i].value;
}
return new Decimal64(LinearCombination.value(a, bDouble));
return new Decimal64(Sum.ofProducts(a, bDouble).getAsDouble());
}
/** {@inheritDoc}
@ -686,8 +686,9 @@ public class Decimal64 extends Number
@Override
public Decimal64 linearCombination(final Decimal64 a1, final Decimal64 b1,
final Decimal64 a2, final Decimal64 b2) {
return new Decimal64(LinearCombination.value(a1.value, b1.value,
a2.value, b2.value));
return new Decimal64(Sum.create()
.addProduct(a1.value, b1.value)
.addProduct(a2.value, b2.value).getAsDouble());
}
/** {@inheritDoc}
@ -696,8 +697,9 @@ public class Decimal64 extends Number
@Override
public Decimal64 linearCombination(final double a1, final Decimal64 b1,
final double a2, final Decimal64 b2) {
return new Decimal64(LinearCombination.value(a1, b1.value,
a2, b2.value));
return new Decimal64(Sum.create()
.addProduct(a1, b1.value)
.addProduct(a2, b2.value).getAsDouble());
}
/** {@inheritDoc}
@ -707,9 +709,10 @@ public class Decimal64 extends Number
public Decimal64 linearCombination(final Decimal64 a1, final Decimal64 b1,
final Decimal64 a2, final Decimal64 b2,
final Decimal64 a3, final Decimal64 b3) {
return new Decimal64(LinearCombination.value(a1.value, b1.value,
a2.value, b2.value,
a3.value, b3.value));
return new Decimal64(Sum.create()
.addProduct(a1.value, b1.value)
.addProduct(a2.value, b2.value)
.addProduct(a3.value, b3.value).getAsDouble());
}
/** {@inheritDoc}
@ -719,9 +722,10 @@ public class Decimal64 extends Number
public Decimal64 linearCombination(final double a1, final Decimal64 b1,
final double a2, final Decimal64 b2,
final double a3, final Decimal64 b3) {
return new Decimal64(LinearCombination.value(a1, b1.value,
a2, b2.value,
a3, b3.value));
return new Decimal64(Sum.create()
.addProduct(a1, b1.value)
.addProduct(a2, b2.value)
.addProduct(a3, b3.value).getAsDouble());
}
/** {@inheritDoc}
@ -732,10 +736,11 @@ public class Decimal64 extends Number
final Decimal64 a2, final Decimal64 b2,
final Decimal64 a3, final Decimal64 b3,
final Decimal64 a4, final Decimal64 b4) {
return new Decimal64(LinearCombination.value(a1.value, b1.value,
a2.value, b2.value,
a3.value, b3.value,
a4.value, b4.value));
return new Decimal64(Sum.create()
.addProduct(a1.value, b1.value)
.addProduct(a2.value, b2.value)
.addProduct(a3.value, b3.value)
.addProduct(a4.value, b4.value).getAsDouble());
}
/** {@inheritDoc}
@ -746,10 +751,10 @@ public class Decimal64 extends Number
final double a2, final Decimal64 b2,
final double a3, final Decimal64 b3,
final double a4, final Decimal64 b4) {
return new Decimal64(LinearCombination.value(a1, b1.value,
a2, b2.value,
a3, b3.value,
a4, b4.value));
return new Decimal64(Sum.create()
.addProduct(a1, b1.value)
.addProduct(a2, b2.value)
.addProduct(a3, b3.value)
.addProduct(a4, b4.value).getAsDouble());
}
}