creators.cc 2.39 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
/*!
 *  Copyright (c) 2020 by Contributors
 * \file graph/creators.cc
 * \brief Functions for constructing graphs.
 */
#include "./heterograph.h"
using namespace dgl::runtime;

namespace dgl {

// creator implementation
HeteroGraphPtr CreateHeteroGraph(
13
    GraphPtr meta_graph, const std::vector<HeteroGraphPtr>& rel_graphs,
14
    const std::vector<int64_t>& num_nodes_per_type) {
15
16
  return HeteroGraphPtr(
      new HeteroGraph(meta_graph, rel_graphs, num_nodes_per_type));
17
18
19
}

HeteroGraphPtr CreateFromCOO(
20
21
    int64_t num_vtypes, int64_t num_src, int64_t num_dst, IdArray row,
    IdArray col, bool row_sorted, bool col_sorted, dgl_format_code_t formats) {
22
  auto unit_g = UnitGraph::CreateFromCOO(
23
      num_vtypes, num_src, num_dst, row, col, row_sorted, col_sorted, formats);
24
25
26
  return HeteroGraphPtr(new HeteroGraph(unit_g->meta_graph(), {unit_g}));
}

27
HeteroGraphPtr CreateFromCOO(
28
    int64_t num_vtypes, const aten::COOMatrix& mat, dgl_format_code_t formats) {
29
  auto unit_g = UnitGraph::CreateFromCOO(num_vtypes, mat, formats);
30
31
32
  return HeteroGraphPtr(new HeteroGraph(unit_g->meta_graph(), {unit_g}));
}

33
HeteroGraphPtr CreateFromCSR(
34
35
    int64_t num_vtypes, int64_t num_src, int64_t num_dst, IdArray indptr,
    IdArray indices, IdArray edge_ids, dgl_format_code_t formats) {
36
  auto unit_g = UnitGraph::CreateFromCSR(
37
      num_vtypes, num_src, num_dst, indptr, indices, edge_ids, formats);
38
39
40
  return HeteroGraphPtr(new HeteroGraph(unit_g->meta_graph(), {unit_g}));
}

41
HeteroGraphPtr CreateFromCSR(
42
    int64_t num_vtypes, const aten::CSRMatrix& mat, dgl_format_code_t formats) {
43
  auto unit_g = UnitGraph::CreateFromCSR(num_vtypes, mat, formats);
44
45
  auto ret = HeteroGraphPtr(new HeteroGraph(unit_g->meta_graph(), {unit_g}));
  return HeteroGraphPtr(new HeteroGraph(unit_g->meta_graph(), {unit_g}));
46
47
48
}

HeteroGraphPtr CreateFromCSC(
49
50
    int64_t num_vtypes, int64_t num_src, int64_t num_dst, IdArray indptr,
    IdArray indices, IdArray edge_ids, dgl_format_code_t formats) {
51
  auto unit_g = UnitGraph::CreateFromCSC(
52
      num_vtypes, num_src, num_dst, indptr, indices, edge_ids, formats);
53
54
55
56
  return HeteroGraphPtr(new HeteroGraph(unit_g->meta_graph(), {unit_g}));
}

HeteroGraphPtr CreateFromCSC(
57
    int64_t num_vtypes, const aten::CSRMatrix& mat, dgl_format_code_t formats) {
58
  auto unit_g = UnitGraph::CreateFromCSC(num_vtypes, mat, formats);
59
60
61
  return HeteroGraphPtr(new HeteroGraph(unit_g->meta_graph(), {unit_g}));
}

62
}  // namespace dgl