@@ -14,6 +14,9 @@ using Ctx = tiledb::Context;
1414bool global_debug = true ;
1515double global_time_of_interest;
1616
17+ PYBIND11_MAKE_OPAQUE (std::vector<uint32_t >);
18+ PYBIND11_MAKE_OPAQUE (std::vector<uint64_t >);
19+
1720namespace {
1821
1922
@@ -91,18 +94,19 @@ static void declare_pyarray_to_matrix(py::module& m, const std::string& suffix)
9194 });
9295}
9396
94- template <typename T>
97+ template <typename T, typename Id_Type = uint64_t >
9598static void declare_kmeans_query (py::module & m, const std::string& suffix) {
9699 m.def ((" kmeans_query_" + suffix).c_str (),
97100 [](const ColMajorMatrix<T>& parts,
98101 const ColMajorMatrix<float >& centroids,
99102 const ColMajorMatrix<float >& query_vectors,
100- std::vector<uint64_t >& indices,
101- std::vector<uint64_t >& ids,
103+ std::vector<Id_Type> indices,
104+ std::vector<Id_Type> ids,
102105 size_t nprobe,
103106 size_t k_nn,
104107 bool nth,
105108 size_t nthreads) -> ColMajorMatrix<size_t > { // TODO change return type
109+
106110 auto r = detail::ivf::qv_query_heap_infinite_ram (
107111 parts,
108112 centroids,
@@ -132,8 +136,29 @@ static void declareColMajorMatrixSubclass(py::module& mod,
132136 cls.def (py::init<const Ctx&, std::string, size_t >(), py::keep_alive<1 ,2 >());
133137}
134138
139+ template <typename T>
140+ void declareStdVector (py::module & m) {
141+
142+ auto name = std::string (" IntVector" ) + typeid (T).name ();
143+ py::class_<std::vector<T>>(m, name.c_str (), py::buffer_protocol ())
144+ .def (py::init<>())
145+ .def (" clear" , &std::vector<T>::clear)
146+ .def (" pop_back" , &std::vector<T>::pop_back)
147+ .def (" __len__" , [](const std::vector<T> &v) { return v.size (); })
148+ .def_buffer ([](std::vector<T> &v) -> py::buffer_info {
149+ return py::buffer_info (
150+ v.data (), /* Pointer to buffer */
151+ sizeof (T), /* Size of one scalar */
152+ py::format_descriptor<T>::format (), /* Python struct-style format descriptor */
153+ 1 , /* Number of dimensions */
154+ { v.size () }, /* Buffer dimensions */
155+ { sizeof (T) });
156+ });
135157}
136158
159+ } // anonymous namespace
160+
161+
137162PYBIND11_MODULE (_tiledbvspy, m) {
138163
139164 py::class_<tiledb::Context> (m, " Ctx" , py::module_local ())
@@ -150,14 +175,19 @@ PYBIND11_MODULE(_tiledbvspy, m) {
150175
151176 /* === Vector === */
152177
153- declareVector<uint32_t >(m, " _u32" );
154- declareVector<uint64_t >(m, " _u64" );
155- declareVector<float >(m, " _f32" );
156- declareVector<double >(m, " _f64" );
178+ // Must have matching PYBIND11_MAKE_OPAQUE declaration at top of file
179+ declareStdVector<uint32_t >(m);
180+ declareStdVector<uint64_t >(m);
157181
158182 m.def (" read_vector_u32" , &read_vector<uint32_t >, " Read a vector from TileDB" );
159183 m.def (" read_vector_u64" , &read_vector<uint64_t >, " Read a vector from TileDB" );
160184
185+ m.def (" _create_vector_u64" , []() {
186+ auto v = std::vector<uint64_t >(10 );
187+ // fill vector with range 1:10 using std::iota
188+ std::iota (v.begin (), v.begin () + 10 , 0 );
189+ return v;
190+ });
161191
162192 /* === Matrix === */
163193
0 commit comments