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

Change typeof(x) <: y to x isa y #996

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
4 changes: 2 additions & 2 deletions src/ode_default_alg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ function default_algorithm(prob::DiffEqBase.AbstractODEProblem{uType, tType, inp
# Bad interaction with ForwardDiff
#!(tType <: AbstractFloat) && (:adaptive ∉ keys(o)) && push!(extra_kwargs,:adaptive=>false)

if typeof(prob.f) <: SplitFunction
if prob.f isa SplitFunction
alg = KenCarp4(autodiff = false)
elseif typeof(prob.f) <: DynamicalODEFunction
elseif prob.f isa DynamicalODEFunction
if tol_level == :low_tol || tol_level == :med_tol
alg = Tsit5()
else
Expand Down
2 changes: 1 addition & 1 deletion test/default_dae_alg_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ prob_dae_resrob = DAEProblem(f, du0, u0, (0.0, 100000.0))
prob = prob_dae_resrob
sol = solve(prob)

@test typeof(sol.alg) <: DifferentialEquations.Sundials.IDA
@test sol.alg isa DifferentialEquations.Sundials.IDA
6 changes: 3 additions & 3 deletions test/default_dde_alg_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ prob = DDEProblem(f, 1.0, h, (0.0, 10.0), constant_lags = lags)

sol = solve(prob)

@test typeof(sol.alg) <: CompositeAlgorithm
@test typeof(sol.alg.algs[1]) <: Tsit5
@test typeof(sol.alg.algs[2]) <: Rosenbrock23
@test sol.alg isa CompositeAlgorithm
@test sol.alg.algs[1] isa Tsit5
@test sol.alg.algs[2] isa Rosenbrock23
2 changes: 1 addition & 1 deletion test/default_discrete_alg_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ using DifferentialEquations, Test

prob = DiscreteProblem(zeros(2), (0.0, 1.0))
sol = solve(prob)
@test typeof(sol.alg) <: FunctionMap
@test sol.alg isa FunctionMap
38 changes: 19 additions & 19 deletions test/default_ode_alg_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ alg, kwargs = default_algorithm(prob_ode_2Dlinear; dt = 1 // 2^(4))
integ = init(prob_ode_2Dlinear; dt = 1 // 2^(4))
sol = solve(prob_ode_2Dlinear; dt = 1 // 2^(4))

@test typeof(sol.alg.algs[1]) <: Tsit5
@test typeof(sol.alg.algs[2]) <: Rosenbrock23
@test sol.alg.algs[1] isa Tsit5
@test sol.alg.algs[2] isa Rosenbrock23

sol = solve(prob_ode_2Dlinear; reltol = 1e-1)

@test typeof(sol.alg.algs[1]) <: Tsit5
@test typeof(sol.alg.algs[2]) <: Rosenbrock23
@test sol.alg.algs[1] isa Tsit5
@test sol.alg.algs[2] isa Rosenbrock23

sol = solve(prob_ode_2Dlinear; reltol = 1e-7)

@test typeof(sol.alg.algs[1]) <: Vern7
@test typeof(sol.alg.algs[2]) <: Rodas5P
@test sol.alg.algs[1] isa Vern7
@test sol.alg.algs[2] isa Rodas5P

sol = solve(prob_ode_2Dlinear; reltol = 1e-10)

@test typeof(sol.alg.algs[1]) <: Vern7
@test typeof(sol.alg.algs[2]) <: Rodas5P
@test sol.alg.algs[1] isa Vern7
@test sol.alg.algs[2] isa Rodas5P

sol = solve(prob_ode_2Dlinear; alg_hints = [:stiff])

@test typeof(sol.alg) <: Rodas5P
@test sol.alg isa Rodas5P

sol = solve(prob_ode_2Dlinear; alg_hints = [:stiff], reltol = 1e-1)

@test typeof(sol.alg) <: Rosenbrock23
@test sol.alg isa Rosenbrock23

const linear_bigα = parse(BigFloat, "1.01")
f = (du, u, p, t) -> begin
Expand All @@ -46,18 +46,18 @@ prob_ode_bigfloat2Dlinear = ODEProblem(f, map(BigFloat, rand(4, 2)) .* ones(4, 2
(0.0, 1.0))

sol = solve(prob_ode_bigfloat2Dlinear; dt = 1 // 2^(4))
@test typeof(sol.alg.algs[1]) <: Vern7
@test typeof(sol.alg.algs[2]) <: Rodas5P
@test sol.alg.algs[1] isa Vern7
@test sol.alg.algs[2] isa Rodas5P

default_algorithm(prob_ode_bigfloat2Dlinear; alg_hints = [:stiff])

sol = solve(prob_ode_bigfloat2Dlinear; alg_hints = [:stiff])

@test typeof(sol.alg) <: Rodas5P
@test sol.alg isa Rodas5P

sol = solve(prob_ode_bigfloat2Dlinear, nothing; alg_hints = [:stiff])

@test typeof(sol.alg) <: Rodas5P
@test sol.alg isa Rodas5P

struct FooAlg end

Expand All @@ -73,21 +73,21 @@ prob = ODEProblem(f, rand(4, 2) .* ones(4, 2) / 2, (0.0, 1.0))

sol = solve(prob; alg_hints = [:stiff])

@test typeof(sol.alg) <: Rodas5P
@test sol.alg isa Rodas5P

sol = solve(prob; alg_hints = [:stiff], reltol = 1e-1)

@test typeof(sol.alg) <: Rosenbrock23
@test sol.alg isa Rosenbrock23

sol = solve(prob; alg_hints = [:stiff], callback = CallbackSet())

@test typeof(sol.alg) <: Rodas5P
@test sol.alg isa Rodas5P

prob = ODEProblem(f, rand(4, 2) .* ones(4, 2) / 2, (0.0, 1.0))

alg, kwargs = default_algorithm(prob; alg_hints = [:stiff])

@test typeof(alg) <: Rodas5P
@test alg isa Rodas5P

m = 1.0
ω = 1.0
Expand All @@ -104,4 +104,4 @@ tspan = (0.0, 10.0)
prob = SecondOrderODEProblem(mass_system!, v0, u0, tspan)
sol = solve(prob)

@test typeof(sol.alg) <: Tsit5
@test sol.alg isa Tsit5
2 changes: 1 addition & 1 deletion test/default_rode_alg_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ tspan = (0.0, 1.0)
prob = RODEProblem(f, u0, tspan)
sol = solve(prob, dt = 1 / 100)

@test typeof(sol.alg) <: RandomEM
@test sol.alg isa RandomEM
14 changes: 7 additions & 7 deletions test/default_sde_alg_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ Random.seed!(100)

prob = prob_sde_additive
sol = solve(prob, dt = 1 / 2^(3))
@test typeof(sol.alg) <: SOSRI
@test sol.alg isa SOSRI

sol = solve(prob, dt = 1 / 2^(3), alg_hints = [:additive])
@test typeof(sol.alg) <: SOSRA
@test sol.alg isa SOSRA

sol = solve(prob, dt = 1 / 2^(3), alg_hints = [:Stratonovich])
@test StochasticDiffEq.alg_interpretation(sol.alg) == :Stratonovich
@test typeof(sol.alg) <: RKMil
@test sol.alg isa RKMil

f = (du, u, p, t) -> du .= 1.01u
g = function (du, u, p, t)
Expand All @@ -35,13 +35,13 @@ end
prob = SDEProblem(f, g, ones(2), (0.0, 1.0), noise_rate_prototype = zeros(2, 4))

sol = solve(prob, dt = 1 / 2^(3))
@test typeof(sol.alg) <: LambaEM
@test sol.alg isa LambaEM

sol = solve(prob, dt = 1 / 2^(3), alg_hints = [:stiff])
@test typeof(sol.alg) <: ISSEM
@test sol.alg isa ISSEM

sol = solve(prob, dt = 1 / 2^(3), alg_hints = [:additive])
@test typeof(sol.alg) <: SOSRA
@test sol.alg isa SOSRA

sol = solve(prob, dt = 1 / 2^(3), alg_hints = [:Stratonovich])
@test typeof(sol.alg) <: LambaEulerHeun
@test sol.alg isa LambaEulerHeun