diff --git a/c/lib.cpp b/c/lib.cpp index 581d3bcc..06d75ead 100644 --- a/c/lib.cpp +++ b/c/lib.cpp @@ -118,6 +118,15 @@ search_result_t search_(index_dense_t* index, void const* vector, scalar_kind_t extern "C" { +USEARCH_EXPORT char const* usearch_version(void) { + int major = USEARCH_VERSION_MAJOR; + int minor = USEARCH_VERSION_MINOR; + int patch = USEARCH_VERSION_PATCH; + static char version[32]; + sprintf(version, "%d.%d.%d", major, minor, patch); + return version; +} + USEARCH_EXPORT usearch_index_t usearch_init(usearch_init_options_t* options, usearch_error_t* error) { USEARCH_ASSERT(options && error && "Missing arguments"); @@ -275,6 +284,16 @@ USEARCH_EXPORT size_t usearch_expansion_search(usearch_index_t index, usearch_er return reinterpret_cast(index)->expansion_search(); } +USEARCH_EXPORT size_t usearch_memory_usage(usearch_index_t index, usearch_error_t* error) { + USEARCH_ASSERT(index && error && "Missing arguments"); + return reinterpret_cast(index)->memory_usage(); +} + +USEARCH_EXPORT char const* usearch_hardware_acceleration(usearch_index_t index, usearch_error_t* error) { + USEARCH_ASSERT(index && error && "Missing arguments"); + return reinterpret_cast(index)->metric().isa_name(); +} + USEARCH_EXPORT void usearch_change_expansion_add(usearch_index_t index, size_t expansion, usearch_error_t* error) { USEARCH_ASSERT(index && error && "Missing arguments"); reinterpret_cast(index)->change_expansion_add(expansion); @@ -348,11 +367,11 @@ USEARCH_EXPORT size_t usearch_search( return result.dump_to(found_keys, found_distances); } -USEARCH_EXPORT size_t usearch_filtered_search( // - usearch_index_t index, // - void const* query, usearch_scalar_kind_t query_kind, // - int (*filter)(usearch_key_t key, void* filter_state), void* filter_state, // - size_t results_limit, usearch_key_t* found_keys, usearch_distance_t* found_distances, usearch_error_t* error) { +USEARCH_EXPORT size_t usearch_filtered_search( // + usearch_index_t index, // + void const* query, usearch_scalar_kind_t query_kind, size_t results_limit, // + int (*filter)(usearch_key_t key, void* filter_state), void* filter_state, // + usearch_key_t* found_keys, usearch_distance_t* found_distances, usearch_error_t* error) { USEARCH_ASSERT(index && query && filter && error && "Missing arguments"); search_result_t result = diff --git a/c/test.c b/c/test.c index 1f086a9a..2498aa06 100644 --- a/c/test.c +++ b/c/test.c @@ -72,6 +72,8 @@ void test_init(size_t const collection_size, size_t const dimensions) { ASSERT(usearch_capacity(index, &error) == collection_size, error); ASSERT(usearch_dimensions(index, &error) == dimensions, error); ASSERT(usearch_connectivity(index, &error) == opts.connectivity, error); + ASSERT(usearch_hardware_acceleration(index, &error), error); + ASSERT(usearch_memory_usage(index, &error), error); usearch_free(index, &error); ASSERT(!error, error); @@ -361,6 +363,8 @@ void test_view(size_t const collection_size, size_t const dimensions) { } int main(int argc, char const* argv[]) { + printf("Running tests...\n"); + printf("USearch version: %s\n", usearch_version()); size_t collection_sizes[] = {11, 512}; size_t dimensions[] = {83, 2}; // Not all distance functions make sense for 1 dimensional data diff --git a/c/usearch.h b/c/usearch.h index 92199e0d..5632aa44 100644 --- a/c/usearch.h +++ b/c/usearch.h @@ -97,6 +97,12 @@ USEARCH_EXPORT typedef struct usearch_init_options_t { bool multi; } usearch_init_options_t; +/** + * @brief Retrieves the version of the library. + * @return The version of the library. + */ +USEARCH_EXPORT char const* usearch_version(void); + /** * @brief Initializes a new instance of the index. * @param options Pointer to the `usearch_init_options_t` structure containing initialization options. @@ -112,6 +118,22 @@ USEARCH_EXPORT usearch_index_t usearch_init(usearch_init_options_t* options, use */ USEARCH_EXPORT void usearch_free(usearch_index_t index, usearch_error_t* error); +/** + * @brief Reports the memory usage of the index. + * @param[in] index The handle to the USearch index to be queried. + * @param[out] error Pointer to a string where the error message will be stored, if an error occurs. + * @return Number of bytes used by the index. + */ +USEARCH_EXPORT size_t usearch_memory_usage(usearch_index_t index, usearch_error_t* error); + +/** + * @brief Reports the SIMD capabilities used by the index on the current CPU. + * @param[in] index The handle to the USearch index to be queried. + * @param[out] error Pointer to a string where the error message will be stored, if an error occurs. + * @return The codename of the SIMD instruction set used by the index. + */ +USEARCH_EXPORT char const* usearch_hardware_acceleration(usearch_index_t index, usearch_error_t* error); + /** * @brief Reports expected file size after serialization. * @param[in] index The handle to the USearch index to be serialized. @@ -320,10 +342,10 @@ USEARCH_EXPORT size_t usearch_count(usearch_index_t index, usearch_key_t, usearc * @param[out] error Pointer to a string where the error message will be stored, if an error occurs. * @return Number of found matches. */ -USEARCH_EXPORT size_t usearch_search( // - usearch_index_t index, // - void const* query_vector, usearch_scalar_kind_t query_kind, // - size_t count, usearch_key_t* keys, usearch_distance_t* distances, usearch_error_t* error); +USEARCH_EXPORT size_t usearch_search( // + usearch_index_t index, // + void const* query_vector, usearch_scalar_kind_t query_kind, size_t count, // + usearch_key_t* keys, usearch_distance_t* distances, usearch_error_t* error); /** * @brief Performs k-Approximate Nearest Neighbors (kANN) Search for closest vectors to query, @@ -333,6 +355,8 @@ USEARCH_EXPORT size_t usearch_search( // * @param[in] query_vector Pointer to the query vector data. * @param[in] query_kind The scalar type used in the query vector data. * @param[in] count Upper bound on the number of neighbors to search, the "k" in "kANN". + * @param[in] filter The custom filter function that returns `true` for vectors to be included. + * @param[in] filter_state The @b optional state pointer to be passed to the custom filter function. * @param[out] keys Output buffer for up to `count` nearest neighbors keys. * @param[out] distances Output buffer for up to `count` distances to nearest neighbors. * @param[out] error Pointer to a string where the error message will be stored, if an error occurs. @@ -340,9 +364,9 @@ USEARCH_EXPORT size_t usearch_search( // */ USEARCH_EXPORT size_t usearch_filtered_search( // usearch_index_t index, // - void const* query_vector, usearch_scalar_kind_t query_kind, // + void const* query_vector, usearch_scalar_kind_t query_kind, size_t count, // int (*filter)(usearch_key_t key, void* filter_state), void* filter_state, // - size_t count, usearch_key_t* keys, usearch_distance_t* distances, usearch_error_t* error); + usearch_key_t* keys, usearch_distance_t* distances, usearch_error_t* error); /** * @brief Retrieves the vector associated with the given key from the index.