From f2c58c51a204655a4859c4a12196a8eb38934d34 Mon Sep 17 00:00:00 2001 From: SaltyChiang Date: Thu, 12 Dec 2024 20:43:12 +0800 Subject: [PATCH] Fix a bug in `field.timeslice()`. --- pyquda_core/pyquda/_version.py | 2 +- pyquda_core/pyquda/field.py | 22 ++++++++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/pyquda_core/pyquda/_version.py b/pyquda_core/pyquda/_version.py index 43e38a8..61fb31c 100644 --- a/pyquda_core/pyquda/_version.py +++ b/pyquda_core/pyquda/_version.py @@ -1 +1 @@ -__version__ = "0.9.11" +__version__ = "0.10.0" diff --git a/pyquda_core/pyquda/field.py b/pyquda_core/pyquda/field.py index cf9ead4..1a654dc 100644 --- a/pyquda_core/pyquda/field.py +++ b/pyquda_core/pyquda/field.py @@ -586,16 +586,10 @@ def timeslice(self, start: int, stop: int = None, step: int = None, return_field gt = self.latt_info.gt stop = (start + 1) if stop is None else stop step = 1 if step is None else step - if step > 0: - s = (start - gt * Lt) % step if start < gt * Lt else 0 - start = max(start - gt * Lt, 0) + s - stop = min(stop - gt * Lt, Lt) - elif step < 0: - s = ((gt + 1) * Lt - start) % step if (gt + 1) * Lt <= start else 0 - start = min(start - gt * Lt, Lt - 1) + s - stop = max(stop - gt * Lt, -1) - start, stop = (0, Lt) if start <= stop else (start, stop) - stop = None if stop == -1 else stop # Workaround for numpy slice + s = (start - gt * Lt) % step if start < gt * Lt and stop > gt * Lt else 0 + start = min(max(start - gt * Lt, 0), Lt) + s + stop = min(max(stop - gt * Lt, 0), Lt) + assert start <= stop and step > 0 if return_field: if self.L5 is None: x = self.__class__(self.latt_info) @@ -607,14 +601,14 @@ def timeslice(self, start: int, stop: int = None, step: int = None, return_field x.data[:, start:stop:step, :, :, :] = self.data[:, start:stop:step, :, :, :] else: x.data[start:stop:step, :, :, :] = self.data[start:stop:step, :, :, :] - return x else: if self.full_field and self.L5 is not None: - return self.data[:, :, start:stop:step, :, :, :] + x = self.data[:, :, start:stop:step, :, :, :] elif self.full_field or self.L5 is not None: - return self.data[:, start:stop:step, :, :, :] + x = self.data[:, start:stop:step, :, :, :] else: - return self.data[start:stop:step, :, :, :] + x = self.data[start:stop:step, :, :, :] + return x class FullField: