Computes the LU factorization of a matrix.
Arguments
- x
An mlx array.
- device
Execution target for APIs that expose a one-off device or stream override. Supply
"gpu","cpu", or anmlx_streamcreated viamlx_new_stream(). Ordinary array operations use the currentmlx_device()instead.
Value
A list with components p (pivot indices), l (lower triangular),
and u (upper triangular). The relationship is A = L[P, ] %*% U.
Details
As of MLX 0.31.1, this operation only runs on CPU. Run it inside
with_device() or local_device(), or pass device = "cpu".
Examples
A <- mlx_matrix(rnorm(16), 4, 4)
lu_result <- mlx_lu(A, device = "cpu")
P <- lu_result$p # Pivot indices
L <- lu_result$l # Lower triangular
U <- lu_result$u # Upper triangular