Test for NAN?

0 views
Skip to first unread message

Stuart Reynolds

unread,
Apr 26, 2018, 6:11:43 PM4/26/18
to numba...@continuum.io
Is there an (efficient) way to test if an array element is NAN in numba? For example, I'd like to check if x[i] is between lo and hi, or result[i] to NAN is x[i] is NAN"

@jit
def _in_range(x, lo, hi, result):
NAN = float('nan')
for i in range(len(x)):
x_i = x[i]
if is_eq_nan(x_i): result[i] = NAN
...

Jason Sachs

unread,
Apr 26, 2018, 6:18:51 PM4/26/18
to numba...@continuum.io

--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users+unsubscribe@continuum.io.
To post to this group, send email to numba...@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/numba-users/CAAy-kd%3DTvc1pmBUMsuTOhfup9croM4241t6O7b6GXee-WLivDQ%40mail.gmail.com.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Stuart Reynolds

unread,
Apr 26, 2018, 6:22:40 PM4/26/18
to numba...@continuum.io
Well... if can, but:

def np_in_range_exclusive(x, lo, hi):
# (x>=lo) & (x<hi)
result = (x>=lo) & (x<hi)
if not may_have_nans(x): return result
else: return np.where(np.isnan(x), NAN, result)

although I count 5 new arrays being constructed, when only one is required, AND numpy generates warning for 
(x>=lo) & (x<hi)
where x has nulls


Kevin Sheppard

unread,
Apr 26, 2018, 6:26:14 PM4/26/18
to numba...@continuum.io
Np.isnan can be used in nopython mode in place of is_eq_nan.

On Thu, 26 Apr 2018 at 23:22 Stuart Reynolds <stu...@stuartreynolds.net> wrote:
Well... if can, but:

def np_in_range_exclusive(x, lo, hi):
# (x>=lo) & (x<hi)
result = (x>=lo) & (x<hi)
if not may_have_nans(x): return result
else: return np.where(np.isnan(x), NAN, result)

although I count 5 new arrays being constructed, when only one is required, AND numpy generates warning for 
(x>=lo) & (x<hi)
where x has nulls

On Thu, Apr 26, 2018 at 3:18 PM, Jason Sachs <jms...@gmail.com> wrote:
On Thu, Apr 26, 2018 at 3:11 PM, Stuart Reynolds <stu...@stuartreynolds.net> wrote:
Is there an (efficient) way to test if an array element is NAN in numba? For example, I'd like to check if x[i] is between lo and hi, or result[i] to NAN is x[i] is NAN"

@jit
def _in_range(x, lo, hi, result):
NAN = float('nan')
for i in range(len(x)):
x_i = x[i]
if is_eq_nan(x_i): result[i] = NAN
...

--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users...@continuum.io.

--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users...@continuum.io.

--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users...@continuum.io.

To post to this group, send email to numba...@continuum.io.

Stuart Reynolds

unread,
Apr 26, 2018, 6:31:54 PM4/26/18
to numba...@continuum.io
Cool -- does it turn into a function call, or is it inlined?

To unsubscribe from this group and stop receiving emails from it, send an email to numba-users+unsubscribe@continuum.io.

--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users+unsubscribe@continuum.io.

--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users+unsubscribe@continuum.io.

To post to this group, send email to numba...@continuum.io.

--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users+unsubscribe@continuum.io.

To post to this group, send email to numba...@continuum.io.
Reply all
Reply to author
Forward
0 new messages