Skip to content

reshape and push! inconsistent behavior #33143

Closed
@cossio

Description

@cossio

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]minor changeMarginal behavior change acceptable for a minor release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions