Skip to content
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
13 changes: 4 additions & 9 deletions src/algorithm/bruteforce/bruteforce_parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include <fmt/format.h>

#include "datacell/flatten_datacell_parameter.h"
#include "impl/logger/logger.h"
#include "inner_string_params.h"
#include "utils/param_compat_macros.h"
#include "vsag/constants.h"

namespace vsag {
Expand Down Expand Up @@ -49,13 +49,8 @@ BruteForceParameter::CheckCompatibility(const ParamPtr& other) const {
if (not InnerIndexParameter::CheckCompatibility(other)) {
return false;
}
auto brute_force_param = std::dynamic_pointer_cast<BruteForceParameter>(other);
if (not brute_force_param) {
logger::error(
"BruteForceParameter::CheckCompatibility: "
"other parameter is not a BruteForceParameter");
return false;
}
return this->base_codes_param->CheckCompatibility(brute_force_param->base_codes_param);
PARAM_CAST_OR_RETURN(BruteForceParameter, p, other);
CHECK_SUB_PARAM(*this, *p, base_codes_param);
return true;
}
} // namespace vsag
59 changes: 18 additions & 41 deletions src/algorithm/hgraph/hgraph_parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "datacell/sparse_vector_datacell_parameter.h"
#include "impl/odescent/odescent_graph_parameter.h"
#include "inner_string_params.h"
#include "utils/param_compat_macros.h"
#include "vsag/constants.h"

