You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support copy and device keywords in from_dlpack (#741)
* support copy in from_dlpack
* specify copy stream
* allow 3-way copy arg to align all constructors
* update to reflect the discussions
* clairfy a bit and fix typos
* sync the copy docs
* clarify what's 'on CPU'
* try to make linter happy
* remove namespace leak clause, clean up, and add an example
* make linter happy
* fix Sphinx complaint about Enum
* add/update v2023-specific notes on device
* remove a note on kDLCPU
---------
Co-authored-by: Ralf Gommers <[email protected]>
Copy file name to clipboardExpand all lines: src/array_api_stubs/_draft/creation_functions.py
+43-3
Original file line number
Diff line number
Diff line change
@@ -214,19 +214,36 @@ def eye(
214
214
"""
215
215
216
216
217
-
deffrom_dlpack(x: object, /) ->array:
217
+
deffrom_dlpack(
218
+
x: object,
219
+
/,
220
+
*,
221
+
device: Optional[device] =None,
222
+
copy: Optional[bool] =None,
223
+
) ->array:
218
224
"""
219
225
Returns a new array containing the data from another (array) object with a ``__dlpack__`` method.
220
226
221
227
Parameters
222
228
----------
223
229
x: object
224
230
input (array) object.
231
+
device: Optional[device]
232
+
device on which to place the created array. If ``device`` is ``None`` and ``x`` supports DLPack, the output array must be on the same device as ``x``. Default: ``None``.
233
+
234
+
The v2023.12 standard only mandates that a compliant library should offer a way for ``from_dlpack`` to return an array
235
+
whose underlying memory is accessible to the Python interpreter, when the corresponding ``device`` is provided. If the
236
+
array library does not support such cases at all, the function must raise ``BufferError``. If a copy must be made to
237
+
enable this support but ``copy`` is set to ``False``, the function must raise ``ValueError``.
238
+
239
+
Other device kinds will be considered for standardization in a future version of this API standard.
240
+
copy: Optional[bool]
241
+
boolean indicating whether or not to copy the input. If ``True``, the function must always copy. If ``False``, the function must never copy, and raise ``BufferError`` in case a copy is deemed necessary (e.g. if a cross-device data movement is requested, and it is not possible without a copy). If ``None``, the function must reuse the existing memory buffer if possible and copy otherwise. Default: ``None``.
0 commit comments