Skip to content

Commit

Permalink
Merge pull request #371 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 3, 2023
2 parents cfd5d95 + ec8e2c4 commit 3fd02b0
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/src/jump_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ is:

```julia
JumpProblem(prob, aggregator, jumps::JumpSet;
save_positions = typeof(prob) <: AbstractDiscreteProblem ? (false, true) :
save_positions = prob isa AbstractDiscreteProblem ? (false, true) :
(true, true))
```

Expand Down
4 changes: 2 additions & 2 deletions src/SSA_stepper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ function DiffEqBase.__init(jump_prob::JumpProblem,
interp = DiffEqBase.ConstantInterpolation(t, u))
save_everystep = any(cb.save_positions)

if typeof(saveat) <: Number
if saveat isa Number
_saveat = prob.tspan[1]:saveat:prob.tspan[2]
else
_saveat = saveat
Expand Down Expand Up @@ -277,7 +277,7 @@ function DiffEqBase.step!(integrator::SSAIntegrator)

jump_modified_u = integrator.u_modified

if !(typeof(integrator.opts.callback.discrete_callbacks) <: Tuple{})
if !(integrator.opts.callback.discrete_callbacks isa Tuple{})
discrete_modified, saved_in_cb = DiffEqBase.apply_discrete_callback!(integrator,
integrator.opts.callback.discrete_callbacks...)
else
Expand Down
4 changes: 2 additions & 2 deletions src/aggregators/aggregated_api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ end

function reset_aggregated_jumps!(integrator, uprev, cb::DiscreteCallback, cbs...;
update_jump_params = true, kwargs...)
if typeof(cb.condition) <: AbstractSSAJumpAggregator
if cb.condition isa AbstractSSAJumpAggregator
maj = cb.condition.ma_jumps
update_jump_params && using_params(maj) &&
update_parameters!(cb.condition.ma_jumps, integrator.p; kwargs...)
Expand All @@ -46,7 +46,7 @@ end

function reset_aggregated_jumps!(integrator, uprev, cb::DiscreteCallback;
update_jump_params = true, kwargs...)
if typeof(cb.condition) <: AbstractSSAJumpAggregator
if cb.condition isa AbstractSSAJumpAggregator
maj = cb.condition.ma_jumps
update_jump_params && using_params(maj) &&
update_parameters!(cb.condition.ma_jumps, integrator.p; kwargs...)
Expand Down
4 changes: 2 additions & 2 deletions src/coupling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ end

function cat_problems(prob::DiscreteProblem, prob_control::DiffEqBase.AbstractODEProblem)
l = length(prob.u0) # add l_c = length(prob_control.u0)
if !(typeof(prob.f) <: typeof(DiffEqBase.DISCRETE_INPLACE_DEFAULT))
if !(prob.f isa typeof(DiffEqBase.DISCRETE_INPLACE_DEFAULT))
@warn("Coupling to DiscreteProblem with nontrivial f. Note that, unless scale_by_time=true, the meaning of f will change when using an ODE/SDE/DDE/DAE solver.")
end

Expand Down Expand Up @@ -87,7 +87,7 @@ end

function cat_problems(prob::DiffEqBase.AbstractSDEProblem, prob_control::DiscreteProblem)
l = length(prob.u0)
if !(typeof(prob_control.f) <: typeof(DiffEqBase.DISCRETE_INPLACE_DEFAULT))
if !(prob_control.f isa typeof(DiffEqBase.DISCRETE_INPLACE_DEFAULT))
@warn("Coupling to DiscreteProblem with nontrivial f. Note that, unless scale_by_time=true, the meaning of f will change when using an ODE/SDE/DDE/DAE solver.")
end
new_f = function (du, u, p, t)
Expand Down
4 changes: 2 additions & 2 deletions src/problem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ end
make_kwarg(; kwargs...) = kwargs

function JumpProblem(prob, aggregator::AbstractAggregatorAlgorithm, jumps::JumpSet;
save_positions = typeof(prob) <: DiffEqBase.AbstractDiscreteProblem ?
save_positions = prob isa DiffEqBase.AbstractDiscreteProblem ?
(false, true) : (true, true),
rng = DEFAULT_RNG, scale_rates = true, useiszero = true,
spatial_system = nothing, hopping_constants = nothing,
Expand Down Expand Up @@ -419,7 +419,7 @@ aggregator(jp::JumpProblem{iip, P, A, C, J}) where {iip, P, A, C, J} = A

@inline function extend_tstops!(tstops,
jp::JumpProblem{P, A, C, J, J2}) where {P, A, C, J, J2}
!(typeof(jp.jump_callback.discrete_callbacks) <: Tuple{}) &&
!(jp.jump_callback.discrete_callbacks isa Tuple{}) &&
push!(tstops, jp.jump_callback.discrete_callbacks[1].condition.next_jump_time)
end

Expand Down
2 changes: 1 addition & 1 deletion test/functionwrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let
prob = DiscreteProblem([0.0], (0.0, 2.0), [1.0])
jprob = JumpProblem(prob, Coevolve(), jump; dep_graph = [[1]], rng)
agg = jprob.discrete_jump_aggregation
@test typeof(agg.affects!) <: Vector{Any}
@test agg.affects! isa Vector{Any}

integ = init(jprob, SSAStepper())
T = Vector{FunctionWrappers.FunctionWrapper{Nothing, Tuple{typeof(integ)}}}
Expand Down
4 changes: 2 additions & 2 deletions test/hawkes_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Nsims = 250

for (i, alg) in enumerate(algs)
jump_prob = hawkes_problem(p, alg; u = u0, tspan, g, h, uselrate = uselrate[i])
if typeof(alg) <: Coevolve
if alg isa Coevolve
stepper = SSAStepper()
else
stepper = Tsit5()
Expand All @@ -123,7 +123,7 @@ for (i, alg) in enumerate(algs)
reset_history!(h)
sols[n] = solve(jump_prob, stepper)
end
if typeof(alg) <: Coevolve
if alg isa Coevolve
λs = permutedims(mapreduce((sol) -> empirical_rate(sol), hcat, sols))
else
cols = length(sols[1].u[1].u)
Expand Down

0 comments on commit 3fd02b0

Please sign in to comment.