-
Notifications
You must be signed in to change notification settings - Fork 311
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: handle louvain with isolated nodes #3897
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
063c7a8
nx-cugraph: handle louvain with isolated nodes
eriknw 2680a59
Merge branch 'branch-23.10' into louvain_isolates
eriknw aef9670
Document that 500 is max of max_level; also, implement is_isolate and…
eriknw e6428e6
Merge branch 'branch-23.10' into louvain_isolates
eriknw 07b90d1
fix test by handling difference in louvain in networkx <3.2
eriknw a4c6353
Add docstrings for custom isolate functions
eriknw cdcec03
Merge branch 'branch-23.10' into louvain_isolates
eriknw bac45e9
Merge branch 'branch-23.10' into louvain_isolates
eriknw dc1bc18
Merge branch 'branch-23.10' into louvain_isolates
eriknw 426fa08
bump flake8-simplify to 0.21.0
eriknw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright (c) 2023, NVIDIA CORPORATION. | ||
# 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 cupy as cp | ||
|
||
from nx_cugraph.convert import _to_graph | ||
from nx_cugraph.utils import networkx_algorithm | ||
|
||
__all__ = ["isolates"] | ||
|
||
|
||
def _isolates(G) -> cp.ndarray: | ||
G = _to_graph(G) | ||
mark_isolates = cp.ones(len(G), bool) | ||
mark_isolates[G.row_indices] = False | ||
if G.is_directed(): | ||
mark_isolates[G.col_indices] = False | ||
return cp.nonzero(mark_isolates)[0] | ||
|
||
|
||
@networkx_algorithm | ||
def isolates(G): | ||
G = _to_graph(G) | ||
return G._nodeiter_to_iter(iter(_isolates(G).tolist())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright (c) 2023, NVIDIA CORPORATION. | ||
# 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 networkx as nx | ||
|
||
import nx_cugraph as nxcg | ||
|
||
|
||
def test_louvain_isolated_nodes(): | ||
def check(left, right): | ||
assert len(left) == len(right) | ||
assert set(map(frozenset, left)) == set(map(frozenset, right)) | ||
|
||
# Empty graph (no nodes) | ||
G = nx.Graph() | ||
nx_result = nx.community.louvain_communities(G) | ||
cg_result = nxcg.community.louvain_communities(G) | ||
check(nx_result, cg_result) | ||
# Graph with no edges | ||
G.add_nodes_from(range(5)) | ||
nx_result = nx.community.louvain_communities(G) | ||
cg_result = nxcg.community.louvain_communities(G) | ||
check(nx_result, cg_result) | ||
# Graph with isolated nodes | ||
G.add_edge(1, 2) | ||
nx_result = nx.community.louvain_communities(G) | ||
cg_result = nxcg.community.louvain_communities(G) | ||
check(nx_result, cg_result) | ||
# Another one | ||
G.add_edge(4, 4) | ||
nx_result = nx.community.louvain_communities(G) | ||
cg_result = nxcg.community.louvain_communities(G) | ||
check(nx_result, cg_result) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add something in the docs about
max_level
being capped at 500?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
(max: 500)
to the max_level parameter doc.