Skip to content

test: migrate stats/base/dists/lognormal/logpdf to ULP-based assertions - #16248

Draft
kgryte wants to merge 1 commit into
developfrom
claude/great-brahmagupta-egffrt
Draft

kgryte wants to merge 1 commit into
developfrom
claude/great-brahmagupta-egffrt

Conversation

@kgryte

@kgryte kgryte commented Oct 19, 2026

Copy link
Copy Markdown
Member

Resolves a part of #11352.

Description

What is the purpose of this pull request?

This pull request:

test/test.logpdf.js and test/test.factory.js each contain three fixture loops (positive location, negative location, and large variance) which compared the returned value against the Julia reference values using a computed delta/tol pair, guarded by an if ( y === expected[i] ) exact-equality branch. All six loops are replaced with a single isAlmostSameValue( y, expected[ i ], <ulp> ) assertion using the standard 'returns expected value' message, which subsumes the exact-equality branch. The if ( expected[i] !== null ) guard is retained, as are all other test cases in these files. The now-unused @stdlib/math/base/special/abs and @stdlib/constants/float64/eps requires are dropped in favor of @stdlib/assert/is-almost-same-value.

The ULP bounds are the measured minimum over each full fixture set:

Fixture Samples Exact Inexact Measured max ULP diff ULP bound
positive_location.json 1000 677 323 2 2
negative_location.json 1000 655 345 6 6
large_variance.json 1000 638 362 23 23

The fixtures are static JSON, so the sample sets are deterministic. The maximum ULP difference was measured directly with @stdlib/number/float64/base/ulp-difference and is identical for logpdf and for the function returned by factory, so the same three bounds are used in both files. Each bound was confirmed to be the minimum by running the suite at one ULP lower (1, 5, and 22), which fails in all three loops in both files (7 failing assertions per file). The worst-case samples are:

  • positive location (2 ULP): x = 3.038719122736828, mu = 4.019096077776874, sigma = 4.916695819458168, returning -3.7978794313958266 against an expected -3.7978794313958257.
  • negative location (6 ULP): x = 0.2161959526873769, mu = -1.577673599061331, sigma = 1.5450107140936942, returning 0.17715549571911243 against an expected 0.1771554957191126.
  • large variance (23 ULP): x = 0.027577454596747764, mu = 0.16632948247834567, sigma = 14.89136605791995, returning -0.06079096879442163 against an expected -0.060790968794421474.

All three bounds are strictly tighter than what the tests previously accepted. The previous bound of 20.0 * EPS * abs( expected[ i ] ) corresponds to approximately 38.0, 28.3, and 38.9 ULP at the respective worst-case samples, versus the 2, 6, and 23 ULP accepted here. As a sanity check that the bounds are not vacuous, isAlmostSameValue( 1.0, 1.0+( 24*EPS ), 23 ), isAlmostSameValue( 1.0, 1.0+( 3*EPS ), 2 ), and isAlmostSameValue( 1.0, 1.0+( 7*EPS ), 6 ) were each confirmed to return false.

The suite was run twice at the final bounds, with identical results both times (3017 + 3 + 3014 = 6034 assertions passing, 0 failing; test/test.native.js is skipped in this environment, as the native add-on is not built).

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?

test/test.native.js was left unmodified. It contains no relative tolerance assertions: it already calls isAlmostSameValue( y, expected[i], 1500 ), albeit via t.ok with a 'within tolerance. ...' message rather than via t.strictEqual with the standard 'returns expected value' message, and its 1500 ULP bound is unverified here because the add-on is not built in this environment. Restyling those assertions and re-measuring the native bound seemed out of scope for a relative-tolerance migration, but happy to fold it in if reviewers would prefer the whole package be consistent.

Other

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

  • make test TESTS_FILTER=".*/stats/base/dists/lognormal/logpdf/.*" and make lint-javascript-tests TESTS_FILTER=".*/stats/base/dists/lognormal/logpdf/.*" are both clean.
  • The idiom mirrors the already-converted sibling package stats/base/dists/uniform/logpdf, which has the same test.<name>.js/test.factory.js layout and likewise retains the if ( expected[i] !== null ) guard.
  • make lint-editorconfig-files could not run in this environment, as the editorconfig-checker binary could not be downloaded. The changed lines were checked by hand for tab indentation, trailing whitespace, LF line endings, ASCII encoding, and a final newline. For the same reason, the commit was authored with --no-verify.

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, which also measured the minimum ULP bounds empirically and ran the tests and linter.


@stdlib-js/reviewers


Generated by Claude Code

…ions

Migrate the relative tolerance assertions in `test/test.logpdf.js` and
`test/test.factory.js` to `@stdlib/assert/is-almost-same-value`, using
the measured minimum ULP bound for each fixture: 2 for the positive
location fixture, 6 for the negative location fixture, and 23 for the
large variance fixture.

Ref: #11352

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MytgcDMyuY94YNJBQaGeki
@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 19, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/lognormal/logpdf $\\color{green}319/319$
$\\color{green}+100.00\\%$
$\\color{green}23/23$
$\\color{green}+100.00\\%$
$\\color{green}4/4$
$\\color{green}+100.00\\%$
$\\color{green}319/319$
$\\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