AlenkaF commented on code in PR #38472:
URL: https://github.com/apache/arrow/pull/38472#discussion_r1415539648
##########
python/pyarrow/array.pxi:
##########
@@ -1778,6 +1778,40 @@ cdef class Array(_PandasConvertible):
return pyarrow_wrap_array(array)
+ def __dlpack__(self, stream=None):
+ """Export a primitive array as a DLPack capsule.
+
+ Parameters
+ ----------
+ stream : int, optional
+ A Python integer representing a pointer to a stream. Currently not
supported.
+ Stream is provided by the consumer to the producer to instruct the
producer
+ to ensure that operations can safely be performed on the array.
+
+ Returns
+ -------
+ capsule : PyCapsule
+ A DLPack capsule for the array, containing a DLPackManagedTensor.
+ """
+ if stream is None:
+ return to_dlpack(self)
+ else:
+ raise NotImplementedError(
+ "Only stream=None is supported."
+ )
+
+ def __dlpack_device__(self):
+ """
+ Performs the operation __dlpack_device__.
Review Comment:
I have missed it too. It is in the second item in the enumerated list at
`Syntax for data interchange with DLPack`:
https://dmlc.github.io/dlpack/latest/python_spec.html#syntax-for-data-interchange-with-dlpack
Numpy doesn't use it in their `from_dlpack(x)` but they have it implemented
for the array object:
https://github.com/numpy/numpy/blob/eabb962d38d8a871b2d76a9198846b49897365eb/numpy/array_api/_array_object.py#L488-L493
PyTorch checks for `__dlpack_device__` in Python:
https://github.com/pytorch/pytorch/blob/89569be2bdb608e64a190c5498f36b711ddd3e8d/torch/utils/dlpack.py#L100-L101
but I am not sure if they have something similar in C++ (I think not).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]