Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
28e9f9fe
提交
28e9f9fe
authored
8月 21, 2012
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ENH: Feature base class in gof.fg
上级
5a523b34
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
50 行增加
和
35 行删除
+50
-35
fg.py
theano/gof/fg.py
+50
-35
没有找到文件。
theano/gof/fg.py
浏览文件 @
28e9f9fe
...
@@ -19,6 +19,7 @@ class InconsistencyError(Exception):
...
@@ -19,6 +19,7 @@ class InconsistencyError(Exception):
"""
"""
pass
pass
class
MissingInputError
(
Exception
):
class
MissingInputError
(
Exception
):
"""
"""
A symbolic input needed to compute the outputs is missing.
A symbolic input needed to compute the outputs is missing.
...
@@ -26,66 +27,80 @@ class MissingInputError(Exception):
...
@@ -26,66 +27,80 @@ class MissingInputError(Exception):
pass
pass
class
Feature
(
object
):
"""
Base class for FunctionGraph extensions.
class
FunctionGraph
(
utils
.
object2
):
See toolbox and ext modules for common extensions.
""" WRITEME
"""
A FunctionGraph represents a subgraph bound by a set of input variables and a
set of output variables, ie a subgraph that specifies a theano function.
The inputs list should contain all the inputs
on which the outputs depend. Variables of type Constant are
not counted as inputs.
The FunctionGraph supports the replace operation which allows to replace a
variable in the subgraph by another, e.g. replace (x + x).out by (2
* x).out. This is the basis for optimization in theano.
This class is also reponsible for verifying that a graph is valid
(ie, all the dtypes and broadcast patterns are compatible with the
way the the Variables are used) and for annotating the Variables with
a .clients field that specifies which Apply nodes use the variable.
The .clients field combined with the .owner field and the Apply nodes'
.inputs field allows the graph to be traversed in both directions.
It can also be "extended" using function_graph.extend(some_object). See the
toolbox and ext modules for common extensions.
Features added with the`extend` function can handle the following events:
- feature.on_attach(function_graph)
def
on_attach
(
self
,
function_graph
):
"""
Called by extend. The feature has great freedom in what
Called by extend. The feature has great freedom in what
it can do with the function_graph: it may, for example, add methods
it can do with the function_graph: it may, for example, add methods
to it dynamically.
to it dynamically.
"""
- feature.on_detach(function_graph)
def
on_detach
(
self
,
function_graph
):
"""
Called by remove_feature(feature). Should remove any dynamically-added
Called by remove_feature(feature). Should remove any dynamically-added
functionality that it installed into the function_graph.
functionality that it installed into the function_graph.
"""
- feature.on_import(function_graph, node)*
def
on_import
(
self
,
function_graph
,
node
):
"""
Called whenever a node is imported into function_graph, which is
Called whenever a node is imported into function_graph, which is
just before the node is actually connected to the graph.
just before the node is actually connected to the graph.
"""
- feature.on_prune(function_graph, node)*
def
on_prune
(
self
,
function_graph
,
node
):
"""
Called whenever a node is pruned (removed) from the function_graph,
Called whenever a node is pruned (removed) from the function_graph,
after it is disconnected from the graph.
after it is disconnected from the graph.
"""
- feature.on_change_input(function_graph, node, i, r, new_r, [reason=None])*
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.
Called whenever node.inputs[i] is changed from r to new_r.
At the moment the callback is done, the change has already
At the moment the callback is done, the change has already
taken place.
taken place.
- feature.orderings(function_graph)
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
Called by toposort. It should return a dictionary of
{node: predecessors} where predecessors is a list of
{node: predecessors} where predecessors is a list of
nodes that should be computed before the key node.
nodes that should be computed before the key node.
* If you raise an exception in the functions marked with an
If you raise an exception in this function, the state of the graph
asterisk, the state of the graph might be inconsistent.
might be broken for all intents and purposes.
"""
- feature.on_setup_node(function_graph, node):
class
FunctionGraph
(
utils
.
object2
):
WRITEME
""" WRITEME
A FunctionGraph represents a subgraph bound by a set of input variables and a
set of output variables, ie a subgraph that specifies a theano function.
The inputs list should contain all the inputs
on which the outputs depend. Variables of type Constant are
not counted as inputs.
The FunctionGraph supports the replace operation which allows to replace a
variable in the subgraph by another, e.g. replace (x + x).out by (2
* x).out. This is the basis for optimization in theano.
This class is also reponsible for verifying that a graph is valid
(ie, all the dtypes and broadcast patterns are compatible with the
way the the Variables are used) and for annotating the Variables with
a .clients field that specifies which Apply nodes use the variable.
The .clients field combined with the .owner field and the Apply nodes'
.inputs field allows the graph to be traversed in both directions.
- feature.on_setup_variable(function_graph, variable):
It can also be "extended" using function_graph.extend(some_object).
WRITEME
See Feature above 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.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论