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

Reduce operations raise error for negative axis values #117

Closed
nils-werner opened this Issue Mar 2, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@nils-werner
Contributor

nils-werner commented Mar 2, 2018

Reduce operations like .sum(), .prod() etc. raise exceptions when you pass a negative axis value:

import sparse
sparse.random((40, 50)).sum(0)  # works
sparse.random((40, 50)).sum(1)  # works
sparse.random((40, 50)).sum(-1)  # fails, should be equivalent to .sum(1)

The traceback I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "proj_dir/sparse/sparse/coo.py", line 1038, in prod
    return self.reduce(np.multiply, axis=axis, keepdims=keepdims, dtype=dtype)
  File "proj_dir/sparse/sparse/coo.py", line 771, in reduce
    a = self.transpose(neg_axis + axis)
  File "proj_dir/sparse/sparse/coo.py", line 1099, in transpose
    raise ValueError("repeated axis in transpose")
ValueError: repeated axis in transpose

@nils-werner nils-werner changed the title from Reduce operations raise error on negative axes to Reduce operations raise error for negative axis values Mar 2, 2018

@hameerabbasi

This comment has been minimized.

Collaborator

hameerabbasi commented Mar 2, 2018

@nils-werner Are you interested in fixing this? It's trivial. You just need to flip the axes to be positive near the top of COO.reduce.

@nils-werner

This comment has been minimized.

Contributor

nils-werner commented Mar 2, 2018

Yeah, I can do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment