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 function
mean
def mean[dtype: DType, input_fn: def[width: Int, rank: Int](IndexList[rank]) capturing thin -> SIMD[dtype, width], output_fn: def[width: SIMDLength, rank: Int](IndexList[rank], SIMD[dtype, width]) capturing thin -> None, /, target: StringSlice[ImmStaticOrigin] = StringSlice("cpu"), *, reduce_dim: Int](input_shape: Coord, output_shape: Coord[input_shape.element_types], context: Optional[DeviceContext] = None)
Computes the mean across the input and output shape.
This performs the mean computation on the domain specified by input_shape,
loading the inputs using the input_fn. The results' domain is
output_shape which are stored using the output_fn.
Parameters:
- βdtype (
DType): The dtype of the input and output. - βinput_fn (
def[width: Int, rank: Int](IndexList[rank]) capturing thin -> SIMD[dtype, width]): The function to load the input. - βoutput_fn (
def[width: SIMDLength, rank: Int](IndexList[rank], SIMD[dtype, width]) capturing thin -> None): The function to store the output. - βtarget (
StringSlice[ImmStaticOrigin]): The target to run on. - βreduce_dim (
Int): The axis to perform the mean on.
Args:
- βinput_shape (
Coord): The input shape. - βoutput_shape (
Coord[input_shape.element_types]): The output shape. - βcontext (
Optional[DeviceContext]): The pointer to DeviceContext.
Raises:
If the operation fails.
def mean[dtype: DType](src: Span[Scalar[dtype]]) -> Scalar[dtype]
Computes the mean value of the elements in a buffer.
Parameters:
- βdtype (
DType): The dtype of the input.
Args:
- βsrc (
Span[Scalar[dtype]]): The buffer of elements for which the mean is computed.
Returns:
Scalar[dtype]: The mean value of the elements in the given buffer.
Raises:
If the operation fails.
def mean[dtype: DType, input_fn_1d: def[dtype_: DType, width: Int](idx: Int) capturing thin -> SIMD[dtype_, width]](length: Int) -> Scalar[dtype]
Computes the arithmetic mean of values generated by a function.
Parameters:
- βdtype (
DType): The data type of the elements. - βinput_fn_1d (
def[dtype_: DType, width: Int](idx: Int) capturing thin -> SIMD[dtype_, width]): A function that generates SIMD values at each index.
Args:
- βlength (
Int): The number of elements to average.
Returns:
Scalar[dtype]: The mean value. For integral types, uses integer division.
Raises:
To comply with how generators are used in this module.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!