- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Closed
Labels
broadcastApplying a function over a collectionApplying a function over a collectionduplicateIndicates similar issues or pull requestsIndicates similar issues or pull requests
Description
Broadcasting with boolean operators seems to be very slow in some circumstances:
See below one example with Julia 1.8.2:
julia> x = randn((100,));
julia> y = randn((1,100));
julia> @time (x.^2 .< 1) .&& (1 .+ y.^2 .<1);
0.004369 seconds (144.73 k allocations: 3.005 MiB)
julia> @btime ($x.^2 .< 1) .&& (1 .+ $y.^2 .<1);
4.009 ms (144713 allocations: 3.00 MiB)
# this works
julia> @btime ($x.^2 .< 1) .&& ($y.^2 .<1);
2.523 μs (3 allocations: 5.56 KiB)
julia> @btime ($x.^2 .< 1) .|| ($y.^2 .+ 1 .<1);
2.738 μs (3 allocations: 5.56 KiB)
Metadata
Metadata
Assignees
Labels
broadcastApplying a function over a collectionApplying a function over a collectionduplicateIndicates similar issues or pull requestsIndicates similar issues or pull requests
Activity
[-]Performance regression allocations when using broadcasting and logical operators[/-][+]Performance regression when using broadcasting and logical operators[/+][-]Performance regression when using broadcasting and logical operators[/-][+]Performance problems when using broadcasting and logical operators[/+]N5N3 commentedon Nov 8, 2022
Our
.&&
and.||
isflatten
based so I believe this is a duplication of #27988.With #43322, I get
So perhaps
.&
is always a better choice here.Broadcast.flatten(bc).f
more complier frendly. (better inferred and inlined) #43322Make `Broadcast.flatten(bc).f` more complier frendly. (better inferre…