summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wiebe <mwwiebe@gmail.com>2011-01-07 13:23:39 -0800
committerMark Wiebe <mwwiebe@gmail.com>2011-01-09 01:55:04 -0800
commite70ee980900b8535b2387be6a18adfbc32c470bc (patch)
tree19a16c2e31a9ebbb476a251790da6d28300345ab
parenteff3118c9a8b1a08a43a437947f12143bb544ff4 (diff)
downloadnumpy-e70ee980900b8535b2387be6a18adfbc32c470bc.tar.gz
ENH: iter: Add the new iterator to the exposed API
To do this, I also removed the search/replace of 'intp' to 'npy_intp', and did that change manually in a number of files. The NOPREFIX macro-based emulation of C++'s "using namespace" feels a bit off to me anyway.
-rw-r--r--numpy/core/code_generators/genapi.py3
-rw-r--r--numpy/core/code_generators/numpy_api.py35
-rw-r--r--numpy/core/include/numpy/ndarraytypes.h74
-rw-r--r--numpy/core/include/numpy/new_iterator.h172
-rw-r--r--numpy/core/src/multiarray/arrayobject.c43
-rw-r--r--numpy/core/src/multiarray/conversion_utils.c24
-rw-r--r--numpy/core/src/multiarray/ctors.c172
-rw-r--r--numpy/core/src/multiarray/iterators.c70
-rw-r--r--numpy/core/src/multiarray/multiarraymodule.c78
-rw-r--r--numpy/core/src/multiarray/new_iterator.c.src215
-rw-r--r--numpy/core/src/multiarray/new_iterator_pywrap.c4
-rw-r--r--numpy/core/tests/test_new_iterator.py38
12 files changed, 488 insertions, 440 deletions
diff --git a/numpy/core/code_generators/genapi.py b/numpy/core/code_generators/genapi.py
index 5cac71a72..4b7726ab4 100644
--- a/numpy/core/code_generators/genapi.py
+++ b/numpy/core/code_generators/genapi.py
@@ -44,6 +44,7 @@ API_FILES = [join('multiarray', 'methods.c'),
join('multiarray', 'conversion_utils.c'),
join('multiarray', 'buffer.c'),
join('multiarray', 'datetime.c'),
+ join('multiarray', 'new_iterator.c.src'),
join('umath', 'ufunc_object.c'),
join('umath', 'loops.c.src'),
]
@@ -57,7 +58,7 @@ def remove_whitespace(s):
return ''.join(s.split())
def _repl(str):
- return str.replace('intp', 'npy_intp').replace('Bool','npy_bool')
+ return str.replace('Bool','npy_bool')
class Function(object):
def __init__(self, name, return_type, args, doc=''):
diff --git a/numpy/core/code_generators/numpy_api.py b/numpy/core/code_generators/numpy_api.py
index 8b8f4a99a..a5d6def23 100644
--- a/numpy/core/code_generators/numpy_api.py
+++ b/numpy/core/code_generators/numpy_api.py
@@ -253,6 +253,41 @@ multiarray_funcs_api = {
'PyArray_TimedeltaToTimedeltaStruct': 218,
'PyArray_DatetimeStructToDatetime': 219,
'PyArray_TimedeltaStructToTimedelta': 220,
+ # New Iterator API
+ 'NpyIter_New': 223,
+ 'NpyIter_MultiNew': 224,
+ 'NpyIter_Copy': 225,
+ 'NpyIter_Deallocate': 226,
+ 'NpyIter_HasDelayedBufAlloc': 227,
+ 'NpyIter_HasInnerLoop': 228,
+ 'NpyIter_RemoveInnerLoop': 229,
+ 'NpyIter_GetInnerStrideArray': 230,
+ 'NpyIter_GetInnerLoopSizePtr': 231,
+ 'NpyIter_Reset': 232,
+ 'NpyIter_ResetBasePointers': 233,
+ 'NpyIter_ResetToIterIndexRange': 234,
+ 'NpyIter_GetNDim': 235,
+ 'NpyIter_GetNIter': 236,
+ 'NpyIter_GetIterNext': 237,
+ 'NpyIter_GetIterSize': 238,
+ 'NpyIter_GetIterIndexRange': 239,
+ 'NpyIter_GetIterIndex': 240,
+ 'NpyIter_GotoIterIndex': 241,
+ 'NpyIter_HasCoords': 242,
+ 'NpyIter_GetShape': 243,
+ 'NpyIter_GetGetCoords': 244,
+ 'NpyIter_GotoCoords': 245,
+ 'NpyIter_RemoveCoords': 246,
+ 'NpyIter_HasIndex': 247,
+ 'NpyIter_GetIndexPtr': 248,
+ 'NpyIter_GotoIndex': 249,
+ 'NpyIter_GetDataPtrArray': 250,
+ 'NpyIter_GetDescrArray': 251,
+ 'NpyIter_GetObjectArray': 252,
+ 'NpyIter_GetIterView': 253,
+ 'NpyIter_GetReadFlags': 254,
+ 'NpyIter_GetWriteFlags': 255,
+ 'NpyIter_DebugPrint': 256,
}
ufunc_types_api = {
diff --git a/numpy/core/include/numpy/ndarraytypes.h b/numpy/core/include/numpy/ndarraytypes.h
index 5a552b8e6..84a41d558 100644
--- a/numpy/core/include/numpy/ndarraytypes.h
+++ b/numpy/core/include/numpy/ndarraytypes.h
@@ -186,6 +186,20 @@ typedef enum {
NPY_KEEPORDER=2
} NPY_ORDER;
+/* For specifying allowed casting in operations which support it */
+typedef enum {
+ /* Only allow identical types */
+ NPY_NO_CASTING=0,
+ /* Allow identical and byte swapped types */
+ NPY_EQUIV_CASTING=1,
+ /* Only allow safe casts */
+ NPY_SAFE_CASTING=2,
+ /* Allow safe casts or casts within the same kind */
+ NPY_SAME_KIND_CASTING=3,
+ /* Allow any casts */
+ NPY_UNSAFE_CASTING=4
+} NPY_CASTING;
+
typedef enum {
NPY_CLIP=0,
NPY_WRAP=1,
@@ -845,6 +859,66 @@ typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *);
#endif
/*****************************
+ * New iterator object
+ *****************************/
+
+/* The actual structure of the iterator is an internal detail */
+typedef struct NpyIter_InternalOnly NpyIter;
+
+/* Iterator function pointers that may be specialized */
+typedef int (*NpyIter_IterNext_Fn )(NpyIter *iter);
+typedef void (*NpyIter_GetCoords_Fn )(NpyIter *iter,
+ npy_intp *outcoords);
+
+/*** Global flags that may be passed to the iterator constructors ***/
+
+/* Track an index representing C order */
+#define NPY_ITER_C_INDEX 0x00000001
+/* Track an index representing Fortran order */
+#define NPY_ITER_F_INDEX 0x00000002
+/* Track coordinates */
+#define NPY_ITER_COORDS 0x00000004
+/* Let the caller handle the inner loop of iteration */
+#define NPY_ITER_NO_INNER_ITERATION 0x00000008
+/* Convert all the operands to a common data type */
+#define NPY_ITER_COMMON_DTYPE 0x00000010
+/* Enables sub-range iteration */
+#define NPY_ITER_RANGED 0x00000020
+/* Enables buffering */
+#define NPY_ITER_BUFFERED 0x00000040
+/* When buffering is enabled, grows the inner loop if possible */
+#define NPY_ITER_GROWINNER 0x00000080
+/* Delay allocation of buffers until first Reset* call */
+#define NPY_ITER_DELAY_BUFALLOC 0x00000100
+
+/*** Per-operand flags that may be passed to the iterator constructors ***/
+
+/* The operand will be read from and written to */
+#define NPY_ITER_READWRITE 0x00010000
+/* The operand will only be read from */
+#define NPY_ITER_READONLY 0x00020000
+/* The operand will only be written to */
+#define NPY_ITER_WRITEONLY 0x00040000
+/* The operand's data must be in native byte order and aligned */
+#define NPY_ITER_NBO_ALIGNED 0x00080000
+/* The operand may be copied to satisfy requirements */
+#define NPY_ITER_COPY 0x00100000
+/* The operand may be copied with UPDATEIFCOPY to satisfy requirements */
+#define NPY_ITER_UPDATEIFCOPY 0x00200000
+/* Allow writeable operands to have references or pointers */
+#define NPY_ITER_WRITEABLE_REFERENCES 0x00400000
+/* Allocate the operand if it is NULL */
+#define NPY_ITER_ALLOCATE 0x00800000
+/* If an operand is allocated, don't use any subtype */
+#define NPY_ITER_NO_SUBTYPE 0x01000000
+/* Require that the dimension match the iterator dimensions exactly */
+#define NPY_ITER_NO_BROADCAST 0x02000000
+
+#define NPY_ITER_GLOBAL_FLAGS 0x0000ffff
+#define NPY_ITER_PER_OP_FLAGS 0xffff0000
+
+
+/*****************************
* Basic iterator object
*****************************/
diff --git a/numpy/core/include/numpy/new_iterator.h b/numpy/core/include/numpy/new_iterator.h
deleted file mode 100644
index 2d54a31af..000000000
--- a/numpy/core/include/numpy/new_iterator.h
+++ /dev/null
@@ -1,172 +0,0 @@
-#ifndef __NPY_NEW_ITERATOR__
-#define __NPY_NEW_ITERATOR__
-
-#include <Python.h>
-#include <numpy/ndarraytypes.h>
-
-/* The actual structure of the iterator is an internal detail */
-typedef struct NpyIter_InternalOnly NpyIter;
-
-/* Iterator function pointers that may be specialized */
-typedef int (*NpyIter_IterNext_Fn )(NpyIter *iter);
-typedef void (*NpyIter_GetCoords_Fn )(NpyIter *iter,
- npy_intp *outcoords);
-
-/* For specifying allowed casting in operations which support it */
-typedef enum {
- /* Only allow identical types */
- NPY_NO_CASTING=0,
- /* Allow identical and byte swapped types */
- NPY_EQUIV_CASTING=1,
- /* Only allow safe casts */
- NPY_SAFE_CASTING=2,
- /* Allow safe casts or casts within the same kind */
- NPY_SAME_KIND_CASTING=3,
- /* Allow any casts */
- NPY_UNSAFE_CASTING=4
-} NPY_CASTING;
-
-
-/* Allocate a new iterator for one array object */
-NpyIter *
-NpyIter_New(PyArrayObject* op, npy_uint32 flags,
- NPY_ORDER order, NPY_CASTING casting,
- PyArray_Descr* dtype,
- npy_intp a_ndim, npy_intp *axes, npy_intp buffersize);
-
-/* Allocate a new iterator for multiple array objects */
-NpyIter *
-NpyIter_MultiNew(npy_intp niter, PyArrayObject **op_in, npy_uint32 flags,
- NPY_ORDER order, NPY_CASTING casting,
- npy_uint32 *op_flags, PyArray_Descr **op_request_dtypes,
- npy_intp oa_ndim, npy_intp **op_axes, npy_intp buffersize);
-
-/* Makes a copy of the iterator */
-NpyIter *
-NpyIter_Copy(NpyIter *iter);
-
-/* Deallocate an iterator */
-int NpyIter_Deallocate(NpyIter* iter);
-
-/* Whether the buffer allocation is being delayed */
-int NpyIter_HasDelayedBufAlloc(NpyIter *iter);
-
-/* Whether the iterator handles the inner loop */
-int NpyIter_HasInnerLoop(NpyIter *iter);
-/* Removes the inner loop handling (so HasInnerLoop returns false) */
-int NpyIter_RemoveInnerLoop(NpyIter *iter);
-/* Get the array of strides for the inner loop (when HasInnerLoop is false) */
-npy_intp *NpyIter_GetInnerStrideArray(NpyIter *iter);
-/* Get a pointer to the size of the inner loop (when HasInnerLoop is false) */
-npy_intp* NpyIter_GetInnerLoopSizePtr(NpyIter *iter);
-
-/* Resets the iterator to its initial state */
-int NpyIter_Reset(NpyIter *iter);
-/* Resets the iterator to its initial state, with new base data pointers */
-int NpyIter_ResetBasePointers(NpyIter *iter, char **baseptrs);
-/* Resets the iterator to a new iterator index range */
-int NpyIter_ResetToIterIndexRange(NpyIter *iter,
- npy_intp istart, npy_intp iend);
-
-/* Gets the number of dimensions being iterated */
-npy_intp NpyIter_GetNDim(NpyIter *iter);
-/* Gets the number of objects being iterated */
-npy_intp NpyIter_GetNIter(NpyIter *iter);
-
-/* Compute the specialized iteration function for an iterator */
-NpyIter_IterNext_Fn NpyIter_GetIterNext(NpyIter *iter);
-
-/* Gets the number of elements being iterated */
-npy_intp NpyIter_GetIterSize(NpyIter *iter);
-/* Get the range of iteration indices being iterated */
-void NpyIter_GetIterIndexRange(NpyIter *iter,
- npy_intp *istart, npy_intp *iend);
-/* Gets the current iteration index */
-npy_intp NpyIter_GetIterIndex(NpyIter *iter);
-/* Sets the iterator to point at the given iteration index */
-int NpyIter_GotoIterIndex(NpyIter *iter, npy_intp iterindex);
-
-/* Whether the iterator is tracking coordinates */
-int NpyIter_HasCoords(NpyIter *iter);
-/* Gets the broadcast shape (if coords are enabled) */
-int NpyIter_GetShape(NpyIter *iter, npy_intp *outshape);
-/* Compute a specialized getcoords function for the iterator */
-NpyIter_GetCoords_Fn NpyIter_GetGetCoords(NpyIter *iter);
-/* Sets the iterator to point at the coordinates in 'coords' */
-int NpyIter_GotoCoords(NpyIter *iter, npy_intp *coords);
-/* Removes coords support from an iterator */
-int NpyIter_RemoveCoords(NpyIter *iter);
-
-/* Whether the iterator is tracking an index */
-int NpyIter_HasIndex(NpyIter *iter);
-/* Get a pointer to the index, if it is being tracked */
-npy_intp *NpyIter_GetIndexPtr(NpyIter *iter);
-/* Sets the iterator to point at the given index */
-int NpyIter_GotoIndex(NpyIter *iter, npy_intp index);
-
-/* Get the array of data pointers (1 per object being iterated) */
-char **NpyIter_GetDataPtrArray(NpyIter *iter);
-/* Get the array of data type pointers (1 per object being iterated) */
-PyArray_Descr **NpyIter_GetDescrArray(NpyIter *iter);
-/* Get the array of objects being iterated */
-PyArrayObject **NpyIter_GetObjectArray(NpyIter *iter);
-/* Returns a view to the i-th object with the iterator's internal axes */
-PyArrayObject *NpyIter_GetIterView(NpyIter *iter, npy_intp i);
-
-/* Gets an array of read flags (1 per object being iterated) */
-void NpyIter_GetReadFlags(NpyIter *iter, char *outreadflags);
-/* Gets an array of write flags (1 per object being iterated) */
-void NpyIter_GetWriteFlags(NpyIter *iter, char *outwriteflags);
-
-/* For debugging */
-NPY_NO_EXPORT void NpyIter_DebugPrint(NpyIter *iter);
-
-
-/*** Global flags that may be passed to the iterator constructors ***/
-
-/* Track an index representing C order */
-#define NPY_ITER_C_INDEX 0x00000001
-/* Track an index representing Fortran order */
-#define NPY_ITER_F_INDEX 0x00000002
-/* Track coordinates */
-#define NPY_ITER_COORDS 0x00000004
-/* Let the caller handle the inner loop of iteration */
-#define NPY_ITER_NO_INNER_ITERATION 0x00000008
-/* Convert all the operands to a common data type */
-#define NPY_ITER_COMMON_DTYPE 0x00000010
-/* Enables sub-range iteration */
-#define NPY_ITER_RANGED 0x00000020
-/* Enables buffering */
-#define NPY_ITER_BUFFERED 0x00000040
-/* When buffering is enabled, grows the inner loop if possible */
-#define NPY_ITER_GROWINNER 0x00000080
-/* Delay allocation of buffers until first Reset* call */
-#define NPY_ITER_DELAY_BUFALLOC 0x00000100
-
-/*** Per-operand flags that may be passed to the iterator constructors ***/
-
-/* The operand will be read from and written to */
-#define NPY_ITER_READWRITE 0x00010000
-/* The operand will only be read from */
-#define NPY_ITER_READONLY 0x00020000
-/* The operand will only be written to */
-#define NPY_ITER_WRITEONLY 0x00040000
-/* The operand's data must be in native byte order and aligned */
-#define NPY_ITER_NBO_ALIGNED 0x00080000
-/* The operand may be copied to satisfy requirements */
-#define NPY_ITER_COPY 0x00100000
-/* The operand may be copied with UPDATEIFCOPY to satisfy requirements */
-#define NPY_ITER_UPDATEIFCOPY 0x00200000
-/* Allow writeable operands to have references or pointers */
-#define NPY_ITER_WRITEABLE_REFERENCES 0x00400000
-/* Allocate the operand if it is NULL */
-#define NPY_ITER_ALLOCATE 0x00800000
-/* If an operand is allocated, don't use any subtype */
-#define NPY_ITER_NO_SUBTYPE 0x01000000
-/* Require that the dimension match the iterator dimensions exactly */
-#define NPY_ITER_NO_BROADCAST 0x02000000
-
-#define NPY_ITER_GLOBAL_FLAGS 0x0000ffff
-#define NPY_ITER_PER_OP_FLAGS 0xffff0000
-
-#endif
diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c
index 03760d3fa..9860cc2f1 100644
--- a/numpy/core/src/multiarray/arrayobject.c
+++ b/numpy/core/src/multiarray/arrayobject.c
@@ -53,7 +53,7 @@ maintainer email: oliphant.travis@ieee.org
/*NUMPY_API
Compute the size of an array (in number of items)
*/
-NPY_NO_EXPORT intp
+NPY_NO_EXPORT npy_intp
PyArray_Size(PyObject *op)
{
if (PyArray_Check(op)) {
@@ -78,7 +78,7 @@ PyArray_CopyObject(PyArrayObject *dest, PyObject *src_object)
*/
if (dest->descr->type == PyArray_CHARLTR && dest->nd > 0 \
&& PyString_Check(src_object)) {
- intp n_new, n_old;
+ npy_intp n_new, n_old;
char *new_string;
PyObject *tmp;
@@ -216,12 +216,12 @@ array_dealloc(PyArrayObject *self) {
static int
dump_data(char **string, int *n, int *max_n, char *data, int nd,
- intp *dimensions, intp *strides, PyArrayObject* self)
+ npy_intp *dimensions, npy_intp *strides, PyArrayObject* self)
{
PyArray_Descr *descr=self->descr;
PyObject *op, *sp;
char *ostring;
- intp i, N;
+ npy_intp i, N;
#define CHECK_MEMORY do { if (*n >= *max_n-16) { \
*max_n *= 2; \
@@ -444,15 +444,15 @@ _myunincmp(PyArray_UCS4 *s1, PyArray_UCS4 *s2, int len1, int len2)
PyArray_UCS4 *sptr;
PyArray_UCS4 *s1t=s1, *s2t=s2;
int val;
- intp size;
+ npy_intp size;
int diff;
- if ((intp)s1 % sizeof(PyArray_UCS4) != 0) {
+ if ((npy_intp)s1 % sizeof(PyArray_UCS4) != 0) {
size = len1*sizeof(PyArray_UCS4);
s1t = malloc(size);
memcpy(s1t, s1, size);
}
- if ((intp)s2 % sizeof(PyArray_UCS4) != 0) {
+ if ((npy_intp)s2 % sizeof(PyArray_UCS4) != 0) {
size = len2*sizeof(PyArray_UCS4);
s2t = malloc(size);
memcpy(s2t, s2, size);
@@ -658,7 +658,7 @@ _compare_strings(PyObject *result, PyArrayMultiIterObject *multi,
{
PyArrayIterObject *iself, *iother;
Bool *dptr;
- intp size;
+ npy_intp size;
int val;
int N1, N2;
int (*cmpfunc)(void *, void *, int, int);
@@ -827,7 +827,7 @@ _void_compare(PyArrayObject *self, PyArrayObject *other, int cmp_op)
PyObject *key, *value, *temp2;
PyObject *op;
Py_ssize_t pos = 0;
- intp result_ndim = PyArray_NDIM(self) > PyArray_NDIM(other) ?
+ npy_intp result_ndim = PyArray_NDIM(self) > PyArray_NDIM(other) ?
PyArray_NDIM(self) : PyArray_NDIM(other);
op = (cmp_op == Py_EQ ? n_ops.logical_and : n_ops.logical_or);
@@ -863,7 +863,7 @@ _void_compare(PyArrayObject *self, PyArrayObject *other, int cmp_op)
/* If the type was multidimensional, collapse that part to 1-D
*/
if (PyArray_NDIM(temp) != result_ndim+1) {
- intp dimensions[NPY_MAXDIMS];
+ npy_intp dimensions[NPY_MAXDIMS];
PyArray_Dims newdims;
newdims.ptr = dimensions;
@@ -871,7 +871,8 @@ _void_compare(PyArrayObject *self, PyArrayObject *other, int cmp_op)
memcpy(dimensions, PyArray_DIMS(temp),
sizeof(intp)*result_ndim);
dimensions[result_ndim] = -1;
- temp2 = PyArray_Newshape(temp, &newdims, PyArray_ANYORDER);
+ temp2 = PyArray_Newshape((PyArrayObject *)temp,
+ &newdims, PyArray_ANYORDER);
if (temp2 == NULL) {
Py_DECREF(temp);
Py_XDECREF(res);
@@ -1099,7 +1100,7 @@ PyArray_ElementStrides(PyObject *arr)
{
int itemsize = PyArray_ITEMSIZE(arr);
int i, N = PyArray_NDIM(arr);
- intp *strides = PyArray_STRIDES(arr);
+ npy_intp *strides = PyArray_STRIDES(arr);
for (i = 0; i < N; i++) {
if ((strides[i] % itemsize) != 0) {
@@ -1128,13 +1129,13 @@ PyArray_ElementStrides(PyObject *arr)
/*NUMPY_API*/
NPY_NO_EXPORT Bool
-PyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,
- intp *dims, intp *newstrides)
+PyArray_CheckStrides(int elsize, int nd, npy_intp numbytes, npy_intp offset,
+ npy_intp *dims, npy_intp *newstrides)
{
int i;
- intp byte_begin;
- intp begin;
- intp end;
+ npy_intp byte_begin;
+ npy_intp begin;
+ npy_intp end;
if (numbytes == 0) {
numbytes = PyArray_MultiplyList(dims, nd) * elsize;
@@ -1201,7 +1202,7 @@ array_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
}
if (strides.ptr != NULL) {
- intp nb, off;
+ npy_intp nb, off;
if (strides.len != dims.len) {
PyErr_SetString(PyExc_ValueError,
"strides, if given, must be " \
@@ -1215,7 +1216,7 @@ array_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
}
else {
nb = buffer.len;
- off = (intp) offset;
+ off = (npy_intp) offset;
}
@@ -1252,10 +1253,10 @@ array_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
else {
/* buffer given -- use it */
if (dims.len == 1 && dims.ptr[0] == -1) {
- dims.ptr[0] = (buffer.len-(intp)offset) / itemsize;
+ dims.ptr[0] = (buffer.len-(npy_intp)offset) / itemsize;
}
else if ((strides.ptr == NULL) &&
- (buffer.len < (offset + (((intp)itemsize)*
+ (buffer.len < (offset + (((npy_intp)itemsize)*
PyArray_MultiplyList(dims.ptr,
dims.len))))) {
PyErr_SetString(PyExc_TypeError,
diff --git a/numpy/core/src/multiarray/conversion_utils.c b/numpy/core/src/multiarray/conversion_utils.c
index 4ad2e9f51..b6214f38e 100644
--- a/numpy/core/src/multiarray/conversion_utils.c
+++ b/numpy/core/src/multiarray/conversion_utils.c
@@ -115,7 +115,7 @@ PyArray_IntpConverter(PyObject *obj, PyArray_Dims *seq)
}
}
seq->len = len;
- nd = PyArray_IntpFromSequence(obj, (intp *)seq->ptr, len);
+ nd = PyArray_IntpFromSequence(obj, (npy_intp *)seq->ptr, len);
if (nd == -1 || nd != len) {
PyDimMem_FREE(seq->ptr);
seq->ptr = NULL;
@@ -155,7 +155,7 @@ PyArray_BufferConverter(PyObject *obj, PyArray_Chunk *buf)
return PY_FAIL;
}
}
- buf->len = (intp) buflen;
+ buf->len = (npy_intp) buflen;
/* Point to the base of the buffer object if present */
#if defined(NPY_PY3K)
@@ -441,7 +441,7 @@ PyArray_PyIntAsInt(PyObject *o)
}
/*NUMPY_API*/
-NPY_NO_EXPORT intp
+NPY_NO_EXPORT npy_intp
PyArray_PyIntAsIntp(PyObject *o)
{
longlong long_value = -1;
@@ -449,7 +449,7 @@ PyArray_PyIntAsIntp(PyObject *o)
static char *msg = "an integer is required";
PyObject *arr;
PyArray_Descr *descr;
- intp ret;
+ npy_intp ret;
if (!o) {
PyErr_SetString(PyExc_TypeError, msg);
@@ -485,7 +485,7 @@ PyArray_PyIntAsIntp(PyObject *o)
arr = PyArray_FromScalar(o, descr);
}
if (arr != NULL) {
- ret = *((intp *)PyArray_DATA(arr));
+ ret = *((npy_intp *)PyArray_DATA(arr));
Py_DECREF(arr);
return ret;
}
@@ -536,7 +536,7 @@ PyArray_PyIntAsIntp(PyObject *o)
return -1;
}
#endif
- return (intp) long_value;
+ return (npy_intp) long_value;
}
/*NUMPY_API
@@ -545,7 +545,7 @@ PyArray_PyIntAsIntp(PyObject *o)
* vals must be large enough to hold maxvals
*/
NPY_NO_EXPORT int
-PyArray_IntpFromSequence(PyObject *seq, intp *vals, int maxvals)
+PyArray_IntpFromSequence(PyObject *seq, npy_intp *vals, int maxvals)
{
int nd, i;
PyObject *op, *err;
@@ -567,9 +567,9 @@ PyArray_IntpFromSequence(PyObject *seq, intp *vals, int maxvals)
#endif
nd = 1;
#if SIZEOF_LONG >= SIZEOF_INTP
- vals[0] = (intp ) PyInt_AsLong(op);
+ vals[0] = (npy_intp ) PyInt_AsLong(op);
#else
- vals[0] = (intp ) PyLong_AsLongLong(op);
+ vals[0] = (npy_intp ) PyLong_AsLongLong(op);
#endif
Py_DECREF(op);
@@ -596,9 +596,9 @@ PyArray_IntpFromSequence(PyObject *seq, intp *vals, int maxvals)
return -1;
}
#if SIZEOF_LONG >= SIZEOF_INTP
- vals[i]=(intp )PyInt_AsLong(op);
+ vals[i]=(npy_intp )PyInt_AsLong(op);
#else
- vals[i]=(intp )PyLong_AsLongLong(op);
+ vals[i]=(npy_intp )PyLong_AsLongLong(op);
#endif
Py_DECREF(op);
@@ -751,7 +751,7 @@ PyArray_TypestrConvert(int itemsize, int gentype)
PyArray_IntTupleFromIntp
*/
NPY_NO_EXPORT PyObject *
-PyArray_IntTupleFromIntp(int len, intp *vals)
+PyArray_IntTupleFromIntp(int len, npy_intp *vals)
{
int i;
PyObject *intTuple = PyTuple_New(len);
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index ecffb0dc1..b89940e1d 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -206,13 +206,13 @@ fromfile_skip_separator(FILE **fp, const char *sep, void *NPY_UNUSED(stream_data
* Strides are only added if given (because data is given).
*/
static int
-_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims,
- intp *newstrides, int oldnd)
+_update_descr_and_dimensions(PyArray_Descr **des, npy_intp *newdims,
+ npy_intp *newstrides, int oldnd)
{
PyArray_Descr *old;
int newnd;
int numnew;
- intp *mydim;
+ npy_intp *mydim;
int i;
int tuple;
@@ -236,17 +236,17 @@ _update_descr_and_dimensions(PyArray_Descr **des, intp *newdims,
}
if (tuple) {
for (i = 0; i < numnew; i++) {
- mydim[i] = (intp) PyInt_AsLong(
+ mydim[i] = (npy_intp) PyInt_AsLong(
PyTuple_GET_ITEM(old->subarray->shape, i));
}
}
else {
- mydim[0] = (intp) PyInt_AsLong(old->subarray->shape);
+ mydim[0] = (npy_intp) PyInt_AsLong(old->subarray->shape);
}
if (newstrides) {
- intp tempsize;
- intp *mystrides;
+ npy_intp tempsize;
+ npy_intp *mystrides;
mystrides = newstrides + oldnd;
/* Make new strides -- alwasy C-contiguous */
@@ -272,12 +272,12 @@ _update_descr_and_dimensions(PyArray_Descr **des, intp *newdims,
* same for each element
*/
static int
-object_depth_and_dimension(PyObject *s, int max, intp *dims)
+object_depth_and_dimension(PyObject *s, int max, npy_intp *dims)
{
- intp *newdims, *test_dims;
+ npy_intp *newdims, *test_dims;
int nd, test_nd;
int i, islist, istuple;
- intp size;
+ npy_intp size;
PyObject *obj;
islist = PyList_Check(s);
@@ -333,10 +333,10 @@ object_depth_and_dimension(PyObject *s, int max, intp *dims)
}
static void
-_strided_byte_copy(char *dst, intp outstrides, char *src, intp instrides,
- intp N, int elsize)
+_strided_byte_copy(char *dst, npy_intp outstrides, char *src,
+ npy_intp instrides, npy_intp N, int elsize)
{
- intp i, j;
+ npy_intp i, j;
char *tout = dst;
char *tin = src;
@@ -379,10 +379,10 @@ _strided_byte_copy(char *dst, intp outstrides, char *src, intp instrides,
}
static void
-_unaligned_strided_byte_move(char *dst, intp outstrides, char *src,
- intp instrides, intp N, int elsize)
+_unaligned_strided_byte_move(char *dst, npy_intp outstrides, char *src,
+ npy_intp instrides, npy_intp N, int elsize)
{
- intp i;
+ npy_intp i;
char *tout = dst;
char *tin = src;
@@ -414,10 +414,10 @@ _unaligned_strided_byte_move(char *dst, intp outstrides, char *src,
}
NPY_NO_EXPORT void
-_unaligned_strided_byte_copy(char *dst, intp outstrides, char *src,
- intp instrides, intp N, int elsize)
+_unaligned_strided_byte_copy(char *dst, npy_intp outstrides, char *src,
+ npy_intp instrides, npy_intp N, int elsize)
{
- intp i;
+ npy_intp i;
char *tout = dst;
char *tin = src;
@@ -448,7 +448,7 @@ _unaligned_strided_byte_copy(char *dst, intp outstrides, char *src,
}
NPY_NO_EXPORT void
-_strided_byte_swap(void *p, intp stride, intp n, int size)
+_strided_byte_swap(void *p, npy_intp stride, npy_intp n, int size)
{
char *a, *b, c = 0;
int j, m;
@@ -491,18 +491,18 @@ _strided_byte_swap(void *p, intp stride, intp n, int size)
}
NPY_NO_EXPORT void
-byte_swap_vector(void *p, intp n, int size)
+byte_swap_vector(void *p, npy_intp n, int size)
{
- _strided_byte_swap(p, (intp) size, n, size);
+ _strided_byte_swap(p, (npy_intp) size, n, size);
return;
}
/* If numitems > 1, then dst must be contiguous */
NPY_NO_EXPORT void
-copy_and_swap(void *dst, void *src, int itemsize, intp numitems,
- intp srcstrides, int swap)
+copy_and_swap(void *dst, void *src, int itemsize, npy_intp numitems,
+ npy_intp srcstrides, int swap)
{
- intp i;
+ npy_intp i;
char *s1 = (char *)src;
char *d1 = (char *)dst;
@@ -528,8 +528,8 @@ _copy_from0d(PyArrayObject *dest, PyArrayObject *src, int usecopy, int swap)
{
char *aligned = NULL;
char *sptr;
- intp numcopies, nbytes;
- void (*myfunc)(char *, intp, char *, intp, intp, int);
+ npy_intp numcopies, nbytes;
+ void (*myfunc)(char *, npy_intp, char *, npy_intp, npy_intp, int);
int retval = -1;
NPY_BEGIN_THREADS_DEF;
@@ -564,7 +564,7 @@ _copy_from0d(PyArrayObject *dest, PyArrayObject *src, int usecopy, int swap)
if ((dest->nd < 2) || PyArray_ISONESEGMENT(dest)) {
char *dptr;
- intp dstride;
+ npy_intp dstride;
dptr = dest->data;
if (dest->nd == 1) {
@@ -633,11 +633,11 @@ _flat_copyinto(PyObject *dst, PyObject *src, NPY_ORDER order)
{
PyArrayIterObject *it;
PyObject *orig_src;
- void (*myfunc)(char *, intp, char *, intp, intp, int);
+ void (*myfunc)(char *, npy_intp, char *, npy_intp, npy_intp, int);
char *dptr;
int axis;
int elsize;
- intp nbytes;
+ npy_intp nbytes;
NPY_BEGIN_THREADS_DEF;
@@ -706,11 +706,11 @@ _flat_copyinto(PyObject *dst, PyObject *src, NPY_ORDER order)
static int
_copy_from_same_shape(PyArrayObject *dest, PyArrayObject *src,
- void (*myfunc)(char *, intp, char *, intp, intp, int),
- int swap)
+ void (*myfunc)(char *, npy_intp, char *, npy_intp, npy_intp, int),
+ int swap)
{
int maxaxis = -1, elsize;
- intp maxdim;
+ npy_intp maxdim;
PyArrayIterObject *dit, *sit;
NPY_BEGIN_THREADS_DEF;
@@ -756,12 +756,12 @@ _copy_from_same_shape(PyArrayObject *dest, PyArrayObject *src,
static int
_broadcast_copy(PyArrayObject *dest, PyArrayObject *src,
- void (*myfunc)(char *, intp, char *, intp, intp, int),
- int swap)
+ void (*myfunc)(char *, npy_intp, char *, npy_intp, npy_intp, int),
+ int swap)
{
int elsize;
PyArrayMultiIterObject *multi;
- int maxaxis; intp maxdim;
+ int maxaxis; npy_intp maxdim;
NPY_BEGIN_THREADS_DEF;
elsize = PyArray_ITEMSIZE(dest);
@@ -841,7 +841,7 @@ static int
_array_copy_into(PyArrayObject *dest, PyArrayObject *src, int usecopy)
{
int swap;
- void (*myfunc)(char *, intp, char *, intp, intp, int);
+ void (*myfunc)(char *, npy_intp, char *, npy_intp, npy_intp, int);
int simple;
int same;
NPY_BEGIN_THREADS_DEF;
@@ -914,7 +914,7 @@ PyArray_MoveInto(PyArrayObject *dest, PyArrayObject *src)
/* adapted from Numarray */
static int
-setArrayFromSequence(PyArrayObject *a, PyObject *s, int dim, intp offset)
+setArrayFromSequence(PyArrayObject *a, PyObject *s, int dim, npy_intp offset)
{
Py_ssize_t i, slen;
int res = -1;
@@ -1042,7 +1042,7 @@ static PyObject *
ObjectArray_FromNestedList(PyObject *s, PyArray_Descr *typecode, int fortran)
{
int nd;
- intp d[MAX_DIMS];
+ npy_intp d[MAX_DIMS];
PyArrayObject *r;
/* Get the depth and the number of dimensions */
@@ -1218,7 +1218,7 @@ discover_itemsize(PyObject *s, int nd, int *itemsize)
* an array of ndim nd, and determine the size in each dimension
*/
static int
-discover_dimensions(PyObject *s, int nd, intp *d, int check_it)
+discover_dimensions(PyObject *s, int nd, npy_intp *d, int check_it)
{
PyObject *e;
int r, n, i, n_lower;
@@ -1285,7 +1285,7 @@ Array_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,
PyArrayObject *r;
int nd;
int err;
- intp d[MAX_DIMS];
+ npy_intp d[MAX_DIMS];
int stop_at_string;
int stop_at_tuple;
int check_it;
@@ -1367,23 +1367,23 @@ Array_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,
*/
NPY_NO_EXPORT PyObject *
PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
- intp *dims, intp *strides, void *data,
+ npy_intp *dims, npy_intp *strides, void *data,
int flags, PyObject *obj)
{
PyArrayObject *self;
int i;
size_t sd;
- intp largest;
- intp size;
+ npy_intp largest;
+ npy_intp size;
if (descr->subarray) {
PyObject *ret;
- intp newdims[2*MAX_DIMS];
- intp *newstrides = NULL;
- memcpy(newdims, dims, nd*sizeof(intp));
+ npy_intp newdims[2*MAX_DIMS];
+ npy_intp *newstrides = NULL;
+ memcpy(newdims, dims, nd*sizeof(npy_intp));
if (strides) {
newstrides = newdims + MAX_DIMS;
- memcpy(newstrides, strides, nd*sizeof(intp));
+ memcpy(newstrides, strides, nd*sizeof(npy_intp));
}
nd =_update_descr_and_dimensions(&descr, newdims,
newstrides, nd);
@@ -1426,7 +1426,7 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
largest = NPY_MAX_INTP / sd;
for (i = 0; i < nd; i++) {
- intp dim = dims[i];
+ npy_intp dim = dims[i];
if (dim == 0) {
/*
@@ -1484,7 +1484,7 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
goto fail;
}
self->strides = self->dimensions + nd;
- memcpy(self->dimensions, dims, sizeof(intp)*nd);
+ memcpy(self->dimensions, dims, sizeof(npy_intp)*nd);
if (strides == NULL) { /* fill it in */
sd = _array_fill_strides(self->strides, dims, nd, sd,
flags, &(self->flags));
@@ -1494,7 +1494,7 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
* we allow strides even when we create
* the memory, but be careful with this...
*/
- memcpy(self->strides, strides, sizeof(intp)*nd);
+ memcpy(self->strides, strides, sizeof(npy_intp)*nd);
sd *= size;
}
}
@@ -1592,8 +1592,8 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
* Generic new array creation routine.
*/
NPY_NO_EXPORT PyObject *
-PyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,
- intp *strides, void *data, int itemsize, int flags,
+PyArray_New(PyTypeObject *subtype, int nd, npy_intp *dims, int type_num,
+ npy_intp *strides, void *data, int itemsize, int flags,
PyObject *obj)
{
PyArray_Descr *descr;
@@ -2319,7 +2319,7 @@ PyArray_FromInterface(PyObject *input)
if (PyErr_Occurred()) {
PyErr_Clear();
}
- memcpy(ret->strides, strides, n*sizeof(intp));
+ memcpy(ret->strides, strides, n*sizeof(npy_intp));
}
else PyErr_Clear();
PyArray_UpdateFlags(ret, UPDATE_ALL);
@@ -2406,7 +2406,7 @@ PyArray_FromDimsAndDataAndDescr(int nd, int *d,
{
PyObject *ret;
int i;
- intp newd[MAX_DIMS];
+ npy_intp newd[MAX_DIMS];
char msg[] = "PyArray_FromDimsAndDataAndDescr: use PyArray_NewFromDescr.";
if (DEPRECATE(msg) < 0) {
@@ -2415,7 +2415,7 @@ PyArray_FromDimsAndDataAndDescr(int nd, int *d,
if (!PyArray_ISNBO(descr->byteorder))
descr->byteorder = '=';
for (i = 0; i < nd; i++) {
- newd[i] = (intp) d[i];
+ newd[i] = (npy_intp) d[i];
}
ret = PyArray_NewFromDescr(&PyArray_Type, descr,
nd, newd,
@@ -2502,7 +2502,7 @@ PyArray_CopyAnyInto(PyArrayObject *dest, PyArrayObject *src)
{
int elsize, simple;
PyArrayIterObject *idest, *isrc;
- void (*myfunc)(char *, intp, char *, intp, intp, int);
+ void (*myfunc)(char *, npy_intp, char *, npy_intp, npy_intp, int);
NPY_BEGIN_THREADS_DEF;
if (!PyArray_EquivArrTypes(dest, src)) {
@@ -2648,7 +2648,7 @@ PyArray_CheckAxis(PyArrayObject *arr, int *axis, int flags)
* accepts NULL type
*/
NPY_NO_EXPORT PyObject *
-PyArray_Zeros(int nd, intp *dims, PyArray_Descr *type, int fortran)
+PyArray_Zeros(int nd, npy_intp *dims, PyArray_Descr *type, int fortran)
{
PyArrayObject *ret;
@@ -2677,7 +2677,7 @@ PyArray_Zeros(int nd, intp *dims, PyArray_Descr *type, int fortran)
* steals referenct to type
*/
NPY_NO_EXPORT PyObject *
-PyArray_Empty(int nd, intp *dims, PyArray_Descr *type, int fortran)
+PyArray_Empty(int nd, npy_intp *dims, PyArray_Descr *type, int fortran)
{
PyArrayObject *ret;
@@ -2705,7 +2705,7 @@ PyArray_Empty(int nd, intp *dims, PyArray_Descr *type, int fortran)
* Return 0 on success, -1 on failure. In case of failure, set a PyExc_Overflow
* exception
*/
-static int _safe_ceil_to_intp(double value, intp* ret)
+static int _safe_ceil_to_intp(double value, npy_intp* ret)
{
double ivalue;
@@ -2714,7 +2714,7 @@ static int _safe_ceil_to_intp(double value, intp* ret)
return -1;
}
- *ret = (intp)ivalue;
+ *ret = (npy_intp)ivalue;
return 0;
}
@@ -2725,7 +2725,7 @@ static int _safe_ceil_to_intp(double value, intp* ret)
NPY_NO_EXPORT PyObject *
PyArray_Arange(double start, double stop, double step, int type_num)
{
- intp length;
+ npy_intp length;
PyObject *range;
PyArray_ArrFuncs *funcs;
PyObject *obj;
@@ -2790,10 +2790,10 @@ PyArray_Arange(double start, double stop, double step, int type_num)
/*
* the formula is len = (intp) ceil((start - stop) / step);
*/
-static intp
+static npy_intp
_calc_length(PyObject *start, PyObject *stop, PyObject *step, PyObject **next, int cmplx)
{
- intp len, tmp;
+ npy_intp len, tmp;
PyObject *val;
double value;
@@ -2870,7 +2870,7 @@ PyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr
PyObject *range;
PyArray_ArrFuncs *funcs;
PyObject *next, *err;
- intp length;
+ npy_intp length;
PyArray_Descr *native = NULL;
int swap;
@@ -2996,22 +2996,22 @@ PyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr
}
static PyArrayObject *
-array_fromfile_binary(FILE *fp, PyArray_Descr *dtype, intp num, size_t *nread)
+array_fromfile_binary(FILE *fp, PyArray_Descr *dtype, npy_intp num, size_t *nread)
{
PyArrayObject *r;
- intp start, numbytes;
+ npy_intp start, numbytes;
if (num < 0) {
int fail = 0;
- start = (intp )ftell(fp);
+ start = (npy_intp)ftell(fp);
if (start < 0) {
fail = 1;
}
if (fseek(fp, 0, SEEK_END) < 0) {
fail = 1;
}
- numbytes = (intp) ftell(fp);
+ numbytes = (npy_intp) ftell(fp);
if (numbytes < 0) {
fail = 1;
}
@@ -3047,17 +3047,17 @@ array_fromfile_binary(FILE *fp, PyArray_Descr *dtype, intp num, size_t *nread)
*/
#define FROM_BUFFER_SIZE 4096
static PyArrayObject *
-array_from_text(PyArray_Descr *dtype, intp num, char *sep, size_t *nread,
+array_from_text(PyArray_Descr *dtype, npy_intp num, char *sep, size_t *nread,
void *stream, next_element next, skip_separator skip_sep,
void *stream_data)
{
PyArrayObject *r;
- intp i;
+ npy_intp i;
char *dptr, *clean_sep, *tmp;
int err = 0;
- intp thisbuf = 0;
- intp size;
- intp bytes, totalbytes;
+ npy_intp thisbuf = 0;
+ npy_intp size;
+ npy_intp bytes, totalbytes;
size = (num >= 0) ? num : FROM_BUFFER_SIZE;
r = (PyArrayObject *)
@@ -3138,7 +3138,7 @@ array_from_text(PyArray_Descr *dtype, intp num, char *sep, size_t *nread,
* necessary is read by this routine.
*/
NPY_NO_EXPORT PyObject *
-PyArray_FromFile(FILE *fp, PyArray_Descr *dtype, intp num, char *sep)
+PyArray_FromFile(FILE *fp, PyArray_Descr *dtype, npy_intp num, char *sep)
{
PyArrayObject *ret;
size_t nread = 0;
@@ -3173,7 +3173,7 @@ PyArray_FromFile(FILE *fp, PyArray_Descr *dtype, intp num, char *sep)
Py_DECREF(dtype);
return NULL;
}
- if (((intp) nread) < num) {
+ if (((npy_intp) nread) < num) {
/* Realloc memory for smaller number of elements */
const size_t nsize = NPY_MAX(nread,1)*ret->descr->elsize;
char *tmp;
@@ -3191,12 +3191,12 @@ PyArray_FromFile(FILE *fp, PyArray_Descr *dtype, intp num, char *sep)
/*NUMPY_API*/
NPY_NO_EXPORT PyObject *
PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type,
- intp count, intp offset)
+ npy_intp count, npy_intp offset)
{
PyArrayObject *ret;
char *data;
Py_ssize_t ts;
- intp s, n;
+ npy_intp s, n;
int itemsize;
int write = 1;
@@ -3247,15 +3247,15 @@ PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type,
if ((offset < 0) || (offset >= ts)) {
PyErr_Format(PyExc_ValueError,
"offset must be non-negative and smaller than buffer "\
- "lenth (%" INTP_FMT ")", (intp)ts);
+ "lenth (%" INTP_FMT ")", (npy_intp)ts);
Py_DECREF(buf);
Py_DECREF(type);
return NULL;
}
data += offset;
- s = (intp)ts - offset;
- n = (intp)count;
+ s = (npy_intp)ts - offset;
+ n = (npy_intp)count;
itemsize = type->elsize;
if (n < 0 ) {
if (s % itemsize != 0) {
@@ -3320,8 +3320,8 @@ PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type,
* for whitespace around the separator is added.
*/
NPY_NO_EXPORT PyObject *
-PyArray_FromString(char *data, intp slen, PyArray_Descr *dtype,
- intp num, char *sep)
+PyArray_FromString(char *data, npy_intp slen, PyArray_Descr *dtype,
+ npy_intp num, char *sep)
{
int itemsize;
PyArrayObject *ret;
@@ -3407,12 +3407,12 @@ PyArray_FromString(char *data, intp slen, PyArray_Descr *dtype,
* steals a reference to dtype (which cannot be NULL)
*/
NPY_NO_EXPORT PyObject *
-PyArray_FromIter(PyObject *obj, PyArray_Descr *dtype, intp count)
+PyArray_FromIter(PyObject *obj, PyArray_Descr *dtype, npy_intp count)
{
PyObject *value;
PyObject *iter = PyObject_GetIter(obj);
PyArrayObject *ret = NULL;
- intp i, elsize, elcount;
+ npy_intp i, elsize, elcount;
char *item, *new_data;
if (iter == NULL) {
@@ -3521,7 +3521,7 @@ PyArray_FromIter(PyObject *obj, PyArray_Descr *dtype, intp count)
*/
NPY_NO_EXPORT size_t
-_array_fill_strides(intp *strides, intp *dims, int nd, size_t itemsize,
+_array_fill_strides(npy_intp *strides, npy_intp *dims, int nd, size_t itemsize,
int inflag, int *objflags)
{
int i;
diff --git a/numpy/core/src/multiarray/iterators.c b/numpy/core/src/multiarray/iterators.c
index f841006ec..5990f8c3d 100644
--- a/numpy/core/src/multiarray/iterators.c
+++ b/numpy/core/src/multiarray/iterators.c
@@ -20,10 +20,10 @@
#define RubberIndex -2
#define SingleIndex -3
-NPY_NO_EXPORT intp
-parse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)
+NPY_NO_EXPORT npy_intp
+parse_subindex(PyObject *op, npy_intp *step_size, npy_intp *n_steps, npy_intp max)
{
- intp index;
+ npy_intp index;
if (op == Py_None) {
*n_steps = PseudoIndex;
@@ -34,7 +34,7 @@ parse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)
index = 0;
}
else if (PySlice_Check(op)) {
- intp stop;
+ npy_intp stop;
if (slice_GetIndices((PySliceObject *)op, max,
&index, &stop, step_size, n_steps) < 0) {
if (!PyErr_Occurred()) {
@@ -77,11 +77,11 @@ parse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)
NPY_NO_EXPORT int
parse_index(PyArrayObject *self, PyObject *op,
- intp *dimensions, intp *strides, intp *offset_ptr)
+ npy_intp *dimensions, npy_intp *strides, npy_intp *offset_ptr)
{
int i, j, n;
int nd_old, nd_new, n_add, n_pseudo;
- intp n_steps, start, offset, step_size;
+ npy_intp n_steps, start, offset, step_size;
PyObject *op1 = NULL;
int is_slice;
@@ -180,7 +180,7 @@ parse_index(PyArrayObject *self, PyObject *op,
}
static int
-slice_coerce_index(PyObject *o, intp *v)
+slice_coerce_index(PyObject *o, npy_intp *v)
{
*v = PyArray_PyIntAsIntp(o);
if (error_converting(*v)) {
@@ -193,11 +193,11 @@ slice_coerce_index(PyObject *o, intp *v)
/* This is basically PySlice_GetIndicesEx, but with our coercion
* of indices to integers (plus, that function is new in Python 2.3) */
NPY_NO_EXPORT int
-slice_GetIndices(PySliceObject *r, intp length,
- intp *start, intp *stop, intp *step,
- intp *slicelength)
+slice_GetIndices(PySliceObject *r, npy_intp length,
+ npy_intp *start, npy_intp *stop, npy_intp *step,
+ npy_intp *slicelength)
{
- intp defstop;
+ npy_intp defstop;
if (r->step == Py_None) {
*step = 1;
@@ -363,7 +363,7 @@ PyArray_IterNew(PyObject *obj)
* Get Iterator broadcast to a particular shape
*/
NPY_NO_EXPORT PyObject *
-PyArray_BroadcastToShape(PyObject *obj, intp *dims, int nd)
+PyArray_BroadcastToShape(PyObject *obj, npy_intp *dims, int nd)
{
PyArrayIterObject *it;
int i, diff, j, compat, k;
@@ -451,7 +451,7 @@ PyArray_IterAllButAxis(PyObject *obj, int *inaxis)
}
if (*inaxis < 0) {
int i, minaxis = 0;
- intp minstride = 0;
+ npy_intp minstride = 0;
i = 0;
while (minstride == 0 && i < PyArray_NDIM(obj)) {
minstride = PyArray_STRIDE(obj,i);
@@ -496,8 +496,8 @@ PyArray_RemoveSmallest(PyArrayMultiIterObject *multi)
PyArrayIterObject *it;
int i, j;
int axis;
- intp smallest;
- intp sumstrides[NPY_MAXDIMS];
+ npy_intp smallest;
+ npy_intp sumstrides[NPY_MAXDIMS];
if (multi->nd == 0) {
return -1;
@@ -562,9 +562,9 @@ iter_length(PyArrayIterObject *self)
static PyObject *
iter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)
{
- intp index, strides;
+ npy_intp index, strides;
int itemsize;
- intp count = 0;
+ npy_intp count = 0;
char *dptr, *optr;
PyObject *r;
int swap;
@@ -623,18 +623,18 @@ iter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)
static PyObject *
iter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)
{
- intp num;
+ npy_intp num;
PyObject *r;
PyArrayIterObject *ind_it;
int itemsize;
int swap;
char *optr;
- intp index;
+ npy_intp index;
PyArray_CopySwapFunc *copyswap;
itemsize = self->ao->descr->elsize;
if (ind->nd == 0) {
- num = *((intp *)ind->data);
+ num = *((npy_intp *)ind->data);
if (num < 0) {
num += self->size;
}
@@ -671,7 +671,7 @@ iter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)
copyswap = PyArray_DESCR(r)->f->copyswap;
swap = (PyArray_ISNOTSWAPPED(r) != PyArray_ISNOTSWAPPED(self->ao));
while (index--) {
- num = *((intp *)(ind_it->dataptr));
+ num = *((npy_intp *)(ind_it->dataptr));
if (num < 0) {
num += self->size;
}
@@ -700,8 +700,8 @@ NPY_NO_EXPORT PyObject *
iter_subscript(PyArrayIterObject *self, PyObject *ind)
{
PyArray_Descr *indtype = NULL;
- intp start, step_size;
- intp n_steps;
+ npy_intp start, step_size;
+ npy_intp n_steps;
PyObject *r;
char *dptr;
int size;
@@ -739,7 +739,7 @@ iter_subscript(PyArrayIterObject *self, PyObject *ind)
return PyArray_ToScalar(self->dataptr, self->ao);
}
else { /* empty array */
- intp ii = 0;
+ npy_intp ii = 0;
Py_INCREF(self->ao->descr);
r = PyArray_NewFromDescr(Py_TYPE(self->ao),
self->ao->descr,
@@ -848,7 +848,7 @@ static int
iter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,
PyArrayIterObject *val, int swap)
{
- intp index, strides;
+ npy_intp index, strides;
char *dptr;
PyArray_CopySwapFunc *copyswap;
@@ -890,15 +890,15 @@ iter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,
PyArrayIterObject *val, int swap)
{
PyArray_Descr *typecode;
- intp num;
+ npy_intp num;
PyArrayIterObject *ind_it;
- intp index;
+ npy_intp index;
PyArray_CopySwapFunc *copyswap;
typecode = self->ao->descr;
copyswap = self->ao->descr->f->copyswap;
if (ind->nd == 0) {
- num = *((intp *)ind->data);
+ num = *((npy_intp *)ind->data);
PyArray_ITER_GOTO1D(self, num);
copyswap(self->dataptr, val->dataptr, swap, self->ao);
return 0;
@@ -909,7 +909,7 @@ iter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,
}
index = ind_it->size;
while (index--) {
- num = *((intp *)(ind_it->dataptr));
+ num = *((npy_intp *)(ind_it->dataptr));
if (num < 0) {
num += self->size;
}
@@ -941,8 +941,8 @@ iter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)
PyArray_Descr *type;
PyArray_Descr *indtype = NULL;
int swap, retval = -1;
- intp start, step_size;
- intp n_steps;
+ npy_intp start, step_size;
+ npy_intp n_steps;
PyObject *obj = NULL;
PyArray_CopySwapFunc *copyswap;
@@ -1122,7 +1122,7 @@ iter_array(PyArrayIterObject *it, PyObject *NPY_UNUSED(op))
{
PyObject *r;
- intp size;
+ npy_intp size;
/* Any argument ignored */
@@ -1226,7 +1226,7 @@ iter_coords_get(PyArrayIterObject *self)
* coordinates not kept track of ---
* need to generate from index
*/
- intp val;
+ npy_intp val;
int i;
val = self->index;
for (i = 0; i < nd; i++) {
@@ -1321,7 +1321,7 @@ NPY_NO_EXPORT int
PyArray_Broadcast(PyArrayMultiIterObject *mit)
{
int i, nd, k, j;
- intp tmp;
+ npy_intp tmp;
PyArrayIterObject *it;
/* Discover the broadcast number of dimensions */
@@ -1944,7 +1944,7 @@ get_ptr_circular(PyArrayIterObject* _iter, npy_intp *coordinates)
* A Neighborhood Iterator object.
*/
NPY_NO_EXPORT PyObject*
-PyArray_NeighborhoodIterNew(PyArrayIterObject *x, intp *bounds,
+PyArray_NeighborhoodIterNew(PyArrayIterObject *x, npy_intp *bounds,
int mode, PyArrayObject* fill)
{
int i;
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c
index 04178f571..95dc98e52 100644
--- a/numpy/core/src/multiarray/multiarraymodule.c
+++ b/numpy/core/src/multiarray/multiarraymodule.c
@@ -85,10 +85,10 @@ PyArray_MultiplyIntList(int *l1, int n)
/*NUMPY_API
* Multiply a List
*/
-NPY_NO_EXPORT intp
-PyArray_MultiplyList(intp *l1, int n)
+NPY_NO_EXPORT npy_intp
+PyArray_MultiplyList(npy_intp *l1, int n)
{
- intp s = 1;
+ npy_intp s = 1;
while (n--) {
s *= (*l1++);
@@ -99,15 +99,15 @@ PyArray_MultiplyList(intp *l1, int n)
/*NUMPY_API
* Multiply a List of Non-negative numbers with over-flow detection.
*/
-NPY_NO_EXPORT intp
-PyArray_OverflowMultiplyList(intp *l1, int n)
+NPY_NO_EXPORT npy_intp
+PyArray_OverflowMultiplyList(npy_intp *l1, int n)
{
- intp prod = 1;
- intp imax = NPY_MAX_INTP;
+ npy_intp prod = 1;
+ npy_intp imax = NPY_MAX_INTP;
int i;
for (i = 0; i < n; i++) {
- intp dim = l1[i];
+ npy_intp dim = l1[i];
if (dim == 0) {
return 0;
@@ -125,10 +125,10 @@ PyArray_OverflowMultiplyList(intp *l1, int n)
* Produce a pointer into array
*/
NPY_NO_EXPORT void *
-PyArray_GetPtr(PyArrayObject *obj, intp* ind)
+PyArray_GetPtr(PyArrayObject *obj, npy_intp* ind)
{
int n = obj->nd;
- intp *strides = obj->strides;
+ npy_intp *strides = obj->strides;
char *dptr = obj->data;
while (n--) {
@@ -141,7 +141,7 @@ PyArray_GetPtr(PyArrayObject *obj, intp* ind)
* Compare Lists
*/
NPY_NO_EXPORT int
-PyArray_CompareLists(intp *l1, intp *l2, int n)
+PyArray_CompareLists(npy_intp *l1, npy_intp *l2, int n)
{
int i;
@@ -168,11 +168,11 @@ PyArray_CompareLists(intp *l1, intp *l2, int n)
* steals a reference to typedescr -- can be NULL
*/
NPY_NO_EXPORT int
-PyArray_AsCArray(PyObject **op, void *ptr, intp *dims, int nd,
+PyArray_AsCArray(PyObject **op, void *ptr, npy_intp *dims, int nd,
PyArray_Descr* typedescr)
{
PyArrayObject *ap;
- intp n, m, i, j;
+ npy_intp n, m, i, j;
char **ptr2;
char ***ptr3;
@@ -216,7 +216,7 @@ PyArray_AsCArray(PyObject **op, void *ptr, intp *dims, int nd,
}
*((char ****)ptr) = ptr3;
}
- memcpy(dims, ap->dimensions, nd*sizeof(intp));
+ memcpy(dims, ap->dimensions, nd*sizeof(npy_intp));
*op = (PyObject *)ap;
return 0;
@@ -233,7 +233,7 @@ PyArray_AsCArray(PyObject **op, void *ptr, intp *dims, int nd,
NPY_NO_EXPORT int
PyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode)
{
- intp newd1;
+ npy_intp newd1;
PyArray_Descr *descr;
char msg[] = "PyArray_As1D: use PyArray_AsCArray.";
@@ -254,7 +254,7 @@ PyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode)
NPY_NO_EXPORT int
PyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int typecode)
{
- intp newdims[2];
+ npy_intp newdims[2];
PyArray_Descr *descr;
char msg[] = "PyArray_As1D: use PyArray_AsCArray.";
@@ -348,7 +348,7 @@ PyArray_Concatenate(PyObject *op, int axis)
char *data;
PyTypeObject *subtype;
double prior1, prior2;
- intp numbytes;
+ npy_intp numbytes;
n = PySequence_Length(op);
if (n == -1) {
@@ -580,7 +580,7 @@ PyArray_CanCoerceScalar(int thistype, int neededtype,
*/
static PyArrayObject *
new_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2,
- int nd, intp dimensions[], int typenum)
+ int nd, npy_intp dimensions[], int typenum)
{
PyArrayObject *ret;
PyTypeObject *subtype;
@@ -616,11 +616,11 @@ PyArray_InnerProduct(PyObject *op1, PyObject *op2)
{
PyArrayObject *ap1, *ap2, *ret = NULL;
PyArrayIterObject *it1, *it2;
- intp i, j, l;
+ npy_intp i, j, l;
int typenum, nd, axis;
- intp is1, is2, os;
+ npy_intp is1, is2, os;
char *op;
- intp dimensions[MAX_DIMS];
+ npy_intp dimensions[MAX_DIMS];
PyArray_DotFunc *dot;
PyArray_Descr *typec;
NPY_BEGIN_THREADS_DEF;
@@ -724,11 +724,11 @@ PyArray_MatrixProduct(PyObject *op1, PyObject *op2)
{
PyArrayObject *ap1, *ap2, *ret = NULL;
PyArrayIterObject *it1, *it2;
- intp i, j, l;
+ npy_intp i, j, l;
int typenum, nd, axis, matchDim;
- intp is1, is2, os;
+ npy_intp is1, is2, os;
char *op;
- intp dimensions[MAX_DIMS];
+ npy_intp dimensions[MAX_DIMS];
PyArray_DotFunc *dot;
PyArray_Descr *typec;
NPY_BEGIN_THREADS_DEF;
@@ -854,8 +854,8 @@ PyArray_CopyAndTranspose(PyObject *op)
{
PyObject *ret, *arr;
int nd;
- intp dims[2];
- intp i,j;
+ npy_intp dims[2];
+ npy_intp i,j;
int elsize, str2;
char *iptr;
char *optr;
@@ -921,9 +921,9 @@ _pyarray_correlate(PyArrayObject *ap1, PyArrayObject *ap2, int typenum,
int mode, int *inverted)
{
PyArrayObject *ret;
- intp length;
- intp i, n1, n2, n, n_left, n_right;
- intp is1, is2, os;
+ npy_intp length;
+ npy_intp i, n1, n2, n, n_left, n_right;
+ npy_intp is1, is2, os;
char *ip1, *ip2, *op;
PyArray_DotFunc *dot;
@@ -952,7 +952,7 @@ _pyarray_correlate(PyArrayObject *ap1, PyArrayObject *ap2, int typenum,
n_left = n_right = 0;
break;
case 1:
- n_left = (intp)(n/2);
+ n_left = (npy_intp)(n/2);
n_right = n - n_left - 1;
break;
case 2:
@@ -1026,11 +1026,11 @@ clean_ret:
static int
_pyarray_revert(PyArrayObject *ret)
{
- intp length;
- intp i;
+ npy_intp length;
+ npy_intp i;
PyArray_CopySwapFunc *copyswap;
char *tmp = NULL, *sw1, *sw2;
- intp os;
+ npy_intp os;
char *op;
length = ret->dimensions[0];
@@ -1456,8 +1456,8 @@ PyArray_EquivTypenums(int typenum1, int typenum2)
static PyObject *
_prepend_ones(PyArrayObject *arr, int nd, int ndmin)
{
- intp newdims[MAX_DIMS];
- intp newstrides[MAX_DIMS];
+ npy_intp newdims[MAX_DIMS];
+ npy_intp newstrides[MAX_DIMS];
int i, k, num;
PyObject *ret;
@@ -1737,7 +1737,7 @@ array_fromstring(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *keywds
Py_XDECREF(descr);
return NULL;
}
- return PyArray_FromString(data, (intp)s, descr, (intp)nin, sep);
+ return PyArray_FromString(data, (npy_intp)s, descr, (npy_intp)nin, sep);
}
@@ -1778,7 +1778,7 @@ array_fromfile(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *keywds)
if (type == NULL) {
type = PyArray_DescrFromType(PyArray_DEFAULT);
}
- ret = PyArray_FromFile(fp, type, (intp) nin, sep);
+ ret = PyArray_FromFile(fp, type, (npy_intp) nin, sep);
ok = npy_PyFile_DupClose(file, fp);
Py_DECREF(file);
if (ok < 0) {
@@ -1802,7 +1802,7 @@ array_fromiter(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *keywds)
Py_XDECREF(descr);
return NULL;
}
- return PyArray_FromIter(iter, descr, (intp)nin);
+ return PyArray_FromIter(iter, descr, (npy_intp)nin);
}
static PyObject *
@@ -1822,7 +1822,7 @@ array_frombuffer(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *keywds
if (type == NULL) {
type = PyArray_DescrFromType(PyArray_DEFAULT);
}
- return PyArray_FromBuffer(obj, type, (intp)nin, (intp)offset);
+ return PyArray_FromBuffer(obj, type, (npy_intp)nin, (npy_intp)offset);
}
static PyObject *
diff --git a/numpy/core/src/multiarray/new_iterator.c.src b/numpy/core/src/multiarray/new_iterator.c.src
index 4eaf6518e..154706ec9 100644
--- a/numpy/core/src/multiarray/new_iterator.c.src
+++ b/numpy/core/src/multiarray/new_iterator.c.src
@@ -5,7 +5,6 @@
#define _MULTIARRAYMODULE
#include <numpy/ndarrayobject.h>
-#include <numpy/new_iterator.h>
#include "lowlevel_strided_loops.h"
/* Rounds up a number of bytes to be divisible by sizeof intp */
@@ -301,8 +300,10 @@ npyiter_copy_from_buffers(NpyIter *iter);
static void
npyiter_copy_to_buffers(NpyIter *iter);
-/* The constructor for an iterator over multiple objects */
-NpyIter *
+/*NUMPY_API
+ * Allocate a new iterator for multiple array objects
+ */
+NPY_NO_EXPORT NpyIter *
NpyIter_MultiNew(npy_intp niter, PyArrayObject **op_in, npy_uint32 flags,
NPY_ORDER order, NPY_CASTING casting,
npy_uint32 *op_flags,
@@ -585,8 +586,10 @@ NpyIter_MultiNew(npy_intp niter, PyArrayObject **op_in, npy_uint32 flags,
return iter;
}
-/* The constructor for an iterator over one object */
-NpyIter *
+/*NUMPY_API
+ * Allocate a new iterator for one array object
+ */
+NPY_NO_EXPORT NpyIter *
NpyIter_New(PyArrayObject *op, npy_uint32 flags,
NPY_ORDER order, NPY_CASTING casting,
PyArray_Descr* dtype,
@@ -608,7 +611,10 @@ NpyIter_New(PyArrayObject *op, npy_uint32 flags,
}
}
-NpyIter *
+/*NUMPY_API
+ * Makes a copy of the iterator
+ */
+NPY_NO_EXPORT NpyIter *
NpyIter_Copy(NpyIter *iter)
{
npy_uint32 itflags = NIT_ITFLAGS(iter);
@@ -708,7 +714,11 @@ NpyIter_Copy(NpyIter *iter)
return newiter;
}
-int NpyIter_Deallocate(NpyIter *iter)
+/*NUMPY_API
+ * Deallocate an iterator
+ */
+NPY_NO_EXPORT int
+NpyIter_Deallocate(NpyIter *iter)
{
npy_uint32 itflags = NIT_ITFLAGS(iter);
npy_intp ndim = NIT_NDIM(iter);
@@ -758,8 +768,11 @@ int NpyIter_Deallocate(NpyIter *iter)
return NPY_SUCCEED;
}
-/* Removes coords support from the iterator */
-int NpyIter_RemoveCoords(NpyIter *iter)
+/*NUMPY_API
+ * Removes coords support from an iterator
+ */
+NPY_NO_EXPORT int
+NpyIter_RemoveCoords(NpyIter *iter)
{
npy_uint32 itflags;
@@ -777,8 +790,11 @@ int NpyIter_RemoveCoords(NpyIter *iter)
return NPY_SUCCEED;
}
-/* Removes the inner loop handling (adds NPY_ITER_NO_INNER_ITERATION) */
-int NpyIter_RemoveInnerLoop(NpyIter *iter)
+/*NUMPY_API
+ * Removes the inner loop handling (so HasInnerLoop returns false)
+ */
+NPY_NO_EXPORT int
+NpyIter_RemoveInnerLoop(NpyIter *iter)
{
npy_uint32 itflags = NIT_ITFLAGS(iter);
npy_intp ndim = NIT_NDIM(iter);
@@ -819,8 +835,11 @@ int NpyIter_RemoveInnerLoop(NpyIter *iter)
return NpyIter_Reset(iter);
}
-/* Resets the iterator to its initial state */
-int NpyIter_Reset(NpyIter *iter)
+/*NUMPY_API
+ * Resets the iterator to its initial state
+ */
+NPY_NO_EXPORT int
+NpyIter_Reset(NpyIter *iter)
{
npy_uint32 itflags = NIT_ITFLAGS(iter);
npy_intp ndim = NIT_NDIM(iter);
@@ -863,8 +882,11 @@ int NpyIter_Reset(NpyIter *iter)
return NPY_SUCCEED;
}
-/* Resets the iterator to its initial state, with new base data pointers */
-int NpyIter_ResetBasePointers(NpyIter *iter, char **baseptrs)
+/*NUMPY_API
+ * Resets the iterator to its initial state, with new base data pointers
+ */
+NPY_NO_EXPORT int
+NpyIter_ResetBasePointers(NpyIter *iter, char **baseptrs)
{
npy_uint32 itflags = NIT_ITFLAGS(iter);
npy_intp ndim = NIT_NDIM(iter);
@@ -902,8 +924,10 @@ int NpyIter_ResetBasePointers(NpyIter *iter, char **baseptrs)
return NPY_SUCCEED;
}
-/* Resets the iterator to a new iterator index range */
-int
+/*NUMPY_API
+ * Resets the iterator to a new iterator index range
+ */
+NPY_NO_EXPORT int
NpyIter_ResetToIterIndexRange(NpyIter *iter,
npy_intp istart, npy_intp iend)
{
@@ -937,7 +961,7 @@ NpyIter_ResetToIterIndexRange(NpyIter *iter,
return NpyIter_Reset(iter);
}
-/*
+/*NUMPY_API
* Sets the iterator to the specified coordinates, which must have the
* correct number of entries for 'ndim'. It is only valid
* when NPY_ITER_COORDS was passed to the constructor. This operation
@@ -945,7 +969,8 @@ NpyIter_ResetToIterIndexRange(NpyIter *iter,
*
* Returns NPY_SUCCEED on success, NPY_FAIL on failure.
*/
-int NpyIter_GotoCoords(NpyIter *iter, npy_intp *coords)
+NPY_NO_EXPORT int
+NpyIter_GotoCoords(NpyIter *iter, npy_intp *coords)
{
npy_uint32 itflags = NIT_ITFLAGS(iter);
npy_intp idim, ndim = NIT_NDIM(iter);
@@ -1023,13 +1048,14 @@ int NpyIter_GotoCoords(NpyIter *iter, npy_intp *coords)
return NPY_SUCCEED;
}
-/*
+/*NUMPY_API
* If the iterator is tracking an index, sets the iterator
* to the specified index.
*
* Returns NPY_SUCCEED on success, NPY_FAIL on failure.
*/
-int NpyIter_GotoIndex(NpyIter *iter, npy_intp index)
+NPY_NO_EXPORT int
+NpyIter_GotoIndex(NpyIter *iter, npy_intp index)
{
npy_uint32 itflags = NIT_ITFLAGS(iter);
npy_intp idim, ndim = NIT_NDIM(iter);
@@ -1110,13 +1136,14 @@ int NpyIter_GotoIndex(NpyIter *iter, npy_intp index)
return NPY_SUCCEED;
}
-/*
+/*NUMPY_API
* Sets the iterator position to the specified iterindex,
* which matches the iteration order of the iterator.
*
* Returns NPY_SUCCEED on success, NPY_FAIL on failure.
*/
-int NpyIter_GotoIterIndex(NpyIter *iter, npy_intp iterindex)
+NPY_NO_EXPORT int
+NpyIter_GotoIterIndex(NpyIter *iter, npy_intp iterindex)
{
npy_uint32 itflags = NIT_ITFLAGS(iter);
npy_intp ndim = NIT_NDIM(iter);
@@ -1175,7 +1202,11 @@ int NpyIter_GotoIterIndex(NpyIter *iter, npy_intp iterindex)
return NPY_SUCCEED;
}
-npy_intp NpyIter_GetIterIndex(NpyIter *iter)
+/*NUMPY_API
+ * Gets the current iteration index
+ */
+NPY_NO_EXPORT npy_intp
+NpyIter_GetIterIndex(NpyIter *iter)
{
npy_uint32 itflags = NIT_ITFLAGS(iter);
npy_intp idim, ndim = NIT_NDIM(iter);
@@ -1225,7 +1256,7 @@ npy_intp NpyIter_GetIterIndex(NpyIter *iter)
*/
/* Specialized iternext (@const_itflags@,@tag_ndim@,@tag_niter@) */
-NPY_NO_EXPORT int
+static int
npyiter_iternext_itflags@tag_itflags@_dims@tag_ndim@_iters@tag_niter@(
NpyIter *iter)
{
@@ -1374,7 +1405,7 @@ npyiter_iternext_itflags@tag_itflags@_dims@tag_ndim@_iters@tag_niter@(
/**end repeat**/
/* iternext function that handle the buffering part */
-NPY_NO_EXPORT int
+static int
npyiter_buffered_iternext(NpyIter *iter)
{
npy_uint32 itflags = NIT_ITFLAGS(iter);
@@ -1429,14 +1460,17 @@ npyiter_buffered_iternext(NpyIter *iter)
/**end repeat**/
/* Specialization of iternext for when the iteration size is 1 */
-NPY_NO_EXPORT int
+static int
npyiter_iternext_sizeone(NpyIter *iter)
{
return 0;
}
-/* Returns a specialized iternext function */
-NpyIter_IterNext_Fn NpyIter_GetIterNext(NpyIter *iter)
+/*NUMPY_API
+ * Compute the specialized iteration function for an iterator
+ */
+NPY_NO_EXPORT NpyIter_IterNext_Fn
+NpyIter_GetIterNext(NpyIter *iter)
{
npy_uint32 itflags = NIT_ITFLAGS(iter);
npy_intp ndim = NIT_NDIM(iter);
@@ -1542,7 +1576,7 @@ NpyIter_IterNext_Fn NpyIter_GetIterNext(NpyIter *iter)
* #tag_itflags = 0, IND, IDP, INDuIDP, NEGP, INDuNEGP,
* BUF, INDuBUF, IDPuBUF, INDuIDPuBUF, NEGPuBUF, INDuNEGPuBUF#
*/
-NPY_NO_EXPORT void
+static void
npyiter_getcoord_itflags@tag_itflags@(NpyIter *iter, npy_intp *outcoord)
{
const npy_uint32 itflags = @const_itflags@;
@@ -1583,8 +1617,11 @@ npyiter_getcoord_itflags@tag_itflags@(NpyIter *iter, npy_intp *outcoord)
}
/**end repeat**/
-/* Returns a specialized getcoord function */
-NpyIter_GetCoords_Fn NpyIter_GetGetCoords(NpyIter *iter)
+/*NUMPY_API
+ * Compute a specialized getcoords function for the iterator
+ */
+NPY_NO_EXPORT NpyIter_GetCoords_Fn
+NpyIter_GetGetCoords(NpyIter *iter)
{
npy_uint32 itflags = NIT_ITFLAGS(iter);
npy_intp ndim = NIT_NDIM(iter);
@@ -1647,42 +1684,73 @@ NpyIter_GetCoords_Fn NpyIter_GetGetCoords(NpyIter *iter)
}
-int NpyIter_HasDelayedBufAlloc(NpyIter *iter)
+/*NUMPY_API
+ * Whether the buffer allocation is being delayed
+ */
+NPY_NO_EXPORT int
+NpyIter_HasDelayedBufAlloc(NpyIter *iter)
{
return (NIT_ITFLAGS(iter)&NPY_ITFLAG_DELAYBUF) != 0;
}
-int NpyIter_HasInnerLoop(NpyIter *iter)
+/*NUMPY_API
+ * Whether the iterator handles the inner loop
+ */
+NPY_NO_EXPORT int
+NpyIter_HasInnerLoop(NpyIter *iter)
{
return (NIT_ITFLAGS(iter)&NPY_ITFLAG_NOINNER) == 0;
}
-int NpyIter_HasCoords(NpyIter *iter)
+/*NUMPY_API
+ * Whether the iterator is tracking coordinates
+ */
+NPY_NO_EXPORT int
+NpyIter_HasCoords(NpyIter *iter)
{
return (NIT_ITFLAGS(iter)&NPY_ITFLAG_HASCOORDS) != 0;
}
-int NpyIter_HasIndex(NpyIter *iter)
+/*NUMPY_API
+ * Whether the iterator is tracking an index
+ */
+NPY_NO_EXPORT int
+NpyIter_HasIndex(NpyIter *iter)
{
return (NIT_ITFLAGS(iter)&NPY_ITFLAG_HASINDEX) != 0;
}
-npy_intp NpyIter_GetNDim(NpyIter *iter)
+/*NUMPY_API
+ * Gets the number of dimensions being iterated
+ */
+NPY_NO_EXPORT npy_intp
+NpyIter_GetNDim(NpyIter *iter)
{
return NIT_NDIM(iter);
}
-npy_intp NpyIter_GetNIter(NpyIter *iter)
+/*NUMPY_API
+ * Gets the number of operands being iterated
+ */
+NPY_NO_EXPORT npy_intp
+NpyIter_GetNIter(NpyIter *iter)
{
return NIT_NITER(iter);
}
-npy_intp NpyIter_GetIterSize(NpyIter *iter)
+/*NUMPY_API
+ * Gets the number of elements being iterated
+ */
+NPY_NO_EXPORT npy_intp
+NpyIter_GetIterSize(NpyIter *iter)
{
return NIT_ITERSIZE(iter);
}
-void
+/*NUMPY_API
+ * Gets the range of iteration indices being iterated
+ */
+NPY_NO_EXPORT void
NpyIter_GetIterIndexRange(NpyIter *iter,
npy_intp *istart, npy_intp *iend)
{
@@ -1690,7 +1758,11 @@ NpyIter_GetIterIndexRange(NpyIter *iter,
*iend = NIT_ITEREND(iter);
}
-int NpyIter_GetShape(NpyIter *iter, npy_intp *outshape)
+/*NUMPY_API
+ * Gets the broadcast shape (if coords are enabled)
+ */
+NPY_NO_EXPORT int
+NpyIter_GetShape(NpyIter *iter, npy_intp *outshape)
{
npy_uint32 itflags = NIT_ITFLAGS(iter);
npy_intp ndim = NIT_NDIM(iter);
@@ -1723,7 +1795,11 @@ int NpyIter_GetShape(NpyIter *iter, npy_intp *outshape)
return NPY_SUCCEED;
}
-char **NpyIter_GetDataPtrArray(NpyIter *iter)
+/*NUMPY_API
+ * Get the array of data pointers (1 per object being iterated)
+ */
+NPY_NO_EXPORT char **
+NpyIter_GetDataPtrArray(NpyIter *iter)
{
npy_uint32 itflags = NIT_ITFLAGS(iter);
npy_intp ndim = NIT_NDIM(iter);
@@ -1739,7 +1815,11 @@ char **NpyIter_GetDataPtrArray(NpyIter *iter)
}
}
-PyArray_Descr **NpyIter_GetDescrArray(NpyIter *iter)
+/*NUMPY_API
+ * Get the array of data type pointers (1 per object being iterated)
+ */
+NPY_NO_EXPORT PyArray_Descr **
+NpyIter_GetDescrArray(NpyIter *iter)
{
/*npy_uint32 itflags = NIT_ITFLAGS(iter);*/
npy_intp ndim = NIT_NDIM(iter);
@@ -1748,7 +1828,11 @@ PyArray_Descr **NpyIter_GetDescrArray(NpyIter *iter)
return NIT_DTYPES(iter);
}
-PyArrayObject **NpyIter_GetObjectArray(NpyIter *iter)
+/*NUMPY_API
+ * Get the array of objects being iterated
+ */
+NPY_NO_EXPORT PyArrayObject **
+NpyIter_GetObjectArray(NpyIter *iter)
{
/*npy_uint32 itflags = NIT_ITFLAGS(iter);*/
npy_intp ndim = NIT_NDIM(iter);
@@ -1757,7 +1841,11 @@ PyArrayObject **NpyIter_GetObjectArray(NpyIter *iter)
return NIT_OBJECTS(iter);
}
-PyArrayObject *NpyIter_GetIterView(NpyIter *iter, npy_intp i)
+/*NUMPY_API
+ * Returns a view to the i-th object with the iterator's internal axes
+ */
+NPY_NO_EXPORT PyArrayObject *
+NpyIter_GetIterView(NpyIter *iter, npy_intp i)
{
npy_uint32 itflags = NIT_ITFLAGS(iter);
npy_intp idim, ndim = NIT_NDIM(iter);
@@ -1814,7 +1902,11 @@ PyArrayObject *NpyIter_GetIterView(NpyIter *iter, npy_intp i)
return view;
}
-npy_intp *NpyIter_GetIndexPtr(NpyIter *iter)
+/*NUMPY_API
+ * Get a pointer to the index, if it is being tracked
+ */
+NPY_NO_EXPORT npy_intp *
+NpyIter_GetIndexPtr(NpyIter *iter)
{
npy_uint32 itflags = NIT_ITFLAGS(iter);
npy_intp ndim = NIT_NDIM(iter);
@@ -1831,7 +1923,11 @@ npy_intp *NpyIter_GetIndexPtr(NpyIter *iter)
}
}
-void NpyIter_GetReadFlags(NpyIter *iter, char *outreadflags)
+/*NUMPY_API
+ * Gets an array of read flags (1 per object being iterated)
+ */
+NPY_NO_EXPORT void
+NpyIter_GetReadFlags(NpyIter *iter, char *outreadflags)
{
/*npy_uint32 itflags = NIT_ITFLAGS(iter);*/
npy_intp ndim = NIT_NDIM(iter);
@@ -1844,7 +1940,11 @@ void NpyIter_GetReadFlags(NpyIter *iter, char *outreadflags)
}
}
-void NpyIter_GetWriteFlags(NpyIter *iter, char *outwriteflags)
+/*NUMPY_API
+ * Gets an array of write flags (1 per object being iterated)
+ */
+NPY_NO_EXPORT void
+NpyIter_GetWriteFlags(NpyIter *iter, char *outwriteflags)
{
/*npy_uint32 itflags = NIT_ITFLAGS(iter);*/
npy_intp ndim = NIT_NDIM(iter);
@@ -1858,7 +1958,11 @@ void NpyIter_GetWriteFlags(NpyIter *iter, char *outwriteflags)
}
-npy_intp *NpyIter_GetInnerStrideArray(NpyIter *iter)
+/*NUMPY_API
+ * Get the array of strides for the inner loop (when HasInnerLoop is false)
+ */
+NPY_NO_EXPORT npy_intp *
+NpyIter_GetInnerStrideArray(NpyIter *iter)
{
npy_uint32 itflags = NIT_ITFLAGS(iter);
npy_intp ndim = NIT_NDIM(iter);
@@ -1874,7 +1978,11 @@ npy_intp *NpyIter_GetInnerStrideArray(NpyIter *iter)
}
}
-npy_intp* NpyIter_GetInnerLoopSizePtr(NpyIter *iter)
+/*NUMPY_API
+ * Get a pointer to the size of the inner loop (when HasInnerLoop is false)
+ */
+NPY_NO_EXPORT npy_intp *
+NpyIter_GetInnerLoopSizePtr(NpyIter *iter)
{
npy_uint32 itflags = NIT_ITFLAGS(iter);
npy_intp ndim = NIT_NDIM(iter);
@@ -3941,7 +4049,8 @@ fail:
* iterindex, updating the pointers as well. This function does
* no error checking.
*/
-static void npyiter_goto_iterindex(NpyIter *iter, npy_intp iterindex)
+static void
+npyiter_goto_iterindex(NpyIter *iter, npy_intp iterindex)
{
npy_uint32 itflags = NIT_ITFLAGS(iter);
npy_intp idim, ndim = NIT_NDIM(iter);
@@ -4193,7 +4302,9 @@ npyiter_copy_to_buffers(NpyIter *iter)
}
}
-/* For debugging */
+/*NUMPY_API
+ * For debugging
+ */
NPY_NO_EXPORT void
NpyIter_DebugPrint(NpyIter *iter)
{
diff --git a/numpy/core/src/multiarray/new_iterator_pywrap.c b/numpy/core/src/multiarray/new_iterator_pywrap.c
index 1d1936fd1..68a741f9f 100644
--- a/numpy/core/src/multiarray/new_iterator_pywrap.c
+++ b/numpy/core/src/multiarray/new_iterator_pywrap.c
@@ -9,8 +9,6 @@
#include "numpy/npy_3kcompat.h"
-#include <numpy/new_iterator.h>
-
typedef struct NewNpyArrayIterObject_tag NewNpyArrayIterObject;
struct NewNpyArrayIterObject_tag {
@@ -2093,7 +2091,7 @@ NPY_NO_EXPORT PyTypeObject NpyIter_Type = {
0, /* ob_size */
#endif
"numpy.newiter", /* tp_name */
- sizeof(NewNpyArrayIterObject), /* tp_basicsize */
+ sizeof(NewNpyArrayIterObject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
(destructor)npyiter_dealloc, /* tp_dealloc */
diff --git a/numpy/core/tests/test_new_iterator.py b/numpy/core/tests/test_new_iterator.py
index 25e96a73d..dc34b655a 100644
--- a/numpy/core/tests/test_new_iterator.py
+++ b/numpy/core/tests/test_new_iterator.py
@@ -1313,7 +1313,7 @@ def test_iter_buffering():
for a in arrays:
for buffersize in (1,2,3,5,8,11,16,1024):
vals = []
- i = np.newiter(a, ['buffered','no_inner_iteration'],
+ i = newiter(a, ['buffered','no_inner_iteration'],
[['readonly','nbo_aligned']],
order='C',
casting='equiv',
@@ -1329,7 +1329,7 @@ def test_iter_write_buffering():
# F-order swapped array
a = np.arange(24).reshape(2,3,4).T.newbyteorder().byteswap()
- i = np.newiter(a, ['buffered'],
+ i = newiter(a, ['buffered'],
[['readwrite','nbo_aligned']],
casting='equiv',
order='C',
@@ -1346,7 +1346,7 @@ def test_iter_buffering_delayed_alloc():
a = np.arange(6)
b = np.arange(1, dtype='f4')
- i = np.newiter([a,b], ['buffered','delay_bufalloc','coords'],
+ i = newiter([a,b], ['buffered','delay_bufalloc','coords'],
casting='unsafe',
op_dtypes='f4')
assert_(i.hasdelayedbufalloc)
@@ -1369,7 +1369,7 @@ def test_iter_buffered_cast_simple():
# Test that buffering can handle a simple cast
a = np.arange(10, dtype='f4')
- i = np.newiter(a, ['buffered','no_inner_iteration'],
+ i = newiter(a, ['buffered','no_inner_iteration'],
[['readwrite','nbo_aligned']],
casting='same_kind',
op_dtypes=[np.dtype('f8')],
@@ -1383,7 +1383,7 @@ def test_iter_buffered_cast_byteswapped():
# Test that buffering can handle a cast which requires swap->cast->swap
a = np.arange(10, dtype='f4').newbyteorder().byteswap()
- i = np.newiter(a, ['buffered','no_inner_iteration'],
+ i = newiter(a, ['buffered','no_inner_iteration'],
[['readwrite','nbo_aligned','same_kind_casts']],
op_dtypes=[np.dtype('f8').newbyteorder()],
buffersize=3)
@@ -1393,7 +1393,7 @@ def test_iter_buffered_cast_byteswapped():
assert_equal(a, 2*np.arange(10, dtype='f4'))
a = np.arange(10, dtype='f8').newbyteorder().byteswap()
- i = np.newiter(a, ['buffered','no_inner_iteration'],
+ i = newiter(a, ['buffered','no_inner_iteration'],
[['readwrite','nbo_aligned','unsafe_casts']],
op_dtypes=[np.dtype('c8').newbyteorder()],
buffersize=3)
@@ -1407,7 +1407,7 @@ def test_iter_buffered_cast_byteswapped():
a = np.arange(10, dtype='c8').newbyteorder().byteswap()
a += 2j
- i = np.newiter(a, ['buffered','no_inner_iteration'],
+ i = newiter(a, ['buffered','no_inner_iteration'],
[['readwrite','nbo_aligned']],
casting='same_kind',
op_dtypes=[np.dtype('c16')],
@@ -1418,7 +1418,7 @@ def test_iter_buffered_cast_byteswapped():
a = np.arange(10, dtype='c8')
a += 2j
- i = np.newiter(a, ['buffered','no_inner_iteration'],
+ i = newiter(a, ['buffered','no_inner_iteration'],
[['readwrite','nbo_aligned']],
casting='same_kind',
op_dtypes=[np.dtype('c16').newbyteorder()],
@@ -1429,7 +1429,7 @@ def test_iter_buffered_cast_byteswapped():
a = np.arange(10, dtype=np.clongdouble).newbyteorder().byteswap()
a += 2j
- i = np.newiter(a, ['buffered','no_inner_iteration'],
+ i = newiter(a, ['buffered','no_inner_iteration'],
[['readwrite','nbo_aligned']],
casting='same_kind',
op_dtypes=[np.dtype('c16')],
@@ -1439,7 +1439,7 @@ def test_iter_buffered_cast_byteswapped():
assert_equal(a, 2*np.arange(10, dtype=np.clongdouble) + 4j)
a = np.arange(10, dtype=np.longdouble).newbyteorder().byteswap()
- i = np.newiter(a, ['buffered','no_inner_iteration'],
+ i = newiter(a, ['buffered','no_inner_iteration'],
[['readwrite','nbo_aligned']],
casting='same_kind',
op_dtypes=[np.dtype('f4')],
@@ -1454,30 +1454,30 @@ def test_iter_buffering_badwriteback():
# a needs write buffering, but had a broadcast dimension
a = np.arange(6).reshape(2,3,1)
b = np.arange(12).reshape(2,3,2)
- assert_raises(ValueError,np.newiter,[a,b],
+ assert_raises(ValueError,newiter,[a,b],
['buffered','no_inner_iteration'],
[['readwrite'],['writeonly']],
order='C')
# But if a is readonly, it's fine
- i = np.newiter([a,b],['buffered','no_inner_iteration'],
+ i = newiter([a,b],['buffered','no_inner_iteration'],
[['readonly'],['writeonly']],
order='C')
# If a has just one element, it's fine too (constant 0 stride)
a = np.arange(1).reshape(1,1,1)
- i = np.newiter([a,b],['buffered','no_inner_iteration'],
+ i = newiter([a,b],['buffered','no_inner_iteration'],
[['readwrite'],['writeonly']],
order='C')
# check that it fails on other dimensions too
a = np.arange(6).reshape(1,3,2)
- assert_raises(ValueError,np.newiter,[a,b],
+ assert_raises(ValueError,newiter,[a,b],
['buffered','no_inner_iteration'],
[['readwrite'],['writeonly']],
order='C')
a = np.arange(4).reshape(2,1,2)
- assert_raises(ValueError,np.newiter,[a,b],
+ assert_raises(ValueError,newiter,[a,b],
['buffered','no_inner_iteration'],
[['readwrite'],['writeonly']],
order='C')
@@ -1485,7 +1485,7 @@ def test_iter_buffering_badwriteback():
def test_iter_buffering_growinner():
# Test that the inner loop grows when no buffering is needed
a = np.arange(30)
- i = np.newiter(a, ['buffered','growinner','no_inner_iteration'],
+ i = newiter(a, ['buffered','growinner','no_inner_iteration'],
buffersize=5)
# Should end up with just one inner loop here
assert_equal(i[0].size, a.size)
@@ -1496,11 +1496,11 @@ def test_iter_no_broadcast():
b = np.arange(6).reshape(2,3,1)
c = np.arange(12).reshape(3,4)
- i = np.newiter([a,b,c], [],
+ i = newiter([a,b,c], [],
[['readonly','no_broadcast'],['readonly'],['readonly']])
- assert_raises(ValueError, np.newiter, [a,b,c], [],
+ assert_raises(ValueError, newiter, [a,b,c], [],
[['readonly'],['readonly','no_broadcast'],['readonly']])
- assert_raises(ValueError, np.newiter, [a,b,c], [],
+ assert_raises(ValueError, newiter, [a,b,c], [],
[['readonly'],['readonly'],['readonly','no_broadcast']])
def test_iter_nested_iters_basic():