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, ImplicitlyCopyable, ImplicitlyDestructible, Movable, Writable

Methods

__init__

@implicit __init__(out self, other: Slice)

Implicitly convert from a general slice.

Args:

  • other (Slice): The other slice.

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

Construct slice given start, end, and stride values.

Args:

write_to

write_to(self, mut writer: T)

Write StridedSlice string representation to a Writer.

Args:

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

write_repr_to

write_repr_to(self, mut writer: T)

Write StridedSlice debug representation to a Writer.

Args:

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

indices

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

Returns a tuple of 3 integers representing start, end, and step of the slice if applied to a container of given length.

Args:

  • length (Int): The length of the target container.

Returns:

Tuple[Int, Int, Int]: A tuple containing three integers for start, end, and step.