Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix reshape sharing semantics #2279

Closed
stevengj opened this issue Feb 12, 2013 · 0 comments
Closed

fix reshape sharing semantics #2279

stevengj opened this issue Feb 12, 2013 · 0 comments
Labels
needs decision A decision on this change is needed

Comments

@stevengj
Copy link
Member

As discussed in https://groups.google.com/d/topic/julia-dev/srGDmeK6i3U/discussion, the semantics of the reshape function are rather inconsistent regarding whether the return value shares the data of the original array or makes a copy. For efficiency (and sometimes functionality), it is often preferable to share data, but it is not practical for arbitrary abstract array types (and currently even for Array types the reshape result is not shared for sufficiently small arrays due to a threshold in jl_reshape_array).

The Matlab reshape function apparently returns shared data, but with copy-on-write behavior so that it has the semantics of a copy. Sometimes copy semantics is useful, but often I would argue that you actually want shared-data semantics (e.g. I've found reshape to be very useful for processing individual dimensions of multidimensional arrays in-place without messy loop-nesting).

It sounds like the best thing might be to have two separate functions:

  • A reshape (or reshape_copy or ...?) function that returns a copy (or its semantic equivalent, e.g. shared data with copy-on-write behavior).
  • A reshape_shared (or reshape or reshape! or view_as or reinterpret_shape or ...?) function that returns an object that shares the data of the original array.
JeffBezanson added a commit that referenced this issue Mar 6, 2013
for now, whether reshape shares data will just have to depend on argument
type. it is popular to write things like reshape(1:4, 2, 2).
JeffBezanson added a commit that referenced this issue Mar 7, 2013
for now, whether reshape shares data will just have to depend on argument
type. it is popular to write things like reshape(1:4, 2, 2).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs decision A decision on this change is needed
Projects
None yet
Development

No branches or pull requests

2 participants