From 2f5bc10b8ee022fe745a6a6866dced15eb9bcda2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Monta=C3=B1ana=20G=C3=B3mez?= Date: Sun, 27 Apr 2025 21:25:21 +0200 Subject: [PATCH] Update sample project and README --- Makefile | 3 +- README.md | 88 +++++++++++++++++++++++++++------ sample/CMakeLists.txt | 33 ++++++------- sample/vcpkg-configuration.json | 21 ++++++++ sample/vcpkg.json | 12 +++++ 5 files changed, 123 insertions(+), 34 deletions(-) create mode 100644 sample/vcpkg-configuration.json create mode 100644 sample/vcpkg.json diff --git a/Makefile b/Makefile index 0f36fae..b663aa8 100644 --- a/Makefile +++ b/Makefile @@ -111,7 +111,8 @@ fname = "tests/data/iris.arff" sample: ## Build sample @echo ">>> Building Sample..."; @if [ -d ./sample/build ]; then rm -rf ./sample/build; fi - @cd sample && cmake -B build -S . -D CMAKE_BUILD_TYPE=Debug && cmake --build build -t bayesnet_sample + @cd sample && cmake -B build -S . -D CMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake && \ + cmake --build build -t bayesnet_sample sample/build/bayesnet_sample $(fname) @echo ">>> Done"; diff --git a/README.md b/README.md index f448f1b..936d67f 100644 --- a/README.md +++ b/README.md @@ -12,43 +12,103 @@ Bayesian Network Classifiers library -## Dependencies +## Setup -The only external dependency is [libtorch](https://pytorch.org/cppdocs/installing.html) which can be installed with the following commands: +### Using the vcpkg library -```bash -wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-shared-with-deps-latest.zip -unzip libtorch-shared-with-deps-latest.zip +You can use the library with the vcpkg library manager. In your project you have to add the following files: + +#### vcpkg.json + +```json +{ + "name": "sample-project", + "version-string": "0.1.0", + "dependencies": [ + "bayesnet" + ] +} ``` -## Setup +#### vcpkg-configuration.json + +```json +{ + "registries": [ + { + "kind": "git", + "repository": "https://github.com/rmontanana/vcpkg-stash", + "baseline": "393efa4e74e053b6f02c4ab03738c8fe796b28e5", + "packages": [ + "folding", + "bayesnet", + "arff-files", + "fimdlp", + "libtorch-bin" + ] + } + ], + "default-registry": { + "kind": "git", + "repository": "https://github.com/microsoft/vcpkg", + "baseline": "760bfd0c8d7c89ec640aec4df89418b7c2745605" + } +} +``` + +#### CMakeLists.txt + +You have to include the following lines in your `CMakeLists.txt` file: + +```cmake +find_package(bayesnet CONFIG REQUIRED) + +add_executable(myapp main.cpp) + +target_link_libraries(myapp PRIVATE bayesnet::bayesnet) +``` + +After that, you can use the `vcpkg` command to install the dependencies: + +```bash +vcpkg install +``` + +**Note: In the `sample` folder you can find a sample application that uses the library. You can use it as a reference to create your own application.** + +## Playing with the library + +The dependencies are managed with [vcpkg](https://vcpkg.io/) and supported by a private vcpkg repository in [https://github.com/rmontanana/vcpkg-stash](https://github.com/rmontanana/vcpkg-stash). ### Getting the code ```bash -git clone --recurse-submodules https://github.com/doctorado-ml/bayesnet +git clone https://github.com/doctorado-ml/bayesnet ``` +Once you have the code, you can use the `make` command to build the project. The `Makefile` is used to manage the build process and it will automatically download and install the dependencies. + ### Release ```bash -make release -make buildr -sudo make install +make init # Install dependencies +make release # Build the release version +make buildr # compile and link the release version ``` ### Debug & Tests ```bash -make debug -make test +make init # Install dependencies +make debug # Build the debug version +make test # Run the tests ``` ### Coverage ```bash -make coverage -make viewcoverage +make coverage # Run the tests with coverage +make viewcoverage # View the coverage report in the browser ``` ### Sample app diff --git a/sample/CMakeLists.txt b/sample/CMakeLists.txt index b6f78ac..0cab4bc 100644 --- a/sample/CMakeLists.txt +++ b/sample/CMakeLists.txt @@ -4,24 +4,19 @@ project(bayesnet_sample) set(CMAKE_CXX_STANDARD 17) -find_package(Torch REQUIRED) -find_library(BayesNet NAMES libBayesNet BayesNet libBayesNet.a REQUIRED) -find_path(Bayesnet_INCLUDE_DIRS REQUIRED NAMES bayesnet) -find_library(FImdlp NAMES libfimdlp.a PATHS REQUIRED) - -message(STATUS "FImdlp=${FImdlp}") -message(STATUS "FImdlp_INCLUDE_DIRS=${FImdlp_INCLUDE_DIRS}") -message(STATUS "BayesNet=${BayesNet}") -message(STATUS "Bayesnet_INCLUDE_DIRS=${Bayesnet_INCLUDE_DIRS}") - -include_directories( - ../tests/lib/Files - lib/json/include - /usr/local/include - /usr/local/include/fimdlp/ -) +find_package(Torch CONFIG REQUIRED) +find_package(bayesnet CONFIG REQUIRED) +find_package(fimdlp CONFIG REQUIRED) +find_package(folding CONFIG REQUIRED) +find_package(arff-files CONFIG REQUIRED) +find_package(nlohman_json CONFIG REQUIRED) add_executable(bayesnet_sample sample.cc) -target_link_libraries(bayesnet_sample ${FImdlp} "${TORCH_LIBRARIES}" "${BayesNet}") -add_executable(bayesnet_sample_xspode sample_xspode.cc) -target_link_libraries(bayesnet_sample_xspode ${FImdlp} "${TORCH_LIBRARIES}" "${BayesNet}") \ No newline at end of file +target_link_libraries(bayesnet_sample PRIVATE + fimdlp::fimdlp + arff-files::arff-files + "${TORCH_LIBRARIES}" + bayesnet::bayesnet + nlohmann_json::nlohmann_json + folding::folding +) diff --git a/sample/vcpkg-configuration.json b/sample/vcpkg-configuration.json new file mode 100644 index 0000000..8ac2108 --- /dev/null +++ b/sample/vcpkg-configuration.json @@ -0,0 +1,21 @@ +{ + "registries": [ + { + "kind": "git", + "repository": "https://github.com/rmontanana/vcpkg-stash", + "baseline": "393efa4e74e053b6f02c4ab03738c8fe796b28e5", + "packages": [ + "folding", + "bayesnet", + "arff-files", + "fimdlp", + "libtorch-bin" + ] + } + ], + "default-registry": { + "kind": "git", + "repository": "https://github.com/microsoft/vcpkg", + "baseline": "760bfd0c8d7c89ec640aec4df89418b7c2745605" + } +} \ No newline at end of file diff --git a/sample/vcpkg.json b/sample/vcpkg.json new file mode 100644 index 0000000..f9bfbd4 --- /dev/null +++ b/sample/vcpkg.json @@ -0,0 +1,12 @@ +{ + "name": "sample-project", + "version-string": "0.1.0", + "dependencies": [ + "bayesnet", + "folding", + "arff-files", + "fimdlp", + "nlohmann-json", + "libtorch-bin" + ] +} \ No newline at end of file