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
Layoutstruct 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). LayoutTensoris a flexible tensor type that combines aLayoutand a pointer to data.The
IntTuplestruct is a hierarchical tuple type, where each element of the tuple can either be an integral value or a nestedIntTuple. TheIntTupletype is used extensively for defining and indexing layouts and layout tensors.