using BenchmarkTools
function test(x, Y)
sum!(x, Y')
return nothing
end
x = rand(Float64, 100)
Y = rand(Float64, 1, 100)
@btime(test(x, Y))
I get the following:
367.952 ns (2 allocations: 96 bytes)
I don’t think I should get any allocations. Can someone please explain what’s going on? And how can I avoid such allocations? (In my real application I have to do a similar computation millions of times.)
If you restart Julia and run that code you’ll see it error out. In the shown snippet you only define a two argument method, and then run one with zero arguments. Possibly you’ve defined that one before, and it contains something that allocates.
EDIT: the issue is the adjoint. Without it, we’re back to zero allocations. I think it is indeed a bug.
EDIT2: no allocations on v1.8.1 on linux! 2 allocations in macos v1.9.0.alpha1
It shouldn’t really be necessary. I mean, loops are fine, but it’s too bad to have to use them over clean simple function calls like sum!. This here seems like a spurious allocation, which will possibly be fixed in a patch release in not too long.