diff options
author | Matti Picus <matti.picus@gmail.com> | 2019-06-01 23:43:00 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-01 23:43:00 +0300 |
commit | 4b4eaa666b18016162c144b7757ba40d8237fdb8 (patch) | |
tree | fff212aed1b49616de5fe137e6f72c5cbde4ae1c /numpy | |
parent | e55563ffca5564cc25c174ad68a9056fb8addcfb (diff) | |
parent | 458b5bd38aa50d4c903ff1117ea811a29f774709 (diff) | |
download | numpy-4b4eaa666b18016162c144b7757ba40d8237fdb8.tar.gz |
Merge pull request #13693 from eric-wieser/const-correct-API
ENH: Pass input strides and dimensions by pointer to const
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/multiarray/ctors.c | 33 | ||||
-rw-r--r-- | numpy/core/src/multiarray/ctors.h | 33 | ||||
-rw-r--r-- | numpy/core/src/multiarray/multiarraymodule.c | 8 | ||||
-rw-r--r-- | numpy/core/src/multiarray/nditer_api.c | 2 |
4 files changed, 42 insertions, 34 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c index 21f7f0335..04658ed16 100644 --- a/numpy/core/src/multiarray/ctors.c +++ b/numpy/core/src/multiarray/ctors.c @@ -944,10 +944,11 @@ discover_dimensions(PyObject *obj, int *maxndim, npy_intp *d, int check_it, * be decrefed. */ NPY_NO_EXPORT PyObject * -PyArray_NewFromDescr_int(PyTypeObject *subtype, PyArray_Descr *descr, int nd, - npy_intp *dims, npy_intp *strides, void *data, - int flags, PyObject *obj, PyObject *base, int zeroed, - int allow_emptystring) +PyArray_NewFromDescr_int( + PyTypeObject *subtype, PyArray_Descr *descr, int nd, + npy_intp const *dims, npy_intp const *strides, void *data, + int flags, PyObject *obj, PyObject *base, int zeroed, + int allow_emptystring) { PyArrayObject_fields *fa; int i, is_empty; @@ -1223,9 +1224,10 @@ PyArray_NewFromDescr_int(PyTypeObject *subtype, PyArray_Descr *descr, int nd, * true, dtype will be decrefed. */ NPY_NO_EXPORT PyObject * -PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, - int nd, npy_intp *dims, npy_intp *strides, void *data, - int flags, PyObject *obj) +PyArray_NewFromDescr( + PyTypeObject *subtype, PyArray_Descr *descr, + int nd, npy_intp const *dims, npy_intp const *strides, void *data, + int flags, PyObject *obj) { return PyArray_NewFromDescrAndBase( subtype, descr, @@ -1239,7 +1241,7 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, NPY_NO_EXPORT PyObject * PyArray_NewFromDescrAndBase( PyTypeObject *subtype, PyArray_Descr *descr, - int nd, npy_intp *dims, npy_intp *strides, void *data, + int nd, npy_intp const *dims, npy_intp const *strides, void *data, int flags, PyObject *obj, PyObject *base) { return PyArray_NewFromDescr_int(subtype, descr, nd, @@ -1267,7 +1269,7 @@ PyArray_NewFromDescrAndBase( */ NPY_NO_EXPORT PyObject * PyArray_NewLikeArrayWithShape(PyArrayObject *prototype, NPY_ORDER order, - PyArray_Descr *dtype, int ndim, npy_intp *dims, int subok) + PyArray_Descr *dtype, int ndim, npy_intp const *dims, int subok) { PyObject *ret = NULL; @@ -1375,9 +1377,10 @@ PyArray_NewLikeArray(PyArrayObject *prototype, NPY_ORDER order, * Generic new array creation routine. */ NPY_NO_EXPORT PyObject * -PyArray_New(PyTypeObject *subtype, int nd, npy_intp *dims, int type_num, - npy_intp *strides, void *data, int itemsize, int flags, - PyObject *obj) +PyArray_New( + PyTypeObject *subtype, int nd, npy_intp const *dims, int type_num, + npy_intp const *strides, void *data, int itemsize, int flags, + PyObject *obj) { PyArray_Descr *descr; PyObject *new; @@ -3135,7 +3138,7 @@ PyArray_CheckAxis(PyArrayObject *arr, int *axis, int flags) * accepts NULL type */ NPY_NO_EXPORT PyObject * -PyArray_Zeros(int nd, npy_intp *dims, PyArray_Descr *type, int is_f_order) +PyArray_Zeros(int nd, npy_intp const *dims, PyArray_Descr *type, int is_f_order) { PyArrayObject *ret; @@ -3173,7 +3176,7 @@ PyArray_Zeros(int nd, npy_intp *dims, PyArray_Descr *type, int is_f_order) * steals a reference to type */ NPY_NO_EXPORT PyObject * -PyArray_Empty(int nd, npy_intp *dims, PyArray_Descr *type, int is_f_order) +PyArray_Empty(int nd, npy_intp const *dims, PyArray_Descr *type, int is_f_order) { PyArrayObject *ret; @@ -4149,7 +4152,7 @@ PyArray_FromIter(PyObject *obj, PyArray_Descr *dtype, npy_intp count) */ NPY_NO_EXPORT void -_array_fill_strides(npy_intp *strides, npy_intp *dims, int nd, size_t itemsize, +_array_fill_strides(npy_intp *strides, npy_intp const *dims, int nd, size_t itemsize, int inflag, int *objflags) { int i; diff --git a/numpy/core/src/multiarray/ctors.h b/numpy/core/src/multiarray/ctors.h index 4932130a7..4768e4efd 100644 --- a/numpy/core/src/multiarray/ctors.h +++ b/numpy/core/src/multiarray/ctors.h @@ -2,28 +2,33 @@ #define _NPY_ARRAY_CTORS_H_ NPY_NO_EXPORT PyObject * -PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd, - npy_intp *dims, npy_intp *strides, void *data, - int flags, PyObject *obj); +PyArray_NewFromDescr( + PyTypeObject *subtype, PyArray_Descr *descr, int nd, + npy_intp const *dims, npy_intp const *strides, void *data, + int flags, PyObject *obj); NPY_NO_EXPORT PyObject * PyArray_NewFromDescrAndBase( - PyTypeObject *subtype, PyArray_Descr *descr, - int nd, npy_intp *dims, npy_intp *strides, void *data, + PyTypeObject *subtype, PyArray_Descr *descr, int nd, + npy_intp const *dims, npy_intp const *strides, void *data, int flags, PyObject *obj, PyObject *base); NPY_NO_EXPORT PyObject * -PyArray_NewFromDescr_int(PyTypeObject *subtype, PyArray_Descr *descr, int nd, - npy_intp *dims, npy_intp *strides, void *data, - int flags, PyObject *obj, PyObject *base, int zeroed, - int allow_emptystring); +PyArray_NewFromDescr_int( + PyTypeObject *subtype, PyArray_Descr *descr, int nd, + npy_intp const *dims, npy_intp const *strides, void *data, + int flags, PyObject *obj, PyObject *base, int zeroed, + int allow_emptystring); NPY_NO_EXPORT PyObject * -PyArray_NewLikeArrayWithShape(PyArrayObject *prototype, NPY_ORDER order, - PyArray_Descr *dtype, int ndim, npy_intp *dims, int subok); +PyArray_NewLikeArrayWithShape( + PyArrayObject *prototype, NPY_ORDER order, + PyArray_Descr *dtype, int ndim, npy_intp const *dims, int subok); -NPY_NO_EXPORT PyObject *PyArray_New(PyTypeObject *, int nd, npy_intp *, - int, npy_intp *, void *, int, int, PyObject *); +NPY_NO_EXPORT PyObject * +PyArray_New( + PyTypeObject *, int nd, npy_intp const *, + int, npy_intp const*, void *, int, int, PyObject *); NPY_NO_EXPORT PyObject * PyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth, @@ -68,7 +73,7 @@ PyArray_CopyAsFlat(PyArrayObject *dst, PyArrayObject *src, /* FIXME: remove those from here */ NPY_NO_EXPORT void -_array_fill_strides(npy_intp *strides, npy_intp *dims, int nd, size_t itemsize, +_array_fill_strides(npy_intp *strides, npy_intp const *dims, int nd, size_t itemsize, int inflag, int *objflags); NPY_NO_EXPORT void diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index 3befe1c91..23195cead 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -130,7 +130,7 @@ PyArray_GetPriority(PyObject *obj, double default_) * Multiply a List of ints */ NPY_NO_EXPORT int -PyArray_MultiplyIntList(int *l1, int n) +PyArray_MultiplyIntList(int const *l1, int n) { int s = 1; @@ -144,7 +144,7 @@ PyArray_MultiplyIntList(int *l1, int n) * Multiply a List */ NPY_NO_EXPORT npy_intp -PyArray_MultiplyList(npy_intp *l1, int n) +PyArray_MultiplyList(npy_intp const *l1, int n) { npy_intp s = 1; @@ -180,7 +180,7 @@ PyArray_OverflowMultiplyList(npy_intp *l1, int n) * Produce a pointer into array */ NPY_NO_EXPORT void * -PyArray_GetPtr(PyArrayObject *obj, npy_intp* ind) +PyArray_GetPtr(PyArrayObject *obj, npy_intp const* ind) { int n = PyArray_NDIM(obj); npy_intp *strides = PyArray_STRIDES(obj); @@ -196,7 +196,7 @@ PyArray_GetPtr(PyArrayObject *obj, npy_intp* ind) * Compare Lists */ NPY_NO_EXPORT int -PyArray_CompareLists(npy_intp *l1, npy_intp *l2, int n) +PyArray_CompareLists(npy_intp const *l1, npy_intp const *l2, int n) { int i; diff --git a/numpy/core/src/multiarray/nditer_api.c b/numpy/core/src/multiarray/nditer_api.c index 7a33ac05e..18ca127e1 100644 --- a/numpy/core/src/multiarray/nditer_api.c +++ b/numpy/core/src/multiarray/nditer_api.c @@ -406,7 +406,7 @@ NpyIter_ResetToIterIndexRange(NpyIter *iter, * Returns NPY_SUCCEED on success, NPY_FAIL on failure. */ NPY_NO_EXPORT int -NpyIter_GotoMultiIndex(NpyIter *iter, npy_intp *multi_index) +NpyIter_GotoMultiIndex(NpyIter *iter, npy_intp const *multi_index) { npy_uint32 itflags = NIT_ITFLAGS(iter); int idim, ndim = NIT_NDIM(iter); |