Skip to content

test: migrate stats/base/dists/hypergeometric/cdf to ULP-based assertions - #15693

Merged
kgryte merged 1 commit into
developfrom
claude/great-brahmagupta-b84gyz
Sep 30, 2026
Merged

kgryte merged 1 commit into
developfrom
claude/great-brahmagupta-b84gyz

Conversation

@kgryte

@kgryte kgryte commented Sep 30, 2026

Copy link
Copy Markdown
Member

Resolves a part of #11352.

Description

What is the purpose of this pull request?

This pull request:

Final ULP constant: 4240 in test/test.cdf.js, test/test.factory.js, and test/test.native.js.

The bound was tightened empirically rather than assumed. Starting from a high bound and bisecting per fixture, the maximum ULP difference across all 1000 Julia fixture values was measured as 4240 — identically for lib/main.js, lib/factory.js, and src/main.c, all three of which agree bit-for-bit on the worst case. The worst fixture is x = 7, N = 214, K = 32, n = 13 (y = 0.9999182652897621 vs. expected 0.9999182652892914).

4240 is the measured minimum: at 4239 that fixture fails in both test/test.cdf.js and test/test.factory.js, and at 4240 the full suite passes.

For context, the previous assertions used tol = 2150.0 * EPS * abs( expected[ i ] ), which near 1.0 corresponds to roughly the same magnitude of error, so this migration does not loosen the existing bound — it just expresses it in ULP rather than in scaled EPS, and pins it to the exact measured worst case.

Only the three test files are changed; the implementation, fixtures, and docs are untouched.

Verification performed:

  • make test TESTS_FILTER=".*/stats/base/dists/hypergeometric/cdf/.*" — passing: 3/3 in test/test.js, 1028/1028 in test/test.cdf.js, 1037/1037 in test/test.factory.js, and 1016/1016 in test/test.native.js. The C addon was built locally (make install-node-addons NODE_ADDONS_PATTERN=stats/base/dists/hypergeometric/cdf), so the native tests genuinely ran rather than being skipped. The suite was run twice at the final ULP value with identical results, to rule out FMA/architecture-dependent flakiness.
  • make lint-javascript-tests TESTS_FILTER=".*/stats/base/dists/hypergeometric/cdf/.*" — clean.

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?

4240 ULP is a wide bound in absolute terms, and it is what the package's own Julia fixtures currently require — the fixture error is dominated by the summation in the CDF rather than by anything the test can tighten. If you would prefer the fixtures be regenerated or the implementation revisited so that a tighter bound becomes achievable, that would be a separate change and I am happy to open it instead.

Other

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

The idiom follows the already-converted sibling packages stats/base/dists/chisquare/cdf and stats/base/dists/planck/cdf, which have the same fixture-loop layout, and the sibling stats/base/dists/hypergeometric/kurtosis.

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

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

This PR was written by Claude Code, running unattended as a scheduled task. The ULP bound was measured empirically by bisecting the per-fixture ULP difference against the package's own fixtures, not guessed; the resulting test suites were then executed twice at the final bound to confirm determinism, and once at 4239 to confirm the bound cannot be tightened further.


@stdlib-js/reviewers


Generated by Claude Code

…rtions

Replace the relative tolerance assertions in the fixture loops of
`test/test.cdf.js`, `test/test.factory.js`, and `test/test.native.js`
with `isAlmostSameValue` ULP comparisons. The bound was measured
empirically by bisecting the per-fixture ULP difference over the full
1000-point Julia fixture set; the maximum is 4240 ULP for the JavaScript
and the C implementation alike, so 4240 is the minimum admissible bound.

Ref: #11352

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BFKMkGyXoycqdWUYnci3AS
@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Good First PR A pull request resolving a Good First Issue. labels Sep 30, 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

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/hypergeometric/cdf $\\color{green}446/446$
$\\color{green}+100.00\\%$
$\\color{green}48/48$
$\\color{green}+100.00\\%$
$\\color{green}5/5$
$\\color{green}+100.00\\%$
$\\color{green}446/446$
$\\color{green}+100.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 30, 2026
@kgryte
kgryte marked this pull request as ready for review September 30, 2026 19:18
@kgryte
kgryte requested a review from a team September 30, 2026 19:18
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Sep 30, 2026
@kgryte
kgryte merged commit 7665af9 into develop Sep 30, 2026
82 checks passed
@kgryte
kgryte deleted the claude/great-brahmagupta-b84gyz branch September 30, 2026 19:19
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Sep 30, 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