提交 10880e71 authored 作者: Gijs van Tulder's avatar 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
......@@ -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,
......
......@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论