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.
Adapted from the Mojo Manual, 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 is a trademark of Modular Inc.; this edition is not affiliated with or endorsed by Modular. License: Apache-2.0 WITH LLVM-exception.