Skip to content

test: migrate stats/strided/sstdevyc to ULP-based assertions - #15858

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

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

Conversation

@kgryte

@kgryte kgryte commented Oct 3, 2026

Copy link
Copy Markdown
Member

Resolves a part of #11352.

Description

What is the purpose of this pull request?

This pull request:

Concretely, in each of test/test.sstdevyc.js, test/test.sstdevyc.native.js, test/test.ndarray.js, and test/test.ndarray.native.js, the following

delta = abs( v - expected );
tol = 1.0 * EPS * abs( expected );
t.strictEqual( delta <= tol, true, 'within tolerance. Actual: '+v+'. E: '+expected+'. tol: '+tol+'. Δ: '+delta+'.' );

is replaced by

t.strictEqual( isAlmostSameValuef( v, expected, N ), true, 'returns expected value' );

along with adding the @stdlib/number/float32/base/assert/is-almost-same-value require and dropping the now-unused @stdlib/math/base/special/abs and @stdlib/constants/float32/eps requires and the delta/tol declarations.

As this package operates on single-precision floating-point numbers, the tests use the single-precision assertion utility (isAlmostSameValuef), matching the convention already established by the sibling packages stats/strided/sstdev, stats/strided/sstdevpn, and stats/strided/sstdevwd, whose test files are otherwise nearly identical to this package's.

ULP bounds

Each of the four files contains two tolerance-based assertions. The measured minimum differs between them, so each assertion carries its own bound rather than a single uniform value:

Assertion ULP constant Measured minimum
the function calculates the population standard deviation of a strided array 1 1
the function calculates the sample standard deviation of a strided array 0 0

The bounds are identical across all four files.

The bounds were tightened empirically rather than guessed. Starting from a high value (64) and lowering it, the population assertion fails at 0 and passes at 1, while the sample assertion is bit-exact and so passes at 0:

x = Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] )

population:  returned 2.986078977584839
             expected 2.9860787391662598   // float64ToFloat32( sqrt( 53.5/6 ) )
             ulp difference: 1

sample:      returned 3.271085500717163
             expected 3.271085500717163    // float64ToFloat32( sqrt( 53.5/5 ) )
             ulp difference: 0

So 1 is the tightest possible non-exact bound for the population case, and the sample case requires no tolerance at all.

The native add-on was compiled locally, so the bounds in the *.native.js files are measured rather than mirrored: the JavaScript and C implementations return the same value for both cases, and the ULP distances above hold for each. The full test suite was run twice at the final values to confirm the result is stable (no FMA/arch-dependent variation); both runs report the same 77 passing assertions and 0 failures.

Note that the prior state of this package applied a uniform 1.0 * EPS relative tolerance to both assertions, which is why the sample case was not previously distinguishable as exact. If reviewers would prefer a uniform 1 in both positions for consistency with the sibling sstdev/sstdevpn/sstdevwd packages — trading the tighter bound for robustness against a future bit-level change in svarianceyc — that is a one-character change and I am happy to make it.

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?

Only the one noted above: whether the exact (0 ULP) bound on the sample standard deviation assertion is preferred over a uniform 1, given that the issue asks for the minimum required ULP value.

Other

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

Only the four test files are modified; no source, documentation, benchmark, or fixture files are touched. test/test.js contains no tolerance-based assertions and is left unchanged.

Verification performed:

  • make test TESTS_FILTER=".*/stats/strided/sstdevyc/.*" — 77 passing, 0 failing, with the native add-on built so that test.sstdevyc.native.js and test.ndarray.native.js actually execute rather than skip. Run twice, with identical results.
  • Minimality confirmed by re-running the suite with the population bound lowered to 0, which fails as expected.
  • make lint-javascript-tests TESTS_FILTER=".*/stats/strided/sstdevyc/.*" — clean, 0 problems across all files.
  • EditorConfig compliance (LF endings, UTF-8, no trailing whitespace, final newline, tab indentation) verified directly against .editorconfig, as the editorconfig-checker binary could not be downloaded in the sandbox used to author this change.

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 task. It studied the migration idiom from previously merged conversions in the same family, applied the mechanical substitution to the four test files, and determined the ULP bounds by measuring the actual ULP distance for both the JavaScript and C implementations and confirming that a lower bound fails while the chosen bound passes, then re-running the suite to confirm the result is deterministic.


@stdlib-js/reviewers

🤖 Generated with Claude Code

https://claude.ai/code/session_01Ecr737FjApcfYpgXawH2cM


Generated by Claude Code

@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 3, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/strided/sstdevyc $\\color{green}358/358$
$\\color{green}+100.00\\%$
$\\color{green}13/13$
$\\color{green}+100.00\\%$
$\\color{green}4/4$
$\\color{green}+100.00\\%$
$\\color{green}358/358$
$\\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

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.

2 participants