当前位置: 首页>>代码示例>>Python>>正文


Python utilities.random函数代码示例

本文整理汇总了Python中test.utilities.random函数的典型用法代码示例。如果您正苦于以下问题:Python random函数的具体用法?Python random怎么用?Python random使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了random函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_slice_1d_2

def test_slice_1d_2(dtype):
    def test(a, b): a[:5] = b[3:8]
    (ao, ah), (b, _) = random(dtype, [10]), random(dtype, [10])
    test(ao, b), hope.jit(test)(ah, b)
    assert check(ao, ah)
    test(ao, b), hope.jit(test)(ah, b)
    assert check(ao, ah)
开发者ID:BrainGrylls,项目名称:hope,代码行数:7,代码来源:test_slice.py

示例2: test_index_2d

def test_index_2d(dtype):
    def fkt(a, b): a[4, 2] = b[3, 4]
    (ao, ah), (b, _) = random(dtype, [5, 5]), random(dtype, [5, 5])
    fkt(ao, b), hope.jit(fkt)(ah, b)
    assert check(ao, ah)
    fkt(ao, b), hope.jit(fkt)(ah, b)
    assert check(ao, ah)
开发者ID:cosmo-ethz,项目名称:hope,代码行数:7,代码来源:test_slice.py

示例3: test_fkt_call_scalar_jit_multi

def test_fkt_call_scalar_jit_multi(dtype):
    hfkt = hope.jit(fkt_call_scalar_jit_multi_fkt)
    (a, _), (c, _) = random(dtype, []), random(dtype, [])
    c = hfkt(a)
    assert check(c, a + 1)
    c = hfkt(a)
    assert check(c, a + 1)
开发者ID:BrainGrylls,项目名称:hope,代码行数:7,代码来源:test_call.py

示例4: test_slice_1d_3

def test_slice_1d_3(dtype):
    def fkt(a, b): a[2:] = b[1:9]
    (ao, ah), (b, _) = random(dtype, [10]), random(dtype, [10])
    fkt(ao, b), hope.jit(fkt)(ah, b)
    assert check(ao, ah)
    fkt(ao, b), hope.jit(fkt)(ah, b)
    assert check(ao, ah)
开发者ID:cosmo-ethz,项目名称:hope,代码行数:7,代码来源:test_slice.py

示例5: test_index_1d

def test_index_1d(dtype):
    def fkt(a, b): a[5] = b[3]
    (ao, ah), (b, _) = random(dtype, [10]), random(dtype, [10])
    fkt(ao, b), hope.jit(fkt)(ah, b)
    assert check(ao, ah)
    fkt(ao, b), hope.jit(fkt)(ah, b)
    assert check(ao, ah)
开发者ID:cosmo-ethz,项目名称:hope,代码行数:7,代码来源:test_slice.py

示例6: test_assignment

def test_assignment(dtype):
    def fkt(a, b): a[:] = b
    (ao, ah), (b, _) = random(dtype, [10]), random(dtype, [10])
    fkt(ao, b), hope.jit(fkt)(ah, b)
    assert check(ao, ah)
    fkt(ao, b), hope.jit(fkt)(ah, b)
    assert check(ao, ah)
开发者ID:cosmo-ethz,项目名称:hope,代码行数:7,代码来源:test_slice.py

示例7: test_cross_div

def test_cross_div(dtypea, dtypeb, dtypec):
    if dtypea == np.int8 and dtypeb == np.int8:
        pytest.skip("Different behaviour in c++ and python for int8 / int8".format(dtypea, dtypeb))

    def fkt(a, b, c):
        c[:] = a / b

    hfkt = hope.jit(fkt)
    (ao, ah), (bo, bh), (co, ch) = random(dtypea, [10]), random(dtypeb, [10]), random(dtypec, [10])
    ao, ah, bo, bh = ao.astype(np.float64), ah.astype(np.float64), bo.astype(np.float64), bh.astype(np.float64)
    ao, ah = (
        np.copysign(np.power(np.abs(ao), 1.0 / 4.0), ao).astype(dtypea),
        np.copysign(np.power(np.abs(ah), 1.0 / 4.0), ah).astype(dtypea),
    )
    bo, bh = (
        np.copysign(np.power(np.abs(bo), 1.0 / 4.0), bo).astype(dtypeb),
        np.copysign(np.power(np.abs(bh), 1.0 / 4.0), bh).astype(dtypeb),
    )
    if np.count_nonzero(bo == 0) > 0:
        bo[bo == 0] += 1
    if np.count_nonzero(bh == 0) > 0:
        bh[bh == 0] += 1
    fkt(ao, bo, co), hfkt(ah, bh, ch)
    assert check(co, ch)
    fkt(ao, bo, co), hfkt(ah, bh, ch)
    assert check(co, ch)
