Пример #1
0
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)
Пример #2
0
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)
Пример #3
0
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)
Пример #4
0
def test_scalar(dtype):
    def fkt(a, b):
        a[3] = b

    (ao, ah), (b, _) = random(dtype, [10]), random(dtype, [])
    fkt(ao, b), hope.jit(fkt)(ah, b)
    assert check(ao, ah)
Пример #5
0
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)
Пример #6
0
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)
Пример #7
0
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)
Пример #8
0
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)
Пример #9
0
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)
Пример #10
0
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)
Пример #11
0
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)
Пример #12
0
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)
Пример #13
0
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)
Пример #14
0
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)
Пример #15
0
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)
Пример #16
0
def test_binary_plus(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)
Пример #17
0
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)
Пример #18
0
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)
Пример #19
0
def test_augmented_plus(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)
Пример #20
0
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)
Пример #21
0
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)
Пример #22
0
def test_merged_slice(dtype):
    def fkt(a, b, c):
        for i in range(10):
            c[:, i] = a[i, :]
    hfkt = hope.jit(fkt)
    (ao, ah), (bo, bh), (co, ch) = random(dtype, [10, 10]), random(dtype, [10, 10]), random(dtype, [10, 10])
    ao, ah, bo, bh = (ao / 2.).astype(dtype), (ah / 2.).astype(dtype), (bo / 2.).astype(dtype), (bh / 2.).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)
Пример #23
0
def test_for_range_2(dtype):
    def fkt(a, b, c):
        for i in range(0, 10):
            c[:, i] = a[i, :]
            c[i, 1] = a[0, 1] + b[i, 5]
    hfkt = hope.jit(fkt)
    (ao, ah), (bo, bh), (co, ch) = random(dtype, [10, 10]), random(dtype, [10, 10]), random(dtype, [10, 10])
    ao, ah, bo, bh = (ao / 2.).astype(dtype), (ah / 2.).astype(dtype), (bo / 2.).astype(dtype), (bh / 2.).astype(dtype)
    assert check(co, ch)
    ro, rh = fkt(ao, bo, co), hfkt(ah, bh, ch)
    assert check(co, ch)
Пример #24
0
def test_augmented_mult(dtype, shape):
    def fkt(a, c):
        c[:] *= a
    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, shape), random(dtype, shape)
    ao, ah = np.copysign(np.power(np.abs(ao), 1. / 4.), ao).astype(dtype), np.copysign(np.power(np.abs(ah), 1. / 4.), ah).astype(dtype)
    co, ch = np.copysign(np.power(np.abs(co), 1. / 4.), co).astype(dtype), np.copysign(np.power(np.abs(ch), 1. / 4.), ch).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)
Пример #25
0
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)
Пример #26
0
def test_func_sum_expr(dtype, shape):
    def fkt(a, b):
        return np.sum(a + b)
    hfkt = hope.jit(fkt)
    (ao, ah), (bo, bh) = random(dtype, shape), random(dtype, shape)
    ao, ah = np.abs(ao) / 2400, np.abs(ah) / 2400
    bo, bh = np.abs(bo) / 2400, np.abs(bh) / 2400
    co, ch = fkt(ao, bo), hfkt(ah, bh)
    assert check(co, ch)
    co, ch = fkt(ao, bo), hfkt(ah, bh)
    assert check(co, ch)
Пример #27
0
def test_cross_add_scalar(dtype):
    def fkt(a, b, c):
        c[:] = a + b
    hfkt = hope.jit(fkt)
    dtypeo = np.float64 if dtype == float else dtype
    (ao, ah), (bo, bh), (co, ch) = random(dtypeo, [100]), random(dtypeo, []), random(dtypeo, [100])
    ao, ah = (ao / 2.).astype(dtype), (ah / 2.).astype(dtype)
    bo, bh = (bo / 2.).astype(dtype), (bh / 2.).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)
Пример #28
0
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)
Пример #29
0
def test_opt_pow_array(dtype, shape):
    def fkt(a, c):
        c[:] = a ** 2.0 + a ** 4 + a ** 7
    hope.config.optimize = True
    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, shape), random(dtype, shape)
    ao, ah = np.copysign(np.power(np.abs(ao), 1. / 8.), ao).astype(dtype), np.copysign(np.power(np.abs(ah), 1. / 8.), ah).astype(dtype)
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
    hope.config.optimize = False
Пример #30
0
def test_merged_slice_2(dtype):
    def fkt(a, c):
        a[1:] = c[:-1] + c[1:]
        c[:] = a
    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, [5]), random(dtype, [5])
    ao, ah = (ao / 4.).astype(dtype), (ah / 4.).astype(dtype)
    co, ch = (co / 4.).astype(dtype), (ch / 4.).astype(dtype)
    fkt(ao, co), hfkt(ah, ch)
    assert check(co, ch)
    fkt(ao, co), hfkt(ah, ch)
    assert check(co, ch)
