torch.can_cast¶
- torch.can_cast(from_, to) bool ¶
確定是否允許在類型提升文件中描述的 PyTorch 轉換規則下進行類型轉換。
- 參數
from_ (dtype) – 原始的
torch.dtype
。to (dtype) – 目標
torch.dtype
。
範例
>>> torch.can_cast(torch.double, torch.float) True >>> torch.can_cast(torch.float, torch.int) False