Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
cbae058c
提交
cbae058c
authored
9月 22, 2016
作者:
Olivier Mastropietro
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Opts had errors in their return value and implementation of tests
上级
c571066f
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
45 行增加
和
6 行删除
+45
-6
opt_uncanonicalize.py
theano/tensor/opt_uncanonicalize.py
+5
-5
test_opt_uncanonicalize.py
theano/tensor/tests/test_opt_uncanonicalize.py
+40
-1
没有找到文件。
theano/tensor/opt_uncanonicalize.py
浏览文件 @
cbae058c
...
...
@@ -114,10 +114,10 @@ def local_alloc_dimshuffle(node):
# check if it only adds dimension to the left
new_order
=
input_
.
owner
.
op
.
new_order
expected_new_order
=
(
'x'
,)
*
(
input_
.
ndim
-
input_
.
owner
.
inputs
[
0
]
.
ndim
)
+
\
tuple
(
range
(
input_
.
owner
.
inputs
.
ndim
))
tuple
(
range
(
input_
.
owner
.
inputs
[
0
]
.
ndim
))
if
new_order
!=
expected_new_order
:
return
False
return
input_
.
owner
.
inputs
return
[
T
.
alloc
(
input_
.
owner
.
inputs
[
0
],
*
node
.
inputs
[
1
:])]
return
False
...
...
@@ -128,10 +128,10 @@ def local_reshape_dimshuffle(node):
If a dimshuffle is inside a reshape and does not change the order
of dimensions, remove it.
"""
if
node
.
op
==
T
.
reshape
:
if
isinstance
(
node
.
op
,
T
.
Reshape
)
:
input_
=
node
.
inputs
[
0
]
if
input_
.
owner
and
isinstance
(
input_
.
owner
.
op
,
DimShuffle
):
new_order
=
input_owner
.
op
.
new_order
new_order
=
input_
.
owner
.
op
.
new_order
offset
=
0
for
i
,
dim
in
enumerate
(
new_order
):
if
dim
==
'x'
:
...
...
@@ -139,5 +139,5 @@ def local_reshape_dimshuffle(node):
continue
elif
i
!=
dim
+
offset
:
return
False
return
input_
.
owner
.
inputs
return
[
T
.
reshape
(
input_
.
owner
.
inputs
[
0
],
tuple
(
node
.
inputs
[
1
]
.
owner
.
inputs
))]
return
False
theano/tensor/tests/test_opt_uncanonicalize.py
浏览文件 @
cbae058c
...
...
@@ -6,9 +6,15 @@ import numpy
import
theano
from
theano
import
function
,
config
from
theano
import
scalar
from
theano.gof
import
FunctionGraph
from
theano.tensor.opt
import
out2in
from
theano.tensor.opt_uncanonicalize
import
(
local_alloc_dimshuffle
,
local_reshape_dimshuffle
)
import
theano.tensor
as
tensor
#from theano.tensor import matrix,max_and_argmax,MaaxAndArgmax,neg
from
theano.tensor.elemwise
import
CAReduce
,
Elemwise
from
theano.tensor.elemwise
import
CAReduce
,
Elemwise
,
DimShuffle
from
theano.tests
import
unittest_tools
as
utt
...
...
@@ -106,3 +112,36 @@ class T_min_max(unittest.TestCase):
assert
len
(
topo
)
==
1
assert
isinstance
(
topo
[
0
]
.
op
,
CAReduce
)
# max
f
(
data
)
def
test_local_alloc_dimshuffle
():
alloc_dimshuffle
=
out2in
(
local_alloc_dimshuffle
)
x
=
T
.
vector
(
'x'
)
m
=
T
.
iscalar
(
'm'
)
out
=
x
.
dimshuffle
(
'x'
,
0
)
out
=
T
.
alloc
(
x
,
m
,
1
,
x
.
shape
[
0
])
g
=
FunctionGraph
(
out
)
alloc_dimshuffle
(
g
)
topo
=
g
.
toposort
()
assert
any
([
not
isinstance
(
x
,
DimShuffle
)
for
x
in
topo
])
def
test_local_reshape_dimshuffle
():
reshape_dimshuffle
=
out2in
(
local_reshape_dimshuffle
)
x
=
T
.
matrix
(
'x'
)
y
=
x
.
dimshuffle
(
'x'
,
0
,
'x'
,
1
)
out
=
T
.
reshape
(
y
,
(
1
,
x
.
shape
[
0
]
*
x
.
shape
[
1
],
1
))
g
=
FunctionGraph
(
out
)
reshape_dimshuffle
(
g
)
topo
=
g
.
toposort
()
assert
any
([
not
isinstance
(
x
,
DimShuffle
)
for
x
in
topo
])
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论