For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /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,
Deinitable,
ImplicitlyCopyable,
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.