jorisvandenbossche commented on code in PR #38472:
URL: https://github.com/apache/arrow/pull/38472#discussion_r1415454572
##########
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:
There is exactly one mention of `__dlpack_device__` on that page (just the
mention that it exists in bullet point no 2), but unfortunately without any
explanation of what it is or should return.
So implementation defined, eg
https://github.com/numpy/numpy/blob/eabb962d38d8a871b2d76a9198846b49897365eb/numpy/_core/src/multiarray/dlpack.c#L279-L287
or
https://github.com/pytorch/pytorch/blob/89569be2bdb608e64a190c5498f36b711ddd3e8d/torch/_tensor.py#L1484-L1502
--
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]