Computes the partial-pivoted LU decomposition of a matrix x:
$$P A = L U,$$
where \(P\) is a permutation matrix, \(L\) is unit lower
triangular, and \(U\) is upper triangular.
This function returns L and U as separate matrices.
Use prim_lu() to get them in packed LU form.
Arguments
- x
(
arrayish)
One input, with exactly 2 axes. Can be any numeric data type: a float keeps its own, and an integer one is converted to the default float data type (seedefault_dtypes()). An R value materializes at its default data type and is converted in the same way.
Value
(named list of arrayish)L and U have the input's data type – or the default float data type
(see default_dtypes()) where the input was an integer one; pivots
and permutation are indices at the default integer data type (see
default_dtypes()).
L– unit lower-triangular factor of shape(m, k), where(m, n) = shape(x)andk = min(m, n).U– upper-triangular factor of shape(k, n).pivots– lengthk, at the default integer data type (seedefault_dtypes()). LAPACK-style sequential row swaps as returned bygetrf.permutation– lengthm, at that same data type. A permutation vector representing \(P\).
Examples
# `L` and `U` keep the input's data type; the pivots are the default integer
x <- nv_matrix(c(4, 3, 6, 3), nrow = 2, dtype = "f64")
nv_lu(x)
#> $L
#> AnvlArray
#> 1.0000 0.0000
#> 0.7500 1.0000
#> [ CPUf64{2,2} ]
#>
#> $U
#> AnvlArray
#> 4.0000 6.0000
#> 0.0000 -1.5000
#> [ CPUf64{2,2} ]
#>
#> $pivots
#> AnvlArray
#> 1
#> 2
#> [ CPUi32{2} ]
#>
#> $permutation
#> AnvlArray
#> 1
#> 2
#> [ CPUi32{2} ]
#>