Skip to content
fn

pinv

→Tensor
pinv(input: Tensor, rcond: float | Tensor | None = None, hermitian: bool = False, atol: float | Tensor | None = None, rtol: float | Tensor | None = None)

Implementing kernel

C++ engine symbols that back this Python API.

Moore-Penrose pseudo-inverse of a matrix.

Returns the unique matrix A+A^+ satisfying the four Moore-Penrose conditions

AA+A=A,A+AA+=A+,(AA+)⊤=AA+,(A+A)⊤=A+A.A A^+ A = A, \quad A^+ A A^+ = A^+, \quad (A A^+)^\top = A A^+, \quad (A^+ A)^\top = A^+ A.

For a thin SVD A=UΣV⊤A = U\Sigma V^\top, the pseudo-inverse is

A+ = V Σ+ U⊤,Σii+={1/σiσi>τ0else.A^+ \,=\, V\,\Sigma^+\,U^\top, \qquad \Sigma^+_{ii} = \begin{cases} 1/\sigma_i & \sigma_i > \tau \\ 0 & \text{else} \end{cases}.

Parameters

inputTensor
Input matrix of shape (*, m, n). Need not be square or full-rank.
rcond(float, Tensor or None)= None
Alias for rtol; mutually exclusive with atol and rtol.
hermitianbool= False
If True, assumes input is symmetric / Hermitian and uses eigh of the lower triangle instead of svd.
atol(float, Tensor or None, keyword - only)= None
Absolute tolerance threshold (treated as 0.0 when None).
rtol(float, Tensor or None, keyword - only)= None
Relative tolerance threshold; defaults to max⁡(m,n)⋅ε\max(m, n) \cdot \varepsilon unless atol > 0, in which case 0.0.

Returns

Tensor

Pseudo-inverse of shape (*, n, m).

Notes

Every shape goes through the SVD-based kernel, a singular square matrix included (routing square input through inv answered a singular one with a non-finite matrix). The gradient follows the reference framework's closed form for a matrix of constant rank, which needs no singular-value gaps, and differentiates again.

The pseudo-inverse provides the least-squares solution of Ax=bAx = b even when AA is singular: x=A+bx = A^+ b.

Examples

>>> import lucid
>>> from lucid.linalg import pinv
>>> A = lucid.tensor([[1.0, 0.0], [0.0, 2.0], [0.0, 0.0]])
>>> lucid.allclose(pinv(A) @ A, lucid.eye(2), atol=1e-5)
True