Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions nx_parallel/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
# Approximation
"approximate_all_pairs_node_connectivity",
# Connectivity
"connectivity.all_pairs_node_connectivity",
"all_pairs_node_connectivity",
]


Expand Down Expand Up @@ -69,9 +69,7 @@ def __str__(self):
def assign_algorithms(cls):
"""Class decorator to assign algorithms to the class attributes."""
for attr in ALGORITHMS:
# get the function name by parsing the module hierarchy
func_name = attr.rsplit(".", 1)[-1]
setattr(cls, func_name, attrgetter(attr)(algorithms))
setattr(cls, attr, attrgetter(attr)(algorithms))
return cls
Comment on lines 69 to 73

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference-- since this decorator is only used on BackendInterface, it might be easier for future code-readers-- if we simply move this logic into the class or immediately after its definition. Not a blocker!



Expand Down
27 changes: 2 additions & 25 deletions nx_parallel/tests/test_get_chunks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pytest

import nx_parallel as nxp
from nx_parallel.interface import ALGORITHMS


def get_functions_with_get_chunks(ignore_funcs=[], package_name="nx_parallel"):
Expand All @@ -30,31 +31,7 @@ def get_functions_with_get_chunks(ignore_funcs=[], package_name="nx_parallel"):


def test_get_functions_with_get_chunks():
# TODO: Instead of `expected` use ALGORTHMS from interface.py
# take care of functions like `connectivity.all_pairs_node_connectivity`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By "functions like connectivity.all_pairs_node_connectivity," I meant those with a name parameter defined in the _dispatchable decorator. For example, approximate_all_pairs_node_connectivity is not the actual name of the function in the networkx but in the name parameter of the decorator-- because the name all_pairs_node_connectivity is already used by connectivity.all_pairs_node_connectivity. The current logic-- splitting on . -- works with existing functions, but i'm not sure if there's a consistent rule for setting the name parameter in networkx. It may be worth updating the code if there is a rule or adding a comment to clarify this for future reference/maintenance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! That makes sense — I’ll close this and keep it in mind to revisit when needed :)

expected = {
"all_pairs_all_shortest_paths",
"all_pairs_bellman_ford_path",
"all_pairs_bellman_ford_path_length",
"all_pairs_dijkstra",
"all_pairs_dijkstra_path",
"all_pairs_dijkstra_path_length",
"all_pairs_node_connectivity",
"all_pairs_shortest_path",
"all_pairs_shortest_path_length",
"approximate_all_pairs_node_connectivity",
"betweenness_centrality",
"closeness_vitality",
"edge_betweenness_centrality",
"is_reachable",
"johnson",
"local_efficiency",
"node_redundancy",
"number_of_isolates",
"square_clustering",
"tournament_is_strongly_connected",
}
assert set(get_functions_with_get_chunks()) == expected
assert set(get_functions_with_get_chunks()) == set(ALGORITHMS)


ignore_funcs = [
Expand Down
Loading