Skip to content

test: migrate stats/base/dists/f/mode to ULP-based assertions - #14147

Merged
kgryte merged 1 commit into
developfrom
kgryte/ulp-f-mode
Aug 10, 2026
Merged

kgryte merged 1 commit into
developfrom
kgryte/ulp-f-mode

Conversation

@kgryte

@kgryte kgryte commented Aug 10, 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/base/dists/f/mode from relative tolerance testing to ULP difference testing, replacing the delta/tol comparisons in test/test.js and test/test.native.js with isAlmostSameValue.
  • adds the @stdlib/assert/is-almost-same-value import and removes the now unused @stdlib/constants/float64/eps and @stdlib/math/base/special/abs imports.

Final ULP constant: 0, in both test files.

The ULP bound was measured rather than guessed: for every fixture value, the minimum ULP difference which admits the computed result was determined directly (searching upward from 0), and the maximum over the full fixture set was taken.

Fixture Values Previous tolerance Measured max ULP diff ULP constant
data.json 100 1.0*EPS 0 0

Both the JavaScript and C implementations reproduce every Julia fixture value exactly, so the measured minimum is 0 ULP — the tightest bound expressible. This is expected here: both implementations evaluate the identical expression ( ( d1-2.0 ) / d1 ) * ( d2 / ( d2+2.0 ) ), which is two divisions and a multiplication with no opportunity for FMA contraction.

test/test.native.js was verified against a locally compiled add-on (make install-node-addons NODE_ADDONS_PATTERN='stats/base/dists/f/mode') so that it did not skip; the 0 ULP bound is therefore measured for the C implementation as well, not merely inherited from the JavaScript results. Each suite was run twice at the final bound to confirm determinism (no FMA/architecture variation); all assertions pass on every run (test.js: 116, test.native.js: 116).

Only the two test files are changed; the implementation and fixtures are untouched.

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.

Opened as a draft pending maintainer review of the 0 ULP bound. A bound of 0 requires bit-for-bit agreement with the fixtures; there is existing precedent in the repo (stats/base/dists/pareto-type1/quantile, stats/base/dists/weibull/logcdf, stats/base/dists/uniform/entropy, and math/base/special/covercos all use 0 for fixture groups which match exactly), and the results here are deterministic IEEE-754 in both implementations. If maintainers would prefer a 1 ULP margin in test/test.native.js as a hedge against compiler/architecture variation in the C build, that is a one-character change.

Two environment notes, neither affecting the diff:

  • The editorconfig-checker stage of the local pre-commit hook could not run, because it downloads its binary from a GitHub release which was not reachable from this environment. EditorConfig conformance was instead verified manually for the changed files (LF line endings, UTF-8, tab indentation, no trailing whitespace, final newline present). Linting passes cleanly with the repository's test configuration (make lint-javascript-files ESLINT_CONF=./etc/eslint/.eslintrc.tests.js FILES=...).
  • make install-node-modules initially failed in this environment because a transitive dependency requested a registry version which was not resolvable here (es-object-atoms@^1.1.2; the registry as seen from this environment publishes at most 1.1.1). A subsequent install attempt resolved successfully and produced a working toolchain. Flagging it in case CI hits the same intermittent resolution failure.

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 written by Claude Code running as an unattended scheduled task: it selected the package, studied prior conversions in the repo to match the established idiom, applied the test migration, measured the minimum ULP bound empirically, and verified tests and linting locally.


@stdlib-js/reviewers


Generated by Claude Code

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

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/f/mode $\\color{green}195/195$
$\\color{green}+100.00\\%$
$\\color{green}10/10$
$\\color{green}+100.00\\%$
$\\color{green}2/2$
$\\color{green}+100.00\\%$
$\\color{green}195/195$
$\\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 Aug 10, 2026
@kgryte
kgryte marked this pull request as ready for review August 10, 2026 20:48
@kgryte
kgryte requested a review from a team August 10, 2026 20:48
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Aug 10, 2026
@kgryte
kgryte merged commit 44cb452 into develop Aug 10, 2026
82 checks passed
@kgryte
kgryte deleted the kgryte/ulp-f-mode branch August 10, 2026 20:50
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Aug 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