Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
def02f4d
提交
def02f4d
authored
6月 10, 2009
作者:
Olivier Delalleau
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Partial merge - I messed up a bit with mercurial
上级
d721ac6b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
43 行增加
和
9 行删除
+43
-9
destroyhandler.py
theano/gof/destroyhandler.py
+34
-3
test_misc.py
theano/tensor/tests/test_misc.py
+9
-6
没有找到文件。
theano/gof/destroyhandler.py
浏览文件 @
def02f4d
...
@@ -68,7 +68,38 @@ def get_impact(root, view_o):
...
@@ -68,7 +68,38 @@ def get_impact(root, view_o):
return
impact
return
impact
class
DestroyHandlerHelper2
(
toolbox
.
Bookkeeper
):
class
DestroyHandlerHelper2
(
toolbox
.
Bookkeeper
):
"""WRITEME"""
"""
The DestroyHandlerHelper2 class detects when a graph is impossible to evaluate because of
aliasing and destructive operations.
Several data structures are used to do this.
When an Op uses its view_map property to declare that an output may be aliased
to an input, then if that output is destroyed, the input is also considering to be
destroyed. The view_maps of several Ops can feed into one another and form a directed graph.
The consequence of destroying any variable in such a graph is that all variables in the graph
must be considered to be destroyed, because they could all be refering to the same
underlying storage. In the current implementation, that graph is a tree, and the root of
that tree is called the foundation. The `droot` property of this class maps from every
graph variable to its foundation. The `impact` property maps backward from the foundation
to all of the variables that depend on it. When any variable is destroyed, this class marks
the foundation of that variable as being destroyed, with the `root_destroyer` property.
"""
droot
=
{}
"""
destroyed view + nonview variables -> foundation
"""
impact
=
{}
"""
destroyed nonview variable -> it + all views of it
"""
root_destroyer
=
{}
"""
root -> destroyer apply
"""
def
__init__
(
self
,
do_imports_on_attach
=
True
):
def
__init__
(
self
,
do_imports_on_attach
=
True
):
self
.
env
=
None
self
.
env
=
None
...
@@ -94,8 +125,8 @@ class DestroyHandlerHelper2(toolbox.Bookkeeper):
...
@@ -94,8 +125,8 @@ class DestroyHandlerHelper2(toolbox.Bookkeeper):
self
.
env
=
env
self
.
env
=
env
self
.
destroyers
=
set
()
#set of Apply instances with non-null destroy_map
self
.
destroyers
=
set
()
#set of Apply instances with non-null destroy_map
self
.
view_i
=
{}
# variable -> variable
self
.
view_i
=
{}
# variable -> variable
used in calculation
self
.
view_o
=
{}
# variable -> set of variables
self
.
view_o
=
{}
# variable -> set of variables
that use this one as a direct input
#clients: how many times does an apply use a given variable
#clients: how many times does an apply use a given variable
self
.
clients
=
{}
# variable -> apply -> ninputs
self
.
clients
=
{}
# variable -> apply -> ninputs
self
.
stale_droot
=
True
self
.
stale_droot
=
True
...
...
theano/tensor/tests/test_misc.py
浏览文件 @
def02f4d
# This bug is detailed in ticket #387. Please close this ticket once the test
import
sys
# passes (http://pylearn.org/theano/trac/ticket/387).
import
numpy
,
theano
import
numpy
,
theano
from
theano
import
tensor
from
theano
import
tensor
def
test_bug_2009_06_02_trac_387
():
def
test_bug_2009_06_02_trac_387
():
y
=
tensor
.
lvector
()
y
=
tensor
.
lvector
(
'y'
)
f
=
theano
.
function
([
y
],
tensor
.
stack
(
y
[
0
]
/
2
))
#f = theano.function([y], tensor.stack(y[0] / 2))
#f = theano.function([y], tensor.join(0,tensor.shape_padleft(y[0] / 2,1)))
f
=
theano
.
function
([
y
],
tensor
.
int_div
(
tensor
.
DimShuffle
(
y
[
0
]
.
broadcastable
,
[
'x'
])(
y
[
0
]),
2
))
sys
.
stdout
.
flush
()
print
f
(
numpy
.
ones
(
1
)
*
3
)
#z = tensor.lscalar('z')
#f = theano.function([z], tensor.DimShuffle([], ['x'])(z) / 2)
print
f
(
numpy
.
ones
(
1
)
*
2
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论