Skip to content

Commit bd922ba

Browse files
committed
Run formatter
1 parent 58d4681 commit bd922ba

File tree

6 files changed

+110
-89
lines changed

6 files changed

+110
-89
lines changed

ext/DiffEqCallbacksSundialsExt.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module DiffEqCallbacksSundialsExt
33
using Sundials: NVector, IDA
44
import DiffEqCallbacks: solver_state_alloc, solver_state_type
55

6-
76
# Allocator; `U` is typically something like `Vector{Float64}`
87
solver_state_alloc(solver::IDA, U::DataType, num_us::Int) = () -> NVector(U(undef, num_us))
98

src/domain.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

src/independentlylinearizedutils.jl

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ using SciMLBase
22

33
export IndependentlyLinearizedSolution
44

5-
65
"""
76
CachePool(T, alloc; thread_safe = true)
87
@@ -40,11 +39,11 @@ mutable struct CachePool{T, THREAD_SAFE}
4039
num_acquired::Int
4140

4241
function CachePool(T, alloc::F; thread_safe::Bool = true) where {F}
43-
return new{T,Val{thread_safe}}(T[], alloc, ReentrantLock(), 0, 0)
42+
return new{T, Val{thread_safe}}(T[], alloc, ReentrantLock(), 0, 0)
4443
end
4544
end
46-
const ThreadSafeCachePool{T} = CachePool{T,Val{true}}
47-
const ThreadUnsafeCachePool{T} = CachePool{T,Val{false}}
45+
const ThreadSafeCachePool{T} = CachePool{T, Val{true}}
46+
const ThreadUnsafeCachePool{T} = CachePool{T, Val{false}}
4847

4948
"""
5049
acquire!(cache::CachePool)
@@ -78,7 +77,9 @@ end
7877
# Thread-safe versions just sub out to the other methods, using `_dummy` to force correct dispatch
7978
acquire!(cache::ThreadSafeCachePool) = @lock cache.lock acquire!(cache, nothing)
8079
release!(cache::ThreadSafeCachePool, val) = @lock cache.lock release!(cache, val, nothing)
81-
is_fully_released(cache::ThreadSafeCachePool) = @lock cache.lock is_fully_released(cache, nothing)
80+
function is_fully_released(cache::ThreadSafeCachePool)
81+
@lock cache.lock is_fully_released(cache, nothing)
82+
end
8283

8384
macro with_cache(cache, name, body)
8485
return quote
@@ -91,20 +92,20 @@ macro with_cache(cache, name, body)
9192
end
9293
end
9394

94-
95-
struct IndependentlyLinearizedSolutionChunksCache{T,S}
95+
struct IndependentlyLinearizedSolutionChunksCache{T, S}
9696
t_chunks::ThreadUnsafeCachePool{Vector{T}}
9797
u_chunks::ThreadUnsafeCachePool{Matrix{S}}
9898
time_masks::ThreadUnsafeCachePool{BitMatrix}
9999

100-
function IndependentlyLinearizedSolutionChunksCache{T,S}(num_us::Int, num_derivatives::Int, chunk_size::Int) where {T,S}
100+
function IndependentlyLinearizedSolutionChunksCache{T, S}(
101+
num_us::Int, num_derivatives::Int, chunk_size::Int) where {T, S}
101102
t_chunks_alloc = () -> Vector{T}(undef, chunk_size)
102-
u_chunks_alloc = () -> Matrix{S}(undef, num_derivatives+1, chunk_size)
103+
u_chunks_alloc = () -> Matrix{S}(undef, num_derivatives + 1, chunk_size)
103104
time_masks_alloc = () -> BitMatrix(undef, num_us, chunk_size)
104105
return new(
105-
CachePool(Vector{T}, t_chunks_alloc; thread_safe=false),
106-
CachePool(Matrix{S}, u_chunks_alloc; thread_safe=false),
107-
CachePool(BitMatrix, time_masks_alloc; thread_safe=false),
106+
CachePool(Vector{T}, t_chunks_alloc; thread_safe = false),
107+
CachePool(Matrix{S}, u_chunks_alloc; thread_safe = false),
108+
CachePool(BitMatrix, time_masks_alloc; thread_safe = false)
108109
)
109110
end
110111
end
@@ -130,16 +131,19 @@ mutable struct IndependentlyLinearizedSolutionChunks{T, S, N}
130131

131132
cache::IndependentlyLinearizedSolutionChunksCache
132133

