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