提交 76884de2 authored 作者: Frederic Bastien's avatar Frederic Bastien

Added test for CudaNdarray.__getitem__ that show a new bug under Ubuntu and fix it.

The bug make the CudaNdarray.__getitem__ return something with the wrong number of dimensions. The bug happen with the param of __getitem__ is a tuple with element that are a numpy.int under Ubuntu(system where PyInt_Check(numpy.int) return false.
上级 c2b2b641
......@@ -1192,7 +1192,9 @@ CudaNdarray_Subscript(PyObject * py_self, PyObject * key)
int rval_nd = self->nd;
for (int d = 0; d < PyTuple_Size(key); ++d)
{
rval_nd -= PyInt_Check(PyTuple_GetItem(key, d));
//On some paltform PyInt_Check(<type 'numpy.int64'>) return true, other it return false.
//So we use PyArray_IsAnyScalar that should covert everything.
rval_nd -= PyArray_IsAnyScalar(PyTuple_GetItem(key, d));
}
//allocate our subtensor view
......@@ -1249,6 +1251,7 @@ CudaNdarray_Subscript(PyObject * py_self, PyObject * key)
}
else if ((intobj=PyNumber_Int(key_d)))
{
assert(PyArray_IsAnyScalar(key_d));
int d_idx = PyInt_AsLong(intobj);
Py_DECREF(intobj);
intobj = NULL;
......
......@@ -293,9 +293,6 @@ def test_mapping_getitem_w_int():
_cmp(numpy.asarray(_a[...]), a[...])
_cmpf(_a,0)
_cmpfV(_a,slice(1))
#TODO: test slice err
#TODO: test tuple err
dim =(5,4,3,2)
a = theano._asarray(numpy.random.rand(*dim), dtype='float32')
......@@ -308,6 +305,21 @@ def test_mapping_getitem_w_int():
_cmpf(_a,(10,0,0,0))
_cmpf(_a,-10)
#test with integer
_cmp(numpy.asarray(_a[1]), a[1])
_cmp(numpy.asarray(_a[-1]), a[-1])
_cmp(numpy.asarray(_a[numpy.int64(1)]), a[numpy.int64(1)])
_cmp(numpy.asarray(_a[numpy.int64(-1)]), a[numpy.int64(-1)])
#test with slice
_cmp(numpy.asarray(_a[1:]), a[1:])
_cmp(numpy.asarray(_a[1:2]), a[1:2])
_cmp(numpy.asarray(_a[-1:1]), a[-1:1])
#test with tuple (mix slice, integer, numpy.int64)
_cmp(numpy.asarray(_a[:,:,::numpy.int64(-1), ::-1]), a[:,:,::-1,::-1])
_cmp(numpy.asarray(_a[:,:,numpy.int64(1),-1]), a[:,:,1,-1])
_cmp(numpy.asarray(_a[:,:,::-1, ::-1]), a[:,:,::-1,::-1])
_cmp(numpy.asarray(_a[:,:,::-10, ::-10]), a[:,:,::-10,::-10])
_cmp(numpy.asarray(_a[:,:,1,-1]), a[:,:,1,-1])
......@@ -316,8 +328,7 @@ def test_mapping_getitem_w_int():
_cmp(numpy.asarray(_a[:,::-20,-1,:]), a[:,::-20,-1,:])
_cmp(numpy.asarray(_a[:,::-2,-1]), a[:,::-2,-1])
_cmp(numpy.asarray(_a[0,::-2,-1]), a[0,::-2,-1])
_cmp(numpy.asarray(_a[1]), a[1])
_cmp(numpy.asarray(_a[-1]), a[-1])
_cmp(numpy.asarray(_a[-1,-1,-1,-2]), a[-1,-1,-1,-2])
_cmp(numpy.asarray(_a[...]), a[...])
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论