Copy report to the repo also (no code changes only comments)

This commit is contained in:
2024-11-21 15:18:39 +02:00
parent 494fdddd04
commit 381a5737db
8 changed files with 221 additions and 5 deletions
+9
View File
@@ -61,6 +61,14 @@ void pdist2(const Matrix& X, const Matrix& Y, Matrix& D2) {
M++;
}
/*!
* Quick select implementation
* \fn void quickselect(std::vector<std::pair<DataType,IndexType>>&, int)
* \tparam DataType
* \tparam IndexType
* \param vec Vector of paire(distance, index) to partially sort over distance
* \param k The number of elements to sort-select
*/
template<typename DataType, typename IndexType>
void quickselect(std::vector<std::pair<DataType, IndexType>>& vec, int k) {
std::nth_element(
@@ -76,6 +84,7 @@ void quickselect(std::vector<std::pair<DataType, IndexType>>& vec, int k) {
/*!
* \param C Is a MxD matrix (Corpus)
* \param Q Is a NxD matrix (Query)
* \param idx_offset The offset of the indexes for output (to match with the actual Corpus indexes)
* \param k The number of nearest neighbors needed
* \param idx Is the Nxk matrix with the k indexes of the C points, that are
* neighbors of the nth point of Q
+30 -4
View File
@@ -38,6 +38,22 @@ void init_workers();
namespace v1 {
/*!
*
* Merge knnsearch results and select the closest neighbors
*
* \tparam DataType
* \tparam IndexType
* \param N1 Neighbors results from one knnsearch
* \param D1 Distances results from one knnsearcs
* \param N2 Neighbors results from second knnsearch
* \param D2 Distances results from second knnsearch
* \param k How many
* \param m How accurate
* \param N Output for Neighbors
* \param D Output for Distances
*/
template <typename DataType, typename IndexType>
void mergeResultsWithM(mtx::Matrix<IndexType>& N1, mtx::Matrix<DataType>& D1,
mtx::Matrix<IndexType>& N2, mtx::Matrix<DataType>& D2,
@@ -77,6 +93,9 @@ void mergeResultsWithM(mtx::Matrix<IndexType>& N1, mtx::Matrix<DataType>& D1,
}
}
/*!
* The main parallelizable body
*/
template<typename MatrixD, typename MatrixI>
void worker_body (std::vector<MatrixD>& corpus_slices,
std::vector<MatrixD>& query_slices,
@@ -109,6 +128,17 @@ void worker_body (std::vector<MatrixD>& corpus_slices,
}
}
/*!
* \param C Is a MxD matrix (Corpus)
* \param Q Is a NxD matrix (Query)
* \param num_slices How many slices to Corpus-Query
* \param k The number of nearest neighbors needed
* \param m accuracy
* \param idx Is the Nxk matrix with the k indexes of the C points, that are
* neighbors of the nth point of Q
* \param dst Is the Nxk matrix with the k distances to the C points of the nth
* point of Q
*/
template<typename MatrixD, typename MatrixI>
void knnsearch(MatrixD& C, MatrixD& Q, size_t num_slices, size_t k, size_t m, MatrixI& idx, MatrixD& dst) {
using DstType = typename MatrixD::dataType;
@@ -147,15 +177,11 @@ void knnsearch(MatrixD& C, MatrixD& Q, size_t num_slices, size_t k, size_t m, Ma
#if defined OMP
#pragma omp parallel for
for (size_t qi = 0; qi < num_slices; ++qi) {
for (size_t qi = 0; qi < num_slices; ++qi) {
worker_body (corpus_slices, query_slices, idx, dst, qi, num_slices, corpus_slice_size, query_slice_size, k, m);
}
}
#elif defined CILK
cilk_for (size_t qi = 0; qi < num_slices; ++qi) {
for (size_t qi = 0; qi < num_slices; ++qi) {
worker_body (corpus_slices, query_slices, idx, dst, qi, num_slices, corpus_slice_size, query_slice_size, k, m);
}
}
#elif defined PTHREADS
std::vector<std::thread> workers;