Skip to content
Snippets Groups Projects
Commit 9412a125 authored by Noam Zerah's avatar Noam Zerah Committed by Maxence Naud
Browse files

Adding new operator Round

parent c38018d4
No related branches found
No related tags found
3 merge requests!279v0.4.0,!253v0.4.0,!214New operator Round
Pipeline #56530 passed
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
#include "aidge/operator/ReLU.hpp" #include "aidge/operator/ReLU.hpp"
#include "aidge/operator/Reshape.hpp" #include "aidge/operator/Reshape.hpp"
#include "aidge/operator/Resize.hpp" #include "aidge/operator/Resize.hpp"
#include "aidge/operator/Round.hpp"
#include "aidge/operator/Shape.hpp" #include "aidge/operator/Shape.hpp"
#include "aidge/operator/Scaling.hpp" #include "aidge/operator/Scaling.hpp"
#include "aidge/operator/Slice.hpp" #include "aidge/operator/Slice.hpp"
......
/********************************************************************************
* 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_ROUND_H_
#define AIDGE_CORE_OPERATOR_ROUND_H_
#include <memory>
#include <vector>
#include <string>
#include "aidge/graph/Node.hpp"
#include "aidge/operator/OperatorTensor.hpp"
#include "aidge/utils/StaticAttributes.hpp"
#include "aidge/utils/Registrar.hpp"
#include "aidge/utils/Types.h"
namespace Aidge {
class Round_Op : public OperatorTensor,
public Registrable<Round_Op,
std::string,
std::function<std::shared_ptr<OperatorImpl>(const Round_Op&)>> {
public:
static const std::string Type;
Round_Op() : OperatorTensor(Type, {InputCategory::Data}, 1) {}
/**
* @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.
*/
Round_Op(const Round_Op& op);
/**
* @brief Clone the operator using its copy-constructor.
* @see Operator::Round_Op
*/
std::shared_ptr<Operator> clone() const override;
void setBackend(const std::string& name, DeviceIdx_t device = 0) override final;
std::set<std::string> getAvailableBackends() const override;
static const std::vector<std::string> getInputsName(){
return {"data_input"};
}
static const std::vector<std::string> getOutputsName(){
return {"data_output"};
}
};
std::shared_ptr<Node> Round(const std::string& name = "");
}
#endif /* AIDGE_CORE_OPERATOR_ROUND_H_ */
/********************************************************************************
* 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 <pybind11/pybind11.h>
#include "aidge/operator/Round.hpp"
#include "aidge/operator/OperatorTensor.hpp"
namespace py = pybind11;
namespace Aidge {
void init_Round(py::module& m) {
py::class_<Round_Op, std::shared_ptr<Round_Op>, OperatorTensor>(m, "RoundOp", py::multiple_inheritance())
.def(py::init<>())
.def_static("get_inputs_name", &Round_Op::getInputsName)
.def_static("get_outputs_name", &Round_Op::getOutputsName)
.def_readonly_static("Type", &Round_Op::Type);
declare_registrable<Round_Op>(m, "RoundOp");
m.def("Round", &Round, py::arg("name") = "", R"mydelimiter(
RoundOp is a tensor operator that rounds the values of a tensor element-wise.
This class rounds each value to the nearest integer. In the case of halves,
the rule is to round them to the nearest even integer.
:param X: input tensor.
:type X: tensor of type float, double, float16, or bfloat16.
:param Y: output tensor with the same shape and type as the input tensor.
)mydelimiter");
}
} // namespace Aidge
...@@ -61,6 +61,7 @@ void init_ReduceMean(py::module&); ...@@ -61,6 +61,7 @@ void init_ReduceMean(py::module&);
void init_ReduceSum(py::module&); void init_ReduceSum(py::module&);
void init_Reshape(py::module&); void init_Reshape(py::module&);
void init_Resize(py::module&); void init_Resize(py::module&);
void init_Round(py::module&);
void init_Scaling(py::module&); void init_Scaling(py::module&);
void init_Shape(py::module&); void init_Shape(py::module&);
void init_Sigmoid(py::module&); void init_Sigmoid(py::module&);
...@@ -143,6 +144,7 @@ void init_Aidge(py::module& m) { ...@@ -143,6 +144,7 @@ void init_Aidge(py::module& m) {
init_ReduceSum(m); init_ReduceSum(m);
init_Reshape(m); init_Reshape(m);
init_Resize(m); init_Resize(m);
init_Round(m);
init_Scaling(m); init_Scaling(m);
init_Shape(m); init_Shape(m);
init_Sigmoid(m); init_Sigmoid(m);
......
/********************************************************************************
* 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 "aidge/operator/Round.hpp"
#include <memory>
#include <string>
#include "aidge/backend/OperatorImpl.hpp"
#include "aidge/data/Tensor.hpp"
#include "aidge/utils/Registrar.hpp"
#include "aidge/utils/Types.h"
const std::string Aidge::Round_Op::Type = "Round";
Aidge::Round_Op::Round_Op(const Aidge::Round_Op& op)
: OperatorTensor(op)
{
if (op.mImpl){
SET_IMPL_MACRO(Round_Op, *this, op.backend());
}else{
mImpl = nullptr;
}
}
std::shared_ptr<Aidge::Operator> Aidge::Round_Op::clone() const {
return std::make_shared<Round_Op>(*this);
}
void Aidge::Round_Op::setBackend(const std::string& name, Aidge::DeviceIdx_t device) {
mImpl = Registrar<Round_Op>::create(name)(*this);
mOutputs[0]->setBackend(name, device);
}
std::set<std::string> Aidge::Round_Op::getAvailableBackends() const {
return Registrar<Round_Op>::getKeys();
}
std::shared_ptr<Aidge::Node> Aidge::Round(const std::string& name) {
return std::make_shared<Node>(std::make_shared<Round_Op>(), name);
}
\ 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