Differences with torch.linspace
torch.linspace
torch.linspace(start,
end,
steps,
*,
out=None,
dtype=None,
layout=torch.strided,
device=None,
requires_grad=False
)
For more information, see torch.linspace.
mindspore.ops.linspace
mindspore.ops.linspace(start,
end,
steps
)
For more information, see mindspore.ops.linspace.
Differences
API function of MindSpore is consistent with that of PyTorch.
MindSpore: The dtype of output Tensor is the same as the parameter start
.
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 |
steps |
steps |
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 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.linspace(1, 10, 5, dtype=torch.float32)
print(output)
# tensor([1.0000, 3.2500, 5.5000, 7.7500, 10.0000])
# MindSpore
import mindspore as ms
from mindspore import Tensor, ops
start = Tensor(1, ms.float32)
limit = Tensor(10, ms.float32)
delta = Tensor(5, ms.int32)
output = ops.linspace(start, limit, delta)
print(output)
# [1. 3.25 5.5 7.75 10.]