提交 d778a86c authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Merge pull request #553 from nouiz/msg

Better error msg and test reshape in the not contiguous case.
...@@ -23,6 +23,8 @@ static int g_gpu_context_active = 0; ...@@ -23,6 +23,8 @@ static int g_gpu_context_active = 0;
PyObject * PyObject *
CudaNdarray_Dimshuffle(PyObject* _unused, PyObject* args); CudaNdarray_Dimshuffle(PyObject* _unused, PyObject* args);
static PyObject *CudaNdarray_get_shape(CudaNdarray *self, void *closure);
/** /**
* *
...@@ -701,7 +703,22 @@ PyObject * CudaNdarray_Reshape(CudaNdarray * self, PyObject * shape) ...@@ -701,7 +703,22 @@ PyObject * CudaNdarray_Reshape(CudaNdarray * self, PyObject * shape)
if( cudaSuccess != err) if( cudaSuccess != err)
{ {
Py_DECREF(rval); Py_DECREF(rval);
PyErr_Format(PyExc_RuntimeError, "Cuda error: %s: %s.\n", "k_copy_reshape_rowmajor", cudaGetErrorString(err)); PyObject * shape_inp = CudaNdarray_get_shape(self, NULL);
PyObject * shape_inp2 = PyObject_Str(shape_inp);
PyObject * shape_dest = PyObject_Str(shape);
PyErr_Format(PyExc_RuntimeError,
"Cuda error in CudaNdarray_Reshape"
"()n_blocks=%d, n_threads=%d, input_shape=%s,"
" dest_shape=%s): %s: %s.\n",
n_blocks, threads_per_block,
PyString_AsString(shape_inp2),
PyString_AsString(shape_dest),
"k_copy_reshape_rowmajor",
cudaGetErrorString(err)
);
Py_DECREF(shape_dest);
Py_DECREF(shape_inp);
Py_DECREF(shape_inp2);
free(rval_dims); free(rval_dims);
return NULL; return NULL;
} }
......
...@@ -380,6 +380,22 @@ def test_reshape(): ...@@ -380,6 +380,22 @@ def test_reshape():
assert numpy.all(aa == n_bb) assert numpy.all(aa == n_bb)
# Test the not contiguous case
shape_1_2x = (shape_1[0] * 2,) + shape_1[1:]
a = theano._asarray(rng.randn(*shape_1_2x), dtype='float32')
b = cuda_ndarray.CudaNdarray(a)
a = a[::2]
b = b[::2]
aa = a.reshape(shape_2)
bb = b.reshape(shape_2)
n_bb = numpy.asarray(bb)
#print n_bb
assert numpy.all(aa == n_bb)
def bad_subtest(shape_1, shape_2, rng): def bad_subtest(shape_1, shape_2, rng):
a = theano._asarray(rng.randn(*shape_1), dtype='float32') a = theano._asarray(rng.randn(*shape_1), dtype='float32')
b = cuda_ndarray.CudaNdarray(a) b = cuda_ndarray.CudaNdarray(a)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论