Skip to content

chore: address review findings in new stats/incr/nan* packages#13602

Open
Planeshifter wants to merge 12 commits into
developfrom
philipp/fix-commit-review-2026-07-21
Open

chore: address review findings in new stats/incr/nan* packages#13602
Planeshifter wants to merge 12 commits into
developfrom
philipp/fix-commit-review-2026-07-21

Conversation

@Planeshifter

@Planeshifter Planeshifter commented Jul 21, 2026

Copy link
Copy Markdown
Member

Description

What is the purpose of this pull request?

Follow-up fixes for commits merged to develop between b772009 (2026-07-20 13:08 -0700) and 729ff85 (2026-07-20 23:22 -0500).

This pull request:

  • stats/incr/nanmpcorrdist: Fixed stats/incr/nanmpcorrdist (regression from 729ff85): lib/main.js gated forwarding of mx/my on arguments.length > 2, so incrnanmpcorrdist( W, mx ) silently dropped mx instead of forwarding to incrmpcorrdist, and the documented TypeError never fired. Changed the condition to arguments.length > 1, matching the base accumulator and stats/incr/nanmpcorr.
  • stats/incr/nanmpcorrdist: Fixed the flaky test tolerances in test/test.js (729ff85) that were failing seed-dependently on develop and on this PR's CI. The tolerance logic otherwise follows the base stats/incr/mpcorrdist tests, with one deviation: the random-sweep test now uses an absolute tolerance of 1.0e6 * EPS instead of 1.0e6 * EPS * |expected| with a 10 * EPS zero-guard. Rationale: d = 1 - r, so floating-point error in d accumulates at the scale of ULPs of unity and is largely independent of |d|; near r ≈ 1 (common when NaN-dense windows keep the effective sample size small), a relative tolerance is arbitrarily strict. Validation: the old assertions failed on ~25% of 2000 simulated seeds; the maximum observed error across 8000 seeds is 2.5e-11 (the new tolerance is ~10x above it); 300 full-suite runs under fresh random seeds pass cleanly. An initial ULP-based rewrite (isAlmostSameValue at unit anchor) was pushed and then reverted in favor of matching the base package's test style.
  • stats/incr/nanmpcorr2: Fix incrnanmpcorr2's two-arg meanx-only call: 026b97a gated forwarding to the base incrmpcorr2 constructor on arguments.length > 2 in lib/main.js, so meanx was silently dropped instead of surfacing the base's TypeError for a missing meany. Changed the condition to arguments.length > 1, matching incrmpcorr2 and the nanmpcorr sibling wrapper.
  • stats/incr/nanewmean: Fixed a copy-paste leftover from the ewmean README: the commented-out equation image src in stats/incr/nanewmean/README.md still pointed at stats/incr/ewmean/docs/img/... instead of its own docs/img, where equation_exponentially_weighted_mean.svg actually lives. Repointed it to stats/incr/nanewmean/docs/img/..., consistent with how nanewstdev self-references (1356c75).
  • stats/incr/nanmmda: Fix path in README (43eb423): the commented-out equation image src pointed at stats/incr/mmda/docs/img/... instead of stats/incr/nanmmda/docs/img/..., same copy-paste slip as nanewmean — now points at the package's own equation_mean_directional_accuracy.svg.
  • stats/incr/nanmme: Fix stats/incr/nanmme: docs/img/equation_mean_error.svg landed empty (0 bytes) in e6abaec. Populated it with the rendered SVG from stats/incr/mme/docs/img/equation_mean_error.svg (8694 bytes), matching how nanmpe/nanmmpe/nanmmda mirror their base packages.
  • stats/incr/nanmmpe: Fixed stats/incr/nanmmpe's .d.ts in 19d792a — it dropped the @stdlib/types triple-slash reference directive after // TypeScript Version: 4.1 that every other nan-wrapper sibling from that commit carries. Restored it in docs/types/index.d.ts to match stats/incr/mmpe and its siblings.
  • stats/incr/nanmmda, stats/incr/nanmmpe: Fixed erroneous Markdown backticks around NaN in the description fields of both packages' package.json (43eb423, 19d792a); package.json descriptions aren't rendered as Markdown, and no other stats/incr package quotes it that way.

