Skip to content

Commit

Permalink
added AdjacencyList.leaves #99
Browse files Browse the repository at this point in the history
  • Loading branch information
jacanchaplais committed Feb 22, 2023
1 parent 0d60ca4 commit 27ecdf9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions graphicle/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1852,6 +1852,16 @@ def _edge_relabel(self) -> base.IntVector:
_, inv = np.unique(self._data, return_inverse=True)
return inv.reshape(-1, 2)

@property
def leaves(self) -> MaskArray:
"""A mask to select the leaves of the DAG."""
sparse_copy = self._sparse.copy()
sparse_copy.data[...] = True
out_degree = sparse_copy.sum(axis=1)
zero_idxs = np.flatnonzero(out_degree == 0)
leaf_mask = np.in1d(sparse_copy.col, zero_idxs)
return MaskArray(leaf_mask)

@property
def data(self) -> base.VoidVector:
return self._data.view(self.dtype).reshape(-1)
Expand Down

0 comments on commit 27ecdf9

Please sign in to comment.