Differences with torch.randint_like
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 an optional input, and the default value is 0.
MindSpore: low
is a mandatory input with no default value.
Categories |
Subcategories |
PyTorch |
MindSpore |
Difference |
---|---|---|---|---|
Parameters |
Parameter 1 |
input |
input |
No difference |
Parameter 2 |
low |
low |
|
|
Parameter 3 |
high |
high |
No difference |
|
Parameter 4 |
dtype |
dtype |
No difference |
|
Parameter 5 |
layout |
- |
Common differences |
|
Parameter 6 |
device |
- |
Common differences |
|
Parameter 7 |
requires_grad |
- |
Common differences |
|
Parameter 8 |
memory_format |
- |
Common differences |
|
Parameter 9 |
- |
seed |
Common differences |
Code Example
# PyTorch
import torch
# PyTorch does not need to input the value of low, which is equivalent to low=0 in MindSpore.
x = torch.tensor([[2, 3], [1, 2]], dtype=torch.int32)
y = torch.randint_like(x, 10)
print(tuple(y.shape))
# (2, 2)
# MindSpore
import mindspore
# MindSpore must take the default value of low in the torch (0 in this case) and pass it in as input.
x = mindspore.Tensor([[2, 3], [1, 2]], mindspore.int32)
x = mindspore.ops.randint_like(x, 0, 10)
print(x.shape)
# (2, 2)