summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2019-06-01 01:12:30 -0700
committerEric Wieser <wieser.eric@gmail.com>2019-06-01 10:52:25 -0700
commit458b5bd38aa50d4c903ff1117ea811a29f774709 (patch)
tree724be8e350f41c6072241815338dcff4ea1dbd52 /numpy
parent392866d1c8dce0abb8cb327a42f8e134f5d2a05e (diff)
downloadnumpy-458b5bd38aa50d4c903ff1117ea811a29f774709.tar.gz
ENH: Pass input strides and dimensions by pointer to const
This makes it possible to call these functions with constant data. It also bakes the contract that the data passed via these pointers will not be changed into the function signatures. This is backwards compatible, because T* can always be passed to a function expecting T const*.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/ctors.c33
-rw-r--r--numpy/core/src/multiarray/ctors.h33
-rw-r--r--numpy/core/src/multiarray/multiarraymodule.c8
-rw-r--r--numpy/core/src/multiarray/nditer_api.c2
4 files changed, 42 insertions, 34 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index 9dc904c08..cce2143a7 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;
@@ -4140,7 +4143,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 137feee4b..51d476792 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);