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

Mojo function

max

def max[axis: Int](inp: LayoutTensor[address_space=inp.address_space, element_layout=inp.element_layout, layout_int_type=inp.layout_int_type, linear_idx_type=inp.linear_idx_type, masked=inp.masked, alignment=inp.alignment], outp: LayoutTensor[address_space=outp.address_space, element_layout=outp.element_layout, layout_int_type=outp.layout_int_type, linear_idx_type=outp.linear_idx_type, masked=outp.masked, alignment=outp.alignment])

Computes maximum reduction along specified axis.

Reduces the input tensor by taking maximum elements along the specified axis and stores the result in the output tensor.

Constraints:

All tensors must have statically known shapes. outp.rank must equal inp.rank - 1. Non-reduction dimensions must match between inp and outp. Currently only supports rank-2 inputs.

Parameters:

  • ​axis (Int): The axis to take maximum along.

Args:

def max[axis: Int](inp: LayoutTensor[address_space=inp.address_space, element_layout=inp.element_layout, layout_int_type=inp.layout_int_type, linear_idx_type=inp.linear_idx_type, masked=inp.masked, alignment=inp.alignment]) -> LayoutTensor[inp.dtype, _reduce_res_row_major_shape(axis, inp.layout), MutAnyOrigin, address_space=inp.address_space, element_layout=inp.element_layout, layout_int_type=inp.layout_int_type, linear_idx_type=inp.linear_idx_type]

Computes maximum reduction along specified axis, returning a new tensor.

Reduces the input tensor by taking maximum elements along the specified axis and returns a new tensor with the results.

Constraints:

All tensors must have statically known shapes. Result will have rank equal to inp.rank - 1. Non-reduction dimensions in the result match the input. Currently only supports rank-2 inputs.

Parameters:

  • ​axis (Int): The axis to take maximum along.

Args:

Returns:

LayoutTensor[inp.dtype, _reduce_res_row_major_shape(axis, inp.layout), MutAnyOrigin, address_space=inp.address_space, element_layout=inp.element_layout, layout_int_type=inp.layout_int_type, linear_idx_type=inp.linear_idx_type]: A new tensor containing the maximum values along the specified axis.

def max[dtype: DType, layout: Layout](x: LayoutTensor[dtype, layout, address_space=x.address_space, element_layout=x.element_layout, layout_int_type=x.layout_int_type, linear_idx_type=x.linear_idx_type, masked=x.masked, alignment=x.alignment], y: LayoutTensor[dtype, layout, address_space=y.address_space, element_layout=y.element_layout, layout_int_type=y.layout_int_type, linear_idx_type=y.linear_idx_type, masked=y.masked, alignment=y.alignment]) -> LayoutTensor[dtype, layout, x.origin, address_space=x.address_space, element_layout=x.element_layout, layout_int_type=x.layout_int_type, linear_idx_type=x.linear_idx_type, masked=x.masked, alignment=x.alignment].MutableAnyType

Computes element-wise maximum of two tensors.

Returns a new tensor containing the element-wise maximum between the input tensors.

Constraints:

Input tensors must have statically known shapes and matching layouts.

Parameters:

  • ​dtype (DType): The data type of the input tensors.
  • ​layout (Layout): The layout of the input tensors.

Args:

Returns:

LayoutTensor[dtype, layout, x.origin, address_space=x.address_space, element_layout=x.element_layout, layout_int_type=x.layout_int_type, linear_idx_type=x.linear_idx_type, masked=x.masked, alignment=x.alignment].MutableAnyType: A new tensor containing the element-wise maximum.

Was this page helpful?