Skip to content

LinearSolve.solve! throws error when using KLUFactorization in LinearSolve.init #57

@mariekeosw

Description

@mariekeosw

Hi there,
I was working with a linear system defined by an ExtendableSparseMatrix, which I wanted to solve using LinearSolve.jl. However, when I tried to solve the system using the cache, I received the following error. The code and error message are documented below.

Note that using linsolve = init(prob) or linsolve = init(prob, UMFPACKFactorization()) runs successfully.

function minimal_example(N; usecache=true)

	b = zeros(N)
	A = ExtendableSparseMatrix(N,N)

	for i in 1:N
		A[i,i] = 1
	end
	flush!(A)
	
	prob = LinearProblem(A, b)
	
	if usecache
		linsolve = LinearSolve.init(prob, KLUFactorization())
		LinearSolve.solve!(linsolve)
	else
		LinearSolve.solve(prob)
	end
	
	return "success return"
end;

Resulting error when using usecache=true:

ERROR: DimensionMismatch: 
Stacktrace:
 [1] klu!(K::LinearSolveSparseArraysExt.KLU.KLUFactorization{…}, nzval::Vector{…}; check::Bool, allowsingular::Bool)
   @ LinearSolveSparseArraysExt.KLU C:\Users\marie\.julia\packages\LinearSolve\wrTJy\src\KLU\klu.jl:640
 [2] klu!
   @ C:\Users\marie\.julia\packages\LinearSolve\wrTJy\src\KLU\klu.jl:638 [inlined]
 [3] solve!(cache::LinearSolve.LinearCache{…}, alg::KLUFactorization; kwargs::@Kwargs{})
   @ LinearSolveSparseArraysExt C:\Users\marie\.julia\packages\LinearSolve\wrTJy\ext\LinearSolveSparseArraysExt.jl:247
 [4] solve!
   @ C:\Users\marie\.julia\packages\LinearSolve\wrTJy\ext\LinearSolveSparseArraysExt.jl:235 [inlined]
 [5] #solve!#11
   @ C:\Users\marie\.julia\packages\LinearSolve\wrTJy\src\common.jl:299 [inlined]
 [6] solve!(::LinearSolve.LinearCache{…})
   @ LinearSolve C:\Users\marie\.julia\packages\LinearSolve\wrTJy\src\common.jl:298
 [7] minimal_example(N::Int64; usecache::Bool)
   @ Main c:\Users\marie\Desktop\WIAS\04_Minimal-working-examples\Minimal-working-example_Compatibility-ExtendableSparse-LinearSolve.jl:20
 [8] top-level scope
   @ c:\Users\marie\Desktop\WIAS\04_Minimal-working-examples\Minimal-working-example_Compatibility-ExtendableSparse-LinearSolve.jl:30
Some type information was truncated. Use `show(err)` to see complete types

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions