{"action":"created","issue":{"url":"https://api.github.com/repos/numba/numba/issues/238","labels_url":"https://api.github.com/repos/numba/numba/issues/238/labels{/name}","comments_url":"https://api.github.com/repos/numba/numba/issues/238/comments","events_url":"https://api.github.com/repos/numba/numba/issues/238/events","html_url":"https://github.com/numba/numba/issues/238","id":15112131,"number":238,"title":"boolean operations produce values incompatible with numpy","user":{"login":"gdementen","id":832092,"avatar_url":"https://avatars.githubusercontent.com/u/832092?v=3","gravatar_id":"","url":"https://api.github.com/users/gdementen","html_url":"https://github.com/gdementen","followers_url":"https://api.github.com/users/gdementen/followers","following_url":"https://api.github.com/users/gdementen/following{/other_user}","gists_url":"https://api.github.com/users/gdementen/gists{/gist_id}","starred_url":"https://api.github.com/users/gdementen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gdementen/subscriptions","organizations_url":"https://api.github.com/users/gdementen/orgs","repos_url":"https://api.github.com/users/gdementen/repos","events_url":"https://api.github.com/users/gdementen/events{/privacy}","received_events_url":"https://api.github.com/users/gdementen/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/numba/numba/labels/0%20-%20Backlog","name":"0 - Backlog","color":"d4c5f9"},{"url":"https://api.github.com/repos/numba/numba/labels/bug","name":"bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2013-06-04T10:42:23Z","updated_at":"2015-05-26T14:18:31Z","closed_at":"2015-05-26T14:18:31Z","body":"On numba 0.8.1, comparisons produce boolean values which are incompatible with numpy: numba uses \"255\" to represent True, while numpy uses 1, this means that, for example, np.sum(boolean_result) is different. \r\n\r\nThis could be considered a bug in numpy, but I guess this has more chance to be \"fixed\" here than in numpy.\r\n\r\nI believe all operations producing boolean values are also affected, but I did not test them all.\r\n\r\n```python\r\nimport numpy as np\r\nfrom numba import autojit\r\n\r\ndef lt(a, b):\r\n    result = np.empty(len(a), dtype=np.bool)\r\n    for i in range(len(a)):\r\n        result[i] = a[i] < b\r\n    return result\r\nlt_nb = autojit(lt)\r\n    \r\na = np.arange(10)\r\n\r\nr1 = lt(a, 5)\r\nr2 = lt_nb(a, 5)\r\n\r\n# workaround\r\n# r2 = r2.astype(np.uint8, copy=False).astype(np.bool)\r\n\r\n# this passes...\r\nassert np.array_equal(r1, r2)\r\n\r\n# but...\r\nprint r1.astype(np.uint8), r2.astype(np.uint8)\r\nassert np.sum(r1) == np.sum(r2)\r\n```"},"comment":{"url":"https://api.github.com/repos/numba/numba/issues/comments/105539920","html_url":"https://github.com/numba/numba/issues/238#issuecomment-105539920","issue_url":"https://api.github.com/repos/numba/numba/issues/238","id":105539920,"user":{"login":"pitrou","id":1721820,"avatar_url":"https://avatars.githubusercontent.com/u/1721820?v=3","gravatar_id":"","url":"https://api.github.com/users/pitrou","html_url":"https://github.com/pitrou","followers_url":"https://api.github.com/users/pitrou/followers","following_url":"https://api.github.com/users/pitrou/following{/other_user}","gists_url":"https://api.github.com/users/pitrou/gists{/gist_id}","starred_url":"https://api.github.com/users/pitrou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pitrou/subscriptions","organizations_url":"https://api.github.com/users/pitrou/orgs","repos_url":"https://api.github.com/users/pitrou/repos","events_url":"https://api.github.com/users/pitrou/events{/privacy}","received_events_url":"https://api.github.com/users/pitrou/received_events","type":"User","site_admin":false},"created_at":"2015-05-26T14:18:31Z","updated_at":"2015-05-26T14:18:31Z","body":"This is currently fixed."}}