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