Skip to content

test: migrate stats/padjust to ULP-based assertions - #16189

Draft
kgryte wants to merge 1 commit into
developfrom
kgryte/ulp-padjust
Draft

kgryte wants to merge 1 commit into
developfrom
kgryte/ulp-padjust

Conversation

@kgryte

@kgryte kgryte commented Oct 16, 2026

Copy link
Copy Markdown
Member

Resolves a part of #11352.

Description

What is the purpose of this pull request?

This pull request:

Each of the eight fixture loops previously computed a relative tolerance (delta = abs( out[i] - expected[i] ) compared against tol = K * EPS * abs( expected[i] ), with K being 10.0, 15.0, or 20.0) and asserted via t.ok. These are replaced with

t.strictEqual( isAlmostSameValue( out[ i ], expected[ i ], 0 ), true, 'returns expected value' );

Notes:

  • Final ULP constant: 0 at all eight assertion sites. This is the measured minimum. ULP bounds were determined empirically by binary searching, for every individual comparison, the smallest maxULP for which isAlmostSameValue returns true, and then taking the per-site maximum over the full fixture set. All 38 comparisons across the eight R reference fixtures are exactly equal, so the required bound is 0. Starting from a high bound and tightening converges to the same result.
  • A bound of 0 is not brittle here: padjust performs only basic IEEE-754 arithmetic together with min/max/cumin/cumax, with no transcendental or libm-backed calls, so the computed values are bit-reproducible rather than platform-dependent.
  • The preceding if ( out[ i ] === expected[ i ] ) exact-comparison branch is folded into the single ULP assertion, since isAlmostSameValue already returns true for exactly equal values. No fixture value is 0, so no signed-zero edge case arises.
  • The now-unused @stdlib/constants/float64/eps and @stdlib/math/base/special/abs requires, and the now-unused delta and tol declarations, are removed.
  • The package has no test/test.native.js; test/test.js is the only test file, and it is the only file changed.

Verification:

  • make test TESTS_FILTER=".*/stats/padjust/.*" → 75 passing, 0 failing, run twice to confirm determinism (no FMA/architecture-dependent variation).
  • ESLint reports an identical set of findings before and after this change (all pre-existing and unrelated to the assertions); the diff introduces no new lint findings and in fact removes a max-lines finding.

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.

The editorconfig lint step could not be executed in the authoring environment, as it requires downloading the editorconfig-checker binary from a GitHub repository which was out of scope for that environment (it fails identically on unmodified files). Compliance was instead verified manually: LF line endings, UTF-8, tab indentation, final newline present, and no trailing whitespace introduced.

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 scheduled task. It studied the conventions established by already-converted packages, applied the conversion, determined the minimum ULP bounds empirically via the binary search described above, and verified the test suite and lint results.


@stdlib-js/reviewers


Generated by Claude Code

Replace relative tolerance comparisons with ULP difference
testing using `@stdlib/assert/is-almost-same-value`. The JS
implementation reproduces the R reference fixtures
bit-for-bit, so the minimum required ULP bound is `0` for
all eight fixture loops.

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

---
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: na
  - 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 Oct 16, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/padjust $\\color{green}604/604$
$\\color{green}+100.00\\%$
$\\color{red}64/65$
$\\color{green}+98.46\\%$
$\\color{green}10/10$
$\\color{green}+100.00\\%$
$\\color{green}604/604$
$\\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.

3 participants