Skip to content

test: migrate stats/base/dists/invgamma/mode to ULP-based assertions - #15502

Merged
kgryte merged 2 commits into
developfrom
kgryte/ulp-stats-base-dists-invgamma-mode
Sep 25, 2026
Merged

kgryte merged 2 commits into
developfrom
kgryte/ulp-stats-base-dists-invgamma-mode

Conversation

@kgryte

@kgryte kgryte commented Sep 24, 2026

Copy link
Copy Markdown
Member

Resolves a part of #11352.

Description

What is the purpose of this pull request?

This pull request:

Both test/test.js and test/test.native.js previously compared against a computed relative tolerance:

delta = abs( y - expected[ i ] );
tol = 2.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. ...' );

and now assert:

t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' );

ULP constant: 0 in both test/test.js and test/test.native.js.

This is the measured minimum over the full 200-value Julia fixture set. Measuring the ULP distance between each computed value and its reference value directly:

implementation fixtures exact (SameValue) matches max ULP difference
JavaScript (lib/main.js) 200 200 0
C (src/main.c, via lib/native.js) 200 200 0

0 is the tightest representable bound, so no further tightening is possible.

Exact agreement is expected here rather than fortuitous: both implementations evaluate the mode as a single IEEE-754 division,

beta / ( alpha + 1.0 )

so each result is correctly rounded and there is no accumulation, no transcendental evaluation, and no opportunity for FMA contraction to change the result. Note that at maxULP === 0 isAlmostSameValue falls back to the SameValue algorithm, which is strictly stronger than the previous y === expected[ i ] fast path (it distinguishes -0 from +0).

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

Verification performed:

  • test/test.js → 214 passing, 0 failing.
  • test/test.native.js → 214 passing, 0 failing. The native add-on was built locally (node-gyp configure build in the package directory) so that test/test.native.js actually executes rather than being skipped; the assertion count confirms the tests were not skipped.
  • Both files were run twice at the final ULP value, with identical results both times, to confirm there is no FMA/architecture-dependent flakiness.
  • ESLint is clean against etc/eslint/.eslintrc.tests.js for both files.
  • Only the two test files are modified.

One environment note for reviewers: make install-node-modules currently fails in a clean container with ETARGET: No matching version found for es-object-atoms@^1.1.2 (requested by array-includes@3.2.0, pulled in transitively via eslint-plugin-import). The published versions of es-object-atoms top out at 1.1.1. This is unrelated to the changes in this PR, but it meant the test and lint runs above were performed against a locally assembled dependency set rather than via make test / make lint.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

This PR was authored by Claude Code running as an unattended scheduled task. It studied the already-merged conversions in this family (e.g. stats/base/dists/invgamma/entropy, stats/base/dists/weibull/skewness, stats/base/dists/geometric/mean) to match the established idiom, then determined the ULP bound empirically by measuring the maximum ULP difference over the fixture set for both the JavaScript and C implementations and re-running the suite to confirm minimality and determinism.


@stdlib-js/reviewers

🤖 Generated with Claude Code

https://claude.ai/code/session_01LRbc6joCcUqZmp2X4Va3wh


Generated by Claude Code

Replace the computed relative-tolerance comparisons in `test/test.js` and
`test/test.native.js` with ULP difference assertions using
`@stdlib/assert/is-almost-same-value`.

The measured maximum ULP difference over the full Julia fixture set is `0`
for both the JavaScript and C implementations, so the tests now assert bitwise
equality with the reference values.

Ref: #11352

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LRbc6joCcUqZmp2X4Va3wh
@stdlib-bot stdlib-bot added the Good First PR A pull request resolving a Good First Issue. label Sep 24, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Hello! 👋

We've noticed that you've been opening a number of PRs addressing good first issues. Thank you for your interest and enthusiasm!

Now that you've made a few contributions, we suggest no longer working on good first issues. Instead, we encourage you to prioritize cleaning up any PRs which have yet to be merged and then proceed to work on more involved tasks.

Not only does this ensure that other new contributors can work on things and get ramped up on all things stdlib, it also ensures that you can spend your time on more challenging problems. 🚀

For ideas for future PRs, feel free to search the codebase for TODOs and FIXMEs and be sure to check out other open issues on the issue tracker. Cheers!

@stdlib-bot stdlib-bot added the Statistics Issue or pull request related to statistical functionality. label Sep 24, 2026
@stdlib-bot

stdlib-bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/invgamma/mode $\\color{green}195/195$
$\\color{green}+0.00\\%$
$\\color{green}10/10$
$\\color{green}+0.00\\%$
$\\color{green}2/2$
$\\color{green}+0.00\\%$
$\\color{green}195/195$
$\\color{green}+0.00\\%$

The above coverage report was generated for the changes in this PR.

@kgryte kgryte added the Tests Pull requests specifically adding tests. label Sep 24, 2026
@kgryte
kgryte marked this pull request as ready for review September 24, 2026 23:57
@kgryte
kgryte requested a review from a team September 24, 2026 23:57
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Sep 24, 2026
@kgryte
kgryte merged commit a81f193 into develop Sep 25, 2026
29 checks passed
@kgryte
kgryte deleted the kgryte/ulp-stats-base-dists-invgamma-mode branch September 25, 2026 00:12
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Good First PR A pull request resolving a Good First Issue. Statistics Issue or pull request related to statistical functionality. Tests Pull requests specifically adding tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants