当前位置: 首页>>代码示例>>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;未经允许,请勿转载。