Function Differences with torch.Tensor.stride

torch.Tensor.stride

torch.Tensor.stride(dim)

For more information, see torch.Tensor.stride.

mindspore.Tensor.strides

mindspore.Tensor.strides()

For more information, see mindspore.Tensor.strides.

Differences

PyTorch: The number of elements that need to be traversed in each dimension, and the return type is a tuple.

MindSpore: The number of bytes that need to be traversed in each dimension, and the return type is a tuple.

Code Example

import mindspore as ms

a = ms.Tensor([[1, 2, 3], [7, 8, 9]])
print(a.strides)
# out:
# (24, 8)

import torch as tc

b = tc.tensor([[1, 2, 3], [7, 8, 9]])
print(b.stride())
# out:
# (3, 1)