Skip to content

Commit

Permalink
Merge pull request #175 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 authored Nov 2, 2023
2 parents 025dfe9 + 10518f8 commit 69c684c
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/autoabstol.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ mutable struct AutoAbstolAffect{T}
end
# Now make `affect!` for this:
function (p::AutoAbstolAffect)(integrator)
if typeof(p.curmax) <: AbstractArray
if p.curmax isa AbstractArray
@. p.curmax = max(p.curmax, abs(integrator.u))
else
p.curmax = max(p.curmax, maximum(abs.(integrator.u)))
end

if typeof(integrator.opts.abstol) <: AbstractArray
if integrator.opts.abstol isa AbstractArray
integrator.opts.abstol .= p.curmax .* integrator.opts.reltol
else
integrator.opts.abstol = p.curmax .* integrator.opts.reltol
Expand Down
12 changes: 6 additions & 6 deletions src/domain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function affect!(integrator, f::AbstractDomainAffect{T, S, uType}) where {T, S,

# define array of next time step, absolute tolerance, and scale factor
if uType <: Nothing
if typeof(integrator.u) <: Union{Number, StaticArraysCore.SArray}
if integrator.u isa Union{Number, StaticArraysCore.SArray}
u = integrator.u
else
u = similar(integrator.u)
Expand Down Expand Up @@ -73,7 +73,7 @@ function affect!(integrator, f::AbstractDomainAffect{T, S, uType}) where {T, S,
p = integrator.p
while tdir * dt > 0
# calculate estimated value of next step and its residuals
if typeof(u) <: Union{Number, StaticArraysCore.SArray}
if u isa Union{Number, StaticArraysCore.SArray}
u = integrator(t)
else
integrator(u, t)
Expand Down Expand Up @@ -186,7 +186,7 @@ end

# create array of residuals
function setup(f::GeneralDomainAffect, integrator)
typeof(f.resid) <: Nothing ? (similar(integrator.u),) : (f.resid,)
f.resid isa Nothing ? (similar(integrator.u),) : (f.resid,)
end

function isaccepted(u, p, t, abstol, f::GeneralDomainAffect{autonomous, F, T, S, uType},
Expand All @@ -199,7 +199,7 @@ function isaccepted(u, p, t, abstol, f::GeneralDomainAffect{autonomous, F, T, S,
end

# accept time step if residuals are smaller than the tolerance
if typeof(abstol) <: Number
if abstol isa Number
all(x -> x < abstol, resid)
else
# element-wise comparison
Expand Down Expand Up @@ -267,7 +267,7 @@ function GeneralDomain(g, u = nothing; nlsolve = NLSOLVEJL_SETUP(), save = true,
abstol = nothing, scalefactor = nothing,
autonomous = maximum(SciMLBase.numargs(g)) == 3,
nlopts = Dict(:ftol => 10 * eps()))
if typeof(u) <: Nothing
if u isa Nothing
affect! = GeneralDomainAffect{autonomous}(g, abstol, scalefactor, nothing, nothing)
else
affect! = GeneralDomainAffect{autonomous}(g, abstol, scalefactor, deepcopy(u),
Expand Down Expand Up @@ -341,7 +341,7 @@ Non-negative solutions of ODEs. Applied Mathematics and Computation 170
(2005): 556-569.
"""
function PositiveDomain(u = nothing; save = true, abstol = nothing, scalefactor = nothing)
if typeof(u) <: Nothing
if u isa Nothing
affect! = PositiveDomainAffect(abstol, scalefactor, nothing)
else
affect! = PositiveDomainAffect(abstol, scalefactor, deepcopy(u))
Expand Down
2 changes: 1 addition & 1 deletion src/function_caller.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function (affect!::FunctionCallingAffect)(integrator, force_func = false)
# Expand lazy dense for interpolation
DiffEqBase.addsteps!(integrator)
end
if typeof(integrator.u) <: Union{Number, StaticArraysCore.SArray}
if integrator.u isa Union{Number, StaticArraysCore.SArray}
curu = integrator(curt)
else
curu = first(get_tmp_cache(integrator))
Expand Down
2 changes: 1 addition & 1 deletion src/integrating.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ end

function (affect!::SavingIntegrandAffect)(integrator)
n = 0
if typeof(integrator.sol.prob) <: Union{SDEProblem, RODEProblem}
if integrator.sol.prob isa Union{SDEProblem, RODEProblem}
n = 10
else
n = div(SciMLBase.alg_order(integrator.alg) + 1, 2)
Expand Down
2 changes: 1 addition & 1 deletion src/integrating_sum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ end

function (affect!::SavingIntegrandSumAffect)(integrator)
n = 0
if typeof(integrator.sol.prob) <: Union{SDEProblem, RODEProblem}
if integrator.sol.prob isa Union{SDEProblem, RODEProblem}
n = 10
else
n = div(SciMLBase.alg_order(integrator.alg) + 1, 2)
Expand Down
6 changes: 3 additions & 3 deletions src/terminatesteadystate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ function allDerivPass(integrator, abstol, reltol, min_t)
if DiffEqBase.isinplace(integrator.sol.prob)
testval = first(get_tmp_cache(integrator))
DiffEqBase.get_du!(testval, integrator)
if typeof(integrator.sol.prob) <: DiffEqBase.DiscreteProblem
if integrator.sol.prob isa DiffEqBase.DiscreteProblem
@. testval = testval - integrator.u
end
else
testval = get_du(integrator)
if typeof(integrator.sol.prob) <: DiffEqBase.DiscreteProblem
if integrator.sol.prob isa DiffEqBase.DiscreteProblem
testval = testval - integrator.u
end
end

if typeof(integrator.u) <: Array
if integrator.u isa Array
any(abs(d) > abstol && abs(d) > reltol * abs(u)
for (d, abstol, reltol, u) in zip(testval, Iterators.cycle(abstol),
Iterators.cycle(reltol), integrator.u)) &&
Expand Down

0 comments on commit 69c684c

Please sign in to comment.