-
Notifications
You must be signed in to change notification settings - Fork 0
/
c_api_common.h
52 lines (43 loc) · 1.31 KB
/
c_api_common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*!
* Copyright (c) 2018 by Contributors
* \file c_api_common.h
* \brief DGL C API common util functions
*/
#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>
#include <dgl/array.h>
#include <dgl/graph_interface.h>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
namespace dgl {
// Communicator handler type
typedef void* CommunicatorHandle;
// KVstore message handler type
typedef void* KVMsgHandle;
/*!
* \brief Convert a vector of NDArray to PackedFunc.
*/
dgl::runtime::PackedFunc ConvertNDArrayVectorToPackedFunc(
const std::vector<dgl::runtime::NDArray>& vec);
/*!
* \brief Copy a vector to an int64_t NDArray.
*
* The element type of the vector must be convertible to int64_t.
*/
template<typename IdType, typename DType>
dgl::runtime::NDArray CopyVectorToNDArray(
const std::vector<DType>& vec) {
using dgl::runtime::NDArray;
const int64_t len = vec.size();
NDArray a = NDArray::Empty({len}, DLDataType{kDLInt, sizeof(IdType), 1}, DLContext{kDLCPU, 0});
std::copy(vec.begin(), vec.end(), static_cast<IdType*>(a->data));
return a;
}
runtime::PackedFunc ConvertEdgeArrayToPackedFunc(const EdgeArray& ea);
} // namespace dgl
#endif // DGL_C_API_COMMON_H_