Skip to content

Commit c803d25

Browse files
Merge pull request #201 from LilithHafner/lh/format
Run JuliaFormatter.format()
2 parents c7a3e7f + 4624d56 commit c803d25

19 files changed

+165
-133
lines changed

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ makedocs(sitename = "DiffEqCallbacks.jl",
1414
modules = [DiffEqCallbacks],
1515
clean = true, doctest = false, linkcheck = true,
1616
linkcheck_ignore = [
17-
"https://www.sciencedirect.com/science/article/pii/S0096300304009683",
17+
"https://www.sciencedirect.com/science/article/pii/S0096300304009683"
1818
],
1919
warnonly = [:missing_docs],
2020
format = Documenter.HTML(assets = ["assets/favicon.ico"],

docs/pages.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ pages = [
88
"steady_state.md",
99
"step_control.md",
1010
"projection.md",
11-
"uncertainty_quantification.md",
11+
"uncertainty_quantification.md"
1212
]

src/DiffEqCallbacks.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module DiffEqCallbacks
22

33
using DiffEqBase, RecursiveArrayTools, DataStructures, RecipesBase, LinearAlgebra,
4-
StaticArraysCore, NLsolve, ForwardDiff, Functors
4+
StaticArraysCore, NLsolve, ForwardDiff, Functors
55

66
import Base.Iterators
77

src/domain.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct GeneralDomainAffect{autonomous, F, T, S, uType} <: AbstractDomainAffect{T
1616
resid::uType
1717

1818
function GeneralDomainAffect{autonomous}(g::F, abstol::T, scalefactor::S, u::uType,
19-
resid::uType) where {autonomous, F, T, S, uType
19+
resid::uType) where {autonomous, F, T, S, uType
2020
}
2121
new{autonomous, F, T, S, uType}(g, abstol, scalefactor, u, resid)
2222
end
@@ -94,7 +94,7 @@ function affect!(integrator, f::AbstractDomainAffect{T, S, uType}) where {T, S,
9494
if dtcache == dt
9595
if integrator.opts.verbose
9696
@warn("Could not restrict values to domain. Iteration was canceled since ",
97-
"proposed time step dt = ", dt, " could not be reduced.")
97+
"proposed time step dt = ", dt," could not be reduced.")
9898
end
9999
break
100100
end
@@ -190,7 +190,7 @@ function setup(f::GeneralDomainAffect, integrator)
190190
end
191191

192192
function isaccepted(u, p, t, abstol, f::GeneralDomainAffect{autonomous, F, T, S, uType},
193-
resid) where {autonomous, F, T, S, uType}
193+
resid) where {autonomous, F, T, S, uType}
194194
# calculate residuals
195195
if autonomous
196196
f.g(resid, u, p)
@@ -264,17 +264,18 @@ Non-negative solutions of ODEs. Applied Mathematics and Computation 170
264264
(2005): 556-569.
265265
"""
266266
function GeneralDomain(g, u = nothing; nlsolve = NLSOLVEJL_SETUP(), save = true,
267-
abstol = nothing, scalefactor = nothing,
268-
autonomous = maximum(SciMLBase.numargs(g)) == 3,
269-
nlopts = Dict(:ftol => 10 * eps()))
267+
abstol = nothing, scalefactor = nothing,
268+
autonomous = maximum(SciMLBase.numargs(g)) == 3,
269+
nlopts = Dict(:ftol => 10 * eps()))
270270
if u isa Nothing
271271
affect! = GeneralDomainAffect{autonomous}(g, abstol, scalefactor, nothing, nothing)
272272
else
273273
affect! = GeneralDomainAffect{autonomous}(g, abstol, scalefactor, deepcopy(u),
274274
deepcopy(u))
275275
end
276276
condition = (u, t, integrator) -> true
277-
CallbackSet(ManifoldProjection(g; nlsolve = nlsolve, save = false,
277+
CallbackSet(
278+
ManifoldProjection(g; nlsolve = nlsolve, save = false,
278279
autonomous = autonomous, nlopts = nlopts),
279280
DiscreteCallback(condition, affect!; save_positions = (false, save)))
280281
end

src/function_caller.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ which gets calls at the time points of interest. The constructor is:
8282
be adapted if `tspan[1] > tspan[end]`.
8383
"""
8484
function FunctionCallingCallback(func;
85-
funcat = Vector{Float64}(),
86-
func_everystep = isempty(funcat),
87-
func_start = true,
88-
tdir = 1)
85+
funcat = Vector{Float64}(),
86+
func_everystep = isempty(funcat),
87+
func_start = true,
88+
tdir = 1)
8989
# funcat conversions, see OrdinaryDiffEq.jl -> integrators/type.jl
9090
if funcat isa Number
9191
# expand to range using tspan in functioncalling_initialize

src/independentlylinearizedutils.jl

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ mutable struct IndependentlyLinearizedSolutionChunks{T, S}
1818
u_offsets::Vector{Int}
1919
t_offset::Int
2020

21-
function IndependentlyLinearizedSolutionChunks{T, S}(num_us::Int, num_derivatives::Int = 0,
21+
function IndependentlyLinearizedSolutionChunks{T, S}(
22+
num_us::Int, num_derivatives::Int = 0,
2223
chunk_size::Int = 100) where {T, S}
2324
return new([Vector{T}(undef, chunk_size)],
24-
[[Matrix{S}(undef, num_derivatives+1, chunk_size)] for _ in 1:num_us],
25+
[[Matrix{S}(undef, num_derivatives + 1, chunk_size)] for _ in 1:num_us],
2526
[BitMatrix(undef, num_us, chunk_size)],
2627
[1 for _ in 1:num_us],
27-
1,
28+
1
2829
)
2930
end
3031
end
@@ -69,7 +70,7 @@ function get_chunks(ilsc::IndependentlyLinearizedSolutionChunks{T, S}) where {T,
6970
# Check if we need to allocate any new `u` chunks (but only for those with `u_mask`)
7071
for (u_idx, u_chunks) in enumerate(ilsc.u_chunks)
7172
if ilsc.u_offsets[u_idx] > chunksize
72-
push!(u_chunks, Matrix{S}(undef, num_derivatives(ilsc)+1, chunksize))
73+
push!(u_chunks, Matrix{S}(undef, num_derivatives(ilsc) + 1, chunksize))
7374
ilsc.u_offsets[u_idx] = 1
7475
end
7576
end
@@ -78,7 +79,7 @@ function get_chunks(ilsc::IndependentlyLinearizedSolutionChunks{T, S}) where {T,
7879
return (
7980
ilsc.t_chunks[end],
8081
ilsc.time_masks[end],
81-
[u_chunks[end] for u_chunks in ilsc.u_chunks],
82+
[u_chunks[end] for u_chunks in ilsc.u_chunks]
8283
)
8384
end
8485

@@ -91,24 +92,25 @@ function get_prev_t(ilsc::IndependentlyLinearizedSolutionChunks)
9192
return -Inf
9293
end
9394
# Otherwise, return the last element of the previous chunk
94-
return ilsc.t_chunks[end-1][end]
95+
return ilsc.t_chunks[end - 1][end]
9596
end
9697
# Otherwise return the previous element of the current chunk
97-
return ilsc.t_chunks[end][ilsc.t_offset-1]
98+
return ilsc.t_chunks[end][ilsc.t_offset - 1]
9899
end
99100

100-
function get_prev_u(ilsc::IndependentlyLinearizedSolutionChunks{T,S}, u_out::Vector{S}) where {T,S}
101+
function get_prev_u(
102+
ilsc::IndependentlyLinearizedSolutionChunks{T, S}, u_out::Vector{S}) where {T, S}
101103
for u_idx in 1:length(ilsc.u_offsets)
102104
if ilsc.u_offsets[u_idx] == 1
103105
if length(ilsc.u_chunks[u_idx]) == 1
104106
# If we have never stored anything for this `u`, just return `0.0`
105107
u_out[u_idx] = S(0)
106108
end
107109
# Otherwise, get the last element of the previous chunk
108-
u_out[u_idx] = ilsc.u_chunks[u_idx][end-1][end]
110+
u_out[u_idx] = ilsc.u_chunks[u_idx][end - 1][end]
109111
else
110112
# Otherwise, return the previous element of the current chunk
111-
u_out[u_idx] = ilsc.u_chunks[u_idx][end][ilsc.u_offsets[u_idx]-1]
113+
u_out[u_idx] = ilsc.u_chunks[u_idx][end][ilsc.u_offsets[u_idx] - 1]
112114
end
113115
end
114116
return u_out
@@ -122,9 +124,9 @@ but only the values identified by the given `u_mask`. The `us` matrix
122124
should be of the size `(num_us(ilsc), num_derivatives(ilsc))`.
123125
"""
124126
function store!(ilsc::IndependentlyLinearizedSolutionChunks{T, S},
125-
t::T,
126-
u::AbstractMatrix{S},
127-
u_mask::BitVector) where {T, S}
127+
t::T,
128+
u::AbstractMatrix{S},
129+
u_mask::BitVector) where {T, S}
128130
# If `t` has been stored before, drop it.
129131
# We don't store duplicate timepoints, even though the solver sometimes does.
130132
if get_prev_t(ilsc) == t
@@ -148,8 +150,6 @@ function store!(ilsc::IndependentlyLinearizedSolutionChunks{T, S},
148150
ilsc.t_offset += 1
149151
end
150152

151-
152-
153153
"""
154154
IndependentlyLinearizedSolution
155155
@@ -171,35 +171,39 @@ mutable struct IndependentlyLinearizedSolution{T, S}
171171

172172
# Bitmatrix denoting which time indices are used for which us.
173173
time_mask::BitMatrix
174-
174+
175175
# Temporary object used during construction, will be set to `nothing` at the end.
176-
ilsc::Union{Nothing,IndependentlyLinearizedSolutionChunks{T,S}}
176+
ilsc::Union{Nothing, IndependentlyLinearizedSolutionChunks{T, S}}
177177
end
178178
# Helper function to create an ILS wrapped around an in-progress ILSC
179-
function IndependentlyLinearizedSolution(ilsc::IndependentlyLinearizedSolutionChunks{T,S}) where {T,S}
179+
function IndependentlyLinearizedSolution(ilsc::IndependentlyLinearizedSolutionChunks{
180+
T, S}) where {T, S}
180181
ils = IndependentlyLinearizedSolution(
181182
T[],
182183
Matrix{S}[],
183-
BitMatrix(undef, 0,0),
184-
ilsc,
184+
BitMatrix(undef, 0, 0),
185+
ilsc
185186
)
186187
return ils
187188
end
188189
# Automatically create an ILS wrapped around an ILSC from a `prob`
189-
function IndependentlyLinearizedSolution(prob::SciMLBase.AbstractDEProblem, num_derivatives = 0)
190+
function IndependentlyLinearizedSolution(
191+
prob::SciMLBase.AbstractDEProblem, num_derivatives = 0)
190192
T = eltype(prob.tspan)
191193
U = isnothing(prob.u0) ? Float64 : eltype(prob.u0)
192194
N = isnothing(prob.u0) ? 0 : length(prob.u0)
193-
chunks = IndependentlyLinearizedSolutionChunks{T,U}(N, num_derivatives)
195+
chunks = IndependentlyLinearizedSolutionChunks{T, U}(N, num_derivatives)
194196
return IndependentlyLinearizedSolution(chunks)
195197
end
196198

197-
num_derivatives(ils::IndependentlyLinearizedSolution) = !isempty(ils.us) ? size(first(ils.us), 1) : 0
199+
function num_derivatives(ils::IndependentlyLinearizedSolution)
200+
!isempty(ils.us) ? size(first(ils.us), 1) : 0
201+
end
198202
num_us(ils::IndependentlyLinearizedSolution) = length(ils.us)
199203
Base.size(ils::IndependentlyLinearizedSolution) = size(ils.time_mask)
200204
Base.length(ils::IndependentlyLinearizedSolution) = length(ils.ts)
201205

202-
function finish!(ils::IndependentlyLinearizedSolution{T, S}, return_code) where {T,S}
206+
function finish!(ils::IndependentlyLinearizedSolution{T, S}, return_code) where {T, S}
203207
function trim_chunk(chunks::Vector, offset)
204208
chunks = [chunk for chunk in chunks]
205209
if eltype(chunks) <: AbstractVector
@@ -225,7 +229,7 @@ function finish!(ils::IndependentlyLinearizedSolution{T, S}, return_code) where
225229
ts = vcat(trim_chunk(ilsc.t_chunks, ilsc.t_offset)...)
226230
time_mask = hcat(trim_chunk(ilsc.time_masks, ilsc.t_offset)...)
227231
us = [hcat(trim_chunk(ilsc.u_chunks[u_idx], ilsc.u_offsets[u_idx])...)
228-
for u_idx in 1:length(ilsc.u_chunks)]
232+
for u_idx in 1:length(ilsc.u_chunks)]
229233
end
230234

231235
# Sanity-check lengths
@@ -317,7 +321,7 @@ end
317321
function Base.seek(ils::IndependentlyLinearizedSolution, t_idx = 1)
318322
return [ILSStateCursor(ils, u_idx, t_idx) for u_idx in 1:length(ils.us)]
319323
end
320-
function iteration_state(ils::IndependentlyLinearizedSolution{T, S}, t_idx=1) where {T, S}
324+
function iteration_state(ils::IndependentlyLinearizedSolution{T, S}, t_idx = 1) where {T, S}
321325
# Nice little hack so we don't have to allocate `u` over and over again
322326
u = zeros(S, (num_us(ils), num_derivatives(ils)))
323327
cursors = seek(ils, t_idx)
@@ -334,7 +338,7 @@ function Base.iterate(ils::IndependentlyLinearizedSolution{T, S},
334338
for deriv_idx in 0:(size(u, 2) - 1)
335339
for u_idx in 1:size(u, 1)
336340
cursors[u_idx] = seek_forward(ils, cursors[u_idx], t)
337-
u[u_idx, deriv_idx+1] = interpolate(ils, cursors[u_idx], t, deriv_idx)
341+
u[u_idx, deriv_idx + 1] = interpolate(ils, cursors[u_idx], t, deriv_idx)
338342
end
339343
end
340344

@@ -347,9 +351,9 @@ end
347351
Batch-sample `ils` at the given timepoints for the given derivative level, storing into `out`.
348352
"""
349353
function sample!(out::Matrix{S},
350-
ils::IndependentlyLinearizedSolution{T, S},
351-
ts::AbstractVector{T},
352-
deriv_idx::Int = 0) where {T, S}
354+
ils::IndependentlyLinearizedSolution{T, S},
355+
ts::AbstractVector{T},
356+
deriv_idx::Int = 0) where {T, S}
353357
sampled_size = (length(ts), length(ils.us))
354358
if size(out) != sampled_size
355359
throw(ArgumentError("Output size ($(size(out))) != sampled size ($(sampled_size))"))
@@ -366,8 +370,8 @@ function sample!(out::Matrix{S},
366370
return out
367371
end
368372
function sample(ils::IndependentlyLinearizedSolution{T, S},
369-
ts::AbstractVector{T},
370-
deriv_idx::Int = 0) where {T, S}
373+
ts::AbstractVector{T},
374+
deriv_idx::Int = 0) where {T, S}
371375
out = Matrix{S}(undef, length(ts), length(ils.us))
372376
return sample!(out, ils, ts, deriv_idx)
373377
end

src/integrating.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ gauss_points = [[0.0],
4141
-0.2386191860831969,
4242
0.2386191860831969,
4343
0.6612093864662645,
44-
0.932469514203152,
44+
0.932469514203152
4545
],
4646
[
4747
-0.9491079123427586,
@@ -50,7 +50,7 @@ gauss_points = [[0.0],
5050
0.0,
5151
0.4058451513773972,
5252
0.7415311855993945,
53-
0.9491079123427586,
53+
0.9491079123427586
5454
],
5555
[
5656
-0.9602898564975363,
@@ -60,7 +60,7 @@ gauss_points = [[0.0],
6060
0.1834346424956498,
6161
0.525532409916329,
6262
0.7966664774136267,
63-
0.9602898564975363,
63+
0.9602898564975363
6464
],
6565
[
6666
-0.9681602395076261,
@@ -71,7 +71,7 @@ gauss_points = [[0.0],
7171
0.3242534234038089,
7272
0.6133714327005904,
7373
0.8360311073266358,
74-
0.9681602395076261,
74+
0.9681602395076261
7575
],
7676
[
7777
-0.9739065285171717,
@@ -83,7 +83,7 @@ gauss_points = [[0.0],
8383
0.4333953941292472,
8484
0.6794095682990244,
8585
0.8650633666889845,
86-
0.9739065285171717,
86+
0.9739065285171717
8787
]]
8888
"""
8989
gauss_weights::Vector{Vector{Float64}}
@@ -100,15 +100,15 @@ gauss_weights = [[2.0],
100100
0.47862867049936647,
101101
0.5688888888888889,
102102
0.47862867049936647,
103-
0.23692688505618908,
103+
0.23692688505618908
104104
],
105105
[
106106
0.17132449237917025,
107107
0.3607615730481385,
108108
0.46791393457269126,
109109
0.46791393457269126,
110110
0.3607615730481385,
111-
0.17132449237917025,
111+
0.17132449237917025
112112
],
113113
[
114114
0.1294849661688702,
@@ -117,7 +117,7 @@ gauss_weights = [[2.0],
117117
0.4179591836734694,
118118
0.3818300505051189,
119119
0.2797053914892766,
120-
0.1294849661688702,
120+
0.1294849661688702
121121
],
122122
[
123123
0.10122853629037676,
@@ -127,7 +127,7 @@ gauss_weights = [[2.0],
127127
0.36268378337836193,
128128
0.31370664587788744,
129129
0.22238103445337445,
130-
0.10122853629037676,
130+
0.10122853629037676
131131
],
132132
[
133133
0.08127438836157437,
@@ -138,7 +138,7 @@ gauss_weights = [[2.0],
138138
0.31234707704000275,
139139
0.2606106964029354,
140140
0.18064816069485742,
141-
0.08127438836157437,
141+
0.08127438836157437
142142
],
143143
[
144144
0.06667134430868821,
@@ -150,7 +150,7 @@ gauss_weights = [[2.0],
150150
0.2692667193099965,
151151
0.21908636251598207,
152152
0.14945134915058056,
153-
0.06667134430868821,
153+
0.06667134430868821
154154
]]
155155

156156
"""
@@ -182,7 +182,7 @@ mutable struct SavingIntegrandAffect{
182182
IntegrandFunc,
183183
tType,
184184
integrandType,
185-
integrandCacheType,
185+
integrandCacheType
186186
}
187187
integrand_func::IntegrandFunc
188188
integrand_values::IntegrandValues{tType, integrandType}
@@ -255,7 +255,7 @@ via `integrand_values.integrand`.
255255
If `integrand_func` is in-place, you must use `cache` to store the output of `integrand_func`.
256256
"""
257257
function IntegratingCallback(integrand_func, integrand_values::IntegrandValues,
258-
cache = nothing)
258+
cache = nothing)
259259
affect! = SavingIntegrandAffect(integrand_func, integrand_values, cache)
260260
condition = (u, t, integrator) -> true
261261
DiscreteCallback(condition, affect!, save_positions = (false, false))

0 commit comments

Comments
 (0)