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] ulab.numpy.roll doesn't copy over data when distance is 0 #686

Closed
relic-se opened this issue Sep 12, 2024 · 2 comments
Closed

[BUG] ulab.numpy.roll doesn't copy over data when distance is 0 #686

relic-se opened this issue Sep 12, 2024 · 2 comments
Labels
bug Something isn't working critical critical bug, requires speedy fix

Comments

@relic-se
Copy link

Describe the bug
A program I am working on performs a call to ulab.numpy.roll to shift around an array by an varying amount of distance. I noticed that when the distance argument is set to 0, the function returns an array of the correct length but with all 0s. Quickly scanning over the code for this in code/numpy/numerical.c, my guess is that L1224 is never run to copy over the results.

if(--counter == 0) {
rarray = results->array;
}

ulab version: 6.4.1-2D

To Reproduce

import ulab.numpy as np
print(data := np.arange(10))
print(np.roll(data, 1))
print(np.roll(data, 0))

Output:

array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int16)
array([9, 0, 1, 2, 3, 4, 5, 6, 7, 8], dtype=int16)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=int16)

Describe the steps to reproduce the behavior.

Expected behavior
I would expect the output of np.roll(data, 0) to simply pass through the data. If the axis is provided, that may have different results, but I am not certain of the expected behavior in that case.

I think a decent enough solution would be to detect if the distance/shift argument is 0 and pass the output through early.

Changing numerical.c#L1223 to if(--counter <= 0) { may also work, but I suspect that it would have the same effect as if distance were equal to 1, which would not be desired.

@relic-se relic-se added the bug Something isn't working label Sep 12, 2024
@v923z
Copy link
Owner

v923z commented Sep 14, 2024

Thanks for pointing this out!

@v923z v923z added the critical critical bug, requires speedy fix label Sep 14, 2024
@v923z v923z mentioned this issue Sep 14, 2024
@v923z
Copy link
Owner

v923z commented Sep 14, 2024

Fixed in #687

@v923z v923z closed this as completed Sep 14, 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 critical critical bug, requires speedy fix
Projects
None yet
Development

No branches or pull requests

2 participants