提交 b2570e99 authored 作者: Pierre Luc Carrier's avatar Pierre Luc Carrier 提交者: Pierre Luc Carrier

Update and move Feature accoding to feedback

上级 13056b2f
...@@ -46,7 +46,7 @@ from theano.gof.fg import \ ...@@ -46,7 +46,7 @@ from theano.gof.fg import \
CachedConstantError, InconsistencyError, MissingInputError, FunctionGraph CachedConstantError, InconsistencyError, MissingInputError, FunctionGraph
from theano.gof.destroyhandler import \ from theano.gof.destroyhandler import \
DestroyHandler, NoOutputFromInplace DestroyHandler
from theano.gof.graph import \ from theano.gof.graph import \
Apply, Variable, Constant, view_roots Apply, Variable, Constant, view_roots
...@@ -74,7 +74,7 @@ from theano.gof.optdb import \ ...@@ -74,7 +74,7 @@ from theano.gof.optdb import \
from theano.gof.toolbox import \ from theano.gof.toolbox import \
Feature, \ Feature, \
Bookkeeper, History, Validator, ReplaceValidate, NodeFinder,\ Bookkeeper, History, Validator, ReplaceValidate, NodeFinder,\
PrintListener, ReplacementDidntRemovedError PrintListener, ReplacementDidntRemovedError, NoOutputFromInplace
from theano.gof.type import \ from theano.gof.type import \
Type, Generic, generic Type, Generic, generic
......
...@@ -7,7 +7,6 @@ import toolbox ...@@ -7,7 +7,6 @@ import toolbox
import graph import graph
from theano.gof.python25 import deque from theano.gof.python25 import deque
from theano.gof.python25 import OrderedDict from theano.gof.python25 import OrderedDict
from theano.gof.toolbox import Feature
from theano.misc.ordered_set import OrderedSet from theano.misc.ordered_set import OrderedSet
from fg import InconsistencyError from fg import InconsistencyError
...@@ -1027,23 +1026,3 @@ class DestroyHandler(toolbox.Bookkeeper): ...@@ -1027,23 +1026,3 @@ class DestroyHandler(toolbox.Bookkeeper):
rval[app] = root_clients rval[app] = root_clients
return rval return rval
class NoOutputFromInplace(Feature):
def __init__(self):
pass
def validate(self, fgraph):
if not hasattr(fgraph, 'destroyers'):
return True
for out in list(fgraph.outputs):
# Validate that the node that produces the output does not produce
# it by modifying something else inplace.
node = out.owner
op = node.op
out_idx = node.outputs.index(out)
if hasattr(op, 'destroy_map') and out_idx in op.destroy_map.keys():
raise InconsistencyError(
"Trying to produce an output ", out,
" by modifying another variable inplace")
import sys import sys
import time import time
import theano
from theano import config from theano import config
from theano.gof.python25 import partial from theano.gof.python25 import partial
from theano.gof.python25 import OrderedDict from theano.gof.python25 import OrderedDict
...@@ -394,3 +395,26 @@ class PreserveNames(Feature): ...@@ -394,3 +395,26 @@ class PreserveNames(Feature):
new_r.name = r.name new_r.name = r.name
class NoOutputFromInplace(Feature):
def validate(self, fgraph):
if not hasattr(fgraph, 'destroyers'):
return True
for out in list(fgraph.outputs):
if out.owner is None:
continue
# Validate that the node that produces the output does not produce
# it by modifying something else inplace.
node = out.owner
op = node.op
out_idx = node.outputs.index(out)
if hasattr(op, 'destroy_map') and out_idx in op.destroy_map.keys():
raise theano.gof.InconsistencyError(
"A function graph Feature has requested (probably for ",
"efficiency reasons for scan) that outputs of the graph",
"be prevented from being the result of inplace ",
"operations. This has prevented output ", out, " from ",
"being the computed by modifying another variable ",
"inplace.")
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论