fn

pinv

Tensor
pinv(x: Tensor)
source

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ΣVA = 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

xTensor
Input matrix of shape (*, m, n). Need not be square or full-rank.

Returns

Tensor

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

Notes

For square, full-rank matrices pinv is equivalent to inv — Lucid routes that case through inv to keep autograd active. For rectangular or rank-deficient inputs the SVD-based engine kernel is invoked (no backward).

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]])
>>> pinv(A) @ A
Tensor([[1.0000, 0.0000],
        [0.0000, 1.0000]])