-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reduce_init
undefined for Broadcasted
#41054
Comments
It seems easy to make this work, but maybe more care is needed to make it fast? With this branch: master...mcabbott:broadcast_init julia> a2 = rand(100,100); b2 = rand(100,100);
julia> bc2i = Broadcast.instantiate(Broadcast.broadcasted(*, a2, b2));
julia> s1 = @btime sum($bc2i, dims=1);
18.416 μs (1 allocation: 896 bytes)
julia> s2 = @btime sum($a2 .* $b2, dims=1);
3.964 μs (3 allocations: 79.08 KiB) I think scalar reductions were made to work in #31020. Reduction over matrices seems much slower than the example there for vectors (of the same length): julia> @btime sum($bc2i);
16.083 μs (0 allocations: 0 bytes)
53.333 μs (0 allocations: 0 bytes) # without Broadcast.instantiate
julia> @btime sum($a2 .* $b2);
4.310 μs (2 allocations: 78.20 KiB)
4.619 μs (0 allocations: 0 bytes) # for LinearAlgebra.dot
julia> a = rand(10_000); b = rand(10_000);
julia> @btime sum(Broadcast.instantiate(Broadcast.broadcasted(*, $a, $b)));
2.458 μs (0 allocations: 0 bytes)
9.291 μs (0 allocations: 0 bytes) # without Broadcast.instantiate |
@mcabbott It seems it is faster now for reducing with broadcasted. I get this with julia 1.8.2: julia> s1 = @btime sum($bc2i, dims=1);
2.767 μs (5 allocations: 1.03 KiB)
julia> s2 = @btime sum($a2 .* $b2, dims=1);
5.888 μs (3 allocations: 79.05 KiB) |
It seems |
Use |
Interesting, didn't know that exist! I wonder why we can't make this work with btw I notice you also have an |
We can make this work, #43736 is a bug fix but it's still not reviewed. Even we get #43736 merged, I'm affaid that its usage is still too limited, as there's no "reliable" way to obtain the correct eltype of a As for |
Sum over a
Broadcasted
along some dimension result inMethodError
forreduce_init
.We have
mapreduce_dim
defined for bothArray
andBroadcast
which callreduce_init
,julia/base/reducedim.jl
Lines 336 to 337 in 58ffe7e
but
reduce_init
only defined forArray
.julia/base/reducedim.jl
Line 108 in 58ffe7e
MWE:
versioninfo:
The text was updated successfully, but these errors were encountered: