summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/release/upcoming_changes/15251.c_api.rst10
-rw-r--r--doc/source/reference/c-api/array.rst2
-rw-r--r--numpy/core/src/common/array_assign.c10
-rw-r--r--numpy/core/src/common/array_assign.h20
-rw-r--r--numpy/core/src/common/lowlevel_strided_loops.h36
-rw-r--r--numpy/core/src/multiarray/_multiarray_tests.c.src6
-rw-r--r--numpy/core/src/multiarray/array_assign_array.c18
-rw-r--r--numpy/core/src/multiarray/array_assign_scalar.c10
-rw-r--r--numpy/core/src/multiarray/arrayobject.c2
-rw-r--r--numpy/core/src/multiarray/common.c2
-rw-r--r--numpy/core/src/multiarray/common.h2
-rw-r--r--numpy/core/src/multiarray/compiled_base.c2
-rw-r--r--numpy/core/src/multiarray/conversion_utils.c2
-rw-r--r--numpy/core/src/multiarray/conversion_utils.h2
-rw-r--r--numpy/core/src/multiarray/ctors.c2
-rw-r--r--numpy/core/src/multiarray/dtype_transfer.c18
-rw-r--r--numpy/core/src/multiarray/einsum.c.src34
-rw-r--r--numpy/core/src/multiarray/item_selection.c6
-rw-r--r--numpy/core/src/multiarray/item_selection.h2
-rw-r--r--numpy/core/src/multiarray/lowlevel_strided_loops.c.src18
-rw-r--r--numpy/core/src/multiarray/multiarraymodule.c2
-rw-r--r--numpy/core/src/multiarray/nditer_constr.c8
-rw-r--r--numpy/core/src/multiarray/shape.c2
-rw-r--r--numpy/core/src/multiarray/shape.h2
-rw-r--r--numpy/core/src/multiarray/strfuncs.c2
-rw-r--r--numpy/core/src/umath/reduction.h4
-rw-r--r--numpy/core/src/umath/ufunc_object.c10
-rw-r--r--numpy/f2py/src/fortranobject.c2
28 files changed, 125 insertions, 111 deletions
diff --git a/doc/release/upcoming_changes/15251.c_api.rst b/doc/release/upcoming_changes/15251.c_api.rst
new file mode 100644
index 000000000..f391c904b
--- /dev/null
+++ b/doc/release/upcoming_changes/15251.c_api.rst
@@ -0,0 +1,10 @@
+Better support for ``const`` dimensions in API functions
+--------------------------------------------------------
+The following functions now accept a constant array of ``npy_intp``:
+
+* `PyArray_BroadcastToShape`
+* `PyArray_IntTupleFromIntp`
+* `PyArray_OverflowMultiplyList`
+
+Previously the caller would have to cast away the const-ness to call these
+functions.
diff --git a/doc/source/reference/c-api/array.rst b/doc/source/reference/c-api/array.rst
index c910efa60..2eaf3a27a 100644
--- a/doc/source/reference/c-api/array.rst
+++ b/doc/source/reference/c-api/array.rst
@@ -2514,7 +2514,7 @@ this useful approach to looping over an array.
stride and that axis will be used.
.. c:function:: PyObject *PyArray_BroadcastToShape( \
- PyObject* arr, npy_intp *dimensions, int nd)
+ PyObject* arr, npy_intp const *dimensions, int nd)
Return an array iterator that is broadcast to iterate as an array
of the shape provided by *dimensions* and *nd*.
diff --git a/numpy/core/src/common/array_assign.c b/numpy/core/src/common/array_assign.c
index 0ac1b01c6..d626d1260 100644
--- a/numpy/core/src/common/array_assign.c
+++ b/numpy/core/src/common/array_assign.c
@@ -27,9 +27,9 @@
/* See array_assign.h for parameter documentation */
NPY_NO_EXPORT int
-broadcast_strides(int ndim, npy_intp *shape,
- int strides_ndim, npy_intp *strides_shape, npy_intp *strides,
- char *strides_name,
+broadcast_strides(int ndim, npy_intp const *shape,
+ int strides_ndim, npy_intp const *strides_shape, npy_intp const *strides,
+ char const *strides_name,
npy_intp *out_strides)
{
int idim, idim_start = ndim - strides_ndim;
@@ -84,8 +84,8 @@ broadcast_error: {
/* See array_assign.h for parameter documentation */
NPY_NO_EXPORT int
-raw_array_is_aligned(int ndim, npy_intp *shape,
- char *data, npy_intp *strides, int alignment)
+raw_array_is_aligned(int ndim, npy_intp const *shape,
+ char *data, npy_intp const *strides, int alignment)
{
/*
diff --git a/numpy/core/src/common/array_assign.h b/numpy/core/src/common/array_assign.h
index 69ef56bb4..f5d884dd9 100644
--- a/numpy/core/src/common/array_assign.h
+++ b/numpy/core/src/common/array_assign.h
@@ -44,8 +44,8 @@ PyArray_AssignRawScalar(PyArrayObject *dst,
* Returns 0 on success, -1 on failure.
*/
NPY_NO_EXPORT int
-raw_array_assign_scalar(int ndim, npy_intp *shape,
- PyArray_Descr *dst_dtype, char *dst_data, npy_intp *dst_strides,
+raw_array_assign_scalar(int ndim, npy_intp const *shape,
+ PyArray_Descr *dst_dtype, char *dst_data, npy_intp const *dst_strides,
PyArray_Descr *src_dtype, char *src_data);
/*
@@ -55,11 +55,11 @@ raw_array_assign_scalar(int ndim, npy_intp *shape,
* Returns 0 on success, -1 on failure.
*/
NPY_NO_EXPORT int
-raw_array_wheremasked_assign_scalar(int ndim, npy_intp *shape,
- PyArray_Descr *dst_dtype, char *dst_data, npy_intp *dst_strides,
+raw_array_wheremasked_assign_scalar(int ndim, npy_intp const *shape,
+ PyArray_Descr *dst_dtype, char *dst_data, npy_intp const *dst_strides,
PyArray_Descr *src_dtype, char *src_data,
PyArray_Descr *wheremask_dtype, char *wheremask_data,
- npy_intp *wheremask_strides);
+ npy_intp const *wheremask_strides);
/******** LOW-LEVEL ARRAY MANIPULATION HELPERS ********/
@@ -80,9 +80,9 @@ raw_array_wheremasked_assign_scalar(int ndim, npy_intp *shape,
* Returns 0 on success, -1 on failure.
*/
NPY_NO_EXPORT int
-broadcast_strides(int ndim, npy_intp *shape,
- int strides_ndim, npy_intp *strides_shape, npy_intp *strides,
- char *strides_name,
+broadcast_strides(int ndim, npy_intp const *shape,
+ int strides_ndim, npy_intp const *strides_shape, npy_intp const *strides,
+ char const *strides_name,
npy_intp *out_strides);
/*
@@ -93,8 +93,8 @@ broadcast_strides(int ndim, npy_intp *shape,
* cannot-be-aligned, in which case 0 (false) is always returned.
*/
NPY_NO_EXPORT int
-raw_array_is_aligned(int ndim, npy_intp *shape,
- char *data, npy_intp *strides, int alignment);
+raw_array_is_aligned(int ndim, npy_intp const *shape,
+ char *data, npy_intp const *strides, int alignment);
/*
* Checks if an array is aligned to its "true alignment"
diff --git a/numpy/core/src/common/lowlevel_strided_loops.h b/numpy/core/src/common/lowlevel_strided_loops.h
index bacd27473..9208d5499 100644
--- a/numpy/core/src/common/lowlevel_strided_loops.h
+++ b/numpy/core/src/common/lowlevel_strided_loops.h
@@ -306,30 +306,30 @@ PyArray_CastRawArrays(npy_intp count,
NPY_NO_EXPORT npy_intp
PyArray_TransferNDimToStrided(npy_intp ndim,
char *dst, npy_intp dst_stride,
- char *src, npy_intp *src_strides, npy_intp src_strides_inc,
- npy_intp *coords, npy_intp coords_inc,
- npy_intp *shape, npy_intp shape_inc,
+ char *src, npy_intp const *src_strides, npy_intp src_strides_inc,
+ npy_intp const *coords, npy_intp coords_inc,
+ npy_intp const *shape, npy_intp shape_inc,
npy_intp count, npy_intp src_itemsize,
PyArray_StridedUnaryOp *stransfer,
NpyAuxData *transferdata);
NPY_NO_EXPORT npy_intp
PyArray_TransferStridedToNDim(npy_intp ndim,
- char *dst, npy_intp *dst_strides, npy_intp dst_strides_inc,
+ char *dst, npy_intp const *dst_strides, npy_intp dst_strides_inc,
char *src, npy_intp src_stride,
- npy_intp *coords, npy_intp coords_inc,
- npy_intp *shape, npy_intp shape_inc,
+ npy_intp const *coords, npy_intp coords_inc,
+ npy_intp const *shape, npy_intp shape_inc,
npy_intp count, npy_intp src_itemsize,
PyArray_StridedUnaryOp *stransfer,
NpyAuxData *transferdata);
NPY_NO_EXPORT npy_intp
PyArray_TransferMaskedStridedToNDim(npy_intp ndim,
- char *dst, npy_intp *dst_strides, npy_intp dst_strides_inc,
+ char *dst, npy_intp const *dst_strides, npy_intp dst_strides_inc,
char *src, npy_intp src_stride,
npy_bool *mask, npy_intp mask_stride,
- npy_intp *coords, npy_intp coords_inc,
- npy_intp *shape, npy_intp shape_inc,
+ npy_intp const *coords, npy_intp coords_inc,
+ npy_intp const *shape, npy_intp shape_inc,
npy_intp count, npy_intp src_itemsize,
PyArray_MaskedStridedUnaryOp *stransfer,
NpyAuxData *data);
@@ -365,8 +365,8 @@ mapiter_set(PyArrayMapIterObject *mit);
* Returns 0 on success, -1 on failure.
*/
NPY_NO_EXPORT int
-PyArray_PrepareOneRawArrayIter(int ndim, npy_intp *shape,
- char *data, npy_intp *strides,
+PyArray_PrepareOneRawArrayIter(int ndim, npy_intp const *shape,
+ char *data, npy_intp const *strides,
int *out_ndim, npy_intp *out_shape,
char **out_data, npy_intp *out_strides);
@@ -387,9 +387,9 @@ PyArray_PrepareOneRawArrayIter(int ndim, npy_intp *shape,
* Returns 0 on success, -1 on failure.
*/
NPY_NO_EXPORT int
-PyArray_PrepareTwoRawArrayIter(int ndim, npy_intp *shape,
- char *dataA, npy_intp *stridesA,
- char *dataB, npy_intp *stridesB,
+PyArray_PrepareTwoRawArrayIter(int ndim, npy_intp const *shape,
+ char *dataA, npy_intp const *stridesA,
+ char *dataB, npy_intp const *stridesB,
int *out_ndim, npy_intp *out_shape,
char **out_dataA, npy_intp *out_stridesA,
char **out_dataB, npy_intp *out_stridesB);
@@ -411,10 +411,10 @@ PyArray_PrepareTwoRawArrayIter(int ndim, npy_intp *shape,
* Returns 0 on success, -1 on failure.
*/
NPY_NO_EXPORT int
-PyArray_PrepareThreeRawArrayIter(int ndim, npy_intp *shape,
- char *dataA, npy_intp *stridesA,
- char *dataB, npy_intp *stridesB,
- char *dataC, npy_intp *stridesC,
+PyArray_PrepareThreeRawArrayIter(int ndim, npy_intp const *shape,
+ char *dataA, npy_intp const *stridesA,
+ char *dataB, npy_intp const *stridesB,
+ char *dataC, npy_intp const *stridesC,
int *out_ndim, npy_intp *out_shape,
char **out_dataA, npy_intp *out_stridesA,
char **out_dataB, npy_intp *out_stridesB,
diff --git a/numpy/core/src/multiarray/_multiarray_tests.c.src b/numpy/core/src/multiarray/_multiarray_tests.c.src
index 5e2cf0edd..1a51c06c7 100644
--- a/numpy/core/src/multiarray/_multiarray_tests.c.src
+++ b/numpy/core/src/multiarray/_multiarray_tests.c.src
@@ -55,7 +55,7 @@ EXPORT(void*) forward_pointer(void *x)
* #typenum = NPY_DOUBLE, NPY_INT#
*/
static int copy_@name@(PyArrayIterObject *itx, PyArrayNeighborhoodIterObject *niterx,
- npy_intp *bounds,
+ npy_intp const *bounds,
PyObject **out)
{
npy_intp i, j;
@@ -97,7 +97,7 @@ static int copy_@name@(PyArrayIterObject *itx, PyArrayNeighborhoodIterObject *ni
/**end repeat**/
static int copy_object(PyArrayIterObject *itx, PyArrayNeighborhoodIterObject *niterx,
- npy_intp *bounds,
+ npy_intp const *bounds,
PyObject **out)
{
npy_intp i, j;
@@ -251,7 +251,7 @@ clean_ax:
static int
copy_double_double(PyArrayNeighborhoodIterObject *itx,
PyArrayNeighborhoodIterObject *niterx,
- npy_intp *bounds,
+ npy_intp const *bounds,
PyObject **out)
{
npy_intp i, j;
diff --git a/numpy/core/src/multiarray/array_assign_array.c b/numpy/core/src/multiarray/array_assign_array.c
index 7ff33ebd7..e40b6c719 100644
--- a/numpy/core/src/multiarray/array_assign_array.c
+++ b/numpy/core/src/multiarray/array_assign_array.c
@@ -29,8 +29,8 @@
* elements, as required by the copy/casting code in lowlevel_strided_loops.c
*/
NPY_NO_EXPORT int
-copycast_isaligned(int ndim, npy_intp *shape,
- PyArray_Descr *dtype, char *data, npy_intp *strides)
+copycast_isaligned(int ndim, npy_intp const *shape,
+ PyArray_Descr *dtype, char *data, npy_intp const *strides)
{
int aligned;
int big_aln, small_aln;
@@ -72,9 +72,9 @@ copycast_isaligned(int ndim, npy_intp *shape,
* Returns 0 on success, -1 on failure.
*/
NPY_NO_EXPORT int
-raw_array_assign_array(int ndim, npy_intp *shape,
- PyArray_Descr *dst_dtype, char *dst_data, npy_intp *dst_strides,
- PyArray_Descr *src_dtype, char *src_data, npy_intp *src_strides)
+raw_array_assign_array(int ndim, npy_intp const *shape,
+ PyArray_Descr *dst_dtype, char *dst_data, npy_intp const *dst_strides,
+ PyArray_Descr *src_dtype, char *src_data, npy_intp const *src_strides)
{
int idim;
npy_intp shape_it[NPY_MAXDIMS];
@@ -152,11 +152,11 @@ raw_array_assign_array(int ndim, npy_intp *shape,
* Returns 0 on success, -1 on failure.
*/
NPY_NO_EXPORT int
-raw_array_wheremasked_assign_array(int ndim, npy_intp *shape,
- PyArray_Descr *dst_dtype, char *dst_data, npy_intp *dst_strides,
- PyArray_Descr *src_dtype, char *src_data, npy_intp *src_strides,
+raw_array_wheremasked_assign_array(int ndim, npy_intp const *shape,
+ PyArray_Descr *dst_dtype, char *dst_data, npy_intp const *dst_strides,
+ PyArray_Descr *src_dtype, char *src_data, npy_intp const *src_strides,
PyArray_Descr *wheremask_dtype, char *wheremask_data,
- npy_intp *wheremask_strides)
+ npy_intp const *wheremask_strides)
{
int idim;
npy_intp shape_it[NPY_MAXDIMS];
diff --git a/numpy/core/src/multiarray/array_assign_scalar.c b/numpy/core/src/multiarray/array_assign_scalar.c
index ecb5be47b..6bc9bcfee 100644
--- a/numpy/core/src/multiarray/array_assign_scalar.c
+++ b/numpy/core/src/multiarray/array_assign_scalar.c
@@ -30,8 +30,8 @@
* Returns 0 on success, -1 on failure.
*/
NPY_NO_EXPORT int
-raw_array_assign_scalar(int ndim, npy_intp *shape,
- PyArray_Descr *dst_dtype, char *dst_data, npy_intp *dst_strides,
+raw_array_assign_scalar(int ndim, npy_intp const *shape,
+ PyArray_Descr *dst_dtype, char *dst_data, npy_intp const *dst_strides,
PyArray_Descr *src_dtype, char *src_data)
{
int idim;
@@ -101,11 +101,11 @@ raw_array_assign_scalar(int ndim, npy_intp *shape,
* Returns 0 on success, -1 on failure.
*/
NPY_NO_EXPORT int
-raw_array_wheremasked_assign_scalar(int ndim, npy_intp *shape,
- PyArray_Descr *dst_dtype, char *dst_data, npy_intp *dst_strides,
+raw_array_wheremasked_assign_scalar(int ndim, npy_intp const *shape,
+ PyArray_Descr *dst_dtype, char *dst_data, npy_intp const *dst_strides,
PyArray_Descr *src_dtype, char *src_data,
PyArray_Descr *wheremask_dtype, char *wheremask_data,
- npy_intp *wheremask_strides)
+ npy_intp const *wheremask_strides)
{
int idim;
npy_intp shape_it[NPY_MAXDIMS], dst_strides_it[NPY_MAXDIMS];
diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c
index a5cebfbd8..6a500bd3f 100644
--- a/numpy/core/src/multiarray/arrayobject.c
+++ b/numpy/core/src/multiarray/arrayobject.c
@@ -1601,7 +1601,7 @@ PyArray_ElementStrides(PyObject *obj)
/*NUMPY_API*/
NPY_NO_EXPORT npy_bool
PyArray_CheckStrides(int elsize, int nd, npy_intp numbytes, npy_intp offset,
- npy_intp *dims, npy_intp *newstrides)
+ npy_intp const *dims, npy_intp const *newstrides)
{
npy_intp begin, end;
npy_intp lower_offset;
diff --git a/numpy/core/src/multiarray/common.c b/numpy/core/src/multiarray/common.c
index c991f7428..64113c40b 100644
--- a/numpy/core/src/multiarray/common.c
+++ b/numpy/core/src/multiarray/common.c
@@ -695,7 +695,7 @@ _IsWriteable(PyArrayObject *ap)
* @return Python unicode string
*/
NPY_NO_EXPORT PyObject *
-convert_shape_to_string(npy_intp n, npy_intp *vals, char *ending)
+convert_shape_to_string(npy_intp n, npy_intp const *vals, char *ending)
{
npy_intp i;
PyObject *ret, *tmp;
diff --git a/numpy/core/src/multiarray/common.h b/numpy/core/src/multiarray/common.h
index 7eee9ddc5..281fc437c 100644
--- a/numpy/core/src/multiarray/common.h
+++ b/numpy/core/src/multiarray/common.h
@@ -61,7 +61,7 @@ NPY_NO_EXPORT npy_bool
_IsWriteable(PyArrayObject *ap);
NPY_NO_EXPORT PyObject *
-convert_shape_to_string(npy_intp n, npy_intp *vals, char *ending);
+convert_shape_to_string(npy_intp n, npy_intp const *vals, char *ending);
/*
* Sets ValueError with "matrices not aligned" message for np.dot and friends
diff --git a/numpy/core/src/multiarray/compiled_base.c b/numpy/core/src/multiarray/compiled_base.c
index cc37026b0..67c861549 100644
--- a/numpy/core/src/multiarray/compiled_base.c
+++ b/numpy/core/src/multiarray/compiled_base.c
@@ -1164,7 +1164,7 @@ fail:
* order must be NPY_CORDER or NPY_FORTRANORDER
*/
static int
-unravel_index_loop(int unravel_ndim, npy_intp *unravel_dims,
+unravel_index_loop(int unravel_ndim, npy_intp const *unravel_dims,
npy_intp unravel_size, npy_intp count,
char *indices, npy_intp indices_stride,
npy_intp *coords, NPY_ORDER order)
diff --git a/numpy/core/src/multiarray/conversion_utils.c b/numpy/core/src/multiarray/conversion_utils.c
index ca126b4b1..531d138d6 100644
--- a/numpy/core/src/multiarray/conversion_utils.c
+++ b/numpy/core/src/multiarray/conversion_utils.c
@@ -1145,7 +1145,7 @@ PyArray_TypestrConvert(int itemsize, int gentype)
PyArray_IntTupleFromIntp
*/
NPY_NO_EXPORT PyObject *
-PyArray_IntTupleFromIntp(int len, npy_intp *vals)
+PyArray_IntTupleFromIntp(int len, npy_intp const *vals)
{
int i;
PyObject *intTuple = PyTuple_New(len);
diff --git a/numpy/core/src/multiarray/conversion_utils.h b/numpy/core/src/multiarray/conversion_utils.h
index cd43f25c3..9bf712c3b 100644
--- a/numpy/core/src/multiarray/conversion_utils.h
+++ b/numpy/core/src/multiarray/conversion_utils.h
@@ -37,7 +37,7 @@ NPY_NO_EXPORT int
PyArray_TypestrConvert(int itemsize, int gentype);
NPY_NO_EXPORT PyObject *
-PyArray_IntTupleFromIntp(int len, npy_intp *vals);
+PyArray_IntTupleFromIntp(int len, npy_intp const *vals);
NPY_NO_EXPORT int
PyArray_SelectkindConverter(PyObject *obj, NPY_SELECTKIND *selectkind);
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index 6921427ce..599eb9765 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -950,7 +950,7 @@ discover_dimensions(PyObject *obj, int *maxndim, npy_intp *d, int check_it,
}
static PyObject *
-raise_memory_error(int nd, npy_intp *dims, PyArray_Descr *descr)
+raise_memory_error(int nd, npy_intp const *dims, PyArray_Descr *descr)
{
static PyObject *exc_type = NULL;
diff --git a/numpy/core/src/multiarray/dtype_transfer.c b/numpy/core/src/multiarray/dtype_transfer.c
index ef0dd4a01..b26d5ac89 100644
--- a/numpy/core/src/multiarray/dtype_transfer.c
+++ b/numpy/core/src/multiarray/dtype_transfer.c
@@ -3832,8 +3832,8 @@ PyArray_CastRawArrays(npy_intp count,
* Returns 0 on success, -1 on failure.
*/
NPY_NO_EXPORT int
-PyArray_PrepareOneRawArrayIter(int ndim, npy_intp *shape,
- char *data, npy_intp *strides,
+PyArray_PrepareOneRawArrayIter(int ndim, npy_intp const *shape,
+ char *data, npy_intp const *strides,
int *out_ndim, npy_intp *out_shape,
char **out_data, npy_intp *out_strides)
{
@@ -3953,9 +3953,9 @@ PyArray_PrepareOneRawArrayIter(int ndim, npy_intp *shape,
* Returns 0 on success, -1 on failure.
*/
NPY_NO_EXPORT int
-PyArray_PrepareTwoRawArrayIter(int ndim, npy_intp *shape,
- char *dataA, npy_intp *stridesA,
- char *dataB, npy_intp *stridesB,
+PyArray_PrepareTwoRawArrayIter(int ndim, npy_intp const *shape,
+ char *dataA, npy_intp const *stridesA,
+ char *dataB, npy_intp const *stridesB,
int *out_ndim, npy_intp *out_shape,
char **out_dataA, npy_intp *out_stridesA,
char **out_dataB, npy_intp *out_stridesB)
@@ -4077,10 +4077,10 @@ PyArray_PrepareTwoRawArrayIter(int ndim, npy_intp *shape,
* Returns 0 on success, -1 on failure.
*/
NPY_NO_EXPORT int
-PyArray_PrepareThreeRawArrayIter(int ndim, npy_intp *shape,
- char *dataA, npy_intp *stridesA,
- char *dataB, npy_intp *stridesB,
- char *dataC, npy_intp *stridesC,
+PyArray_PrepareThreeRawArrayIter(int ndim, npy_intp const *shape,
+ char *dataA, npy_intp const *stridesA,
+ char *dataB, npy_intp const *stridesB,
+ char *dataC, npy_intp const *stridesC,
int *out_ndim, npy_intp *out_shape,
char **out_dataA, npy_intp *out_stridesA,
char **out_dataB, npy_intp *out_stridesB,
diff --git a/numpy/core/src/multiarray/einsum.c.src b/numpy/core/src/multiarray/einsum.c.src
index 58af44091..70af3fef9 100644
--- a/numpy/core/src/multiarray/einsum.c.src
+++ b/numpy/core/src/multiarray/einsum.c.src
@@ -107,7 +107,7 @@
*/
static void
@name@_sum_of_products_@noplabel@(int nop, char **dataptr,
- npy_intp *strides, npy_intp count)
+ npy_intp const *strides, npy_intp count)
{
#if (@nop@ == 1) || (@nop@ <= 3 && !@complex@)
char *data0 = dataptr[0];
@@ -206,7 +206,7 @@ static void
static void
@name@_sum_of_products_contig_one(int nop, char **dataptr,
- npy_intp *NPY_UNUSED(strides), npy_intp count)
+ npy_intp const *NPY_UNUSED(strides), npy_intp count)
{
@type@ *data0 = (@type@ *)dataptr[0];
@type@ *data_out = (@type@ *)dataptr[1];
@@ -268,7 +268,7 @@ finish_after_unrolled_loop:
static void
@name@_sum_of_products_contig_two(int nop, char **dataptr,
- npy_intp *NPY_UNUSED(strides), npy_intp count)
+ npy_intp const *NPY_UNUSED(strides), npy_intp count)
{
@type@ *data0 = (@type@ *)dataptr[0];
@type@ *data1 = (@type@ *)dataptr[1];
@@ -354,7 +354,7 @@ finish_after_unrolled_loop:
/* Some extra specializations for the two operand case */
static void
@name@_sum_of_products_stride0_contig_outcontig_two(int nop, char **dataptr,
- npy_intp *NPY_UNUSED(strides), npy_intp count)
+ npy_intp const *NPY_UNUSED(strides), npy_intp count)
{
@temptype@ value0 = @from@(*(@type@ *)dataptr[0]);
@type@ *data1 = (@type@ *)dataptr[1];
@@ -483,7 +483,7 @@ finish_after_unrolled_loop:
static void
@name@_sum_of_products_contig_stride0_outcontig_two(int nop, char **dataptr,
- npy_intp *NPY_UNUSED(strides), npy_intp count)
+ npy_intp const *NPY_UNUSED(strides), npy_intp count)
{
@type@ *data0 = (@type@ *)dataptr[0];
@temptype@ value1 = @from@(*(@type@ *)dataptr[1]);
@@ -567,7 +567,7 @@ finish_after_unrolled_loop:
static void
@name@_sum_of_products_contig_contig_outstride0_two(int nop, char **dataptr,
- npy_intp *NPY_UNUSED(strides), npy_intp count)
+ npy_intp const *NPY_UNUSED(strides), npy_intp count)
{
@type@ *data0 = (@type@ *)dataptr[0];
@type@ *data1 = (@type@ *)dataptr[1];
@@ -727,7 +727,7 @@ finish_after_unrolled_loop:
static void
@name@_sum_of_products_stride0_contig_outstride0_two(int nop, char **dataptr,
- npy_intp *NPY_UNUSED(strides), npy_intp count)
+ npy_intp const *NPY_UNUSED(strides), npy_intp count)
{
@temptype@ value0 = @from@(*(@type@ *)dataptr[0]);
@type@ *data1 = (@type@ *)dataptr[1];
@@ -826,7 +826,7 @@ finish_after_unrolled_loop:
static void
@name@_sum_of_products_contig_stride0_outstride0_two(int nop, char **dataptr,
- npy_intp *NPY_UNUSED(strides), npy_intp count)
+ npy_intp const *NPY_UNUSED(strides), npy_intp count)
{
@type@ *data0 = (@type@ *)dataptr[0];
@temptype@ value1 = @from@(*(@type@ *)dataptr[1]);
@@ -927,7 +927,7 @@ finish_after_unrolled_loop:
static void
@name@_sum_of_products_contig_three(int nop, char **dataptr,
- npy_intp *NPY_UNUSED(strides), npy_intp count)
+ npy_intp const *NPY_UNUSED(strides), npy_intp count)
{
@type@ *data0 = (@type@ *)dataptr[0];
@type@ *data1 = (@type@ *)dataptr[1];
@@ -971,7 +971,7 @@ static void
static void
@name@_sum_of_products_contig_@noplabel@(int nop, char **dataptr,
- npy_intp *NPY_UNUSED(strides), npy_intp count)
+ npy_intp const *NPY_UNUSED(strides), npy_intp count)
{
NPY_EINSUM_DBG_PRINT1("@name@_sum_of_products_contig_@noplabel@ (%d)\n",
(int)count);
@@ -1024,7 +1024,7 @@ static void
static void
@name@_sum_of_products_contig_outstride0_one(int nop, char **dataptr,
- npy_intp *strides, npy_intp count)
+ npy_intp const *strides, npy_intp count)
{
#if @complex@
@temptype@ accum_re = 0, accum_im = 0;
@@ -1201,7 +1201,7 @@ finish_after_unrolled_loop:
static void
@name@_sum_of_products_outstride0_@noplabel@(int nop, char **dataptr,
- npy_intp *strides, npy_intp count)
+ npy_intp const *strides, npy_intp count)
{
#if @complex@
@temptype@ accum_re = 0, accum_im = 0;
@@ -1319,7 +1319,7 @@ static void
static void
bool_sum_of_products_@noplabel@(int nop, char **dataptr,
- npy_intp *strides, npy_intp count)
+ npy_intp const *strides, npy_intp count)
{
#if (@nop@ <= 3)
char *data0 = dataptr[0];
@@ -1376,7 +1376,7 @@ bool_sum_of_products_@noplabel@(int nop, char **dataptr,
static void
bool_sum_of_products_contig_@noplabel@(int nop, char **dataptr,
- npy_intp *strides, npy_intp count)
+ npy_intp const *strides, npy_intp count)
{
#if (@nop@ <= 3)
char *data0 = dataptr[0];
@@ -1484,7 +1484,7 @@ finish_after_unrolled_loop:
static void
bool_sum_of_products_outstride0_@noplabel@(int nop, char **dataptr,
- npy_intp *strides, npy_intp count)
+ npy_intp const *strides, npy_intp count)
{
npy_bool accum = 0;
@@ -1538,7 +1538,7 @@ bool_sum_of_products_outstride0_@noplabel@(int nop, char **dataptr,
/**end repeat**/
-typedef void (*sum_of_products_fn)(int, char **, npy_intp *, npy_intp);
+typedef void (*sum_of_products_fn)(int, char **, npy_intp const*, npy_intp);
/* These tables need to match up with the type enum */
static sum_of_products_fn
@@ -1720,7 +1720,7 @@ static sum_of_products_fn _unspecialized_table[NPY_NTYPES][4] = {
static sum_of_products_fn
get_sum_of_products_function(int nop, int type_num,
- npy_intp itemsize, npy_intp *fixed_strides)
+ npy_intp itemsize, npy_intp const *fixed_strides)
{
int iop;
diff --git a/numpy/core/src/multiarray/item_selection.c b/numpy/core/src/multiarray/item_selection.c
index e6867083f..e2c3ebd00 100644
--- a/numpy/core/src/multiarray/item_selection.c
+++ b/numpy/core/src/multiarray/item_selection.c
@@ -825,7 +825,7 @@ PyArray_Choose(PyArrayObject *ip, PyObject *op, PyArrayObject *out,
*/
static int
_new_sortlike(PyArrayObject *op, int axis, PyArray_SortFunc *sort,
- PyArray_PartitionFunc *part, npy_intp *kth, npy_intp nkth)
+ PyArray_PartitionFunc *part, npy_intp const *kth, npy_intp nkth)
{
npy_intp N = PyArray_DIM(op, axis);
npy_intp elsize = (npy_intp)PyArray_ITEMSIZE(op);
@@ -953,7 +953,7 @@ fail:
static PyObject*
_new_argsortlike(PyArrayObject *op, int axis, PyArray_ArgSortFunc *argsort,
PyArray_ArgPartitionFunc *argpart,
- npy_intp *kth, npy_intp nkth)
+ npy_intp const *kth, npy_intp nkth)
{
npy_intp N = PyArray_DIM(op, axis);
npy_intp elsize = (npy_intp)PyArray_ITEMSIZE(op);
@@ -2028,7 +2028,7 @@ count_nonzero_bytes_384(const npy_uint64 * w)
* Returns -1 on error.
*/
NPY_NO_EXPORT npy_intp
-count_boolean_trues(int ndim, char *data, npy_intp *ashape, npy_intp *astrides)
+count_boolean_trues(int ndim, char *data, npy_intp const *ashape, npy_intp const *astrides)
{
int idim;
npy_intp shape[NPY_MAXDIMS], strides[NPY_MAXDIMS];
diff --git a/numpy/core/src/multiarray/item_selection.h b/numpy/core/src/multiarray/item_selection.h
index 2276b4db7..c1c8b5567 100644
--- a/numpy/core/src/multiarray/item_selection.h
+++ b/numpy/core/src/multiarray/item_selection.h
@@ -8,7 +8,7 @@
* Returns -1 on error.
*/
NPY_NO_EXPORT npy_intp
-count_boolean_trues(int ndim, char *data, npy_intp *ashape, npy_intp *astrides);
+count_boolean_trues(int ndim, char *data, npy_intp const *ashape, npy_intp const *astrides);
/*
* Gets a single item from the array, based on a single multi-index
diff --git a/numpy/core/src/multiarray/lowlevel_strided_loops.c.src b/numpy/core/src/multiarray/lowlevel_strided_loops.c.src
index 63b2a8842..d234c366c 100644
--- a/numpy/core/src/multiarray/lowlevel_strided_loops.c.src
+++ b/numpy/core/src/multiarray/lowlevel_strided_loops.c.src
@@ -974,9 +974,9 @@ PyArray_GetStridedNumericCastFn(int aligned, npy_intp src_stride,
NPY_NO_EXPORT npy_intp
PyArray_TransferNDimToStrided(npy_intp ndim,
char *dst, npy_intp dst_stride,
- char *src, npy_intp *src_strides, npy_intp src_strides_inc,
- npy_intp *coords, npy_intp coords_inc,
- npy_intp *shape, npy_intp shape_inc,
+ char *src, npy_intp const *src_strides, npy_intp src_strides_inc,
+ npy_intp const *coords, npy_intp coords_inc,
+ npy_intp const *shape, npy_intp shape_inc,
npy_intp count, npy_intp src_itemsize,
PyArray_StridedUnaryOp *stransfer,
NpyAuxData *data)
@@ -1092,10 +1092,10 @@ PyArray_TransferNDimToStrided(npy_intp ndim,
/* See documentation of arguments in lowlevel_strided_loops.h */
NPY_NO_EXPORT npy_intp
PyArray_TransferStridedToNDim(npy_intp ndim,
- char *dst, npy_intp *dst_strides, npy_intp dst_strides_inc,
+ char *dst, npy_intp const *dst_strides, npy_intp dst_strides_inc,
char *src, npy_intp src_stride,
- npy_intp *coords, npy_intp coords_inc,
- npy_intp *shape, npy_intp shape_inc,
+ npy_intp const *coords, npy_intp coords_inc,
+ npy_intp const *shape, npy_intp shape_inc,
npy_intp count, npy_intp src_itemsize,
PyArray_StridedUnaryOp *stransfer,
NpyAuxData *data)
@@ -1211,11 +1211,11 @@ PyArray_TransferStridedToNDim(npy_intp ndim,
/* See documentation of arguments in lowlevel_strided_loops.h */
NPY_NO_EXPORT npy_intp
PyArray_TransferMaskedStridedToNDim(npy_intp ndim,
- char *dst, npy_intp *dst_strides, npy_intp dst_strides_inc,
+ char *dst, npy_intp const *dst_strides, npy_intp dst_strides_inc,
char *src, npy_intp src_stride,
npy_uint8 *mask, npy_intp mask_stride,
- npy_intp *coords, npy_intp coords_inc,
- npy_intp *shape, npy_intp shape_inc,
+ npy_intp const *coords, npy_intp coords_inc,
+ npy_intp const *shape, npy_intp shape_inc,
npy_intp count, npy_intp src_itemsize,
PyArray_MaskedStridedUnaryOp *stransfer,
NpyAuxData *data)
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c
index 2540fba61..a725d9a49 100644
--- a/numpy/core/src/multiarray/multiarraymodule.c
+++ b/numpy/core/src/multiarray/multiarraymodule.c
@@ -161,7 +161,7 @@ PyArray_MultiplyList(npy_intp const *l1, int n)
* Multiply a List of Non-negative numbers with over-flow detection.
*/
NPY_NO_EXPORT npy_intp
-PyArray_OverflowMultiplyList(npy_intp *l1, int n)
+PyArray_OverflowMultiplyList(npy_intp const *l1, int n)
{
npy_intp prod = 1;
int i;
diff --git a/numpy/core/src/multiarray/nditer_constr.c b/numpy/core/src/multiarray/nditer_constr.c
index 5e770338d..e40a2d594 100644
--- a/numpy/core/src/multiarray/nditer_constr.c
+++ b/numpy/core/src/multiarray/nditer_constr.c
@@ -56,7 +56,7 @@ static int
npyiter_fill_axisdata(NpyIter *iter, npy_uint32 flags, npyiter_opitflags *op_itflags,
char **op_dataptr,
const npy_uint32 *op_flags, int **op_axes,
- npy_intp *itershape);
+ npy_intp const *itershape);
static void
npyiter_replace_axisdata(NpyIter *iter, int iop,
PyArrayObject *op,
@@ -80,7 +80,7 @@ npyiter_get_common_dtype(int nop, PyArrayObject **op,
static PyArrayObject *
npyiter_new_temp_array(NpyIter *iter, PyTypeObject *subtype,
npy_uint32 flags, npyiter_opitflags *op_itflags,
- int op_ndim, npy_intp *shape,
+ int op_ndim, npy_intp const *shape,
PyArray_Descr *op_dtype, const int *op_axes);
static int
npyiter_allocate_arrays(NpyIter *iter,
@@ -1424,7 +1424,7 @@ static int
npyiter_fill_axisdata(NpyIter *iter, npy_uint32 flags, npyiter_opitflags *op_itflags,
char **op_dataptr,
const npy_uint32 *op_flags, int **op_axes,
- npy_intp *itershape)
+ npy_intp const *itershape)
{
npy_uint32 itflags = NIT_ITFLAGS(iter);
int idim, ndim = NIT_NDIM(iter);
@@ -2476,7 +2476,7 @@ npyiter_get_common_dtype(int nop, PyArrayObject **op,
static PyArrayObject *
npyiter_new_temp_array(NpyIter *iter, PyTypeObject *subtype,
npy_uint32 flags, npyiter_opitflags *op_itflags,
- int op_ndim, npy_intp *shape,
+ int op_ndim, npy_intp const *shape,
PyArray_Descr *op_dtype, const int *op_axes)
{
npy_uint32 itflags = NIT_ITFLAGS(iter);
diff --git a/numpy/core/src/multiarray/shape.c b/numpy/core/src/multiarray/shape.c
index 4e31f003b..127ac5134 100644
--- a/numpy/core/src/multiarray/shape.c
+++ b/numpy/core/src/multiarray/shape.c
@@ -981,7 +981,7 @@ PyArray_Flatten(PyArrayObject *a, NPY_ORDER order)
/* See shape.h for parameters documentation */
NPY_NO_EXPORT PyObject *
-build_shape_string(npy_intp n, npy_intp *vals)
+build_shape_string(npy_intp n, npy_intp const *vals)
{
npy_intp i;
PyObject *ret, *tmp;
diff --git a/numpy/core/src/multiarray/shape.h b/numpy/core/src/multiarray/shape.h
index 0451a463e..d25292556 100644
--- a/numpy/core/src/multiarray/shape.h
+++ b/numpy/core/src/multiarray/shape.h
@@ -6,7 +6,7 @@
* A negative value in 'vals' gets interpreted as newaxis.
*/
NPY_NO_EXPORT PyObject *
-build_shape_string(npy_intp n, npy_intp *vals);
+build_shape_string(npy_intp n, npy_intp const *vals);
/*
* Creates a sorted stride perm matching the KEEPORDER behavior
diff --git a/numpy/core/src/multiarray/strfuncs.c b/numpy/core/src/multiarray/strfuncs.c
index 495d897b2..33f3a6543 100644
--- a/numpy/core/src/multiarray/strfuncs.c
+++ b/numpy/core/src/multiarray/strfuncs.c
@@ -64,7 +64,7 @@ extend_str(char **strp, Py_ssize_t n, Py_ssize_t *maxp)
static int
dump_data(char **string, Py_ssize_t *n, Py_ssize_t *max_n, char *data, int nd,
- npy_intp *dimensions, npy_intp *strides, PyArrayObject* self)
+ npy_intp const *dimensions, npy_intp const *strides, PyArrayObject* self)
{
PyObject *op = NULL, *sp = NULL;
char *ostring;
diff --git a/numpy/core/src/umath/reduction.h b/numpy/core/src/umath/reduction.h
index dfaeabcbb..0c2183ed6 100644
--- a/numpy/core/src/umath/reduction.h
+++ b/numpy/core/src/umath/reduction.h
@@ -100,8 +100,8 @@ typedef int (PyArray_AssignReduceIdentityFunc)(PyArrayObject *result,
*/
typedef int (PyArray_ReduceLoopFunc)(NpyIter *iter,
char **dataptr,
- npy_intp *strideptr,
- npy_intp *countptr,
+ npy_intp const *strideptr,
+ npy_intp const *countptr,
NpyIter_IterNextFunc *iternext,
int needs_api,
npy_intp skip_first_count,
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index 7bf530b6b..9ef0f822b 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -3424,8 +3424,8 @@ reduce_type_resolver(PyUFuncObject *ufunc, PyArrayObject *arr,
}
static int
-reduce_loop(NpyIter *iter, char **dataptrs, npy_intp *strides,
- npy_intp *countptr, NpyIter_IterNextFunc *iternext,
+reduce_loop(NpyIter *iter, char **dataptrs, npy_intp const *strides,
+ npy_intp const *countptr, NpyIter_IterNextFunc *iternext,
int needs_api, npy_intp skip_first_count, void *data)
{
PyArray_Descr *dtypes[3], **iter_dtypes;
@@ -3502,7 +3502,11 @@ reduce_loop(NpyIter *iter, char **dataptrs, npy_intp *strides,
strides_copy[2] = strides[0];
if (!masked) {
- innerloop(dataptrs_copy, countptr,
+ /* gh-15252: The signature of the inner loop considers `countptr`
+ * mutable. Inner loops aren't actually allowed to modify this
+ * though, so it's fine to cast it.
+ */
+ innerloop(dataptrs_copy, (npy_intp *)countptr,
strides_copy, innerloopdata);
}
else {
diff --git a/numpy/f2py/src/fortranobject.c b/numpy/f2py/src/fortranobject.c
index 973741ca7..456e64893 100644
--- a/numpy/f2py/src/fortranobject.c
+++ b/numpy/f2py/src/fortranobject.c
@@ -590,7 +590,7 @@ count_negative_dimensions(const int rank,
}
#ifdef DEBUG_COPY_ND_ARRAY
-void dump_dims(int rank, npy_intp* dims) {
+void dump_dims(int rank, npy_intp const* dims) {
int i;
printf("[");
for(i=0;i<rank;++i) {