Skip to content

test: migrate stats/base/dists/chisquare/logpdf to ULP-based assertions - #15121

Draft
kgryte wants to merge 1 commit into
developfrom
kgryte/ulp-chisquare-logpdf
Draft

test: migrate stats/base/dists/chisquare/logpdf to ULP-based assertions#15121
kgryte wants to merge 1 commit into
developfrom
kgryte/ulp-chisquare-logpdf

Conversation

@kgryte

@kgryte kgryte commented Sep 9, 2026

Copy link
Copy Markdown
Member

Resolves a part of #11352.

Description

What is the purpose of this pull request?

This pull request:

  • migrates the tests for stats/base/dists/chisquare/logpdf from computed relative-tolerance comparisons (delta = abs( y - expected[ i ] ) / tol = 10.0 * EPS * abs( expected[ i ] ), asserted via t.ok( delta <= tol, ... )) to ULP-difference assertions using @stdlib/assert/is-almost-same-value.
  • applies the migration to test/test.logpdf.js, test/test.factory.js, and test/test.native.js (one fixture block in each).
  • removes the now-unused @stdlib/math/base/special/abs require from all three test files, along with the delta and tol variable declarations and the redundant y === expected[ i ] exact-match branch.

The @stdlib/constants/float64/eps require is retained in all three files, as EPS remains in use by the "returns -Infinity for all x < 0" test (x = -( randu()*100.0 ) - EPS;).

Only test files are changed; no implementation, fixture, or documentation changes are included.

ULP bounds

Fixture block Fixture Previous tolerance ULP bound
logpdf for x given degrees of freedom k (test.logpdf.js, test.factory.js, test.native.js) julia/decimal_decimal.json 10.0 * EPS * abs( expected[ i ] ) 15

15 is the minimum integer N such that isAlmostSameValue( y, expected[ i ], N ) holds for every entry in the fixture. Starting from a high bound and tightening, the measured maximum ULP difference over the 5000 fixture values is exactly 15, attained at x = 8.727837272289122, k = 17.266858371208855 (y = -3.6381142627612433, expected -3.6381142627612366). This was confirmed independently of the test harness by searching, for each fixture entry, for the smallest N satisfying isAlmostSameValue( y, expected[ i ], N ), and confirmed within the harness by observing that N = 14 fails exactly one assertion while N = 15 passes all of them. Both the main function and the function returned by factory produce identical results, so both share the same bound.

The C implementation was measured the same way over the same fixture and also requires exactly 15 ULP, attaining its maximum at the same fixture entry, so test.native.js uses the same bound as the JavaScript tests.

The native add-on was built locally, so test/test.native.js executes rather than being skipped. The full suite was run twice at the final bound with identical results both times: 15348 assertions passing across test.js (3), test.logpdf.js (5115), test.factory.js (5115), and test.native.js (5115); no failures and no skipped tests. make eslint-tests TESTS_FILTER=".*/stats/base/dists/chisquare/logpdf/.*" is 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?

No.

Other

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

The resulting assertion matches the idiom used by already-migrated sibling packages such as stats/base/dists/triangular/cdf and stats/base/dists/planck/logcdf, which apply the migration across test.<name>.js, test.factory.js, and test.native.js over the same style of Julia fixtures.

Two environment notes:

  • make install-node-modules initially failed because npm could not resolve es-object-atoms@^1.1.2 from a stale local cache; clearing the npm cache and re-running the install resolved it, with no change to any manifest in this repository.
  • The pre-commit editorconfig hook could not run, since it downloads its checker binary from GitHub and network access to that repository is not available in this environment; the three changed files were instead verified manually against .editorconfig (LF endings, UTF-8, tab indentation, no trailing whitespace, final newline present).

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 written primarily by Claude Code, running as an unattended scheduled task. It selected the package, studied previously converted packages in the same family to match the established idiom, performed the conversion, and determined the minimum passing ULP bound empirically over the full fixture set.


@stdlib-js/reviewers

🤖 Generated with Claude Code

https://claude.ai/code/session_016LHxfiAd8FbaZFbDEqvzFG


Generated by Claude Code

@stdlib-bot stdlib-bot added the Good First PR A pull request resolving a Good First Issue. label Sep 9, 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 9, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/chisquare/logpdf $\\color{green}240/240$
$\\color{green}+100.00\\%$
$\\color{green}7/7$
$\\color{green}+100.00\\%$
$\\color{green}3/3$
$\\color{green}+100.00\\%$
$\\color{green}240/240$
$\\color{green}+100.00\\%$

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

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants