From 3e06dc159cf0561b85ff22bfd5e76a7bf9e4a72b Mon Sep 17 00:00:00 2001 From: Ivan Carvalho Date: Sat, 27 May 2023 03:21:47 -0400 Subject: [PATCH 01/12] Try to shorten Bellman-Ford --- rustworkx/__init__.py | 63 ++++++------------------------------------- 1 file changed, 8 insertions(+), 55 deletions(-) diff --git a/rustworkx/__init__.py b/rustworkx/__init__.py index 40e3cd6c7..9e8d3f8c7 100644 --- a/rustworkx/__init__.py +++ b/rustworkx/__init__.py @@ -2301,36 +2301,8 @@ def bellman_ford_shortest_paths( raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@bellman_ford_shortest_paths.register(PyDiGraph) -def _digraph_bellman_ford_shortest_path( - graph, - source, - target=None, - weight_fn=None, - default_weight=1.0, - as_undirected=False, -): - return digraph_bellman_ford_shortest_paths( - graph, - source, - target=target, - weight_fn=weight_fn, - default_weight=default_weight, - as_undirected=as_undirected, - ) - - -@bellman_ford_shortest_paths.register(PyGraph) -def _graph_bellman_ford_shortest_path( - graph, source, target=None, weight_fn=None, default_weight=1.0 -): - return graph_bellman_ford_shortest_paths( - graph, - source, - target=target, - weight_fn=weight_fn, - default_weight=default_weight, - ) +bellman_ford_shortest_paths.register(PyDiGraph, digraph_bellman_ford_shortest_paths) +bellman_ford_shortest_paths.register(PyGraph, graph_bellman_ford_shortest_paths) @functools.singledispatch @@ -2360,14 +2332,8 @@ def bellman_ford_shortest_path_lengths(graph, node, edge_cost_fn, goal=None): raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@bellman_ford_shortest_path_lengths.register(PyDiGraph) -def _digraph_bellman_ford_shortest_path_lengths(graph, node, edge_cost_fn, goal=None): - return digraph_bellman_ford_shortest_path_lengths(graph, node, edge_cost_fn, goal=goal) - - -@bellman_ford_shortest_path_lengths.register(PyGraph) -def _graph_bellman_ford_shortest_path_lengths(graph, node, edge_cost_fn, goal=None): - return graph_bellman_ford_shortest_path_lengths(graph, node, edge_cost_fn, goal=goal) +bellman_ford_shortest_path_lengths.register(PyDiGraph, digraph_bellman_ford_shortest_path_lengths) +bellman_ford_shortest_path_lengths.register(PyGraph, graph_bellman_ford_shortest_path_lengths) @functools.singledispatch @@ -2406,14 +2372,8 @@ def all_pairs_bellman_ford_path_lengths(graph, edge_cost_fn): raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@all_pairs_bellman_ford_path_lengths.register(PyDiGraph) -def _digraph_all_pairs_bellman_ford_path_lengths(graph, edge_cost_fn): - return digraph_all_pairs_bellman_ford_path_lengths(graph, edge_cost_fn) - - -@all_pairs_bellman_ford_path_lengths.register(PyGraph) -def _graph_all_pairs_bellman_ford_path_lengths(graph, edge_cost_fn): - return graph_all_pairs_bellman_ford_path_lengths(graph, edge_cost_fn) +all_pairs_bellman_ford_path_lengths.register(PyDiGraph, digraph_all_pairs_bellman_ford_path_lengths) +all_pairs_bellman_ford_path_lengths.register(PyGraph, graph_all_pairs_bellman_ford_path_lengths) @functools.singledispatch @@ -2452,15 +2412,8 @@ def all_pairs_bellman_ford_shortest_paths(graph, edge_cost_fn): raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@all_pairs_bellman_ford_shortest_paths.register(PyDiGraph) -def _digraph_all_pairs_bellman_ford_shortest_path(graph, edge_cost_fn): - return digraph_all_pairs_bellman_ford_shortest_paths(graph, edge_cost_fn) - - -@all_pairs_bellman_ford_shortest_paths.register(PyGraph) -def _graph_all_pairs_bellman_ford_shortest_path(graph, edge_cost_fn): - return graph_all_pairs_bellman_ford_shortest_paths(graph, edge_cost_fn) - +all_pairs_bellman_ford_shortest_paths.register(PyDiGraph, digraph_all_pairs_bellman_ford_shortest_paths) +all_pairs_bellman_ford_shortest_paths.register(PyGraph, graph_all_pairs_bellman_ford_shortest_paths) @functools.singledispatch def node_link_json(graph, path=None, graph_attrs=None, node_attrs=None, edge_attrs=None): From 248023f0e8a38aac4191899c7aa25abe3ef7e5c5 Mon Sep 17 00:00:00 2001 From: Ivan Carvalho Date: Sat, 27 May 2023 03:30:24 -0400 Subject: [PATCH 02/12] More shortening --- rustworkx/__init__.py | 46 ++++++++----------------------------------- 1 file changed, 8 insertions(+), 38 deletions(-) diff --git a/rustworkx/__init__.py b/rustworkx/__init__.py index 9e8d3f8c7..32de7c98a 100644 --- a/rustworkx/__init__.py +++ b/rustworkx/__init__.py @@ -2107,15 +2107,8 @@ def tree_edge(self, edge): raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@bfs_search.register(PyDiGraph) -def _digraph_bfs_search(graph, source, visitor): - return digraph_bfs_search(graph, source, visitor) - - -@bfs_search.register(PyGraph) -def _graph_bfs_search(graph, source, visitor): - return graph_bfs_search(graph, source, visitor) - +bfs_search.register(PyDiGraph, digraph_bfs_search) +bfs_search.register(PyGraph, graph_bfs_search) @functools.singledispatch def dfs_search(graph, source, visitor): @@ -2187,15 +2180,8 @@ def tree_edge(self, edge): raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@dfs_search.register(PyDiGraph) -def _digraph_dfs_search(graph, source, visitor): - return digraph_dfs_search(graph, source, visitor) - - -@dfs_search.register(PyGraph) -def _graph_dfs_search(graph, source, visitor): - return graph_dfs_search(graph, source, visitor) - +dfs_search.register(PyDiGraph, digraph_dfs_search) +dfs_search.register(PyGraph, graph_dfs_search) @functools.singledispatch def dijkstra_search(graph, source, weight_fn, visitor): @@ -2254,14 +2240,8 @@ def dijkstra_search(graph, source, weight_fn, visitor): raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@dijkstra_search.register(PyDiGraph) -def _digraph_dijkstra_search(graph, source, weight_fn, visitor): - return digraph_dijkstra_search(graph, source, weight_fn, visitor) - - -@dijkstra_search.register(PyGraph) -def _graph_dijkstra_search(graph, source, weight_fn, visitor): - return graph_dijkstra_search(graph, source, weight_fn, visitor) +dijkstra_search.register(PyDiGraph, digraph_dijkstra_search) +dijkstra_search.register(PyGraph, graph_dijkstra_search) @functools.singledispatch @@ -2445,15 +2425,5 @@ def node_link_json(graph, path=None, graph_attrs=None, node_attrs=None, edge_att raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@node_link_json.register(PyDiGraph) -def _digraph_node_link_json(graph, path=None, graph_attrs=None, node_attrs=None, edge_attrs=None): - return digraph_node_link_json( - graph, path=path, graph_attrs=graph_attrs, node_attrs=node_attrs, edge_attrs=edge_attrs - ) - - -@node_link_json.register(PyGraph) -def _graph_node_link_json(graph, path=None, graph_attrs=None, node_attrs=None, edge_attrs=None): - return graph_node_link_json( - graph, path=path, graph_attrs=graph_attrs, node_attrs=node_attrs, edge_attrs=edge_attrs - ) +node_link_json.register(PyDiGraph, digraph_node_link_json) +node_link_json.register(PyGraph, graph_node_link_json) From 99770b50d1245110b7cbe78f21f3138279512034 Mon Sep 17 00:00:00 2001 From: Ivan Carvalho Date: Sat, 27 May 2023 03:40:11 -0400 Subject: [PATCH 03/12] Even more --- rustworkx/__init__.py | 151 ++++++------------------------------------ 1 file changed, 20 insertions(+), 131 deletions(-) diff --git a/rustworkx/__init__.py b/rustworkx/__init__.py index 32de7c98a..b1103e6a9 100644 --- a/rustworkx/__init__.py +++ b/rustworkx/__init__.py @@ -1646,14 +1646,8 @@ def closeness_centrality(graph, wf_improved=True): raise TypeError("Invalid input type %s for graph" % type(graph)) -@closeness_centrality.register(PyDiGraph) -def _digraph_closeness_centrality(graph, wf_improved=True): - return digraph_closeness_centrality(graph, wf_improved=wf_improved) - - -@closeness_centrality.register(PyGraph) -def _graph_closeness_centrality(graph, wf_improved=True): - return graph_closeness_centrality(graph, wf_improved=wf_improved) +closeness_centrality.register(PyDiGraph, digraph_closeness_centrality) +closeness_centrality.register(PyGraph, graph_closeness_centrality) @functools.singledispatch @@ -1700,22 +1694,8 @@ def edge_betweenness_centrality(graph, normalized=True, parallel_threshold=50): raise TypeError("Invalid input type %s for graph" % type(graph)) -@edge_betweenness_centrality.register(PyDiGraph) -def _digraph_edge_betweenness_centrality(graph, normalized=True, parallel_threshold=50): - return digraph_edge_betweenness_centrality( - graph, - normalized=normalized, - parallel_threshold=parallel_threshold, - ) - - -@edge_betweenness_centrality.register(PyGraph) -def _graph_edge_betweenness_centrality(graph, normalized=True, parallel_threshold=50): - return graph_edge_betweenness_centrality( - graph, - normalized=normalized, - parallel_threshold=parallel_threshold, - ) +edge_betweenness_centrality.register(PyDiGraph, digraph_edge_betweenness_centrality) +edge_betweenness_centrality.register(PyGraph, graph_edge_betweenness_centrality) @functools.singledispatch @@ -1758,22 +1738,8 @@ def eigenvector_centrality(graph, weight_fn=None, default_weight=1.0, max_iter=1 """ -@eigenvector_centrality.register(PyDiGraph) -def _digraph_eigenvector_centrality( - graph, weight_fn=None, default_weight=1.0, max_iter=100, tol=1e-6 -): - return digraph_eigenvector_centrality( - graph, weight_fn=weight_fn, default_weight=default_weight, max_iter=max_iter, tol=tol - ) - - -@eigenvector_centrality.register(PyGraph) -def _graph_eigenvector_centrality( - graph, weight_fn=None, default_weight=1.0, max_iter=100, tol=1e-6 -): - return graph_eigenvector_centrality( - graph, weight_fn=weight_fn, default_weight=default_weight, max_iter=max_iter, tol=tol - ) +eigenvector_centrality.register(PyDiGraph, digraph_eigenvector_centrality) +eigenvector_centrality.register(PyGraph, graph_eigenvector_centrality) @functools.singledispatch @@ -1834,50 +1800,8 @@ def vf2_mapping( raise TypeError("Invalid Input Type %s for graph" % type(first)) -@vf2_mapping.register(PyDiGraph) -def _digraph_vf2_mapping( - first, - second, - node_matcher=None, - edge_matcher=None, - id_order=True, - subgraph=False, - induced=True, - call_limit=None, -): - return digraph_vf2_mapping( - first, - second, - node_matcher=node_matcher, - edge_matcher=edge_matcher, - id_order=id_order, - subgraph=subgraph, - induced=induced, - call_limit=call_limit, - ) - - -@vf2_mapping.register(PyGraph) -def _graph_vf2_mapping( - first, - second, - node_matcher=None, - edge_matcher=None, - id_order=True, - subgraph=False, - induced=True, - call_limit=None, -): - return graph_vf2_mapping( - first, - second, - node_matcher=node_matcher, - edge_matcher=edge_matcher, - id_order=id_order, - subgraph=subgraph, - induced=induced, - call_limit=call_limit, - ) +vf2_mapping.register(PyDiGraph, digraph_vf2_mapping) +vf2_mapping.register(PyGraph, graph_vf2_mapping) @functools.singledispatch @@ -1921,24 +1845,8 @@ def union( raise TypeError("Invalid Input Type %s for graph" % type(first)) -@union.register(PyDiGraph) -def _digraph_union( - first, - second, - merge_nodes=False, - merge_edges=False, -): - return digraph_union(first, second, merge_nodes=merge_nodes, merge_edges=merge_edges) - - -@union.register(PyGraph) -def _graph_union( - first, - second, - merge_nodes=False, - merge_edges=False, -): - return graph_union(first, second, merge_nodes=merge_nodes, merge_edges=merge_edges) +union.register(PyDiGraph, digraph_union) +union.register(PyGraph, graph_union) @functools.singledispatch @@ -1971,20 +1879,8 @@ def tensor_product( raise TypeError("Invalid Input Type %s for graph" % type(first)) -@tensor_product.register(PyDiGraph) -def _digraph_tensor_product( - first, - second, -): - return digraph_tensor_product(first, second) - - -@tensor_product.register(PyGraph) -def _graph_tensor_product( - first, - second, -): - return graph_tensor_product(first, second) +tensor_product.register(PyDiGraph, digraph_tensor_product) +tensor_product.register(PyGraph, graph_tensor_product) @functools.singledispatch @@ -2017,20 +1913,8 @@ def cartesian_product( raise TypeError("Invalid Input Type %s for graph" % type(first)) -@cartesian_product.register(PyDiGraph) -def _digraph_cartesian_product( - first, - second, -): - return digraph_cartesian_product(first, second) - - -@cartesian_product.register(PyGraph) -def _graph_cartesian_product( - first, - second, -): - return graph_cartesian_product(first, second) +cartesian_product.register(PyDiGraph, digraph_cartesian_product) +cartesian_product.register(PyGraph, graph_cartesian_product) @functools.singledispatch @@ -2110,6 +1994,7 @@ def tree_edge(self, edge): bfs_search.register(PyDiGraph, digraph_bfs_search) bfs_search.register(PyGraph, graph_bfs_search) + @functools.singledispatch def dfs_search(graph, source, visitor): """Depth-first traversal of a directed/undirected graph. @@ -2183,6 +2068,7 @@ def tree_edge(self, edge): dfs_search.register(PyDiGraph, digraph_dfs_search) dfs_search.register(PyGraph, graph_dfs_search) + @functools.singledispatch def dijkstra_search(graph, source, weight_fn, visitor): """Dijkstra traversal of a graph. @@ -2392,9 +2278,12 @@ def all_pairs_bellman_ford_shortest_paths(graph, edge_cost_fn): raise TypeError("Invalid Input Type %s for graph" % type(graph)) -all_pairs_bellman_ford_shortest_paths.register(PyDiGraph, digraph_all_pairs_bellman_ford_shortest_paths) +all_pairs_bellman_ford_shortest_paths.register( + PyDiGraph, digraph_all_pairs_bellman_ford_shortest_paths +) all_pairs_bellman_ford_shortest_paths.register(PyGraph, graph_all_pairs_bellman_ford_shortest_paths) + @functools.singledispatch def node_link_json(graph, path=None, graph_attrs=None, node_attrs=None, edge_attrs=None): """Generate a JSON object representing a graph in a node-link format From 161e96954c752fdb34f1423afd0e3fc96e913d02 Mon Sep 17 00:00:00 2001 From: Ivan Carvalho Date: Sat, 27 May 2023 03:54:54 -0400 Subject: [PATCH 04/12] Almost done with shortening --- rustworkx/__init__.py | 182 +++++------------------------------------- 1 file changed, 22 insertions(+), 160 deletions(-) diff --git a/rustworkx/__init__.py b/rustworkx/__init__.py index b1103e6a9..eb6d23a27 100644 --- a/rustworkx/__init__.py +++ b/rustworkx/__init__.py @@ -221,23 +221,8 @@ def unweighted_average_shortest_path_length(graph, parallel_threshold=300, disco raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@unweighted_average_shortest_path_length.register(PyDiGraph) -def _digraph_unweighted_average_shortest_path_length( - graph, parallel_threshold=300, as_undirected=False, disconnected=False -): - return digraph_unweighted_average_shortest_path_length( - graph, - parallel_threshold=parallel_threshold, - as_undirected=as_undirected, - disconnected=disconnected, - ) - - -@unweighted_average_shortest_path_length.register(PyGraph) -def _graph_unweighted_shortest_path_length(graph, parallel_threshold=300, disconnected=False): - return graph_unweighted_average_shortest_path_length( - graph, parallel_threshold=parallel_threshold, disconnected=disconnected - ) +unweighted_average_shortest_path_length.register(PyDiGraph, digraph_unweighted_average_shortest_path_length) +unweighted_average_shortest_path_length.register(PyGraph, graph_unweighted_average_shortest_path_length) @functools.singledispatch @@ -276,24 +261,8 @@ def adjacency_matrix(graph, weight_fn=None, default_weight=1.0, null_value=0.0): raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@adjacency_matrix.register(PyDiGraph) -def _digraph_adjacency_matrix(graph, weight_fn=None, default_weight=1.0, null_value=0.0): - return digraph_adjacency_matrix( - graph, - weight_fn=weight_fn, - default_weight=default_weight, - null_value=null_value, - ) - - -@adjacency_matrix.register(PyGraph) -def _graph_adjacency_matrix(graph, weight_fn=None, default_weight=1.0, null_value=0.0): - return graph_adjacency_matrix( - graph, - weight_fn=weight_fn, - default_weight=default_weight, - null_value=null_value, - ) +adjacency_matrix.register(PyDiGraph, digraph_adjacency_matrix) +adjacency_matrix.register(PyGraph, graph_adjacency_matrix) @functools.singledispatch @@ -319,14 +288,8 @@ def all_simple_paths(graph, from_, to, min_depth=None, cutoff=None): raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@all_simple_paths.register(PyDiGraph) -def _digraph_all_simple_paths(graph, from_, to, min_depth=None, cutoff=None): - return digraph_all_simple_paths(graph, from_, to, min_depth=min_depth, cutoff=cutoff) - - -@all_simple_paths.register(PyGraph) -def _graph_all_simple_paths(graph, from_, to, min_depth=None, cutoff=None): - return graph_all_simple_paths(graph, from_, to, min_depth=min_depth, cutoff=cutoff) +all_simple_paths.register(PyDiGraph, digraph_all_simple_paths) +all_simple_paths.register(PyGraph, graph_all_simple_paths) @functools.singledispatch @@ -385,34 +348,8 @@ def floyd_warshall( raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@floyd_warshall.register(PyDiGraph) -def _digraph_floyd_warshall( - graph, - weight_fn=None, - default_weight=1.0, - parallel_threshold=300, -): - return digraph_floyd_warshall( - graph, - weight_fn=weight_fn, - default_weight=default_weight, - parallel_threshold=parallel_threshold, - ) - - -@floyd_warshall.register(PyGraph) -def _graph_floyd_warshall( - graph, - weight_fn=None, - default_weight=1.0, - parallel_threshold=300, -): - return graph_floyd_warshall( - graph, - weight_fn=weight_fn, - default_weight=default_weight, - parallel_threshold=parallel_threshold, - ) +floyd_warshall.register(PyDiGraph, digraph_floyd_warshall) +floyd_warshall.register(PyGraph, graph_floyd_warshall) @functools.singledispatch @@ -464,27 +401,8 @@ def floyd_warshall_numpy( raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@floyd_warshall_numpy.register(PyDiGraph) -def _digraph_floyd_warshall_numpy( - graph, weight_fn=None, default_weight=1.0, parallel_threshold=300 -): - return digraph_floyd_warshall_numpy( - graph, - weight_fn=weight_fn, - default_weight=default_weight, - parallel_threshold=parallel_threshold, - ) - - -@floyd_warshall_numpy.register(PyGraph) -def _graph_floyd_warshall_numpy(graph, weight_fn=None, default_weight=1.0, parallel_threshold=300): - return graph_floyd_warshall_numpy( - graph, - weight_fn=weight_fn, - default_weight=default_weight, - parallel_threshold=parallel_threshold, - ) - +floyd_warshall_numpy.register(PyDiGraph, digraph_floyd_warshall_numpy) +floyd_warshall_numpy.register(PyGraph, graph_floyd_warshall_numpy) @functools.singledispatch def astar_shortest_path(graph, node, goal_fn, edge_cost_fn, estimate_cost_fn): @@ -513,14 +431,8 @@ def astar_shortest_path(graph, node, goal_fn, edge_cost_fn, estimate_cost_fn): raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@astar_shortest_path.register(PyDiGraph) -def _digraph_astar_shortest_path(graph, node, goal_fn, edge_cost_fn, estimate_cost_fn): - return digraph_astar_shortest_path(graph, node, goal_fn, edge_cost_fn, estimate_cost_fn) - - -@astar_shortest_path.register(PyGraph) -def _graph_astar_shortest_path(graph, node, goal_fn, edge_cost_fn, estimate_cost_fn): - return graph_astar_shortest_path(graph, node, goal_fn, edge_cost_fn, estimate_cost_fn) +astar_shortest_path.register(PyDiGraph, digraph_astar_shortest_path) +astar_shortest_path.register(PyGraph, graph_astar_shortest_path) @functools.singledispatch @@ -557,34 +469,8 @@ def dijkstra_shortest_paths( raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@dijkstra_shortest_paths.register(PyDiGraph) -def _digraph_dijkstra_shortest_path( - graph, - source, - target=None, - weight_fn=None, - default_weight=1.0, - as_undirected=False, -): - return digraph_dijkstra_shortest_paths( - graph, - source, - target=target, - weight_fn=weight_fn, - default_weight=default_weight, - as_undirected=as_undirected, - ) - - -@dijkstra_shortest_paths.register(PyGraph) -def _graph_dijkstra_shortest_path(graph, source, target=None, weight_fn=None, default_weight=1.0): - return graph_dijkstra_shortest_paths( - graph, - source, - target=target, - weight_fn=weight_fn, - default_weight=default_weight, - ) +dijkstra_shortest_paths.register(PyDiGraph, digraph_dijkstra_shortest_paths) +dijkstra_shortest_paths.register(PyGraph, graph_dijkstra_shortest_paths) @functools.singledispatch @@ -620,14 +506,8 @@ def all_pairs_dijkstra_shortest_paths(graph, edge_cost_fn): raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@all_pairs_dijkstra_shortest_paths.register(PyDiGraph) -def _digraph_all_pairsdijkstra_shortest_path(graph, edge_cost_fn): - return digraph_all_pairs_dijkstra_shortest_paths(graph, edge_cost_fn) - - -@all_pairs_dijkstra_shortest_paths.register(PyGraph) -def _graph_all_pairs_dijkstra_shortest_path(graph, edge_cost_fn): - return graph_all_pairs_dijkstra_shortest_paths(graph, edge_cost_fn) +all_pairs_dijkstra_shortest_paths.register(PyDiGraph, digraph_all_pairs_dijkstra_shortest_paths) +all_pairs_dijkstra_shortest_paths.register(PyGraph, graph_all_pairs_dijkstra_shortest_paths) @functools.singledispatch @@ -655,14 +535,8 @@ def all_pairs_all_simple_paths(graph, min_depth=None, cutoff=None): raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@all_pairs_all_simple_paths.register(PyDiGraph) -def _digraph_all_pairs_all_simple_paths(graph, min_depth=None, cutoff=None): - return digraph_all_pairs_all_simple_paths(graph, min_depth=min_depth, cutoff=cutoff) - - -@all_pairs_all_simple_paths.register(PyGraph) -def _graph_all_pairs_all_simple_paths(graph, min_depth=None, cutoff=None): - return graph_all_pairs_all_simple_paths(graph, min_depth=min_depth, cutoff=cutoff) +all_pairs_all_simple_paths.register(PyDiGraph, digraph_all_pairs_all_simple_paths) +all_pairs_all_simple_paths.register(PyGraph, graph_all_pairs_all_simple_paths) @functools.singledispatch @@ -698,14 +572,8 @@ def all_pairs_dijkstra_path_lengths(graph, edge_cost_fn): raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@all_pairs_dijkstra_path_lengths.register(PyDiGraph) -def _digraph_all_pairs_dijkstra_path_lengths(graph, edge_cost_fn): - return digraph_all_pairs_dijkstra_path_lengths(graph, edge_cost_fn) - - -@all_pairs_dijkstra_path_lengths.register(PyGraph) -def _graph_all_pairs_dijkstra_path_lengths(graph, edge_cost_fn): - return graph_all_pairs_dijkstra_path_lengths(graph, edge_cost_fn) +all_pairs_dijkstra_path_lengths.register(PyDiGraph, digraph_all_pairs_dijkstra_path_lengths) +all_pairs_dijkstra_path_lengths.register(PyGraph, graph_all_pairs_dijkstra_path_lengths) @functools.singledispatch @@ -733,14 +601,8 @@ def dijkstra_shortest_path_lengths(graph, node, edge_cost_fn, goal=None): raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@dijkstra_shortest_path_lengths.register(PyDiGraph) -def _digraph_dijkstra_shortest_path_lengths(graph, node, edge_cost_fn, goal=None): - return digraph_dijkstra_shortest_path_lengths(graph, node, edge_cost_fn, goal=goal) - - -@dijkstra_shortest_path_lengths.register(PyGraph) -def _graph_dijkstra_shortest_path_lengths(graph, node, edge_cost_fn, goal=None): - return graph_dijkstra_shortest_path_lengths(graph, node, edge_cost_fn, goal=goal) +dijkstra_shortest_path_lengths.register(PyDiGraph, digraph_dijkstra_shortest_path_lengths) +dijkstra_shortest_path_lengths.register(PyGraph, graph_dijkstra_shortest_path_lengths) @functools.singledispatch From aeac267338ca2dad2c03fb7e03f0ef92ed7f43c9 Mon Sep 17 00:00:00 2001 From: Ivan Carvalho Date: Sat, 27 May 2023 04:01:47 -0400 Subject: [PATCH 05/12] Finish shortening --- rustworkx/__init__.py | 320 ++++++------------------------------------ 1 file changed, 41 insertions(+), 279 deletions(-) diff --git a/rustworkx/__init__.py b/rustworkx/__init__.py index eb6d23a27..06b812f35 100644 --- a/rustworkx/__init__.py +++ b/rustworkx/__init__.py @@ -162,18 +162,11 @@ def distance_matrix(graph, parallel_threshold=300, as_undirected=False, null_val raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@distance_matrix.register(PyDiGraph) -def _digraph_distance_matrix(graph, parallel_threshold=300, as_undirected=False, null_value=0.0): - return digraph_distance_matrix( - graph, - parallel_threshold=parallel_threshold, - as_undirected=as_undirected, - null_value=null_value, - ) +distance_matrix.register(PyDiGraph, digraph_distance_matrix) @distance_matrix.register(PyGraph) -def _graph_distance_matrix(graph, parallel_threshold=300, null_value=0.0): +def _(graph, parallel_threshold=300, null_value=0.0): return graph_distance_matrix( graph, parallel_threshold=parallel_threshold, null_value=null_value ) @@ -221,8 +214,12 @@ def unweighted_average_shortest_path_length(graph, parallel_threshold=300, disco raise TypeError("Invalid Input Type %s for graph" % type(graph)) -unweighted_average_shortest_path_length.register(PyDiGraph, digraph_unweighted_average_shortest_path_length) -unweighted_average_shortest_path_length.register(PyGraph, graph_unweighted_average_shortest_path_length) +unweighted_average_shortest_path_length.register( + PyDiGraph, digraph_unweighted_average_shortest_path_length +) +unweighted_average_shortest_path_length.register( + PyGraph, graph_unweighted_average_shortest_path_length +) @functools.singledispatch @@ -404,6 +401,7 @@ def floyd_warshall_numpy( floyd_warshall_numpy.register(PyDiGraph, digraph_floyd_warshall_numpy) floyd_warshall_numpy.register(PyGraph, graph_floyd_warshall_numpy) + @functools.singledispatch def astar_shortest_path(graph, node, goal_fn, edge_cost_fn, estimate_cost_fn): """Compute the A* shortest path for a graph @@ -630,14 +628,8 @@ def k_shortest_path_lengths(graph, start, k, edge_cost, goal=None): raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@k_shortest_path_lengths.register(PyDiGraph) -def _digraph_k_shortest_path_lengths(graph, start, k, edge_cost, goal=None): - return digraph_k_shortest_path_lengths(graph, start, k, edge_cost, goal=goal) - - -@k_shortest_path_lengths.register(PyGraph) -def _graph_k_shortest_path_lengths(graph, start, k, edge_cost, goal=None): - return graph_k_shortest_path_lengths(graph, start, k, edge_cost, goal=goal) +k_shortest_path_lengths.register(PyDiGraph, digraph_k_shortest_path_lengths) +k_shortest_path_lengths.register(PyGraph, graph_k_shortest_path_lengths) @functools.singledispatch @@ -684,14 +676,8 @@ def dfs_edges(graph, source=None): raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@dfs_edges.register(PyDiGraph) -def _digraph_dfs_edges(graph, source=None): - return digraph_dfs_edges(graph, source=source) - - -@dfs_edges.register(PyGraph) -def _graph_dfs_edges(graph, source=None): - return graph_dfs_edges(graph, source=source) +dfs_edges.register(PyDiGraph, digraph_dfs_edges) +dfs_edges.register(PyGraph, graph_dfs_edges) @functools.singledispatch @@ -750,28 +736,8 @@ def is_isomorphic( raise TypeError("Invalid Input Type %s for graph" % type(first)) -@is_isomorphic.register(PyDiGraph) -def _digraph_is_isomorphic( - first, - second, - node_matcher=None, - edge_matcher=None, - id_order=True, - call_limit=None, -): - return digraph_is_isomorphic(first, second, node_matcher, edge_matcher, id_order, call_limit) - - -@is_isomorphic.register(PyGraph) -def _graph_is_isomorphic( - first, - second, - node_matcher=None, - edge_matcher=None, - id_order=True, - call_limit=None, -): - return graph_is_isomorphic(first, second, node_matcher, edge_matcher, id_order, call_limit) +is_isomorphic.register(PyDiGraph, digraph_is_isomorphic) +is_isomorphic.register(PyGraph, graph_is_isomorphic) @functools.singledispatch @@ -813,14 +779,8 @@ def is_isomorphic_node_match(first, second, matcher, id_order=True): raise TypeError("Invalid Input Type %s for graph" % type(first)) -@is_isomorphic_node_match.register(PyDiGraph) -def _digraph_is_isomorphic_node_match(first, second, matcher, id_order=True): - return digraph_is_isomorphic(first, second, matcher, id_order=id_order) - - -@is_isomorphic_node_match.register(PyGraph) -def _graph_is_isomorphic_node_match(first, second, matcher, id_order=True): - return graph_is_isomorphic(first, second, matcher, id_order=id_order) +is_isomorphic_node_match.register(PyDiGraph, digraph_is_isomorphic) +is_isomorphic_node_match.register(PyGraph, graph_is_isomorphic) @functools.singledispatch @@ -880,34 +840,8 @@ def is_subgraph_isomorphic( raise TypeError("Invalid Input Type %s for graph" % type(first)) -@is_subgraph_isomorphic.register(PyDiGraph) -def _digraph_is_subgraph_isomorphic( - first, - second, - node_matcher=None, - edge_matcher=None, - id_order=False, - induced=True, - call_limit=None, -): - return digraph_is_subgraph_isomorphic( - first, second, node_matcher, edge_matcher, id_order, induced, call_limit - ) - - -@is_subgraph_isomorphic.register(PyGraph) -def _graph_is_subgraph_isomorphic( - first, - second, - node_matcher=None, - edge_matcher=None, - id_order=False, - induced=True, - call_limit=None, -): - return graph_is_subgraph_isomorphic( - first, second, node_matcher, edge_matcher, id_order, induced, call_limit - ) +is_subgraph_isomorphic.register(PyDiGraph, digraph_is_subgraph_isomorphic) +is_subgraph_isomorphic.register(PyGraph, graph_is_subgraph_isomorphic) @functools.singledispatch @@ -936,14 +870,8 @@ def transitivity(graph): raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@transitivity.register(PyDiGraph) -def _digraph_transitivity(graph): - return digraph_transitivity(graph) - - -@transitivity.register(PyGraph) -def _graph_transitivity(graph): - return graph_transitivity(graph) +transitivity.register(PyDiGraph, digraph_transitivity) +transitivity.register(PyGraph, graph_transitivity) @functools.singledispatch @@ -968,14 +896,8 @@ def core_number(graph): raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@core_number.register(PyDiGraph) -def _digraph_core_number(graph): - return digraph_core_number(graph) - - -@core_number.register(PyGraph) -def _graph_core_number(graph): - return graph_core_number(graph) +core_number.register(PyDiGraph, digraph_core_number) +core_number.register(PyGraph, graph_core_number) @functools.singledispatch @@ -995,14 +917,8 @@ def complement(graph): raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@complement.register(PyDiGraph) -def _digraph_complement(graph): - return digraph_complement(graph) - - -@complement.register(PyGraph) -def _graph_complement(graph): - return graph_complement(graph) +complement.register(PyDiGraph, digraph_complement) +complement.register(PyGraph, graph_complement) @functools.singledispatch @@ -1020,14 +936,8 @@ def random_layout(graph, center=None, seed=None): raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@random_layout.register(PyDiGraph) -def _digraph_random_layout(graph, center=None, seed=None): - return digraph_random_layout(graph, center=center, seed=seed) - - -@random_layout.register(PyGraph) -def _graph_random_layout(graph, center=None, seed=None): - return graph_random_layout(graph, center=center, seed=seed) +random_layout.register(PyDiGraph, digraph_random_layout) +random_layout.register(PyGraph, graph_random_layout) @functools.singledispatch @@ -1095,70 +1005,8 @@ def spring_layout( raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@spring_layout.register(PyDiGraph) -def _digraph_spring_layout( - graph, - pos=None, - fixed=None, - k=None, - repulsive_exponent=2, - adaptive_cooling=True, - num_iter=50, - tol=1e-6, - weight_fn=None, - default_weight=1, - scale=1, - center=None, - seed=None, -): - return digraph_spring_layout( - graph, - pos, - fixed, - k, - repulsive_exponent, - adaptive_cooling, - num_iter, - tol, - weight_fn, - default_weight, - scale, - center, - seed, - ) - - -@spring_layout.register(PyGraph) -def _graph_spring_layout( - graph, - pos=None, - fixed=None, - k=None, - repulsive_exponent=2, - adaptive_cooling=True, - num_iter=50, - tol=1e-6, - weight_fn=None, - default_weight=1, - scale=1, - center=None, - seed=None, -): - return graph_spring_layout( - graph, - pos, - fixed, - k, - repulsive_exponent, - adaptive_cooling, - num_iter, - tol, - weight_fn, - default_weight, - scale, - center, - seed, - ) +spring_layout.register(PyDiGraph, digraph_spring_layout) +spring_layout.register(PyGraph, graph_spring_layout) def networkx_converter(graph, keep_attributes: bool = False): @@ -1232,42 +1080,8 @@ def bipartite_layout( raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@bipartite_layout.register(PyDiGraph) -def _digraph_bipartite_layout( - graph, - first_nodes, - horizontal=False, - scale=1, - center=None, - aspect_ratio=4 / 3, -): - return digraph_bipartite_layout( - graph, - first_nodes, - horizontal=horizontal, - scale=scale, - center=center, - aspect_ratio=aspect_ratio, - ) - - -@bipartite_layout.register(PyGraph) -def _graph_bipartite_layout( - graph, - first_nodes, - horizontal=False, - scale=1, - center=None, - aspect_ratio=4 / 3, -): - return graph_bipartite_layout( - graph, - first_nodes, - horizontal=horizontal, - scale=scale, - center=center, - aspect_ratio=aspect_ratio, - ) +bipartite_layout.register(PyDiGraph, digraph_bipartite_layout) +bipartite_layout.register(PyGraph, graph_bipartite_layout) @functools.singledispatch @@ -1286,14 +1100,8 @@ def circular_layout(graph, scale=1, center=None): raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@circular_layout.register(PyDiGraph) -def _digraph_circular_layout(graph, scale=1, center=None): - return digraph_circular_layout(graph, scale=scale, center=center) - - -@circular_layout.register(PyGraph) -def _graph_circular_layout(graph, scale=1, center=None): - return graph_circular_layout(graph, scale=scale, center=center) +circular_layout.register(PyDiGraph, digraph_circular_layout) +circular_layout.register(PyGraph, graph_circular_layout) @functools.singledispatch @@ -1317,14 +1125,8 @@ def shell_layout(graph, nlist=None, rotate=None, scale=1, center=None): raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@shell_layout.register(PyDiGraph) -def _digraph_shell_layout(graph, nlist=None, rotate=None, scale=1, center=None): - return digraph_shell_layout(graph, nlist=nlist, rotate=rotate, scale=scale, center=center) - - -@shell_layout.register(PyGraph) -def _graph_shell_layout(graph, nlist=None, rotate=None, scale=1, center=None): - return graph_shell_layout(graph, nlist=nlist, rotate=rotate, scale=scale, center=center) +shell_layout.register(PyDiGraph, digraph_shell_layout) +shell_layout.register(PyGraph, graph_shell_layout) @functools.singledispatch @@ -1348,26 +1150,8 @@ def spiral_layout(graph, scale=1, center=None, resolution=0.35, equidistant=Fals raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@spiral_layout.register(PyDiGraph) -def _digraph_spiral_layout(graph, scale=1, center=None, resolution=0.35, equidistant=False): - return digraph_spiral_layout( - graph, - scale=scale, - center=center, - resolution=resolution, - equidistant=equidistant, - ) - - -@spiral_layout.register(PyGraph) -def _graph_spiral_layout(graph, scale=1, center=None, resolution=0.35, equidistant=False): - return graph_spiral_layout( - graph, - scale=scale, - center=center, - resolution=resolution, - equidistant=equidistant, - ) +spiral_layout.register(PyDiGraph, digraph_spiral_layout) +spiral_layout.register(PyGraph, graph_spiral_layout) @functools.singledispatch @@ -1385,14 +1169,8 @@ def num_shortest_paths_unweighted(graph, source): raise TypeError("Invalid input type %s for graph" % type(graph)) -@num_shortest_paths_unweighted.register(PyDiGraph) -def _digraph_num_shortest_paths_unweighted(graph, source): - return digraph_num_shortest_paths_unweighted(graph, source) - - -@num_shortest_paths_unweighted.register(PyGraph) -def _graph_num_shortest_paths_unweighted(graph, source): - return graph_num_shortest_paths_unweighted(graph, source) +num_shortest_paths_unweighted.register(PyDiGraph, digraph_num_shortest_paths_unweighted) +num_shortest_paths_unweighted.register(PyGraph, graph_num_shortest_paths_unweighted) @functools.singledispatch @@ -1442,24 +1220,8 @@ def betweenness_centrality(graph, normalized=True, endpoints=False, parallel_thr raise TypeError("Invalid input type %s for graph" % type(graph)) -@betweenness_centrality.register(PyDiGraph) -def _digraph_betweenness_centrality(graph, normalized=True, endpoints=False, parallel_threshold=50): - return digraph_betweenness_centrality( - graph, - normalized=normalized, - endpoints=endpoints, - parallel_threshold=parallel_threshold, - ) - - -@betweenness_centrality.register(PyGraph) -def _graph_betweenness_centrality(graph, normalized=True, endpoints=False, parallel_threshold=50): - return graph_betweenness_centrality( - graph, - normalized=normalized, - endpoints=endpoints, - parallel_threshold=parallel_threshold, - ) +betweenness_centrality.register(PyDiGraph, digraph_betweenness_centrality) +betweenness_centrality.register(PyGraph, graph_betweenness_centrality) @functools.singledispatch From 7bf5385d56aff1429caa9dd74cddacffc4bbfc59 Mon Sep 17 00:00:00 2001 From: Ivan Carvalho Date: Sat, 27 May 2023 04:35:11 -0400 Subject: [PATCH 06/12] Fix layout incorrect default arguments --- src/layout/mod.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 818103661..997c488ae 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -249,7 +249,9 @@ pub fn digraph_random_layout( /// :returns: The bipartite layout of the graph. /// :rtype: Pos2DMapping #[pyfunction] -#[pyo3(text_signature = "(graph, first_nodes, /, horitontal=False, scale=1, +#[pyo3( + signature=(graph, first_nodes, horizontal=false, scale=1.0, center=None, aspect_ratio=1.33333333333333), + text_signature = "(graph, first_nodes, /, horitontal=False, scale=1, center=None, aspect_ratio=1.33333333333333)")] pub fn graph_bipartite_layout( graph: &graph::PyGraph, @@ -285,7 +287,9 @@ pub fn graph_bipartite_layout( /// :returns: The bipartite layout of the graph. /// :rtype: Pos2DMapping #[pyfunction] -#[pyo3(text_signature = "(graph, first_nodes, /, horitontal=False, scale=1, +#[pyo3( + signature=(graph, first_nodes, horizontal=false, scale=1.0, center=None, aspect_ratio=1.33333333333333), + text_signature = "(graph, first_nodes, /, horitontal=False, scale=1, center=None, aspect_ratio=1.33333333333333)")] pub fn digraph_bipartite_layout( graph: &digraph::PyDiGraph, @@ -406,7 +410,9 @@ pub fn digraph_shell_layout( /// :returns: The spiral layout of the graph. /// :rtype: Pos2DMapping #[pyfunction] -#[pyo3(text_signature = "(graph, /, scale=1, center=None, resolution=0.35, +#[pyo3( + signature=(graph, scale=1.0, center=None, resolution=0.35, equidistant=false), + text_signature = "(graph, /, scale=1, center=None, resolution=0.35, equidistant=False)")] pub fn graph_spiral_layout( graph: &graph::PyGraph, @@ -432,7 +438,9 @@ pub fn graph_spiral_layout( /// :returns: The spiral layout of the graph. /// :rtype: Pos2DMapping #[pyfunction] -#[pyo3(text_signature = "(graph, /, scale=1, center=None, resolution=0.35, +#[pyo3( + signature=(graph, scale=1.0, center=None, resolution=0.35, equidistant=false), + text_signature = "(graph, /, scale=1, center=None, resolution=0.35, equidistant=False)")] pub fn digraph_spiral_layout( graph: &digraph::PyDiGraph, From 1415a3d788062a24e6c29fd316d95e4063bbfb60 Mon Sep 17 00:00:00 2001 From: Ivan Carvalho Date: Sat, 27 May 2023 13:26:40 -0400 Subject: [PATCH 07/12] Simplify distance_matrix --- rustworkx/__init__.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/rustworkx/__init__.py b/rustworkx/__init__.py index 06b812f35..079b43219 100644 --- a/rustworkx/__init__.py +++ b/rustworkx/__init__.py @@ -163,13 +163,7 @@ def distance_matrix(graph, parallel_threshold=300, as_undirected=False, null_val distance_matrix.register(PyDiGraph, digraph_distance_matrix) - - -@distance_matrix.register(PyGraph) -def _(graph, parallel_threshold=300, null_value=0.0): - return graph_distance_matrix( - graph, parallel_threshold=parallel_threshold, null_value=null_value - ) +distance_matrix.register(PyGraph, graph_distance_matrix) @functools.singledispatch From c943e950916dcfc1851f443ea602920b4a322f72 Mon Sep 17 00:00:00 2001 From: Ivan Carvalho Date: Sat, 27 May 2023 14:19:29 -0400 Subject: [PATCH 08/12] Minor detail about is_isomorphic_node_match --- rustworkx/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rustworkx/__init__.py b/rustworkx/__init__.py index 079b43219..cefd106cf 100644 --- a/rustworkx/__init__.py +++ b/rustworkx/__init__.py @@ -773,8 +773,8 @@ def is_isomorphic_node_match(first, second, matcher, id_order=True): raise TypeError("Invalid Input Type %s for graph" % type(first)) -is_isomorphic_node_match.register(PyDiGraph, digraph_is_isomorphic) -is_isomorphic_node_match.register(PyGraph, graph_is_isomorphic) +is_isomorphic_node_match.register(PyDiGraph, functools.partial(digraph_is_isomorphic, edge_matcher=None)) +is_isomorphic_node_match.register(PyGraph, functools.partial(graph_is_isomorphic, edge_matcher=None)) @functools.singledispatch From bf79b405e0342ecc6aafff3c6690077278c0e544 Mon Sep 17 00:00:00 2001 From: Ivan Carvalho Date: Sat, 27 May 2023 14:22:46 -0400 Subject: [PATCH 09/12] Black --- rustworkx/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rustworkx/__init__.py b/rustworkx/__init__.py index cefd106cf..4b8af2568 100644 --- a/rustworkx/__init__.py +++ b/rustworkx/__init__.py @@ -773,8 +773,12 @@ def is_isomorphic_node_match(first, second, matcher, id_order=True): raise TypeError("Invalid Input Type %s for graph" % type(first)) -is_isomorphic_node_match.register(PyDiGraph, functools.partial(digraph_is_isomorphic, edge_matcher=None)) -is_isomorphic_node_match.register(PyGraph, functools.partial(graph_is_isomorphic, edge_matcher=None)) +is_isomorphic_node_match.register( + PyDiGraph, functools.partial(digraph_is_isomorphic, edge_matcher=None) +) +is_isomorphic_node_match.register( + PyGraph, functools.partial(graph_is_isomorphic, edge_matcher=None) +) @functools.singledispatch From 5429f0a9c61c8fe38fc526e297ee9588c4fd77c8 Mon Sep 17 00:00:00 2001 From: Ivan Carvalho Date: Wed, 21 Jun 2023 11:10:03 -0400 Subject: [PATCH 10/12] Sync with main --- rustworkx/__init__.py | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/rustworkx/__init__.py b/rustworkx/__init__.py index 6a21d7ddc..56defb219 100644 --- a/rustworkx/__init__.py +++ b/rustworkx/__init__.py @@ -1410,34 +1410,8 @@ def katz_centrality( """ -@katz_centrality.register(PyDiGraph) -def _digraph_katz_centrality( - graph, alpha=0.1, beta=1.0, weight_fn=None, default_weight=1.0, max_iter=1000, tol=1e-6 -): - return digraph_katz_centrality( - graph, - alpha=alpha, - beta=beta, - weight_fn=weight_fn, - default_weight=default_weight, - max_iter=max_iter, - tol=tol, - ) - - -@katz_centrality.register(PyGraph) -def _graph_katz_centrality( - graph, alpha=0.1, beta=1.0, weight_fn=None, default_weight=1.0, max_iter=1000, tol=1e-6 -): - return graph_katz_centrality( - graph, - alpha=alpha, - beta=beta, - weight_fn=weight_fn, - default_weight=default_weight, - max_iter=max_iter, - tol=tol, - ) +eigenvector_centrality.register(PyDiGraph, digraph_katz_centrality) +eigenvector_centrality.register(PyGraph, graph_katz_centrality) @functools.singledispatch From 9a56d6d597a156aae4fdded5de0dee88b9907582 Mon Sep 17 00:00:00 2001 From: Ivan Carvalho Date: Wed, 21 Jun 2023 11:28:36 -0400 Subject: [PATCH 11/12] Minor fix --- rustworkx/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rustworkx/__init__.py b/rustworkx/__init__.py index 56defb219..d3f1ba537 100644 --- a/rustworkx/__init__.py +++ b/rustworkx/__init__.py @@ -1358,6 +1358,7 @@ def eigenvector_centrality(graph, weight_fn=None, default_weight=1.0, max_iter=1 centrality score for that node. :rtype: CentralityMapping """ + raise TypeError("Invalid input type %s for graph" % type(graph)) eigenvector_centrality.register(PyDiGraph, digraph_eigenvector_centrality) @@ -1408,10 +1409,11 @@ def katz_centrality( centrality score for that node. :rtype: CentralityMapping """ + raise TypeError("Invalid input type %s for graph" % type(graph)) -eigenvector_centrality.register(PyDiGraph, digraph_katz_centrality) -eigenvector_centrality.register(PyGraph, graph_katz_centrality) +katz_centrality.register(PyDiGraph, digraph_katz_centrality) +katz_centrality.register(PyGraph, graph_katz_centrality) @functools.singledispatch From 629d3450bdf5f02652205fd648acd1334fabbfcf Mon Sep 17 00:00:00 2001 From: Ivan Carvalho Date: Sun, 13 Aug 2023 13:20:16 -0400 Subject: [PATCH 12/12] Sync with new functions --- rustworkx/__init__.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/rustworkx/__init__.py b/rustworkx/__init__.py index 5e6f18c02..48f65fde0 100644 --- a/rustworkx/__init__.py +++ b/rustworkx/__init__.py @@ -488,14 +488,8 @@ def has_path( raise TypeError("Invalid Input Type %s for graph" % type(graph)) -@has_path.register(PyDiGraph) -def _digraph_has_path(graph, source, target, as_undirected=False): - return digraph_has_path(graph, source, target=target, as_undirected=as_undirected) - - -@has_path.register(PyGraph) -def _graph_has_path(graph, source, target): - return graph_has_path(graph, source, target=target) +has_path.register(PyDiGraph, digraph_has_path) +has_path.register(PyGraph, graph_has_path) @functools.singledispatch