Skip to content

Commit

Permalink
fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
jnke2016 committed Oct 1, 2024
1 parent fec091f commit efbdb38
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 74 deletions.
12 changes: 6 additions & 6 deletions cpp/src/c_api/graph_mg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,12 @@ extern "C" cugraph_error_code_t cugraph_graph_create_mg(
if (weight_type == cugraph_data_type_id_t::NTYPES) weight_type = p_weights[i]->type_;
}

if (symmetrize == TRUE){
CAPI_EXPECTS(
(properties->is_symmetric == TRUE),
CUGRAPH_INVALID_INPUT,
"Invalid input arguments: The graph property must be symmetric if 'symmetrize' is set to True.",
*error);
if (symmetrize == TRUE) {
CAPI_EXPECTS((properties->is_symmetric == TRUE),
CUGRAPH_INVALID_INPUT,
"Invalid input arguments: The graph property must be symmetric if 'symmetrize' "
"is set to True.",
*error);
}

CAPI_EXPECTS(p_src[i]->type_ == vertex_type,
Expand Down
24 changes: 12 additions & 12 deletions cpp/src/c_api/graph_sg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,12 +581,12 @@ extern "C" cugraph_error_code_t cugraph_graph_create_sg(
auto p_edge_type_ids =
reinterpret_cast<cugraph::c_api::cugraph_type_erased_device_array_view_t const*>(edge_type_ids);

if (symmetrize == TRUE){
CAPI_EXPECTS(
(properties->is_symmetric == TRUE),
CUGRAPH_INVALID_INPUT,
"Invalid input arguments: The graph property must be symmetric if 'symmetrize' is set to True.",
*error);
if (symmetrize == TRUE) {
CAPI_EXPECTS((properties->is_symmetric == TRUE),
CUGRAPH_INVALID_INPUT,
"Invalid input arguments: The graph property must be symmetric if 'symmetrize' is "
"set to True.",
*error);
}

CAPI_EXPECTS(p_src->size_ == p_dst->size_,
Expand Down Expand Up @@ -757,12 +757,12 @@ cugraph_error_code_t cugraph_graph_create_sg_from_csr(
weight_type = cugraph_data_type_id_t::FLOAT32;
}

if (symmetrize == TRUE){
CAPI_EXPECTS(
(properties->is_symmetric == TRUE),
CUGRAPH_INVALID_INPUT,
"Invalid input arguments: The graph property must be symmetric if 'symmetrize' is set to True.",
*error);
if (symmetrize == TRUE) {
CAPI_EXPECTS((properties->is_symmetric == TRUE),
CUGRAPH_INVALID_INPUT,
"Invalid input arguments: The graph property must be symmetric if 'symmetrize' is "
"set to True.",
*error);
}

CAPI_EXPECTS(
Expand Down
4 changes: 1 addition & 3 deletions python/cugraph/cugraph/components/connectivity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2023, NVIDIA CORPORATION.
# Copyright (c) 2019-2024, 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
Expand Down Expand Up @@ -287,8 +287,6 @@ def strongly_connected_components(
"strongly_connected_components", G, directed, connection, return_labels
)

print("G = ", G)

# FIXME: allow nx_weight_attr to be specified
(G, input_type) = ensure_cugraph_obj(
G, nx_weight_attr="weight", matrix_graph_type=Graph(directed=directed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def __from_edgelist(
"If the edges are already symmetric, set the 'symmetrize' "
"flag to False"
)

if symmetrize is None:
# default behavior
symmetrize = not self.properties.directed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def __from_edgelist(
raise ValueError(
"The edgelist can only be symmetrized for undirected graphs."
)

if self.properties.directed:
if symmetrize:
raise ValueError(
Expand All @@ -168,7 +168,7 @@ def __from_edgelist(
"If the edges are already symmetric, set the 'symmetrize' "
"flag to False"
)

if symmetrize is None:
# default behavior
symmetrize = not self.properties.directed
Expand Down Expand Up @@ -299,7 +299,7 @@ def __from_edgelist(
# be returned. If set to False, the API will assume that the edges are already
# symmetric. Duplicated edges will be dropped unless the graph is a
# MultiGraph(Not Implemented yet)

if edge_attr is not None:
value_col = {
self.edgeWeightCol: elist[weight] if weight in edge_attr else None,
Expand Down Expand Up @@ -1359,9 +1359,8 @@ def has_edge(self, u, v):
df, simpleGraphImpl.srcCol, simpleGraphImpl.dstCol
)
value_col = None

self.edgelist = simpleGraphImpl.EdgeList(source_col, dest_col, value_col)

self.edgelist = simpleGraphImpl.EdgeList(source_col, dest_col, value_col)

return (
(df[simpleGraphImpl.srcCol] == u) & (df[simpleGraphImpl.dstCol] == v)
Expand Down
17 changes: 8 additions & 9 deletions python/cugraph/cugraph/structure/hypergraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,21 +288,20 @@ def hypergraph(
"src",
"dst",
"weights",
symmetrize=not graph.is_directed())

symmetrize=not graph.is_directed(),
)

df["src"] = source_col
df["dst"] = dest_col
df["weights"] = value_col
else:
source_col, dest_col= symmetrize(
graph.edgelist.edgelist_df,
"src",
"dst",
symmetrize=not graph.is_directed())

source_col, dest_col = symmetrize(
graph.edgelist.edgelist_df, "src", "dst", symmetrize=not graph.is_directed()
)

df["src"] = source_col
df["dst"] = dest_col

graph.edgelist.edgelist_df = df

return {
Expand Down
12 changes: 5 additions & 7 deletions python/cugraph/cugraph/structure/property_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2005,7 +2005,7 @@ def edge_props_to_graph(
G.from_cudf_edgelist(edge_prop_df.reset_index(), **create_args)
else:
G.from_pandas_edgelist(edge_prop_df.reset_index(), **create_args)

# FIXME: Property_graph does not fully leverage the PLC API yet.
# It still relies on the edges being symmetrized by the deprecated
# symmetrize function.
Expand All @@ -2018,15 +2018,13 @@ def edge_props_to_graph(
"src",
"dst",
"weights",
symmetrize=not G.is_directed())
symmetrize=not G.is_directed(),
)
else:
source_col, dest_col = symmetrize(
G.edgelist.edgelist_df,
"src",
"dst",
symmetrize=not G.is_directed())
G.edgelist.edgelist_df, "src", "dst", symmetrize=not G.is_directed()
)


renumbered_edge_prop_df = cudf.DataFrame()
renumbered_edge_prop_df["src"] = source_col
renumbered_edge_prop_df["dst"] = dest_col
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,8 @@ def test_uniform_neighbor_sample_simple(input_combo):

# FIXME: Uses the deprecated implementation of symmetrize.
source_col, dest_col = symmetrize(
input_df,
"src",
"dst",
symmetrize=not G.is_directed())
input_df, "src", "dst", symmetrize=not G.is_directed()
)

input_df = cudf.DataFrame()
input_df["src"] = source_col
Expand Down
6 changes: 2 additions & 4 deletions python/cugraph/cugraph/tests/structure/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,8 @@ def test_to_directed(graph_file):

# FIXME: Uses the deprecated implementation of symmetrize.
source_col, dest_col = symmetrize(
G.edgelist.edgelist_df,
"src",
"dst",
symmetrize=not G.is_directed())
G.edgelist.edgelist_df, "src", "dst", symmetrize=not G.is_directed()
)

input_df = cudf.DataFrame()
input_df["src"] = source_col
Expand Down
2 changes: 1 addition & 1 deletion python/cugraph/cugraph/tests/structure/test_multigraph.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2023, NVIDIA CORPORATION.
# Copyright (c) 2020-2024, 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
Expand Down
33 changes: 11 additions & 22 deletions python/cugraph/cugraph/utilities/nx_factory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2023, NVIDIA CORPORATION.
# Copyright (c) 2020-2024, 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
Expand Down Expand Up @@ -119,10 +119,8 @@ def convert_from_nx(
"""

if isinstance(nxG, nx.classes.digraph.DiGraph):
print("creating a directed graph")
G = cugraph.Graph(directed=True)
elif isinstance(nxG, nx.classes.graph.Graph):
print("creating an undirected graph")
G = cugraph.Graph()
else:
raise TypeError(
Expand All @@ -137,11 +135,9 @@ def convert_from_nx(
# hence, the symmetrization cannot be performed at the graph
# creation. Use the deprecated 'symmetrize' function for now.
source_col, dest_col = symmetrize(
_gdf,
"src",
"dst",
symmetrize=not G.is_directed())

_gdf, "src", "dst", symmetrize=not G.is_directed()
)

_gdf = cudf.DataFrame()

_gdf["src"] = source_col
Expand All @@ -153,20 +149,17 @@ def convert_from_nx(
edge_attr=None,
renumber=do_renumber,
store_transposed=store_transposed,
)
)
else:
if weight is None:
_gdf = convert_weighted_unnamed_to_gdf(nxG, vertex_type)
# FIXME: The legacy algorithms do not support the PLC graph
# hence, the symmetrization cannot be performed at the graph
# creation. Use the deprecated 'symmetrize' function for now.
source_col, dest_col, value_col = symmetrize(
_gdf,
"src",
"target",
"weight",
symmetrize=not G.is_directed())

_gdf, "src", "target", "weight", symmetrize=not G.is_directed()
)

_gdf = cudf.DataFrame()

_gdf["src"] = source_col
Expand All @@ -187,12 +180,9 @@ def convert_from_nx(
# hence, the symmetrization cannot be performed at the graph
# creation. Use the deprecated 'symmetrize' function for now.
source_col, dest_col, value_col = symmetrize(
_gdf,
"src",
"dst",
"weight",
symmetrize=not G.is_directed())

_gdf, "src", "dst", "weight", symmetrize=not G.is_directed()
)

_gdf = cudf.DataFrame()

_gdf["src"] = source_col
Expand All @@ -207,7 +197,6 @@ def convert_from_nx(
renumber=do_renumber,
store_transposed=store_transposed,
)


return G

Expand Down

0 comments on commit efbdb38

Please sign in to comment.