Fused native lowering for reduction #
A checked reduction allocates only its final output tensor. For each output coordinate, the executable kernel:
- converts the retained output axes to elementary-axis coordinates;
- enumerates assignments of only the axes removed by the reduction;
- reconstructs the corresponding original input coordinate;
- reads that scalar directly from the input tensor's native array.
There are no intermediate reshape, permutation, or reduction tensors. A
generic reducer still receives a Multiset, because its type promises that
the result is independent of coordinate enumeration order, but that multiset
contains exactly one value per removed-axis assignment.
The correctness proof uses the abstract reduction-fiber equivalence only in
the theorem layer. The executable definitions remain computable and operate
directly on native Rep storage.
Every input axis is either retained or assigned by the reduction fiber.
Reconstruct one original input coordinate from its retained output axes and one assignment of all removed axes.
Instances For
Compute the row-major input index selected by one output coordinate and one flat reduced-axis coordinate.
Instances For
Collect exactly the input values belonging to one output coordinate through a flat scalar reader.
The executable enumeration uses the row-major flat index of the removed-axis
shape. This avoids constructing the generic Fintype instance for a
dependent function tuple at every output coordinate.
Instances For
Collect one reduction fiber from an ordinary tensor's flat storage.
Instances For
Fold one reduction fiber without materializing its value multiset.
The traversal is the same row-major enumeration used by reductionValues.
Only the accumulator and the current scalar remain live in the loop.
Instances For
Fold one reduction fiber by reading an ordinary tensor's flat storage.
Instances For
Fold a nonempty reduction fiber from its first row-major value.
Starting from an actual tensor entry avoids inventing sentinel values for
operations such as minimum and maximum. The remaining entries are visited in
the same order as reductionFoldl, so scalar operations with observable
operand order, including IEEE min and max in the presence of NaNs, have a
fully specified result.
Instances For
Fold a nonempty reduction fiber by reading an ordinary tensor's flat storage.
Instances For
Execute a checked reduction with one final output allocation.
The aggregate receives one value for every assignment of the removed axes. Its result type may differ from the input scalar type, and its empty-multiset value determines empty-fiber behavior.
Instances For
Fused native reduction equals the independent coordinate-fiber denotation for every multiset aggregate, checked reduction plan, and input tensor.
The fused reduction enumerates exactly the certified number of fiber values.
Reduce every fiber through one accumulator loop and one scalar finalizer.
The finalizer also receives the certified fiber cardinality. This supports cardinality-dependent reductions such as the arithmetic mean without constructing a multiset merely to count its entries.
Instances For
Reduce every nonempty fiber from its first row-major value.
Unlike reduceNonemptyTensor, this executor does not materialize a multiset.
It is intended for ordered binary operations whose result may depend on
traversal order.
Instances For
The direct accumulator executor implements the independent row-major ordered reduction denotation for every scalar operation.
In particular, this theorem requires no associativity or commutativity and is therefore suitable for IEEE floating-point arithmetic.
The direct first-value executor implements the independent ordered nonempty reduction denotation for every binary scalar operation.
The direct accumulator executor implements any multiset aggregate that factors through an order-independent left fold and the multiset cardinality.
The accumulator executor also implements nonempty aggregates that factor through an order-independent fold and the certified fiber cardinality.
Additive reduction executes as one direct scalar fold per output entry.
Multiplicative reduction executes as one direct scalar fold per output entry.
Boolean disjunction reduction executes without constructing a multiset.
Boolean conjunction reduction executes without constructing a multiset.
Exact mean reduction accumulates the sum directly and divides once by the certified fiber cardinality.
Execute a reduction whose aggregate is defined only for nonempty multisets, using the same single-allocation fused kernel.
Instances For
Fused nonempty reduction equals its independent coordinate-fiber denotation.