Repository navigation
Conversation
…in `stats/base/dists/chi/logpdf` `(k-1) * ln(x)` is `0 * -Infinity = NaN` at `x = 0` when `k = 1`, while `chi/pdf` correctly returns `sqrt(2/π)` there. Skip the term when `k = 1`, keeping the order of the remaining operations so other results are unchanged.
5 of 7 tasks
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
5 of 7 tasks
Member
|
@Planeshifter Mind taking a look at this PR? |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request:
stats/base/dists/chi/logpdf(JS,factory, and C) returningNaNatx = 0whenk = 1.The log density is
(1-k/2) ln 2 + (k-1) ln(x) - x^2/2 - ln Gamma(k/2). Withk = 1andx = 0, the middle term is0 * -Infinity = NaN, butx^(k-1) = x^0is1there. The fix skips(k-1) ln(x)whenk = 1. For otherk,x = 0still gives+Infinity(k < 1) or-Infinity(k > 1), as it did before. I kept the order of the remaining additions as it was, so every other result is unchanged bit for bit. Rearranging the sum shifts rounding enough to fail 388 of the existing fixture checks.Related Issues
No.
Questions
No.
Other
x = 0withk = 1,k < 1andk > 1intest.logpdf.js,test.factory.jsandtest.native.js. Thek = 1assertion fails ondevelop, and all tests pass here.stats/base/distsfunction against SciPy at the support boundaries. Some other densities also return0atx = 0where the density is finite or infinite:weibullfork <= 1,kumaraswamyfora <= 1,betaprimeforalpha <= 1, andlog-logisticforbeta <= 1.gamma,beta,chisquareandfalready handle this case. I'll send those as separate PRs so each can be reviewed on its own.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was written primarily by Claude Code. The bug was found by comparing every
stats/base/distsfunction against SciPy on random parameters.@stdlib-js/reviewers