creators.cc 2.42 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
14
15
16
    GraphPtr meta_graph,
    const std::vector<HeteroGraphPtr>& rel_graphs,
    const std::vector<int64_t>& num_nodes_per_type) {
  return HeteroGraphPtr(new HeteroGraph(meta_graph, rel_graphs, num_nodes_per_type));
17
18
19
20
}

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

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

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

43
44
HeteroGraphPtr CreateFromCSR(
    int64_t num_vtypes, const aten::CSRMatrix& mat,
45
46
47
48
49
50
51
    dgl_format_code_t formats) {
  auto unit_g = UnitGraph::CreateFromCSR(num_vtypes, mat, formats);
  auto ret = HeteroGraphPtr(new HeteroGraph(
      unit_g->meta_graph(),
      {unit_g}));
  return HeteroGraphPtr(new HeteroGraph(unit_g->meta_graph(),
                                                       {unit_g}));
52
53
54
55
56
}

HeteroGraphPtr CreateFromCSC(
    int64_t num_vtypes, int64_t num_src, int64_t num_dst,
    IdArray indptr, IdArray indices, IdArray edge_ids,
57
    dgl_format_code_t formats) {
58
  auto unit_g = UnitGraph::CreateFromCSC(
59
      num_vtypes, num_src, num_dst, indptr, indices, edge_ids, formats);
60
61
62
63
64
  return HeteroGraphPtr(new HeteroGraph(unit_g->meta_graph(), {unit_g}));
}

HeteroGraphPtr CreateFromCSC(
    int64_t num_vtypes, const aten::CSRMatrix& mat,
65
66
    dgl_format_code_t formats) {
  auto unit_g = UnitGraph::CreateFromCSC(num_vtypes, mat, formats);
67
68
69
  return HeteroGraphPtr(new HeteroGraph(unit_g->meta_graph(), {unit_g}));
}

70
}  // namespace dgl