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

[BUG] Reshaping a slice creates an empty array #658

Closed
furbrain opened this issue Feb 7, 2024 · 6 comments
Closed

[BUG] Reshaping a slice creates an empty array #658

furbrain opened this issue Feb 7, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@furbrain
Copy link

furbrain commented Feb 7, 2024

Describe the bug
Calling reshape on a slice of an array can lead to an empty array.
ulab version 6.4.1-2D

To Reproduce

>>> a = np.array(range(36)).reshape((6,6))
>>> a
array([[0.0, 1.0, 2.0, 3.0, 4.0, 5.0],
       [6.0, 7.0, 8.0, 9.0, 10.0, 11.0],
       [12.0, 13.0, 14.0, 15.0, 16.0, 17.0],
       [18.0, 19.0, 20.0, 21.0, 22.0, 23.0],
       [24.0, 25.0, 26.0, 27.0, 28.0, 29.0],
       [30.0, 31.0, 32.0, 33.0, 34.0, 35.0]], dtype=float32)
>>> b = a[0,:]
>>> b.reshape((1,6))
array([[0.0, 1.0, 2.0, 3.0, 4.0, 5.0]], dtype=float32)
>>> c = a[:,0]
>>> c.reshape((1,6))
array([], shape=(0,6), dtype=float32)

Expected behavior

c should be [[0.0, 6.0, 12.0, 18.0, 24.0, 30.0]], not []

Additional context

This seems to be a result of recent changes. Ulab (6.0.12) that came with circuitpython 8.1 did not have this issue

@furbrain furbrain added the bug Something isn't working label Feb 7, 2024
@v923z
Copy link
Owner

v923z commented Feb 7, 2024

I get

c.reshape((1,6))
array([[0.0],
       [6.0],
       [12.0],
       [18.0],
       [24.0],
       [30.0]], dtype=float64)

which is also wrong.

@furbrain
Copy link
Author

furbrain commented Feb 8, 2024

I think that is correct: c is looking at the first column, b is looking at the first row. My demo code was running on a nrf52840 in circuitpython

Phil

@furbrain
Copy link
Author

furbrain commented Feb 8, 2024

Sorry, didn't look at your result properly. I see the issue...

@furbrain
Copy link
Author

furbrain commented Feb 8, 2024

Just had a look at numpy docs for reshape: "it is not always possible to change the shape of an array without copying the data"

@v923z
Copy link
Owner

v923z commented Feb 10, 2024

Yes, that's correct, but your particular example should still be doable without copying. I'll try to sort out the issue.

@v923z v923z mentioned this issue Feb 10, 2024
@v923z
Copy link
Owner

v923z commented Feb 10, 2024

Fixed in #660

@v923z v923z closed this as completed Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants