1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//! # rmumps
//!
//! A pure Rust multifrontal sparse symmetric indefinite (LDL^T) solver.
//!
//! rmumps factorizes sparse symmetric matrices using a multifrontal method with
//! Bunch-Kaufman pivoting, providing inertia detection (counts of positive, negative,
//! and zero eigenvalues in the D factor). It is designed for solving KKT systems
//! arising in interior point methods for nonlinear optimization.
//!
//! ## Features
//!
//! - **Multifrontal factorization**: organizes sparse LDL^T into dense operations on
//! frontal matrices for better cache utilization than simplicial methods
//! - **Bunch-Kaufman pivoting**: 1x1 and 2x2 pivots for symmetric indefinite matrices
//! - **Inertia detection**: counts positive/negative/zero eigenvalues from D factor
//! - **AMD ordering**: approximate minimum degree fill-reducing permutation
//! - **Supernodal elimination tree**: groups columns into supernodes for efficiency
//! - **Iterative refinement**: configurable refinement steps for improved accuracy
//! - **Cached symbolic analysis**: analyze once, refactor with new values (same pattern)
//! - **Parallel level-set factorization**: independent supernodes factored via rayon
//!
//! ## Usage
//!
//! ```rust
//! use rmumps::coo::CooMatrix;
//! use rmumps::solver::{Solver, SolverOptions};
//!
//! // Create a 3x3 symmetric positive definite matrix (upper triangle, COO format)
//! let coo = CooMatrix::new(3,
//! vec![0, 1, 2, 0, 1], // rows
//! vec![0, 1, 2, 1, 2], // cols (col >= row)
//! vec![4.0, 5.0, 6.0, 1.0, 2.0], // values
//! ).unwrap();
//!
//! let mut solver = Solver::new(SolverOptions::default());
//! let inertia = solver.analyze_and_factor(&coo).unwrap();
//! assert_eq!(inertia.positive, 3);
//!
//! let rhs = vec![1.0, 2.0, 3.0];
//! let mut solution = vec![0.0; 3];
//! solver.solve(&rhs, &mut solution).unwrap();
//! ```
//!
//! ## Architecture
//!
//! The solver follows a three-phase approach:
//!
//! 1. **Symbolic analysis** (`symbolic.rs`): computes elimination tree, supernodes,
//! and frontal matrix structure from the sparsity pattern
//! 2. **Numeric factorization** (`numeric.rs`): assembles and partially factors
//! frontal matrices bottom-up through the elimination tree
//! 3. **Solve** (`solve.rs`): forward/backward substitution through the supernodal
//! factorization, with optional iterative refinement
//!
//! Key modules:
//! - `coo`: COO (triplet) sparse matrix format
//! - `csc`: CSC (compressed sparse column) format with COO conversion
//! - `ordering`: fill-reducing orderings (AMD, natural)
//! - `etree`: elimination tree construction (Liu 1990)
//! - `symbolic`: supernodal symbolic factorization
//! - `frontal`: frontal matrix assembly and partial factorization
//! - `dense`: column-major dense matrix with BLAS-like operations
//! - `pivot`: Bunch-Kaufman pivoting for dense symmetric indefinite matrices
//! - `numeric`: multifrontal numeric factorization with inertia tracking
//! - `solve`: triangular solve with iterative refinement
//! - `solver`: high-level API combining all phases
/// Sparse symmetric matrix in COO (triplet) format.
/// Sparse symmetric matrix in CSC (compressed sparse column) format.
/// Column-major dense matrix with BLAS-like operations.
/// Elimination tree construction from sparse matrix structure.
/// Fill-reducing orderings (AMD, natural).
/// Bunch-Kaufman pivoting for dense symmetric indefinite matrices.
/// Frontal matrix assembly and partial factorization.
/// Multifrontal numeric factorization with inertia tracking.
/// Triangular solve with iterative refinement.
/// High-level solver API combining symbolic analysis, numeric factorization, and solve.
/// Matrix scaling (diagonal equilibration, Ruiz) for improved pivot quality.
/// Supernodal symbolic factorization from sparsity pattern.
/// Preconditioner trait and basic implementations.
/// MINRES iterative solver for symmetric systems.
/// Incomplete LDL^T factorization for preconditioning.
use fmt;
/// Inertia of a symmetric matrix after LDL^T factorization.
/// Counts the signs of diagonal entries in D.
/// Error from the solver.