Refactor into library
This commit is contained in:
19
Makefile
19
Makefile
@@ -4,8 +4,8 @@ SHELL := /bin/bash
|
|||||||
|
|
||||||
f_release = build_release
|
f_release = build_release
|
||||||
f_debug = build_debug
|
f_debug = build_debug
|
||||||
app_targets = main
|
app_targets = example
|
||||||
test_targets = unit_tests_bayesnet unit_tests_platform
|
test_targets = unit_tests_pywrap
|
||||||
n_procs = -j 16
|
n_procs = -j 16
|
||||||
|
|
||||||
define ClearTests
|
define ClearTests
|
||||||
@@ -31,21 +31,6 @@ setup: ## Install dependencies for tests and coverage
|
|||||||
pip install gcovr; \
|
pip install gcovr; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dest ?= ${HOME}/bin
|
|
||||||
install: ## Copy binary files to bin folder
|
|
||||||
@echo "Destination folder: $(dest)"
|
|
||||||
make buildr
|
|
||||||
@echo ">>> Copying files to $(dest)"
|
|
||||||
@cp $(f_release)/src/Platform/b_main $(dest)
|
|
||||||
@cp $(f_release)/src/Platform/b_list $(dest)
|
|
||||||
@cp $(f_release)/src/Platform/b_manage $(dest)
|
|
||||||
@cp $(f_release)/src/Platform/b_best $(dest)
|
|
||||||
|
|
||||||
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
|
buildd: ## Build the debug targets
|
||||||
cmake --build $(f_debug) -t $(app_targets) $(n_procs)
|
cmake --build $(f_debug) -t $(app_targets) $(n_procs)
|
||||||
|
|
||||||
|
@@ -3,6 +3,9 @@ include_directories(${PyWrap_SOURCE_DIR}/lib/json/include)
|
|||||||
include_directories(${Python3_INCLUDE_DIRS})
|
include_directories(${Python3_INCLUDE_DIRS})
|
||||||
include_directories(${TORCH_INCLUDE_DIRS})
|
include_directories(${TORCH_INCLUDE_DIRS})
|
||||||
|
|
||||||
add_executable(main main.cc STree.cc SVC.cc RandomForest.cc PyClassifier.cc PyWrap.cc)
|
|
||||||
|
|
||||||
target_link_libraries(main ${Python3_LIBRARIES} "${TORCH_LIBRARIES}" ${LIBTORCH_PYTHON} Boost::boost Boost::python Boost::numpy ArffFiles)
|
add_library(PyWrap SHARED PyWrap.cc STree.cc SVC.cc RandomForest.cc PyClassifier.cc)
|
||||||
|
target_link_libraries(PyWrap ${Python3_LIBRARIES} "${TORCH_LIBRARIES}" ${LIBTORCH_PYTHON} Boost::boost Boost::python Boost::numpy ArffFiles)
|
||||||
|
|
||||||
|
add_executable(example example.cc)
|
||||||
|
target_link_libraries(example PyWrap)
|
@@ -1,5 +1,4 @@
|
|||||||
#include "PyClassifier.h"
|
#include "PyClassifier.h"
|
||||||
#include <iostream>
|
|
||||||
namespace pywrap {
|
namespace pywrap {
|
||||||
namespace bp = boost::python;
|
namespace bp = boost::python;
|
||||||
namespace np = boost::python::numpy;
|
namespace np = boost::python::numpy;
|
||||||
@@ -7,7 +6,6 @@ namespace pywrap {
|
|||||||
{
|
{
|
||||||
// This id allows to have more than one instance of the same module/class
|
// This id allows to have more than one instance of the same module/class
|
||||||
id = reinterpret_cast<clfId_t>(this);
|
id = reinterpret_cast<clfId_t>(this);
|
||||||
std::cout << "PyClassifier: Creating instance of " << module << " and class " << className << " id " << id << std::endl;
|
|
||||||
pyWrap = PyWrap::GetInstance();
|
pyWrap = PyWrap::GetInstance();
|
||||||
pyWrap->importClass(id, module, className);
|
pyWrap->importClass(id, module, className);
|
||||||
}
|
}
|
||||||
@@ -40,7 +38,6 @@ namespace pywrap {
|
|||||||
PyClassifier& PyClassifier::fit(torch::Tensor& X, torch::Tensor& y, const std::vector<std::string>& features, const std::string& className, std::map<std::string, std::vector<int>>& states)
|
PyClassifier& PyClassifier::fit(torch::Tensor& X, torch::Tensor& y, const std::vector<std::string>& features, const std::string& className, std::map<std::string, std::vector<int>>& states)
|
||||||
{
|
{
|
||||||
if (!fitted && hyperparameters.size() > 0) {
|
if (!fitted && hyperparameters.size() > 0) {
|
||||||
std::cout << "PyClassifier: Setting hyperparameters" << std::endl;
|
|
||||||
pyWrap->setHyperparameters(id, hyperparameters);
|
pyWrap->setHyperparameters(id, hyperparameters);
|
||||||
}
|
}
|
||||||
auto [Xn, yn] = tensors2numpy(X, y);
|
auto [Xn, yn] = tensors2numpy(X, y);
|
||||||
|
@@ -3,7 +3,6 @@
|
|||||||
#include "PyWrap.h"
|
#include "PyWrap.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <boost/python/numpy.hpp>
|
#include <boost/python/numpy.hpp>
|
||||||
|
|
||||||
@@ -117,7 +116,6 @@ namespace pywrap {
|
|||||||
void PyWrap::setHyperparameters(const clfId_t id, const json& hyperparameters)
|
void PyWrap::setHyperparameters(const clfId_t id, const json& hyperparameters)
|
||||||
{
|
{
|
||||||
// Set hyperparameters as attributes of the class
|
// Set hyperparameters as attributes of the class
|
||||||
std::cout << "Building dictionary of arguments" << std::endl;
|
|
||||||
PyObject* pValue;
|
PyObject* pValue;
|
||||||
PyObject* instance = getClass(id);
|
PyObject* instance = getClass(id);
|
||||||
for (const auto& [key, value] : hyperparameters.items()) {
|
for (const auto& [key, value] : hyperparameters.items()) {
|
||||||
|
Reference in New Issue
Block a user