Skip to content

Commit

Permalink
Fix a bug in field.timeslice().
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltyChiang committed Dec 12, 2024
1 parent 79c0b74 commit f2c58c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pyquda_core/pyquda/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.9.11"
__version__ = "0.10.0"
22 changes: 8 additions & 14 deletions pyquda_core/pyquda/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit f2c58c5

Please sign in to comment.