Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d6cd1459
提交
d6cd1459
authored
10月 08, 2014
作者:
Paul Christiano
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Preliminary version of dot+subtensor optimization, supporting arbitrary indexing.
上级
098261ed
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
29 行增加
和
8 行删除
+29
-8
opt.py
theano/tensor/opt.py
+17
-5
subtensor.py
theano/tensor/subtensor.py
+12
-3
没有找到文件。
theano/tensor/opt.py
浏览文件 @
d6cd1459
...
@@ -2193,13 +2193,25 @@ def local_subtensor_of_dot(node):
...
@@ -2193,13 +2193,25 @@ def local_subtensor_of_dot(node):
# We don't want to compute twice the sub part.
# We don't want to compute twice the sub part.
if
len
(
node
.
inputs
[
0
]
.
clients
)
>
1
:
if
len
(
node
.
inputs
[
0
]
.
clients
)
>
1
:
return
return
# Do we index/slice on the outer dimensions only?
if
node
.
inputs
[
0
]
.
ndim
>=
1
and
len
(
node
.
op
.
idx_list
)
==
1
:
a
=
node
.
inputs
[
0
]
.
owner
.
inputs
[
0
]
a
=
node
.
inputs
[
0
]
.
owner
.
inputs
[
0
]
b
=
node
.
inputs
[
0
]
.
owner
.
inputs
[
1
]
b
=
node
.
inputs
[
0
]
.
owner
.
inputs
[
1
]
a_sub
=
node
.
op
.
make_node
(
a
,
*
node
.
inputs
[
1
:])
.
outputs
[
0
]
return
[
T
.
dot
(
a_sub
,
b
)]
num_a_indices
=
min
(
a
.
ndim
-
1
,
len
(
node
.
op
.
idx_list
))
return
a_indices
=
node
.
op
.
idx_list
[:
num_a_indices
]
b_indices
=
(
slice
(
None
,
None
,
None
),)
+
node
.
op
.
idx_list
[
num_a_indices
:]
num_a_inputs
=
theano
.
tensor
.
subtensor
.
get_idx_list
(
node
.
inputs
,
a_indices
,
get_count
=
True
)
a_inputs
=
node
.
inputs
[
1
:
1
+
num_a_inputs
]
b_inputs
=
node
.
inputs
[
1
+
num_a_inputs
:]
import
pdb
;
pdb
.
set_trace
()
a_sub
=
Subtensor
(
a_indices
)
.
make_node
(
a
,
*
a_inputs
)
b_sub
=
Subtensor
(
b_indices
)
.
make_node
(
b
,
*
b_inputs
)
return
[
T
.
dot
(
a_sub
,
b_sub
)]
@register_canonicalize
@register_canonicalize
...
...
theano/tensor/subtensor.py
浏览文件 @
d6cd1459
...
@@ -65,14 +65,20 @@ def make_constant(args):
...
@@ -65,14 +65,20 @@ def make_constant(args):
return
tuple
(
map
(
conv
,
args
))
return
tuple
(
map
(
conv
,
args
))
def
get_idx_list
(
inputs
,
idx_list
):
def
get_idx_list
(
inputs
,
idx_list
,
get_count
=
False
):
'''
'''
Given a list of inputs to the subtensor and its idx_list reorders
Given a list of inputs to the subtensor and its idx_list reorders
the inputs according to the idx list to get the right values
the inputs according to the idx list to get the right values.
If get_counts=True, instead returns the number of inputs consumed
during this process.
'''
'''
# The number of indices
n
=
len
(
inputs
)
-
1
# The subtensor (or idx_list) does not depend on the inputs.
# The subtensor (or idx_list) does not depend on the inputs.
if
len
(
inputs
)
==
1
:
if
n
==
0
:
return
tuple
(
idx_list
)
return
tuple
(
idx_list
)
indices
=
list
(
reversed
(
list
(
inputs
[
1
:])))
indices
=
list
(
reversed
(
list
(
inputs
[
1
:])))
...
@@ -87,6 +93,9 @@ def get_idx_list(inputs, idx_list):
...
@@ -87,6 +93,9 @@ def get_idx_list(inputs, idx_list):
else
:
else
:
return
entry
return
entry
cdata
=
tuple
(
map
(
convert
,
idx_list
))
cdata
=
tuple
(
map
(
convert
,
idx_list
))
if
get_count
:
return
n
-
len
(
indices
)
else
:
return
cdata
return
cdata
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论