| 26 | |
| 27 | template <size_t BATCH_SIZE> |
| 28 | int FlatBuilder<BATCH_SIZE>::init_impl(const IndexMeta &meta, |
| 29 | const ailego::Params ¶ms, |
| 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 | } |
no test coverage detected