Skip to content

Commit

Permalink
python binding rangeQueries definition
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunjiangZhu committed Oct 24, 2019
1 parent 62d71dd commit 1f71bde
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified python_bindings/.DS_Store
Binary file not shown.
22 changes: 22 additions & 0 deletions python_bindings/nmslib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,23 @@ void exportIndex(py::module * m) {
" A 1D vector of the ids of each nearest neighbour.\n"
"distances: array_like.\n"
" A 1D vector of the distance to each nearest neigbhour.\n")

.def("rangeQuery", &IndexWrapper<dist_t>::rangeQuery,
py::arg("vector"), py::arg("radius") = 0.2,
"Finds the neighbours of a vector in the index, with distance smaller than the radius \n\n"
"Parameters\n"
"----------\n"
"vector: array_like\n"
" A 1D vector to query for.\n"
"radius: float optional\n"
" The radius\n"
"\n"
"Returns\n"
"----------\n"
"ids: array_like.\n"
" A 1D vector of the ids of each nearest neighbour.\n"
"distances: array_like.\n"
" A 1D vector of the distance to each nearest neigbhour.\n")

.def("knnQueryBatch", &IndexWrapper<dist_t>::knnQueryBatch,
py::arg("queries"), py::arg("k") = 10, py::arg("num_threads") = 0,
Expand Down Expand Up @@ -775,6 +792,11 @@ void exportLegacyAPI(py::module * m) {
py::list ids(ret[0]);
return ids;
});
m->def("rangeQuery", [](py::object self, dist_t radius, py::object query) {
py::tuple ret = self.attr("rangeQuery")(query, radius);
py::list ids(ret[0]);
return ids;
});
m->def("getDataPoint", [](py::object self, size_t pos) {
return self.attr("__getitem__")(pos);
});
Expand Down
Binary file modified similarity_search/.DS_Store
Binary file not shown.

0 comments on commit 1f71bde

Please sign in to comment.