summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2013-05-31 16:39:32 +0200
committerSebastian Berg <sebastian@sipsolutions.net>2013-05-31 19:16:02 +0200
commit3a340b0db0e5629543efabdfacd54abf9f4148e7 (patch)
treef06afe9ca06cb82432b5cbf4439b9da059626ce9
parentc51f2549e824f4e8bcee550d993fe6a1ced9cacb (diff)
downloadnumpy-3a340b0db0e5629543efabdfacd54abf9f4148e7.tar.gz
MAINT: Create new function PyArray_IntpFromIndexSequence
This function uses npy_intp to in principle support larger then int sequence lengths.
-rw-r--r--numpy/core/src/multiarray/conversion_utils.c30
-rw-r--r--numpy/core/src/multiarray/conversion_utils.h3
2 files changed, 26 insertions, 7 deletions
diff --git a/numpy/core/src/multiarray/conversion_utils.c b/numpy/core/src/multiarray/conversion_utils.c
index 3ea5957b9..91243d1b7 100644
--- a/numpy/core/src/multiarray/conversion_utils.c
+++ b/numpy/core/src/multiarray/conversion_utils.c
@@ -121,7 +121,7 @@ PyArray_IntpConverter(PyObject *obj, PyArray_Dims *seq)
}
}
seq->len = len;
- nd = PyArray_IntpFromSequence(obj, (npy_intp *)seq->ptr, (int) len);
+ nd = PyArray_IntpFromIndexSequence(obj, (npy_intp *)seq->ptr, len);
if (nd == -1 || nd != len) {
PyDimMem_FREE(seq->ptr);
seq->ptr = NULL;
@@ -828,15 +828,19 @@ PyArray_PyIntAsIntp(PyObject *o)
return (npy_intp) long_value;
}
-/*NUMPY_API
- * PyArray_IntpFromSequence
+
+/*
+ * PyArray_IntpFromIndexSequence
* Returns the number of dimensions or -1 if an error occurred.
- * vals must be large enough to hold maxvals
+ * vals must be large enough to hold maxvals.
+ * Opposed to PyArray_IntpFromSequence it uses and returns npy_intp
+ * for the number of values.
*/
-NPY_NO_EXPORT int
-PyArray_IntpFromSequence(PyObject *seq, npy_intp *vals, int maxvals)
+NPY_NO_EXPORT npy_intp
+PyArray_IntpFromIndexSequence(PyObject *seq, npy_intp *vals, npy_intp maxvals)
{
- int nd, i;
+ Py_ssize_t nd;
+ npy_intp i;
PyObject *op, *err;
/*
@@ -886,6 +890,18 @@ PyArray_IntpFromSequence(PyObject *seq, npy_intp *vals, int maxvals)
return nd;
}
+/*NUMPY_API
+ * PyArray_IntpFromSequence
+ * Returns the number of dimensions or -1 if an error occurred.
+ * vals must be large enough to hold maxvals
+ */
+NPY_NO_EXPORT int
+PyArray_IntpFromSequence(PyObject *seq, npy_intp *vals, int maxvals)
+{
+ return (int)PyArray_IntpFromIndexSequence(seq, vals, (npy_intp)maxvals);
+}
+
+
/**
* WARNING: This flag is a bad idea, but was the only way to both
* 1) Support unpickling legacy pickles with object types.
diff --git a/numpy/core/src/multiarray/conversion_utils.h b/numpy/core/src/multiarray/conversion_utils.h
index baa110e90..cc16cd9c7 100644
--- a/numpy/core/src/multiarray/conversion_utils.h
+++ b/numpy/core/src/multiarray/conversion_utils.h
@@ -25,6 +25,9 @@ PyArray_PyIntAsInt(PyObject *o);
NPY_NO_EXPORT npy_intp
PyArray_PyIntAsIntp(PyObject *o);
+NPY_NO_EXPORT npy_intp
+PyArray_IntpFromIndexSequence(PyObject *seq, npy_intp *vals, npy_intp maxvals);
+
NPY_NO_EXPORT int
PyArray_IntpFromSequence(PyObject *seq, npy_intp *vals, int maxvals);