Skip to content

Commit 8361ce8

Browse files
authored
Merge pull request numpy#26241 from seberg/intp-doc-fixups
DOC: Fixup intp/uintp documentation for ssize_t/size_t changes
2 parents 934e94d + 816df7e commit 8361ce8

File tree

2 files changed

+46
-21
lines changed

2 files changed

+46
-21
lines changed

doc/source/reference/arrays.scalars.rst

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ of the flexible itemsize array types (:class:`str_`,
3737

3838
**Figure:** Hierarchy of type objects representing the array data
3939
types. Not shown are the two integer types :class:`intp` and
40-
:class:`uintp` which just point to the integer type that holds a
41-
pointer for the platform. All the number types can be obtained
42-
using bit-width names as well.
40+
:class:`uintp` which are used for indexing (the same as the
41+
default integer since NumPy 2).
4342

4443

4544
.. TODO - use something like this instead of the diagram above, as it generates
@@ -377,21 +376,29 @@ are also provided.
377376

378377
Alias for the signed integer type (one of `numpy.byte`, `numpy.short`,
379378
`numpy.intc`, `numpy.int_`, `numpy.long` and `numpy.longlong`)
380-
that is the same size as a pointer.
379+
that is used as a default integer and for indexing.
381380

382-
Compatible with the C ``intptr_t``.
381+
Compatible with the C ``Py_ssize_t``.
383382

384-
:Character code: ``'p'``
383+
:Character code: ``'n'``
384+
385+
.. versionchanged:: 2.0
386+
Before NumPy 2, this had the same size as a pointer. In practice this
387+
is almost always identical, but the character code ``'p'`` maps to the C
388+
``intptr_t``. The character code ``'n'`` was added in NumPy 2.0.
385389

386390
.. attribute:: uintp
387391

388-
Alias for the unsigned integer type (one of `numpy.ubyte`, `numpy.ushort`,
389-
`numpy.uintc`, `numpy.uint`, `numpy.ulong` and `numpy.ulonglong`)
390-
that is the same size as a pointer.
392+
Alias for the unsigned integer type that is the same size as ``intp``.
393+
394+
Compatible with the C ``size_t``.
391395

392-
Compatible with the C ``uintptr_t``.
396+
:Character code: ``'N'``
393397

394-
:Character code: ``'P'``
398+
.. versionchanged:: 2.0
399+
Before NumPy 2, this had the same size as a pointer. In practice this
400+
is almost always identical, but the character code ``'P'`` maps to the C
401+
``uintptr_t``. The character code ``'N'`` was added in NumPy 2.0.
395402

396403
.. autoclass:: numpy.float16
397404

doc/source/reference/c-api/dtype.rst

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,26 @@ Enumerated types
170170

171171
.. c:enumerator:: NPY_INTP
172172
173-
The enumeration value for a signed integer type which is the same
174-
size as a (void \*) pointer. This is the type used by all
173+
The enumeration value for a signed integer of type ``Py_ssize_t``
174+
(same as ``ssize_t`` if defined). This is the type used by all
175175
arrays of indices.
176176

177+
.. versionchanged:: 2.0
178+
Previously, this was the same as ``intptr_t`` (same size as a
179+
pointer). In practice, this is identical except on very niche
180+
platforms.
181+
You can use the ``'p'`` character code for the pointer meaning.
182+
177183
.. c:enumerator:: NPY_UINTP
178184
179-
The enumeration value for an unsigned integer type which is the
180-
same size as a (void \*) pointer.
185+
The enumeration value for an unsigned integer type that is identical
186+
to a ``size_t``.
187+
188+
.. versionchanged:: 2.0
189+
Previously, this was the same as ``uintptr_t`` (same size as a
190+
pointer). In practice, this is identical except on very niche
191+
platforms.
192+
You can use the ``'P'`` character code for the pointer meaning.
181193

182194
.. c:enumerator:: NPY_MASK
183195
@@ -287,14 +299,20 @@ all platforms for all the kinds of numeric types. Commonly 8-, 16-,
287299
types are available.
288300

289301

290-
Integer that can hold a pointer
291-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
302+
Further integer aliases
303+
~~~~~~~~~~~~~~~~~~~~~~~
292304

293-
The constants **NPY_INTP** and **NPY_UINTP** refer to an
294-
enumerated integer type that is large enough to hold a pointer on the
295-
platform. Index arrays should always be converted to **NPY_INTP**
296-
, because the dimension of the array is of type npy_intp.
305+
The constants **NPY_INTP** and **NPY_UINTP** refer to an ``Py_ssize_t``
306+
and ``size_t``.
307+
Although in practice normally true, these types are strictly speaking not
308+
pointer sized and the character codes ``'p'`` and ``'P'`` can be used for
309+
pointer sized integers.
310+
(Before NumPy 2, ``intp`` was pointer size, but this almost never matched
311+
the actual use, which is the reason for the name.)
297312

313+
Since NumPy 2, **NPY_DEFAULT_INT** is additionally defined.
314+
The value of the macro is runtime dependent: Since NumPy 2, it maps to
315+
``NPY_INTP`` while on earlier versions it maps to ``NPY_LONG``.
298316

299317
C-type names
300318
------------

0 commit comments

Comments
 (0)