Skip to content

style: align outliers in stats/base/dists/chi with namespace majority patterns#11722

Closed
Planeshifter wants to merge 2 commits intodevelopfrom
philipp/drift-stats-base-dists-chi-2026-04-22
Closed

style: align outliers in stats/base/dists/chi with namespace majority patterns#11722
Planeshifter wants to merge 2 commits intodevelopfrom
philipp/drift-stats-base-dists-chi-2026-04-22

Conversation

@Planeshifter
Copy link
Copy Markdown
Member

Description

Aligning outliers in stats/base/dists/chi with namespace majority patterns (random namespace pick, seed 2026-04-22-drift).

Namespace summary

  • Target namespace: @stdlib/stats/base/dists/chi
  • Member count: 12 non-autogenerated packages (cdf, ctor, entropy, kurtosis, logpdf, mean, mode, pdf, quantile, skewness, stdev, variance)
  • Features analyzed: file tree, package.json shape, README section layout, manifest.json shape, test/benchmark/examples naming, public signature, validation prologue, error construction, JSDoc shape, @stdlib/* dependencies
  • Features with a clear majority (≥75% conformance): native-addon file set (binding.gyp, manifest.json, include/, src/, lib/native.js, benchmark/benchmark.native.js, test/test.native.js, examples/c/), top-level ## C APIs README section, validation prologue at top of lib/main.js, Julia fixture layout under test/fixtures/julia/
  • Features without a clear majority (excluded): lib/factory.js (only present for functions taking a shape-parameter closure — 4/12) and related test.factory.js; these are structurally optional and excluded from drift detection

stats/base/dists/chi/stdev

Adds an explicit NaN / negative-k validation prologue to lib/main.js, aligning stdev with the convention followed by 10 of the 12 siblings in @stdlib/stats/base/dists/chi (~83% conformance). Previously, the guard was implicit — invalid inputs propagated through the variance delegation and happened to return NaN by accident rather than by contract. Observable behavior is unchanged; this is a correctness-by-construction fix that makes the invariant explicit at the call site.

stats/base/dists/chi/cdf

Restructures cdf/README.md to match the canonical section layout shared by 10 of 12 packages in the @stdlib/stats/base/dists/chi namespace (~83% conformance; reference: pdf/README.md, logpdf/README.md). The C APIs block is extracted from inside <section class="usage">, promoted to a top-level <section class="c"> wrapper, and its headings are raised one level (## C APIs, ### Usage). Section order is corrected to JS Usage → JS Examples → C APIs. No prose or code-block content is changed.

Related Issues

No.

Questions

No.

Other

Validation

  • Structural features extracted via direct filesystem / package.json / README inspection across all 12 members.
  • Semantic features (public signature, validation prologue, error construction, JSDoc shape, @stdlib/* dependencies) extracted per-package from lib/main.js.
  • Three-agent validation (semantic, cross-reference, structural) run over each outlier finding; only findings confirmed by all applicable agents survived to this PR.

Deliberately excluded from this PR

  • quantile/ lacks native C entirely (missing binding.gyp, manifest.json, include/, src/, lib/native.js, C benchmark/examples, test/test.native.js) — out of scope: adding native support requires authoring a C implementation, not a mechanical drift fix.
  • quantile/lib/main.js lacks the majority validation prologue — cross-reference verdict was confirmed-drift, but the semantic-review agent flagged it as intentional-deviation because quantile is a one-liner that delegates to gammaQuantile (which performs NaN propagation and its own domain checks). Per the routine, any intentional-deviation verdict from any agent drops the correction.
  • stdev/test/fixtures/ uses Python fixtures while 11/11 siblings (excluding ctor) use Julia fixtures — out of scope: regenerating fixtures from a different reference implementation is a cascading change that would require re-verifying tolerance against the existing test data.
  • ctor/ outliers on virtually every structural feature — intentional deviation: ctor is a distribution constructor, not a scalar function, and has a genuinely different shape.

Checklist

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

This PR was authored by an automated cross-package drift-detection routine driven by Claude Code. The routine (1) selected stats/base/dists/chi at random (seed 2026-04-22-drift) from eligible stdlib namespaces (≥8 non-autogenerated members), (2) extracted structural and semantic features from every member, (3) computed majority patterns with a 75% conformance threshold, (4) ran three independent validation agents to confirm each outlier finding as mechanical, non-semantic drift, and (5) applied only corrections that preserved observable behavior and did not require cascading changes. Every edit and commit message was produced by the routine; a human maintainer should audit before promoting this PR out of draft.


@stdlib-js/reviewers

claude added 2 commits April 22, 2026 12:54
…vention

Add explicit `isnan(k) || k < 0.0` guard at the top of `lib/main.js`,
matching the validation prologue used by `mean` and `variance` in the
same namespace (validation prologue present in 10/12 chi siblings, 83%).
The guard preserves observable behavior — NaN and negative `k` already
returned NaN via delegation to `variance()` — but makes the contract
explicit and consistent with the rest of `stats/base/dists/chi`.
Restructure `README.md` so C APIs live in their own
`<section class="c">` with a top-level `## C APIs` heading (present in
10/12 chi siblings, 83%), and so the JS `## Examples` section precedes
the C APIs section rather than following it. Promote the C subsection
heading from `#### Usage` to `### Usage` to match the level-3/level-3
pairing used by `pdf/README.md` and `logpdf/README.md`. No prose or
code-block content is modified.
@stdlib-bot stdlib-bot added the Statistics Issue or pull request related to statistical functionality. label Apr 22, 2026
@stdlib-bot
Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/chi/cdf $\color{red}277/279$
$\color{green}+99.28%$
$\color{red}23/24$
$\color{green}+95.83%$
$\color{green}4/4$
$\color{green}+100.00%$
$\color{red}277/279$
$\color{green}+99.28%$
stats/base/dists/chi/stdev $\color{green}163/163$
$\color{green}+100.00%$
$\color{green}8/8$
$\color{green}+100.00%$
$\color{green}2/2$
$\color{green}+100.00%$
$\color{green}163/163$
$\color{green}+100.00%$

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Statistics Issue or pull request related to statistical functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants