The Mojo ManualXYZ Homework Edition

⇩ Download ▾

Chapter 9: Layouts and LayoutTensor

Mojo's layout package provides a number of APIs for working with dense multidimensional arrays, which simplify writing algorithms for handling linear algebra.

This package includes the following main types:

  • The Layout struct describes an arrangement of data in memory. A layout is a function that maps a set of logical coordinates (like (x, y) in a two-dimensional array) to a linear index value. Layouts can be hierarchical (for example, representing a 2D matrix that's further subdivided into tiles).
  • LayoutTensor is a flexible tensor type that combines a Layout and a pointer to data.
  • The IntTuple struct is a hierarchical tuple type, where each element of the tuple can either be an integral value or a nested IntTuple. The IntTuple type is used extensively for defining and indexing layouts and layout tensors.

Adapted from the Mojo Manual and the MAX GPU programming guides, part of the Modular Platform repository (github.com/modular/modular), Copyright (c) Modular Inc., licensed under the Apache License v2.0 with LLVM Exceptions. Changes were made: reformatted as an accessible XYZ web edition with build-verified example outputs. Mojo and MAX are trademarks of Modular Inc.; this edition is not affiliated with or endorsed by Modular. License: Apache-2.0 WITH LLVM-exception.

These eBooks are a prerelease and are not yet certified conformant with WCAG 2.1 AA or any other accessibility standard. Every page is built against an automated accessibility gate, and our target for the published editions is WCAG 2.2 Level AA. If something is unusable, please tell us.