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
ArgMin
struct ArgMin[dtype: DType, W: Int = simd_width_of[dtype]()]
Argmin reduction monoid: mirrors ArgMax with </ge comparison (see ArgMax for the algorithm + design notes).
Parametersβ
- βdtype (
DType): The value dtype. - βW (
Int): SIMD width of the per-lane accumulator. Same GPU/CPU default rationale asArgMax.
Fieldsβ
- βbest (
Scalar[dtype]): Final scalar best value. - βbest_idx (
Int): Final scalar best index. - βacc_values (
SIMD[dtype, W]): Per-lane running min during SIMD-wide tile accumulation. - βacc_indices (
SIMD[DType.int64, W]): Per-lane axis indices corresponding toacc_values.
Implemented traitsβ
AnyType,
Copyable,
ImplicitlyCopyable,
ImplicitlyDeletable,
Movable,
ReduceOp,
RegisterPassable,
TrivialRegisterPassable
comptime membersβ
Singleβ
comptime Single = ArgMin[dtype, Int(1)]
widthβ
comptime width = W
Methodsβ
__init__β
def __init__() -> Self
Identity: best = +inf/MAX, best_idx = Int.MAX, SIMD accs at the same identity.
__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: ArgMin[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 via lane-wise compare-and-select. Mirrors ArgMax.accumulate with the >= rule: padded value lanes +inf/MAX, padded index lanes Int64.MAX, so they always lose to any real candidate. ge (not gt) preserves the lower-idx tie-break. idx is the scaffolder-built per-lane axis-position vector β the monoid never adds an iota.
Parameters:
Args:
- βval (
SIMD[val_dtype, w]): The SIMD tile to fold. - βidx (
SIMD[DType.int64, w]): Per-lane axis positions ofval's lanes.
joinβ
def join(mut self, other: Self)
Sequential combine. Element-wise SIMD merge of the acc; scalar merge of the (best, best_idx) tail. Tie-symmetric: when values tie, the smaller index wins. Mirrors ArgMax.join with < instead of >.
Args:
- βother (
Self): The state to combine intoself.
reduceβ
def reduce(self) -> Self.Single
SIMD-tree collapse (faster than the default lane-fold for a value+index select): min value in lane 0, lowest index among the min lanes. join_parallel folds lane 0 into (best, best_idx).
Returns:
Self.Single
join_parallelβ
def join_parallel[R: Reducer](mut self, reducer: R)
Folds the within-thread acc at lane 0 into the scalar (best, best_idx), resets the SIMD acc, combines across participants via reducer.generic, and leaves the winning index in acc_indices[0]. Mirrors ArgMax.join_parallel with the < tie-break. Works at any W (collapse pre-reduces to lane 0 when W > 1).
Parameters:
- βR (
Reducer): The parallel 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!