-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Open
Labels
broadcastApplying a function over a collectionApplying a function over a collection
Description
It would be nice if we could propagate IndexStyle
for broadcasts. The issue is the following:
julia> using BenchmarkTools
julia> n=10_000; d=1; T=Int32; a=rand(T, d*n); b=rand(T, d, n); ac=copy(a); bc=copy(b); inc=Ref(T(3));
julia> @btime broadcast!(+, ac, a, inc); @btime broadcast!(+, bc, b, inc);
2.221 μs (0 allocations: 0 bytes)
39.333 μs (0 allocations: 0 bytes)
julia> n=10_000; d=2; T=Float32; a=rand(T, d*n); b=rand(T, d, n); ac=copy(a); bc=copy(b); inc=Ref(T(3));
julia> @btime broadcast!(+, ac, a, inc); @btime broadcast!(+, bc, b, inc);
4.531 μs (0 allocations: 0 bytes)
35.019 μs (0 allocations: 0 bytes)
julia> n=10_000; d=8; T=Float64; a=rand(T, d*n); b=rand(T, d, n); ac=copy(a); bc=copy(b); inc=Ref(T(3));
julia> @btime broadcast!(+, ac, a, inc); @btime broadcast!(+, bc, b, inc);
59.652 μs (0 allocations: 0 bytes)
88.321 μs (0 allocations: 0 bytes)
Currently, broadcasts always use cartesian indexing. This is slow and prevents a lot of simd.
In the relatively common case that dest
and all args
support linear indexing, and the only cases of dropped dimensions are zero-dimensional (as above), we should use linear indexing for a significant speedup (up to 20x), especially if the first dimension is small (which is a very common occurence).
Metadata
Metadata
Assignees
Labels
broadcastApplying a function over a collectionApplying a function over a collection