Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3c052bff
提交
3c052bff
authored
8月 21, 2012
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FIX: remove circular dependency in gof import
上级
28e9f9fe
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
63 行增加
和
59 行删除
+63
-59
__init__.py
theano/gof/__init__.py
+1
-0
fg.py
theano/gof/fg.py
+1
-54
toolbox.py
theano/gof/toolbox.py
+61
-5
没有找到文件。
theano/gof/__init__.py
浏览文件 @
3c052bff
...
@@ -70,6 +70,7 @@ from optdb import \
...
@@ -70,6 +70,7 @@ from optdb import \
EquilibriumDB
,
SequenceDB
,
ProxyDB
EquilibriumDB
,
SequenceDB
,
ProxyDB
from
toolbox
import
\
from
toolbox
import
\
Feature
,
\
Bookkeeper
,
History
,
Validator
,
ReplaceValidate
,
NodeFinder
,
\
Bookkeeper
,
History
,
Validator
,
ReplaceValidate
,
NodeFinder
,
\
PrintListener
,
ReplacementDidntRemovedError
PrintListener
,
ReplacementDidntRemovedError
...
...
theano/gof/fg.py
浏览文件 @
3c052bff
...
@@ -27,59 +27,6 @@ class MissingInputError(Exception):
...
@@ -27,59 +27,6 @@ class MissingInputError(Exception):
pass
pass
class
Feature
(
object
):
"""
Base class for FunctionGraph extensions.
See toolbox and ext modules for common extensions.
"""
def
on_attach
(
self
,
function_graph
):
"""
Called by extend. The feature has great freedom in what
it can do with the function_graph: it may, for example, add methods
to it dynamically.
"""
def
on_detach
(
self
,
function_graph
):
"""
Called by remove_feature(feature). Should remove any dynamically-added
functionality that it installed into the function_graph.
"""
def
on_import
(
self
,
function_graph
,
node
):
"""
Called whenever a node is imported into function_graph, which is
just before the node is actually connected to the graph.
"""
def
on_prune
(
self
,
function_graph
,
node
):
"""
Called whenever a node is pruned (removed) from the function_graph,
after it is disconnected from the graph.
"""
def
on_change_input
(
self
,
function_graph
,
node
,
i
,
r
,
new_r
,
reason
=
None
):
"""
Called whenever node.inputs[i] is changed from r to new_r.
At the moment the callback is done, the change has already
taken place.
If you raise an exception in this function, the state of the graph
might be broken for all intents and purposes.
"""
def
orderings
(
self
,
function_graph
):
"""
Called by toposort. It should return a dictionary of
{node: predecessors} where predecessors is a list of
nodes that should be computed before the key node.
If you raise an exception in this function, the state of the graph
might be broken for all intents and purposes.
"""
class
FunctionGraph
(
utils
.
object2
):
class
FunctionGraph
(
utils
.
object2
):
""" WRITEME
""" WRITEME
A FunctionGraph represents a subgraph bound by a set of input variables and a
A FunctionGraph represents a subgraph bound by a set of input variables and a
...
@@ -100,7 +47,7 @@ class FunctionGraph(utils.object2):
...
@@ -100,7 +47,7 @@ class FunctionGraph(utils.object2):
.inputs field allows the graph to be traversed in both directions.
.inputs field allows the graph to be traversed in both directions.
It can also be "extended" using function_graph.extend(some_object).
It can also be "extended" using function_graph.extend(some_object).
See
Feature abov
e for event types and documentation.
See
toolbox.Featur
e for event types and documentation.
Historically, the FunctionGraph was called an Env. Keep this in mind
Historically, the FunctionGraph was called an Env. Keep this in mind
while reading out-of-date documentation, e-mail support threads, etc.
while reading out-of-date documentation, e-mail support threads, etc.
...
...
theano/gof/toolbox.py
浏览文件 @
3c052bff
...
@@ -19,7 +19,61 @@ class ReplacementDidntRemovedError(Exception):
...
@@ -19,7 +19,61 @@ class ReplacementDidntRemovedError(Exception):
pass
pass
class
Bookkeeper
:
class
Feature
(
object
):
"""
Base class for FunctionGraph extensions.
See toolbox and ext modules for common extensions.
"""
def
on_attach
(
self
,
function_graph
):
"""
Called by extend. The feature has great freedom in what
it can do with the function_graph: it may, for example, add methods
to it dynamically.
"""
def
on_detach
(
self
,
function_graph
):
"""
Called by remove_feature(feature). Should remove any dynamically-added
functionality that it installed into the function_graph.
"""
def
on_import
(
self
,
function_graph
,
node
):
"""
Called whenever a node is imported into function_graph, which is
just before the node is actually connected to the graph.
"""
def
on_prune
(
self
,
function_graph
,
node
):
"""
Called whenever a node is pruned (removed) from the function_graph,
after it is disconnected from the graph.
"""
def
on_change_input
(
self
,
function_graph
,
node
,
i
,
r
,
new_r
,
reason
=
None
):
"""
Called whenever node.inputs[i] is changed from r to new_r.
At the moment the callback is done, the change has already
taken place.
If you raise an exception in this function, the state of the graph
might be broken for all intents and purposes.
"""
def
orderings
(
self
,
function_graph
):
"""
Called by toposort. It should return a dictionary of
{node: predecessors} where predecessors is a list of
nodes that should be computed before the key node.
If you raise an exception in this function, the state of the graph
might be broken for all intents and purposes.
"""
return
{}
class
Bookkeeper
(
Feature
):
def
on_attach
(
self
,
fgraph
):
def
on_attach
(
self
,
fgraph
):
for
node
in
graph
.
io_toposort
(
fgraph
.
inputs
,
fgraph
.
outputs
):
for
node
in
graph
.
io_toposort
(
fgraph
.
inputs
,
fgraph
.
outputs
):
...
@@ -30,7 +84,7 @@ class Bookkeeper:
...
@@ -30,7 +84,7 @@ class Bookkeeper:
self
.
on_prune
(
fgraph
,
node
)
self
.
on_prune
(
fgraph
,
node
)
class
History
:
class
History
(
Feature
)
:
def
__init__
(
self
):
def
__init__
(
self
):
self
.
history
=
{}
self
.
history
=
{}
...
@@ -69,7 +123,7 @@ class History:
...
@@ -69,7 +123,7 @@ class History:
self
.
history
[
fgraph
]
=
h
self
.
history
[
fgraph
]
=
h
class
Validator
:
class
Validator
(
Feature
)
:
def
on_attach
(
self
,
fgraph
):
def
on_attach
(
self
,
fgraph
):
for
attr
in
(
'validate'
,
'validate_time'
):
for
attr
in
(
'validate'
,
'validate_time'
):
...
@@ -224,7 +278,7 @@ class NodeFinder(dict, Bookkeeper):
...
@@ -224,7 +278,7 @@ class NodeFinder(dict, Bookkeeper):
return
all
return
all
class
PrintListener
(
object
):
class
PrintListener
(
Feature
):
def
__init__
(
self
,
active
=
True
):
def
__init__
(
self
,
active
=
True
):
self
.
active
=
active
self
.
active
=
active
...
@@ -251,7 +305,9 @@ class PrintListener(object):
...
@@ -251,7 +305,9 @@ class PrintListener(object):
node
,
i
,
r
,
new_r
)
node
,
i
,
r
,
new_r
)
class
PreserveNames
:
class
PreserveNames
(
Feature
)
:
def
on_change_input
(
self
,
fgraph
,
mode
,
i
,
r
,
new_r
,
reason
=
None
):
def
on_change_input
(
self
,
fgraph
,
mode
,
i
,
r
,
new_r
,
reason
=
None
):
if
r
.
name
is
not
None
and
new_r
.
name
is
None
:
if
r
.
name
is
not
None
and
new_r
.
name
is
None
:
new_r
.
name
=
r
.
name
new_r
.
name
=
r
.
name
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论