mindspore.ops.pinv

View Source On Gitee
mindspore.ops.pinv(x, *, atol=None, rtol=None, hermitian=False)[source]

Computes the (Moore-Penrose) pseudo-inverse of a matrix.

This function is computed using SVD. If x=USVT ,Than the pseudo-inverse of x is: x+=VS+UT , S+ is the reciprocal of each non-zero element on the diagonal of S, and zero remains in place. Batch matrices are supported. If x is a batch matrix, the output has the same batch dimension when atol or rtol is float. If atol or rtol is a Tensor, its shape must be broadcast to the singular value returned by x.svd . If x.shape is (B,M,N), and the shape of atol or rtol is (K,B), the output shape is (K,B,N,M). When the Hermitian is True, temporary support only real domain, x is treated as a real symmetric, so x is not checked internally, and only use the lower triangular part in the computations. When the singular value of x (or the norm of the eigenvalues when hermitian = True) that are below threshold (max(atol,σrtol), σ as the largest singular value or characteristic value), it is set to zero, and is not used in the computations. If rtol is not specified and x is a matrix of dimensions (M, N), then rtol is set to be rtol=max(M,N)ε, ε is the eps value of x.dtype. If rtol is not specified and atol specifies a value larger than zero, rtol is set to zero.

Note

This function uses svd internally, (or eigh , when hermitian = True ). So it has the same problem as these functions. For details, see the warnings in svd() and eigh().

Parameters

x (Tensor) – The input tensor whose shape is (,M,N), * is zero or more batch dimensions. When hermitian is True, batch dimensions are not supported temporarily.

Keyword Arguments
  • atol (float, Tensor) – The absolute tolerance value. Default None .

  • rtol (float, Tensor) – The relative tolerance value. Default None .

  • hermitian (bool) – Whether x is assumed to be symmetric if real. Default False .

Outputs:

A tensor whose shape is (,N,M), * is zero or more batch dimensions.

Supported Platforms:

CPU

Examples

>>> import mindspore
>>> x = mindspore.tensor([[4., 0.], [0., 5.]], mindspore.float32)
>>> output = mindspore.ops.pinv(x)
>>> print(output)
[[0.25 0.  ]
 [0.   0.2 ]]