Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve coverage rate #330

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/io/memory_block_io_parameter_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

// Copyright 2024-present the vsag project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "memory_block_io_parameter.h"

#include <catch2/catch_test_macros.hpp>

#include "parameter_test.h"

using namespace vsag;

TEST_CASE("memory_block_io_parameter", "[ut][memory_block_io]") {
std::string param_str = "{}";
auto param = std::make_shared<MemoryBlockIOParameter>();
param->FromJson(param_str);
ParameterTest::TestToJson(param);
}
29 changes: 29 additions & 0 deletions src/io/memory_io_parameter_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

// Copyright 2024-present the vsag project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "memory_io_parameter.h"

#include <catch2/catch_test_macros.hpp>

#include "parameter_test.h"

using namespace vsag;

TEST_CASE("memory_io_parameter", "[ut][memory_io]") {
std::string param_str = "{}";
auto param = std::make_shared<MemoryIOParameter>();
param->FromJson(param_str);
ParameterTest::TestToJson(param);
}
33 changes: 33 additions & 0 deletions src/parameter_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

// Copyright 2024-present the vsag project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <catch2/catch_test_macros.hpp>

#include "parameter.h"

namespace vsag {
class ParameterTest {
public:
static void
TestToJson(const ParamPtr& param) {
auto json1 = param->ToJson();
auto str1 = param->ToString();
param->FromJson(json1);
REQUIRE(param->ToString() == str1);
}
};
} // namespace vsag
29 changes: 29 additions & 0 deletions src/quantization/fp32_quantizer_parameter_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

// Copyright 2024-present the vsag project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "fp32_quantizer_parameter.h"

#include <catch2/catch_test_macros.hpp>

#include "parameter_test.h"

using namespace vsag;

