Passing views to function without allocation

This really isn’t views; it’s the reshape (which implicitly happens when view’ing with linear indexing). This is because reshapes of Array are handled in C. Use a Julia-native reshape and it gives you what you want:

julia> @btime mul!(reshape(view($a2, :, :), :), $b, $c); # reshape of a view
  11.295 μs (0 allocations: 0 bytes)

julia> @btime mul!(Base.ReshapedArray($a2, (length($a2),), ()), $b, $c);
  11.114 μs (0 allocations: 0 bytes)

We should make the ReshapedArray constructor easier to use (and export it).

11 Likes