IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /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. /get-started.md).

Mojo struct

ComposedLayout

struct ComposedLayout[offset: Optional[Int] = Int(0)]

Layout composed of a Layout and a Swizzle applied sequentially.

Combines a base layout with a swizzle. The output of the layout is input to the swizzle, with an optional offset in between.

Parameters​

  • ​offset (Optional[Int]): Optional offset between layouts (default: 0).

Fields​

  • ​layout_a (Layout): The base layout to apply.
  • ​layout_b (Swizzle): The swizzle to apply.

Implemented traits​

AnyType, Copyable, ImplicitlyDeletable, Movable

comptime members​

has_shape​

comptime has_shape = True

True because the base layout always has a shape.

Methods​

__init__​

def __init__(out self, var layout_a: Layout, layout_b: Swizzle)

Initialize ComposedLayout with a layout and swizzle.

Args:

  • ​layout_a (Layout): The base layout.
  • ​layout_b (Swizzle): The swizzle.

def __init__(out self, *, copy: Self)

Copy constructor for ComposedLayout.

Args:

  • ​copy (Self): The ComposedLayout to copy from.

__call__​

def __call__(self, idx: IntTuple) -> Int

Apply composed layout to an index.

Applies the layout, then adds offset, then applies the swizzle.

Args:

  • ​idx (IntTuple): The index to transform.

Returns:

Int: The transformed index.

def __call__(self, idx: IntTuple, offset_val: Int) -> Int

Apply composed layout with runtime offset.

Applies the layout, then adds runtime offset_val, then the swizzle. Static offset must not be set when using runtime offset.

Args:

  • ​idx (IntTuple): The index to transform.
  • ​offset_val (Int): Runtime offset to apply.

Returns:

Int: The transformed index.

size​

def size(self) -> Int

Get the size of the composed layout.

Returns the size of the base layout.

Returns:

Int: The size of the base layout.

cosize​

def cosize(self) -> Int

Get the cosize of the composed layout.

Returns the cosize of the swizzle.

Returns:

Int: The cosize of the swizzle.

Was this page helpful?