Skip to content

test: migrate stats/base/dists/lognormal/variance to ULP-based assertions - #14069

Merged
kgryte merged 1 commit into
developfrom
kgryte/ulp-lognormal-variance
Aug 8, 2026
Merged

test: migrate stats/base/dists/lognormal/variance to ULP-based assertions#14069
kgryte merged 1 commit into
developfrom
kgryte/ulp-lognormal-variance

Conversation

@kgryte

@kgryte kgryte commented Aug 8, 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/lognormal/variance from computed relative tolerance testing (delta = abs( y - expected[i] ), tol = 1.0 * EPS * abs( expected[i] ), t.ok( delta <= tol, ... )) to ULP difference testing using @stdlib/assert/is-almost-same-value.
  • updates both test/test.js and test/test.native.js, which mirror one another.
  • removes the now unused @stdlib/math/base/special/abs and @stdlib/constants/float64/eps requires from both test files (neither is used elsewhere in these files).

ULP bounds (tightened to the measured minimum over the full fixture set):

Fixture file Test case ULP bound Measured maximum ULP difference
fixtures/julia/data.json the function returns the variance of a lognormal distribution 0 0 (JS and native)

Notes on how the bound was determined:

  • The bound is the minimum non-negative integer for which every fixture value passes. All 100 fixture values are bit-for-bit exact against the Julia reference values, for both the JavaScript and the C implementations, so 0 is both the measured maximum and the tightest possible bound.
  • The measurement was performed by computing, for each fixture value, the smallest N for which isAlmostSameValue( y, expected[i], N ) is true, and taking the maximum over the fixture set. Starting from a bound of 64 and lowering, the suite passes all the way down to 0.
  • This is consistent with the implementation: the variance of a lognormal distribution is ( exp( s2 ) - 1 ) * exp( ( 2*mu ) + s2 ) with s2 = sigma^2, and the JavaScript and C implementations evaluate exactly the same expression using the same underlying exp kernel, leaving no room for the two to diverge on these inputs.
  • Because the results are exact, the old y === expected[i] fast path was taken for every fixture value and the tolerance branch was never exercised.
  • The JavaScript and C implementations agree exactly, so test.js and test.native.js use identical bounds.
  • The native add-on was compiled locally (node-gyp rebuild), so test/test.native.js was exercised against the actual C implementation rather than skipped. Both test files were run twice at the final bound with identical results (110 assertions for test.js, 111 for test.native.js, all passing, per run), so the bound is not sensitive to FMA/contraction differences on this machine.

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?

Two minor points:

  • The existing if ( expected[i] !== null ) guard was retained in both loops in order to keep the diff limited to the tolerance math. The current fixture data contains no null entries, so the guard is presently inert and could be dropped if reviewers prefer.
  • Given that every fixture value is bit-for-bit exact, a bound of 0 is equivalent to a strict equality check. isAlmostSameValue( ..., 0 ) was chosen for consistency with the other converted packages, matching the approach taken in stats/base/dists/erlang/skewness (test: migrate stats/base/dists/erlang/skewness to ULP-based assertions #14022).

Other

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

  • Only the two test files are modified; no source, documentation, benchmark, or fixture files are touched.
  • Verified with make test TESTS_FILTER=".*/stats/base/dists/lognormal/variance/.*" and by running both test files directly against the compiled add-on. Linting is clean via ESLint using etc/eslint/.eslintrc.tests.js.
  • The editorconfig pre-commit hook could not run in this environment, as it downloads its binary from a host this session cannot reach. The two files were instead checked against .editorconfig (LF endings, tab indentation, final newline, UTF-8); the diff introduces no new violations.
  • The idiom follows previously merged conversions, in particular stats/base/dists/erlang/skewness (test: migrate stats/base/dists/erlang/skewness to ULP-based assertions #14022), which uses an inline integer ULP argument per fixture loop and the 'returns expected value' assertion message.

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. The test migration follows the idiom established by previously merged conversions, and the ULP bound was measured empirically against both the JavaScript and compiled C implementations rather than guessed.


@stdlib-js/reviewers


Generated by Claude Code

…rtions

Migrates the tests for `stats/base/dists/lognormal/variance` from
computed relative tolerance checks to ULP-based assertions using
`@stdlib/assert/is-almost-same-value`. The ULP bound was tightened to
the measured minimum (0) over the full fixture set for both the
JavaScript and compiled C implementations.

Ref: #11352
@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 8, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/lognormal/variance $\\color{green}178/178$
$\\color{green}+100.00\\%$
$\\color{green}9/9$
$\\color{green}+100.00\\%$
$\\color{green}2/2$
$\\color{green}+100.00\\%$
$\\color{green}178/178$
$\\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 8, 2026
@kgryte
kgryte marked this pull request as ready for review August 8, 2026 23:27
@kgryte
kgryte requested a review from a team August 8, 2026 23:27
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Aug 8, 2026
@kgryte
kgryte merged commit 3f3fce8 into develop Aug 8, 2026
82 checks passed
@kgryte
kgryte deleted the kgryte/ulp-lognormal-variance branch August 8, 2026 23:28
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Aug 8, 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.

4 participants