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

Distinction between rank-0 arrays and scalars #22

Open
asmeurer opened this issue May 7, 2020 · 2 comments
Open

Distinction between rank-0 arrays and scalars #22

asmeurer opened this issue May 7, 2020 · 2 comments

Comments

@asmeurer
Copy link
Member

asmeurer commented May 7, 2020

There are some instances where reduce currently transforms one index into another where they don't give the same thing on scalars or rank-0 arrays. For example

>>> np.int64(0)[...]
array(0)
>>> np.int64(0)[()]
0
>>> np.array(0)[...]
array(0)
>>> np.int64(0)[...]
array(0)

Currently ellipsis().reduce() gives Tuple().

>>> np.array([1, 2, 3])[0,]
1
>>> np.array([1, 2, 3])[0,...]
array(1)

Currently the code assumes that tuples always implicitly end in an ellipsis (Tuple.reduce removes any trailing ellipsis) .

I don't know if we should care about this distinction.

@asmeurer
Copy link
Member Author

This will happen in more cases after fixing #31. For now, I am adding a note to Tuple.reduce about it indicating that ndindex does not distinguish between rank-0 arrays and scalars.

@asmeurer asmeurer added this to the Low Priority milestone May 19, 2020
@asmeurer
Copy link
Member Author

We could fix this by adding an allow_rank0_equals_scalar flag to the reduce methods. If False, indices won't reduce to each other if one can produce a scalar but the other a rank-0 array. The default should likely stay as True, since False would prevent removing redundant ellipses in many cases, and for most use-cases, scalars and rank-0 arrays are interchangable.

I don't plan to implement this soon, as I don't believe I will need it.

@scopatz scopatz removed this from the Low Priority milestone Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants