Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default tolerance for complex #58

Merged
merged 3 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(eltype(prob.A)),
reltol=default_tol(eltype(prob.A)),
maxiters=length(prob.b),
verbose=false,
Pl = nothing,
Expand Down
12 changes: 11 additions & 1 deletion src/pardiso.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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) ...]
Expand Down
10 changes: 4 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,12 @@ end
MKLPardisoIterate(),
)

u = solve(prob1, alg; cache_kwargs...)
u = solve(prob1, alg; cache_kwargs...).u
@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...).u
@test eltype(u) <: Complex
@test_broken A2 * u b2
end

end
Expand Down