Skip to content

Commit

Permalink
fix build for old GCC versions
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyAv46 committed Jan 5, 2025
1 parent 727b86c commit 8e25f5a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/VecSim/spaces/space_includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95483
#if (__GNUC__ < 11)
#define _mm256_loadu_epi8(ptr) _mm256_maskz_loadu_epi8(~0, ptr)
#define _mm512_loadu_epi8(ptr) _mm512_maskz_loadu_epi8(~0, ptr)
#endif
#elif defined(__clang__)
#include <xmmintrin.h>
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/test_uint8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void UINT8Test::create_index_test(params_t index_params) {
VecSimIndex_AddVector(index, vector, 0);

ASSERT_EQ(VecSimIndex_IndexSize(index), 1);
ASSERT_EQ(index->getDistanceFrom_Unsafe(0, vector), 0);
ASSERT_FLOAT_EQ(index->getDistanceFrom_Unsafe(0, vector), 0);

ASSERT_NO_FATAL_FAILURE(
CompareVectors(static_cast<const uint8_t *>(this->GetDataByInternalId(0)), vector, dim));
Expand Down Expand Up @@ -314,8 +314,8 @@ void UINT8Test::search_by_id_test(params_t index_params) {
// (closest), 51...55
static size_t expected_res_order[] = {45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55};
auto verify_res = [&](size_t id, double score, size_t index) {
ASSERT_EQ(id, expected_res_order[index]); // results are sorted by ID
ASSERT_EQ(score, 4 * (50 - id) * (50 - id)); // L2 distance
ASSERT_EQ(id, expected_res_order[index]); // results are sorted by ID
ASSERT_FLOAT_EQ(score, 4 * (50 - id) * (50 - id)); // L2 distance
};

runTopKSearchTest(index, query, k, verify_res, nullptr, BY_ID);
Expand Down Expand Up @@ -356,7 +356,7 @@ void UINT8Test::search_by_score_test(params_t index_params) {
static size_t expected_res_order[] = {50, 49, 51, 48, 52, 47, 53, 46, 54, 45, 55};
auto verify_res = [&](size_t id, double score, size_t index) {
ASSERT_EQ(id, expected_res_order[index]);
ASSERT_EQ(score, 4 * (50 - id) * (50 - id)); // L2 distance
ASSERT_FLOAT_EQ(score, 4 * (50 - id) * (50 - id)); // L2 distance
};

// Search by score
Expand Down Expand Up @@ -386,7 +386,7 @@ void UINT8Test::metrics_test(params_t index_params) {
double expected_score = 0;

auto verify_res = [&](size_t id, double score, size_t index) {
ASSERT_EQ(score, expected_score) << "failed at vector id:" << id;
ASSERT_DOUBLE_EQ(score, expected_score) << "failed at vector id:" << id;
};

for (size_t i = 0; i < n; i++) {
Expand All @@ -398,7 +398,7 @@ void UINT8Test::metrics_test(params_t index_params) {
auto *index_vector = static_cast<const uint8_t *>(this->GetDataByInternalId(i));
float index_vector_norm = *(reinterpret_cast<const float *>(index_vector + dim));
float vector_norm = spaces::IntegralType_ComputeNorm<uint8_t>(vector, dim);
ASSERT_EQ(index_vector_norm, vector_norm) << "wrong vector norm for vector id:" << i;
ASSERT_FLOAT_EQ(index_vector_norm, vector_norm) << "wrong norm for vector id:" << i;
} else if (metric == VecSimMetric_IP) {
expected_score = UINT8_InnerProduct(vector, vector, dim);
}
Expand Down Expand Up @@ -541,7 +541,7 @@ void UINT8Test::test_override(params_t params) {
ASSERT_EQ(id, new_n - 1 - index) << "id: " << id << " score: " << score;
float diff = new_n - id;
float exp_score = 4 * diff * diff;
ASSERT_EQ(score, exp_score) << "id: " << id << " score: " << score;
ASSERT_FLOAT_EQ(score, exp_score) << "id: " << id << " score: " << score;
};
runTopKSearchTest(index, query, 300, verify_res);
}
Expand Down

0 comments on commit 8e25f5a

Please sign in to comment.