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

Behaviour of transpose() and reshape() are incompatible with numpy #19

Closed
nickovs opened this issue Nov 14, 2019 · 1 comment
Closed

Comments

@nickovs
Copy link
Contributor

nickovs commented Nov 14, 2019

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.

@v923z
Copy link
Owner

v923z commented Apr 9, 2020

#92 should fix the issue.

@v923z v923z closed this as completed Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants