You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2018/08/16 13:14:15 UTC
[1/3] commons-rng git commit: Number of rerun set to 1 in sampling
tests.
Repository: commons-rng
Updated Branches:
refs/heads/master f2586803f -> 74c2b58d3
Number of rerun set to 1 in sampling tests.
Reinstates commit 2a31d8764facb77c8a3c301b0613078df8c93d13.
Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/c54506bd
Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/c54506bd
Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/c54506bd
Branch: refs/heads/master
Commit: c54506bd2859ae351b108e7b87494652812f9db8
Parents: f258680
Author: Gilles <er...@apache.org>
Authored: Thu Aug 16 14:23:47 2018 +0200
Committer: Gilles <er...@apache.org>
Committed: Thu Aug 16 14:23:47 2018 +0200
----------------------------------------------------------------------
commons-rng-sampling/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-rng/blob/c54506bd/commons-rng-sampling/pom.xml
----------------------------------------------------------------------
diff --git a/commons-rng-sampling/pom.xml b/commons-rng-sampling/pom.xml
index f56eec0..90c291a 100644
--- a/commons-rng-sampling/pom.xml
+++ b/commons-rng-sampling/pom.xml
@@ -72,7 +72,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
- <rerunFailingTestsCount>4</rerunFailingTestsCount>
+ <rerunFailingTestsCount>1</rerunFailingTestsCount>
</configuration>
</plugin>
</plugins>
[3/3] commons-rng git commit: RNG-55: Forbid negative dimension.
Posted by er...@apache.org.
RNG-55: Forbid negative dimension.
Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/74c2b58d
Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/74c2b58d
Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/74c2b58d
Branch: refs/heads/master
Commit: 74c2b58d321f1cd08e3a9b8f1911bada8008a319
Parents: 8539ccb
Author: Gilles <er...@apache.org>
Authored: Thu Aug 16 14:52:00 2018 +0200
Committer: Gilles <er...@apache.org>
Committed: Thu Aug 16 14:52:00 2018 +0200
----------------------------------------------------------------------
.../java/org/apache/commons/rng/sampling/UnitSphereSampler.java | 4 ++++
.../org/apache/commons/rng/sampling/UnitSphereSamplerTest.java | 5 +++++
src/changes/changes.xml | 3 ++-
3 files changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-rng/blob/74c2b58d/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/UnitSphereSampler.java
----------------------------------------------------------------------
diff --git a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/UnitSphereSampler.java b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/UnitSphereSampler.java
index 46dd474..cbb3785 100644
--- a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/UnitSphereSampler.java
+++ b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/UnitSphereSampler.java
@@ -40,6 +40,10 @@ public class UnitSphereSampler {
*/
public UnitSphereSampler(int dimension,
UniformRandomProvider rng) {
+ if (dimension <= 0) {
+ throw new IllegalArgumentException("Dimension must be strictly positive");
+ }
+
this.dimension = dimension;
sampler = new ZigguratNormalizedGaussianSampler(rng);
}
http://git-wip-us.apache.org/repos/asf/commons-rng/blob/74c2b58d/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/UnitSphereSamplerTest.java
----------------------------------------------------------------------
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/UnitSphereSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/UnitSphereSamplerTest.java
index 2b7ff47..fb4ac08 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/UnitSphereSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/UnitSphereSamplerTest.java
@@ -25,6 +25,11 @@ import org.apache.commons.rng.UniformRandomProvider;
* Test for {@link UnitSphereSampler}.
*/
public class UnitSphereSamplerTest {
+ @Test(expected = IllegalArgumentException.class)
+ public void testPrecondition() {
+ new UnitSphereSampler(0, null);
+ }
+
/**
* Test the distribution of points in two dimensions.
*/
http://git-wip-us.apache.org/repos/asf/commons-rng/blob/74c2b58d/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 2bd1a44..bbb9893 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -68,7 +68,8 @@ It is however not part of the official API and no compatibility
should be expected in subsequent releases.
">
<action dev="erans" type="fix" issue="RNG-55" due-to="Alex D. Herbert">
- "UnitSphereSampler": Prevent returning NaN components.
+ "UnitSphereSampler": Prevent returning NaN components and forbid
+ negative dimension.
</action>
</release>
[2/3] commons-rng git commit: RNG-55: Check for zero norm.
Posted by er...@apache.org.
RNG-55: Check for zero norm.
Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/8539ccbe
Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/8539ccbe
Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/8539ccbe
Branch: refs/heads/master
Commit: 8539ccbeda3d390390cfc57185cfc6d2f6d0ebee
Parents: c54506b
Author: Gilles <er...@apache.org>
Authored: Thu Aug 16 14:44:56 2018 +0200
Committer: Gilles <er...@apache.org>
Committed: Thu Aug 16 14:44:56 2018 +0200
----------------------------------------------------------------------
.../commons/rng/sampling/UnitSphereSampler.java | 9 +++++++++
.../rng/sampling/UnitSphereSamplerTest.java | 18 ++++++++++++++++++
src/changes/changes.xml | 3 +++
3 files changed, 30 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-rng/blob/8539ccbe/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/UnitSphereSampler.java
----------------------------------------------------------------------
diff --git a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/UnitSphereSampler.java b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/UnitSphereSampler.java
index b289025..46dd474 100644
--- a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/UnitSphereSampler.java
+++ b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/UnitSphereSampler.java
@@ -59,6 +59,15 @@ public class UnitSphereSampler {
normSq += comp * comp;
}
+ if (normSq == 0) {
+ // Zero-norm vector is discarded.
+ // Using recursion as it is highly unlikely to generate more
+ // than a few such vectors. It also protects against infinite
+ // loop (in case a buggy generator is used), by eventually
+ // raising a "StackOverflowError".
+ return nextVector();
+ }
+
final double f = 1 / Math.sqrt(normSq);
for (int i = 0; i < dimension; i++) {
v[i] *= f;
http://git-wip-us.apache.org/repos/asf/commons-rng/blob/8539ccbe/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/UnitSphereSamplerTest.java
----------------------------------------------------------------------
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/UnitSphereSamplerTest.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/UnitSphereSamplerTest.java
index a66e4cd..2b7ff47 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/UnitSphereSamplerTest.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/UnitSphereSamplerTest.java
@@ -56,6 +56,24 @@ public class UnitSphereSamplerTest {
}
}
+ /** Cf. RNG-55. */
+ @Test(expected = StackOverflowError.class)
+ public void testBadProvider1() {
+ final UniformRandomProvider bad = new UniformRandomProvider() {
+ public long nextLong(long n) { return 0; }
+ public long nextLong() { return 0; }
+ public int nextInt(int n) { return 0; }
+ public int nextInt() { return 0; }
+ public float nextFloat() { return 0; }
+ public double nextDouble() { return 0;}
+ public void nextBytes(byte[] bytes, int start, int len) {}
+ public void nextBytes(byte[] bytes) {}
+ public boolean nextBoolean() { return false; }
+ };
+
+ new UnitSphereSampler(1, bad).nextVector();
+ }
+
/**
* @return the length (L2-norm) of given vector.
*/
http://git-wip-us.apache.org/repos/asf/commons-rng/blob/8539ccbe/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f36c4e3..2bd1a44 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -67,6 +67,9 @@ Additional code is provided in the following module:
It is however not part of the official API and no compatibility
should be expected in subsequent releases.
">
+ <action dev="erans" type="fix" issue="RNG-55" due-to="Alex D. Herbert">
+ "UnitSphereSampler": Prevent returning NaN components.
+ </action>
</release>
<release version="1.1" date="2018-08-14" description="