Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
akhileshh committed Nov 21, 2023
1 parent 7aec3a6 commit 92b9078
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions pychunkedgraph/graph/edits.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def __init__(
self._old_hierarchy_d = old_hierarchy_d
self._new_old_id_d = new_old_id_d
self._old_new_id_d = old_new_id_d
self._new_ids_d = defaultdict(list) # new IDs in each layer
self._new_ids_d = defaultdict(list)
self._operation_id = operation_id
self._time_stamp = time_stamp
self._last_successful_ts = parent_ts
Expand Down Expand Up @@ -572,7 +572,6 @@ def _update_cross_edge_cache(self, parent, children):
time_stamp=self._last_successful_ts,
)
edge_parents_d = dict(zip(edge_nodes, edge_parents))

new_cx_edges_d = {}
for layer in range(parent_layer, self.cg.meta.layer_count):
edges = cx_edges_d.get(layer, types.empty_2d)
Expand All @@ -583,37 +582,44 @@ def _update_cross_edge_cache(self, parent, children):
assert np.all(edges[:, 0] == parent)
self.cg.cache.cross_chunk_edges_cache[parent] = new_cx_edges_d

def _update_neighbor_parents(self, neighbor, ceil_layer, updated) -> list:
updated_parents = []
def _update_neighbor_parents(self, neighbor, ceil_layer: int, updated: set) -> list:
"""helper for `_update_skipped_neighbors`"""
parents = []
while True:
parent = self.cg.get_parent(neighbor, time_stamp=self._last_successful_ts)
parent_layer = self.cg.get_chunk_layer(parent)
if parent_layer >= ceil_layer or parent in updated:
break
children = self.cg.get_children(parent)
self._update_cross_edge_cache(parent, children)
updated_parents.append(parent)
parents.append(parent)
neighbor = parent
return updated_parents
return parents

def _update_skipped_neighbors(self, node, layer, parent_layer):
"""
Updates cross edges of neighbors of a skip connection node.
Neighbors of such nodes can have parents at contiguous layers.
This method updates cross edges of all such parents
from `layer` through `parent_layer`.
"""
updated_parents = set()
cx_edges_d = self.cg.cache.cross_chunk_edges_cache[node]
for l in range(layer, parent_layer + 1):
layer_edges = cx_edges_d.get(l, types.empty_2d)
for _layer in range(layer, parent_layer + 1):
layer_edges = cx_edges_d.get(_layer, types.empty_2d)
neighbors = layer_edges[:, 1]
for n in neighbors:
if n in self._new_old_id_d:
# ignore new ids
continue
res = self._update_neighbor_parents(n, parent_layer, updated_parents)
updated_parents.update(res)

updated_entries = []
for parent in updated_parents:
val_dict = {}
for layer, edges in self.cg.cache.cross_chunk_edges_cache[parent].items():
val_dict[attributes.Connectivity.CrossChunkEdge[layer]] = edges
for _layer, edges in self.cg.cache.cross_chunk_edges_cache[parent].items():
val_dict[attributes.Connectivity.CrossChunkEdge[_layer]] = edges
rkey = serialize_uint64(parent)
row = self.cg.client.mutate_row(rkey, val_dict, time_stamp=self._time_stamp)
updated_entries.append(row)
Expand Down

0 comments on commit 92b9078

Please sign in to comment.