Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d1461eb1
提交
d1461eb1
authored
9月 16, 2012
作者:
Ian Goodfellow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
doc
上级
2e2081fc
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
29 行增加
和
13 行删除
+29
-13
fg.py
theano/gof/fg.py
+14
-6
toolbox.py
theano/gof/toolbox.py
+15
-7
没有找到文件。
theano/gof/fg.py
浏览文件 @
d1461eb1
...
@@ -449,21 +449,29 @@ class FunctionGraph(utils.object2):
...
@@ -449,21 +449,29 @@ class FunctionGraph(utils.object2):
Adds a gof.toolbox.Feature to this function_graph
Adds a gof.toolbox.Feature to this function_graph
and triggers its on_attach callback
and triggers its on_attach callback
"""
"""
# Filter out literally identical features
if
feature
in
self
.
_features
:
if
feature
in
self
.
_features
:
return
# the feature is already present
return
# the feature is already present
#it would be nice if we could require a specific class instead of
# Filter out functionally identical features.
#a "workalike" so we could do actual error checking
# Features may use their on_attach method to raise
#if not isinstance(feature, toolbox.Feature):
# toolbox.AlreadyThere if they detect that some
# raise TypeError("Expected gof.toolbox.Feature instance, got "+\
# installed feature does the same thing already
# str(type(feature)))
attach
=
getattr
(
feature
,
'on_attach'
,
None
)
attach
=
getattr
(
feature
,
'on_attach'
,
None
)
if
attach
is
not
None
:
if
attach
is
not
None
:
try
:
try
:
attach
(
self
)
attach
(
self
)
except
toolbox
.
AlreadyThere
:
except
toolbox
.
AlreadyThere
:
return
return
#it would be nice if we could require a specific class instead of
#a "workalike" so we could do actual error checking
#if not isinstance(feature, toolbox.Feature):
# raise TypeError("Expected gof.toolbox.Feature instance, got "+\
# str(type(feature)))
# Add the feature
self
.
_features
.
append
(
feature
)
self
.
_features
.
append
(
feature
)
def
remove_feature
(
self
,
feature
):
def
remove_feature
(
self
,
feature
):
...
...
theano/gof/toolbox.py
浏览文件 @
d1461eb1
...
@@ -7,6 +7,9 @@ import graph
...
@@ -7,6 +7,9 @@ import graph
class
AlreadyThere
(
Exception
):
class
AlreadyThere
(
Exception
):
"""Raised by a Feature's on_attach callback method if the FunctionGraph
attempting to attach the feature already has a functionally identical
feature."""
pass
pass
...
@@ -32,13 +35,18 @@ class Feature(object):
...
@@ -32,13 +35,18 @@ class Feature(object):
def
on_attach
(
self
,
function_graph
):
def
on_attach
(
self
,
function_graph
):
"""
"""
Called by FunctionGraph.attach_feature, the method that attaches the feature
Called by FunctionGraph.attach_feature, the method that attaches
to the FunctionGraph. Since this is called after the FunctionGraph
the feature to the FunctionGraph. Since this is called after the
is initially populated, this is where you should run checks on the
FunctionGraph is initially populated, this is where you should
initial contents of the FunctionGraph.
run checks on the initial contents of the FunctionGraph.
The feature has great freedom in what
it can do with the function_graph: it may, for example, add methods
The on_attach method may raise the AlreadyThere exception to cancel
to it dynamically.
the attach operation if it detects that another Feature instance
implementing the same functionality is already atttached to the
FunctionGraph.
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
):
def
on_detach
(
self
,
function_graph
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论