node2vec_cpu.cc 1.38 KB
Newer Older
Quan (Andy) Gan's avatar
Quan (Andy) Gan committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*!
 *  Copyright (c) 2021 by Contributors
 * \file graph/sampling/node2vec_cpu.cc
 * \brief DGL sampler - CPU implementation of node2vec random walk with OpenMP
 */

#include <dgl/array.h>
#include <dgl/base_heterograph.h>
#include <utility>

#include "node2vec_randomwalk.h"

namespace dgl {

using namespace dgl::runtime;
using namespace dgl::aten;

namespace sampling {

namespace impl {

22
template <DGLDeviceType XPU, typename IdxType>
Quan (Andy) Gan's avatar
Quan (Andy) Gan committed
23
24
25
26
27
28
29
30
31
32
33
std::pair<IdArray, IdArray> Node2vec(
    const HeteroGraphPtr hg, const IdArray seeds, const double p,
    const double q, const int64_t walk_length,
    const FloatArray &prob) {
  TerminatePredicate<IdxType> terminate = [](IdxType *data, dgl_id_t curr,
                                             int64_t len) { return false; };

  return Node2vecRandomWalk<XPU, IdxType>(hg, seeds, p, q, walk_length, prob,
                                          terminate);
}

34
template std::pair<IdArray, IdArray> Node2vec<kDGLCPU, int32_t>(
Quan (Andy) Gan's avatar
Quan (Andy) Gan committed
35
36
37
38
39
    const HeteroGraphPtr hg,
    const IdArray seeds, const double p,
    const double q,
    const int64_t walk_length,
    const FloatArray &prob);
40
template std::pair<IdArray, IdArray> Node2vec<kDGLCPU, int64_t>(
Quan (Andy) Gan's avatar
Quan (Andy) Gan committed
41
42
43
44
45
46
47
48
49
50
51
    const HeteroGraphPtr hg,
    const IdArray seeds, const double p,
    const double q,
    const int64_t walk_length,
    const FloatArray &prob);

};  // namespace impl

};  // namespace sampling

};  // namespace dgl