Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
fb435772
提交
fb435772
authored
11月 12, 2015
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3511 from yingzha/ccw
Remove useless reshape
上级
23369bc4
0f6d8a5f
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
34 行增加
和
8 行删除
+34
-8
opt.py
theano/tensor/opt.py
+16
-0
test_opt.py
theano/tensor/tests/test_opt.py
+18
-8
没有找到文件。
theano/tensor/opt.py
浏览文件 @
fb435772
...
...
@@ -3703,6 +3703,22 @@ register_canonicalize(local_reshape_chain(T.Reshape),
name
=
'local_reshape_chain'
)
@register_canonicalize
@register_stabilize
@gof.local_optimizer
([
T
.
Reshape
])
def
local_useless_reshape
(
node
):
"""
Remove Reshape when both the input and the output have a
single dimension.
"""
if
isinstance
(
node
.
op
,
T
.
Reshape
):
if
(
node
.
inputs
[
0
]
.
ndim
==
1
and
node
.
outputs
[
0
]
.
ndim
==
1
and
node
.
inputs
[
0
]
.
broadcastable
==
node
.
outputs
[
0
]
.
broadcastable
):
return
[
node
.
inputs
[
0
]]
@register_canonicalize
@register_stabilize
@gof.local_optimizer
([
T
.
Reshape
])
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
fb435772
...
...
@@ -3135,7 +3135,7 @@ def test_local_fill_useless():
assert
T
.
Alloc
in
ops
f
(
m_
,
x_
)
class
Test_local_useless_elemwise_comparison
(
unittest
.
TestCase
):
def
test_local_useless_elemwise_comparison
(
self
):
# TODO: test each case individually.
...
...
@@ -3171,7 +3171,7 @@ class Test_local_useless_elemwise_comparison(unittest.TestCase):
>Sum{acc_dtype=float64} [id L] ''
> |X[t] [id M] -> [id I]
"""
mode
=
theano
.
compile
.
get_default_mode
()
.
excluding
(
'fusion'
)
f
=
theano
.
function
([
X
,
Y
],
Z
,
mode
=
mode
)
theano
.
printing
.
debugprint
(
f
,
print_type
=
True
)
...
...
@@ -3211,7 +3211,7 @@ class Test_local_useless_elemwise_comparison(unittest.TestCase):
assert
len
(
elem
.
inputs
)
==
1
,
elem
.
inputs
assert
isinstance
(
elem
.
inputs
[
0
],
T
.
TensorConstant
),
elem
assert
T
.
extract_constant
(
elem
.
inputs
[
0
])
==
val
,
val
def
assert_identity
(
self
,
f
):
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
1
...
...
@@ -3224,10 +3224,10 @@ class Test_local_useless_elemwise_comparison(unittest.TestCase):
def
test_inequality_with_self
(
self
):
x
=
T
.
scalar
(
'x'
,
dtype
=
config
.
floatX
)
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'local_useless_elemwise_comparison'
)
f
=
theano
.
function
([
x
],
T
.
lt
(
x
,
x
),
mode
=
mode
)
self
.
assert_eqs_const
(
f
,
0
)
f
=
theano
.
function
([
x
],
T
.
le
(
x
,
x
),
mode
=
mode
)
self
.
assert_eqs_const
(
f
,
1
)
...
...
@@ -3289,10 +3289,10 @@ class Test_local_useless_elemwise_comparison(unittest.TestCase):
f
=
theano
.
function
([
x
,
y
],
T
.
ge
(
x
.
shape
[
0
]
+
y
.
shape
[
0
],
0
),
mode
=
mode
)
self
.
assert_eqs_const
(
f
,
1
)
def
test_and
(
self
):
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'canonicalize'
)
x
=
T
.
scalar
(
'x'
,
dtype
=
'int8'
)
f
=
theano
.
function
([
x
],
T
.
and_
(
x
,
0
),
mode
=
mode
)
...
...
@@ -5704,7 +5704,7 @@ def test_local_flatten_lift():
class
Test_Reshape
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
mode
=
mode_opt
self
.
mode
=
mode_opt
self
.
op
=
tensor
.
Reshape
def
test_local_reshape
(
self
):
...
...
@@ -5716,6 +5716,16 @@ class Test_Reshape(unittest.TestCase):
assert
sum
(
isinstance
(
node
.
op
,
self
.
op
)
for
node
in
topo
)
==
1
def
test_local_useless_reshape
():
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'local_useless_reshape'
)
i
=
T
.
iscalar
(
'i'
)
m
=
theano
.
tensor
.
mgrid
[
0
:
i
,]
f
=
theano
.
function
([
i
],
m
,
mode
=
mode
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
not
any
(
isinstance
(
n
.
op
,
tensor
.
basic
.
Reshape
)
for
n
in
topo
)
def
test_local_reshape_lift
():
x
=
tensor
.
tensor4
()
out
=
T
.
exp
(
x
)
.
reshape
([
x
.
size
])
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论