torch / torch
torch.set_default_dtype¶
-
torch.
set_default_dtype
(d)[source]¶ Sets the default floating point dtype to
d
. This dtype is:The inferred dtype for python floats in
torch.tensor()
.Used to infer dtype for python complex numbers. The default complex dtype is set to
torch.complex128
if default floating point dtype istorch.float64
, otherwise it’s set totorch.complex64
The default floating point dtype is initially
torch.float32
.- Parameters
d (
torch.dtype
) – the floating point dtype to make the default
Example
>>> # initial default for floating point is torch.float32 >>> torch.tensor([1.2, 3]).dtype torch.float32 >>> # initial default for floating point is torch.complex64 >>> torch.tensor([1.2, 3j]).dtype torch.complex64 >>> torch.set_default_dtype(torch.float64) >>> torch.tensor([1.2, 3]).dtype # a new floating point tensor torch.float64 >>> torch.tensor([1.2, 3j]).dtype # a new complex tensor torch.complex128
此页内容是否对您有帮助