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
normalize_neg_index
def normalize_neg_index(idx: Int, dim_size: Int) -> Int
Indices passed to gather and scatter ops may be negative. This performs a normalization so that they can be used to index into a buffer.
Returns val + dim if val < 0 else val
Returns:
Int
Raises:
If the index is out of range [-dim_size, dim_size).
def normalize_neg_index[dtype: DType, width: SIMDLength, out_type: DType = DType.int](idx: SIMD[dtype, width], dim_size: Int) -> SIMD[out_type, width]
Indices passed to gather and scatter ops may be negative. This performs a normalization so that they can be used to index into a buffer.
Returns val + dim if val < 0 else val
Parameters:
- βdtype (
DType): Integral element type of the input index vector. - βwidth (
SIMDLength): SIMD vector width of the input index vector. - βout_type (
DType): Element type of the normalized output vector (defaults toDType.int).
Args:
- βidx (
SIMD[dtype, width]): Vector of indices to normalize; values may be negative. - βdim_size (
Int): Size of the dimension being indexed; valid indices are in[-dim_size, dim_size).
Returns:
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!