Skip to content

test: migrate stats/incr/nanmhmean to ULP-based assertions - #15125

Merged
kgryte merged 1 commit into
developfrom
kgryte/ulp-nanmhmean
Sep 10, 2026
Merged

test: migrate stats/incr/nanmhmean to ULP-based assertions#15125
kgryte merged 1 commit into
developfrom
kgryte/ulp-nanmhmean

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/incr/nanmhmean from computed relative-tolerance comparisons (delta = abs( expected - actual ) / tol = EPSILON * abs( expected ), asserted via t.equal( delta <= tol, ... )) to ULP-difference assertions using @stdlib/assert/is-almost-same-value.
  • applies the migration to the two tolerance-based assertion sites in test/test.js. The package has no test/test.native.js, and the remaining assertions in the file are exact comparisons against null, NaN, and exactly representable values, which are correct as-is and are left unchanged.
  • removes the now-unused @stdlib/math/base/special/abs and @stdlib/constants/float64/eps requires, along with the delta and tol variable declarations.
  • collapses the if ( actual[ i ] === expected[ i ] ) { ... } else { ... } branch in the moving-harmonic-mean test into a single ULP assertion, matching the migrated idiom.

Only a test file is changed; no implementation, fixture, or documentation changes are included.

ULP bounds

Assertion Previous tolerance ULP bound
moving harmonic mean computed incrementally (8 values) EPSILON * abs( expected ) 1
current harmonic mean when not provided an input value 1.1 * EPSILON * abs( expected ) 2

These are the minimum integer bounds N such that isAlmostSameValue( actual, expected, N ) holds at each site. They were measured independently of the test harness by computing ulpDifference( actual, expected ) directly at every assertion site, starting from a high bound (64, which passes) and tightening:

  • Moving harmonic mean: the per-element ULP differences are 0, 1, 1, 0, 1, 1, 1, 1, so 1 is the tightest bound covering the loop. N = 0 fails on six of the eight elements (e.g., 2.4000000000000004 vs. 2.4, and 2.769230769230769 vs. 2.7692307692307696).
  • Current harmonic mean: the accumulator returns 3.750000000000001 against a hand-computed expected value of 3.75, a difference of exactly 2 ULP, so N = 2 is required and N = 1 fails.

Tightening either site by one ULP was verified to fail (7 of 31 assertions fail at N - 1), confirming both bounds are minimal rather than merely sufficient.

make test TESTS_FILTER=".*/stats/incr/nanmhmean/.*" was run twice at the final bounds with identical results: 31/31 passing on both runs, no failures, ruling out FMA/architecture-dependent flakiness on this platform. make eslint-tests TESTS_FILTER=".*/stats/incr/nanmhmean/.*" 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?

The second site requires 2 ULP rather than 1. This reflects the pre-existing test, which already used a loosened 1.1 * EPSILON tolerance at that site (as opposed to the plain EPSILON used in the loop), so the looser bound is carried over rather than introduced here. The expected value is hand-computed from the textbook formula, so the extra ULP is accumulation error in the incremental algorithm relative to the closed-form value, not a regression. Flagging it in case a reviewer would prefer the expected value be adjusted instead; no change was made, since that would go beyond migrating the assertions.

Other

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

The resulting diff mirrors the already-merged migration for the sibling package stats/incr/nanmstdev (#15072), which has the same accumulator test structure.

One environment note, which did not affect verification: make install-node-modules initially failed with ETARGET for es-object-atoms@^1.1.2. As previously observed in #15116, this is a stale local npm packument cache rather than a repository or registry problem; npm cache clean --force followed by make install-node-modules and make init succeeded, and the full toolchain was available for this PR. Separately, the lint-editorconfig-files pre-commit step could not download the editorconfig-checker binary in this sandbox and was skipped via SKIP_LINT_EDITORCONFIG; the changed lines were checked manually for LF line endings, tab indentation, no trailing whitespace, and a final newline. All other pre-commit lint steps ran normally.

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 migrated packages in the same family to match the established idiom, performed the migration, and determined the minimum passing ULP bound empirically at each assertion site.


@stdlib-js/reviewers

🤖 Generated with Claude Code

https://claude.ai/code/session_012QwrWGg9D1Fp13W6tJv1gF


Generated by Claude Code

Ref: #11352

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

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

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/incr/nanmhmean $\\color{green}148/148$
$\\color{green}+100.00\\%$
$\\color{green}6/6$
$\\color{green}+100.00\\%$
$\\color{green}2/2$
$\\color{green}+100.00\\%$
$\\color{green}148/148$
$\\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 10, 2026
@kgryte
kgryte marked this pull request as ready for review September 10, 2026 04:53
@kgryte
kgryte requested a review from a team September 10, 2026 04:53
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Sep 10, 2026
@kgryte
kgryte merged commit f5c37de into develop Sep 10, 2026
82 checks passed
@kgryte
kgryte deleted the kgryte/ulp-nanmhmean branch September 10, 2026 04:54
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Sep 10, 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