Skip to content

Throw an ArgumentError from cholesky and ldlt for an index type CHOLMOD cannot take - #1117

Merged
ViralBShah merged 1 commit into
mainfrom
vs/cholmod-index-type-error
Oct 26, 2026
Merged

ViralBShah merged 1 commit into
mainfrom
vs/cholmod-index-type-error

Conversation

@ViralBShah

Copy link
Copy Markdown
Member

cholesky and ldlt of a sparse matrix whose index type does not promote with Int to one CHOLMOD takes, such as UInt64, throw a bare TypeError from inside the CHOLMOD.Sparse conversion, where lu names the matrix type. cholesky! and ldlt! reject index types like Int16 that cholesky and ldlt accept.

Before

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

julia> cholesky(SparseMatrixCSC{Float64,UInt64}(A))
ERROR: TypeError: in Sparse, in Ti, expected Ti<:Union{Int32, Int64}, got Type{UInt64}

julia> cholesky(SparseMatrixCSC{Float64,Int16}(A));   # works

julia> cholesky!(cholesky(A), SparseMatrixCSC{Float64,Int16}(A))
ERROR: TypeError: in Sparse, in Ti, expected Ti<:Union{Int32, Int64}, got Type{Int16}

After

julia> cholesky(SparseMatrixCSC{Float64,UInt64}(A))
ERROR: ArgumentError: matrix type SparseMatrixCSC{Float64, UInt64} not supported: CHOLMOD needs an index type of Int32 or Int64. Try converting its index type to Int first.

julia> cholesky!(cholesky(A), SparseMatrixCSC{Float64,Int16}(A))
SparseArrays.CHOLMOD.Factor{Float64, Int64}
...

The six CHOLMOD.Sparse conversions from a SparseMatrixCSC or a Symmetric/Hermitian view of one computed Ti <: ITypes ? Ti : promote_type(Ti, Int) and passed the result to Sparse{Tv, Ti} unchecked. They now call a helper, cholmod_itype, that does the same promotion and throws the ArgumentError when the result is not in ITypes; the message lists ITypes, which is Int32 alone on a 32-bit build. cholesky!(F, A) and ldlt!(F, A) used to convert A to Sparse{eltype(F), Ti} with A's own index type, which factorize_p! then converted again to the factor's. They now convert straight to the factor's index type, so they accept any integer index type, UInt64 included, as long as the indices fit. This touches dispatch: those two methods now take the index type from F rather than from A.

🤖 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

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 94.73%. Comparing base (a5211ce) to head (3ad68c7).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/solvers/cholmod.jl 93.33% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1117   +/-   ##
=======================================
  Coverage   94.72%   94.73%           
=======================================
  Files          16       16           
  Lines       10319    10327    +8     
=======================================
+ Hits         9775     9783    +8     
  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.

… CHOLMOD cannot take

An index type that does not promote with `Int` to `Int32` or `Int64`, such as
`UInt64`, now throws an `ArgumentError` naming the matrix type instead of a bare
`TypeError`. `cholesky!` and `ldlt!` convert `A` to the index type of the factor,
so they accept every index type, such as `Int16`, that `cholesky` and `ldlt` accept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ViralBShah
ViralBShah force-pushed the vs/cholmod-index-type-error branch from efd0926 to 3ad68c7 Compare October 26, 2026 14:01
@ViralBShah
ViralBShah merged commit 31a10e8 into main Oct 26, 2026
12 checks passed
@ViralBShah
ViralBShah deleted the vs/cholmod-index-type-error branch October 26, 2026 14:29
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