|
52 | 52 | ## Indexing utilities ##
|
53 | 53 | #########################
|
54 | 54 |
|
55 |
| -@pure increment(::Type{Val{N}}) where {N} = Val{N+1} |
56 |
| - |
57 |
| -@inline index_sizes(s::Size, inds...) = _index_sizes(s, Val{1}, (), inds...) |
58 |
| -@inline _index_sizes(s::Size, ::Type{Val{N}}, x::Tuple) where {N} = x |
59 |
| -@inline _index_sizes(s::Size, v::Type{Val{N}}, x::Tuple, ::Int, inds...) where {N} = _index_sizes(s, increment(v), (x..., Size()), inds...) |
60 |
| -@inline _index_sizes(s::Size, v::Type{Val{N}}, x::Tuple, a::StaticArray, inds...) where {N} = _index_sizes(s, increment(v), (x..., Size(a)), inds...) |
61 |
| -@inline _index_sizes(s::Size, v::Type{Val{N}}, x::Tuple, a::Colon, inds...) where {N} = _index_sizes(s, increment(v), (x..., Size(s[N])), inds...) |
62 |
| - |
63 |
| -@inline index_sizes(inds...) = _index_sizes(Val{1}, (), inds...) |
64 |
| -@inline _index_sizes(::Type{Val{N}}, x::Tuple) where {N} = x |
65 |
| -@inline _index_sizes(v::Type{Val{N}}, x::Tuple, ::Int, inds...) where {N} = _index_sizes(increment(v), (x..., Size()), inds...) |
66 |
| -@inline _index_sizes(v::Type{Val{N}}, x::Tuple, a::StaticArray, inds...) where {N} = _index_sizes(increment(v), (x..., Size(a)), inds...) |
| 55 | +@pure tail(::Type{Size{S}}) where {S} = Size{Base.tail(S)} |
| 56 | +@inline tail(::S) where {S<:Size} = tail(S)() |
| 57 | +@inline tail(s::Size{()}) = s |
| 58 | + |
| 59 | +@inline index_sizes(s::Size) = () |
| 60 | +@inline index_sizes(s::Size, ::Int, inds...) = (Size(), index_sizes(tail(s), inds...)...) |
| 61 | +@inline index_sizes(s::Size, a::StaticArray, inds...) = (Size(a), index_sizes(tail(s), inds...)...) |
| 62 | +@inline index_sizes(s::Size, ::Colon, inds...) = (Size(s[1]), index_sizes(tail(s), inds...)...) |
| 63 | + |
| 64 | +@inline index_sizes() = () |
| 65 | +@inline index_sizes(::Int, inds...) = (Size(), index_sizes(inds...)...) |
| 66 | +@inline index_sizes(a::StaticArray, inds...) = (Size(a), index_sizes(inds...)...) |
67 | 67 |
|
68 | 68 | out_index_size(ind_sizes::Type{<:Size}...) = Size(_out_index_size((), ind_sizes...))
|
69 | 69 | @inline _out_index_size(t::Tuple) = t
|
|
0 commit comments