提交 def02f4d authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Partial merge - I messed up a bit with mercurial

上级 d721ac6b
......@@ -68,7 +68,38 @@ def get_impact(root, view_o):
return impact
class DestroyHandlerHelper2(toolbox.Bookkeeper):
"""WRITEME"""
"""
The DestroyHandlerHelper2 class detects when a graph is impossible to evaluate because of
aliasing and destructive operations.
Several data structures are used to do this.
When an Op uses its view_map property to declare that an output may be aliased
to an input, then if that output is destroyed, the input is also considering to be
destroyed. The view_maps of several Ops can feed into one another and form a directed graph.
The consequence of destroying any variable in such a graph is that all variables in the graph
must be considered to be destroyed, because they could all be refering to the same
underlying storage. In the current implementation, that graph is a tree, and the root of
that tree is called the foundation. The `droot` property of this class maps from every
graph variable to its foundation. The `impact` property maps backward from the foundation
to all of the variables that depend on it. When any variable is destroyed, this class marks
the foundation of that variable as being destroyed, with the `root_destroyer` property.
"""
droot = {}
"""
destroyed view + nonview variables -> foundation
"""
impact = {}
"""
destroyed nonview variable -> it + all views of it
"""
root_destroyer = {}
"""
root -> destroyer apply
"""
def __init__(self, do_imports_on_attach=True):
self.env = None
......@@ -94,8 +125,8 @@ class DestroyHandlerHelper2(toolbox.Bookkeeper):
self.env = env
self.destroyers = set() #set of Apply instances with non-null destroy_map
self.view_i = {} # variable -> variable
self.view_o = {} # variable -> set of variables
self.view_i = {} # variable -> variable used in calculation
self.view_o = {} # variable -> set of variables that use this one as a direct input
#clients: how many times does an apply use a given variable
self.clients = {} # variable -> apply -> ninputs
self.stale_droot = True
......
# This bug is detailed in ticket #387. Please close this ticket once the test
# passes (http://pylearn.org/theano/trac/ticket/387).
import sys
import numpy, theano
from theano import tensor
def test_bug_2009_06_02_trac_387():
y = tensor.lvector()
f = theano.function([y], tensor.stack(y[0] / 2))
y = tensor.lvector('y')
#f = theano.function([y], tensor.stack(y[0] / 2))
#f = theano.function([y], tensor.join(0,tensor.shape_padleft(y[0] / 2,1)))
f = theano.function([y], tensor.int_div(tensor.DimShuffle(y[0].broadcastable, ['x'])(y[0]), 2))
sys.stdout.flush()
print f(numpy.ones(1) * 3)
#z = tensor.lscalar('z')
#f = theano.function([z], tensor.DimShuffle([], ['x'])(z) / 2)
print f(numpy.ones(1) * 2)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论