Shortcuts

torch.result_type

torch.result_type(tensor1, tensor2) 数据类型

返回对提供的输入张量执行算术运算后将得到的结果的torch.dtype。有关类型提升逻辑的更多信息,请参阅类型提升文档

Parameters
  • 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