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

Change typeof(x) <: y to x isa y #66

Merged
merged 1 commit into from
Nov 2, 2023
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
26 changes: 13 additions & 13 deletions src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function DiffEqBase.__solve(prob::DiffEqBase.AbstractSteadyStateProblem,
for more details.
"""

if typeof(prob.u0) <: Number
if prob.u0 isa Number
u0 = [prob.u0]
else
u0 = vec(deepcopy(prob.u0))
Expand All @@ -25,27 +25,27 @@ function DiffEqBase.__solve(prob::DiffEqBase.AbstractSteadyStateProblem,
sizeu = size(prob.u0)
p = prob.p

if typeof(prob) <: SteadyStateProblem
if prob isa SteadyStateProblem
if !isinplace(prob) &&
(typeof(prob.u0) <: AbstractVector || typeof(prob.u0) <: Number)
(prob.u0 isa AbstractVector || prob.u0 isa Number)
f! = (du, u) -> (du[:] = prob.f(u, p, Inf); nothing)
elseif !isinplace(prob) && typeof(prob.u0) <: AbstractArray
elseif !isinplace(prob) && prob.u0 isa AbstractArray
f! = (du, u) -> (du[:] = vec(prob.f(reshape(u, sizeu), p, Inf)); nothing)
elseif typeof(prob.u0) <: AbstractVector
elseif prob.u0 isa AbstractVector
f! = (du, u) -> (prob.f(du, u, p, Inf); nothing)
else # Then it's an in-place function on an abstract array
f! = (du, u) -> (prob.f(reshape(du, sizeu),
reshape(u, sizeu), p, Inf);
du = vec(du);
nothing)
end
elseif typeof(prob) <: NonlinearProblem
elseif prob isa NonlinearProblem
if !isinplace(prob) &&
(typeof(prob.u0) <: AbstractVector || typeof(prob.u0) <: Number)
(prob.u0 isa AbstractVector || prob.u0 isa Number)
f! = (du, u) -> (du[:] = prob.f(u, p); nothing)
elseif !isinplace(prob) && typeof(prob.u0) <: AbstractArray
elseif !isinplace(prob) && prob.u0 isa AbstractArray
f! = (du, u) -> (du[:] = vec(prob.f(reshape(u, sizeu), p)); nothing)
elseif typeof(prob.u0) <: AbstractVector
elseif prob.u0 isa AbstractVector
f! = (du, u) -> (prob.f(du, u, p); nothing)
else # Then it's an in-place function on an abstract array
f! = (du, u) -> (prob.f(reshape(du, sizeu),
Expand All @@ -58,9 +58,9 @@ function DiffEqBase.__solve(prob::DiffEqBase.AbstractSteadyStateProblem,
# du = similar(u)
# f = (u) -> (f!(du,u); du) # out-of-place version

if typeof(alg) <: SSRootfind
if alg isa SSRootfind
original = alg.nlsolve(f!, u0, abstol)
if typeof(original) <: NLsolve.SolverResults
if original isa NLsolve.SolverResults
u = reshape(original.zero, sizeu)
resid = similar(u)
f!(resid, u)
Expand All @@ -83,9 +83,9 @@ function DiffEqBase.__solve(prob::DiffEqBase.AbstractSteadyStateProblem,
tspan = alg.tspan isa Tuple ? alg.tspan :
convert.(DiffEqBase.value(real(eltype(prob.u0))),
(DiffEqBase.value(zero(alg.tspan)), alg.tspan))
if typeof(prob) <: SteadyStateProblem
if prob isa SteadyStateProblem
f = prob.f
elseif typeof(prob) <: NonlinearProblem
elseif prob isa NonlinearProblem
if isinplace(prob)
f = (du, u, p, t) -> prob.f(du, u, p)
else
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sol = solve(prob,
iterations = Int(1e6),
ftol = abstol))))
@test sol.retcode == ReturnCode.Success
@test typeof(sol.original) <: NLsolve.SolverResults
@test sol.original isa NLsolve.SolverResults

f(du, sol.u, nothing, 0)
@test du == [0, 0]
Expand Down
Loading