Skip to content

Commit 885525d

Browse files
authored
Merge pull request #524 from pydata/add_isinf
Add isinf function
2 parents af34c3c + d8a42ff commit 885525d

File tree

6 files changed

+17
-3
lines changed

6 files changed

+17
-3
lines changed

numexpr/expressions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ def multiply(x, y):
368368

369369
'isnan': func(numpy.isnan, 'bool'),
370370
'isfinite': func(numpy.isfinite, 'bool'),
371+
'isinf': func(numpy.isinf, 'bool'),
371372

372373
'sum': gen_reduce_axis_func('sum'),
373374
'prod': gen_reduce_axis_func('prod'),
@@ -524,6 +525,6 @@ class FuncNode(OpNode):
524525
def __init__(self, opcode=None, args=None, kind=None):
525526
if (kind is None) and (args is not None):
526527
kind = commonKind(args)
527-
if opcode in ("isnan", "isfinite"): # bodge for boolean return functions
528+
if opcode in ("isnan", "isfinite", "isinf"): # bodge for boolean return functions
528529
kind = 'bool'
529530
OpNode.__init__(self, opcode, args, kind)

numexpr/functions.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ FUNC_DD(FUNC_DD_LAST, NULL, NULL, NULL)
9393
#endif
9494
FUNC_BD(FUNC_ISNAN_BD, "isnan_bd", isnand, vdIsnan)
9595
FUNC_BD(FUNC_ISFINITE_BD, "isfinite_bd", isfinited, vdIsfinite)
96+
FUNC_BD(FUNC_ISINF_BD, "isinf_bd", isinfd, vdIsinf)
9697
FUNC_BD(FUNC_BD_LAST, NULL, NULL, NULL)
9798
#ifdef ELIDE_FUNC_BD
9899
#undef ELIDE_FUNC_BD
@@ -106,6 +107,7 @@ FUNC_BD(FUNC_BD_LAST, NULL, NULL, NULL)
106107
#endif // use wrappers as there is name collision with isnanf in std
107108
FUNC_BF(FUNC_ISNAN_BF, "isnan_bf", isnanf_, isnanf2, vfIsnan)
108109
FUNC_BF(FUNC_ISFINITE_BF, "isfinite_bf", isfinitef_, isfinitef2, vfIsfinite)
110+
FUNC_BF(FUNC_ISINF_BF, "isinf_bf", isinff_, isinff2, vfIsinf)
109111
FUNC_BF(FUNC_BF_LAST, NULL, NULL, NULL, NULL)
110112
#ifdef ELIDE_FUNC_BF
111113
#undef ELIDE_FUNC_BF

numexpr/msvc_function_stubs.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ inline bool isfinitef_(float x) { return !!::_finite(x); } // MSVC has _finite
5454
inline bool isnanf_(float x) { return !!::_isnan(x); } // MSVC has _isnan
5555
inline bool isfinited(double x) { return !!::_finite(x); }
5656
inline bool isnand(double x) { return !!::_isnan(x); }
57-
57+
inline bool isinfd(double x) { return !!::isinf(x); }
58+
inline bool isinff_(float x) { return !!::isinf(x); }
5859

5960
/* Now the actual stubs */
6061

@@ -151,6 +152,11 @@ inline bool isfinitef2(float x) {
151152
return isfinitef_(x);
152153
}
153154

155+
inline bool isinff2(float x) {
156+
return isinff_(x);
157+
}
158+
159+
154160
// Needed for allowing the internal casting in numexpr machinery for
155161
// conjugate operations
156162
inline float fconjf2(float x) {

numexpr/necompiler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
"ceil",
7272
"floor",
7373
"isnan",
74-
"isfinite"
74+
"isfinite",
75+
"isinf",
7576
]
7677

7778

numexpr/numexpr_config.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ inline bool isfinitef_(float x) { return !!::isfinite(x); }
5555
inline bool isnanf_(float x) { return !!::isnan(x); }
5656
inline bool isfinited(double x) { return !!::isfinite(x); }
5757
inline bool isnand(double x) { return !!::isnan(x); }
58+
inline bool isinff_(float x) { return !!::isinf(x); }
59+
inline bool isinfd(double x) { return !!::isinf(x); }
5860
#endif
5961

6062
#endif // NUMEXPR_CONFIG_HPP

numexpr/tests/test_numexpr.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,10 +703,12 @@ def test_bool_funcs(self):
703703

704704
assert np.all(evaluate("isnan(a)") == np.isnan(a))
705705
assert np.all(evaluate("isfinite(a)") == np.isfinite(a))
706+
assert np.all(evaluate("isinf(a)") == np.isinf(a))
706707
a = a.astype(np.float64)
707708
assert a.dtype == np.float64
708709
assert np.all(evaluate("isnan(a)") == np.isnan(a))
709710
assert np.all(evaluate("isfinite(a)") == np.isfinite(a))
711+
assert np.all(evaluate("isinf(a)") == np.isinf(a))
710712

711713
if 'sparc' not in platform.machine():
712714
# Execution order set here so as to not use too many threads

0 commit comments

Comments
 (0)