Skip to content

Commit 411777b

Browse files
committed
Fix KLUFactorization for AbstractSparseMatrixCSC subtypes
Fixes #737 by handling the case where the cached KLU factorization is uninitialized (PREALLOCATED_KLU) or has a dimension mismatch with the input matrix. The issue occurred when using AbstractSparseMatrixCSC subtypes because: 1. The cacheval would be set to PREALLOCATED_KLU (a 0x0 matrix) 2. pattern_changed would return false for this case 3. klu! would be called with mismatched dimensions, causing an error The fix checks if the cacheval is uninitialized or has a size mismatch, and creates a new factorization in those cases instead of trying to reuse the incompatible cached value. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent ff7947f commit 411777b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

ext/LinearSolveSparseArraysExt.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,13 @@ function SciMLBase.solve!(cache::LinearSolve.LinearCache, alg::KLUFactorization;
259259
SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A),
260260
nonzeros(A)),
261261
check = false)
262+
elseif cacheval === nothing || cacheval === PREALLOCATED_KLU ||
263+
length(nonzeros(A)) != length(cacheval.nzval)
264+
# Create new factorization if cacheval is uninitialized or size mismatch
265+
fact = KLU.klu(
266+
SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A),
267+
nonzeros(A)),
268+
check = false)
262269
else
263270
fact = KLU.klu!(cacheval, nonzeros(A), check = false)
264271
end

0 commit comments

Comments
 (0)