# Problems with posdef symmetric matrix and LinearSolve

**URL:** <https://discourse.julialang.org/t/problems-with-posdef-symmetric-matrix-and-linearsolve/92343>\
**Category:** General Usage\
**Tags:** question, package\
**Created:** [December 31, 2022, 12:29am UTC](https://discourse.julialang.org/t/problems-with-posdef-symmetric-matrix-and-linearsolve/92343 "2022-12-31T00:29:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CodeLenz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/codelenz/32/3419_2.png) [@CodeLenz](https://discourse.julialang.org/u/CodeLenz)\
**Post date:** [December 31, 2022, 12:29am UTC](https://discourse.julialang.org/t/problems-with-posdef-symmetric-matrix-and-linearsolve/92343/1 "2022-12-31T00:29:07Z")

</div>

I am trying to move some FEM code to use the LinearSolve package. Consider the code

```julia
using LinearAlgebra, SparseArrays, LinearSolve

# Create a posdef symmetric matrix
A = sprand(100,100,0.01); A = A + A' + 100*I;

# rhs
b=rand(100);

# Set the problem
prob = LinearProblem(A,b)
sol = solve(prob)

# Check algorithm
sol.alg 

# ir returns KLUFactorization(true, true)

# Check solution...OK
norm(A * sol.u .- b)

# Enforce symmetry to use Cholesky, since A is symmetric and posdef
prob2 = LinearProblem(Symmetric(A),b)
sol2 = solve(prob2)

# Gives the error 
# = 
 ERROR: MethodError: no method matching ldiv!(::SparseArrays.CHOLMOD.Factor{Float64}, # ::Vector{Float64})

Closest candidates are:
  ldiv!(::Any, ::ChainRulesCore.AbstractThunk)
   @ ChainRulesCore ~/.julia/packages/ChainRulesCore/C73ay/src/tangent_types/thunks.jl:95
  ldiv!(::Any, ::LinearSolve.InvPreconditioner, ::Any)
   @ LinearSolve ~/.julia/packages/LinearSolve/HbBUp/src/preconditioners.jl:30
  ldiv!(::Any, ::LinearSolve.ComposePreconditioner, ::Any)
   @ LinearSolve ~/.julia/packages/LinearSolve/HbBUp/src/preconditioners.jl:17
  ...
=#

```

Am I doing something wrong with LinearSolve or is it a bug ?

Thank you very much,  
Eduardo.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [December 31, 2022, 2:43pm UTC](https://discourse.julialang.org/t/problems-with-posdef-symmetric-matrix-and-linearsolve/92343/2 "2022-12-31T14:43:55Z")

</div>

It was a bug. Fixed in patch v1.32.2 which should be released within an hour.

> <https://github.com/SciML/LinearSolve.jl/pull/246>

---

<div class="post-metadata">

**Author:** ![CodeLenz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/codelenz/32/3419_2.png) [@CodeLenz](https://discourse.julialang.org/u/CodeLenz)\
**Post date:** [December 31, 2022, 2:58pm UTC](https://discourse.julialang.org/t/problems-with-posdef-symmetric-matrix-and-linearsolve/92343/3 "2022-12-31T14:58:09Z")

</div>

Wow! That was fast!

Thank you very much for your help and for all the packages.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [December 31, 2022, 3:04pm UTC](https://discourse.julialang.org/t/problems-with-posdef-symmetric-matrix-and-linearsolve/92343/4 "2022-12-31T15:04:59Z")

</div>

Released
