c_api_common.h 1.26 KB
Newer Older
1
2
3
4
5
/*!
 *  Copyright (c) 2018 by Contributors
 * \file c_api_common.h
 * \brief DGL C API common util functions
 */
Lingfan Yu's avatar
Lingfan Yu committed
6
7
8
9
10
11
#ifndef DGL_C_API_COMMON_H_
#define DGL_C_API_COMMON_H_

#include <dgl/runtime/ndarray.h>
#include <dgl/runtime/packed_func.h>
#include <dgl/runtime/registry.h>
12
13
#include <dgl/array.h>
#include <dgl/graph_interface.h>
GaiYu0's avatar
GaiYu0 committed
14
#include <algorithm>
Lingfan Yu's avatar
Lingfan Yu committed
15
#include <vector>
16
#include <string>
Lingfan Yu's avatar
Lingfan Yu committed
17
18
19

namespace dgl {

20
21
// Communicator handler type
typedef void* CommunicatorHandle;
Lingfan Yu's avatar
Lingfan Yu committed
22

Chao Ma's avatar
Chao Ma committed
23
24
25
// KVstore message handler type
typedef void* KVMsgHandle;

26
27
28
/*!
 * \brief Convert a vector of NDArray to PackedFunc.
 */
29
30
dgl::runtime::PackedFunc ConvertNDArrayVectorToPackedFunc(
    const std::vector<dgl::runtime::NDArray>& vec);
Lingfan Yu's avatar
Lingfan Yu committed
31

GaiYu0's avatar
GaiYu0 committed
32
33
34
35
36
37
/*!
 * \brief Copy a vector to an int64_t NDArray.
 *
 * The element type of the vector must be convertible to int64_t.
 */
template<typename DType>
38
dgl::runtime::NDArray CopyVectorToNDArray(
GaiYu0's avatar
GaiYu0 committed
39
    const std::vector<DType>& vec) {
40
  using dgl::runtime::NDArray;
GaiYu0's avatar
GaiYu0 committed
41
42
43
44
45
46
  const int64_t len = vec.size();
  NDArray a = NDArray::Empty({len}, DLDataType{kDLInt, 64, 1}, DLContext{kDLCPU, 0});
  std::copy(vec.begin(), vec.end(), static_cast<int64_t*>(a->data));
  return a;
}

47
48
runtime::PackedFunc ConvertEdgeArrayToPackedFunc(const EdgeArray& ea);

49
}  // namespace dgl
Lingfan Yu's avatar
Lingfan Yu committed
50

51
#endif  // DGL_C_API_COMMON_H_