Repository navigation
test: migrate stats/base/dists/lognormal/entropy to ULP-based assertions - #14635
Merged
Merged
Conversation
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:
stats/base/dists/lognormal/entropyfrom relative tolerance testing to ULP difference testing, per [RFC]: Migratemath/base/specialpackages from relative tolerance testing to ULP difference testing (tracking issue) #11352.delta/tolcomparisons intest/test.jsandtest/test.native.jswitht.strictEqual( isAlmostSameValue( y, expected[ i ], 21 ), true, 'returns expected value' );, adding the@stdlib/assert/is-almost-same-valuerequire and dropping the now unused@stdlib/math/base/special/absand@stdlib/constants/float64/epsrequires.ULP bound:
21(bothtest/test.jsandtest/test.native.js), the measured minimum over the fixture set.The bound was determined empirically rather than assumed. Starting from a high bound and bisecting downward over
isAlmostSameValueacross the full Julia fixture set (100 values), the minimum admissible bound is exactly21. The distribution of ULP differences over the fixtures is:0ULP (bit-identical to the Julia reference): 29 values1ULP: 32 values2ULP: 16 values3ULP: 6 values4ULP: 5 values5–7ULP: 5 values11–13ULP: 5 values19ULP: 1 value21ULP: 1 valueThe largest ULP difference is therefore
21, attained atmu = -2.2043783383184983,sigma = 2.3638997544259355(returned0.0748728884657351vs. expected0.07487288846573481). Lowering the bound to20was confirmed to fail (1 failing assertion per suite), so the bound cannot be tightened further. The suite was then run twice at the final bound with identical results (110/110 fortest/test.jsand 111/111 fortest/test.native.jsin each run), so the bound is not sensitive to run-to-run variation.The previous relative tolerance was
18.0 * EPS * abs( expected[ i ] ). SinceEPS * abs( x )equalsmULP forabs( x ) = m * 2**ewithmin[1, 2), that tolerance corresponds to between18and36ULP depending on where the expected value falls within its binade; at the worst-case fixture (m ≈ 1.198) it corresponds to roughly21.6ULP. The new bound of21therefore sits just inside the prior accuracy budget rather than loosening it.To confirm that
21is also correct for the C implementation, the native addon was compiled locally andtest/test.native.jswas executed against the real addon rather than being skipped: it likewise passes all 111 assertions at21ULP, twice, and bisecting the native results independently also yields21as the minimum, with the worst case at the same fixture index. In fact, the JavaScript and C implementations agree bit-for-bit across all 100 fixtures, which is expected given that both evaluateln( sigma * exp( mu + 0.5 ) * sqrt( 2*pi ) )using the same stdlib kernels. This matches the sibling conversions in this family (halfnormal/entropy,beta/entropy,weibull/entropy), which likewise use a single bound across both suites.Only the two test files are modified; no implementation, fixture, or documentation changes are included.
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
Notes on local verification:
make install-node-modulesinitially failed in this environment because the local npm cache held a stale packument fores-object-atoms, causinges-object-atoms@^1.1.2to resolve as nonexistent. Clearing the npm cache resolved it; no repository files were involved.make lint-editorconfig-files(run via the pre-commit hook) could not execute because theeditorconfig-checkerbinary download is blocked in this environment. The changed files were instead checked manually for indentation (tabs), trailing whitespace, line endings (LF), and final newline, and match the surrounding files exactly.make eslint-tests TESTS_FILTER=".*/stats/base/dists/lognormal/entropy/.*"reports no problems for either file.make test TESTS_FILTER=".*/stats/base/dists/lognormal/entropy/.*"passes.git statusconfirms that the only changed files are the two test files.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was authored by Claude Code running as an unattended scheduled task. It studied previously merged conversions under #11352 (including the
halfnormal/entropysibling) to match the established idiom, applied the migration, measured the minimum ULP bound empirically against the fixtures for both the JavaScript and the locally compiled C implementation, and verified that the tests pass and that the files lint cleanly.@stdlib-js/reviewers
Generated by Claude Code