Skip to content

Commit

Permalink
Fixing a bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
searchivairus committed Feb 9, 2018
1 parent 524883d commit 8d7ab43
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions python_bindings/nmslib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ struct IndexWrapper {
py::array_t<dist_t> temp(input);
std::vector<dist_t> tempVect(temp.data(0), temp.data(0) + temp.size());
auto vectSpacePtr = reinterpret_cast<VectorSpace<dist_t>*>(space.get());
vectSpacePtr->CreateObjFromVect(id, -1, tempVect);
return vectSpacePtr->CreateObjFromVect(id, -1, tempVect);
// This way it will not always work properly
//return new Object(id, -1, temp.size() * sizeof(dist_t), temp.data(0));
}
case DATATYPE_DENSE_UINT8_VECTOR: {
py::array_t<uint8_t> temp(input);
std::vector<uint8_t> tempVect(temp.data(0), temp.data(0) + temp.size());
auto vectSiftPtr = reinterpret_cast<SpaceL2SqrSift*>(space.get());
vectSiftPtr->CreateObjFromUint8Vect(id, -1, tempVect);
return vectSiftPtr->CreateObjFromUint8Vect(id, -1, tempVect);
}
case DATATYPE_OBJECT_AS_STRING: {
std::string temp = py::cast<std::string>(input);
Expand Down Expand Up @@ -681,6 +681,13 @@ void exportLegacyAPI(py::module * m) {
throw py::value_error("Invalid datatype for data in addDataPointBatch");
}
}
if (data_type == DATATYPE_DENSE_UINT8_VECTOR) {
DistType dist_type = py::cast<DistType>(self.attr("distType"));
if (! ((dist_type == DISTTYPE_FLOAT) && (py::isinstance<py::array_t<uint8_t>>(data))) ) {
throw py::value_error("Invalid datatype for data in addDataPointBatch");
}

}

size_t offset = py::len(self);
int insertions = py::cast<int>(self.attr("addDataPointBatch")(data, ids));
Expand Down

0 comments on commit 8d7ab43

Please sign in to comment.