Skip to content

Commit ec7c59f

Browse files
committed
initialize random seed
1 parent 84b4617 commit ec7c59f

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

csrc/cpu/ego_sample_cpu.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ ego_k_hop_sample_adj_cpu(torch::Tensor rowptr, torch::Tensor col,
1515
torch::Tensor idx, int64_t depth,
1616
int64_t num_neighbors, bool replace) {
1717

18+
srand(time(NULL) + 1000 * getpid()); // Initialize random seed.
19+
1820
std::vector<torch::Tensor> out_rowptrs(idx.numel() + 1);
1921
std::vector<torch::Tensor> out_cols(idx.numel());
2022
std::vector<torch::Tensor> out_n_ids(idx.numel());

csrc/cpu/hgt_sample_cpu.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ hgt_sample_cpu(const c10::Dict<rel_t, torch::Tensor> &colptr_dict,
101101
const c10::Dict<node_t, vector<int64_t>> &num_samples_dict,
102102
const int64_t num_hops) {
103103

104+
srand(time(NULL) + 1000 * getpid()); // Initialize random seed.
105+
104106
// Create a mapping to convert single string relations to edge type triplets:
105107
unordered_map<rel_t, edge_t> to_edge_type;
106108
for (const auto &kv : colptr_dict) {

csrc/cpu/neighbor_sample_cpu.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ tuple<torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor>
1111
sample(const torch::Tensor &colptr, const torch::Tensor &row,
1212
const torch::Tensor &input_node, const vector<int64_t> num_neighbors) {
1313

14+
srand(time(NULL) + 1000 * getpid()); // Initialize random seed.
15+
1416
// Initialize some data structures for the sampling process:
1517
vector<int64_t> samples;
1618
unordered_map<int64_t, int64_t> to_local_node;
@@ -121,6 +123,8 @@ hetero_sample(const vector<node_t> &node_types,
121123
const c10::Dict<rel_t, vector<int64_t>> &num_neighbors_dict,
122124
const int64_t num_hops) {
123125

126+
srand(time(NULL) + 1000 * getpid()); // Initialize random seed.
127+
124128
// Create a mapping to convert single string relations to edge type triplets:
125129
unordered_map<rel_t, edge_t> to_edge_type;
126130
for (const auto &k : edge_types)

csrc/cpu/sample_cpu.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ sample_adj_cpu(torch::Tensor rowptr, torch::Tensor col, torch::Tensor idx,
1111
CHECK_CPU(idx);
1212
CHECK_INPUT(idx.dim() == 1);
1313

14+
srand(time(NULL) + 1000 * getpid()); // Initialize random seed.
15+
1416
auto rowptr_data = rowptr.data_ptr<int64_t>();
1517
auto col_data = col.data_ptr<int64_t>();
1618
auto idx_data = idx.data_ptr<int64_t>();

0 commit comments

Comments
 (0)