From 0ef42959c4075455fa0e5b49c7e614a5234b8ed0 Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Fri, 11 Dec 2020 10:33:17 +0100 Subject: [PATCH 1/2] Do not modify key in place within setitem, getitem --- heat/core/dndarray.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/heat/core/dndarray.py b/heat/core/dndarray.py index 4c9d0d6f97..bafc0ade42 100644 --- a/heat/core/dndarray.py +++ b/heat/core/dndarray.py @@ -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: @@ -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 From d277e7be8d7a75d82c2edf4b5cb16b3d3243a510 Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Fri, 11 Dec 2020 10:44:40 +0100 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2435124c1a..8520bba20e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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