fn

lu

Tensor
lu(A: Tensor, pivot: bool = True)
source

Full LU decomposition with explicit factors (P,L,U)(P, L, U).

Decomposes a square matrix AA as

A=PLU,A \,=\, P\,L\,U,

where PP is a row permutation, LL is unit-lower triangular (ones on the diagonal), and UU is upper triangular. Unlike lu_factor (which returns a packed factor + integer pivots), this routine returns the three factors as explicit dense tensors — convenient for inspection or for re-using P,L,UP,L,U in downstream linear-algebra expressions.

Parameters

ATensor
Square matrix of shape (n, n). Batched inputs are not yet exposed through the Python wrapper (will raise).
pivot(bool, keyword - only)= True
Must be True (the default). False would request an unpivoted LU; Lucid does not currently ship that kernel and raises NotImplementedError.

Returns

Tensor

Permutation matrix of shape (n, n).

Notes

Implemented as a Python composite over lu_factor followed by explicit triangular masking and pivot-to-matrix conversion. Cost is O(23n3)O(\tfrac{2}{3} n^3), dominated by the underlying LULU factorization.

Examples

>>> import lucid
>>> from lucid.linalg import lu
>>> A = lucid.tensor([[2.0, 1.0], [4.0, 7.0]])
>>> P, L, U = lu(A)
>>> (P @ L @ U).numpy()
array([[2., 1.],
       [4., 7.]], dtype=float32)