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