/*! * 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 #include #include #include #include #include #include #include #include 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& vec); /*! * \brief Copy a vector to an NDArray. * * The data type of the NDArray will be IdType, which must be an integer type. * The element type (DType) of the vector must be convertible to IdType. */ template dgl::runtime::NDArray CopyVectorToNDArray(const std::vector& vec) { using dgl::runtime::NDArray; const int64_t len = vec.size(); NDArray a = NDArray::Empty( {len}, DGLDataType{kDGLInt, sizeof(IdType) * 8, 1}, DGLContext{kDGLCPU, 0}); std::copy(vec.begin(), vec.end(), static_cast(a->data)); return a; } runtime::PackedFunc ConvertEdgeArrayToPackedFunc(const EdgeArray& ea); } // namespace dgl #endif // DGL_C_API_COMMON_H_