MCPcopy Create free account
hub / github.com/alibaba/zvec / init_impl

Method init_impl

src/core/algorithm/flat/flat_builder.cc:28–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26
27template <size_t BATCH_SIZE>
28int FlatBuilder<BATCH_SIZE>::init_impl(const IndexMeta &meta,
29 const ailego::Params &params,
30 bool verify_metric) {
31 meta_ = meta;
32
33 // Set the major order
34 bool column_major_order = false;
35 if (params.get(PARAM_FLAT_COLUMN_MAJOR_ORDER, &column_major_order)) {
36 meta_.set_major_order(column_major_order ? IndexMeta::MO_COLUMN
37 : IndexMeta::MO_ROW);
38 }
39
40 // Verify column major order
41 if (meta_.major_order() != IndexMeta::MO_ROW) {
42 IndexMeta::DataType dt = meta_.data_type();
43
44 bool support_column_major = false;
45 if ((dt != IndexMeta::DataType::DT_FP32 &&
46 dt != IndexMeta::DataType::DT_FP16 &&
47 dt != IndexMeta::DataType::DT_INT8 && dt != IndexMeta::DT_INT4 &&
48 dt != IndexMeta::DT_BINARY32 && dt != IndexMeta::DT_BINARY64) ||
49 (meta_.unit_size() != IndexMeta::UnitSizeof(dt))) {
50 if (meta_.major_order() == IndexMeta::MO_COLUMN) {
51 LOG_ERROR("Unsupported type %d with unit size %u.", dt,
52 meta_.unit_size());
53 return IndexError_Unsupported;
54 } else {
55 support_column_major = false;
56 }
57 }
58 if (meta_.element_size() % IndexMeta::AlignSizeof(dt) != 0) {
59 if (meta_.major_order() == IndexMeta::MO_COLUMN) {
60 LOG_ERROR("Unsupported type %d with dimension %u.", dt,
61 meta_.dimension());
62 return IndexError_Unsupported;
63 } else {
64 support_column_major = false;
65 }
66 }
67
68 if (meta_.major_order() == IndexMeta::MO_UNDEFINED &&
69 support_column_major) {
70 meta_.set_major_order(IndexMeta::MO_COLUMN);
71 }
72 }
73
74 if (verify_metric && !VerifyMetric(meta_)) {
75 LOG_ERROR("Invalid index measure %s.", meta_.metric_name().c_str());
76 return IndexError_InvalidArgument;
77 }
78
79 std::string tag = std::to_string(BATCH_SIZE);
80 ailego::Params searcher_params;
81 searcher_params.set(PARAM_FLAT_BATCH_SIZE, BATCH_SIZE);
82 meta_.set_searcher("FlatSearcher" + tag, 0, searcher_params);
83 meta_.set_builder("FlatBuilder" + tag, 0, params);
84 return 0;
85}

Callers 1

initMethod · 0.95

Calls 13

VerifyMetricFunction · 0.85
set_major_orderMethod · 0.80
c_strMethod · 0.80
set_builderMethod · 0.80
to_stringFunction · 0.50
getMethod · 0.45
major_orderMethod · 0.45
data_typeMethod · 0.45
unit_sizeMethod · 0.45
element_sizeMethod · 0.45
dimensionMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected