You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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 forArray
types thereshape
result is not shared for sufficiently small arrays due to a threshold injl_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 foundreshape
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:
reshape
(orreshape_copy
or ...?) function that returns a copy (or its semantic equivalent, e.g. shared data with copy-on-write behavior).reshape_shared
(orreshape
orreshape!
orview_as
orreinterpret_shape
or ...?) function that returns an object that shares the data of the original array.The text was updated successfully, but these errors were encountered: