Skip to content

Commit bf78843

Browse files
authored
Update mutability example (#90)
Closes gh-82
1 parent 38c49c5 commit bf78843

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

spec/design_topics/copies_views_and_mutation.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ This simple example illustrates that:
1212

1313
```python
1414
x = ones(1)
15-
x += 2
16-
y = x # `y` *may* be a view
15+
y = x[:] # `y` *may* be a view on the data of `x`
1716
y -= 1 # if `y` is a view, this modifies `x`
1817
```
1918

2019
Code as simple as the above example will not be portable between array
21-
libraries - for NumPy/PyTorch/CuPy/MXNet `x` will contain the value `2`,
22-
while for TensorFlow/JAX/Dask it will contain the value `3`. The combination
20+
libraries - for NumPy/PyTorch/CuPy/MXNet `x` will contain the value `0`,
21+
while for TensorFlow/JAX/Dask it will contain the value `1`. The combination
2322
of views and mutability is fundamentally problematic here if the goal is to
2423
be able to write code with unambiguous semantics.
2524

0 commit comments

Comments
 (0)