mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-15 03:53:41 +02:00
memory saving storage of irregular observables implemented
This commit is contained in:
parent
5077dfaad2
commit
e5c0e031db
1 changed files with 13 additions and 4 deletions
|
@ -78,7 +78,7 @@ class Obs:
|
||||||
if len(dc) == 1:
|
if len(dc) == 1:
|
||||||
self.idl[name] = range(idx[0], idx[-1] + dc[0], dc[0])
|
self.idl[name] = range(idx[0], idx[-1] + dc[0], dc[0])
|
||||||
else:
|
else:
|
||||||
self.idl[name] = list(idx)
|
self.idl[name] = np.array(idx, dtype=_type_chooser(len(idx)))
|
||||||
else:
|
else:
|
||||||
raise Exception('incompatible type for idl[%s].' % (name))
|
raise Exception('incompatible type for idl[%s].' % (name))
|
||||||
else:
|
else:
|
||||||
|
@ -822,9 +822,12 @@ def merge_idx(idl):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Use groupby to efficiently check whether all elements of idl are identical
|
# Use groupby to efficiently check whether all elements of idl are identical
|
||||||
g = groupby(idl)
|
try:
|
||||||
if next(g, True) and not next(g, False):
|
g = groupby(idl)
|
||||||
return idl[0]
|
if next(g, True) and not next(g, False):
|
||||||
|
return idl[0]
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
if np.all([type(idx) is range for idx in idl]):
|
if np.all([type(idx) is range for idx in idl]):
|
||||||
if len(set([idx[0] for idx in idl])) == 1:
|
if len(set([idx[0] for idx in idl])) == 1:
|
||||||
|
@ -1464,3 +1467,9 @@ def merge_obs(list_of_obs):
|
||||||
o.is_merged = np.any([oi.is_merged for oi in list_of_obs])
|
o.is_merged = np.any([oi.is_merged for oi in list_of_obs])
|
||||||
o.reweighted = np.max([oi.reweighted for oi in list_of_obs])
|
o.reweighted = np.max([oi.reweighted for oi in list_of_obs])
|
||||||
return o
|
return o
|
||||||
|
|
||||||
|
def _type_chooser(n):
|
||||||
|
for dtype in [np.uint8, np.uint16, np.uint32, np.uint64]:
|
||||||
|
if n <= dtype(-1):
|
||||||
|
return dtype
|
||||||
|
raise Exception('{} is really big!'.format(n))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue