utils.py 文件源码

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

项目:snape 作者: mbernico 项目源码 文件源码
def assert_valid_percent(x, eq_lower=False, eq_upper=False):
    # these are all castable to float
    assert_is_type(x, (float, np.float, np.int, int, long, np.long))
    x = float(x)

    # test lower bound:
    if not ((eq_lower and 0. <= x) or ((not eq_lower) and 0. < x)):
        raise ValueError('Expected 0. %s x, but got x=%r'
                         % ('<=' if eq_lower else '<', x))
    if not ((eq_upper and x <= 1.) or ((not eq_upper) and x < 1.)):
        raise ValueError('Expected x %s 1., but got x=%r'
                         % ('<=' if eq_upper else '<', x))
    return x
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号