Skip to content

Commit

Permalink
add release note, error out if offset is used
Browse files Browse the repository at this point in the history
  • Loading branch information
mattip committed Nov 9, 2021
1 parent c38b7f3 commit f6076ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions doc/release/upcoming_changes/19083.new_feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Add NEP 47-compatible dlpack support
------------------------------------

Add a ``ndarray.__dlpack__()`` method which returns a ``dlpack`` C structure
wrapped in a ``PyCapsule``. Also add a ``np._from_dlpack(obj)`` function, where
``obj`` supports ``__dlpack__()``, and returns an ``ndarray``.
8 changes: 7 additions & 1 deletion numpy/core/src/multiarray/dlpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ array_dlpack(PyArrayObject *self,
if (data == NULL) {
return NULL;
}
if ((char *)PyArray_DATA(self) - data != 0) {
PyErr_SetString(PyExc_TypeError,
"Offsets not clearly supported by this "
"version of DLPack.");
return NULL;
}

DLManagedTensor *managed = PyMem_Malloc(sizeof(DLManagedTensor));
if (managed == NULL) {
Expand Down Expand Up @@ -238,7 +244,7 @@ array_dlpack(PyArrayObject *self,
if (PyArray_SIZE(self) != 1 && !PyArray_IS_C_CONTIGUOUS(self)) {
managed->dl_tensor.strides = managed_strides;
}
managed->dl_tensor.byte_offset = (char *)PyArray_DATA(self) - data;
managed->dl_tensor.byte_offset = 0;
managed->manager_ctx = self;
managed->deleter = array_dlpack_deleter;

Expand Down

0 comments on commit f6076ee

Please sign in to comment.