Skip to content

Commit

Permalink
DOC, ENH: Improve docstring of real_if_close (#23087)
Browse files Browse the repository at this point in the history
* fix docstring of real_if_close

* factor out dtype
  • Loading branch information
eendebakpt committed Jan 25, 2023
1 parent b97ca89 commit eccd86a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions numpy/lib/type_check.py
Expand Up @@ -2,7 +2,6 @@
"""
import functools
import warnings

__all__ = ['iscomplexobj', 'isrealobj', 'imag', 'iscomplex',
'isreal', 'nan_to_num', 'real', 'real_if_close',
Expand All @@ -12,7 +11,7 @@
from .._utils import set_module
import numpy.core.numeric as _nx
from numpy.core.numeric import asarray, asanyarray, isnan, zeros
from numpy.core import overrides
from numpy.core import overrides, getlimits
from .ufunclike import isneginf, isposinf


Expand Down Expand Up @@ -541,7 +540,8 @@ def real_if_close(a, tol=100):
Input array.
tol : float
Tolerance in machine epsilons for the complex part of the elements
in the array.
in the array. If the tolerance is <=1, then the absolute tolerance
is used.
Returns
-------
Expand Down Expand Up @@ -572,11 +572,11 @@ def real_if_close(a, tol=100):
"""
a = asanyarray(a)
if not issubclass(a.dtype.type, _nx.complexfloating):
type_ = a.dtype.type
if not issubclass(type_, _nx.complexfloating):
return a
if tol > 1:
from numpy.core import getlimits
f = getlimits.finfo(a.dtype.type)
f = getlimits.finfo(type_)
tol = f.eps * tol
if _nx.all(_nx.absolute(a.imag) < tol):
a = a.real
Expand Down

0 comments on commit eccd86a

Please sign in to comment.