44
55# # constructors
66
7- ArrayPartition (x... ) = ArrayPartition ((x... ))
7+ ArrayPartition (x... ) = ArrayPartition ((x... , ))
88
99function ArrayPartition (x:: S , :: Type{Val{copy_x}} = Val{false }) where {S<: Tuple ,copy_x}
1010 T = promote_type (eltype .(x)... )
124124
125125Base. mapreduce (f,op,A:: ArrayPartition ) = mapreduce (f,op,(mapreduce (f,op,x) for x in A. x))
126126Base. any (f,A:: ArrayPartition ) = any (f,(any (f,x) for x in A. x))
127- function Base. copy ! (dest:: Array ,A:: ArrayPartition )
127+ function Base. copyto ! (dest:: Array ,A:: ArrayPartition )
128128 @assert length (dest) == length (A)
129129 cur = 1
130130 @inbounds for i in 1 : length (A. x)
@@ -133,7 +133,7 @@ function Base.copy!(dest::Array,A::ArrayPartition)
133133 end
134134end
135135
136- function Base. copy ! (A:: ArrayPartition ,src:: ArrayPartition )
136+ function Base. copyto ! (A:: ArrayPartition ,src:: ArrayPartition )
137137 @assert length (src) == length (A)
138138 cur = 1
139139 @inbounds for i in 1 : length (A. x)
145145# # indexing
146146
147147# Interface for the linear indexing. This is just a view of the underlying nested structure
148- @static if VERSION >= v " 0.7-"
149- @inline Base. firstindex (A:: ArrayPartition ) = 1
150- @inline Base. lastindex (A:: ArrayPartition ) = length (A)
151- else
152- @inline Base. endof (A:: ArrayPartition ) = length (A)
153- end
148+ @inline Base. firstindex (A:: ArrayPartition ) = 1
149+ @inline Base. lastindex (A:: ArrayPartition ) = length (A)
154150
155151@inline function Base. getindex (A:: ArrayPartition , i:: Int )
156152 @boundscheck checkbounds (A, i)
@@ -220,9 +216,8 @@ recursive_eltype(A::ArrayPartition) = recursive_eltype(first(A.x))
220216
221217# # iteration
222218
223- Base. start (A:: ArrayPartition ) = start (Chain (A. x))
224- Base. next (A:: ArrayPartition ,state) = next (Chain (A. x),state)
225- Base. done (A:: ArrayPartition ,state) = done (Chain (A. x),state)
219+ Base. iterate (A:: ArrayPartition ) = iterate (Chain (A. x))
220+ Base. iterate (A:: ArrayPartition ,state) = iterate (Chain (A. x),state)
226221
227222Base. length (A:: ArrayPartition ) = sum ((length (x) for x in A. x))
228223Base. size (A:: ArrayPartition ) = (length (A),)
@@ -238,14 +233,19 @@ Base.show(io::IO, m::MIME"text/plain", A::ArrayPartition) = show(io, m, A.x)
238233
239234# # broadcasting
240235
241- Base. Broadcast. _containertype (:: Type{<:ArrayPartition} ) = ArrayPartition
242- Base. Broadcast. promote_containertype (:: Type{ArrayPartition} , :: Type ) = ArrayPartition
243- Base. Broadcast. promote_containertype (:: Type , :: Type{ArrayPartition} ) = ArrayPartition
244- Base. Broadcast. promote_containertype (:: Type{ArrayPartition} , :: Type{ArrayPartition} ) = ArrayPartition
245- Base. Broadcast. promote_containertype (:: Type{ArrayPartition} , :: Type{Array} ) = ArrayPartition
246- Base. Broadcast. promote_containertype (:: Type{Array} , :: Type{ArrayPartition} ) = ArrayPartition
236+ struct APStyle <: Broadcast.BroadcastStyle end
237+ Base. BroadcastStyle (:: Type{<:ArrayPartition} ) = Broadcast. ArrayStyle {ArrayPartition} ()
238+ Base. BroadcastStyle (:: Broadcast.ArrayStyle{ArrayPartition} ,:: Broadcast.ArrayStyle ) = Broadcast. Style {ArrayPartition} ()
239+ Base. BroadcastStyle (:: Broadcast.ArrayStyle ,:: Broadcast.ArrayStyle{ArrayPartition} ) = Broadcast. Style {ArrayPartition} ()
240+ Base. similar (bc:: Broadcast.Broadcasted{Broadcast.ArrayStyle{ArrayPartition}} ,:: Type{ElType} ) where ElType = similar (bc)
241+
242+ function Base. copy (bc:: Broadcast.Broadcasted{Broadcast.ArrayStyle{ArrayPartition}} )
243+ ret = Broadcast. flatten (bc)
244+ __broadcast (ret. f,ret. args... )
245+ end
246+
247+ @generated function __broadcast (f,as... )
247248
248- @generated function Base. Broadcast. broadcast_c (f, :: Type{ArrayPartition} , as... )
249249 # common number of partitions
250250 N = npartitions (as... )
251251
@@ -254,12 +254,15 @@ Base.Broadcast.promote_containertype(::Type{Array}, ::Type{ArrayPartition}) = Ar
254254 # index partitions
255255 $ ((as[d] <: ArrayPartition ? :(as[$ d]. x[i]) : :(as[$ d])
256256 for d in 1 : length (as)). .. )))
257-
258257 build_arraypartition (N, expr)
259258end
260259
261- @generated function Base. Broadcast. broadcast_c! (f, :: Type{ArrayPartition} , :: Type ,
262- dest:: ArrayPartition , as... )
260+ function Base. copyto! (dest:: AbstractArray ,bc:: Broadcast.Broadcasted{Broadcast.ArrayStyle{ArrayPartition}} )
261+ ret = Broadcast. flatten (bc)
262+ __broadcast! (ret. f,dest,ret. args... )
263+ end
264+
265+ @generated function __broadcast! (f, dest, as... )
263266 # common number of partitions
264267 N = npartitions (dest, as... )
265268
0 commit comments