提交 743f01e7 authored 作者: Frederic Bastien's avatar Frederic Bastien

make the indexing with int and slice into 0d array return the same error as with numpy.

上级 5b5735d6
......@@ -1084,7 +1084,7 @@ CudaNdarray_Subscript(PyObject * py_self, PyObject * key)
//int d_idx = PyInt_AsLong(key);
if (self->nd == 0)
{
PyErr_SetString(PyExc_NotImplementedError, "index into 0-d array");
PyErr_SetString(PyExc_IndexError, "0-d arrays can't be indexed");
return NULL;
}
int d_dim = CudaNdarray_HOST_DIMS(self)[0];
......@@ -1133,7 +1133,7 @@ CudaNdarray_Subscript(PyObject * py_self, PyObject * key)
{
if (self->nd == 0)
{
PyErr_SetString(PyExc_NotImplementedError, "index into 0-d array");
PyErr_SetString(PyExc_ValueError, "cannot slice a 0-d array");
return NULL;
}
......
......@@ -265,6 +265,17 @@ def test_mapping_getitem_w_int():
else:
raise Exception("Did not generate out or bound error")
def _cmpfV(x,*y):
try:
if len(y)==1:
x.__getitem__(*y)
else:
x.__getitem__(y)
except ValueError:
pass
else:
raise Exception("Did not generate out or bound error")
dim =(2,)
a = theano._asarray(numpy.random.rand(*dim), dtype='float32')
_a = cuda_ndarray.CudaNdarray(a)
......@@ -280,6 +291,8 @@ def test_mapping_getitem_w_int():
a = theano._asarray(numpy.random.rand(*dim), dtype='float32')
_a = cuda_ndarray.CudaNdarray(a)
_cmp(numpy.asarray(_a[...]), a[...])
_cmpf(_a,0)
_cmpfV(_a,slice(1))
#TODO: test slice err
#TODO: test tuple err
......@@ -292,6 +305,7 @@ def test_mapping_getitem_w_int():
_cmpf(_a,slice(-1),slice(-1),-10,slice(-1))
_cmpf(_a,0,slice(0,-1,-20),-10)
_cmpf(_a,10)
_cmpf(_a,(10,0,0,0))
_cmpf(_a,-10)
_cmp(numpy.asarray(_a[:,:,::-1, ::-1]), a[:,:,::-1,::-1])
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论