Skip to content

test: migrate stats/base/dists/gamma/pdf to ULP-based assertions - #14206

Merged
kgryte merged 1 commit into
developfrom
kgryte/ulp-gamma-pdf
Aug 12, 2026
Merged

test: migrate stats/base/dists/gamma/pdf to ULP-based assertions#14206
kgryte merged 1 commit into
developfrom
kgryte/ulp-gamma-pdf

Conversation

@kgryte

@kgryte kgryte commented Aug 12, 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/gamma/pdf from relative tolerance testing (delta = abs( y - expected[i] ), tol = 170.0 * EPS * abs( expected[i] ), t.ok( delta <= tol, ... )) to ULP difference testing using @stdlib/assert/is-almost-same-value.
  • updates test/test.pdf.js, test/test.factory.js, and test/test.native.js, which mirror one another. test/test.js only asserts the shape of the exported API and contains no tolerance comparisons, so it is left untouched.
  • removes the now unused @stdlib/math/base/special/abs and @stdlib/constants/float64/eps imports from the three updated test files, as abs and EPS are not used anywhere else in those files.

The ULP bounds were tightened to the measured minimum which passes over the full fixture set, for both the JavaScript and the C implementations:

Fixture file Test case Previous tolerance ULP bound Measured maximum ULP difference
fixtures/julia/both_large.json evaluates the pdf for x given large alpha and beta 170.0 * EPS 275 275 (JS and native)
fixtures/julia/large_shape.json evaluates the pdf for x given large shape parameter alpha 140.0 * EPS 168 168 (JS and native)
fixtures/julia/large_rate.json evaluates the pdf for x given large rate parameter beta 120.0 * EPS 208 208 (JS and native)

Notes on how the bounds were determined:

  • Each bound is the minimum non-negative integer for which every fixture value passes, found by binary searching isAlmostSameValue per fixture value and taking the maximum over each 1000-value fixture set. In each set exactly one value attains the maximum, so none of the three bounds can be lowered.
  • Lowering each bound by one (274, 167, 207) was explicitly checked and fails with exactly three failing assertions, one per fixture set, confirming that the bounds are tight.
  • The JavaScript and C implementations agree exactly with one another on all 3000 fixture values, so test.pdf.js, test.factory.js, and test.native.js use identical bounds. The number of bit-for-bit exact values against the Julia reference is likewise identical for both implementations (10 of 1000 for both_large, 18 of 1000 for large_shape, 38 of 1000 for large_rate).
  • The bounds are larger than for many previously converted packages because the fixtures deliberately probe large shape and rate parameters, where the pdf is evaluated through ln(gamma)-style intermediates and the accumulated error relative to the Julia reference is correspondingly larger. The bounds are consistent in magnitude with the relative tolerances they replace (a k * EPS relative tolerance corresponds to roughly k to 2k ULP, depending on where the value sits within its binade).
  • The native add-on was compiled locally, so test/test.native.js was exercised against the actual C implementation rather than skipped.
  • The full test suite was run twice at the final bounds, with identical results per run: 3 assertions for test.js, 3026 for test.pdf.js, 3030 for test.factory.js, and 3026 for test.native.js, all passing.

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.

  • Only the three test files are modified; no source, documentation, benchmark, or fixture files are touched.
  • Linting is clean via make lint-javascript-tests TESTS_FILTER=".*/stats/base/dists/gamma/pdf/.*", which uses etc/eslint/.eslintrc.tests.js.
  • Environment note: the pre-commit hook's EditorConfig check could not run in this session, as it downloads the editorconfig-checker binary from GitHub releases and that request is blocked here. The commit was therefore made with SKIP_LINT_EDITORCONFIG=1; every other pre-commit check (JavaScript test linting, filename linting, license headers, commit message linting) ran and passed. The three modified files were instead checked manually against .editorconfig: LF line endings, UTF-8, tab indentation, no trailing whitespace, and a final newline.

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 bounds were measured empirically against both the JavaScript and compiled C implementations rather than guessed.


@stdlib-js/reviewers


Generated by Claude Code

Replace relative EPS-based tolerance checks with ULP-based assertions
using `@stdlib/assert/is-almost-same-value`. ULP bounds were tightened
to the measured minimum over the full fixture sets.

Ref: #11352

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

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

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/gamma/pdf $\\color{red}487/539$
$\\color{green}+90.35\\%$
$\\color{red}40/49$
$\\color{green}+81.63\\%$
$\\color{green}6/6$
$\\color{green}+100.00\\%$
$\\color{red}487/539$
$\\color{green}+90.35\\%$

The above coverage report was generated for the changes in this PR.

@kgryte kgryte added the Tests Pull requests specifically adding tests. label Aug 12, 2026
@kgryte
kgryte marked this pull request as ready for review August 12, 2026 22:59
@kgryte
kgryte requested a review from a team August 12, 2026 22:59
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Aug 12, 2026
@kgryte
kgryte merged commit 57b9c44 into develop Aug 12, 2026
82 checks passed
@kgryte
kgryte deleted the kgryte/ulp-gamma-pdf branch August 12, 2026 23:01
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Aug 12, 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