Related Issues

Does this pull request have any related issues?

No.

Questions

Any questions for reviewers of this pull request?

Simulation shows the base stats/incr/mpcorrdist test carries the same flaw: under its own tolerances and NaN-free datasets, it fails on 1134/5000 simulated seeds (~23%) — it just runs rarely, as tests only execute when the package changes. The same relative-tolerance pattern (without even a zero-guard) exists in stats/incr/nanmpcorr2/mpcorr2, though the known-means/ paths were empirically stable in 2000-seed simulation. Recommend applying the same absolute-tolerance fix family-wide in a follow-up.

Other

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

Validation performed on all 26 commits merged to develop in the 24-hour window (b772009…729ff85):

  • Style-guide compliance audit of hand-written commits (the 8 new stats/incr/nan* accumulator packages, blas/asum, blas/ext/base/zxdy + ndarray variant, the math/base/special/sind ULP test migration) against docs/style-guides and established reference packages.
  • Bug scan of all per-commit diffs, including verification that the constants/float64/nan C refactor (b953edd) is a semantics-preserving literal-to-constant swap (146↔146 balanced across 99 source files with matching include/manifest updates), that the blas/asum dtype dispatch table is correct, and that the zxdy complex-division loops handle strides/offsets correctly.
  • Both behavioral fixes were smoke-tested: the corrected wrappers now throw the documented TypeError on two-argument calls and delegate correctly on three-argument calls; existing test suites exercise only 0/1/3-argument calls, so no test changes are required for them.
  • The nanmpcorrdist test-tolerance fix was validated empirically: 2000-seed simulation of the old assertions (~25% failing seeds), 8000-seed measurement of maximum error (2.5e-11 vs the 2.2e-10 tolerance), and 300 clean full-suite runs under fresh random seeds.
  • Deliberately excluded: anything requiring subjective interpretation (e.g. wording of an additional NaN-behavior note in stats/incr/nanmmpe's README, which already documents the behavior in its intro and usage sections).

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 as part of a scheduled automated review of commits recently merged to develop, with the test-tolerance fix directed by a maintainer. All findings were cross-validated by multiple independent review passes and verified against the repository before applying fixes.

@stdlib-bot stdlib-bot added the Statistics Issue or pull request related to statistical functionality. label Jul 21, 2026
@Planeshifter Planeshifter changed the title fix: address review findings in new stats/incr/nan* packages chore: address review findings in new stats/incr/nan* packages Jul 21, 2026
@Planeshifter
Planeshifter marked this pull request as ready for review July 21, 2026 13:55
@Planeshifter
Planeshifter requested a review from a team July 21, 2026 13:55
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Jul 21, 2026
Replaces EPS-relative tolerance checks with ULP-based comparisons via
`@stdlib/assert/is-almost-same-value`. As the correlation distance is
computed as `d = 1 - r`, floating-point error in `d` arises at the
scale of ULPs of unity, so values are compared at unit scale
(`1.0 + d`). The previous relative tolerances collapsed toward zero
for near-zero distances (r ~ 1), causing seed-dependent failures in
roughly one out of four runs (496/2000 simulated seeds; observed max
drift of 54958 ULPs at unit scale, hence a 1e6 ULP budget matching
the previous `1.0e6 * EPS` relative tolerance).
@stdlib-bot

stdlib-bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/incr/nanewmean $\\color{green}131/131$
$\\color{green}+0.00\\%$
$\\color{green}7/7$
$\\color{green}+0.00\\%$
$\\color{green}2/2$
$\\color{green}+0.00\\%$
$\\color{green}131/131$
$\\color{green}+0.00\\%$
stats/incr/nanmmda $\\color{green}152/152$
$\\color{green}+0.00\\%$
$\\color{green}8/8$
$\\color{green}+0.00\\%$
$\\color{green}2/2$
$\\color{green}+0.00\\%$
$\\color{green}152/152$
$\\color{green}+0.00\\%$
stats/incr/nanmme $\\color{green}146/146$
$\\color{green}+0.00\\%$
$\\color{green}8/8$
$\\color{green}+0.00\\%$
$\\color{green}2/2$
$\\color{green}+0.00\\%$
$\\color{green}146/146$
$\\color{green}+0.00\\%$
stats/incr/nanmmpe $\\color{green}149/149$
$\\color{green}+0.00\\%$
$\\color{green}8/8$
$\\color{green}+0.00\\%$
$\\color{green}2/2$
$\\color{green}+0.00\\%$
$\\color{green}149/149$
$\\color{green}+0.00\\%$
stats/incr/nanmpcorr2 $\\color{green}170/170$
$\\color{green}+0.00\\%$
$\\color{green}12/12$
$\\color{green}+0.00\\%$
$\\color{green}2/2$
$\\color{green}+0.00\\%$
$\\color{green}170/170$
$\\color{green}+0.00\\%$
stats/incr/nanmpcorrdist $\\color{green}156/156$
$\\color{green}+0.00\\%$
$\\color{green}11/11$
$\\color{green}+0.00\\%$
$\\color{green}2/2$
$\\color{green}+0.00\\%$
$\\color{green}156/156$
$\\color{green}+0.00\\%$

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

@Planeshifter
Planeshifter requested a review from kgryte July 21, 2026 14:12
claude added 2 commits July 21, 2026 14:18
The correlation distance is computed as `d = 1 - r`, meaning
floating-point error in `d` accumulates at the scale of ULPs of unity
and is largely independent of the magnitude of `d` itself. For
near-zero distances (r ~ 1; common when NaN-dense windows keep the
effective sample size small), a relative tolerance is arbitrarily
strict, causing seed-dependent failures in ~25% of simulated seeds
(and matching failures observed on develop). An absolute tolerance of
`1.0e6 * EPS` reuses the magnitude of the previous relative tolerance
at O(1) distances and bounds the maximum observed error (2.5e-11
across 8000 simulated seeds) with ~10x headroom. All other tolerance
logic matches `stats/incr/mpcorrdist`.
@kgryte kgryte removed the Needs Review A pull request which needs code review. label Jul 21, 2026

Copy link
Copy Markdown
Member Author

FYI: the coverage job failed again on 9cdfa8f — 3 assertions in the nanmpcorrdist random-sweep test, hitting both failure modes in one run:

✖ dataset: 5. window: 1. expected: 1.1102230246251565e-16. actual: 8.881784197001252e-16. tol: 2.465190328815662e-26.
✖ dataset: 8. window: 2. expected: 0. actual: 2.55351295663786e-15. tol: 2.220446049250313e-15.
✖ dataset: 8. window: 3. expected: 0. actual: 2.55351295663786e-15. tol: 2.220446049250313e-15.

These are the tolerances restored by the discard of 306ca40. Under them, ~25% of seeds fail (simulated over 2000 seeds); the base mpcorrdist test has the same rate (1134/5000 seeds) under its own NaN-free datasets, so this is a family-wide issue rather than specific to the nan wrapper. Error in d = 1 - r is absolute-scale (max 2.4e-11 across 8000 seeds), which is why any relative tolerance collapses near r ≈ 1.

Happy to reinstate the absolute-tolerance change (3-line diff, tol = 1.0e6 * EPS in the random sweep) or leave this to a family-wide fix covering mpcorrdist/nanmpcorr2/mpcorr2 — whichever you prefer.


Generated by Claude Code

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.

4 participants