Skip to content

Commit e2fb383

Browse files
Merge pull request #58 from SciML/complex
Fix default tolerance for complex
2 parents d8054e0 + 50331e2 commit e2fb383

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

src/common.jl

+7-2
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,15 @@ init_cacheval(alg::Union{SciMLLinearSolveAlgorithm,Nothing}, A, b, u) = nothing
6969

7070
SciMLBase.init(prob::LinearProblem, args...; kwargs...) = SciMLBase.init(prob,nothing,args...;kwargs...)
7171

72+
default_tol(::Type{T}) where T = (eps(T))
73+
default_tol(::Type{Complex{T}}) where T = (eps(T))
74+
default_tol(::Type{<:Rational}) = 0
75+
default_tol(::Type{<:Integer}) = 0
76+
7277
function SciMLBase.init(prob::LinearProblem, alg::Union{SciMLLinearSolveAlgorithm,Nothing}, args...;
7378
alias_A = false, alias_b = false,
74-
abstol=eps(eltype(prob.A)),
75-
reltol=eps(eltype(prob.A)),
79+
abstol=default_tol(eltype(prob.A)),
80+
reltol=default_tol(eltype(prob.A)),
7681
maxiters=length(prob.b),
7782
verbose=false,
7883
Pl = nothing,

src/pardiso.jl

+11-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,17 @@ function init_cacheval(alg::PardisoJL, cache::LinearCache)
4040

4141
Pardiso.pardisoinit(solver) # default initialization
4242

43-
matrix_type !== nothing && Pardiso.set_matrixtype!(solver, matrix_type)
43+
if matrix_type !== nothing
44+
Pardiso.set_matrixtype!(solver, matrix_type)
45+
else
46+
if eltype(A) <: Real
47+
Pardiso.set_matrixtype!(solver, Pardiso.REAL_NONSYM)
48+
elseif eltype(A) <: Complex
49+
Pardiso.set_matrixtype!(solver, Pardiso.COMPLEX_NONSYM)
50+
else
51+
error("Number type not supported by Pardiso")
52+
end
53+
end
4454
cache.verbose && Pardiso.set_msglvl!(solver, Pardiso.MESSAGE_LEVEL_ON)
4555

4656
# pass in vector of tuples like [(iparm::Int, key::Int) ...]

test/runtests.jl

+4-6
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,12 @@ end
186186
MKLPardisoIterate(),
187187
)
188188

189-
u = solve(prob1, alg; cache_kwargs...)
189+
u = solve(prob1, alg; cache_kwargs...).u
190190
@test A1 * u b1
191191

192-
# common interface doesn't support complex types
193-
# https://github.com/SciML/LinearSolve.jl/issues/38
194-
195-
# u = solve(prob2, alg; cache_kwargs...)
196-
# @test A2 * u ≈ b2
192+
u = solve(prob2, alg; cache_kwargs...).u
193+
@test eltype(u) <: Complex
194+
@test_broken A2 * u b2
197195
end
198196

199197
end

0 commit comments

Comments
 (0)