For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).
Mojo struct
MinMax
struct MinMax[dtype: DType, W: Int = simd_width_of[dtype]()]
Fused min+max reduction monoid: tracks both min(self, x) and max(self, x) in one state. Cuts the axis walk in half vs running separate ReduceMin + ReduceMax.
Two SIMD fields β min_acc (running minimum) and max_acc (running
maximum). accumulate is one expression per field; reduce
reduces each into its lane 0.
Parametersβ
- βdtype (
DType): The accumulator dtype. - βW (
Int): SIMD width of the lane-wise accumulators. Defaults to the target'ssimd_width_of[dtype].
Fieldsβ
- βmin_acc (
SIMD[dtype, W]): Lane-wise running minimum. Final scalar inmin_acc[0]. - βmax_acc (
SIMD[dtype, W]): Lane-wise running maximum. Final scalar inmax_acc[0].
Implemented traitsβ
AnyType,
Copyable,
ImplicitlyCopyable,
ImplicitlyDeletable,
Movable,
ReduceOp,
RegisterPassable,
TrivialRegisterPassable
comptime membersβ
Singleβ
comptime Single = MinMax[dtype, Int(1)]
widthβ
comptime width = W
Methodsβ
__init__β
def __init__() -> Self
Identity: min_acc = +inf_W, max_acc = -inf_W.
__getitem__β
def __getitem__(self, j: Int) -> Self.Single
Returns lane j as a width-1 monoid.
Returns:
Self.Single
__setitem__β
def __setitem__(mut self, j: Int, s: MinMax[dtype, Int(1)])
Writes width-1 monoid s into lane j.
accumulateβ
def accumulate[val_dtype: DType, w: Int](mut self, val: SIMD[val_dtype, w], idx: SIMD[DType.int64, w] = 0)
Folds a SIMD tile into both accumulators. Each field uses its own identity padding via Self.pad: +inf/MAX for the min field, -inf/MIN for the max field, so padded lanes never affect the result.
Parameters:
Args:
- βval (
SIMD[val_dtype, w]): The SIMD tile to fold. - βidx (
SIMD[DType.int64, w]): Unused (min/max are index-agnostic).
joinβ
def join(mut self, other: Self)
Sequential combine: lane-wise min and max.
Args:
- βother (
Self): The state to combine intoself.
reduceβ
def reduce(self) -> Self.Single
Collapses each field's W lane partials via the reduce_min / reduce_max intrinsics.
Overrides the default lane-fold so the vectorized horizontal min/max are emitted explicitly (a measured CPU win; GPU-neutral).
Returns:
Self.Single: A width-1 MinMax with the min in min_acc[0] and the max
in max_acc[0].
join_parallelβ
def join_parallel[R: Reducer](mut self, reducer: R)
Cross-thread combine via reducer.min / reducer.max, splatting each scalar result across its field's lanes. Runs after reduce.
Parameters:
- βR (
Reducer): The parallel scalar reducer.
Args:
- βreducer (
R): The reducer instance.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!