{"action":"created","issue":{"url":"https://api.github.com/repos/numba/numba/issues/3465","repository_url":"https://api.github.com/repos/numba/numba","labels_url":"https://api.github.com/repos/numba/numba/issues/3465/labels{/name}","comments_url":"https://api.github.com/repos/numba/numba/issues/3465/comments","events_url":"https://api.github.com/repos/numba/numba/issues/3465/events","html_url":"https://github.com/numba/numba/issues/3465","id":376555328,"node_id":"MDU6SXNzdWUzNzY1NTUzMjg=","number":3465,"title":"Add support for np.clip","user":{"login":"arvoelke","id":5420057,"node_id":"MDQ6VXNlcjU0MjAwNTc=","avatar_url":"https://avatars2.githubusercontent.com/u/5420057?v=4","gravatar_id":"","url":"https://api.github.com/users/arvoelke","html_url":"https://github.com/arvoelke","followers_url":"https://api.github.com/users/arvoelke/followers","following_url":"https://api.github.com/users/arvoelke/following{/other_user}","gists_url":"https://api.github.com/users/arvoelke/gists{/gist_id}","starred_url":"https://api.github.com/users/arvoelke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arvoelke/subscriptions","organizations_url":"https://api.github.com/users/arvoelke/orgs","repos_url":"https://api.github.com/users/arvoelke/repos","events_url":"https://api.github.com/users/arvoelke/events{/privacy}","received_events_url":"https://api.github.com/users/arvoelke/received_events","type":"User","site_admin":false},"labels":[{"id":572873264,"node_id":"MDU6TGFiZWw1NzI4NzMyNjQ=","url":"https://api.github.com/repos/numba/numba/labels/feature_request","name":"feature_request","color":"bfd4f2","default":false},{"id":1101464864,"node_id":"MDU6TGFiZWwxMTAxNDY0ODY0","url":"https://api.github.com/repos/numba/numba/labels/good%20first%20issue","name":"good first issue","color":"5319e7","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-11-01T20:22:04Z","updated_at":"2018-11-02T18:12:41Z","closed_at":null,"author_association":"NONE","body":"## Feature request\r\n\r\nCurrently `np.clip(a, a_min, a_max, out=None)` and `a.clip(a_min=None, a_max=None, out=None)` are not supported by `@njit`.\r\n\r\nI tried to implement this myself, but am having trouble installing `llvm-6.0` in order to test my development branch locally. So, without knowing what I'm doing (first time looking at `numba` source code), this was my blind attempt implementing `np.clip(...)`:\r\n\r\n```python\r\n# File: numba/targets/arrayobj.py\r\n\r\n@lower_builtin(np.clip, types.Array)\r\ndef array_clip(context, builder, sig, args):\r\n    def np_clip_impl(a, a_min, a_max, out=None):\r\n        if out is None:\r\n            out = np.empty_like(a)\r\n        for i in range(len(a)):\r\n            if a[i] < a_min:\r\n                out[i] = a_min\r\n            elif a[i] > a_max:\r\n                out[i] = a_max\r\n            else:\r\n                out[i] = a[i]\r\n        return out\r\n\r\n    return context.compile_internal(builder, np_clip_impl, sig, args)\r\n```\r\n\r\nFollowing the pattern in #3462, I'm guessing that something like this is also needed (for `a.clip(...)`):\r\n\r\n```python\r\n# File: numba/targets/arrayobj.py\r\n\r\n@overload_method(types.Array, 'clip')\r\ndef array_clip(a, a_min, a_max, out=None):\r\n    def impl(a, a_min, a_max, out=None):\r\n        return np.clip(a, a_min, a_max, out)\r\n    return impl\r\n```\r\n\r\n**Edit**: The above implementation is incomplete since the signature for `a.clip` is:\r\n```\r\n    a.clip(min=None, max=None, out=None)\r\n```\r\nNote the default values, which are not present for `np.clip`.\r\n\r\nFurthermore, `None` can be passed to `np.clip` for `a_min` or `a_max`, in which case the lower or upper bounds are ignored, respectively."},"comment":{"url":"https://api.github.com/repos/numba/numba/issues/comments/435464517","html_url":"https://github.com/numba/numba/issues/3465#issuecomment-435464517","issue_url":"https://api.github.com/repos/numba/numba/issues/3465","id":435464517,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNTQ2NDUxNw==","user":{"login":"arvoelke","id":5420057,"node_id":"MDQ6VXNlcjU0MjAwNTc=","avatar_url":"https://avatars2.githubusercontent.com/u/5420057?v=4","gravatar_id":"","url":"https://api.github.com/users/arvoelke","html_url":"https://github.com/arvoelke","followers_url":"https://api.github.com/users/arvoelke/followers","following_url":"https://api.github.com/users/arvoelke/following{/other_user}","gists_url":"https://api.github.com/users/arvoelke/gists{/gist_id}","starred_url":"https://api.github.com/users/arvoelke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arvoelke/subscriptions","organizations_url":"https://api.github.com/users/arvoelke/orgs","repos_url":"https://api.github.com/users/arvoelke/repos","events_url":"https://api.github.com/users/arvoelke/events{/privacy}","received_events_url":"https://api.github.com/users/arvoelke/received_events","type":"User","site_admin":false},"created_at":"2018-11-02T18:12:41Z","updated_at":"2018-11-02T18:12:41Z","author_association":"NONE","body":"Thanks for the words of encouragement! I managed to get my dev branch working after using that conda command, and have made a pull request at #3468."}}
{"actor":{"display_login":"arvoelke"}}