Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b453a024
提交
b453a024
authored
3月 01, 2016
作者:
Samira Shabanian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
opt is almost done
上级
0aa5ff77
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
65 行增加
和
2 行删除
+65
-2
opt.py
theano/tensor/opt.py
+33
-1
test_opt.py
theano/tensor/tests/test_opt.py
+32
-1
没有找到文件。
theano/tensor/opt.py
浏览文件 @
b453a024
...
@@ -3576,6 +3576,38 @@ def local_join_make_vector(node):
...
@@ -3576,6 +3576,38 @@ def local_join_make_vector(node):
return
[
ret
]
return
[
ret
]
#################
# Exp stability #
#################
@register_stabilize
@register_specialize
@register_canonicalize
@gof.local_optimizer
([
T
.
Elemwise
])
def
local_expm1
(
node
):
"""
This optimization detects exp(a)-1 and converts this to expm1(a).
"""
if
(
isinstance
(
node
.
op
,
T
.
Elemwise
)
and
isinstance
(
node
.
op
.
scalar_op
,
theano
.
scalar
.
basic
.
Sub
)):
in1
,
in2
=
node
.
inputs
out
=
node
.
outputs
[
0
]
#import pdb; pdb.set_trace()
if
(
in1
.
owner
and
isinstance
(
in1
.
owner
.
op
,
T
.
Elemwise
)
and
isinstance
(
in1
.
owner
.
op
.
scalar_op
,
theano
.
scalar
.
basic
.
Exp
)
and
T
.
extract_constant
(
in2
)
==
1
):
in11
=
in1
.
owner
.
inputs
[
0
]
new_out
=
T
.
expm1
(
in11
)
# import pdb; pdb.set_trace()
if
new_out
.
dtype
!=
out
.
dtype
:
new_out
=
T
.
cast
(
new_out
,
dtype
=
out
.
dtype
)
# The ones could have forced a specific length
if
new_out
.
type
!=
out
.
type
:
new_out
=
broadcast_like
(
new_out
,
out
,
node
.
fgraph
)
return
[
new_out
]
###############
###############
# Switch opts #
# Switch opts #
###############
###############
...
@@ -6756,7 +6788,7 @@ def local_grad_clip(node):
...
@@ -6756,7 +6788,7 @@ def local_grad_clip(node):
@register_stabilize
@register_stabilize
@register_specialize
@register_specialize
@gof.local_optimizer
([
T
.
Alloc
])
@gof.local_optimizer
([
T
.
Alloc
])
def
local_merge_allo
c
(
node
):
def
local_merge_allo
(
c
node
):
# This opt takes care of several cases:
# 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, 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, y, 1, 1), x, y, z, w) -> Alloc(m, x, y, z, w)
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
b453a024
...
@@ -37,7 +37,8 @@ from theano.tensor.opt import (
...
@@ -37,7 +37,8 @@ from theano.tensor.opt import (
Shape_i
,
Shape_i
,
Assert
,
Assert
,
MakeVector
,
MakeVector
,
make_vector
make_vector
,
local_expm1
)
)
from
theano
import
tensor
from
theano
import
tensor
from
theano
import
tensor
as
T
from
theano
import
tensor
as
T
...
@@ -6122,6 +6123,36 @@ class TestIntDivByOne(unittest.TestCase):
...
@@ -6122,6 +6123,36 @@ class TestIntDivByOne(unittest.TestCase):
assert
len
(
divs
)
==
0
assert
len
(
divs
)
==
0
def
test_local_expm1
():
x
=
matrix
(
'x'
)
u
=
T
.
scalar
(
'u'
)
y
=
T
.
exp
(
x
)
-
1.
z
=
T
.
exp
(
x
)
-
2.
t
=
T
.
exp
(
x
)
-
x
s
=
T
.
exp
(
u
)
-
numpy
.
ones
((
4
,
3
))
.
astype
(
config
.
floatX
)
#f = function([x], y)
#g = function([x], z)
#h = function([x], t)
r
=
function
([
u
],
s
)
x_val
=
numpy
.
random
.
rand
(
4
,
3
)
.
astype
(
config
.
floatX
)
#f_val = f(x_val)
#g_val = g(x_val)
#h_val = h(x_val)
u_val
=
r
(
1.0
)
#assert any(isinstance(n.op, T.Elemwise) and isinstance(n.op.scalar_op, theano.scalar.basic.Expm1)
# for n in f.maker.fgraph.toposort())
#assert not any(isinstance(n.op, T.Elemwise) and isinstance(n.op.scalar_op, theano.scalar.basic.Expm1)
# for n in g.maker.fgraph.toposort())
#assert not any(isinstance(n.op, T.Elemwise) and isinstance(n.op.scalar_op, theano.scalar.basic.Expm1)
# for n in h.maker.fgraph.toposort())
def
test_local_merge_alloc
():
def
test_local_merge_alloc
():
# Add this opt to the default mode,
# Add this opt to the default mode,
# otherwise, FAST_COMPILE fails.
# otherwise, FAST_COMPILE fails.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论