Skip to content

Commit 83cb71f

Browse files
committed
Add check ensuring that the vertices are numbered consecutively if renumber is False
1 parent 8ea7e35 commit 83cb71f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

cpp/src/c_api/graph_sg.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,46 @@ struct create_graph_functor : public cugraph::c_api::abstract_functor {
292292
if (renumber_) {
293293
*number_map = std::move(new_number_map.value());
294294
} else {
295+
// Ensure vertices are numbered consecutively
296+
rmm::device_uvector<vertex_t> vertices(edgelist_srcs.size(), handle_.get_stream());
297+
298+
raft::copy<vertex_t>(
299+
vertices.data(), edgelist_srcs.data(), edgelist_srcs.size(), handle_.get_stream());
300+
301+
cugraph::detail::sort_ints(
302+
handle_.get_stream(),
303+
raft::device_span<vertex_t>{vertices.data(), vertices.size()});
304+
305+
cugraph::detail::unique_ints(
306+
handle_.get_stream(),
307+
raft::device_span<vertex_t>{vertices.data(), vertices.size()});
308+
309+
auto unique_srcs_size = vertices.size();
310+
vertices.resize(unique_srcs_size + edgelist_dsts.size(), handle_.get_stream());
311+
312+
raft::copy<vertex_t>(
313+
vertices.data() + unique_srcs_size,
314+
edgelist_dsts.data(),
315+
edgelist_dsts.size(),
316+
handle_.get_stream());
317+
295318
number_map->resize(graph->number_of_vertices(), handle_.get_stream());
296319
cugraph::detail::sequence_fill(handle_.get_stream(),
297320
number_map->data(),
298321
number_map->size(),
299322
graph->view().local_vertex_partition_range_first());
323+
324+
auto is_consecutive = cugraph::detail::is_equal(
325+
handle_.get_stream(),
326+
raft::device_span<vertex_t>{vertices.data(), vertices.size()},
327+
raft::device_span<vertex_t>{number_map->data(), number_map->size()}
328+
);
329+
330+
if (!is_consecutive) {
331+
mark_error(CUGRAPH_INVALID_INPUT, "Vertex list must be numbered consecutively from 0 when 'renumber' is 'false'");
332+
return;
333+
}
334+
300335
}
301336

302337
if (new_edge_weights) { *edge_weights = std::move(new_edge_weights.value()); }

0 commit comments

Comments
 (0)