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
TopK_2
struct TopK_2[T: DType, largest: Bool = True]
Tracks the single best (value, index) pair per thread during top-K reductions.
Fields: p: Flattened index of the tracked element. u: Value of the tracked element.
Parametersβ
- βT (
DType): Data type of the tracked values. - βlargest (
Bool): Whether the best value is the maximum (top k) or minimum (bottom k).
Fieldsβ
- βp (
Int): - βu (
Scalar[T]):
Implemented traitsβ
AnyType,
Copyable,
Defaultable,
ImplicitlyCopyable,
ImplicitlyDeletable,
Movable,
RegisterPassable,
TrivialRegisterPassable
Methodsβ
__init__β
def __init__() -> Self
Initializes the tracker with a dead value and a zero index.
insertβ
def insert(mut self, elem: Scalar[T], elem_id: Int)
Replaces the tracked element when the candidate beats the current best.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!