reduce.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:npstreams 作者: LaurentRDC 项目源码 文件源码
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__))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号