summaryrefslogtreecommitdiff
path: root/scipy/base/src/arrayobject.c
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2005-09-14 23:34:12 +0000
committerTravis Oliphant <oliphant@enthought.com>2005-09-14 23:34:12 +0000
commitff01b26fd14c55ff93210190e9bcc42711c5eee2 (patch)
tree8cea61ce2908c40e083f1614bd97f0fbad36ef47 /scipy/base/src/arrayobject.c
parentb48b35f199ec5d54b2ce3334d5ffa96f17fe1a60 (diff)
downloadnumpy-ff01b26fd14c55ff93210190e9bcc42711c5eee2.tar.gz
Added EnsureArray to C-API and used it to clean up some method calls
Diffstat (limited to 'scipy/base/src/arrayobject.c')
-rw-r--r--scipy/base/src/arrayobject.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/scipy/base/src/arrayobject.c b/scipy/base/src/arrayobject.c
index aa23443ed..e4e033389 100644
--- a/scipy/base/src/arrayobject.c
+++ b/scipy/base/src/arrayobject.c
@@ -5179,6 +5179,30 @@ PyArray_FromAny(PyObject *op, PyArray_Typecode *typecode, int min_depth,
requires);
}
+/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0, 0) */
+/* that special cases Arrays and PyArray_Scalars up front */
+/* it also decrefs op if any conversion needs to take place
+ -- so it can be used like PyArray_EnsureArray(some_function(...)) */
+
+static PyObject *
+PyArray_EnsureArray(PyObject *op)
+{
+ PyObject *new;
+
+ if (op == NULL) return NULL;
+
+ if (PyArray_Check(op)) return op;
+
+ if (PyArray_IsScalar(op, Generic)) {
+ new = PyArray_FromScalar(op, NULL);
+ Py_DECREF(op);
+ return new;
+ }
+ new = PyArray_FromAny(op, NULL, 0, 0, 0);
+ Py_DECREF(op);
+ return new;
+}
+
/* These are all compressed into a single API */
/* Deprecated calls -- Use PyArray_FromAny */