Skip to content

Commit

Permalink
enh: got rid of for-loop in map_indices_parent2child (~100x speed-up)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Jan 3, 2024
1 parent a5a73a4 commit 3a4da89
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
0.56.4
- fix: integer overflow in downsample_grid
- enh: cythonize downsample_grid (~10x speed-up)
- enh: got rid of for-loop in map_indices_parent2child (~100x speed-up)
- ref: new submodule for hierarchy format
0.56.3
- fix: regression missing check for basin availability
Expand Down
27 changes: 10 additions & 17 deletions dclab/rtdc_dataset/fmt_hierarchy/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,36 +54,29 @@ def map_indices_child2root(child, child_indices):


def map_indices_parent2child(child, parent_indices):
"""Map parent RTDCBase event indices to RTDC_Hierarchy
"""Map parent RTDCBase event indices to RTDC_Hierarchy child
Parameters
----------
child: RTDC_Hierarchy
hierarchy child
parent_indices: 1d ndarray
hierarchy parent (`child.hparent`) indices to map
hierarchy parent (`child.hparent`) indices to map to child
Returns
-------
child_indices: 1d ndarray
child indices
equivalent of `parent_indices` in `child` dataset
"""
parent = child.hparent
# filters
# this boolean array defines `child` in the parent
pf = parent.filter.all
# indices in child
child_indices = []
count = 0
for ii in range(len(pf)):
if pf[ii]:
# only append indices if they exist in child
if ii in parent_indices:
# current child event count is the child index
child_indices.append(count)
# increment child event count
count += 1

return np.array(child_indices)
# all event indices in parent that define `child`
pf_loc = np.where(pf)[0]
# boolean array with size `len(child)` indicating where the
# `parent_indices` are set.
same = np.in1d(pf_loc, parent_indices)
return np.where(same)[0]


def map_indices_root2child(child, root_indices):
Expand Down

0 comments on commit 3a4da89

Please sign in to comment.