Skip to content

test: migrate stats/base/dists/chi/skewness to ULP-based assertions - #15828

Merged
kgryte merged 1 commit into
developfrom
claude/great-brahmagupta-wbovpu
Oct 12, 2026
Merged

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

Conversation

@kgryte

@kgryte kgryte commented Oct 2, 2026

Copy link
Copy Markdown
Member

Description

What is the purpose of this pull request?

This pull request:

  • migrates the test suite of stats/base/dists/chi/skewness from computed relative-tolerance comparisons to ULP-based assertions, per [RFC]: Migrate math/base/special packages from relative tolerance testing to ULP difference testing (tracking issue) #11352.
  • replaces the if ( y === expected[i] ) { ... } else { delta = abs( y - expected[i] ); tol = 1e-11 * abs( expected[i] ); t.ok( delta <= tol, ... ); } branches in test/test.js and test/test.native.js with a single t.strictEqual( isAlmostSameValue( y, expected[ i ], 12890 ), true, 'returns expected value' ); assertion.
  • adds the @stdlib/assert/is-almost-same-value require and removes the now-unused @stdlib/math/base/special/abs require, along with the delta/tol declarations.

ULP bound

  • Final ULP constant: 12890 (used in both test/test.js and test/test.native.js).
  • 12890 is the measured minimum. It was determined by bisecting the ULP bound over the complete 50-point test/fixtures/julia/data.json fixture set. The worst-case point is fixture index 16 (k = 18.567573180927845, returned 0.1696036355271358 vs. expected 0.16960363552749358).
  • Minimality was verified empirically for both files: at N = 12890 the JavaScript suite reports 56 passing assertions and 0 failures and the native suite reports 55 passing and 0 failures; at N = 12889 exactly one assertion fails in each file — the worst-case point.
  • The native add-on was built locally (make install-node-addons) so that test/test.native.js actually exercises the C implementation rather than skipping. The C implementation mirrors the JavaScript implementation operation for operation, and bottoms out at the same minimum of 12890.
  • The suite was run twice at the final N = 12890 with identical results, confirming the bound is not sensitive to FMA/arch variation on this platform.
  • For reference, the previous tolerance was 1e-11 * abs( expected[i] ), which corresponds to roughly 4.5e4 ULP, so the new bound is a meaningful tightening of what this suite previously accepted.

Verification

  • make test TESTS_FILTER=".*/stats/base/dists/chi/skewness/.*" → 56 / 56 passing for test/test.js and 55 / 55 passing for test/test.native.js (two consecutive runs).
  • make lint-javascript-tests TESTS_FILTER=".*/stats/base/dists/chi/skewness/.*" → clean, exit 0.
  • Only the two test files are modified; no source, documentation, benchmark, or fixture files are touched.

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?

  • 12890 ULP is large in absolute terms. It is the tightest value that passes the existing fixtures, and it is roughly 3.5x tighter than the 1e-11 relative tolerance it replaces, so it is a strict improvement over the status quo. The magnitude comes from the implementation itself: skewness composes chi/mean and chi/variance and then evaluates ( mu / sigma3 ) * ( 1 - 2*sigma2 ), where the 1 - 2*sigma2 factor cancels catastrophically as k grows. If reviewers would prefer the underlying accuracy be investigated rather than codified, happy to split that out into a separate issue.

Other

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

  • The idiom follows the convention already settled on in this family of packages (e.g. stats/base/dists/weibull/skewness, stats/base/dists/planck/variance, stats/base/dists/chisquare/quantile): an inline numeric ULP literal rather than a named constant, the same bound shared between test.js and test.native.js, and the standardized 'returns expected value' assertion message.
  • The repository's pre-commit EditorConfig hook could not run in this environment, because it downloads the editorconfig-checker binary from a GitHub repository outside this session's allowed scope. EditorConfig conformance was therefore checked manually for both files: LF line endings, UTF-8, tab indentation, no trailing whitespace, and a single final newline.

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 by Claude Code running as an unattended scheduled task. It selected the package, mirrored the conversion idiom from previously merged PRs in the same family, measured the minimum ULP bound by bisection over the fixture set, built the native add-on to confirm the same bound holds for the C implementation, and verified the tests and linting.


@stdlib-js/reviewers


Generated by Claude Code

Replace the computed relative-tolerance comparisons in `test/test.js` and
`test/test.native.js` with `isAlmostSameValue` assertions. The ULP bound of
`12890` is the measured minimum over the full fixture set for both the
JavaScript and C implementations.

Ref: #11352

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016FowxTcTEq1WLD4Vqu5hFD
@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 Oct 2, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/chi/skewness $\\color{green}172/172$
$\\color{green}+100.00\\%$
$\\color{green}8/8$
$\\color{green}+100.00\\%$
$\\color{green}2/2$
$\\color{green}+100.00\\%$
$\\color{green}172/172$
$\\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 Oct 12, 2026
@kgryte
kgryte marked this pull request as ready for review October 12, 2026 13:31
@kgryte
kgryte requested a review from a team October 12, 2026 13:31
@kgryte kgryte added the Needs Follow-up Pull request requiring one or more follow-up actions. label Oct 12, 2026
@kgryte
kgryte merged commit 8f417a2 into develop Oct 12, 2026
82 checks passed
@kgryte
kgryte deleted the claude/great-brahmagupta-wbovpu branch October 12, 2026 13:32
@kgryte

kgryte commented Oct 12, 2026

Copy link
Copy Markdown
Member Author

We should investigate the accuracy issues mentioned in the OP.

@stdlib-bot stdlib-bot added Needs Review A pull request which needs code review. and removed Needs Review A pull request which needs code review. labels Oct 12, 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. Needs Follow-up Pull request requiring one or more follow-up actions. 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