Skip to content

Commit d416d03

Browse files
committed
Check for sparsity pattern change without allocating
1 parent 0bbacb4 commit d416d03

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

ext/LinearSolveSparseArraysExt.jl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,19 @@ end
394394
end # @static if Base.USE_GPL_LIBS
395395

396396
function LinearSolve.pattern_changed(fact, A::SparseArrays.SparseMatrixCSC)
397-
!(SparseArrays.decrement(SparseArrays.getcolptr(A)) ==
398-
fact.colptr && SparseArrays.decrement(SparseArrays.getrowval(A)) ==
399-
fact.rowval)
397+
colptr0 = fact.colptr # has 0-based indices
398+
colptr1 = SparseArrays.getcolptr(A) # has 1-based indices
399+
length(colptr0) == length(colptr1) || return true
400+
@inbounds for i in eachindex(colptr0)
401+
colptr0[i] + 1 == colptr1[i] || return true
402+
end
403+
rowval0 = fact.rowval
404+
rowval1 = SparseArrays.getrowval(A)
405+
length(rowval0) == length(rowval1) || return true
406+
@inbounds for i in eachindex(rowval0)
407+
rowval0[i] + 1 == rowval1[i] || return true
408+
end
409+
return false
400410
end
401411

402412
@static if Base.USE_GPL_LIBS

0 commit comments

Comments
 (0)