Puzzling reshape and push!

Note that we have:

julia> xvec = rand(4);

julia> xmat = reshape(xvec, 2, 2);

julia> push!(xvec, 1.0)
ERROR: cannot resize array with shared data
Stacktrace:
 [1] _growend! at ./array.jl:811 [inlined]
 [2] push!(::Array{Float64,1}, ::Float64) at ./array.jl:853
 [3] top-level scope at REPL[50]:100:

I am not sure if this is related to who is “owner” of the underlying buffer but it seems kinda odd.

2 Likes