Skip to content
Snippets Groups Projects
Commit e1520d3f authored by Maxence Naud's avatar Maxence Naud
Browse files

Fix Producer constructor with pybind

parent 1fb848bd
No related branches found
No related tags found
2 merge requests!105version 0.2.0,!88Basic supervised learning
...@@ -32,9 +32,28 @@ Aidge::Producer_Op::Producer_Op(const std::shared_ptr<Aidge::Tensor> tensor, boo ...@@ -32,9 +32,28 @@ Aidge::Producer_Op::Producer_Op(const std::shared_ptr<Aidge::Tensor> tensor, boo
Attributes_(attr<ProdAttr::Constant>(constant)) Attributes_(attr<ProdAttr::Constant>(constant))
{ {
mOutputs[0] = tensor; // copy the pointer of the Tensor mOutputs[0] = tensor; // copy the pointer of the Tensor
mImpl = (tensor->hasImpl()) ? #ifdef PYBIND
std::make_shared<OperatorImpl>(*this, tensor->getImpl()->backend()) : if(Py_IsInitialized()) {
nullptr; auto obj = py::cast(&(*this));
setImpl((mOutputs[0]->hasImpl()) ?
(Registrar<Producer_Op>::exists({mOutputs[0]->getImpl()->backend()}) ?
Registrar<Producer_Op>::create(mOutputs[0]->getImpl()->backend())(*this) :
std::make_shared<OperatorImpl>(*this, mOutputs[0]->getImpl()->backend())) :
nullptr);
} else {
setImpl((mOutputs[0]->hasImpl()) ?
(Registrar<Producer_Op>::exists({mOutputs[0]->getImpl()->backend()}) ?
Registrar<Producer_Op>::create(mOutputs[0]->getImpl()->backend())(*this) :
std::make_shared<OperatorImpl>(*this, mOutputs[0]->getImpl()->backend())) :
nullptr);
}
#else
setImpl((mOutputs[0]->hasImpl()) ?
(Registrar<Producer_Op>::exists({mOutputs[0]->getImpl()->backend()}) ?
Registrar<Producer_Op>::create(mOutputs[0]->getImpl()->backend())(*this) :
std::make_shared<OperatorImpl>(*this, mOutputs[0]->getImpl()->backend())) :
nullptr);
#endif
} }
/** /**
...@@ -46,12 +65,29 @@ Aidge::Producer_Op::Producer_Op(const Aidge::Producer_Op& op) ...@@ -46,12 +65,29 @@ Aidge::Producer_Op::Producer_Op(const Aidge::Producer_Op& op)
: OperatorTensor(op), : OperatorTensor(op),
Attributes_(op) Attributes_(op)
{ {
if (op.mImpl){ mOutputs[0] = std::make_shared<Tensor>(*(op.getOutput(0)));
SET_IMPL_MACRO(Producer_Op, *this, op.backend()); #ifdef PYBIND
} else { if(Py_IsInitialized()) {
mImpl = nullptr; auto obj = py::cast(&(*this));
} setImpl((mOutputs[0]->hasImpl()) ?
// mOutputs[0] = std::make_shared<Tensor>(*(op.getOutput(0))); (Registrar<Producer_Op>::exists({mOutputs[0]->getImpl()->backend()}) ?
Registrar<Producer_Op>::create(mOutputs[0]->getImpl()->backend())(*this) :
std::make_shared<OperatorImpl>(*this, mOutputs[0]->getImpl()->backend())) :
nullptr);
} else {
setImpl((mOutputs[0]->hasImpl()) ?
(Registrar<Producer_Op>::exists({mOutputs[0]->getImpl()->backend()}) ?
Registrar<Producer_Op>::create(mOutputs[0]->getImpl()->backend())(*this) :
std::make_shared<OperatorImpl>(*this, mOutputs[0]->getImpl()->backend())) :
nullptr);
}
#else
setImpl((mOutputs[0]->hasImpl()) ?
(Registrar<Producer_Op>::exists({mOutputs[0]->getImpl()->backend()}) ?
Registrar<Producer_Op>::create(mOutputs[0]->getImpl()->backend())(*this) :
std::make_shared<OperatorImpl>(*this, mOutputs[0]->getImpl()->backend())) :
nullptr);
#endif
// if (mOutputs[0]->hasImpl()) { // if (mOutputs[0]->hasImpl()) {
// if (Registrar<Producer_Op>::exists({mOutputs[0]->getImpl()->backend()})){ // if (Registrar<Producer_Op>::exists({mOutputs[0]->getImpl()->backend()})){
// setImpl(Registrar<Producer_Op>::create(mOutputs[0]->getImpl()->backend())(*this)); // setImpl(Registrar<Producer_Op>::create(mOutputs[0]->getImpl()->backend())(*this));
...@@ -66,6 +102,21 @@ Aidge::Producer_Op::Producer_Op(const Aidge::Producer_Op& op) ...@@ -66,6 +102,21 @@ Aidge::Producer_Op::Producer_Op(const Aidge::Producer_Op& op)
} }
void Aidge::Producer_Op::setBackend(const std::string& name, Aidge::DeviceIdx_t device) { void Aidge::Producer_Op::setBackend(const std::string& name, Aidge::DeviceIdx_t device) {
SET_IMPL_MACRO(Producer_Op, *this, name); #ifdef PYBIND
if(Py_IsInitialized()) {
auto obj = py::cast(&(*this));
setImpl((Registrar<Producer_Op>::exists({name})) ?
Registrar<Producer_Op>::create(name)(*this) :
std::make_shared<OperatorImpl>(*this, name));
} else {
setImpl((Registrar<Producer_Op>::exists({name})) ?
Registrar<Producer_Op>::create(name)(*this) :
std::make_shared<OperatorImpl>(*this, name));
}
#else
setImpl((Registrar<Producer_Op>::exists({name})) ?
Registrar<Producer_Op>::create(name)(*this) :
std::make_shared<OperatorImpl>(*this, name));
#endif
mOutputs[0]->setBackend(name, device); mOutputs[0]->setBackend(name, device);
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment