107 lines
1.8 KiB
C++
107 lines
1.8 KiB
C++
#include "knn_opencl.h"
|
|
|
|
#include <cmath>
|
|
#include <iostream>
|
|
#include <vector>
|
|
|
|
int main()
|
|
{
|
|
const std::vector<float> database = {
|
|
1.0f, 0.0f,
|
|
0.0f, 1.0f,
|
|
0.70710678f, 0.70710678f,
|
|
};
|
|
|
|
const std::vector<float> queries = {
|
|
1.0f, 0.0f,
|
|
0.0f, 1.0f,
|
|
};
|
|
|
|
face_knn::SearchOptions options;
|
|
|
|
options.dimension = 2;
|
|
options.top_k = 2;
|
|
|
|
const auto output =
|
|
face_knn::search_cpu(
|
|
database,
|
|
queries,
|
|
3,
|
|
2,
|
|
options
|
|
);
|
|
|
|
const auto first =
|
|
face_knn::query_neighbors(
|
|
output,
|
|
0
|
|
);
|
|
|
|
const auto second =
|
|
face_knn::query_neighbors(
|
|
output,
|
|
1
|
|
);
|
|
|
|
if (
|
|
first.size() != 2
|
|
|| second.size() != 2
|
|
) {
|
|
std::cerr
|
|
<< "Numero vicini errato\n";
|
|
|
|
return 1;
|
|
}
|
|
|
|
if (
|
|
first[0].index != 0
|
|
|| second[0].index != 1
|
|
) {
|
|
std::cerr
|
|
<< "Top-1 errato\n";
|
|
|
|
return 1;
|
|
}
|
|
|
|
if (
|
|
std::fabs(first[0].score - 1.0f)
|
|
> 0.000001f
|
|
|| std::fabs(second[0].score - 1.0f)
|
|
> 0.000001f
|
|
) {
|
|
std::cerr
|
|
<< "Score top-1 errato\n";
|
|
|
|
return 1;
|
|
}
|
|
|
|
const auto filtered =
|
|
face_knn::exclude_neighbor(
|
|
first,
|
|
0
|
|
);
|
|
|
|
if (
|
|
filtered.empty()
|
|
|| filtered[0].index != 2
|
|
) {
|
|
std::cerr
|
|
<< "Leave-one-out errato\n";
|
|
|
|
return 1;
|
|
}
|
|
|
|
std::cout
|
|
<< "OK: backend CPU dinamico\n"
|
|
<< "query_count="
|
|
<< output.query_count
|
|
<< "\n"
|
|
<< "database_count="
|
|
<< output.database_count
|
|
<< "\n"
|
|
<< "top_k="
|
|
<< output.top_k
|
|
<< "\n";
|
|
|
|
return 0;
|
|
}
|