Complete implementation but runtime failing
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "PyClassifier.h"
|
||||
#include <torch/csrc/autograd/python_variable.h>
|
||||
#include <torch/csrc/utils/tensor_numpy.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace pywrap {
|
||||
|
||||
@@ -13,7 +15,11 @@ namespace pywrap {
|
||||
{
|
||||
pyWrap->clean(module, className);
|
||||
}
|
||||
|
||||
PyObject* PyClassifier::toPyObject(torch::Tensor& tensor)
|
||||
{
|
||||
return torch::utils::tensor_to_numpy(tensor);
|
||||
//return THPVariable_Wrap(tensor);
|
||||
}
|
||||
std::string PyClassifier::version()
|
||||
{
|
||||
return pyWrap->version(module, className);
|
||||
@@ -25,10 +31,35 @@ 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)
|
||||
{
|
||||
PyObject* Xp = NULL;//THPVariable_Wrap(X);
|
||||
PyObject* yp = NULL;//THPVariable_Wrap(y);
|
||||
std::cout << "Converting X to PyObject" << std::endl;
|
||||
std::cout << "X.defined() = " << X.defined() << std::endl;
|
||||
//std::cout << "X.pyobj() = " << X.pyobj() << std::endl;
|
||||
PyObject* Xp = toPyObject(X);
|
||||
std::cout << "Converting y to PyObject" << std::endl;
|
||||
PyObject* yp = toPyObject(y);
|
||||
std::cout << "Calling fit" << std::endl;
|
||||
pyWrap->fit(module, className, Xp, yp);
|
||||
Py_DECREF(Xp);
|
||||
Py_DECREF(yp);
|
||||
return *this;
|
||||
}
|
||||
torch::Tensor PyClassifier::predict(torch::Tensor& X)
|
||||
{
|
||||
PyObject* Xp = toPyObject(X);
|
||||
auto PyResult = pyWrap->predict(module, className, Xp);
|
||||
auto result = THPVariable_Unpack(PyResult);
|
||||
Py_DECREF(Xp);
|
||||
Py_DECREF(PyResult);
|
||||
return result;
|
||||
}
|
||||
double PyClassifier::score(torch::Tensor& X, torch::Tensor& y)
|
||||
{
|
||||
PyObject* Xp = toPyObject(X);
|
||||
PyObject* yp = toPyObject(y);
|
||||
auto result = pyWrap->score(module, className, Xp, yp);
|
||||
Py_DECREF(Xp);
|
||||
Py_DECREF(yp);
|
||||
return result;
|
||||
}
|
||||
|
||||
} /* namespace PyWrap */
|
Reference in New Issue
Block a user