From 36978a68c2f6a85f8a264733a6947b8c1c1bb2b7 Mon Sep 17 00:00:00 2001 From: Paris Morgan Date: Tue, 15 Oct 2024 12:32:13 -0700 Subject: [PATCH] Add start, stop, and temporal_policy to FeatureVector and FeatureVectorArray (#549) --- .../src/tiledb/vector_search/ingestion.py | 7 +- .../vector_search/type_erased_module.cc | 27 ++++-- src/include/api/feature_vector.h | 46 +++++++--- src/include/api/feature_vector_array.h | 84 +++++++++++-------- src/include/detail/linalg/tdb_vector.h | 12 ++- src/include/detail/linalg/vector.h | 14 ++-- src/include/test/unit_api_feature_vector.cc | 10 +++ .../test/unit_api_feature_vector_array.cc | 24 +++++- src/include/test/unit_api_flat_l2_index.cc | 2 +- src/include/test/utils/set_seed_from_catch.h | 2 +- 10 files changed, 163 insertions(+), 65 deletions(-) diff --git a/apis/python/src/tiledb/vector_search/ingestion.py b/apis/python/src/tiledb/vector_search/ingestion.py index 6131c0732..e8b221e3b 100644 --- a/apis/python/src/tiledb/vector_search/ingestion.py +++ b/apis/python/src/tiledb/vector_search/ingestion.py @@ -1661,7 +1661,12 @@ def ingest_type_erased( ctx = vspy.Ctx(config) data = vspy.FeatureVectorArray( - ctx, parts_array_uri, ids_array_uri, 0, to_temporal_policy(index_timestamp) + ctx, + parts_array_uri, + ids_array_uri, + 0, # first_col + 0, # last_col + to_temporal_policy(index_timestamp), ) if index_type == "VAMANA": index = vspy.IndexVamana(ctx, index_group_uri) diff --git a/apis/python/src/tiledb/vector_search/type_erased_module.cc b/apis/python/src/tiledb/vector_search/type_erased_module.cc index e323ef979..0933f2ac6 100644 --- a/apis/python/src/tiledb/vector_search/type_erased_module.cc +++ b/apis/python/src/tiledb/vector_search/type_erased_module.cc @@ -182,9 +182,22 @@ void init_type_erased_module(py::module_& m) { py::class_(m, "FeatureVector", py::buffer_protocol()) .def( - py::init(), - py::keep_alive<1, 2>() // IndexIVFFlat should keep ctx alive. - ) + "__init__", + [](FeatureVector& instance, + const tiledb::Context& ctx, + const std::string& uri, + size_t first_col, + size_t last_col, + std::optional temporal_policy) { + new (&instance) + FeatureVector(ctx, uri, first_col, last_col, temporal_policy); + }, + py::keep_alive<1, 2>(), + py::arg("ctx"), + py::arg("uri"), + py::arg("first_col") = 0, + py::arg("last_col") = 0, + py::arg("temporal_policy") = std::nullopt) .def(py::init()) .def(py::init()) .def("dimensions", &FeatureVector::dimensions) @@ -244,16 +257,18 @@ void init_type_erased_module(py::module_& m) { const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, - size_t num_vectors, + size_t first_col, + size_t last_col, std::optional temporal_policy) { new (&instance) FeatureVectorArray( - ctx, uri, ids_uri, num_vectors, temporal_policy); + ctx, uri, ids_uri, first_col, last_col, temporal_policy); }, py::keep_alive<1, 2>(), // FeatureVectorArray should keep ctx alive. py::arg("ctx"), py::arg("uri"), py::arg("ids_uri") = "", - py::arg("num_vectors") = 0, + py::arg("first_col") = 0, + py::arg("last_col") = 0, py::arg("temporal_policy") = std::nullopt) .def(py::init()) .def("dimensions", &FeatureVectorArray::dimensions) diff --git a/src/include/api/feature_vector.h b/src/include/api/feature_vector.h index a53609a2a..7e33d977e 100644 --- a/src/include/api/feature_vector.h +++ b/src/include/api/feature_vector.h @@ -86,13 +86,20 @@ class FeatureVector { * @param ctx * @param uri */ - FeatureVector(const tiledb::Context& ctx, const std::string& uri) { - auto array = tiledb_helpers::open_array(tdb_func__, ctx, uri, TILEDB_READ); + FeatureVector( + const tiledb::Context& ctx, + const std::string& uri, + size_t start = 0, + size_t end = 0, + std::optional temporal_policy_input = std::nullopt) { + auto temporal_policy = temporal_policy_input.value_or(TemporalPolicy{}); + auto array = tiledb_helpers::open_array( + tdb_func__, ctx, uri, TILEDB_READ, temporal_policy); feature_type_ = get_array_datatype(*array); array->close(); - tdb_vector_from_datatype(ctx, uri); + tdb_vector_from_datatype(ctx, uri, start, end, temporal_policy); } /* @@ -126,25 +133,35 @@ class FeatureVector { * Dispatch to the appropriate concrete class based on the datatype. */ void tdb_vector_from_datatype( - const tiledb::Context& ctx, const std::string& uri) { + const tiledb::Context& ctx, + const std::string& uri, + size_t start, + size_t end, + TemporalPolicy temporal_policy) { switch (feature_type_) { case TILEDB_FLOAT32: - vector_ = std::make_unique>>(ctx, uri); + vector_ = std::make_unique>>( + ctx, uri, start, end, temporal_policy); break; case TILEDB_INT8: - vector_ = std::make_unique>>(ctx, uri); + vector_ = std::make_unique>>( + ctx, uri, start, end, temporal_policy); break; case TILEDB_UINT8: - vector_ = std::make_unique>>(ctx, uri); + vector_ = std::make_unique>>( + ctx, uri, start, end, temporal_policy); break; case TILEDB_INT32: - vector_ = std::make_unique>>(ctx, uri); + vector_ = std::make_unique>>( + ctx, uri, start, end, temporal_policy); break; case TILEDB_UINT32: - vector_ = std::make_unique>>(ctx, uri); + vector_ = std::make_unique>>( + ctx, uri, start, end, temporal_policy); break; case TILEDB_UINT64: - vector_ = std::make_unique>>(ctx, uri); + vector_ = std::make_unique>>( + ctx, uri, start, end, temporal_policy); break; default: throw std::runtime_error("Unsupported attribute type"); @@ -202,8 +219,13 @@ class FeatureVector { explicit vector_impl(size_t size) : vector_(size) { } - vector_impl(const tiledb::Context& ctx, const std::string& uri) - : vector_(ctx, uri) { + vector_impl( + const tiledb::Context& ctx, + const std::string& uri, + size_t start, + size_t end, + TemporalPolicy temporal_policy) + : vector_(ctx, uri, start, end, temporal_policy) { } //[[nodiscard]] void* data() override { // return _cpo::data(vector_); diff --git a/src/include/api/feature_vector_array.h b/src/include/api/feature_vector_array.h index c19ae8af4..b898934f9 100644 --- a/src/include/api/feature_vector_array.h +++ b/src/include/api/feature_vector_array.h @@ -83,7 +83,8 @@ class FeatureVectorArray { const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri = "", - size_t num_vectors = 0, + size_t first_col = 0, + size_t last_col = 0, std::optional temporal_policy_input = std::nullopt) { auto temporal_policy = temporal_policy_input.value_or(TemporalPolicy{}); auto array = tiledb_helpers::open_array( @@ -105,7 +106,7 @@ class FeatureVectorArray { throw std::runtime_error("Unsupported features attribute type"); } vector_array = tdb_col_major_matrix_dispatch_table.at(feature_type_)( - ctx, uri, num_vectors, temporal_policy); + ctx, uri, first_col, last_col, temporal_policy); } else { auto ids_array = tiledb_helpers::open_array( tdb_func__, ctx, ids_uri, TILEDB_READ, temporal_policy); @@ -120,7 +121,7 @@ class FeatureVectorArray { "Unsupported attribute type for feature vector with ids"); } vector_array = tdb_col_major_matrix_with_ids_dispatch_table.at(type)( - ctx, uri, ids_uri, num_vectors, temporal_policy); + ctx, uri, ids_uri, first_col, last_col, temporal_policy); } (void)vector_array->load(); } @@ -224,23 +225,40 @@ class FeatureVectorArray { struct vector_array_impl : vector_array_base { explicit vector_array_impl(T&& t) : impl_vector_array(std::forward(t)) { - // explicit vector_array_impl(const T& t) - // : impl_vector_array(t) { } vector_array_impl( const tiledb::Context& ctx, const std::string& uri, - size_t num_vectors, + size_t first_col, + size_t last_col, TemporalPolicy temporal_policy) - : impl_vector_array(ctx, uri, num_vectors, temporal_policy) { + : impl_vector_array( + ctx, + uri, + 0, + std::nullopt, + first_col, + last_col != 0 ? std::optional(last_col) : std::nullopt, + 0, + temporal_policy) { } vector_array_impl( const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, - size_t num_vectors, + size_t first_col, + size_t last_col, TemporalPolicy temporal_policy) - : impl_vector_array(ctx, uri, ids_uri, num_vectors, temporal_policy) { + : impl_vector_array( + ctx, + uri, + ids_uri, + 0, + std::nullopt, + first_col, + last_col != 0 ? std::optional(last_col) : std::nullopt, + 0, + temporal_policy) { } vector_array_impl(size_t rows, size_t cols) : impl_vector_array(rows, cols) { @@ -277,7 +295,7 @@ class FeatureVectorArray { using col_major_matrix_table_type = std::map; static const col_major_matrix_table_type col_major_matrix_dispatch_table; - using tdb_col_major_matrix_constructor_function = std::function(const tiledb::Context&, const std::string&, size_t, TemporalPolicy)>; + using tdb_col_major_matrix_constructor_function = std::function(const tiledb::Context&, const std::string&, size_t, size_t, TemporalPolicy)>; using tdb_col_major_matrix_table_type = std::map; static const tdb_col_major_matrix_table_type tdb_col_major_matrix_dispatch_table; @@ -285,7 +303,7 @@ class FeatureVectorArray { using col_major_matrix_with_ids_table_type = std::map, col_major_matrix_with_ids_constructor_function>; static const col_major_matrix_with_ids_table_type col_major_matrix_with_ids_dispatch_table; - using tdb_col_major_matrix_with_ids_constructor_function = std::function(const tiledb::Context&, const std::string&, const std::string&, size_t, TemporalPolicy)>; + using tdb_col_major_matrix_with_ids_constructor_function = std::function(const tiledb::Context&, const std::string&, const std::string&, size_t, size_t, TemporalPolicy)>; using tdb_col_major_matrix_with_ids_table_type = std::map, tdb_col_major_matrix_with_ids_constructor_function>; static const tdb_col_major_matrix_with_ids_table_type tdb_col_major_matrix_with_ids_dispatch_table; // clang-format on @@ -312,13 +330,13 @@ const FeatureVectorArray::col_major_matrix_table_type FeatureVectorArray::col_ma }; const FeatureVectorArray::tdb_col_major_matrix_table_type FeatureVectorArray::tdb_col_major_matrix_dispatch_table = { - {TILEDB_FLOAT32, [](const tiledb::Context& ctx, const std::string& uri, size_t num_vectors, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, num_vectors, temporal_policy); }}, - {TILEDB_INT8, [](const tiledb::Context& ctx, const std::string& uri, size_t num_vectors, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, num_vectors, temporal_policy); }}, - {TILEDB_UINT8, [](const tiledb::Context& ctx, const std::string& uri, size_t num_vectors, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, num_vectors, temporal_policy); }}, - {TILEDB_INT32, [](const tiledb::Context& ctx, const std::string& uri, size_t num_vectors, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, num_vectors, temporal_policy); }}, - {TILEDB_UINT32, [](const tiledb::Context& ctx, const std::string& uri, size_t num_vectors, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, num_vectors, temporal_policy); }}, - {TILEDB_INT64, [](const tiledb::Context& ctx, const std::string& uri, size_t num_vectors, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, num_vectors, temporal_policy); }}, - {TILEDB_UINT64, [](const tiledb::Context& ctx, const std::string& uri, size_t num_vectors, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, num_vectors, temporal_policy); }}, + {TILEDB_FLOAT32, [](const tiledb::Context& ctx, const std::string& uri, size_t first_col, size_t last_col, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, first_col, last_col, temporal_policy); }}, + {TILEDB_INT8, [](const tiledb::Context& ctx, const std::string& uri, size_t first_col, size_t last_col, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, first_col, last_col, temporal_policy); }}, + {TILEDB_UINT8, [](const tiledb::Context& ctx, const std::string& uri, size_t first_col, size_t last_col, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, first_col, last_col, temporal_policy); }}, + {TILEDB_INT32, [](const tiledb::Context& ctx, const std::string& uri, size_t first_col, size_t last_col, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, first_col, last_col, temporal_policy); }}, + {TILEDB_UINT32, [](const tiledb::Context& ctx, const std::string& uri, size_t first_col, size_t last_col, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, first_col, last_col, temporal_policy); }}, + {TILEDB_INT64, [](const tiledb::Context& ctx, const std::string& uri, size_t first_col, size_t last_col, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, first_col, last_col, temporal_policy); }}, + {TILEDB_UINT64, [](const tiledb::Context& ctx, const std::string& uri, size_t first_col, size_t last_col, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, first_col, last_col, temporal_policy); }}, }; const FeatureVectorArray::col_major_matrix_with_ids_table_type FeatureVectorArray::col_major_matrix_with_ids_dispatch_table = { @@ -340,21 +358,21 @@ const FeatureVectorArray::col_major_matrix_with_ids_table_type FeatureVectorArra }; const FeatureVectorArray::tdb_col_major_matrix_with_ids_table_type FeatureVectorArray::tdb_col_major_matrix_with_ids_dispatch_table = { - {{TILEDB_FLOAT32, TILEDB_UINT32},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t num_vectors, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, ids_uri, num_vectors, temporal_policy);}}, - {{TILEDB_INT8, TILEDB_UINT32},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t num_vectors, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, ids_uri, num_vectors, temporal_policy);}}, - {{TILEDB_UINT8, TILEDB_UINT32},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t num_vectors, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, ids_uri, num_vectors, temporal_policy);}}, - {{TILEDB_INT32, TILEDB_UINT32},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t num_vectors, TemporalPolicy temporal_policy) {return std::make_unique>>(ctx, uri, ids_uri, num_vectors, temporal_policy);}}, - {{TILEDB_UINT32, TILEDB_UINT32},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t num_vectors, TemporalPolicy temporal_policy) {return std::make_unique>>(ctx, uri, ids_uri, num_vectors, temporal_policy);}}, - {{TILEDB_INT64, TILEDB_UINT32},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t num_vectors, TemporalPolicy temporal_policy) {return std::make_unique>>(ctx, uri, ids_uri, num_vectors, temporal_policy);}}, - {{TILEDB_UINT64, TILEDB_UINT32},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t num_vectors, TemporalPolicy temporal_policy) {return std::make_unique>>(ctx, uri, ids_uri, num_vectors, temporal_policy);}}, - - {{TILEDB_FLOAT32, TILEDB_UINT64},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t num_vectors, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, ids_uri, num_vectors, temporal_policy);}}, - {{TILEDB_INT8, TILEDB_UINT64},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t num_vectors, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, ids_uri, num_vectors, temporal_policy);}}, - {{TILEDB_UINT8, TILEDB_UINT64},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t num_vectors, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, ids_uri, num_vectors, temporal_policy);}}, - {{TILEDB_INT32, TILEDB_UINT64},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t num_vectors, TemporalPolicy temporal_policy) {return std::make_unique>>(ctx, uri, ids_uri, num_vectors, temporal_policy);}}, - {{TILEDB_UINT32, TILEDB_UINT64},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t num_vectors, TemporalPolicy temporal_policy) {return std::make_unique>>(ctx, uri, ids_uri, num_vectors, temporal_policy);}}, - {{TILEDB_INT64, TILEDB_UINT64},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t num_vectors, TemporalPolicy temporal_policy) {return std::make_unique>>(ctx, uri, ids_uri, num_vectors, temporal_policy);}}, - {{TILEDB_UINT64, TILEDB_UINT64},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t num_vectors, TemporalPolicy temporal_policy) {return std::make_unique>>(ctx, uri, ids_uri, num_vectors, temporal_policy);}}, + {{TILEDB_FLOAT32, TILEDB_UINT32},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t first_col, size_t last_col, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, ids_uri, first_col, last_col, temporal_policy);}}, + {{TILEDB_INT8, TILEDB_UINT32},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t first_col, size_t last_col, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, ids_uri, first_col, last_col, temporal_policy);}}, + {{TILEDB_UINT8, TILEDB_UINT32},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t first_col, size_t last_col, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, ids_uri, first_col, last_col, temporal_policy);}}, + {{TILEDB_INT32, TILEDB_UINT32},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t first_col, size_t last_col, TemporalPolicy temporal_policy) {return std::make_unique>>(ctx, uri, ids_uri, first_col, last_col, temporal_policy);}}, + {{TILEDB_UINT32, TILEDB_UINT32},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t first_col, size_t last_col, TemporalPolicy temporal_policy) {return std::make_unique>>(ctx, uri, ids_uri, first_col, last_col, temporal_policy);}}, + {{TILEDB_INT64, TILEDB_UINT32},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t first_col, size_t last_col, TemporalPolicy temporal_policy) {return std::make_unique>>(ctx, uri, ids_uri, first_col, last_col, temporal_policy);}}, + {{TILEDB_UINT64, TILEDB_UINT32},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t first_col, size_t last_col, TemporalPolicy temporal_policy) {return std::make_unique>>(ctx, uri, ids_uri, first_col, last_col, temporal_policy);}}, + + {{TILEDB_FLOAT32, TILEDB_UINT64},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t first_col, size_t last_col, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, ids_uri, first_col, last_col, temporal_policy);}}, + {{TILEDB_INT8, TILEDB_UINT64},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t first_col, size_t last_col, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, ids_uri, first_col, last_col, temporal_policy);}}, + {{TILEDB_UINT8, TILEDB_UINT64},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t first_col, size_t last_col, TemporalPolicy temporal_policy) { return std::make_unique>>(ctx, uri, ids_uri, first_col, last_col, temporal_policy);}}, + {{TILEDB_INT32, TILEDB_UINT64},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t first_col, size_t last_col, TemporalPolicy temporal_policy) {return std::make_unique>>(ctx, uri, ids_uri, first_col, last_col, temporal_policy);}}, + {{TILEDB_UINT32, TILEDB_UINT64},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t first_col, size_t last_col, TemporalPolicy temporal_policy) {return std::make_unique>>(ctx, uri, ids_uri, first_col, last_col, temporal_policy);}}, + {{TILEDB_INT64, TILEDB_UINT64},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t first_col, size_t last_col, TemporalPolicy temporal_policy) {return std::make_unique>>(ctx, uri, ids_uri, first_col, last_col, temporal_policy);}}, + {{TILEDB_UINT64, TILEDB_UINT64},[](const tiledb::Context& ctx, const std::string& uri, const std::string& ids_uri, size_t first_col, size_t last_col, TemporalPolicy temporal_policy) {return std::make_unique>>(ctx, uri, ids_uri, first_col, last_col, temporal_policy);}}, }; // clang-format on diff --git a/src/include/detail/linalg/tdb_vector.h b/src/include/detail/linalg/tdb_vector.h index e860cf995..1a7ca3566 100644 --- a/src/include/detail/linalg/tdb_vector.h +++ b/src/include/detail/linalg/tdb_vector.h @@ -47,8 +47,16 @@ class tdbVector : public Vector { using Base::Base; public: - tdbVector(const tiledb::Context& ctx, const std::string& uri) - : Base(read_vector(ctx, uri)) { + tdbVector( + const tiledb::Context& ctx, + const std::string& uri, + size_t start, + size_t end, + TemporalPolicy temporal_policy) + : Base( + (start == 0 && end == 0) ? + read_vector(ctx, uri, temporal_policy) : + read_vector(ctx, uri, start, end, temporal_policy)) { } }; diff --git a/src/include/detail/linalg/vector.h b/src/include/detail/linalg/vector.h index 2f4b67709..06ac9dcbc 100644 --- a/src/include/detail/linalg/vector.h +++ b/src/include/detail/linalg/vector.h @@ -44,11 +44,11 @@ #if 0 template std::vector read_vector( - const tiledb::Context& ctx, - const std::string&, - size_t start_pos, - size_t end_pos, - uint64_t timestamp); + const tiledb::Context& ctx, + const std::string&, + size_t start_pos, + size_t end_pos, + uint64_t timestamp); #endif template @@ -165,7 +165,7 @@ void debug_vector( const V& v, const std::string& msg = "", size_t max_size = 10) { size_t end = std::min(max_size, dimensions(v)); if (!msg.empty()) { - std::cout << msg << ": "; + std::cout << msg << " (" << dimensions(v) << "): "; } std::cout << "["; for (size_t i = 0; i < end; ++i) { @@ -185,7 +185,7 @@ void debug_vector( const V& v, const std::string& msg = "", size_t max_size = 10) { size_t end = std::min(max_size, dimensions(v)); if (!msg.empty()) { - std::cout << msg << ": "; + std::cout << msg << " (" << dimensions(v) << "): "; } std::cout << "["; size_t idx = 0; diff --git a/src/include/test/unit_api_feature_vector.cc b/src/include/test/unit_api_feature_vector.cc index 7ebaf2df5..defcd3cee 100644 --- a/src/include/test/unit_api_feature_vector.cc +++ b/src/include/test/unit_api_feature_vector.cc @@ -141,6 +141,16 @@ TEMPLATE_LIST_TEST_CASE("api: FeatureVector read", "[api]", TestTypes) { auto bz = (TestType*)y.data(); auto ez = by + dimensions(y); CHECK(std::equal(bz, ez, begin(x))); + + if (N > 10) { + auto vector = FeatureVector{ctx, vname, 0, 10}; + CHECK(dimensions(vector) == 10); + } + + if (N > 10) { + auto vector = FeatureVector{ctx, vname, 5, 10}; + CHECK(dimensions(vector) == 5); + } } TEMPLATE_TEST_CASE( diff --git a/src/include/test/unit_api_feature_vector_array.cc b/src/include/test/unit_api_feature_vector_array.cc index 53bda9ad1..33829ce0e 100644 --- a/src/include/test/unit_api_feature_vector_array.cc +++ b/src/include/test/unit_api_feature_vector_array.cc @@ -69,6 +69,16 @@ TEST_CASE("feature vector array open", "[api]") { CHECK(d.feature_type() == TILEDB_FLOAT32); CHECK(dimensions(d) == 128); CHECK(num_vectors(d) == num_sift_vectors); + + auto e = FeatureVectorArray(ctx, sift_inputs_uri, "", 0, 100); + CHECK(e.feature_type() == TILEDB_FLOAT32); + CHECK(dimensions(e) == 128); + CHECK(num_vectors(e) == 100); + + auto f = FeatureVectorArray(ctx, sift_inputs_uri, "", 50, 100); + CHECK(f.feature_type() == TILEDB_FLOAT32); + CHECK(dimensions(f) == 128); + CHECK(num_vectors(f) == 50); } template @@ -668,7 +678,12 @@ TEST_CASE("temporal_policy", "[api]") { // Read the data at timestamp 99. { auto feature_vector_array = FeatureVectorArray( - ctx, feature_vectors_uri, ids_uri, 0, TemporalPolicy(TimeTravel, 99)); + ctx, + feature_vectors_uri, + ids_uri, + 0, + 0, + TemporalPolicy(TimeTravel, 99)); auto data = MatrixView{ (FeatureType*)feature_vector_array.data(), extents(feature_vector_array)[0], @@ -689,7 +704,12 @@ TEST_CASE("temporal_policy", "[api]") { // Read the data at timestamp 50. { auto feature_vector_array = FeatureVectorArray( - ctx, feature_vectors_uri, ids_uri, 0, TemporalPolicy(TimeTravel, 50)); + ctx, + feature_vectors_uri, + ids_uri, + 0, + 0, + TemporalPolicy(TimeTravel, 50)); CHECK(extents(feature_vector_array)[0] == 0); CHECK(extents(feature_vector_array)[1] == 0); CHECK(feature_vector_array.num_vectors() == 0); diff --git a/src/include/test/unit_api_flat_l2_index.cc b/src/include/test/unit_api_flat_l2_index.cc index 85cfeee41..860ccdb47 100644 --- a/src/include/test/unit_api_flat_l2_index.cc +++ b/src/include/test/unit_api_flat_l2_index.cc @@ -149,7 +149,7 @@ TEST_CASE("api: queries", "[api][flat_l2_index]") { CHECK(dimensions(a) == dim); CHECK(num_vectors(a) == numv); - auto aq = QueryVectorArray(ctx, q_uri, "", num_queries); + auto aq = QueryVectorArray(ctx, q_uri, "", 0, num_queries); load(aq); auto [aq_scores, aq_top_k] = a.query(aq, k_nn); diff --git a/src/include/test/utils/set_seed_from_catch.h b/src/include/test/utils/set_seed_from_catch.h index 2e4c8f90d..e0c4ac24c 100644 --- a/src/include/test/utils/set_seed_from_catch.h +++ b/src/include/test/utils/set_seed_from_catch.h @@ -56,4 +56,4 @@ class SetSeedFromCatch : public Catch::EventListenerBase { CATCH_REGISTER_LISTENER(SetSeedFromCatch) -#endif // TILEDB_TEST_SUPPORT_PRNG_H +#endif // SET_SEED_FROM_CATCH_H