def _check_binary_ufunc(ufunc):
""" Check that ufunc is suitable for ``ireduce_ufunc`` """
if not isinstance(ufunc, np.ufunc):
raise TypeError('{} is not a NumPy Ufunc'.format(ufunc.__name__))
if not ufunc.nin == 2:
raise ValueError('Only binary ufuncs are supported, and {} is \
not one of them'.format(ufunc.__name__))
# Ufuncs that always return bool are problematic because they can be reduced
# but not be accumulated.
# Recall: numpy.dtype('?') == np.bool
if all(type_signature[-1] == '?' for type_signature in ufunc.types):
raise ValueError('Only binary ufuncs that preserve type are supported, \
and {} is not one of them'.format(ufunc.__name__))
评论列表
文章目录