当前位置: 首页>>代码示例>>Python>>正文


Python DecoderCache.shrink方法代码示例

本文整理汇总了Python中nengo.cache.DecoderCache.shrink方法的典型用法代码示例。如果您正苦于以下问题:Python DecoderCache.shrink方法的具体用法?Python DecoderCache.shrink怎么用?Python DecoderCache.shrink使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nengo.cache.DecoderCache的用法示例。


在下文中一共展示了DecoderCache.shrink方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_decoder_cache_shrink_threadsafe

# 需要导入模块: from nengo.cache import DecoderCache [as 别名]
# 或者: from nengo.cache.DecoderCache import shrink [as 别名]
def test_decoder_cache_shrink_threadsafe(monkeypatch, tmpdir):
    """Tests that shrink handles files deleted by other processes."""
    cache_dir = str(tmpdir)
    solver_mock = SolverMock()
    another_solver = SolverMock('another_solver')

    cache = DecoderCache(cache_dir=cache_dir)
    cache.wrap_solver(solver_mock)(**get_solver_test_args())
    limit = cache.get_size()

    # Ensure differing time stamps (depending on the file system the timestamp
    # resolution might be as bad as 1 day).
    for filename in os.listdir(cache.cache_dir):
        path = os.path.join(cache.cache_dir, filename)
        timestamp = os.stat(path).st_atime
        timestamp -= 60 * 60 * 24 * 2  # 2 days
        os.utime(path, (timestamp, timestamp))

    cache.wrap_solver(another_solver)(**get_solver_test_args())

    cache_size = cache.get_size_in_bytes()
    assert cache_size > 0

    def raise_file_not_found(*args, **kwargs):
        raise OSError(errno.ENOENT, "File not found.")

    monkeypatch.setattr(cache, 'get_size_in_bytes', lambda: cache_size)
    monkeypatch.setattr('os.stat', raise_file_not_found)
    monkeypatch.setattr('os.remove', raise_file_not_found)
    monkeypatch.setattr('os.unlink', raise_file_not_found)

    cache.shrink(limit)
开发者ID:amshenoy,项目名称:nengo,代码行数:34,代码来源:test_cache.py

示例2: test_decoder_cache_shrinking

# 需要导入模块: from nengo.cache import DecoderCache [as 别名]
# 或者: from nengo.cache.DecoderCache import shrink [as 别名]
def test_decoder_cache_shrinking(tmpdir):
    cache_dir = str(tmpdir)
    solver_mock = SolverMock()
    another_solver = SolverMock('another_solver')

    cache = DecoderCache(cache_dir=cache_dir)
    cache.wrap_solver(solver_mock)(**get_solver_test_args())

    # Ensure differing time stamps (depending on the file system the timestamp
    # resolution might be as bad as 1 day).
    for path in cache.get_files():
        timestamp = os.stat(path).st_atime
        timestamp -= 60 * 60 * 24 * 2  # 2 days
        os.utime(path, (timestamp, timestamp))

    cache.wrap_solver(another_solver)(**get_solver_test_args())

    cache_size = cache.get_size_in_bytes()
    assert cache_size > 0

    cache.shrink(cache_size - 1)

    # check that older cached result was removed
    assert SolverMock.n_calls[solver_mock] == 1
    cache.wrap_solver(another_solver)(**get_solver_test_args())
    cache.wrap_solver(solver_mock)(**get_solver_test_args())
    assert SolverMock.n_calls[solver_mock] == 2
    assert SolverMock.n_calls[another_solver] == 1
开发者ID:amshenoy,项目名称:nengo,代码行数:30,代码来源:test_cache.py

示例3: test_shrink_does_not_fail_if_lock_cannot_be_acquired

# 需要导入模块: from nengo.cache import DecoderCache [as 别名]
# 或者: from nengo.cache.DecoderCache import shrink [as 别名]
def test_shrink_does_not_fail_if_lock_cannot_be_acquired(tmpdir):
    cache = DecoderCache(cache_dir=str(tmpdir))
    cache._index._lock.timeout = 1.
    with cache:
        cache.wrap_solver(SolverMock())(**get_solver_test_args())
    with cache._index._lock:
        cache.shrink(limit=0)
开发者ID:nengo,项目名称:nengo,代码行数:9,代码来源:test_cache.py

示例4: test_warns_out_of_context

# 需要导入模块: from nengo.cache import DecoderCache [as 别名]
# 或者: from nengo.cache.DecoderCache import shrink [as 别名]
def test_warns_out_of_context(tmpdir):
    cache_dir = str(tmpdir)
    cache = DecoderCache(cache_dir=cache_dir)

    with warns(UserWarning):
        cache.shrink()

    solver_mock = SolverMock()
    solver = cache.wrap_solver(solver_mock)
    with warns(UserWarning):
        solver(**get_solver_test_args())
    assert SolverMock.n_calls[solver_mock] == 1
开发者ID:GYGit,项目名称:nengo,代码行数:14,代码来源:test_cache.py

示例5: test_decoder_cache_shrinking

# 需要导入模块: from nengo.cache import DecoderCache [as 别名]
# 或者: from nengo.cache.DecoderCache import shrink [as 别名]
def test_decoder_cache_shrinking(tmpdir):
    cache_dir = str(tmpdir)
    solver_mock = SolverMock()
    another_solver = SolverMock('another_solver')

    M = 100
    N = 10
    D = 2
    activities = np.ones((M, D))
    targets = np.ones((M, N))
    rng = np.random.RandomState(42)

    cache = DecoderCache(cache_dir=cache_dir)
    cache.wrap_solver(solver_mock)(activities, targets, rng)
    limit = cache.get_size()

    # Ensure differing time stamps (depending on the file system the timestamp
    # resolution might be as bad as 1 day).
    for filename in os.listdir(cache.cache_dir):
        path = os.path.join(cache.cache_dir, filename)
        timestamp = os.stat(path).st_atime
        timestamp -= 60 * 60 * 24 * 2  # 2 days
        os.utime(path, (timestamp, timestamp))

    cache.wrap_solver(another_solver)(activities, targets, rng)

    assert cache.get_size() > 0

    cache.shrink(limit)

    # check that older cached result was removed
    assert SolverMock.n_calls[solver_mock] == 1
    cache.wrap_solver(another_solver)(activities, targets, rng)
    cache.wrap_solver(solver_mock)(activities, targets, rng)
    assert SolverMock.n_calls[solver_mock] == 2
    assert SolverMock.n_calls[another_solver] == 1
开发者ID:goaaron,项目名称:blouw-etal-2015,代码行数:38,代码来源:test_cache.py


注:本文中的nengo.cache.DecoderCache.shrink方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。