Repository: numba/numba

Issue:
isnan(int) isinf(int) should work
<!--

Thanks for opening an issue! To help the Numba team handle your information
efficiently, please first ensure that there is no other issue present that
already describes the issue you have
(search at https://github.com/numba/numba/issues?&q=is%3Aissue).

For more general "how do I do X?" type questions, please speak to us in real
time on https://gitter.im/numba/numba or post to the Numba mailing list
https://groups.google.com/a/continuum.io/forum/#!forum/numba-users.

-->

## Reporting a bug

<!--

Before submitting a bug report please ensure that you can check off these boxes:

-->

- [x] I am using the latest released version of Numba (most recent is visible in
 the change log (https://github.com/numba/numba/blob/master/CHANGE_LOG).
- [ ] I have included below a minimal working reproducer (if you are unsure how
 to write one see http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports).

`math.isnan(123)` and `math.isinf(123)` should not cause jit'ed function to raise TypingError.


Discussion:
This can be probably be solved easily by implementing isnan(int)=>False
@sklam could you provide a minimal snippet that exposes this bug?
@esc 
Oh, I just noticed it only break CUDA backend.

```python
from numba import njit
from numba import cuda
import math

@cuda.jit
def foo(x):
    math.isnan(x)


foo(1)
```
will raise:
```
numba.errors.LoweringError: Failed in nopython mode pipeline (step: nopython mode backend)
No definition for lowering <built-in function isnan>(int64,) -> bool

File "isnan.py", line 7:
def foo(x):
    math.isnan(x)
    ^

[1] During: lowering "$0.4 = call $0.2(x, kws=[], vararg=None, func=$0.2, args=[Var(x, isnan.py (7))])" at isnan.py (7)
```
The lowering error indicates that the CUDA backend has no implementation for it.  An implementation is needed in https://github.com/numba/numba/blob/master/numba/cuda/libdevice.py
I'd like to work on this issue.


@niteya-shah feel free to address the issue and submit a pull-request for review.

Resolving patch:
diff --git a/numba/cuda/cudaimpl.py b/numba/cuda/cudaimpl.py
--- a/numba/cuda/cudaimpl.py
+++ b/numba/cuda/cudaimpl.py
@@ -468,6 +468,12 @@ def ptx_round(context, builder, sig, args):
     ])
 
 
+@lower(math.isinf, types.Integer)
+@lower(math.isnan, types.Integer)
+def math_isinf_isnan_int(context, builder, sig, args):
+    return lc.Constant.int(lc.Type.int(1), 0)
+
+
 def gen_deg_rad(const):
     def impl(context, builder, sig, args):
         argty, = sig.args


Test patch:
diff --git a/numba/cuda/tests/cudapy/test_math.py b/numba/cuda/tests/cudapy/test_math.py
--- a/numba/cuda/tests/cudapy/test_math.py
+++ b/numba/cuda/tests/cudapy/test_math.py
@@ -1,7 +1,7 @@
 import sys
 import numpy as np
 from numba.cuda.testing import unittest, CUDATestCase
-from numba import cuda, float32, float64, int32
+from numba import cuda, float32, float64, int32, int64
 import math
 
 
@@ -198,6 +198,7 @@ def unary_template(self, func, npfunc, npdtype, npmtype, start, stop):
         cfunc[1, nelem](A, B)
         self.assertTrue(np.allclose(npfunc(A), B))
 
+
     def unary_bool_template_float32(self, func, npfunc, start=0, stop=1):
         self.unary_template(func, npfunc, np.float32, float32, start, stop)
 
@@ -205,6 +206,15 @@ def unary_bool_template_float32(self, func, npfunc, start=0, stop=1):
     def unary_bool_template_float64(self, func, npfunc, start=0, stop=1):
         self.unary_template(func, npfunc, np.float64, float64, start, stop)
 
+
+    def unary_bool_template_int32(self, func, npfunc, start=0, stop=49):
+        self.unary_template(func, npfunc, np.int32, int32, start, stop)
+
+
+    def unary_bool_template_int64(self, func, npfunc, start=0, stop=49):
+        self.unary_template(func, npfunc, np.int64, int64, start, stop)
+
+
     def unary_bool_template(self, func, npfunc, npdtype, npmtype, start, stop):
         nelem = 50
         A = np.linspace(start, stop, nelem).astype(npdtype)
@@ -555,6 +565,8 @@ def test_math_mod_binop(self):
     def test_math_isnan(self):
         self.unary_bool_template_float32(math_isnan, np.isnan)
         self.unary_bool_template_float64(math_isnan, np.isnan)
+        self.unary_bool_template_int32(math_isnan, np.isnan)
+        self.unary_bool_template_int64(math_isnan, np.isnan)
 
     #------------------------------------------------------------------------------
     # test_math_isinf
@@ -563,6 +575,8 @@ def test_math_isnan(self):
     def test_math_isinf(self):
         self.unary_bool_template_float32(math_isinf, np.isinf)
         self.unary_bool_template_float64(math_isinf, np.isinf)
+        self.unary_bool_template_int32(math_isinf, np.isnan)
+        self.unary_bool_template_int64(math_isinf, np.isnan)
 
     #------------------------------------------------------------------------------
     # test_math_degrees