TEST_CASE("fp32_quantizer_parameter", "[ut][fp32_quantizer_parameter]") {
std::string param_str = "{}";
auto param = std::make_shared<FP32QuantizerParameter>();
param->FromJson(param_str);
ParameterTest::TestToJson(param);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

// Copyright 2024-present the vsag project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "sq4_quantizer_parameter.h"

#include <catch2/catch_test_macros.hpp>

#include "parameter_test.h"

using namespace vsag;

TEST_CASE("sq4_quantizer_parameter", "[ut][sq4_quantizer_parameter]") {
std::string param_str = "{}";
auto param = std::make_shared<SQ4QuantizerParameter>();
param->FromJson(param_str);
ParameterTest::TestToJson(param);
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ SQ4UniformQuantizer<metric>::ProcessQueryImpl(const DataType* query,
computer.buf_ = reinterpret_cast<uint8_t*>(this->allocator_->Allocate(this->code_size_));
this->EncodeOneImpl(query, computer.buf_);
} catch (const std::bad_alloc& e) {
computer.buf_ = nullptr;
logger::error("bad alloc when init computer buf");
throw std::bad_alloc();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

// Copyright 2024-present the vsag project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "sq4_uniform_quantizer_parameter.h"

#include <catch2/catch_test_macros.hpp>

#include "parameter_test.h"

using namespace vsag;

TEST_CASE("sq4_uniform_quantizer_parameter", "[ut][sq4_uniform_quantizer_parameter]") {
std::string param_str = "{}";
auto param = std::make_shared<SQ4UniformQuantizerParameter>();
param->FromJson(param_str);
ParameterTest::TestToJson(param);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

// Copyright 2024-present the vsag project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "sq8_quantizer_parameter.h"

#include <catch2/catch_test_macros.hpp>

#include "parameter_test.h"

using namespace vsag;

TEST_CASE("sq8_quantizer_parameter", "[ut][sq8_quantizer_parameter]") {
std::string param_str = "{}";
auto param = std::make_shared<SQ8QuantizerParameter>();
param->FromJson(param_str);
ParameterTest::TestToJson(param);
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ SQ8UniformQuantizer<metric>::ProcessQueryImpl(const DataType* query,
computer.buf_ = reinterpret_cast<uint8_t*>(this->allocator_->Allocate(this->code_size_));
this->EncodeOneImpl(query, computer.buf_);
} catch (const std::bad_alloc& e) {
computer.buf_ = nullptr;
logger::error("bad alloc when init computer buf");
throw std::bad_alloc();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

// Copyright 2024-present the vsag project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "sq8_uniform_quantizer_parameter.h"

#include <catch2/catch_test_macros.hpp>

#include "parameter_test.h"

using namespace vsag;

TEST_CASE("sq8_uniform_quantizer_parameter", "[ut][sq8_uniform_quantizer_parameter]") {
std::string param_str = "{}";
auto param = std::make_shared<SQ8UniformQuantizerParameter>();
param->FromJson(param_str);
ParameterTest::TestToJson(param);
}
13 changes: 0 additions & 13 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,13 @@ WindowResultQueue::WindowResultQueue() {
queue_.resize(DEFAULT_WATCH_WINDOW_SIZE);
}

WindowResultQueue::WindowResultQueue(size_t window_size) {
queue_.resize(window_size > 0 ? window_size : DEFAULT_WATCH_WINDOW_SIZE);
}

void
WindowResultQueue::Push(float value) {
size_t window_size = queue_.size();
queue_[count_ % window_size] = value;
count_++;
}

size_t
WindowResultQueue::ResizeWindowSize(size_t new_window_size) {
if (new_window_size > queue_.size()) {
count_ = std::min(count_, queue_.size());
queue_.resize(new_window_size);
}
return queue_.size();
}

float
WindowResultQueue::GetAvgResult() const {
size_t statstic_num = std::min(count_, queue_.size());
Expand Down
5 changes: 0 additions & 5 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,9 @@ class WindowResultQueue {
public:
WindowResultQueue();

explicit WindowResultQueue(size_t window_size);

void
Push(float value);

size_t
ResizeWindowSize(size_t new_window_size_);

[[nodiscard]] float
GetAvgResult() const;

Expand Down
58 changes: 35 additions & 23 deletions tests/test_brute_force.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,26 +297,37 @@ TEST_CASE_PERSISTENT_FIXTURE(fixtures::BruteForceTestIndex,
auto origin_size = vsag::Options::Instance().block_size_limit();
auto size = GENERATE(1024 * 1024 * 2);
auto metric_type = GENERATE("l2", "ip", "cosine");
std::string base_quantization_str = GENERATE("sq8", "fp32");
const std::string name = "brute_force";
auto search_param = "";

for (auto& dim : dims) {
vsag::Options::Instance().set_block_size_limit(size);
auto param =
GenerateBruteForceBuildParametersString(metric_type, dim, base_quantization_str);
auto index = TestFactory(name, param, true);
for (auto& [base_quantization_str, recall] : test_cases) {
vsag::Options::Instance().set_block_size_limit(size);
auto param =
GenerateBruteForceBuildParametersString(metric_type, dim, base_quantization_str);
auto index = TestFactory(name, param, true);

if (index->CheckFeature(vsag::SUPPORT_BUILD)) {
auto dataset = pool.GetDatasetAndCreate(dim, base_count, metric_type);
TestBuildIndex(index, dataset, true);
if (index->CheckFeature(vsag::SUPPORT_SERIALIZE_FILE) and
index->CheckFeature(vsag::SUPPORT_DESERIALIZE_FILE)) {
auto index2 = TestFactory(name, param, true);
TestSerializeFile(index, index2, dataset, search_param, true);
if (index->CheckFeature(vsag::SUPPORT_BUILD)) {
auto dataset = pool.GetDatasetAndCreate(dim, base_count, metric_type);
TestBuildIndex(index, dataset, true);
if (index->CheckFeature(vsag::SUPPORT_SERIALIZE_FILE) and
index->CheckFeature(vsag::SUPPORT_DESERIALIZE_FILE)) {
auto index2 = TestFactory(name, param, true);
TestSerializeFile(index, index2, dataset, search_param, true);
}
if (index->CheckFeature(vsag::SUPPORT_SERIALIZE_BINARY_SET) and
index->CheckFeature(vsag::SUPPORT_DESERIALIZE_BINARY_SET)) {
auto index2 = TestFactory(name, param, true);
TestSerializeBinarySet(index, index2, dataset, search_param, true);
}
if (index->CheckFeature(vsag::SUPPORT_SERIALIZE_FILE) and
index->CheckFeature(vsag::SUPPORT_DESERIALIZE_READER_SET)) {
auto index2 = TestFactory(name, param, true);
TestSerializeReaderSet(index, index2, dataset, search_param, name, true);
}
}
vsag::Options::Instance().set_block_size_limit(origin_size);
}
vsag::Options::Instance().set_block_size_limit(origin_size);
}
}

Expand All @@ -327,20 +338,21 @@ TEST_CASE_PERSISTENT_FIXTURE(fixtures::BruteForceTestIndex,
auto origin_size = vsag::Options::Instance().block_size_limit();
auto size = GENERATE(1024 * 1024 * 2);
auto metric_type = GENERATE("l2", "ip", "cosine");
std::string base_quantization_str = GENERATE("sq8", "fp32");
const std::string name = "brute_force";
for (auto& dim : dims) {
vsag::Options::Instance().set_block_size_limit(size);
auto param =
GenerateBruteForceBuildParametersString(metric_type, dim, base_quantization_str, 1);
auto index = vsag::Factory::CreateIndex(name, param, allocator.get());
if (not index.has_value()) {
continue;
for (auto& [base_quantization_str, recall] : test_cases) {
vsag::Options::Instance().set_block_size_limit(size);
auto param =
GenerateBruteForceBuildParametersString(metric_type, dim, base_quantization_str, 1);
auto index = vsag::Factory::CreateIndex(name, param, allocator.get());
if (not index.has_value()) {
continue;
}
auto dataset = pool.GetDatasetAndCreate(dim, base_count, metric_type);
TestContinueAddIgnoreRequire(index.value(), dataset);
vsag::Options::Instance().set_block_size_limit(origin_size);
}
auto dataset = pool.GetDatasetAndCreate(dim, base_count, metric_type);
TestContinueAddIgnoreRequire(index.value(), dataset);
}
vsag::Options::Instance().set_block_size_limit(origin_size);
}

TEST_CASE_PERSISTENT_FIXTURE(fixtures::BruteForceTestIndex,
Expand Down
Loading
Loading