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_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,17 +64,16 @@ 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)

View File

@@ -1,7 +1,4 @@
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
@@ -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";

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}
${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)
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})
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)