提交 fae7ce30 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Use defaultdict instead of dict in memodict.

Python 2.4's dict ignores the __missing__ method, but we already had an implementation of defaultdict in Python 2.4 that does.
上级 3df0b3b7
......@@ -14,7 +14,7 @@ from copy import copy
import theano
import warnings
from theano.gof import utils
from theano.gof.python25 import deque
from theano.gof.python25 import any, deque
# Lazy imports to avoid circular dependencies.
is_same_graph_with_merge = None
......
from graph import list_of_nodes
from theano.gof.python25 import any, defaultdict
## {{{ http://code.activestate.com/recipes/578231/ (r1)
def memodict(f):
""" Memoization decorator for a function taking a single argument """
class memodict(dict):
class memodict(defaultdict):
def __missing__(self, key):
ret = self[key] = f(key)
return ret
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论