|
124 | 124 |
|
125 | 125 | Base.mapreduce(f,op,A::ArrayPartition) = mapreduce(f,op,(mapreduce(f,op,x) for x in A.x)) |
126 | 126 | Base.any(f,A::ArrayPartition) = any(f,(any(f,x) for x in A.x)) |
| 127 | +function Base.copy!(dest::Array,A::ArrayPartition) |
| 128 | + @assert length(dest) == length(A) |
| 129 | + cur = 1 |
| 130 | + @inbounds for i in 1:length(A.x) |
| 131 | + dest[cur:(cur+length(A.x[i])-1)] .= A.x[i] |
| 132 | + cur += length(A.x[i]) |
| 133 | + end |
| 134 | +end |
| 135 | + |
| 136 | +function Base.copy!(A::ArrayPartition,src::ArrayPartition) |
| 137 | + @assert length(src) == length(A) |
| 138 | + cur = 1 |
| 139 | + @inbounds for i in 1:length(A.x) |
| 140 | + A.x[i] .= @view(src[cur:(cur+length(A.x[i])-1)]) |
| 141 | + cur += length(A.x[i]) |
| 142 | + end |
| 143 | +end |
127 | 144 |
|
128 | 145 | ## indexing |
129 | 146 |
|
@@ -225,7 +242,7 @@ Base.Broadcast.promote_containertype(::Type{Array}, ::Type{ArrayPartition}) = Ar |
225 | 242 | N = npartitions(as...) |
226 | 243 |
|
227 | 244 | # broadcast partitions separately |
228 | | - expr = :(broadcast(f, |
| 245 | + expr = :(@show "here!"; broadcast(f, |
229 | 246 | # index partitions |
230 | 247 | $((as[d] <: ArrayPartition ? :(as[$d].x[i]) : :(as[$d]) |
231 | 248 | for d in 1:length(as))...))) |
|
250 | 267 | end |
251 | 268 | end |
252 | 269 |
|
| 270 | +@generated function Base.broadcast!(f, ::Type{ArrayPartition}, ::Type, |
| 271 | + dest::Array, as...) |
| 272 | + # common number of partitions |
| 273 | + N = npartitions(dest, as...) |
| 274 | + |
| 275 | + # broadcast partitions separately |
| 276 | + quote |
| 277 | + @show "here" |
| 278 | + @show dest |
| 279 | + for i in 1:$N |
| 280 | + broadcast!(f, dest.x[i], |
| 281 | + # index partitions |
| 282 | + $((as[d] <: ArrayPartition ? :(as[$d].x[i]) : :(as[$d]) |
| 283 | + for d in 1:length(as))...)) |
| 284 | + end |
| 285 | + dest |
| 286 | + end |
| 287 | +end |
| 288 | + |
253 | 289 | ## utils |
254 | 290 |
|
255 | 291 | """ |
|
0 commit comments