scran_graph_cluster
Graph-based clustering of cells
Loading...
Searching...
No Matches
edges_to_graph.hpp
Go to the documentation of this file.
1#ifndef SCRAN_GRAPH_CLUSTER_EDGES_TO_GRAPH_HPP
2#define SCRAN_GRAPH_CLUSTER_EDGES_TO_GRAPH_HPP
3
4#include <cstddef>
5
6#include "raiigraph/raiigraph.hpp"
7#include "sanisizer/sanisizer.hpp"
8
9#include "igraph.h"
10
16namespace scran_graph_cluster {
17
33template<typename Vertex_>
34raiigraph::Graph edges_to_graph(const std::size_t double_edges, const Vertex_* const edges, const std::size_t num_vertices, const bool directed) {
35 raiigraph::initialize();
36
37 // Make sure signature doesn't require any igraph-related types, as these
38 // might not be usable before the library is initialized.
39 const auto actual_directed = (directed ? IGRAPH_DIRECTED : IGRAPH_UNDIRECTED);
40
41 if constexpr(std::is_same<Vertex_, igraph_int_t>::value) {
42 const auto edge_view = igraph_vector_int_view(edges, sanisizer::cast<igraph_int_t>(double_edges));
43 return raiigraph::Graph(&edge_view, num_vertices, actual_directed);
44 } else {
45 auto tmp = sanisizer::create<raiigraph::IntegerVector>(double_edges);
46 auto& payload = *(tmp.get());
47 for (std::size_t x = 0; x < double_edges; ++x) {
48 VECTOR(payload)[x] = edges[x];
49 }
50 return raiigraph::Graph(tmp, num_vertices, actual_directed);
51 }
52}
53
54}
55
56#endif
Graph-based clustering of single-cell data.
Definition build_snn_graph.hpp:22
raiigraph::Graph edges_to_graph(const std::size_t double_edges, const Vertex_ *const edges, const std::size_t num_vertices, const bool directed)
Definition edges_to_graph.hpp:34