8000 DOC: Added explanation document on interoperability by melissawm · Pull Request #20185 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

DOC: Added explanation document on interoperability #20185

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

Merged
merged 5 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/reference/arrays.classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ however, of why your subroutine may not be able to handle an arbitrary
subclass of an array is that matrices redefine the "*" operator to be
matrix-multiplication, rather than element-by-element multiplication.

.. _special-attributes-and-methods:

Special attributes and methods
==============================
Expand Down
32 changes: 19 additions & 13 deletions doc/source/reference/arrays.interface.rst
10000
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

.. _arrays.interface:

*******************
The Array Interface
*******************
****************************
The array interface protocol
****************************

.. note::

This page describes the numpy-specific API for accessing the contents of
a numpy array from other C extensions. :pep:`3118` --
This page describes the NumPy-specific API for accessing the contents of
a NumPy array from other C extensions. :pep:`3118` --
:c:func:`The Revised Buffer Protocol <PyObject_GetBuffer>` introduces
similar, standardized API to Python 2.6 and 3.0 for any extension
module to use. Cython__'s buffer array support
uses the :pep:`3118` API; see the `Cython numpy
uses the :pep:`3118` API; see the `Cython NumPy
tutorial`__. Cython provides a way to write code that supports the buffer
protocol with Python versions older than 2.6 because it has a
backward-compatible implementation utilizing the array interface
Expand Down Expand Up @@ -81,7 +81,8 @@ This approach to the interface consists of the object having an
===== ================================================================
``t`` Bit field (following integer gives the number of
bits in the bit field).
``b`` Boolean (integer type where all values are only True or False)
``b`` Boolean (integer type where all values are only ``True`` or
``False``)
``i`` Integer
``u`` Unsigned integer
``f`` Floating point
Expand Down Expand Up @@ -141,11 +142,11 @@ This approach to the interface consists of the object having an
must be stored by the new object if the memory area is to be
secured.

**Default**: None
**Default**: ``None``

**strides** (optional)
Either ``None`` to indicate a C-style contiguous array or
a Tuple of strides which provides the number of bytes needed
a tuple of strides which provides the number of bytes needed
to jump to the next array element in the corresponding
dimension. Each entry must be an integer (a Python
:py:class:`int`). As with shape, the values may
Expand All @@ -156,26 +157,26 @@ This approach to the interface consists of the object having an
memory buffer. In this model, the last dimension of the array
varies the fastest. For example, the default strides tuple
for an object whose array entries are 8 bytes long and whose
shape is ``(10, 20, 30)`` would be ``(4800, 240, 8)``
shape is ``(10, 20, 30)`` would be ``(4800, 240, 8)``.

**Default**: ``None`` (C-style contiguous)

**mask** (optional)
None or an object exposing the array interface. All
``None`` or an object exposing the array interface. All
elements of the mask array should be interpreted only as true
or not true indicating which elements of this array are valid.
The shape of this object should be `"broadcastable"
<arrays.broadcasting.broadcastable>` to the shape of the
original array.

**Default**: None (All array values are valid)
**Default**: ``None`` (All array values are valid)

**offset** (optional)
An integer offset into the array data region. This can only be
used when data is ``None`` or returns a :class:`buffer`
object.

**Default**: 0.
**Default**: ``0``.

**version** (required)
An integer showing the version of the interface (i.e. 3 for
Expand Down Expand Up @@ -243,6 +244,11 @@ flag is present.
returning the :c:type:`PyCapsule`, and configure a destructor to decref this
reference.

.. note::

:obj:`__array_struct__` is considered legacy and should not be used for new
code. Use the :py:doc:`buffer protocol <c-api/buffer>` instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we deprecate it? I think also ndarray.dlpack could be mentioned as an alternative, although I see it is not part of the documentation ...

Checking for uses of __array_struct__ I found only pygame, and opened pygame/pygame#2949 to ask about removing it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good idea to me

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I add a deprecation note here? Or wait until it is actually marked for deprecation?



Type description examples
=========================
Expand Down
Loading
0