代码拉取完成,页面将自动刷新
以下映射关系均可参考本文。
PyTorch APIs | MindSpore APIs |
---|---|
torch.ger | mindspore.ops.ger |
torch.Tensor.ger | mindspore.Tensor.ger |
torch.ger(input, vec2, *, out=None)
更多内容详见torch.ger。
mindspore.ops.ger(input, other)
更多内容详见mindspore.ops.ger。
MindSpore此API功能与PyTorch不一致。
PyTorch: 参数 input
和 vec2
支持uint, int和float下的所有数据类型,且可以是不同的数据类型,返回值的数据类型选择输入参数中范围更大的数据类型。
MindSpore: 参数 input
和 other
的数据类型支持float16/32/64,必须是相同的数据类型,返回值的数据类型和输入一致。
功能上无差异。
分类 | 子类 | PyTorch | MindSpore | 差异 |
---|---|---|---|---|
参数 | 参数 1 | input | input | PyTorch支持uint、int和float下的所有数据类型,MindSpore仅支持float16/32/64。 |
参数 2 | vec2 | other | PyTorch支持uint、int和float下的所有数据类型,MindSpore仅支持float16/32/64。 | |
参数 3 | out | - | 详见通用差异参数表 |
输入的数据类型是int,返回值的数据类型也是int。
# PyTorch
import torch
import numpy as np
x1 = np.arange(3)
x2 = np.arange(6)
input = torch.tensor(x1, dtype=torch.int32)
other = torch.tensor(x2, dtype=torch.int32)
output = torch.ger(input, other)
print(output)
# tensor([[ 0, 0, 0, 0, 0, 0],
# [ 0, 1, 2, 3, 4, 5],
# [ 0, 2, 4, 6, 8, 10]], dtype=torch.int32)
print(output.dtype)
# torch.int32
# MindSpore目前无法支持该功能
输入的数据类型是float,返回值的数据类型也是float。
# PyTorch
import torch
import numpy as np
x1 = np.arange(3)
x2 = np.arange(6)
input = torch.tensor(x1, dtype=torch.float32)
other = torch.tensor(x2, dtype=torch.float32)
output = torch.ger(input, other)
print(output)
# tensor([[ 0., 0., 0., 0., 0., 0.],
# [ 0., 1., 2., 3., 4., 5.],
# [ 0., 2., 4., 6., 8., 10.]])
print(output.dtype)
# torch.float32
# MindSpore
import mindspore as ms
import numpy as np
x1 = np.arange(3)
x2 = np.arange(6)
input = ms.Tensor(x1, ms.float32)
other = ms.Tensor(x2, ms.float32)
output = ms.ops.ger(input, other)
print(output)
# [[ 0. 0. 0. 0. 0. 0.]
# [ 0. 1. 2. 3. 4. 5.]
# [ 0. 2. 4. 6. 8. 10.]]
print(output.dtype)
# Float32
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。