The following mapping relationships can be found in this file.
PyTorch APIs | MindSpore APIs |
---|---|
torch.svd | mindspore.ops.svd |
torch.Tensor.svd | mindspore.Tensor.svd |
torch.svd(input, some=True, compute_uv=True, *, out=None)
For more information, see torch.svd.
mindspore.ops.svd(input, full_matrices=False, compute_uv=True)
For more information, see mindspore.ops.svd.
API function of MindSpore is not consistent with that of PyTorch.
PyTorch:
If some
is True, the method returns the reduced singular value decomposition.
There are always three output values, and the order of the output values is u, s, v.
If compute_uv
is False, the returned u and v will be zero-filled matrices.
MindSpore:
If full_matrices
is False, the method returns the reduced singular value decomposition.
If compute_uv
is False, there is only one output value s.
If compute_uv
is True, there are three output values in the order s, u, v.
torch.svd()
has been deprecated in PyTorch 1.8.0 and later, and alternative apitorch.linalg.svd()
is recommended, which has the same parameterfull_matrices
asmindspore.ops.svd
.
Categories | Subcategories | PyTorch | MindSpore | Differences |
---|---|---|---|---|
Parameters | Parameter 1 | input | input | Consistent |
Parameter 2 | some | full_matrices | To return the reduced singular value decomposition, MindSpore should set full_matrices to False, and PyTorch should set some to True |
|
Parameter 3 | compute_uv | compute_uv | If compute_uv is True, the order of output values of MindSpore is s, u, v, and the order of PyTorch is u, s, v |
|
Parameter 4 | out | - | For details, see General Difference Parameter Table |
When
compute_uv
is False, PyTorch has three output values.
# PyTorch
import torch
input = torch.tensor([[1, 2], [-4, -5], [2, 1]], dtype=torch.float32)
u, s, v = torch.svd(input, some=False, compute_uv=False)
print(s)
print(u)
print(v)
# tensor([7.0653, 1.0401])
# tensor([[0., 0., 0.],
# [0., 0., 0.],
# [0., 0., 0.]])
# tensor([[0., 0.],
# [0., 0.]])
# MindSpore doesn't support this feature currently.
When
compute_uv
is True, the order of output values is inconsistent. The output values of singular value decomposition are not unique.
# PyTorch
import torch
input = torch.tensor([[1, 2], [-4, -5], [2, 1]], dtype=torch.float32)
u, s, v = torch.svd(input, some=False, compute_uv=True)
print(s)
print(u)
print(v)
# tensor([7.0653, 1.0401])
# tensor([[-0.3082, -0.4882, 0.8165],
# [ 0.9061, 0.1107, 0.4082],
# [-0.2897, 0.8657, 0.4082]])
# tensor([[-0.6386, 0.7695],
# [-0.7695, -0.6386]])
# MindSpore
import mindspore as ms
input = ms.Tensor([[1, 2], [-4, -5], [2, 1]], ms.float32)
s, u, v = ms.ops.svd(input, full_matrices=True, compute_uv=True)
print(s)
print(u)
print(v)
# [7.0652843 1.040081 ]
# [[ 0.30821905 -0.48819482 0.81649697]
# [-0.90613353 0.11070572 0.40824813]
# [ 0.2896955 0.8656849 0.4082479 ]]
# [[ 0.63863593 0.769509 ]
# [ 0.769509 -0.63863593]]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。