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=U*S*V^{T}\) ,Than the pseudo-inverse of x is: \(x^{+}=V*S^{+}*U^{T}\) , \(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, \sigma \cdot rtol)\), \(\sigma\) 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)*\varepsilon\), \(\varepsilon\) 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) –

A matrix to be calculated. Only float32, float64 are supported Tensor dtypes. 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) – absolute tolerance value. Default: None .

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

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

Outputs:
  • output (Tensor) - same type as input. Shape is \((*, N, M)\), * is zero or more batch dimensions.

Raises
Supported Platforms:

CPU

Examples

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