MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
mtl::sparse::factorization::lu_numeric< Value > Struct Template Reference

Result of numeric LU factorization. More...

#include <sparse_lu.hpp>

Public Member Functions

std::size_t num_rows () const
std::size_t num_cols () const
const util::csc_matrix< Value > & factorL () const
 Read-only access to the factors (L unit lower, U upper; both CSC).
const util::csc_matrix< Value > & factorU () const
void set_factor (util::csc_matrix< Value > L, util::csc_matrix< Value > U)
 Install the factors and (re)build the coupled forward (L) and upper (U) solve schedules from them.
bool has_factor () const
 True once factors (and their coupled schedules) have been installed.
Value rcond () const
 A cheap estimate of the reciprocal condition number: min |u_kk| / max |u_kk| over U's diagonal, as SuiteSparse's klu_rcond.
template<typename Parameters>
Value rgrowth (const mat::compressed2D< Value, Parameters > &A) const
 The reciprocal pivot growth: the minimum over U's columns k of max_i |A(i, q[k])| / max_i |U(i, k)|, capped at 1, as SuiteSparse's klu_rgrowth.
template<typename VecX, typename VecB>
void solve_transpose (VecX &x, const VecB &b) const
 Solve A^T x = b (the transpose, not the conjugate transpose).
template<typename Parameters>
Value condest (const mat::compressed2D< Value, Parameters > &A) const
 An estimate of the 1-norm condition number ||A||_1 ||A^{-1}||_1, as SuiteSparse's klu_condest: Hager's method with Higham's refinements (detail::inverse_norm1_estimate), from at most 11 solves.
void set_factor_values (std::vector< Value > Lvals, std::vector< Value > Uvals)
 Install recomputed VALUES on the already-installed factor pattern, keeping the existing solve schedules.
template<typename Accumulator = void, typename VecX, typename VecB>
void solve (VecX &x, const VecB &b) const
 Solve A*x = b using the LU factorization.
template<typename Accumulator = void, typename VecX, typename VecB>
void solve (VecX &x, const VecB &b, std::vector< Value > &w) const
 solve(x, b) with the caller's workspace w, resized to n: a caller that solves many small systems (native_klu's blocks) reuses one buffer instead of allocating per solve (issue 908).

Public Attributes

std::vector< std::size_t > row_perm
std::vector< std::size_t > row_pinv
std::size_t num_perturbed = 0
lu_symbolic symbolic

Detailed Description

template<typename Value>
struct mtl::sparse::factorization::lu_numeric< Value >

Result of numeric LU factorization.

Contains L (unit lower triangular) and U (upper triangular) in CSC, plus the row and column permutations.

Member Function Documentation

◆ condest()

template<typename Value>
template<typename Parameters>
Value mtl::sparse::factorization::lu_numeric< Value >::condest ( const mat::compressed2D< Value, Parameters > & A) const
inline

An estimate of the 1-norm condition number ||A||_1 ||A^{-1}||_1, as SuiteSparse's klu_condest: Hager's method with Higham's refinements (detail::inverse_norm1_estimate), from at most 11 solves.

A lower bound, exact or within a factor of 3 in practice. Far more telling than rcond() and far cheaper than forming A^{-1}. A must be the matrix this factorization is of. 1 for n = 0; NaN if A or a solve holds a NaN.

◆ factorL()

template<typename Value>
const util::csc_matrix< Value > & mtl::sparse::factorization::lu_numeric< Value >::factorL ( ) const
inline

Read-only access to the factors (L unit lower, U upper; both CSC).

◆ factorU()

template<typename Value>
const util::csc_matrix< Value > & mtl::sparse::factorization::lu_numeric< Value >::factorU ( ) const
inline

◆ has_factor()

template<typename Value>
bool mtl::sparse::factorization::lu_numeric< Value >::has_factor ( ) const
inline

True once factors (and their coupled schedules) have been installed.

◆ num_cols()

template<typename Value>
std::size_t mtl::sparse::factorization::lu_numeric< Value >::num_cols ( ) const
inline

◆ num_rows()

template<typename Value>
std::size_t mtl::sparse::factorization::lu_numeric< Value >::num_rows ( ) const
inline

◆ rcond()

template<typename Value>
Value mtl::sparse::factorization::lu_numeric< Value >::rcond ( ) const
inline

A cheap estimate of the reciprocal condition number: min |u_kk| / max |u_kk| over U's diagonal, as SuiteSparse's klu_rcond.

It costs O(n). It is a crude first check, not a bound: a small value means U's pivots span many orders of magnitude. 1 for n = 0; NaN if a pivot is NaN.

Exceptions
std::logic_errorif no factor is installed (n > 0).

◆ rgrowth()

