提交 147a7155 authored 作者: nouiz's avatar nouiz

Merge pull request #976 from lamblin/py24

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