Skip to content

test: migrate stats/pcorrtest to ULP-based assertions - #16193

Draft
kgryte wants to merge 1 commit into
developfrom
kgryte/ulp-stats-pcorrtest
Draft

kgryte wants to merge 1 commit into
developfrom
kgryte/ulp-stats-pcorrtest

Conversation

@kgryte

@kgryte kgryte commented Oct 16, 2026

Copy link
Copy Markdown
Member

Resolves a part of #11352.

Description

What is the purpose of this pull request?

This pull request:

  • migrates stats/pcorrtest tests from computed relative tolerance comparisons to ULP-based assertions using @stdlib/assert/is-almost-same-value.
  • removes the now unused @stdlib/math/base/special/abs and @stdlib/constants/float64/eps requires, along with the delta and tol locals.

Only test/test.js is modified; the package has no native test file, and test/test.validate.js contains no tolerance-based assertions.

ULP bounds

Each assertion site uses the measured minimum ULP difference (computed via @stdlib/number/float64/base/ulp-difference against the existing R fixtures, then confirmed to fail at N-1):

Test (alternative) Assertion Previous tolerance ULP bound
default (two-sided) pValue 1e-6 * abs( expected ) 167809046
default (two-sided) statistic 10.0 * EPS * abs( expected ) 0
default (two-sided) ci[ i ] 20.0 * EPS * abs( expected[ i ] ) 1
less pValue 100 * EPS * abs( expected ) 0
less statistic 10.0 * EPS * abs( expected ) 0
less ci[ i ] 10.0 * EPS * abs( expected[ i ] ) 3
greater pValue 100 * EPS * abs( expected ) 0
greater statistic 10.0 * EPS * abs( expected ) 2
greater ci[ i ] 10.0 * EPS * abs( expected[ i ] ) 3

The confidence interval assertions remain inside their existing for loops, so each loop's bound is the maximum of its two elements (less: ci[0] needs 0, ci[1] needs 3; greater: ci[0] needs 3, ci[1] needs 0).

The large bound for the two-sided pValue reflects the pre-existing looseness of that one assertion: the fixture value 1.8577967705803216e-9 and the computed value 1.857796805282419e-9 agree to only ~1.9e-8 relative error (the prior tolerance was 1e-6 relative, i.e. roughly 4.5e9 ULP), so the migration tightens that assertion by ~27x while remaining honest about the JS/R disagreement at that magnitude.

Verification:

  • make test TESTS_FILTER=".*/stats/pcorrtest/.*" → 133 assertions passing, 0 failing. Run twice at the final bounds with identical results (no FMA/arch-dependent flakiness).
  • make lint-javascript-tests TESTS_FILTER=".*/stats/pcorrtest/.*" → 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?

  • Should the confidence interval assertions be unrolled to ci[0]/ci[1] so that each element can carry its own tighter bound (as in stats/ttest2 and stats/vartest, whose fixtures expose separate lower/upper fields)? The loop was kept here to minimize the diff.

Other

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

No.

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 authored by Claude Code running as an unattended scheduled task. The ULP bounds were measured empirically against the existing fixtures and each was confirmed to be the minimum passing integer.


@stdlib-js/reviewers


Generated by Claude Code

Replace computed relative tolerance comparisons with
`@stdlib/assert/is-almost-same-value` checks using the minimum required
ULP bounds, as measured over the existing R fixtures.

Ref: #11352

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ViMiodafCBgA7gPyrVsJ4p
@stdlib-bot stdlib-bot added Good First PR A pull request resolving a Good First Issue. Statistics Issue or pull request related to statistical functionality. and removed Good First PR A pull request resolving a Good First Issue. labels Oct 16, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/pcorrtest $\\color{green}519/519$
$\\color{green}+100.00\\%$
$\\color{green}83/83$
$\\color{green}+100.00\\%$
$\\color{green}4/4$
$\\color{green}+100.00\\%$
$\\color{green}519/519$
$\\color{green}+100.00\\%$

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Statistics Issue or pull request related to statistical functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants