make sure locating window is not out of bounds

This commit is contained in:
Jingang Liang 2020-09-01 15:55:56 +08:00
parent 361767ad2d
commit fe0221445e
2 changed files with 4 additions and 2 deletions

View file

@ -1143,7 +1143,8 @@ class WindowedMultipole(EqualityMixin):
# the 1-based vs. 0-based indexing. Similarly startw needs to be
# decreased by 1. endw does not need to be decreased because
# range(startw, endw) does not include endw.
i_window = int(np.floor((sqrtE - sqrt(self.E_min)) / self.spacing))
i_window = min(self.n_windows - 1,
int(np.floor((sqrtE - sqrt(self.E_min)) / self.spacing)))
startw = self.windows[i_window, 0] - 1
endw = self.windows[i_window, 1]

View file

@ -70,7 +70,8 @@ WindowedMultipole::evaluate(double E, double sqrtkT)
double invE = 1.0 / E;
// Locate window containing energy
int i_window = (sqrtE - std::sqrt(E_min_)) / spacing_;
int i_window = std::min(windows_.shape()[0] - 1,
(sqrtE - std::sqrt(E_min_)) / spacing_);
int startw = windows_(i_window, 0) - 1;
int endw = windows_(i_window, 1) - 1;