From 795112cb2c61228728695b2ba4682db20cb91f82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Monta=C3=B1ana=20G=C3=B3mez?= Date: Tue, 9 Jan 2024 17:08:41 +0100 Subject: [PATCH] Add BayesNet library to PyClassifiers library --- CMakeLists.txt | 20 ++++++------- Makefile | 48 ++++++++++++++++++++++---------- gcovr.cfg | 4 +++ src/PyClassifiers/CMakeLists.txt | 4 +-- src/PyClassifiers/XGBoost.cc | 2 +- tests/CMakeLists.txt | 2 +- 6 files changed, 51 insertions(+), 29 deletions(-) create mode 100644 gcovr.cfg diff --git a/CMakeLists.txt b/CMakeLists.txt index f809c87..17a74ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") + # Options # ------- option(ENABLE_TESTING "Unit testing build" OFF) @@ -36,8 +37,8 @@ set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) find_package(Boost 1.66.0 REQUIRED COMPONENTS python3 numpy3) if(Boost_FOUND) - message("Boost_INCLUDE_DIRS=${Boost_INCLUDE_DIRS}") - include_directories(${Boost_INCLUDE_DIRS}) + message("Boost_INCLUDE_DIRS=${Boost_INCLUDE_DIRS}") + include_directories(${Boost_INCLUDE_DIRS}) endif() # Python @@ -50,11 +51,11 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_P include(AddGitSubmodule) if (CODE_COVERAGE) - enable_testing() - include(CodeCoverage) - MESSAGE("Code coverage enabled") - set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -O0 -g") - SET(GCC_COVERAGE_LINK_FLAGS " ${GCC_COVERAGE_LINK_FLAGS} -lgcov --coverage") + enable_testing() + include(CodeCoverage) + MESSAGE("Code coverage enabled") + set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -O0 -g") + SET(GCC_COVERAGE_LINK_FLAGS " ${GCC_COVERAGE_LINK_FLAGS} -lgcov --coverage") endif (CODE_COVERAGE) if (ENABLE_CLANG_TIDY) @@ -63,19 +64,18 @@ endif (ENABLE_CLANG_TIDY) # External libraries - dependencies of PyClassifiers # -------------------------------------------------- -# include(FetchContent) add_git_submodule("lib/BayesNet") # Subdirectories # -------------- +file(GLOB PyClassifiers_SOURCES CONFIGURE_DEPENDS ${PyClassifiers_SOURCE_DIR}/src/PyClassifiers/*.cc ${PyClassifiers_SOURCE_DIR}/src/PyClassifiers/*.hpp) add_subdirectory(config) add_subdirectory(src/PyClassifiers) # Testing # ------- - if (ENABLE_TESTING) MESSAGE("Testing enabled") include(CTest) add_subdirectory(tests) -endif (ENABLE_TESTING) +endif (ENABLE_TESTING) \ No newline at end of file diff --git a/Makefile b/Makefile index 84102e0..e964637 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,7 @@ -SHELL := /bin/bash -.DEFAULT_GOAL := help -.PHONY: help build test clean debug - +f_release = build_release f_debug = build_debug app_targets = PyClassifiers -test_targets = unit_tests_pyclassifiers +test_targets = unit_tests_pyclassifiers n_procs = -j 16 define ClearTests @@ -20,27 +17,49 @@ define ClearTests fi ; endef -submodules: ## Update submodules - @echo ">>> Updating submodules..."; - @git submodule update --init --recursive - @echo ">>> Done"; + +setup: ## Install dependencies for tests and coverage + @if [ "$(shell uname)" = "Darwin" ]; then \ + brew install gcovr; \ + brew install lcov; \ + fi + @if [ "$(shell uname)" = "Linux" ]; then \ + pip install gcovr; \ + fi + +dependency: ## Create a dependency graph diagram of the project (build/dependency.png) + @echo ">>> Creating dependency graph diagram of the project..."; + $(MAKE) debug + cd $(f_debug) && cmake .. --graphviz=dependency.dot && dot -Tpng dependency.dot -o dependency.png + +buildd: ## Build the debug targets + cmake --build $(f_debug) -t $(app_targets) $(n_procs) + +buildr: ## Build the release targets + cmake --build $(f_release) -t $(app_targets) $(n_procs) clean: ## Clean the tests info @echo ">>> Cleaning Debug PyClassifiers tests..."; $(call ClearTests) @echo ">>> Done"; -build: ## Build a version of the project +debug: ## Build a debug version of the project @echo ">>> Building Debug PyClassifiers..."; @if [ -d ./$(f_debug) ]; then rm -rf ./$(f_debug); fi @mkdir $(f_debug); @cmake -S . -B $(f_debug) -D CMAKE_BUILD_TYPE=Debug -D ENABLE_TESTING=ON -D CODE_COVERAGE=ON - @cmake --build $(f_debug) $(n_procs) + @echo ">>> Done"; + +release: ## Build a Release version of the project + @echo ">>> Building Release PyClassifiers..."; + @if [ -d ./$(f_release) ]; then rm -rf ./$(f_release); fi + @mkdir $(f_release); + @cmake -S . -B $(f_release) -D CMAKE_BUILD_TYPE=Release @echo ">>> Done"; opt = "" test: ## Run tests (opt="-s") to verbose output the tests, (opt="-c='Test Maximum Spanning Tree'") to run only that section - @echo ">>> Running PyClassifiers & Platform tests..."; + @echo ">>> Running PyClassifiers tests..."; @$(MAKE) clean @cmake --build $(f_debug) -t $(test_targets) $(n_procs) @for t in $(test_targets); do \ @@ -52,10 +71,9 @@ test: ## Run tests (opt="-s") to verbose output the tests, (opt="-c='Test Maximu @echo ">>> Done"; coverage: ## Run tests and generate coverage report (build/index.html) - @echo ">>> Building tests with coverage..."; + @echo ">>> Building tests with coverage..." @$(MAKE) test - @cd $(f_debug) ; \ - gcovr --config ../gcovr.cfg tests ; + @gcovr $(f_debug)/tests @echo ">>> Done"; diff --git a/gcovr.cfg b/gcovr.cfg new file mode 100644 index 0000000..89e0877 --- /dev/null +++ b/gcovr.cfg @@ -0,0 +1,4 @@ +filter = src/ +exclude-directories = build_debug/lib/ +print-summary = yes +sort-percentage = yes diff --git a/src/PyClassifiers/CMakeLists.txt b/src/PyClassifiers/CMakeLists.txt index 42ba8f2..22e51a3 100644 --- a/src/PyClassifiers/CMakeLists.txt +++ b/src/PyClassifiers/CMakeLists.txt @@ -6,6 +6,6 @@ include_directories( ${Python3_INCLUDE_DIRS} ${TORCH_INCLUDE_DIRS} ) -add_library(PyClassifiers SHARED PyWrap.cc STree.cc ODTE.cc SVC.cc RandomForest.cc PyClassifier.cc) +add_library(PyClassifiers SHARED ${PyClassifiers_SOURCES}) #target_link_libraries(PyClassifiers ${Python3_LIBRARIES} "${TORCH_LIBRARIES}" ${LIBTORCH_PYTHON} Boost::boost Boost::python Boost::numpy xgboost::xgboost) -target_link_libraries(PyClassifiers ${Python3_LIBRARIES} "${TORCH_LIBRARIES}" ${LIBTORCH_PYTHON} Boost::boost Boost::python Boost::numpy) \ No newline at end of file +target_link_libraries(PyClassifiers BayesNet ${Python3_LIBRARIES} "${TORCH_LIBRARIES}" ${LIBTORCH_PYTHON} Boost::boost Boost::python Boost::numpy) \ No newline at end of file diff --git a/src/PyClassifiers/XGBoost.cc b/src/PyClassifiers/XGBoost.cc index 5afd628..7d9476e 100644 --- a/src/PyClassifiers/XGBoost.cc +++ b/src/PyClassifiers/XGBoost.cc @@ -3,7 +3,7 @@ -See https ://stackoverflow.com/questions/36071672/using-xgboost-in-c +//See https ://stackoverflow.com/questions/36071672/using-xgboost-in-c diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 813d6ad..25b0393 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,6 +12,6 @@ if(ENABLE_TESTING) ) set(TEST_SOURCES_PYCLASSIFIERS TestPythonClassifiers.cc TestUtils.cc ${PyClassifiers_SOURCES}) add_executable(${TEST_PYCLASSIFIERS} ${TEST_SOURCES_PYCLASSIFIERS}) - target_link_libraries(${TEST_PYCLASSIFIERS} PUBLIC "${TORCH_LIBRARIES}" PyClassifiers ArffFiles mdlp Catch2::Catch2WithMain) + target_link_libraries(${TEST_PYCLASSIFIERS} PUBLIC "${TORCH_LIBRARIES}" ${Python3_LIBRARIES} ${LIBTORCH_PYTHON} Boost::boost Boost::python Boost::numpy ArffFiles mdlp Catch2::Catch2WithMain) add_test(NAME ${TEST_PYCLASSIFIERS} COMMAND ${TEST_PYCLASSIFIERS}) endif(ENABLE_TESTING) \ No newline at end of file