-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: LHT129 <[email protected]>
- Loading branch information
Showing
5 changed files
with
204 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
// 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 "bucket_datacell_parameter.h" | ||
|
||
#include <fmt/format-inl.h> | ||
|
||
#include "inner_string_params.h" | ||
|
||
namespace vsag { | ||
BucketDataCellParameter::BucketDataCellParameter() = default; | ||
|
||
void | ||
BucketDataCellParameter::FromJson(const JsonType& json) { | ||
CHECK_ARGUMENT(json.contains(IO_PARAMS_KEY), | ||
fmt::format("bucket interface parameters must contains {}", IO_PARAMS_KEY)); | ||
this->io_parameter_ = IOParameter::GetIOParameterByJson(json[IO_PARAMS_KEY]); | ||
|
||
CHECK_ARGUMENT( | ||
json.contains(QUANTIZATION_PARAMS_KEY), | ||
fmt::format("bucket interface parameters must contains {}", QUANTIZATION_PARAMS_KEY)); | ||
this->quantizer_parameter_ = | ||
QuantizerParameter::GetQuantizerParameterByJson(json[QUANTIZATION_PARAMS_KEY]); | ||
|
||
if (json.contains(BUCKETS_COUNT_KEY)) { | ||
this->buckets_count_ = json[BUCKETS_COUNT_KEY]; | ||
} | ||
} | ||
|
||
JsonType | ||
BucketDataCellParameter::ToJson() { | ||
JsonType json; | ||
json[IO_PARAMS_KEY] = this->io_parameter_->ToJson(); | ||
json[QUANTIZATION_PARAMS_KEY] = this->quantizer_parameter_->ToJson(); | ||
json[BUCKETS_COUNT_KEY] = this->buckets_count_; | ||
return json; | ||
} | ||
} // namespace vsag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
// 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 "io/io_parameter.h" | ||
#include "parameter.h" | ||
#include "quantization/quantizer_parameter.h" | ||
|
||
namespace vsag { | ||
|
||
class BucketDataCellParameter : public Parameter { | ||
public: | ||
explicit BucketDataCellParameter(); | ||
|
||
void | ||
FromJson(const JsonType& json) override; | ||
|
||
JsonType | ||
ToJson() override; | ||
|
||
public: | ||
QuantizerParamPtr quantizer_parameter_{nullptr}; | ||
|
||
IOParamPtr io_parameter_{nullptr}; | ||
|
||
int64_t buckets_count_{1}; | ||
}; | ||
|
||
using BucketDataCellParamPtr = std::shared_ptr<BucketDataCellParameter>; | ||
|
||
} // namespace vsag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
|
||
// 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 "bucket_datacell_parameter.h" | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
|
||
#include "parameter_test.h" | ||
|
||
using namespace vsag; | ||
|
||
TEST_CASE("BucketDataCellParameter ToJson Test", "[ut][BucketDataCellParameter]") { | ||
std::string param_str = R"( | ||
{ | ||
"io_params": { | ||
"type": "memory_io" | ||
}, | ||
"quantization_params": { | ||
"type": "sq8" | ||
}, | ||
"buckets_count": 10 | ||
})"; | ||
auto param = std::make_shared<BucketDataCellParameter>(); | ||
auto json = JsonType::parse(param_str); | ||
param->FromJson(json); | ||
REQUIRE(param->buckets_count_ == 10); | ||
ParameterTest::TestToJson(param); | ||
} | ||
|
||
TEST_CASE("BucketDataCellParameter Parse Exception", "[ut][BucketDataCellParameter]") { | ||
auto check_param = [](const std::string& str) -> BucketDataCellParamPtr { | ||
auto param = std::make_shared<BucketDataCellParameter>(); | ||
auto json = JsonType::parse(str); | ||
param->FromJson(json); | ||
return param; | ||
}; | ||
|
||
SECTION("miss io param") { | ||
std::string param_str = R"( | ||
{ | ||
"quantization_params": { | ||
"type": "sq8", | ||
}, | ||
"buckets_count": 10 | ||
})"; | ||
REQUIRE_THROWS(check_param(param_str)); | ||
} | ||
|
||
SECTION("miss quantization param") { | ||
std::string param_str = R"( | ||
{ | ||
"io_params": { | ||
"type": "memory_io" | ||
}, | ||
"buckets_count": 10 | ||
})"; | ||
REQUIRE_THROWS(check_param(param_str)); | ||
} | ||
|
||
SECTION("wrong io param type") { | ||
std::string param_str = R"( | ||
{ | ||
"io_params": { | ||
"type": "wrong_io" | ||
}, | ||
"buckets_count": 10 | ||
})"; | ||
REQUIRE_THROWS(check_param(param_str)); | ||
} | ||
|
||
SECTION("wrong quantization param type") { | ||
std::string param_str = R"( | ||
{ | ||
"quantization_params": { | ||
"type": "wrong_quantization", | ||
}, | ||
"buckets_count": 10 | ||
})"; | ||
REQUIRE_THROWS(check_param(param_str)); | ||
} | ||
|
||
SECTION("valid on missing buckets_count") { | ||
std::string param_str = R"( | ||
{ | ||
"io_params": { | ||
"type": "memory_io" | ||
}, | ||
"quantization_params": { | ||
"type": "sq8" | ||
} | ||
})"; | ||
auto param = check_param(param_str); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters