zheng-da commented on a change in pull request #13509: Speedup and fix bug for 
dgl_csr_sampling op
URL: https://github.com/apache/incubator-mxnet/pull/13509#discussion_r239366285
 
 

 ##########
 File path: src/operator/contrib/dgl_graph.cc
 ##########
 @@ -613,35 +607,42 @@ static void SampleSubgraph(const NDArray &csr,
         node_queue.pop();
         continue;
       }
-      tmp_src_list.clear();
-      tmp_edge_list.clear();
       tmp_sampled_src_list.clear();
       tmp_sampled_edge_list.clear();
-      GetSrcList(val_list,
-                 col_list,
-                 indptr,
-                 dst_id,
-                 &tmp_src_list,
-                 &tmp_edge_list);
       if (probability == nullptr) {  // uniform-sample
-        GetUniformSample(tmp_src_list,
-                       tmp_edge_list,
+        GetUniformSample(val_list,
+                       col_list,
+                       indptr,
+                       dst_id,
                        num_neighbor,
                        &tmp_sampled_src_list,
                        &tmp_sampled_edge_list,
                        &time_seed);
       } else {  // non-uniform-sample
         GetNonUniformSample(probability,
-                       tmp_src_list,
-                       tmp_edge_list,
+                       val_list,
+                       col_list,
+                       indptr,
+                       dst_id,
                        num_neighbor,
                        &tmp_sampled_src_list,
                        &tmp_sampled_edge_list,
                        &time_seed);
       }
-      neigh_mp.insert(std::pair<dgl_id_t, neigh_list>(dst_id,
-        neigh_list(tmp_sampled_src_list,
-                   tmp_sampled_edge_list)));
+      CHECK_EQ(tmp_sampled_src_list.size(),
+               tmp_sampled_edge_list.size());
+      size_t pos = neighbor_list.size();
+      neigh_pos[dst_id] = pos;
+      // First we push the size of neighbor vector
+      neighbor_list.push_back(tmp_sampled_edge_list.size());
+      // Then push the vertices
+      for (size_t i = 0; i < tmp_sampled_src_list.size(); ++i) {
+        neighbor_list.push_back(tmp_sampled_src_list[i]);
+      }
+      // Finally we push the edge list
+      for (size_t i = 0; i < tmp_sampled_edge_list.size(); ++i) {
+        neighbor_list.push_back(tmp_sampled_edge_list[i]);
+      }
 
 Review comment:
   another way is to maintain two lists: one for column Ids and the other for 
the values. anyway, this implementation also works.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to