Skip to content

Commit

Permalink
Ran automatic formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpryce committed Nov 3, 2023
1 parent ee31c1f commit 5262adb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 38 deletions.
64 changes: 31 additions & 33 deletions python/src/builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,12 @@ template void build_disk_index<int8_t>(diskann::Metric, const std::string &, con
double, double, uint32_t, uint32_t);

template <typename T, typename TagT, typename LabelT>
std::string prepare_filtered_label_map(
diskann::Index<T, TagT, LabelT>& index,
const std::string& index_output_path,
const std::string& filter_labels_file,
const std::string& universal_label
) {
std::string prepare_filtered_label_map(diskann::Index<T, TagT, LabelT> &index, const std::string &index_output_path,
const std::string &filter_labels_file, const std::string &universal_label)
{
std::string labels_file_to_use = index_output_path + "_label_formatted.txt";
std::string mem_labels_int_map_file = index_output_path + "_labels_map.txt";
convert_labels_string_to_int(filter_labels_file, labels_file_to_use,
mem_labels_int_map_file, universal_label);
convert_labels_string_to_int(filter_labels_file, labels_file_to_use, mem_labels_int_map_file, universal_label);
if (!universal_label.empty())
{
uint32_t unv_label_as_num = 0;
Expand All @@ -50,27 +46,21 @@ std::string prepare_filtered_label_map(
return labels_file_to_use;
}

template std::string prepare_filtered_label_map<float>(diskann::Index<float, uint32_t, uint32_t>&,
const std::string&,
const std::string&,
const std::string&);
template std::string prepare_filtered_label_map<float>(diskann::Index<float, uint32_t, uint32_t> &, const std::string &,
const std::string &, const std::string &);

template std::string prepare_filtered_label_map<int8_t>(diskann::Index<int8_t, uint32_t, uint32_t>&,
const std::string&,
const std::string&,
const std::string&);
template std::string prepare_filtered_label_map<int8_t>(diskann::Index<int8_t, uint32_t, uint32_t> &,
const std::string &, const std::string &, const std::string &);

template std::string prepare_filtered_label_map<uint8_t>(diskann::Index<uint8_t, uint32_t, uint32_t>&,
const std::string&,
const std::string&,
const std::string&);
template std::string prepare_filtered_label_map<uint8_t>(diskann::Index<uint8_t, uint32_t, uint32_t> &,
const std::string &, const std::string &, const std::string &);

template <typename T, typename TagT, typename LabelT>
void build_memory_index(const diskann::Metric metric, const std::string &vector_bin_path,
const std::string &index_output_path, const uint32_t graph_degree, const uint32_t complexity,
const float alpha, const uint32_t num_threads, const bool use_pq_build,
const size_t num_pq_bytes, const bool use_opq, const bool use_tags,
const std::string& filter_labels_file, const std::string& universal_label,
const std::string &filter_labels_file, const std::string &universal_label,
const uint32_t filter_complexity)
{
diskann::IndexWriteParameters index_build_params = diskann::IndexWriteParametersBuilder(complexity, graph_degree)
Expand Down Expand Up @@ -100,19 +90,27 @@ void build_memory_index(const diskann::Metric metric, const std::string &vector_
size_t tag_dims = 1;
diskann::load_bin(tags_file, tags_data, data_num, tag_dims);
std::vector<TagT> tags(tags_data, tags_data + data_num);
if (filter_labels_file.empty()) {
if (filter_labels_file.empty())
{
index.build(vector_bin_path.c_str(), data_num, tags);
} else {
auto labels_file = prepare_filtered_label_map<T, TagT, LabelT>(index, index_output_path, filter_labels_file, universal_label);
}
else
{
auto labels_file = prepare_filtered_label_map<T, TagT, LabelT>(index, index_output_path, filter_labels_file,
universal_label);
index.build_filtered_index(vector_bin_path.c_str(), labels_file, data_num, tags);
}
}
else
{
if (filter_labels_file.empty()) {
if (filter_labels_file.empty())
{
index.build(vector_bin_path.c_str(), data_num);
} else {
auto labels_file = prepare_filtered_label_map<T, TagT, LabelT>(index, index_output_path, filter_labels_file, universal_label);
}
else
{
auto labels_file = prepare_filtered_label_map<T, TagT, LabelT>(index, index_output_path, filter_labels_file,
universal_label);
index.build_filtered_index(vector_bin_path.c_str(), labels_file, data_num);
}
}
Expand All @@ -121,15 +119,15 @@ void build_memory_index(const diskann::Metric metric, const std::string &vector_
}

template void build_memory_index<float>(diskann::Metric, const std::string &, const std::string &, uint32_t, uint32_t,
float, uint32_t, bool, size_t, bool,bool, const std::string&,
const std::string&, uint32_t);
float, uint32_t, bool, size_t, bool, bool, const std::string &,
const std::string &, uint32_t);

template void build_memory_index<int8_t>(diskann::Metric, const std::string &, const std::string &, uint32_t, uint32_t,
float, uint32_t, bool, size_t, bool, bool, const std::string&,
const std::string&, uint32_t);
float, uint32_t, bool, size_t, bool, bool, const std::string &,
const std::string &, uint32_t);

template void build_memory_index<uint8_t>(diskann::Metric, const std::string &, const std::string &, uint32_t, uint32_t,
float, uint32_t, bool, size_t, bool, bool, const std::string&,
const std::string&, uint32_t);
float, uint32_t, bool, size_t, bool, bool, const std::string &,
const std::string &, uint32_t);

} // namespace diskannpy
4 changes: 2 additions & 2 deletions python/src/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ template <typename T> inline void add_variant(py::module_ &m, const Variant &var

m.def(variant.memory_builder_name.c_str(), &diskannpy::build_memory_index<T>, "distance_metric"_a,
"data_file_path"_a, "index_output_path"_a, "graph_degree"_a, "complexity"_a, "alpha"_a, "num_threads"_a,
"use_pq_build"_a, "num_pq_bytes"_a, "use_opq"_a, "use_tags"_a = false,
"filter_labels_file"_a = "", "universal_label"_a = "", "filter_complexity"_a = 0);
"use_pq_build"_a, "num_pq_bytes"_a, "use_opq"_a, "use_tags"_a = false, "filter_labels_file"_a = "",
"universal_label"_a = "", "filter_complexity"_a = 0);

py::class_<diskannpy::StaticMemoryIndex<T>>(m, variant.static_memory_index_name.c_str())
.def(py::init<const diskann::Metric, const std::string &, const size_t, const size_t, const uint32_t,
Expand Down
5 changes: 2 additions & 3 deletions python/src/static_memory_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ NeighborsAndDistances<StaticIdType> StaticMemoryIndex<DT>::search(

template <typename DT>
NeighborsAndDistances<StaticIdType> StaticMemoryIndex<DT>::search_with_filter(
py::array_t<DT, py::array::c_style | py::array::forcecast> &query,
const uint64_t knn, const uint64_t complexity, const filterT filter
)
py::array_t<DT, py::array::c_style | py::array::forcecast> &query, const uint64_t knn, const uint64_t complexity,
const filterT filter)
{
py::array_t<StaticIdType> ids(knn);
py::array_t<float> dists(knn);
Expand Down

0 comments on commit 5262adb

Please sign in to comment.