Function Differences with torch.all
The following mapping relationships can be found in this file.
PyTorch APIs |
MindSpore APIs |
---|---|
torch.all |
mindspore.ops.all |
torch.Tensor.all |
mindspore.Tensor.all |
torch.all
torch.all(input, dim, keepdim=False, *, out=None) -> Tensor
For more information, see torch.all.
mindspore.ops.all
mindspore.ops.all(x, axis=(), keep_dims=False) -> Tensor
For more information, see mindspore.ops.all.
Differences
PyTorch: Perform logic AND on the elements of input
according to the specified dim
. keepdim
controls whether the output and input have the same dimension. out
can fetch the output.
MindSpore: Perform logic AND on the elements of x
according to the specified axis
. The keep_dims
has the same function as PyTorch, and MindSpore does not have the out
parameter. MindSpore has a default value for axis
, and performs the logical AND on all elements of x
if axis
is the default.
Categories |
Subcategories |
PyTorch |
MindSpore |
Differences |
---|---|---|---|---|
Parameters |
Parameter 1 |
input |
x |
Same function, different parameter names |
Parameter 2 |
dim |
axis |
PyTorch must pass |
|
Parameter 3 |
keepdim |
keep_dims |
Same function, different parameter names |
|
Parameter 4 |
out |
- |
PyTorch |
Code Example
# PyTorch
import torch
input = torch.tensor([[False, True, False, True], [False, True, False, False]])
print(torch.all(input, dim=0, keepdim=True))
# tensor([[False, True, False, False]])
# MindSpore
import mindspore
x = mindspore.Tensor([[False, True, False, True], [False, True, False, False]])
print(mindspore.ops.all(x, axis=0, keep_dims=True))
# [[False True False False]]