Skip to content

test: migrate stats/base/dists/beta/logpdf to ULP-based assertions - #15656

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

kgryte wants to merge 1 commit into
developfrom
kgryte/ulp-beta-logpdf

Conversation

@kgryte

@kgryte kgryte commented Sep 29, 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 unit tests for @stdlib/stats/base/dists/beta/logpdf from relative tolerance checks (delta <= tol, computed as <k> * EPS * abs( expected[ i ] )) to ULP-based assertions using @stdlib/assert/is-almost-same-value.
  • Applies the migration to test/test.logpdf.js, test/test.factory.js, and test/test.native.js (the three files containing fixture loops with computed tolerances). test/test.js only performs exact comparisons and is left unchanged.
  • Removes the now-unused @stdlib/math/base/special/abs and @stdlib/constants/float64/eps requires, along with the delta and tol declarations and the y === expected[i] fast-path branch.

ULP bounds

The bounds are the measured minima over the full fixture sets (1000 elements each), determined by computing the maximum ULP difference between the actual and expected values for every fixture element:

Fixture Previous tolerance ULP bound Notes
both_large.json 45000.0 * EPS 45056 892/1000 elements are inexact; max measured ULP difference is 45056.
large_alpha.json 20000.0 * EPS (JS) / 22000.0 * EPS (native) 20480 732/1000 elements are inexact; max measured ULP difference is 20480.
large_beta.json 20000.0 * EPS 13312 740/1000 elements are inexact; max measured ULP difference is 13312; tightened from the previous, looser tolerance.

The bounds are large because the fixtures concentrate near the mode, where logpdf values are close to zero and subject to catastrophic cancellation; in absolute terms the largest discrepancy is on the order of 5e-15. Each bound is nonetheless equal to or tighter than the relative tolerance it replaces.

The same bounds are used in test.logpdf.js, test.factory.js, and test.native.js. The native add-on was built locally and measured independently: the C implementation produces the same maxima (45056 / 20480 / 13312), so the previously higher native large_alpha tolerance was slack rather than a JS/C divergence.

Verification

  • Package tests are green (make test TESTS_FILTER=".*/stats/base/dists/beta/logpdf/.*"), and the suite was run twice at the final bounds with identical results (9093 passing assertions, 0 failing). test.native.js was exercised against a locally built add-on rather than skipped.
  • Minimality was confirmed programmatically: lowering each bound by one (45055 / 20479 / 13311) produces exactly three failures, one per fixture loop.
  • make lint-javascript-tests TESTS_FILTER=".*/stats/base/dists/beta/logpdf/.*" is clean.
  • Only the three test files are changed.

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?

  • The measured bounds here are considerably larger than in most converted packages, for the cancellation reason noted above. Please flag if you would prefer the fixtures be regenerated over a range that avoids the near-zero region instead of encoding bounds this wide.

Other

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

The inline integer bound idiom (rather than a named ULP constant) mirrors the prevailing convention in stats/base/dists, where all already-converted test files use inline literals.

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, which surveyed prior converted packages to match the established idiom, applied the test edits, and measured the minimum ULP bounds empirically over the fixture sets for both the JavaScript and native implementations.


@stdlib-js/reviewers

🤖 Generated with Claude Code

https://claude.ai/code/session_018Jh65nerjkdreo4WZ75TVj


Generated by Claude Code

Replaces the relative-tolerance comparisons (`delta <= tol`) in the
fixture loops with `@stdlib/assert/is-almost-same-value` assertions. The
ULP bounds are the measured minima over the full fixture sets: `45056`
for the both-large fixtures, `20480` for the large `alpha` fixtures, and
`13312` for the large `beta` fixtures. The same bounds hold for the
JavaScript and native implementations.

Ref: #11352

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

---
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: passed
  - 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 Sep 29, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

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