diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2a5cb8e2828..082b830bb4b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: args: ["--config=setup.cfg"] files: python/.*$ types: [file] - types_or: [python] # TODO: Enable [python, cython] + types_or: [python, cython] additional_dependencies: ["flake8-force"] - repo: https://github.com/asottile/yesqa rev: v1.3.0 diff --git a/python/cugraph/cugraph/centrality/betweenness_centrality_wrapper.pyx b/python/cugraph/cugraph/centrality/betweenness_centrality_wrapper.pyx index 3d34304ff13..ec11a535ba2 100644 --- a/python/cugraph/cugraph/centrality/betweenness_centrality_wrapper.pyx +++ b/python/cugraph/cugraph/centrality/betweenness_centrality_wrapper.pyx @@ -16,7 +16,8 @@ # cython: embedsignature = True # cython: language_level = 3 -from cugraph.centrality.betweenness_centrality cimport betweenness_centrality as c_betweenness_centrality +from cugraph.centrality.betweenness_centrality cimport \ + betweenness_centrality as c_betweenness_centrality from cugraph.structure.graph_primtypes cimport * from libc.stdint cimport uintptr_t from libcpp cimport bool @@ -37,7 +38,7 @@ def get_output_df(number_of_vertices, result_dtype): def get_batch(sources, number_of_workers, current_worker): batch_size = len(sources) // number_of_workers - begin = current_worker * batch_size + begin = current_worker * batch_size end = (current_worker + 1) * batch_size if current_worker == (number_of_workers - 1): end = len(sources) @@ -55,23 +56,25 @@ cdef void run_c_betweenness_centrality(uintptr_t c_handle, uintptr_t c_batch, result_dtype): if result_dtype == np.float64: - c_betweenness_centrality[int, int, double, double](( c_handle)[0], - ( c_graph)[0], - c_betweenness, - normalized, - endpoints, - c_weights, - number_of_sources_in_batch, - c_batch) + c_betweenness_centrality[int, int, double, double]( + ( c_handle)[0], + ( c_graph)[0], + c_betweenness, + normalized, + endpoints, + c_weights, + number_of_sources_in_batch, + c_batch) elif result_dtype == np.float32: - c_betweenness_centrality[int, int, float, float](( c_handle)[0], - ( c_graph)[0], - c_betweenness, - normalized, - endpoints, - c_weights, - number_of_sources_in_batch, - c_batch) + c_betweenness_centrality[int, int, float, float]( + ( c_handle)[0], + ( c_graph)[0], + c_betweenness, + normalized, + endpoints, + c_weights, + number_of_sources_in_batch, + c_batch) else: raise ValueError("result_dtype can only be np.float64 or np.float32") @@ -127,7 +130,8 @@ def run_internal_work(handle, input_data, normalized, endpoints, raise ValueError("result_dtype can only be np.float64 or np.float32") c_identifier = result_df['vertex'].__cuda_array_interface__['data'][0] - c_betweenness = result_df['betweenness_centrality'].__cuda_array_interface__['data'][0] + c_betweenness = \ + result_df['betweenness_centrality'].__cuda_array_interface__['data'][0] if weights is not None: c_weights = weights.__cuda_array_interface__['data'][0] @@ -152,6 +156,7 @@ def run_internal_work(handle, input_data, normalized, endpoints, return result_df + def run_mg_work(input_data, normalized, endpoints, weights, sources, result_dtype, session_id): @@ -170,20 +175,20 @@ def run_mg_work(input_data, normalized, endpoints, def batch_betweenness_centrality(input_graph, normalized, endpoints, - weights, vertices, result_dtype): + weights, vertices, result_dtype): df = None client = get_client() comms = Comms.get_comms() replicated_adjlists = input_graph.batch_adjlists - work_futures = [client.submit(run_mg_work, - (data, input_graph.is_directed()), - normalized, - endpoints, - weights, - vertices, - result_dtype, - comms.sessionId, - workers=[worker]) for + work_futures = [client.submit(run_mg_work, + (data, input_graph.is_directed()), + normalized, + endpoints, + weights, + vertices, + result_dtype, + comms.sessionId, + workers=[worker]) for idx, (worker, data) in enumerate(replicated_adjlists.items())] dask.distributed.wait(work_futures) df = work_futures[0].result() @@ -215,13 +220,13 @@ def betweenness_centrality(input_graph, normalized, endpoints, weights, if not input_graph.adjlist: input_graph.view_adj_list() - if Comms.is_initialized() and input_graph.batch_enabled == True: + if Comms.is_initialized() and input_graph.batch_enabled is True: df = batch_betweenness_centrality(input_graph, - normalized, - endpoints, - weights, - vertices, - result_dtype) + normalized, + endpoints, + weights, + vertices, + result_dtype) else: df = sg_betweenness_centrality(input_graph, normalized, diff --git a/python/cugraph/cugraph/centrality/edge_betweenness_centrality_wrapper.pyx b/python/cugraph/cugraph/centrality/edge_betweenness_centrality_wrapper.pyx index bf4a80701ff..aa633699905 100644 --- a/python/cugraph/cugraph/centrality/edge_betweenness_centrality_wrapper.pyx +++ b/python/cugraph/cugraph/centrality/edge_betweenness_centrality_wrapper.pyx @@ -16,7 +16,8 @@ # cython: embedsignature = True # cython: language_level = 3 -from cugraph.centrality.betweenness_centrality cimport edge_betweenness_centrality as c_edge_betweenness_centrality +from cugraph.centrality.betweenness_centrality cimport \ + edge_betweenness_centrality as c_edge_betweenness_centrality from cugraph.structure import graph_primtypes_wrapper from cugraph.structure.graph_primtypes cimport * from libc.stdint cimport uintptr_t @@ -40,7 +41,7 @@ def get_output_df(indices, result_dtype): def get_batch(sources, number_of_workers, current_worker): batch_size = len(sources) // number_of_workers - begin = current_worker * batch_size + begin = current_worker * batch_size end = (current_worker + 1) * batch_size if current_worker == (number_of_workers - 1): end = len(sources) @@ -49,7 +50,7 @@ def get_batch(sources, number_of_workers, current_worker): def run_mg_work(input_data, normalized, weights, sources, - result_dtype, session_id): + result_dtype, session_id): result = None number_of_workers = Comms.get_n_workers(session_id) @@ -80,7 +81,7 @@ def run_internal_work(handle, input_data, normalized, weights, batch, cdef GraphCSRViewDouble graph_double cdef GraphCSRViewFloat graph_float - (offsets, indices, graph_weights), is_directed = input_data + (offsets, indices, graph_weights), is_directed = input_data if graph_weights is not None: c_graph_weights = graph_weights.__cuda_array_interface__['data'][0] @@ -93,7 +94,8 @@ def run_internal_work(handle, input_data, normalized, weights, batch, result_df = get_output_df(indices, result_dtype) c_src_identifier = result_df['src'].__cuda_array_interface__['data'][0] c_dst_identifier = result_df['dst'].__cuda_array_interface__['data'][0] - c_betweenness = result_df['betweenness_centrality'].__cuda_array_interface__['data'][0] + c_betweenness = \ + result_df['betweenness_centrality'].__cuda_array_interface__['data'][0] number_of_sources_in_batch = len(batch) if result_dtype == np.float64: @@ -140,38 +142,41 @@ cdef void run_c_edge_betweenness_centrality(uintptr_t c_handle, uintptr_t c_batch, result_dtype): if result_dtype == np.float64: - c_edge_betweenness_centrality[int, int, double, double](( c_handle)[0], - ( c_graph)[0], - c_betweenness, - normalized, - c_weights, - number_of_sources_in_batch, - c_batch) + c_edge_betweenness_centrality[int, int, double, double]( + ( c_handle)[0], + ( c_graph)[0], + c_betweenness, + normalized, + c_weights, + number_of_sources_in_batch, + c_batch) elif result_dtype == np.float32: - c_edge_betweenness_centrality[int, int, float, float](( c_handle)[0], - ( c_graph)[0], - c_betweenness, - normalized, - c_weights, - number_of_sources_in_batch, - c_batch) + c_edge_betweenness_centrality[int, int, float, float]( + ( c_handle)[0], + ( c_graph)[0], + c_betweenness, + normalized, + c_weights, + number_of_sources_in_batch, + c_batch) else: raise ValueError("result_dtype can only be np.float64 or np.float32") + def batch_edge_betweenness_centrality(input_graph, - normalized, - weights, vertices, result_dtype): + normalized, + weights, vertices, result_dtype): client = get_client() comms = Comms.get_comms() replicated_adjlists = input_graph.batch_adjlists - work_futures = [client.submit(run_mg_work, - (data, input_graph.is_directed()), - normalized, - weights, - vertices, - result_dtype, - comms.sessionId, - workers=[worker]) for + work_futures = [client.submit(run_mg_work, + (data, input_graph.is_directed()), + normalized, + weights, + vertices, + result_dtype, + comms.sessionId, + workers=[worker]) for (worker, data) in replicated_adjlists.items()] dask.distributed.wait(work_futures) df = work_futures[0].result() @@ -200,25 +205,26 @@ def edge_betweenness_centrality(input_graph, normalized, weights, cdef GraphCSRViewDouble graph_double cdef GraphCSRViewFloat graph_float - df = None if not input_graph.adjlist: input_graph.view_adj_list() - if Comms.is_initialized() and input_graph.batch_enabled == True: + if Comms.is_initialized() and input_graph.batch_enabled is True: df = batch_edge_betweenness_centrality(input_graph, normalized, - weights, vertices, - result_dtype) + weights, vertices, + result_dtype) else: df = sg_edge_betweenness_centrality(input_graph, normalized, weights, vertices, result_dtype) if result_dtype == np.float64: graph_double = get_graph_view[GraphCSRViewDouble](input_graph) - graph_double.get_source_indices((df['src'].__cuda_array_interface__['data'][0])) + graph_double.get_source_indices( + (df['src'].__cuda_array_interface__['data'][0])) elif result_dtype == np.float32: graph_float = get_graph_view[GraphCSRViewFloat](input_graph) - graph_float.get_source_indices((df['src'].__cuda_array_interface__['data'][0])) + graph_float.get_source_indices( + (df['src'].__cuda_array_interface__['data'][0])) return df diff --git a/python/cugraph/cugraph/community/ecg.pxd b/python/cugraph/cugraph/community/ecg.pxd index 4f13237eac7..0f3f11492d6 100644 --- a/python/cugraph/cugraph/community/ecg.pxd +++ b/python/cugraph/cugraph/community/ecg.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, 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 @@ -21,9 +21,9 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef void ecg[VT,ET,WT]( + cdef void ecg[VT, ET, WT]( const handle_t &handle, - const GraphCSRView[VT,ET,WT] &graph, + const GraphCSRView[VT, ET, WT] &graph, WT min_weight, VT ensemble_size, VT* ecg_parts) except + diff --git a/python/cugraph/cugraph/community/ecg_wrapper.pyx b/python/cugraph/cugraph/community/ecg_wrapper.pyx index c6d3251b730..c61aac1004c 100644 --- a/python/cugraph/cugraph/community/ecg_wrapper.pyx +++ b/python/cugraph/cugraph/community/ecg_wrapper.pyx @@ -38,9 +38,13 @@ def ecg(input_graph, min_weight=.05, ensemble_size=16): cdef unique_ptr[handle_t] handle_ptr handle_ptr.reset(new handle_t()) - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, - input_graph.adjlist.indices], [np.int32, np.int64]) - [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [ + input_graph.adjlist.offsets, + input_graph.adjlist.indices, + ], [np.int32, np.int64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.weights], [np.float32, np.float64]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) @@ -55,30 +59,38 @@ def ecg(input_graph, min_weight=.05, ensemble_size=16): cdef uintptr_t c_partition = df['partition'].__cuda_array_interface__['data'][0] cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] graph_float - cdef GraphCSRView[int,int,double] graph_double + cdef GraphCSRView[int, int, float] graph_float + cdef GraphCSRView[int, int, double] graph_double if weights.dtype == np.float32: - graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_float = GraphCSRView[int, int, float]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) graph_float.get_vertex_identifiers(c_identifier) - c_ecg[int,int,float](handle_ptr.get()[0], - graph_float, - min_weight, - ensemble_size, - c_partition) + c_ecg[int, int, float](handle_ptr.get()[0], + graph_float, + min_weight, + ensemble_size, + c_partition) else: - graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_double = GraphCSRView[int, int, double]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) graph_double.get_vertex_identifiers(c_identifier) - c_ecg[int,int,double](handle_ptr.get()[0], - graph_double, - min_weight, - ensemble_size, - c_partition) + c_ecg[int, int, double](handle_ptr.get()[0], + graph_double, + min_weight, + ensemble_size, + c_partition) return df diff --git a/python/cugraph/cugraph/community/ktruss_subgraph.pxd b/python/cugraph/cugraph/community/ktruss_subgraph.pxd index d993c31c375..d267dfb2d6e 100644 --- a/python/cugraph/cugraph/community/ktruss_subgraph.pxd +++ b/python/cugraph/cugraph/community/ktruss_subgraph.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, 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 @@ -21,6 +21,6 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef unique_ptr[GraphCOO[VT,ET,WT]] k_truss_subgraph[VT,ET,WT]( - const GraphCOOView[VT,ET,WT] &graph, + cdef unique_ptr[GraphCOO[VT, ET, WT]] k_truss_subgraph[VT, ET, WT]( + const GraphCOOView[VT, ET, WT] &graph, int k) except + diff --git a/python/cugraph/cugraph/community/ktruss_subgraph_wrapper.pyx b/python/cugraph/cugraph/community/ktruss_subgraph_wrapper.pyx index d3b7a38ba41..a10de4fe2b8 100644 --- a/python/cugraph/cugraph/community/ktruss_subgraph_wrapper.pyx +++ b/python/cugraph/cugraph/community/ktruss_subgraph_wrapper.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, 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 @@ -23,20 +23,25 @@ import numpy as np def ktruss_subgraph_float(input_graph, k, use_weights): - cdef GraphCOOViewFloat in_graph = get_graph_view[GraphCOOViewFloat](input_graph, use_weights) - return coo_to_df(move(k_truss_subgraph[int,int,float](in_graph, k))) + cdef GraphCOOViewFloat in_graph = get_graph_view[GraphCOOViewFloat]( + input_graph, use_weights) + return coo_to_df(move(k_truss_subgraph[int, int, float](in_graph, k))) def ktruss_subgraph_double(input_graph, k, use_weights): - cdef GraphCOOViewDouble in_graph = get_graph_view[GraphCOOViewDouble](input_graph, use_weights) - return coo_to_df(move(k_truss_subgraph[int,int,double](in_graph, k))) + cdef GraphCOOViewDouble in_graph = get_graph_view[GraphCOOViewDouble]( + input_graph, use_weights) + return coo_to_df(move(k_truss_subgraph[int, int, double](in_graph, k))) def ktruss_subgraph(input_graph, k, use_weights): [input_graph.edgelist.edgelist_df['src'], - input_graph.edgelist.edgelist_df['dst']] = graph_primtypes_wrapper.datatype_cast([input_graph.edgelist.edgelist_df['src'], - input_graph.edgelist.edgelist_df['dst']], - [np.int32]) + input_graph.edgelist.edgelist_df['dst']] = graph_primtypes_wrapper.datatype_cast( + [ + input_graph.edgelist.edgelist_df['src'], + input_graph.edgelist.edgelist_df['dst'], + ], + [np.int32]) if graph_primtypes_wrapper.weight_type(input_graph) == np.float64 and use_weights: return ktruss_subgraph_double(input_graph, k, use_weights) else: diff --git a/python/cugraph/cugraph/community/leiden.pxd b/python/cugraph/cugraph/community/leiden.pxd index 871dc826c06..baf3caa6671 100644 --- a/python/cugraph/cugraph/community/leiden.pxd +++ b/python/cugraph/cugraph/community/leiden.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, 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 @@ -23,9 +23,9 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef pair[size_t, weight_t] leiden[vertex_t,edge_t,weight_t]( + cdef pair[size_t, weight_t] leiden[vertex_t, edge_t, weight_t]( const handle_t &handle, - const GraphCSRView[vertex_t,edge_t,weight_t] &graph, + const GraphCSRView[vertex_t, edge_t, weight_t] &graph, vertex_t *leiden_parts, size_t max_level, weight_t resolution) except + diff --git a/python/cugraph/cugraph/community/leiden_wrapper.pyx b/python/cugraph/cugraph/community/leiden_wrapper.pyx index 1b41134c625..43184c45dfc 100644 --- a/python/cugraph/cugraph/community/leiden_wrapper.pyx +++ b/python/cugraph/cugraph/community/leiden_wrapper.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, 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 @@ -38,20 +38,22 @@ def leiden(input_graph, max_iter, resolution): weights = None final_modularity = None - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) if input_graph.adjlist.weights is not None: - [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.weights], [np.float32, np.float64]) else: weights = cudf.Series(np.full(num_edges, 1.0, dtype=np.float32)) # Create the output dataframe df = cudf.DataFrame() df['vertex'] = cudf.Series(np.zeros(num_verts, dtype=np.int32)) - df['partition'] = cudf.Series(np.zeros(num_verts,dtype=np.int32)) + df['partition'] = cudf.Series(np.zeros(num_verts, dtype=np.int32)) cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] @@ -59,16 +61,20 @@ def leiden(input_graph, max_iter, resolution): cdef uintptr_t c_partition = df['partition'].__cuda_array_interface__['data'][0] cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] graph_float - cdef GraphCSRView[int,int,double] graph_double + cdef GraphCSRView[int, int, float] graph_float + cdef GraphCSRView[int, int, double] graph_double cdef float final_modularity_float = 1.0 cdef double final_modularity_double = 1.0 cdef int num_level = 0 if weights.dtype == np.float32: - graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_float = GraphCSRView[int, int, float]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) graph_float.get_vertex_identifiers(c_identifier) num_level, final_modularity_float = c_leiden(handle_ptr.get()[0], @@ -79,8 +85,12 @@ def leiden(input_graph, max_iter, resolution): final_modularity = final_modularity_float else: - graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_double = GraphCSRView[int, int, double]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) graph_double.get_vertex_identifiers(c_identifier) num_level, final_modularity_double = c_leiden(handle_ptr.get()[0], diff --git a/python/cugraph/cugraph/community/spectral_clustering.pxd b/python/cugraph/cugraph/community/spectral_clustering.pxd index 346eb50a157..64cf6f71e3f 100644 --- a/python/cugraph/cugraph/community/spectral_clustering.pxd +++ b/python/cugraph/cugraph/community/spectral_clustering.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, 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 @@ -21,8 +21,8 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph::ext_raft": - cdef void balancedCutClustering[VT,ET,WT]( - const GraphCSRView[VT,ET,WT] &graph, + cdef void balancedCutClustering[VT, ET, WT]( + const GraphCSRView[VT, ET, WT] &graph, const int num_clusters, const int num_eigen_vects, const float evs_tolerance, @@ -31,8 +31,8 @@ cdef extern from "cugraph/algorithms.hpp" namespace "cugraph::ext_raft": const int kmean_max_iter, VT* clustering) except + - cdef void spectralModularityMaximization[VT,ET,WT]( - const GraphCSRView[VT,ET,WT] &graph, + cdef void spectralModularityMaximization[VT, ET, WT]( + const GraphCSRView[VT, ET, WT] &graph, const int n_clusters, const int n_eig_vects, const float evs_tolerance, @@ -41,20 +41,20 @@ cdef extern from "cugraph/algorithms.hpp" namespace "cugraph::ext_raft": const int kmean_max_iter, VT* clustering) except + - cdef void analyzeClustering_modularity[VT,ET,WT]( - const GraphCSRView[VT,ET,WT] &graph, + cdef void analyzeClustering_modularity[VT, ET, WT]( + const GraphCSRView[VT, ET, WT] &graph, const int n_clusters, const VT* clustering, WT* score) except + - cdef void analyzeClustering_edge_cut[VT,ET,WT]( - const GraphCSRView[VT,ET,WT] &graph, + cdef void analyzeClustering_edge_cut[VT, ET, WT]( + const GraphCSRView[VT, ET, WT] &graph, const int n_clusters, const VT* clustering, WT* score) except + - cdef void analyzeClustering_ratio_cut[VT,ET,WT]( - const GraphCSRView[VT,ET,WT] &graph, + cdef void analyzeClustering_ratio_cut[VT, ET, WT]( + const GraphCSRView[VT, ET, WT] &graph, const int n_clusters, const VT* clustering, WT* score) except + diff --git a/python/cugraph/cugraph/community/spectral_clustering_wrapper.pyx b/python/cugraph/cugraph/community/spectral_clustering_wrapper.pyx index 8a04e2c1017..d00e0874a16 100644 --- a/python/cugraph/cugraph/community/spectral_clustering_wrapper.pyx +++ b/python/cugraph/cugraph/community/spectral_clustering_wrapper.pyx @@ -16,11 +16,13 @@ # cython: embedsignature = True # cython: language_level = 3 -from cugraph.community.spectral_clustering cimport balancedCutClustering as c_balanced_cut_clustering -from cugraph.community.spectral_clustering cimport spectralModularityMaximization as c_spectral_modularity_maximization -from cugraph.community.spectral_clustering cimport analyzeClustering_modularity as c_analyze_clustering_modularity -from cugraph.community.spectral_clustering cimport analyzeClustering_edge_cut as c_analyze_clustering_edge_cut -from cugraph.community.spectral_clustering cimport analyzeClustering_ratio_cut as c_analyze_clustering_ratio_cut +from cugraph.community.spectral_clustering cimport ( + balancedCutClustering as c_balanced_cut_clustering, + spectralModularityMaximization as c_spectral_modularity_maximization, + analyzeClustering_modularity as c_analyze_clustering_modularity, + analyzeClustering_edge_cut as c_analyze_clustering_edge_cut, + analyzeClustering_ratio_cut as c_analyze_clustering_ratio_cut, +) from cugraph.structure.graph_primtypes cimport * from cugraph.structure import graph_primtypes_wrapper from libc.stdint cimport uintptr_t @@ -43,19 +45,23 @@ def spectralBalancedCutClustering(input_graph, if input_graph.is_directed(): raise ValueError("directed graphs are not supported") else: - raise TypeError(f"only cugraph.Graph objects are supported, got: {type(input_graph)}") + raise TypeError( + f"only cugraph.Graph objects are supported, got: {type(input_graph)}" + ) if not input_graph.adjlist: input_graph.view_adj_list() weights = None - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) if input_graph.adjlist.weights is not None: - [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.weights], [np.float32, np.float64]) else: weights = cudf.Series(np.full(num_edges, 1.0, dtype=np.float32)) @@ -70,12 +76,16 @@ def spectralBalancedCutClustering(input_graph, cdef uintptr_t c_cluster = df['cluster'].__cuda_array_interface__['data'][0] cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] graph_float - cdef GraphCSRView[int,int,double] graph_double + cdef GraphCSRView[int, int, float] graph_float + cdef GraphCSRView[int, int, double] graph_double if weights.dtype == np.float32: - graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_float = GraphCSRView[int, int, float]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) graph_float.get_vertex_identifiers(c_identifier) c_balanced_cut_clustering(graph_float, @@ -87,8 +97,12 @@ def spectralBalancedCutClustering(input_graph, kmean_max_iter, c_cluster) else: - graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_double = GraphCSRView[int, int, double]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) graph_double.get_vertex_identifiers(c_identifier) c_balanced_cut_clustering(graph_double, @@ -102,6 +116,7 @@ def spectralBalancedCutClustering(input_graph, return df + def spectralModularityMaximizationClustering(input_graph, num_clusters, num_eigen_vects=2, @@ -116,15 +131,21 @@ def spectralModularityMaximizationClustering(input_graph, if input_graph.is_directed(): raise ValueError("directed graphs are not supported") else: - raise TypeError(f"only cugraph.Graph objects are supported, got: {type(input_graph)}") + raise TypeError( + f"only cugraph.Graph objects are supported, got: {type(input_graph)}" + ) if not input_graph.adjlist: input_graph.view_adj_list() if input_graph.adjlist.weights is None: - raise Exception("spectral modularity maximization must be called on a graph with weights") + raise Exception( + "spectral modularity maximization must be called on a graph with weights" + ) - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) - [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.weights], [np.float32, np.float64]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) @@ -140,12 +161,16 @@ def spectralModularityMaximizationClustering(input_graph, cdef uintptr_t c_identifier = df['vertex'].__cuda_array_interface__['data'][0] cdef uintptr_t c_cluster = df['cluster'].__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] graph_float - cdef GraphCSRView[int,int,double] graph_double + cdef GraphCSRView[int, int, float] graph_float + cdef GraphCSRView[int, int, double] graph_double if weights.dtype == np.float32: - graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_float = GraphCSRView[int, int, float]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) graph_float.get_vertex_identifiers(c_identifier) c_spectral_modularity_maximization(graph_float, @@ -157,8 +182,12 @@ def spectralModularityMaximizationClustering(input_graph, kmean_max_iter, c_cluster) else: - graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_double = GraphCSRView[int, int, double]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) graph_double.get_vertex_identifiers(c_identifier) c_spectral_modularity_maximization(graph_double, @@ -172,6 +201,7 @@ def spectralModularityMaximizationClustering(input_graph, return df + def analyzeClustering_modularity(input_graph, n_clusters, clustering): """ Call analyzeClustering_modularity_nvgraph @@ -180,21 +210,28 @@ def analyzeClustering_modularity(input_graph, n_clusters, clustering): if input_graph.is_directed(): raise ValueError("directed graphs are not supported") else: - raise TypeError(f"only cugraph.Graph objects are supported, got: {type(input_graph)}") + raise TypeError( + f"only cugraph.Graph objects are supported, got: {type(input_graph)}" + ) if not input_graph.adjlist: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) - [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.weights], [np.float32, np.float64]) score = None num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) if input_graph.adjlist.weights is None: - raise Exception("analyze clustering modularity must be called on a graph with weights") + raise Exception( + "analyze clustering modularity must be called on a graph with weights" + ) if input_graph.adjlist.weights is not None: - [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.weights], [np.float32, np.float64]) else: weights = cudf.Series(np.full(num_edges, 1.0, dtype=np.float32)) @@ -203,14 +240,18 @@ def analyzeClustering_modularity(input_graph, n_clusters, clustering): cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] cdef uintptr_t c_cluster = clustering.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] graph_float - cdef GraphCSRView[int,int,double] graph_double + cdef GraphCSRView[int, int, float] graph_float + cdef GraphCSRView[int, int, double] graph_double cdef float score_float cdef double score_double if weights.dtype == np.float32: - graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_float = GraphCSRView[int, int, float]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) c_analyze_clustering_modularity(graph_float, n_clusters, @@ -219,8 +260,12 @@ def analyzeClustering_modularity(input_graph, n_clusters, clustering): score = score_float else: - graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_double = GraphCSRView[int, int, double]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) c_analyze_clustering_modularity(graph_double, n_clusters, @@ -230,6 +275,7 @@ def analyzeClustering_modularity(input_graph, n_clusters, clustering): return score + def analyzeClustering_edge_cut(input_graph, n_clusters, clustering): """ Call analyzeClustering_edge_cut_nvgraph @@ -238,18 +284,22 @@ def analyzeClustering_edge_cut(input_graph, n_clusters, clustering): if input_graph.is_directed(): raise ValueError("directed graphs are not supported") else: - raise TypeError(f"only cugraph.Graph objects are supported, got: {type(input_graph)}") + raise TypeError( + f"only cugraph.Graph objects are supported, got: {type(input_graph)}" + ) if not input_graph.adjlist: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) score = None num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) if input_graph.adjlist.weights is not None: - [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.weights], [np.float32, np.float64]) else: weights = cudf.Series(np.full(num_edges, 1.0, dtype=np.float32)) @@ -258,14 +308,18 @@ def analyzeClustering_edge_cut(input_graph, n_clusters, clustering): cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] cdef uintptr_t c_cluster = clustering.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] graph_float - cdef GraphCSRView[int,int,double] graph_double + cdef GraphCSRView[int, int, float] graph_float + cdef GraphCSRView[int, int, double] graph_double cdef float score_float cdef double score_double if weights.dtype == np.float32: - graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_float = GraphCSRView[int, int, float]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) c_analyze_clustering_edge_cut(graph_float, n_clusters, @@ -274,8 +328,12 @@ def analyzeClustering_edge_cut(input_graph, n_clusters, clustering): score = score_float else: - graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_double = GraphCSRView[int, int, double]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) c_analyze_clustering_edge_cut(graph_double, n_clusters, @@ -285,6 +343,7 @@ def analyzeClustering_edge_cut(input_graph, n_clusters, clustering): return score + def analyzeClustering_ratio_cut(input_graph, n_clusters, clustering): """ Call analyzeClustering_ratio_cut_nvgraph @@ -293,18 +352,22 @@ def analyzeClustering_ratio_cut(input_graph, n_clusters, clustering): if input_graph.is_directed(): raise ValueError("directed graphs are not supported") else: - raise TypeError(f"only cugraph.Graph objects are supported, got: {type(input_graph)}") + raise TypeError( + f"only cugraph.Graph objects are supported, got: {type(input_graph)}" + ) if not input_graph.adjlist: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) score = None num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) if input_graph.adjlist.weights is not None: - [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.weights], [np.float32, np.float64]) else: weights = cudf.Series(np.full(num_edges, 1.0, dtype=np.float32)) @@ -313,14 +376,18 @@ def analyzeClustering_ratio_cut(input_graph, n_clusters, clustering): cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] cdef uintptr_t c_cluster = clustering.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] graph_float - cdef GraphCSRView[int,int,double] graph_double + cdef GraphCSRView[int, int, float] graph_float + cdef GraphCSRView[int, int, double] graph_double cdef float score_float cdef double score_double if weights.dtype == np.float32: - graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_float = GraphCSRView[int, int, float]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) c_analyze_clustering_ratio_cut(graph_float, n_clusters, @@ -329,8 +396,12 @@ def analyzeClustering_ratio_cut(input_graph, n_clusters, clustering): score = score_float else: - graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_double = GraphCSRView[int, int, double]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) c_analyze_clustering_ratio_cut(graph_double, n_clusters, diff --git a/python/cugraph/cugraph/community/subgraph_extraction.pxd b/python/cugraph/cugraph/community/subgraph_extraction.pxd index 583e220327d..bc2b789ea71 100644 --- a/python/cugraph/cugraph/community/subgraph_extraction.pxd +++ b/python/cugraph/cugraph/community/subgraph_extraction.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, 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 @@ -22,7 +22,7 @@ from libcpp.memory cimport unique_ptr cdef extern from "cugraph/algorithms.hpp" namespace "cugraph::subgraph": - cdef unique_ptr[GraphCOO[VT,ET,WT]] extract_subgraph_vertex[VT,ET,WT]( - const GraphCOOView[VT,ET,WT] &graph, + cdef unique_ptr[GraphCOO[VT, ET, WT]] extract_subgraph_vertex[VT, ET, WT]( + const GraphCOOView[VT, ET, WT] &graph, const VT *vertices, ET num_vertices) except + diff --git a/python/cugraph/cugraph/community/subgraph_extraction_wrapper.pyx b/python/cugraph/cugraph/community/subgraph_extraction_wrapper.pyx index 46dc5c07eaf..a2f7689fddb 100644 --- a/python/cugraph/cugraph/community/subgraph_extraction_wrapper.pyx +++ b/python/cugraph/cugraph/community/subgraph_extraction_wrapper.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, 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 @@ -16,7 +16,8 @@ # cython: embedsignature = True # cython: language_level = 3 -from cugraph.community.subgraph_extraction cimport extract_subgraph_vertex as c_extract_subgraph_vertex +from cugraph.community.subgraph_extraction cimport \ + extract_subgraph_vertex as c_extract_subgraph_vertex from cugraph.structure.graph_primtypes cimport * from cugraph.structure import graph_primtypes_wrapper from libc.stdint cimport uintptr_t @@ -36,10 +37,15 @@ def subgraph(input_graph, vertices): if not input_graph.edgelist: input_graph.view_edge_list() - [src, dst] = graph_primtypes_wrapper.datatype_cast([input_graph.edgelist.edgelist_df['src'], input_graph.edgelist.edgelist_df['dst']], [np.int32]) + [src, dst] = graph_primtypes_wrapper.datatype_cast( + [ + input_graph.edgelist.edgelist_df['src'], + input_graph.edgelist.edgelist_df['dst'] + ], [np.int32]) if input_graph.edgelist.weights: - [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.edgelist.edgelist_df['weights']], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [input_graph.edgelist.edgelist_df['weights']], [np.float32, np.float64]) if weights.dtype == np.float64: use_float = False @@ -47,10 +53,10 @@ def subgraph(input_graph, vertices): num_edges = len(src) num_input_vertices = len(vertices) - cdef GraphCOOView[int,int,float] in_graph_float - cdef GraphCOOView[int,int,double] in_graph_double - cdef unique_ptr[GraphCOO[int,int,float]] out_graph_float - cdef unique_ptr[GraphCOO[int,int,double]] out_graph_double + cdef GraphCOOView[int, int, float] in_graph_float + cdef GraphCOOView[int, int, double] in_graph_double + cdef unique_ptr[GraphCOO[int, int, float]] out_graph_float + cdef unique_ptr[GraphCOO[int, int, double]] out_graph_double cdef uintptr_t c_src = src.__cuda_array_interface__['data'][0] cdef uintptr_t c_dst = dst.__cuda_array_interface__['data'][0] @@ -63,18 +69,26 @@ def subgraph(input_graph, vertices): cdef uintptr_t c_vertices = vertices.__cuda_array_interface__['data'][0] if use_float: - in_graph_float = GraphCOOView[int,int,float](c_src, c_dst, c_weights, num_verts, num_edges); - df = coo_to_df(move(c_extract_subgraph_vertex(in_graph_float, c_vertices, num_input_vertices))); + in_graph_float = GraphCOOView[int, int, float]( + c_src, c_dst, c_weights, num_verts, num_edges) + df = coo_to_df(move(c_extract_subgraph_vertex( + in_graph_float, c_vertices, num_input_vertices))) else: - in_graph_double = GraphCOOView[int,int,double](c_src, c_dst, c_weights, num_verts, num_edges); - df = coo_to_df(move(c_extract_subgraph_vertex(in_graph_double, c_vertices, num_input_vertices))); + in_graph_double = GraphCOOView[int, int, double]( + c_src, c_dst, c_weights, num_verts, num_edges) + df = coo_to_df(move(c_extract_subgraph_vertex( + in_graph_double, c_vertices, num_input_vertices))) # renumber vertices to match original input vertices_df = cudf.DataFrame() vertices_df['v'] = vertices vertices_df = vertices_df.reset_index(drop=True).reset_index() - df = df.merge(vertices_df, left_on='src', right_on='index', how='left').drop(columns=['src', 'index']).rename(columns={'v': 'src'}, copy=False) - df = df.merge(vertices_df, left_on='dst', right_on='index', how='left').drop(columns=['dst', 'index']).rename(columns={'v': 'dst'}, copy=False) + df = df.merge(vertices_df, left_on='src', right_on='index', how='left') \ + .drop(columns=['src', 'index']) \ + .rename(columns={'v': 'src'}, copy=False) + df = df.merge(vertices_df, left_on='dst', right_on='index', how='left') \ + .drop(columns=['dst', 'index']) \ + .rename(columns={'v': 'dst'}, copy=False) return df diff --git a/python/cugraph/cugraph/components/connectivity.pxd b/python/cugraph/cugraph/components/connectivity.pxd index 9829ce17325..92c58f2ce2b 100644 --- a/python/cugraph/cugraph/components/connectivity.pxd +++ b/python/cugraph/cugraph/components/connectivity.pxd @@ -25,7 +25,7 @@ cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": ctypedef enum cugraph_cc_t: CUGRAPH_STRONG "cugraph::cugraph_cc_t::CUGRAPH_STRONG" - cdef void connected_components[VT,ET,WT]( - const GraphCSRView[VT,ET,WT] &graph, + cdef void connected_components[VT, ET, WT]( + const GraphCSRView[VT, ET, WT] &graph, cugraph_cc_t connect_type, VT *labels) except + diff --git a/python/cugraph/cugraph/components/connectivity_wrapper.pyx b/python/cugraph/cugraph/components/connectivity_wrapper.pyx index 2a5888f9c9b..7f854ae5291 100644 --- a/python/cugraph/cugraph/components/connectivity_wrapper.pyx +++ b/python/cugraph/cugraph/components/connectivity_wrapper.pyx @@ -35,7 +35,8 @@ def strongly_connected_components(input_graph): if not input_graph.adjlist: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) @@ -44,14 +45,15 @@ def strongly_connected_components(input_graph): df['vertex'] = cudf.Series(np.zeros(num_verts, dtype=np.int32)) df['labels'] = cudf.Series(np.zeros(num_verts, dtype=np.int32)) - cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] - cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] - cdef uintptr_t c_identifier = df['vertex'].__cuda_array_interface__['data'][0]; - cdef uintptr_t c_labels_val = df['labels'].__cuda_array_interface__['data'][0]; + cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] + cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] + cdef uintptr_t c_identifier = df['vertex'].__cuda_array_interface__['data'][0] + cdef uintptr_t c_labels_val = df['labels'].__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] g + cdef GraphCSRView[int, int, float] g - g = GraphCSRView[int,int,float](c_offsets, c_indices, NULL, num_verts, num_edges) + g = GraphCSRView[int, int, float]( + c_offsets, c_indices, NULL, num_verts, num_edges) cdef cugraph_cc_t connect_type=CUGRAPH_STRONG connected_components(g, connect_type, c_labels_val) diff --git a/python/cugraph/cugraph/dask/comms/comms.pxd b/python/cugraph/cugraph/dask/comms/comms.pxd index 3f8f8c2ca59..1fcbd513c98 100644 --- a/python/cugraph/cugraph/dask/comms/comms.pxd +++ b/python/cugraph/cugraph/dask/comms/comms.pxd @@ -21,5 +21,5 @@ from pylibraft.common.handle cimport * cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": - cdef void init_subcomms(handle_t &handle, - size_t row_comm_size) + cdef void init_subcomms(handle_t &handle, + size_t row_comm_size) diff --git a/python/cugraph/cugraph/dask/structure/replication.pyx b/python/cugraph/cugraph/dask/structure/replication.pyx index 64f43663517..d665d320af4 100644 --- a/python/cugraph/cugraph/dask/structure/replication.pyx +++ b/python/cugraph/cugraph/dask/structure/replication.pyx @@ -38,15 +38,20 @@ def replicate_cudf_dataframe(cudf_dataframe, client=None, comms=None): dask_cudf_df = dask_cudf.from_cudf(cudf_dataframe, npartitions=1) df_length = len(dask_cudf_df) - _df_data = get_mg_batch_data(dask_cudf_df, batch_enabled=True) - df_data = mg_utils.prepare_worker_to_parts(_df_data, client) - - workers_to_futures = {worker: client.submit(_replicate_cudf_dataframe, - (data, cudf_dataframe.columns.values, cudf_dataframe.dtypes, df_length), - comms.sessionId, - workers=[worker]) for - (worker, data) in - df_data.worker_to_parts.items()} + _df_data = get_mg_batch_data(dask_cudf_df, batch_enabled=True) + df_data = mg_utils.prepare_worker_to_parts(_df_data, client) + + workers_to_futures = { + worker: client.submit(_replicate_cudf_dataframe, + ( + data, + cudf_dataframe.columns.values, + cudf_dataframe.dtypes, + df_length + ), + comms.sessionId, + workers=[worker]) + for worker, data in df_data.worker_to_parts.items()} dd.wait(workers_to_futures) return workers_to_futures @@ -72,7 +77,7 @@ def _replicate_cudf_dataframe(input_data, session_id): dtype = dtypes[idx] series = cudf.Series(np.zeros(df_length), dtype=dtype) df_data[column] = series - c_series = series.__cuda_array_interface__['data'][0] + c_series = series.__cuda_array_interface__['data'][0] comms_bcast(c_handle, c_series, df_length, series.dtype) if has_data: @@ -87,8 +92,8 @@ def replicate_cudf_series(cudf_series, client=None, comms=None): raise TypeError("Expected a cudf.Series to replicate") client = mg_utils.get_client() if client is None else client comms = Comms.get_comms() if comms is None else comms - dask_cudf_series = dask_cudf.from_cudf(cudf_series, - npartitions=1) + dask_cudf_series = dask_cudf.from_cudf(cudf_series, + npartitions=1) series_length = len(dask_cudf_series) _series_data = get_mg_batch_data(dask_cudf_series, batch_enabled=True) series_data = mg_utils.prepare_worker_to_parts(_series_data) @@ -98,9 +103,9 @@ def replicate_cudf_series(cudf_series, client=None, comms=None): client.submit(_replicate_cudf_series, (data, series_length, dtype), comms.sessionId, - workers=[worker]) for - (worker, data) in - series_data.worker_to_parts.items()} + workers=[worker]) for + (worker, data) in + series_data.worker_to_parts.items()} dd.wait(workers_to_futures) return workers_to_futures @@ -134,11 +139,11 @@ cdef comms_bcast(uintptr_t handle, uintptr_t value_ptr, size_t count, dtype): - if dtype == np.int32: + if dtype == np.int32: c_utils.comms_bcast(( handle)[0], value_ptr, count) elif dtype == np.float32: c_utils.comms_bcast(( handle)[0], value_ptr, count) elif dtype == np.float64: c_utils.comms_bcast(( handle)[0], value_ptr, count) else: - raise TypeError("Unsupported broadcast type") \ No newline at end of file + raise TypeError("Unsupported broadcast type") diff --git a/python/cugraph/cugraph/generators/rmat.pxd b/python/cugraph/cugraph/generators/rmat.pxd index 7c3a4165e3e..b6f9f4530e4 100644 --- a/python/cugraph/cugraph/generators/rmat.pxd +++ b/python/cugraph/cugraph/generators/rmat.pxd @@ -40,7 +40,8 @@ cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": bool clip_and_flip, bool scramble_vertex_ids) except + - cdef vector[pair[unique_ptr[device_buffer], unique_ptr[device_buffer]]] call_generate_rmat_edgelists[vertex_t]( + cdef vector[pair[unique_ptr[device_buffer], unique_ptr[device_buffer]]] \ + call_generate_rmat_edgelists[vertex_t]( const handle_t &handle, size_t n_edgelists, size_t min_scale, diff --git a/python/cugraph/cugraph/generators/rmat_wrapper.pyx b/python/cugraph/cugraph/generators/rmat_wrapper.pyx index 7f1e7f5a219..22796fcb883 100644 --- a/python/cugraph/cugraph/generators/rmat_wrapper.pyx +++ b/python/cugraph/cugraph/generators/rmat_wrapper.pyx @@ -61,26 +61,28 @@ def generate_rmat_edgelist( cdef unique_ptr[graph_generator_t] gg_ret_ptr - if (vertex_t==np.dtype("int32")): - gg_ret_ptr = move(call_generate_rmat_edgelist[int]( deref(handle_), - scale, - num_edges, - a, - b, - c, - seed, - clip_and_flip, - scramble_vertex_ids)) - else: # (vertex_t == np.dtype("int64")) - gg_ret_ptr = move(call_generate_rmat_edgelist[long]( deref(handle_), - scale, - num_edges, - a, - b, - c, - seed, - clip_and_flip, - scramble_vertex_ids)) + if vertex_t == np.dtype("int32"): + gg_ret_ptr = move(call_generate_rmat_edgelist[int]( + deref(handle_), + scale, + num_edges, + a, + b, + c, + seed, + clip_and_flip, + scramble_vertex_ids)) + else: # (vertex_t == np.dtype("int64")) + gg_ret_ptr = move(call_generate_rmat_edgelist[long]( + deref(handle_), + scale, + num_edges, + a, + b, + c, + seed, + clip_and_flip, + scramble_vertex_ids)) gg_ret = move(gg_ret_ptr.get()[0]) @@ -104,7 +106,7 @@ def generate_rmat_edgelists( seed, clip_and_flip, scramble_vertex_ids - ): +): vertex_t = np.dtype("int32") if (2**max_scale) > (2**31 - 1): @@ -128,32 +130,35 @@ def generate_rmat_edgelists( cdef vector[pair[unique_ptr[device_buffer], unique_ptr[device_buffer]]] gg_ret_ptr if (vertex_t==np.dtype("int32")): - gg_ret_ptr = move(call_generate_rmat_edgelists[int]( deref(handle_), - n_edgelists, - min_scale, - max_scale, - edge_factor, - s_distribution, - e_distribution, - seed, - clip_and_flip, - scramble_vertex_ids)) - else: # (vertex_t == np.dtype("int64")) - gg_ret_ptr = move(call_generate_rmat_edgelists[long]( deref(handle_), - n_edgelists, - min_scale, - max_scale, - edge_factor, - s_distribution, - e_distribution, - seed, - clip_and_flip, - scramble_vertex_ids)) + gg_ret_ptr = move(call_generate_rmat_edgelists[int]( + deref(handle_), + n_edgelists, + min_scale, + max_scale, + edge_factor, + s_distribution, + e_distribution, + seed, + clip_and_flip, + scramble_vertex_ids)) + else: # (vertex_t == np.dtype("int64")) + gg_ret_ptr = move(call_generate_rmat_edgelists[long]( + deref(handle_), + n_edgelists, + min_scale, + max_scale, + edge_factor, + s_distribution, + e_distribution, + seed, + clip_and_flip, + scramble_vertex_ids)) list_df = [] for i in range(n_edgelists): set_source = move_device_buffer_to_column(move(gg_ret_ptr[i].first), vertex_t) - set_destination = move_device_buffer_to_column(move(gg_ret_ptr[i].second), vertex_t) + set_destination = move_device_buffer_to_column( + move(gg_ret_ptr[i].second), vertex_t) df = cudf.DataFrame() df['src'] = set_source @@ -161,5 +166,5 @@ def generate_rmat_edgelists( list_df.append(df) - #Return a list of dataframes + # Return a list of dataframes return list_df diff --git a/python/cugraph/cugraph/layout/force_atlas2_wrapper.pyx b/python/cugraph/cugraph/layout/force_atlas2_wrapper.pyx index 73de7415971..da6be88a716 100644 --- a/python/cugraph/cugraph/layout/force_atlas2_wrapper.pyx +++ b/python/cugraph/cugraph/layout/force_atlas2_wrapper.pyx @@ -51,7 +51,7 @@ def force_atlas2(input_graph, cdef unique_ptr[handle_t] handle_ptr handle_ptr.reset(new handle_t()) - handle_ = handle_ptr.get(); + handle_ = handle_ptr.get() if not input_graph.edgelist: input_graph.view_edge_list() @@ -59,8 +59,8 @@ def force_atlas2(input_graph, num_verts = input_graph.number_of_vertices() num_edges = len(input_graph.edgelist.edgelist_df['src']) - cdef GraphCOOView[int,int,float] graph_float - cdef GraphCOOView[int,int,double] graph_double + cdef GraphCOOView[int, int, float] graph_float + cdef GraphCOOView[int, int, double] graph_double df = cudf.DataFrame() df['vertex'] = cudf.Series(np.arange(num_verts, dtype=np.int32)) @@ -76,7 +76,8 @@ def force_atlas2(input_graph, if input_graph.edgelist.weights: weights = input_graph.edgelist.edgelist_df["weights"] - [weights] = graph_primtypes_wrapper.datatype_cast([weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [weights], [np.float32, np.float64]) c_weights = weights.__cuda_array_interface__['data'][0] cdef uintptr_t x_start = NULL @@ -97,60 +98,68 @@ def force_atlas2(input_graph, if callback: callback_ptr = callback.get_native_callback() - # We keep np.float32 as results for both cases pos = cuda.device_array( - (num_verts, 2), - order="F", - dtype=np.float32) + (num_verts, 2), + order="F", + dtype=np.float32) pos_ptr = pos.device_ctypes_pointer.value if input_graph.edgelist.weights \ and input_graph.edgelist.edgelist_df['weights'].dtype == np.float64: - graph_double = GraphCOOView[int,int, double](c_src_indices, - c_dst_indices, c_weights, num_verts, num_edges) - - c_force_atlas2[int, int, double](handle_[0], - graph_double, - pos_ptr, - max_iter, - x_start, - y_start, - outbound_attraction_distribution, - lin_log_mode, - prevent_overlapping, - edge_weight_influence, - jitter_tolerance, - barnes_hut_optimize, - barnes_hut_theta, - scaling_ratio, - strong_gravity_mode, - gravity, - verbose, - callback_ptr) + graph_double = GraphCOOView[int, int, double]( + c_src_indices, + c_dst_indices, + c_weights, + num_verts, + num_edges) + + c_force_atlas2[int, int, double]( + handle_[0], + graph_double, + pos_ptr, + max_iter, + x_start, + y_start, + outbound_attraction_distribution, + lin_log_mode, + prevent_overlapping, + edge_weight_influence, + jitter_tolerance, + barnes_hut_optimize, + barnes_hut_theta, + scaling_ratio, + strong_gravity_mode, + gravity, + verbose, + callback_ptr) else: - graph_float = GraphCOOView[int,int,float](c_src_indices, - c_dst_indices, c_weights, num_verts, - num_edges) - c_force_atlas2[int, int, float](handle_[0], - graph_float, - pos_ptr, - max_iter, - x_start, - y_start, - outbound_attraction_distribution, - lin_log_mode, - prevent_overlapping, - edge_weight_influence, - jitter_tolerance, - barnes_hut_optimize, - barnes_hut_theta, - scaling_ratio, - strong_gravity_mode, - gravity, - verbose, - callback_ptr) + graph_float = GraphCOOView[int, int, float]( + c_src_indices, + c_dst_indices, + c_weights, + num_verts, + num_edges) + c_force_atlas2[int, int, float]( + handle_[0], + graph_float, + pos_ptr, + max_iter, + x_start, + y_start, + outbound_attraction_distribution, + lin_log_mode, + prevent_overlapping, + edge_weight_influence, + jitter_tolerance, + barnes_hut_optimize, + barnes_hut_theta, + scaling_ratio, + strong_gravity_mode, + gravity, + verbose, + callback_ptr) pos_df = cudf.DataFrame(pos, columns=['x', 'y']) df['x'] = pos_df['x'] diff --git a/python/cugraph/cugraph/linear_assignment/lap.pxd b/python/cugraph/cugraph/linear_assignment/lap.pxd index 9f65e215891..8712cfce7cb 100644 --- a/python/cugraph/cugraph/linear_assignment/lap.pxd +++ b/python/cugraph/cugraph/linear_assignment/lap.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021, NVIDIA CORPORATION. +# Copyright (c) 2020-2022, 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 @@ -20,24 +20,24 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef weight_t hungarian[vertex_t,edge_t,weight_t]( + cdef weight_t hungarian[vertex_t, edge_t, weight_t]( const handle_t &handle, - const GraphCOOView[vertex_t,edge_t,weight_t] &graph, + const GraphCOOView[vertex_t, edge_t, weight_t] &graph, vertex_t num_workers, const vertex_t *workers, vertex_t *assignments, weight_t epsilon) except + - cdef weight_t hungarian[vertex_t,edge_t,weight_t]( + cdef weight_t hungarian[vertex_t, edge_t, weight_t]( const handle_t &handle, - const GraphCOOView[vertex_t,edge_t,weight_t] &graph, + const GraphCOOView[vertex_t, edge_t, weight_t] &graph, vertex_t num_workers, const vertex_t *workers, vertex_t *assignments) except + cdef extern from "cugraph/algorithms.hpp": - cdef weight_t dense_hungarian "cugraph::dense::hungarian" [vertex_t,weight_t]( + cdef weight_t dense_hungarian "cugraph::dense::hungarian" [vertex_t, weight_t]( const handle_t &handle, const weight_t *costs, vertex_t num_rows, @@ -45,7 +45,7 @@ cdef extern from "cugraph/algorithms.hpp": vertex_t *assignments, weight_t epsilon) except + - cdef weight_t dense_hungarian "cugraph::dense::hungarian" [vertex_t,weight_t]( + cdef weight_t dense_hungarian "cugraph::dense::hungarian" [vertex_t, weight_t]( const handle_t &handle, const weight_t *costs, vertex_t num_rows, diff --git a/python/cugraph/cugraph/linear_assignment/lap_wrapper.pyx b/python/cugraph/cugraph/linear_assignment/lap_wrapper.pyx index c173f45fa3f..2204136a1e7 100644 --- a/python/cugraph/cugraph/linear_assignment/lap_wrapper.pyx +++ b/python/cugraph/cugraph/linear_assignment/lap_wrapper.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021, NVIDIA CORPORATION. +# Copyright (c) 2020-2022, 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 @@ -36,7 +36,7 @@ def sparse_hungarian(input_graph, workers, epsilon): cdef unique_ptr[handle_t] handle_ptr handle_ptr.reset(new handle_t()) - handle_ = handle_ptr.get(); + handle_ = handle_ptr.get() """ We need a COO of the graph. @@ -52,7 +52,8 @@ def sparse_hungarian(input_graph, workers, epsilon): weights = input_graph.edgelist.edgelist_df["weights"] [src, dst] = graph_primtypes_wrapper.datatype_cast([src, dst], [np.int32]) - [weights] = graph_primtypes_wrapper.datatype_cast([weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [weights], [np.float32, np.float64]) [local_workers] = graph_primtypes_wrapper.datatype_cast([workers], [np.int32]) num_verts = input_graph.number_of_vertices() @@ -62,30 +63,52 @@ def sparse_hungarian(input_graph, workers, epsilon): df['vertex'] = workers df['assignment'] = cudf.Series(np.zeros(len(workers), dtype=np.int32)) - if epsilon == None: + if epsilon is None: epsilon = 1e-6 - cdef uintptr_t c_src = src.__cuda_array_interface__['data'][0] - cdef uintptr_t c_dst = dst.__cuda_array_interface__['data'][0] - cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] - cdef uintptr_t c_workers = local_workers.__cuda_array_interface__['data'][0] + cdef uintptr_t c_src = src.__cuda_array_interface__['data'][0] + cdef uintptr_t c_dst = dst.__cuda_array_interface__['data'][0] + cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] + cdef uintptr_t c_workers = local_workers.__cuda_array_interface__['data'][0] - cdef uintptr_t c_identifier = df['vertex'].__cuda_array_interface__['data'][0]; - cdef uintptr_t c_assignment = df['assignment'].__cuda_array_interface__['data'][0]; + cdef uintptr_t c_identifier = df['vertex'].__cuda_array_interface__['data'][0] + cdef uintptr_t c_assignment = df['assignment'].__cuda_array_interface__['data'][0] cdef float c_epsilon_float = epsilon cdef double c_epsilon_double = epsilon - cdef GraphCOOView[int,int,float] g_float - cdef GraphCOOView[int,int,double] g_double + cdef GraphCOOView[int, int, float] g_float + cdef GraphCOOView[int, int, double] g_double if weights.dtype == np.float32: - g_float = GraphCOOView[int,int,float](c_src, c_dst, c_weights, num_verts, num_edges) - - cost = c_hungarian[int,int,float](handle_[0], g_float, len(workers), c_workers, c_assignment, c_epsilon_float) + g_float = GraphCOOView[int, int, float]( + c_src, + c_dst, + c_weights, + num_verts, + num_edges) + + cost = c_hungarian[int, int, float]( + handle_[0], + g_float, + len(workers), + c_workers, + c_assignment, + c_epsilon_float) else: - g_double = GraphCOOView[int,int,double](c_src, c_dst, c_weights, num_verts, num_edges) - - cost = c_hungarian[int,int,double](handle_[0], g_double, len(workers), c_workers, c_assignment, c_epsilon_double) + g_double = GraphCOOView[int, int, double]( + c_src, + c_dst, + c_weights, + num_verts, + num_edges) + + cost = c_hungarian[int, int, double]( + handle_[0], + g_double, + len(workers), + c_workers, + c_assignment, + c_epsilon_double) return cost, df @@ -99,11 +122,11 @@ def dense_hungarian(costs, num_rows, num_columns, epsilon): cdef unique_ptr[handle_t] handle_ptr handle_ptr.reset(new handle_t()) - handle_ = handle_ptr.get(); + handle_ = handle_ptr.get() assignment = cudf.Series(np.zeros(num_rows, dtype=np.int32)) - if epsilon == None: + if epsilon is None: epsilon = 1e-6 cdef uintptr_t c_costs = costs.__cuda_array_interface__['data'][0] @@ -112,12 +135,29 @@ def dense_hungarian(costs, num_rows, num_columns, epsilon): cdef double c_epsilon_double = epsilon if costs.dtype == np.float32: - cost = c_dense_hungarian[int,float](handle_[0], c_costs, num_rows, num_columns, c_assignment, c_epsilon_float) + cost = c_dense_hungarian[int, float]( + handle_[0], + c_costs, + num_rows, + num_columns, + c_assignment, + c_epsilon_float) elif costs.dtype == np.float64: - cost = c_dense_hungarian[int,double](handle_[0], c_costs, num_rows, num_columns, c_assignment, c_epsilon_double) + cost = c_dense_hungarian[int, double]( + handle_[0], + c_costs, + num_rows, + num_columns, + c_assignment, + c_epsilon_double) elif costs.dtype == np.int32: - cost = c_dense_hungarian[int,double](handle_[0], c_costs, num_rows, num_columns, c_assignment) + cost = c_dense_hungarian[int, double]( + handle_[0], + c_costs, + num_rows, + num_columns, + c_assignment) else: - raise("unsported type: ", costs.dtype) + raise ValueError(f"unsupported type: {costs.dtype}") return cost, assignment diff --git a/python/cugraph/cugraph/link_prediction/jaccard.pxd b/python/cugraph/cugraph/link_prediction/jaccard.pxd index 9e8c82ec3d8..902849168d7 100644 --- a/python/cugraph/cugraph/link_prediction/jaccard.pxd +++ b/python/cugraph/cugraph/link_prediction/jaccard.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, 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 @@ -21,13 +21,13 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef void jaccard[VT,ET,WT]( - const GraphCSRView[VT,ET,WT] &graph, + cdef void jaccard[VT, ET, WT]( + const GraphCSRView[VT, ET, WT] &graph, const WT *weights, WT *result) except + - cdef void jaccard_list[VT,ET,WT]( - const GraphCSRView[VT,ET,WT] &graph, + cdef void jaccard_list[VT, ET, WT]( + const GraphCSRView[VT, ET, WT] &graph, const WT *weights, ET num_pairs, const VT *first, diff --git a/python/cugraph/cugraph/link_prediction/jaccard_wrapper.pyx b/python/cugraph/cugraph/link_prediction/jaccard_wrapper.pyx index e66d8bf0b5c..4b76879bc0e 100644 --- a/python/cugraph/cugraph/link_prediction/jaccard_wrapper.pyx +++ b/python/cugraph/cugraph/link_prediction/jaccard_wrapper.pyx @@ -33,20 +33,21 @@ def jaccard(input_graph, weights_arr=None, vertex_pair=None): indices = None if input_graph.adjlist: - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, - input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) elif input_graph.transposedadjlist: - # - # NOTE: jaccard ONLY operates on an undirected graph, so CSR and CSC should be - # equivalent. The undirected check has already happened, so we'll just use - # the CSC as if it were CSR. - # - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.transposedadjlist.offsets, - input_graph.transposedadjlist.indices], [np.int32]) + # NOTE: jaccard ONLY operates on an undirected graph, so CSR and CSC + # should be equivalent. The undirected check has already happened, so + # we'll just use the CSC as if it were CSR. + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [ + input_graph.transposedadjlist.offsets, + input_graph.transposedadjlist.indices, + ], [np.int32]) else: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, - input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) @@ -63,13 +64,14 @@ def jaccard(input_graph, weights_arr=None, vertex_pair=None): cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] graph_float - cdef GraphCSRView[int,int,double] graph_double + cdef GraphCSRView[int, int, float] graph_float + cdef GraphCSRView[int, int, double] graph_double weight_type = np.float32 if weights_arr is not None: - [weights] = graph_primtypes_wrapper.datatype_cast([weights_arr], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [weights_arr], [np.float32, np.float64]) c_weights = weights.__cuda_array_interface__['data'][0] weight_type = weights.dtype @@ -92,23 +94,25 @@ def jaccard(input_graph, weights_arr=None, vertex_pair=None): c_second_col = second.__cuda_array_interface__['data'][0] if weight_type == np.float32: - graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, - c_weights, num_verts, num_edges) - c_jaccard_list[int,int,float](graph_float, - c_weights, - result_size, - c_first_col, - c_second_col, - c_result_col) + graph_float = GraphCSRView[int, int, float]( + c_offsets, c_indices, c_weights, + num_verts, num_edges) + c_jaccard_list[int, int, float](graph_float, + c_weights, + result_size, + c_first_col, + c_second_col, + c_result_col) else: - graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, - c_weights, num_verts, num_edges) - c_jaccard_list[int,int,double](graph_double, - c_weights, - result_size, - c_first_col, - c_second_col, - c_result_col) + graph_double = GraphCSRView[int, int, double]( + c_offsets, c_indices, c_weights, + num_verts, num_edges) + c_jaccard_list[int, int, double](graph_double, + c_weights, + result_size, + c_first_col, + c_second_col, + c_result_col) return df else: @@ -126,14 +130,14 @@ def jaccard(input_graph, weights_arr=None, vertex_pair=None): nan_as_null=False) c_result_col = df['jaccard_coeff'].__cuda_array_interface__['data'][0] - graph_float = GraphCSRView[int,int,float](c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) - c_jaccard[int,int,float](graph_float, - c_weights, - c_result_col) + graph_float = GraphCSRView[int, int, float](c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) + c_jaccard[int, int, float](graph_float, + c_weights, + c_result_col) graph_float.get_source_indices(c_src_index_col) else: @@ -141,14 +145,14 @@ def jaccard(input_graph, weights_arr=None, vertex_pair=None): nan_as_null=False) c_result_col = df['jaccard_coeff'].__cuda_array_interface__['data'][0] - graph_double = GraphCSRView[int,int,double](c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) - c_jaccard[int,int,double](graph_double, - c_weights, - c_result_col) + graph_double = GraphCSRView[int, int, double](c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) + c_jaccard[int, int, double](graph_double, + c_weights, + c_result_col) graph_double.get_source_indices(c_src_index_col) diff --git a/python/cugraph/cugraph/link_prediction/overlap.pxd b/python/cugraph/cugraph/link_prediction/overlap.pxd index f0654472587..ccb47e630a9 100644 --- a/python/cugraph/cugraph/link_prediction/overlap.pxd +++ b/python/cugraph/cugraph/link_prediction/overlap.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, 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 @@ -21,13 +21,13 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef void overlap[VT,ET,WT]( - const GraphCSRView[VT,ET,WT] &graph, + cdef void overlap[VT, ET, WT]( + const GraphCSRView[VT, ET, WT] &graph, const WT *weights, WT *result) except + - cdef void overlap_list[VT,ET,WT]( - const GraphCSRView[VT,ET,WT] &graph, + cdef void overlap_list[VT, ET, WT]( + const GraphCSRView[VT, ET, WT] &graph, const WT *weights, ET num_pairs, const VT *first, diff --git a/python/cugraph/cugraph/link_prediction/overlap_wrapper.pyx b/python/cugraph/cugraph/link_prediction/overlap_wrapper.pyx index 0f61460a72f..18dc46e854e 100644 --- a/python/cugraph/cugraph/link_prediction/overlap_wrapper.pyx +++ b/python/cugraph/cugraph/link_prediction/overlap_wrapper.pyx @@ -33,7 +33,8 @@ def overlap(input_graph, weights_arr=None, vertex_pair=None): if not input_graph.adjlist: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) @@ -50,13 +51,14 @@ def overlap(input_graph, weights_arr=None, vertex_pair=None): cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] graph_float - cdef GraphCSRView[int,int,double] graph_double + cdef GraphCSRView[int, int, float] graph_float + cdef GraphCSRView[int, int, double] graph_double weight_type = np.float32 if weights_arr is not None: - [weights] = graph_primtypes_wrapper.datatype_cast([weights_arr], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [weights_arr], [np.float32, np.float64]) c_weights = weights.__cuda_array_interface__['data'][0] weight_type = weights.dtype @@ -79,23 +81,31 @@ def overlap(input_graph, weights_arr=None, vertex_pair=None): c_second_col = second.__cuda_array_interface__['data'][0] if weight_type == np.float32: - graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, - c_weights, num_verts, num_edges) - c_overlap_list[int,int,float](graph_float, - c_weights, - result_size, - c_first_col, - c_second_col, - c_result_col) + graph_float = GraphCSRView[int, int, float]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) + c_overlap_list[int, int, float](graph_float, + c_weights, + result_size, + c_first_col, + c_second_col, + c_result_col) else: - graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, - c_weights, num_verts, num_edges) - c_overlap_list[int,int,double](graph_double, - c_weights, - result_size, - c_first_col, - c_second_col, - c_result_col) + graph_double = GraphCSRView[int, int, double]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) + c_overlap_list[int, int, double](graph_double, + c_weights, + result_size, + c_first_col, + c_second_col, + c_result_col) return df else: @@ -113,14 +123,15 @@ def overlap(input_graph, weights_arr=None, vertex_pair=None): nan_as_null=False) c_result_col = df['overlap_coeff'].__cuda_array_interface__['data'][0] - graph_float = GraphCSRView[int,int,float](c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) - c_overlap[int,int,float](graph_float, - c_weights, - c_result_col) + graph_float = GraphCSRView[int, int, float]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) + c_overlap[int, int, float](graph_float, + c_weights, + c_result_col) graph_float.get_source_indices(c_src_index_col) else: @@ -128,14 +139,15 @@ def overlap(input_graph, weights_arr=None, vertex_pair=None): nan_as_null=False) c_result_col = df['overlap_coeff'].__cuda_array_interface__['data'][0] - graph_double = GraphCSRView[int,int,double](c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) - c_overlap[int,int,double](graph_double, - c_weights, - c_result_col) + graph_double = GraphCSRView[int, int, double]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) + c_overlap[int, int, double](graph_double, + c_weights, + c_result_col) graph_double.get_source_indices(c_src_index_col) diff --git a/python/cugraph/cugraph/structure/graph_primtypes.pxd b/python/cugraph/cugraph/structure/graph_primtypes.pxd index f02f33edb67..7a62ef6c79e 100644 --- a/python/cugraph/cugraph/structure/graph_primtypes.pxd +++ b/python/cugraph/cugraph/structure/graph_primtypes.pxd @@ -43,9 +43,9 @@ cdef extern from "cugraph/legacy/graph.hpp" namespace "cugraph::legacy": bool tree PropType has_negative_edges - cdef cppclass GraphViewBase[VT,ET,WT]: + cdef cppclass GraphViewBase[VT, ET, WT]: WT *edge_data - handle_t *handle; + handle_t *handle GraphProperties prop VT number_of_vertices ET number_of_edges @@ -56,109 +56,116 @@ cdef extern from "cugraph/legacy/graph.hpp" namespace "cugraph::legacy": void set_local_data(VT* local_vertices_, ET* local_edges_, VT* local_offsets_) void get_vertex_identifiers(VT *) const - GraphViewBase(WT*,VT,ET) + GraphViewBase(WT*, VT, ET) - cdef cppclass GraphCOOView[VT,ET,WT](GraphViewBase[VT,ET,WT]): + cdef cppclass GraphCOOView[VT, ET, WT](GraphViewBase[VT, ET, WT]): VT *src_indices VT *dst_indices - void degree(ET *,DegreeDirection) const + void degree(ET *, DegreeDirection) const GraphCOOView() GraphCOOView(const VT *, const ET *, const WT *, size_t, size_t) - cdef cppclass GraphCompressedSparseBaseView[VT,ET,WT](GraphViewBase[VT,ET,WT]): + cdef cppclass GraphCompressedSparseBaseView[VT, ET, WT](GraphViewBase[VT, ET, WT]): ET *offsets VT *indices void get_source_indices(VT *) const - void degree(ET *,DegreeDirection) const + void degree(ET *, DegreeDirection) const - GraphCompressedSparseBaseView(const VT *, const ET *, const WT *, size_t, size_t) + GraphCompressedSparseBaseView( + const VT *, const ET *, const WT *, size_t, size_t) - cdef cppclass GraphCSRView[VT,ET,WT](GraphCompressedSparseBaseView[VT,ET,WT]): + cdef cppclass GraphCSRView[VT, ET, WT](GraphCompressedSparseBaseView[VT, ET, WT]): GraphCSRView() GraphCSRView(const VT *, const ET *, const WT *, size_t, size_t) - cdef cppclass GraphCSCView[VT,ET,WT](GraphCompressedSparseBaseView[VT,ET,WT]): + cdef cppclass GraphCSCView[VT, ET, WT](GraphCompressedSparseBaseView[VT, ET, WT]): GraphCSCView() GraphCSCView(const VT *, const ET *, const WT *, size_t, size_t) - cdef cppclass GraphCOOContents[VT,ET,WT]: + cdef cppclass GraphCOOContents[VT, ET, WT]: VT number_of_vertices ET number_of_edges unique_ptr[device_buffer] src_indices unique_ptr[device_buffer] dst_indices unique_ptr[device_buffer] edge_data - cdef cppclass GraphCOO[VT,ET,WT]: + cdef cppclass GraphCOO[VT, ET, WT]: GraphCOO( - VT nv, - ET ne, - bool has_data) except+ - GraphCOOContents[VT,ET,WT] release() - GraphCOOView[VT,ET,WT] view() + VT nv, + ET ne, + bool has_data) except+ + GraphCOOContents[VT, ET, WT] release() + GraphCOOView[VT, ET, WT] view() - cdef cppclass GraphSparseContents[VT,ET,WT]: + cdef cppclass GraphSparseContents[VT, ET, WT]: VT number_of_vertices ET number_of_edges unique_ptr[device_buffer] offsets unique_ptr[device_buffer] indices unique_ptr[device_buffer] edge_data - cdef cppclass GraphCSC[VT,ET,WT]: + cdef cppclass GraphCSC[VT, ET, WT]: GraphCSC( - VT nv, - ET ne, - bool has_data) except+ - GraphSparseContents[VT,ET,WT] release() - GraphCSCView[VT,ET,WT] view() + VT nv, + ET ne, + bool has_data) except+ + GraphSparseContents[VT, ET, WT] release() + GraphCSCView[VT, ET, WT] view() - cdef cppclass GraphCSR[VT,ET,WT]: + cdef cppclass GraphCSR[VT, ET, WT]: GraphCSR( - VT nv, - ET ne, - bool has_data) except+ - GraphSparseContents[VT,ET,WT] release() - GraphCSRView[VT,ET,WT] view() + VT nv, + ET ne, + bool has_data) except+ + GraphSparseContents[VT, ET, WT] release() + GraphCSRView[VT, ET, WT] view() cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef unique_ptr[GraphCOO[VT, ET, WT]] get_two_hop_neighbors[VT,ET,WT]( + cdef unique_ptr[GraphCOO[VT, ET, WT]] get_two_hop_neighbors[VT, ET, WT]( const GraphCSRView[VT, ET, WT] &graph) except + cdef extern from "" namespace "std" nogil: - cdef unique_ptr[GraphCOO[int,int,float]] move(unique_ptr[GraphCOO[int,int,float]]) - cdef unique_ptr[GraphCOO[int,int,double]] move(unique_ptr[GraphCOO[int,int,double]]) - cdef GraphCOOContents[int,int,float] move(GraphCOOContents[int,int,float]) - cdef GraphCOOContents[int,int,double] move(GraphCOOContents[int,int,double]) + cdef unique_ptr[GraphCOO[int, int, float]] move( + unique_ptr[GraphCOO[int, int, float]]) + cdef unique_ptr[GraphCOO[int, int, double]] move( + unique_ptr[GraphCOO[int, int, double]]) + cdef GraphCOOContents[int, int, float] move(GraphCOOContents[int, int, float]) + cdef GraphCOOContents[int, int, double] move(GraphCOOContents[int, int, double]) cdef device_buffer move(device_buffer) cdef unique_ptr[device_buffer] move(unique_ptr[device_buffer]) - cdef unique_ptr[GraphCSR[int,int,float]] move(unique_ptr[GraphCSR[int,int,float]]) - cdef unique_ptr[GraphCSR[int,int,double]] move(unique_ptr[GraphCSR[int,int,double]]) - cdef GraphSparseContents[int,int,float] move(GraphSparseContents[int,int,float]) - cdef GraphSparseContents[int,int,double] move(GraphSparseContents[int,int,double]) - -ctypedef unique_ptr[GraphCOO[int,int,float]] GraphCOOPtrFloat -ctypedef unique_ptr[GraphCOO[int,int,double]] GraphCOOPtrDouble + cdef unique_ptr[GraphCSR[int, int, float]] move( + unique_ptr[GraphCSR[int, int, float]]) + cdef unique_ptr[GraphCSR[int, int, double]] move( + unique_ptr[GraphCSR[int, int, double]]) + cdef GraphSparseContents[int, int, float] move( + GraphSparseContents[int, int, float]) + cdef GraphSparseContents[int, int, double] move( + GraphSparseContents[int, int, double]) + +ctypedef unique_ptr[GraphCOO[int, int, float]] GraphCOOPtrFloat +ctypedef unique_ptr[GraphCOO[int, int, double]] GraphCOOPtrDouble ctypedef fused GraphCOOPtrType: GraphCOOPtrFloat GraphCOOPtrDouble -ctypedef unique_ptr[GraphCSR[int,int,float]] GraphCSRPtrFloat -ctypedef unique_ptr[GraphCSR[int,int,double]] GraphCSRPtrDouble +ctypedef unique_ptr[GraphCSR[int, int, float]] GraphCSRPtrFloat +ctypedef unique_ptr[GraphCSR[int, int, double]] GraphCSRPtrDouble ctypedef fused GraphCSRPtrType: GraphCSRPtrFloat GraphCSRPtrDouble -ctypedef GraphCOOView[int,int,float] GraphCOOViewFloat -ctypedef GraphCOOView[int,int,double] GraphCOOViewDouble -ctypedef GraphCSRView[int,int,float] GraphCSRViewFloat -ctypedef GraphCSRView[int,int,double] GraphCSRViewDouble +ctypedef GraphCOOView[int, int, float] GraphCOOViewFloat +ctypedef GraphCOOView[int, int, double] GraphCOOViewDouble +ctypedef GraphCSRView[int, int, float] GraphCSRViewFloat +ctypedef GraphCSRView[int, int, double] GraphCSRViewDouble ctypedef fused GraphCOOViewType: GraphCOOViewFloat @@ -174,8 +181,11 @@ ctypedef fused GraphViewType: GraphCSRViewFloat GraphCSRViewDouble -cdef move_device_buffer_to_column(unique_ptr[device_buffer] device_buffer_unique_ptr, dtype) -cdef move_device_buffer_to_series(unique_ptr[device_buffer] device_buffer_unique_ptr, dtype, series_name) +cdef move_device_buffer_to_column( + unique_ptr[device_buffer] device_buffer_unique_ptr, dtype) +cdef move_device_buffer_to_series( + unique_ptr[device_buffer] device_buffer_unique_ptr, dtype, series_name) cdef coo_to_df(GraphCOOPtrType graph) cdef csr_to_series(GraphCSRPtrType graph) -cdef GraphViewType get_graph_view(input_graph, bool weightless=*, GraphViewType* dummy=*) +cdef GraphViewType get_graph_view( + input_graph, bool weightless=*, GraphViewType* dummy=*) diff --git a/python/cugraph/cugraph/structure/graph_primtypes.pyx b/python/cugraph/cugraph/structure/graph_primtypes.pyx index fadd0f73a08..796d18677f6 100644 --- a/python/cugraph/cugraph/structure/graph_primtypes.pyx +++ b/python/cugraph/cugraph/structure/graph_primtypes.pyx @@ -25,8 +25,8 @@ from cudf.core.buffer import as_buffer import cudf -cdef move_device_buffer_to_column( - unique_ptr[device_buffer] device_buffer_unique_ptr, dtype): +cdef move_device_buffer_to_column(unique_ptr[device_buffer] device_buffer_unique_ptr, + dtype): """ Transfers ownership of device_buffer_unique_ptr to a cuDF buffer which is used to construct a cudf column object, which is then returned. If the @@ -41,8 +41,8 @@ cdef move_device_buffer_to_column( return None -cdef move_device_buffer_to_series( - unique_ptr[device_buffer] device_buffer_unique_ptr, dtype, series_name): +cdef move_device_buffer_to_series(unique_ptr[device_buffer] device_buffer_unique_ptr, + dtype, series_name): """ Transfers ownership of device_buffer_unique_ptr to a cuDF buffer which is used to construct a cudf.Series object with name series_name, which is then @@ -101,12 +101,18 @@ cdef csr_to_series(GraphCSRPtrType graph): return (csr_offsets, csr_indices, csr_weights) -cdef GraphCSRViewType get_csr_graph_view(input_graph, bool weighted=True, GraphCSRViewType* dummy=NULL): +cdef GraphCSRViewType get_csr_graph_view( + input_graph, + bool weighted=True, + GraphCSRViewType* dummy=NULL +): if not input_graph.adjlist: input_graph.view_adj_list() - cdef uintptr_t c_off = input_graph.adjlist.offsets.__cuda_array_interface__['data'][0] - cdef uintptr_t c_ind = input_graph.adjlist.indices.__cuda_array_interface__['data'][0] + cdef uintptr_t c_off = \ + input_graph.adjlist.offsets.__cuda_array_interface__['data'][0] + cdef uintptr_t c_ind = \ + input_graph.adjlist.indices.__cuda_array_interface__['data'][0] cdef uintptr_t c_weights = NULL if input_graph.adjlist.weights is not None and weighted: @@ -116,13 +122,19 @@ cdef GraphCSRViewType get_csr_graph_view(input_graph, bool weighted=True, GraphC num_edges = input_graph.number_of_edges(directed_edges=True) cdef GraphCSRViewType in_graph if GraphCSRViewType is GraphCSRViewFloat: - in_graph = GraphCSRViewFloat(c_off, c_ind, c_weights, num_verts, num_edges) + in_graph = GraphCSRViewFloat( + c_off, c_ind, c_weights, num_verts, num_edges) elif GraphCSRViewType is GraphCSRViewDouble: - in_graph = GraphCSRViewDouble(c_off, c_ind, c_weights, num_verts, num_edges) + in_graph = GraphCSRViewDouble( + c_off, c_ind, c_weights, num_verts, num_edges) return in_graph -cdef GraphCOOViewType get_coo_graph_view(input_graph, bool weighted=True, GraphCOOViewType* dummy=NULL): +cdef GraphCOOViewType get_coo_graph_view( + input_graph, + bool weighted=True, + GraphCOOViewType* dummy=NULL +): # FIXME: this function assumes columns named "src" and "dst" and can only # be used for SG graphs due to that assumption. if not input_graph.edgelist: @@ -131,23 +143,32 @@ cdef GraphCOOViewType get_coo_graph_view(input_graph, bool weighted=True, GraphC num_edges = input_graph.number_of_edges(directed_edges=True) num_verts = input_graph.number_of_vertices() - cdef uintptr_t c_src = input_graph.edgelist.edgelist_df['src'].__cuda_array_interface__['data'][0] - cdef uintptr_t c_dst = input_graph.edgelist.edgelist_df['dst'].__cuda_array_interface__['data'][0] + cdef uintptr_t c_src = \ + input_graph.edgelist.edgelist_df['src'].__cuda_array_interface__['data'][0] + cdef uintptr_t c_dst = \ + input_graph.edgelist.edgelist_df['dst'].__cuda_array_interface__['data'][0] cdef uintptr_t c_weights = NULL # FIXME explicit check for None fails, different behavior than get_csr_graph_view if input_graph.edgelist.weights and weighted: - c_weights = input_graph.edgelist.edgelist_df['weights'].__cuda_array_interface__['data'][0] + c_weights = \ + input_graph.edgelist.edgelist_df['weights'].__cuda_array_interface__['data'][0] # noqa: E501 cdef GraphCOOViewType in_graph if GraphCOOViewType is GraphCOOViewFloat: - in_graph = GraphCOOViewFloat(c_src, c_dst, c_weights, num_verts, num_edges) + in_graph = GraphCOOViewFloat( + c_src, c_dst, c_weights, num_verts, num_edges) elif GraphCOOViewType is GraphCOOViewDouble: - in_graph = GraphCOOViewDouble(c_src, c_dst, c_weights, num_verts, num_edges) + in_graph = GraphCOOViewDouble( + c_src, c_dst, c_weights, num_verts, num_edges) return in_graph -cdef GraphViewType get_graph_view(input_graph, bool weighted = True, GraphViewType* dummy=NULL): +cdef GraphViewType get_graph_view( + input_graph, + bool weighted=True, + GraphViewType* dummy=NULL +): if GraphViewType is GraphCOOViewFloat: return get_coo_graph_view[GraphCOOViewFloat](input_graph, weighted, dummy) elif GraphViewType is GraphCOOViewDouble: diff --git a/python/cugraph/cugraph/structure/graph_primtypes_wrapper.pyx b/python/cugraph/cugraph/structure/graph_primtypes_wrapper.pyx index b680be143c9..700d56d503f 100644 --- a/python/cugraph/cugraph/structure/graph_primtypes_wrapper.pyx +++ b/python/cugraph/cugraph/structure/graph_primtypes_wrapper.pyx @@ -17,7 +17,8 @@ # cython: language_level = 3 from cugraph.structure.graph_primtypes cimport * -from cugraph.structure.graph_primtypes cimport get_two_hop_neighbors as c_get_two_hop_neighbors +from cugraph.structure.graph_primtypes cimport \ + get_two_hop_neighbors as c_get_two_hop_neighbors from cugraph.structure.utils_wrapper import * from libcpp cimport bool import enum @@ -55,10 +56,16 @@ def view_adj_list(input_graph): if input_graph.edgelist is None: raise ValueError('Graph is Empty') - [src, dst] = datatype_cast([input_graph.edgelist.edgelist_df['src'], input_graph.edgelist.edgelist_df['dst']], [np.int32]) + [src, dst] = datatype_cast( + [ + input_graph.edgelist.edgelist_df['src'], + input_graph.edgelist.edgelist_df['dst'], + ], [np.int32]) weights = None if input_graph.edgelist.weights: - [weights] = datatype_cast([input_graph.edgelist.edgelist_df['weights']], [np.float32, np.float64]) + [weights] = datatype_cast( + [input_graph.edgelist.edgelist_df['weights']], + [np.float32, np.float64]) return coo2csr(src, dst, weights) @@ -73,10 +80,16 @@ def view_transposed_adj_list(input_graph): else: input_graph.view_edge_list() - [src, dst] = datatype_cast([input_graph.edgelist.edgelist_df['src'], input_graph.edgelist.edgelist_df['dst']], [np.int32]) + [src, dst] = datatype_cast( + [ + input_graph.edgelist.edgelist_df['src'], + input_graph.edgelist.edgelist_df['dst'] + ], [np.int32]) weights = None if input_graph.edgelist.weights: - [weights] = datatype_cast([input_graph.edgelist.edgelist_df['weights']], [np.float32, np.float64]) + [weights] = datatype_cast( + [input_graph.edgelist.edgelist_df['weights']], + [np.float32, np.float64]) return coo2csr(dst, src, weights) @@ -86,24 +99,33 @@ def view_edge_list(input_graph): if input_graph.adjlist is None: raise RuntimeError('Graph is Empty') - [offsets, indices] = datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) [weights] = datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] graph - graph = GraphCSRView[int,int,float](c_offsets, c_indices, NULL, num_verts, num_edges) + cdef GraphCSRView[int, int, float] graph + graph = GraphCSRView[int, int, float]( + c_offsets, c_indices, NULL, num_verts, num_edges) - src_indices = cudf.Series(np.zeros(num_edges), dtype= indices.dtype) + src_indices = cudf.Series(np.zeros(num_edges), dtype=indices.dtype) cdef uintptr_t c_src_indices = src_indices.__cuda_array_interface__['data'][0] graph.get_source_indices(c_src_indices) return src_indices, indices, weights -def _degree_coo(edgelist_df, src_name, dst_name, direction=Direction.ALL, num_verts=None, sID=None): +def _degree_coo( + edgelist_df, + src_name, + dst_name, + direction=Direction.ALL, + num_verts=None, + sID=None +): # # Computing the degree of the input graph from COO # @@ -130,14 +152,15 @@ def _degree_coo(edgelist_df, src_name, dst_name, direction=Direction.ALL, num_ve vertex_col = cudf.Series(np.zeros(num_verts, dtype=np.int32)) degree_col = cudf.Series(np.zeros(num_verts, dtype=np.int32)) - cdef GraphCOOView[int,int,float] graph + cdef GraphCOOView[int, int, float] graph cdef uintptr_t c_vertex = vertex_col.__cuda_array_interface__['data'][0] cdef uintptr_t c_degree = degree_col.__cuda_array_interface__['data'][0] cdef uintptr_t c_src = src.__cuda_array_interface__['data'][0] cdef uintptr_t c_dst = dst.__cuda_array_interface__['data'][0] - graph = GraphCOOView[int,int,float](c_src, c_dst, NULL, num_verts, num_edges) + graph = GraphCOOView[int, int, float]( + c_src, c_dst, NULL, num_verts, num_edges) cdef size_t handle_size_t if sID is not None: @@ -171,14 +194,15 @@ def _degree_csr(offsets, indices, direction=Direction.ALL): vertex_col = cudf.Series(np.zeros(num_verts, dtype=np.int32)) degree_col = cudf.Series(np.zeros(num_verts, dtype=np.int32)) - cdef GraphCSRView[int,int,float] graph + cdef GraphCSRView[int, int, float] graph cdef uintptr_t c_vertex = vertex_col.__cuda_array_interface__['data'][0] cdef uintptr_t c_degree = degree_col.__cuda_array_interface__['data'][0] cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] - graph = GraphCSRView[int,int,float](c_offsets, c_indices, NULL, num_verts, num_edges) + graph = GraphCSRView[int, int, float]( + c_offsets, c_indices, NULL, num_verts, num_edges) graph.degree( c_degree, dir) graph.get_vertex_identifiers(c_vertex) @@ -229,9 +253,9 @@ def _mg_degree(input_graph, direction=Direction.ALL): def _degree(input_graph, direction=Direction.ALL): # FIXME: this function assumes columns named "src" and "dst" and can only # be used for SG graphs due to that assumption. - transpose_direction = { Direction.ALL: Direction.ALL, - Direction.IN: Direction.OUT, - Direction.OUT: Direction.IN } + transpose_direction = {Direction.ALL: Direction.ALL, + Direction.IN: Direction.OUT, + Direction.OUT: Direction.IN} if input_graph.adjlist is not None: return _degree_csr(input_graph.adjlist.offsets, @@ -262,20 +286,26 @@ def _degrees(input_graph): def get_two_hop_neighbors(input_graph): # FIXME: this function assumes columns named "src" and "dst" and can only # be used for SG graphs due to that assumption. - cdef GraphCSRView[int,int,float] graph + cdef GraphCSRView[int, int, float] graph offsets = None indices = None transposed = False if input_graph.adjlist: - [offsets, indices] = datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], + [np.int32]) elif input_graph.transposedadjlist: - [offsets, indices] = datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], + [np.int32]) transposed = True else: input_graph.view_adj_list() - [offsets, indices] = datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], + [np.int32]) cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] @@ -283,13 +313,14 @@ def get_two_hop_neighbors(input_graph): num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) - graph = GraphCSRView[int,int,float](c_offsets, c_indices, NULL, num_verts, num_edges) + graph = GraphCSRView[int, int, float]( + c_offsets, c_indices, NULL, num_verts, num_edges) df = coo_to_df(move(c_get_two_hop_neighbors(graph))) if not transposed: - df.rename(columns={'src':'first', 'dst':'second'}, inplace=True) + df.rename(columns={'src': 'first', 'dst': 'second'}, inplace=True) else: - df.rename(columns={'dst':'first', 'src':'second'}, inplace=True) + df.rename(columns={'dst': 'first', 'src': 'second'}, inplace=True) return df diff --git a/python/cugraph/cugraph/structure/graph_utilities.pxd b/python/cugraph/cugraph/structure/graph_utilities.pxd index 74edb61fafa..30e66691e78 100644 --- a/python/cugraph/cugraph/structure/graph_utilities.pxd +++ b/python/cugraph/cugraph/structure/graph_utilities.pxd @@ -36,7 +36,7 @@ cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": doubleType "cugraph::cython::numberTypeEnum::doubleType" cdef cppclass graph_container_t: - pass + pass cdef void populate_graph_container( graph_container_t &graph_container, @@ -145,14 +145,16 @@ cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": pair[vertex_t, vertex_t] get_part_local_vertex_range() vertex_t get_part_local_vertex_first() vertex_t get_part_local_vertex_last() - pair[vertex_t, vertex_t] get_part_vertex_partition_range(size_t vertex_partition_idx) + pair[vertex_t, vertex_t] get_part_vertex_partition_range( + size_t vertex_partition_idx) vertex_t get_part_vertex_partition_first(size_t vertex_partition_idx) vertex_t get_part_vertex_partition_last(size_t vertex_partition_idx) vertex_t get_part_vertex_partition_size(size_t vertex_partition_idx) size_t get_part_number_of_matrix_partitions() vertex_t get_part_matrix_partition_major_first(size_t partition_idx) vertex_t get_part_matrix_partition_major_last(size_t partition_idx) - vertex_t get_part_matrix_partition_major_value_start_offset(size_t partition_idx) + vertex_t get_part_matrix_partition_major_value_start_offset( + size_t partition_idx) pair[vertex_t, vertex_t] get_part_matrix_partition_minor_range() vertex_t get_part_matrix_partition_minor_first() vertex_t get_part_matrix_partition_minor_last() @@ -161,7 +163,8 @@ cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": # cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": - cdef unique_ptr[major_minor_weights_t[vertex_t, edge_t, weight_t]] call_shuffle[vertex_t, edge_t, weight_t]( + cdef unique_ptr[major_minor_weights_t[vertex_t, edge_t, weight_t]] \ + call_shuffle[vertex_t, edge_t, weight_t]( const handle_t &handle, vertex_t *edgelist_major_vertices, vertex_t *edgelist_minor_vertices, diff --git a/python/cugraph/cugraph/structure/renumber_wrapper.pyx b/python/cugraph/cugraph/structure/renumber_wrapper.pyx index 58c64104f65..56a902022e2 100644 --- a/python/cugraph/cugraph/structure/renumber_wrapper.pyx +++ b/python/cugraph/cugraph/structure/renumber_wrapper.pyx @@ -38,9 +38,12 @@ from cugraph.structure.graph_primtypes cimport move_device_buffer_to_series cdef renumber_helper(shuffled_vertices_t* ptr_maj_min_w, vertex_t, weights): # extract shuffled result: # - cdef pair[unique_ptr[device_buffer], size_t] pair_s_major = deref(ptr_maj_min_w).get_major_wrap() - cdef pair[unique_ptr[device_buffer], size_t] pair_s_minor = deref(ptr_maj_min_w).get_minor_wrap() - cdef pair[unique_ptr[device_buffer], size_t] pair_s_weights = deref(ptr_maj_min_w).get_weights_wrap() + cdef pair[unique_ptr[device_buffer], size_t] pair_s_major = \ + deref(ptr_maj_min_w).get_major_wrap() + cdef pair[unique_ptr[device_buffer], size_t] pair_s_minor = \ + deref(ptr_maj_min_w).get_minor_wrap() + cdef pair[unique_ptr[device_buffer], size_t] pair_s_weights = \ + deref(ptr_maj_min_w).get_weights_wrap() shuffled_major_series = move_device_buffer_to_series( move(pair_s_major.first), vertex_t, "shuffled_major") @@ -49,9 +52,10 @@ cdef renumber_helper(shuffled_vertices_t* ptr_maj_min_w, vertex_t, weights): move(pair_s_minor.first), vertex_t, "shuffled_minor") shuffled_df = cudf.DataFrame() - # Some workers might have no data therefore ensure the empty column have the appropriate - # vertex_t or weight_t. Failing to do that will create am empty column of type object - # which is not supported by '__cuda_array_interface__' + # Some workers might have no data therefore ensure the empty column have + # the appropriate vertex_t or weight_t. Failing to do that will create am + # empty column of type object which is not supported by + # '__cuda_array_interface__' if shuffled_major_series is None: shuffled_df['major_vertices'] = cudf.Series(dtype=vertex_t) else: @@ -88,10 +92,12 @@ def renumber(input_df, # maybe use cpdef ? # TODO: get handle_t out of handle... handle_ptr = handle_size_t - # FIXME: call_shuffle currently works on major/minor while call_renumber is updated to work on - # source/destination. We'd better update call_shuffle to work on source/destination as well to - # avoid switching between major/minor & source/destination. Deferring this work at this moment - # expecting this legacy code path will be replaced with the new pylibcugrpah & C API based path. + # FIXME: call_shuffle currently works on major/minor while call_renumber is + # updated to work on source/destination. We'd better update call_shuffle to + # work on source/destination as well to avoid switching between major/minor + # & source/destination. Deferring this work at this moment expecting this + # legacy code path will be replaced with the new pylibcugrpah & C API based + # path. if not transposed: major_vertices = input_df[renumbered_src_col_name] @@ -100,7 +106,7 @@ def renumber(input_df, # maybe use cpdef ? major_vertices = input_df[renumbered_dst_col_name] minor_vertices = input_df[renumbered_src_col_name] - cdef uintptr_t c_edge_weights = NULL # set below... + cdef uintptr_t c_edge_weights = NULL # set below... vertex_t = major_vertices.dtype if num_global_edges > (2**31 - 1): @@ -134,8 +140,8 @@ def renumber(input_df, # maybe use cpdef ? cdef uintptr_t shuffled_dst = NULL # FIXME: Fix fails when do_check = True - cdef bool do_check = False # ? for now... - cdef bool mg_flag = is_multi_gpu # run Single-GPU or MNMG + cdef bool do_check = False # ? for now... + cdef bool mg_flag = is_multi_gpu # run Single-GPU or MNMG cdef pair[unique_ptr[device_buffer], size_t] pair_original @@ -172,25 +178,35 @@ def renumber(input_df, # maybe use cpdef ? cdef size_t rank_indx = rank if (vertex_t == np.dtype("int32")): - if ( edge_t == np.dtype("int32")): - if( weight_t == np.dtype("float32")): - if(is_multi_gpu): - ptr_shuffled_32_32_32.reset(call_shuffle[int, int, float](deref(handle_ptr), - c_major_vertices, - c_minor_vertices, - c_edge_weights, - num_local_edges, - weights is not None).release()) - shuffled_df = renumber_helper(ptr_shuffled_32_32_32.get(), vertex_t, weights) + if edge_t == np.dtype("int32"): + if weight_t == np.dtype("float32"): + if is_multi_gpu: + ptr_shuffled_32_32_32.reset(call_shuffle[int, int, float]( + deref(handle_ptr), + c_major_vertices, + c_minor_vertices, + c_edge_weights, + num_local_edges, + weights is not None).release()) + shuffled_df = renumber_helper( + ptr_shuffled_32_32_32.get(), vertex_t, weights) major_vertices = shuffled_df['major_vertices'] minor_vertices = shuffled_df['minor_vertices'] num_local_edges = len(shuffled_df) if not transposed: - major = renumbered_src_col_name; minor = renumbered_dst_col_name + major = renumbered_src_col_name + minor = renumbered_dst_col_name else: - major = renumbered_dst_col_name; minor = renumbered_src_col_name - shuffled_df = shuffled_df.rename(columns={'major_vertices':major, 'minor_vertices':minor}, copy=False) - edge_counts_32 = move(ptr_shuffled_32_32_32.get().get_edge_counts_wrap()) + major = renumbered_dst_col_name + minor = renumbered_src_col_name + shuffled_df = shuffled_df.rename( + columns={ + 'major_vertices': major, + 'minor_vertices': minor, + }, + copy=False) + edge_counts_32 = move( + ptr_shuffled_32_32_32.get().get_edge_counts_wrap()) else: shuffled_df = input_df edge_counts_32 = make_unique[vector[int]](1, num_local_edges) @@ -202,32 +218,37 @@ def renumber(input_df, # maybe use cpdef ? shuffled_src = minor_vertices.__cuda_array_interface__['data'][0] shuffled_dst = major_vertices.__cuda_array_interface__['data'][0] - ptr_renum_tuple_32_32.reset(call_renumber[int, int](deref(handle_ptr), - shuffled_src, - shuffled_dst, - deref(edge_counts_32.get()), - transposed, - do_check, - mg_flag).release()) + ptr_renum_tuple_32_32.reset(call_renumber[int, int]( + deref(handle_ptr), + shuffled_src, + shuffled_dst, + deref(edge_counts_32.get()), + transposed, + do_check, + mg_flag).release()) - pair_original = ptr_renum_tuple_32_32.get().get_dv_wrap() # original vertices: see helper + # original vertices: see helper + pair_original = ptr_renum_tuple_32_32.get().get_dv_wrap() original_series = move_device_buffer_to_series( move(pair_original.first), vertex_t, "original") # extract unique_ptr[partition_offsets]: # - uniq_partition_vector_32 = move(ptr_renum_tuple_32_32.get().get_partition_offsets_wrap()) + uniq_partition_vector_32 = move( + ptr_renum_tuple_32_32.get().get_partition_offsets_wrap()) # create series out of a partition range from rank to rank+1: # if is_multi_gpu: - new_series = cudf.Series(np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), - uniq_partition_vector_32.get()[0].at(rank_indx+1)), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), + uniq_partition_vector_32.get()[0].at(rank_indx+1)), + dtype=vertex_t) else: - new_series = cudf.Series(np.arange(0, ptr_renum_tuple_32_32.get().get_num_vertices()), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(0, ptr_renum_tuple_32_32.get().get_num_vertices()), + dtype=vertex_t) # create new cudf df # # and add the previous series to it: @@ -236,32 +257,44 @@ def renumber(input_df, # maybe use cpdef ? renumbered_map['original_ids'] = original_series renumbered_map['new_ids'] = new_series - uniq_segment_vector_32 = move(ptr_renum_tuple_32_32.get().get_segment_offsets_wrap()) - segment_offsets = [None] * (deref(uniq_segment_vector_32).size()) + uniq_segment_vector_32 = move( + ptr_renum_tuple_32_32.get().get_segment_offsets_wrap()) + segment_offsets = [None] * ( + deref(uniq_segment_vector_32).size()) for i in range(len(segment_offsets)): - segment_offsets[i] = deref(uniq_segment_vector_32)[i] + segment_offsets[i] = deref(uniq_segment_vector_32)[i] return renumbered_map, segment_offsets, shuffled_df - elif( weight_t == np.dtype("float64")): - if(is_multi_gpu): - ptr_shuffled_32_32_64.reset(call_shuffle[int, int, double](deref(handle_ptr), - c_major_vertices, - c_minor_vertices, - c_edge_weights, - num_local_edges, - weights is not None).release()) - - shuffled_df = renumber_helper(ptr_shuffled_32_32_64.get(), vertex_t, weights) + elif weight_t == np.dtype("float64"): + if is_multi_gpu: + ptr_shuffled_32_32_64.reset(call_shuffle[int, int, double]( + deref(handle_ptr), + c_major_vertices, + c_minor_vertices, + c_edge_weights, + num_local_edges, + weights is not None).release()) + + shuffled_df = renumber_helper( + ptr_shuffled_32_32_64.get(), vertex_t, weights) major_vertices = shuffled_df['major_vertices'] minor_vertices = shuffled_df['minor_vertices'] num_local_edges = len(shuffled_df) if not transposed: - major = renumbered_src_col_name; minor = renumbered_dst_col_name + major = renumbered_src_col_name + minor = renumbered_dst_col_name else: - major = renumbered_dst_col_name; minor = renumbered_src_col_name - shuffled_df = shuffled_df.rename(columns={'major_vertices':major, 'minor_vertices':minor}, copy=False) - edge_counts_32 = move(ptr_shuffled_32_32_64.get().get_edge_counts_wrap()) + major = renumbered_dst_col_name + minor = renumbered_src_col_name + shuffled_df = shuffled_df.rename( + columns={ + 'major_vertices': major, + 'minor_vertices': minor, + }, + copy=False) + edge_counts_32 = move( + ptr_shuffled_32_32_64.get().get_edge_counts_wrap()) else: shuffled_df = input_df edge_counts_32 = make_unique[vector[int]](1, num_local_edges) @@ -273,32 +306,37 @@ def renumber(input_df, # maybe use cpdef ? shuffled_src = minor_vertices.__cuda_array_interface__['data'][0] shuffled_dst = major_vertices.__cuda_array_interface__['data'][0] - ptr_renum_tuple_32_32.reset(call_renumber[int, int](deref(handle_ptr), - shuffled_src, - shuffled_dst, - deref(edge_counts_32.get()), - transposed, - do_check, - mg_flag).release()) + ptr_renum_tuple_32_32.reset(call_renumber[int, int]( + deref(handle_ptr), + shuffled_src, + shuffled_dst, + deref(edge_counts_32.get()), + transposed, + do_check, + mg_flag).release()) - pair_original = ptr_renum_tuple_32_32.get().get_dv_wrap() # original vertices: see helper + # original vertices: see helper + pair_original = ptr_renum_tuple_32_32.get().get_dv_wrap() original_series = move_device_buffer_to_series( move(pair_original.first), vertex_t, "original") # extract unique_ptr[partition_offsets]: # - uniq_partition_vector_32 = move(ptr_renum_tuple_32_32.get().get_partition_offsets_wrap()) + uniq_partition_vector_32 = move( + ptr_renum_tuple_32_32.get().get_partition_offsets_wrap()) # create series out of a partition range from rank to rank+1: # if is_multi_gpu: - new_series = cudf.Series(np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), - uniq_partition_vector_32.get()[0].at(rank_indx+1)), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), + uniq_partition_vector_32.get()[0].at(rank_indx+1)), + dtype=vertex_t) else: - new_series = cudf.Series(np.arange(0, ptr_renum_tuple_32_32.get().get_num_vertices()), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(0, ptr_renum_tuple_32_32.get().get_num_vertices()), + dtype=vertex_t) # create new cudf df # @@ -308,33 +346,45 @@ def renumber(input_df, # maybe use cpdef ? renumbered_map['original_ids'] = original_series renumbered_map['new_ids'] = new_series - uniq_segment_vector_32 = move(ptr_renum_tuple_32_32.get().get_segment_offsets_wrap()) - segment_offsets = [None] * (deref(uniq_segment_vector_32).size()) + uniq_segment_vector_32 = move( + ptr_renum_tuple_32_32.get().get_segment_offsets_wrap()) + segment_offsets = [None] * ( + deref(uniq_segment_vector_32).size()) for i in range(len(segment_offsets)): - segment_offsets[i] = deref(uniq_segment_vector_32)[i] + segment_offsets[i] = deref(uniq_segment_vector_32)[i] return renumbered_map, segment_offsets, shuffled_df - elif ( edge_t == np.dtype("int64")): - if( weight_t == np.dtype("float32")): - if(is_multi_gpu): - ptr_shuffled_32_64_32.reset(call_shuffle[int, long, float](deref(handle_ptr), - c_major_vertices, - c_minor_vertices, - c_edge_weights, - num_local_edges, - weights is not None).release()) - - shuffled_df = renumber_helper(ptr_shuffled_32_64_32.get(), vertex_t, weights) + elif edge_t == np.dtype("int64"): + if weight_t == np.dtype("float32"): + if is_multi_gpu: + ptr_shuffled_32_64_32.reset(call_shuffle[int, long, float]( + deref(handle_ptr), + c_major_vertices, + c_minor_vertices, + c_edge_weights, + num_local_edges, + weights is not None).release()) + + shuffled_df = renumber_helper( + ptr_shuffled_32_64_32.get(), vertex_t, weights) major_vertices = shuffled_df['major_vertices'] minor_vertices = shuffled_df['minor_vertices'] num_local_edges = len(shuffled_df) if not transposed: - major = renumbered_src_col_name; minor = renumbered_dst_col_name + major = renumbered_src_col_name + minor = renumbered_dst_col_name else: - major = renumbered_dst_col_name; minor = renumbered_src_col_name - shuffled_df = shuffled_df.rename(columns={'major_vertices':major, 'minor_vertices':minor}, copy=False) - edge_counts_64 = move(ptr_shuffled_32_64_32.get().get_edge_counts_wrap()) + major = renumbered_dst_col_name + minor = renumbered_src_col_name + shuffled_df = shuffled_df.rename( + columns={ + 'major_vertices': major, + 'minor_vertices': minor, + }, + copy=False) + edge_counts_64 = move( + ptr_shuffled_32_64_32.get().get_edge_counts_wrap()) else: shuffled_df = input_df edge_counts_64 = make_unique[vector[long]](1, num_local_edges) @@ -346,32 +396,37 @@ def renumber(input_df, # maybe use cpdef ? shuffled_src = minor_vertices.__cuda_array_interface__['data'][0] shuffled_dst = major_vertices.__cuda_array_interface__['data'][0] - ptr_renum_tuple_32_64.reset(call_renumber[int, long](deref(handle_ptr), - shuffled_src, - shuffled_dst, - deref(edge_counts_64.get()), - transposed, - do_check, - mg_flag).release()) + ptr_renum_tuple_32_64.reset(call_renumber[int, long]( + deref(handle_ptr), + shuffled_src, + shuffled_dst, + deref(edge_counts_64.get()), + transposed, + do_check, + mg_flag).release()) - pair_original = ptr_renum_tuple_32_64.get().get_dv_wrap() # original vertices: see helper + # original vertices: see helper + pair_original = ptr_renum_tuple_32_64.get().get_dv_wrap() original_series = move_device_buffer_to_series( move(pair_original.first), vertex_t, "original") # extract unique_ptr[partition_offsets]: # - uniq_partition_vector_32 = move(ptr_renum_tuple_32_64.get().get_partition_offsets_wrap()) + uniq_partition_vector_32 = move( + ptr_renum_tuple_32_64.get().get_partition_offsets_wrap()) # create series out of a partition range from rank to rank+1: # if is_multi_gpu: - new_series = cudf.Series(np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), - uniq_partition_vector_32.get()[0].at(rank_indx+1)), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), + uniq_partition_vector_32.get()[0].at(rank_indx+1)), + dtype=vertex_t) else: - new_series = cudf.Series(np.arange(0, ptr_renum_tuple_32_64.get().get_num_vertices()), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(0, ptr_renum_tuple_32_64.get().get_num_vertices()), + dtype=vertex_t) # create new cudf df # @@ -381,31 +436,43 @@ def renumber(input_df, # maybe use cpdef ? renumbered_map['original_ids'] = original_series renumbered_map['new_ids'] = new_series - uniq_segment_vector_32 = move(ptr_renum_tuple_32_64.get().get_segment_offsets_wrap()) - segment_offsets = [None] * (deref(uniq_segment_vector_32).size()) + uniq_segment_vector_32 = move( + ptr_renum_tuple_32_64.get().get_segment_offsets_wrap()) + segment_offsets = [None] * ( + deref(uniq_segment_vector_32).size()) for i in range(len(segment_offsets)): - segment_offsets[i] = deref(uniq_segment_vector_32)[i] + segment_offsets[i] = deref(uniq_segment_vector_32)[i] return renumbered_map, segment_offsets, shuffled_df - elif( weight_t == np.dtype("float64")): - if(is_multi_gpu): - ptr_shuffled_32_64_64.reset(call_shuffle[int, long, double](deref(handle_ptr), - c_major_vertices, - c_minor_vertices, - c_edge_weights, - num_local_edges, - weights is not None).release()) - - shuffled_df = renumber_helper(ptr_shuffled_32_64_64.get(), vertex_t, weights) + elif weight_t == np.dtype("float64"): + if is_multi_gpu: + ptr_shuffled_32_64_64.reset(call_shuffle[int, long, double]( + deref(handle_ptr), + c_major_vertices, + c_minor_vertices, + c_edge_weights, + num_local_edges, + weights is not None).release()) + + shuffled_df = renumber_helper( + ptr_shuffled_32_64_64.get(), vertex_t, weights) major_vertices = shuffled_df['major_vertices'] minor_vertices = shuffled_df['minor_vertices'] num_local_edges = len(shuffled_df) if not transposed: - major = renumbered_src_col_name; minor = renumbered_dst_col_name + major = renumbered_src_col_name + minor = renumbered_dst_col_name else: - major = renumbered_dst_col_name; minor = renumbered_src_col_name - shuffled_df = shuffled_df.rename(columns={'major_vertices':major, 'minor_vertices':minor}, copy=False) - edge_counts_64 = move(ptr_shuffled_32_64_64.get().get_edge_counts_wrap()) + major = renumbered_dst_col_name + minor = renumbered_src_col_name + shuffled_df = shuffled_df.rename( + columns={ + 'major_vertices': major, + 'minor_vertices': minor, + }, + copy=False) + edge_counts_64 = move( + ptr_shuffled_32_64_64.get().get_edge_counts_wrap()) else: shuffled_df = input_df edge_counts_64 = make_unique[vector[long]](1, num_local_edges) @@ -417,32 +484,37 @@ def renumber(input_df, # maybe use cpdef ? shuffled_src = minor_vertices.__cuda_array_interface__['data'][0] shuffled_dst = major_vertices.__cuda_array_interface__['data'][0] - ptr_renum_tuple_32_64.reset(call_renumber[int, long](deref(handle_ptr), - shuffled_src, - shuffled_dst, - deref(edge_counts_64.get()), - transposed, - do_check, - mg_flag).release()) + ptr_renum_tuple_32_64.reset(call_renumber[int, long]( + deref(handle_ptr), + shuffled_src, + shuffled_dst, + deref(edge_counts_64.get()), + transposed, + do_check, + mg_flag).release()) - pair_original = ptr_renum_tuple_32_64.get().get_dv_wrap() # original vertices: see helper + # original vertices: see helper + pair_original = ptr_renum_tuple_32_64.get().get_dv_wrap() original_series = move_device_buffer_to_series( move(pair_original.first), vertex_t, "original") # extract unique_ptr[partition_offsets]: # - uniq_partition_vector_32 = move(ptr_renum_tuple_32_64.get().get_partition_offsets_wrap()) + uniq_partition_vector_32 = move( + ptr_renum_tuple_32_64.get().get_partition_offsets_wrap()) # create series out of a partition range from rank to rank+1: # if is_multi_gpu: - new_series = cudf.Series(np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), - uniq_partition_vector_32.get()[0].at(rank_indx+1)), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), + uniq_partition_vector_32.get()[0].at(rank_indx+1)), + dtype=vertex_t) else: - new_series = cudf.Series(np.arange(0, ptr_renum_tuple_32_64.get().get_num_vertices()), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(0, ptr_renum_tuple_32_64.get().get_num_vertices()), + dtype=vertex_t) # create new cudf df # # and add the previous series to it: @@ -451,34 +523,46 @@ def renumber(input_df, # maybe use cpdef ? renumbered_map['original_ids'] = original_series renumbered_map['new_ids'] = new_series - uniq_segment_vector_32 = move(ptr_renum_tuple_32_64.get().get_segment_offsets_wrap()) - segment_offsets = [None] * (deref(uniq_segment_vector_32).size()) + uniq_segment_vector_32 = move( + ptr_renum_tuple_32_64.get().get_segment_offsets_wrap()) + segment_offsets = [None] * ( + deref(uniq_segment_vector_32).size()) for i in range(len(segment_offsets)): - segment_offsets[i] = deref(uniq_segment_vector_32)[i] + segment_offsets[i] = deref(uniq_segment_vector_32)[i] return renumbered_map, segment_offsets, shuffled_df - elif (vertex_t == np.dtype("int64")): - if ( edge_t == np.dtype("int64")): - if( weight_t == np.dtype("float32")): - if(is_multi_gpu): - ptr_shuffled_64_64_32.reset(call_shuffle[long, long, float](deref(handle_ptr), - c_major_vertices, - c_minor_vertices, - c_edge_weights, - num_local_edges, - weights is not None).release()) - - shuffled_df = renumber_helper(ptr_shuffled_64_64_32.get(), vertex_t, weights) + elif vertex_t == np.dtype("int64"): + if edge_t == np.dtype("int64"): + if weight_t == np.dtype("float32"): + if is_multi_gpu: + ptr_shuffled_64_64_32.reset(call_shuffle[long, long, float]( + deref(handle_ptr), + c_major_vertices, + c_minor_vertices, + c_edge_weights, + num_local_edges, + weights is not None).release()) + + shuffled_df = renumber_helper( + ptr_shuffled_64_64_32.get(), vertex_t, weights) major_vertices = shuffled_df['major_vertices'] minor_vertices = shuffled_df['minor_vertices'] num_local_edges = len(shuffled_df) if not transposed: - major = renumbered_src_col_name; minor = renumbered_dst_col_name + major = renumbered_src_col_name + minor = renumbered_dst_col_name else: - major = renumbered_dst_col_name; minor = renumbered_src_col_name - shuffled_df = shuffled_df.rename(columns={'major_vertices':major, 'minor_vertices':minor}, copy=False) - edge_counts_64 = move(ptr_shuffled_64_64_32.get().get_edge_counts_wrap()) + major = renumbered_dst_col_name + minor = renumbered_src_col_name + shuffled_df = shuffled_df.rename( + columns={ + 'major_vertices': major, + 'minor_vertices': minor, + }, + copy=False) + edge_counts_64 = move( + ptr_shuffled_64_64_32.get().get_edge_counts_wrap()) else: shuffled_df = input_df edge_counts_64 = make_unique[vector[long]](1, num_local_edges) @@ -490,32 +574,37 @@ def renumber(input_df, # maybe use cpdef ? shuffled_src = minor_vertices.__cuda_array_interface__['data'][0] shuffled_dst = major_vertices.__cuda_array_interface__['data'][0] - ptr_renum_tuple_64_64.reset(call_renumber[long, long](deref(handle_ptr), - shuffled_src, - shuffled_dst, - deref(edge_counts_64.get()), - transposed, - do_check, - mg_flag).release()) + ptr_renum_tuple_64_64.reset(call_renumber[long, long]( + deref(handle_ptr), + shuffled_src, + shuffled_dst, + deref(edge_counts_64.get()), + transposed, + do_check, + mg_flag).release()) - pair_original = ptr_renum_tuple_64_64.get().get_dv_wrap() # original vertices: see helper + # original vertices: see helper + pair_original = ptr_renum_tuple_64_64.get().get_dv_wrap() original_series = move_device_buffer_to_series( move(pair_original.first), vertex_t, "original") # extract unique_ptr[partition_offsets]: # - uniq_partition_vector_64 = move(ptr_renum_tuple_64_64.get().get_partition_offsets_wrap()) + uniq_partition_vector_64 = move( + ptr_renum_tuple_64_64.get().get_partition_offsets_wrap()) # create series out of a partition range from rank to rank+1: # if is_multi_gpu: - new_series = cudf.Series(np.arange(uniq_partition_vector_64.get()[0].at(rank_indx), - uniq_partition_vector_64.get()[0].at(rank_indx+1)), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(uniq_partition_vector_64.get()[0].at(rank_indx), + uniq_partition_vector_64.get()[0].at(rank_indx+1)), + dtype=vertex_t) else: - new_series = cudf.Series(np.arange(0, ptr_renum_tuple_64_64.get().get_num_vertices()), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(0, ptr_renum_tuple_64_64.get().get_num_vertices()), + dtype=vertex_t) # create new cudf df # @@ -525,32 +614,44 @@ def renumber(input_df, # maybe use cpdef ? renumbered_map['original_ids'] = original_series renumbered_map['new_ids'] = new_series - uniq_segment_vector_64 = move(ptr_renum_tuple_64_64.get().get_segment_offsets_wrap()) - segment_offsets = [None] * (deref(uniq_segment_vector_64).size()) + uniq_segment_vector_64 = move( + ptr_renum_tuple_64_64.get().get_segment_offsets_wrap()) + segment_offsets = [None] * ( + deref(uniq_segment_vector_64).size()) for i in range(len(segment_offsets)): - segment_offsets[i] = deref(uniq_segment_vector_64)[i] + segment_offsets[i] = deref(uniq_segment_vector_64)[i] return renumbered_map, segment_offsets, shuffled_df - elif( weight_t == np.dtype("float64")): - if(is_multi_gpu): - ptr_shuffled_64_64_64.reset(call_shuffle[long, long, double](deref(handle_ptr), - c_major_vertices, - c_minor_vertices, - c_edge_weights, - num_local_edges, - weights is not None).release()) - - shuffled_df = renumber_helper(ptr_shuffled_64_64_64.get(), vertex_t, weights) + elif weight_t == np.dtype("float64"): + if is_multi_gpu: + ptr_shuffled_64_64_64.reset(call_shuffle[long, long, double]( + deref(handle_ptr), + c_major_vertices, + c_minor_vertices, + c_edge_weights, + num_local_edges, + weights is not None).release()) + + shuffled_df = renumber_helper( + ptr_shuffled_64_64_64.get(), vertex_t, weights) major_vertices = shuffled_df['major_vertices'] minor_vertices = shuffled_df['minor_vertices'] num_local_edges = len(shuffled_df) if not transposed: - major = renumbered_src_col_name; minor = renumbered_dst_col_name + major = renumbered_src_col_name + minor = renumbered_dst_col_name else: - major = renumbered_dst_col_name; minor = renumbered_src_col_name - shuffled_df = shuffled_df.rename(columns={'major_vertices':major, 'minor_vertices':minor}, copy=False) - edge_counts_64 = move(ptr_shuffled_64_64_64.get().get_edge_counts_wrap()) + major = renumbered_dst_col_name + minor = renumbered_src_col_name + shuffled_df = shuffled_df.rename( + columns={ + 'major_vertices': major, + 'minor_vertices': minor, + }, + copy=False) + edge_counts_64 = move( + ptr_shuffled_64_64_64.get().get_edge_counts_wrap()) else: shuffled_df = input_df edge_counts_64 = make_unique[vector[long]](1, num_local_edges) @@ -562,32 +663,37 @@ def renumber(input_df, # maybe use cpdef ? shuffled_src = minor_vertices.__cuda_array_interface__['data'][0] shuffled_dst = major_vertices.__cuda_array_interface__['data'][0] - ptr_renum_tuple_64_64.reset(call_renumber[long, long](deref(handle_ptr), - shuffled_src, - shuffled_dst, - deref(edge_counts_64.get()), - transposed, - do_check, - mg_flag).release()) + ptr_renum_tuple_64_64.reset(call_renumber[long, long]( + deref(handle_ptr), + shuffled_src, + shuffled_dst, + deref(edge_counts_64.get()), + transposed, + do_check, + mg_flag).release()) - pair_original = ptr_renum_tuple_64_64.get().get_dv_wrap() # original vertices: see helper + # original vertices: see helper + pair_original = ptr_renum_tuple_64_64.get().get_dv_wrap() original_series = move_device_buffer_to_series( move(pair_original.first), vertex_t, "original") # extract unique_ptr[partition_offsets]: # - uniq_partition_vector_64 = move(ptr_renum_tuple_64_64.get().get_partition_offsets_wrap()) + uniq_partition_vector_64 = move( + ptr_renum_tuple_64_64.get().get_partition_offsets_wrap()) # create series out of a partition range from rank to rank+1: # if is_multi_gpu: - new_series = cudf.Series(np.arange(uniq_partition_vector_64.get()[0].at(rank_indx), - uniq_partition_vector_64.get()[0].at(rank_indx+1)), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(uniq_partition_vector_64.get()[0].at(rank_indx), + uniq_partition_vector_64.get()[0].at(rank_indx+1)), + dtype=vertex_t) else: - new_series = cudf.Series(np.arange(0, ptr_renum_tuple_64_64.get().get_num_vertices()), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(0, ptr_renum_tuple_64_64.get().get_num_vertices()), + dtype=vertex_t) # create new cudf df # @@ -597,9 +703,11 @@ def renumber(input_df, # maybe use cpdef ? renumbered_map['original_ids'] = original_series renumbered_map['new_ids'] = new_series - uniq_segment_vector_64 = move(ptr_renum_tuple_64_64.get().get_segment_offsets_wrap()) - segment_offsets = [None] * (deref(uniq_segment_vector_64).size()) + uniq_segment_vector_64 = move( + ptr_renum_tuple_64_64.get().get_segment_offsets_wrap()) + segment_offsets = [None] * ( + deref(uniq_segment_vector_64).size()) for i in range(len(segment_offsets)): - segment_offsets[i] = deref(uniq_segment_vector_64)[i] + segment_offsets[i] = deref(uniq_segment_vector_64)[i] return renumbered_map, segment_offsets, shuffled_df diff --git a/python/cugraph/cugraph/structure/utils.pxd b/python/cugraph/cugraph/structure/utils.pxd index 687109215bd..2089b8ea0f5 100644 --- a/python/cugraph/cugraph/structure/utils.pxd +++ b/python/cugraph/cugraph/structure/utils.pxd @@ -22,10 +22,10 @@ from libcpp.memory cimport unique_ptr cdef extern from "cugraph/legacy/functions.hpp" namespace "cugraph": - cdef unique_ptr[GraphCSR[VT,ET,WT]] coo_to_csr[VT,ET,WT]( - const GraphCOOView[VT,ET,WT] &graph) except + + cdef unique_ptr[GraphCSR[VT, ET, WT]] coo_to_csr[VT, ET, WT]( + const GraphCOOView[VT, ET, WT] &graph) except + cdef void comms_bcast[value_t]( - const handle_t &handle, - value_t *dst, - size_t size) except + + const handle_t &handle, + value_t *dst, + size_t size) except + diff --git a/python/cugraph/cugraph/structure/utils_wrapper.pyx b/python/cugraph/cugraph/structure/utils_wrapper.pyx index d8b14669789..ddf7fb2a485 100644 --- a/python/cugraph/cugraph/structure/utils_wrapper.pyx +++ b/python/cugraph/cugraph/structure/utils_wrapper.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021, NVIDIA CORPORATION. +# Copyright (c) 2020-2022, 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 @@ -43,9 +43,10 @@ def create_csr_float(source_col, dest_col, weights): if weights is not None: c_weights = weights.__cuda_array_interface__['data'][0] - cdef GraphCOOView[int,int,float] in_graph - in_graph = GraphCOOView[int,int,float](c_src, c_dst, c_weights, num_verts, num_edges) - return csr_to_series(move(c_utils.coo_to_csr[int,int,float](in_graph))) + cdef GraphCOOView[int, int, float] in_graph + in_graph = GraphCOOView[int, int, float]( + c_src, c_dst, c_weights, num_verts, num_edges) + return csr_to_series(move(c_utils.coo_to_csr[int, int, float](in_graph))) def create_csr_double(source_col, dest_col, weights): @@ -59,14 +60,16 @@ def create_csr_double(source_col, dest_col, weights): if weights is not None: c_weights = weights.__cuda_array_interface__['data'][0] - cdef GraphCOOView[int,int,double] in_graph - in_graph = GraphCOOView[int,int,double](c_src, c_dst, c_weights, num_verts, num_edges) - return csr_to_series(move(c_utils.coo_to_csr[int,int,double](in_graph))) + cdef GraphCOOView[int, int, double] in_graph + in_graph = GraphCOOView[int, int, double]( + c_src, c_dst, c_weights, num_verts, num_edges) + return csr_to_series(move(c_utils.coo_to_csr[int, int, double](in_graph))) def coo2csr(source_col, dest_col, weights=None): if len(source_col) != len(dest_col): - raise Exception("source_col and dest_col should have the same number of elements") + raise Exception( + "source_col and dest_col should have the same number of elements") if source_col.dtype != dest_col.dtype: raise Exception("source_col and dest_col should be the same type") @@ -75,7 +78,11 @@ def coo2csr(source_col, dest_col, weights=None): raise Exception("source_col and dest_col must be type np.int32") if len(source_col) == 0: - return cudf.Series(np.zeros(1, dtype=np.int32)), cudf.Series(np.zeros(1, dtype=np.int32)), weights + return ( + cudf.Series(np.zeros(1, dtype=np.int32)), + cudf.Series(np.zeros(1, dtype=np.int32)), + weights, + ) if weight_type(weights) == np.float64: return create_csr_double(source_col, dest_col, weights) diff --git a/python/cugraph/cugraph/tree/minimum_spanning_tree.pxd b/python/cugraph/cugraph/tree/minimum_spanning_tree.pxd index 32c76ede554..5cf89f89bd0 100644 --- a/python/cugraph/cugraph/tree/minimum_spanning_tree.pxd +++ b/python/cugraph/cugraph/tree/minimum_spanning_tree.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, 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 @@ -21,5 +21,6 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef unique_ptr[GraphCOO[VT,ET,WT]] minimum_spanning_tree[VT,ET,WT](const handle_t &handle, - const GraphCSRView[VT,ET,WT] &graph) except + + cdef unique_ptr[GraphCOO[VT, ET, WT]] minimum_spanning_tree[VT, ET, WT]( + const handle_t &handle, + const GraphCSRView[VT, ET, WT] &graph) except + diff --git a/python/cugraph/cugraph/tree/minimum_spanning_tree_wrapper.pyx b/python/cugraph/cugraph/tree/minimum_spanning_tree_wrapper.pyx index 7e51a07a5c2..d34aebcc8c5 100644 --- a/python/cugraph/cugraph/tree/minimum_spanning_tree_wrapper.pyx +++ b/python/cugraph/cugraph/tree/minimum_spanning_tree_wrapper.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021, NVIDIA CORPORATION. +# Copyright (c) 2020-2022, 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 @@ -28,62 +28,70 @@ import cudf import numpy as np import cupy as cp + def mst_float(num_verts, num_edges, offsets, indices, weights): cdef unique_ptr[handle_t] handle_ptr handle_ptr.reset(new handle_t()) - handle_ = handle_ptr.get(); + handle_ = handle_ptr.get() cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] graph_float - graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, c_weights, num_verts, num_edges) - return coo_to_df(move(c_mst[int,int,float](handle_[0], graph_float))) + cdef GraphCSRView[int, int, float] graph_float + graph_float = GraphCSRView[int, int, float]( + c_offsets, c_indices, c_weights, num_verts, num_edges) + return coo_to_df(move(c_mst[int, int, float](handle_[0], graph_float))) def mst_double(num_verts, num_edges, offsets, indices, weights): cdef unique_ptr[handle_t] handle_ptr handle_ptr.reset(new handle_t()) - handle_ = handle_ptr.get(); + handle_ = handle_ptr.get() cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,double] graph_double - graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, c_weights, num_verts, num_edges) - return coo_to_df(move(c_mst[int,int,double](handle_[0], graph_double))) + cdef GraphCSRView[int, int, double] graph_double + graph_double = GraphCSRView[int, int, double]( + c_offsets, c_indices, c_weights, num_verts, num_edges) + return coo_to_df(move(c_mst[int, int, double](handle_[0], graph_double))) def minimum_spanning_tree(input_graph): if not input_graph.adjlist: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) if input_graph.adjlist.weights is not None: - [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.weights], [np.float32, np.float64]) else: weights = cudf.Series(cp.full(num_edges, 1.0, dtype=np.float32)) if graph_primtypes_wrapper.weight_type(input_graph) == np.float32: - df = mst_float(num_verts, num_edges, offsets, indices, weights) - return df + df = mst_float(num_verts, num_edges, offsets, indices, weights) + return df else: return mst_double(num_verts, num_edges, offsets, indices, weights) + def maximum_spanning_tree(input_graph): if not input_graph.adjlist: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) if input_graph.adjlist.weights is not None: - [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.weights], [np.float32, np.float64]) else: weights = cudf.Series(cp.full(num_edges, 1.0, dtype=np.float32)) if graph_primtypes_wrapper.weight_type(input_graph) == np.float32: - df = mst_float(num_verts, num_edges, offsets, indices, weights) - return df + df = mst_float(num_verts, num_edges, offsets, indices, weights) + return df else: return mst_double(num_verts, num_edges, offsets, indices, weights) diff --git a/python/cugraph/cugraph/utilities/path_retrieval.pxd b/python/cugraph/cugraph/utilities/path_retrieval.pxd index dcbbef5127d..2396f461518 100644 --- a/python/cugraph/cugraph/utilities/path_retrieval.pxd +++ b/python/cugraph/cugraph/utilities/path_retrieval.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2021, NVIDIA CORPORATION. +# Copyright (c) 2021-2022, 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 @@ -20,10 +20,11 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/utilities/path_retrieval.hpp" namespace "cugraph": - cdef void get_traversed_cost[vertex_t, weight_t](const handle_t &handle, - const vertex_t *vertices, - const vertex_t *preds, - const weight_t *info_weights, - weight_t *out, - vertex_t stop_vertex, - vertex_t num_vertices) except + + cdef void get_traversed_cost[vertex_t, weight_t]( + const handle_t &handle, + const vertex_t *vertices, + const vertex_t *preds, + const weight_t *info_weights, + weight_t *out, + vertex_t stop_vertex, + vertex_t num_vertices) except + diff --git a/python/cugraph/cugraph/utilities/path_retrieval_wrapper.pyx b/python/cugraph/cugraph/utilities/path_retrieval_wrapper.pyx index 98d11ad07df..062a63e1d0a 100644 --- a/python/cugraph/cugraph/utilities/path_retrieval_wrapper.pyx +++ b/python/cugraph/cugraph/utilities/path_retrieval_wrapper.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2021, NVIDIA CORPORATION. +# Copyright (c) 2021-2022, 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 @@ -38,7 +38,7 @@ def get_traversed_cost(input_df, stop_vertex): cdef unique_ptr[handle_t] handle_ptr handle_ptr.reset(new handle_t()) - handle_ = handle_ptr.get(); + handle_ = handle_ptr.get() cdef uintptr_t vertices = NULL cdef uintptr_t preds = NULL @@ -51,7 +51,8 @@ def get_traversed_cost(input_df, stop_vertex): out = df['info'].__cuda_array_interface__['data'][0] if weight_t == np.float32: - c_get_traversed_cost(handle_[0], + c_get_traversed_cost( + handle_[0], vertices, preds, info_weights, @@ -59,7 +60,8 @@ def get_traversed_cost(input_df, stop_vertex): stop_vertex, num_verts) elif weight_t == np.float64: - c_get_traversed_cost(handle_[0], + c_get_traversed_cost( + handle_[0], vertices, preds, info_weights, diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/algorithms.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/algorithms.pxd index be377257d46..3de813d62f6 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/algorithms.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/algorithms.pxd @@ -135,7 +135,7 @@ cdef extern from "cugraph_c/algorithms.h": cugraph_random_walk_result_get_path_sizes( cugraph_random_walk_result_t* result ) - + cdef size_t \ cugraph_random_walk_result_get_max_path_length( cugraph_random_walk_result_t* result @@ -160,7 +160,6 @@ cdef extern from "cugraph_c/algorithms.h": cugraph_error_t** error ) - ########################################################################### # sampling ctypedef struct cugraph_sample_result_t: @@ -222,7 +221,7 @@ cdef extern from "cugraph_c/algorithms.h": cugraph_random_walk_result_t** result, cugraph_error_t** error ) - + # biased random walks cdef cugraph_error_code_t \ cugraph_based_random_walks( diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/centrality_algorithms.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/centrality_algorithms.pxd index 8e8b1c8e923..9981d04e0f8 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/centrality_algorithms.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/centrality_algorithms.pxd @@ -56,8 +56,8 @@ cdef extern from "cugraph_c/centrality_algorithms.h": cugraph_pagerank( const cugraph_resource_handle_t* handle, cugraph_graph_t* graph, - const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_vertices, - const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_sums, + const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_vertices, # noqa: E501 + const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_sums, # noqa: E501 const cugraph_type_erased_device_array_view_t* initial_guess_vertices, const cugraph_type_erased_device_array_view_t* initial_guess_values, double alpha, @@ -72,8 +72,8 @@ cdef extern from "cugraph_c/centrality_algorithms.h": cugraph_personalized_pagerank( const cugraph_resource_handle_t* handle, cugraph_graph_t* graph, - const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_vertices, - const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_sums, + const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_vertices, # noqa: E501 + const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_sums, # noqa: E501 const cugraph_type_erased_device_array_view_t* initial_guess_vertices, const cugraph_type_erased_device_array_view_t* initial_guess_values, const cugraph_type_erased_device_array_view_t* personalization_vertices, @@ -98,7 +98,7 @@ cdef extern from "cugraph_c/centrality_algorithms.h": cugraph_centrality_result_t** result, cugraph_error_t** error ) - + ########################################################################### # katz centrality cdef cugraph_error_code_t \ @@ -124,17 +124,17 @@ cdef extern from "cugraph_c/centrality_algorithms.h": cugraph_hits_result_get_vertices( cugraph_hits_result_t* result ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_hits_result_get_hubs( cugraph_hits_result_t* result ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_hits_result_get_authorities( cugraph_hits_result_t* result ) - + cdef void \ cugraph_hits_result_free( cugraph_hits_result_t* result diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/community_algorithms.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/community_algorithms.pxd index 90ae44cbead..4dbfba55fa6 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/community_algorithms.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/community_algorithms.pxd @@ -45,17 +45,17 @@ cdef extern from "cugraph_c/community_algorithms.h": cugraph_triangle_count_result_get_vertices( cugraph_triangle_count_result_t* result ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_triangle_count_result_get_counts( cugraph_triangle_count_result_t* result ) - + cdef void \ cugraph_triangle_count_result_free( cugraph_triangle_count_result_t* result ) - + cdef cugraph_error_code_t \ cugraph_triangle_count( const cugraph_resource_handle_t* handle, @@ -80,10 +80,10 @@ cdef extern from "cugraph_c/community_algorithms.h": cugraph_heirarchical_clustering_result_get_clusters( cugraph_heirarchical_clustering_result_t* result ) - + cdef double cugraph_heirarchical_clustering_result_get_modularity( cugraph_heirarchical_clustering_result_t* result - ) + ) cdef void \ cugraph_heirarchical_clustering_result_free( @@ -100,7 +100,7 @@ cdef extern from "cugraph_c/community_algorithms.h": cugraph_heirarchical_clustering_result_t** result, cugraph_error_t** error ) - + # extract_ego cdef cugraph_error_code_t \ cugraph_extract_ego( diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/core_algorithms.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/core_algorithms.pxd index 4d3509e8b7f..8d5d7c346cd 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/core_algorithms.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/core_algorithms.pxd @@ -36,7 +36,7 @@ cdef extern from "cugraph_c/core_algorithms.h": # core number ctypedef struct cugraph_core_result_t: pass - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_core_result_get_vertices( cugraph_core_result_t* result @@ -46,7 +46,7 @@ cdef extern from "cugraph_c/core_algorithms.h": cugraph_core_result_get_core_numbers( cugraph_core_result_t* result ) - + cdef void \ cugraph_core_result_free( cugraph_core_result_t* result @@ -66,7 +66,7 @@ cdef extern from "cugraph_c/core_algorithms.h": cugraph_core_result_t** result, cugraph_error_t** error ) - + ########################################################################### # k-core ctypedef struct cugraph_k_core_result_t: @@ -76,22 +76,22 @@ cdef extern from "cugraph_c/core_algorithms.h": cugraph_k_core_result_get_src_vertices( cugraph_k_core_result_t* result ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_k_core_result_get_dst_vertices( cugraph_k_core_result_t* result ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_k_core_result_get_weights( cugraph_k_core_result_t* result ) - + cdef void \ cugraph_k_core_result_free( cugraph_k_core_result_t* result ) - + cdef cugraph_error_code_t \ cugraph_core_result_create( const cugraph_resource_handle_t* handle, @@ -100,7 +100,7 @@ cdef extern from "cugraph_c/core_algorithms.h": cugraph_core_result_t** core_result, cugraph_error_t** error ) - + cdef cugraph_error_code_t \ cugraph_k_core( const cugraph_resource_handle_t* handle, diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/error.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/error.pxd index 4b20daa1135..7dee4a5eb74 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/error.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/error.pxd @@ -26,7 +26,7 @@ cdef extern from "cugraph_c/error.h": CUGRAPH_UNSUPPORTED_TYPE_COMBINATION ctypedef struct cugraph_error_t: - pass + pass const char* \ cugraph_error_message( diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/graph.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/graph.pxd index 590c5679264..39ec4e766da 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/graph.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/graph.pxd @@ -38,19 +38,20 @@ cdef extern from "cugraph_c/graph.h": bool_t is_multigraph cdef cugraph_error_code_t \ - cugraph_sg_graph_create( - const cugraph_resource_handle_t* handle, - const cugraph_graph_properties_t* properties, - const cugraph_type_erased_device_array_view_t* src, - const cugraph_type_erased_device_array_view_t* dst, - const cugraph_type_erased_device_array_view_t* weights, - const cugraph_type_erased_device_array_view_t* edge_ids, - const cugraph_type_erased_device_array_view_t* edge_types, - bool_t store_transposed, - bool_t renumber, - bool_t check, - cugraph_graph_t** graph, - cugraph_error_t** error) + cugraph_sg_graph_create( + const cugraph_resource_handle_t* handle, + const cugraph_graph_properties_t* properties, + const cugraph_type_erased_device_array_view_t* src, + const cugraph_type_erased_device_array_view_t* dst, + const cugraph_type_erased_device_array_view_t* weights, + const cugraph_type_erased_device_array_view_t* edge_ids, + const cugraph_type_erased_device_array_view_t* edge_types, + bool_t store_transposed, + bool_t renumber, + bool_t check, + cugraph_graph_t** graph, + cugraph_error_t** error + ) # This may get renamed to cugraph_graph_free() cdef void \ @@ -79,7 +80,7 @@ cdef extern from "cugraph_c/graph.h": cugraph_mg_graph_free( cugraph_graph_t* graph ) - + cdef cugraph_error_code_t \ cugraph_sg_graph_create_from_csr( const cugraph_resource_handle_t* handle, @@ -95,12 +96,12 @@ cdef extern from "cugraph_c/graph.h": cugraph_graph_t** graph, cugraph_error_t** error ) - + cdef void \ cugraph_sg_graph_free( cugraph_graph_t* graph ) - + cdef cugraph_error_code_t \ cugraph_mg_graph_create( const cugraph_resource_handle_t* handle, @@ -116,7 +117,7 @@ cdef extern from "cugraph_c/graph.h": cugraph_graph_t** graph, cugraph_error_t** error ) - + cdef void \ cugraph_mg_graph_free( cugraph_graph_t* graph diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_functions.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_functions.pxd index f18e9848182..eab1e5cf09d 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_functions.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_functions.pxd @@ -36,13 +36,13 @@ from pylibcugraph._cugraph_c.array cimport ( ) cdef extern from "cugraph_c/graph_functions.h": - #""" - #ctypedef struct cugraph_similarity_result_t: - # pass - #""" + # """ + # ctypedef struct cugraph_similarity_result_t: + # pass + # """ ctypedef struct cugraph_vertex_pairs_t: pass - + from pylibcugraph._cugraph_c.error cimport ( cugraph_error_code_t, @@ -61,22 +61,22 @@ cdef extern from "cugraph_c/graph_functions.h": # vertex_pairs ctypedef struct cugraph_vertex_pairs_t: pass - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_vertex_pairs_get_first( cugraph_vertex_pairs_t* vertex_pairs ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_vertex_pairs_get_second( cugraph_vertex_pairs_t* vertex_pairs ) - + cdef void \ cugraph_vertex_pairs_free( cugraph_vertex_pairs_t* vertex_pairs ) - + cdef cugraph_error_code_t \ cugraph_create_vertex_pairs( const cugraph_resource_handle_t* handle, @@ -86,21 +86,21 @@ cdef extern from "cugraph_c/graph_functions.h": cugraph_vertex_pairs_t** vertex_pairs, cugraph_error_t** error ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_vertex_pairs_get_first( cugraph_vertex_pairs_t* vertex_pairs ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_vertex_pairs_get_second( cugraph_vertex_pairs_t* vertex_pairs ) - + cdef void cugraph_vertex_pairs_free( cugraph_vertex_pairs_t* vertex_pairs - ) - + ) + cdef cugraph_error_code_t cugraph_two_hop_neighbors( const cugraph_resource_handle_t* handle, const cugraph_graph_t* graph, @@ -117,7 +117,7 @@ cdef extern from "cugraph_c/graph_functions.h": cugraph_vertex_pairs_t** result, cugraph_error_t** error ) - + ########################################################################### # induced_subgraph ctypedef struct cugraph_induced_subgraph_result_t: @@ -127,27 +127,27 @@ cdef extern from "cugraph_c/graph_functions.h": cugraph_induced_subgraph_get_sources( cugraph_induced_subgraph_result_t* induced_subgraph ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_induced_subgraph_get_destinations( cugraph_induced_subgraph_result_t* induced_subgraph ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_induced_subgraph_get_edge_weights( cugraph_induced_subgraph_result_t* induced_subgraph ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_induced_subgraph_get_subgraph_offsets( cugraph_induced_subgraph_result_t* induced_subgraph ) - + cdef void \ cugraph_induced_subgraph_result_free( cugraph_induced_subgraph_result_t* induced_subgraph ) - + cdef cugraph_error_code_t \ cugraph_extract_induced_subgraph( const cugraph_resource_handle_t* handle, diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/labeling_algorithms.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/labeling_algorithms.pxd index 7c911235a54..e1072d4c24c 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/labeling_algorithms.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/labeling_algorithms.pxd @@ -41,17 +41,17 @@ cdef extern from "cugraph_c/labeling_algorithms.h": cugraph_labeling_result_get_vertices( cugraph_labeling_result_t* result ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_labeling_result_get_labels( cugraph_labeling_result_t* result ) - + cdef void \ cugraph_labeling_result_free( cugraph_labeling_result_t* result ) - + cdef cugraph_error_code_t \ cugraph_weakly_connected_components( const cugraph_resource_handle_t* handle, @@ -60,4 +60,3 @@ cdef extern from "cugraph_c/labeling_algorithms.h": cugraph_labeling_result_t** result, cugraph_error_t** error ) - \ No newline at end of file diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/resource_handle.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/resource_handle.pxd index 633107a1acb..df688a08760 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/resource_handle.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/resource_handle.pxd @@ -36,17 +36,14 @@ cdef extern from "cugraph_c/resource_handle.h": pass # FIXME: the void* raft_handle arg will change in a future release - cdef cugraph_resource_handle_t* \ - cugraph_create_resource_handle( - void* raft_handle - ) - - cdef int \ - cugraph_resource_handle_get_rank( - const cugraph_resource_handle_t* handle - ) - - cdef void \ - cugraph_free_resource_handle( - cugraph_resource_handle_t* p_handle - ) + cdef cugraph_resource_handle_t* cugraph_create_resource_handle( + void* raft_handle + ) + + cdef int cugraph_resource_handle_get_rank( + const cugraph_resource_handle_t* handle + ) + + cdef void cugraph_free_resource_handle( + cugraph_resource_handle_t* p_handle + ) diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/similarity_algorithms.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/similarity_algorithms.pxd index 0d98bb8e14a..6f20096a428 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/similarity_algorithms.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/similarity_algorithms.pxd @@ -36,21 +36,21 @@ from pylibcugraph._cugraph_c.graph_functions cimport ( cdef extern from "cugraph_c/similarity_algorithms.h": ########################################################################### - #""" + # """ ctypedef struct cugraph_similarity_result_t: pass - #""" + # """ cdef cugraph_type_erased_device_array_view_t* \ cugraph_similarity_result_get_similarity( cugraph_similarity_result_t* result ) - + cdef void \ cugraph_similarity_result_free( cugraph_similarity_result_t* result ) - + ########################################################################### # jaccard coefficients cdef cugraph_error_code_t \ diff --git a/python/pylibcugraph/pylibcugraph/bfs.pyx b/python/pylibcugraph/pylibcugraph/bfs.pyx index 6886e6b059a..0eb3da99918 100644 --- a/python/pylibcugraph/pylibcugraph/bfs.pyx +++ b/python/pylibcugraph/pylibcugraph/bfs.pyx @@ -56,8 +56,9 @@ from pylibcugraph.graphs cimport ( _GPUGraph, ) -def bfs(ResourceHandle handle, _GPUGraph graph, - sources, bool_t direction_optimizing, int32_t depth_limit, + +def bfs(ResourceHandle handle, _GPUGraph graph, + sources, bool_t direction_optimizing, int32_t depth_limit, bool_t compute_predecessors, bool_t do_expensive_check): """ Performs a Breadth-first search starting from the provided sources. @@ -108,10 +109,10 @@ def bfs(ResourceHandle handle, _GPUGraph graph, weights = G.edgelist.edgelist_df['weights'] sg = SGGraph( - resource_handle = handle, - graph_properties = GraphProperties(is_multigraph=G.is_multigraph()), - src_array = srcs, - dst_array = dsts, + resource_handle = handle, + graph_properties = GraphProperties(is_multigraph=G.is_multigraph()), + src_array = srcs, + dst_array = dsts, weight_array = weights, store_transposed=False, renumber=False, @@ -119,7 +120,7 @@ def bfs(ResourceHandle handle, _GPUGraph graph, ) res = pylibcugraph_bfs( - handle, + handle, sg, cudf.Series([0], dtype='int32'), False, @@ -129,7 +130,7 @@ def bfs(ResourceHandle handle, _GPUGraph graph, ) distances, predecessors, vertices = res - + final_results = cudf.DataFrame({ 'distance': cudf.Series(distances), 'vertex': cudf.Series(vertices), @@ -163,7 +164,7 @@ def bfs(ResourceHandle handle, _GPUGraph graph, cai_sources_ptr, len(sources), get_c_type_from_numpy_type(sources.dtype)) - + cdef cugraph_paths_result_t* result_ptr error_code = cugraph_bfs( @@ -185,7 +186,7 @@ def bfs(ResourceHandle handle, _GPUGraph graph, cdef cugraph_type_erased_device_array_view_t* predecessors_ptr = \ cugraph_paths_result_get_predecessors(result_ptr) - + cdef cugraph_type_erased_device_array_view_t* vertices_ptr = \ cugraph_paths_result_get_vertices(result_ptr) @@ -193,7 +194,7 @@ def bfs(ResourceHandle handle, _GPUGraph graph, cupy_distances = copy_to_cupy_array(c_resource_handle_ptr, distances_ptr) cupy_predecessors = copy_to_cupy_array(c_resource_handle_ptr, predecessors_ptr) cupy_vertices = copy_to_cupy_array(c_resource_handle_ptr, vertices_ptr) - + # deallocate the no-longer needed result struct cugraph_paths_result_free(result_ptr) diff --git a/python/pylibcugraph/pylibcugraph/components/_connectivity.pxd b/python/pylibcugraph/pylibcugraph/components/_connectivity.pxd index b1915ee108b..ff9fb17e12c 100644 --- a/python/pylibcugraph/pylibcugraph/components/_connectivity.pxd +++ b/python/pylibcugraph/pylibcugraph/components/_connectivity.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, 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 @@ -27,8 +27,8 @@ cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": CUGRAPH_STRONG "cugraph::cugraph_cc_t::CUGRAPH_STRONG" NUM_CONNECTIVITY_TYPES "cugraph::cugraph_cc_t::NUM_CONNECTIVITY_TYPES" - cdef void connected_components[VT,ET,WT]( - const GraphCSRView[VT,ET,WT] &graph, + cdef void connected_components[VT, ET, WT]( + const GraphCSRView[VT, ET, WT] &graph, cugraph_cc_t connect_type, VT *labels) except + @@ -37,4 +37,3 @@ cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": const handle_t &handle, const graph_container_t &g, vertex_t *identifiers) except + - diff --git a/python/pylibcugraph/pylibcugraph/components/_connectivity.pyx b/python/pylibcugraph/pylibcugraph/components/_connectivity.pyx index 02e7549d1c5..c3d63a1b4d9 100644 --- a/python/pylibcugraph/pylibcugraph/components/_connectivity.pyx +++ b/python/pylibcugraph/pylibcugraph/components/_connectivity.pyx @@ -39,7 +39,9 @@ def _ensure_arg_types(**kwargs): raise TypeError(f"{arg_name} array must have a dtype of int32") -def strongly_connected_components(offsets, indices, weights, num_verts, num_edges, labels): +def strongly_connected_components( + offsets, indices, weights, num_verts, num_edges, labels +): """ Generate the Strongly Connected Components and attach a component label to each vertex. @@ -122,10 +124,10 @@ def strongly_connected_components(offsets, indices, weights, num_verts, num_edge cdef uintptr_t c_edge_weights = NULL cdef uintptr_t c_labels = labels.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] g + cdef GraphCSRView[int, int, float] g - g = GraphCSRView[int,int,float](c_offsets, c_indices, NULL, num_verts, num_edges) + g = GraphCSRView[int, int, float]( + c_offsets, c_indices, NULL, num_verts, num_edges) cdef cugraph_cc_t connect_type=CUGRAPH_STRONG connected_components(g, connect_type, c_labels) - diff --git a/python/pylibcugraph/pylibcugraph/core_number.pyx b/python/pylibcugraph/pylibcugraph/core_number.pyx index 7d0c42f7dd0..ccc49a35850 100644 --- a/python/pylibcugraph/pylibcugraph/core_number.pyx +++ b/python/pylibcugraph/pylibcugraph/core_number.pyx @@ -31,7 +31,7 @@ from pylibcugraph._cugraph_c.array cimport ( from pylibcugraph._cugraph_c.graph cimport ( cugraph_graph_t, ) -from pylibcugraph._cugraph_c.core_algorithms cimport ( +from pylibcugraph._cugraph_c.core_algorithms cimport ( cugraph_core_result_t, cugraph_core_number, cugraph_k_core_degree_type_t, @@ -51,6 +51,7 @@ from pylibcugraph.utils cimport ( get_c_type_from_numpy_type, ) + def core_number(ResourceHandle resource_handle, _GPUGraph graph, degree_type, @@ -63,17 +64,17 @@ def core_number(ResourceHandle resource_handle, resource_handle: ResourceHandle Handle to the underlying device and host resource needed for referencing data and running algorithms. - + graph : SGGraph or MGGraph The input graph, for either Single or Multi-GPU operations. - + degree_type: str This option determines if the core number computation should be based on input, output, or both directed edges, with valid values being "incoming", "outgoing", and "bidirectional" respectively. This option is currently ignored in this release, and setting it will result in a warning. - + do_expensive_check: bool If True, performs more extensive tests on the inputs to ensure validity, at the expense of increased run time. diff --git a/python/pylibcugraph/pylibcugraph/egonet.pyx b/python/pylibcugraph/pylibcugraph/egonet.pyx index 639e4c386a7..862e22f103c 100644 --- a/python/pylibcugraph/pylibcugraph/egonet.pyx +++ b/python/pylibcugraph/pylibcugraph/egonet.pyx @@ -73,7 +73,7 @@ def ego_graph(ResourceHandle resource_handle, graph : SGGraph or MGGraph The input graph. - + source_vertices : cudf.Series The centered nodes from which the induced subgraph will be extracted @@ -124,10 +124,8 @@ def ego_graph(ResourceHandle resource_handle, cdef cugraph_error_code_t error_code cdef cugraph_error_t* error_ptr - cdef cugraph_type_erased_device_array_view_t* \ - source_vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - source_vertices) + cdef cugraph_type_erased_device_array_view_t* source_vertices_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(source_vertices) error_code = cugraph_extract_ego(c_resource_handle_ptr, c_graph_ptr, @@ -164,4 +162,4 @@ def ego_graph(ResourceHandle resource_handle, cugraph_induced_subgraph_result_free(result_ptr) return (cupy_sources, cupy_destinations, - cupy_edge_weights, cupy_subgraph_offsets) + cupy_edge_weights, cupy_subgraph_offsets) diff --git a/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx b/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx index 88612c242e2..20014e80546 100644 --- a/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx +++ b/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx @@ -127,7 +127,7 @@ def eigenvector_centrality(ResourceHandle resource_handle, cugraph_centrality_result_get_vertices(result_ptr) cdef cugraph_type_erased_device_array_view_t* values_ptr = \ cugraph_centrality_result_get_values(result_ptr) - + cupy_vertices = copy_to_cupy_array(c_resource_handle_ptr, vertices_ptr) cupy_values = copy_to_cupy_array(c_resource_handle_ptr, values_ptr) diff --git a/python/pylibcugraph/pylibcugraph/graph_properties.pxd b/python/pylibcugraph/pylibcugraph/graph_properties.pxd index 491c343480d..628da39846a 100644 --- a/python/pylibcugraph/pylibcugraph/graph_properties.pxd +++ b/python/pylibcugraph/pylibcugraph/graph_properties.pxd @@ -14,9 +14,7 @@ # Have cython use python 3 syntax # cython: language_level = 3 -from pylibcugraph._cugraph_c.graph cimport ( - cugraph_graph_properties_t, -) +from pylibcugraph._cugraph_c.graph cimport cugraph_graph_properties_t cdef class GraphProperties: diff --git a/python/pylibcugraph/pylibcugraph/graph_properties.pyx b/python/pylibcugraph/pylibcugraph/graph_properties.pyx index ad1431900f6..c0f3565045e 100644 --- a/python/pylibcugraph/pylibcugraph/graph_properties.pyx +++ b/python/pylibcugraph/pylibcugraph/graph_properties.pyx @@ -26,7 +26,7 @@ cdef class GraphProperties: def __getnewargs_ex__(self): is_symmetric = self.c_graph_properties.is_symmetric is_multigraph = self.c_graph_properties.is_multigraph - return ((),{"is_symmetric":is_symmetric, "is_multigraph":is_multigraph}) + return ((), {"is_symmetric": is_symmetric, "is_multigraph": is_multigraph}) def __getstate__(self): return () diff --git a/python/pylibcugraph/pylibcugraph/graphs.pxd b/python/pylibcugraph/pylibcugraph/graphs.pxd index e468738f529..62a3ef999a6 100644 --- a/python/pylibcugraph/pylibcugraph/graphs.pxd +++ b/python/pylibcugraph/pylibcugraph/graphs.pxd @@ -28,5 +28,4 @@ cdef class SGGraph(_GPUGraph): pass cdef class MGGraph(_GPUGraph): - pass - + pass diff --git a/python/pylibcugraph/pylibcugraph/graphs.pyx b/python/pylibcugraph/pylibcugraph/graphs.pyx index 7640f5cdee5..70a0c3954a0 100644 --- a/python/pylibcugraph/pylibcugraph/graphs.pyx +++ b/python/pylibcugraph/pylibcugraph/graphs.pyx @@ -74,7 +74,7 @@ cdef class SGGraph(_GPUGraph): Object defining intended properties for the graph. src_or_offset_array : device array type - Device array containing either the vertex identifiers of the source of + Device array containing either the vertex identifiers of the source of each directed edge if represented in COO format or the offset if CSR format. In the case of a COO, the order of the array corresponds to the ordering of the dst_or_index_array, where the ith item in @@ -106,22 +106,22 @@ cdef class SGGraph(_GPUGraph): do_expensive_check : bool If True, performs more extensive tests on the inputs to ensure validitity, at the expense of increased run time. - + edge_id_array : device array type Device array containing the edge ids of each directed edge. Must match the ordering of the src/dst arrays. Optional (may be null). If provided, edge_type_array must also be provided. - + edge_type_array : device array type Device array containing the edge types of each directed edge. Must match the ordering of the src/dst/edge_id arrays. Optional (may be null). If provided, edge_id_array must be provided. - + input_array_format: str, optional (default='COO') Input representation used to construct a graph COO: arrays represent src_array and dst_array CSR: arrays represent offset_array and index_array - + Examples --------- >>> import pylibcugraph, cupy, numpy @@ -168,7 +168,8 @@ cdef class SGGraph(_GPUGraph): if edge_type_array is not None: assert_CAI_type(edge_type_array, "edge_type_array") - # FIXME: assert that src_or_offset_array and dst_or_index_array have the same type + # FIXME: assert that src_or_offset_array and dst_or_index_array have + # the same type cdef cugraph_error_t* error_ptr cdef cugraph_error_code_t error_code @@ -210,7 +211,7 @@ cdef class SGGraph(_GPUGraph): &error_ptr) assert_success(error_code, error_ptr, - "cugraph_sg_graph_create()") + "cugraph_sg_graph_create()") elif input_array_format == "CSR": error_code = cugraph_sg_graph_create_from_csr( @@ -228,11 +229,12 @@ cdef class SGGraph(_GPUGraph): &error_ptr) assert_success(error_code, error_ptr, - "cugraph_sg_graph_create_from_csr()") - + "cugraph_sg_graph_create_from_csr()") + else: - raise ValueError("invalid 'input_array_format'. Only " - "'COO' and 'CSR' format are supported." + raise ValueError( + "invalid 'input_array_format'. Only 'COO' and 'CSR' format " + "are supported." ) cugraph_type_erased_device_array_view_free(srcs_or_offsets_view_ptr) @@ -283,10 +285,10 @@ cdef class MGGraph(_GPUGraph): store_transposed : bool Set to True if the graph should be transposed. This is required for some algorithms, such as pagerank. - + num_edges : int Number of edges - + do_expensive_check : bool If True, performs more extensive tests on the inputs to ensure validitity, at the expense of increased run time. @@ -295,7 +297,7 @@ cdef class MGGraph(_GPUGraph): Device array containing the edge ids of each directed edge. Must match the ordering of the src/dst arrays. Optional (may be null). If provided, edge_type_array must also be provided. - + edge_type_array : device array type Device array containing the edge types of each directed edge. Must match the ordering of the src/dst/edge_id arrays. Optional (may be @@ -331,7 +333,7 @@ cdef class MGGraph(_GPUGraph): if edge_id_array is not None: assert_CAI_type(edge_id_array, "edge_id_array") if edge_type_array is not None: - assert_CAI_type(edge_type_array, "edge_type_array") + assert_CAI_type(edge_type_array, "edge_type_array") # FIXME: assert that src_array and dst_array have the same type diff --git a/python/pylibcugraph/pylibcugraph/hits.pyx b/python/pylibcugraph/pylibcugraph/hits.pyx index 7c472f54866..0615a1cf77c 100644 --- a/python/pylibcugraph/pylibcugraph/hits.pyx +++ b/python/pylibcugraph/pylibcugraph/hits.pyx @@ -55,14 +55,16 @@ from pylibcugraph.utils cimport ( ) -def hits(ResourceHandle resource_handle, - _GPUGraph graph, - double tol, - size_t max_iter, - initial_hubs_guess_vertices, - initial_hubs_guess_values, - bool_t normalized, - bool_t do_expensive_check): +def hits( + ResourceHandle resource_handle, + _GPUGraph graph, + double tol, + size_t max_iter, + initial_hubs_guess_vertices, + initial_hubs_guess_values, + bool_t normalized, + bool_t do_expensive_check +): """ Compute HITS hubs and authorities values for each vertex @@ -78,7 +80,7 @@ def hits(ResourceHandle resource_handle, graph : SGGraph or MGGraph The input graph, for either Single or Multi-GPU operations. - + tol : float, optional (default=1.0e-5) Set the tolerance the approximation, this parameter should be a small magnitude value. This parameter is not currently supported. @@ -104,7 +106,7 @@ def hits(ResourceHandle resource_handle, A tuple of device arrays, where the third item in the tuple is a device array containing the vertex identifiers, the first and second items are device arrays containing respectively the hubs and authorities values for the corresponding - vertices + vertices Examples -------- @@ -115,30 +117,32 @@ def hits(ResourceHandle resource_handle, cdef uintptr_t cai_initial_hubs_guess_vertices_ptr = NULL cdef uintptr_t cai_initial_hubs_guess_values_ptr = NULL - cdef cugraph_type_erased_device_array_view_t* initial_hubs_guess_vertices_view_ptr = NULL - cdef cugraph_type_erased_device_array_view_t* initial_hubs_guess_values_view_ptr = NULL + cdef cugraph_type_erased_device_array_view_t* \ + initial_hubs_guess_vertices_view_ptr = NULL + cdef cugraph_type_erased_device_array_view_t* \ + initial_hubs_guess_values_view_ptr = NULL - # FIXME: Add check ensuring that both initial_hubs_guess_vertices + # FIXME: Add check ensuring that both initial_hubs_guess_vertices # and initial_hubs_guess_values are passed when calling only pylibcugraph HITS. # This is already True for cugraph HITS - - if initial_hubs_guess_vertices is not None: + + if initial_hubs_guess_vertices is not None: assert_CAI_type(initial_hubs_guess_vertices, "initial_hubs_guess_vertices") - + cai_initial_hubs_guess_vertices_ptr = \ - initial_hubs_guess_vertices.__cuda_array_interface__["data"][0] + initial_hubs_guess_vertices.__cuda_array_interface__["data"][0] initial_hubs_guess_vertices_view_ptr = \ cugraph_type_erased_device_array_view_create( cai_initial_hubs_guess_vertices_ptr, len(initial_hubs_guess_vertices), get_c_type_from_numpy_type(initial_hubs_guess_vertices.dtype)) - + if initial_hubs_guess_values is not None: assert_CAI_type(initial_hubs_guess_values, "initial_hubs_guess_values") cai_initial_hubs_guess_values_ptr = \ - initial_hubs_guess_values.__cuda_array_interface__["data"][0] + initial_hubs_guess_values.__cuda_array_interface__["data"][0] initial_hubs_guess_values_view_ptr = \ cugraph_type_erased_device_array_view_create( @@ -179,13 +183,13 @@ def hits(ResourceHandle resource_handle, cupy_hubs = copy_to_cupy_array(c_resource_handle_ptr, hubs_ptr) cupy_authorities = copy_to_cupy_array(c_resource_handle_ptr, authorities_ptr) - + cugraph_hits_result_free(result_ptr) if initial_hubs_guess_vertices is not None: cugraph_type_erased_device_array_view_free( initial_hubs_guess_vertices_view_ptr) - + if initial_hubs_guess_values is not None: cugraph_type_erased_device_array_view_free( initial_hubs_guess_values_view_ptr) diff --git a/python/pylibcugraph/pylibcugraph/jaccard_coefficients.pyx b/python/pylibcugraph/pylibcugraph/jaccard_coefficients.pyx index 805ee821eab..ee0e2da4f28 100644 --- a/python/pylibcugraph/pylibcugraph/jaccard_coefficients.pyx +++ b/python/pylibcugraph/pylibcugraph/jaccard_coefficients.pyx @@ -57,15 +57,17 @@ from pylibcugraph.utils cimport ( ) -def EXPERIMENTAL__jaccard_coefficients(ResourceHandle resource_handle, - _GPUGraph graph, - first, - second, - bool_t use_weight, - bool_t do_expensive_check): +def EXPERIMENTAL__jaccard_coefficients( + ResourceHandle resource_handle, + _GPUGraph graph, + first, + second, + bool_t use_weight, + bool_t do_expensive_check +): """ Compute the Jaccard coefficients for the specified vertex_pairs. - + Note that Jaccard similarity must run on a symmetric graph. Parameters @@ -76,13 +78,13 @@ def EXPERIMENTAL__jaccard_coefficients(ResourceHandle resource_handle, graph : SGGraph or MGGraph The input graph, for either Single or Multi-GPU operations. - + first : Source of the vertex pair. - + second : Destination of the vertex pair. - + use_weight : bool, optional (default=False) Currently not supported @@ -112,16 +114,12 @@ def EXPERIMENTAL__jaccard_coefficients(ResourceHandle resource_handle, cdef cugraph_error_t* error_ptr # 'first' is a required parameter - cdef cugraph_type_erased_device_array_view_t* \ - first_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - first) + cdef cugraph_type_erased_device_array_view_t* first_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(first) # 'second' is a required parameter - cdef cugraph_type_erased_device_array_view_t* \ - second_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - second) + cdef cugraph_type_erased_device_array_view_t* second_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(second) error_code = cugraph_create_vertex_pairs(c_resource_handle_ptr, c_graph_ptr, diff --git a/python/pylibcugraph/pylibcugraph/k_core.pyx b/python/pylibcugraph/pylibcugraph/k_core.pyx index 50344469b11..010a9270b5b 100644 --- a/python/pylibcugraph/pylibcugraph/k_core.pyx +++ b/python/pylibcugraph/pylibcugraph/k_core.pyx @@ -31,7 +31,7 @@ from pylibcugraph._cugraph_c.array cimport ( from pylibcugraph._cugraph_c.graph cimport ( cugraph_graph_t, ) -from pylibcugraph._cugraph_c.core_algorithms cimport ( +from pylibcugraph._cugraph_c.core_algorithms cimport ( cugraph_core_result_t, cugraph_k_core_result_t, cugraph_core_result_create, @@ -55,6 +55,7 @@ from pylibcugraph.utils cimport ( create_cugraph_type_erased_device_array_view_from_py_obj, ) + def k_core(ResourceHandle resource_handle, _GPUGraph graph, size_t k, @@ -72,21 +73,21 @@ def k_core(ResourceHandle resource_handle, resource_handle: ResourceHandle Handle to the underlying device and host resource needed for referencing data and running algorithms. - + graph : SGGraph or MGGraph The input graph, for either Single or Multi-GPU operations. - + k : size_t (default=None) Order of the core. This value must not be negative. If set to None the main core is returned. - + degree_type: str This option determines if the core number computation should be based on input, output, or both directed edges, with valid values being "incoming", "outgoing", and "bidirectional" respectively. This option is currently ignored in this release, and setting it will result in a warning. - + core_result : device array type Precomputed core number of the nodes of the graph G If set to None, the core numbers of the nodes are calculated @@ -115,22 +116,17 @@ def k_core(ResourceHandle resource_handle, cdef cugraph_error_code_t error_code cdef cugraph_error_t* error_ptr - degree_type_map = { "incoming": cugraph_k_core_degree_type_t.K_CORE_DEGREE_TYPE_IN, "outgoing": cugraph_k_core_degree_type_t.K_CORE_DEGREE_TYPE_OUT, "bidirectional": cugraph_k_core_degree_type_t.K_CORE_DEGREE_TYPE_INOUT} - cdef cugraph_type_erased_device_array_view_t* \ - vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - core_result["vertex"]) - - cdef cugraph_type_erased_device_array_view_t* \ - core_numbers_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - core_result["values"]) - + cdef cugraph_type_erased_device_array_view_t* vertices_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(core_result["vertex"]) + + cdef cugraph_type_erased_device_array_view_t* core_numbers_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(core_result["values"]) + # Create a core_number result error_code = cugraph_core_result_create(c_resource_handle_ptr, vertices_view_ptr, @@ -139,7 +135,6 @@ def k_core(ResourceHandle resource_handle, &error_ptr) assert_success(error_code, error_ptr, "cugraph_core_result_create") - # compute k_core error_code = cugraph_k_core(c_resource_handle_ptr, c_graph_ptr, @@ -151,7 +146,6 @@ def k_core(ResourceHandle resource_handle, &error_ptr) assert_success(error_code, error_ptr, "cugraph_k_core_number") - cdef cugraph_type_erased_device_array_view_t* src_vertices_ptr = \ cugraph_k_core_result_get_src_vertices(k_core_result_ptr) cdef cugraph_type_erased_device_array_view_t* dst_vertices_ptr = \ diff --git a/python/pylibcugraph/pylibcugraph/katz_centrality.pyx b/python/pylibcugraph/pylibcugraph/katz_centrality.pyx index 0f08e690f92..8652f651d0a 100644 --- a/python/pylibcugraph/pylibcugraph/katz_centrality.pyx +++ b/python/pylibcugraph/pylibcugraph/katz_centrality.pyx @@ -97,7 +97,7 @@ def katz_centrality(ResourceHandle resource_handle, do_expensive_check : bool_t A flag to run expensive checks for input arguments if True. - + Returns ------- @@ -114,9 +114,9 @@ def katz_centrality(ResourceHandle resource_handle, cdef cugraph_error_code_t error_code cdef cugraph_error_t* error_ptr - cdef uintptr_t cai_betas_ptr + cdef uintptr_t cai_betas_ptr cdef cugraph_type_erased_device_array_view_t* betas_ptr - + if betas is not None: cai_betas_ptr = betas.__cuda_array_interface__["data"][0] betas_ptr = \ @@ -145,7 +145,7 @@ def katz_centrality(ResourceHandle resource_handle, cugraph_centrality_result_get_vertices(result_ptr) cdef cugraph_type_erased_device_array_view_t* values_ptr = \ cugraph_centrality_result_get_values(result_ptr) - + cupy_vertices = copy_to_cupy_array(c_resource_handle_ptr, vertices_ptr) cupy_values = copy_to_cupy_array(c_resource_handle_ptr, values_ptr) diff --git a/python/pylibcugraph/pylibcugraph/node2vec.pyx b/python/pylibcugraph/pylibcugraph/node2vec.pyx index a550070e7a7..2ef962ae0c6 100644 --- a/python/pylibcugraph/pylibcugraph/node2vec.pyx +++ b/python/pylibcugraph/pylibcugraph/node2vec.pyx @@ -55,13 +55,15 @@ from pylibcugraph.utils cimport ( ) -def node2vec(ResourceHandle resource_handle, - _GPUGraph graph, - seed_array, - size_t max_depth, - bool_t compress_result, - double p, - double q): +def node2vec( + ResourceHandle resource_handle, + _GPUGraph graph, + seed_array, + size_t max_depth, + bool_t compress_result, + double p, + double q +): """ Computes random walks under node2vec sampling procedure. @@ -172,8 +174,8 @@ def node2vec(ResourceHandle resource_handle, cupy_paths = copy_to_cupy_array(c_resource_handle_ptr, paths_ptr) cupy_weights = copy_to_cupy_array(c_resource_handle_ptr, weights_ptr) cupy_path_sizes = copy_to_cupy_array(c_resource_handle_ptr, - path_sizes_ptr) - + path_sizes_ptr) + cugraph_random_walk_result_free(result_ptr) cugraph_type_erased_device_array_view_free(seed_view_ptr) diff --git a/python/pylibcugraph/pylibcugraph/overlap_coefficients.pyx b/python/pylibcugraph/pylibcugraph/overlap_coefficients.pyx index 6af71116469..8eea14ec48d 100644 --- a/python/pylibcugraph/pylibcugraph/overlap_coefficients.pyx +++ b/python/pylibcugraph/pylibcugraph/overlap_coefficients.pyx @@ -57,15 +57,17 @@ from pylibcugraph.utils cimport ( ) -def EXPERIMENTAL__overlap_coefficients(ResourceHandle resource_handle, - _GPUGraph graph, - first, - second, - bool_t use_weight, - bool_t do_expensive_check): +def EXPERIMENTAL__overlap_coefficients( + ResourceHandle resource_handle, + _GPUGraph graph, + first, + second, + bool_t use_weight, + bool_t do_expensive_check +): """ Compute the Overlap coefficients for the specified vertex_pairs. - + Note that Overlap similarity must run on a symmetric graph. @@ -77,13 +79,13 @@ def EXPERIMENTAL__overlap_coefficients(ResourceHandle resource_handle, graph : SGGraph or MGGraph The input graph, for either Single or Multi-GPU operations. - + first : Source of the vertex pair. - + second : Destination of the vertex pair. - + use_weight : bool, optional (default=False) Currently not supported @@ -113,16 +115,12 @@ def EXPERIMENTAL__overlap_coefficients(ResourceHandle resource_handle, cdef cugraph_error_t* error_ptr # 'first' is a required parameter - cdef cugraph_type_erased_device_array_view_t* \ - first_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - first) + cdef cugraph_type_erased_device_array_view_t* first_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(first) # 'second' is a required parameter - cdef cugraph_type_erased_device_array_view_t* \ - second_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - second) + cdef cugraph_type_erased_device_array_view_t* second_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(second) error_code = cugraph_create_vertex_pairs(c_resource_handle_ptr, c_graph_ptr, diff --git a/python/pylibcugraph/pylibcugraph/pagerank.pyx b/python/pylibcugraph/pylibcugraph/pagerank.pyx index 7d8f7807ead..1a01efd146c 100644 --- a/python/pylibcugraph/pylibcugraph/pagerank.pyx +++ b/python/pylibcugraph/pylibcugraph/pagerank.pyx @@ -55,16 +55,18 @@ from pylibcugraph.utils cimport ( ) -def pagerank(ResourceHandle resource_handle, - _GPUGraph graph, - precomputed_vertex_out_weight_vertices, - precomputed_vertex_out_weight_sums, - initial_guess_vertices, - initial_guess_values, - double alpha, - double epsilon, - size_t max_iterations, - bool_t do_expensive_check): +def pagerank( + ResourceHandle resource_handle, + _GPUGraph graph, + precomputed_vertex_out_weight_vertices, + precomputed_vertex_out_weight_sums, + initial_guess_vertices, + initial_guess_values, + double alpha, + double epsilon, + size_t max_iterations, + bool_t do_expensive_check +): """ Find the PageRank score for every vertex in a graph by computing an approximation of the Pagerank eigenvector using the power method. The @@ -166,15 +168,11 @@ def pagerank(ResourceHandle resource_handle, raise RuntimeError("pagerank requires the numpy package, which could " "not be imported") - cdef cugraph_type_erased_device_array_view_t* \ - initial_guess_vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - initial_guess_vertices) + cdef cugraph_type_erased_device_array_view_t* initial_guess_vertices_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(initial_guess_vertices) - cdef cugraph_type_erased_device_array_view_t* \ - initial_guess_values_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - initial_guess_values) + cdef cugraph_type_erased_device_array_view_t* initial_guess_values_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(initial_guess_values) cdef cugraph_resource_handle_t* c_resource_handle_ptr = \ resource_handle.c_resource_handle_ptr @@ -182,15 +180,15 @@ def pagerank(ResourceHandle resource_handle, cdef cugraph_type_erased_device_array_view_t* \ precomputed_vertex_out_weight_vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - precomputed_vertex_out_weight_vertices) + create_cugraph_type_erased_device_array_view_from_py_obj( + precomputed_vertex_out_weight_vertices) # FIXME: assert that precomputed_vertex_out_weight_sums # type == weight type cdef cugraph_type_erased_device_array_view_t* \ precomputed_vertex_out_weight_sums_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - precomputed_vertex_out_weight_sums) + create_cugraph_type_erased_device_array_view_from_py_obj( + precomputed_vertex_out_weight_sums) cdef cugraph_centrality_result_t* result_ptr cdef cugraph_error_code_t error_code @@ -227,8 +225,10 @@ def pagerank(ResourceHandle resource_handle, if initial_guess_values is not None: cugraph_type_erased_device_array_view_free(initial_guess_values_view_ptr) if precomputed_vertex_out_weight_vertices is not None: - cugraph_type_erased_device_array_view_free(precomputed_vertex_out_weight_vertices_view_ptr) + cugraph_type_erased_device_array_view_free( + precomputed_vertex_out_weight_vertices_view_ptr) if precomputed_vertex_out_weight_sums is not None: - cugraph_type_erased_device_array_view_free(precomputed_vertex_out_weight_sums_view_ptr) + cugraph_type_erased_device_array_view_free( + precomputed_vertex_out_weight_sums_view_ptr) return (cupy_vertices, cupy_pageranks) diff --git a/python/pylibcugraph/pylibcugraph/personalized_pagerank.pyx b/python/pylibcugraph/pylibcugraph/personalized_pagerank.pyx index 89b57f139a1..1fe29ab30aa 100644 --- a/python/pylibcugraph/pylibcugraph/personalized_pagerank.pyx +++ b/python/pylibcugraph/pylibcugraph/personalized_pagerank.pyx @@ -90,19 +90,19 @@ def personalized_pagerank(ResourceHandle resource_handle, precomputed_vertex_out_weight_sums : device array type Corresponding precomputed sum of outgoing vertices weight (a performance optimization) - + initial_guess_vertices : device array type Subset of vertices of graph for initial guess for pagerank values (a performance optimization) - + initial_guess_values : device array type Pagerank values for vertices (a performance optimization) - + personalization_vertices : device array type Subset of vertices of graph for personalization (a performance optimization) - + personalization_values : device array type Personalization values for vertices (a performance optimization) @@ -184,13 +184,13 @@ def personalized_pagerank(ResourceHandle resource_handle, cdef cugraph_type_erased_device_array_view_t* \ initial_guess_vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - initial_guess_vertices) + create_cugraph_type_erased_device_array_view_from_py_obj( + initial_guess_vertices) cdef cugraph_type_erased_device_array_view_t* \ initial_guess_values_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - initial_guess_values) + create_cugraph_type_erased_device_array_view_from_py_obj( + initial_guess_values) cdef cugraph_resource_handle_t* c_resource_handle_ptr = \ resource_handle.c_resource_handle_ptr @@ -198,44 +198,45 @@ def personalized_pagerank(ResourceHandle resource_handle, cdef cugraph_type_erased_device_array_view_t* \ precomputed_vertex_out_weight_vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - precomputed_vertex_out_weight_vertices) + create_cugraph_type_erased_device_array_view_from_py_obj( + precomputed_vertex_out_weight_vertices) # FIXME: assert that precomputed_vertex_out_weight_sums # type == weight type cdef cugraph_type_erased_device_array_view_t* \ precomputed_vertex_out_weight_sums_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - precomputed_vertex_out_weight_sums) - + create_cugraph_type_erased_device_array_view_from_py_obj( + precomputed_vertex_out_weight_sums) + cdef cugraph_type_erased_device_array_view_t* \ personalization_vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - personalization_vertices) - + create_cugraph_type_erased_device_array_view_from_py_obj( + personalization_vertices) + cdef cugraph_type_erased_device_array_view_t* \ personalization_values_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - personalization_values) + create_cugraph_type_erased_device_array_view_from_py_obj( + personalization_values) cdef cugraph_centrality_result_t* result_ptr cdef cugraph_error_code_t error_code cdef cugraph_error_t* error_ptr - error_code = cugraph_personalized_pagerank(c_resource_handle_ptr, - c_graph_ptr, - precomputed_vertex_out_weight_vertices_view_ptr, - precomputed_vertex_out_weight_sums_view_ptr, - initial_guess_vertices_view_ptr, - initial_guess_values_view_ptr, - personalization_vertices_view_ptr, - personalization_values_view_ptr, - alpha, - epsilon, - max_iterations, - do_expensive_check, - &result_ptr, - &error_ptr) + error_code = cugraph_personalized_pagerank( + c_resource_handle_ptr, + c_graph_ptr, + precomputed_vertex_out_weight_vertices_view_ptr, + precomputed_vertex_out_weight_sums_view_ptr, + initial_guess_vertices_view_ptr, + initial_guess_values_view_ptr, + personalization_vertices_view_ptr, + personalization_values_view_ptr, + alpha, + epsilon, + max_iterations, + do_expensive_check, + &result_ptr, + &error_ptr) assert_success(error_code, error_ptr, "cugraph_personalized_pagerank") # Extract individual device array pointers from result and copy to cupy @@ -255,9 +256,11 @@ def personalized_pagerank(ResourceHandle resource_handle, if initial_guess_values is not None: cugraph_type_erased_device_array_view_free(initial_guess_values_view_ptr) if precomputed_vertex_out_weight_vertices is not None: - cugraph_type_erased_device_array_view_free(precomputed_vertex_out_weight_vertices_view_ptr) + cugraph_type_erased_device_array_view_free( + precomputed_vertex_out_weight_vertices_view_ptr) if precomputed_vertex_out_weight_sums is not None: - cugraph_type_erased_device_array_view_free(precomputed_vertex_out_weight_sums_view_ptr) + cugraph_type_erased_device_array_view_free( + precomputed_vertex_out_weight_sums_view_ptr) if personalization_vertices is not None: cugraph_type_erased_device_array_view_free(personalization_vertices_view_ptr) if personalization_values is not None: diff --git a/python/pylibcugraph/pylibcugraph/resource_handle.pyx b/python/pylibcugraph/pylibcugraph/resource_handle.pyx index 75f03e67d91..b5a97495138 100644 --- a/python/pylibcugraph/pylibcugraph/resource_handle.pyx +++ b/python/pylibcugraph/pylibcugraph/resource_handle.pyx @@ -18,7 +18,7 @@ from pylibcugraph._cugraph_c.resource_handle cimport ( cugraph_create_resource_handle, cugraph_free_resource_handle, ) -#from cugraph.dask.traversal cimport mg_bfs as c_bfs +# from cugraph.dask.traversal cimport mg_bfs as c_bfs from pylibcugraph cimport resource_handle as c_resource_handle diff --git a/python/pylibcugraph/pylibcugraph/sorensen_coefficients.pyx b/python/pylibcugraph/pylibcugraph/sorensen_coefficients.pyx index 12647baccb2..1b72baf0a26 100644 --- a/python/pylibcugraph/pylibcugraph/sorensen_coefficients.pyx +++ b/python/pylibcugraph/pylibcugraph/sorensen_coefficients.pyx @@ -57,15 +57,17 @@ from pylibcugraph.utils cimport ( ) -def EXPERIMENTAL__sorensen_coefficients(ResourceHandle resource_handle, - _GPUGraph graph, - first, - second, - bool_t use_weight, - bool_t do_expensive_check): +def EXPERIMENTAL__sorensen_coefficients( + ResourceHandle resource_handle, + _GPUGraph graph, + first, + second, + bool_t use_weight, + bool_t do_expensive_check +): """ Compute the Sorensen coefficients for the specified vertex_pairs. - + Note that Sorensen similarity must run on a symmetric graph. Parameters @@ -76,13 +78,13 @@ def EXPERIMENTAL__sorensen_coefficients(ResourceHandle resource_handle, graph : SGGraph or MGGraph The input graph, for either Single or Multi-GPU operations. - + first : Source of the vertex pair. - + second : Destination of the vertex pair. - + use_weight : bool, optional (default=False) Currently not supported @@ -112,16 +114,12 @@ def EXPERIMENTAL__sorensen_coefficients(ResourceHandle resource_handle, cdef cugraph_error_t* error_ptr # 'first' is a required parameter - cdef cugraph_type_erased_device_array_view_t* \ - first_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - first) + cdef cugraph_type_erased_device_array_view_t* first_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(first) # 'second' is a required parameter - cdef cugraph_type_erased_device_array_view_t* \ - second_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - second) + cdef cugraph_type_erased_device_array_view_t* second_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(second) error_code = cugraph_create_vertex_pairs(c_resource_handle_ptr, c_graph_ptr, @@ -132,12 +130,12 @@ def EXPERIMENTAL__sorensen_coefficients(ResourceHandle resource_handle, assert_success(error_code, error_ptr, "vertex_pairs") error_code = cugraph_sorensen_coefficients(c_resource_handle_ptr, - c_graph_ptr, - vertex_pairs_ptr, - use_weight, - do_expensive_check, - &result_ptr, - &error_ptr) + c_graph_ptr, + vertex_pairs_ptr, + use_weight, + do_expensive_check, + &result_ptr, + &error_ptr) assert_success(error_code, error_ptr, "cugraph_sorensen_coefficients") # Extract individual device array pointers from result and copy to cupy diff --git a/python/pylibcugraph/pylibcugraph/sssp.pyx b/python/pylibcugraph/pylibcugraph/sssp.pyx index b2cd829cb2e..4d55eb224e3 100644 --- a/python/pylibcugraph/pylibcugraph/sssp.pyx +++ b/python/pylibcugraph/pylibcugraph/sssp.pyx @@ -49,12 +49,14 @@ from pylibcugraph.utils cimport ( ) -def sssp(ResourceHandle resource_handle, - _GPUGraph graph, - size_t source, - double cutoff, - bool_t compute_predecessors, - bool_t do_expensive_check): +def sssp( + ResourceHandle resource_handle, + _GPUGraph graph, + size_t source, + double cutoff, + bool_t compute_predecessors, + bool_t do_expensive_check +): """ Compute the distance and predecessors for shortest paths from the specified source to all the vertices in the graph. The returned distances array will diff --git a/python/pylibcugraph/pylibcugraph/structure/graph_primtypes.pxd b/python/pylibcugraph/pylibcugraph/structure/graph_primtypes.pxd index 32b700dc513..ad88589d7ab 100644 --- a/python/pylibcugraph/pylibcugraph/structure/graph_primtypes.pxd +++ b/python/pylibcugraph/pylibcugraph/structure/graph_primtypes.pxd @@ -39,9 +39,9 @@ cdef extern from "cugraph/legacy/graph.hpp" namespace "cugraph::legacy": bool tree PropType has_negative_edges - cdef cppclass GraphViewBase[VT,ET,WT]: + cdef cppclass GraphViewBase[VT, ET, WT]: WT *edge_data - handle_t *handle; + handle_t *handle GraphProperties prop VT number_of_vertices ET number_of_edges @@ -52,30 +52,31 @@ cdef extern from "cugraph/legacy/graph.hpp" namespace "cugraph::legacy": void set_local_data(VT* local_vertices_, ET* local_edges_, VT* local_offsets_) void get_vertex_identifiers(VT *) const - GraphViewBase(WT*,VT,ET) + GraphViewBase(WT*, VT, ET) - cdef cppclass GraphCOOView[VT,ET,WT](GraphViewBase[VT,ET,WT]): + cdef cppclass GraphCOOView[VT, ET, WT](GraphViewBase[VT, ET, WT]): VT *src_indices VT *dst_indices - void degree(ET *,DegreeDirection) const + void degree(ET *, DegreeDirection) const GraphCOOView() GraphCOOView(const VT *, const ET *, const WT *, size_t, size_t) - cdef cppclass GraphCompressedSparseBaseView[VT,ET,WT](GraphViewBase[VT,ET,WT]): + cdef cppclass GraphCompressedSparseBaseView[VT, ET, WT](GraphViewBase[VT, ET, WT]): ET *offsets VT *indices void get_source_indices(VT *) const - void degree(ET *,DegreeDirection) const + void degree(ET *, DegreeDirection) const - GraphCompressedSparseBaseView(const VT *, const ET *, const WT *, size_t, size_t) + GraphCompressedSparseBaseView( + const VT *, const ET *, const WT *, size_t, size_t) - cdef cppclass GraphCSRView[VT,ET,WT](GraphCompressedSparseBaseView[VT,ET,WT]): + cdef cppclass GraphCSRView[VT, ET, WT](GraphCompressedSparseBaseView[VT, ET, WT]): GraphCSRView() GraphCSRView(const VT *, const ET *, const WT *, size_t, size_t) - cdef cppclass GraphCSCView[VT,ET,WT](GraphCompressedSparseBaseView[VT,ET,WT]): + cdef cppclass GraphCSCView[VT, ET, WT](GraphCompressedSparseBaseView[VT, ET, WT]): GraphCSCView() GraphCSCView(const VT *, const ET *, const WT *, size_t, size_t) diff --git a/python/pylibcugraph/pylibcugraph/structure/graph_utilities.pxd b/python/pylibcugraph/pylibcugraph/structure/graph_utilities.pxd index d9532cd4190..5d0c2326c10 100644 --- a/python/pylibcugraph/pylibcugraph/structure/graph_utilities.pxd +++ b/python/pylibcugraph/pylibcugraph/structure/graph_utilities.pxd @@ -30,7 +30,7 @@ cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": doubleType "cugraph::cython::numberTypeEnum::doubleType" cdef cppclass graph_container_t: - pass + pass cdef void populate_graph_container( graph_container_t &graph_container, diff --git a/python/pylibcugraph/pylibcugraph/testing/type_utils.pyx b/python/pylibcugraph/pylibcugraph/testing/type_utils.pyx index 253551eba11..8f6b5eb32f8 100644 --- a/python/pylibcugraph/pylibcugraph/testing/type_utils.pyx +++ b/python/pylibcugraph/pylibcugraph/testing/type_utils.pyx @@ -47,7 +47,7 @@ from pylibcugraph._cugraph_c.array cimport ( def create_sampling_result(ResourceHandle resource_handle, - device_sources, + device_sources, device_destinations, device_indices): """ diff --git a/python/pylibcugraph/pylibcugraph/triangle_count.pyx b/python/pylibcugraph/pylibcugraph/triangle_count.pyx index e26b2a291cf..00d55f544c8 100644 --- a/python/pylibcugraph/pylibcugraph/triangle_count.pyx +++ b/python/pylibcugraph/pylibcugraph/triangle_count.pyx @@ -74,11 +74,11 @@ def triangle_count(ResourceHandle resource_handle, start_list: device array type Device array containing the list of vertices for triangle counting. If 'None' the entire set of vertices in the graph is processed - + do_expensive_check: bool If True, performs more extensive tests on the inputs to ensure validitity, at the expense of increased run time. - + Returns ------- A tuple of device arrays, where the first item in the tuple is a device @@ -112,7 +112,7 @@ def triangle_count(ResourceHandle resource_handle, get_c_type_from_numpy_type(start_list.dtype)) else: start_ptr = NULL - + error_code = cugraph_triangle_count(c_resource_handle_ptr, c_graph_ptr, start_ptr, @@ -133,5 +133,5 @@ def triangle_count(ResourceHandle resource_handle, if start_list is not None: cugraph_type_erased_device_array_view_free(start_ptr) - + return (cupy_vertices, cupy_counts) diff --git a/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx b/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx index 649f7980747..3a25286240e 100644 --- a/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx +++ b/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx @@ -69,7 +69,7 @@ def get_two_hop_neighbors(ResourceHandle resource_handle, graph : SGGraph or MGGraph The input graph, for either Single or Multi-GPU operations. - + start_vertices : Optional array of starting vertices If None use all, if specified compute two-hop neighbors for these starting vertices @@ -90,10 +90,8 @@ def get_two_hop_neighbors(ResourceHandle resource_handle, cdef cugraph_type_erased_device_array_view_t* start_vertices_ptr - cdef cugraph_type_erased_device_array_view_t* \ - start_vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - start_vertices) + cdef cugraph_type_erased_device_array_view_t* start_vertices_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(start_vertices) error_code = cugraph_two_hop_neighbors(c_resource_handle_ptr, c_graph_ptr, @@ -105,16 +103,16 @@ def get_two_hop_neighbors(ResourceHandle resource_handle, cdef cugraph_type_erased_device_array_view_t* first_ptr = \ cugraph_vertex_pairs_get_first(result_ptr) - + cdef cugraph_type_erased_device_array_view_t* second_ptr = \ cugraph_vertex_pairs_get_second(result_ptr) - + cupy_first = copy_to_cupy_array(c_resource_handle_ptr, first_ptr) cupy_second = copy_to_cupy_array(c_resource_handle_ptr, second_ptr) # Free all pointers cugraph_vertex_pairs_free(result_ptr) if start_vertices is not None: - cugraph_type_erased_device_array_view_free(start_vertices_view_ptr) + cugraph_type_erased_device_array_view_free(start_vertices_view_ptr) return cupy_first, cupy_second diff --git a/python/pylibcugraph/pylibcugraph/uniform_neighbor_sample.pyx b/python/pylibcugraph/pylibcugraph/uniform_neighbor_sample.pyx index 0d86053a679..1b5c9d550c4 100644 --- a/python/pylibcugraph/pylibcugraph/uniform_neighbor_sample.pyx +++ b/python/pylibcugraph/pylibcugraph/uniform_neighbor_sample.pyx @@ -62,6 +62,7 @@ from pylibcugraph.internal_types.sampling_result cimport ( SamplingResult, ) + def uniform_neighbor_sample(ResourceHandle resource_handle, _GPUGraph input_graph, start_list, diff --git a/python/pylibcugraph/pylibcugraph/utils.pxd b/python/pylibcugraph/pylibcugraph/utils.pxd index 7fc140e9aed..44f51f09a93 100644 --- a/python/pylibcugraph/pylibcugraph/utils.pxd +++ b/python/pylibcugraph/pylibcugraph/utils.pxd @@ -44,12 +44,12 @@ cdef get_c_weight_type_from_numpy_edge_ids_type(numpy_type) cdef get_numpy_edge_ids_type_from_c_weight_type(data_type_id_t c_type) cdef copy_to_cupy_array( - cugraph_resource_handle_t* c_resource_handle_ptr, - cugraph_type_erased_device_array_view_t* device_array_view_ptr) + cugraph_resource_handle_t* c_resource_handle_ptr, + cugraph_type_erased_device_array_view_t* device_array_view_ptr) cdef copy_to_cupy_array_ids( - cugraph_resource_handle_t* c_resource_handle_ptr, - cugraph_type_erased_device_array_view_t* device_array_view_ptr) + cugraph_resource_handle_t* c_resource_handle_ptr, + cugraph_type_erased_device_array_view_t* device_array_view_ptr) cdef cugraph_type_erased_device_array_view_t* \ create_cugraph_type_erased_device_array_view_from_py_obj(python_obj) diff --git a/python/pylibcugraph/pylibcugraph/utils.pyx b/python/pylibcugraph/pylibcugraph/utils.pyx index a9fc8fce711..baab68788a3 100644 --- a/python/pylibcugraph/pylibcugraph/utils.pyx +++ b/python/pylibcugraph/pylibcugraph/utils.pyx @@ -68,7 +68,7 @@ cdef assert_success(cugraph_error_code_t code, raise ValueError(error_msg) elif code == cugraph_error_code_t.CUGRAPH_NOT_IMPLEMENTED: code_str = "CUGRAPH_NOT_IMPLEMENTED" - error_msg = f"non-success value returned from {api_name}: {code_str}\ "\ + error_msg = f"non-success value returned from {api_name}: {code_str} "\ f"{c_error}" raise NotImplementedError(error_msg) elif code == cugraph_error_code_t.CUGRAPH_UNSUPPORTED_TYPE_COMBINATION: @@ -133,8 +133,10 @@ cdef get_c_type_from_numpy_type(numpy_type): elif numpy_type == numpy.float64: return data_type_id_t.FLOAT64 else: - raise RuntimeError("Internal error: got invalid data type enum value " - f"from Numpy: {numpy_type}") + raise RuntimeError( + "Internal error: got invalid data type enum value from Numpy: " + f"{numpy_type}" + ) cdef get_c_weight_type_from_numpy_edge_ids_type(numpy_type): if numpy_type == numpy.int32: @@ -150,8 +152,9 @@ cdef get_numpy_edge_ids_type_from_c_weight_type(data_type_id_t c_weight_type): cdef copy_to_cupy_array( - cugraph_resource_handle_t* c_resource_handle_ptr, - cugraph_type_erased_device_array_view_t* device_array_view_ptr): + cugraph_resource_handle_t* c_resource_handle_ptr, + cugraph_type_erased_device_array_view_t* device_array_view_ptr +): """ Copy the contents from a device array view as returned by various cugraph_* APIs to a new cupy device array, typically intended to be used as a return @@ -186,8 +189,9 @@ cdef copy_to_cupy_array( return cupy_array cdef copy_to_cupy_array_ids( - cugraph_resource_handle_t* c_resource_handle_ptr, - cugraph_type_erased_device_array_view_t* device_array_view_ptr): + cugraph_resource_handle_t* c_resource_handle_ptr, + cugraph_type_erased_device_array_view_t* device_array_view_ptr +): """ Copy the contents from a device array view as returned by various cugraph_* APIs to a new cupy device array, typically intended to be used as a return @@ -207,7 +211,9 @@ cdef copy_to_cupy_array_ids( cdef cugraph_type_erased_device_array_view_t* cupy_array_view_ptr = \ cugraph_type_erased_device_array_view_create( - cupy_array_ptr, array_size, get_c_type_from_numpy_type(cupy_array.dtype)) + cupy_array_ptr, + array_size, + get_c_type_from_numpy_type(cupy_array.dtype)) cdef cugraph_error_t* error_ptr error_code = cugraph_type_erased_device_array_view_copy( @@ -223,21 +229,21 @@ cdef copy_to_cupy_array_ids( return cupy_array cdef cugraph_type_erased_device_array_view_t* \ - create_cugraph_type_erased_device_array_view_from_py_obj(python_obj): - cdef uintptr_t cai_ptr = NULL - cdef cugraph_type_erased_device_array_view_t* view_ptr = NULL - if python_obj is not None: - cai_ptr = python_obj.__cuda_array_interface__["data"][0] - view_ptr = cugraph_type_erased_device_array_view_create( - cai_ptr, - len(python_obj), - get_c_type_from_numpy_type(python_obj.dtype)) - - return view_ptr + create_cugraph_type_erased_device_array_view_from_py_obj(python_obj): + cdef uintptr_t cai_ptr = NULL + cdef cugraph_type_erased_device_array_view_t* view_ptr = NULL + if python_obj is not None: + cai_ptr = python_obj.__cuda_array_interface__["data"][0] + view_ptr = cugraph_type_erased_device_array_view_create( + cai_ptr, + len(python_obj), + get_c_type_from_numpy_type(python_obj.dtype)) + + return view_ptr cdef create_cupy_array_view_for_device_ptr( - cugraph_type_erased_device_array_view_t* device_array_view_ptr, - owning_py_object): + cugraph_type_erased_device_array_view_t* device_array_view_ptr, + owning_py_object): if device_array_view_ptr == NULL: raise ValueError("device_array_view_ptr cannot be NULL") diff --git a/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx b/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx index abd78aa8c10..26f991403b2 100644 --- a/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx +++ b/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx @@ -65,8 +65,7 @@ def _ensure_args(graph, offsets, indices, weights): else: invalid_input = [i for p in [offsets, indices] if p is None] input_type = "csr_arrays" - - + if len(invalid_input) != 0: raise TypeError("Invalid input combination: Must set either 'graph' or " "a combination of 'offsets', 'indices' and 'weights', not both") @@ -75,7 +74,7 @@ def _ensure_args(graph, offsets, indices, weights): assert_CAI_type(offsets, "offsets") assert_CAI_type(indices, "indices") assert_CAI_type(weights, "weights", True) - + return input_type @@ -99,7 +98,7 @@ def weakly_connected_components(ResourceHandle resource_handle, graph : SGGraph or MGGraph The input graph. - + offsets : object supporting a __cuda_array_interface__ interface Array containing the offsets values of a Compressed Sparse Row matrix that represents the graph. @@ -137,7 +136,7 @@ def weakly_connected_components(ResourceHandle resource_handle, ... store_transposed=False, renumber=True, do_expensive_check=False) >>> (vertices, labels) = weakly_connected_components( ... resource_handle, G, None, None, None, None, False) - + >>> vertices [0, 1, 2] >>> labels @@ -182,18 +181,20 @@ def weakly_connected_components(ResourceHandle resource_handle, resource_handle = ResourceHandle() graph_props = GraphProperties( - is_symmetric=True, is_multigraph=False) + is_symmetric=True, + is_multigraph=False, + ) graph = SGGraph( - resource_handle, - graph_props, - offsets, - indices, - weights, - store_transposed=False, - renumber=False, - do_expensive_check=True, - input_array_format="CSR" - ) + resource_handle, + graph_props, + offsets, + indices, + weights, + store_transposed=False, + renumber=False, + do_expensive_check=True, + input_array_format="CSR", + ) cdef cugraph_resource_handle_t* c_resource_handle_ptr = \ resource_handle.c_resource_handle_ptr