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).

Python function

default_dtype

default_dtype()

max.experimental.tensor.default_dtype(dtype)

source

Context manager for setting the default dtype for tensor creation.

Sets the default data type used for tensor creation within the context. All tensors created inside the context block without an explicit dtype parameter will use this data type.

from max.experimental import tensor
from max.dtype import DType

with tensor.default_dtype(DType.int32):
    x = tensor.Tensor.ones((2, 3))  # Created with int32
    y = tensor.Tensor.zeros((2, 3))  # Also int32

Parameters:

dtype (DType) – The data type to use as the default for tensor creation within the context.

Returns:

A context manager that sets the default dtype.

Return type:

AbstractContextManager[DType]