testing.py 文件源码

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

项目:crowddynamics 作者: jaantollander 项目源码 文件源码
def reals(min_value=None,
          max_value=None,
          exclude_zero=None,
          shape=None,
          dtype=np.float):
    """Real number strategy that excludes nan and inf.

    Args:
        min_value (Number, optional):
        max_value (Number, optional):
        exclude_zero (str, optional):
            Choices from: (None, 'exact', 'near')
        shape (int|tuple, optional):
            None for scalar output and int or tuple of int for array output.
        dtype (numpy.float):
            Numpy float type
    """
    # TODO: size as strategy
    assert dtype is None or np.dtype(dtype).kind == u'f'
    if min_value is not None and max_value is not None:
        assert max_value > min_value

    elements = st.floats(min_value, max_value, False, False)

    # Filter values
    if exclude_zero == 'exact':
        elements = elements.filter(lambda x: x != 0.0)
    elif exclude_zero == 'near':
        elements = elements.filter(lambda x: not np.isclose(x, 0.0))

    # Strategy
    if shape is None:
        return elements
    else:
        return arrays(dtype, shape, elements)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号