Refactor Makefile

This commit is contained in:
Ricardo Montañana Gómez 2023-10-05 11:45:00 +02:00
parent 5f0676691c
commit da8d018ec4
Signed by: rmontanana
GPG Key ID: 46064262FD9A7ADE
3 changed files with 33 additions and 41 deletions

View File

@ -1,6 +1,6 @@
SHELL := /bin/bash SHELL := /bin/bash
.DEFAULT_GOAL := help .DEFAULT_GOAL := help
.PHONY: coverage setup help build test .PHONY: coverage setup help build test clean debug release
setup: ## Install dependencies for tests and coverage setup: ## Install dependencies for tests and coverage
@if [ "$(shell uname)" = "Darwin" ]; then \ @if [ "$(shell uname)" = "Darwin" ]; then \
@ -28,45 +28,47 @@ build: ## Build the main and BayesNetSample
cmake --build build -t b_main -t BayesNetSample -t b_manage -t b_list -t b_best -j 32 cmake --build build -t b_main -t BayesNetSample -t b_manage -t b_list -t b_best -j 32
clean: ## Clean the debug info clean: ## Clean the debug info
@echo ">>> Cleaning Debug BayesNet ..."; @echo ">>> Cleaning Debug BayesNet...";
find . -name "*.gcda" -print0 | xargs -0 rm $(call ClearTests)
@echo ">>> Done"; @echo ">>> Done";
clang-uml: ## Create uml class and sequence diagrams clang-uml: ## Create uml class and sequence diagrams
clang-uml -p --add-compile-flag -I /usr/lib/gcc/x86_64-redhat-linux/8/include/ clang-uml -p --add-compile-flag -I /usr/lib/gcc/x86_64-redhat-linux/8/include/
debug: ## Build a debug version of the project debug: ## Build a debug version of the project
@echo ">>> Building Debug BayesNet ..."; @echo ">>> Building Debug BayesNet...";
@if [ -d ./build ]; then rm -rf ./build; fi @if [ -d ./build ]; then rm -rf ./build; fi
@mkdir build; @mkdir build;
cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -D ENABLE_TESTING=ON -D CODE_COVERAGE=ON; \ @cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -D ENABLE_TESTING=ON -D CODE_COVERAGE=ON;
cmake --build build -t b_main -t BayesNetSample -t b_manage -t b_list -t b_best -t unit_tests -j 32;
@echo ">>> Done"; @echo ">>> Done";
release: ## Build a Release version of the project release: ## Build a Release version of the project
@echo ">>> Building Release BayesNet ..."; @echo ">>> Building Release BayesNet...";
@if [ -d ./build ]; then rm -rf ./build; fi @if [ -d ./build ]; then rm -rf ./build; fi
@mkdir build; @mkdir build;
cmake -S . -B build -D CMAKE_BUILD_TYPE=Release; \ @cmake -S . -B build -D CMAKE_BUILD_TYPE=Release;
cmake --build build -t b_main -t BayesNetSample -t b_manage -t b_list -t b_best -j 32;
@echo ">>> Done"; @echo ">>> Done";
test: ## Run tests test: ## Run tests
@echo "* Running tests..."; @echo ">>> Running tests...";
find . -name "*.gcda" -print0 | xargs -0 rm $(MAKE) clean
@cd build; \ @cmake --build build --target unit_tests ;
cmake --build . --target unit_tests ; @if [ -f build/tests/unit_tests ]; then cd build/tests ; ./unit_tests ; fi ;
@cd build/tests; \ @echo ">>> Done";
./unit_tests;
coverage: ## Run tests and generate coverage report (build/index.html) coverage: ## Run tests and generate coverage report (build/index.html)
@echo "*Building tests..."; @echo ">>> Building tests with coverage...";
find . -name "*.gcda" -print0 | xargs -0 rm $(MAKE) test
@cd build; \ @gcovr
cmake --build . --target unit_tests ; @echo ">>> Done";
@cd build/tests; \
./unit_tests; define ClearTests =
gcovr ; $(eval nfiles=$(find . -name "*.gcda" -print))
@if [ -f build/tests/unit_tests ]; then rm -f build/tests/unit_tests ; fi ;
@if test "${nfiles}" != "" ; then \
find . -name "*.gcda" -print0 | xargs -0 rm 2>/dev/null ;\
fi ;
endef
help: ## Show help message help: ## Show help message
@IFS=$$'\n' ; \ @IFS=$$'\n' ; \

@ -1 +1 @@
Subproject commit 44e72c5862f9d549453a4ff6e8ceab0da19705e5 Subproject commit 29355a0887475488c7cc470ad43cc867fcfa92e2

View File

@ -9,7 +9,7 @@ using namespace std;
TEST_CASE("Metrics Test", "[Metrics]") TEST_CASE("Metrics Test", "[Metrics]")
{ {
string file_name = GENERATE("glass", "iris", "ecoli", "diabetes"); string file_name = GENERATE("glass", "iris", "ecoli", "diabetes");
map<string, pair<int, vector<int>>> results = { map<string, pair<int, vector<int>>> resultsKBest = {
{"glass", {7, { 3, 2, 0, 1, 6, 7, 5 }}}, {"glass", {7, { 3, 2, 0, 1, 6, 7, 5 }}},
{"iris", {3, { 1, 0, 2 }} }, {"iris", {3, { 1, 0, 2 }} },
{"ecoli", {6, { 2, 3, 1, 0, 4, 5 }}}, {"ecoli", {6, { 2, 3, 1, 0, 4, 5 }}},
@ -31,26 +31,16 @@ TEST_CASE("Metrics Test", "[Metrics]")
{ {
bayesnet::Metrics metrics(XDisc, featuresDisc, classNameDisc, classNumStates); bayesnet::Metrics metrics(XDisc, featuresDisc, classNameDisc, classNumStates);
torch::Tensor weights = torch::full({ nSamples }, 1.0 / nSamples, torch::kDouble); torch::Tensor weights = torch::full({ nSamples }, 1.0 / nSamples, torch::kDouble);
vector<int> kBest = metrics.SelectKBestWeighted(weights, true, results.at(file_name).first); vector<int> kBest = metrics.SelectKBestWeighted(weights, true, resultsKBest.at(file_name).first);
REQUIRE(kBest.size() == results.at(file_name).first); REQUIRE(kBest.size() == resultsKBest.at(file_name).first);
REQUIRE(kBest == results.at(file_name).second); REQUIRE(kBest == resultsKBest.at(file_name).second);
} }
SECTION("Test mutualInformation") SECTION("Test mutualInformation")
{ {
// torch::Tensor samples = torch::rand({ 10, 5 }); bayesnet::Metrics metrics(XDisc, featuresDisc, classNameDisc, classNumStates);
// vector<string> features = { "feature1", "feature2", "feature3", "feature4", "feature5" }; torch::Tensor weights = torch::full({ nSamples }, 1.0 / nSamples, torch::kDouble);
// string className = "class1"; auto result = metrics.mutualInformation(dataset.index({ 1, "..." }), dataset.index({ 2, "..." }), weights);
// int classNumStates = 2; REQUIRE(result == 0.87);
// bayesnet::Metrics obj(samples, features, className, classNumStates);
// torch::Tensor firstFeature = samples.select(1, 0);
// torch::Tensor secondFeature = samples.select(1, 1);
// torch::Tensor weights = torch::ones({ 10 });
// double mi = obj.mutualInformation(firstFeature, secondFeature, weights);
// REQUIRE(mi >= 0);
} }
} }