Skip to content

Commit

Permalink
fix: missing k handling in iterator_func
Browse files Browse the repository at this point in the history
  • Loading branch information
Derek Alexander authored and Derek Alexander committed Sep 27, 2024
1 parent 4761654 commit e02a009
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions nx_parallel/algorithms/centrality/betweenness.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,18 @@ def betweenness_centrality(
if hasattr(G, "graph_object"):
G = G.graph_object

if k is None:
nodes = G.nodes
else:
nodes = seed.sample(list(G.nodes), k)

def process_func(G, chunk, weight, endpoints):
return _betweenness_centrality_node_subset(
G, chunk, weight=weight, endpoints=endpoints
)

def iterator_func(G):
return G.nodes
if k is None:
return G.nodes
else:
return seed.sample(list(G.nodes), k)

results = nxp.utils.chunks.execute_parallel(
bt_cs = nxp.utils.chunks.execute_parallel(
G,
process_func=process_func,
iterator_func=iterator_func,
Expand All @@ -64,7 +62,7 @@ def iterator_func(G):

# Reducing partial solution
bt_c = {}
for bt in results:
for bt in bt_cs:
for n, value in bt.items():
bt_c[n] = bt_c.get(n, 0.0) + value

Expand Down Expand Up @@ -115,18 +113,16 @@ def edge_betweenness_centrality(
if hasattr(G, "graph_object"):
G = G.graph_object

if k is None:
nodes = G.nodes
else:
nodes = seed.sample(list(G.nodes), k)

def process_func(G, chunk, weight) -> dict:
def process_func(G, chunk, weight):
return _edge_betweenness_centrality_node_subset(G, chunk, weight=weight)

def iterator_func(G):
return nodes
if k is None:
return G.nodes
else:
return seed.sample(list(G.nodes), k)

results = nxp.utils.chunk.execute_parallel(
bt_cs = nxp.utils.chunk.execute_parallel(
G,
process_func=process_func,
iterator_func=iterator_func,
Expand All @@ -136,12 +132,12 @@ def iterator_func(G):

# Reducing partial solution
bt_c = {}
for partial_bt in results:
for partial_bt in bt_cs:
for edge, value in partial_bt.items():
bt_c[edge] = bt_c.get(edge, 0.0) + value

for node in G: # remove nodes to only return edges
bt_c.pop(node, None)
for n in G: # remove nodes to only return edges
del bt_c[n]

betweenness = _rescale_e(bt_c, len(G), normalized=normalized, k=k)

Expand Down

0 comments on commit e02a009

Please sign in to comment.