Skip to content

Commit 378e4bb

Browse files
authored
Support for general index types (#27)
* Start adding support for general index types (with spherical harmonics as application) * Matrix indexing * quasi_reindex * QuasiCartesianIndexing works * convert tests pass * basic tests pass * Broadcast tests pass * Convert int indexing to float indexing in views * Tests pass! * v0.2 * Fixes from ContinuumArrays.jl
1 parent fbdb01d commit 378e4bb

11 files changed

+259
-249
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
*.jl.mem
44
deps/deps.jl
55
.DS_Store
6+
Manifest.toml

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
name = "QuasiArrays"
22
uuid = "c4ea9172-b204-11e9-377d-29865faadc5c"
33
authors = ["Sheehan Olver <[email protected]>"]
4-
version = "0.1.1"
4+
version = "0.2"
55

66
[deps]
77
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
88
LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02"
99
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1010

1111
[compat]
12-
ArrayLayouts = "0.1.4"
13-
LazyArrays = "0.14.7, 0.15"
12+
ArrayLayouts = "0.1.5"
13+
LazyArrays = "0.15"
1414
julia = "1.3"
1515

1616
[extras]

src/QuasiArrays.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Base: @_inline_meta, DimOrInd, OneTo, @_propagate_inbounds_meta, @_noinli
1313
import Base: ViewIndex, Slice, IdentityUnitRange, ScalarIndex, RangeIndex, view, viewindexing, ensure_indexable, index_dimsum,
1414
check_parent_index_match, reindex, _isdisjoint, unsafe_indices, _unsafe_ind2sub,
1515
_ind2sub, _sub2ind, _ind2sub_recurse, _lookup, SubArray,
16-
parentindices, reverse, ndims, checkbounds,
16+
parentindices, reverse, ndims, checkbounds, uncolon,
1717
promote_shape, maybeview, checkindex, checkbounds_indices,
1818
throw_boundserror, rdims, replace_in_print_matrix, show,
1919
hcat, vcat, hvcat
@@ -47,7 +47,7 @@ import Base.IteratorsMD
4747
export AbstractQuasiArray, AbstractQuasiMatrix, AbstractQuasiVector, materialize,
4848
QuasiArray, QuasiMatrix, QuasiVector, QuasiDiagonal, Inclusion,
4949
QuasiAdjoint, QuasiTranspose, ApplyQuasiArray, ApplyQuasiMatrix, ApplyQuasiVector,
50-
BroadcastQuasiArray, BroadcastQuasiMatrix, BroadcastQuasiVector
50+
BroadcastQuasiArray, BroadcastQuasiMatrix, BroadcastQuasiVector, indextype
5151

5252
if VERSION < v"1.3-"
5353
"""

src/abstractquasiarray.jl

Lines changed: 50 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ convert(::Type{AbstractArray{T,N}}, a::AbstractQuasiArray{<:Any,N}) where {T,N}
4242
convert(::Type{AbstractMatrix}, a::AbstractQuasiMatrix) = convert(AbstractArray, a)
4343
convert(::Type{AbstractVector}, a::AbstractQuasiVector) = convert(AbstractArray, a)
4444

45-
45+
indextype(A::AbstractQuasiArray) = Tuple{map(eltype, axes(A))...}
4646

4747

4848
"""
@@ -218,8 +218,8 @@ end
218218
keys(s::IndexStyle, A::AbstractQuasiArray, B::AbstractQuasiArray...) = eachindex(s, A, B...)
219219

220220
"""
221-
lastindex(collection) -> Number
222-
lastindex(collection, d) -> Number
221+
lastindex(collection) -> index
222+
lastindex(collection, d) -> index
223223
224224
Return the last index of `collection`. If `d` is given, return the last index of `collection` along dimension `d`.
225225
@@ -239,8 +239,8 @@ lastindex(a::AbstractQuasiArray) = (@_inline_meta; last(eachindex(IndexLinear(),
239239
lastindex(a::AbstractQuasiArray, d) = (@_inline_meta; last(axes(a, d)))
240240

241241
"""
242-
firstindex(collection) -> Number
243-
firstindex(collection, d) -> Number
242+
firstindex(collection) -> index
243+
firstindex(collection, d) -> index
244244
245245
Return the first index of `collection`. If `d` is given, return the first index of `collection` along dimension `d`.
246246
@@ -259,7 +259,7 @@ firstindex(a::AbstractQuasiArray, d) = (@_inline_meta; first(axes(a, d)))
259259
first(a::AbstractQuasiArray) = a[first(eachindex(a))]
260260
stride(A::AbstractQuasiArray, k::Integer) = strides(A)[k]
261261

262-
function isassigned(a::AbstractQuasiArray, i::Number...)
262+
function isassigned(a::AbstractQuasiArray, i...)
263263
try
264264
a[i...]
265265
true
@@ -277,11 +277,6 @@ function checkbounds(::Type{Bool}, A::AbstractQuasiArray, I...)
277277
checkbounds_indices(Bool, axes(A), I)
278278
end
279279

280-
# Linear indexing is explicitly allowed when there is only one (non-cartesian) index
281-
function checkbounds(::Type{Bool}, A::AbstractQuasiArray, i)
282-
@_inline_meta
283-
checkindex(Bool, eachindex(IndexLinear(), A), i)
284-
end
285280
# As a special extension, allow using logical arrays that match the source array exactly
286281
function checkbounds(::Type{Bool}, A::AbstractQuasiArray{<:Any,N}, I::AbstractQuasiArray{Bool,N}) where N
287282
@_inline_meta
@@ -291,7 +286,7 @@ end
291286

292287
function checkbounds(A::AbstractQuasiArray, I...)
293288
@_inline_meta
294-
checkbounds(Bool, A, I...) || throw_boundserror(A, I)
289+
checkbounds(Bool, A, to_indices(A,I)...) || throw_boundserror(A, I)
295290
nothing
296291
end
297292

@@ -302,11 +297,11 @@ similar(a::AbstractQuasiArray, ::Type{T}) where {T} = simila
302297
similar(a::AbstractQuasiArray{T}, dims::Tuple) where {T} = similar(a, T, dims)
303298
similar(a::AbstractQuasiArray{T}, dims::QuasiDimOrInd...) where {T} = similar(a, T, dims)
304299
similar(a::AbstractQuasiArray, ::Type{T}, dims::QuasiDimOrInd...) where {T} = similar(a, T, dims)
305-
similar(::Type{<:AbstractQuasiArray{T}}, shape::NTuple{N,AbstractQuasiOrVector{<:Number}}) where {N,T} =
300+
similar(::Type{<:AbstractQuasiArray{T}}, shape::NTuple{N,AbstractQuasiOrVector}) where {N,T} =
306301
QuasiArray{T,N}(undef, convert.(AbstractVector, shape))
307-
similar(a::AbstractQuasiArray, ::Type{T}, dims::NTuple{N,AbstractQuasiOrVector{<:Number}}) where {T,N} =
302+
similar(a::AbstractQuasiArray, ::Type{T}, dims::NTuple{N,AbstractQuasiOrVector}) where {T,N} =
308303
QuasiArray{T,N}(undef, convert.(AbstractVector, dims))
309-
similar(a::AbstractQuasiArray, ::Type{T}, dims::Vararg{AbstractQuasiOrVector{<:Number},N}) where {T,N} =
304+
similar(a::AbstractQuasiArray, ::Type{T}, dims::Vararg{AbstractQuasiOrVector,N}) where {T,N} =
310305
QuasiArray{T,N}(undef, convert.(AbstractVector, dims))
311306

312307
similar(a::AbstractQuasiArray{T}, m::Int) where {T} = Vector{T}(undef, m)
@@ -376,56 +371,45 @@ end
376371

377372
isempty(a::AbstractQuasiArray) = (length(a) == 0)
378373

379-
function getindex(A::AbstractQuasiArray, I...)
374+
getindex(A::AbstractQuasiArray, I...) = _getindex(indextype(A), A, I)
375+
376+
function _getindex(::Type{IND}, A::AbstractQuasiArray, I) where IND
380377
@_propagate_inbounds_meta
381-
error_if_canonical_getindex(IndexStyle(A), A, I...)
382-
_getindex(IndexStyle(A), A, to_indices(A, I)...)
378+
error_if_canonical_getindex(IndexStyle(A), A, I)
379+
_getindex(IND, IndexStyle(A), A, to_indices(A, I))
383380
end
384381
function unsafe_getindex(A::AbstractQuasiArray, I...)
385382
@_inline_meta
386383
@inbounds r = getindex(A, I...)
387384
r
388385
end
389386

390-
error_if_canonical_getindex(::IndexLinear, A::AbstractQuasiArray, ::Number) =
391-
error("getindex not defined for ", typeof(A))
392-
error_if_canonical_getindex(::IndexCartesian, A::AbstractQuasiArray{T,N}, ::Vararg{Number,N}) where {T,N} =
393-
error("getindex not defined for ", typeof(A))
394-
error_if_canonical_getindex(::IndexStyle, ::AbstractQuasiArray, ::Any...) = nothing
395-
396387
## Internal definitions
397-
_getindex(::IndexStyle, A::AbstractQuasiArray, I...) = lazy_getindex(A, I...)
388+
_getindex(_, ::IndexStyle, A::AbstractQuasiArray, I) = lazy_getindex(A, I...)
398389

399-
## IndexLinear Scalar indexing: canonical method is one Int
400-
_getindex(::IndexLinear, A::AbstractQuasiArray, i::Number) = (@_propagate_inbounds_meta; getindex(A, i))
401-
function _getindex(::IndexLinear, A::AbstractQuasiArray, I::Vararg{Number,M}) where M
402-
@_inline_meta
403-
@boundscheck checkbounds(A, I...) # generally _to_linear_index requires bounds checking
404-
@inbounds r = getindex(A, _to_linear_index(A, I...))
405-
r
406-
end
407-
_to_linear_index(A::AbstractQuasiArray, i::Number) = i
408-
_to_linear_index(A::AbstractQuasiVector, i::Number, I::Number...) = i
409-
_to_linear_index(A::AbstractQuasiArray) = 1
410-
_to_linear_index(A::AbstractQuasiArray, I::Number...) = (@_inline_meta; _sub2ind(A, I...))
411390

412-
## IndexCartesian Scalar indexing: Canonical method is full dimensionality of Numbers
413-
function _getindex(::IndexCartesian, A::AbstractQuasiArray, I::Vararg{Number,M}) where M
391+
## IndexCartesian Scalar indexing: Canonical method is full dimensionality of indices
392+
function _getindex(::Type{IND}, ::IndexCartesian, A::AbstractQuasiArray, I::IND) where {M,IND}
414393
@_inline_meta
415394
@boundscheck checkbounds(A, I...) # generally _to_subscript_indices requires bounds checking
416395
@inbounds r = getindex(A, _to_subscript_indices(A, I...)...)
417396
r
418397
end
419-
function _getindex(::IndexCartesian, A::AbstractQuasiArray{T,N}, I::Vararg{Number, N}) where {T,N}
420-
@_propagate_inbounds_meta
421-
getindex(A, I...)
422-
end
423-
_to_subscript_indices(A::AbstractQuasiArray, i::Number) = (@_inline_meta; _unsafe_ind2sub(A, i))
398+
399+
error_if_canonical_getindex(::IndexCartesian, A::AbstractQuasiArray{T,N}, I::Tuple) where {T,N} =
400+
_error_if_canonical_getindex(indextype(A), A, I)
401+
402+
_error_if_canonical_getindex(::Type{IND}, A::AbstractQuasiArray{T,N}, I::IND) where {T,N,IND} =
403+
error("getindex not defined for ", typeof(A))
404+
405+
_error_if_canonical_getindex(::Type, ::AbstractQuasiArray, ::Any...) = nothing
406+
407+
_to_subscript_indices(A::AbstractQuasiArray, i) = (@_inline_meta; _unsafe_ind2sub(A, i))
424408
_to_subscript_indices(A::AbstractQuasiArray{T,N}) where {T,N} = (@_inline_meta; fill_to_length((), 1, Val(N)))
425409
_to_subscript_indices(A::AbstractQuasiArray{T,0}) where {T} = ()
426-
_to_subscript_indices(A::AbstractQuasiArray{T,0}, i::Number) where {T} = ()
427-
_to_subscript_indices(A::AbstractQuasiArray{T,0}, I::Number...) where {T} = ()
428-
function _to_subscript_indices(A::AbstractQuasiArray{T,N}, I::Number...) where {T,N}
410+
_to_subscript_indices(A::AbstractQuasiArray{T,0}, i) where {T} = ()
411+
_to_subscript_indices(A::AbstractQuasiArray{T,0}, I...) where {T} = ()
412+
function _to_subscript_indices(A::AbstractQuasiArray{T,N}, I...) where {T,N}
429413
@_inline_meta
430414
J, Jrem = IteratorsMD.split(I, Val(N))
431415
_to_subscript_indices(A, J, Jrem)
@@ -437,51 +421,43 @@ function __to_subscript_indices(A::AbstractQuasiArray,
437421
@_inline_meta
438422
(J..., map(first, tail(_remaining_size(J, axes(A))))...)
439423
end
440-
_to_subscript_indices(A::AbstractQuasiArray{T,N}, I::Vararg{Number,N}) where {T,N} = I
424+
_to_subscript_indices(A::AbstractQuasiArray{T,N}, I::Vararg{Any,N}) where {T,N} = I
441425

442426
## Setindex! is defined similarly. We first dispatch to an internal _setindex!
443427
# function that allows dispatch on array storage
444428

445429

446430
function setindex!(A::AbstractQuasiArray, v, I...)
447431
@_propagate_inbounds_meta
448-
error_if_canonical_setindex(IndexStyle(A), A, I...)
449-
_setindex!(IndexStyle(A), A, v, to_indices(A, I)...)
432+
error_if_canonical_setindex(IndexStyle(A), A, I)
433+
_setindex!(indextype(A), IndexStyle(A), A, v, to_indices(A, I))
450434
end
451435
function unsafe_setindex!(A::AbstractQuasiArray, v, I...)
452436
@_inline_meta
453437
@inbounds r = setindex!(A, v, I...)
454438
r
455439
end
456440

457-
error_if_canonical_setindex(::IndexLinear, A::AbstractQuasiArray, ::Number) =
458-
error("setindex! not defined for ", typeof(A))
459-
error_if_canonical_setindex(::IndexCartesian, A::AbstractQuasiArray{T,N}, ::Vararg{Number,N}) where {T,N} =
441+
error_if_canonical_setindex(::IndexCartesian, A::AbstractQuasiArray{T,N}, I::Tuple) where {T,N} =
442+
_error_if_canonical_setindex(indextype(A), A, I)
443+
444+
_error_if_canonical_setindex(::Type{IND}, A::AbstractQuasiArray{T,N}, I::IND) where {T,N,IND} =
460445
error("setindex! not defined for ", typeof(A))
461-
error_if_canonical_setindex(::IndexStyle, ::AbstractQuasiArray, ::Any...) = nothing
462446

447+
_error_if_canonical_setindex(::Type, ::AbstractQuasiArray, ::Any...) = nothing
463448
## Internal definitions
464-
_setindex!(::IndexStyle, A::AbstractQuasiArray, v, I...) =
449+
_setindex!(::Type, ::IndexStyle, A::AbstractQuasiArray, v, I) =
465450
error("setindex! for $(typeof(A)) with types $(typeof(I)) is not supported")
466451

467-
## IndexLinear Scalar indexing
468-
_setindex!(::IndexLinear, A::AbstractQuasiArray, v, i::Number) = (@_propagate_inbounds_meta; setindex!(A, v, i))
469-
function _setindex!(::IndexLinear, A::AbstractQuasiArray, v, I::Vararg{Number,M}) where M
470-
@_inline_meta
471-
@boundscheck checkbounds(A, I...)
472-
@inbounds r = setindex!(A, v, _to_linear_index(A, I...))
473-
r
474-
end
475-
476452
# IndexCartesian Scalar indexing
477-
function _setindex!(::IndexCartesian, A::AbstractQuasiArray{T,N}, v, I::Vararg{Number, N}) where {T,N}
453+
function _setindex!(::Type{IND}, ::IndexCartesian, A::AbstractQuasiArray{T,N}, v, I::NTuple{N,Any}) where {T,N,IND}
478454
@_propagate_inbounds_meta
479455
setindex!(A, v, I...)
480456
end
481-
function _setindex!(::IndexCartesian, A::AbstractQuasiArray, v, I::Vararg{Number,M}) where M
457+
function _setindex!(::Type{IND}, ::IndexCartesian, A::AbstractQuasiArray, v, I::NTuple{M,Any}) where {M,IND}
482458
@_inline_meta
483459
@boundscheck checkbounds(A, I...)
484-
@inbounds r = setindex!(A, v, _to_subscript_indices(A, I...)...)
460+
@inbounds r = setindex!(A, v, _to_subscript_indices(IND, A, I...)...)
485461
r
486462
end
487463

@@ -516,8 +492,8 @@ dataids(A::AbstractQuasiArray) = (UInt(objectid(A)),)
516492

517493

518494
## structured matrix methods ##
519-
replace_in_print_matrix(A::AbstractQuasiMatrix,i::Number,j::Number,s::AbstractString) = s
520-
replace_in_print_matrix(A::AbstractQuasiVector,i::Number,j::Number,s::AbstractString) = s
495+
replace_in_print_matrix(A::AbstractQuasiMatrix,i,j,s::AbstractString) = s
496+
replace_in_print_matrix(A::AbstractQuasiVector,i,j,s::AbstractString) = s
521497

522498
## Concatenation ##
523499
eltypeof(x::AbstractQuasiArray) = eltype(x)
@@ -565,45 +541,14 @@ function (==)(A::AbstractQuasiArray, B::AbstractQuasiArray)
565541
return anymissing ? missing : true
566542
end
567543

568-
# _sub2ind and _ind2sub
569-
# fallbacks
570-
function _sub2ind(A::AbstractQuasiArray, I...)
571-
@_inline_meta
572-
_sub2ind(axes(A), I...)
573-
end
574-
575-
function _ind2sub(A::AbstractQuasiArray, ind)
576-
@_inline_meta
577-
_ind2sub(axes(A), ind)
578-
end
579-
580-
# Vectorized forms
581-
function _sub2ind(inds::Indices{1}, I1::AbstractQuasiVector{T}, I::AbstractQuasiVector{T}...) where T<:Number
582-
throw(ArgumentError("Linear indexing is not defined for one-dimensional arrays"))
583-
end
584-
_sub2ind(inds::Tuple{OneTo}, I1::AbstractQuasiVector{T}, I::AbstractQuasiVector{T}...) where {T<:Number} =
585-
_sub2ind_vecs(inds, I1, I...)
586-
_sub2ind(inds::Union{DimsInteger,Indices}, I1::AbstractQuasiVector{T}, I::AbstractQuasiVector{T}...) where {T<:Number} =
587-
_sub2ind_vecs(inds, I1, I...)
588-
function _sub2ind_vecs(inds, I::AbstractQuasiVector...)
589-
I1 = I[1]
590-
Iinds = axes1(I1)
591-
for j = 2:length(I)
592-
axes1(I[j]) == Iinds || throw(DimensionMismatch("indices of I[1] ($(Iinds)) does not match indices of I[$j] ($(axes1(I[j])))"))
593-
end
594-
Iout = similar(I1)
595-
_sub2ind!(Iout, inds, Iinds, I)
596-
Iout
597-
end
598-
599544
_lookup(ind, r::Inclusion) = ind
600545

601-
_ind2sub(dims::NTuple{N,Number}, ind::Number) where N = (@_inline_meta; _ind2sub_recurse(dims, ind-1))
602-
_ind2sub(inds::QuasiIndices, ind::Number) = (@_inline_meta; _ind2sub_recurse(inds, ind-1))
603-
_ind2sub(inds::Tuple{Inclusion{<:Number},AbstractUnitRange{<:Integer}}, ind::Number) = (@_inline_meta; _ind2sub_recurse(inds, ind-1))
604-
_ind2sub(inds::Tuple{AbstractUnitRange{<:Integer},Inclusion{<:Number}}, ind::Number) = (@_inline_meta; _ind2sub_recurse(inds, ind-1))
546+
_ind2sub(dims::NTuple{N,Any}, ind) where N = (@_inline_meta; _ind2sub_recurse(dims, ind-1))
547+
_ind2sub(inds::QuasiIndices, ind) = (@_inline_meta; _ind2sub_recurse(inds, ind-1))
548+
_ind2sub(inds::Tuple{Inclusion{<:Any},AbstractUnitRange{<:Integer}}, ind) = (@_inline_meta; _ind2sub_recurse(inds, ind-1))
549+
_ind2sub(inds::Tuple{AbstractUnitRange{<:Integer},Inclusion{<:Any}}, ind) = (@_inline_meta; _ind2sub_recurse(inds, ind-1))
605550

606-
function _ind2sub(inds::Union{NTuple{N,Number},QuasiIndices{N}}, ind::AbstractQuasiVector{<:Number}) where N
551+
function _ind2sub(inds::Union{NTuple{N,Any},QuasiIndices{N}}, ind::AbstractQuasiVector) where N
607552
M = length(ind)
608553
t = ntuple(n->similar(ind),Val(N))
609554
for (i,idx) in pairs(IndexLinear(), ind)

src/indices.jl

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,23 @@ to_index(I::AbstractQuasiArray) = I
100100
to_index(I::AbstractQuasiArray{<:Union{AbstractArray, Colon}}) =
101101
throw(ArgumentError("invalid index: $I of type $(typeof(I))"))
102102

103-
to_quasi_index(i::Number) = i
104-
to_quasi_index(i) = Base.to_index(i)
105-
to_index(A::AbstractQuasiArray, i) = to_quasi_index(i)
103+
to_quasi_index(::Type{IND}, i) where IND = convert(IND, i)
104+
to_quasi_index(::Type{IND}, I::AbstractArray) where IND<:AbstractArray = convert(IND, I)
105+
to_quasi_index(::Type{IND}, I::AbstractQuasiArray) where IND<:AbstractQuasiArray = convert(IND, I)
106+
to_quasi_index(::Type{IND}, I::AbstractArray) where IND = convert(AbstractArray{IND}, I)
107+
to_quasi_index(::Type{IND}, I::AbstractQuasiArray) where IND = convert(AbstractQuasiArray{IND}, I)
108+
to_quasi_index(::Type{IND}, I::AbstractArray{<:AbstractArray}) where IND<:AbstractArray = convert(AbstractArray{IND}, I)
109+
to_quasi_index(::Type{IND}, I::AbstractQuasiArray{<:AbstractArray}) where IND<:AbstractArray = convert(AbstractQuasiArray{IND}, I)
110+
111+
to_quasi_index(A, IND, i) = to_quasi_index(IND,i)
112+
113+
to_indices(A::AbstractQuasiArray, inds, ::Tuple{}) = ()
114+
to_indices(A::AbstractQuasiArray, inds, I::Tuple{Any,Vararg{Any}}) =
115+
(@_inline_meta; (to_quasi_index(A, eltype(inds[1]), I[1]), to_indices(A, _maybetail(inds), tail(I))...))
116+
@inline to_indices(A::AbstractQuasiArray, inds, I::Tuple{Colon, Vararg{Any}}) =
117+
(uncolon(inds, I), to_indices(A, _maybetail(inds), tail(I))...)
118+
119+
106120

107121
LinearIndices(A::AbstractQuasiArray) = LinearIndices(axes(A))
108122

@@ -164,9 +178,9 @@ size(S::Inclusion) = (cardinality(S.domain),)
164178
length(S::Inclusion) = cardinality(S.domain)
165179
unsafe_length(S::Inclusion) = cardinality(S.domain)
166180
cardinality(S::Inclusion) = cardinality(S.domain)
167-
getindex(S::Inclusion{T}, i::Number) where T =
181+
getindex(S::Inclusion{T}, i::T) where T =
168182
(@_inline_meta; @boundscheck checkbounds(S, i); convert(T,i))
169-
getindex(S::Inclusion{T}, i::AbstractVector{<:Number}) where T =
183+
getindex(S::Inclusion{T}, i::AbstractVector{T}) where T =
170184
(@_inline_meta; @boundscheck checkbounds(S, i); convert(AbstractVector{T},i))
171185
getindex(S::Inclusion, i::Inclusion) =
172186
(@_inline_meta; @boundscheck checkbounds(S, i); copy(S))
@@ -176,10 +190,10 @@ iterate(S::Inclusion, s...) = iterate(S.domain, s...)
176190

177191
in(x, S::Inclusion) = x in S.domain
178192

179-
checkindex(::Type{Bool}, inds::Inclusion, i::Number) = i inds.domain
193+
checkindex(::Type{Bool}, inds::Inclusion, i) = i inds.domain
180194
checkindex(::Type{Bool}, inds::Inclusion, ::Colon) = true
181195
checkindex(::Type{Bool}, inds::Inclusion, ::Inclusion) = true
182-
function checkindex(::Type{Bool}, inds::Inclusion, I::AbstractArray)
196+
function __checkindex(::Type{Bool}, inds::Inclusion, I::AbstractArray)
183197
@_inline_meta
184198
b = true
185199
for i in I
@@ -188,9 +202,16 @@ function checkindex(::Type{Bool}, inds::Inclusion, I::AbstractArray)
188202
b
189203
end
190204

191-
function checkindex(::Type{Bool}, inds::Inclusion, r::AbstractRange)
205+
checkindex(::Type{Bool}, inds::Inclusion{T}, I::AbstractArray{T}) where T =
206+
__checkindex(Bool, inds, I)
207+
checkindex(::Type{Bool}, inds::Inclusion{T}, I::AbstractArray{T}) where T<:AbstractArray =
208+
__checkindex(Bool, inds, I)
209+
checkindex(::Type{Bool}, inds::Inclusion{T}, I::AbstractArray{<:AbstractArray}) where T<:AbstractArray =
210+
__checkindex(Bool, inds, convert(AbstractArray{T}, I))
211+
212+
function checkindex(::Type{Bool}, inds::Inclusion{T}, r::AbstractRange) where T
192213
@_propagate_inbounds_meta
193-
isempty(r) | (checkindex(Bool, inds, first(r)) & checkindex(Bool, inds, last(r)))
214+
isempty(r) | (checkindex(Bool, inds, convert(T, first(r))) & checkindex(Bool, inds, last(r)))
194215
end
195216
checkindex(::Type{Bool}, indx::Inclusion, I::AbstractVector{Bool}) = indx == axes1(I)
196217
checkindex(::Type{Bool}, indx::Inclusion, I::AbstractArray{Bool}) = false

0 commit comments

Comments
 (0)