Skip to content

Failures for linear solve with cholesky factor and sparse vector #630

@blegat

Description

@blegat

The first example works correctly, while makes me thing that this is a supported operation. The second one produces an error though and the third one even produces a vector with an incorrect index

julia> A = sparse(Matrix(I, 2, 2))
2×2 SparseMatrixCSC{Bool, Int64} with 2 stored entries:
 1  
   1

julia> b = sparse(ones(2))
2-element SparseVector{Float64, Int64} with 2 stored entries:
  [1]  =  1.0
  [2]  =  1.0

julia> cholesky(A).L \ b
2-element SparseVector{Float64, Int64} with 2 stored entries:
  [1]  =  1.0
  [2]  =  1.0

julia> A = sparse(Matrix(I, 1, 1))
1×1 SparseMatrixCSC{Bool, Int64} with 1 stored entry:
 1

julia> b = sparse(ones(1))
1-element SparseVector{Float64, Int64} with 1 stored entry:
  [1]  =  1.0

julia> cholesky(A).L \ b
ERROR: SparseArrays.CHOLMOD.CHOLMODException("B cannot be stored in symmetric mode")
Stacktrace:
 [1] error_handler(status::Int32, file::Cstring, line::Int32, message::Cstring)
   @ SparseArrays.CHOLMOD ~/.julia/juliaup/julia-1.11.5+0.x64.linux.gnu/share/julia/stdlib/v1.11/SparseArrays/src/solvers/cholmod.jl:122
 [2] cholmod_l_spsolve(arg1::Int64, arg2::SparseArrays.CHOLMOD.Factor{…}, arg3::SparseArrays.CHOLMOD.Sparse{…}, arg4::Base.RefValue{…})
   @ SparseArrays.LibSuiteSparse ~/.julia/juliaup/julia-1.11.5+0.x64.linux.gnu/share/julia/stdlib/v1.11/SparseArrays/src/solvers/wrappers.jl:1458
 [3] spsolve(sys::Int64, F::SparseArrays.CHOLMOD.Factor{Float64, Int64}, B::SparseArrays.CHOLMOD.Sparse{Float64, Int64})
   @ SparseArrays.CHOLMOD ~/.julia/juliaup/julia-1.11.5+0.x64.linux.gnu/share/julia/stdlib/v1.11/SparseArrays/src/solvers/cholmod.jl:755
 [4] \
   @ ~/.julia/juliaup/julia-1.11.5+0.x64.linux.gnu/share/julia/stdlib/v1.11/SparseArrays/src/solvers/cholmod.jl:1803 [inlined]
 [5] \(L::SparseArrays.CHOLMOD.FactorComponent{Float64, :L, Int64}, B::SparseVector{Float64, Int64})
   @ SparseArrays.CHOLMOD ~/.julia/juliaup/julia-1.11.5+0.x64.linux.gnu/share/julia/stdlib/v1.11/SparseArrays/src/solvers/cholmod.jl:1847
 [6] top-level scope
   @ REPL[32]:1
Some type information was truncated. Use `show(err)` to see complete types.

julia> A = sparse(Matrix(I, 2, 2))
2×2 SparseMatrixCSC{Bool, Int64} with 2 stored entries:
 1  
   1

julia> b = sparse(zeros(2))
2-element SparseVector{Float64, Int64} with 0 stored entries

julia> cholesky(A).L \ b
2-element SparseVector{Float64, Int64} with 1 stored entry:
  [1194158802]  =  0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions