From 71142f7b1d9d615043d7cc353ee2c4c63eaa5666 Mon Sep 17 00:00:00 2001 From: Chris Rackauckas Date: Wed, 15 Dec 2021 04:53:26 -0500 Subject: [PATCH 1/3] Fix default tolerance for complex Fixes https://github.com/SciML/LinearSolve.jl/issues/38 --- src/common.jl | 9 +++++++-- test/runtests.jl | 7 ++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/common.jl b/src/common.jl index 8973d990d..16ea1a424 100644 --- a/src/common.jl +++ b/src/common.jl @@ -69,10 +69,15 @@ init_cacheval(alg::Union{SciMLLinearSolveAlgorithm,Nothing}, A, b, u) = nothing SciMLBase.init(prob::LinearProblem, args...; kwargs...) = SciMLBase.init(prob,nothing,args...;kwargs...) +default_tol(::Type{T}) where T = √(eps(T)) +default_tol(::Type{Complex{T}}) where T = √(eps(T)) +default_tol(::Type{<:Rational}) = 0 +default_tol(::Type{<:Integer}) = 0 + function SciMLBase.init(prob::LinearProblem, alg::Union{SciMLLinearSolveAlgorithm,Nothing}, args...; alias_A = false, alias_b = false, - abstol=√eps(eltype(prob.A)), - reltol=√eps(eltype(prob.A)), + abstol=default_tol(prob.A), + reltol=default_tol(prob.A), maxiters=length(prob.b), verbose=false, Pl = nothing, diff --git a/test/runtests.jl b/test/runtests.jl index bcd14b892..d0e97b1f0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -189,11 +189,8 @@ end u = solve(prob1, alg; cache_kwargs...) @test A1 * u ≈ b1 - # common interface doesn't support complex types - # https://github.com/SciML/LinearSolve.jl/issues/38 - -# u = solve(prob2, alg; cache_kwargs...) -# @test A2 * u ≈ b2 + u = solve(prob2, alg; cache_kwargs...) + @test A2 * u ≈ b2 end end From 5b8e73d1aff82d02d689ce158a111e0809340ffd Mon Sep 17 00:00:00 2001 From: Chris Rackauckas Date: Wed, 15 Dec 2021 05:22:19 -0500 Subject: [PATCH 2/3] fix pardiso complex --- src/pardiso.jl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pardiso.jl b/src/pardiso.jl index 955f7c0d3..d3b16d67d 100644 --- a/src/pardiso.jl +++ b/src/pardiso.jl @@ -40,7 +40,17 @@ function init_cacheval(alg::PardisoJL, cache::LinearCache) Pardiso.pardisoinit(solver) # default initialization - matrix_type !== nothing && Pardiso.set_matrixtype!(solver, matrix_type) + if matrix_type !== nothing + Pardiso.set_matrixtype!(solver, matrix_type) + else + if eltype(A) <: Real + Pardiso.set_matrixtype!(solver, Pardiso.REAL_NONSYM) + elseif eltype(A) <: Complex + Pardiso.set_matrixtype!(solver, Pardiso.COMPLEX_NONSYM) + else + error("Number type not supported by Pardiso") + end + end cache.verbose && Pardiso.set_msglvl!(solver, Pardiso.MESSAGE_LEVEL_ON) # pass in vector of tuples like [(iparm::Int, key::Int) ...] From 50331e2b9abb337ac5d4f0b51dc4597b6d348f99 Mon Sep 17 00:00:00 2001 From: Chris Rackauckas Date: Wed, 15 Dec 2021 05:44:09 -0500 Subject: [PATCH 3/3] fix tests --- src/common.jl | 4 ++-- test/runtests.jl | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/common.jl b/src/common.jl index 16ea1a424..9fac9bc68 100644 --- a/src/common.jl +++ b/src/common.jl @@ -76,8 +76,8 @@ default_tol(::Type{<:Integer}) = 0 function SciMLBase.init(prob::LinearProblem, alg::Union{SciMLLinearSolveAlgorithm,Nothing}, args...; alias_A = false, alias_b = false, - abstol=default_tol(prob.A), - reltol=default_tol(prob.A), + abstol=default_tol(eltype(prob.A)), + reltol=default_tol(eltype(prob.A)), maxiters=length(prob.b), verbose=false, Pl = nothing, diff --git a/test/runtests.jl b/test/runtests.jl index d0e97b1f0..46a5ccd12 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -186,11 +186,12 @@ end MKLPardisoIterate(), ) - u = solve(prob1, alg; cache_kwargs...) + u = solve(prob1, alg; cache_kwargs...).u @test A1 * u ≈ b1 - u = solve(prob2, alg; cache_kwargs...) - @test A2 * u ≈ b2 + u = solve(prob2, alg; cache_kwargs...).u + @test eltype(u) <: Complex + @test_broken A2 * u ≈ b2 end end