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

Fix 'Producer_Op::clone' to create a new producer and not use shallow copy

parent 2e5ace67
No related branches found
No related tags found
2 merge requests!279v0.4.0,!273[Fix] Producer clone and Tensor copy
......@@ -44,7 +44,7 @@ Aidge::Producer_Op::Producer_Op(const std::shared_ptr<Aidge::Tensor> tensor, boo
attr<ProdAttr::Constant>(constant)))
{
mOutputs[0] = tensor; // copy the pointer of the Tensor
if (mOutputs[0]->getImpl() && Registrar<Producer_Op>::exists({mOutputs[0]->getImpl()->backend()})){
if (mOutputs[0] && mOutputs[0]->hasImpl() && Registrar<Producer_Op>::exists({mOutputs[0]->getImpl()->backend()})){
SET_IMPL_MACRO(Producer_Op, *this, mOutputs[0]->getImpl()->backend());
}
else {
......@@ -61,7 +61,7 @@ Aidge::Producer_Op::Producer_Op(const Aidge::Producer_Op& op)
: OperatorTensor(op),
mAttributes(op.mAttributes)
{
mOutputs[0] = std::make_shared<Tensor>(*(op.getOutput(0)));
*mOutputs[0] = *(op.getOutput(0));
if (mOutputs[0]->getImpl() && Registrar<Producer_Op>::exists({mOutputs[0]->getImpl()->backend()})){
SET_IMPL_MACRO(Producer_Op, *this, mOutputs[0]->getImpl()->backend());
}
......@@ -71,7 +71,12 @@ Aidge::Producer_Op::Producer_Op(const Aidge::Producer_Op& op)
}
std::shared_ptr<Aidge::Operator> Aidge::Producer_Op::clone() const {
return std::make_shared<Producer_Op>(*this);
// mOutput cannot be nullptr because of OperatorTensor constructor
std::shared_ptr<Tensor> newTensor = std::make_shared<Tensor>(mOutputs[0]->clone());
std::shared_ptr<Producer_Op> newOp = std::make_shared<Producer_Op>(newTensor, constant());
return newOp;
}
void Aidge::Producer_Op::setBackend(const std::string& name, Aidge::DeviceIdx_t device) {
......
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