Differences with torch.range
torch.range
torch.range(start=0,
end,
step=1,
*,
out=None,
dtype=None,
layout=torch.strided,
device=None,
requires_grad=False
)
For more information, see torch.range.
mindspore.ops.range
mindspore.ops.range(start,
end,
step
)
For more information, see mindspore.ops.range.
Differences
API function of MindSpore is consistent with that of PyTorch.
MindSpore: The dtype of output Tensor is the same as input Tensor.
PyTorch: the dtype of output Tensor is determined by the parameter dtype
.
Categories |
Subcategories |
PyTorch |
MindSpore |
Difference |
---|---|---|---|---|
input |
input 1 |
start |
start |
The data type of |
input 2 |
end |
end |
The data type of |
|
input 3 |
step |
step |
The data type of |
|
input 4 |
out |
- |
For details, see General Difference Parameter Table |
|
input 5 |
dtype |
- |
The dtype of output Tensor in MindSpore is the same as input Tensor,while the dtype of output Tensor in PyTorch is determined by the parameter |
|
input 6 |
layout |
- |
For details, see General Difference Parameter Table |
|
input 7 |
device |
- |
For details, see General Difference Parameter Table |
|
input 8 |
requires_grad |
- |
For details, see General Difference Parameter Table |
Code Example
# PyTorch
import torch
output = torch.range(0, 10, 4, dtype=torch.float32)
print(output)
# tensor([0., 4., 8.])
# MindSpore
import mindspore as ms
from mindspore import Tensor, ops
start = Tensor(0, ms.float32)
limit = Tensor(10, ms.float32)
delta = Tensor(4, ms.float32)
output = ops.range(start, limit, delta)
print(output)
# [0. 4. 8.]