133-
function IndependentlyLinearizedSolutionChunks{T, S}(num_us::Int, num_derivatives::Int = 0,
134+
function IndependentlyLinearizedSolutionChunks{T, S}(
135+
num_us::Int, num_derivatives::Int = 0,
134136
chunk_size::Int = 512,
135-
cache::IndependentlyLinearizedSolutionChunksCache = IndependentlyLinearizedSolutionChunksCache{T,S}(num_us, num_derivatives, chunk_size)) where {T, S}
137+
cache::IndependentlyLinearizedSolutionChunksCache = IndependentlyLinearizedSolutionChunksCache{
138+
T, S}(num_us, num_derivatives, chunk_size)) where {T, S}
136139
t_chunks = [acquire!(cache.t_chunks)]
137140
u_chunks = [[acquire!(cache.u_chunks)] for _ in 1:num_us]
138141
time_masks = [acquire!(cache.time_masks)]
139142
last_chunks = [u_chunks[u_idx][1] for u_idx in 1:num_us]
140143
u_offsets = [1 for _ in 1:num_us]
141144
t_offset = 1
142-
return new{T,S,num_derivatives}(t_chunks, u_chunks, time_masks, last_chunks, u_offsets, t_offset, cache)
145+
return new{T, S, num_derivatives}(
146+
t_chunks, u_chunks, time_masks, last_chunks, u_offsets, t_offset, cache)
143147
end
144148
end
145149

@@ -158,8 +162,7 @@ function num_us(ilsc::IndependentlyLinearizedSolutionChunks)
158162
end
159163
return length(ilsc.u_chunks)
160164
end
161-
num_derivatives(ilsc::IndependentlyLinearizedSolutionChunks{T,S,N}) where {T,S,N} = N
162-
165+
num_derivatives(ilsc::IndependentlyLinearizedSolutionChunks{T, S, N}) where {T, S, N} = N
163166

