Skip to content

Check the matrix size in ldlt! and cholesky! of a CHOLMOD.Factor before refactorizing - #1122

Merged
ViralBShah merged 1 commit into
mainfrom
vs/cholmod-ldlt-validate-first
Oct 26, 2026
Merged

ViralBShah merged 1 commit into
mainfrom
vs/cholmod-ldlt-validate-first

Conversation

@ViralBShah

Copy link
Copy Markdown
Member

ldlt!(F, A) on an LLt CHOLMOD.Factor converts F to a simplicial LDLt before CHOLMOD checks the size of A, so a call with a matrix of the wrong size throws and still changes the kind of F.

Before

julia> A = sparse([4.0 1 0; 1 4 1; 0 1 4]); F = cholesky(A);

julia> propertynames(F)
(:L, :U, :PtL, :UP, :p, :ptr)

julia> ldlt!(F, sparse(1.0I, 4, 4))
ERROR: SparseArrays.CHOLMOD.CHOLMODException("A and L dimensions do not match")

julia> propertynames(F)
(:L, :U, :PtL, :UP, :D, :LD, :DU, :PtLD, :DUP, :p, :ptr)

julia> cholesky!(cholesky(A), sparse(1.0I, 4, 4))
ERROR: SparseArrays.CHOLMOD.CHOLMODException("A and L dimensions do not match")

After

julia> ldlt!(F, sparse(1.0I, 4, 4))
ERROR: DimensionMismatch: matrix has size (4, 4), but the factorization has size (3, 3)

julia> propertynames(F)
(:L, :U, :PtL, :UP, :p, :ptr)

julia> cholesky!(cholesky(A), sparse(1.0I, 4, 4))
ERROR: DimensionMismatch: matrix has size (4, 4), but the factorization has size (3, 3)

ldlt! calls change_factor! before factorize_p!, and only the latter reaches CHOLMOD's dimension check. A new check_refactor_size compares size(A) with size(F) under the factor's lock, before anything writes to F, in both ldlt! and cholesky!. cholesky! already left F unchanged, and gets the check so that the two throw the same error. The eltype is already fixed by dispatch and the stype by check_hermitian_stype, and a non-square matrix fails that check, so size is the only precondition missing.

Potential breakage: a size mismatch now throws DimensionMismatch instead of CHOLMODException, from both ldlt! and cholesky!.

🤖 Generated with Claude Code

@ViralBShah ViralBShah added backport 1.13 Change should be backported to release-1.13 backport 1.14 labels Oct 26, 2026
@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.73%. Comparing base (e4a42b4) to head (be0757b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1122   +/-   ##
=======================================
  Coverage   94.73%   94.73%           
=======================================
  Files          16       16           
  Lines       10325    10330    +5     
=======================================
+ Hits         9781     9786    +5     
  Misses        544      544           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…` before refactorizing

`ldlt!(F, A)` converted an LLt factor to LDLt before CHOLMOD rejected a matrix
of another size, so the failed call changed the kind of `F`. Both now throw a
`DimensionMismatch` before touching the factor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ViralBShah
ViralBShah force-pushed the vs/cholmod-ldlt-validate-first branch from 0cbca18 to be0757b Compare October 26, 2026 14:58
@ViralBShah
ViralBShah merged commit 1a0d484 into main Oct 26, 2026
12 checks passed
@ViralBShah
ViralBShah deleted the vs/cholmod-ldlt-validate-first branch October 26, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 1.13 Change should be backported to release-1.13 backport 1.14

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant