IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
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).

StridedSlice

struct StridedSlice

Represents a slice expression that has a stride.

This type is used to support different behavior for strided vs unstrided slicing.

Implemented traits​

AnyType, Copyable, Deinitable, ImplicitlyCopyable, Movable, Writable

Methods​

__init__​

@implicit def __init__(out self, other: Slice)

Implicitly convert from a general slice.

Args:

  • ​other (Slice): The other slice.

def __init__(out self, start: Optional[Int], end: Optional[Int], stride: Int, __slice_literal__: NoneType = None)

Constructs a strided slice with the given start, end, and stride.

Args:

  • ​start (Optional[Int]): The starting index of the slice.
  • ​end (Optional[Int]): The end index of the slice.
  • ​stride (Int): The step increment value of the slice.
  • ​slice_literal (NoneType): Enables slice literal syntax.

write_to​

def write_to(self, mut writer: T)

Writes the strided slice's string representation to a writer.

Args:

  • ​writer (T): The object to write to.

write_repr_to​

def write_repr_to(self, mut writer: T)

Writes the strided slice's debug representation to a writer.

Args:

  • ​writer (T): The object to write to.

indices​

def indices(self, length: Int) -> Tuple[Int, Int, Int]

Resolves the slice's bounds against the length of a container.

Bounds resolve with the same rules as Slice.indices().

Args:

  • ​length (Int): The length of the container the slice applies to.

Returns:

Tuple[Int, Int, Int]: A tuple of the resolved start, end, and step.