From 244887861c8b6d74d65e5d4b5039e3fde8b7cb60 Mon Sep 17 00:00:00 2001 From: nahumsa Date: Thu, 10 Mar 2022 18:23:54 -0300 Subject: [PATCH 01/11] add difference and tests --- src/difference.rs | 110 +++++++++++++++++++++++++++++++ src/lib.rs | 4 ++ tests/digraph/test_difference.py | 57 ++++++++++++++++ tests/graph/test_difference.py | 57 ++++++++++++++++ 4 files changed, 228 insertions(+) create mode 100644 src/difference.rs create mode 100644 tests/digraph/test_difference.py create mode 100644 tests/graph/test_difference.py diff --git a/src/difference.rs b/src/difference.rs new file mode 100644 index 000000000..13623edcd --- /dev/null +++ b/src/difference.rs @@ -0,0 +1,110 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. + +use crate::{digraph, graph, StablePyGraph}; + +use hashbrown::HashSet; + +use petgraph::visit::{EdgeRef, IntoEdgeReferences}; +use petgraph::{algo, EdgeType}; + +use pyo3::exceptions::PyIndexError; +use pyo3::prelude::*; +use pyo3::Python; + +fn difference( + py: Python, + first: &StablePyGraph, + second: &StablePyGraph, +) -> PyResult> { + let indexes_first = first.node_indices().collect::>(); + let indexes_second = second.node_indices().collect::>(); + + if indexes_first != indexes_second { + return Err(PyIndexError::new_err( + "Node sets of the graphs should be equal", + )); + } + + let mut final_graph = StablePyGraph::::with_capacity( + first.node_count(), + first.edge_count() - second.edge_count(), + ); + + for node in first.node_indices() { + let weight = &first[node]; + final_graph.add_node(weight.clone_ref(py)); + } + + for e in first.edge_references() { + let has_edge = second.find_edge(e.source(), e.target()); + + match has_edge { + Some(_x) => continue, + None => final_graph.add_edge(e.source(), e.target(), e.weight().clone_ref(py)), + }; + } + + Ok(final_graph) +} + +/// Return a new PyGraph that is the difference from two input +/// PyGraph objects +/// +/// :param PyGraph first: The first undirected graph object +/// :param PyGraph second: The second undirected graph object +/// +/// :returns: A new PyGraph object that is the difference of ``first`` +/// and ``second``. It's worth noting the weight/data payload objects are +/// passed by reference from ``first`` graph to this new object. +/// +/// :rtype: :class:`~retworkx.PyGraph` +#[pyfunction()] +#[pyo3(text_signature = "(first, second, /)")] +fn graph_difference(py: Python, first: &graph::PyGraph, second: &graph::PyGraph) -> PyResult { + let out_graph = difference(py, &first.graph, &second.graph)?; + + Ok(graph::PyGraph { + graph: out_graph, + multigraph: true, + node_removed: false, + }) +} + +/// Return a new PyDiGraph that is the difference from two input +/// PyGraph objects +/// +/// :param PyGraph first: The first undirected graph object +/// :param PyGraph second: The second undirected graph object +/// +/// :returns: A new PyDiGraph object that is the difference of ``first`` +/// and ``second``. It's worth noting the weight/data payload objects are +/// passed by reference from ``first`` graph to this new object. +/// +/// :rtype: :class:`~retworkx.PyDiGraph` +#[pyfunction()] +#[pyo3(text_signature = "(first, second, /)")] +fn digraph_difference( + py: Python, + first: &digraph::PyDiGraph, + second: &digraph::PyDiGraph, +) -> PyResult { + let out_graph = difference(py, &first.graph, &second.graph)?; + + Ok(digraph::PyDiGraph { + graph: out_graph, + cycle_state: algo::DfsSpace::default(), + check_cycle: false, + node_removed: false, + multigraph: true, + }) +} diff --git a/src/lib.rs b/src/lib.rs index 20cebd077..589ff8dad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,7 @@ mod centrality; mod coloring; mod connectivity; mod dag_algo; +mod difference; mod digraph; mod dot_utils; mod generators; @@ -38,6 +39,7 @@ use centrality::*; use coloring::*; use connectivity::*; use dag_algo::*; +use difference::*; use isomorphism::*; use layout::*; use matching::*; @@ -325,6 +327,8 @@ fn retworkx(py: Python<'_>, m: &PyModule) -> PyResult<()> { m.add_wrapped(wrap_pyfunction!(graph_union))?; m.add_wrapped(wrap_pyfunction!(digraph_cartesian_product))?; m.add_wrapped(wrap_pyfunction!(graph_cartesian_product))?; + m.add_wrapped(wrap_pyfunction!(digraph_difference))?; + m.add_wrapped(wrap_pyfunction!(graph_difference))?; m.add_wrapped(wrap_pyfunction!(topological_sort))?; m.add_wrapped(wrap_pyfunction!(descendants))?; m.add_wrapped(wrap_pyfunction!(ancestors))?; diff --git a/tests/digraph/test_difference.py b/tests/digraph/test_difference.py new file mode 100644 index 000000000..04ef8ff7c --- /dev/null +++ b/tests/digraph/test_difference.py @@ -0,0 +1,57 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import unittest +import retworkx + + +class TestDifference(unittest.TestCase): + def test_null_difference_null(self): + graph_1 = retworkx.PyDiGraph() + graph_2 = retworkx.PyDiGraph() + + graph_difference = retworkx.digraph_difference(graph_1, graph_2) + + self.assertEqual(graph_difference.num_nodes(), 0) + self.assertEqual(graph_difference.num_edges(), 0) + + def test_difference_non_matching(self): + graph_1 = retworkx.generators.directed_path_graph(2) + graph_2 = retworkx.generators.directed_path_graph(3) + + with self.assertRaises(IndexError): + _ = retworkx.digraph_difference(graph_1, graph_2) + + def test_difference_weights_edges(self): + graph_1 = retworkx.PyDiGraph() + graph_1.add_nodes_from(["a_1", "a_2", "a_3", "a_4"]) + graph_1.extend_from_weighted_edge_list([(0, 1, "e_1"), + (1, 2, "e_2"), + (2, 3, "e_3"), + (3, 0, "e_4"), + (0, 2, "e_5"), + (1, 3, "e_6"), + ]) + graph_2 = retworkx.PyDiGraph() + graph_2.add_nodes_from(["a_1", "a_2", "a_3", "a_4"]) + graph_2.extend_from_weighted_edge_list([(0, 1, "e_1"), + (1, 2, "e_2"), + (2, 3, "e_3"), + (3, 0, "e_4"), + ]) + + graph_difference = retworkx.digraph_difference(graph_1, graph_2) + + expected_edges = [(0, 2, 'e_5'), (1, 3, 'e_6')] + self.assertEqual(graph_difference.num_nodes(), 4) + self.assertEqual(graph_difference.num_edges(), 2) + self.assertEqual(graph_difference.weighted_edge_list(), expected_edges) \ No newline at end of file diff --git a/tests/graph/test_difference.py b/tests/graph/test_difference.py new file mode 100644 index 000000000..f6bbdbe4c --- /dev/null +++ b/tests/graph/test_difference.py @@ -0,0 +1,57 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import unittest +import retworkx + + +class TestDifference(unittest.TestCase): + def test_null_difference_null(self): + graph_1 = retworkx.PyGraph() + graph_2 = retworkx.PyGraph() + + graph_difference = retworkx.graph_difference(graph_1, graph_2) + + self.assertEqual(graph_difference.num_nodes(), 0) + self.assertEqual(graph_difference.num_edges(), 0) + + def test_difference_non_matching(self): + graph_1 = retworkx.generators.path_graph(2) + graph_2 = retworkx.generators.path_graph(3) + + with self.assertRaises(IndexError): + _ = retworkx.graph_difference(graph_1, graph_2) + + def test_difference_weights(self): + graph_1 = retworkx.PyGraph() + graph_1.add_nodes_from(["a_1", "a_2", "a_3", "a_4"]) + graph_1.extend_from_weighted_edge_list([(0, 1, "e_1"), + (1, 2, "e_2"), + (2, 3, "e_3"), + (3, 0, "e_4"), + (0, 2, "e_5"), + (1, 3, "e_6"), + ]) + graph_2 = retworkx.PyGraph() + graph_2.add_nodes_from(["a_1", "a_2", "a_3", "a_4"]) + graph_2.extend_from_weighted_edge_list([(0, 1, "e_1"), + (1, 2, "e_2"), + (2, 3, "e_3"), + (3, 0, "e_4"), + ]) + + graph_difference = retworkx.graph_difference(graph_1, graph_2) + + expected_edges = [(0, 2, 'e_5'), (1, 3, 'e_6')] + self.assertEqual(graph_difference.num_nodes(), 4) + self.assertEqual(graph_difference.num_edges(), 2) + self.assertEqual(graph_difference.weighted_edge_list(), expected_edges) \ No newline at end of file From 85d4b2968c04b73e960df49fd9fa5e39b36e5fc8 Mon Sep 17 00:00:00 2001 From: nahumsa Date: Thu, 10 Mar 2022 18:24:07 -0300 Subject: [PATCH 02/11] add docs reference --- docs/source/api.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/source/api.rst b/docs/source/api.rst index d35ef4510..a7138c4b4 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -279,6 +279,7 @@ the functions from the explicitly typed based on the data type. retworkx.digraph_core_number retworkx.digraph_complement retworkx.digraph_union + retworkx.digraph_difference retworkx.digraph_tensor_product retworkx.digraph_cartesian_product retworkx.digraph_random_layout @@ -326,6 +327,7 @@ typed API based on the data type. retworkx.graph_core_number retworkx.graph_complement retworkx.graph_union + retworkx.graph_difference retworkx.graph_tensor_product retworkx.graph_cartesian_product retworkx.graph_random_layout From 1e2853e3787a9de0fa2e8dbff7f66fe68e4a0d91 Mon Sep 17 00:00:00 2001 From: nahumsa Date: Thu, 10 Mar 2022 18:24:14 -0300 Subject: [PATCH 03/11] add release notes --- ...add-graph-difference-9916bf3d612f0b1a.yaml | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 releasenotes/notes/add-graph-difference-9916bf3d612f0b1a.yaml diff --git a/releasenotes/notes/add-graph-difference-9916bf3d612f0b1a.yaml b/releasenotes/notes/add-graph-difference-9916bf3d612f0b1a.yaml new file mode 100644 index 000000000..7cadbf932 --- /dev/null +++ b/releasenotes/notes/add-graph-difference-9916bf3d612f0b1a.yaml @@ -0,0 +1,31 @@ +--- +features: + - | + Add two new functions which calculates the difference of two graphs :func:`~retworkx.graph_difference` + for undirected graphs and :func:`~retworkx.digraph_difference` for directed graphs. For example: + + .. jupyter-execute:: + + import retworkx + from retworkx.visualization import mpl_draw + + graph_1 = retworkx.PyGraph() + graph_1.add_nodes_from(["a_1", "a_2", "a_3", "a_4"]) + graph_1.extend_from_weighted_edge_list([(0, 1, "e_1"), + (1, 2, "e_2"), + (2, 3, "e_3"), + (3, 0, "e_4"), + (0, 2, "e_5"), + (1, 3, "e_6"), + ]) + graph_2 = retworkx.PyGraph() + graph_2.add_nodes_from(["a_1", "a_2", "a_3", "a_4"]) + graph_2.extend_from_weighted_edge_list([(0, 1, "e_1"), + (1, 2, "e_2"), + (2, 3, "e_3"), + (3, 0, "e_4"), + ]) + + graph_difference = retworkx.graph_difference(graph_1, graph_2) + + mpl_draw(graph_difference) \ No newline at end of file From 15f9dc5978e1abd8dd1619ca5880a935eea2f515 Mon Sep 17 00:00:00 2001 From: nahumsa Date: Thu, 10 Mar 2022 18:28:19 -0300 Subject: [PATCH 04/11] add difference on __init__.py --- retworkx/__init__.py | 35 +++++++++++++++++++++++++++++++++++ src/difference.rs | 6 +++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/retworkx/__init__.py b/retworkx/__init__.py index 460111643..5ce04f640 100644 --- a/retworkx/__init__.py +++ b/retworkx/__init__.py @@ -1814,6 +1814,41 @@ def _graph_cartesian_product( return graph_cartesian_product(first, second) +@functools.singledispatch +def difference( + first, + second, +): + """Return a new PyGraph that is the difference from two input + graph objects + + :param first: The first graph object + :param second: The second graph object + + :returns: A new graph object that is the difference of ``second`` and + ``first``. It's worth noting the weight/data payload objects are + passed by reference from ``first`` to this new object. + + :rtype: :class:`~retworkx.PyGraph` or :class:`~retworkx.PyDiGraph` + """ + raise TypeError("Invalid Input Type %s for graph" % type(first)) + + +@difference.register(PyDiGraph) +def _digraph_difference( + first, + second, +): + return digraph_difference(first, second) + + +@difference.register(PyGraph) +def _graph_difference( + first, + second, +): + return graph_difference(first, second) + @functools.singledispatch def bfs_search(graph, source, visitor): """Breadth-first traversal of a directed/undirected graph. diff --git a/src/difference.rs b/src/difference.rs index 13623edcd..907924cd7 100644 --- a/src/difference.rs +++ b/src/difference.rs @@ -70,7 +70,11 @@ fn difference( /// :rtype: :class:`~retworkx.PyGraph` #[pyfunction()] #[pyo3(text_signature = "(first, second, /)")] -fn graph_difference(py: Python, first: &graph::PyGraph, second: &graph::PyGraph) -> PyResult { +fn graph_difference( + py: Python, + first: &graph::PyGraph, + second: &graph::PyGraph, +) -> PyResult { let out_graph = difference(py, &first.graph, &second.graph)?; Ok(graph::PyGraph { From d83b7db187e7d6a8bf80c715df991a875ecfb36e Mon Sep 17 00:00:00 2001 From: nahumsa Date: Thu, 10 Mar 2022 19:02:58 -0300 Subject: [PATCH 05/11] lint --- retworkx/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/retworkx/__init__.py b/retworkx/__init__.py index 5ce04f640..7907ff3e5 100644 --- a/retworkx/__init__.py +++ b/retworkx/__init__.py @@ -1849,6 +1849,7 @@ def _graph_difference( ): return graph_difference(first, second) + @functools.singledispatch def bfs_search(graph, source, visitor): """Breadth-first traversal of a directed/undirected graph. From 37b140d0e50c664e16f11124e709896483e6fbfe Mon Sep 17 00:00:00 2001 From: nahumsa Date: Thu, 10 Mar 2022 19:03:03 -0300 Subject: [PATCH 06/11] lint --- tests/digraph/test_difference.py | 40 ++++++++++++++++++-------------- tests/graph/test_difference.py | 40 ++++++++++++++++++-------------- 2 files changed, 46 insertions(+), 34 deletions(-) diff --git a/tests/digraph/test_difference.py b/tests/digraph/test_difference.py index 04ef8ff7c..935c29dde 100644 --- a/tests/digraph/test_difference.py +++ b/tests/digraph/test_difference.py @@ -20,38 +20,44 @@ def test_null_difference_null(self): graph_2 = retworkx.PyDiGraph() graph_difference = retworkx.digraph_difference(graph_1, graph_2) - + self.assertEqual(graph_difference.num_nodes(), 0) self.assertEqual(graph_difference.num_edges(), 0) def test_difference_non_matching(self): graph_1 = retworkx.generators.directed_path_graph(2) graph_2 = retworkx.generators.directed_path_graph(3) - + with self.assertRaises(IndexError): _ = retworkx.digraph_difference(graph_1, graph_2) def test_difference_weights_edges(self): graph_1 = retworkx.PyDiGraph() graph_1.add_nodes_from(["a_1", "a_2", "a_3", "a_4"]) - graph_1.extend_from_weighted_edge_list([(0, 1, "e_1"), - (1, 2, "e_2"), - (2, 3, "e_3"), - (3, 0, "e_4"), - (0, 2, "e_5"), - (1, 3, "e_6"), - ]) + graph_1.extend_from_weighted_edge_list( + [ + (0, 1, "e_1"), + (1, 2, "e_2"), + (2, 3, "e_3"), + (3, 0, "e_4"), + (0, 2, "e_5"), + (1, 3, "e_6"), + ] + ) graph_2 = retworkx.PyDiGraph() graph_2.add_nodes_from(["a_1", "a_2", "a_3", "a_4"]) - graph_2.extend_from_weighted_edge_list([(0, 1, "e_1"), - (1, 2, "e_2"), - (2, 3, "e_3"), - (3, 0, "e_4"), - ]) - + graph_2.extend_from_weighted_edge_list( + [ + (0, 1, "e_1"), + (1, 2, "e_2"), + (2, 3, "e_3"), + (3, 0, "e_4"), + ] + ) + graph_difference = retworkx.digraph_difference(graph_1, graph_2) - expected_edges = [(0, 2, 'e_5'), (1, 3, 'e_6')] + expected_edges = [(0, 2, "e_5"), (1, 3, "e_6")] self.assertEqual(graph_difference.num_nodes(), 4) self.assertEqual(graph_difference.num_edges(), 2) - self.assertEqual(graph_difference.weighted_edge_list(), expected_edges) \ No newline at end of file + self.assertEqual(graph_difference.weighted_edge_list(), expected_edges) diff --git a/tests/graph/test_difference.py b/tests/graph/test_difference.py index f6bbdbe4c..88c30be93 100644 --- a/tests/graph/test_difference.py +++ b/tests/graph/test_difference.py @@ -20,38 +20,44 @@ def test_null_difference_null(self): graph_2 = retworkx.PyGraph() graph_difference = retworkx.graph_difference(graph_1, graph_2) - + self.assertEqual(graph_difference.num_nodes(), 0) self.assertEqual(graph_difference.num_edges(), 0) def test_difference_non_matching(self): graph_1 = retworkx.generators.path_graph(2) graph_2 = retworkx.generators.path_graph(3) - + with self.assertRaises(IndexError): _ = retworkx.graph_difference(graph_1, graph_2) def test_difference_weights(self): graph_1 = retworkx.PyGraph() graph_1.add_nodes_from(["a_1", "a_2", "a_3", "a_4"]) - graph_1.extend_from_weighted_edge_list([(0, 1, "e_1"), - (1, 2, "e_2"), - (2, 3, "e_3"), - (3, 0, "e_4"), - (0, 2, "e_5"), - (1, 3, "e_6"), - ]) + graph_1.extend_from_weighted_edge_list( + [ + (0, 1, "e_1"), + (1, 2, "e_2"), + (2, 3, "e_3"), + (3, 0, "e_4"), + (0, 2, "e_5"), + (1, 3, "e_6"), + ] + ) graph_2 = retworkx.PyGraph() graph_2.add_nodes_from(["a_1", "a_2", "a_3", "a_4"]) - graph_2.extend_from_weighted_edge_list([(0, 1, "e_1"), - (1, 2, "e_2"), - (2, 3, "e_3"), - (3, 0, "e_4"), - ]) - + graph_2.extend_from_weighted_edge_list( + [ + (0, 1, "e_1"), + (1, 2, "e_2"), + (2, 3, "e_3"), + (3, 0, "e_4"), + ] + ) + graph_difference = retworkx.graph_difference(graph_1, graph_2) - expected_edges = [(0, 2, 'e_5'), (1, 3, 'e_6')] + expected_edges = [(0, 2, "e_5"), (1, 3, "e_6")] self.assertEqual(graph_difference.num_nodes(), 4) self.assertEqual(graph_difference.num_edges(), 2) - self.assertEqual(graph_difference.weighted_edge_list(), expected_edges) \ No newline at end of file + self.assertEqual(graph_difference.weighted_edge_list(), expected_edges) From 3ec589222ab1ef366307fa49efa107ea220a2007 Mon Sep 17 00:00:00 2001 From: nahumsa Date: Wed, 6 Apr 2022 15:48:58 -0300 Subject: [PATCH 07/11] add pub for differences --- src/difference.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/difference.rs b/src/difference.rs index 907924cd7..1d1076fa6 100644 --- a/src/difference.rs +++ b/src/difference.rs @@ -70,7 +70,7 @@ fn difference( /// :rtype: :class:`~retworkx.PyGraph` #[pyfunction()] #[pyo3(text_signature = "(first, second, /)")] -fn graph_difference( +pub fn graph_difference( py: Python, first: &graph::PyGraph, second: &graph::PyGraph, @@ -97,7 +97,7 @@ fn graph_difference( /// :rtype: :class:`~retworkx.PyDiGraph` #[pyfunction()] #[pyo3(text_signature = "(first, second, /)")] -fn digraph_difference( +pub fn digraph_difference( py: Python, first: &digraph::PyDiGraph, second: &digraph::PyDiGraph, From e582eb3a39ece860275a1cca75724666a6ed9b6d Mon Sep 17 00:00:00 2001 From: Ivan Carvalho Date: Mon, 1 Aug 2022 16:10:17 -0700 Subject: [PATCH 08/11] Update release note --- .../add-graph-difference-9916bf3d612f0b1a.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/releasenotes/notes/add-graph-difference-9916bf3d612f0b1a.yaml b/releasenotes/notes/add-graph-difference-9916bf3d612f0b1a.yaml index 7cadbf932..db931deb5 100644 --- a/releasenotes/notes/add-graph-difference-9916bf3d612f0b1a.yaml +++ b/releasenotes/notes/add-graph-difference-9916bf3d612f0b1a.yaml @@ -1,15 +1,15 @@ --- features: - | - Add two new functions which calculates the difference of two graphs :func:`~retworkx.graph_difference` - for undirected graphs and :func:`~retworkx.digraph_difference` for directed graphs. For example: + Add two new functions which calculates the difference of two graphs :func:`~rustworkx.graph_difference` + for undirected graphs and :func:`~rustworkx.digraph_difference` for directed graphs. For example: .. jupyter-execute:: - import retworkx - from retworkx.visualization import mpl_draw + import rustworkx + from rustworkx.visualization import mpl_draw - graph_1 = retworkx.PyGraph() + graph_1 = rustworkx.PyGraph() graph_1.add_nodes_from(["a_1", "a_2", "a_3", "a_4"]) graph_1.extend_from_weighted_edge_list([(0, 1, "e_1"), (1, 2, "e_2"), @@ -18,7 +18,7 @@ features: (0, 2, "e_5"), (1, 3, "e_6"), ]) - graph_2 = retworkx.PyGraph() + graph_2 = rustworkx.PyGraph() graph_2.add_nodes_from(["a_1", "a_2", "a_3", "a_4"]) graph_2.extend_from_weighted_edge_list([(0, 1, "e_1"), (1, 2, "e_2"), @@ -26,6 +26,6 @@ features: (3, 0, "e_4"), ]) - graph_difference = retworkx.graph_difference(graph_1, graph_2) + graph_difference = rustworkx.graph_difference(graph_1, graph_2) mpl_draw(graph_difference) \ No newline at end of file From 126c4861672fc8a8f1837bc16f2b7c3aab9c7536 Mon Sep 17 00:00:00 2001 From: Ivan Carvalho Date: Mon, 1 Aug 2022 16:28:13 -0700 Subject: [PATCH 09/11] Add attrs to constructor --- src/difference.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/difference.rs b/src/difference.rs index 60b6c284e..45f4a0aed 100644 --- a/src/difference.rs +++ b/src/difference.rs @@ -81,6 +81,7 @@ pub fn graph_difference( graph: out_graph, multigraph: true, node_removed: false, + attrs: py.None(), }) } @@ -110,5 +111,6 @@ pub fn digraph_difference( check_cycle: false, node_removed: false, multigraph: true, + attrs: py.None(), }) } From 91dad7eaa518bedb774a1ff93ab2dc49acb07335 Mon Sep 17 00:00:00 2001 From: Ivan Carvalho Date: Mon, 1 Aug 2022 16:31:37 -0700 Subject: [PATCH 10/11] Black --- rustworkx/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rustworkx/__init__.py b/rustworkx/__init__.py index 13a0ad51f..25829db67 100644 --- a/rustworkx/__init__.py +++ b/rustworkx/__init__.py @@ -2339,6 +2339,7 @@ def _digraph_all_pairs_bellman_ford_shortest_path(graph, edge_cost_fn): def _graph_all_pairs_bellman_ford_shortest_path(graph, edge_cost_fn): return graph_all_pairs_bellman_ford_shortest_paths(graph, edge_cost_fn) + @functools.singledispatch def difference( first, @@ -2370,4 +2371,3 @@ def _graph_difference( second, ): return graph_difference(first, second) - From 7a6815f7ff985dd714cc9bc82c904ac1fd64b3ff Mon Sep 17 00:00:00 2001 From: Ivan Carvalho Date: Mon, 1 Aug 2022 23:09:46 -0700 Subject: [PATCH 11/11] Update api.rst --- docs/source/api.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/api.rst b/docs/source/api.rst index 5fc7f248a..9209d87b0 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -302,7 +302,7 @@ the functions from the explicitly typed based on the data type. rustworkx.digraph_core_number rustworkx.digraph_complement rustworkx.digraph_union - retworkx.digraph_difference + rustworkx.digraph_difference rustworkx.digraph_tensor_product rustworkx.digraph_cartesian_product rustworkx.digraph_random_layout @@ -356,7 +356,7 @@ typed API based on the data type. rustworkx.graph_core_number rustworkx.graph_complement rustworkx.graph_union - retworkx.graph_difference + rustworkx.graph_difference rustworkx.graph_tensor_product rustworkx.graph_cartesian_product rustworkx.graph_random_layout