Reshape() still allocating memory in Julia 1.5.0

It is great to see views no longer allocate memory in Julia 1.5.0! This we be very helpful for a project I am currenlty working on. However, it seems that calls to reshape still do, unless I use the @uviews macro supplied by the UnsafeArrays package to eliminate them. Can someone explain why this is the case? Are there plans in the future to eliminate the memory allocations associated with calls to reshape() (and vec() as well)?

julia> using BenchmarkTools

julia> using UnsafeArrays

julia> a = randn(100)
100-element Array{Float64,1}:
 -0.10131566194390249
 -0.3090057904680784
 -0.8342574939971495
 -1.9101534313663693
 -0.01942695121108661
  1.2380580173747395
 -0.7220378280748764
  0.5679909763700992
  0.1006528537275284
  2.491269220868096
  0.45491790075601357
  0.46437278384713054
  2.261232813644681
  0.2727657136830683
  0.6555262301235976
  ⋮
  0.6582256372992632
  0.32156954628540485
 -1.3147561472118623
 -0.05350755172464439
 -1.2597052326182427
 -1.1226128270713656
  0.08976136344834987
  0.5435023475693727
  0.897905133249907
  1.3093223174069848
 -0.17262471113063685
  0.7142855991564516
 -0.14363321654072264
 -1.7994262913504766

julia> function test1(a)
       a′ = reshape(a,10,10)
       return nothing
       end
test1 (generic function with 1 method)

julia> function test2(a)
       @uviews a begin
       a′ = reshape(a,10,10)
       end
       return nothing
       end
test2 (generic function with 1 method)

julia> @btime test1(a)
  46.273 ns (2 allocations: 96 bytes)

julia> @btime test2(a)
  10.127 ns (0 allocations: 0 bytes)
1 Like

This is

https://github.com/JuliaLang/julia/issues/24237

2 Likes

Thank you for your response! The thread you linked was very helpful!