Skip to content

test: migrate stats/base/dists/gamma/mgf to ULP-based assertions - #15950

Merged
kgryte merged 1 commit into
developfrom
kgryte/ulp-gamma-mgf
Oct 12, 2026
Merged

kgryte merged 1 commit into
developfrom
kgryte/ulp-gamma-mgf

Conversation

@kgryte

@kgryte kgryte commented Oct 7, 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/mgf from relative tolerance testing to ULP difference testing, replacing the computed delta/tol comparisons with @stdlib/assert/is-almost-same-value.

  • applies the same change to test/test.mgf.js, test/test.factory.js, and test/test.native.js.

  • uses the following ULP bounds, one per Julia fixture set, identical across all three test files:

    Fixture set Previous relative tolerance ULP bound (measured minimum)
    both_large 3000.0 * EPS * abs( expected[ i ] ) 3259
    large_shape 6500.0 * EPS * abs( expected[ i ] ) 10882
    large_rate 1200.0–2200.0 * EPS * abs( expected[ i ] ) 2062

Each bound is the measured minimum over the full 1000-case fixture set: decrementing all three by one produces exactly three failures (one per fixture set), confirming that every bound is attained and none can be tightened further.

The bounds are large because the MGF is evaluated as pow( 1 - t/beta, -alpha ), and the fixture sets deliberately probe large shape and rate parameters where 1 - t/beta approaches zero. Raising a near-zero base to a large negative power amplifies the rounding error in the base by a factor of roughly alpha / (1 - t/beta), so results spanning 50+ orders of magnitude (up to ~1e56) carry a correspondingly large relative error. The worst large_shape case is x = 6.606761672303701, alpha = 19.435205706716904, beta = 6.617230456158223, where the result is ~2.71e54. The previous relative tolerances admitted the same cases: a tolerance of N * EPS * abs( expected[ i ] ) permits between N and 2N ULPs depending on where the result falls within its binade, so the old 6500.0 * EPS bound allowed up to ~13000 ULPs.

Measurements were taken with the native add-on built locally, so the native implementation was exercised rather than skipped. The JavaScript and native implementations are structurally identical (pow( 1 - t/beta, -alpha )) and agree bit-for-bit on every fixture case, so both require exactly the same minimum bounds.

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?

No.

Other

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

The package test suite was run twice at the final ULP bounds to confirm determinism (no FMA or architecture-dependent variation): 3020 assertions in test/test.factory.js, 3017 in test/test.mgf.js, 3017 in test/test.native.js, and 3 in test/test.js, all passing on both runs. make eslint-tests TESTS_FILTER=".*/stats/base/dists/gamma/mgf/.*" is clean for all four files.

The migration idiom mirrors previously converted packages in the same family, in particular stats/base/dists/gamma/quantile, which shares the same main/factory/native test layout and the same both_large/large_shape/large_rate fixture sets: the if ( y === expected[i] ) equality branch is collapsed into a single assertion (an exact match is already a zero-ULP difference), the assertion message is normalized to 'returns expected value', and the abs/EPS requires are replaced by a single isAlmostSameValue require.

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 mirrored the migration idiom from previously converted packages in the same family (e.g. stats/base/dists/gamma/quantile, stats/base/dists/gamma/cdf) and determined the minimum passing ULP bounds empirically.


@stdlib-js/reviewers

🤖 Generated with Claude Code

https://claude.ai/code/session_013vj7gTBcnhuXinFm5GiE5g


Generated by Claude Code

Replace computed relative tolerance comparisons with ULP-based
assertions using `@stdlib/assert/is-almost-same-value`. The ULP bounds
were tightened to the measured minimums over the full 1000-case
fixture sets: 3259 (`both_large`), 10882 (`large_shape`), and 2062
(`large_rate`). The JavaScript and native implementations require
identical bounds.

Ref: #11352

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

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

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/gamma/mgf $\\color{green}322/322$
$\\color{green}+100.00\\%$
$\\color{green}23/23$
$\\color{green}+100.00\\%$
$\\color{green}4/4$
$\\color{green}+100.00\\%$
$\\color{green}322/322$
$\\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 Oct 12, 2026
@kgryte
kgryte marked this pull request as ready for review October 12, 2026 00:07
@kgryte
kgryte requested a review from a team October 12, 2026 00:07
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Oct 12, 2026
@kgryte
kgryte merged commit 63a4212 into develop Oct 12, 2026
82 checks passed
@kgryte
kgryte deleted the kgryte/ulp-gamma-mgf branch October 12, 2026 00:09
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Oct 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