@@ -29,8 +29,8 @@ axes_types(::Type{T}) where {T<:Array} = NTuple{ndims(T),OneTo{Int}}
29
29
return axes_types (parent_type (T))
30
30
end
31
31
end
32
- axes_types (:: Type{LinearIndices{N,R}} ) where {N,R} = R
33
- axes_types (:: Type{CartesianIndices{N,R}} ) where {N,R} = R
32
+ axes_types (:: Type{<: LinearIndices{N,R}} ) where {N,R} = R
33
+ axes_types (:: Type{<: CartesianIndices{N,R}} ) where {N,R} = R
34
34
function axes_types (:: Type{T} ) where {T<: VecAdjTrans }
35
35
Tuple{SOneTo{1 },axes_types (parent_type (T), static (1 ))}
36
36
end
40
40
function axes_types (:: Type{T} ) where {T<: PermutedDimsArray }
41
41
eachop_tuple (field_type, to_parent_dims (T), axes_types (parent_type (T)))
42
42
end
43
+ axes_types (T:: Type{<:Base.IdentityUnitRange} ) = Tuple{T}
43
44
axes_types (:: Type{<:Base.Slice{I}} ) where {I} = Tuple{Base. IdentityUnitRange{I}}
45
+ axes_types (:: Type{<:Base.Slice{I}} ) where {I<: Base.IdentityUnitRange } = Tuple{I}
44
46
function axes_types (:: Type{T} ) where {T<: AbstractRange }
45
47
if known_length (T) === nothing
46
48
return Tuple{OneTo{Int}}
@@ -207,49 +209,30 @@ end
207
209
208
210
Base. keys (x:: LazyAxis ) = keys (parent (x))
209
211
210
- Base. IndexStyle (:: Type{T} ) where {T <: LazyAxis } = IndexStyle (parent_type (T))
212
+ Base. IndexStyle (:: Type{<:LazyAxis} ) = IndexStyle (parent_type (T))
211
213
212
- can_change_size (:: Type{LazyAxis{N,P}} ) where {N,P} = can_change_size (P )
214
+ ArrayInterfaceCore . can_change_size (@nospecialize T :: Type{<: LazyAxis} ) = can_change_size (fieldtype (T, :parent ) )
213
215
214
- ArrayInterfaceCore. known_first (:: Type{LazyAxis{N,P}} ) where {N,P} = known_offsets (P, static (N))
215
- ArrayInterfaceCore. known_first (:: Type{LazyAxis{:,P}} ) where {P} = 1
216
- Base. firstindex (x:: LazyAxis ) = first (x)
216
+ ArrayInterfaceCore. known_first (:: Type{<:LazyAxis{N,P}} ) where {N,P} = known_offsets (P, static (N))
217
+ ArrayInterfaceCore. known_first (:: Type{<:LazyAxis{:,P}} ) where {P} = 1
217
218
@inline function Base. first (x:: LazyAxis{N} ):: Int where {N}
218
219
if ArrayInterfaceCore. known_first (x) === nothing
219
- return Int (offsets (parent (x), static (N)))
220
+ return Int (offsets (parent (x), StaticInt (N)))
220
221
else
221
222
return Int (known_first (x))
222
223
end
223
224
end
224
- @inline function Base. first (x:: LazyAxis{:} ):: Int
225
- if known_first (x) === nothing
226
- return first (parent (x))
227
- else
228
- return known_first (x)
229
- end
230
- end
225
+ @inline Base. first (x:: LazyAxis{:} ):: Int = Int (offset1 (getfield (x, :parent )))
231
226
ArrayInterfaceCore. known_last (:: Type{LazyAxis{N,P}} ) where {N,P} = known_last (axes_types (P, static (N)))
232
227
ArrayInterfaceCore. known_last (:: Type{LazyAxis{:,P}} ) where {P} = known_length (P)
233
228
Base. last (x:: LazyAxis ) = _last (known_last (x), x)
234
229
_last (:: Nothing , x) = last (parent (x))
235
230
_last (N:: Int , x) = N
236
231
237
- known_length (:: Type{LazyAxis{N,P}} ) where {N,P} = known_size (P, static (N))
238
- known_length (:: Type{LazyAxis{:,P}} ) where {P} = known_length (P)
239
- @inline function Base. length (x:: LazyAxis{N} ):: Int where {N}
240
- if known_length (x) === nothing
241
- return size (getfield (x, :parent ), static (N))
242
- else
243
- return known_length (x)
244
- end
245
- end
246
- @inline function Base. length (x:: LazyAxis{:} ):: Int
247
- if known_length (x) === nothing
248
- return length (parent (x))
249
- else
250
- return known_length (x)
251
- end
252
- end
232
+ known_length (:: Type{<:LazyAxis{:,P}} ) where {P} = known_length (P)
233
+ known_length (:: Type{<:LazyAxis{N,P}} ) where {N,P} = known_size (P, static (N))
234
+ @inline Base. length (x:: LazyAxis{:} ) = Base. length (getfield (x, :parent ))
235
+ @inline Base. length (x:: LazyAxis{N} ) where {N} = Base. size (getfield (x, :parent ), N)
253
236
254
237
Base. axes (x:: LazyAxis ) = (Base. axes1 (x),)
255
238
Base. axes1 (x:: LazyAxis ) = x
@@ -259,14 +242,6 @@ Base.axes(x::Slice{<:LazyAxis}) = (Base.axes1(x),)
259
242
Base. axes1 (x:: Slice{<:LazyAxis} ) = indices (parent (x. indices))
260
243
Base. to_shape (x:: LazyAxis ) = length (x)
261
244
262
- @inline function Base. checkindex (:: Type{Bool} , x:: LazyAxis , i:: CanonicalInt )
263
- if known_first (x) === nothing || known_last (x) === nothing
264
- return checkindex (Bool, parent (x), i)
265
- else # everything is static so we don't have to retrieve the axis
266
- return (! (known_first (x) > i) || ! (known_last (x) < i))
267
- end
268
- end
269
-
270
245
@propagate_inbounds function Base. getindex (x:: LazyAxis , i:: CanonicalInt )
271
246
@boundscheck checkindex (Bool, x, i) || throw (BoundsError (x, i))
272
247
return Int (i)
@@ -288,8 +263,7 @@ constructed or it is simply retrieved.
288
263
@generated function lazy_axes (x:: X ) where {X}
289
264
Expr (:block , Expr (:meta , :inline ), Expr (:tuple , [:(LazyAxis {$dim} (x)) for dim in 1 : ndims (X)]. .. ))
290
265
end
291
- lazy_axes (x:: LinearIndices ) = axes (x)
292
- lazy_axes (x:: CartesianIndices ) = axes (x)
266
+ lazy_axes (x:: Union{LinearIndices,CartesianIndices,AbstractRange} ) = axes (x)
293
267
@inline lazy_axes (x:: MatAdjTrans ) = reverse (lazy_axes (parent (x)))
294
268
@inline lazy_axes (x:: VecAdjTrans ) = (SOneTo {1} (), first (lazy_axes (parent (x))))
295
269
@inline lazy_axes (x:: PermutedDimsArray ) = permute (lazy_axes (parent (x)), to_parent_dims (x))
0 commit comments