提交 1380aedb authored 作者: Brandon T. Willard's avatar Brandon T. Willard 提交者: Brandon T. Willard

Remove unused aesara.graph.callcache

上级 7d71505d
import logging
import pickle
_logger = logging.getLogger("aesara.graph.callcache")
class CallCache:
def __init__(self, filename=None):
self.filename = filename
try:
if filename is None:
raise OSError("bad filename") # just goes to except
with open(filename) as f:
self.cache = pickle.load(f)
except OSError:
self.cache = {}
def persist(self, filename=None):
"""
Cache "filename" as a pickle file
"""
if filename is None:
filename = self.filename
with open(filename, "w") as f:
pickle.dump(self.cache, f)
def call(self, fn, args=(), key=None):
"""
Retrieve item from the cache(if available)
based on a key
Parameters:
----------
key
parameter to retrieve cache item
fn,args
key to retrieve if "key" is None
"""
if key is None:
key = (fn, tuple(args))
if key not in self.cache:
_logger.debug("cache miss %i", len(self.cache))
self.cache[key] = fn(*args)
else:
_logger.debug("cache hit %i", len(self.cache))
return self.cache[key]
def __del__(self):
try:
if self.filename:
self.persist()
except Exception as e:
_logger.error("persist failed %s %s", self.filename, e)
......@@ -3,7 +3,6 @@ Defines Linkers that deal with C implementations.
"""
import logging
import os
import sys
from collections import defaultdict
from copy import copy
......@@ -21,7 +20,6 @@ from aesara.graph.basic import (
io_toposort,
vars_between,
)
from aesara.graph.callcache import CallCache
from aesara.link.basic import Container, Linker, LocalLinker, PerformLinker
from aesara.link.c.cmodule import (
METH_VARARGS,
......@@ -55,18 +53,6 @@ def get_module_cache(init_args=None):
return _get_module_cache(config.compiledir, init_args=init_args)
_persistent_module_cache = None
def get_persistent_module_cache():
global _persistent_module_cache
if _persistent_module_cache is None:
_persistent_module_cache = CallCache(
os.path.join(config.compiledir, "persistent_cache")
)
return _persistent_module_cache
class CodeBlock:
"""
Represents a computation unit composed of declare, behavior, and cleanup.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论