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

Most array functions are broken when called with a negative axis #4125

Open
ShreyasKhandekar opened this issue Feb 28, 2025 · 0 comments
Open
Labels
bug Something isn't working

Comments

@ShreyasKhandekar
Copy link
Contributor

Describe the bug
A negative axis argument like -1 is often used in Python to specify the innermost axis for a multidimensional array. This is how numpy behaves.

The most common use case is when we want to do some operation on just the last axis of a 2D array like:

a = ak.randint(0, 100, 100).reshape(10, 10)
print(ak.sum(a, axis=1))

To Reproduce

a = ak.randint(0, 100, 100).reshape(10, 10)
print(ak.sum(a, axis=-1))

We get the error:

Expected behavior
axis=-1 and axis=1 should behave the same for a 2D array to get the same behavior as numpy.

Error Message

ValueError: Failed to squeeze array: Unable to squeeze array with shape (10, 1) along axes -1 into a 1D array

Is this a Blocking Issue

  • Not blocking

  • Are there any known work-arounds? yes

  • If a known work around exists, please provide a code block demonstrating it.

    • You can just do a.ndim+axis when axis < 0 to fix this
    • This means this is a very easy fix, just that there are a lot of places to fix, and that's if we want to make this change at all.

Additional Context

This issue assumes that this behavior is a bug.
It can be reasonably stated that since Chapel doesn't support negative indexing like Python, we just choose not to support this and the user can fix this where the want using the workaround above.
But on the other hand, this brings Arkouda closer to being a drop in replacement for numpy.

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

1 participant