Skip to content

Commit d8a3c61

Browse files
Fix deprecation warnings regarding indexing (#154)
* fix deprecation warnings * remove empty line
1 parent 9570b0a commit d8a3c61

File tree

2 files changed

+43
-35
lines changed

2 files changed

+43
-35
lines changed

src/utilities.jl

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ end
3131
isnegative(sol::ODESolution)
3232
3333
Returns `true` if `sol.u` contains negative elements.
34-
34+
3535
Please note that negative values may occur when plotting the solution, depending on the interpolation used.
3636
3737
See also [`isnonnegative`](@ref).
@@ -43,26 +43,28 @@ end
4343
"""
4444
isnonnegative(u)
4545
46-
Negation of [`isnegative`](@ref).
46+
Negation of [`isnegative`](@ref).
4747
"""
4848
isnonnegative(args...) = !isnegative(args...)
4949

5050
### Errors #########################################################################
5151
"""
5252
rel_max_error_tend(sol, ref_sol)
5353
54-
Returns the relative maximum error between `sol` and `ref_sol` at time `sol.t[end]`.
54+
Returns the relative maximum error between `sol` and `ref_sol` at time `sol.t[end]`.
5555
"""
56-
function rel_max_error_tend(sol, ref_sol)
56+
function rel_max_error_tend(sol::AbstractVector, ref_sol::AbstractVector)
5757
return maximum(abs.((sol[end] .- ref_sol[end]) ./ ref_sol[end]))
5858
end
5959

60+
rel_max_error_tend(sol, ref_sol) = rel_max_error_tend(sol.u, ref_sol.u)
61+
6062
"""
6163
rel_max_error_overall(sol, ref_sol)
6264
63-
Returns the maximum of the relative maximum errors between `sol` and `ref_sol` over all time steps.
65+
Returns the maximum of the relative maximum errors between `sol` and `ref_sol` over all time steps.
6466
"""
65-
function rel_max_error_overall(sol, ref_sol)
67+
function rel_max_error_overall(sol::AbstractVector, ref_sol::AbstractVector)
6668
err = zero(eltype(eltype(sol)))
6769
for i in eachindex(sol)
6870
max_err_i = maximum(abs.((abs.(sol[i]) .- abs.(ref_sol[i])) ./ ref_sol[i]))
@@ -73,26 +75,32 @@ function rel_max_error_overall(sol, ref_sol)
7375
return err
7476
end
7577

78+
rel_max_error_overall(sol, ref_sol) = rel_max_error_overall(sol.u, ref_sol.u)
79+
7680
"""
7781
rel_l1_error_tend(sol, ref_sol)
7882
79-
Returns the relative l1 error between `sol` and `ref_sol` at time `sol.t[end]`.
83+
Returns the relative l1 error between `sol` and `ref_sol` at time `sol.t[end]`.
8084
"""
81-
function rel_l1_error_tend(sol, ref_sol)
85+
function rel_l1_error_tend(sol::AbstractVector, ref_sol::AbstractVector)
8286
return sum(abs.((sol[end] .- ref_sol[end]) ./ ref_sol[end])) / length(ref_sol[end])
8387
end
8488

89+
rel_l1_error_tend(sol, ref_sol) = rel_l1_error_tend(sol.u, ref_sol.u)
90+
8591
"""
8692
rel_l2_error_tend(sol, ref_sol)
8793
88-
Returns the relative l2 error between `sol` and `ref_sol` at time `sol.t[end]`.
94+
Returns the relative l2 error between `sol` and `ref_sol` at time `sol.t[end]`.
8995
"""
90-
function rel_l2_error_tend(sol, ref_sol)
96+
function rel_l2_error_tend(sol::AbstractVector, ref_sol::AbstractVector)
9197
return sqrt(sum(abs2.((sol[end] .- ref_sol[end]) ./ ref_sol[end])) /
9298
length(ref_sol[end]))
9399
end
94100

95-
### Functions to compute work-precision diagrams ##########################################
101+
rel_l2_error_tend(sol, ref_sol) = rel_l2_error_tend(sol.u, ref_sol.u)
102+
103+
### Functions to compute work-precision diagrams ##########################################
96104
function _compute_time(benchmark_f, seconds, numruns)
97105
benchmark_f() # pre-compile
98106

@@ -127,7 +135,7 @@ end
127135

128136
"""
129137
work_precision_fixed!(dict, prob, algs, labels, dts, alg_ref;
130-
compute_error = rel_max_error_tend,
138+
compute_error = rel_max_error_tend,
131139
seconds = 2,
132140
numruns = 20)
133141
)
@@ -170,14 +178,14 @@ end
170178
"""
171179
work_precision_fixed(prob, algs, labels, dts, alg_ref;
172180
compute_error = rel_max_error_tend,
173-
seconds = 2,
181+
seconds = 2,
174182
numruns = 20)
175183
176-
Returns a dictionary to create work-precision diagrams.
177-
The problem `prob` is solved by each algorithm in `algs` for all the step sizes defined in `dts`.
178-
For each step size the error and computing time are stored in the dictionary.
184+
Returns a dictionary to create work-precision diagrams.
185+
The problem `prob` is solved by each algorithm in `algs` for all the step sizes defined in `dts`.
186+
For each step size the error and computing time are stored in the dictionary.
179187
If the solve is not successful for a given step size, then `(Inf, Inf)` is stored in the dictionary.
180-
The strings in the array `labels` are used as keys of the dictionary.
188+
The strings in the array `labels` are used as keys of the dictionary.
181189
The reference solution used for error computations is computed with the algorithm `alg_ref`.
182190
183191
### Keyword arguments: ###
@@ -198,10 +206,10 @@ end
198206
"""
199207
work_precision_adaptive(prob, algs, labels, abstols, reltols, alg_ref;
200208
adaptive_ref = false,
201-
abstol_ref = 1e-14,
209+
abstol_ref = 1e-14,
202210
reltol_ref = 1e-13,
203211
compute_error = rel_max_error_tend,
204-
seconds = 2,
212+
seconds = 2,
205213
numruns = 20,
206214
kwargs...)
207215
@@ -251,18 +259,18 @@ end
251259
"""
252260
work_precision_adaptive(prob, algs, labels, abstols, reltols, alg_ref;
253261
adaptive_ref = false,
254-
abstol_ref = 1e-14,
262+
abstol_ref = 1e-14,
255263
reltol_ref = 1e-13,
256264
compute_error = rel_max_error_tend,
257-
seconds = 2,
258-
numruns = 20,
265+
seconds = 2,
266+
numruns = 20,
259267
kwargs...)
260268
261-
Returns a dictionary to create work-precision diagrams.
262-
The problem `prob` is solved by each algorithm in `algs` for all tolerances defined in `abstols` and `reltols`.
263-
For the respective tolerances the error and computing time are stored in the dictionary.
269+
Returns a dictionary to create work-precision diagrams.
270+
The problem `prob` is solved by each algorithm in `algs` for all tolerances defined in `abstols` and `reltols`.
271+
For the respective tolerances the error and computing time are stored in the dictionary.
264272
If the solve is not successful for the given tolerances, then `(Inf, Inf)` is stored in the dictionary.
265-
The strings in the array `labels` are used as keys of the dictionary.
273+
The strings in the array `labels` are used as keys of the dictionary.
266274
The reference solution used for error computations is computed with the algorithm `alg_ref`.
267275
Additional keyword arguments are passed on to `solve`.
268276

test/runtests.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,7 +2283,7 @@ end
22832283
end
22842284

22852285
# Here we run a single scheme multiple times and check
2286-
# that the errors are identical and that the computing times
2286+
# that the errors are identical and that the computing times
22872287
# differ only slightly.
22882288
@testset "work-precision fixed" begin
22892289
prob = prob_pds_nonlinmod
@@ -2304,7 +2304,7 @@ end
23042304
@test all(y -> y == v[1], v)
23052305
end
23062306

2307-
# check that computing times are close enough
2307+
# check that computing times are close enough
23082308
for (i, _) in enumerate(dts)
23092309
v = [value[i][2] for (key, value) in wp]
23102310
m1 = mean(v)
@@ -2316,10 +2316,10 @@ end
23162316
end
23172317

23182318
# Here we run a single scheme multiple times and check
2319-
# that the errors are identical and that the computing times
2319+
# that the errors are identical and that the computing times
23202320
# differ only slightly.
23212321
@testset "work-precision adaptive" begin
2322-
@testset "adatpive_ref = false" begin
2322+
@testset "adaptive_ref = false" begin
23232323
prob = prob_pds_nonlinmod
23242324
alg = MPRK22(1.0)
23252325
algs = [alg; alg; alg; alg; alg]
@@ -2341,18 +2341,18 @@ end
23412341
@test all(y -> y == v[1], v)
23422342
end
23432343

2344-
# check that computing times are close enough
2344+
# check that computing times are close enough
23452345
for (i, _) in enumerate(abstols)
23462346
v = [value[i][2] for (key, value) in wp]
23472347
m1 = mean(v)
23482348
# This test allows computing times that are
23492349
# 2.5 times the mean value. In a loglog plot these
2350-
# differences won't be significant.
2350+
# differences won't be significant.
23512351
@test maximum((v .- m1) ./ m1) < 1.5
23522352
end
23532353
end
23542354

2355-
@testset "adatpive_ref = true" begin
2355+
@testset "adaptive_ref = true" begin
23562356
prob = prob_pds_robertson
23572357
alg = MPRK22(1.0)
23582358
algs = [alg; alg; alg; alg; alg]
@@ -2374,13 +2374,13 @@ end
23742374
@test all(y -> y == v[1], v)
23752375
end
23762376

2377-
# check that computing times are close enough
2377+
# check that computing times are close enough
23782378
for (i, _) in enumerate(abstols)
23792379
v = [value[i][2] for (key, value) in wp]
23802380
m1 = mean(v)
23812381
# This test allows computing times that are
23822382
# 2.5 times the mean value. In a loglog plot these
2383-
# differences won't be significant.
2383+
# differences won't be significant.
23842384
@test maximum((v .- m1) ./ m1) < 1.5
23852385
end
23862386
end

0 commit comments

Comments
 (0)