From be18b997823fa64bda84b2d8aba5614de518b052 Mon Sep 17 00:00:00 2001 From: Benjamin Brock Date: Mon, 3 Mar 2025 13:23:32 -0800 Subject: [PATCH 01/11] Small fixes to work with Mac OS. --- CMakeLists.txt | 5 ++--- include/binsparse/hdf5_tools.hpp | 1 + include/binsparse/type_info.hpp | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bfacb3..e6f2e00 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,9 +6,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) add_subdirectory(include) -find_package(HDF5 REQUIRED COMPONENTS CXX) -target_link_libraries(binsparse INTERFACE ${HDF5_CXX_LIBRARIES}) -target_include_directories(binsparse INTERFACE . ${HDF5_INCLUDE_DIRS}) +find_package(HDF5 REQUIRED COMPONENTS C CXX) +target_link_libraries(binsparse INTERFACE ${HDF5_C_LIBRARIES} hdf5::hdf5_cpp) if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) # Dependencies needed only for examples/test diff --git a/include/binsparse/hdf5_tools.hpp b/include/binsparse/hdf5_tools.hpp index 70c8c79..baec1cb 100644 --- a/include/binsparse/hdf5_tools.hpp +++ b/include/binsparse/hdf5_tools.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include diff --git a/include/binsparse/type_info.hpp b/include/binsparse/type_info.hpp index 892daa5..37a3f99 100644 --- a/include/binsparse/type_info.hpp +++ b/include/binsparse/type_info.hpp @@ -45,8 +45,9 @@ struct type_info { } }; -template <> -struct type_info { +template + requires std::is_same_v +struct type_info { static constexpr auto label() noexcept { return "uint64"; } From e8bc0244125eeaa3ef55e76b13b58a27f703e144 Mon Sep 17 00:00:00 2001 From: Benjamin Brock Date: Mon, 3 Mar 2025 13:27:15 -0800 Subject: [PATCH 02/11] Add CI. --- .github/workflows/ci.yml | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d851157 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,41 @@ +name: "CI" + +on: + push: + branches: + - main + + pull_request: + +jobs: + checks: + runs-on: 'ubuntu-latest' + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.12' + cache: 'pip' + - run: pip install -r requirements.txt + - name: Checks + uses: pre-commit/action@v3.0.0 + + gcc: + runs-on: 'ubuntu-latest' + strategy: + matrix: + cxx: [gcc, clang] + name: ${{ matrix.cxx }} + env: + CXX: ${{ matrix.cxx }} + steps: + - uses: actions/checkout@v4 + - name: CMake + run: | + sudo apt-get update + sudo apt-get install libhdf5-dev g++-12 + cmake -B build + - name: Build + run: VERBOSE=true make -C build -j `nproc` + - name: Test + run: ./build/test/gtest/binsparse-tests From 5c8328659e491601ed9243c1d879e6713fe33a67 Mon Sep 17 00:00:00 2001 From: Benjamin Brock Date: Mon, 3 Mar 2025 13:29:25 -0800 Subject: [PATCH 03/11] Change names of jobs, compilers used. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d851157..cacaa6e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: runs-on: 'ubuntu-latest' strategy: matrix: - cxx: [gcc, clang] + cxx: [g++-12, clang++] name: ${{ matrix.cxx }} env: CXX: ${{ matrix.cxx }} From b4e5e9d3024f45793c3e1e899eea18aaa412e67d Mon Sep 17 00:00:00 2001 From: Benjamin Brock Date: Mon, 3 Mar 2025 13:34:44 -0800 Subject: [PATCH 04/11] Print out downloads for testing during CMake build. --- test/gtest/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index de02885..10d0a0f 100644 --- a/test/gtest/CMakeLists.txt +++ b/test/gtest/CMakeLists.txt @@ -13,6 +13,8 @@ function(download_data url file_name) file(ARCHIVE_EXTRACT INPUT ${DATASET_ARCHIVE} ${DATASET_DIR}) + + message(STATUS "Downloading file ${DATASET_ARCHIVE} to ${DATASET_DIR}") endfunction() enable_testing() From f4b34c1410ebe3fef9ba425b0d7248bea3cf081a Mon Sep 17 00:00:00 2001 From: Benjamin Brock Date: Mon, 3 Mar 2025 13:46:35 -0800 Subject: [PATCH 05/11] Fix typo --- test/gtest/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index 10d0a0f..be3b5c9 100644 --- a/test/gtest/CMakeLists.txt +++ b/test/gtest/CMakeLists.txt @@ -7,7 +7,7 @@ function(download_data url file_name) string(REPLACE ".tar.gz" "" - DATSET_DIR + DATASET_DIR ${DATASET_ARCHIVE}) file(ARCHIVE_EXTRACT INPUT From a5e55c9ee3595e51249d7e2f88341c551918541e Mon Sep 17 00:00:00 2001 From: Benjamin Brock Date: Mon, 3 Mar 2025 13:50:38 -0800 Subject: [PATCH 06/11] Fix extraction statement --- test/gtest/CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index be3b5c9..23209c2 100644 --- a/test/gtest/CMakeLists.txt +++ b/test/gtest/CMakeLists.txt @@ -10,9 +10,7 @@ function(download_data url file_name) DATASET_DIR ${DATASET_ARCHIVE}) - file(ARCHIVE_EXTRACT INPUT - ${DATASET_ARCHIVE} - ${DATASET_DIR}) + file(ARCHIVE_EXTRACT INPUT ${DATASET_ARCHIVE} DESTINATION ${DATASET_DIR}) message(STATUS "Downloading file ${DATASET_ARCHIVE} to ${DATASET_DIR}") endfunction() From d16779531534938cea42d26589020d0818b8216b Mon Sep 17 00:00:00 2001 From: Benjamin Brock Date: Mon, 3 Mar 2025 13:56:01 -0800 Subject: [PATCH 07/11] Fix extraction directory --- .github/workflows/ci.yml | 2 +- test/gtest/CMakeLists.txt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cacaa6e..2e7d246 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,6 +36,6 @@ jobs: sudo apt-get install libhdf5-dev g++-12 cmake -B build - name: Build - run: VERBOSE=true make -C build -j `nproc` + run: make -C build -j `nproc` - name: Test run: ./build/test/gtest/binsparse-tests diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index 23209c2..21931a5 100644 --- a/test/gtest/CMakeLists.txt +++ b/test/gtest/CMakeLists.txt @@ -10,6 +10,8 @@ function(download_data url file_name) DATASET_DIR ${DATASET_ARCHIVE}) + cmake_path(REMOVE_FILENAME DATASET_DIR) + file(ARCHIVE_EXTRACT INPUT ${DATASET_ARCHIVE} DESTINATION ${DATASET_DIR}) message(STATUS "Downloading file ${DATASET_ARCHIVE} to ${DATASET_DIR}") From 5442192d4a4becad0c99a25c8b4cbb39cad063b9 Mon Sep 17 00:00:00 2001 From: Benjamin Brock Date: Mon, 3 Mar 2025 13:58:59 -0800 Subject: [PATCH 08/11] Print out where matrix market files are. --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2e7d246..5c9a53d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,4 +38,6 @@ jobs: - name: Build run: make -C build -j `nproc` - name: Test - run: ./build/test/gtest/binsparse-tests + run: | + find . -iname "*.mtx" + ./build/test/gtest/binsparse-tests From 451ffc8dc001f4070c8f5fc1c953b7b2465501f6 Mon Sep 17 00:00:00 2001 From: Benjamin Brock Date: Mon, 3 Mar 2025 14:28:18 -0800 Subject: [PATCH 09/11] Allow tests to be called from multiple directories; search for test files. --- test/gtest/coo_test.cpp | 19 ++++++++++--------- test/gtest/csr_test.cpp | 19 ++++++++++--------- test/gtest/util.hpp | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 test/gtest/util.hpp diff --git a/test/gtest/coo_test.cpp b/test/gtest/coo_test.cpp index fe0b338..3e6f187 100644 --- a/test/gtest/coo_test.cpp +++ b/test/gtest/coo_test.cpp @@ -1,12 +1,8 @@ -#include - -#include - +#include "util.hpp" #include - -inline std::vector file_paths({"1138_bus/1138_bus.mtx", - "chesapeake/chesapeake.mtx", - "mouse_gene/mouse_gene.mtx"}); +#include +#include +#include TEST(BinsparseReadWrite, COOFormat) { using T = float; @@ -14,7 +10,10 @@ TEST(BinsparseReadWrite, COOFormat) { std::string binsparse_file = "out.bsp.hdf5"; - for (auto&& file_path : file_paths) { + auto base_path = find_prefix(files.front()); + + for (auto&& file : files) { + auto file_path = base_path + file; auto x = binsparse::__detail::mmread< T, I, binsparse::__detail::coo_matrix_owning>(file_path); @@ -46,4 +45,6 @@ TEST(BinsparseReadWrite, COOFormat) { delete matrix_.rowind; delete matrix_.colind; } + + std::filesystem::remove(binsparse_file); } diff --git a/test/gtest/csr_test.cpp b/test/gtest/csr_test.cpp index 43cc760..4faa180 100644 --- a/test/gtest/csr_test.cpp +++ b/test/gtest/csr_test.cpp @@ -1,12 +1,8 @@ -#include - -#include - +#include "util.hpp" #include - -inline std::vector file_paths({"1138_bus/1138_bus.mtx", - "chesapeake/chesapeake.mtx", - "mouse_gene/mouse_gene.mtx"}); +#include +#include +#include TEST(BinsparseReadWrite, CSRFormat) { using T = float; @@ -14,7 +10,10 @@ TEST(BinsparseReadWrite, CSRFormat) { std::string binsparse_file = "out.bsp.hdf5"; - for (auto&& file_path : file_paths) { + auto base_path = find_prefix(files.front()); + + for (auto&& file : files) { + auto file_path = base_path + file; auto x = binsparse::__detail::mmread< T, I, binsparse::__detail::csr_matrix_owning>(file_path); @@ -46,4 +45,6 @@ TEST(BinsparseReadWrite, CSRFormat) { delete matrix_.row_ptr; delete matrix_.colind; } + + std::filesystem::remove(binsparse_file); } diff --git a/test/gtest/util.hpp b/test/gtest/util.hpp new file mode 100644 index 0000000..4c0f5ad --- /dev/null +++ b/test/gtest/util.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include +#include +#include + +inline std::vector files({"data/1138_bus/1138_bus.mtx", + "data/chesapeake/chesapeake.mtx", + "data/mouse_gene/mouse_gene.mtx"}); + +inline std::string find_prefix(std::string file_name) { + if (std::filesystem::exists("../../" + file_name)) { + return "../../"; + } else if (std::filesystem::exists("build/" + file_name)) { + return "build/"; + } else { + return ""; + } +} From c557b41479baafdf910a9605e10de90c2eee82c8 Mon Sep 17 00:00:00 2001 From: Benjamin Brock Date: Mon, 3 Mar 2025 14:33:58 -0800 Subject: [PATCH 10/11] Add MacOS to CI. --- .github/workflows/ci.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5c9a53d..d47af11 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,5 +39,18 @@ jobs: run: make -C build -j `nproc` - name: Test run: | - find . -iname "*.mtx" + ./build/test/gtest/binsparse-tests + + macos: + runs-on: 'macos-latest' + steps: + - uses: actions/checkout@v4 + - name: CMake + run: | + brew install hdf5 + cmake -B build + - name: Build + run: make -C build -j + - name: Test + run: | ./build/test/gtest/binsparse-tests From 627b75452b46fc6d4af1def0d923f7c1941fbb63 Mon Sep 17 00:00:00 2001 From: Benjamin Brock Date: Mon, 3 Mar 2025 14:38:15 -0800 Subject: [PATCH 11/11] Fix indentation. --- test/gtest/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index 21931a5..25df59e 100644 --- a/test/gtest/CMakeLists.txt +++ b/test/gtest/CMakeLists.txt @@ -5,16 +5,16 @@ function(download_data url file_name) ${url} ${DATASET_ARCHIVE}) - string(REPLACE + string(REPLACE ".tar.gz" "" DATASET_DIR ${DATASET_ARCHIVE}) - cmake_path(REMOVE_FILENAME DATASET_DIR) + cmake_path(REMOVE_FILENAME DATASET_DIR) - file(ARCHIVE_EXTRACT INPUT ${DATASET_ARCHIVE} DESTINATION ${DATASET_DIR}) + file(ARCHIVE_EXTRACT INPUT ${DATASET_ARCHIVE} DESTINATION ${DATASET_DIR}) - message(STATUS "Downloading file ${DATASET_ARCHIVE} to ${DATASET_DIR}") + message(STATUS "Downloading file ${DATASET_ARCHIVE}, extracting to ${DATASET_DIR}.") endfunction() enable_testing()