Merge pull request #63 from s-kuberski/feature/irregularMC

Bugfix in _reduce_deltas. Results were correct, but performance was bad
This commit is contained in:
Fabian Joswig 2022-02-10 13:55:51 +00:00 committed by GitHub
commit dbcceeea3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View file

@ -1214,6 +1214,9 @@ def derived_observable(func, data, array_mode=False, **kwargs):
def _reduce_deltas(deltas, idx_old, idx_new):
"""Extract deltas defined on idx_old on all configs of idx_new.
Assumes, that idx_old and idx_new are correctly defined idl, i.e., they
are ordered in an ascending order.
Parameters
----------
deltas : list
@ -1233,8 +1236,6 @@ def _reduce_deltas(deltas, idx_old, idx_new):
ret = np.zeros(shape)
oldpos = 0
for i in range(shape):
if oldpos == idx_old[i]:
raise Exception('idx_old and idx_new do not match!')
pos = -1
for j in range(oldpos, len(idx_old)):
if idx_old[j] == idx_new[i]:
@ -1242,7 +1243,8 @@ def _reduce_deltas(deltas, idx_old, idx_new):
break
if pos < 0:
raise Exception('Error in _reduce_deltas: Config %d not in idx_old' % (idx_new[i]))
ret[i] = deltas[j]
ret[i] = deltas[pos]
oldpos = pos
return np.array(ret)