Skip to content

Commit

Permalink
enh: more caching of event size and shape for HDF5 format
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Oct 24, 2023
1 parent dd922d9 commit fcbcd27
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
0.54.3
- enh: more caching of event size and shape for HDF5 format
- enh: faster computation of contour length for DCOR format
- fix: implement `__contains__` for DCOR logs and tables
- enh: use dcserv version 2 in DCOR format (fast S3 access)
Expand Down
14 changes: 10 additions & 4 deletions dclab/rtdc_dataset/fmt_hdf5/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def __iter__(self):

def __len__(self):
if self._length is None:
assert False
# computing the length of an H5Group is slow
self._length = len(self.h5group)
return self._length
Expand Down Expand Up @@ -207,6 +206,8 @@ def shape(self):
class H5TraceEvent:
def __init__(self, h5group):
self.h5group = h5group
self._num_traces = None
self._shape = None

def __getitem__(self, idx):
return self.h5group[idx]
Expand All @@ -215,7 +216,9 @@ def __contains__(self, item):
return item in self.h5group

def __len__(self):
return len(self.h5group)
if self._num_traces is None:
self._num_traces = len(self.h5group)
return self._num_traces

def __iter__(self):
for key in sorted(self.h5group.keys()):
Expand All @@ -226,5 +229,8 @@ def keys(self):

@property
def shape(self):
atrace = list(self.h5group.keys())[0]
return tuple([len(self.h5group)] + list(self.h5group[atrace].shape))
if self._shape is None:
atrace = list(self.h5group.keys())[0]
self._shape = tuple([len(self)] + list(self.h5group[atrace].shape))
return self._shape

0 comments on commit fcbcd27

Please sign in to comment.