def _check_all_finite(X):
"""General check for all finite values in X."""
# First try an O(n) time, O(1) space solution for the common case that
# everything is finite; fall back to O(n) space np.isfinite to prevent
# false positives from overflow in sum method.
try:
if (X.dtype.char in np.typecodes['AllFloat'] and not
np.isfinite(X.sum()) and not np.isfinite(X).all()):
return False
else:
return True
except Exception as e:
warnings.warn('Could not check array for all finite. Ensure X is an'
'array type, and consider converting to an ndarray or'
'scipy sparse array. Details:\n%r' % e, InputDataWarning)
评论列表
文章目录