Skip to content

test: migrate stats/strided/sstdev to ULP-based assertions - #15665

Merged
kgryte merged 1 commit into
developfrom
kgryte/ulp-stats-strided-sstdev
Sep 30, 2026
Merged

kgryte merged 1 commit into
developfrom
kgryte/ulp-stats-strided-sstdev

Conversation

@kgryte

@kgryte kgryte commented Sep 29, 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.sstdev.js, test/test.sstdev.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, 1 ), 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 package stats/strided/sstdevpn, whose test files are otherwise line-for-line identical to this package's.

ULP bound

File ULP constant Measured minimum
test/test.sstdev.js 1 1
test/test.sstdev.native.js 1 1
test/test.ndarray.js 1 1
test/test.ndarray.native.js 1 1

The bound was tightened empirically rather than guessed. Starting from a high value and lowering it, 1 is the smallest integer for which the assertions pass; at 0 all four files fail, as the returned value is not bit-identical to the expected value:

x:        Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] )
returned: 2.986078977584839
expected: 2.9860787391662598   // float64ToFloat32( sqrt( 53.5/6 ) )

So 1 is the tightest possible non-exact bound here. The native add-on was compiled locally, so the 1 bound in the *.native.js files is measured rather than mirrored: the JavaScript and C implementations return the same value for this case, and both are exactly one ULP from the expected value. This is also consistent with the prior state of this package, which applied an identical 1.0 * EPS tolerance in all four files.

The full test suite was run twice at the final value to confirm the result is stable (no FMA/arch-dependent variation); both runs report the same 77 passing assertions and 0 failures.

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.

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/sstdev/.*" — 77 passing, 0 failing, with the native add-on built so that test.sstdev.native.js and test.ndarray.native.js actually execute rather than skip. Run twice, with identical results.
  • ESLint against etc/eslint/.eslintrc.tests.js (the configuration make lint-javascript-tests applies to test files) — clean, 0 problems across all four files.

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 1 ULP bound by measuring the actual ULP distance for both the JavaScript and C implementations and confirming that 0 fails while 1 passes, then re-running the suite to confirm the result is deterministic.


@stdlib-js/reviewers

🤖 Generated with Claude Code

https://claude.ai/code/session_019QGSqj3XSMadv5etJbf1wZ


Generated by Claude Code

Ref: #11352

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019QGSqj3XSMadv5etJbf1wZ

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: skipped
  - task: lint_markdown_pkg_readmes
    status: na
  - task: lint_markdown_docs
    status: na
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@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 29, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/strided/sstdev $\\color{green}348/348$
$\\color{green}+100.00\\%$
$\\color{green}13/13$
$\\color{green}+100.00\\%$
$\\color{green}4/4$
$\\color{green}+100.00\\%$
$\\color{green}348/348$
$\\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 05:59
@kgryte
kgryte requested a review from a team September 30, 2026 05:59
@kgryte
kgryte merged commit ad77212 into develop Sep 30, 2026
66 checks passed
@kgryte
kgryte deleted the kgryte/ulp-stats-strided-sstdev branch September 30, 2026 06:00
@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 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