Skip to content
Snippets Groups Projects
Commit da65006f authored by Cyril Moineau's avatar Cyril Moineau
Browse files

Add Pad operator to python binding.

parent 16ff708b
No related branches found
No related tags found
1 merge request!56Changes related to aidgeonnx::DevONNX
/********************************************************************************
* 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
......@@ -34,6 +34,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&);
......@@ -79,6 +80,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);
......
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