From 09f464308056ce93838b12d4e20602ec220c63f9 Mon Sep 17 00:00:00 2001 From: Pablo Brubeck Date: Thu, 29 Aug 2024 10:15:05 +0100 Subject: [PATCH] DatView: Fix zero() --- pyop2/types/dat.py | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/pyop2/types/dat.py b/pyop2/types/dat.py index 5ee339bcc..404c64acb 100644 --- a/pyop2/types/dat.py +++ b/pyop2/types/dat.py @@ -681,6 +681,7 @@ def __init__(self, dat, index): if not (0 <= i < d): raise ex.IndexValueError("Can't create DatView with index %s for Dat with shape %s" % (index, dat.dim)) self.index = index + self._idx = (slice(None), *index) self._parent = dat # Point at underlying data super(DatView, self).__init__(dat.dataset, @@ -722,39 +723,31 @@ def halo_valid(self, value): @property def data(self): - full = self._parent.data - idx = (slice(None), *self.index) - return full[idx] + return self._parent.data[self._idx] @property def data_ro(self): - full = self._parent.data_ro - idx = (slice(None), *self.index) - return full[idx] + return self._parent.data_ro[self._idx] @property def data_wo(self): - full = self._parent.data_wo - idx = (slice(None), *self.index) - return full[idx] + return self._parent.data_wo[self._idx] @property def data_with_halos(self): - full = self._parent.data_with_halos - idx = (slice(None), *self.index) - return full[idx] + return self._parent.data_with_halos[self._idx] @property def data_ro_with_halos(self): - full = self._parent.data_ro_with_halos - idx = (slice(None), *self.index) - return full[idx] + return self._parent.data_ro_with_halos[self._idx] @property def data_wo_with_halos(self): - full = self._parent.data_wo_with_halos - idx = (slice(None), *self.index) - return full[idx] + return self._parent.data_wo_with_halos[self._idx] + + @property + def _data(self): + return self._parent._data[self._idx] class Dat(AbstractDat, VecAccessMixin):