test_numpy_mt19937.py 文件源码

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

项目:scipy-2017-cython-tutorial 作者: kwmsmith 项目源码 文件源码
def test_int64_uint64_corner_case(self):
        # When stored in Numpy arrays, `lbnd` is casted
        # as np.int64, and `ubnd` is casted as np.uint64.
        # Checking whether `lbnd` >= `ubnd` used to be
        # done solely via direct comparison, which is incorrect
        # because when Numpy tries to compare both numbers,
        # it casts both to np.float64 because there is
        # no integer superset of np.int64 and np.uint64. However,
        # `ubnd` is too large to be represented in np.float64,
        # causing it be round down to np.iinfo(np.int64).max,
        # leading to a ValueError because `lbnd` now equals
        # the new `ubnd`.

        dt = np.int64
        tgt = np.iinfo(np.int64).max
        lbnd = np.int64(np.iinfo(np.int64).max)
        ubnd = np.uint64(np.iinfo(np.int64).max + 1)

        # None of these function calls should
        # generate a ValueError now.
        actual = mt19937.randint(lbnd, ubnd, dtype=dt)
        assert_equal(actual, tgt)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号