开发者ID:you13,项目名称:hope,代码行数:26,代码来源:test_op_div.py

示例8: test_call_scalar_jit_fun_return

def test_call_scalar_jit_fun_return(dtype):
    def fkt(a):
        return fkt_call_scalar_jit_fun_return_callback(a)
    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, []), random(dtype, [])
    co, ch = fkt(ao), hfkt(ah)
    assert check(co, ch)
    co, ch = fkt(ao), hfkt(ah)
    assert check(co, ch)
开发者ID:BrainGrylls,项目名称:hope,代码行数:9,代码来源:test_call.py

示例9: test_augmented_rshift

def test_augmented_rshift(dtype, shape):
    def fkt(a, c):
        c[:] >>= a
    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, [10]), random(dtype, [10])
    ao, ah = (ao % (np.dtype(dtype).itemsize * 8)).astype(dtype), (ah % (np.dtype(dtype).itemsize * 8)).astype(dtype)
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
开发者ID:BrainGrylls,项目名称:hope,代码行数:10,代码来源:test_operators.py

示例10: test_binary_rshift

def test_binary_rshift(dtype, shape):
    def fkt(a, b, c):
        c[:] = a >> b
    hfkt = hope.jit(fkt)
    (ao, ah), (bo, bh), (co, ch) = random(dtype, shape), random(dtype, shape), random(dtype, shape)
    bo, bh = (bo % (np.dtype(dtype).itemsize * 8)).astype(dtype), (bh % (np.dtype(dtype).itemsize * 8)).astype(dtype)
    fkt(ao, bo, co),  hfkt(ah, bh, ch)
    assert check(co, ch)
    fkt(ao, bo, co),  hfkt(ah, bh, ch)
    assert check(co, ch)
开发者ID:BrainGrylls,项目名称:hope,代码行数:10,代码来源:test_operators.py

示例11: test_binary_minus

def test_binary_minus(dtype, shape):
    def fkt(a, b, c):
        c[:] = a - b
    hfkt = hope.jit(fkt)
    (ao, ah), (bo, bh), (co, ch) = random(dtype, shape), random(dtype, shape), random(dtype, shape)
    ao, ah, bo, bh = (ao / 2.).astype(dtype), (ah / 2.).astype(dtype), (bo / 2.).astype(dtype), (bh / 2.).astype(dtype)
    ro, rh = fkt(ao, bo, co),  hfkt(ah, bh, ch)
    assert check(co, ch)
    ro, rh = fkt(ao, bo, co),  hfkt(ah, bh, ch)
    assert check(co, ch)
开发者ID:BrainGrylls,项目名称:hope,代码行数:10,代码来源:test_op_minus.py

示例12: test_augmented_minus

def test_augmented_minus(dtype, shape):
    def fkt(a, c):
        c[:] -= a
    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, shape), random(dtype, shape)
    ao, ah, co, ch = (ao / 4.).astype(dtype), (ah / 4.).astype(dtype), (co / 2.).astype(dtype), (ch / 2.).astype(dtype)
    ro, rh = fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
    ro, rh = fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
开发者ID:BrainGrylls,项目名称:hope,代码行数:10,代码来源:test_op_minus.py

示例13: test_call_local_fun

def test_call_local_fun(dtype, shape):
    def fkt(a, b, c):
        fkt_call_local_fun_callback(a, b)
        c[:] = a
    hfkt = hope.jit(fkt)
    (ao, ah), (bo, bh), (co, ch) = random(dtype, shape), random(dtype, shape), random(dtype, shape)
    fkt(ao, bo, co),  hfkt(ah, bh, ch)
    assert check(co, ch)
    fkt(ao, bo, co),  hfkt(ah, bh, ch)
    assert check(co, ch)
开发者ID:BrainGrylls,项目名称:hope,代码行数:10,代码来源:test_call.py

示例14: test_binary_pow

def test_binary_pow(dtype, shape):
    def fkt(a, c):
        c[:] = a ** 2
    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, shape), random(dtype, shape)
    ao, ah = np.copysign(np.sqrt(np.abs(ao)), ao).astype(dtype), np.copysign(np.sqrt(np.abs(ah)), ah).astype(dtype)
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
开发者ID:BrainGrylls,项目名称:hope,代码行数:10,代码来源:test_op_pow.py

示例15: test_augmented_mod

def test_augmented_mod(dtype, shape):
    def fkt(a, c):
        c[:] %= a
    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, shape), random(dtype, shape)
    if np.count_nonzero(ao == 0) > 0: ao[ao == 0] += 1
    if np.count_nonzero(ah == 0) > 0: ah[ah == 0] += 1
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
开发者ID:BrainGrylls,项目名称:hope,代码行数:11,代码来源:test_operators.py


注:本文中的test.utilities.random函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。