Skip to content

Commit

Permalink
run julia formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
hexaeder committed Apr 17, 2024
1 parent 0b96e24 commit c335a54
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ext/PreallocationToolsReverseDiffExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ using PreallocationTools
isdefined(Base, :get_extension) ? (import ReverseDiff) : (import ..ReverseDiff)

# PreallocationTools https://github.com/SciML/PreallocationTools.jl/issues/39
function Base.getindex(b::PreallocationTools.LazyBufferCache, u::ReverseDiff.TrackedArray, s = b.sizemap(size(u)))
function Base.getindex(b::PreallocationTools.LazyBufferCache,

Check warning on line 7 in ext/PreallocationToolsReverseDiffExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/PreallocationToolsReverseDiffExt.jl#L7

Added line #L7 was not covered by tests
u::ReverseDiff.TrackedArray, s = b.sizemap(size(u)))
T = ReverseDiff.TrackedArray
buf = get!(b.bufs, (T, s)) do
# declare type since b.bufs dictionary is untyped
Expand Down
8 changes: 6 additions & 2 deletions src/PreallocationTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,18 @@ function similar_type(x::AbstractArray{T}, s::NTuple{N, Integer}) where {T, N}
typeof(similar(x, ntuple(Returns(1), N)))
end

function get_tmp(b::LazyBufferCache, u::T, s=b.sizemap(size(u))) where {T <: AbstractArray}
function get_tmp(
b::LazyBufferCache, u::T, s = b.sizemap(size(u))) where {T <: AbstractArray}
get!(b.bufs, (T, s)) do
similar(u, s) # buffer to allocate if it was not found in b.bufs
end::similar_type(u, s) # declare type since b.bufs dictionary is untyped
end

# override the [] method
Base.getindex(b::LazyBufferCache, u::T, s=b.sizemap(size(u))) where {T <: AbstractArray} = get_tmp(b, u, s)
function Base.getindex(
b::LazyBufferCache, u::T, s = b.sizemap(size(u))) where {T <: AbstractArray}
get_tmp(b, u, s)
end

# GeneralLazyBufferCache

Expand Down

0 comments on commit c335a54

Please sign in to comment.