torch.can_cast

torch.can_cast(from_, to) bool 返回一个布尔值,表示是否可以从类型 from_ 转换到类型 to

根据 PyTorch 中的类型转换规则(如类型提升文档中所述),确定是否允许进行类型转换。

参数

示例:

>>> torch.can_cast(torch.double, torch.float)
True
>>> torch.can_cast(torch.float, torch.int)
False
本页目录