Add BayesNet library to PyClassifiers library

This commit is contained in:
2024-01-09 17:08:41 +01:00
parent 1ef8faf10a
commit 795112cb2c
6 changed files with 51 additions and 29 deletions

View File

@@ -25,6 +25,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
# Options # Options
# ------- # -------
option(ENABLE_TESTING "Unit testing build" OFF) option(ENABLE_TESTING "Unit testing build" OFF)
@@ -36,8 +37,8 @@ set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF) set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.66.0 REQUIRED COMPONENTS python3 numpy3) find_package(Boost 1.66.0 REQUIRED COMPONENTS python3 numpy3)
if(Boost_FOUND) if(Boost_FOUND)
message("Boost_INCLUDE_DIRS=${Boost_INCLUDE_DIRS}") message("Boost_INCLUDE_DIRS=${Boost_INCLUDE_DIRS}")
include_directories(${Boost_INCLUDE_DIRS}) include_directories(${Boost_INCLUDE_DIRS})
endif() endif()
# Python # Python
@@ -50,11 +51,11 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_P
include(AddGitSubmodule) include(AddGitSubmodule)
if (CODE_COVERAGE) if (CODE_COVERAGE)
enable_testing() enable_testing()
include(CodeCoverage) include(CodeCoverage)
MESSAGE("Code coverage enabled") MESSAGE("Code coverage enabled")
set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -O0 -g") set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -O0 -g")
SET(GCC_COVERAGE_LINK_FLAGS " ${GCC_COVERAGE_LINK_FLAGS} -lgcov --coverage") SET(GCC_COVERAGE_LINK_FLAGS " ${GCC_COVERAGE_LINK_FLAGS} -lgcov --coverage")
endif (CODE_COVERAGE) endif (CODE_COVERAGE)
if (ENABLE_CLANG_TIDY) if (ENABLE_CLANG_TIDY)
@@ -63,19 +64,18 @@ endif (ENABLE_CLANG_TIDY)
# External libraries - dependencies of PyClassifiers # External libraries - dependencies of PyClassifiers
# -------------------------------------------------- # --------------------------------------------------
# include(FetchContent)
add_git_submodule("lib/BayesNet") add_git_submodule("lib/BayesNet")
# Subdirectories # Subdirectories
# -------------- # --------------
file(GLOB PyClassifiers_SOURCES CONFIGURE_DEPENDS ${PyClassifiers_SOURCE_DIR}/src/PyClassifiers/*.cc ${PyClassifiers_SOURCE_DIR}/src/PyClassifiers/*.hpp)
add_subdirectory(config) add_subdirectory(config)
add_subdirectory(src/PyClassifiers) add_subdirectory(src/PyClassifiers)
# Testing # Testing
# ------- # -------
if (ENABLE_TESTING) if (ENABLE_TESTING)
MESSAGE("Testing enabled") MESSAGE("Testing enabled")
include(CTest) include(CTest)
add_subdirectory(tests) add_subdirectory(tests)
endif (ENABLE_TESTING) endif (ENABLE_TESTING)

View File

@@ -1,10 +1,7 @@
SHELL := /bin/bash f_release = build_release
.DEFAULT_GOAL := help
.PHONY: help build test clean debug
f_debug = build_debug f_debug = build_debug
app_targets = PyClassifiers app_targets = PyClassifiers
test_targets = unit_tests_pyclassifiers test_targets = unit_tests_pyclassifiers
n_procs = -j 16 n_procs = -j 16
define ClearTests define ClearTests
@@ -20,27 +17,49 @@ define ClearTests
fi ; fi ;
endef endef
submodules: ## Update submodules
@echo ">>> Updating submodules..."; setup: ## Install dependencies for tests and coverage
@git submodule update --init --recursive @if [ "$(shell uname)" = "Darwin" ]; then \
@echo ">>> Done"; 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 clean: ## Clean the tests info
@echo ">>> Cleaning Debug PyClassifiers tests..."; @echo ">>> Cleaning Debug PyClassifiers tests...";
$(call ClearTests) $(call ClearTests)
@echo ">>> Done"; @echo ">>> Done";
build: ## Build a version of the project debug: ## Build a debug version of the project
@echo ">>> Building Debug PyClassifiers..."; @echo ">>> Building Debug PyClassifiers...";
@if [ -d ./$(f_debug) ]; then rm -rf ./$(f_debug); fi @if [ -d ./$(f_debug) ]; then rm -rf ./$(f_debug); fi
@mkdir $(f_debug); @mkdir $(f_debug);
@cmake -S . -B $(f_debug) -D CMAKE_BUILD_TYPE=Debug -D ENABLE_TESTING=ON -D CODE_COVERAGE=ON @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"; @echo ">>> Done";
opt = "" opt = ""
test: ## Run tests (opt="-s") to verbose output the tests, (opt="-c='Test Maximum Spanning Tree'") to run only that section 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 @$(MAKE) clean
@cmake --build $(f_debug) -t $(test_targets) $(n_procs) @cmake --build $(f_debug) -t $(test_targets) $(n_procs)
@for t in $(test_targets); do \ @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"; @echo ">>> Done";
coverage: ## Run tests and generate coverage report (build/index.html) coverage: ## Run tests and generate coverage report (build/index.html)
@echo ">>> Building tests with coverage..."; @echo ">>> Building tests with coverage..."
@$(MAKE) test @$(MAKE) test
@cd $(f_debug) ; \ @gcovr $(f_debug)/tests
gcovr --config ../gcovr.cfg tests ;
@echo ">>> Done"; @echo ">>> Done";

4
gcovr.cfg Normal file
View File

@@ -0,0 +1,4 @@
filter = src/
exclude-directories = build_debug/lib/
print-summary = yes
sort-percentage = yes

View File

@@ -6,6 +6,6 @@ include_directories(
${Python3_INCLUDE_DIRS} ${Python3_INCLUDE_DIRS}
${TORCH_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 xgboost::xgboost)
target_link_libraries(PyClassifiers ${Python3_LIBRARIES} "${TORCH_LIBRARIES}" ${LIBTORCH_PYTHON} Boost::boost Boost::python Boost::numpy) target_link_libraries(PyClassifiers BayesNet ${Python3_LIBRARIES} "${TORCH_LIBRARIES}" ${LIBTORCH_PYTHON} Boost::boost Boost::python Boost::numpy)

View File

@@ -3,7 +3,7 @@
See https ://stackoverflow.com/questions/36071672/using-xgboost-in-c //See https ://stackoverflow.com/questions/36071672/using-xgboost-in-c

View File

@@ -12,6 +12,6 @@ if(ENABLE_TESTING)
) )
set(TEST_SOURCES_PYCLASSIFIERS TestPythonClassifiers.cc TestUtils.cc ${PyClassifiers_SOURCES}) set(TEST_SOURCES_PYCLASSIFIERS TestPythonClassifiers.cc TestUtils.cc ${PyClassifiers_SOURCES})
add_executable(${TEST_PYCLASSIFIERS} ${TEST_SOURCES_PYCLASSIFIERS}) 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}) add_test(NAME ${TEST_PYCLASSIFIERS} COMMAND ${TEST_PYCLASSIFIERS})
endif(ENABLE_TESTING) endif(ENABLE_TESTING)