diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d47af11 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,56 @@ +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: [g++-12, 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: make -C build -j `nproc` + - name: Test + run: | + ./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 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"; } diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index de02885..25df59e 100644 --- a/test/gtest/CMakeLists.txt +++ b/test/gtest/CMakeLists.txt @@ -5,14 +5,16 @@ function(download_data url file_name) ${url} ${DATASET_ARCHIVE}) - string(REPLACE + string(REPLACE ".tar.gz" "" - DATSET_DIR + DATASET_DIR ${DATASET_ARCHIVE}) - file(ARCHIVE_EXTRACT INPUT - ${DATASET_ARCHIVE} - ${DATASET_DIR}) + cmake_path(REMOVE_FILENAME DATASET_DIR) + + file(ARCHIVE_EXTRACT INPUT ${DATASET_ARCHIVE} DESTINATION ${DATASET_DIR}) + + message(STATUS "Downloading file ${DATASET_ARCHIVE}, extracting to ${DATASET_DIR}.") endfunction() enable_testing() 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 ""; + } +}