Commit 81ecb35
feat: const-ify Lu/Ldlt det + solve_vec and Matrix inf_norm + det_errbound
Make six public methods `const fn`, completing const-evaluation parity
with `Matrix::det_direct` and `Vector::dot` now that MSRV 1.95 exposes
`f64::mul_add` as const (1.94) and `core::hint::cold_path` as const
(1.95):
- `Lu::det`, `Lu::solve_vec`
- `Ldlt::det`, `Ldlt::solve_vec`
- `Matrix::inf_norm`, `Matrix::det_errbound`
Iterator chains (`.iter().map().sum()`, `.enumerate().take(i)`,
`.enumerate().skip(i + 1)`, `.iter_mut().enumerate().take(D)`) were
rewritten as `while` loops since they are not const-stable.
Fix error-variant correctness in both solve_vec paths:
- A corrupt stored `U` / `D` diagonal at `(i, i)` now surfaces as
`LaError::NonFinite { row: Some(i), col: i }`, matching the
convention used by `Matrix::det`, `Lu::factor`, and `Ldlt::factor`.
- A computed-intermediate overflow keeps `row: None, col: i`.
- Previously both were conflated into `row: None, col: i`, defeating
debuggability for callers who construct factorizations directly.
Sharpen `LaError::NonFinite` variant docs and the `# Errors` sections of
`Lu::solve_vec` / `Ldlt::solve_vec` to spell out the `(row, col)`
contract for each failure mode.
Cleanup:
- Import `ERR_COEFF_{2,3,4}` at `src/matrix.rs` top; drop `crate::`
prefixes inside `Matrix::det_errbound`.
- Rename intermediate bindings `q` / `v` → `quotient` to stay under
`clippy::many_single_char_names`.
- Rename const-evaluability tests from `*_is_const_evaluable_*` to
`*_const_eval_*` for a concise, consistent style.
Tests:
- Added `{lu,ldlt,inf_norm,det_errbound}_const_eval_*` tests that force
compile-time evaluation inside `const { … }` initializers.
- Added `solve_vec_defensive_non_finite_diagonal_{2,3,4,5}d` in
`src/lu.rs` covering the new split error path (previously only the
`Singular` defensive path was exercised).
- Updated matching `Ldlt` defensive tests to assert the new
`row: Some(D - 1), col: D - 1` payload.
Validation: `just ci` passes — 164 unit tests, 324 integration/feature
tests, 28 doctests; clippy pedantic + nursery as errors; all examples.
Co-Authored-By: Oz <oz-agent@warp.dev>1 parent aba1dc7 commit 81ecb35
4 files changed
Lines changed: 342 additions & 56 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
| 127 | + | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
| 130 | + | |
130 | 131 | | |
| 132 | + | |
131 | 133 | | |
132 | 134 | | |
133 | 135 | | |
| |||
154 | 156 | | |
155 | 157 | | |
156 | 158 | | |
157 | | - | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
158 | 168 | | |
159 | | - | |
| 169 | + | |
160 | 170 | | |
161 | 171 | | |
162 | 172 | | |
163 | | - | |
| 173 | + | |
| 174 | + | |
164 | 175 | | |
165 | 176 | | |
166 | | - | |
167 | | - | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
168 | 181 | | |
169 | 182 | | |
170 | 183 | | |
171 | 184 | | |
172 | 185 | | |
173 | 186 | | |
| 187 | + | |
174 | 188 | | |
175 | 189 | | |
176 | 190 | | |
177 | | - | |
| 191 | + | |
| 192 | + | |
178 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
179 | 198 | | |
180 | 199 | | |
181 | | - | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
182 | 204 | | |
183 | 205 | | |
184 | 206 | | |
185 | 207 | | |
186 | 208 | | |
187 | 209 | | |
188 | | - | |
189 | | - | |
| 210 | + | |
| 211 | + | |
190 | 212 | | |
191 | 213 | | |
192 | 214 | | |
193 | | - | |
| 215 | + | |
| 216 | + | |
194 | 217 | | |
195 | 218 | | |
196 | 219 | | |
197 | | - | |
| 220 | + | |
| 221 | + | |
198 | 222 | | |
199 | 223 | | |
200 | | - | |
201 | | - | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
202 | 228 | | |
203 | 229 | | |
204 | 230 | | |
205 | 231 | | |
206 | 232 | | |
207 | 233 | | |
| 234 | + | |
208 | 235 | | |
209 | 236 | | |
210 | 237 | | |
| |||
487 | 514 | | |
488 | 515 | | |
489 | 516 | | |
490 | | - | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
491 | 520 | | |
492 | 521 | | |
493 | 522 | | |
| |||
498 | 527 | | |
499 | 528 | | |
500 | 529 | | |
501 | | - | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
502 | 537 | | |
503 | 538 | | |
504 | 539 | | |
| |||
524 | 559 | | |
525 | 560 | | |
526 | 561 | | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
527 | 623 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
122 | 132 | | |
123 | | - | |
124 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
125 | 136 | | |
126 | | - | |
| 137 | + | |
127 | 138 | | |
128 | 139 | | |
129 | 140 | | |
| |||
0 commit comments