Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ab5a218b
提交
ab5a218b
authored
1月 30, 2010
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tensor opt - added local_subtensor_unary canonicalization
上级
e91f68d0
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
51 行增加
和
1 行删除
+51
-1
opt.py
theano/tensor/opt.py
+12
-0
test_opt.py
theano/tensor/tests/test_opt.py
+39
-1
没有找到文件。
theano/tensor/opt.py
浏览文件 @
ab5a218b
...
...
@@ -293,6 +293,18 @@ register_canonicalize(local_fill_lift, 'fill_lift')
# Subtensor opts #
##################
@register_canonicalize
@gof.local_optimizer
([])
def
local_subtensor_unary
(
node
):
"""
unary(x)[idx] -> unary(x[idx])
"""
if
isinstance
(
node
.
op
,
T
.
Subtensor
):
u
=
node
.
inputs
[
0
]
if
u
.
owner
and
isinstance
(
u
.
owner
.
op
,
T
.
Elemwise
)
and
len
(
u
.
owner
.
inputs
)
==
1
:
idx
=
node
.
inputs
[
1
:]
x_idx
=
node
.
op
(
u
.
owner
.
inputs
[
0
],
*
idx
)
return
[
u
.
owner
.
op
(
x_idx
)]
@gof.local_optimizer
([
None
,
None
])
def
local_subtensor_make_vector
(
node
):
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
ab5a218b
...
...
@@ -6,7 +6,8 @@ import numpy
import
theano
from
theano
import
gof
from
theano.tensor.opt
import
*
from
theano
import
tensor
from
theano
import
tensor
#do not use, there is an import * below that hides it
from
theano
import
tensor
as
TT
#ugly but works for now...
from
theano.tensor
import
TensorType
,
inplace
from
theano.gof
import
Env
from
theano.tensor.elemwise
import
DimShuffle
...
...
@@ -79,6 +80,7 @@ def test_add_canonizer_problem0():
f
=
function
([
label
],
r
)
from
theano.tensor
import
*
# Why is there TWO 'import *' in this file???
class
test_greedy_distribute
(
unittest
.
TestCase
):
def
test_main
(
self
):
...
...
@@ -940,6 +942,42 @@ def test_log1p():
f
=
function
([
z
],
T
.
log
(
1
+
(
z
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
==
[
T
.
log1p
]
class
test_local_subtensor_unary
():
def
test0
(
self
):
# basic test that the Op works
mode
=
theano
.
config
.
mode
if
mode
==
'FAST_COMPILE'
:
mode
=
'FAST_RUN'
x
=
TT
.
matrix
()
f
=
function
([
x
],
TT
.
exp
(
x
)[
0
],
mode
=
mode
)
prog
=
f
.
maker
.
env
.
toposort
()
assert
isinstance
(
prog
[
0
]
.
op
,
TT
.
Subtensor
)
#first subtensor
assert
prog
[
1
]
.
op
==
TT
.
exp
f
([[
0
,
1
],[
2
,
3
]])
# let debugmode test something
def
test1
(
self
):
# basic test that the optimization doesn't work with broadcasting
# ... It *could* be extended to,
# ... but right now it doesn't, so it shouldn't try.
mode
=
theano
.
config
.
mode
if
mode
==
'FAST_COMPILE'
:
mode
=
'FAST_RUN'
x
=
TT
.
matrix
()
y
=
TT
.
vector
()
f
=
function
([
x
,
y
],
TT
.
exp
(
x
+
y
)[
0
],
mode
=
mode
)
prog
=
f
.
maker
.
env
.
toposort
()
# the optimization works through exp() but not add()
print
prog
assert
isinstance
(
prog
[
0
]
.
op
,
TT
.
DimShuffle
)
assert
prog
[
1
]
.
op
==
TT
.
add
assert
isinstance
(
prog
[
2
]
.
op
,
TT
.
Subtensor
)
#first subtensor
assert
prog
[
3
]
.
op
==
inplace
.
exp_inplace
f
([[
0
,
1
],[
2
,
3
]],
[
4
,
5
])
# let debugmode test something
if
__name__
==
'__main__'
:
# unittest.main()
test_fusion
()
.
tes_memory_leak
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论