{"action":"opened","issue":{"url":"https://api.github.com/repos/HIPS/autograd/issues/39","labels_url":"https://api.github.com/repos/HIPS/autograd/issues/39/labels{/name}","comments_url":"https://api.github.com/repos/HIPS/autograd/issues/39/comments","events_url":"https://api.github.com/repos/HIPS/autograd/issues/39/events","html_url":"https://github.com/HIPS/autograd/issues/39","id":98850277,"number":39,"title":"numpy.take and duplicate indices","user":{"login":"andrewowens","id":1158082,"avatar_url":"https://avatars.githubusercontent.com/u/1158082?v=3","gravatar_id":"","url":"https://api.github.com/users/andrewowens","html_url":"https://github.com/andrewowens","followers_url":"https://api.github.com/users/andrewowens/followers","following_url":"https://api.github.com/users/andrewowens/following{/other_user}","gists_url":"https://api.github.com/users/andrewowens/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewowens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewowens/subscriptions","organizations_url":"https://api.github.com/users/andrewowens/orgs","repos_url":"https://api.github.com/users/andrewowens/repos","events_url":"https://api.github.com/users/andrewowens/events{/privacy}","received_events_url":"https://api.github.com/users/andrewowens/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-08-03T22:30:50Z","updated_at":"2015-08-03T22:30:50Z","closed_at":null,"body":"Hi,\r\n\r\nFirst of all, thanks for making autograd! It's been extremely useful.  \r\n\r\nI noticed though that np.take produces the wrong result if the index array contains duplicate values.  For example, \r\n`quick_grad_check(lambda x: np.sum(x[[0,0]]), np.array([1.]))`\r\nfails with:\r\n`AssertionError: Check failed! nd=2.0, ad=1.0`\r\n\r\nYou can fix it by changing a line in `primitive_sum_arrays` (in `numpy_extra.py`) from\r\n`new_array[array.idx] += array.val`\r\nto:\r\n`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.\r\n\r\n"}}