test: migrate stats/base/dists/gamma/quantile to ULP-based assertions - #14167
Merged
Conversation
Ref: #11352 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PDwfERAzjEANsUeUns9Jtk
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request:
stats/base/dists/gamma/quantilefrom relative-tolerance (EPS-scaled) test assertions to ULP-based assertions using@stdlib/assert/is-almost-same-value, per [RFC]: Migratemath/base/specialpackages from relative tolerance testing to ULP difference testing (tracking issue) #11352.Changes are confined to
test/test.factory.jsandtest/test.quantile.js. In both files, theabs/EPSrequires are replaced byisAlmostSameValue, thedelta/tollocals are dropped, and the exact-vs-tolerance branch in each fixture loop collapses to a single assertion:test/test.jscontains no tolerance logic and is unchanged. There is notest/test.native.jsfor this package.Final ULP constants and measured minimum
Each file has three fixture loops, one per fixture set. The bounds are per-loop, and the JavaScript and factory code paths measured identically, so both files carry the same three constants:
both_large.json1350.0 * EPS * abs( expected )2525large_shape.json20.0 * EPS * abs( expected )1919large_rate.json200.0 * EPS * abs( expected )9696Every bound is set to its measured minimum. Starting from a high bound (
64) and lowering, the per-fixture ULP distance was measured across the full fixture set (1000 cases per set, 3000 total, evaluated through bothquantileandfactory). The worst cases are:both_large:p = 0.6041052641053029,alpha = 13.178550784263962,beta = 29.560554891882354— computed0.46731926882997005vs. Julia reference0.46731926882997143, a distance of 25 ULP.large_shape:p = 0.40591542057549845,alpha = 15.079668014020719,beta = 0.4604400783822804— computed30.088463625651276vs.30.088463625651343, a distance of 19 ULP.large_rate:p = 0.10603179296890075,alpha = 0.14961229701531797,beta = 17.62916971802366— computed1.0940978379647893e-8vs.1.0940978379647734e-8, a distance of 96 ULP.Lowering any of the three bounds by one (
24,18,95) fails exactly one assertion in the corresponding loop, so each is the tightest integer bound that passes.Both test files were run twice at the final bounds and passed identically each time (
test/test.quantile.js: 3024 assertions;test/test.factory.js: 3028 assertions;test/test.js: 3 assertions), indicating no run-to-run variation.The quantile is computed via
gammaincinv, an iterative inverse of the incomplete gamma function, so bounds in the tens of ULP are expected rather than the sub-ULP bounds seen for closed-form rational moments. Thelarge_rateset is the loosest because its expected values are near1e-8, where the reference and the iterative refinement disagree in the last several bits.Note that the ULP bounds are substantially tighter than the previous relative tolerances implied for
both_large(1350 * EPS) and looser forlarge_rate(200 * EPS), which is the expected consequence of moving from a magnitude-scaled tolerance to a representable-gap measure.Related Issues
This pull request has the following related issues:
math/base/specialpackages from relative tolerance testing to ULP difference testing (tracking issue) #11352Questions
All three bounds are set to their exact measured minima, with no margin. If reviewers would prefer some headroom to absorb possible FMA/toolchain variation on other architectures, the constants can be raised.
Other
Verification performed in this environment:
make install-node-modulesandmake initcompleted successfully, and the tests were run through the installed toolchain. (Thees-object-atoms@^1.1.2resolution failure seen in earlier conversion runs was a stale npm packument cache;npm cache clean --forceplus a fresh fetch resolved it.)etc/eslint/.eslintrc.tests.js) over all three test files — clean. Note thatmake lint-javascript-filesapplies the source config (.eslintrc.js) rather than the test config, and so reportsno-restricted-syntaxerrors for the standardfunction test( t )idiom; this reproduces identically on untouched, already-merged files such asstats/base/dists/pareto-type1/quantile/test/test.quantile.js, and is unrelated to this change.lint-editorconfig-filesfails in this environment on an unrelated GitHub API call (GitHub access to this repository is not enabled for this session).The diff mirrors already-merged conversions such as
stats/base/dists/pareto-type1/quantileandstats/base/dists/signrank/quantile. Opened as a draft so CI can act as the authoritative lint and test check.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was written by Claude Code running as an unattended scheduled task. It studied previously merged ULP conversions to match the established idiom, applied the test changes, and measured the minimum passing ULP bound empirically over the full fixture set for both the
quantileandfactorycode paths.@stdlib-js/reviewers
Generated by Claude Code