Reductions #
Fold, sum/product/mean/variance, axis reductions, and last-axis reductions.
Reductions #
Left fold over all tensor elements.
Instances For
Right fold over all tensor elements.
Instances For
Output shape after summing along axis (drops that dimension).
Instances For
simp lemma: dropping axis 1 from a 2D (nQ+1)×(nK+1) shape yields (nQ+1).
simp lemma: dropping axis 1 from a 2D nQ×nK shape yields nQ.
simp lemma: dropping axis 3 from a 4D b×h×w×c shape yields b×h×w.
simp lemma: dropping axis 0 from a positive .dim (n+1) s yields s.
simp lemma: dropping axis k+1 recurses into the tail shape.
simp lemma: dropping axis 0 from a 2D (kH+1)×(kW+1) yields (kW+1).
simp lemma: dropping axis 0 from .dim n inner yields inner (even when n=0).
Reflexive broadcast proof (s can broadcast to itself).
Instances For
Build a broadcast proof from the reduced shape back to the original shape.
We use this when a backward pass computes something in the reduced shape (e.g. a mean/variance) and we need to broadcast it back to match the original tensor shape.
Instances For
Reduce a tensor of shape (n, innerShape) by applying f across the first axis.
This is the basic “reduce over axis 0” primitive that we reuse to implement broadcast-adjoints and multi-axis reducers.
Instances For
Reduce a gradient from a broadcast target shape back to the original input shape.
This is the adjoint of broadcastTo for sum-reduction: broadcast duplicates values, so the
backward pass sums contributions across broadcasted dimensions.
PyTorch analogy: this is the logic behind "sum over broadcasted dimensions" that happens in
autograd for expand + elementwise ops.
Adjoint of broadcastTo under sum-reduction: collapse broadcasted dimensions by summing.
Instances For
Generic reduction along a (provably reducible) axis.
reduce_dim f axis x applies f to the slices along axis, and returns a tensor whose shape is
shape_after_sum s axis (i.e. that axis is dropped).
Instances For
Sum-reduction along a given axis.
Instances For
Sum-reduction along axis, with axis validity inferred via valid_axis_inst.
Instances For
Product-reduction along a given axis.
Instances For
Product-reduction along axis when you already have a valid_axis proof.
Instances For
Mean-reduction along a given axis.
Instances For
Mean-reduction along axis, with axis validity provided as a typeclass argument.
Instances For
Sum of squares reduced along an axis (helper for variance).
Instances For
Variance-reduction along a given axis (population variance, divides by n).
Instances For
Variance-reduction along axis, with axis validity provided as a typeclass argument.
Instances For
Min-reduction along a given axis.
Instances For
Max-reduction along a given axis.
Instances For
Max-reduction along axis, with axis validity inferred via valid_axis_inst.
Instances For
Reduce along the last axis of s (i.e. axis rank s - 1).
Instances For
Like reduce_last_dim, but infers axis validity via valid_axis_inst.
Instances For
Mean-reduce along the last axis.
Instances For
Sum-reduce along the last axis of a 2D tensor (seqLen, embedDim).
Instances For
Product-reduce along the last axis of a 2D tensor (seqLen, embedDim).
Instances For
Max-reduce along the last axis.
Instances For
Min-reduce along the last axis.
Instances For
Mean-reduce along the last axis (with axis validity as a typeclass argument).
Instances For
Mean-reduce along the last axis, specialized for proofs that assume well-formedness.
Instances For
Sum-reduce along the last axis (with axis validity inferred via valid_axis_inst).