Repository navigation
test: migrate stats/base/dists/gamma/mgf to ULP-based assertions - #15950
Merged
Merged
Conversation
Replace computed relative tolerance comparisons with ULP-based assertions using `@stdlib/assert/is-almost-same-value`. The ULP bounds were tightened to the measured minimums over the full 1000-case fixture sets: 3259 (`both_large`), 10882 (`large_shape`), and 2062 (`large_rate`). The JavaScript and native implementations require identical bounds. Ref: #11352 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013vj7gTBcnhuXinFm5GiE5g --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: skipped - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
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.
Resolves a part of #11352.
Description
This pull request:
migrates the tests for
stats/base/dists/gamma/mgffrom relative tolerance testing to ULP difference testing, replacing the computeddelta/tolcomparisons with@stdlib/assert/is-almost-same-value.applies the same change to
test/test.mgf.js,test/test.factory.js, andtest/test.native.js.uses the following ULP bounds, one per Julia fixture set, identical across all three test files:
both_large3000.0 * EPS * abs( expected[ i ] )large_shape6500.0 * EPS * abs( expected[ i ] )large_rate1200.0–2200.0 * EPS * abs( expected[ i ] )Each bound is the measured minimum over the full 1000-case fixture set: decrementing all three by one produces exactly three failures (one per fixture set), confirming that every bound is attained and none can be tightened further.
The bounds are large because the MGF is evaluated as
pow( 1 - t/beta, -alpha ), and the fixture sets deliberately probe large shape and rate parameters where1 - t/betaapproaches zero. Raising a near-zero base to a large negative power amplifies the rounding error in the base by a factor of roughlyalpha / (1 - t/beta), so results spanning 50+ orders of magnitude (up to ~1e56) carry a correspondingly large relative error. The worstlarge_shapecase isx = 6.606761672303701,alpha = 19.435205706716904,beta = 6.617230456158223, where the result is ~2.71e54. The previous relative tolerances admitted the same cases: a tolerance ofN * EPS * abs( expected[ i ] )permits betweenNand2NULPs depending on where the result falls within its binade, so the old6500.0 * EPSbound allowed up to ~13000 ULPs.Measurements were taken with the native add-on built locally, so the native implementation was exercised rather than skipped. The JavaScript and native implementations are structurally identical (
pow( 1 - t/beta, -alpha )) and agree bit-for-bit on every fixture case, so both require exactly the same minimum bounds.Only the three test files are changed.
Related Issues
This pull request has the following related issues:
math/base/specialpackages from relative tolerance testing to ULP difference testing (tracking issue) #11352Questions
No.
Other
The package test suite was run twice at the final ULP bounds to confirm determinism (no FMA or architecture-dependent variation): 3020 assertions in
test/test.factory.js, 3017 intest/test.mgf.js, 3017 intest/test.native.js, and 3 intest/test.js, all passing on both runs.make eslint-tests TESTS_FILTER=".*/stats/base/dists/gamma/mgf/.*"is clean for all four files.The migration idiom mirrors previously converted packages in the same family, in particular
stats/base/dists/gamma/quantile, which shares the samemain/factory/nativetest layout and the sameboth_large/large_shape/large_ratefixture sets: theif ( y === expected[i] )equality branch is collapsed into a single assertion (an exact match is already a zero-ULP difference), the assertion message is normalized to'returns expected value', and theabs/EPSrequires are replaced by a singleisAlmostSameValuerequire.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was authored by Claude Code, which mirrored the migration idiom from previously converted packages in the same family (e.g.
stats/base/dists/gamma/quantile,stats/base/dists/gamma/cdf) and determined the minimum passing ULP bounds empirically.@stdlib-js/reviewers
🤖 Generated with Claude Code
https://claude.ai/code/session_013vj7gTBcnhuXinFm5GiE5g
Generated by Claude Code