Skip to content

Commit c102bcb

Browse files
committed
allow 3-way copy arg to align all constructors
1 parent a92e481 commit c102bcb

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/array_api_stubs/_draft/array_object.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def __dlpack__(
294294
stream: Optional[Union[int, Any]] = None,
295295
max_version: Optional[tuple[int, int]] = None,
296296
dl_device: Optional[Tuple[Enum, int]] = None,
297-
copy: Optional[bool] = False
297+
copy: Optional[bool] = None
298298
) -> PyCapsule:
299299
"""
300300
Exports the array for consumption by :func:`~array_api.from_dlpack` as a DLPack capsule.
@@ -335,23 +335,24 @@ def __dlpack__(
335335
not want to think about stream handling at all, potentially at the
336336
cost of more synchronizations than necessary.
337337
max_version: Optional[tuple[int, int]]
338-
The maximum DLPack version that the *consumer* (i.e., the caller of
338+
the maximum DLPack version that the *consumer* (i.e., the caller of
339339
``__dlpack__``) supports, in the form of a 2-tuple ``(major, minor)``.
340340
This method may return a capsule of version ``max_version`` (recommended
341341
if it does support that), or of a different version.
342342
This means the consumer must verify the version even when
343343
`max_version` is passed.
344344
dl_device: Optional[Tuple[Enum, int]]
345-
The DLPack device type. Default is ``None``, meaning the exported capsule
345+
the DLPack device type. Default is ``None``, meaning the exported capsule
346346
should be on the same device as ``self`` is. When specified, the format
347347
must follow that of the return value of :meth:`array.__dlpack_device__`.
348348
If the device type cannot be handled by the producer, this function must
349349
raise `BufferError`.
350350
copy: Optional[bool]
351-
Whether or not a copy should be made. Default is ``False`` to enable
352-
zero-copy data exchange. However, a user can request a copy to be made
353-
by the producer (through the consumer's :func:`~array_api.from_dlpack`)
354-
to move data across the library (and/or device) boundary.
351+
boolean indicating whether or not to copy the input. If ``True``, the
352+
function must always copy (paerformed by the producer), potentially allowing
353+
data movement across the library (and/or device) boundary. If ``False``,
354+
the function must never copy. If ``None``, the function must reuse existing
355+
memory buffer if possible and copy otherwise. Default: ``None``.
355356
356357
Returns
357358
-------

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)