Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some miscelenious issues encountered while working on #335 #339

Merged
merged 3 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(USEARCH_IS_MAIN_PROJECT ON)
endif ()

# Allow CMake 3.13+ to override options when using FetchContent / add_subdirectory
if (POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif ()

# Options
option(USEARCH_INSTALL "Install CMake targets" OFF)

Expand All @@ -31,11 +36,6 @@ option(USEARCH_BUILD_WOLFRAM "Compile Wolfram Language bindings" OFF)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
include(ExternalProject)

# Allow CMake 3.13+ to override options when using FetchContent / add_subdirectory
if (POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif ()

# Configuration
include(GNUInstallDirs)
set(USEARCH_TARGET_NAME ${PROJECT_NAME})
Expand Down
11 changes: 9 additions & 2 deletions cpp/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,14 @@ void test_cosine(std::size_t collection_size, std::size_t dimensions) {
metric_punned_t metric(dimensions, metric_kind_t::cos_k, scalar_kind<scalar_at>());
index_dense_config_t config(connectivity);
config.multi = multi;
index_t index = index_t::make(metric, config);
index_t index;
{
index_t index_tmp1 = index_t::make(metric, config);
// move construction
index_t index_tmp2 = std::move(index_tmp1);
// move assignment
index = std::move(index_tmp2);
}
test_cosine<true>(index, matrix);
}
}
Expand Down Expand Up @@ -313,4 +320,4 @@ int main(int, char**) {
test_tanimoto<std::int64_t, std::uint32_t>(dimensions, connectivity);

return 0;
}
}
4 changes: 2 additions & 2 deletions include/usearch/index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ class output_file_t {
serialization_result_t write(void const* begin, std::size_t length) noexcept {
serialization_result_t result;
std::size_t written = std::fwrite(begin, length, 1, file_);
if (!written)
if (length && !written)
return result.failed(std::strerror(errno));
return result;
}
Expand Down Expand Up @@ -1404,7 +1404,7 @@ class input_file_t {
serialization_result_t read(void* begin, std::size_t length) noexcept {
serialization_result_t result;
std::size_t read = std::fread(begin, length, 1, file_);
if (!read)
if (length && !read)
return result.failed(std::feof(file_) ? "End of file reached!" : std::strerror(errno));
return result;
}
Expand Down
3 changes: 2 additions & 1 deletion include/usearch/index_plugins.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1819,7 +1819,8 @@ class flat_hash_multi_set_gt {
}

// Reset populated slots count
std::memset(data_, 0, buckets_ * bytes_per_bucket());
if (data_)
std::memset(data_, 0, buckets_ * bytes_per_bucket());
populated_slots_ = 0;
}

Expand Down
Loading