dglgraph_data.h 1.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
/*!
 *  Copyright (c) 2019 by Contributors
 * \file graph/serialize/dglgraph_data.h
 * \brief Graph serialization header
 */
#ifndef DGL_GRAPH_SERIALIZE_DGLGRAPH_DATA_H_
#define DGL_GRAPH_SERIALIZE_DGLGRAPH_DATA_H_

#include <dgl/array.h>
10
#include <dgl/graph.h>
11
#include <dgl/immutable_graph.h>
12
#include <dgl/packed_func_ext.h>
13
#include <dgl/runtime/container.h>
14
#include <dgl/runtime/ndarray.h>
15
#include <dgl/runtime/object.h>
16
17
18
19
#include <dmlc/io.h>
#include <dmlc/type_traits.h>

#include <algorithm>
20
#include <iostream>
21
#include <memory>
22
23
#include <string>
#include <utility>
24
25
#include <vector>

26
27
28
#include "../../c_api_common.h"

using dgl::ImmutableGraph;
29
using dgl::runtime::NDArray;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using namespace dgl::runtime;

namespace dgl {
namespace serialize {

typedef std::pair<std::string, NDArray> NamedTensor;

class GraphDataObject : public runtime::Object {
 public:
  ImmutableGraphPtr gptr;
  std::vector<NamedTensor> node_tensors;
  std::vector<NamedTensor> edge_tensors;
  static constexpr const char *_type_key = "graph_serialize.GraphData";

44
45
46
  void SetData(
      ImmutableGraphPtr gptr, Map<std::string, Value> node_tensors,
      Map<std::string, Value> edge_tensors);
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

  void Save(dmlc::Stream *fs) const;

  bool Load(dmlc::Stream *fs);

  DGL_DECLARE_OBJECT_TYPE_INFO(GraphDataObject, runtime::Object);
};

class GraphData : public runtime::ObjectRef {
 public:
  DGL_DEFINE_OBJECT_REF_METHODS(GraphData, runtime::ObjectRef, GraphDataObject);

  /*! \brief create a new GraphData reference */
  static GraphData Create() {
    return GraphData(std::make_shared<GraphDataObject>());
  }
};

ImmutableGraphPtr ToImmutableGraph(GraphPtr g);

}  // namespace serialize
}  // namespace dgl

#endif  // DGL_GRAPH_SERIALIZE_DGLGRAPH_DATA_H_