From 10518f8ea5e854f959888325609e2b25330bdd59 Mon Sep 17 00:00:00 2001 From: Pepijn de Vos Date: Thu, 2 Nov 2023 18:20:46 +0100 Subject: [PATCH] Change typeof(x) <: y to x isa y --- src/autoabstol.jl | 4 ++-- src/domain.jl | 12 ++++++------ src/function_caller.jl | 2 +- src/integrating.jl | 2 +- src/integrating_sum.jl | 2 +- src/terminatesteadystate.jl | 6 +++--- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/autoabstol.jl b/src/autoabstol.jl index d8bad948..367712a7 100644 --- a/src/autoabstol.jl +++ b/src/autoabstol.jl @@ -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 diff --git a/src/domain.jl b/src/domain.jl index 7e39e4b8..0b0e9bc1 100644 --- a/src/domain.jl +++ b/src/domain.jl @@ -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) @@ -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) @@ -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}, @@ -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 @@ -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), @@ -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)) diff --git a/src/function_caller.jl b/src/function_caller.jl index 345fd892..960af226 100644 --- a/src/function_caller.jl +++ b/src/function_caller.jl @@ -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)) diff --git a/src/integrating.jl b/src/integrating.jl index 9bd76fe6..dc58e3d8 100644 --- a/src/integrating.jl +++ b/src/integrating.jl @@ -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) diff --git a/src/integrating_sum.jl b/src/integrating_sum.jl index 72cf8303..cc13cf20 100644 --- a/src/integrating_sum.jl +++ b/src/integrating_sum.jl @@ -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) diff --git a/src/terminatesteadystate.jl b/src/terminatesteadystate.jl index e10eaf26..ec3ed31b 100644 --- a/src/terminatesteadystate.jl +++ b/src/terminatesteadystate.jl @@ -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)) &&