after reinterpret
ing and dropdims
ing on an Array
, the result is a complicated type which nominally is equivalent to just an Array. i can use collect
to simplify it, but it allocates memory. is there a way to simplify it without memory allocation? here’s an MWE:
julia> using FixedPointNumbers, Colors
julia> A = rand(N0f8, 4, 300,500);
julia> @time B = dropdims(reinterpret(RGBA{N0f8}, A), dims=1);
0.036302 seconds (219.65 k allocations: 11.421 MiB, 99.83% compilation time)
julia> @time B = dropdims(reinterpret(RGBA{N0f8}, A), dims=1);
0.000008 seconds (2 allocations: 80 bytes)
julia> typeof(B)
Base.ReshapedArray{RGBA{N0f8}, 2, Base.ReinterpretArray{RGBA{N0f8}, 3, UInt8, Array{UInt8, 3}, false}, Tuple{}}
julia> @time C = collect(dropdims(reinterpret(RGBA{N0f8}, A), dims=1)); # only the collect is different here
0.033743 seconds (114.19 k allocations: 6.190 MiB, 99.52% compilation time)
julia> @time C = collect(dropdims(reinterpret(RGBA{N0f8}, A), dims=1));
0.000089 seconds (5 allocations: 608.156 KiB)
julia> typeof(C)
Matrix{RGBA{N0f8}} (alias for Array{RGBA{Normed{UInt8, 8}}, 2})
julia> B == C
true