Skip to content

Commit

Permalink
Merge pull request #66 from pepijndevos/new-branch
Browse files Browse the repository at this point in the history
Change typeof(x) <: y to x isa y
  • Loading branch information
ChrisRackauckas committed Nov 2, 2023
2 parents 676de5d + 040cfcf commit 5bcf372
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
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

0 comments on commit 5bcf372

Please sign in to comment.