Function Differences with torch.randint_like

View Source On Gitee

torch.randint_like

torch.randint_like(input, low=0, high, *, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format)

For more information, see torch.randint_like.

mindspore.ops.randint_like

mindspore.ops.randint_like(input, low, high, *, dtype=None, seed=None)

For more information, see mindspore.ops.randint_like.

Differences

PyTorch:low is optional with default value: 0.

MindSpore:low is not optional and has no default value.

Categories

Subcategories

PyTorch

MindSpore

Differences

Parameter

Parameter 1

input

input

-

Parameter 2

low

low

low has default value 0 in PyTorch, MindSpore does not.

Parameter 3

high

high

-

Parameter 4

dtype

dtype

-

Parameter 5

layout

-

General difference

Parameter 6

device

-

General difference

Parameter 7

requires_grad

-

General difference

Parameter 8

memory_format

-

General difference

Parameter 9

-

seed

General difference

Code Example 1

# PyTorch
import torch

# PyTorch does not need to set the value of low.
x = torch.tensor([[2, 3], [1, 2]], dtype=torch.float32)
y = torch.randint_like(x, 10)
print(tuple(y.shape))
# (2, 2)

# MindSpore
import mindspore

# MindSpore must set the default value of low in PyTorch(0 in this case), as one of the inputs.
x = mindspore.Tensor([[2, 3], [1, 2]], mindspore.float32)
y = mindspore.ops.randint_like(x, 0, 10)
print(y.shape)
# (2, 2)