For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
check_slice_bounds
def check_slice_bounds[cpu_default: Bool = True](slice: ContiguousSlice, len: Int, location: OptionalReg[SourceLocation] = None) -> Tuple[Int, Int]
Bounds check for slice indexing, which is on by default for CPU, and off by default for GPU.
Resolves slice's optional start/end against len and aborts if the
resolved start or end index is out of bounds, or if start is greater than
end. ContiguousSlice does not support negative (from-the-end) indices,
so a negative start or end is always out of bounds.
Parameters:
- cpu_default (
Bool): If the bounds check is on by default on CPU.
Args:
- slice (
ContiguousSlice): The slice to resolve and bounds check. - len (
Int): The size of the container. - location (
OptionalReg[SourceLocation]):SourceLocationshown on assert error. Defaults to showing the callsite two levels of function calls above this one. So ifcheck_slice_boundsis called inside a__getitem__method, it will show the source location where the incorrect slice was provided.
Returns:
Tuple[Int, Int]: The slice's resolved (start, end).