diff --git a/conanfile.py b/conanfile.py index 662b4bb5..4d2f56a6 100644 --- a/conanfile.py +++ b/conanfile.py @@ -8,7 +8,7 @@ class CompressorRecipe(ConanFile): settings = "os", "compiler", "build_type", "arch" - generators = "CMakeDeps" + generators = "CMakeConfigDeps" def requirements(self): self.requires("spdlog/1.16.0", options={"use_std_fmt": True, "no_exceptions": True}) # type: ignore diff --git a/source/centipede/CMakeLists.txt b/source/centipede/CMakeLists.txt index 7d814919..e71158f6 100644 --- a/source/centipede/CMakeLists.txt +++ b/source/centipede/CMakeLists.txt @@ -1,6 +1,6 @@ add_library(core SHARED) add_library(centipede::centipede ALIAS core) -target_compile_features(core PRIVATE cxx_std_26) +target_compile_features(core PUBLIC cxx_std_26) target_compile_options( core PRIVATE @@ -22,6 +22,8 @@ target_sources( FILES centipede.hpp ) +target_link_libraries(core PUBLIC Eigen3::Eigen GSL::gsl) + add_subdirectory(core) add_subdirectory(util) add_subdirectory(writer) diff --git a/source/centipede/core/CMakeLists.txt b/source/centipede/core/CMakeLists.txt index bfe3f77b..db336665 100644 --- a/source/centipede/core/CMakeLists.txt +++ b/source/centipede/core/CMakeLists.txt @@ -1,6 +1,5 @@ target_sources( core - PRIVATE handler.cpp PUBLIC FILE_SET publicHeaders TYPE HEADERS @@ -10,7 +9,6 @@ target_sources( engines/master_engine.hpp handler.hpp ) -target_link_libraries(core PUBLIC Eigen3::Eigen GSL::gsl) target_compile_definitions( core PUBLIC diff --git a/source/centipede/core/engines/base_engine.hpp b/source/centipede/core/engines/base_engine.hpp index 8c3bdba8..2146ea33 100644 --- a/source/centipede/core/engines/base_engine.hpp +++ b/source/centipede/core/engines/base_engine.hpp @@ -178,7 +178,7 @@ namespace centipede::core::engine /** * @brief Empty base engine class. The real implementation is defined in its specialization. */ - template + template class Engine { }; diff --git a/source/centipede/core/engines/eigen_engine.hpp b/source/centipede/core/engines/eigen_engine.hpp index 41165042..176215a9 100644 --- a/source/centipede/core/engines/eigen_engine.hpp +++ b/source/centipede/core/engines/eigen_engine.hpp @@ -26,7 +26,7 @@ namespace centipede::core::engine * @brief Engine template specialization for Eigen library implementation. */ template - class Engine : public Base + class Engine : public Base { public: /** @@ -192,7 +192,7 @@ namespace centipede::core::engine global_t_.setFromSortedTriplets(triplets_.begin(), triplets_.end()); } - auto fit_local_pars() -> EnumError<> + auto fit_local_pars() -> VoidError { // NOTE: Multiplications will trigger temporary object (memory allocation later during the assignment.) Eigen::internal::set_is_malloc_allowed(false); @@ -234,7 +234,7 @@ namespace centipede::core::engine return std::pair{ ndf, chi_square }; } - auto update_global_factor_matrix() -> EnumError<> + auto update_global_factor_matrix() -> VoidError { // TODO: Perform the production using index accessing. // NOTE: Seems that there is no way to prevent memory allocation with sparse matrices. @@ -257,7 +257,7 @@ namespace centipede::core::engine return {}; } - auto update_global_rhs_vector() -> EnumError<> + auto update_global_rhs_vector() -> VoidError { // TODO: Perform the production using index accessing. // NOTE: Seems that there is no way to prevent memory allocation with sparse matrices. @@ -274,9 +274,10 @@ namespace centipede::core::engine static void resize_globals(Globals& globals, std::size_t n_globals) { - globals.rhs_vec.resize(n_globals); + const auto num_of_globals = static_cast(n_globals); + globals.rhs_vec.resize(num_of_globals); globals.rhs_vec.setZero(); - globals.factor_matrix.resize(n_globals, n_globals); + globals.factor_matrix.resize(num_of_globals, num_of_globals); globals.factor_matrix.setZero(); } diff --git a/source/centipede/core/engines/engine_concept.hpp b/source/centipede/core/engines/engine_concept.hpp index a13c5658..a8e8bbdb 100644 --- a/source/centipede/core/engines/engine_concept.hpp +++ b/source/centipede/core/engines/engine_concept.hpp @@ -14,7 +14,7 @@ namespace centipede::core::engine /** * @brief Concept used for core::engine::Master option. */ - template + template concept EngineLike = requires(Engine engine, Result& result, typename Engine::Globals& globals) { diff --git a/source/centipede/core/engines/engine_types.hpp b/source/centipede/core/engines/engine_types.hpp index daddd5bf..3becb757 100644 --- a/source/centipede/core/engines/engine_types.hpp +++ b/source/centipede/core/engines/engine_types.hpp @@ -8,7 +8,7 @@ namespace centipede::core::engine * @brief Engine types. * */ - enum class MatrixEngineType : uint8_t + enum class MatrixEngine : uint8_t { eigen, xtensor, @@ -20,7 +20,7 @@ namespace centipede::core::engine */ struct MasterOpt { - MatrixEngineType engine_type = MatrixEngineType::eigen; + MatrixEngine engine_type = MatrixEngine::eigen; bool has_multi_slaves = false; //!< Use taskflow or not. }; @@ -28,5 +28,5 @@ namespace centipede::core::engine namespace centipede { - using EngineType = core::engine::MatrixEngineType; + using MatrixEngine = core::engine::MatrixEngine; } diff --git a/source/centipede/core/engines/master_engine.hpp b/source/centipede/core/engines/master_engine.hpp index bfd0ac01..86571db3 100644 --- a/source/centipede/core/engines/master_engine.hpp +++ b/source/centipede/core/engines/master_engine.hpp @@ -48,7 +48,7 @@ namespace centipede::core::engine Entry entry; //!< Data storing the current entry. }; - using Result = Result; + using ResultType = Result; using EngineImp = Engine; using DataTypeUsed = DataType; @@ -153,7 +153,7 @@ namespace centipede::core::engine private: Config config_; - Result result_; + ResultType result_; State current_state_; EngineImp engine_imp_{}; EngineImp::Globals globals_{}; diff --git a/source/centipede/core/handler.cpp b/source/centipede/core/handler.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/source/centipede/core/handler.hpp b/source/centipede/core/handler.hpp index 5adc4bf4..1a99c8ba 100644 --- a/source/centipede/core/handler.hpp +++ b/source/centipede/core/handler.hpp @@ -6,7 +6,7 @@ #include "centipede/util/return_types.hpp" #include -namespace centipede::core +namespace centipede { /** @@ -14,7 +14,7 @@ namespace centipede::core * * This class should handle all inputs and configurations from users */ - template + template class Handler { public: @@ -26,7 +26,7 @@ namespace centipede::core { std::size_t n_globals = 0; //!< Number of global parameters. }; - using EngineType = engine::Master; + using EngineType = core::engine::Master; /** * @brief Constructor @@ -61,4 +61,4 @@ namespace centipede::core // std::vector<> }; -} // namespace centipede::core +} // namespace centipede diff --git a/source/centipede/util/return_types.hpp b/source/centipede/util/return_types.hpp index 7ac79ee4..520da800 100644 --- a/source/centipede/util/return_types.hpp +++ b/source/centipede/util/return_types.hpp @@ -10,6 +10,9 @@ namespace centipede { + /** + * @brief Template alias for expected string results. + */ using StrError = std::expected; /** @@ -17,4 +20,9 @@ namespace centipede */ template using EnumError = std::expected; + + /** + * @brief Template alias for expected void results. + */ + using VoidError = std::expected; } // namespace centipede diff --git a/test/integration_tests/CMakeLists.txt b/test/integration_tests/CMakeLists.txt index 782365a7..f8865929 100644 --- a/test/integration_tests/CMakeLists.txt +++ b/test/integration_tests/CMakeLists.txt @@ -8,17 +8,14 @@ set(COMPILE_OPTIONS -fno-rtti ) +#===================================writer=================================== + add_executable(integration_test_writer test_writer.cpp) target_link_libraries(integration_test_writer PRIVATE centipede::centipede) target_compile_options(integration_test_writer PRIVATE ${COMPILE_OPTIONS}) -# if(ENABLE_COVERAGE) -# target_compile_options(integration_test_writer PRIVATE --coverage) -# target_link_options(integration_test_writer PRIVATE --coverage) -# endif() - add_test(NAME integration_test_writer_data_gen COMMAND integration_test_writer) set_tests_properties(integration_test_writer_data_gen PROPERTIES TIMEOUT 10) @@ -33,3 +30,23 @@ set_tests_properties( integration_test_writer_res PROPERTIES DEPENDS integration_test_writer_data_gen ) + +#===================================eigen core=============================== + +find_package(mps) + +if(mps_FOUND) + message(STATUS "Testing with simulated data from mps is enabled!") + add_executable(test_eigen test_eigen.cpp) + + target_link_libraries(test_eigen PRIVATE centipede::centipede mps::mps) + + target_compile_options(test_eigen PRIVATE ${COMPILE_OPTIONS}) + + add_test(NAME integration_test_eigen COMMAND test_eigen) + set_tests_properties(integration_test_eigen PROPERTIES TIMEOUT 10) +else() + message(STATUS "Testing with simulated data from mps is disabled!") +endif() + +#============================================================================== diff --git a/test/integration_tests/test_eigen.cpp b/test/integration_tests/test_eigen.cpp new file mode 100644 index 00000000..8081e64a --- /dev/null +++ b/test/integration_tests/test_eigen.cpp @@ -0,0 +1,17 @@ +#include "centipede/centipede.hpp" +#include +#include + +namespace +{ + // void entrypoints_generator() {} +} // namespace + +auto main() -> int +{ + auto entries = std::vector>{}; + + auto handler = centipede::Handler{}; + + return EXIT_SUCCESS; +} diff --git a/test/unit_tests/test_eigen_engine.cpp b/test/unit_tests/test_eigen_engine.cpp index 8c815ce8..48a3099f 100644 --- a/test/unit_tests/test_eigen_engine.cpp +++ b/test/unit_tests/test_eigen_engine.cpp @@ -13,7 +13,7 @@ namespace centipede::test TEST(eigen_engine, constructor) { constexpr auto n_global_pars = 10; - auto engine = core::engine::Engine{ n_global_pars }; + auto engine = core::engine::Engine{ n_global_pars }; const auto& factor_matrix = engine.get_global_factor_matrix(); EXPECT_EQ(factor_matrix.rows(), n_global_pars); EXPECT_EQ(factor_matrix.cols(), n_global_pars); @@ -24,7 +24,7 @@ namespace centipede::test TEST(eigen_engine, solve_rank_deficit) { - using EngineClass = core::engine::Engine; + using EngineClass = core::engine::Engine; auto result = Result{}; const auto globals = []() @@ -48,7 +48,7 @@ namespace centipede::test TEST(eigen_engine, solve_negative_definite) { - using EngineClass = core::engine::Engine; + using EngineClass = core::engine::Engine; auto result = Result{}; const auto globals = []() @@ -69,7 +69,7 @@ namespace centipede::test TEST(eigen_engine, solve_zero_factor_matrix) { - using EngineClass = core::engine::Engine; + using EngineClass = core::engine::Engine; auto result = Result{}; const auto globals = []() @@ -90,7 +90,7 @@ namespace centipede::test TEST(eigen_engine, solve_zero_rhs_vector) { - using EngineClass = core::engine::Engine; + using EngineClass = core::engine::Engine; auto result = Result{}; const auto globals = []() @@ -111,7 +111,7 @@ namespace centipede::test TEST(eigen_engine, solve) { - using EngineClass = core::engine::Engine; + using EngineClass = core::engine::Engine; auto result = Result{}; const auto globals = []() diff --git a/test/unit_tests/test_handler.cpp b/test/unit_tests/test_handler.cpp index ac7e32f6..fdeb0cd6 100644 --- a/test/unit_tests/test_handler.cpp +++ b/test/unit_tests/test_handler.cpp @@ -6,7 +6,7 @@ namespace { constexpr auto DEFAULT_MAX_POINT = 30; - using centipede::core::Handler; + using centipede::Handler; } // namespace diff --git a/test/unit_tests/test_master_engine.cpp b/test/unit_tests/test_master_engine.cpp index a19be642..b8eade34 100644 --- a/test/unit_tests/test_master_engine.cpp +++ b/test/unit_tests/test_master_engine.cpp @@ -16,7 +16,7 @@ namespace centipede::core::engine { namespace { - struct Globals + struct GlobalsType { }; @@ -25,18 +25,18 @@ namespace centipede::core::engine { public: MOCK_METHOD(void, construct_with, (std::size_t n_globals), ()); - MOCK_METHOD(void, solve, (const Globals& globals, Result& result), ()); + MOCK_METHOD(void, solve, (const GlobalsType& globals, Result& result), ()); }; } // namespace /** @cond */ template - class Engine + class Engine { public: Engine(std::size_t n_globals) { mock_helper->construct_with(n_globals); } - using Globals = Globals; + using Globals = GlobalsType; static void solve(const Globals& globals, Result& result) { mock_helper->solve(globals, result); } @@ -49,7 +49,7 @@ namespace centipede::core::engine }; template - MockHelper* Engine::mock_helper = nullptr; + MockHelper* Engine::mock_helper = nullptr; /** @endcond */ } // namespace centipede::core::engine @@ -60,13 +60,13 @@ namespace centipede::test class master_engine : public testing::Test { public: - using Master = engine::Master; + using Master = engine::Master; using Config = Master::Config; protected: using MockHelperType = core::engine::MockHelper; using EngineClass = Master::EngineImp; - using Result = Result; + using ResultType = Result; void SetUp() override { @@ -184,7 +184,7 @@ namespace centipede::test EXPECT_CALL(*engine_class_, add_to_result(testing::_)).Times(1); EXPECT_CALL(*mock_helper_, solve(testing::_, testing::_)) .Times(1) - .WillOnce([](const auto&, Result& result) { result.error_status = ErrorCode::success; }); + .WillOnce([](const auto&, ResultType& result) { result.error_status = ErrorCode::success; }); EXPECT_TRUE_RES(master_->solve()); } @@ -195,7 +195,7 @@ namespace centipede::test EXPECT_CALL(*engine_class_, add_to_result(testing::_)).Times(1); EXPECT_CALL(*mock_helper_, solve(testing::_, testing::_)) .Times(1) - .WillOnce([](const auto&, Result& result) { result.error_status = ErrorCode::analysis_rank_deficit; }); + .WillOnce([](const auto&, ResultType& result) { result.error_status = ErrorCode::analysis_rank_deficit; }); auto res = master_->solve(); EXPECT_FALSE(res);