template<typename Value>
template<typename Parameters>
Value mtl::sparse::factorization::lu_numeric< Value >::rgrowth ( const mat::compressed2D< Value, Parameters > & A) const
inline

The reciprocal pivot growth: the minimum over U's columns k of max_i |A(i, q[k])| / max_i |U(i, k)|, capped at 1, as SuiteSparse's klu_rgrowth.

Near 1 means the pivots fit A; a tiny value means elements of U grew far past A's, and the factorization (a refactorization, which keeps an earlier pivot sequence, above all) cannot be trusted. It costs O(nnz(A) + nnz(U)). A must be the matrix this factorization is of. 1 for n = 0; NaN if A or U holds a NaN.

Exceptions
std::invalid_argumentif A's dimensions are not n x n.
std::logic_errorif no factor is installed (n > 0).

◆ set_factor()

template<typename Value>
void mtl::sparse::factorization::lu_numeric< Value >::set_factor ( util::csc_matrix< Value > L,
util::csc_matrix< Value > U )
inline

Install the factors and (re)build the coupled forward (L) and upper (U) solve schedules from them.

L, U and their schedules are always set together here, so the schedules' cached structure always matches the factors' patterns. Both must be square and match the symbolic dimension. Strongly exception safe: both schedules are built into locals before any member is replaced, so a throw leaves the object unchanged.

◆ set_factor_values()

template<typename Value>
void mtl::sparse::factorization::lu_numeric< Value >::set_factor_values ( std::vector< Value > Lvals,
std::vector< Value > Uvals )
inline

Install recomputed VALUES on the already-installed factor pattern, keeping the existing solve schedules.

The schedules are value-agnostic – they cache positions into L_.values / U_.values, not the values – so a same-pattern refactorization can swap in new numbers and skip the O(nnz) schedule rebuild set_factor pays. Only the value arrays change; col_ptr / row_ind are kept.

Requires a factor already installed, and value arrays of exactly the installed nnz – a PATTERN change must go through set_factor. The schedules' built_nnz staleness guards (the ones the solves assert on) are re-checked here, so a schedule can never be left silently stale. Strongly exception safe: all validation precedes any member replacement.

◆ solve() [1/2]

template<typename Value>
template<typename Accumulator = void, typename VecX, typename VecB>
void mtl::sparse::factorization::lu_numeric< Value >::solve ( VecX & x,
const VecB & b ) const
inline

Solve A*x = b using the LU factorization.

P*A*Q = L*U, so A = P^T * L * U * Q^T A*x = b => P^T * L * U * Q^T * x = b => L * U * Q^T * x = P * b Let y = Q^T * x, then L * U * y = P * b

  1. w = P * b
  2. L * z = w (forward solve)
  3. U * y = z (back solve)
  4. x = Q * y Accumulator (default void, leading as in the numeric phase) selects the accumulator policy of the triangular-solve row reductions (#535): void is the raw Value loop; see level_schedule.hpp for the contract.

◆ solve() [2/2]

template<typename Value>
template<typename Accumulator = void, typename VecX, typename VecB>
void mtl::sparse::factorization::lu_numeric< Value >::solve ( VecX & x,
const VecB & b,
std::vector< Value > & w ) const
inline

solve(x, b) with the caller's workspace w, resized to n: a caller that solves many small systems (native_klu's blocks) reuses one buffer instead of allocating per solve (issue 908).

Same arithmetic. w must not share storage with x or b: b is read through the row permutation while w is written. x and b may be the same vector (all of b is read into w before x is written).

◆ solve_transpose()

template<typename Value>
template<typename VecX, typename VecB>
void mtl::sparse::factorization::lu_numeric< Value >::solve_transpose ( VecX & x,
const VecB & b ) const
inline

Solve A^T x = b (the transpose, not the conjugate transpose).

With P A Q = L U, A^T = Q U^T L^T P, so U^T L^T (P x) = Q^T b: a forward solve with U^T, a back solve with L^T, then the row permutation. x and b may be the same vector. Serial: the transposed solves have no schedule.

Exceptions
std::logic_errorif no factor is installed (n > 0).
std::invalid_argumenton a size mismatch.

Member Data Documentation

◆ num_perturbed

template<typename Value>
std::size_t mtl::sparse::factorization::lu_numeric< Value >::num_perturbed = 0

◆ row_perm

template<typename Value>
std::vector<std::size_t> mtl::sparse::factorization::lu_numeric< Value >::row_perm

◆ row_pinv

template<typename Value>
std::vector<std::size_t> mtl::sparse::factorization::lu_numeric< Value >::row_pinv

◆ symbolic

template<typename Value>
lu_symbolic mtl::sparse::factorization::lu_numeric< Value >::symbolic

The documentation for this struct was generated from the following file:
  • /home/runner/work/mtl5/mtl5/include/mtl/sparse/factorization/sparse_lu.hpp