335 Star 1.5K Fork 862

MindSpore / docs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ger.md 3.41 KB
一键复制 编辑 原始数据 按行查看 历史
luojianing 提交于 2023-07-21 15:16 . replace target=blank

Differences with torch.ger

View Source On Gitee

The following mapping relationships can be found in this file.

PyTorch APIs MindSpore APIs
torch.ger mindspore.ops.ger
torch.Tensor.ger mindspore.Tensor.ger

torch.ger

torch.ger(input, vec2, *, out=None)

For more information, see torch.ger.

mindspore.ops.ger

mindspore.ops.ger(input, other)

For more information, see mindspore.ops.ger.

Differences

API function of MindSpore is not consistent with that of PyTorch.

PyTorch: The parameters input and vec2 support all data types of uint, int and float, and can be different data types. The data type of the return value selects a larger range of data types in the input parameter.

MindSpore: The data types of parameters input and other support float16/32/64, and must be the same data type. The data type of the return value is the same as the input.

Categories Subcategories PyTorch MindSpore Differences
Parameters Parameter 1 input input PyTorch supports all data types of uint, int and float, and MindSpore only supports float16/32/64
Parameter 2 vec2 other PyTorch supports all data types of uint, int and float, and MindSpore only supports float16/32/64
Parameter 3 out - For details, see General Difference Parameter Table

Code Example 1

The data type of the input is int, and the data type of the return value is also 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)
print(output.dtype)
# tensor([[ 0,  0,  0,  0,  0,  0],
#         [ 0,  1,  2,  3,  4,  5],
#         [ 0,  2,  4,  6,  8, 10]], dtype=torch.int32)
# torch.int32
# MindSpore doesn't support this feature currently.

Code Example 2

The data type of the input is float, and the data type of the return value is also 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)
print(output.dtype)
# tensor([[ 0.,  0.,  0.,  0.,  0.,  0.],
#         [ 0.,  1.,  2.,  3.,  4.,  5.],
#         [ 0.,  2.,  4.,  6.,  8., 10.]])
# 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)
print(output.dtype)
# [[ 0.  0.  0.  0.  0.  0.]
#  [ 0.  1.  2.  3.  4.  5.]
#  [ 0.  2.  4.  6.  8. 10.]]
# Float32
1
https://gitee.com/mindspore/docs.git
git@gitee.com:mindspore/docs.git
mindspore
docs
docs
r2.0

搜索帮助

53164aa7 5694891 3bd8fe86 5694891