提交 3f49e74b authored 作者: Frederic Bastien's avatar Frederic Bastien

Add tp_repr to CudaNdarray. This make DebugMode error print the value instead of…

Add tp_repr to CudaNdarray. This make DebugMode error print the value instead of <CudaNdarray object at 0x7f229c2f6eb0>
上级 709c9440
......@@ -3054,6 +3054,21 @@ static PyGetSetDef CudaNdarray_getset[] = {
{NULL, NULL, NULL, NULL} /* Sentinel */
};
PyObject *CudaNdarray_repr(PyObject *self)
{
CudaNdarray *object = (CudaNdarray *)self;
PyObject * np_object = CudaNdarray_CreateArrayObj(object);
PyObject * str = PyObject_Str((PyObject *) np_object);
char * cstr = PyString_AsString(str);
PyObject * out = PyString_FromFormat("%s%s%s",
"CudaNdarray(",
cstr,
")");
Py_DECREF(str);
Py_DECREF(np_object);
return out;
}
static PyTypeObject CudaNdarrayType =
{
#if PY_MAJOR_VERSION >= 3
......@@ -3070,7 +3085,7 @@ static PyTypeObject CudaNdarrayType =
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
CudaNdarray_repr, /*tp_repr*/
&CudaNdarrayNumberMethods, /*tp_as_number*/
0, /*tp_as_sequence*/
&CudaNdarrayMappingMethods,/*tp_as_mapping*/
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论