提交 7ccbc028 authored 作者: Ian Goodfellow's avatar Ian Goodfellow

use isinstance(foo, python25.OrderedDict) instead of 'Ordered' in

str(type(foo))
上级 5d8ae96e
...@@ -13,6 +13,7 @@ from profiling import ProfileStats ...@@ -13,6 +13,7 @@ from profiling import ProfileStats
from pfunc import pfunc from pfunc import pfunc
from numpy import any # to work in python 2.4 from numpy import any # to work in python 2.4
import warnings import warnings
from theano import gof
def function(inputs, outputs=None, mode=None, updates=None, givens=None, def function(inputs, outputs=None, mode=None, updates=None, givens=None,
no_default_updates=False, accept_inplace=False, name=None, no_default_updates=False, accept_inplace=False, name=None,
...@@ -163,9 +164,8 @@ def function(inputs, outputs=None, mode=None, updates=None, givens=None, ...@@ -163,9 +164,8 @@ def function(inputs, outputs=None, mode=None, updates=None, givens=None,
if updates is None: if updates is None:
updates = [] updates = []
# I use the string value of the type to do type checking here since if isinstance(updates, dict) and \
# OrderedDict is not available in python2.4 not isinstance(updates, gof.python25.OrderedDict):
if isinstance(updates, dict) and 'Ordered' not in str(type(updates)):
warnings.warn("Expected OrderedDict, got "+str(type(updates))+ "Using " warnings.warn("Expected OrderedDict, got "+str(type(updates))+ "Using "
"a standard dictionary here results in " "a standard dictionary here results in "
"non-deterministic behavior. You should use an OrderedDict" "non-deterministic behavior. You should use an OrderedDict"
......
...@@ -13,6 +13,7 @@ __contact__ = "Razvan Pascanu <r.pascanu@gmail>" ...@@ -13,6 +13,7 @@ __contact__ = "Razvan Pascanu <r.pascanu@gmail>"
import itertools import itertools
import logging import logging
import numpy import numpy
import warnings
from theano.compile import SharedVariable, function from theano.compile import SharedVariable, function
from theano import compile from theano import compile
...@@ -468,8 +469,10 @@ def scan(fn, ...@@ -468,8 +469,10 @@ def scan(fn,
dummy_outs.append(condition) dummy_outs.append(condition)
# If we use a regular dict here, the results are non-deterministic # If we use a regular dict here, the results are non-deterministic
assert isinstance(updates, (list, tuple)) or (isinstance(updates, dict) and \ if not isinstance(updates, (list, tuple)):
'Ordered' in str(type(updates))) if isinstance(updates, dict) and \
not isinstance(updates, gof.python25.OrderedDict):
warnings.warn("Using non-deterministic dictionary.")
dummy_f = function(dummy_args, dummy_f = function(dummy_args,
dummy_outs, dummy_outs,
......
...@@ -18,6 +18,7 @@ import logging ...@@ -18,6 +18,7 @@ import logging
from itertools import izip from itertools import izip
import numpy import numpy
import warnings
import theano import theano
from theano.compile.pfunc import rebuild_collect_shared from theano.compile.pfunc import rebuild_collect_shared
...@@ -203,9 +204,10 @@ def get_updates_and_outputs(ls): ...@@ -203,9 +204,10 @@ def get_updates_and_outputs(ls):
def is_updates(elem): def is_updates(elem):
if isinstance(elem, dict): if isinstance(elem, dict):
# Make sure the updates will be applied in a deterministic order # Make sure the updates will be applied in a deterministic order
if 'Ordered' not in str(type(elem)): if not isinstance(elem, gof.python25.OrderedDict):
raise TypeError("Expected OrderedDict or OrderedUpdates, got "\ warnings.warn("Expected OrderedDict or OrderedUpdates, got "\
+str(type(elem))) +str(type(elem))+". This can make your script non-"
"deterministic.")
return True return True
# Dictionaries can be given as lists of tuples # Dictionaries can be given as lists of tuples
if (isinstance(elem, (list, tuple)) and if (isinstance(elem, (list, tuple)) and
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论