Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
10880e71
提交
10880e71
authored
8月 04, 2017
作者:
Gijs van Tulder
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Subtensor with too many indices now raises IndexError.
This replaces the ValueError and makes it consistent with the behavior of AdvancedSubtensor and NumPy indexing.
上级
5ac920e9
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
4 行增加
和
27 行删除
+4
-27
subtensor.py
theano/tensor/subtensor.py
+2
-15
test_subtensor.py
theano/tensor/tests/test_subtensor.py
+2
-12
没有找到文件。
theano/tensor/subtensor.py
浏览文件 @
10880e71
...
...
@@ -280,11 +280,6 @@ class Subtensor(Op):
@todo: add support for advanced tensor indexing (in Subtensor_dx too).
"""
e_invalid
=
(
'The index list is longer (size
%
d) than the number of '
'dimensions of the tensor(namely
%
d). You are asking for '
'a dimension of the tensor that does not exist! You might '
'need to use dimshuffle to add extra dimension to your '
'tensor.'
)
e_subslice
=
'nested slicing is not supported'
e_indextype
=
"Invalid index type or slice for Subtensor"
debug
=
0
...
...
@@ -473,10 +468,7 @@ class Subtensor(Op):
idx_list
=
list
(
self
.
idx_list
)
if
len
(
idx_list
)
>
x
.
type
.
ndim
:
exception
=
ValueError
(
Subtensor
.
e_invalid
%
(
len
(
idx_list
),
x
.
type
.
ndim
))
exception
.
subtensor_invalid
=
True
raise
exception
raise
IndexError
(
'too many indices for array'
)
input_types
=
Subtensor
.
collapse
(
idx_list
,
lambda
entry
:
isinstance
(
entry
,
...
...
@@ -1292,12 +1284,7 @@ class IncSubtensor(Op):
idx_list
=
list
(
self
.
idx_list
)
if
len
(
idx_list
)
>
x
.
type
.
ndim
:
exception
=
ValueError
(
Subtensor
.
e_invalid
%
(
len
(
idx_list
),
x
.
type
.
ndim
))
exception
.
subtensor_invalid
=
True
raise
exception
raise
IndexError
(
'too many indices for array'
)
input_types
=
Subtensor
.
collapse
(
idx_list
,
...
...
theano/tensor/tests/test_subtensor.py
浏览文件 @
10880e71
...
...
@@ -120,12 +120,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
def
test0_err_invalid
(
self
):
# it is impossible to retrieve a view of a 0-d tensor
n
=
self
.
shared
(
np
.
ones
((),
dtype
=
self
.
dtype
))
try
:
n
[
0
]
except
ValueError
as
e
:
self
.
assertTrue
(
hasattr
(
e
,
'subtensor_invalid'
))
return
self
.
fail
()
self
.
assertRaises
(
IndexError
,
n
.
__getitem__
,
0
)
@change_flags
(
compute_test_value
=
'off'
)
def
test1_err_bounds
(
self
):
...
...
@@ -184,12 +179,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
def
test1_err_invalid
(
self
):
n
=
self
.
shared
(
np
.
ones
(
1
,
dtype
=
self
.
dtype
))
try
:
n
[
0
,
0
]
except
ValueError
as
e
:
self
.
assertTrue
(
hasattr
(
e
,
'subtensor_invalid'
))
return
self
.
fail
()
self
.
assertRaises
(
IndexError
,
n
.
__getitem__
,
(
0
,
0
))
def
test1_ok_elem
(
self
):
n
=
self
.
shared
(
np
.
ones
(
1
,
dtype
=
self
.
dtype
)
*
5
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论