Login
📚 The Mojo Manual
Chapters ▾

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.