Пример #31
0
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)
Пример #32
0
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)
Пример #33
0
def test_return_arr_expr(dtype, shape):
    def fkt(a, c):
        return a ** -2 + a ** -4.0 + a ** -7
    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, shape), random(dtype, shape)
    ao, ah = np.copysign(np.power(np.abs(ao), 1. / 8.), ao).astype(dtype), np.copysign(np.power(np.abs(ah), 1. / 8.), ah).astype(dtype)
    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)
Пример #34
0
def test_augmented_floordiv(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
    ro, rh = fkt(ao, co),  hfkt(ah, ch)
    if dtype in [np.float32, np.float64, float]:
        co[co < 1. /  (np.finfo(dtype).max * np.finfo(dtype).resolution)] /= np.finfo(dtype).resolution
        ch[ch < 1. /  (np.finfo(dtype).max * np.finfo(dtype).resolution)] /= np.finfo(dtype).resolution
    assert check(co.astype(dtype), ch.astype(dtype))
Пример #35
0
def test_func_sum_expr(dtype, shape):
    def fkt(a, b):
        return np.sum(a + b)

    hfkt = hope.jit(fkt)
    (ao, ah), (bo, bh) = random(dtype, shape), random(dtype, shape)
    ao, ah = np.abs(ao) / 2400, np.abs(ah) / 2400
    bo, bh = np.abs(bo) / 2400, np.abs(bh) / 2400
    co, ch = fkt(ao, bo), hfkt(ah, bh)
    assert check(co, ch)
    co, ch = fkt(ao, bo), hfkt(ah, bh)
    assert check(co, ch)
Пример #36
0
def test_binary_floordiv(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)
    if np.count_nonzero(bo == 0) > 0: bo[bo == 0] += 1
    if np.count_nonzero(bh == 0) > 0: bh[bh == 0] += 1
    ro, rh = fkt(ao, bo, co),  hfkt(ah, bh, ch)
    if dtype in [np.float32, np.float64, float]:
        co[co < 1. /  (np.finfo(dtype).max * np.finfo(dtype).resolution)] /= np.finfo(dtype).resolution
        ch[ch < 1. /  (np.finfo(dtype).max * np.finfo(dtype).resolution)] /= np.finfo(dtype).resolution
    assert check(co, ch)
Пример #37
0
def test_opt_pow_scalar(dtype):
    def fkt(a, c):
        c[0] = a ** 2 + a ** 4 + a ** 7.0
    hope.config.optimize = True
    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, []), random(dtype, [1])
    ao, ah = np.copysign(np.power(np.abs(ao), 1. / 8.), ao).astype(dtype), np.copysign(np.power(np.abs(ah), 1. / 8.), ah).astype(dtype)
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
    hope.config.optimize = False
Пример #38
0
def test_cross_add_dtype(dtypea, dtypeb, dtypec):
    def fkt(a, b, c):
        c[:] = a + b
    hfkt = hope.jit(fkt)
    dtypeao = np.float64 if dtypea == float else dtypea
    dtypebo = np.float64 if dtypeb == float else dtypeb
    (ao, ah), (bo, bh), (co, ch) = random(dtypeao, [100]), random(dtypebo, [100]), random(dtypec, [100])
    ao, ah = (ao / 2.).astype(dtypea), (ah / 2.).astype(dtypea)
    bo, bh = (bo / 2.).astype(dtypeb), (bh / 2.).astype(dtypeb)
    fkt(ao.astype(dtypea), bo.astype(dtypeb), co),  hfkt(ah.astype(dtypea), bh.astype(dtypeb), ch)
    assert check(co, ch)
    fkt(ao.astype(dtypea), bo.astype(dtypeb), co),  hfkt(ah.astype(dtypea), bh.astype(dtypeb), ch)
    assert check(co, ch)
Пример #39
0
def test_merged_slice_2(dtype):
    def fkt(a, c):
        a[1:] = c[:-1] + c[1:]
        c[:] = a

    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, [5]), random(dtype, [5])
    ao, ah = (ao / 4.).astype(dtype), (ah / 4.).astype(dtype)
    co, ch = (co / 4.).astype(dtype), (ch / 4.).astype(dtype)
    fkt(ao, co), hfkt(ah, ch)
    assert check(co, ch)
    fkt(ao, co), hfkt(ah, ch)
    assert check(co, ch)
Пример #40
0
def test_ifelse_scalar():
    def fkt(a, b, c):
        if b > 0:
            c[:] = -a
        else:
            c[:] = a
    hfkt = hope.jit(fkt)
    (ao, ah), (bo, bh), (co, ch) = random(np.int_, [10]), (1, 1), random(np.int_, [10])
    fkt(ao, bo, co), hfkt(ah, bh, ch)
    assert check(co, ch)
    (ao, ah), (bo, bh), (co, ch) = random(np.int_, [10]), (0, 0), random(np.int_, [10])
    fkt(ao, bo, co), hfkt(ah, bh, ch)
    assert check(co, ch)
Пример #41
0
def test_binary_mult(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 = np.copysign(np.sqrt(np.abs(ao.astype(np.float64))).astype(dtype), ao).astype(dtype)
    ah = np.copysign(np.sqrt(np.abs(ah.astype(np.float64))).astype(dtype), ah).astype(dtype)
    bo = np.copysign(np.sqrt(np.abs(bo.astype(np.float64))).astype(dtype), bo).astype(dtype)
    bh = np.copysign(np.sqrt(np.abs(bh.astype(np.float64))).astype(dtype), bh).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)
