This is an automated email from the ASF dual-hosted git repository. erans pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-math.git
commit 55e7cf0a51378a99e4cf6894b80e47f81f91e312 Author: Gilles Sadowski <gillese...@gmail.com> AuthorDate: Mon May 31 02:42:34 2021 +0200 MATH-1596: Remove dependency on "RandomVectorGenerator". --- .../commons/math4/legacy/random/HaltonSequenceGenerator.java | 12 +++++++----- .../commons/math4/legacy/random/SobolSequenceGenerator.java | 12 ++++++------ .../math4/legacy/random/HaltonSequenceGeneratorTest.java | 6 +++--- .../math4/legacy/random/SobolSequenceGeneratorTest.java | 4 ++-- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/HaltonSequenceGenerator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/HaltonSequenceGenerator.java index 63dda90..ff620b9 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/HaltonSequenceGenerator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/HaltonSequenceGenerator.java @@ -16,6 +16,8 @@ */ package org.apache.commons.math4.legacy.random; +import java.util.function.Supplier; + import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NotPositiveException; import org.apache.commons.math4.legacy.exception.NullArgumentException; @@ -41,7 +43,7 @@ import org.apache.commons.math4.legacy.exception.OutOfRangeException; * <p> * The generator supports two modes: * <ul> - * <li>sequential generation of points: {@link #nextVector()}</li> + * <li>sequential generation of points: {@link #get()}</li> * <li>random access to the i-th point in the sequence: {@link #skipTo(int)}</li> * </ul> * @@ -50,7 +52,7 @@ import org.apache.commons.math4.legacy.exception.OutOfRangeException; * On the Halton sequence and its scramblings</a> * @since 3.3 */ -public class HaltonSequenceGenerator implements RandomVectorGenerator { +public class HaltonSequenceGenerator implements Supplier<double[]> { /** The first 40 primes. */ private static final int[] PRIMES = new int[] { @@ -119,7 +121,7 @@ public class HaltonSequenceGenerator implements RandomVectorGenerator { /** {@inheritDoc} */ @Override - public double[] nextVector() { + public double[] get() { final double[] v = new double[dimension]; for (int i = 0; i < dimension; i++) { int index = count; @@ -165,12 +167,12 @@ public class HaltonSequenceGenerator implements RandomVectorGenerator { */ public double[] skipTo(final int index) { count = index; - return nextVector(); + return get(); } /** * Returns the index i of the next point in the Halton sequence that will be returned - * by calling {@link #nextVector()}. + * by calling {@link #get()}. * * @return the index of the next point */ diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/SobolSequenceGenerator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/SobolSequenceGenerator.java index c43b4f1..3bcb8ce 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/SobolSequenceGenerator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/SobolSequenceGenerator.java @@ -24,6 +24,7 @@ import java.nio.charset.Charset; import java.util.Arrays; import java.util.NoSuchElementException; import java.util.StringTokenizer; +import java.util.function.Supplier; import org.apache.commons.math4.legacy.exception.MathInternalError; import org.apache.commons.math4.legacy.exception.MathParseException; @@ -44,7 +45,7 @@ import org.apache.commons.math4.legacy.util.FastMath; * <p> * The generator supports two modes: * <ul> - * <li>sequential generation of points: {@link #nextVector()}</li> + * <li>sequential generation of points: {@link #get()}</li> * <li>random access to the i-th point in the sequence: {@link #skipTo(int)}</li> * </ul> * @@ -53,8 +54,7 @@ import org.apache.commons.math4.legacy.util.FastMath; * * @since 3.3 */ -public class SobolSequenceGenerator implements RandomVectorGenerator { - +public class SobolSequenceGenerator implements Supplier<double[]> { /** The number of bits to use. */ private static final int BITS = 52; @@ -253,7 +253,7 @@ public class SobolSequenceGenerator implements RandomVectorGenerator { /** {@inheritDoc} */ @Override - public double[] nextVector() { + public double[] get() { final double[] v = new double[dimension]; if (count == 0) { count++; @@ -308,12 +308,12 @@ public class SobolSequenceGenerator implements RandomVectorGenerator { } } count = index; - return nextVector(); + return get(); } /** * Returns the index i of the next point in the Sobol sequence that will be returned - * by calling {@link #nextVector()}. + * by calling {@link #get()}. * * @return the index of the next point */ diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/random/HaltonSequenceGeneratorTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/random/HaltonSequenceGeneratorTest.java index a756b30..4dd800b 100644 --- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/random/HaltonSequenceGeneratorTest.java +++ b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/random/HaltonSequenceGeneratorTest.java @@ -61,7 +61,7 @@ public class HaltonSequenceGeneratorTest { @Test public void test3DReference() { for (int i = 0; i < referenceValues.length; i++) { - double[] result = generator.nextVector(); + double[] result = generator.get(); Assert.assertArrayEquals(referenceValues[i], result, 1e-3); Assert.assertEquals(i + 1, generator.getNextIndex()); } @@ -71,7 +71,7 @@ public class HaltonSequenceGeneratorTest { public void test2DUnscrambledReference() { generator = new HaltonSequenceGenerator(2, new int[] {2, 3}, null); for (int i = 0; i < referenceValuesUnscrambled.length; i++) { - double[] result = generator.nextVector(); + double[] result = generator.get(); Assert.assertArrayEquals(referenceValuesUnscrambled[i], result, 1e-3); Assert.assertEquals(i + 1, generator.getNextIndex()); } @@ -125,7 +125,7 @@ public class HaltonSequenceGeneratorTest { Assert.assertEquals(6, generator.getNextIndex()); for (int i = 6; i < referenceValues.length; i++) { - result = generator.nextVector(); + result = generator.get(); Assert.assertArrayEquals(referenceValues[i], result, 1e-3); Assert.assertEquals(i + 1, generator.getNextIndex()); } diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/random/SobolSequenceGeneratorTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/random/SobolSequenceGeneratorTest.java index d77894c..11c45a3 100644 --- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/random/SobolSequenceGeneratorTest.java +++ b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/random/SobolSequenceGeneratorTest.java @@ -50,7 +50,7 @@ public class SobolSequenceGeneratorTest { @Test public void test3DReference() { for (int i = 0; i < referenceValues.length; i++) { - double[] result = generator.nextVector(); + double[] result = generator.get(); Assert.assertArrayEquals(referenceValues[i], result, 1e-6); Assert.assertEquals(i + 1, generator.getNextIndex()); } @@ -98,7 +98,7 @@ public class SobolSequenceGeneratorTest { Assert.assertEquals(6, generator.getNextIndex()); for (int i = 6; i < referenceValues.length; i++) { - result = generator.nextVector(); + result = generator.get(); Assert.assertArrayEquals(referenceValues[i], result, 1e-6); Assert.assertEquals(i + 1, generator.getNextIndex()); }