diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-10-17 21:43:08 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-10-17 21:43:08 +0000 |
commit | 8a142f7dafd5a820190e61e7173de1fde8acee7a (patch) | |
tree | 27f2fa185cab35bd63e4c9b76c3381da29ca66de /numpy/core/src/arrayobject.c | |
parent | 32b16bbd43214d80362530a4c6dfd156dcab6b04 (diff) | |
download | numpy-8a142f7dafd5a820190e61e7173de1fde8acee7a.tar.gz |
Allow ability to reset the string function to the builtin string function.
Diffstat (limited to 'numpy/core/src/arrayobject.c')
-rw-r--r-- | numpy/core/src/arrayobject.c | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index acac4810d..ededf70a0 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -4082,7 +4082,7 @@ dump_data(char **string, int *n, int *max_n, char *data, int nd, } static PyObject * -array_repr_builtin(PyArrayObject *self) +array_repr_builtin(PyArrayObject *self, int repr) { PyObject *ret; char *string; @@ -4095,27 +4095,35 @@ array_repr_builtin(PyArrayObject *self) return NULL; } - n = 6; - sprintf(string, "array("); - + if (repr) { + n = 6; + sprintf(string, "array("); + } + else { + n = 0; + } if (dump_data(&string, &n, &max_n, self->data, self->nd, self->dimensions, self->strides, self) < 0) { _pya_free(string); return NULL; } - if (PyArray_ISEXTENDED(self)) { - char buf[100]; - snprintf(buf, sizeof(buf), "%d", self->descr->elsize); - sprintf(string+n, ", '%c%s')", self->descr->type, buf); - ret = PyString_FromStringAndSize(string, n+6+strlen(buf)); + if (repr) { + if (PyArray_ISEXTENDED(self)) { + char buf[100]; + snprintf(buf, sizeof(buf), "%d", self->descr->elsize); + sprintf(string+n, ", '%c%s')", self->descr->type, buf); + ret = PyString_FromStringAndSize(string, n+6+strlen(buf)); + } + else { + sprintf(string+n, ", '%c')", self->descr->type); + ret = PyString_FromStringAndSize(string, n+6); + } } else { - sprintf(string+n, ", '%c')", self->descr->type); - ret = PyString_FromStringAndSize(string, n+6); + ret = PyString_FromStringAndSize(string, n); } - _pya_free(string); return ret; } @@ -4152,7 +4160,7 @@ array_repr(PyArrayObject *self) PyObject *s, *arglist; if (PyArray_ReprFunction == NULL) { - s = array_repr_builtin(self); + s = array_repr_builtin(self, 1); } else { arglist = Py_BuildValue("(O)", self); s = PyEval_CallObject(PyArray_ReprFunction, arglist); @@ -4167,7 +4175,7 @@ array_str(PyArrayObject *self) PyObject *s, *arglist; if (PyArray_StrFunction == NULL) { - s = array_repr(self); + s = array_repr_builtin(self, 0); } else { arglist = Py_BuildValue("(O)", self); s = PyEval_CallObject(PyArray_StrFunction, arglist); |