Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0a01d19a
提交
0a01d19a
authored
3月 30, 2012
作者:
Olivier Delalleau
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #572 from lamblin/fix_alloc_opt
Always introduce Alloc node when calling alloc()
上级
2c9fa876
aa6a4960
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
30 行增加
和
1 行删除
+30
-1
basic.py
theano/tensor/basic.py
+7
-1
opt.py
theano/tensor/opt.py
+1
-0
test_opt.py
theano/tensor/tests/test_opt.py
+22
-0
没有找到文件。
theano/tensor/basic.py
浏览文件 @
0a01d19a
...
@@ -2897,6 +2897,12 @@ class Alloc(gof.Op):
...
@@ -2897,6 +2897,12 @@ class Alloc(gof.Op):
def
__call__
(
self
,
val
,
*
shapes
):
def
__call__
(
self
,
val
,
*
shapes
):
"""
"""
If the alloc would be useless, this function returns val.
If the alloc would be useless, this function returns val.
If this function is called outside of a graph optimization context
(for instance, it is manually called by a user building a graph),
then we always return an Alloc node, to allow for DebugMode to check
for size mismatches.
If you always want an Alloc node, call make_node.
If you always want an Alloc node, call make_node.
"""
"""
ret
=
super
(
Alloc
,
self
)
.
__call__
(
val
,
*
shapes
)
ret
=
super
(
Alloc
,
self
)
.
__call__
(
val
,
*
shapes
)
...
@@ -2904,7 +2910,7 @@ class Alloc(gof.Op):
...
@@ -2904,7 +2910,7 @@ class Alloc(gof.Op):
# It makes optimization difficult when useless allocs are thrown
# It makes optimization difficult when useless allocs are thrown
# into the graph at every stage of optimization. This little logic
# into the graph at every stage of optimization. This little logic
# tries to help at least in some cases.
# tries to help at least in some cases.
if
val
.
type
==
ret
.
type
:
if
hasattr
(
val
,
'env'
)
and
(
val
.
type
==
ret
.
type
)
:
return
val
return
val
except
AttributeError
:
except
AttributeError
:
pass
pass
...
...
theano/tensor/opt.py
浏览文件 @
0a01d19a
...
@@ -1073,6 +1073,7 @@ def local_fill_to_alloc(node):
...
@@ -1073,6 +1073,7 @@ def local_fill_to_alloc(node):
@register_specialize
@register_specialize
@register_stabilize
@register_canonicalize
@register_canonicalize
@gof.local_optimizer
([
T
.
alloc
])
@gof.local_optimizer
([
T
.
alloc
])
def
local_useless_alloc
(
node
):
def
local_useless_alloc
(
node
):
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
0a01d19a
...
@@ -2194,6 +2194,28 @@ def test_local_fill_useless():
...
@@ -2194,6 +2194,28 @@ def test_local_fill_useless():
f
(
m_
,
x_
)
f
(
m_
,
x_
)
class
Test_local_useless_alloc
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
def
test0
(
self
):
x
=
shared
(
self
.
rng
.
randn
(
3
,
7
))
a
=
tensor
.
alloc
(
x
,
6
,
7
)
# It is a bad idea to have tensor.alloc return x directly,
# because the shape mismatch cannot be caught.
assert
a
.
owner
and
isinstance
(
a
.
owner
.
op
,
tensor
.
Alloc
)
f
=
function
([],
a
,
mode
=
mode_opt
)
# The optimization should then be applied, and remove Alloc
assert
([
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
==
[
compile
.
deep_copy_op
])
# In DebugMode, the shape mismatch should be detected
if
isinstance
(
mode_opt
,
compile
.
DebugMode
):
self
.
assertRaises
(
ValueError
,
f
)
class
test_shapeoptimizer
(
unittest
.
TestCase
):
class
test_shapeoptimizer
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
utt
.
seed_rng
()
utt
.
seed_rng
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论