fn
einops_reduce_op
→TensorImplPtrint einops_reduce_op(const int & a, const int & pattern, int reduction, const int & axes_lengths)Reduce a tensor over one or more axes specified by an einops pattern.
Axes present on the lhs but absent from the rhs are collapsed using
the given reduction code. axes_lengths is forwarded to the internal
rearrange step that aligns axes before the reduction.
Math
For reduction = sum:
where are the axes dropped between lhs and rhs.
The mean / max / min / prod variants substitute the corresponding monoid.
See Also
einops_rearrange_op, einops_repeat_op, einsum_op
Parameters
aTensorImplPtrInput tensor.
patternstd::stringEinops pattern
"lhs -> rhs" with at least one axis dropped on the rhs.reductionintReduction code:
1=mean, 2=sum, 3=max, 4=min, 5=prod. Must match the Python-side enum.axes_lengthsstd::map<std::string, std::int64_t>Named sizes for axes whose size cannot be inferred from
a.shape.Returns
TensorImplPtrReduced tensor of the shape implied by rhs.
Raises
EinopsPatternErrorIf the pattern is malformed or no axis is dropped (use
rearrange instead).:invalid_argumentIf
reduction is outside the accepted code range.