Skip to content

Commit 4c134fe

Browse files
authored
Add admonition concerning array view mutation (#420)
* Add admonition concerning array view mutation * Update admonition
1 parent 416b71a commit 4c134fe

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Diff for: spec/design_topics/copies_views_and_mutation.rst

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
Copy-view behaviour and mutability
44
==================================
55

6+
.. admonition:: Mutating views
7+
:class: important
8+
9+
Array API consumers are *strongly* advised to avoid *any* mutating operations when an array object may be either a "view" (i.e., an array whose data refers to memory that belongs to another array) or own memory of which one or more other array objects may be views. This admonition may become more strict in the future (e.g., this specification may require that view mutation be prohibited and trigger an exception). Accordingly, only perform mutation operations (e.g., in-place assignment) when absolutely confident that array data belongs to one, and only one, array object.
10+
611
Strided array implementations (e.g. NumPy, PyTorch, CuPy, MXNet) typically
712
have the concept of a "view", meaning an array containing data in memory that
813
belongs to another array (i.e. a different "view" on the original data).
@@ -70,6 +75,3 @@ of reusing arrays that are no longer needed as buffers.
7075
This leaves the problem of the initial example - with this API standard it
7176
remains possible to write code that will not work the same for all array
7277
libraries. This is something that the user must be careful about.
73-
74-
.. note::
75-
It is recommended that users avoid any mutating operations when a view may be involved.

0 commit comments

Comments
 (0)