namespace vsag {
Expand Down Expand Up @@ -158,55 +159,31 @@ HGraphParameter::ToJson() const {

bool
HGraphParameter::CheckCompatibility(const ParamPtr& other) const {
auto hgraph_param = std::dynamic_pointer_cast<HGraphParameter>(other);
if (hgraph_param == nullptr) {
logger::error("HGraphParameter::CheckCompatibility: other is not HGraphParameter");
return false;
}
PARAM_CAST_OR_RETURN(HGraphParameter, p, other);
auto have_reorder = this->use_reorder && not this->ignore_reorder;
auto have_reorder_other = hgraph_param->use_reorder && not hgraph_param->ignore_reorder;
auto have_reorder_other = p->use_reorder && not p->ignore_reorder;
if (have_reorder != have_reorder_other) {
logger::error(
"HGraphParameter::CheckCompatibility: use_reorder and ignore_reorder must be the same");
return false;
}
if (not this->base_codes_param->CheckCompatibility(hgraph_param->base_codes_param)) {
logger::error("HGraphParameter::CheckCompatibility: base_codes_param is not compatible");
return false;
}
if (have_reorder && this->reorder_source != hgraph_param->reorder_source) {
logger::error("HGraphParameter::CheckCompatibility: reorder_source is not compatible");
return false;
}
if (have_reorder && this->reorder_source != HGRAPH_REORDER_SOURCE_BASE) {
if (not this->precise_codes_param ||
not this->precise_codes_param->CheckCompatibility(hgraph_param->precise_codes_param)) {
logger::error(
"HGraphParameter::CheckCompatibility: precise_codes_param is not compatible");
return false;
CHECK_SUB_PARAM(*this, *p, base_codes_param);
if (have_reorder) {
CHECK_FIELD_EQ(*this, *p, reorder_source);
if (this->reorder_source != HGRAPH_REORDER_SOURCE_BASE) {
if (not this->precise_codes_param ||
not this->precise_codes_param->CheckCompatibility(p->precise_codes_param)) {
logger::error(
"HGraphParameter::CheckCompatibility: precise_codes_param is not compatible");
return false;
}
}
}
if (not this->bottom_graph_param->CheckCompatibility(hgraph_param->bottom_graph_param)) {
logger::error("HGraphParameter::CheckCompatibility: bottom_graph_param is not compatible");
return false;
}
if (use_attribute_filter != hgraph_param->use_attribute_filter) {
logger::error("HGraphParameter::CheckCompatibility: use_attribute_filter must be the same");
return false;
}
if (support_duplicate != hgraph_param->support_duplicate) {
logger::error("HGraphParameter::CheckCompatibility: support_duplicate must be the same");
return false;
}
if (duplicate_distance_threshold != hgraph_param->duplicate_distance_threshold) {
logger::error(
"HGraphParameter::CheckCompatibility: duplicate_distance_threshold must be the same");
return false;
}
if (support_force_remove != hgraph_param->support_force_remove) {
logger::error("HGraphParameter::CheckCompatibility: support_force_remove must be the same");
return false;
}
CHECK_SUB_PARAM(*this, *p, bottom_graph_param);
CHECK_FIELD_EQ(*this, *p, use_attribute_filter);
CHECK_FIELD_EQ(*this, *p, support_duplicate);
CHECK_FIELD_EQ(*this, *p, duplicate_distance_threshold);
CHECK_FIELD_EQ(*this, *p, support_force_remove);
return true;
}

Expand Down
37 changes: 7 additions & 30 deletions src/algorithm/inner_index_parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "datacell/flatten_datacell_parameter.h"
#include "impl/logger/logger.h"
#include "inner_string_params.h"
#include "utils/param_compat_macros.h"
#include "vsag/constants.h"

namespace vsag {
Expand Down Expand Up @@ -145,38 +146,14 @@ InnerIndexParameter::ToJson() const {
}
bool
InnerIndexParameter::CheckCompatibility(const ParamPtr& other) const {
auto inner_index_param = std::dynamic_pointer_cast<InnerIndexParameter>(other);
if (not inner_index_param) {
logger::error(
"InnerIndexParameter::CheckCompatibility: other parameter is not InnerIndexParameter");
return false;
}
if (this->use_reorder != inner_index_param->use_reorder) {
logger::error("InnerIndexParameter::CheckCompatibility: use_reorder mismatch");
return false;
}
if (this->reorder_source != inner_index_param->reorder_source) {
logger::error("InnerIndexParameter::CheckCompatibility: reorder_source mismatch");
return false;
}
PARAM_CAST_OR_RETURN(InnerIndexParameter, p, other);
CHECK_FIELD_EQ(*this, *p, use_reorder);
CHECK_FIELD_EQ(*this, *p, reorder_source);
if (this->use_reorder && this->reorder_source != HGRAPH_REORDER_SOURCE_BASE) {
if (not this->precise_codes_param->CheckCompatibility(
inner_index_param->precise_codes_param)) {
logger::error("InnerIndexParameter::CheckCompatibility: precise_codes_param mismatch");
return false;
}
CHECK_SUB_PARAM(*this, *p, precise_codes_param);
}

if (this->use_attribute_filter != inner_index_param->use_attribute_filter) {
logger::error("InnerIndexParameter::CheckCompatibility: use_attribute_filter mismatch");
return false;
}

if (this->label_remap_type != inner_index_param->label_remap_type) {
logger::error("InnerIndexParameter::CheckCompatibility: label_remap_type mismatch");
return false;
}

CHECK_FIELD_EQ(*this, *p, use_attribute_filter);
CHECK_FIELD_EQ(*this, *p, label_remap_type);
return true;
}
} // namespace vsag
28 changes: 4 additions & 24 deletions src/algorithm/ivf/gno_imi_parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

#include <fmt/format.h>

#include "impl/logger/logger.h"
#include "inner_string_params.h"
#include "utils/param_compat_macros.h"

namespace vsag {

Expand Down Expand Up @@ -49,29 +49,9 @@ GNOIMIParameter::ToJson() const {
}
bool
GNOIMIParameter::CheckCompatibility(const ParamPtr& other) const {
auto gno_imi_param = std::dynamic_pointer_cast<GNOIMIParameter>(other);
if (!gno_imi_param) {
logger::error(
"GNOIMIParameter::CheckCompatibility: "
"other parameter is not GNOIMIParameter");
return false;
}
if (this->first_order_buckets_count != gno_imi_param->first_order_buckets_count) {
logger::error(
"GNOIMIParameter::CheckCompatibility: "
"first_order_buckets_count mismatch: {} != {}",
this->first_order_buckets_count,
gno_imi_param->first_order_buckets_count);
return false;
}
if (this->second_order_buckets_count != gno_imi_param->second_order_buckets_count) {
logger::error(
"GNOIMIParameter::CheckCompatibility: "
"second_order_buckets_count mismatch: {} != {}",
this->second_order_buckets_count,
gno_imi_param->second_order_buckets_count);
return false;
}
PARAM_CAST_OR_RETURN(GNOIMIParameter, p, other);
CHECK_FIELD_EQ(*this, *p, first_order_buckets_count);
CHECK_FIELD_EQ(*this, *p, second_order_buckets_count);
return true;
}
} // namespace vsag
28 changes: 5 additions & 23 deletions src/algorithm/ivf/ivf_parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <fmt/format.h>

#include "inner_string_params.h"
#include "utils/param_compat_macros.h"
#include "vsag/constants.h"
namespace vsag {

Expand Down Expand Up @@ -64,29 +65,10 @@ IVFParameter::CheckCompatibility(const ParamPtr& other) const {
if (not InnerIndexParameter::CheckCompatibility(other)) {
return false;
}
auto ivf_param = std::dynamic_pointer_cast<IVFParameter>(other);
if (not ivf_param) {
logger::error("IVFParameter::CheckCompatibility: other parameter is not IVFParameter");
return false;
}

if (this->buckets_per_data != ivf_param->buckets_per_data) {
logger::error("IVFParameter::CheckCompatibility: buckets_per_data mismatch");
return false;
}

if (not this->bucket_param->CheckCompatibility(ivf_param->bucket_param)) {
logger::error("IVFParameter::CheckCompatibility: bucket_param mismatch");
return false;
}

if (not this->ivf_partition_strategy_parameter->CheckCompatibility(
ivf_param->ivf_partition_strategy_parameter)) {
logger::error(
"IVFParameter::CheckCompatibility: ivf_partition_strategy_parameter "
"mismatch");
return false;
}
PARAM_CAST_OR_RETURN(IVFParameter, p, other);
CHECK_FIELD_EQ(*this, *p, buckets_per_data);
CHECK_SUB_PARAM(*this, *p, bucket_param);
CHECK_SUB_PARAM(*this, *p, ivf_partition_strategy_parameter);
return true;
}

Expand Down
23 changes: 5 additions & 18 deletions src/algorithm/ivf/ivf_partition_strategy_parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

#include <iostream>

#include "impl/logger/logger.h"
#include "inner_string_params.h"
#include "utils/param_compat_macros.h"
#include "vsag/constants.h"

namespace vsag {
Expand Down Expand Up @@ -75,23 +75,10 @@ IVFPartitionStrategyParameters::ToJson() const {

bool
IVFPartitionStrategyParameters::CheckCompatibility(const ParamPtr& other) const {
auto ivf_partition_param = std::dynamic_pointer_cast<IVFPartitionStrategyParameters>(other);
if (not ivf_partition_param) {
logger::error(
"IVFPartitionStrategyParameters::CheckCompatibility: other parameter is not "
"IVFPartitionStrategyParameters");
return false;
}
if (partition_strategy_type != ivf_partition_param->partition_strategy_type) {
std::string message = fmt::format(
"IVFPartitionStrategyParameters::CheckCompatibility: partition strategy type mismatch, "
"this: {}, other: {}",
(int)partition_strategy_type,
(int)ivf_partition_param->partition_strategy_type);
logger::error(message);
return false;
}
return this->gnoimi_param->CheckCompatibility(ivf_partition_param->gnoimi_param);
PARAM_CAST_OR_RETURN(IVFPartitionStrategyParameters, p, other);
CHECK_FIELD_EQ(*this, *p, partition_strategy_type);
CHECK_SUB_PARAM(*this, *p, gnoimi_param);
return true;
}

} // namespace vsag
57 changes: 12 additions & 45 deletions src/algorithm/pyramid/pyramid_zparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "index/diskann_zparameters.h"
#include "io/memory_io_parameter.h"
#include "quantization/fp32_quantizer_parameter.h"
#include "utils/param_compat_macros.h"

// NOLINTBEGIN(readability-simplify-boolean-expr)

Expand Down Expand Up @@ -95,55 +96,21 @@ PyramidParameters::ToJson() const {

bool
PyramidParameters::CheckCompatibility(const ParamPtr& other) const {
auto pyramid_param = std::dynamic_pointer_cast<PyramidParameters>(other);
if (not pyramid_param) {
logger::error(
"PyramidParameters::CheckCompatibility: other parameter is not PyramidParameters");
return false;
}
if (not graph_param->CheckCompatibility(pyramid_param->graph_param)) {
logger::error("PyramidParameters::CheckCompatibility: graph parameters are not compatible");
return false;
}

if (not base_codes_param->CheckCompatibility(pyramid_param->base_codes_param)) {
logger::error(
"PyramidParameters::CheckCompatibility: flatten data cell parameters are not "
"compatible");
return false;
}
if (no_build_levels.size() != pyramid_param->no_build_levels.size() ||
not std::is_permutation(no_build_levels.begin(),
no_build_levels.end(),
pyramid_param->no_build_levels.begin())) {
PARAM_CAST_OR_RETURN(PyramidParameters, p, other);
CHECK_SUB_PARAM(*this, *p, graph_param);
CHECK_SUB_PARAM(*this, *p, base_codes_param);
if (no_build_levels.size() != p->no_build_levels.size() ||
not std::is_permutation(
no_build_levels.begin(), no_build_levels.end(), p->no_build_levels.begin())) {
logger::error("PyramidParameters::CheckCompatibility: no_build_levels are not compatible");
return false;
}

if (pyramid_param->use_reorder != this->use_reorder) {
logger::error(
"PyramidParameters::CheckCompatibility: use_reorder settings are not compatible");
return false;
}

if (this->use_reorder &&
not precise_codes_param->CheckCompatibility(pyramid_param->precise_codes_param)) {
logger::error(
"PyramidParameters::CheckCompatibility: precise_codes_param are not compatible");
return false;
}

if (this->index_min_size != pyramid_param->index_min_size) {
logger::error("PyramidParameters::CheckCompatibility: index_min_size are not compatible");
return false;
}

if (this->support_duplicate != pyramid_param->support_duplicate) {
logger::error(
"PyramidParameters::CheckCompatibility: support_duplicate are not compatible");
return false;
CHECK_FIELD_EQ(*this, *p, use_reorder);
if (this->use_reorder) {
CHECK_SUB_PARAM(*this, *p, precise_codes_param);
}

CHECK_FIELD_EQ(*this, *p, index_min_size);
CHECK_FIELD_EQ(*this, *p, support_duplicate);
return true;
}

Expand Down
Loading
Loading