Skip to content
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

Do not modify key in place within setitem, getitem #706

Merged
merged 2 commits into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- [#678](https://github.com/helmholtz-analytics/heat/pull/678) Bugfix: Internal functions now use explicit device parameters for DNDarray and torch.Tensor initializations.
- [#684](https://github.com/helmholtz-analytics/heat/pull/684) Bug fix: distributed `reshape` now works on booleans as well.
- [#706](https://github.com/helmholtz-analytics/heat/pull/706) Bug fix: prevent `__setitem__`, `__getitem__` from modifying key in place

# v0.5.0

Expand Down
2 changes: 2 additions & 0 deletions heat/core/dndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,7 @@ def __getitem__(self, key):
(1/2) >>> tensor([0.])
(2/2) >>> tensor([0., 0.])
"""
key = getattr(key, "copy()", key)
l_dtype = self.dtype.torch_type()
kgshape_flag = False
if isinstance(key, DNDarray) and key.ndim == self.ndim:
Expand Down Expand Up @@ -3111,6 +3112,7 @@ def __setitem__(self, key, value):
(2/2) >>> tensor([[0., 1., 0., 0., 0.],
[0., 1., 0., 0., 0.]])
"""
key = getattr(key, "copy()", key)
if isinstance(key, DNDarray) and key.ndim == self.ndim:
# this splits the key into torch.Tensors in each dimension for advanced indexing
lkey = [slice(None, None, None)] * self.ndim
Expand Down