Skip to content

Commit

Permalink
Merge pull request #70 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 8, 2023
2 parents e22c16a + 8cc9f96 commit 03ab5e4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
10 changes: 5 additions & 5 deletions src/integrators/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ end
step_accept_controller!(integrator, getalg(integrator.alg))
integrator.last_stepfail = false
integrator.tprev = integrator.t
if typeof(integrator.t) <: AbstractFloat && !isempty(integrator.opts.tstops)
if integrator.t isa AbstractFloat && !isempty(integrator.opts.tstops)
tstop = integrator.tdir * first(integrator.opts.tstops)
@fastmath abs(ttmp - tstop) < 10eps(integrator.t) ? (integrator.t = tstop) :
(integrator.t = ttmp)
Expand All @@ -60,7 +60,7 @@ end
end
else # Non adaptive
integrator.tprev = integrator.t
if typeof(integrator.t) <: AbstractFloat && !isempty(integrator.opts.tstops)
if integrator.t isa AbstractFloat && !isempty(integrator.opts.tstops)
tstop = integrator.tdir * first(integrator.opts.tstops)
# For some reason 10eps(integrator.t) is slow here
# TODO: Allow higher precision but profile
Expand Down Expand Up @@ -328,7 +328,7 @@ end
save_val = val
copyat_or_push!(integrator.sol.t, integrator.saveiter, curt)
copyat_or_push!(integrator.sol.u, integrator.saveiter, save_val, Val{false})
if typeof(integrator.alg) <: StochasticDiffEq.StochasticDiffEqCompositeAlgorithm
if integrator.alg isa StochasticDiffEq.StochasticDiffEqCompositeAlgorithm
copyat_or_push!(integrator.sol.alg_choice, integrator.saveiter,
integrator.cache.current)
end
Expand All @@ -341,7 +341,7 @@ end
copyat_or_push!(integrator.sol.u, integrator.saveiter,
integrator.u[integrator.opts.save_idxs], Val{false})
end
if typeof(integrator.alg) <:
if integrator.alg isa
Union{StochasticDiffEq.StochasticDiffEqCompositeAlgorithm,
StochasticDiffEq.StochasticDiffEqRODECompositeAlgorithm}
copyat_or_push!(integrator.sol.alg_choice, integrator.saveiter,
Expand All @@ -359,7 +359,7 @@ end
integrator.u[integrator.opts.save_idxs], Val{false})
end
copyat_or_push!(integrator.sol.t, integrator.saveiter, integrator.t)
if typeof(integrator.alg) <:
if integrator.alg isa
Union{StochasticDiffEq.StochasticDiffEqCompositeAlgorithm,
StochasticDiffEq.StochasticDiffEqRODECompositeAlgorithm}
copyat_or_push!(integrator.sol.alg_choice, integrator.saveiter,
Expand Down
2 changes: 1 addition & 1 deletion src/integrators/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function handle_discontinuities!(integrator::SDDEIntegrator)
# remove all discontinuities close to the current time point as well and
# calculate minimal order of these discontinuities
# integrator.EEst has unitless type of integrator.t
if typeof(integrator.EEst) <: AbstractFloat
if integrator.EEst isa AbstractFloat
maxΔt = 10eps(integrator.t)

while !isempty(integrator.opts.d_discontinuities) &&
Expand Down
24 changes: 12 additions & 12 deletions src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ function DiffEqBase.__init(prob::AbstractSDDEProblem,# TODO DiffEqBasee.Abstract
Rational{Int}}[],
save_idxs = nothing,
save_everystep = isempty(saveat),
save_noise = save_everystep && (typeof(prob.f) <: Tuple ?
save_noise = save_everystep && (prob.f isa Tuple ?
DiffEqBase.has_analytic(prob.f[1]) :
DiffEqBase.has_analytic(prob.f)),
save_on = true,
save_start = save_everystep || isempty(saveat) ||
typeof(saveat) <: Number ? true :
saveat isa Number ? true :
prob.tspan[1] in saveat,
save_end = nothing,
callback = nothing,
Expand Down Expand Up @@ -68,7 +68,7 @@ function DiffEqBase.__init(prob::AbstractSDDEProblem,# TODO DiffEqBasee.Abstract
discontinuity_reltol = 0, kwargs...) where {recompile_flag}

# alg = getalg(alg0);
if typeof(prob.f) <: Tuple
if prob.f isa Tuple
if any(mm != I for mm in prob.f.mass_matrix)
error("This solver is not able to use mass matrices.")
end
Expand All @@ -80,7 +80,7 @@ function DiffEqBase.__init(prob::AbstractSDDEProblem,# TODO DiffEqBasee.Abstract
@warn("Dense output is incompatible with saveat. Please use the SavingCallback from the Callback Library to mix the two behaviors.")
end

if typeof(prob.noise) <: NoiseProcess && prob.noise.bridge === nothing && adaptive
if prob.noise isa NoiseProcess && prob.noise.bridge === nothing && adaptive
error("Bridge function must be given for adaptivity. Either declare this function in noise process or set adaptive=false")
end

Expand Down Expand Up @@ -156,9 +156,9 @@ function DiffEqBase.__init(prob::AbstractSDDEProblem,# TODO DiffEqBasee.Abstract
reltol_internal = real.(reltol)
end

if isinplace(prob) && typeof(u) <: AbstractArray && eltype(u) <: Number &&
if isinplace(prob) && u isa AbstractArray && eltype(u) <: Number &&
uBottomEltypeNoUnits == uBottomEltype # Could this be more efficient for other arrays?
if !(typeof(u) <: ArrayPartition)
if !(u isa ArrayPartition)
rate_prototype = recursivecopy(u)
else
rate_prototype = similar(u,
Expand All @@ -185,7 +185,7 @@ function DiffEqBase.__init(prob::AbstractSDDEProblem,# TODO DiffEqBasee.Abstract
end

#= TODO: Jump handling
if typeof(_prob) <: JumpProblem && _prob.regular_jump !== nothing
if _prob isa JumpProblem && _prob.regular_jump !== nothing
if !isnothing(_prob.regular_jump.mark_dist) == nothing # https://github.com/JuliaDiffEq/DifferentialEquations.jl/issues/250
error("Mark distributions are currently not supported in SimpleTauLeaping")
Expand Down Expand Up @@ -256,7 +256,7 @@ function DiffEqBase.__init(prob::AbstractSDDEProblem,# TODO DiffEqBasee.Abstract
else
randElType = uBottomEltypeNoUnits # Strip units and type info
if StochasticDiffEq.is_diagonal_noise(prob)
if typeof(u) <: SArray
if u isa SArray
rand_prototype = zero(u) # TODO: Array{randElType} for units
else
rand_prototype = (u .- u) ./ sqrt(oneunit(t))
Expand Down Expand Up @@ -306,7 +306,7 @@ function DiffEqBase.__init(prob::AbstractSDDEProblem,# TODO DiffEqBasee.Abstract
reinit!(W, t)
end
# Reseed
if typeof(W) <: NoiseProcess && W.reseed
if W isa NoiseProcess && W.reseed
Random.seed!(W.rng, _seed)
end
elseif W.t[end] != t
Expand Down Expand Up @@ -489,7 +489,7 @@ function DiffEqBase.__init(prob::AbstractSDDEProblem,# TODO DiffEqBasee.Abstract
StochasticDiffEq.initialize_callbacks!(integrator, initialize_save)
initialize!(integrator, integrator.cache)

save_start && typeof(alg) <: StochasticDiffEq.StochasticDiffEqCompositeAlgorithm &&
save_start && alg isa StochasticDiffEq.StochasticDiffEqCompositeAlgorithm &&
copyat_or_push!(alg_choice, 1, integrator.cache.current)
end

Expand Down Expand Up @@ -527,7 +527,7 @@ function DiffEqBase.solve!(integrator::SDDEIntegrator)
end
postamble!(integrator)

f = typeof(integrator.sol.prob.f) <: Tuple ? integrator.sol.prob.f[1] :
f = integrator.sol.prob.f isa Tuple ? integrator.sol.prob.f[1] :
integrator.sol.prob.f

if DiffEqBase.has_analytic(f)
Expand Down Expand Up @@ -589,7 +589,7 @@ function tstop_saveat_disc_handling(tstops, saveat, d_discontinuities, tspan,

# saving time points
saveat_internal = BinaryMinHeap{tType}()
if typeof(saveat) <: Number
if saveat isa Number
if (t0:saveat:tf)[end] == tf
for t in (t0 + saveat):saveat:tf
push!(saveat_internal, tdir * t)
Expand Down
6 changes: 3 additions & 3 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function has_dependent_lags(prob::SDDEProblem)
end

function u_uprev(u0; alias_u0 = false)
if typeof(u0) <: Tuple
if u0 isa Tuple
u = ArrayPartition(prob.u0, Val{true})
else
if alias_u0
Expand Down Expand Up @@ -247,10 +247,10 @@ end

function unwrap_alg(integrator::SDDEIntegrator, is_stiff)
alg = integrator.alg
iscomp = typeof(alg) <: StochasticDiffEq.StochasticCompositeAlgorithm
iscomp = alg isa StochasticDiffEq.StochasticCompositeAlgorithm
if !iscomp
return alg
elseif typeof(alg.choice_function) <: DiffEqBase.AutoSwitch
elseif alg.choice_function isa DiffEqBase.AutoSwitch
num = is_stiff ? 2 : 1
return alg.algs[num]
else
Expand Down

0 comments on commit 03ab5e4

Please sign in to comment.