예제 #1
0
파일: test_op_div.py 프로젝트: you13/hope
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)
예제 #2
0
파일: test_call.py 프로젝트: sthagen/hope
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)
예제 #3
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)
예제 #4
0
파일: test_object.py 프로젝트: sthagen/hope
def test_cls_1():
    inst = Cls()
    inst.fkt_1()
    assert check(inst.af, inst.res)
    inst.af = np.array([1, 2, 3], dtype=np.int_)
    inst.fkt_1()
    assert check(inst.af, inst.res)
예제 #5
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)
예제 #6
0
def test_cls_1():
    inst = Cls()
    inst.fkt_1()
    assert check(inst.af, inst.res)
    inst.af = np.array([1, 2, 3], dtype=np.int_)
    inst.fkt_1()
    assert check(inst.af, inst.res)
예제 #7
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)
예제 #8
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)
예제 #9
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)
예제 #10
0
def test_index_2d_2(dtype):
    def fkt(a): a[1:4, 1:4] = 1
    (ao, ah) = random(dtype, [5, 5])
    
    fkt(ao), hope.jit(fkt)(ah)
    assert check(ao, ah)
    fkt(ao), hope.jit(fkt)(ah)
    assert check(ao, ah)
예제 #11
0
파일: test_slice.py 프로젝트: sthagen/hope
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
파일: test_slice.py 프로젝트: sthagen/hope
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
파일: test_slice.py 프로젝트: sthagen/hope
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)
예제 #14
0
파일: test_slice.py 프로젝트: sthagen/hope
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)
예제 #15
0
파일: test_call.py 프로젝트: sthagen/hope
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)
예제 #16
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)
예제 #17
0
파일: test_call.py 프로젝트: sthagen/hope
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)
예제 #18
0
파일: test_slice.py 프로젝트: sthagen/hope
def test_index_2d_2(dtype):
    def fkt(a):
        a[1:4, 1:4] = 1

    (ao, ah) = random(dtype, [5, 5])

    fkt(ao), hope.jit(fkt)(ah)
    assert check(ao, ah)
    fkt(ao), hope.jit(fkt)(ah)
    assert check(ao, ah)
예제 #19
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)
예제 #20
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)
예제 #21
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)
예제 #22
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)
예제 #23
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)
예제 #24
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)
예제 #25
0
def test_func_sum_var(dtype, shape):
    def fkt(a):
        return np.sum(a)
    hfkt = hope.jit(fkt)
    ao, ah = random(dtype, shape)
    ao, ah = ao / 1200, ah / 1200
    co, ch = fkt(ao), hfkt(ah)
    assert check(co, ch)
    co, ch = fkt(ao), hfkt(ah)
    assert check(co, ch)
예제 #26
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)
예제 #27
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)
예제 #28
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)
예제 #29
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)
예제 #30
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)
예제 #31
0
def test_func_sum_var(dtype, shape):
    def fkt(a):
        return np.sum(a)

    hfkt = hope.jit(fkt)
    ao, ah = random(dtype, shape)
    ao, ah = ao / 1200, ah / 1200
    co, ch = fkt(ao), hfkt(ah)
    assert check(co, ch)
    co, ch = fkt(ao), hfkt(ah)
    assert check(co, ch)
예제 #32
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)
예제 #33
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)
예제 #34
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
예제 #35
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)
예제 #36
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
예제 #37
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)
예제 #38
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)
예제 #39
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)
예제 #40
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)
예제 #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
파일: test_slice.py 프로젝트: sthagen/hope
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)
예제 #43
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)
예제 #44
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)
예제 #45
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)
예제 #46
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)
예제 #47
0
파일: test_slice.py 프로젝트: sthagen/hope
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)
예제 #48
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
예제 #49
0
파일: test_return.py 프로젝트: sthagen/hope
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)
예제 #50
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
예제 #51
0
파일: test_return.py 프로젝트: sthagen/hope
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)
예제 #52
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
예제 #53
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)
예제 #54
0
파일: test_ufig.py 프로젝트: sthagen/hope
def test_ufig_sin_cos():
    sinTable = np.sin(
        np.array(range(0, (1 << 11) + 1), dtype=np.float64) * 2. * np.pi /
        np.float64(1 << 11))
    cosTable = np.cos(
        np.array(range(0, (1 << 11) + 1), dtype=np.float64) * 2. * np.pi /
        np.float64(1 << 11))
    rngBuffer = np.random.randint(0, 1 << 32, size=(44497, )).astype(np.uint32)

    def fkt_sncn(pt, rng, sinTable, cosTable):
        scL = rng >> (32 - 11)
        scB = np.float64(rng & np.uint32(
            (1 << (32 - 11)) - 1)) / np.float64(1 << (32 - 11))
        scA = 1. - scB
        pt[0] = scA * sinTable[scL] + scB * sinTable[scL + 1]
        pt[1] = scA * cosTable[scL] + scB * cosTable[scL + 1]

    rngBuffer = np.random.randint(0, 1 << 32, size=(1000, )).astype(np.uint32)
    pt, hpt = np.array([0., 0.]), np.array([0., 0.])
    hope.config.optimize = True
    hsncn = hope.jit(fkt_sncn)

    for rng in rngBuffer:
        fkt_sncn(pt, rng, sinTable, cosTable)
        hsncn(hpt, rng, sinTable, cosTable)
        assert check(pt, hpt)
        ang = rng / float(1 << 32) * 2. * np.pi
        assert np.all((hpt - np.array([np.sin(ang), np.cos(ang)])) / pt < 1e-5)
    hope.config.optimize = False
예제 #55
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)
예제 #56
0
파일: test_slice.py 프로젝트: sthagen/hope
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)