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 function
gather
def gather[dtype: DType, indices_type: DType, //, *, axis: Int, target: StringSlice[ImmStaticOrigin] = StringSlice("cpu")](output: TileTensor[dtype, Storage=output.Storage, address_space=output.address_space, linear_idx_type=output.linear_idx_type], input: TileTensor[dtype, Storage=input.Storage, address_space=input.address_space, linear_idx_type=input.linear_idx_type], indices: TileTensor[indices_type, Storage=indices.Storage, address_space=indices.address_space, linear_idx_type=indices.linear_idx_type], *, context: DeviceContext)
Gather operation as defined in https://github.com/onnx/onnx/blob/main/docs/Operators.md#Gather.
Note that this is NOT the same as the default PyTorch gather (which is equivalent to https://github.com/onnx/onnx/blob/main/docs/Operators.md#gatherelements).
Parameters:
- βdtype (
DType): Element type ofinputandoutput. - βindices_type (
DType): Element type of theindicestensor. - βaxis (
Int): Axis along which to gather frominput. - βtarget (
StringSlice[ImmStaticOrigin]): Target backend to execute on, such as "cpu" or "cuda" (defaults to "cpu").
Args:
- βoutput (
TileTensor[dtype, Storage=output.Storage, address_space=output.address_space, linear_idx_type=output.linear_idx_type]): Gathered values, shaped per the ONNX Gather spec. - βinput (
TileTensor[dtype, Storage=input.Storage, address_space=input.address_space, linear_idx_type=input.linear_idx_type]): Source tensor to gather values from. - βindices (
TileTensor[indices_type, Storage=indices.Storage, address_space=indices.address_space, linear_idx_type=indices.linear_idx_type]): Indices to gather alongaxis. - βcontext (
DeviceContext): Device context for execution.
def gather[dtype: DType, indices_type: DType, InputFnType: def[width: Int, rank: Int, element_alignment: Int](IndexList[rank]) -> SIMD[dtype, width] & ImplicitlyCopyable & RegisterPassable, IndicesFnType: def[width: Int, rank: Int](IndexList[rank]) -> SIMD[indices_type, width] & ImplicitlyCopyable & RegisterPassable, OutputFnType: def[width: SIMDLength, rank: Int, element_alignment: Int](IndexList[rank], SIMD[dtype, width]) -> None & ImplicitlyCopyable & RegisterPassable, *, prefetch_fn: OptionalReg[def[input_rank: Int, indices_rank: Int](IndexList[input_rank], IndexList[indices_rank]) capturing thin -> None] = None, target: StringSlice[ImmStaticOrigin] = StringSlice("cpu")](axis: Axis, input_shape: IndexList[element_type=input_shape.element_type], indices_shape: IndexList[element_type=indices_shape.element_type], output_shape: IndexList[element_type=output_shape.element_type], *, input_fn: InputFnType, indices_fn: IndicesFnType, output_fn: OutputFnType, context: DeviceContext) where (eq InputFnType.dtype, dtype) where (eq IndicesFnType.indices_type, indices_type) where (eq OutputFnType.dtype, dtype)
Gather operation as defined in https://github.com/onnx/onnx/blob/main/docs/Operators.md#Gather.
Note that this is NOT the same as the default PyTorch gather (which is equivalent to https://github.com/onnx/onnx/blob/main/docs/Operators.md#gatherelements).
Parameters:
- βdtype (
DType): Element type of the input and output tensors. - βindices_type (
DType): Element type of theindicestensor. - βInputFnType (
def[width: Int, rank: Int, element_alignment: Int](IndexList[rank]) -> SIMD[dtype, width]&ImplicitlyCopyable&RegisterPassable): Function type that loads a SIMD vector from the input tensor at given coordinates. - βIndicesFnType (
def[width: Int, rank: Int](IndexList[rank]) -> SIMD[indices_type, width]&ImplicitlyCopyable&RegisterPassable): Function type that loads a SIMD vector of indices from the indices buffer at given coordinates. - βOutputFnType (
def[width: SIMDLength, rank: Int, element_alignment: Int](IndexList[rank], SIMD[dtype, width]) -> None&ImplicitlyCopyable&RegisterPassable): Function type that stores a SIMD vector into the output tensor at given coordinates. - βprefetch_fn (
OptionalReg[def[input_rank: Int, indices_rank: Int](IndexList[input_rank], IndexList[indices_rank]) capturing thin -> None]): Optional prefetch callback for software index prefetching (defaults to None). - βtarget (
StringSlice[ImmStaticOrigin]): Target backend to execute on, such as "cpu" or "cuda" (defaults to "cpu").
Args:
- βaxis (
Axis): Validated axis along which to gather from the input tensor. - βinput_shape (
IndexList[element_type=input_shape.element_type]): Shape of the input tensor. - βindices_shape (
IndexList[element_type=indices_shape.element_type]): Shape of the indices tensor. - βoutput_shape (
IndexList[element_type=output_shape.element_type]): Shape of the output tensor. - βinput_fn (
InputFnType): Callback that loads values from the input tensor. - βindices_fn (
IndicesFnType): Callback that loads indices from the indices tensor. - βoutput_fn (
OutputFnType): Callback that stores values into the output tensor. - βcontext (
DeviceContext): Device context for execution.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!