Skip to content
Snippets Groups Projects
Commit 1ca06bd3 authored by Maxence Naud's avatar Maxence Naud
Browse files

add pybind changes

parent 988de664
No related branches found
No related tags found
No related merge requests found
Showing
with 186 additions and 58 deletions
...@@ -9,11 +9,11 @@ ...@@ -9,11 +9,11 @@
* *
********************************************************************************/ ********************************************************************************/
#include <memory>
#include <pybind11/pybind11.h> #include <pybind11/pybind11.h>
#include "aidge/operator/Add.hpp" #include "aidge/operator/Add.hpp"
#include "aidge/data/Tensor.hpp"
#include "aidge/backend/OperatorImpl.hpp"
#include "aidge/operator/OperatorTensor.hpp" #include "aidge/operator/OperatorTensor.hpp"
#include "aidge/utils/Types.h" #include "aidge/utils/Types.h"
...@@ -22,13 +22,17 @@ namespace Aidge { ...@@ -22,13 +22,17 @@ namespace Aidge {
void declare_Add(py::module &m) { void declare_Add(py::module &m) {
py::class_<Add_Op, std::shared_ptr<Add_Op>, OperatorTensor>(m, "AddOp", py::multiple_inheritance()) py::class_<Add_Op, std::shared_ptr<Add_Op>, OperatorTensor>(m, "AddOp", py::multiple_inheritance())
.def_static("get_inputs_name", &Add_Op::getInputsName) .def(py::init<const IOIndex_t>(), py::arg("nb_inputs"))
.def_static("get_outputs_name", &Add_Op::getOutputsName); .def_static("get_inputs_name", &Add_Op::getInputsName)
.def_static("get_outputs_name", &Add_Op::getOutputsName);
declare_registrable<Add_Op>(m, "AddOp"); declare_registrable<Add_Op>(m, "AddOp");
m.def("Add", &Add, py::arg("nbIn"), py::arg("name") = "");
m.def("Add", &Add, py::arg("nb_inputs"), py::arg("name") = "");
} }
void init_Add(py::module &m) { void init_Add(py::module &m) {
declare_Add(m); declare_Add(m);
} }
} // namespace Aidge } // namespace Aidge
...@@ -28,16 +28,18 @@ namespace Aidge { ...@@ -28,16 +28,18 @@ namespace Aidge {
template <DimIdx_t DIM> void declare_AvgPoolingOp(py::module &m) { template <DimIdx_t DIM> void declare_AvgPoolingOp(py::module &m) {
const std::string pyClassName("AvgPoolingOp" + std::to_string(DIM) + "D"); const std::string pyClassName("AvgPoolingOp" + std::to_string(DIM) + "D");
py::class_<AvgPooling_Op<DIM>, std::shared_ptr<AvgPooling_Op<DIM>>, Attributes, OperatorTensor>( py::class_<AvgPooling_Op<DIM>, std::shared_ptr<AvgPooling_Op<DIM>>, Attributes, OperatorTensor>(
m, pyClassName.c_str(), m, pyClassName.c_str(),
py::multiple_inheritance()) py::multiple_inheritance())
.def(py::init<const std::array<DimSize_t, DIM> &, .def(py::init<const std::array<DimSize_t, DIM> &,
const std::array<DimSize_t, DIM> &>(), const std::array<DimSize_t, DIM> &>(),
py::arg("kernel_dims"), py::arg("kernel_dims"),
py::arg("stride_dims")) py::arg("stride_dims"))
.def("get_inputs_name", &AvgPooling_Op<DIM>::getInputsName) .def("get_inputs_name", &AvgPooling_Op<DIM>::getInputsName)
.def("get_outputs_name", &AvgPooling_Op<DIM>::getOutputsName) .def("get_outputs_name", &AvgPooling_Op<DIM>::getOutputsName)
.def("attributes_name", &AvgPooling_Op<DIM>::staticGetAttrsName); .def("attributes_name", &AvgPooling_Op<DIM>::staticGetAttrsName);
declare_registrable<AvgPooling_Op<DIM>>(m, pyClassName); declare_registrable<AvgPooling_Op<DIM>>(m, pyClassName);
m.def(("AvgPooling" + std::to_string(DIM) + "D").c_str(), [](const std::vector<DimSize_t>& kernel_dims, m.def(("AvgPooling" + std::to_string(DIM) + "D").c_str(), [](const std::vector<DimSize_t>& kernel_dims,
const std::string& name, const std::string& name,
const std::vector<DimSize_t> &stride_dims) { const std::vector<DimSize_t> &stride_dims) {
...@@ -48,7 +50,6 @@ template <DimIdx_t DIM> void declare_AvgPoolingOp(py::module &m) { ...@@ -48,7 +50,6 @@ template <DimIdx_t DIM> void declare_AvgPoolingOp(py::module &m) {
}, py::arg("kernel_dims"), }, py::arg("kernel_dims"),
py::arg("name") = "", py::arg("name") = "",
py::arg("stride_dims") = std::vector<DimSize_t>(DIM,1)); py::arg("stride_dims") = std::vector<DimSize_t>(DIM,1));
} }
...@@ -61,4 +62,5 @@ void init_AvgPooling(py::module &m) { ...@@ -61,4 +62,5 @@ void init_AvgPooling(py::module &m) {
// m.def("AvgPooling1D", static_cast<NodeAPI(*)(const char*, int, int, int const // m.def("AvgPooling1D", static_cast<NodeAPI(*)(const char*, int, int, int const
// (&)[1])>(&AvgPooling)); // (&)[1])>(&AvgPooling));
} }
} // namespace Aidge } // namespace Aidge
...@@ -24,18 +24,20 @@ template <DimSize_t DIM> ...@@ -24,18 +24,20 @@ template <DimSize_t DIM>
void declare_BatchNormOp(py::module& m) { void declare_BatchNormOp(py::module& m) {
const std::string pyClassName("BatchNormOp" + std::to_string(DIM) + "D"); const std::string pyClassName("BatchNormOp" + std::to_string(DIM) + "D");
py::class_<BatchNorm_Op<DIM>, std::shared_ptr<BatchNorm_Op<DIM>>, Attributes, OperatorTensor>(m, pyClassName.c_str(), py::multiple_inheritance()) py::class_<BatchNorm_Op<DIM>, std::shared_ptr<BatchNorm_Op<DIM>>, Attributes, OperatorTensor>(m, pyClassName.c_str(), py::multiple_inheritance())
.def(py::init<float, float>(), .def(py::init<float, float>(),
py::arg("epsilon"), py::arg("epsilon"),
py::arg("momentum")) py::arg("momentum"))
.def_static("get_inputs_name", &BatchNorm_Op<DIM>::getInputsName) .def_static("get_inputs_name", &BatchNorm_Op<DIM>::getInputsName)
.def_static("get_outputs_name", &BatchNorm_Op<DIM>::getOutputsName) .def_static("get_outputs_name", &BatchNorm_Op<DIM>::getOutputsName)
.def_static("attributes_name", &BatchNorm_Op<DIM>::staticGetAttrsName); .def_static("attributes_name", &BatchNorm_Op<DIM>::staticGetAttrsName);
declare_registrable<BatchNorm_Op<DIM>>(m, pyClassName); declare_registrable<BatchNorm_Op<DIM>>(m, pyClassName);
m.def(("BatchNorm" + std::to_string(DIM) + "D").c_str(), &BatchNorm<DIM>, py::arg("nbFeatures"), py::arg("epsilon") = 1.0e-5F, py::arg("momentum") = 0.1F, py::arg("name") = ""); m.def(("BatchNorm" + std::to_string(DIM) + "D").c_str(), &BatchNorm<DIM>, py::arg("nb_features"), py::arg("epsilon") = 1.0e-5F, py::arg("momentum") = 0.1F, py::arg("name") = "");
} }
void init_BatchNorm(py::module &m) { void init_BatchNorm(py::module &m) {
declare_BatchNormOp<2>(m); declare_BatchNormOp<2>(m);
} }
} // namespace Aidge } // namespace Aidge
...@@ -21,11 +21,16 @@ namespace Aidge { ...@@ -21,11 +21,16 @@ namespace Aidge {
void init_Concat(py::module& m) { void init_Concat(py::module& m) {
py::class_<Concat_Op, std::shared_ptr<Concat_Op>, Attributes, OperatorTensor>(m, "ConcatOp", py::multiple_inheritance()) py::class_<Concat_Op, std::shared_ptr<Concat_Op>, Attributes, OperatorTensor>(m, "ConcatOp", py::multiple_inheritance())
.def_static("get_inputs_name", &Concat_Op::getInputsName) .def(py::init<const IOIndex_t, const DimSize_t>(),
.def_static("get_outputs_name", &Concat_Op::getOutputsName) py::arg("nb_inputs"),
.def_static("attributes_name", &Concat_Op::staticGetAttrsName); py::arg("axis"))
.def_static("get_inputs_name", &Concat_Op::getInputsName)
.def_static("get_outputs_name", &Concat_Op::getOutputsName)
.def_static("attributes_name", &Concat_Op::staticGetAttrsName);
declare_registrable<Concat_Op>(m, "ConcatOp"); declare_registrable<Concat_Op>(m, "ConcatOp");
m.def("Concat", &Concat, py::arg("nbIn"), py::arg("axis"), py::arg("name") = "");
m.def("Concat", &Concat, py::arg("nb_inputs"), py::arg("axis"), py::arg("name") = "");
} }
} // namespace Aidge } // namespace Aidge
...@@ -20,9 +20,11 @@ namespace Aidge { ...@@ -20,9 +20,11 @@ namespace Aidge {
void init_Div(py::module& m) { void init_Div(py::module& m) {
py::class_<Div_Op, std::shared_ptr<Div_Op>, OperatorTensor>(m, "DivOp", py::multiple_inheritance()) py::class_<Div_Op, std::shared_ptr<Div_Op>, OperatorTensor>(m, "DivOp", py::multiple_inheritance())
.def_static("get_inputs_name", &Div_Op::getInputsName) .def(py::init<>())
.def_static("get_outputs_name", &Div_Op::getOutputsName); .def_static("get_inputs_name", &Div_Op::getInputsName)
.def_static("get_outputs_name", &Div_Op::getOutputsName);
declare_registrable<Div_Op>(m, "DivOp"); declare_registrable<Div_Op>(m, "DivOp");
m.def("Div", &Div, py::arg("name") = ""); m.def("Div", &Div, py::arg("name") = "");
} }
} // namespace Aidge } // namespace Aidge
...@@ -20,9 +20,12 @@ namespace Aidge { ...@@ -20,9 +20,12 @@ namespace Aidge {
void init_Erf(py::module& m) { void init_Erf(py::module& m) {
py::class_<Erf_Op, std::shared_ptr<Erf_Op>, OperatorTensor>(m, "ErfOp", py::multiple_inheritance()) py::class_<Erf_Op, std::shared_ptr<Erf_Op>, OperatorTensor>(m, "ErfOp", py::multiple_inheritance())
.def_static("get_inputs_name", &Erf_Op::getInputsName) .def(py::init<>())
.def_static("get_outputs_name", &Erf_Op::getOutputsName); .def_static("get_inputs_name", &Erf_Op::getInputsName)
.def_static("get_outputs_name", &Erf_Op::getOutputsName);
declare_registrable<Erf_Op>(m, "ErfOp"); declare_registrable<Erf_Op>(m, "ErfOp");
m.def("Erf", &Erf, py::arg("name") = ""); m.def("Erf", &Erf, py::arg("name") = "");
} }
} // namespace Aidge } // namespace Aidge
...@@ -22,14 +22,18 @@ namespace Aidge { ...@@ -22,14 +22,18 @@ namespace Aidge {
void declare_FC(py::module &m) { void declare_FC(py::module &m) {
py::class_<FC_Op, std::shared_ptr<FC_Op>, Attributes, OperatorTensor>(m, "FCOp", py::multiple_inheritance()) py::class_<FC_Op, std::shared_ptr<FC_Op>, Attributes, OperatorTensor>(m, "FCOp", py::multiple_inheritance())
.def_static("get_inputs_name", &FC_Op::getInputsName) .def(py::init<bool>(), py::arg("no_bias"))
.def_static("get_outputs_name", &FC_Op::getOutputsName) .def_static("get_inputs_name", &FC_Op::getInputsName)
.def_static("attributes_name", &FC_Op::staticGetAttrsName); .def_static("get_outputs_name", &FC_Op::getOutputsName)
.def_static("attributes_name", &FC_Op::staticGetAttrsName);
declare_registrable<FC_Op>(m, "FCOp"); declare_registrable<FC_Op>(m, "FCOp");
m.def("FC", &FC, py::arg("in_channels"), py::arg("out_channels"), py::arg("nobias") = false, py::arg("name") = "");
m.def("FC", &FC, py::arg("in_channels"), py::arg("out_channels"), py::arg("no_bias") = false, py::arg("name") = "");
} }
void init_FC(py::module &m) { void init_FC(py::module &m) {
declare_FC(m); declare_FC(m);
} }
} // namespace Aidge } // namespace Aidge
...@@ -22,11 +22,19 @@ namespace Aidge { ...@@ -22,11 +22,19 @@ namespace Aidge {
void init_Gather(py::module& m) { void init_Gather(py::module& m) {
py::class_<Gather_Op, std::shared_ptr<Gather_Op>, Attributes, OperatorTensor>(m, "GatherOp", py::multiple_inheritance()) py::class_<Gather_Op, std::shared_ptr<Gather_Op>, Attributes, OperatorTensor>(m, "GatherOp", py::multiple_inheritance())
.def_static("get_inputs_name", &Gather_Op::getInputsName) .def(py::init<std::int8_t,
.def_static("get_outputs_name", &Gather_Op::getOutputsName) const std::vector<int64_t>,
.def_static("attributes_name", &Gather_Op::staticGetAttrsName); const std::vector<DimSize_t>>(),
py::arg("axis"),
py::arg("indices"),
py::arg("gathered_shape"))
.def_static("get_inputs_name", &Gather_Op::getInputsName)
.def_static("get_outputs_name", &Gather_Op::getOutputsName)
.def_static("attributes_name", &Gather_Op::staticGetAttrsName);
declare_registrable<Gather_Op>(m, "GatherOp"); declare_registrable<Gather_Op>(m, "GatherOp");
m.def("Gather", &Gather, py::arg("axis") = 0, py::arg("indices") = std::vector<std::int64_t>(), py::arg("gathered_shape") = std::vector<std::size_t>(), py::arg("name") = ""); m.def("Gather", &Gather, py::arg("axis") = 0, py::arg("indices") = std::vector<std::int64_t>(), py::arg("gathered_shape") = std::vector<std::size_t>(), py::arg("name") = "");
} }
} // namespace Aidge } // namespace Aidge
...@@ -9,23 +9,33 @@ ...@@ -9,23 +9,33 @@
* *
********************************************************************************/ ********************************************************************************/
#include <stdio.h>
#include <string>
#include <pybind11/functional.h>
#include <pybind11/pybind11.h> #include <pybind11/pybind11.h>
#include <pybind11/stl.h> #include <pybind11/stl.h>
#include <pybind11/functional.h>
#include <stdio.h>
#include "aidge/backend/OperatorImpl.hpp" #include "aidge/backend/OperatorImpl.hpp"
#include "aidge/data/Tensor.hpp" #include "aidge/data/Tensor.hpp"
#include "aidge/operator/GenericOperator.hpp" #include "aidge/operator/GenericOperator.hpp"
#include "aidge/operator/OperatorTensor.hpp" #include "aidge/operator/OperatorTensor.hpp"
#include "aidge/utils/Types.h"
namespace py = pybind11; namespace py = pybind11;
namespace Aidge { namespace Aidge {
void init_GenericOperator(py::module& m) { void init_GenericOperator(py::module& m) {
py::class_<GenericOperator_Op, std::shared_ptr<GenericOperator_Op>, DynamicAttributes, OperatorTensor>(m, "GenericOperatorOp", py::class_<GenericOperator_Op, std::shared_ptr<GenericOperator_Op>, DynamicAttributes, OperatorTensor>(m, "GenericOperatorOp",
py::multiple_inheritance()) py::multiple_inheritance())
.def_readonly_static("identity", &GenericOperator_Op::Identity) .def(py::init<const std::string&, IOIndex_t, IOIndex_t, IOIndex_t>(),
.def("set_forward_dims", &GenericOperator_Op::setForwardDims, py::arg("computation_function")); py::arg("type"),
py::arg("nb_data"),
py::arg("nb_param"),
py::arg("nb_outputs"))
.def_readonly_static("identity", &GenericOperator_Op::Identity)
.def("set_forward_dims", &GenericOperator_Op::setForwardDims, py::arg("computation_function"));
// &GenericOperator // &GenericOperator
m.def("GenericOperator", m.def("GenericOperator",
......
...@@ -23,9 +23,13 @@ void init_GlobalAveragePooling(py::module &m) { ...@@ -23,9 +23,13 @@ void init_GlobalAveragePooling(py::module &m) {
py::class_<GlobalAveragePooling_Op, std::shared_ptr<GlobalAveragePooling_Op>, py::class_<GlobalAveragePooling_Op, std::shared_ptr<GlobalAveragePooling_Op>,
OperatorTensor>(m, pyClassName.c_str(), OperatorTensor>(m, pyClassName.c_str(),
py::multiple_inheritance()) py::multiple_inheritance())
.def(py::init<>())
.def_static("get_inputs_name", &GlobalAveragePooling_Op::getInputsName) .def_static("get_inputs_name", &GlobalAveragePooling_Op::getInputsName)
.def_static("get_outputs_name", &GlobalAveragePooling_Op::getOutputsName); .def_static("get_outputs_name", &GlobalAveragePooling_Op::getOutputsName);
declare_registrable<GlobalAveragePooling_Op>(m, pyClassName); declare_registrable<GlobalAveragePooling_Op>(m, pyClassName);
m.def("globalaveragepooling", &GlobalAveragePooling, py::arg("name") = ""); m.def("globalaveragepooling", &GlobalAveragePooling, py::arg("name") = "");
} }
} // namespace Aidge } // namespace Aidge
...@@ -19,10 +19,12 @@ namespace py = pybind11; ...@@ -19,10 +19,12 @@ namespace py = pybind11;
namespace Aidge { namespace Aidge {
void init_Identity(py::module& m) { void init_Identity(py::module& m) {
py::class_<Identity_Op, std::shared_ptr<Identity_Op>, Operator>(m, "IdentityOp", py::multiple_inheritance()) py::class_<Identity_Op, std::shared_ptr<Identity_Op>, OperatorTensor>(m, "IdentityOp", py::multiple_inheritance())
.def_static("get_inputs_name", &Identity_Op::getInputsName) .def(py::init<>())
.def_static("get_outputs_name", &Identity_Op::getOutputsName); .def_static("get_inputs_name", &Identity_Op::getInputsName)
.def_static("get_outputs_name", &Identity_Op::getOutputsName);
m.def("Identity", &Identity, py::arg("name") = ""); m.def("Identity", &Identity, py::arg("name") = "");
} }
} // namespace Aidge } // namespace Aidge
...@@ -20,10 +20,12 @@ namespace Aidge { ...@@ -20,10 +20,12 @@ namespace Aidge {
void init_LeakyReLU(py::module& m) { void init_LeakyReLU(py::module& m) {
py::class_<LeakyReLU_Op, std::shared_ptr<LeakyReLU_Op>, Attributes, OperatorTensor>(m, "LeakyReLUOp", py::multiple_inheritance()) py::class_<LeakyReLU_Op, std::shared_ptr<LeakyReLU_Op>, Attributes, OperatorTensor>(m, "LeakyReLUOp", py::multiple_inheritance())
.def_static("get_inputs_name", &LeakyReLU_Op::getInputsName) .def(py::init<float>(), py::arg("negative_slope"))
.def_static("get_outputs_name", &LeakyReLU_Op::getOutputsName) .def_static("get_inputs_name", &LeakyReLU_Op::getInputsName)
.def_static("attributes_name", &LeakyReLU_Op::staticGetAttrsName); .def_static("get_outputs_name", &LeakyReLU_Op::getOutputsName)
.def_static("attributes_name", &LeakyReLU_Op::staticGetAttrsName);
declare_registrable<LeakyReLU_Op>(m, "LeakyReLUOp"); declare_registrable<LeakyReLU_Op>(m, "LeakyReLUOp");
m.def("LeakyReLU", &LeakyReLU, py::arg("negative_slope") = 0.0f, py::arg("name") = ""); m.def("LeakyReLU", &LeakyReLU, py::arg("negative_slope") = 0.0f, py::arg("name") = "");
} }
} // namespace Aidge } // namespace Aidge
...@@ -22,8 +22,9 @@ namespace Aidge { ...@@ -22,8 +22,9 @@ namespace Aidge {
void init_MatMul(py::module &m) { void init_MatMul(py::module &m) {
py::class_<MatMul_Op, std::shared_ptr<MatMul_Op>, OperatorTensor>(m, "MatMulOp", py::multiple_inheritance()) py::class_<MatMul_Op, std::shared_ptr<MatMul_Op>, OperatorTensor>(m, "MatMulOp", py::multiple_inheritance())
.def_static("get_inputs_name", &MatMul_Op::getInputsName) .def(py::init<>())
.def_static("get_outputs_name", &MatMul_Op::getOutputsName); .def_static("get_inputs_name", &MatMul_Op::getInputsName)
.def_static("get_outputs_name", &MatMul_Op::getOutputsName);
declare_registrable<MatMul_Op>(m, "MatMulOp"); declare_registrable<MatMul_Op>(m, "MatMulOp");
m.def("MatMul", &MatMul, py::arg("name") = ""); m.def("MatMul", &MatMul, py::arg("name") = "");
} }
......
...@@ -47,6 +47,24 @@ template <DimIdx_t DIM> void declare_PaddedConvOp(py::module &m) { ...@@ -47,6 +47,24 @@ template <DimIdx_t DIM> void declare_PaddedConvOp(py::module &m) {
py::arg("padding_dims") = std::vector<DimSize_t>(2*DIM,0), py::arg("padding_dims") = std::vector<DimSize_t>(2*DIM,0),
py::arg("dilation_dims") = std::vector<DimSize_t>(DIM,1), py::arg("dilation_dims") = std::vector<DimSize_t>(DIM,1),
py::arg("no_bias")= false); py::arg("no_bias")= false);
m.def(("PaddedConvOp" + std::to_string(DIM) + "D").c_str(), [](
const std::vector<DimSize_t>& kernel_dims,
const std::vector<DimSize_t> &stride_dims,
const std::vector<DimSize_t> &padding_dims,
const std::vector<DimSize_t> &dilation_dims,
bool no_bias)
{
AIDGE_ASSERT(kernel_dims.size() == DIM, "kernel_dims size [{}] does not match DIM [{}]", kernel_dims.size(), DIM);
AIDGE_ASSERT(stride_dims.size() == DIM, "stride_dims size [{}] does not match DIM [{}]", stride_dims.size(), DIM);
AIDGE_ASSERT(padding_dims.size() == 2*DIM, "padding_dims size [{}] does not match DIM [{}]", padding_dims.size(), 2*DIM);
AIDGE_ASSERT(dilation_dims.size() == DIM, "dilation_dims size [{}] does not match DIM [{}]", dilation_dims.size(), DIM);
return PaddedConv_Op<DIM>(to_array<DIM>(kernel_dims.begin()), to_array<DIM>(stride_dims.begin()), to_array<2*DIM>(padding_dims.begin()), to_array<DIM>(dilation_dims.begin()), no_bias);
}, py::arg("kernel_dims"),
py::arg("stride_dims") = std::vector<DimSize_t>(DIM,1),
py::arg("padding_dims") = std::vector<DimSize_t>(2*DIM,0),
py::arg("dilation_dims") = std::vector<DimSize_t>(DIM,1),
py::arg("no_bias")= false);
} }
template <DimIdx_t DIM> void declare_PaddedConvDepthWiseOp(py::module &m) { template <DimIdx_t DIM> void declare_PaddedConvDepthWiseOp(py::module &m) {
...@@ -71,6 +89,24 @@ template <DimIdx_t DIM> void declare_PaddedConvDepthWiseOp(py::module &m) { ...@@ -71,6 +89,24 @@ template <DimIdx_t DIM> void declare_PaddedConvDepthWiseOp(py::module &m) {
py::arg("padding_dims") = std::vector<DimSize_t>(2*DIM,0), py::arg("padding_dims") = std::vector<DimSize_t>(2*DIM,0),
py::arg("dilation_dims") = std::vector<DimSize_t>(DIM,1), py::arg("dilation_dims") = std::vector<DimSize_t>(DIM,1),
py::arg("no_bias") = false); py::arg("no_bias") = false);
m.def(("PaddedConvDepthWiseOp" + std::to_string(DIM) + "D").c_str(), [](
const std::vector<DimSize_t>& kernel_dims,
const std::vector<DimSize_t> &stride_dims,
const std::vector<DimSize_t> &padding_dims,
const std::vector<DimSize_t> &dilation_dims,
bool no_bias)
{
AIDGE_ASSERT(kernel_dims.size() == DIM, "kernel_dims size [{}] does not match DIM [{}]", kernel_dims.size(), DIM);
AIDGE_ASSERT(stride_dims.size() == DIM, "stride_dims size [{}] does not match DIM [{}]", stride_dims.size(), DIM);
AIDGE_ASSERT(padding_dims.size() == 2*DIM, "padding_dims size [{}] does not match DIM [{}]", padding_dims.size(), 2*DIM);
AIDGE_ASSERT(dilation_dims.size() == DIM, "dilation_dims size [{}] does not match DIM [{}]", dilation_dims.size(), DIM);
return PaddedConvDepthWise_Op<DIM>(to_array<DIM>(kernel_dims.begin()), to_array<DIM>(stride_dims.begin()), to_array<2*DIM>(padding_dims.begin()), to_array<DIM>(dilation_dims.begin()), no_bias);
}, py::arg("kernel_dims"),
py::arg("stride_dims") = std::vector<DimSize_t>(DIM,1),
py::arg("padding_dims") = std::vector<DimSize_t>(2*DIM,0),
py::arg("dilation_dims") = std::vector<DimSize_t>(DIM,1),
py::arg("no_bias") = false);
} }
...@@ -89,7 +125,18 @@ template <DimIdx_t DIM> void declare_PaddedAvgPoolingOp(py::module &m) { ...@@ -89,7 +125,18 @@ template <DimIdx_t DIM> void declare_PaddedAvgPoolingOp(py::module &m) {
py::arg("name") = "", py::arg("name") = "",
py::arg("stride_dims") = std::vector<DimSize_t>(DIM,1), py::arg("stride_dims") = std::vector<DimSize_t>(DIM,1),
py::arg("padding_dims") = std::vector<DimSize_t>(2*DIM,0)); py::arg("padding_dims") = std::vector<DimSize_t>(2*DIM,0));
m.def(("PaddedAvgPoolingOp" + std::to_string(DIM) + "D").c_str(), [](const std::vector<DimSize_t>& kernel_dims,
const std::vector<DimSize_t> &stride_dims,
const std::vector<DimSize_t> &padding_dims)
{
AIDGE_ASSERT(kernel_dims.size() == DIM, "kernel_dims size [{}] does not match DIM [{}]", kernel_dims.size(), DIM);
AIDGE_ASSERT(stride_dims.size() == DIM, "stride_dims size [{}] does not match DIM [{}]", stride_dims.size(), DIM);
AIDGE_ASSERT(padding_dims.size() == 2*DIM, "padding_dims size [{}] does not match DIM [{}]", padding_dims.size(), 2*DIM);
return PaddedAvgPooling_Op<DIM>(to_array<DIM>(kernel_dims.begin()), to_array<DIM>(stride_dims.begin()), to_array<2*DIM>(padding_dims.begin()));
}, py::arg("kernel_dims"),
py::arg("stride_dims") = std::vector<DimSize_t>(DIM,1),
py::arg("padding_dims") = std::vector<DimSize_t>(2*DIM,0));
} }
template <DimIdx_t DIM> void declare_PaddedMaxPoolingOp(py::module &m) { template <DimIdx_t DIM> void declare_PaddedMaxPoolingOp(py::module &m) {
...@@ -109,6 +156,20 @@ template <DimIdx_t DIM> void declare_PaddedMaxPoolingOp(py::module &m) { ...@@ -109,6 +156,20 @@ template <DimIdx_t DIM> void declare_PaddedMaxPoolingOp(py::module &m) {
py::arg("stride_dims") = std::vector<DimSize_t>(DIM,1), py::arg("stride_dims") = std::vector<DimSize_t>(DIM,1),
py::arg("padding_dims") = std::vector<DimSize_t>(2*DIM,0), py::arg("padding_dims") = std::vector<DimSize_t>(2*DIM,0),
py::arg("ceil_mode") = false); py::arg("ceil_mode") = false);
m.def(("PaddedMaxPoolingOp" + std::to_string(DIM) + "D").c_str(), [](const std::vector<DimSize_t>& kernel_dims,
const std::vector<DimSize_t> &stride_dims,
const std::vector<DimSize_t> &padding_dims,
bool ceil_mode)
{
AIDGE_ASSERT(kernel_dims.size() == DIM, "kernel_dims size [{}] does not match DIM [{}]", kernel_dims.size(), DIM);
AIDGE_ASSERT(stride_dims.size() == DIM, "stride_dims size [{}] does not match DIM [{}]", stride_dims.size(), DIM);
AIDGE_ASSERT(padding_dims.size() == 2*DIM, "padding_dims size [{}] does not match DIM [{}]", padding_dims.size(), 2*DIM);
return PaddedMaxPooling_Op<DIM>(to_array<DIM>(kernel_dims.begin()), to_array<DIM>(stride_dims.begin()), to_array<2*DIM>(padding_dims.begin()), ceil_mode);
}, py::arg("kernel_dims"),
py::arg("stride_dims") = std::vector<DimSize_t>(DIM,1),
py::arg("padding_dims") = std::vector<DimSize_t>(2*DIM,0),
py::arg("ceil_mode") = false);
} }
...@@ -118,21 +179,24 @@ void declare_LSTMOp(py::module &m) { ...@@ -118,21 +179,24 @@ void declare_LSTMOp(py::module &m) {
py::arg("seq_length"), py::arg("seq_length"),
py::arg("nobias") = false, py::arg("nobias") = false,
py::arg("name") = ""); py::arg("name") = "");
m.def("LSTMOp", &LSTM_Op,
py::arg("seq_length"),
py::arg("nobias") = false);
} }
void init_MetaOperatorDefs(py::module &m) { void init_MetaOperatorDefs(py::module &m) {
declare_PaddedConvOp<1>(m); // declare_PaddedConvOp<1>(m);
declare_PaddedConvOp<2>(m); declare_PaddedConvOp<2>(m);
declare_PaddedConvOp<3>(m); // declare_PaddedConvOp<3>(m);
declare_PaddedConvDepthWiseOp<1>(m); // declare_PaddedConvDepthWiseOp<1>(m);
declare_PaddedConvDepthWiseOp<2>(m); declare_PaddedConvDepthWiseOp<2>(m);
declare_PaddedConvDepthWiseOp<3>(m); // declare_PaddedConvDepthWiseOp<3>(m);
declare_PaddedAvgPoolingOp<1>(m); // declare_PaddedAvgPoolingOp<1>(m);
declare_PaddedAvgPoolingOp<2>(m); declare_PaddedAvgPoolingOp<2>(m);
declare_PaddedAvgPoolingOp<3>(m); // declare_PaddedAvgPoolingOp<3>(m);
declare_PaddedMaxPoolingOp<1>(m); // declare_PaddedMaxPoolingOp<1>(m);
declare_PaddedMaxPoolingOp<2>(m); declare_PaddedMaxPoolingOp<2>(m);
declare_PaddedMaxPoolingOp<3>(m); // declare_PaddedMaxPoolingOp<3>(m);
declare_LSTMOp(m); declare_LSTMOp(m);
py::class_<MetaOperator_Op, std::shared_ptr<MetaOperator_Op>, OperatorTensor>(m, "MetaOperator_Op", py::multiple_inheritance()) py::class_<MetaOperator_Op, std::shared_ptr<MetaOperator_Op>, OperatorTensor>(m, "MetaOperator_Op", py::multiple_inheritance())
......
...@@ -20,6 +20,7 @@ namespace Aidge { ...@@ -20,6 +20,7 @@ namespace Aidge {
void init_Mul(py::module& m) { void init_Mul(py::module& m) {
py::class_<Mul_Op, std::shared_ptr<Mul_Op>, OperatorTensor>(m, "MulOp", py::multiple_inheritance()) py::class_<Mul_Op, std::shared_ptr<Mul_Op>, OperatorTensor>(m, "MulOp", py::multiple_inheritance())
.def(py::init<>())
.def_static("get_inputs_name", &Mul_Op::getInputsName) .def_static("get_inputs_name", &Mul_Op::getInputsName)
.def_static("get_outputs_name", &Mul_Op::getOutputsName); .def_static("get_outputs_name", &Mul_Op::getOutputsName);
declare_registrable<Mul_Op>(m, "MulOp"); declare_registrable<Mul_Op>(m, "MulOp");
......
...@@ -20,6 +20,7 @@ namespace Aidge { ...@@ -20,6 +20,7 @@ namespace Aidge {
void init_Pop(py::module& m) { void init_Pop(py::module& m) {
py::class_<Pop_Op, std::shared_ptr<Pop_Op>, OperatorTensor, Attributes>(m, "PopOp", py::multiple_inheritance()) py::class_<Pop_Op, std::shared_ptr<Pop_Op>, OperatorTensor, Attributes>(m, "PopOp", py::multiple_inheritance())
.def(py::init<>())
.def_static("get_inputs_name", &Pop_Op::getInputsName) .def_static("get_inputs_name", &Pop_Op::getInputsName)
.def_static("get_outputs_name", &Pop_Op::getOutputsName); .def_static("get_outputs_name", &Pop_Op::getOutputsName);
......
...@@ -20,6 +20,7 @@ namespace Aidge { ...@@ -20,6 +20,7 @@ namespace Aidge {
void init_Pow(py::module& m) { void init_Pow(py::module& m) {
py::class_<Pow_Op, std::shared_ptr<Pow_Op>, OperatorTensor>(m, "PowOp", py::multiple_inheritance()) py::class_<Pow_Op, std::shared_ptr<Pow_Op>, OperatorTensor>(m, "PowOp", py::multiple_inheritance())
.def(py::init<>())
.def_static("get_inputs_name", &Pow_Op::getInputsName) .def_static("get_inputs_name", &Pow_Op::getInputsName)
.def_static("get_outputs_name", &Pow_Op::getOutputsName); .def_static("get_outputs_name", &Pow_Op::getOutputsName);
declare_registrable<Pow_Op>(m, "PowOp"); declare_registrable<Pow_Op>(m, "PowOp");
......
...@@ -35,12 +35,22 @@ void init_Producer(py::module &m) { ...@@ -35,12 +35,22 @@ void init_Producer(py::module &m) {
m, m,
"ProducerOp", "ProducerOp",
py::multiple_inheritance()) py::multiple_inheritance())
.def(py::init<const std::shared_ptr<Tensor>, bool>(), py::arg("tensor"), py::arg("constant"))
.def("dims", &Producer_Op::dims) .def("dims", &Producer_Op::dims)
.def_static("get_inputs_name", &Producer_Op::getInputsName) .def_static("get_inputs_name", &Producer_Op::getInputsName)
.def_static("get_outputs_name", &Producer_Op::getOutputsName) .def_static("get_outputs_name", &Producer_Op::getOutputsName)
.def_static("attributes_name", &Producer_Op::staticGetAttrsName); .def_static("attributes_name", &Producer_Op::staticGetAttrsName);
m.def("Producer", static_cast<std::shared_ptr<Node>(*)(const std::shared_ptr<Tensor>, const std::string&, bool)>(&Producer), py::arg("tensor"), py::arg("name") = "", py::arg("constant") = false);
m.def("Producer", static_cast<std::shared_ptr<Node>(*)(
const std::shared_ptr<Tensor>,
const std::string&,
bool)>(&Producer),
py::arg("tensor"),
py::arg("name") = "",
py::arg("constant") = false);
declare_registrable<Producer_Op>(m, "ProducerOp"); declare_registrable<Producer_Op>(m, "ProducerOp");
declare_Producer<1>(m); declare_Producer<1>(m);
declare_Producer<2>(m); declare_Producer<2>(m);
declare_Producer<3>(m); declare_Producer<3>(m);
......
...@@ -20,6 +20,7 @@ namespace Aidge { ...@@ -20,6 +20,7 @@ namespace Aidge {
void init_ReLU(py::module& m) { void init_ReLU(py::module& m) {
py::class_<ReLU_Op, std::shared_ptr<ReLU_Op>, OperatorTensor>(m, "ReLUOp", py::multiple_inheritance()) py::class_<ReLU_Op, std::shared_ptr<ReLU_Op>, OperatorTensor>(m, "ReLUOp", py::multiple_inheritance())
.def(py::init<>())
.def_static("get_inputs_name", &ReLU_Op::getInputsName) .def_static("get_inputs_name", &ReLU_Op::getInputsName)
.def_static("get_outputs_name", &ReLU_Op::getOutputsName); .def_static("get_outputs_name", &ReLU_Op::getOutputsName);
declare_registrable<ReLU_Op>(m, "ReLUOp"); declare_registrable<ReLU_Op>(m, "ReLUOp");
......
...@@ -28,6 +28,7 @@ void declare_ReduceMeanOp(py::module &m) { ...@@ -28,6 +28,7 @@ void declare_ReduceMeanOp(py::module &m) {
const std::string pyClassName("ReduceMeanOp"); const std::string pyClassName("ReduceMeanOp");
py::class_<ReduceMean_Op, std::shared_ptr<ReduceMean_Op>, Attributes, OperatorTensor>( py::class_<ReduceMean_Op, std::shared_ptr<ReduceMean_Op>, Attributes, OperatorTensor>(
m, pyClassName.c_str(), py::multiple_inheritance()) m, pyClassName.c_str(), py::multiple_inheritance())
.def(py::init<std::vector<std::int32_t>, DimSize_t>(), py::arg("axes"), py::arg("keep_dims"))
.def_static("get_inputs_name", &ReduceMean_Op::getInputsName) .def_static("get_inputs_name", &ReduceMean_Op::getInputsName)
.def_static("get_outputs_name", &ReduceMean_Op::getOutputsName) .def_static("get_outputs_name", &ReduceMean_Op::getOutputsName)
.def_static("attributes_name", &ReduceMean_Op::staticGetAttrsName) .def_static("attributes_name", &ReduceMean_Op::staticGetAttrsName)
......
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