Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1c26e1a9
提交
1c26e1a9
authored
6月 11, 2013
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add opt local_reshape_lift to enable softplus opt with reshape in the middle.
上级
1e2d5bca
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
44 行增加
和
0 行删除
+44
-0
test_sigm.py
theano/tensor/nnet/tests/test_sigm.py
+11
-0
opt.py
theano/tensor/opt.py
+20
-0
test_opt.py
theano/tensor/tests/test_opt.py
+13
-0
没有找到文件。
theano/tensor/nnet/tests/test_sigm.py
浏览文件 @
1c26e1a9
...
@@ -382,6 +382,17 @@ class T_softplus_opts(unittest.TestCase):
...
@@ -382,6 +382,17 @@ class T_softplus_opts(unittest.TestCase):
assert
isinstance
(
topo
[
2
]
.
op
.
scalar_op
,
theano
.
scalar
.
Neg
)
assert
isinstance
(
topo
[
2
]
.
op
.
scalar_op
,
theano
.
scalar
.
Neg
)
f
(
numpy
.
random
.
rand
(
54
,
11
)
.
astype
(
config
.
floatX
))
f
(
numpy
.
random
.
rand
(
54
,
11
)
.
astype
(
config
.
floatX
))
# Same test with a reshape
out
=
T
.
log
(
1
-
sigmoid
(
x
)
.
reshape
([
x
.
size
]))
f
=
theano
.
function
([
x
],
out
,
mode
=
self
.
m
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
#assert len(topo) == 3
assert
any
(
isinstance
(
node
.
op
,
T
.
Reshape
)
for
node
in
topo
)
assert
any
(
isinstance
(
getattr
(
node
.
op
,
'scalar_op'
,
None
),
theano
.
tensor
.
nnet
.
sigm
.
ScalarSoftplus
)
for
node
in
topo
)
f
(
numpy
.
random
.
rand
(
54
,
11
)
.
astype
(
config
.
floatX
))
def
test_log1pexp_to_softplus
(
self
):
def
test_log1pexp_to_softplus
(
self
):
m
=
theano
.
config
.
mode
m
=
theano
.
config
.
mode
if
m
==
'FAST_COMPILE'
:
if
m
==
'FAST_COMPILE'
:
...
...
theano/tensor/opt.py
浏览文件 @
1c26e1a9
...
@@ -2436,6 +2436,26 @@ def local_reshape_chain(node):
...
@@ -2436,6 +2436,26 @@ def local_reshape_chain(node):
return
False
return
False
register_canonicalize
(
local_reshape_chain
)
register_canonicalize
(
local_reshape_chain
)
@register_canonicalize
@register_stabilize
@gof.local_optimizer
([])
def
local_reshape_lift
(
node
):
"""
Reshape(UnaryElemwise(x)) -> UnaryElemwise(Reshape(x))
This optimization is needed by optimization
nnet/sigm.py:log1msigm_to_softplus to get applied when there is a reshape.
"""
if
(
isinstance
(
node
.
op
,
T
.
Reshape
)
and
node
.
inputs
[
0
]
.
owner
and
isinstance
(
node
.
inputs
[
0
]
.
owner
.
op
,
T
.
Elemwise
)
and
len
(
node
.
inputs
[
0
]
.
owner
.
inputs
)
==
1
):
r
=
node
.
op
(
node
.
inputs
[
0
]
.
owner
.
inputs
[
0
],
node
.
inputs
[
1
])
e
=
node
.
inputs
[
0
]
.
owner
.
op
(
r
)
return
[
e
]
if
0
:
if
0
:
# TODO: Test that this optimziation works.
# TODO: Test that this optimziation works.
@register_canonicalize
@register_canonicalize
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
1c26e1a9
...
@@ -4004,6 +4004,19 @@ def test_local_flatten_lift():
...
@@ -4004,6 +4004,19 @@ def test_local_flatten_lift():
assert
isinstance
(
topo
[
1
]
.
op
,
tensor
.
Elemwise
)
assert
isinstance
(
topo
[
1
]
.
op
,
tensor
.
Elemwise
)
def
test_local_reshape_lift
():
x
=
tensor
.
tensor4
()
out
=
T
.
exp
(
x
)
.
reshape
([
x
.
size
])
assert
out
.
ndim
==
1
mode
=
compile
.
mode
.
get_default_mode
()
mode
=
mode
.
including
(
'local_reshape_lift'
)
f
=
theano
.
function
([
x
],
out
,
mode
=
mode
)
f
(
numpy
.
random
.
rand
(
5
,
4
,
3
,
2
)
.
astype
(
config
.
floatX
))
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
isinstance
(
topo
[
-
2
]
.
op
,
tensor
.
Reshape
)
assert
isinstance
(
topo
[
-
1
]
.
op
,
tensor
.
Elemwise
)
class
Test_lift_transpose_through_dot
(
unittest
.
TestCase
):
class
Test_lift_transpose_through_dot
(
unittest
.
TestCase
):
def
simple_optimize
(
self
,
g
):
def
simple_optimize
(
self
,
g
):
out2in
(
opt
.
local_useless_elemwise
)
.
optimize
(
g
)
out2in
(
opt
.
local_useless_elemwise
)
.
optimize
(
g
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论