PyArray_GETITEM and PyArray_SETITEM
Hello All, I need to make use of the limited numpy API access Pybind11 gives, in order to add a feature to it. It seems to give access to functions from numpy_api.py [1]. I need to use PyArray_GETITEM and PyArray_SETITEM in order to get and set array elements [2], these functions / macros are not exposed via numpy_api.py, but are in `numpy/ndarraytypes.h`. We were wondering why aren't PyArray_GETITEM and PyArray_SETITEM exposed like the rest of numpy API? Is it possible to replicate the behavior using the members exposed in numpy_api.py ? Any help would be appreciated. Mmanu [1] https://github.com/numpy/numpy/blob/1368cbb696ae27b849eed67b4fd31c 550a55dad5/numpy/core/code_generators/numpy_api.py [2] https://github.com/pybind/pybind11/pull/1152/files#diff- 52f1945d779be1e60903590907bb9326R241
On 11/13/2017 01:53 PM, Mmanu Chaturvedi wrote:
Hello All,
I need to make use of the limited numpy API access Pybind11 gives, in order to add a feature to it. It seems to give access to functions from numpy_api.py [1]. I need to use PyArray_GETITEM and PyArray_SETITEM in order to get and set array elements [2], these functions / macros are not exposed via numpy_api.py, but are in `numpy/ndarraytypes.h`.
We were wondering why aren't PyArray_GETITEM and PyArray_SETITEM exposed like the rest of numpy API? Is it possible to replicate the behavior using the members exposed in numpy_api.py ? Any help would be appreciated.
Mmanu
It looks like that was the plan. There are comments there saying they would become part of the API in "numpy 2.0" (which hasn't happened yet). In the meantime, maybe you can use PySequence_SetItem? I expect that there is only very minimal overhead in using that vs PyArray_SETITEM. Allan
It’s worth noting that PyArray_GETITEM is the equivalent of arr[....].item(), not arr[...]. If you want the behavior of the latter, use PyArray_Scalar instead. Similarly, PyArray_SETITEM is only guaranteed to be equivalent to arr[...] = x when isinstance(x, np.generic) is false. I don’t think these belong in public API yet, because they don’t expose the interface that most people might expect. Their names are based solely on the names of descr->f->getitem. Eric On Fri, 17 Nov 2017 at 13:12 Allan Haldane <allanhaldane@gmail.com> wrote:
On 11/13/2017 01:53 PM, Mmanu Chaturvedi wrote:
Hello All,
I need to make use of the limited numpy API access Pybind11 gives, in order to add a feature to it. It seems to give access to functions from numpy_api.py [1]. I need to use PyArray_GETITEM and PyArray_SETITEM in order to get and set array elements [2], these functions / macros are not exposed via numpy_api.py, but are in `numpy/ndarraytypes.h`.
We were wondering why aren't PyArray_GETITEM and PyArray_SETITEM exposed like the rest of numpy API? Is it possible to replicate the behavior using the members exposed in numpy_api.py ? Any help would be appreciated.
Mmanu
It looks like that was the plan. There are comments there saying they would become part of the API in "numpy 2.0" (which hasn't happened yet).
In the meantime, maybe you can use PySequence_SetItem? I expect that there is only very minimal overhead in using that vs PyArray_SETITEM.
Allan _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@python.org https://mail.python.org/mailman/listinfo/numpy-discussion
participants (3)
-
Allan Haldane
-
Eric Wieser
-
Mmanu Chaturvedi