diff --git a/python_binding/operator/pybind_MetaOperatorDefs.cpp b/python_binding/operator/pybind_MetaOperatorDefs.cpp index 6df5a43f64bf8335108ccd99a1588a1367955b77..d1eff7b387f9b339e6641a8049e020a7e8a4f021 100644 --- a/python_binding/operator/pybind_MetaOperatorDefs.cpp +++ b/python_binding/operator/pybind_MetaOperatorDefs.cpp @@ -122,7 +122,8 @@ void init_MetaOperatorDefs(py::module &m) { declare_PaddedMaxPoolingOp<2>(m); declare_PaddedMaxPoolingOp<3>(m); - py::class_<MetaOperator_Op, std::shared_ptr<MetaOperator_Op>, Operator>(m, "MetaOperator_Op", py::multiple_inheritance()); + py::class_<MetaOperator_Op, std::shared_ptr<MetaOperator_Op>, Operator>(m, "MetaOperator_Op", py::multiple_inheritance()) + .def("get_micro_graph", &MetaOperator_Op::getMicroGraph); m.def("meta_operator", &MetaOperator, py::arg("type"), diff --git a/python_binding/operator/pybind_Pad.cpp b/python_binding/operator/pybind_Pad.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0956d6260e50d3be2418b1cf4089df87e442e54a --- /dev/null +++ b/python_binding/operator/pybind_Pad.cpp @@ -0,0 +1,66 @@ +/******************************************************************************** + * 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 <pybind11/stl.h> +#include <iostream> +#include <string> +#include <vector> +#include <array> + +#include "aidge/backend/OperatorImpl.hpp" +#include "aidge/operator/Pad.hpp" +#include "aidge/operator/Operator.hpp" +#include "aidge/utils/Types.h" + +namespace py = pybind11; +namespace Aidge { + +template <DimIdx_t DIM> void declare_PadOp(py::module &m) { + py::class_<Pad_Op<DIM>, std::shared_ptr<Pad_Op<DIM>>, Operator, Attributes>( + m, ("PadOp" + std::to_string(DIM) + "D").c_str(), + py::multiple_inheritance()) + .def(py::init<const std::array<DimSize_t, 2*DIM> &, + const PadBorderType &, + double>(), + py::arg("beginEndTuples"), + py::arg("borderType") = PadBorderType::Constant, + py::arg("borderValue") = 0.0) + .def("get_inputs_name", &Pad_Op<DIM>::getInputsName) + .def("get_outputs_name", &Pad_Op<DIM>::getOutputsName) + ; + + m.def(("Pad" + std::to_string(DIM) + "D").c_str(), [](const std::vector<DimSize_t>& beginEndTuples, + const std::string& name, + const PadBorderType &borderType = PadBorderType::Constant, + double borderValue = 0.0) { + AIDGE_ASSERT(beginEndTuples.size() == 2*DIM, "begin_end_tuples size [%ld] does not match DIM [%d]", beginEndTuples.size(), 2*DIM); + return Pad<DIM>(to_array<2*DIM>(beginEndTuples.begin()), name, borderType, borderValue); + }, + py::arg("begin_end_tuples"), + py::arg("name") = "", + py::arg("border_type") = PadBorderType::Constant, + py::arg("border_value") = 0.0); +} + + +void init_Pad(py::module &m) { + py::enum_<PadBorderType>(m, "pad_border_type") + .value("Constant", PadBorderType::Constant) + .value("Edge", PadBorderType::Edge) + .value("Reflect", PadBorderType::Reflect) + .value("Wrap", PadBorderType::Wrap) + .export_values(); + declare_PadOp<1>(m); + declare_PadOp<2>(m); + declare_PadOp<3>(m); +} +} // namespace Aidge diff --git a/python_binding/pybind_core.cpp b/python_binding/pybind_core.cpp index 23b54e46b23a341add8ba7291551c0f84f705bea..b1e0e0d11fbbae61a6b853e866adc02e77f315dd 100644 --- a/python_binding/pybind_core.cpp +++ b/python_binding/pybind_core.cpp @@ -35,6 +35,7 @@ void init_MaxPooling(py::module&); void init_MetaOperatorDefs(py::module&); void init_Mul(py::module&); void init_Producer(py::module&); +void init_Pad(py::module&); void init_Pow(py::module&); void init_ReLU(py::module&); void init_Softmax(py::module&); @@ -81,6 +82,8 @@ void init_Aidge(py::module& m){ init_MaxPooling(m); init_MetaOperatorDefs(m); init_Mul(m); + init_Pad(m); + init_Pow(m); init_ReLU(m); init_Softmax(m);