比较与torch.Tensor.repeat的差异
torch.Tensor.repeat
torch.Tensor.repeat(*sizes)
更多内容详见torch.Tensor.repeat。
mindspore.Tensor.tile
mindspore.Tensor.tile(multiples)
更多内容详见mindspore.Tensor.tile。
差异对比
接口 mindspore.Tensor.tile 的使用方式和 torch.Tensor.repeat 基本一致。
| 分类 | 子类 | PyTorch | MindSpore | 差异 | 
|---|---|---|---|---|
| 参数 | 参数 1 | *sizes | multiples | PyTorch的参数类型是 torch.Size 或 int;MindSpore的参数类型必须是 tuple。 | 
代码示例
# PyTorch
import torch
input = torch.tensor([[1, 2], [3, 4]], dtype=torch.float32)
output = input.repeat(16, 1)
print(output.shape)
# torch.Size([32, 2])
# MindSpore
import mindspore
x = mindspore.Tensor([[1, 2], [3, 4]], dtype=mindspore.float32)
output = x.tile((16, 1))
print(output.shape)
# (32, 2)