5 #include "ThreadPool.hpp"
6 #include "DistanceMetric.hpp"
8 namespace mltk::metrics::dist {
11 mltk::Point<double>::Matrix rows;
12 bool isDiagonal{
false};
13 size_t threads{ std::thread::hardware_concurrency() };
18 explicit BaseMatrix(
mltk::Data<double> &data,
const bool isDiagonal =
false,
const size_t threads = std::thread::hardware_concurrency()) {
19 this->threads = threads;
20 this->isDiagonal = isDiagonal;
21 this->rows = mltk::Point<double>::Matrix(data.
size());
24 bool isDiagonalMatrix()
const {
return this->isDiagonal;}
26 size_t size()
const {
return this->rows.
size();}
33 template<
typename DistanceFunc = metrics::dist::Eucl
idean<
double> >
36 DistanceFunc dist_function{};
41 auto loop = [data,
this](
const int a,
const int b) {
42 for(
size_t idx = a; idx < b; idx++) {
45 for(
size_t j = 0; j < idx; j++){
46 this->rows[data(idx).Id()-1][data(j).Id()-1] = this->dist_function(data(idx), data(j));
49 if(isDiagonal)
continue;
51 for(
size_t j = idx+1; j < data.
size(); j++){
52 this->rows[data(idx).Id()-1][data(j).Id()-1] = this->dist_function(data(idx), data(j));
65 this->threads = threads;
66 this->isDiagonal = isDiagonal;
67 this->rows = mltk::Point<double>::Matrix(data.
size());
size_t size() const
Returns the size of the dataset.
Definition: Data.hpp:208
std::size_t size() const
Returns the dimension of the point.
Definition: Point.hpp:133
A C++17 thread pool class. The user submits tasks to be executed into a queue. Whenever a thread beco...
Definition: ThreadPool.hpp:39
void wait_for_tasks()
Wait for tasks to be completed. Normally, this function waits for all tasks, both those that are curr...
Definition: ThreadPool.hpp:291
void parallelize_loop(const T1 &first_index, const T2 &index_after_last, const F &loop, ui32 num_blocks=0)
Parallelize a loop by splitting it into blocks, submitting each block separately to the thread pool,...
Definition: ThreadPool.hpp:126
Definition: DistanceMatrix.hpp:9
Definition: DistanceMatrix.hpp:34