Expand description
Descriptive statistics — zero-allocation kernels over caller-owned slices.
These are the single source of truth for descriptive statistics in the
engine. Domain/specialized libraries MUST call these rather than
re-implementing mean/variance/etc. inline (Modality-First Composition;
see MODALITY_FIRST_CONSOLIDATION.md).
Every function operates on a slice the caller already owns — no Vec, no
allocation, no copy. median_in_place sorts the caller’s buffer with the
non-allocating sort_unstable_by; the caller decides whether to clone first.
None is returned for an empty slice so callers can map it onto their own
error type without this layer inventing one.
Functions§
- argmax
- Index of the maximum value (the first on a tie) — the argmax selection used for greedy
token decoding (choose the highest-scoring logit).
Nonefor an empty slice. Non-finite values compare by the usual>(aNaNnever wins). - covariance
- Covariance of two equal-length series.
sample == truedivides byn-1(Bessel), else byn.Noneif the lengths differ or are empty. - kurtosis
- Excess kurtosis (
g2 = m₄ / m₂² − 3); 0 for a normal distribution.Noneif empty;Some(0.0)for a constant series. - max
- Maximum element by total-order comparison.
Noneif empty. - mean
- Arithmetic mean.
Noneif empty. - median_
in_ place - Median, sorting the caller’s buffer in place (no allocation).
Noneif empty. - median_
sorted - Median of a slice that is already sorted ascending.
Noneif empty. For an even count, returns the mean of the two central elements. - min
- Minimum element by total-order comparison.
Noneif empty. - mode_
in_ place - Mode — the most frequently occurring value, with its count.
- quantile_
in_ place - Quantile, sorting the caller’s buffer in place (no allocation).
Noneif empty. - quantile_
sorted - Linear-interpolated quantile of an already-sorted-ascending slice (the
numpy “linear” / R type-7 convention).
qis clamped to[0,1].Noneif empty. - skewness
- Sample skewness (Fisher–Pearson,
g1 = m₃ / m₂^{3/2}), the standardised third moment.Noneif empty;Some(0.0)for a constant series (zero spread). - std_dev
- Standard deviation = sqrt(variance).
Noneif empty. - sum
- Sum of all elements. Zero for an empty slice.
- variance
- Variance.
sample == trueuses Bessel’s correction (divide by n-1); otherwise the population variance (divide by n).Noneif empty.