histogram

std.stats.histogram · Level L3

Counts per bin for increasing bin edges, with NumPy's rules: half-open bins, the last one closed, values outside the edges not counted. Each value's bin comes from comparisons, becomes an integer slot with Cast, and is counted with ScatterAdd.

cᵢ = #{ x : eᵢ ≤ x < eᵢ₊₁ }

Signature

histogram(x: f64[n], edges: f64[m]) → f64[m−1]

Requires: m ≥ 2

Structure

The function as NOVA stores it: one box per input, operation and output, and arrows that carry values. A double border marks another library function this one runs — called once, or by Scan once per element; select it to open that function.

edgesf64[m]xf64[n]0.0SizemReshapeerReshapexcSlicelastMultiplyedge_zeros[0.0]Multiplyx01.0GreateraboveEqualon_lastConcatslotsAddonesReduceSumn_aboveSubtractat_or_belowSubtractbucketCastslotScatterAddfilledSlicecountscountsf64[m−1]
  • input
  • operation
  • constant
  • call
  • output

Verification

  • Signature proven by NOVA’s shape solver, for every size with m ≥ 2.
  • Equal to the reference np.histogram(x, edges)[0] in exact rational arithmetic, on all 40 test cases.
  • All 134 float64 results are exact: the error is zero.
  • Interpreter and NumPy backend return bit-identical results.
Accuracy in detail
correctly rounded (the float64 nearest the exact value)
100%
bit-equal to the NumPy formula in float64
87%
largest error, in units in the last place
0

Note

Slot 0 collects values below the first edge and slot m values above the last; both are sliced away. A value equal to the last edge moves down one slot, into the closed last bin.

Identity

Calls
—
Called by
—
sha256:db7302996d18bbe30c61607e1186a2594edd8752a3fa3fda74a26871a812d9fa

The semantic hash of the graph. It changes when the program changes, and never when only its documentation does.