Skip to content

Commit 861b28c

Browse files
committed
docs: clarify copy kwarg behavior in asarray for libraries disallowing mutation
Ref: data-apis#495
1 parent 52bbfeb commit 861b28c

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/array_api_stubs/_draft/creation_functions.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,15 @@ def asarray(
100100
101101
Default: ``None``.
102102
103-
.. admonition:: Note
104-
:class: note
105-
106-
If ``dtype`` is not ``None``, then array conversions should obey :ref:`type-promotion` rules. Conversions not specified according to :ref:`type-promotion` rules may or may not be permitted by a conforming array library. To perform an explicit cast, use :func:`array_api.astype`.
107-
108-
.. note::
109-
If an input value exceeds the precision of the resolved output array data type, behavior is left unspecified and, thus, implementation-defined.
110-
111103
device: Optional[device]
112104
device on which to place the created array. If ``device`` is ``None`` and ``obj`` is an array, the output array device must be inferred from ``obj``. Default: ``None``.
113105
copy: Optional[bool]
114106
boolean indicating whether or not to copy the input. If ``True``, the function must always copy. If ``False``, the function must never copy for input which supports the buffer protocol and must raise a ``ValueError`` in case a copy would be necessary. If ``None``, the function must reuse existing memory buffer if possible and copy otherwise. Default: ``None``.
115107
108+
.. note::
109+
110+
A common use case for setting ``copy`` equal to ``True`` is to guarantee that, when provided an array ``x``, ``asarray(x, copy=True)`` returns an array which may be mutated without affecting user data. For conforming implementations which disallow mutation, explicitly copying array data belonging to a known array type to a new memory location may not be necessary. Accordingly, such implementations may choose to ignore the ``copy`` keyword argument when ``obj`` is an array belonging to that implementation.
111+
116112
Returns
117113
-------
118114
out: array
@@ -121,6 +117,10 @@ def asarray(
121117
Notes
122118
-----
123119
120+
- If ``dtype`` is not ``None``, then array conversions should obey :ref:`type-promotion` rules. Conversions not specified according to :ref:`type-promotion` rules may or may not be permitted by a conforming array library. To perform an explicit cast, use :func:`array_api.astype`.
121+
- If an input value exceeds the precision of the resolved output array data type, behavior is left unspecified and, thus, implementation-defined.
122+
- must ensure that the returned array does not share data with another array, either by copying the data to a new memory location or in some other way (e.g., this property is guaranteed by design)
123+
124124
.. versionchanged:: 2022.12
125125
Added complex data type support.
126126
"""

0 commit comments

Comments
 (0)