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
.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
@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
clean: ## Clean the debug info
@echo ">>> Cleaning Debug BayesNet ...";
find . -name "*.gcda" -print0 | xargs -0 rm
@echo ">>> Cleaning Debug BayesNet...";
$(call ClearTests)
@echo ">>> Done";
clang-uml: ## Create uml class and sequence diagrams
clang-uml -p --add-compile-flag -I /usr/lib/gcc/x86_64-redhat-linux/8/include/
debug: ## Build a debug version of the project
@echo ">>> Building Debug BayesNet ...";
@echo ">>> Building Debug BayesNet...";
@if [ -d ./build ]; then rm -rf ./build; fi
@mkdir build;
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;
@cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -D ENABLE_TESTING=ON -D CODE_COVERAGE=ON;
@echo ">>> Done";
release: ## Build a Release version of the project
@echo ">>> Building Release BayesNet ...";
@echo ">>> Building Release BayesNet...";
@if [ -d ./build ]; then rm -rf ./build; fi
@mkdir build;
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;
@cmake -S . -B build -D CMAKE_BUILD_TYPE=Release;
@echo ">>> Done";
test: ## Run tests
@echo "* Running tests...";
find . -name "*.gcda" -print0 | xargs -0 rm
@cd build; \
cmake --build . --target unit_tests ;
@cd build/tests; \
./unit_tests;
@echo ">>> Running tests...";
$(MAKE) clean
@cmake --build build --target unit_tests ;
@if [ -f build/tests/unit_tests ]; then cd build/tests ; ./unit_tests ; fi ;
@echo ">>> Done";
coverage: ## Run tests and generate coverage report (build/index.html)
@echo "*Building tests...";
find . -name "*.gcda" -print0 | xargs -0 rm
@cd build; \
cmake --build . --target unit_tests ;
@cd build/tests; \
./unit_tests;
gcovr ;
@echo ">>> Building tests with coverage...";
$(MAKE) test
@gcovr
@echo ">>> Done";
define ClearTests =
$(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
@IFS=$$'\n' ; \

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

View File

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