Skip to content

Commit 5a7771d

Browse files
Merge pull request #536 from pepijndevos/new-branch
Change typeof(x) <: y to x isa y
2 parents 585a1aa + e037ef6 commit 5a7771d

13 files changed

+92
-92
lines changed

src/ensemble/basic_ensemble_solve.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function batch_func(i, prob, alg; kwargs...)
105105
new_prob = prob.prob_func(_prob, i, iter)
106106
rerun = true
107107
x = prob.output_func(solve(new_prob, alg; kwargs...), i)
108-
if !(typeof(x) <: Tuple)
108+
if !(x isa Tuple)
109109
rerun_warn()
110110
_x = (x, false)
111111
else
@@ -117,7 +117,7 @@ function batch_func(i, prob, alg; kwargs...)
117117
_prob = prob.safetycopy ? deepcopy(prob.prob) : prob.prob
118118
new_prob = prob.prob_func(_prob, i, iter)
119119
x = prob.output_func(solve(new_prob, alg; kwargs...), i)
120-
if !(typeof(x) <: Tuple)
120+
if !(x isa Tuple)
121121
rerun_warn()
122122
_x = (x, false)
123123
else
@@ -170,7 +170,7 @@ function solve_batch(prob, alg, ensemblealg::EnsembleThreads, II, pmap_batch_siz
170170
return solve_batch(prob, alg, EnsembleSerial(), II, pmap_batch_size; kwargs...)
171171
end
172172

173-
if typeof(prob.prob) <: AbstractJumpProblem && length(II) != 1
173+
if prob.prob isa AbstractJumpProblem && length(II) != 1
174174
probs = [deepcopy(prob.prob) for i in 1:nthreads]
175175
else
176176
probs = prob.prob

src/ensemble/ensemble_analysis.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ get_timestep(sim, i) = (getindex(sol, i) for sol in sim)
77
get_timepoint(sim, t) = (sol(t) for sol in sim)
88
function componentwise_vectors_timestep(sim, i)
99
arr = [get_timestep(sim, i)...]
10-
if typeof(arr[1]) <: AbstractArray
10+
if arr[1] isa AbstractArray
1111
return vecarr_to_vectors(VectorOfArray(arr))
1212
else
1313
return arr
1414
end
1515
end
1616
function componentwise_vectors_timepoint(sim, t)
1717
arr = [get_timepoint(sim, t)...]
18-
if typeof(arr[1]) <: AbstractArray
18+
if arr[1] isa AbstractArray
1919
return vecarr_to_vectors(VectorOfArray(arr))
2020
else
2121
return arr
@@ -123,7 +123,7 @@ end
123123

124124
function SciMLBase.EnsembleSummary(sim::SciMLBase.AbstractEnsembleSolution{T, N},
125125
t = sim[1].t; quantiles = [0.05, 0.95]) where {T, N}
126-
if typeof(sim[1]) <: SciMLSolution
126+
if sim[1] isa SciMLSolution
127127
m, v = timeseries_point_meanvar(sim, t)
128128
med = timeseries_point_median(sim, t)
129129
qlow = timeseries_point_quantile(sim, quantiles[1], t)
@@ -190,13 +190,13 @@ function componentwise_mean(A)
190190
mean = zero(x0) ./ 1
191191
for x in A
192192
n += 1
193-
if typeof(x0) <: AbstractArray && !(typeof(x0) <: StaticArraysCore.SArray)
193+
if x0 isa AbstractArray && !(x0 isa StaticArraysCore.SArray)
194194
mean .+= x
195195
else
196196
mean += x
197197
end
198198
end
199-
if typeof(x0) <: AbstractArray && !(typeof(x0) <: StaticArraysCore.SArray)
199+
if x0 isa AbstractArray && !(x0 isa StaticArraysCore.SArray)
200200
mean ./= n
201201
else
202202
mean /= n
@@ -215,7 +215,7 @@ function componentwise_meanvar(A; bessel = true)
215215
delta2 = zero(x0) ./ 1
216216
for x in A
217217
n += 1
218-
if typeof(x0) <: AbstractArray && !(typeof(x0) <: StaticArraysCore.SArray)
218+
if x0 isa AbstractArray && !(x0 isa StaticArraysCore.SArray)
219219
delta .= x .- mean
220220
mean .+= delta ./ n
221221
delta2 .= x .- mean
@@ -231,13 +231,13 @@ function componentwise_meanvar(A; bessel = true)
231231
return NaN
232232
else
233233
if bessel
234-
if typeof(x0) <: AbstractArray && !(typeof(x0) <: StaticArraysCore.SArray)
234+
if x0 isa AbstractArray && !(x0 isa StaticArraysCore.SArray)
235235
M2 .= M2 ./ (n .- 1)
236236
else
237237
M2 = M2 ./ (n .- 1)
238238
end
239239
else
240-
if typeof(x0) <: AbstractArray && !(typeof(x0) <: StaticArraysCore.SArray)
240+
if x0 isa AbstractArray && !(x0 isa StaticArraysCore.SArray)
241241
M2 .= M2 ./ n
242242
else
243243
M2 = M2 ./ n
@@ -257,7 +257,7 @@ function componentwise_meancov(A, B; bessel = true)
257257
dx = zero(x0) ./ 1
258258
for (x, y) in zip(A, B)
259259
n += 1
260-
if typeof(x0) <: AbstractArray && !(typeof(x0) <: StaticArraysCore.SArray)
260+
if x0 isa AbstractArray && !(x0 isa StaticArraysCore.SArray)
261261
dx .= x .- meanx
262262
meanx .+= dx ./ n
263263
meany .+= (y .- meany) ./ n
@@ -273,13 +273,13 @@ function componentwise_meancov(A, B; bessel = true)
273273
return NaN
274274
else
275275
if bessel
276-
if typeof(x0) <: AbstractArray && !(typeof(x0) <: StaticArraysCore.SArray)
276+
if x0 isa AbstractArray && !(x0 isa StaticArraysCore.SArray)
277277
C .= C ./ (n .- 1)
278278
else
279279
C = C ./ (n .- 1)
280280
end
281281
else
282-
if typeof(x0) <: AbstractArray && !(typeof(x0) <: StaticArraysCore.SArray)
282+
if x0 isa AbstractArray && !(x0 isa StaticArraysCore.SArray)
283283
C .= C ./ n
284284
else
285285
C = C ./ n
@@ -293,7 +293,7 @@ function componentwise_meancor(A, B; bessel = true)
293293
mx, my, cov = componentwise_meancov(A, B; bessel = bessel)
294294
mx, vx = componentwise_meanvar(A; bessel = bessel)
295295
my, vy = componentwise_meanvar(B; bessel = bessel)
296-
if typeof(vx) <: AbstractArray
296+
if vx isa AbstractArray
297297
vx .= sqrt.(vx)
298298
vy .= sqrt.(vy)
299299
else
@@ -316,7 +316,7 @@ function componentwise_weighted_meancov(A, B, W; weight_type = :reliability)
316316
dx = zero(x0) ./ 1
317317
for (x, y, w) in zip(A, B, W)
318318
n += 1
319-
if typeof(x0) <: AbstractArray && !(typeof(x0) <: StaticArraysCore.SArray)
319+
if x0 isa AbstractArray && !(x0 isa StaticArraysCore.SArray)
320320
wsum .+= w
321321
wsum2 .+= w .* w
322322
dx .= x .- meanx
@@ -336,19 +336,19 @@ function componentwise_weighted_meancov(A, B, W; weight_type = :reliability)
336336
return NaN
337337
else
338338
if weight_type == :population
339-
if typeof(x0) <: AbstractArray && !(typeof(x0) <: StaticArraysCore.SArray)
339+
if x0 isa AbstractArray && !(x0 isa StaticArraysCore.SArray)
340340
C .= C ./ wsum
341341
else
342342
C = C ./ wsum
343343
end
344344
elseif weight_type == :reliability
345-
if typeof(x0) <: AbstractArray && !(typeof(x0) <: StaticArraysCore.SArray)
345+
if x0 isa AbstractArray && !(x0 isa StaticArraysCore.SArray)
346346
C .= C ./ (wsum .- wsum2 ./ wsum)
347347
else
348348
C = C ./ (wsum .- wsum2 ./ wsum)
349349
end
350350
elseif weight_type == :frequency
351-
if typeof(x0) <: AbstractArray && !(typeof(x0) <: StaticArraysCore.SArray)
351+
if x0 isa AbstractArray && !(x0 isa StaticArraysCore.SArray)
352352
C .= C ./ (wsum .- 1)
353353
else
354354
C = C ./ (wsum .- 1)

src/ensemble/ensemble_solutions.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ end
139139
### Plot Recipes
140140

141141
@recipe function f(sim::AbstractEnsembleSolution;
142-
zcolors = typeof(sim.u) <: AbstractArray ? fill(nothing, length(sim.u)) :
142+
zcolors = sim.u isa AbstractArray ? fill(nothing, length(sim.u)) :
143143
nothing,
144144
trajectories = eachindex(sim))
145145
for i in trajectories
@@ -156,16 +156,16 @@ end
156156
end
157157

158158
@recipe function f(sim::EnsembleSummary;
159-
trajectories = typeof(sim.u[1]) <: AbstractArray ? eachindex(sim.u[1]) :
159+
trajectories = sim.u[1] isa AbstractArray ? eachindex(sim.u[1]) :
160160
1,
161161
error_style = :ribbon, ci_type = :quantile)
162162
if ci_type == :SEM
163-
if typeof(sim.u[1]) <: AbstractArray
163+
if sim.u[1] isa AbstractArray
164164
u = vecarr_to_vectors(sim.u)
165165
else
166166
u = [sim.u.u]
167167
end
168-
if typeof(sim.u[1]) <: AbstractArray
168+
if sim.u[1] isa AbstractArray
169169
ci_low = vecarr_to_vectors(VectorOfArray([sqrt.(sim.v[i] / sim.num_monte) .*
170170
1.96 for i in 1:length(sim.v)]))
171171
ci_high = ci_low
@@ -175,12 +175,12 @@ end
175175
ci_high = ci_low
176176
end
177177
elseif ci_type == :quantile
178-
if typeof(sim.med[1]) <: AbstractArray
178+
if sim.med[1] isa AbstractArray
179179
u = vecarr_to_vectors(sim.med)
180180
else
181181
u = [sim.med.u]
182182
end
183-
if typeof(sim.u[1]) <: AbstractArray
183+
if sim.u[1] isa AbstractArray
184184
ci_low = u - vecarr_to_vectors(sim.qlow)
185185
ci_high = vecarr_to_vectors(sim.qhigh) - u
186186
else

src/integrator_interface.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ Base.length(iter::TimeChoiceIterator) = length(iter.ts)
750750

751751
@recipe function f(integrator::DEIntegrator;
752752
denseplot = (integrator.opts.calck ||
753-
typeof(integrator) <: AbstractSDEIntegrator) &&
753+
integrator isa AbstractSDEIntegrator) &&
754754
integrator.iter > 0,
755755
plotdensity = 10,
756756
plot_analytic = false, vars = nothing, idxs = nothing)
@@ -797,7 +797,7 @@ Base.length(iter::TimeChoiceIterator) = length(iter.ts)
797797
else # just get values
798798
if x[j] == 0
799799
push!(plot_vecs[j - 1], integrator.t)
800-
elseif x[j] == 1 && !(typeof(integrator.u) <: AbstractArray)
800+
elseif x[j] == 1 && !(integrator.u isa AbstractArray)
801801
push!(plot_vecs[j - 1], integrator.u)
802802
else
803803
push!(plot_vecs[j - 1], integrator.u[x[j]])
@@ -816,7 +816,7 @@ Base.length(iter::TimeChoiceIterator) = length(iter.ts)
816816
else # Just get values
817817
if x[j] == 0
818818
push!(plot_vecs[j], integrator.t)
819-
elseif x[j] == 1 && !(typeof(integrator.u) <: AbstractArray)
819+
elseif x[j] == 1 && !(integrator.u isa AbstractArray)
820820
push!(plot_vecs[j],
821821
integrator.sol.prob.f(Val{:analytic}, integrator.t,
822822
integrator.sol[1]))
@@ -840,7 +840,7 @@ Base.length(iter::TimeChoiceIterator) = length(iter.ts)
840840
end
841841

