@@ -144,45 +144,32 @@ end
144
144
return copyto! (dest, Base. Broadcast. instantiate (Base. Broadcast. Broadcasted {BS} (bc. f, bc. args, combine_blockaxes .(axes (dest),axes (bc)))))
145
145
end
146
146
147
- @generated function _generic_blockbroadcast_copyto! (dest:: AbstractArray ,
147
+ function _generic_blockbroadcast_copyto! (dest:: AbstractArray ,
148
148
bc:: Broadcasted{<:AbstractBlockStyle{NDims}, <:Any, <:Any, Args} ) where {NDims, Args <: Tuple }
149
149
150
- NArgs = length (Args. parameters)
151
-
152
- # `bvar(0, dim)` is a variable for BlockIndexRange of `dim`-th dimension
153
- # of `dest` array. `bvar(i, dim)` is a similar variable of `i`-th
154
- # argument in `bc.args`.
155
- bvar (i, dim) = Symbol (" blockindexrange_" , i, " _" , dim)
156
-
157
- function forloop (dim)
158
- if dim > 0
159
- quote
160
- for ($ (bvar (0 , dim)), $ (bvar .(1 : NArgs, dim)... ),) in zip (
161
- subblocks (dest, bs, $ dim),
162
- subblocks .(bc. args, Ref (bs), Ref ($ dim))... )
163
- $ (forloop (dim - 1 ))
164
- end
165
- end
166
- else
167
- bview (a, i) = :(_bview ($ a, $ ([bvar (i, d) for d in 1 : NDims]. .. )))
168
- destview = bview (:dest , 0 )
169
- argblocks = [bview (:(bc. args[$ i]), i) for i in 1 : NArgs]
170
- quote
171
- broadcast! (bc. f, $ destview, $ (argblocks... ))
172
- end
173
- end
150
+ NArgs = fieldcount (Args)
151
+
152
+ bs = axes (bc)
153
+ if ! blockisequal (axes (dest), bs)
154
+ copyto! (PseudoBlockArray (dest, bs), bc)
155
+ return dest
174
156
end
175
157
176
- quote
177
- bs = axes (bc)
178
- if ! blockisequal ( axes ( dest) , bs)
179
- copyto! ( PseudoBlockArray (dest , bs), bc)
180
- return dest
158
+ t = ntuple (NDims) do dim
159
+ zip (
160
+ subblocks ( dest, bs, dim),
161
+ map (x -> subblocks (x , bs, dim ), bc. args) ...
162
+ )
181
163
end
182
164
183
- $ (forloop (NDims))
184
- return dest
165
+ for inds in Iterators. product (t... )
166
+ destinds, bcinds = map (first, inds), ntuple (i -> map (x-> x[i+ 1 ], inds), NArgs)
167
+ destview = _bview (dest, destinds... )
168
+ argblocks = ntuple (i -> _bview (bc. args[i], bcinds[i]. .. ), NArgs)
169
+ broadcast! (bc. f, destview, argblocks... )
185
170
end
171
+
172
+ return dest
186
173
end
187
174
188
175
copyto! (dest:: AbstractArray ,
0 commit comments