@@ -28,7 +28,8 @@ argdims(::ArrayStyle, ::Type{T}) where {T<:AbstractArray} = ndims(T)
2828argdims (:: ArrayStyle , :: Type{T} ) where {N,T<: CartesianIndex{N} } = N
2929argdims (:: ArrayStyle , :: Type{T} ) where {N,T<: AbstractArray{CartesianIndex{N}} } = N
3030argdims (:: ArrayStyle , :: Type{T} ) where {N,T<: AbstractArray{<:Any,N} } = N
31- argdims (:: ArrayStyle , :: Type{T} ) where {N,T<: LogicalIndex{<:Any,<:AbstractArray{Bool,N}} } = N
31+ argdims (:: ArrayStyle , :: Type{T} ) where {N,T<: LogicalIndex{<:Any,<:AbstractArray{Bool,N}} } =
32+ N
3233@generated function argdims (s:: ArrayStyle , :: Type{T} ) where {N,T<: Tuple{Vararg{Any,N}} }
3334 e = Expr (:tuple )
3435 for p in T. parameters
@@ -116,20 +117,35 @@ flatten_new_indexer(A::Array2, args) = ...
116117@inline function flatten_args (A, args:: Tuple{Arg,Vararg{Any}} ) where {Arg}
117118 return (first (args), flatten_args (A, tail (args))... )
118119end
119- @inline function flatten_args (A, args:: Tuple{Arg,Vararg{Any}} ) where {N,Arg<: CartesianIndex{N} }
120+ @inline function flatten_args (
121+ A,
122+ args:: Tuple{Arg,Vararg{Any}} ,
123+ ) where {N,Arg<: CartesianIndex{N} }
120124 return (first (args). I... , flatten_args (A, tail (args))... )
121125end
122- @inline function flatten_args (A, args:: Tuple{Arg,Vararg{Any}} ) where {N,Arg<: LinearIndices{N} }
126+ @inline function flatten_args (
127+ A,
128+ args:: Tuple{Arg,Vararg{Any}} ,
129+ ) where {N,Arg<: LinearIndices{N} }
123130 return (eachindex (first (args)), flatten_args (A, tail (args))... )
124131end
125- @inline function flatten_args (A, args:: Tuple{Arg,Vararg{Any}} ) where {N,Arg<: CartesianIndices{N} }
132+ @inline function flatten_args (
133+ A,
134+ args:: Tuple{Arg,Vararg{Any}} ,
135+ ) where {N,Arg<: CartesianIndices{N} }
126136 return (first (args). indices... , flatten_args (A, tail (args))... )
127137end
128138# we preserve CartesianIndices{0} for dropping dimensions
129- @inline function flatten_args (A, args:: Tuple{Arg,Vararg{Any}} ) where {Arg<: CartesianIndices{0} }
139+ @inline function flatten_args (
140+ A,
141+ args:: Tuple{Arg,Vararg{Any}} ,
142+ ) where {Arg<: CartesianIndices{0} }
130143 return (first (args), flatten_args (A, tail (args))... )
131144end
132- @inline function flatten_args (A, args:: Tuple{Arg,Vararg{Any}} ) where {N,Arg<: AbstractArray{Bool,N} }
145+ @inline function flatten_args (
146+ A,
147+ args:: Tuple{Arg,Vararg{Any}} ,
148+ ) where {N,Arg<: AbstractArray{Bool,N} }
133149 if length (args) === 1
134150 if IndexStyle (A) isa IndexLinear
135151 return (LogicalIndex {Int} (first (args)),)
@@ -167,7 +183,7 @@ ArrayInterface.can_flatten(::Type{A}, ::Type{T}) where {A<:ForbiddenArray,T<:New
167183can_flatten (A, x) = can_flatten (typeof (A), typeof (x))
168184can_flatten (:: Type{A} , :: Type{T} ) where {A,T} = false
169185can_flatten (:: Type{A} , :: Type{T} ) where {A,I<: CartesianIndex ,T<: AbstractArray{I} } = false
170- can_flatten (:: Type{A} , :: Type{T} ) where {A,T<: CartesianIndices } = true
186+ can_flatten (:: Type{A} , :: Type{T} ) where {A,T<: CartesianIndices } = true
171187can_flatten (:: Type{A} , :: Type{T} ) where {A,N,T<: AbstractArray{Bool,N} } = N > 1
172188can_flatten (:: Type{A} , :: Type{T} ) where {A,N,T<: CartesianIndex{N} } = true
173189@generated function can_flatten (:: Type{A} , :: Type{T} ) where {A,T<: Tuple }
@@ -196,11 +212,18 @@ be accomplished using `to_index(axis, arg)`.
196212 end
197213end
198214@propagate_inbounds to_indices (A, args:: Tuple{} ) = to_indices (A, axes (A), ())
199- @propagate_inbounds function to_indices (A, axs:: Tuple , args:: Tuple{Arg,Vararg{Any}} ) where {Arg}
215+ @propagate_inbounds function to_indices (
216+ A,
217+ axs:: Tuple ,
218+ args:: Tuple{Arg,Vararg{Any}} ,
219+ ) where {Arg}
200220 N = argdims (A, Arg)
201221 if N > 1
202222 axes_front, axes_tail = Base. IteratorsMD. split (axs, Val (N))
203- return (to_multi_index (axes_front, first (args)), to_indices (A, axes_tail, tail (args))... )
223+ return (
224+ to_multi_index (axes_front, first (args)),
225+ to_indices (A, axes_tail, tail (args))... ,
226+ )
204227 else
205228 return (to_index (first (axs), first (args)), to_indices (A, tail (axs), tail (args))... )
206229 end
211234 end
212235 return to_indices (A, tail (axs), args)
213236end
214- @propagate_inbounds function to_indices (A, :: Tuple{} , args:: Tuple{Arg,Vararg{Any}} ) where {Arg}
237+ @propagate_inbounds function to_indices (
238+ A,
239+ :: Tuple{} ,
240+ args:: Tuple{Arg,Vararg{Any}} ,
241+ ) where {Arg}
215242 return (to_index (OneTo (1 ), first (args)), to_indices (A, (), tail (args))... )
216243end
217244to_indices (A, axs:: Tuple{} , args:: Tuple{} ) = ()
@@ -265,13 +292,21 @@ end
265292 @boundscheck checkbounds (axis, arg)
266293 return @inbounds (axis[arg])
267294end
268- @propagate_inbounds function to_index (:: IndexStyle , axis, arg:: AbstractArray{I} ) where {I<: Integer }
295+ @propagate_inbounds function to_index (
296+ :: IndexStyle ,
297+ axis,
298+ arg:: AbstractArray{I} ,
299+ ) where {I<: Integer }
269300 @boundscheck if ! checkindex (Bool, axis, arg)
270301 throw (BoundsError (axis, arg))
271302 end
272303 return arg
273304end
274- @propagate_inbounds function to_index (:: IndexStyle , axis, arg:: AbstractRange{I} ) where {I<: Integer }
305+ @propagate_inbounds function to_index (
306+ :: IndexStyle ,
307+ axis,
308+ arg:: AbstractRange{I} ,
309+ ) where {I<: Integer }
275310 @boundscheck if ! checkindex (Bool, axis, arg)
276311 throw (BoundsError (axis, arg))
277312 end
@@ -291,7 +326,8 @@ function unsafe_reconstruct(A::OneTo, data; kwargs...)
291326 if can_change_size (A)
292327 return typeof (A)(data)
293328 else
294- if data isa Slice || ! (known_length (A) === nothing || known_length (A) != = known_length (data))
329+ if data isa Slice ||
330+ ! (known_length (A) === nothing || known_length (A) != = known_length (data))
295331 return A
296332 else
297333 return OneTo (data)
@@ -302,7 +338,8 @@ function unsafe_reconstruct(A::UnitRange, data; kwargs...)
302338 if can_change_size (A)
303339 return typeof (A)(data)
304340 else
305- if data isa Slice || ! (known_length (A) === nothing || known_length (A) != = known_length (data))
341+ if data isa Slice ||
342+ ! (known_length (A) === nothing || known_length (A) != = known_length (data))
306343 return A
307344 else
308345 return UnitRange (data)
@@ -313,7 +350,8 @@ function unsafe_reconstruct(A::OptionallyStaticUnitRange, data; kwargs...)
313350 if can_change_size (A)
314351 return typeof (A)(data)
315352 else
316- if data isa Slice || ! (known_length (A) === nothing || known_length (A) != = known_length (data))
353+ if data isa Slice ||
354+ ! (known_length (A) === nothing || known_length (A) != = known_length (data))
317355 return A
318356 else
319357 return OptionallyStaticUnitRange (data)
@@ -344,7 +382,11 @@ pair of axes and indices calling [`to_axis`](@ref).
344382end
345383to_axes (A, :: Tuple{Ax,Vararg{Any}} , :: Tuple{} ) where {Ax} = ()
346384to_axes (A, :: Tuple{} , :: Tuple{} ) = ()
347- @propagate_inbounds function to_axes (A, axs:: Tuple{Ax,Vararg{Any}} , inds:: Tuple{I,Vararg{Any}} ) where {Ax,I}
385+ @propagate_inbounds function to_axes (
386+ A,
387+ axs:: Tuple{Ax,Vararg{Any}} ,
388+ inds:: Tuple{I,Vararg{Any}} ,
389+ ) where {Ax,I}
348390 N = argdims (A, I)
349391 if N === 0
350392 # drop this dimension
@@ -355,7 +397,10 @@ to_axes(A, ::Tuple{}, ::Tuple{}) = ()
355397 # Only multidimensional AbstractArray{Bool} and AbstractVector{CartesianIndex{N}}
356398 # make it to this point. They collapse several dimensions into one.
357399 axes_front, axes_tail = Base. IteratorsMD. split (axs, Val (N))
358- return (to_multi_axis (IndexStyle (A), axes_front, first (inds)), to_axes (A, axes_tail, tail (inds))... )
400+ return (
401+ to_multi_axis (IndexStyle (A), axes_front, first (inds)),
402+ to_axes (A, axes_tail, tail (inds))... ,
403+ )
359404 end
360405end
361406
@@ -368,7 +413,8 @@ previously executed `to_index(old_axis, arg) -> index`. `to_axis` assumes that
368413`new_axis` begins at one and extends the length of `index` (i.e., one-based indexing).
369414"""
370415@inline function to_axis (axis, inds)
371- if ! can_change_size (axis) && (known_length (inds) != = nothing && known_length (axis) === known_length (inds))
416+ if ! can_change_size (axis) &&
417+ (known_length (inds) != = nothing && known_length (axis) === known_length (inds))
372418 return axis
373419 else
374420 return to_axis (IndexStyle (axis), axis, inds)
@@ -497,8 +543,7 @@ Store the given values at the given key or index within a collection.
497543 if can_setindex (A)
498544 return unsafe_setindex! (A, val, to_indices (A, args))
499545 else
500- error (" Instance of type $(typeof (A)) are not mutable and cannot change " *
501- " elements after construction." )
546+ error (" Instance of type $(typeof (A)) are not mutable and cannot change elements after construction." )
502547 end
503548end
504549@propagate_inbounds function setindex! (A, val; kwargs... )
@@ -533,7 +578,7 @@ have been checked for being in bounds. Any new array type using `ArrayInterface.
533578must define `unsafe_set_element!(::NewArrayType, val, inds)`.
534579"""
535580function unsafe_set_element! (A, val, inds; kwargs... )
536- throw (MethodError (unsafe_set_element!, (A, val, inds)))
581+ return throw (MethodError (unsafe_set_element!, (A, val, inds)))
537582end
538583function unsafe_set_element! (A:: Array{T} , val, inds:: Tuple ) where {T}
539584 if length (inds) === 0
@@ -555,7 +600,6 @@ Sets `inds` of `A` to `val`. `inds` is assumed to have been bounds-checked.
555600 return _unsafe_setindex! (IndexStyle (A), A, val, inds... ; kwargs... )
556601end
557602
558-
559603# these let us use `@ncall` on getindex/setindex! that have kwargs
560604function _setindex_kwargs! (x, val, kwargs, args... )
561605 @inbounds setindex! (x, val, args... ; kwargs... )
@@ -569,7 +613,7 @@ function _generate_unsafe_getindex!_body(N::Int)
569613 Base. @_inline_meta
570614 D = eachindex (dest)
571615 Dy = iterate (D)
572- @inbounds Base. Cartesian. @nloops $ N j d-> I[d] begin
616+ @inbounds Base. Cartesian. @nloops $ N j d -> I[d] begin
573617 # This condition is never hit, but at the moment
574618 # the optimizer is not clever enough to split the union without it
575619 Dy === nothing && return dest
@@ -584,11 +628,11 @@ end
584628function _generate_unsafe_setindex!_body (N:: Int )
585629 quote
586630 x′ = Base. unalias (A, x)
587- Base. Cartesian. @nexprs $ N d-> (I_d = Base. unalias (A, I[d]))
631+ Base. Cartesian. @nexprs $ N d -> (I_d = Base. unalias (A, I[d]))
588632 idxlens = Base. Cartesian. @ncall $ N Base. index_lengths I
589- Base. Cartesian. @ncall $ N Base. setindex_shape_check x′ (d-> idxlens[d])
633+ Base. Cartesian. @ncall $ N Base. setindex_shape_check x′ (d -> idxlens[d])
590634 Xy = iterate (x′)
591- @inbounds Base. Cartesian. @nloops $ N i d-> I_d begin
635+ @inbounds Base. Cartesian. @nloops $ N i d -> I_d begin
592636 # This is never reached, but serves as an assumption for
593637 # the optimizer that it does not need to emit error paths
594638 Xy === nothing && break
@@ -600,11 +644,21 @@ function _generate_unsafe_setindex!_body(N::Int)
600644 end
601645end
602646
603- @generated function _unsafe_getindex! (dest:: AbstractArray , src:: AbstractArray , I:: Vararg{Union{Real, AbstractArray}, N} ; kwargs... ) where N
604- _generate_unsafe_getindex!_body (N)
647+ @generated function _unsafe_getindex! (
648+ dest:: AbstractArray ,
649+ src:: AbstractArray ,
650+ I:: Vararg{Union{Real,AbstractArray},N} ;
651+ kwargs... ,
652+ ) where {N}
653+ return _generate_unsafe_getindex!_body (N)
605654end
606655
607- @generated function _unsafe_setindex! (:: IndexStyle , A:: AbstractArray , x, I:: Vararg{Union{Real,AbstractArray}, N} ; kwargs... ) where N
608- _generate_unsafe_setindex!_body (N)
656+ @generated function _unsafe_setindex! (
657+ :: IndexStyle ,
658+ A:: AbstractArray ,
659+ x,
660+ I:: Vararg{Union{Real,AbstractArray},N} ;
661+ kwargs... ,
662+ ) where {N}
663+ return _generate_unsafe_setindex!_body (N)
609664end
610-
0 commit comments