Skip to content

Commit d2d9d44

Browse files
committed
fix(edits/split): filter out inactive cross edges AT EACH LAYER
1 parent 3b314fd commit d2d9d44

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

pychunkedgraph/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.0.3"
1+
__version__ = "3.0.0"

pychunkedgraph/graph/chunkedgraph.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import time
44
import typing
55
import datetime
6+
from itertools import chain
7+
from functools import reduce
68

79
import numpy as np
810
from pychunkedgraph import __version__
@@ -667,8 +669,6 @@ def get_l2_agglomerations(
667669
Children of Level 2 Node IDs and edges.
668670
Edges are read from cloud storage.
669671
"""
670-
from itertools import chain
671-
from functools import reduce
672672
from .misc import get_agglomerations
673673

674674
chunk_ids = np.unique(self.get_chunk_ids_from_node_ids(level2_ids))
@@ -708,13 +708,9 @@ def get_l2_agglomerations(
708708
sv_parent_d.update(dict(zip(svs.tolist(), [l2id] * len(svs))))
709709

710710
if active:
711-
n1, n2 = all_chunk_edges.node_ids1, all_chunk_edges.node_ids2
712-
layers = self.get_cross_chunk_edges_layer(all_chunk_edges.get_pairs())
713-
max_layer = np.max(layers) + 1
714-
parents1 = self.get_roots(n1, stop_layer=max_layer, time_stamp=time_stamp)
715-
parents2 = self.get_roots(n2, stop_layer=max_layer, time_stamp=time_stamp)
716-
mask = parents1 == parents2
717-
all_chunk_edges = all_chunk_edges[mask]
711+
all_chunk_edges = edge_utils.filter_inactive_cross_edges(
712+
self, all_chunk_edges, time_stamp=time_stamp
713+
)
718714

719715
in_edges, out_edges, cross_edges = edge_utils.categorize_edges_v2(
720716
self.meta, all_chunk_edges, sv_parent_d

pychunkedgraph/graph/edges/utils.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from typing import Iterable
1010
from typing import Optional
1111
from collections import defaultdict
12+
from functools import reduce
1213

1314
import fastremap
1415
import numpy as np
@@ -46,7 +47,9 @@ def concatenate_chunk_edges(chunk_edge_dicts: Iterable) -> Dict:
4647
return edges_dict
4748

4849

49-
def concatenate_cross_edge_dicts(edges_ds: Iterable[Dict], unique: bool = False) -> Dict:
50+
def concatenate_cross_edge_dicts(
51+
edges_ds: Iterable[Dict], unique: bool = False
52+
) -> Dict:
5053
"""Combines cross chunk edge dicts of form {layer id : edge list}."""
5154
result_d = defaultdict(list)
5255
for edges_d in edges_ds:
@@ -182,3 +185,20 @@ def get_edges_status(cg, edges: Iterable, time_stamp: Optional[float] = None):
182185
active_status.extend(mask)
183186
active_status = np.array(active_status, dtype=bool)
184187
return existence_status, active_status
188+
189+
190+
def filter_inactive_cross_edges(
191+
cg, all_chunk_edges: Edges, time_stamp: Optional[float] = None
192+
):
193+
result = []
194+
layers = cg.get_cross_chunk_edges_layer(all_chunk_edges.get_pairs())
195+
for layer in np.unique(layers):
196+
layer_mask = layers == layer
197+
parent_layer = layer + 1
198+
layer_edges = all_chunk_edges[layer_mask]
199+
n1, n2 = layer_edges.node_ids1, layer_edges.node_ids2
200+
parents1 = cg.get_roots(n1, stop_layer=parent_layer, time_stamp=time_stamp)
201+
parents2 = cg.get_roots(n2, stop_layer=parent_layer, time_stamp=time_stamp)
202+
mask = parents1 == parents2
203+
result.append(layer_edges[mask])
204+
return reduce(lambda x, y: x + y, result, Edges([], []))

0 commit comments

Comments
 (0)