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

Mojo struct

ImageData

struct ImageData[LayoutType: TensorLayout, //, dtype: DType, static_image_layout: Image2DLayout, origin: MutOrigin]

Utility class that generalizes conv2d data and filter tensor with a given data layout.

Fields​

  • ​data (TileTensor[dtype, LayoutType, origin]):
  • ​dynamic_image_layout (Image2DLayout):

Implemented traits​

AnyType, Copyable, ImplicitlyCopyable, ImplicitlyDeletable, Movable, RegisterPassable, TrivialRegisterPassable

Methods​

__init__​

def __init__(data: TileTensor[dtype, LayoutType, origin], _layout: Image2DLayout) -> Self

Construct of an image data instance with dynamic layout param.

Args:

def __init__(data: TileTensor[dtype, LayoutType, origin]) -> Self

__getitem__​

def __getitem__(self, n: Int, c: Int, h: Int, w: Int) -> Scalar[dtype]

Reads the underlying data buffer based on the tensor index and under- lying data layout.

Args:

  • ​n (Int): Index on the batch dimension.
  • ​c (Int): Index on the channel dimension.
  • ​h (Int): Index on the height dimension.
  • ​w (Int): Index on the width dimension.

Returns:

Scalar[dtype]: The value stored at the given index position.

__setitem__​

def __setitem__(self, n: Int, c: Int, h: Int, w: Int, value: Scalar[dtype])

Writes the underlying data buffer based on the tensor index and under- lying data layout.

Args:

  • ​n (Int): Index on the batch dimension.
  • ​c (Int): Index on the channel dimension.
  • ​h (Int): Index on the height dimension.
  • ​w (Int): Index on the width dimension.
  • ​value (Scalar[dtype]): The value to store at the given index position.

to_static_layout​

def to_static_layout[new_static_image_layout: Image2DLayout](self) -> ImageData[dtype, new_static_image_layout, origin]

Conversion utility from a fully dynamic data structure, e.g. from c shim to one with compile-time known data layout.

Returns:

ImageData[dtype, new_static_image_layout, origin]: The image data with static data layout.

get_image_layout​

def get_image_layout(self) -> Image2DLayout

The getter function of the underlying data layout, resolving from either statically or dynamically provided information.

Returns:

Image2DLayout: The resolved data layout tag for this image instance.

get_flat_index​

def get_flat_index(self, n: Int, c: Int, h: Int, w: Int) -> Int

Converts the dimension index to the flat index of the underlying data based on the tensor layout.

Args:

  • ​n (Int): Index on the batch dimension.
  • ​c (Int): Index on the channel dimension.
  • ​h (Int): Index on the height dimension.
  • ​w (Int): Index on the width dimension.

Returns:

Int: An integer containing the index based on the underlying data layout.

get_tuple_index​

def get_tuple_index(self, idx: Int) -> IndexList[Int(4)]

Converts the flat index to the dimension index of the underlying data based on the tensor layout.

Args:

  • ​idx (Int): Flat index.

Returns:

IndexList[Int(4)]: A IndexList containing the index in NCHW order.

num_elements​

def num_elements(self) -> Int

Returns:

Int