I’m experimenting with functors. I noticed that when I pass an array to the functor, that it is allocating memory even if it should be possible without memory allocation.
Here is a simplified version:
struct Foo end
(::Foo)(x) = sum(x)
foo = Foo()
a = randn(10)
@btime foo($a) # 19.765 ns (1 allocation: 16 bytes)
@btime sum($a) # 5.792 ns (0 allocations: 0 bytes)
Why is foo($a)
allocating memory?
In case that it matters: I’m using Julia 1.5.3