Python function
defaults_like
defaults_like()
max.experimental.tensor.defaults_like(like)
Context manager setting the default dtype and device for tensor creation.
Sets the default data type and device used for tensor creation within the context. All tensors created inside the context block without explicit dtypes or devices will use these parameters.
from max.experimental import tensor
from max.driver import CPU
from max.dtype import DType
x = Tensor.zeros([1], dtype=DType.int32, device=CPU())
with tensor.defaults_like(x):
y = tensor.Tensor.zeros((2, 3)) # int32, cpu
z = tensor.Tensor.zeros((2, 3), dtype=DType.float32) # float32, cpu-
Parameters:
-
like (Tensor | TensorType) – Tensor or tensor type whose dtype and device to use as defaults.
-
Returns:
-
A context manager that sets the default dtype and device.
-
Return type:
-
Generator[None]
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!