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

replace typeof(x) <: with x isa #2047

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
14 changes: 7 additions & 7 deletions src/adams_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function ϕ_and_ϕstar!(cache, du, k)
ξ = dt = dts[1]
ξ0 = zero(dt)
β[1] = one(dt)
if typeof(cache) <: OrdinaryDiffEqMutableCache
if cache isa OrdinaryDiffEqMutableCache
ϕ_n[1] .= du
ϕstar_n[1] .= du
else
Expand All @@ -18,7 +18,7 @@ function ϕ_and_ϕstar!(cache, du, k)
ξ0 += dts[i]
β[i] = β[i - 1] * ξ / ξ0
ξ += dts[i]
if typeof(cache) <: OrdinaryDiffEqMutableCache
if cache isa OrdinaryDiffEqMutableCache
@.. broadcast=false ϕ_n[i]=ϕ_n[i - 1] - ϕstar_nm1[i - 1]
@.. broadcast=false ϕstar_n[i]=β[i] * ϕ_n[i]
else
Expand All @@ -35,7 +35,7 @@ function ϕ_and_ϕstar!(cache::Union{VCABMConstantCache, VCABMCache}, du, k)
ξ = dt = dts[1]
ξ0 = zero(dt)
β[1] = one(dt)
if typeof(cache) <: OrdinaryDiffEqMutableCache
if cache isa OrdinaryDiffEqMutableCache
ϕ_n[1] .= du
ϕstar_n[1] .= du
else
Expand All @@ -46,7 +46,7 @@ function ϕ_and_ϕstar!(cache::Union{VCABMConstantCache, VCABMCache}, du, k)
ξ0 += dts[i]
β[i] = β[i - 1] * ξ / ξ0
ξ += dts[i]
if typeof(cache) <: OrdinaryDiffEqMutableCache
if cache isa OrdinaryDiffEqMutableCache
@.. broadcast=false ϕ_n[i]=ϕ_n[i - 1] - ϕstar_nm1[i - 1]
@.. broadcast=false ϕstar_n[i]=β[i] * ϕ_n[i]
else
Expand All @@ -63,7 +63,7 @@ function expand_ϕ_and_ϕstar!(cache, i)
@unpack ξ, ξ0, β, dts, ϕstar_nm1, ϕ_n, ϕstar_n = cache
ξ0 += dts[i]
β[i] = β[i - 1] * ξ / ξ0
if typeof(cache) <: OrdinaryDiffEqMutableCache
if cache isa OrdinaryDiffEqMutableCache
@.. broadcast=false ϕ_n[i]=ϕ_n[i - 1] - ϕstar_nm1[i - 1]
@.. broadcast=false ϕstar_n[i]=β[i] * ϕ_n[i]
else
Expand All @@ -77,13 +77,13 @@ function ϕ_np1!(cache, du_np1, k)
@unpack ϕ_np1, ϕstar_n = cache
for i in 1:k
if i != 1
if typeof(cache) <: OrdinaryDiffEqMutableCache
if cache isa OrdinaryDiffEqMutableCache
@.. broadcast=false ϕ_np1[i]=ϕ_np1[i - 1] - ϕstar_n[i - 1]
else
ϕ_np1[i] = ϕ_np1[i - 1] - ϕstar_n[i - 1]
end
else
if typeof(cache) <: OrdinaryDiffEqMutableCache
if cache isa OrdinaryDiffEqMutableCache
ϕ_np1[i] .= du_np1
else
ϕ_np1[i] = du_np1
Expand Down
12 changes: 6 additions & 6 deletions src/alg_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ function DiffEqBase.prepare_alg(alg::Union{
elseif (prob isa ODEProblem || prob isa DDEProblem) &&
(prob.f.mass_matrix === nothing ||
(prob.f.mass_matrix !== nothing &&
!(typeof(prob.f.jac_prototype) <: AbstractSciMLOperator)))
!(prob.f.jac_prototype isa AbstractSciMLOperator)))
linsolve = LinearSolve.defaultalg(prob.f.jac_prototype, u0)
else
# If mm is a sparse matrix and A is a MatrixOperator, then let linear
Expand Down Expand Up @@ -793,7 +793,7 @@ function default_controller(alg::Union{ExtrapolationMidpointDeuflhard,
end

function _digest_beta1_beta2(alg, cache, ::Val{QT}, _beta1, _beta2) where {QT}
if typeof(alg) <: OrdinaryDiffEqCompositeAlgorithm
if alg isa OrdinaryDiffEqCompositeAlgorithm
beta2 = _beta2 === nothing ?
_composite_beta2_default(alg.algs, cache.current, Val(QT)) : _beta2
beta1 = _beta1 === nothing ?
Expand Down Expand Up @@ -966,10 +966,10 @@ alg_can_repeat_jac(alg::OrdinaryDiffEqNewtonAdaptiveAlgorithm) = true
alg_can_repeat_jac(alg::IRKC) = false

function unwrap_alg(alg::SciMLBase.DEAlgorithm, is_stiff)
iscomp = typeof(alg) <: CompositeAlgorithm
iscomp = alg isa CompositeAlgorithm
if !iscomp
return alg
elseif typeof(alg.choice_function) <: AutoSwitchCache
elseif alg.choice_function isa AutoSwitchCache
if is_stiff === nothing
throwautoswitch(alg)
end
Expand All @@ -986,10 +986,10 @@ end

function unwrap_alg(integrator, is_stiff)
alg = integrator.alg
iscomp = typeof(alg) <: CompositeAlgorithm
iscomp = alg isa CompositeAlgorithm
if !iscomp
return alg
elseif typeof(alg.choice_function) <: AutoSwitchCache
elseif alg.choice_function isa AutoSwitchCache
if is_stiff === nothing
throwautoswitch(alg)
end
Expand Down
2 changes: 1 addition & 1 deletion src/caches/extrapolation_caches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ function alg_cache(alg::ImplicitDeuflhardExtrapolation, u, rate_prototype,
end

#Update stage_number by the jacobian size
jac_dim = typeof(rate_prototype) <: Union{CompiledFloats, BigFloat} ? 1 :
jac_dim = rate_prototype isa Union{CompiledFloats, BigFloat} ? 1 :
sum(size(rate_prototype))
stage_number = stage_number .+ jac_dim

Expand Down
10 changes: 5 additions & 5 deletions src/caches/kencarp_kvaerno_caches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function alg_cache(alg::KenCarp3, u, rate_prototype, ::Type{uEltypeNoUnits},
uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(true))
fsalfirst = zero(rate_prototype)

if typeof(f) <: SplitFunction
if f isa SplitFunction
k1 = zero(u)
k2 = zero(u)
k3 = zero(u)
Expand Down Expand Up @@ -228,7 +228,7 @@ function alg_cache(alg::KenCarp4, u, rate_prototype, ::Type{uEltypeNoUnits},
uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(true))
fsalfirst = zero(rate_prototype)

if typeof(f) <: SplitFunction
if f isa SplitFunction
k1 = zero(u)
k2 = zero(u)
k3 = zero(u)
Expand Down Expand Up @@ -368,7 +368,7 @@ function alg_cache(alg::KenCarp5, u, rate_prototype, ::Type{uEltypeNoUnits},
uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(true))
fsalfirst = zero(rate_prototype)

if typeof(f) <: SplitFunction
if f isa SplitFunction
k1 = zero(u)
k2 = zero(u)
k3 = zero(u)
Expand Down Expand Up @@ -455,7 +455,7 @@ function alg_cache(alg::KenCarp47, u, rate_prototype, ::Type{uEltypeNoUnits},
uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(true))
fsalfirst = zero(rate_prototype)

if typeof(f) <: SplitFunction
if f isa SplitFunction
k1 = zero(u)
k2 = zero(u)
k3 = zero(u)
Expand Down Expand Up @@ -542,7 +542,7 @@ function alg_cache(alg::KenCarp58, u, rate_prototype, ::Type{uEltypeNoUnits},
uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(true))
fsalfirst = zero(rate_prototype)

if typeof(f) <: SplitFunction
if f isa SplitFunction
k1 = zero(u)
k2 = zero(u)
k3 = zero(u)
Expand Down
36 changes: 18 additions & 18 deletions src/dense/generic_dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ end
@inline function ode_addsteps!(integrator, f = integrator.f, always_calc_begin = false,
allow_calc_end = true, force_calc_end = false)
cache = integrator.cache
if !(typeof(cache) <: CompositeCache)
if !(cache isa CompositeCache)
_ode_addsteps!(integrator.k, integrator.tprev, integrator.uprev, integrator.u,
integrator.dt, f, integrator.p, cache,
always_calc_begin, allow_calc_end, force_calc_end)
Expand Down Expand Up @@ -88,7 +88,7 @@ end

@inline function ode_interpolant(Θ, integrator::DiffEqBase.DEIntegrator, idxs, deriv)
DiffEqBase.addsteps!(integrator)
if !(typeof(integrator.cache) <: CompositeCache)
if !(integrator.cache isa CompositeCache)
val = ode_interpolant(Θ, integrator.dt, integrator.uprev, integrator.u,
integrator.k, integrator.cache, idxs, deriv)
else
Expand Down Expand Up @@ -120,7 +120,7 @@ end

@inline function ode_interpolant!(val, Θ, integrator::DiffEqBase.DEIntegrator, idxs, deriv)
DiffEqBase.addsteps!(integrator)
if !(typeof(integrator.cache) <: CompositeCache)
if !(integrator.cache isa CompositeCache)
ode_interpolant!(val, Θ, integrator.dt, integrator.uprev, integrator.u,
integrator.k, integrator.cache, idxs, deriv)
else
Expand Down Expand Up @@ -208,7 +208,7 @@ end

@inline function ode_extrapolant!(val, Θ, integrator::DiffEqBase.DEIntegrator, idxs, deriv)
DiffEqBase.addsteps!(integrator)
if !(typeof(integrator.cache) <: CompositeCache)
if !(integrator.cache isa CompositeCache)
ode_interpolant!(val, Θ, integrator.t - integrator.tprev, integrator.uprev2,
integrator.uprev, integrator.k, integrator.cache, idxs, deriv)
else
Expand Down Expand Up @@ -239,7 +239,7 @@ end

@inline function ode_extrapolant(Θ, integrator::DiffEqBase.DEIntegrator, idxs, deriv)
DiffEqBase.addsteps!(integrator)
if !(typeof(integrator.cache) <: CompositeCache)
if !(integrator.cache isa CompositeCache)
ode_interpolant(Θ, integrator.t - integrator.tprev, integrator.uprev2,
integrator.uprev, integrator.k, integrator.cache, idxs, deriv)
else
Expand Down Expand Up @@ -298,12 +298,12 @@ end

function evaluate_interpolant(f, Θ, dt, timeseries, i₋, i₊, cache, idxs,
deriv, ks, ts, id, p)
if typeof(cache) <: (FunctionMapCache) || typeof(cache) <: FunctionMapConstantCache
if cache isa (FunctionMapCache) || cache isa FunctionMapConstantCache
return ode_interpolant(Θ, dt, timeseries[i₋], timeseries[i₊], 0, cache, idxs,
deriv)
elseif !id.dense
return linear_interpolant(Θ, dt, timeseries[i₋], timeseries[i₊], idxs, deriv)
elseif typeof(cache) <: CompositeCache
elseif cache isa CompositeCache
return evaluate_composite_cache(f, Θ, dt, timeseries, i₋, i₊, cache.caches, idxs,
deriv, ks, ts, p, id.alg_choice[i₊])
else
Expand Down Expand Up @@ -367,7 +367,7 @@ function ode_interpolation!(vals, tvals, id::I, idxs, deriv::D, p,
i₊ = 2
# if CompositeCache, have an inplace cache for lower allocations
# (expecting the same algorithms for large portions of ts)
if typeof(cache) <: OrdinaryDiffEq.CompositeCache
if cache isa OrdinaryDiffEq.CompositeCache
current_alg = id.alg_choice[i₊]
cache_i₊ = cache.caches[current_alg]
end
Expand All @@ -389,7 +389,7 @@ function ode_interpolation!(vals, tvals, id::I, idxs, deriv::D, p,
dt = ts[i₊] - ts[i₋]
Θ = iszero(dt) ? oneunit(t) / oneunit(dt) : (t - ts[i₋]) / dt

if typeof(cache) <: (FunctionMapCache) || typeof(cache) <: FunctionMapConstantCache
if cache isa (FunctionMapCache) || cache isa FunctionMapConstantCache
if eltype(vals) <: AbstractArray
ode_interpolant!(vals[j], Θ, dt, timeseries[i₋], timeseries[i₊], 0, cache,
idxs, deriv)
Expand All @@ -405,7 +405,7 @@ function ode_interpolation!(vals, tvals, id::I, idxs, deriv::D, p,
vals[j] = linear_interpolant(Θ, dt, timeseries[i₋], timeseries[i₊], idxs,
deriv)
end
elseif typeof(cache) <: CompositeCache
elseif cache isa CompositeCache
if current_alg != id.alg_choice[i₊] # switched algorithm
current_alg = id.alg_choice[i₊]
@inbounds cache_i₊ = cache.caches[current_alg] # this alloc is costly
Expand Down Expand Up @@ -462,12 +462,12 @@ function ode_interpolation(tval::Number, id::I, idxs, deriv::D, p,
dt = ts[i₊] - ts[i₋]
Θ = iszero(dt) ? oneunit(tval) / oneunit(dt) : (tval - ts[i₋]) / dt

if typeof(cache) <: (FunctionMapCache) || typeof(cache) <: FunctionMapConstantCache
if cache isa (FunctionMapCache) || cache isa FunctionMapConstantCache
val = ode_interpolant(Θ, dt, timeseries[i₋], timeseries[i₊], 0, cache, idxs,
deriv)
elseif !id.dense
val = linear_interpolant(Θ, dt, timeseries[i₋], timeseries[i₊], idxs, deriv)
elseif typeof(cache) <: CompositeCache
elseif cache isa CompositeCache
_ode_addsteps!(ks[i₊], ts[i₋], timeseries[i₋], timeseries[i₊], dt, f, p,
cache.caches[id.alg_choice[i₊]]) # update the kcurrent
val = ode_interpolant(Θ, dt, timeseries[i₋], timeseries[i₊], ks[i₊],
Expand Down Expand Up @@ -510,12 +510,12 @@ function ode_interpolation!(out, tval::Number, id::I, idxs, deriv::D, p,
dt = ts[i₊] - ts[i₋]
Θ = iszero(dt) ? oneunit(tval) / oneunit(dt) : (tval - ts[i₋]) / dt

if typeof(cache) <: (FunctionMapCache) || typeof(cache) <: FunctionMapConstantCache
if cache isa (FunctionMapCache) || cache isa FunctionMapConstantCache
ode_interpolant!(out, Θ, dt, timeseries[i₋], timeseries[i₊], 0, cache, idxs,
deriv)
elseif !id.dense
linear_interpolant!(out, Θ, dt, timeseries[i₋], timeseries[i₊], idxs, deriv)
elseif typeof(cache) <: CompositeCache
elseif cache isa CompositeCache
_ode_addsteps!(ks[i₊], ts[i₋], timeseries[i₋], timeseries[i₊], dt, f, p,
cache.caches[id.alg_choice[i₊]]) # update the kcurrent
ode_interpolant!(out, Θ, dt, timeseries[i₋], timeseries[i₊], ks[i₊],
Expand All @@ -537,7 +537,7 @@ By default, Hermite interpolant so update the derivative at the two ends
function _ode_addsteps!(k, t, uprev, u, dt, f, p, cache, always_calc_begin = false,
allow_calc_end = true, force_calc_end = false)
if length(k) < 2 || always_calc_begin
if typeof(cache) <: OrdinaryDiffEqMutableCache
if cache isa OrdinaryDiffEqMutableCache
rtmp = similar(u, eltype(eltype(k)))
f(rtmp, uprev, p, t)
copyat_or_push!(k, 1, rtmp)
Expand All @@ -560,10 +560,10 @@ end

function ode_interpolant(Θ, dt, y₀, y₁, k, cache::OrdinaryDiffEqMutableCache, idxs,
T::Type{Val{TI}}) where {TI}
if typeof(idxs) <: Number || typeof(y₀) <: Union{Number, SArray}
if idxs isa Number || y₀ isa Union{Number, SArray}
# typeof(y₀) can be these if saveidxs gives a single value
_ode_interpolant(Θ, dt, y₀, y₁, k, cache, idxs, T)
elseif typeof(idxs) <: Nothing
elseif idxs isa Nothing
if y₁ isa Array{<:Number}
out = similar(y₁, eltype(first(y₁) * oneunit(Θ)))
copyto!(out, y₁)
Expand Down Expand Up @@ -592,7 +592,7 @@ end

# If no dispatch found, assume Hermite
function _ode_interpolant(Θ, dt, y₀, y₁, k, cache, idxs, T::Type{Val{TI}}) where {TI}
hermite_interpolant(Θ, dt, y₀, y₁, k, Val{typeof(cache) <: OrdinaryDiffEqMutableCache},
hermite_interpolant(Θ, dt, y₀, y₁, k, Val{cache isa OrdinaryDiffEqMutableCache},
idxs, T)
end

Expand Down
10 changes: 5 additions & 5 deletions src/dense/interpolants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ end
"""
"""
@def owrenzen3unpack begin
if typeof(cache) <: OrdinaryDiffEqMutableCache
if cache isa OrdinaryDiffEqMutableCache
@unpack r13, r12, r23, r22, r33, r32 = cache.tab
else
@unpack r13, r12, r23, r22, r33, r32 = cache
Expand Down Expand Up @@ -891,7 +891,7 @@ end
"""
"""
@def owrenzen4unpack begin
if typeof(cache) <: OrdinaryDiffEqMutableCache
if cache isa OrdinaryDiffEqMutableCache
@unpack r14, r13, r12, r34, r33, r32, r44, r43, r42, r54, r53, r52, r64, r63, r62 = cache.tab
else
@unpack r14, r13, r12, r34, r33, r32, r44, r43, r42, r54, r53, r52, r64, r63, r62 = cache
Expand Down Expand Up @@ -1143,7 +1143,7 @@ end
"""
"""
@def owrenzen5unpack begin
if typeof(cache) <: OrdinaryDiffEqMutableCache
if cache isa OrdinaryDiffEqMutableCache
@unpack r15, r14, r13, r12, r35, r34, r33, r32, r45, r44, r43, r42, r55, r54, r53, r52, r65, r64, r63, r62, r75, r74, r73, r72, r85, r84, r83, r82 = cache.tab
else
@unpack r15, r14, r13, r12, r35, r34, r33, r32, r45, r44, r43, r42, r55, r54, r53, r52, r65, r64, r63, r62, r75, r74, r73, r72, r85, r84, r83, r82 = cache
Expand Down Expand Up @@ -1514,7 +1514,7 @@ end
Coefficients taken from RKSuite
"""
@def bs5unpack begin
if typeof(cache) <: OrdinaryDiffEqMutableCache
if cache isa OrdinaryDiffEqMutableCache
@unpack r016, r015, r014, r013, r012, r036, r035, r034, r033, r032, r046, r045, r044, r043, r042, r056, r055, r054, r053, r052, r066, r065, r064, r063, r062, r076, r075, r074, r073, r072, r086, r085, r084, r083, r082, r096, r095, r094, r093, r106, r105, r104, r103, r102, r116, r115, r114, r113, r112 = cache.tab
else
@unpack r016, r015, r014, r013, r012, r036, r035, r034, r033, r032, r046, r045, r044, r043, r042, r056, r055, r054, r053, r052, r066, r065, r064, r063, r062, r076, r075, r074, r073, r072, r086, r085, r084, r083, r082, r096, r095, r094, r093, r106, r105, r104, r103, r102, r116, r115, r114, r113, r112 = cache
Expand Down Expand Up @@ -2841,7 +2841,7 @@ end
"""
"""
@def dprkn6unpack begin
if typeof(cache) <: OrdinaryDiffEqMutableCache
if cache isa OrdinaryDiffEqMutableCache
@unpack r14, r13, r12, r11, r10, r34, r33, r32, r31, r44, r43, r42, r41, r54, r53, r52, r51, r64, r63, r62, r61, rp14, rp13, rp12, rp11, rp10, rp34, rp33, rp32, rp31, rp44, rp43, rp42, rp41, rp54, rp53, rp52, rp51, rp64, rp63, rp62, rp61 = cache.tab
else
@unpack r14, r13, r12, r11, r10, r34, r33, r32, r31, r44, r43, r42, r41, r54, r53, r52, r51, r64, r63, r62, r61, rp14, rp13, rp12, rp11, rp10, rp34, rp33, rp32, rp31, rp44, rp43, rp42, rp41, rp54, rp53, rp52, rp51, rp64, rp63, rp62, rp61 = cache
Expand Down
2 changes: 1 addition & 1 deletion src/dense/rosenbrock_interpolants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
From MATLAB ODE Suite by Shampine
"""
@def rosenbrock2332unpack begin
if typeof(cache) <: OrdinaryDiffEqMutableCache
if cache isa OrdinaryDiffEqMutableCache
d = cache.tab.d
else
d = cache.d
Expand Down
6 changes: 3 additions & 3 deletions src/dense/stiff_addsteps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function _ode_addsteps!(k, t, uprev, u, dt, f, p,
end

mass_matrix = f.mass_matrix
if typeof(uprev) <: AbstractArray
if uprev isa AbstractArray
J = ForwardDiff.jacobian(uf, uprev)
W = mass_matrix - γ * J
else
Expand Down Expand Up @@ -188,7 +188,7 @@ function _ode_addsteps!(k, t, uprev, u, dt, f, p, cache::Rodas4ConstantCache,

# Jacobian
uf.t = t
if typeof(uprev) <: AbstractArray
if uprev isa AbstractArray
J = ForwardDiff.jacobian(uf, uprev)
W = mass_matrix / dtgamma - J
else
Expand Down Expand Up @@ -574,7 +574,7 @@ function _ode_addsteps!(k, t, uprev, u, dt, f, p, cache::Rosenbrock5ConstantCach

# Jacobian
uf.t = t
if typeof(uprev) <: AbstractArray
if uprev isa AbstractArray
J = ForwardDiff.jacobian(uf, uprev)
W = mass_matrix / dtgamma - J
else
Expand Down
Loading
Loading