-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
API: bump MAXDIMS/MAXARGS to 64 introduce NPY_AXIS_RAVEL #25149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
fc1bb6b
af55c6b
bbc4083
6a878e3
3270231
d6840f5
a5a250f
8dddc54
56b792c
0498d8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Lager ``NPY_MAXDIMS`` and ``NPY_MAXARGS``, ``NPY_RAVEL_AXIS`` introduced | ||
------------------------------------------------------------------------ | ||
|
||
``NPY_MAXDIMS`` is now 64, you may want to review its use. This is usually | ||
used in stack allocation, where the increase should be safe. | ||
However, we do encourage generally to remove any use of ``NPY_MAXDIMS`` and | ||
``NPY_MAXARGS`` to eventually allow removing the constraint completely. | ||
In some cases, ``NPY_MAXDIMS`` was passed (and returned) to mean ``axis=None`` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you make "In some cases" a little more specific? Does this only impact things that interact with numpy via the C API, or could you trigger this behavior from the python API too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The python side places are already mentioned in the other one, but made it a bit more concrete. |
||
these must be replaced with ``NPY_RAVEL_AXIS``. | ||
See also :ref:`migration_maxdims`. |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,8 @@ | ||||
Out-of-bound axis not the same as ``axis=None`` | ||||
----------------------------------------------- | ||||
In some cases ``axis=32`` or for concatenate any large value | ||||
was the same as ``axis=None``. | ||||
Except for ``concatenate`` this was deprecate. | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Was the deprecation noisy for other functions? Just wondering if we might want to merely deprecate this usage for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It gave a deprecation warning. I briefly considered that, and think that this is ridiculously niche. IIRC, we were close to not do the deprecation warning in the other path also. We are talking about |
||||
Any out of bound axis value will now error, make sure to use | ||||
``axis=None``. | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,8 +41,30 @@ Some are defined in ``numpy/_core/include/numpy/npy_2_compat.h`` | |
(for example ``NPY_DEFAULT_INT``) which can be vendored in full or part | ||
to have the definitions available when compiling against NumPy 1.x. | ||
|
||
If necessary, ``PyArray_RUNTIME_VERSION >= NPY_2_0_API_VERSION`` can be | ||
used to explicitly implement different behavior on NumPy 1.x and 2.0. | ||
(The compat header defines it in a way compatible with such use.) | ||
|
||
Please let us know if you require additional workarounds here. | ||
|
||
.. _migration_maxdims: | ||
|
||
Increased maximum number of dimensions | ||
-------------------------------------- | ||
The maximum number of dimensions (and arguments) was increased to 64, this | ||
affects the ``NPY_MAXDIMS`` and ``NPY_MAXARGS`` macros. | ||
It may be good to review their use, and we generally encourage you to | ||
not use this macros (especially ``NPY_MAXARGS``), so that a future version of | ||
seberg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
NumPy can remove this limitation on the number of dimensions. | ||
|
||
``NPY_MAXDIMS`` was also used to signal ``axis=None`` in the C-API, including | ||
the ``PyArray_AxisConverter``. | ||
If you run into this problem, you will see ``-2147483648`` | ||
(the minimum integer value) or ``64`` being used as an invalid axis. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might help to include the exact text of the error they'd see, so if they google the error message they'll find the migration guide |
||
Wherever you do, you must replace ``NPY_MAXDIMS`` with ``NPY_RAVEL_AXIS``. | ||
This is defined in the ``npy_2_compat.h`` header and runtime dependent. | ||
|
||
|
||
Namespace changes | ||
================= | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,8 +119,11 @@ PyArray_Type and PyArrayObject | |
array. When nd is 0, the array is sometimes called a rank-0 | ||
array. Such arrays have undefined dimensions and strides and | ||
cannot be accessed. Macro :c:data:`PyArray_NDIM` defined in | ||
``ndarraytypes.h`` points to this data member. :c:data:`NPY_MAXDIMS` | ||
is the largest number of dimensions for any array. | ||
``ndarraytypes.h`` points to this data member. | ||
Although most operations may be limited in dimensionality, we do not | ||
advertise a maximum dimension. Anyone explicitly relying on one | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a remnant of an earlier version that completely removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It wasn't a remnant, but rephrased a bit. |
||
must check for it. Before NumPy 2.0, NumPy used 32 dimensions at most | ||
after it, the limit is currently 64. | ||
|
||
.. c:member:: npy_intp *dimensions | ||
|
||
|
@@ -986,11 +989,11 @@ PyArrayIter_Type and PyArrayIterObject | |
int nd_m1; | ||
npy_intp index; | ||
npy_intp size; | ||
npy_intp coordinates[NPY_MAXDIMS]; | ||
npy_intp dims_m1[NPY_MAXDIMS]; | ||
npy_intp strides[NPY_MAXDIMS]; | ||
npy_intp backstrides[NPY_MAXDIMS]; | ||
npy_intp factors[NPY_MAXDIMS]; | ||
npy_intp coordinates[NPY_MAXDIMS_LEGACY_ITERS]; | ||
npy_intp dims_m1[NPY_MAXDIMS_LEGACY_ITERS]; | ||
npy_intp strides[NPY_MAXDIMS_LEGACY_ITERS]; | ||
npy_intp backstrides[NPY_MAXDIMS_LEGACY_ITERS]; | ||
npy_intp factors[NPY_MAXDIMS_LEGACY_ITERS]; | ||
PyArrayObject *ao; | ||
char *dataptr; | ||
npy_bool contiguous; | ||
|
@@ -1086,8 +1089,8 @@ PyArrayMultiIter_Type and PyArrayMultiIterObject | |
npy_intp size; | ||
npy_intp index; | ||
int nd; | ||
npy_intp dimensions[NPY_MAXDIMS]; | ||
PyArrayIterObject *iters[NPY_MAXDIMS]; | ||
npy_intp dimensions[NPY_MAXDIMS_LEGACY_ITERS]; | ||
PyArrayIterObject *iters[NPY_MAXDIMS_LEGACY_ITERS]; | ||
} PyArrayMultiIterObject; | ||
|
||
.. c:macro: PyObject_HEAD | ||
|
@@ -1141,20 +1144,20 @@ PyArrayNeighborhoodIter_Type and PyArrayNeighborhoodIterObject | |
PyObject_HEAD | ||
int nd_m1; | ||
npy_intp index, size; | ||
npy_intp coordinates[NPY_MAXDIMS] | ||
npy_intp dims_m1[NPY_MAXDIMS]; | ||
npy_intp strides[NPY_MAXDIMS]; | ||
npy_intp backstrides[NPY_MAXDIMS]; | ||
npy_intp factors[NPY_MAXDIMS]; | ||
npy_intp coordinates[NPY_MAXDIMS_LEGACY_ITERS] | ||
npy_intp dims_m1[NPY_MAXDIMS_LEGACY_ITERS]; | ||
npy_intp strides[NPY_MAXDIMS_LEGACY_ITERS]; | ||
npy_intp backstrides[NPY_MAXDIMS_LEGACY_ITERS]; | ||
npy_intp factors[NPY_MAXDIMS_LEGACY_ITERS]; | ||
PyArrayObject *ao; | ||
char *dataptr; | ||
npy_bool contiguous; | ||
npy_intp bounds[NPY_MAXDIMS][2]; | ||
npy_intp limits[NPY_MAXDIMS][2]; | ||
npy_intp limits_sizes[NPY_MAXDIMS]; | ||
npy_intp bounds[NPY_MAXDIMS_LEGACY_ITERS][2]; | ||
npy_intp limits[NPY_MAXDIMS_LEGACY_ITERS][2]; | ||
npy_intp limits_sizes[NPY_MAXDIMS_LEGACY_ITERS]; | ||
npy_iter_get_dataptr_t translate; | ||
npy_intp nd; | ||
npy_intp dimensions[NPY_MAXDIMS]; | ||
npy_intp dimensions[NPY_MAXDIMS_LEGACY_ITERS]; | ||
PyArrayIterObject* _internal_iter; | ||
char* constant; | ||
int mode; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,9 +182,8 @@ cdef extern from "numpy/arrayobject.h": | |
NPY_ARRAY_UPDATE_ALL | ||
|
||
cdef enum: | ||
NPY_MAXDIMS | ||
|
||
npy_intp NPY_MAX_ELSIZE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a bit random, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this removal need a release note? Just to say that if someone was using and relying on it, it wasn't doing what they thought it did. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤷 I doubt anyone will notice, but sure, added. |
||
NPY_MAXDIMS # 64 on NumPy 2.x and 32 on NumPy 1.x | ||
NPY_RAVEL_AXIS # Used for functions like PyArray_Mean | ||
|
||
ctypedef void (*PyArray_VectorUnaryFunc)(void *, void *, npy_intp, void *, void *) | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.