Repository navigation
LDLᵀ: keep NaN pivots and count them as negative in the inertia, as CHOLMOD #207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1321,8 +1321,8 @@ const _SP_CTL = _SP_C0 | |
| # requested `psg[g]` (`pivot_sign` in factor-column order) when nonzero, else the sign of d (+ for 0). | ||
| # Returns (pivot, replaced). A pure function of (d, eps, psg[g]): the factorization stays bitwise | ||
| # deterministic. eps = 0 returns a zero pivot as ±0 (the caller fails the front, as before #194); | ||
| # NaN and Inf are not "tiny" and come back unchanged, so the caller's finiteness test fails them | ||
| # (the stock kernel replaces a NaN pivot and accepts an Inf one). | ||
| # NaN and Inf are not "tiny" and come back unchanged; the callers keep them, as CHOLMOD's dbound does, | ||
| # and the inertia counts a NaN as negative (as the stock kernel). | ||
| @inline function _ldl_static_pivot(dk::R, eps::R, psg, g) where {R} | ||
| if abs(dk) < eps || iszero(dk) | ||
| s = @inbounds psg[g] | ||
|
|
@@ -1340,7 +1340,7 @@ end | |
| if ctl[SDS._ST_STATUS] == 0 | ||
| g = Int(ctl[_SP_C0]) + j - 1 | ||
| dk, rep = _ldl_static_pivot(real(buf[lf + SDS._packed(j, j, f)]), eps, psg, g) | ||
| if isfinite(dk) && !iszero(dk) # NaN/Inf must fail like potrf, not "factor" | ||
| if !iszero(dk) # a NaN or Inf pivot is kept, as CHOLMOD's (the inertia counts a NaN as negative) | ||
| if li == 1 | ||
| d[g] = dk | ||
| piv[g] = Int32(g) | ||
|
|
@@ -1440,7 +1440,7 @@ end | |
| w = Int(front_ncols[v]) | ||
| if j <= w && st[1] == Int32(0) | ||
| dk, rep = _ldl_static_pivot(real(sh[SDS._packed(j, j, 64)]), eps, psg, g0 + j) | ||
| if isfinite(dk) && !iszero(dk) # NaN/Inf must fail like potrf, not "factor" | ||
| if !iszero(dk) # a NaN or Inf pivot is kept, as CHOLMOD's (the inertia counts a NaN as negative) | ||
| if li == 1 | ||
| d[g0 + j] = dk | ||
| pivot_kind[g0 + j] = rep ? SDS.PIVOT_KIND_PERTURBED : SDS.PIVOT_KIND_1X1 | ||
|
|
@@ -1984,7 +1984,7 @@ end | |
| # PIV: the wide fronts are factored without interchanges (identity local order) | ||
| PIV && (gpiv[gj] = gj % eltype(gpiv)) | ||
| dj, rep = _ldl_static_pivot(dj, epsc, psg, gj) | ||
| if st[1] == Int32(0) && isfinite(dj) && !iszero(dj) | ||
| if st[1] == Int32(0) && !iszero(dj) # NaN/Inf kept, as CHOLMOD's | ||
| piv[1] = dj # d stays on the diagonal | ||
| sh[SDS._packed(j, j, 64)] = dj | ||
| d[gj] = dj | ||
|
|
@@ -2858,13 +2858,11 @@ Phases (`execute!(phase, F, X, B; asynchronous = true)`): | |
| `"factorization"`): the fused factorization of the current values, then the | ||
| inverses of the diagonal blocks; sets `"info"` (`0`, or the original column | ||
| of the first failed pivot: a non-positive Cholesky pivot, or for `"S"` a | ||
| zero pivot under `pivot_epsilon = 0`, or a non-finite pivot). A failed | ||
| factorization does not throw. Unlike the stock kernel, which replaces a NaN | ||
| pivot and accepts an infinite one, the fused LDLᵀ fails the factorization on | ||
| both under any `pivot_epsilon`, so a NaN or Inf in the matrix is reported | ||
| rather than factored (with `pivot_type = 'D'` only in the fronts wider than | ||
| 64: the subtrees and the narrow fronts then run the stock pivot rule, NaN | ||
| and Inf included). `"S"` factors | ||
| zero pivot under `pivot_epsilon = 0`). A failed factorization does not | ||
| throw. As on the stock pipeline and in CHOLMOD, the LDLᵀ keeps a NaN or | ||
| infinite pivot (`"info"` stays `0`) and the inertia counts a NaN pivot as | ||
| negative; a NaN propagates through the rest of its front and its ancestors, | ||
| so it shows as an inertia defect rather than as `info ≠ 0`. `"S"` factors | ||
| its wide fronts in the fused kernel under either `wides` strategy (a front's | ||
| pivots may take both signs), so the in-kernel wide-front limit applies to it | ||
| on every part: a front with more than `1023 · 32` rows below a panel raises | ||
|
|
@@ -2903,8 +2901,9 @@ run to run; `deterministic_mode = 1` runs the forward sweep without atomics | |
| children's buffers in order), and the solution is bitwise reproducible too. | ||
| `getparam` | ||
| returns `"info"`, `"inertia"` (`(npos, nneg)`; `"SPD"`: the positive pivots and | ||
| `0`; `"S"`: the counts of positive and negative entries of `D`, a replaced | ||
| pivot counted with the sign it was given), `"npivots"` (`"S"`: the number of | ||
| `0`; `"S"`: the counts of the entries of `D` that are positive and that are | ||
| neither positive nor zero, NaN included, as CHOLMOD's; a replaced pivot is | ||
| counted with the sign it was given), `"npivots"` (`"S"`: the number of | ||
| replaced pivots, valid when `"info"` is `0`), the analysis data | ||
| `"perm_reorder_row"`, `"perm_reorder_col"`, `"perm_row"`, `"perm_col"`, | ||
| `"lu_nnz"`, `"flops"`, `"nsuperpanels"` of the inner solver, `"ir_n_steps"` (the | ||
|
|
@@ -3346,7 +3345,8 @@ function SDS.getparam(F::FusedSolver{T, INT}, name::AbstractString) where {T, IN | |
| name == "npivots" && | ||
| return INT(count(==(SDS.PIVOT_KIND_PERTURBED), view(F.inner.numeric.pivot_kind, 1:size(F, 1)))) | ||
| d = view(F.inner.numeric.d, 1:size(F, 1)) | ||
| return (INT(count(>(zero(T)), d)), INT(count(<(zero(T)), d))) | ||
| # CHOLMOD's count (MadCore's inertia of its D): positive if > 0, zero if 0, else (NaN too) negative | ||
| return (INT(count(>(zero(T)), d)), INT(count(x -> !(x > zero(T)) && !iszero(x), d))) | ||
|
Comment on lines
+3348
to
+3349
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit (non-blocking): the fused |
||
| end | ||
| name == "memory_estimates" && return _fused_memory_estimates(F) | ||
| name == "ir_n_steps" && return SDS.getparam(F.inner, name) # the steps of the last solve, as DirectSolver | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -397,7 +397,9 @@ end | |
| x = _fget(F, c, c) | ||
| dk = H ? T(real(x)) : x | ||
| kind = PIVOT_KIND_1X1 | ||
| if !(abs(dk) >= ε) || iszero(dk) # tiny (or NaN, or exactly zero): perturb | ||
| # tiny or exactly zero: perturb. A NaN pivot is kept (as CHOLMOD's dbound) and counted as negative by the | ||
| # inertia below | ||
| if abs(dk) < ε || iszero(dk) | ||
| iszero(dk) && (ctl[_LT_STAT + STAT_NZERO] += one(IT)) | ||
| dk = _perturbation_sign(dk, Int(psign[perm[piv[c0 + c - 1]]]), H) * ε | ||
| kind = PIVOT_KIND_PERTURBED | ||
|
|
@@ -408,10 +410,10 @@ end | |
| d[g] = dk | ||
| d[n + g] = zero(T) | ||
| pivot_kind[g] = kind | ||
| if H | ||
| if H # CHOLMOD's count (MadCore's inertia of its D): positive if > 0, zero if 0, else (NaN too) negative | ||
| if real(dk) > 0 | ||
| ctl[_LT_STAT + STAT_NPOS] += one(IT) | ||
| elseif real(dk) < 0 | ||
| elseif !iszero(real(dk)) | ||
| ctl[_LT_STAT + STAT_NNEG] += one(IT) | ||
|
Comment on lines
+413
to
417
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No test exercises the new behaviour. |
||
| end | ||
| end | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The public docstrings still describe the behaviour this line removes. In this file, the
execute!docstring (lines 2859–2867) lists "a non-finite pivot" among the causes ofinfo ≠ 0and says "Unlike the stock kernel, which replaces a NaN pivot and accepts an infinite one, the fused LDLᵀ fails the factorization on both under anypivot_epsilon, so a NaN or Inf in the matrix is reported rather than factored"; thegetparamdocstring (lines 2905–2907) describes"inertia"for"S"as "the counts of positive and negative entries ofD". Outside the diff,src/kkt.jl:88–90(KKTSolverdocstring: "On the fused pipeline a NaN or infinite pivot fails the factorization (info ≠ 0)") anddocs/src/lib/kkt.md:55–59say the same. All four are rendered in the documentation and are now wrong. Fix: state the new rule once (a NaN or Inf pivot is kept on both pipelines,infostays0, the inertia counts a pivot as positive if> 0, zero if0, else negative, NaN included, as CHOLMOD) and drop the stock-vs-fused contrast.