refactor: replace isProbability with inline range check in stats/base/dists/bernoulli/mgf#12292
Merged
kgryte merged 1 commit intoMay 27, 2026
Conversation
…ase/dists/bernoulli/mgf` Normalize the probability-range validation in `lib/main.js` and `lib/factory.js` to the inline form `isnan( p ) || p < 0.0 || p > 1.0` used by every other member of the `stats/base/dists/bernoulli` namespace (12/13 siblings; 92.3% conformance). Cross-namespace, the same inline form is used by 20/22 `stats/base/dists/*/mgf` packages (90.9%), so the previous `!isProbability(p)` form is also a minority across the wider `stats/base/dists` family. Behavior preserved: `isProbability(x)` returns `x >= 0.0 && x <= 1.0`, so `!isProbability(p)` and `isnan(p) || p < 0.0 || p > 1.0` agree on NaN, ±Infinity, and all finite inputs. The `@stdlib/math/base/assert/is-probability` import is removed from both files since it is no longer used. Manual smoke-tested against the existing `test/test.mgf.js` boundary cases (`NaN`, ±Infinity, `2.0`, `-0.5` for `p`); all return `NaN` as before.
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
kgryte
approved these changes
May 27, 2026
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
Normalizes the probability-range validation in
@stdlib/stats/base/dists/bernoulli/mgf(bothlib/main.jsandlib/factory.js) from!isProbability( p )to the inline formisnan( p ) || p < 0.0 || p > 1.0used by every other JS member of thestats/base/dists/bernoullinamespace, and removes the now-unused@stdlib/math/base/assert/is-probabilityrequire from both files.Namespace summary
@stdlib/stats/base/dists/bernoullicdf,ctor,entropy,kurtosis,mean,median,mgf,mode,pmf,quantile,skewness,stdev,variance)package.jsontop-level /scripts/stdlibkey sets;manifest.jsonkey set; README##/###section sequence;test//benchmark//examples/filenames; per-packagelib/main.jsandlib/factory.jspublic signature, validation prologue, return kind, error-construction style, JSDoc shape, andrequiredependency set.package.jsontop-level 18-key set (13/13 = 100%);manifest.jsonpresence + 3-key set (12/13 = 92%); the native-bindings file groupbinding.gyp/include.gypi/src/{Makefile,addon.c,main.c}/lib/native.js/include/.../<name>.h/examples/c/**/benchmark/c/**/benchmark/benchmark.native.js/test/test.native.js(12/13 = 92%); README 5-section sequence## Usage→## Examples→## C APIs→### Usage→### Examples(11/13 = 85%);test/fixtures/julia/REQUIRE+runner.jl(11/13 = 85%); validation prologueisnan( p ) || p < 0.0 || p > 1.0in JS sources wherepis checked (12/13 = 92%);valuereturn kind (13/13 = 100%); JSDochasExample(13/13 = 100%).name(p)8/13 vs 2-arg distribution-function packages 4/13 vsctor1/13 — no shape ≥75%); error-construction style (onlyctorthrows; the remaining 12 returnNaN, so this is degenerate).stats/base/dists/bernoulli/mgfReplaces
!isProbability( p )with the inlineisnan( p ) || p < 0.0 || p > 1.0check in bothlib/main.jsandlib/factory.js, and drops the unused@stdlib/math/base/assert/is-probabilityimport from each file. The inline form is what the other 12 bernoulli siblings use (92.3% conformance) and what 20 of the 22stats/base/dists/*/mgfpackages across the wider namespace use (90.9%).isProbability( x )is defined asx >= 0.0 && x <= 1.0, so the two forms agree on NaN, ±Infinity, and all finite inputs; observable behavior is preserved.Validation
Checked:
package.jsonshape;manifest.jsonshape; README##/###section list;test//benchmark//examples/filenames) across all 13 members.requiredependency set) across all 13 members by reading eachlib/main.js(andlib/factory.jswhere present) directly.bernoulli/mgfvalidation prologue):!isProbability( p )andisnan( p ) || p < 0.0 || p > 1.0are mathematically equivalent for double-precision input (NaN, ±Infinity, and out-of-range values all map to the false branch ofisProbability, which becomes the true branch of!isProbability, matching the disjunction).test/test.mgf.jsboundary cases (NaN, ±Infinity,2.0,-0.5forp) all returnNaNunder both forms,README.mdanddocs/repl.txtmake no reference toisProbability, and no sibling package importsbernoulli/mgfdirectly.stats/base/dists/bernoullior proposes this fix.test/test.mgf.jsexercises; all returnNaNas before.Deliberately excluded:
ctor— absence of the native-bindings file group,gypfile,manifest.json, and the canonical## Usage→## ExamplesREADME structure. Intentional: pure-JS class constructor with no native numerical hot path; the constructor's documentation legitimately requires intermediate property/method subsections.mode— extra## Notessection between## Usageand## Examples. Intentional: the Bernoulli mode is undefined atp === 0.5; the note documents stdlib's0convention. Stripping the section would lose content.stdev— usestest/fixtures/python/instead oftest/fixtures/julia/, and delegatesstdev( p ) = sqrt( variance( p ) )rather than carrying the canonical validation prologue. Cascading / intentional: regenerating fixtures and updating thetapetest loader is out of scope for a mechanical drift PR; the delegation idiom was the subject of merged PR refactor: reuse variance instats/base/dists/bernoulli/stdev#11366 and is correct.src/main.cforbernoulli/mgfonly checksisnan( t ) || isnan( p ), missing thep < 0.0 || p > 1.0range thatcdf/src/main.candpmf/src/main.capply, andlib/native.jsJSDoc actually documents the missing-check behaviour as expected. Not fixed here: changing observable native-path output and the documented examples is out of scope; surfacing as a separate behavioural follow-up.Related Issues
This pull request has no related issues.
Questions
No.
Other
stats/base/dists/geometric/mgfcarries the identicalisProbabilitydrift (the only other distribution-namespacemgfpackage using the predicate form) and is a clear follow-up candidate. Internal run metadata (random seed, full per-feature distributions, dropped corrections with reasons) lives in the local drift report at~/drift-reports/drift-stats-base-dists-bernoulli-2026-05-26.md.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was authored by Claude Code via the cross-package drift-detection routine: structural and semantic features were extracted from every member of
stats/base/dists/bernoulli, the majority pattern was computed at a 75% conformance threshold, and three independent validation agents (semantic-review, cross-reference, structural-review) confirmed the single surviving correction was high-signal mechanical drift before any file was edited. The edit replaces a predicate-based probability check with the namespace-standard inline check and removes the now-unused require; no test, fixture, or behavioural change.@stdlib-js/reviewers
Generated by Claude Code