(G, source, target_nodes, cutoff)
| 865 | |
| 866 | |
| 867 | def 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 | |
| 891 | def all_simple_paths(G, source, target_nodes, cutoff=None): |
no test coverage detected