Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3b0f4cdb
提交
3b0f4cdb
authored
7月 14, 2015
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make local_merge_alloc apply in more case
上级
36d1eca8
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
22 行增加
和
2 行删除
+22
-2
opt.py
theano/tensor/opt.py
+5
-1
test_opt.py
theano/tensor/tests/test_opt.py
+17
-1
没有找到文件。
theano/tensor/opt.py
浏览文件 @
3b0f4cdb
...
...
@@ -5897,6 +5897,7 @@ def local_merge_alloc(node):
# This opt takes care of several cases:
# Alloc(Alloc(m, x, 1, 1, 1), x, y, z, w) -> Alloc(m, x, y, z, w)
# Alloc(Alloc(m, y, 1, 1), x, y, z, w) -> Alloc(m, x, y, z, w)
# Alloc(Alloc(m, y1, 1, 1), x, y2, z, w) -> Alloc(m, x, assert(y1, y1==y2), z, w)
if
not
isinstance
(
node
.
op
,
T
.
Alloc
):
return
False
if
not
node
.
inputs
[
0
]
.
owner
or
not
isinstance
(
...
...
@@ -5912,10 +5913,13 @@ def local_merge_alloc(node):
# The reverse ordering is needed when an Alloc add an implicit new
# broadcasted dimensions to its inputs[0]. Eg:
# Alloc(Alloc(m, y, 1, 1), x, y, z, w) -> Alloc(m, x, y, z, w)
i
=
0
for
dim_inner
,
dim_outer
in
zip
(
dims_inner_rev
,
dims_outer_rev
):
if
dim_inner
!=
dim_outer
:
if
isinstance
(
dim_inner
,
Constant
)
and
dim_inner
.
data
==
1
:
pass
else
:
return
False
dims_outer
[
-
1
-
i
]
=
assert_op
(
dim_outer
,
T
.
eq
(
dim_outer
,
dim_inner
))
i
+=
1
return
[
T
.
alloc
(
inputs_inner
[
0
],
*
dims_outer
)]
theano/tensor/tests/test_opt.py
浏览文件 @
3b0f4cdb
...
...
@@ -13,6 +13,7 @@ import numpy
from
six.moves
import
xrange
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.attrib
import
attr
from
nose.tools
import
assert_raises
from
numpy.testing
import
dec
from
numpy.testing.noseclasses
import
KnownFailureTest
...
...
@@ -5448,9 +5449,10 @@ def test_local_merge_alloc():
# otherwise, FAST_COMPILE fails.
default_mode
=
theano
.
compile
.
mode
.
get_default_mode
()
opt_mode
=
default_mode
.
including
(
"local_merge_alloc"
)
x
=
T
.
iscalar
(
'x'
)
y
=
T
.
iscalar
(
'y'
)
y2
=
T
.
iscalar
(
'y2'
)
z
=
T
.
iscalar
(
'z'
)
w
=
T
.
iscalar
(
'w'
)
m
=
T
.
fscalar
(
'm'
)
...
...
@@ -5474,6 +5476,20 @@ def test_local_merge_alloc():
o
=
f
(
0.
,
1
,
2
,
3
,
4
)
assert
o
.
shape
==
(
1
,
2
,
3
,
4
)
# case 3
# Alloc(Alloc(m, y1, 1, 1), x, y2, z, w) ->
# Alloc(m, x, assert(y1, y1==y2), z, w)
output
=
T
.
alloc
(
T
.
alloc
(
m
,
y
,
1
,
1
),
x
,
y2
,
z
,
w
)
f
=
theano
.
function
([
m
,
x
,
y
,
y2
,
z
,
w
],
output
,
mode
=
opt_mode
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
3
assert
isinstance
(
topo
[
-
2
]
.
op
,
T
.
opt
.
Assert
)
assert
isinstance
(
topo
[
-
1
]
.
op
,
T
.
Alloc
)
o
=
f
(
0.
,
1
,
2
,
2
,
3
,
4
)
assert
o
.
shape
==
(
1
,
2
,
3
,
4
)
assert_raises
((
AssertionError
,
ValueError
),
f
,
0.
,
1
,
2
,
5
,
3
,
4
)
if
__name__
==
'__main__'
:
t
=
TestMakeVector
(
'setUp'
)
t
.
setUp
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论