| 756 | } |
| 757 | |
| 758 | void batchInsert( |
| 759 | py::array_t<double> objects, |
| 760 | bool debug = false |
| 761 | ) { |
| 762 | py::buffer_info info = objects.request(); |
| 763 | if (debug) { |
| 764 | std::cerr << info.shape.size() << ":" << info.shape[0] << ":" << info.shape[1] << std::endl; |
| 765 | } |
| 766 | if ((objects.flags() & py::detail::npy_api::constants::NPY_ARRAY_C_CONTIGUOUS_) == 0) { |
| 767 | std::stringstream msg; |
| 768 | msg << "ngtpy::batchInsert: Error! The array order is not C type. " << static_cast<int>(objects.flags()) |
| 769 | << ":" << static_cast<int>(py::detail::npy_api::constants::NPY_ARRAY_C_CONTIGUOUS_); |
| 770 | NGTThrowException(msg); |
| 771 | } |
| 772 | auto ptr = static_cast<double *>(info.ptr); |
| 773 | assert(info.shape.size() == 2); |
| 774 | for (int idx = 0; idx < info.shape[0]; idx++) { |
| 775 | if (debug) { |
| 776 | for (int i = 0; i < info.shape[1]; i++) { |
| 777 | std::cerr << *(ptr + i) << " "; |
| 778 | } |
| 779 | std::cerr << std::endl; |
| 780 | } |
| 781 | std::vector<float> v(ptr, ptr + info.shape[1]); |
| 782 | ptr += info.shape[1]; |
| 783 | QBG::Index::append(v); |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | py::array_t<uint32_t> batchSearchTmp( |
| 788 | py::array_t<float> queries, |