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

Symmetrize edgelist when creating a CSR graph #4716

Merged
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: 1 addition & 1 deletion cpp/src/c_api/graph_sg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ cugraph_error_code_t cugraph_graph_create_sg_from_csr(
p_edge_ids,
p_edge_type_ids,
renumber,
FALSE, // symmetrize
symmetrize,
do_expensive_check);

try {
Expand Down
32 changes: 32 additions & 0 deletions python/cugraph/cugraph/tests/structure/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from cudf.testing import assert_series_equal
from cudf.testing.testing import assert_frame_equal
from cugraph.structure.symmetrize import symmetrize
from cugraph.datasets import karate_asymmetric

# MG
import dask_cudf
Expand Down Expand Up @@ -204,6 +205,37 @@ def test_add_adj_list_to_edge_list(graph_file):
compare_series(destinations_cu, destinations_exp)


@pytest.mark.sg
def test_create_undirected_graph_from_asymmetric_adj_list():
# karate_asymmetric.get_path()
Mnx = utils.read_csv_for_nx(karate_asymmetric.get_path())
N = max(max(Mnx["0"]), max(Mnx["1"])) + 1
Mcsr = scipy.sparse.csr_matrix((Mnx.weight, (Mnx["0"], Mnx["1"])), shape=(N, N))

offsets = cudf.Series(Mcsr.indptr)
indices = cudf.Series(Mcsr.indices)

G = cugraph.Graph(directed=False)

with pytest.raises(Exception):
# Ifan undirected graph is created with 'symmetrize' set to False, the
# edgelist provided by the user must be symmetric.
G.from_cudf_adjlist(offsets, indices, None, symmetrize=False)

G = cugraph.Graph(directed=False)
G.from_cudf_adjlist(offsets, indices, None, symmetrize=True)

rlratzel marked this conversation as resolved.
Show resolved Hide resolved
# FIXME: Since we have no mechanism to access the symmetrized edgelist
# from the graph_view_t, assert that the edgelist size is unchanged. Once
# exposing 'decompress_to_edgelist', ensure that
# G.number_of_edges() == 2 * karate_asymmetric.get_edgelist()?
assert G.number_of_edges() == len(karate_asymmetric.get_edgelist())

# FIXME: Once 'decompress_to_edgelist' is exposed to the
# python API, ensure that the derived edgelist is symmetric
# if symmetrize = True.


# Test
@pytest.mark.sg
@pytest.mark.parametrize("graph_file", utils.DATASETS)
Expand Down
Loading