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
In numpy, ndarray.transpose() returns a view of the original array and ndarray.reshape() returns a view when possible and otherwise they returns a new array. In both cases the array object passed in as the argument is left unaffected. The current ulab behaviour is to reshape the argument that was passed and return the modified original.
The code for both of these functions will naturally get reworked with the new N-dimensional arrays and views, so this GitHub issue is more a spec for the new code than a plea for fixing the old code.
FWIW, in the code I started writing for ndarray the "if possible" test for reshape was simple and dumb: reshape used a view if and only if the input array or view had never been sliced or transposed (which implies that the stride on each dimension is the product of the lengths of all the more deeply nested dimensions). In practice I just kept a flag that was set on creation of new arrays but cleared for new slice or transposes views. Views created by subscripting using only integer indices copied the flag from the parent. In practice this meant that there are some cases that could have used a view but ended up copying because the code to check those cases seemed unnecessarily complex for Micropython.
The text was updated successfully, but these errors were encountered:
In
numpy
,ndarray.transpose()
returns a view of the original array andndarray.reshape()
returns a view when possible and otherwise they returns a new array. In both cases the array object passed in as the argument is left unaffected. The currentulab
behaviour is to reshape the argument that was passed and return the modified original.The code for both of these functions will naturally get reworked with the new N-dimensional arrays and views, so this GitHub issue is more a spec for the new code than a plea for fixing the old code.
FWIW, in the code I started writing for
ndarray
the "if possible" test for reshape was simple and dumb:reshape
used a view if and only if the input array or view had never been sliced or transposed (which implies that the stride on each dimension is the product of the lengths of all the more deeply nested dimensions). In practice I just kept a flag that was set on creation of new arrays but cleared for new slice or transposes views. Views created by subscripting using only integer indices copied the flag from the parent. In practice this meant that there are some cases that could have used a view but ended up copying because the code to check those cases seemed unnecessarily complex for Micropython.The text was updated successfully, but these errors were encountered: