MCPcopy Create free account
hub / github.com/alibaba/GraphScope / get_all_simple_paths

Function get_all_simple_paths

python/graphscope/nx/algorithms/builtin.py:867–888  ·  view source on GitHub ↗
(G, source, target_nodes, cutoff)

Source from the content-addressed store, hash-verified

865
866
867def get_all_simple_paths(G, source, target_nodes, cutoff):
868 @project_to_simple
869 def _all_simple_paths(G, source, target_nodes, cutoff):
870 targets_json = json.dumps(target_nodes)
871 return AppAssets(algo="all_simple_paths", context="tensor")(
872 G, source, targets_json, cutoff
873 )
874
875 if not isinstance(target_nodes, list):
876 target_nodes = [target_nodes]
877 if source not in G or len(target_nodes) != len(list(G.nbunch_iter(target_nodes))):
878 raise ValueError("nx.NodeNotFound")
879 if cutoff is None:
880 cutoff = len(G) - 1
881 if cutoff < 1 or source in target_nodes:
882 return []
883 ctx = _all_simple_paths(G, source, list(set(target_nodes)), cutoff)
884 paths = ctx.to_numpy("r", axis=0).tolist()
885 if len(paths) == 1:
886 if not isinstance(paths[0], list):
887 return []
888 return paths
889
890
891def all_simple_paths(G, source, target_nodes, cutoff=None):

Callers 2

all_simple_pathsFunction · 0.85
all_simple_edge_pathsFunction · 0.85

Calls 3

_all_simple_pathsFunction · 0.85
nbunch_iterMethod · 0.80
to_numpyMethod · 0.45

Tested by

no test coverage detected