From 1be1a5ccca009a0070f646235f59f71f33ad56b7 Mon Sep 17 00:00:00 2001 From: cmoineau <cyril.moineau@cea.fr> Date: Tue, 24 Sep 2024 12:11:31 +0000 Subject: [PATCH] Add Atan operator to aidge_core. --- include/aidge/operator/Atan.hpp | 53 +++++++++++++++++++++++++ python_binding/operator/pybind_Atan.cpp | 31 +++++++++++++++ python_binding/pybind_core.cpp | 2 + src/operator/Atan.cpp | 53 +++++++++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 include/aidge/operator/Atan.hpp create mode 100644 python_binding/operator/pybind_Atan.cpp create mode 100644 src/operator/Atan.cpp diff --git a/include/aidge/operator/Atan.hpp b/include/aidge/operator/Atan.hpp new file mode 100644 index 000000000..c6b6abab9 --- /dev/null +++ b/include/aidge/operator/Atan.hpp @@ -0,0 +1,53 @@ +/******************************************************************************** + * 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_ATAN_H_ +#define AIDGE_CORE_OPERATOR_ATAN_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" + +namespace Aidge { + +class Atan_Op : public OperatorTensor, + public Registrable<Atan_Op, std::string, std::function<std::shared_ptr<OperatorImpl>(const Atan_Op&)>> { +public: + static const std::string Type; + + Atan_Op(); + + Atan_Op(const Atan_Op& 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> Atan(const std::string& name = ""); +} + +#endif /* AIDGE_CORE_OPERATOR_ATAN_H_ */ diff --git a/python_binding/operator/pybind_Atan.cpp b/python_binding/operator/pybind_Atan.cpp new file mode 100644 index 000000000..e9e277fcc --- /dev/null +++ b/python_binding/operator/pybind_Atan.cpp @@ -0,0 +1,31 @@ +/******************************************************************************** + * 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/data/Tensor.hpp" +#include "aidge/operator/Atan.hpp" +#include "aidge/operator/OperatorTensor.hpp" + +namespace py = pybind11; +namespace Aidge { + +void init_Atan(py::module& m) { + py::class_<Atan_Op, std::shared_ptr<Atan_Op>, OperatorTensor>(m, "AtanOp", py::multiple_inheritance()) + .def(py::init<>()) + .def_static("get_inputs_name", &Atan_Op::getInputsName) + .def_static("get_outputs_name", &Atan_Op::getOutputsName); + + declare_registrable<Atan_Op>(m, "AtanOp"); + + m.def("Atan", &Atan, py::arg("name") = ""); +} +} // namespace Aidge diff --git a/python_binding/pybind_core.cpp b/python_binding/pybind_core.cpp index d8fa37507..f0db1e0f0 100644 --- a/python_binding/pybind_core.cpp +++ b/python_binding/pybind_core.cpp @@ -31,6 +31,7 @@ void init_OperatorTensor(py::module&); void init_Add(py::module&); void init_And(py::module&); void init_ArgMax(py::module&); +void init_Atan(py::module&); void init_AvgPooling(py::module&); void init_BatchNorm(py::module&); void init_Concat(py::module&); @@ -113,6 +114,7 @@ void init_Aidge(py::module& m) { init_Add(m); init_And(m); init_ArgMax(m); + init_Atan(m); init_AvgPooling(m); init_BatchNorm(m); init_Concat(m); diff --git a/src/operator/Atan.cpp b/src/operator/Atan.cpp new file mode 100644 index 000000000..c0a494ee6 --- /dev/null +++ b/src/operator/Atan.cpp @@ -0,0 +1,53 @@ +/******************************************************************************** + * 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/Atan.hpp" + +#include <memory> +#include <string> + +#include "aidge/data/Tensor.hpp" +#include "aidge/utils/Registrar.hpp" +#include "aidge/utils/Types.h" + +const std::string Aidge::Atan_Op::Type = "Atan"; + +Aidge::Atan_Op::Atan_Op() : OperatorTensor(Type, {InputCategory::Data}, 1) {} + +Aidge::Atan_Op::Atan_Op(const Aidge::Atan_Op& op) + : OperatorTensor(op) +{ + if (op.mImpl){ + SET_IMPL_MACRO(Atan_Op, *this, op.backend()); + } else { + mImpl = nullptr; + } +} + +std::shared_ptr<Aidge::Operator> Aidge::Atan_Op::clone() const { + return std::make_shared<Atan_Op>(*this); +} + + +void Aidge::Atan_Op::setBackend(const std::string& name, Aidge::DeviceIdx_t device) { + mImpl = Registrar<Atan_Op>::create(name)(*this); + mOutputs[0]->setBackend(name, device); +} + +std::set<std::string> Aidge::Atan_Op::getAvailableBackends() const { + return Registrar<Atan_Op>::getKeys(); +} + +/////////////////////////////////////////////////// + +std::shared_ptr<Aidge::Node> Aidge::Atan(const std::string& name) { + return std::make_shared<Node>(std::make_shared<Atan_Op>(), name); +} -- GitLab