diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-03-13 03:37:36 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-03-13 03:37:36 +0000 |
commit | 67940c3d69c51bae3561695693020ced3d9d470a (patch) | |
tree | 38d928e5ed7af6b6f72858cf76e89a75c8521bbb /numpy/core/src/multiarraymodule.c | |
parent | cda50abbda59616f3794ca748c791a01a6e693a5 (diff) | |
download | numpy-67940c3d69c51bae3561695693020ced3d9d470a.tar.gz |
Fix up oldnumeric.py functions to return intput class where possible. Allow complex-valued arrays in PyArray_Round. Add backward-compatible support for Python2.5 ssize_t changes.
Diffstat (limited to 'numpy/core/src/multiarraymodule.c')
-rw-r--r-- | numpy/core/src/multiarraymodule.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c index d55987959..0d6f2e4b4 100644 --- a/numpy/core/src/multiarraymodule.c +++ b/numpy/core/src/multiarraymodule.c @@ -216,6 +216,39 @@ power_of_ten(int n) static PyObject * PyArray_Round(PyArrayObject *a, int decimals) { + if (PyArray_ISCOMPLEX(a)) { + PyObject *part; + PyObject *round_part; + PyObject *new; + int res; + new = PyArray_Copy(a); + if (new == NULL) return NULL; + + /* new.real = a.real.round(decimals) */ + part = PyObject_GetAttrString(new, "real"); + if (part == NULL) {Py_DECREF(new); return NULL;} + round_part = PyArray_Round\ + ((PyArrayObject *)PyArray_EnsureAnyArray(part), + decimals); + Py_DECREF(part); + if (round_part == NULL) {Py_DECREF(new); return NULL;} + res = PyObject_SetAttrString(new, "real", round_part); + Py_DECREF(round_part); + if (res < 0) {Py_DECREF(new); return NULL;} + + /* new.imag = a.imag.round(decimals) */ + part = PyObject_GetAttrString(new, "imag"); + if (part == NULL) {Py_DECREF(new); return NULL;} + round_part = PyArray_Round\ + ((PyArrayObject *)PyArray_EnsureAnyArray(part), + decimals); + Py_DECREF(part); + if (round_part == NULL) {Py_DECREF(new); return NULL;} + res = PyObject_SetAttrString(new, "imag", round_part); + Py_DECREF(round_part); + if (res < 0) {Py_DECREF(new); return NULL;} + return new; + } /* do the most common case first */ if (decimals == 0) { if (PyArray_ISINTEGER(a)) { |