Skip to content
Open
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
2 changes: 1 addition & 1 deletion nx_parallel/algorithms/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _compute_clustering_chunk(node_iter_chunk):
return clustering


@nxp._configure_if_nx_active()
@nxp._configure_if_nx_active(should_run=nxp.should_run_if_nodes_none)
def triangles(G, nodes=None, get_chunks="chunks"):
"""The nodes are chunked into `node_chunks` and for all `node_chunks`
the number of triangles that include a node as one vertex is computed
Expand Down
13 changes: 13 additions & 0 deletions nx_parallel/tests/test_should_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ def dummy_if_large(G):
assert dummy_if_large.should_run(largeG)


def test_should_run_if_nodes_none():
@nxp._configure_if_nx_active(should_run=nxp.should_run_if_nodes_none)
def dummy_nodes_none(G, nodes=None):
pass

G = nx.fast_gnp_random_graph(20, 0.6, seed=42)
assert (
dummy_nodes_none.should_run(G, nodes=[1, 3])
== "Parallel execution only supported when `nodes` is None"
)
assert dummy_nodes_none.should_run(G)


def test_should_run_if_sparse():
@nxp._configure_if_nx_active(should_run=nxp.should_run_if_sparse(threshold=0.4))
def dummy_if_sparse(G):
Expand Down
7 changes: 7 additions & 0 deletions nx_parallel/utils/should_run_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"default_should_run",
"should_skip_parallel",
"should_run_if_large",
"should_run_if_nodes_none",
"should_run_if_sparse",
]

Expand All @@ -30,6 +31,12 @@ def default_should_run(*_):
return True


def should_run_if_nodes_none(G, nodes=None, *_):
if nodes is None:
return True
return "Parallel execution only supported when `nodes` is None"


def should_run_if_sparse(threshold=0.3):
def wrapper(G, *_):
if hasattr(G, "graph_object"):
Expand Down
Loading