Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nx-cugraph: add core_number (undirected graphs only) #4100

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions python/nx-cugraph/_nx_cugraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"complete_graph",
"complete_multipartite_graph",
"connected_components",
"core_number",
"cubical_graph",
"cycle_graph",
"davis_southern_women_graph",
Expand Down Expand Up @@ -127,6 +128,7 @@
"bfs_successors": "`sort_neighbors` parameter is not yet supported.",
"bfs_tree": "`sort_neighbors` parameter is not yet supported.",
"clustering": "Directed graphs and `weight` parameter are not yet supported.",
"core_number": "Directed graphs are not yet supported.",
"edge_betweenness_centrality": "`weight` parameter is not yet supported, and RNG with seed may be different.",
"eigenvector_centrality": "`nstart` parameter is not used, but it is checked for validity.",
"from_pandas_edgelist": "cudf.DataFrame inputs also supported; value columns with str is unsuppported.",
Expand Down
30 changes: 29 additions & 1 deletion python/nx-cugraph/nx_cugraph/algorithms/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,42 @@
import pylibcugraph as plc

import nx_cugraph as nxcg
from nx_cugraph.convert import _to_undirected_graph
from nx_cugraph.utils import (
_get_int_dtype,
index_dtype,
networkx_algorithm,
not_implemented_for,
)

__all__ = ["k_truss"]
__all__ = ["core_number", "k_truss"]


@not_implemented_for("directed")
@not_implemented_for("multigraph")
@networkx_algorithm(is_incomplete=True, plc="core_number", version_added="24.02")
def core_number(G):
"""Directed graphs are not yet supported."""
G = _to_undirected_graph(G)
if len(G) == 0:
return {}
if nxcg.number_of_selfloops(G) > 0:
raise nx.NetworkXNotImplemented(
"Input graph has self loops which is not permitted; "
"Consider using G.remove_edges_from(nx.selfloop_edges(G))."
)
node_ids, core_numbers = plc.core_number(
resource_handle=plc.ResourceHandle(),
graph=G._get_plc_graph(),
degree_type="bidirectional",
do_expensive_check=False,
)
return G._nodearrays_to_dict(node_ids, core_numbers)


@core_number._can_run
def _(G):
return not G.is_directed()


@not_implemented_for("directed")
Expand Down