Skip to content

test: migrate stats/incr/mapcorr to ULP-based assertions - #16147

Merged
kgryte merged 1 commit into
developfrom
kgryte/ulp-stats-incr-mapcorr
Oct 14, 2026
Merged

kgryte merged 1 commit into
developfrom
kgryte/ulp-stats-incr-mapcorr

Conversation

@kgryte

@kgryte kgryte commented Oct 14, 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/mapcorr from relative tolerance testing to ULP difference testing, replacing the computed delta/tol comparisons with @stdlib/assert/is-almost-same-value, following the idiom established in the already migrated stats/incr/mpcorr (the signed analog of this package) and stats/incr/mpcorr2.
  • switches the simulated datasets from the global PRNG seed (randu.seed) to a fixed seed (123456), which is required in order for a tightened ULP bound to be deterministic. This mirrors stats/incr/mpcorr, stats/incr/mpcorr2, and stats/incr/nanmpcorr2, which all use the same fixed seed.

Files changed (tests only):

  • test/test.js

Tests which already performed exact comparisons (t.strictEqual on null, 0, exactly representable values, and NaN checks via isnan) were left untouched.

Measured ULP bounds

Each bound was tightened to the minimum integer that still passes over the full set of expected values in the corresponding test. The minima were measured programmatically (per-case minimum required ULP difference, maximized over the test's cases), and minimality was verified mechanically: decrementing any bound by one produces test failures.

Test ULP
computes a moving sample absolute Pearson correlation coefficient incrementally 6716
computes a moving sample absolute Pearson correlation coefficient incrementally (known means) 1623
if not provided an input value, returns the current coefficient (unknown means) 1
if not provided an input value, returns the current coefficient (known means) 0
if provided NaN, the accumulated value is NaN for at least W invocations (unknown means) 1

Since mapcorr returns the absolute value of the coefficient computed by mpcorr, the measured bounds for the two fixture-driven tests (6716 and 1623) are identical to the bounds already merged for stats/incr/mpcorr, which is a useful consistency check.

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 change from randu.seed to the fixed seed 123456 is strictly speaking beyond a mechanical tolerance-to-ULP substitution, but without it the datasets differ on every run and no tight ULP bound can be stated or relied upon. The already merged stats/incr/mpcorr, stats/incr/mpcorr2, and stats/incr/nanmpcorr2 made the same change as part of their migrations, so this follows precedent; please flag if a different seed is preferred.

Other

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

  • make test TESTS_FILTER=".*/stats/incr/mapcorr/.*" is green (2422 assertions passing). The suite was run twice at the final ULP values to confirm determinism.
  • make lint-javascript-tests TESTS_FILTER=".*/stats/incr/mapcorr/.*" is clean.
  • The package has no test/test.native.js.

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. The ULP bounds were measured programmatically rather than guessed, and each bound was verified to be minimal by confirming that one less ULP fails.


@stdlib-js/reviewers

🤖 Generated with Claude Code

https://claude.ai/code/session_01ECS7suxhHt53frTb9zwh3T


Generated by Claude Code

Replace the relative tolerance assertions in the test suite with ULP
difference assertions via `@stdlib/assert/is-almost-same-value`. In
order for the fixture-based assertions to be deterministic, the
simulated datasets now use a fixed PRNG seed, as is done in
`stats/incr/mpcorr`.

The measured minimum ULP bounds are `6716` (moving coefficient,
unknown means), `1623` (moving coefficient, known means), `1` and `0`
(accumulated coefficient, unknown and known means, respectively), and
`1` (NaN propagation).

Ref: #11352

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

---
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 the Good First PR A pull request resolving a Good First Issue. label Oct 14, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Hello! 👋

We've noticed that you've been opening a number of PRs addressing good first issues. Thank you for your interest and enthusiasm!

Now that you've made a few contributions, we suggest no longer working on good first issues. Instead, we encourage you to prioritize cleaning up any PRs which have yet to be merged and then proceed to work on more involved tasks.

Not only does this ensure that other new contributors can work on things and get ramped up on all things stdlib, it also ensures that you can spend your time on more challenging problems. 🚀

For ideas for future PRs, feel free to search the codebase for TODOs and FIXMEs and be sure to check out other open issues on the issue tracker. Cheers!

@stdlib-bot stdlib-bot added the Statistics Issue or pull request related to statistical functionality. label Oct 14, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/incr/mapcorr $\\color{green}166/166$
$\\color{green}+100.00\\%$
$\\color{green}17/17$
$\\color{green}+100.00\\%$
$\\color{green}2/2$
$\\color{green}+100.00\\%$
$\\color{green}166/166$
$\\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 14, 2026
@kgryte
kgryte marked this pull request as ready for review October 14, 2026 18:33
@kgryte
kgryte requested a review from a team October 14, 2026 18:33
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Oct 14, 2026
@kgryte
kgryte merged commit 3bd71d2 into develop Oct 14, 2026
82 checks passed
@kgryte
kgryte deleted the kgryte/ulp-stats-incr-mapcorr branch October 14, 2026 18:34
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Oct 14, 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