Skip to content

Commit

Permalink
Merge pull request #30 from Tokazama/is_splat_index
Browse files Browse the repository at this point in the history
Support for new `is_splat_index` trait
  • Loading branch information
ChrisRackauckas authored Nov 28, 2021
2 parents 16fadeb + fecfde5 commit 2a18fc0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name = "EllipsisNotation"
uuid = "da5c29d0-fa7d-589e-88eb-ea29b0a81949"
authors = ["Chris Rackauckas <[email protected]>"]
version = "1.1.1"
version = "1.1.2"

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"

[compat]
julia = "1.5"
ArrayInterface = "3"
julia = "1.5"
11 changes: 4 additions & 7 deletions src/EllipsisNotation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,21 @@ true
module EllipsisNotation

using ArrayInterface
using ArrayInterface: indices


import Base: to_indices, tail

struct Ellipsis end
const .. = Ellipsis()
const .. = Ellipsis()

@inline function to_indices(A, inds::NTuple{M, Any}, I::Tuple{Ellipsis, Vararg{Any, N}}) where {M,N}
# Align the remaining indices to the tail of the `inds`
colons = ntuple(n->Colon(), M-N)
to_indices(A, inds, (colons..., tail(I)...))
end

Base.@propagate_inbounds function ArrayInterface.to_indices(A, inds::Tuple{Vararg{Any,M}}, I::Tuple{Ellipsis,Vararg{Any, N}}) where {M,N}
return ArrayInterface.to_indices(A, inds, (ntuple(i -> indices(inds[i]), Val(M-N))..., tail(I)...))
end
ArrayInterface.to_indices(A, inds::Tuple{}, I::Tuple{Ellipsis}) = ()
ArrayInterface.is_splat_index(::Type{Ellipsis}) = ArrayInterface.static(true)
ArrayInterface.ndims_index(::Type{Ellipsis}) = ArrayInterface.static(1)
ArrayInterface.to_index(x, ::Ellipsis) = ntuple(i -> ArrayInterface.indices(x, i), Val(ndims(x)))

export ..

Expand Down

0 comments on commit 2a18fc0

Please sign in to comment.