Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4b8b01c6
提交
4b8b01c6
authored
9月 17, 2012
作者:
Matthew Rocklin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove new_io_toposort from active code.
Add docstrings Remove dependence function by default. Can now sort by anything. Does not respect dependence by default.
上级
479614ec
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
21 行增加
和
11 行删除
+21
-11
fg.py
theano/gof/fg.py
+1
-6
graph.py
theano/gof/graph.py
+20
-5
没有找到文件。
theano/gof/fg.py
浏览文件 @
4b8b01c6
...
...
@@ -554,14 +554,9 @@ class FunctionGraph(utils.object2):
return
list
(
self
.
apply_nodes
)
fg
=
self
# TODO - This is a hack.
# Should change deeper in to just move around functions
ords
=
self
.
orderings
()
ords
=
[
lambda
a
,
b
:
(
1
if
b
in
d
.
get
(
a
,
())
else
-
1
if
a
in
d
.
get
(
b
,
())
else
0
)
for
d
in
ords
]
order
=
graph
.
new_
io_toposort
(
fg
.
inputs
,
fg
.
outputs
,
ords
)
order
=
graph
.
io_toposort
(
fg
.
inputs
,
fg
.
outputs
,
ords
)
return
order
def
orderings
(
self
):
...
...
theano/gof/graph.py
浏览文件 @
4b8b01c6
...
...
@@ -1028,7 +1028,6 @@ def memodict(f):
return
memodict
()
.
__getitem__
## end of http://code.activestate.com/recipes/578231/ }}}
@memodict
def
depends
((
a
,
b
)):
return
(
not
set
(
a
.
inputs
)
.
isdisjoint
(
set
(
b
.
outputs
))
...
...
@@ -1046,11 +1045,27 @@ def dependence(a, b):
if
depends
((
b
,
a
)):
return
-
1
return
0
def
new_io_toposort
(
inputs
,
outputs
,
cmps
=
[]):
""" Same as io_toposort """
cmps
=
[
dependence
]
+
cmps
# enforce that dependence is the strongest cmp fn
def
sort_apply_nodes
(
inputs
,
outputs
,
cmps
):
""" Order a graph of apply nodes according to a list of comparators
The following example sorts first by dependence of nodes (this is a
topological sort) and then by lexicographical ordering (nodes that start
with 'E' come before nodes that start with 'I' if there is no dependence.
>>> from theano.gof.graph import sort_apply_nodes, dependence
>>> from theano.tensor import matrix, dot
>>> x = matrix('x')
>>> y = dot(x*2, x+1)
>>> str_cmp = lambda a, b: cmp(str(a), str(b)) # lexicographical sort
>>> sort_apply_nodes([x], [y], cmps=[dependence, str_cmp])
[Elemwise{add,no_inplace}(x, InplaceDimShuffle{x,x}.0),
InplaceDimShuffle{x,x}(TensorConstant{2}),
Elemwise{mul,no_inplace}(x, InplaceDimShuffle{x,x}.0),
InplaceDimShuffle{x,x}(TensorConstant{1}),
dot(Elemwise{mul,no_inplace}.0, Elemwise{add,no_inplace}.0)]
"""
# An aggregate comparator - looks at each cmp in order
# An aggregate comparator - looks at each cmp
function
in order
def
cmp
(
a
,
b
,
fns
=
cmps
):
if
not
fns
:
return
0
head
,
tail
=
fns
[
0
],
fns
[
1
:]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论