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

numpy.take and duplicate indices #39

Closed
andrewowens opened this issue Aug 3, 2015 · 1 comment
Closed

numpy.take and duplicate indices #39

andrewowens opened this issue Aug 3, 2015 · 1 comment

Comments

@andrewowens
Copy link

Hi,

First of all, thanks for making autograd! It's been extremely useful.

I noticed though that np.take produces the wrong result if the index array contains duplicate values. For example,
quick_grad_check(lambda x: np.sum(x[[0,0]]), np.array([1.]))
fails with:
AssertionError: Check failed! nd=2.0, ad=1.0

You can fix it by changing a line in primitive_sum_arrays (in numpy_extra.py) from
new_array[array.idx] += array.val
to:
numpy.add.at(new_array, array.idx, array.val). I'm not sure if this error occurs elsewhere, but it seems to at least fix the problem in all of the cases that I've tried.

@duvenaud
Copy link
Contributor

Thanks for the bug report and the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants