From 472f51daf6ea729e75da10539c4b7fa9ad110b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Monta=C3=B1ana=20G=C3=B3mez?= Date: Mon, 6 Nov 2023 23:44:33 +0100 Subject: [PATCH] Remove trace messages --- src/PyClassifier.cc | 6 +----- src/PyHelper.hpp | 2 -- src/PyWrap.cc | 20 ++------------------ src/main.cc | 2 +- 4 files changed, 4 insertions(+), 26 deletions(-) diff --git a/src/PyClassifier.cc b/src/PyClassifier.cc index c7684a4..a17b7d2 100644 --- a/src/PyClassifier.cc +++ b/src/PyClassifier.cc @@ -1,6 +1,5 @@ #include "PyClassifier.h" #include "numpy/arrayobject.h" -#include namespace pywrap { namespace bp = boost::python; @@ -12,9 +11,7 @@ namespace pywrap { } PyClassifier::~PyClassifier() { - std::cout << "Cleaning Classifier" << std::endl; pyWrap->clean(module, className); - std::cout << "Classifier cleaned" << std::endl; } np::ndarray tensor2numpy(torch::Tensor& X) { @@ -52,13 +49,12 @@ namespace pywrap { auto Xn = tensor2numpy(X); CPyObject Xp = bp::incref(bp::object(Xn).ptr()); PyObject* incoming = pyWrap->predict(module, className, Xp); - std::cout << "Return from predict" << std::endl; bp::handle<> handle(incoming); bp::object object(handle); np::ndarray prediction = np::from_object(object); if (PyErr_Occurred()) { PyErr_Print(); - throw std::runtime_error("Error cleaning module " + module + " and class " + className); + throw std::runtime_error("Error creating object for predict in " + module + " and class " + className); } int* data = reinterpret_cast(prediction.get_data()); std::vector v1(data, data + prediction.shape(0)); diff --git a/src/PyHelper.hpp b/src/PyHelper.hpp index ea3f5df..2db3262 100644 --- a/src/PyHelper.hpp +++ b/src/PyHelper.hpp @@ -14,14 +14,12 @@ namespace pywrap { public: CPyInstance() { - std::cout << "PyHelper:Initializing Python interpreter" << std::endl; Py_Initialize(); np::initialize(); } ~CPyInstance() { - std::cout << "PyHelper:Finalizing Python interpreter" << std::endl; Py_Finalize(); } }; diff --git a/src/PyWrap.cc b/src/PyWrap.cc index f5f183f..2def016 100644 --- a/src/PyWrap.cc +++ b/src/PyWrap.cc @@ -1,7 +1,6 @@ #define PY_SSIZE_T_CLEAN #include #include "PyWrap.h" -#include #include #include #include @@ -17,32 +16,22 @@ namespace pywrap { { std::lock_guard lock(mutex); if (wrapper == nullptr) { - std::cout << "Creando instancia" << std::endl; wrapper = new PyWrap(); pyInstance = new CPyInstance(); - std::cout << "Instancia creada" << std::endl; } return wrapper; } void PyWrap::RemoveInstance() { if (wrapper != nullptr) { - std::cout << "Liberando instancia Python Stack" << std::endl; if (pyInstance != nullptr) { - std::cout << "-Liberando Python => PyHelper" << std::endl; delete pyInstance; - } else { - std::cout << "*No había instancia de python para liberar. => PyHelper" << std::endl; } pyInstance = nullptr; if (wrapper != nullptr) { - std::cout << "-Liberando PyWrap." << std::endl; delete wrapper; - } else { - std::cout << "*No había instancia de PyWrap para liberar." << std::endl; } wrapper = nullptr; - std::cout << "Instancia liberada" << std::endl; } } void PyWrap::importClass(const std::string& moduleName, const std::string& className) @@ -53,7 +42,7 @@ namespace pywrap { } CPyObject module = PyImport_ImportModule(moduleName.c_str()); if (PyErr_Occurred()) { - errorAbort("Could't import module " + moduleName); + errorAbort("Couldn't import module " + moduleName); } CPyObject classObject = PyObject_GetAttrString(module, className.c_str()); if (PyErr_Occurred()) { @@ -68,17 +57,14 @@ namespace pywrap { classObject.AddRef(); instance.AddRef(); moduleClassMap.insert({ { moduleName, className }, { module.getObject(), classObject.getObject(), instance.getObject() } }); - std::cout << "Clase importada" << std::endl; } void PyWrap::clean(const std::string& moduleName, const std::string& className) { std::lock_guard lock(mutex); - std::cout << "Start cleaning " << moduleName << "." << className << std::endl; auto result = moduleClassMap.find({ moduleName, className }); if (result == moduleClassMap.end()) { return; } - std::cout << "--> Cleaning PyObject" << std::endl; Py_DECREF(std::get<0>(result->second)); Py_DECREF(std::get<1>(result->second)); Py_DECREF(std::get<2>(result->second)); @@ -90,11 +76,10 @@ namespace pywrap { if (moduleClassMap.empty()) { RemoveInstance(); } - std::cout << "End Cleaning " << moduleName << "." << className << std::endl; } void PyWrap::errorAbort(const std::string& message) { - std::cout << message << std::endl; + std::cerr << message << std::endl; PyErr_Print(); RemoveInstance(); exit(1); @@ -146,7 +131,6 @@ namespace pywrap { PyObject* PyWrap::predict(const std::string& moduleName, const std::string& className, CPyObject& X) { - std::cout << "Llamando método predict" << std::endl; PyObject* instance = getClass(moduleName, className); PyObject* result; std::string method = "predict"; diff --git a/src/main.cc b/src/main.cc index 82f44de..dabec35 100644 --- a/src/main.cc +++ b/src/main.cc @@ -44,7 +44,7 @@ int main(int argc, char* argv[]) { cout << "* Begin." << endl; { - auto [X, y, features, className, states] = loadDataset("wine", true); + auto [X, y, features, className, states] = loadDataset("wine", false); cout << "X: " << X.sizes() << endl; cout << "y: " << y.sizes() << endl; auto clf = pywrap::STree();