Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
24102962
提交
24102962
authored
3月 18, 2011
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Test new cases for local_subtensor_merge, and fix one of them.
上级
3944c371
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
17 行增加
和
9 行删除
+17
-9
opt.py
theano/tensor/opt.py
+17
-9
test_opt.py
theano/tensor/tests/test_opt.py
+0
-0
没有找到文件。
theano/tensor/opt.py
浏览文件 @
24102962
...
...
@@ -1152,11 +1152,13 @@ def local_subtensor_merge(node):
1) var[int:][-1] -> var[-1] # a little different for when the first subtensor is empty.
2) var[::-1][int] -> var[-int-1]
3) var[::-1][:int] -> var[:-int-1:-1]
4) var[int1::][:int2] -> var[int1:switch(idx1>=0,
idx1,
maximum(u.owner.inputs[0].shape[0]+idx1, 0)
) + idx2]
4) var[int1::][:int2] ->
var[int1:int2 + switch(int2<0,
0,
switch(int1>=0,
int1,
maximum(u.owner.inputs[0].shape[0]+int1,
0))]
"""
if
(
isinstance
(
node
.
op
,
T
.
Subtensor
)
and
len
(
node
.
op
.
idx_list
)
==
1
):
...
...
@@ -1270,11 +1272,17 @@ def local_subtensor_merge(node):
elif
isinstance
(
idx2
,
int
):
idx2
=
T
.
as_tensor_variable
(
idx2
)
# The maximum is needed to don't have shape[0] - idx1 < 0
idx2_neg
=
T
.
maximum
(
u
.
owner
.
inputs
[
0
]
.
shape
[
0
]
+
idx1
,
0
)
new_idx2
=
T
.
switch
(
idx1
>=
0
,
idx1
,
idx2_neg
)
+
idx2
# Get positive version of idx1
# TODO: use Razvan's code for that
# The maximum is needed so that shape[0] + idx1 >= 0
neg_idx1
=
T
.
maximum
(
u
.
owner
.
inputs
[
0
]
.
shape
[
0
]
+
idx1
,
0
)
new_idx1
=
T
.
switch
((
idx1
>=
0
),
idx1
,
neg_idx1
)
# If idx2<0, we are indexing from the end, so idx2 is OK
# If we are indexing from the beginning, we need to add pos_idx1
new_idx2
=
idx2
+
T
.
switch
((
idx2
<
0
),
0
,
new_idx1
)
return
[
u
.
owner
.
inputs
[
0
][
idx1
:
new_idx2
]]
return
[
u
.
owner
.
inputs
[
0
][
new_
idx1
:
new_idx2
]]
@register_canonicalize
@gof.local_optimizer
([
None
])
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
24102962
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论