factorize_lu: Reusable LU Factorization

View source: R/factorize.R

factorize_luR Documentation

Reusable LU Factorization

Description

Compute an LU factorization once and reuse it for different right-hand sides.

Usage

factorize_lu(a, pivot = 1L, ordering = 1L)

## S3 method for class 'sanic_lu'
solve(a, b, ...)

Arguments

a

For factorize_lu(), a nonempty square numeric matrix, dense or sparse (dgCMatrix). For solve(), a sanic_lu factorization.

pivot

Pivoting scheme for dense matrices, as in solve_lu.

ordering

Ordering scheme for sparse matrices, as in solve_lu.

b

Numeric vector or matrix of right-hand sides. If missing, compute the inverse. Sparse right-hand sides are converted to dense matrices.

...

Unused; additional arguments are rejected.

Details

The factorization owns its data: changing or removing a does not affect subsequent solves. Dense LU uses partial pivoting by default; pivot = 2 uses full pivoting and checks for singularity. As with solve_lu(), partial pivoting assumes an invertible matrix and does not perform a rank check. Sparse LU ignores pivot.

Factorizations are session-local external pointers. They cannot be reused after serialization (for example, with saveRDS()) or in another R process; recreate them from the original matrix instead.

Value

factorize_lu() returns an object of class sanic_lu. Its solve() method returns a numeric matrix, including for vector right-hand sides. Omitting b computes the inverse.

Examples

A <- matrix(c(4, 1, 2, 3), 2)
f <- factorize_lu(A)
solve(f, c(1, 2))
solve(f, cbind(c(1, 2), c(3, 4)))
solve(f)

sanic documentation built on Oct. 25, 2026, 5:06 p.m.