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
Copy file name to clipboardExpand all lines: src/array_api_stubs/_draft/creation_functions.py
+26-5
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,7 @@
19
19
20
20
21
21
from ._typesimport (
22
+
Any,
22
23
List,
23
24
NestedSequence,
24
25
Optional,
@@ -214,19 +215,36 @@ def eye(
214
215
"""
215
216
216
217
217
-
deffrom_dlpack(x: object, /) ->array:
218
+
deffrom_dlpack(
219
+
x: object, /, *,
220
+
device: Optional[device] =None,
221
+
copy: Optional[bool] =False,
222
+
) ->Union[array, Any]:
218
223
"""
219
224
Returns a new array containing the data from another (array) object with a ``__dlpack__`` method.
220
225
221
226
Parameters
222
227
----------
223
228
x: object
224
229
input (array) object.
230
+
device: Optional[device]
231
+
device on which to place the created array. If ``device`` is ``None`` and ``x`` supports DLPack, the output array device must be inferred from ``x``. Default: ``None``.
232
+
233
+
The v2023.12 standard only mandates that a compliant library must offer a way for ``from_dlpack`` to create an array on CPU (using
234
+
the library-chosen way to represent the CPU device - ``kDLCPU`` in DLPack - e.g. a ``"CPU"`` string or a ``Device("CPU")`` object).
235
+
If the compliant library does not support the CPU device and needs to outsource to another (compliant) array library, it may do so
236
+
with a clear user documentation and/or run-time warning. If a copy must be made to enable this, and ``copy`` is set to ``False``,
237
+
the function must raise ``ValueError``.
238
+
239
+
Other kinds of devices will be considered for standardization in a future version.
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 must raise a ``BufferError`` in case a copy would be necessary (e.g. the producer disallows views). Default: ``False``.
225
242
226
243
Returns
227
244
-------
228
-
out: array
229
-
an array containing the data in `x`.
245
+
out: Union[array, Any]
246
+
an array containing the data in ``x``. In the case that the compliant library does not support the given ``device`` out of box
247
+
and must oursource to another (compliant) library, the output will be that library's compliant array object.
0 commit comments