MCPcopy Create free account
hub / github.com/DeepGraphLearning/graphvite / predict

Method predict

include/core/solver.h:660–723  ·  view source on GitHub ↗

* @brief Predict logits for samples * @param _samples edge samples */

Source from the content-addressed store, hash-verified

658 * @param _samples edge samples
659 */
660 std::vector<Float> predict(const std::vector<EdgeSample> &_samples) {
661 samples = &_samples;
662 is_train = false;
663
664 pool_offsets.resize(num_sampler + 1);
665 for (auto &&sampler_offsets : pool_offsets) {
666 sampler_offsets.resize(num_partition);
667 for (auto &&partition_offsets : sampler_offsets)
668 partition_offsets.resize(num_partition);
669 }
670 predict_pool.resize(num_partition);
671 for (auto &&partition_pool : predict_pool)
672 partition_pool.resize(num_partition);
673 sample_indexes.resize(num_partition);
674 for (auto &&partition_indexes : sample_indexes)
675 partition_indexes.resize(num_partition);
676
677 std::vector<std::thread> sample_threads(num_sampler + num_worker);
678 size_t num_sample = samples->size();
679 size_t work_load = (num_sample + num_sampler - 1) / num_sampler;
680 for (int i = 0; i < num_sampler + num_worker; i++)
681 sample_threads[i] = std::thread(&Sampler::count, samplers[0], work_load * i,
682 std::min(work_load * (i + 1), num_sample), i);
683 for (auto &&thread : sample_threads)
684 thread.join();
685
686 for (int i = 0; i < num_sampler; i++)
687 for (int j = 0; j < num_partition; j++)
688 for (int k = 0; k < num_partition; k++)
689 pool_offsets[i + 1][j][k] += pool_offsets[i][j][k];
690 predict_batch_id = 0;
691 num_predict_batch = 0;
692 size_t all_pool = 0;
693 for (int i = 0; i < num_partition; i++)
694 for (int j = 0; j < num_partition; j++) {
695 size_t this_pool_size = pool_offsets[num_sampler][i][j];
696 all_pool += this_pool_size;
697 predict_pool[i][j].resize(this_pool_size);
698 sample_indexes[i][j].resize(this_pool_size);
699 num_predict_batch += (this_pool_size + batch_size - 1) / batch_size;
700 }
701
702 for (int i = 0; i < num_sampler + num_worker; i++)
703 sample_threads[i] = std::thread(&Sampler::distribute, samplers[0], work_load * i,
704 std::min(work_load * (i + 1), num_sample), i);
705 for (auto &&thread : sample_threads)
706 thread.join();
707
708 results.resize(num_sample);
709 std::vector<std::thread> worker_threads(num_worker);
710 auto schedule = get_schedule();
711 for (auto &&assignment : schedule) {
712 for (int i = 0; i < assignment.size(); i++)
713 worker_threads[i] = std::thread(&Worker::predict, workers[i], assignment[i].first, assignment[i].second);
714 for (int i = 0; i < assignment.size(); i++)
715 worker_threads[i].join();
716 }
717

Callers 1

graphvite_predictMethod · 0.45

Calls 1

resizeMethod · 0.80

Tested by

no test coverage detected