Closed
Description
Consider the following example:
xmat = randn(5,5)
xvec = reshape(xmat, 25)
push!(xvec, 3)
xvec[1] = 0.0
xmat[1] # not zero
Here push!
has decoupled xmat
and xvec
, though one would expect that a reshaped array always point to the same memory as the original array. I think the push!
here should raise an error.
Contrast the example above with the following (source: https://discourse.julialang.org/t/puzzling-reshape-and-push/28326/2):
xvec = rand(4)
xmat = reshape(xvec, 2, 2)
push!(xvec, 1.0) # ERROR: cannot resize array with shared data
To be consistent it seems to me that my first example above should also be an error.