IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
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: Int, 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

Returns:

SIMD[out_type, width]