Пример #1
0
void ForecastMachine::compute_distances()
{
    /*
    size_t rows = which_pred.size() / num_threads;
    size_t extra = which_pred.size() % num_threads;
    size_t start = 0;
    size_t end = rows;
    
    std::vector<std::thread> workers;
    for(int t = 1; t <= num_threads; ++t)
    {
        if(t == num_threads)
            end += extra;
        
        // set up calculations to be done
        workers.push_back(std::thread([start, end, this]()
                                 {
                                     size_t curr_pred;
                                     for(size_t i = start; i < end; ++i)
                                     {
                                         curr_pred = which_pred[i];
    */
    for(auto& curr_pred: which_pred)
    {
        for(auto& curr_lib: which_lib)
        {
            // if(std::isnan(distances[curr_pred][curr_lib]))
            // {
            //     distances[curr_pred][curr_lib] = dist_func(data_vectors[curr_pred],
            //                                                 data_vectors[curr_lib]);
            //     distances[curr_lib][curr_pred] = distances[curr_pred][curr_lib];                              
            // }
            distances.insert(curr_pred, curr_lib) = dist_func(data_vectors[curr_pred],
                                                              data_vectors[curr_lib]);
            distances.insert(curr_lib, curr_pred) = distances.coeff(curr_pred, curr_lib);
        }
    }
    /*
                                }));
        
        // set up rows for next calc
        start = end;
        end = start + rows;
    }
    
    for(auto& tt: workers)
        tt.join();
    */
    return;
}
Пример #2
0
struct btp_distances *
btp_threads_compare(struct btp_thread **threads, int m, int n, btp_dist_thread_type dist_func)
{
    struct btp_distances *distances;
    struct btp_thread *thread1, *thread2;
    int i, j, ok, all;

    distances = btp_distances_new(m, n);

    for (i = 0; i < m; i++)
        for (j = i + 1; j < n; j++)
        {
            ok = all = 0;
            btp_thread_quality_counts(threads[i], &ok, &all);
            btp_thread_quality_counts(threads[j], &ok, &all);

            if (ok == all)
            {
                thread1 = threads[i];
                thread2 = threads[j];
            }
            else
            {
                /* There are some unknown function names, try to pair them, but
                 * the threads need to be copied first. */
                thread1 = btp_thread_dup(threads[i], false);
                thread2 = btp_thread_dup(threads[j], false);
                btp_normalize_paired_unknown_function_names(thread1, thread2);
            }

            distances->distances[get_distance_position(distances, i, j)] = dist_func(thread1, thread2);

            if (ok != all)
            {
                btp_thread_free(thread1);
                btp_thread_free(thread2);
            }
        }

    return distances;
}