creators.cc 2.48 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
22
    IdArray row, IdArray col,
    bool row_sorted, bool col_sorted, dgl_format_code_t formats) {
23
  auto unit_g = UnitGraph::CreateFromCOO(
24
      num_vtypes, num_src, num_dst, row, col, row_sorted, col_sorted, formats);
25
26
27
  return HeteroGraphPtr(new HeteroGraph(unit_g->meta_graph(), {unit_g}));
}

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

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

44
45
HeteroGraphPtr CreateFromCSR(
    int64_t num_vtypes, const aten::CSRMatrix& mat,
46
47
48
49
50
51
52
    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}));
53
54
55
56
57
}

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

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

71
}  // namespace dgl