[LinearSolve] Inexact error in solving 4x4 linear system of equations

I have this issue in solving a simple set of equations:

julia> using LinearSolve


julia> let 
           A =  [1.0           0.0       -1.0         0.0
           0.0       -3152.28       0.0      3152.28
           0.388658      0.921382  -1.76854    -1.45868
           0.921382     -0.388658   1.45868     1.76854]
           b = [0, 0, 1, 0]
           prob = LinearProblem(A, b)
           solve(prob)
       end
ERROR: InexactError: Int64(3.8064439666352263)
Stacktrace:
  [1] Int64
    @ ./float.jl:788 [inlined]
  [2] convert
    @ ./number.jl:7 [inlined]
  [3] setindex!
    @ ./array.jl:966 [inlined]
  [4] ldiv!(A::LinearAlgebra.UpperTriangular{Float64, Matrix{Float64}}, b::Vector{Int64})
    @ LinearAlgebra ~/.julia/juliaup/julia-1.8.2+0.x64/share/julia/stdlib/v1.8/LinearAlgebra/src/triangular.jl:1200
  [5] ldiv!(A::LinearAlgebra.LU{Float64, Matrix{Float64}, Vector{Int64}}, B::Vector{Int64})
    @ LinearAlgebra ~/.julia/juliaup/julia-1.8.2+0.x64/share/julia/stdlib/v1.8/LinearAlgebra/src/lu.jl:409
  [6] _ldiv!
    @ ~/.julia/packages/LinearSolve/E7qHt/src/factorization.jl:5 [inlined]
  [7] #solve#6
    @ ~/.julia/packages/LinearSolve/E7qHt/src/factorization.jl:21 [inlined]
  [8] solve(cache::LinearSolve.LinearCache{Matrix{Float64}, Vector{Int64}, Vector{Int64}, SciMLBase.NullParameters, Nothing, LinearAlgebra.LU{Float64, Matrix{Float64}, Vector{Int64}}, IterativeSolvers.Identity, IterativeSolvers.Identity, Float64, Nothing}, alg::GenericLUFactorization{LinearAlgebra.RowMaximum})
    @ LinearSolve ~/.julia/packages/LinearSolve/E7qHt/src/factorization.jl:16
  [9] solve(::LinearSolve.LinearCache{Matrix{Float64}, Vector{Int64}, Vector{Int64}, SciMLBase.NullParameters, Nothing, LinearAlgebra.LU{Float64, Matrix{Float64}, Vector{Int64}}, IterativeSolvers.Identity, IterativeSolvers.Identity, Float64, Nothing}, ::Nothing; assumptions::LinearSolve.OperatorAssumptions{Nothing}, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ LinearSolve ~/.julia/packages/LinearSolve/E7qHt/src/default.jl:145
 [10] solve
    @ ~/.julia/packages/LinearSolve/E7qHt/src/default.jl:141 [inlined]
 [11] #solve#5
    @ ~/.julia/packages/LinearSolve/E7qHt/src/common.jl:158 [inlined]
 [12] solve(::LinearSolve.LinearCache{Matrix{Float64}, Vector{Int64}, Vector{Int64}, SciMLBase.NullParameters, Nothing, LinearAlgebra.LU{Float64, Matrix{Float64}, Vector{Int64}}, IterativeSolvers.Identity, IterativeSolvers.Identity, Float64, Nothing})
    @ LinearSolve ~/.julia/packages/LinearSolve/E7qHt/src/common.jl:157
 [13] solve(::LinearProblem{Nothing, true, Matrix{Float64}, Vector{Int64}, SciMLBase.NullParameters, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ LinearSolve ~/.julia/packages/LinearSolve/E7qHt/src/common.jl:148
 [14] solve(::LinearProblem{Nothing, true, Matrix{Float64}, Vector{Int64}, SciMLBase.NullParameters, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}})
    @ LinearSolve ~/.julia/packages/LinearSolve/E7qHt/src/common.jl:147
 [15] top-level scope
    @ REPL[2]:8

(@v1.8) pkg> st LinearSolve
Status `~/.julia/environments/v1.8/Project.toml`
  [7ed4a6bd] LinearSolve v1.26.1

julia> versioninfo()
Julia Version 1.8.2
Commit 36034abf260 (2022-09-29 15:21 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, skylake)
  Threads: 1 on 8 virtual cores

Anyone knows what goes wrong?

make b = Float64[0, 0, 1, 0] right now. you are to store the solution in a Vector{Int} but the solution isn’t integral.

Thanks, that fixed it! Maybe a more helpful error could be provided?

probably. want to file an issue?

Sure :slight_smile: