Skip to content

Commit

Permalink
Merge pull request #15 from oxinabox/patch-1
Browse files Browse the repository at this point in the history
Remove type-piracy
  • Loading branch information
ChrisRackauckas authored Apr 14, 2019
2 parents 787a2ed + 909b514 commit 2ee5949
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/EllipsisNotation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ __precompile__()
module EllipsisNotation

import Base: to_indices, tail
const .. = Val{:..}()

struct Ellipsis end
const .. = Ellipsis()

@inline fillcolons(inds, I) = fillcolons((), inds, I)

Expand All @@ -12,15 +14,15 @@ const .. = Val{:..}()
@inline fillcolons(colons, t::NTuple{N, <:Any}, ::NTuple{N, <:Any}) where {N} = colons
@inline fillcolons(colons, t::Tuple, s::Tuple) = fillcolons((colons..., :), tail(t), s)

@inline function to_indices(A, inds, I::Tuple{Val{:..}, Vararg{Any, N}}) where N
@inline function to_indices(A, inds, I::Tuple{Ellipsis, Vararg{Any, N}}) where N
# Align the remaining indices to the tail of the `inds`
colons = fillcolons(inds, tail(I))
to_indices(A, inds, (colons..., tail(I)...))
end

# avoid copying if indexing with .. alone, see
# https://github.com/JuliaDiffEq/OrdinaryDiffEq.jl/issues/214
@inline Base.getindex(A::AbstractArray, ::Val{:..}) = A
@inline Base.getindex(A::AbstractArray, ::Ellipsis) = A

export ..

Expand Down

0 comments on commit 2ee5949

Please sign in to comment.