Skip to content

Commit 8bc321c

Browse files
committed
allow 3-way copy arg to align all constructors
1 parent 181eefb commit 8bc321c

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

Diff for: src/array_api_stubs/_draft/array_object.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def __dlpack__(
292292
stream: Optional[Union[int, Any]] = None,
293293
max_version: Optional[tuple[int, int]] = None,
294294
dl_device: Optional[Tuple[Enum, int]] = None,
295-
copy: Optional[bool] = False
295+
copy: Optional[bool] = None
296296
) -> PyCapsule:
297297
"""
298298
Exports the array for consumption by :func:`~array_api.from_dlpack` as a DLPack capsule.
@@ -333,21 +333,22 @@ def __dlpack__(
333333
not want to think about stream handling at all, potentially at the
334334
cost of more synchronizations than necessary.
335335
max_version: Optional[tuple[int, int]]
336-
The maximum DLPack version that the *consumer* (i.e., the caller of
336+
the maximum DLPack version that the *consumer* (i.e., the caller of
337337
``__dlpack__``) supports, in the form of a 2-tuple ``(major, minor)``.
338338
This method may return a capsule of version ``max_version`` (recommended
339339
if it does support that), or of a different version.
340340
dl_device: Optional[Tuple[Enum, int]]
341-
The DLPack device type. Default is ``None``, meaning the exported capsule
341+
the DLPack device type. Default is ``None``, meaning the exported capsule
342342
should be on the same device as ``self`` is. When specified, the format
343343
must follow that of the return value of :meth:`array.__dlpack_device__`.
344344
If the device type cannot be handled by the producer, this function must
345345
raise `BufferError`.
346346
copy: Optional[bool]
347-
Whether or not a copy should be made. Default is ``False`` to enable
348-
zero-copy data exchange. However, a user can request a copy to be made
349-
by the producer (through the consumer's :func:`~array_api.from_dlpack`)
350-
to move data across the library (and/or device) boundary.
347+
boolean indicating whether or not to copy the input. If ``True``, the
348+
function must always copy (paerformed by the producer), potentially allowing
349+
data movement across the library (and/or device) boundary. If ``False``,
350+
the function must never copy. If ``None``, the function must reuse existing
351+
memory buffer if possible and copy otherwise. Default: ``None``.
351352
352353
Returns
353354
-------

Diff for: src/array_api_stubs/_draft/creation_functions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def eye(
218218
def from_dlpack(
219219
x: object, /, *,
220220
device: Optional[device] = None,
221-
copy: Optional[bool] = False,
221+
copy: Optional[bool] = None
222222
) -> Union[array, Any]:
223223
"""
224224
Returns a new array containing the data from another (array) object with a ``__dlpack__`` method.
@@ -238,7 +238,7 @@ def from_dlpack(
238238
239239
Other kinds of devices will be considered for standardization in a future version.
240240
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``.
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). If ``None``, the function must reuse existing memory buffer if possible and copy otherwise. Default: ``None``.
242242
243243
If a copy is needed, the stream over which the copy is performed must be taken from the consumer, following the DLPack protocol (see :meth:`array.__dlpack__`).
244244

0 commit comments

Comments
 (0)