@@ -365,14 +365,20 @@ end
365365end
366366
367367@inline function Base. copyto! (dest:: ArrayPartition ,
368- bc:: Broadcast.Broadcasted{ArrayPartitionStyle{Style}} ) where {
369- Style,
370- }
368+ bc:: Broadcast.Broadcasted{ArrayPartitionStyle{Style}} ) where {Style}
371369 N = npartitions (dest, bc)
372- @inline function f (i)
373- copyto! (dest. x[i], unpack (bc, i))
370+ # If dest is all the same underlying array type, use for-loop
371+ if all (x isa typeof (first (dest. x)) for x in dest. x)
372+ @inbounds for i in 1 : N
373+ copyto! (dest. x[i], unpack (bc, i))
374+ end
375+ else
376+ # Fall back to original implementation for complex broadcasts
377+ @inline function f (i)
378+ copyto! (dest. x[i], unpack (bc, i))
379+ end
380+ ntuple (f, Val (N))
374381 end
375- ntuple (f, Val (N))
376382 dest
377383end
378384
411417 i) where {Style <: Broadcast.DefaultArrayStyle }
412418 Broadcast. Broadcasted {Style} (bc. f, unpack_args (i, bc. args))
413419end
414- unpack (x, :: Any ) = x
415- unpack (x:: ArrayPartition , i) = x. x[i]
420+ @inline unpack (x, :: Any ) = x
421+ @inline unpack (x:: ArrayPartition , i) = x. x[i]
416422
417423@inline function unpack_args (i, args:: Tuple )
418424 (unpack (args[1 ], i), unpack_args (i, Base. tail (args))... )
0 commit comments