Esempio n. 1
0
def test_op_logical(done, op, vector_size, use_numpy=False):
    if vector_size > 1:
        if use_numpy:
            data = np.random.rand(vector_size)
            p = 0.1
            data = np.random.choice(a=[False, True],
                                    size=(vector_size),
                                    p=[p, 1 - p])
        else:
            data = list(map(bool, range(0, vector_size)))
    else:
        data = bool(random.randint(0, 1))

    finished_future = Future(2)
    chares = Array(TestVec, vector_size, args=[op, data])
    chares.do_test(None, finished_future)
    section = chares[0:vector_size]
    section.do_test(section, finished_future)
    val1, val2 = finished_future.get()

    try:
        if vector_size > 1:
            assert list(val1) == list(val2)
        else:
            assert val1 == val2
        print('[Main] Reduction with Reducer.%s passes.' % get_op_name(op))
        done(True)
    except AssertionError:
        print('[Main] Reduction with Reducer.%s is not correct.' %
              get_op_name(op))
        done(False)
Esempio n. 2
0
def test_op(done, op, vector_size, use_numpy=False):
    if vector_size > 1:
        if use_numpy:
            data = np.random.rand(vector_size)
        else:
            data = list(range(0, vector_size))
    else:
        data = random.uniform(0, 5)

    finished_future = Future(2)
    chares = Array(TestVec, vector_size, args=[op, data])
    chares.do_test(None, finished_future, awaitable=True).get()
    section = chares[0:vector_size]
    section.do_test(section, finished_future)
    val1, val2 = finished_future.get()

    try:
        if vector_size > 1:
            if use_numpy:
                assert np.isclose(val1, val2, atol=1e-5).all()
            else:
                assert list(val1) == list(val2)
        else:
            assert val1 == val2
        print('[Main] Reduction with Reducer.%s passes.' % get_op_name(op))
        done(True)
    except AssertionError:
        print('[Main] Reduction with Reducer.%s is not correct.' %
              get_op_name(op))
        done(False)