Skip to content

Commit

Permalink
Add universal methods (#241)
Browse files Browse the repository at this point in the history
* Add universal methods

In the rust generated Python API we need to have fixed class inpurts to
satisfy the traits used by the pyo3 macro generated FFI functions. This
results in duplicate methods like digraph_dfs_edges and graph_dfs_edges
with the same implementation just differing input types. To simplify the
API for users this commit adds universal functions to the python side of
the retworkx package to take in any retworkx graph object and dispatch to
the proper function in the rust generated api that relies on strict
input types.

Fixes #215

* Add release notes

* Cleanup docs for new functions

* Add as_undirected flag to distance_matrix()
  • Loading branch information
mtreinish committed Feb 3, 2021
1 parent f908abb commit 00c9584
Show file tree
Hide file tree
Showing 4 changed files with 475 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ Random Circuit Functions
Algorithm Functions
-------------------

Specific Graph Type Methods
'''''''''''''''''''''''''''

.. autosummary::
:toctree: stubs

Expand Down Expand Up @@ -88,6 +91,27 @@ Algorithm Functions
retworkx.digraph_find_cycle
retworkx.digraph_union

Universal Functions
'''''''''''''''''''

These functions are algorithm functions that wrap per graph object
type functions in the algorithms API but can be run with a
:class:`~retworkx.PyGraph`, :class:`~retworkx.PyDiGraph`, or
:class:`~retworkx.PyDAG` object.

.. autosummary::
:toctree: stubs

retworkx.distance_matrix
retworkx.floyd_warshall_numpy
retworkx.adjacency_matrix
retworkx.all_simple_paths
retworkx.astar_shortest_path
retworkx.dijkstra_shortest_paths
retworkx.dijkstra_shortest_path_lengths
retworkx.k_shortest_path_lengths
retworkx.dfs_edges

Exceptions
----------

Expand Down
16 changes: 16 additions & 0 deletions releasenotes/notes/add-universal-functions-1e54351f1f7afa4b.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
features:
- |
New universal functions that can take in a :class:`~retworkx.PyGraph` or
:class:`~retworkx.PyDiGraph` instead of being class specific have been to
the retworkx API. These new functions are:
* :func:`retworkx.distance_matrix`
* :func:`retworkx.floyd_warshall_numpy`
* :func:`retworkx.adjacency_matrix`
* :func:`retworkx.all_simple_paths`
* :func:`retworkx.astar_shortest_path`
* :func:`retworkx.dijkstra_shortest_paths`
* :func:`retworkx.dijkstra_shortest_path_lengths`
* :func:`retworkx.k_shortest_path_lengths`
* :func:`retworkx.dfs_edges`
Loading

0 comments on commit 00c9584

Please sign in to comment.