Skip to content

test: migrate stats/base/dists/gamma/entropy to ULP-based assertions - #15918

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

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

Conversation

@kgryte

@kgryte kgryte commented Oct 5, 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/entropy 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 both test/test.js and test/test.native.js.
  • uses a ULP bound of 188416 in both test files. This is the measured minimum: a binary search over the full 200-case Julia fixture set shows that 188416 ULPs passes every case while 188415 fails, for both the JavaScript and the native implementation.

The bound is large because the differential entropy of a gamma distribution is computed as a sum of terms of opposing sign (alpha - ln(beta) + lngamma(alpha) + (1-alpha)*digamma(alpha)), so fixture cases where the result falls close to zero suffer catastrophic cancellation. The worst case is alpha = 16.524296224667474, beta = 16.463066273781664, where the result is -2.4488832308833e-4 — roughly five orders of magnitude smaller than the individual summands — and the absolute error is ~1e-20. The previous relative tolerance of 1e-10 * abs( expected[ i ] ) admitted the same cases. For comparison, the already-migrated sibling package stats/base/dists/invgamma/entropy settled on a bound of 90112 ULPs for the same reason.

Measurements were taken with the native add-on built locally, so the native implementation was exercised rather than skipped. Both implementations required exactly the same minimum bound.

Only the two 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 bound to confirm determinism (214 assertions passing in each of test/test.js and test/test.native.js on both runs), and make lint-javascript-tests TESTS_FILTER=".*/stats/base/dists/gamma/entropy/.*" is clean for both files.

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 merged conversions in the same family (e.g. stats/base/dists/invgamma/entropy) and determined the minimum passing ULP bound empirically.


@stdlib-js/reviewers

🤖 Generated with Claude Code

https://claude.ai/code/session_01H6NQ1XGDBg2vzphpvakfVr


Generated by Claude Code

Replace computed relative tolerance comparisons with ULP-based
assertions using `@stdlib/assert/is-almost-same-value`. The ULP bound
was tightened to the measured minimum of 188416 ULPs for both the
JavaScript and native implementations over the full 200-case fixture
set.

Ref: #11352

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

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/gamma/entropy $\\color{green}202/202$
$\\color{green}+100.00\\%$
$\\color{green}10/10$
$\\color{green}+100.00\\%$
$\\color{green}2/2$
$\\color{green}+100.00\\%$
$\\color{green}202/202$
$\\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 12:55
@kgryte
kgryte requested a review from a team October 12, 2026 12:55
@kgryte
kgryte merged commit 93a0c8c into develop Oct 12, 2026
66 checks passed
@kgryte
kgryte deleted the kgryte/ulp-gamma-entropy branch October 12, 2026 12:56
@stdlib-bot stdlib-bot added Needs Review A pull request which needs code review. and removed Needs Review A pull request which needs code review. labels 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