Repository navigation
Conversation
…e) and not failed (fused), and the inertia counts a NaN pivot as negative (positive if > 0, zero if 0, else negative)
| # tiny or exactly zero: perturb. A NaN pivot is kept (as CHOLMOD's dbound): it counts in neither npos nor | ||
| # nneg, so the inertia shows it as a zero eigenvalue, the signal of a singular matrix |
There was a problem hiding this comment.
This comment contradicts the code it introduces. It says a kept NaN pivot "counts in neither npos nor nneg, so the inertia shows it as a zero eigenvalue", but the count below (elseif !iszero(real(dk)), and the comment on it) puts a NaN into STAT_NNEG, which is also what the PR title, the reference kernel and the fused getparam do. Fix: replace the second sentence with the actual rule, e.g. "A NaN pivot is kept (as CHOLMOD's dbound) and counted as negative by the inertia below".
| 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) |
There was a problem hiding this comment.
No test exercises the new behaviour. grep -rn "NaN\|isnan\|isfinite\|\bInf\b" test/ finds nothing in test_numeric_ldlt.jl, test_reference_ldlt.jl, test_fused.jl or test_kkt.jl, so the change from "perturb a NaN pivot" (stock, reference) / "fail the factorization" (fused) to "keep it and count it as negative" lands with no coverage of either the kept pivot (pivot_kind == PIVOT_KIND_1X1, d NaN, npivots unchanged, fused info == 0) or the inertia ((npos, nneg) with the NaN pivots in nneg, inertia(K) with nzero == 0). Fix: add a testset that puts a NaN on the diagonal of a small KKT-like matrix from test/matrices.jl, over BACKENDS and eltypes_among(...) with Random.seed!(666), on the stock kernel, the reference and the fused pipeline (both pivot_type = 'N' and 'D', since the diagonal-pivoting path reaches the pivot through _lt_pass3!/line 553 and the fused kernels at 1343, 1443 and 1987 are three separate code paths), and checks the pivot kind, info and the inertia.
| 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) |
There was a problem hiding this comment.
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 of info ≠ 0 and says "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"; the getparam docstring (lines 2905–2907) describes "inertia" for "S" as "the counts of positive and negative entries of D". Outside the diff, src/kkt.jl:88–90 (KKTSolver docstring: "On the fused pipeline a NaN or infinite pivot fails the factorization (info ≠ 0)") and docs/src/lib/kkt.md:55–59 say 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, info stays 0, the inertia counts a pivot as positive if > 0, zero if 0, else negative, NaN included, as CHOLMOD) and drop the stock-vs-fused contrast.
| # 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))) |
There was a problem hiding this comment.
nit (non-blocking): the fused "inertia" and "info" outputs and the stock "inertia" change meaning for matrices with a NaN, which MadNLP's binding reads; CHANGELOG.md has recorded every such behaviour change so far (e.g. the pivot_epsilon default under "Changed") but has no entry for this one. Add an Unreleased "Changed" entry. Also, with a NaN kept the whole remainder of the front and its ancestors turns NaN, so every later pivot counts as negative and the root pivot always does; worth one sentence in the docs so a reader understands why a NaN shows up as an inertia defect rather than as info ≠ 0.
There was a problem hiding this comment.
VERDICT: CHANGES_REQUESTED (head f156dcd)
This is not a TNN task PR (no TASKS.md section, no Report), so it was reviewed against AGENTS.md, PLAN.md and the PR body.
Checked:
- Scope: three source files, no PLAN.md/TASKS.md/Manifest changes, no public name or parameter string changed.
- Correctness of the new rule:
abs(d) < eps || iszero(d)leaves a NaN unperturbed in the stock kernel and the reference; the fused kernels keep a NaN/Inf pivot at the three pivot sites (regime A, narrow fronts, wide fronts) and leaveinfoat 0; the 2×2 path still rejects a NaN throughisfinite(det);_ldl_static_pivotalready returned NaN/Inf unchanged. The inertia count (> 0positive,0zero, else negative) is consistent across the stock kernel, the reference and the fusedgetparam, andinertia(K)derivesnzerofrom it, so a NaN lands innneg, as the PR says. - Conventions: generic in
T/INT, no new allocation or host synchronization in the kernels, no@allowscalar. - CI on this head: CPU-only, cuda, amdgpu, Aurora and the docs build pass.
Blocking findings (inline comments):
src/numeric/ldlt.jl:400-401: the new comment says a NaN pivot counts in neithernposnornnegand shows as a zero eigenvalue; the code four lines below counts it as negative.- No test covers the new behaviour on any path (stock kernel, reference, fused with
pivot_type'N'and'D',KKTSolver.inertia); nothing intest/puts a NaN or Inf pivot through LDLᵀ. The old behaviour was untested too, which is why CI stayed green. - Public docstrings and docs still describe the old behaviour:
src/fused.jlexecute!(lines 2859–2867: "a non-finite pivot" fails, "Unlike the stock kernel, which replaces a NaN pivot …") andgetparam(2905–2907),src/kkt.jl:88–90(KKTSolver),docs/src/lib/kkt.md:55–59.
Non-blocking: no CHANGELOG entry for a behaviour change that MadNLP observes through info and inertia.
…aN counts as negative), docstrings and docs describe the kept NaN on both pipelines, CHANGELOG entry, and tests of the kept pivot and the inertia on the stock kernel, the reference and the fused pipeline (:none and :diagonal)
LDLᵀ pivots are handled as CHOLMOD handles them:
_inertia_ldltdoes for CHOLMOD).With this, an interior-point solver sees a NaN pivot as a wrong inertia and regularizes, as it does with CHOLMOD, instead of either solving with a replaced pivot or failing.
Benchmarked through MadNLP (ShiftedPreset and CondensedPreset on CUDA, full ACOPF/COPS/CUTEst/Mittelmann sets) together with the SDSSolver defaults of madsuite-org/MadNLP.jl
sds-pivot-sign.