Skip to content

Commit bd91e28

Browse files
committed
allow sampling of all nodes
1 parent 8fb5428 commit bd91e28

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

csrc/cpu/sample_cpu.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,30 @@ sample_adj_cpu(torch::Tensor rowptr, torch::Tensor col, torch::Tensor rowcount,
3232
n_ids.push_back(i);
3333
}
3434

35-
if (replace) { // Sample with replacement ====================================
35+
if (num_neighbors < 0) { // No sampling ======================================
36+
37+
int64_t r, c, e, offset = 0;
38+
for (int64_t i = 0; i < idx.size(0); i++) {
39+
r = idx_data[i];
40+
41+
for (int64_t j = 0; j < rowcount_data[r]; j++) {
42+
e = rowptr_data[r] + j;
43+
c = col_data[e];
44+
45+
if (n_id_map.count(c) == 0) {
46+
n_id_map[c] = n_ids.size();
47+
n_ids.push_back(c);
48+
}
49+
50+
cols.push_back(n_id_map[c]);
51+
e_ids.push_back(e);
52+
}
53+
offset = cols.size();
54+
out_rowptr_data[i + 1] = offset;
55+
}
56+
}
57+
58+
else if (replace) { // Sample with replacement ===============================
3659

3760
int64_t r, c, e, offset = 0;
3861
for (int64_t i = 0; i < idx.size(0); i++) {

0 commit comments

Comments
 (0)