Skip to content

Update mutability example #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions spec/design_topics/copies_views_and_mutation.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ This simple example illustrates that:

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

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

Expand Down