Пример #42
0
def test_binary_mod(dtype, shape):
    if JENKINS and dtype == np.int8:
        pytest.skip("Fails on debian: dtype={0!s}".format(dtype))
    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)
    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)
Пример #43
0
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)
Пример #44
0
def test_merged_slice(dtype):
    def fkt(a, b, c):
        for i in range(10):
            c[:, i] = a[i, :]

    hfkt = hope.jit(fkt)
    (ao, ah), (bo, bh), (co, ch) = random(dtype, [10, 10]), random(
        dtype, [10, 10]), random(dtype, [10, 10])
    ao, ah, bo, bh = (ao / 2.).astype(dtype), (ah / 2.).astype(dtype), (
        bo / 2.).astype(dtype), (bh / 2.).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)
Пример #45
0
def test_opt_pow_scalar(dtype):
    def fkt(a, c):
        c[0] = a**2 + a**4 + a**7.0

    hope.config.optimize = True
    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, []), random(dtype, [1])
    ao, ah = np.copysign(np.power(np.abs(ao), 1. / 8.),
                         ao).astype(dtype), np.copysign(
                             np.power(np.abs(ah), 1. / 8.), ah).astype(dtype)
    fkt(ao, co), hfkt(ah, ch)
    assert check(co, ch)
    fkt(ao, co), hfkt(ah, ch)
    assert check(co, ch)
    hope.config.optimize = False
Пример #46
0
def test_return_arr_expr(dtype, shape):
    def fkt(a, c):
        return a**-2 + a**-4.0 + a**-7

    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, shape), random(dtype, shape)
    ao, ah = np.copysign(np.power(np.abs(ao), 1. / 8.),
                         ao).astype(dtype), np.copysign(
                             np.power(np.abs(ah), 1. / 8.), ah).astype(dtype)
    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)
Пример #47
0
def test_opt_pow_array(dtype, shape):
    def fkt(a, c):
        c[:] = a**2.0 + a**4 + a**7

    hope.config.optimize = True
    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, shape), random(dtype, shape)
    ao, ah = np.copysign(np.power(np.abs(ao), 1. / 8.),
                         ao).astype(dtype), np.copysign(
                             np.power(np.abs(ah), 1. / 8.), ah).astype(dtype)
    fkt(ao, co), hfkt(ah, ch)
    assert check(co, ch)
    fkt(ao, co), hfkt(ah, ch)
    assert check(co, ch)
    hope.config.optimize = False
Пример #48
0
def test_augmented_mult(dtype, shape):
    def fkt(a, c):
        c[:] *= a

    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, shape), random(dtype, shape)
    ao, ah = np.copysign(np.power(np.abs(ao), 1. / 4.),
                         ao).astype(dtype), np.copysign(
                             np.power(np.abs(ah), 1. / 4.), ah).astype(dtype)
    co, ch = np.copysign(np.power(np.abs(co), 1. / 4.),
                         co).astype(dtype), np.copysign(
                             np.power(np.abs(ch), 1. / 4.), ch).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)
Пример #49
0
def test_opt_basic_scalar(dtype):
    def fkt(a, c):
        c[0] = a**-2

    hope.config.optimize = True
    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, []), random(dtype, [1])
    ao, ah = 1. / np.power(np.abs(ao), 1. / 2.).astype(dtype), 1. / np.power(
        np.abs(ah), 1. / 2.).astype(dtype)
    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)
    hope.config.optimize = False
Пример #50
0
def test_blocks_1(dtype):
    def fkt(a, b, c, d):
        e = b[6:9]
        a[2:5] = e
        a[0] = 0
        a[0] = c[1]
        b[:] = d

    (ao, ah), (bo, bh), (c, _), (d, _) = random(dtype, [10]), random(
        dtype, [10]), random(dtype, [10]), random(dtype, [10])
    fkt(ao, bo, c, d), hope.jit(fkt)(ah, bh, c, d)
    assert check(ao, ah)
    assert check(bo, bh)
    fkt(ao, bo, c, d), hope.jit(fkt)(ah, bh, c, d)
    assert check(ao, ah)
    assert check(bo, bh)
Пример #51
0
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. / 4.), ao).astype(dtypea), np.copysign(np.power(np.abs(ah), 1. / 4.), ah).astype(dtypea)
    bo, bh = np.copysign(np.power(np.abs(bo), 1. / 4.), bo).astype(dtypeb), np.copysign(np.power(np.abs(bh), 1. / 4.), 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)
Пример #52
0
def test_return_arrayscalar(dtype):
    def fkt(a):
        return a[2]

    ao, ah = random(dtype, [10])
    ro, rh = fkt(ao), hope.jit(fkt)(ah)
    assert check(ro, rh)
Пример #53
0
def test_func_uint32(dtype):
    def fkt(a):
        return np.uint32(a)
    hfkt = hope.jit(fkt)
    ao, ah = random(dtype, [])
    co, ch = fkt(ao), hfkt(ah)
    assert type(co) == type(ch)