Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4f05b2f8
提交
4f05b2f8
authored
4月 18, 2016
作者:
Mohammad Pezeshki
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
useless alloc is now replaced with dimshuffle
上级
c7b07251
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
27 行增加
和
5 行删除
+27
-5
opt.py
theano/tensor/opt.py
+27
-5
没有找到文件。
theano/tensor/opt.py
浏览文件 @
4f05b2f8
...
@@ -47,7 +47,7 @@ from theano.tensor.type import (values_eq_approx_remove_inf,
...
@@ -47,7 +47,7 @@ from theano.tensor.type import (values_eq_approx_remove_inf,
from
theano.gof.opt
import
(
Optimizer
,
pre_constant_merge
,
from
theano.gof.opt
import
(
Optimizer
,
pre_constant_merge
,
pre_greedy_local_optimizer
)
pre_greedy_local_optimizer
)
from
theano.gof
import
toolbox
from
theano.gof
import
toolbox
from
theano.tensor.basic
import
get_scalar_constant_value
,
ShapeError
,
NotScalarConstantError
from
theano.tensor.basic
import
Alloc
,
get_scalar_constant_value
,
ShapeError
,
NotScalarConstantError
from
six
import
StringIO
from
six
import
StringIO
_logger
=
logging
.
getLogger
(
'theano.tensor.opt'
)
_logger
=
logging
.
getLogger
(
'theano.tensor.opt'
)
...
@@ -1683,10 +1683,32 @@ def local_useless_alloc(node):
...
@@ -1683,10 +1683,32 @@ def local_useless_alloc(node):
of the input. This is not needed.
of the input. This is not needed.
"""
"""
if
node
.
op
==
T
.
alloc
:
op
=
node
.
op
if
node
.
inputs
[
0
]
.
type
==
node
.
outputs
[
0
]
.
type
:
if
not
isinstance
(
op
,
Alloc
):
# We don't need to copy over any stack traces here
return
False
return
[
node
.
inputs
[
0
]]
input
=
node
.
inputs
[
0
]
output
=
node
.
outputs
[
0
]
# Check if dtype and broadcast remain the same.
if
input
.
type
==
output
.
type
:
# We don't need to copy over any stack traces here
return
[
input
]
# Check if alloc adds a broadcastable dimension with shape 1.
output_shape
=
node
.
inputs
[
1
:]
num_dims_with_size_1_added_to_left
=
0
for
i
in
range
(
len
(
output_shape
)):
if
output_shape
[
i
]
.
value
==
1
:
num_dims_with_size_1_added_to_left
+=
1
else
:
break
if
num_dims_with_size_1_added_to_left
>
0
:
new_output_shape
=
output_shape
[
num_dims_with_size_1_added_to_left
:]
inner
=
op
(
*
([
input
]
+
new_output_shape
))
dimshuffle_new_order
=
([
'x'
]
*
num_dims_with_size_1_added_to_left
+
range
(
len
(
new_output_shape
)))
return
[
DimShuffle
(
inner
.
type
.
broadcastable
,
dimshuffle_new_order
)(
inner
)]
# Don't register by default.
# Don't register by default.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论