torch.result_type¶
- torch.result_type(tensor1, tensor2) → dtype
返回对提供的输入张量执行算术运算后得到的
torch.dtype
。有关类型提升逻辑的更多信息,请参阅类型提升文档。- 参数:
tensor1(张量或数字)- 输入张量或数字
tensor2(张量或数字)- 输入张量或数字
示例:
>>> torch.result_type(torch.tensor([1, 2], dtype=torch.int), 1.0) torch.float32 >>> torch.result_type(torch.tensor([1, 2], dtype=torch.uint8), torch.tensor(1)) torch.uint8