當前位置: 首頁>>代碼示例>>Python>>正文


Python MemmapingPool.apply_async方法代碼示例

本文整理匯總了Python中joblib.pool.MemmapingPool.apply_async方法的典型用法代碼示例。如果您正苦於以下問題:Python MemmapingPool.apply_async方法的具體用法?Python MemmapingPool.apply_async怎麽用?Python MemmapingPool.apply_async使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在joblib.pool.MemmapingPool的用法示例。


在下文中一共展示了MemmapingPool.apply_async方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_memmaping_pool_for_large_arrays_in_return

# 需要導入模塊: from joblib.pool import MemmapingPool [as 別名]
# 或者: from joblib.pool.MemmapingPool import apply_async [as 別名]
def test_memmaping_pool_for_large_arrays_in_return(tmpdir):
    """Check that large arrays are not copied in memory in return"""
    assert_array_equal = np.testing.assert_array_equal

    # Build an array reducers that automaticaly dump large array content
    # but check that the returned datastructure are regular arrays to avoid
    # passing a memmap array pointing to a pool controlled temp folder that
    # might be confusing to the user

    # The MemmapingPool user can always return numpy.memmap object explicitly
    # to avoid memory copy
    p = MemmapingPool(3, max_nbytes=10, temp_folder=tmpdir.strpath)
    try:
        res = p.apply_async(np.ones, args=(1000,))
        large = res.get()
        assert not has_shareable_memory(large)
        assert_array_equal(large, np.ones(1000))
    finally:
        p.terminate()
        del p
開發者ID:,項目名稱:,代碼行數:22,代碼來源:

示例2: test_workaround_against_bad_memmap_with_copied_buffers

# 需要導入模塊: from joblib.pool import MemmapingPool [as 別名]
# 或者: from joblib.pool.MemmapingPool import apply_async [as 別名]
def test_workaround_against_bad_memmap_with_copied_buffers(tmpdir):
    """Check that memmaps with a bad buffer are returned as regular arrays

    Unary operations and ufuncs on memmap instances return a new memmap
    instance with an in-memory buffer (probably a numpy bug).
    """
    assert_array_equal = np.testing.assert_array_equal

    p = MemmapingPool(3, max_nbytes=10, temp_folder=tmpdir.strpath)
    try:
        # Send a complex, large-ish view on a array that will be converted to
        # a memmap in the worker process
        a = np.asarray(np.arange(6000).reshape((1000, 2, 3)),
                       order='F')[:, :1, :]

        # Call a non-inplace multiply operation on the worker and memmap and
        # send it back to the parent.
        b = p.apply_async(_worker_multiply, args=(a, 3)).get()
        assert not has_shareable_memory(b)
        assert_array_equal(b, 3 * a)
    finally:
        p.terminate()
        del p
開發者ID:,項目名稱:,代碼行數:25,代碼來源:


注:本文中的joblib.pool.MemmapingPool.apply_async方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。