I find the following behavior puzzling. Start with:
A = randn(5,5)
x = reshape(A, 25)
At this point, A and x point to the same memory block. Indeed:
x[1] = 1.0
A[1] # returns 1.0
But now, since x is one-dimensional, I can push! to it:
push!(x, 3)
x[1] = 0.0
A[1] # not zero
The push! decouples x and A, which now point to different blocks in memory.
But this feels like a subtle side-effect. Is this intentional? Why not preserve the guarantee that a reshaped array always points to the original array, and let push! raise an error instead in this situation?
I’m not sure what the issue here would be. I think that the behavior should be consistent, but I’m not sure how. You agree that in my example above push!(x, 3) should raise an error? It seems to me that an error is the consistent thing to do (especially considering @kristoffer.carlsson example).