提交 a5a3632f authored 作者: Frederic's avatar Frederic

metter error msg and fix potential futur bug.

currently indices_obj and indices are the same, but it can change in the futur.
上级 6e16ef97
...@@ -839,14 +839,14 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){ ...@@ -839,14 +839,14 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){
PyObject * axis_iobj = PyNumber_Long(axis_obj); PyObject * axis_iobj = PyNumber_Long(axis_obj);
if (!axis_iobj) { if (!axis_iobj) {
PyErr_SetString(PyExc_NotImplementedError,"CudaNdarray_TakeFrom: axis must be convertable to a long"); PyErr_SetString(PyExc_NotImplementedError,"CudaNdarray_TakeFrom: axis must be convertable to a long");
Py_DECREF(indices_obj); Py_DECREF(indices);
return NULL; return NULL;
} }
long axis = PyInt_AsLong(axis_iobj); long axis = PyInt_AsLong(axis_iobj);
Py_DECREF(axis_iobj); axis_iobj=NULL; Py_DECREF(axis_iobj); axis_iobj=NULL;
if (axis != 0) { if (axis != 0) {
PyErr_SetString(PyExc_NotImplementedError,"CudaNdarray_TakeFrom: only axis=0 is currently supported"); PyErr_SetString(PyExc_NotImplementedError,"CudaNdarray_TakeFrom: only axis=0 is currently supported");
Py_DECREF(indices_obj); Py_DECREF(indices);
return NULL; return NULL;
} }
...@@ -869,13 +869,13 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){ ...@@ -869,13 +869,13 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){
if (!out) { if (!out) {
out = (CudaNdarray*)CudaNdarray_New(); out = (CudaNdarray*)CudaNdarray_New();
if (!out){ if (!out){
Py_DECREF(indices_obj); Py_DECREF(indices);
free(dims); free(dims);
return NULL; return NULL;
} }
if (CudaNdarray_alloc_contiguous(out, self->nd, dims)) { if (CudaNdarray_alloc_contiguous(out, self->nd, dims)) {
Py_DECREF(out); Py_DECREF(out);
Py_DECREF(indices_obj); Py_DECREF(indices);
free(dims); free(dims);
return NULL; return NULL;
} }
...@@ -887,14 +887,16 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){ ...@@ -887,14 +887,16 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){
if (clipmode_obj) { if (clipmode_obj) {
char * clipmode = PyString_AsString(clipmode_obj); char * clipmode = PyString_AsString(clipmode_obj);
if (! clipmode){ if (! clipmode){
Py_DECREF(indices_obj); Py_DECREF(indices);
Py_DECREF(out); Py_DECREF(out);
free(dims); free(dims);
return NULL; return NULL;
} }
if (strcmp(clipmode, "raise") != 0) { if (strcmp(clipmode, "raise") != 0) {
PyErr_SetString(PyExc_NotImplementedError,"CudaNdarray_TakeFrom: only the raise mode is currently supported"); PyErr_Format(PyExc_NotImplementedError,
Py_DECREF(indices_obj); "CudaNdarray_TakeFrom: only the raise mode is currently supported. Got '%s'",
clipmode);
Py_DECREF(indices);
Py_DECREF(out); Py_DECREF(out);
free(dims); free(dims);
return NULL; return NULL;
...@@ -913,7 +915,7 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){ ...@@ -913,7 +915,7 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){
if (err_var == NULL) { if (err_var == NULL) {
err_var = (int*)device_malloc(sizeof(int)); err_var = (int*)device_malloc(sizeof(int));
if (!err_var) { // PyErr set by device_malloc if (!err_var) { // PyErr set by device_malloc
Py_DECREF(indices_obj); Py_DECREF(indices);
Py_DECREF(out); Py_DECREF(out);
free(dims); free(dims);
return NULL; return NULL;
...@@ -928,7 +930,7 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){ ...@@ -928,7 +930,7 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){
PyErr_Format(PyExc_RuntimeError, PyErr_Format(PyExc_RuntimeError,
"Error setting device error code to 0. %s", "Error setting device error code to 0. %s",
cudaGetErrorString(err)); cudaGetErrorString(err));
Py_DECREF(indices_obj); Py_DECREF(indices);
Py_DECREF(out); Py_DECREF(out);
free(dims); free(dims);
return NULL; return NULL;
...@@ -1025,7 +1027,7 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){ ...@@ -1025,7 +1027,7 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){
"Cuda error: %s: %s.\n", "Cuda error: %s: %s.\n",
"CudaNdarray_TakeFrom", "CudaNdarray_TakeFrom",
cudaGetErrorString(err)); cudaGetErrorString(err));
Py_DECREF(indices_obj); Py_DECREF(indices);
Py_DECREF(out); Py_DECREF(out);
return NULL; return NULL;
} }
...@@ -1040,7 +1042,7 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){ ...@@ -1040,7 +1042,7 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){
"Cuda error: %s: %s when trying to get the error value.\n", "Cuda error: %s: %s when trying to get the error value.\n",
"CudaNdarray_TakeFrom", "CudaNdarray_TakeFrom",
cudaGetErrorString(err)); cudaGetErrorString(err));
Py_DECREF(indices_obj); Py_DECREF(indices);
Py_DECREF(out); Py_DECREF(out);
return NULL; return NULL;
} }
...@@ -1055,17 +1057,17 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){ ...@@ -1055,17 +1057,17 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){
err = cudaMemset((void*)err_var, 0, sizeof(int)); err = cudaMemset((void*)err_var, 0, sizeof(int));
if (cudaSuccess != err) { if (cudaSuccess != err) {
PyErr_Format(PyExc_MemoryError, "Error setting device error code to 0 after having an index error. %s", cudaGetErrorString(err)); PyErr_Format(PyExc_MemoryError, "Error setting device error code to 0 after having an index error. %s", cudaGetErrorString(err));
Py_DECREF(indices_obj); Py_DECREF(indices);
Py_DECREF(out); Py_DECREF(out);
return NULL; return NULL;
} }
Py_DECREF(indices_obj); Py_DECREF(indices);
Py_DECREF(out); Py_DECREF(out);
return NULL; return NULL;
} }
Py_DECREF(indices_obj); Py_DECREF(indices);
if (verbose) printf("TAKE SUCCEDED\n"); if (verbose) printf("TAKE SUCCEDED\n");
return (PyObject *)out; return (PyObject *)out;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论