Skip to content

Commit

Permalink
Switch from macro to type alias for FwdExtrapSpec
Browse files Browse the repository at this point in the history
Julia seems to have difficult tracking coverage for macros -> Switch to
using a type alias to avoid this

JuliaLang/julia#36283

Still not having coverage issues, but they go away if we disable
inlining -> julia --inline=no ...
  • Loading branch information
awadell1 committed Jan 11, 2021
1 parent 0f0f929 commit 9d8e5d5
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/iterate.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Similar to ExtrapDimSpec but for only a single dimension
const ExtrapSpec = Union{BoundaryCondition,Tuple{BoundaryCondition,BoundaryCondition}}

# Macro to get create ExtrapSpec for checking if a KnotIterator has a given BC
# for forward iteration
macro FwdExtrapSpec(bc)
:( Union{$bc,Tuple{BoundaryCondition,$bc}} )
end
# Type Alias to get Boundary Condition or forward boundary conditions if
# directional
const FwdExtrapSpec{FwdBC} = Union{FwdBC, Tuple{BoundaryCondition, FwdBC}}

"""
KnotIterator{T,ET}(k::AbstractArray{T}, bc::ET)
Expand Down Expand Up @@ -132,12 +130,12 @@ iterate(iter::KnotIterator) = iterate(iter, 1)
iterate(iter::KnotIterator, idx::Integer) = idx <= iter.nknots ? (iter.knots[idx], idx+1) : nothing

# For repeating knots state is the knot index + offset value
function iterate(iter::KnotIterator{T,ET}) where {T,ET <: @FwdExtrapSpec(RepeatKnots)}
function iterate(iter::KnotIterator{T,ET}) where {T,ET <: FwdExtrapSpec{RepeatKnots}}
iterate(iter, (1, zero(T)))
end

# Periodic: Iterate over knots, updating the offset each cycle
function iterate(iter::KnotIterator{T,ET}, state::Tuple) where {T, ET <: @FwdExtrapSpec(Periodic)}
function iterate(iter::KnotIterator{T,ET}, state::Tuple) where {T, ET <: FwdExtrapSpec{Periodic}}
state === nothing && return nothing
curidx, offset = state[1], state[2]

Expand All @@ -156,7 +154,7 @@ end

# Reflect: Iterate over knots, updating the offset after a forward and backwards
# cycle
function iterate(iter::KnotIterator{T, ET}, state) where {T, ET <: @FwdExtrapSpec(Reflect)}
function iterate(iter::KnotIterator{T, ET}, state) where {T, ET <: FwdExtrapSpec{Reflect}}
state === nothing && return nothing
curidx, offset = state[1], state[2]

Expand Down

0 comments on commit 9d8e5d5

Please sign in to comment.