I am using a simple broadcast expression, and getting a surprising (to me) result depending on whether I use views or not.
#setup a = rand(UInt64, 1000, 1000) b = rand(UInt64, 1000, 1000) c = rand(UInt64, 1000);
Doing a broadcast op without views:
@benchmark $c .= $a[10,:] .& $b[:,10] BenchmarkTools.Trial: memory estimate: 15.88 KiB allocs estimate: 2 -------------- minimum time: 3.607 μs (0.00% GC)
Doing the op when employing views is much faster:
@benchmark $c .= (@view $a[10,:]) .& (@view $b[:,10]) BenchmarkTools.Trial: memory estimate: 96 bytes allocs estimate: 2 -------------- minimum time: 1.491 μs (0.00% GC)
Obviously, the explicit use of views does not need to allocate copies of the subarrays I want to operate on. However, I was very surprised that the broadcasting does not use views automatically.
I was hoping someone can help me build a more “julia philosophy coherent” mental image of why broadcast does not automatically use views. Is this something that might be automated in future versions of Julia?