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

made Apply and Variable into subclasses of Node

上级 75e65054
......@@ -160,13 +160,12 @@ def _contains_cycle(inputs, outputs, orderings):
fifo_queue.append(node)
node_to_parents[node] = parents
rset = set()
rlist = []
visit_count = 0
while fifo_queue:
node = fifo_queue.popleft()
if node not in rset:
rlist.append(node)
visit_count += 1
rset.add(node)
for client in node_to_children.get(node, []):
node_to_parents[client] = [a for a in node_to_parents[client] if a is not node]
......@@ -174,7 +173,7 @@ def _contains_cycle(inputs, outputs, orderings):
fifo_queue.append(client)
return len(rlist) != len(node_to_parents.keys())
return visit_count != len(node_to_parents.keys())
......
......@@ -21,7 +21,25 @@ is_same_graph_with_merge = None
equal_computations = None
class Apply(utils.object2):
class Node(utils.object2):
"""A Node in a theano graph.
Graphs contain two kinds of Nodes--
Variable and Apply.
Edges in the graph are not explicitly represented.
Instead each Node keeps track of its parents via
Variable.owner / Apply.inputs and its children
via Variable.clients / Apply.outputs.
"""
def get_parents(self):
""" Return a list of the parents of this node.
Should return a copy--i.e., modifying the return
value should not modify the graph structure."""
raise NotImplementedError()
class Apply(Node):
"""
An :term:`Apply` instance is a node in an expression graph which represents the application
of an `Op` to some input `Variable` nodes, producing some output `Variable` nodes.
......@@ -213,7 +231,7 @@ class Apply(utils.object2):
"""property: Number of outputs"""
class Variable(utils.object2):
class Variable(Node):
"""
A :term:`Variable` is a node in an expression graph that represents a variable.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论