@@ -389,7 +389,6 @@ A scalar `setindex!` which is always allowed.
389
389
"""
390
390
allowed_setindex! (x, v, i... ) = Base. setindex! (x, v, i... )
391
391
392
-
393
392
"""
394
393
ArrayIndex{N}
395
394
@@ -514,14 +513,14 @@ julia> ArrayInterface.known_step(typeof(1:4))
514
513
"""
515
514
known_step (x) = known_step (typeof (x))
516
515
known_step (:: Type{T} ) where {T} = parent_type (T) <: T ? nothing : known_step (parent_type (T))
517
- known_step (:: Type{<:AbstractUnitRange} ) = 1
516
+ known_step (@nospecialize T :: Type{<:AbstractUnitRange} ) = 1
518
517
519
518
"""
520
519
is_splat_index(::Type{T}) -> Bool
521
520
Returns `static(true)` if `T` is a type that splats across multiple dimensions.
522
521
"""
523
- is_splat_index (@nospecialize (x)) = is_splat_index (typeof (x))
524
522
is_splat_index (T:: Type ) = false
523
+ is_splat_index (@nospecialize (x)) = is_splat_index (typeof (x))
525
524
526
525
"""
527
526
ndims_index(::Type{I}) -> Int
@@ -530,11 +529,13 @@ Returns the number of dimension that an instance of `I` maps to when indexing. F
530
529
`CartesianIndex{3}` maps to 3 dimensions. If this method is not explicitly defined, then `1`
531
530
is returned.
532
531
"""
533
- ndims_index (@nospecialize (i)) = ndims_index (typeof (i))
534
- ndims_index (:: Type{I} ) where {I} = 1
535
532
ndims_index (:: Type{<:Base.AbstractCartesianIndex{N}} ) where {N} = N
536
- ndims_index (:: Type{<:AbstractArray{T}} ) where {T} = ndims_index (T)
537
- ndims_index (:: Type{<:AbstractArray{Bool,N}} ) where {N} = N
538
- ndims_index (:: Type{<:Base.LogicalIndex{<:Any,<:AbstractArray{Bool,N}}} ) where {N} = N
533
+ # preserve CartesianIndices{0} as they consume a dimension.
534
+ ndims_index (:: Type{CartesianIndices{0,Tuple{}}} ) = 1
535
+ ndims_index (@nospecialize T:: Type{<:AbstractArray{Bool}} ) = ndims (T)
536
+ ndims_index (@nospecialize T:: Type{<:AbstractArray} ) = ndims_index (eltype (T))
537
+ ndims_index (@nospecialize T:: Type{<:Base.LogicalIndex} ) = ndims (fieldtype (T, :mask ))
538
+ ndims_index (T:: DataType ) = 1
539
+ ndims_index (@nospecialize (i)) = ndims_index (typeof (i))
539
540
540
541
end # module
0 commit comments