diff options
author | Joscha Reimer <jor@informatik.uni-kiel.de> | 2018-07-05 10:25:13 +0200 |
---|---|---|
committer | Joscha Reimer <jor@informatik.uni-kiel.de> | 2018-07-05 16:05:35 +0200 |
commit | 4e2dd4140e2a7220ef645665a7ce6381493d273d (patch) | |
tree | 8d601755599e1b43ebf91b5a12bbedbce39786e3 /numpy/lib | |
parent | d126856bf1b7ed79d696fcc49fcf5b579bb8d156 (diff) | |
download | numpy-4e2dd4140e2a7220ef645665a7ce6381493d273d.tar.gz |
BUG: isposinf and isneginf now also work with complex values
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/ufunclike.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/numpy/lib/ufunclike.py b/numpy/lib/ufunclike.py index e0bd95182..fc059d2f7 100644 --- a/numpy/lib/ufunclike.py +++ b/numpy/lib/ufunclike.py @@ -81,6 +81,21 @@ def fix(x, out=None): res = res[()] return res + +def _isinf(x, sign, out=None): + if nx.isscalar(x): + if out is not None: + raise ValueError('out has to be None if x is scalar.') + return nx.isinf(x) and nx.sign(x) == sign + else: + x = nx.asanyarray(x) + out = nx.isinf(x, out) + if x.ndim == 0: + out = nx.asanyarray(out) + out_b = out.astype(bool, copy=False) + out[out_b] = nx.sign(x[out_b]) == sign + return out + @_deprecate_out_named_y def isposinf(x, out=None): """ @@ -138,7 +153,7 @@ def isposinf(x, out=None): array([0, 0, 1]) """ - return nx.logical_and(nx.isinf(x), ~nx.signbit(x), out) + return _isinf(x, 1, out=out) @_deprecate_out_named_y @@ -199,4 +214,4 @@ def isneginf(x, out=None): array([1, 0, 0]) """ - return nx.logical_and(nx.isinf(x), nx.signbit(x), out) + return _isinf(x, -1, out=out) |