Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3867a916
提交
3867a916
authored
10月 22, 2014
作者:
Dustin Webb
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improved support for multiple alloc and dimshuffle alloc combinations and added assocaited tests.
上级
4b0a5c10
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
57 行增加
和
8 行删除
+57
-8
opt.py
theano/tensor/opt.py
+16
-8
test_opt.py
theano/tensor/tests/test_opt.py
+41
-0
没有找到文件。
theano/tensor/opt.py
浏览文件 @
3867a916
...
@@ -1554,14 +1554,14 @@ def local_alloc_elemwise(node):
...
@@ -1554,14 +1554,14 @@ def local_alloc_elemwise(node):
if
len
(
node
.
outputs
)
>
1
:
if
len
(
node
.
outputs
)
>
1
:
# Ensure all outputs have the same broadcast pattern
# Ensure all outputs have the same broadcast pattern
# This is a supposition that I'm not sure is always true.
# This is a supposition that I'm not sure is always true.
assert
all
([
list
(
o
.
type
.
broadcastable
)
==
list
(
assert
all
([
o
.
type
.
broadcastable
==
node
.
outputs
[
0
]
.
type
.
broadcastable
)
for
o
in
node
.
outputs
[
0
]
.
type
.
broadcastable
for
o
in
node
.
outputs
[
1
:]])
node
.
outputs
[
1
:]])
# The broadcast pattern of the ouptut must match the broadcast pattern of
# The broadcast pattern of the ouptut must match the broadcast pattern of
# at least one of the inputs.
# at least one of the inputs.
if
not
any
([
list
(
i
.
type
.
broadcastable
)
==
list
(
if
not
any
([
i
.
type
.
broadcastable
==
node
.
outputs
[
0
]
.
type
.
broadcastable
)
for
i
in
node
.
inputs
]):
node
.
outputs
[
0
]
.
type
.
broadcastable
for
i
in
node
.
inputs
]):
return
False
return
False
def
dimshuffled_alloc
(
i
):
def
dimshuffled_alloc
(
i
):
...
@@ -1593,12 +1593,20 @@ def local_alloc_elemwise(node):
...
@@ -1593,12 +1593,20 @@ def local_alloc_elemwise(node):
if
assert_op_idx
<
0
:
if
assert_op_idx
<
0
:
# We want to optimize as many allocs as possible. When there is more
# We want to optimize as many allocs as possible. When there is more
# than one then do all but one.
# than one then do all but one.
l
=
[
idx
for
idx
,
i
in
enumerate
(
node
.
inputs
)
# number of inputs with alloc or dimshuffle alloc
if
i
.
type
.
broadcastable
==
node
.
outputs
[
0
]
.
type
.
broadcastable
]
l2
=
[
i
for
i
in
node
.
inputs
if
len
(
l
)
>
1
:
if
(
i
.
owner
and
(
isinstance
(
i
.
owner
.
op
,
T
.
Alloc
)
or
dimshuffled_alloc
(
i
)))]
# If only 1 alloc or dimshuffle alloc, it is the one we will use for the shape
# So no alloc would be removed.
if
len
(
l2
)
>
1
:
# l containt inputs with alloc or dimshuffle alloc only.
# Its length will always be at least one, as we checked that before
l
=
[
idx
for
idx
,
i
in
enumerate
(
node
.
inputs
)
if
i
.
type
.
broadcastable
==
node
.
outputs
[
0
]
.
type
.
broadcastable
]
assert_op_idx
=
l
[
0
]
# The first one is as good as any to use.
assert_op_idx
=
l
[
0
]
# The first one is as good as any to use.
else
:
else
:
#
Otherwise nothing can be done.
#
Nothing would be optimized!
return
False
return
False
assert_op
=
node
.
inputs
[
assert_op_idx
]
assert_op
=
node
.
inputs
[
assert_op_idx
]
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
3867a916
...
@@ -2620,6 +2620,47 @@ class Test_local_alloc_elemwise(unittest.TestCase):
...
@@ -2620,6 +2620,47 @@ class Test_local_alloc_elemwise(unittest.TestCase):
self
.
_verify_alloc_count
(
func
,
0
)
self
.
_verify_alloc_count
(
func
,
0
)
self
.
_verify_assert_count
(
func
,
0
)
self
.
_verify_assert_count
(
func
,
0
)
def
test_multi_input_single_alloc
(
self
):
tv
=
T
.
alloc
(
self
.
vec
,
5
,
5
)
tm
=
T
.
alloc
(
self
.
mat
,
5
,
5
,
5
)
func
=
function
(
[
self
.
vec
,
self
.
mat
],
tv
+
tm
,
mode
=
'FAST_COMPILE'
)
self
.
_verify_alloc_count
(
func
,
2
)
self
.
_verify_assert_count
(
func
,
0
)
func
=
function
(
[
self
.
vec
,
self
.
mat
],
tv
+
tm
,
mode
=
'FAST_RUN'
)
self
.
_verify_alloc_count
(
func
,
1
)
self
.
_verify_assert_count
(
func
,
0
)
s
=
T
.
iscalar
(
's'
)
tv
=
T
.
alloc
(
self
.
vec
,
s
,
s
)
tm
=
T
.
alloc
(
self
.
mat
,
5
,
5
,
5
)
func
=
function
(
[
self
.
vec
,
self
.
mat
,
s
],
tv
+
tm
,
mode
=
'FAST_COMPILE'
)
self
.
_verify_alloc_count
(
func
,
2
)
self
.
_verify_assert_count
(
func
,
0
)
func
=
function
(
[
self
.
vec
,
self
.
mat
,
s
],
tv
+
tm
,
mode
=
'FAST_RUN'
)
self
.
_verify_alloc_count
(
func
,
1
)
self
.
_verify_assert_count
(
func
,
1
)
def
test_local_subtensor_of_alloc
():
def
test_local_subtensor_of_alloc
():
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论