Skip to content
Snippets Groups Projects
Commit 13d0638c authored by Olivier BICHLER's avatar Olivier BICHLER
Browse files

Added Pop operator to handle sequences

parent 7bd2c0f9
No related branches found
No related tags found
No related merge requests found
/********************************************************************************
* Copyright (c) 2023 CEA-List
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
********************************************************************************/
#ifndef AIDGE_CORE_OPERATOR_POP_H_
#define AIDGE_CORE_OPERATOR_POP_H_
#include <cassert>
#include <memory>
#include <vector>
#include "aidge/utils/Registrar.hpp"
#include "aidge/operator/OperatorTensor.hpp"
#include "aidge/backend/OperatorImpl.hpp"
#include "aidge/data/Tensor.hpp"
#include "aidge/graph/Node.hpp"
#include "aidge/utils/Types.h"
#include "aidge/utils/StaticAttributes.hpp"
namespace Aidge {
enum class PopAttr { ForwardStep };
class Pop_Op : public OperatorTensor,
public Registrable<Pop_Op, std::string, std::unique_ptr<OperatorImpl>(const Pop_Op&)>,
public StaticAttributes<PopAttr, unsigned int> {
public:
static const std::string Type;
using Attributes_ = StaticAttributes<PopAttr, unsigned int>;
template <PopAttr e>
using attr = typename Attributes_::template attr<e>;
Pop_Op()
: OperatorTensor(Type, 1, 0, 1),
Attributes_(attr<PopAttr::ForwardStep>(0))
{
}
/**
* @brief Copy-constructor. Copy the operator attributes and its output tensor(s), but not its input tensors (the new operator has no input associated).
* @param op Operator to copy.
*/
Pop_Op(const Pop_Op& op)
: OperatorTensor(op),
Attributes_(op)
{
mImpl = op.mImpl ? Registrar<Pop_Op>::create(op.mOutputs[0]->getImpl()->backend())(*this) : nullptr;
}
/**
* @brief Clone the operator using its copy-constructor.
* @see Operator::Pop_Op
*/
std::shared_ptr<Operator> clone() const override {
return std::make_shared<Pop_Op>(*this);
}
void setBackend(const std::string& name, DeviceIdx_t device = 0) override {
mImpl = Registrar<Pop_Op>::create({name})(*this);
mOutputs[0]->setBackend(name, device);
}
void computeOutputDims() override final;
void updateConsummerProducer() override;
void forward() override;
static const std::vector<std::string> getInputsName(){
return {"data_input"};
}
static const std::vector<std::string> getOutputsName(){
return {"data_output"};
}
};
inline std::shared_ptr<Node> Pop(const std::string& name = "") {
return std::make_shared<Node>(std::make_shared<Pop_Op>(), name);
}
} // namespace Aidge
namespace {
template <>
const char *const EnumStrings<Aidge::PopAttr>::data[] = {
"ForwardStep"
};
}
#endif /* AIDGE_CORE_OPERATOR_POP_H_ */
\ No newline at end of file
/********************************************************************************
* Copyright (c) 2023 CEA-List
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
********************************************************************************/
#include <string>
#include "aidge/operator/Pop.hpp"
const std::string Aidge::Pop_Op::Type = "Pop";
void Aidge::Pop_Op::computeOutputDims() {
// check inputs have been associated
if (!getInput(0)) {
AIDGE_THROW_OR_ABORT(std::runtime_error, "{}: input #0 should be associated with a Tensor", type());
}
if (!(getInput(0)->empty())) {
auto inputDims = getInput(0)->dims();
inputDims.erase(inputDims.begin());
getOutput(0)->resize(inputDims);
}
}
void Aidge::Pop_Op::updateConsummerProducer() {
Operator::updateConsummerProducer();
this->template getAttr<PopAttr::ForwardStep>() = 0;
}
void Aidge::Pop_Op::forward() {
Operator::forward();
++this->template getAttr<PopAttr::ForwardStep>();
}
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