mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-03-15 23:00:25 +01:00
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:
commit
dbcceeea3a
2 changed files with 21 additions and 3 deletions
|
@ -1214,6 +1214,9 @@ def derived_observable(func, data, array_mode=False, **kwargs):
|
||||||
def _reduce_deltas(deltas, idx_old, idx_new):
|
def _reduce_deltas(deltas, idx_old, idx_new):
|
||||||
"""Extract deltas defined on idx_old on all configs of 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
|
Parameters
|
||||||
----------
|
----------
|
||||||
deltas : list
|
deltas : list
|
||||||
|
@ -1233,8 +1236,6 @@ def _reduce_deltas(deltas, idx_old, idx_new):
|
||||||
ret = np.zeros(shape)
|
ret = np.zeros(shape)
|
||||||
oldpos = 0
|
oldpos = 0
|
||||||
for i in range(shape):
|
for i in range(shape):
|
||||||
if oldpos == idx_old[i]:
|
|
||||||
raise Exception('idx_old and idx_new do not match!')
|
|
||||||
pos = -1
|
pos = -1
|
||||||
for j in range(oldpos, len(idx_old)):
|
for j in range(oldpos, len(idx_old)):
|
||||||
if idx_old[j] == idx_new[i]:
|
if idx_old[j] == idx_new[i]:
|
||||||
|
@ -1242,7 +1243,8 @@ def _reduce_deltas(deltas, idx_old, idx_new):
|
||||||
break
|
break
|
||||||
if pos < 0:
|
if pos < 0:
|
||||||
raise Exception('Error in _reduce_deltas: Config %d not in idx_old' % (idx_new[i]))
|
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)
|
return np.array(ret)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -675,3 +675,19 @@ def test_import_jackknife():
|
||||||
my_jacks = my_obs.export_jackknife()
|
my_jacks = my_obs.export_jackknife()
|
||||||
reconstructed_obs = pe.import_jackknife(my_jacks, 'test')
|
reconstructed_obs = pe.import_jackknife(my_jacks, 'test')
|
||||||
assert my_obs == reconstructed_obs
|
assert my_obs == reconstructed_obs
|
||||||
|
|
||||||
|
|
||||||
|
def test_reduce_deltas():
|
||||||
|
idx_old = range(1, 101)
|
||||||
|
deltas = [float(i) for i in idx_old]
|
||||||
|
idl = [
|
||||||
|
range(2, 26, 2),
|
||||||
|
range(1, 101),
|
||||||
|
np.arange(1, 101),
|
||||||
|
[1, 2, 3, 5, 6, 7, 9, 12],
|
||||||
|
[7],
|
||||||
|
]
|
||||||
|
for idx_new in idl:
|
||||||
|
new = pe.obs._reduce_deltas(deltas, idx_old, idx_new)
|
||||||
|
print(new)
|
||||||
|
assert(np.alltrue([float(i) for i in idx_new] == new))
|
||||||
|
|
Loading…
Add table
Reference in a new issue