Repository navigation
Conversation
Replace the relative tolerance comparison in the native test suite with an ULP difference assertion via `@stdlib/assert/is-almost-same-value`. The previous tolerance (`100.0 * EPS * abs( expected )`) permitted between 100 and 200 ULP, depending on where the expected value fell within its binade. The assertion now uses a fixed bound of 100 ULP, which is no looser than the previous tolerance at any magnitude. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019w9g3A83wPWaSyDCVzKnEb
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
This branch has not been deployed
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/gamma/logcdffrom relative tolerance testing to ULP difference testing.The package had exactly one relative tolerance comparison, in
test/test.native.js:which is replaced by
isAlmostSameValuereturnstruefor exactly equal values, so they === expectedbranch collapses into the single assertion. The now-unusedabsimport and thedeltaandtollocals are removed;EPSis retained, as it remains in use for generating the random input values.The existing
NOTEexplaining the elevated tolerance (differences in accumulated error between the JavaScript and C implementations, as the package wrapscdf, which relies ongammainc, where compiler optimizations can result in different error propagation) is retained, as the rationale still applies to the ULP bound.ULP bound
The final ULP constant is 100, and this is the one point I would like a reviewer's opinion on.
The measured minimum on this machine is 0. The native addon was built locally and the comparison instrumented with
number/float64/base/ulp-difference: across 30 runs of the test (30,000 random input triples), the native C result andln( cdf( x, alpha, beta ) )agreed bit-for-bit in every single case. The test also passes with the bound set to0.I did not tighten the bound to
0, because doing so would rest entirely on a single platform/compiler. The tolerance branch is effectively dead code on this build, so there is no local measurement that can characterize the JS-vs-C divergence theNOTEdescribes, and a bound of0would be expected to fail on any platform where that divergence is non-zero.100was chosen instead as the strictest faithful translation of the previous tolerance. For|expected|in the binade[2^e, 2^(e+1)), one ULP isEPS * 2^e, so100.0 * EPS * abs( expected )admitted between 100 and 200 ULP depending on position within the binade. A fixed bound of 100 ULP is therefore never looser than the previous tolerance at any magnitude, while preserving the documented cross-compiler allowance. This is also in line with the bounds used by already-migrated native tests in this family (gamma/cdfuses 131/32/149,normal/logcdfuses 584,gamma/logpdfuses 1024/384/448).If you would prefer the measured minimum of
0, or a different value, I am happy to change it.Verification
test.js(3),test.factory.js(1030),test.logcdf.js(1026),test.native.js(1026).test.native.jswas run twice at the final bound of 100 to confirm determinism; both runs pass 1026/1026.make lint-javascript-fileson the changed file reports no new errors. The 8 remainingno-restricted-syntax(FunctionExpression) errors are pre-existing and reproduce identically on the unmodified file fromdevelop.test/test.native.js.Related Issues
This pull request has the following related issues:
math/base/specialpackages from relative tolerance testing to ULP difference testing (tracking issue) #11352Reference Packages
This pull request followed these packages:
stats/base/dists/normal/logcdfstats/base/dists/gamma/cdfstats/base/dists/gamma/logpdft.strictEqual( isAlmostSameValue( y, expected, N ), true, 'returns expected value' ), the'returns expected value'message, the placement of the@stdlib/assert/is-almost-same-valuerequire directly aftertape, and the practice of retaining a generous ULP bound for native JS-vs-C comparisons.uniform, so there is no fixed fixture set over which to minimize. The bound had to be reasoned about from the previous tolerance's binade-relative width rather than read off a single measured maximum, as described above.Questions
Yes — one, on the ULP bound. The measured minimum here is
0, but the previous tolerance and the in-codeNOTEboth exist to absorb JS-vs-C divergence that does not reproduce on this platform. I kept100on the grounds that it is strictly no looser than what the test previously accepted. Please let me know if you would rather have the measured0.Other
test/test.native.jsis skipped unless the native addon is present. The addon was built locally withnode-gyp rebuildin order to actually exercise the converted assertion; without it, the migrated code path is never run.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was written primarily by Claude Code, running as an unattended scheduled task. It selected the package, studied the already-migrated packages in the same family to match conventions, performed the migration, instrumented the comparison to measure actual ULP differences, and determined the final bound.
@stdlib-js/reviewers
Generated by Claude Code