提交 fb14fa28 authored 作者: Ian Goodfellow's avatar Ian Goodfellow

whitelist all generators

上级 b9b082e4
......@@ -577,13 +577,13 @@ if 0:
# OPT: pre-compute this on import
tolerate_same = getattr(app.op, 'destroyhandler_tolerate_same', [])
assert isinstance(tolerate_same, list)
tolerated = OrderedSet((idx1 for idx0, idx1 in tolerate_same
if idx0 == destroyed_idx), known_deterministic=True)
tolerated = OrderedSet(idx1 for idx0, idx1 in tolerate_same
if idx0 == destroyed_idx)
tolerated.add(destroyed_idx)
tolerate_aliased = getattr(app.op, 'destroyhandler_tolerate_aliased', [])
assert isinstance(tolerate_aliased, list)
ignored = OrderedSet((idx1 for idx0, idx1 in tolerate_aliased
if idx0 == destroyed_idx), known_deterministic=True)
ignored = OrderedSet(idx1 for idx0, idx1 in tolerate_aliased
if idx0 == destroyed_idx)
#print 'tolerated', tolerated
#print 'ignored', ignored
for i, input in enumerate(app.inputs):
......@@ -961,13 +961,13 @@ class DestroyHandler(toolbox.Bookkeeper):
# OPT: pre-compute this on import
tolerate_same = getattr(app.op, 'destroyhandler_tolerate_same', [])
assert isinstance(tolerate_same, list)
tolerated = OrderedSet((idx1 for idx0, idx1 in tolerate_same
if idx0 == destroyed_idx), known_deterministic=True)
tolerated = OrderedSet(idx1 for idx0, idx1 in tolerate_same
if idx0 == destroyed_idx)
tolerated.add(destroyed_idx)
tolerate_aliased = getattr(app.op, 'destroyhandler_tolerate_aliased', [])
assert isinstance(tolerate_aliased, list)
ignored = OrderedSet((idx1 for idx0, idx1 in tolerate_aliased
if idx0 == destroyed_idx), known_deterministic=True)
ignored = OrderedSet(idx1 for idx0, idx1 in tolerate_aliased
if idx0 == destroyed_idx)
#print 'tolerated', tolerated
#print 'ignored', ignored
for i, input in enumerate(app.inputs):
......
......@@ -7,7 +7,7 @@ except ImportError:
from theano.gof.python25 import OrderedDict
import types
def check_deterministic(iterable, known_deterministic):
def check_deterministic(iterable):
# Most places where OrderedSet is used, theano interprets any exception
# whatsoever as a problem that an optimization introduced into the graph.
# If I raise a TypeError when the DestoryHandler tries to do something
......@@ -16,8 +16,6 @@ def check_deterministic(iterable, known_deterministic):
# theano to use exceptions correctly, so that this can be a TypeError.
if iterable is not None:
assert isinstance(iterable, (list, tuple, OrderedSet, types.GeneratorType))
if isinstance(iterable, types.GeneratorType):
assert known_deterministic
if MutableSet is not None:
# From http://code.activestate.com/recipes/576694/
......@@ -47,13 +45,13 @@ if MutableSet is not None:
# Added by IG-- pre-existing theano code expected sets
# to have this method
def update(self, iterable, known_deterministic = False):
check_deterministic(iterable, known_deterministic)
def update(self, iterable):
check_deterministic(iterable)
self |= iterable
def __init__(self, iterable=None, known_deterministic=False):
def __init__(self, iterable=None):
# Checks added by IG
check_deterministic(iterable, known_deterministic)
check_deterministic(iterable)
self.end = end = []
end += [None, end, end] # sentinel node for doubly linked list
self.map = {} # key --> [key, prev, next]
......@@ -121,13 +119,13 @@ else:
An implementation of OrderedSet based on the keys of
an OrderedDict.
"""
def __init__(self, iterable=None, known_deterministic=False):
def __init__(self, iterable=None):
self.data = OrderedDict()
if iterable is not None:
self.update(iterable, known_deterministic)
self.update(iterable)
def update(self, container, known_deterministic=False):
check_deterministic(container, known_deterministic)
def update(self, container):
check_deterministic(container)
for elem in container:
self.add(elem)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论