Example #1
0
def test_map_no_call():
    explorer = Explorer(parallel='thread')
    cached = explorer.cache_function(my_function)
    data = explorer.map(cached, processes=2, x=range(5))
    data_no_call = explorer.map_no_call(cached, x=range(2, 9))
    print(data, data_no_call)
    assert data_no_call[-1] is None
    assert data_no_call[-2] is None
    assert all(data_no_call[0:3] == data[2:])
Example #2
0
def test_maps():
    explorer = Explorer()

    def my_function(x):
        return x + 1

    data = explorer.map(my_function, x=range(5))
    print(data)
    assert np.allclose(data, np.arange(1, 6))

    def my_function(x, y):
        return x + y

    data = explorer.map(my_function, x=range(5), y=range(3))
    print(data)
    assert data.shape == (5, 3)
    assert data[1, 2] == my_function(1, 2)
    assert data[4, 2] == 4 + 2
def test_mproc_cache():
    explorer = Explorer(parallel='process', cache=FunctoolsCache_Mproc())
    data = explorer.map(my_function, processes=2, x=range(5))
    print('cache info', my_function.cache_info())
    print('cache', my_function._cache)
    data_no_call = explorer.map_no_call(my_function, x=range(2, 9))
    print(data, data_no_call)
    assert data_no_call[-1] is None
    assert data_no_call[-2] is None
    assert all(data_no_call[0:3] == data[2:])
Example #4
0
def test_mproc_cache(tmpdir):
    cache = JobLibCache(str(tmpdir), verbose=1)
    # smoke
    explorer = Explorer(parallel='joblib', cache=cache)
    parallel = JobLib(n_jobs=3, verbose=10)

    explorer = Explorer(parallel=parallel, cache=cache)
    func = explorer.cache_function(my_function)

    start = time.time()
    data = explorer.map(func, processes=2, x=range(6))
    dur = time.time() - start
    assert dur < 6 * DELAY

    data_no_call = explorer.map_no_call(func, x=range(3, 10))
    print(data, data_no_call)
    assert data_no_call[-1] is None
    assert data_no_call[-2] is None
    assert all(data_no_call[0:3] == data[3:])
Example #5
0
def test_mproc():
    explorer = Explorer(parallel='process')
    data = explorer.map(my_function, processes=2, x=range(5))
    print(data)
    assert np.allclose(data, np.arange(1, 6))