842842
# Special case labels when idxs = (:x,:y,:z) or (:x) or [:x,:y] ...
843-
if typeof(idxs) <: Tuple && (typeof(idxs[1]) == Symbol && typeof(idxs[2]) == Symbol)
843+
if idxs isa Tuple && (typeof(idxs[1]) == Symbol && typeof(idxs[2]) == Symbol)
844844
xlabel --> idxs[1]
845845
ylabel --> idxs[2]
846846
if length(idxs) > 2

src/interpolation.jl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ end
8181
continuity::Symbol = :left) where {I, D}
8282
t = id.t
8383
u = id.u
84-
typeof(id) <: HermiteInterpolation && (du = id.du)
84+
id isa HermiteInterpolation && (du = id.du)
8585
tdir = sign(t[end] - t[1])
8686
idx = sortperm(tvals, rev = tdir < 0)
8787
i = 2 # Start the search thinking it's between t[1] and t[2]
@@ -91,17 +91,17 @@ end
9191
error("Solution interpolation cannot extrapolate past the final timepoint. Either solve on a longer timespan or use the local extrapolation from the integrator interface.")
9292
tdir * tvals[idx[1]] < tdir * t[1] &&
9393
error("Solution interpolation cannot extrapolate before the first timepoint. Either start solving earlier or use the local extrapolation from the integrator interface.")
94-
if typeof(idxs) <: Number
94+
if idxs isa Number
9595
vals = Vector{eltype(first(u))}(undef, length(tvals))
96-
elseif typeof(idxs) <: AbstractVector
96+
elseif idxs isa AbstractVector
9797
vals = Vector{Vector{eltype(first(u))}}(undef, length(tvals))
9898
else
9999
vals = Vector{eltype(u)}(undef, length(tvals))
100100
end
101101
for j in idx
102102
tval = tvals[j]
103103
i = searchsortedfirst(@view(t[i:end]), tval, rev = tdir < 0) + i - 1 # It's in the interval t[i-1] to t[i]
104-
avoid_constant_ends = deriv != Val{0} #|| typeof(tval) <: ForwardDiff.Dual
104+
avoid_constant_ends = deriv != Val{0} #|| tval isa ForwardDiff.Dual
105105
avoid_constant_ends && i == 1 && (i += 1)
106106
if !avoid_constant_ends && t[i - 1] == tval # Can happen if it's the first value!
107107
if idxs === nothing
@@ -118,11 +118,11 @@ end
118118
vals[j] = u[k][idxs]
119119
end
120120
else
121-
typeof(id) <: SensitivityInterpolation && error(SENSITIVITY_INTERP_MESSAGE)
121+
id isa SensitivityInterpolation && error(SENSITIVITY_INTERP_MESSAGE)
122122
dt = t[i] - t[i - 1]
123123
Θ = (tval - t[i - 1]) / dt
124124
idxs_internal = idxs
125-
if typeof(id) <: HermiteInterpolation
125+
if id isa HermiteInterpolation
126126
vals[j] = interpolant(Θ, id, dt, u[i - 1], u[i], du[i - 1], du[i],
127127
idxs_internal, deriv)
128128
else
@@ -143,7 +143,7 @@ times t (sorted), with values u and derivatives ks
143143
continuity::Symbol = :left) where {I, D}
144144
t = id.t
145145
u = id.u
146-
typeof(id) <: HermiteInterpolation && (du = id.du)
146+
id isa HermiteInterpolation && (du = id.du)
147147
tdir = sign(t[end] - t[1])
148148
idx = sortperm(tvals, rev = tdir < 0)
149149
i = 2 # Start the search thinking it's between t[1] and t[2]
@@ -156,7 +156,7 @@ times t (sorted), with values u and derivatives ks
156156
for j in idx
157157
tval = tvals[j]
158158
i = searchsortedfirst(@view(t[i:end]), tval, rev = tdir < 0) + i - 1 # It's in the interval t[i-1] to t[i]
159-
avoid_constant_ends = deriv != Val{0} #|| typeof(tval) <: ForwardDiff.Dual
159+
avoid_constant_ends = deriv != Val{0} #|| tval isa ForwardDiff.Dual
160160
avoid_constant_ends && i == 1 && (i += 1)
161161
if !avoid_constant_ends && t[i - 1] == tval # Can happen if it's the first value!
162162
if idxs === nothing
@@ -173,19 +173,19 @@ times t (sorted), with values u and derivatives ks
173173
vals[j] = u[k][idxs]
174174
end
175175
else
176-
typeof(id) <: SensitivityInterpolation && error(SENSITIVITY_INTERP_MESSAGE)
176+
id isa SensitivityInterpolation && error(SENSITIVITY_INTERP_MESSAGE)
177177
dt = t[i] - t[i - 1]
178178
Θ = (tval - t[i - 1]) / dt
179179
idxs_internal = idxs
180180
if eltype(u) <: Union{AbstractArray, ArrayPartition}
181-
if typeof(id) <: HermiteInterpolation
181+
if id isa HermiteInterpolation
182182
interpolant!(vals[j], Θ, id, dt, u[i - 1], u[i], du[i - 1], du[i],
183183
idxs_internal, deriv)
184184
else
185185
interpolant!(vals[j], Θ, id, dt, u[i - 1], u[i], idxs_internal, deriv)
186186
end
187187
else
188-
if typeof(id) <: HermiteInterpolation
188+
if id isa HermiteInterpolation
189189
vals[j] = interpolant(Θ, id, dt, u[i - 1], u[i], du[i - 1], du[i],
190190
idxs_internal, deriv)
191191
else
@@ -206,7 +206,7 @@ times t (sorted), with values u and derivatives ks
206206
continuity::Symbol = :left) where {I, D}
207207
t = id.t
208208
u = id.u
209-
typeof(id) <: HermiteInterpolation && (du = id.du)
209+
id isa HermiteInterpolation && (du = id.du)
210210
tdir = sign(t[end] - t[1])
211211
t[end] == t[1] && tval != t[end] &&
212212
error("Solution interpolation cannot extrapolate from a single timepoint. Either solve on a longer timespan or use the local extrapolation from the integrator interface.")
@@ -215,7 +215,7 @@ times t (sorted), with values u and derivatives ks
215215
tdir * tval < tdir * t[1] &&
216216
error("Solution interpolation cannot extrapolate before the first timepoint. Either start solving earlier or use the local extrapolation from the integrator interface.")
217217
@inbounds i = searchsortedfirst(t, tval, rev = tdir < 0) # It's in the interval t[i-1] to t[i]
218-
avoid_constant_ends = deriv != Val{0} #|| typeof(tval) <: ForwardDiff.Dual
218+
avoid_constant_ends = deriv != Val{0} #|| tval isa ForwardDiff.Dual
219219
avoid_constant_ends && i == 1 && (i += 1)
220220
if !avoid_constant_ends && t[i] == tval
221221
lasti = lastindex(t)
@@ -232,11 +232,11 @@ times t (sorted), with values u and derivatives ks
232232
val = u[i - 1][idxs]
233233
end
234234
else
235-
typeof(id) <: SensitivityInterpolation && error(SENSITIVITY_INTERP_MESSAGE)
235+
id isa SensitivityInterpolation && error(SENSITIVITY_INTERP_MESSAGE)
236236
dt = t[i] - t[i - 1]
237237
Θ = (tval - t[i - 1]) / dt
238238
idxs_internal = idxs
239-
if typeof(id) <: HermiteInterpolation
239+
if id isa HermiteInterpolation
240240
val = interpolant(Θ, id, dt, u[i - 1], u[i], du[i - 1], du[i], idxs_internal,
241241
deriv)
242242
else
@@ -256,7 +256,7 @@ times t (sorted), with values u and derivatives ks
256256
continuity::Symbol = :left) where {I, D}
257257
t = id.t
258258
u = id.u
259-
typeof(id) <: HermiteInterpolation && (du = id.du)
259+
id isa HermiteInterpolation && (du = id.du)
260260
tdir = sign(t[end] - t[1])
261261
t[end] == t[1] && tval != t[end] &&
262262
error("Solution interpolation cannot extrapolate from a single timepoint. Either solve on a longer timespan or use the local extrapolation from the integrator interface.")
@@ -265,7 +265,7 @@ times t (sorted), with values u and derivatives ks
265265
tdir * tval < tdir * t[1] &&
266266
error("Solution interpolation cannot extrapolate before the first timepoint. Either start solving earlier or use the local extrapolation from the integrator interface.")
267267
@inbounds i = searchsortedfirst(t, tval, rev = tdir < 0) # It's in the interval t[i-1] to t[i]
268-
avoid_constant_ends = deriv != Val{0} #|| typeof(tval) <: ForwardDiff.Dual
268+
avoid_constant_ends = deriv != Val{0} #|| tval isa ForwardDiff.Dual
269269
avoid_constant_ends && i == 1 && (i += 1)
270270
if !avoid_constant_ends && t[i] == tval
271271
lasti = lastindex(t)
@@ -282,11 +282,11 @@ times t (sorted), with values u and derivatives ks
282282
copy!(out, u[i - 1][idxs])
283283
end
284284
else
285-
typeof(id) <: SensitivityInterpolation && error(SENSITIVITY_INTERP_MESSAGE)
285+
id isa SensitivityInterpolation && error(SENSITIVITY_INTERP_MESSAGE)
286286
dt = t[i] - t[i - 1]
287287
Θ = (tval - t[i - 1]) / dt
288288
idxs_internal = idxs
289-
if typeof(id) <: HermiteInterpolation
289+
if id isa HermiteInterpolation
290290
interpolant!(out, Θ, id, dt, u[i - 1], u[i], du[i - 1], du[i], idxs_internal,
291291
deriv)
292292
else

0 commit comments

Comments
 (0)