Skip to content

reject bases below 2 in HaltonSequenceGenerator - #355

Open
insaf021 wants to merge 1 commit into
apache:masterfrom
insaf021:halton-reject-small-bases
Open

insaf021 wants to merge 1 commit into
apache:masterfrom
insaf021:halton-reject-small-bases

Conversation

@insaf021

Copy link
Copy Markdown
Contributor

On master, with custom bases:

new HaltonSequenceGenerator(1, new int[] {1}, null).skipTo(1)    // never returns
new HaltonSequenceGenerator(1, new int[] {0}, null).skipTo(1)    // ArithmeticException: / by zero
new HaltonSequenceGenerator(1, new int[] {-2}, null).skipTo(1)   // [-0.5]
new HaltonSequenceGenerator(3, new int[] {2, 3}, null)           // "3 out of [1, 40] range"

The constructor clones bases without looking at the values, and get() decomposes the index with while (index > 0) { ...; index /= base[i]; }. A base of 1 never reduces the index, so every point after the first spins forever. A base of 0 divides by zero on the second point instead of failing at construction, and a negative base gives coordinates outside the documented [0, 1] interval. No base below 2 is meaningful for a Halton sequence, so the constructor now rejects it with NumberIsTooSmallException, after the existing argument checks.

The dimension check in the same constructor reported PRIMES.length as the upper bound, although the javadoc documents [1, len] with len the length of bases. It now reports bases.length.

HaltonSequenceGeneratorTest gains testConstructorInvalidBase and an upper-bound assertion in testConstructor2; both fail on master and pass with the patch. mvn clean install apache-rat:check checkstyle:check spotbugs:check javadoc:javadoc -pl commons-math-legacy -am is green on JDK 21 (3265 tests in legacy; the only reruns are the randomised SimplexOptimizerTest cases).

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.21%. Comparing base (f554608) to head (49e2796).
⚠️ Report is 420 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #355      +/-   ##
============================================
+ Coverage     86.54%   87.21%   +0.66%     
+ Complexity     9787       91    -9696     
============================================
  Files           532      499      -33     
  Lines         35516    33545    -1971     
  Branches       6194     5858     -336     
============================================
- Hits          30738    29256    -1482     
+ Misses         3518     3165     -353     
+ Partials       1260     1124     -136     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants