This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit 803f9cd8eed29597aa2a84866e82c620b4ce175b
Author: Alex Herbert <[email protected]>
AuthorDate: Wed Aug 26 09:03:35 2026 +0100

    Validate alpha is finite
---
 .../rng/sampling/distribution/GuideTableDiscreteSampler.java |  7 ++++---
 .../sampling/distribution/GuideTableDiscreteSamplerTest.java | 12 ++++--------
 src/changes/changes.xml                                      |  3 +++
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git 
a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/GuideTableDiscreteSampler.java
 
b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/GuideTableDiscreteSampler.java
index 7d38aaad..d5002ade 100644
--- 
a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/GuideTableDiscreteSampler.java
+++ 
b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/GuideTableDiscreteSampler.java
@@ -143,7 +143,8 @@ public final class GuideTableDiscreteSampler
      * @return the sampler
      * @throws IllegalArgumentException if {@code probabilities} is null or 
empty, a
      * probability is negative, infinite or {@code NaN}, the sum of all
-     * probabilities is not strictly positive, or {@code alpha} is not 
strictly positive.
+     * probabilities is not strictly positive, or {@code alpha} is not strictly
+     * positive and finite.
      */
     public static SharedStateDiscreteSampler of(UniformRandomProvider rng,
                                                 double[] probabilities,
@@ -201,13 +202,13 @@ public final class GuideTableDiscreteSampler
      * @param probabilities The probabilities.
      * @param alpha The alpha factor used to set the guide table size.
      * @throws IllegalArgumentException if {@code probabilities} is null or 
empty, or
-     * {@code alpha} is not strictly positive.
+     * {@code alpha} is not strictly positive and finite.
      */
     private static void validateParameters(double[] probabilities, double 
alpha) {
         if (probabilities == null || probabilities.length == 0) {
             throw new IllegalArgumentException("Probabilities must not be 
empty.");
         }
-        InternalUtils.requireStrictlyPositive(alpha, "alpha");
+        InternalUtils.requireStrictlyPositiveFinite(alpha, "alpha");
     }
 
     /**
diff --git 
a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/GuideTableDiscreteSamplerTest.java
 
b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/GuideTableDiscreteSamplerTest.java
index 19454cbf..b3530d67 100644
--- 
a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/GuideTableDiscreteSamplerTest.java
+++ 
b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/GuideTableDiscreteSamplerTest.java
@@ -65,14 +65,10 @@ class GuideTableDiscreteSamplerTest {
         assertConstructorThrows(new double[4], 1.0);
     }
 
-    @Test
-    void testConstructorThrowsWithZeroAlpha() {
-        assertConstructorThrows(new double[] {0.5, 0.5}, 0.0);
-    }
-
-    @Test
-    void testConstructorThrowsWithNegativeAlpha() {
-        assertConstructorThrows(new double[] {0.5, 0.5}, -1.0);
+    @ParameterizedTest
+    @ValueSource(doubles = {0.0, -1.0, Double.POSITIVE_INFINITY, Double.NaN})
+    void testConstructorThrowsWithBadAlpha(double alpha) {
+        assertConstructorThrows(new double[] {0.5, 0.5}, alpha);
     }
 
     /**
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index c7a76b93..6f018ede 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -56,6 +56,9 @@ If the output is not quite correct, check for invisible 
trailing spaces!
     <release version="1.8" date="TBD" description="
 New features, updates and bug fixes (requires Java 8).
 ">
+      <action dev="aherbert" type="update" due-to="Alex Herbert">
+        "GuideTableDiscreteSampler": Validate alpha is finite.
+      </action>
       <action dev="aherbert" type="fix" due-to="Alex Herbert" issue="RNG-201">
         "PoissonSamplerCache": Limit the maximum mean to the same support
         as the LargeMeanPoissonSampler. Means above the limit, or NaN, will 
throw

Reply via email to