164167
function Base.isempty(ilsc::IndependentlyLinearizedSolutionChunks)
165168
return length(ilsc.t_chunks) == 1 && ilsc.t_offset == 1
@@ -187,7 +190,7 @@ function get_chunks(ilsc::IndependentlyLinearizedSolutionChunks{T, S}) where {T,
187190
return (
188191
ilsc.t_chunks[end],
189192
ilsc.time_masks[end],
190-
ilsc.last_chunks,
193+
ilsc.last_chunks
191194
)
192195
end
193196

@@ -283,37 +286,43 @@ mutable struct IndependentlyLinearizedSolution{T, S, N}
283286
time_mask::BitMatrix
284287

285288
# Temporary object used during construction, will be set to `nothing` at the end.
286-
ilsc::Union{Nothing,IndependentlyLinearizedSolutionChunks{T,S,N}}
287-
ilsc_cache_pool::Union{Nothing,ThreadSafeCachePool{IndependentlyLinearizedSolutionChunksCache{T,S}}}
289+
ilsc::Union{Nothing, IndependentlyLinearizedSolutionChunks{T, S, N}}
290+
ilsc_cache_pool::Union{
291+
Nothing, ThreadSafeCachePool{IndependentlyLinearizedSolutionChunksCache{T, S}}}
288292
end
289293
# Helper function to create an ILS wrapped around an in-progress ILSC
290-
function IndependentlyLinearizedSolution(ilsc::IndependentlyLinearizedSolutionChunks{T,S,N}, cache_pool = nothing) where {T,S,N}
291-
return IndependentlyLinearizedSolution{T,S,N}(
294+
function IndependentlyLinearizedSolution(
295+
ilsc::IndependentlyLinearizedSolutionChunks{T, S, N},
296+
cache_pool = nothing) where {T, S, N}
297+
return IndependentlyLinearizedSolution{T, S, N}(
292298
T[],
293299
Matrix{S}[],
294-
BitMatrix(undef, 0,0),
300+
BitMatrix(undef, 0, 0),
295301
ilsc,
296-
cache_pool,
302+
cache_pool
297303
)
298304
end
299305
# Automatically create an ILS wrapped around an ILSC from a `prob`
300-
function IndependentlyLinearizedSolution(prob::SciMLBase.AbstractDEProblem, num_derivatives = 0;
301-
cache_pool = nothing,
302-
chunk_size::Int = 512)
306+
function IndependentlyLinearizedSolution(
307+
prob::SciMLBase.AbstractDEProblem, num_derivatives = 0;
308+
cache_pool = nothing,
309+
chunk_size::Int = 512)
303310
T = eltype(prob.tspan)
304311
S = eltype(prob.u0)
305312
U = isnothing(prob.u0) ? Float64 : eltype(prob.u0)
306313
num_us = isnothing(prob.u0) ? 0 : length(prob.u0)
307314
if cache_pool === nothing
308-
cache = IndependentlyLinearizedSolutionChunksCache{T,S}(num_us, num_derivatives, chunk_size)
315+
cache = IndependentlyLinearizedSolutionChunksCache{T, S}(
316+
num_us, num_derivatives, chunk_size)
309317
else
310318
cache = acquire!(cache_pool)
311319
end
312-
chunks = IndependentlyLinearizedSolutionChunks{T,U}(num_us, num_derivatives, chunk_size, cache)
320+
chunks = IndependentlyLinearizedSolutionChunks{T, U}(
321+
num_us, num_derivatives, chunk_size, cache)
313322
return IndependentlyLinearizedSolution(chunks, cache_pool)
314323
end
315324

316-
num_derivatives(::IndependentlyLinearizedSolution{T,S,N}) where {T,S,N} = N
325+
num_derivatives(::IndependentlyLinearizedSolution{T, S, N}) where {T, S, N} = N
317326
num_us(ils::IndependentlyLinearizedSolution) = length(ils.us)
318327
Base.size(ils::IndependentlyLinearizedSolution) = size(ils.time_mask)
319328
Base.length(ils::IndependentlyLinearizedSolution) = length(ils.ts)
@@ -344,33 +353,34 @@ function finish!(ils::IndependentlyLinearizedSolution{T, S}, return_code) where
344353
chunk_len(chunk) = size(chunk, ndims(chunk))
345354
function chunks_len(chunks::Vector, offset)
346355
len = 0
347-
for chunk_idx in 1:length(chunks)-1
356+
for chunk_idx in 1:(length(chunks) - 1)
348357
len += chunk_len(chunks[chunk_idx])
349358
end
350359
return len + offset - 1
351360
end
352361

353-
function copy_chunk!(out::Vector, in::Vector, out_offset::Int, len=chunk_len(in))
362+
function copy_chunk!(out::Vector, in::Vector, out_offset::Int, len = chunk_len(in))
354363
for idx in 1:len
355-
out[idx+out_offset] = in[idx]
364+
out[idx + out_offset] = in[idx]
356365
end
357366
end
358-
function copy_chunk!(out::AbstractMatrix, in::AbstractMatrix, out_offset::Int, len=chunk_len(in))
367+
function copy_chunk!(out::AbstractMatrix, in::AbstractMatrix,
368+
out_offset::Int, len = chunk_len(in))
359369
for zdx in 1:size(in, 1)
360370
for idx in 1:len
361-
out[zdx, idx+out_offset] = in[zdx, idx]
371+
out[zdx, idx + out_offset] = in[zdx, idx]
362372
end
363373
end
364374
end
365375

366376
function collapse_chunks!(out, chunks, offset::Int)
367377
write_offset = 0
368-
for chunk_idx in 1:(length(chunks)-1)
378+
for chunk_idx in 1:(length(chunks) - 1)
369379
chunk = chunks[chunk_idx]
370380
copy_chunk!(out, chunk, write_offset)
371381
write_offset += chunk_len(chunk)
372382
end
373-
copy_chunk!(out, chunks[end], write_offset, offset-1)
383+
copy_chunk!(out, chunks[end], write_offset, offset - 1)
374384
end
375385

376386
# Collapse t_chunks
@@ -380,11 +390,13 @@ function finish!(ils::IndependentlyLinearizedSolution{T, S}, return_code) where
380390
# Collapse u_chunks
381391
us = Vector{Matrix{S}}(undef, length(ilsc.u_chunks))
382392
for u_idx in 1:length(ilsc.u_chunks)
383-
us[u_idx] = Matrix{S}(undef, size(ilsc.u_chunks[u_idx][1],1), chunks_len(ilsc.u_chunks[u_idx], ilsc.u_offsets[u_idx]))
393+
us[u_idx] = Matrix{S}(undef, size(ilsc.u_chunks[u_idx][1], 1),
394+
chunks_len(ilsc.u_chunks[u_idx], ilsc.u_offsets[u_idx]))
384395
collapse_chunks!(us[u_idx], ilsc.u_chunks[u_idx], ilsc.u_offsets[u_idx])
385396
end
386397

387-
time_mask = BitMatrix(undef, size(ilsc.time_masks[1], 1), chunks_len(ilsc.time_masks, ilsc.t_offset))
398+
time_mask = BitMatrix(
399+
undef, size(ilsc.time_masks[1], 1), chunks_len(ilsc.time_masks, ilsc.t_offset))
388400
collapse_chunks!(time_mask, ilsc.time_masks, ilsc.t_offset)
389401
end
390402

0 commit comments

Comments
 (0)