Skip to content
Snippets Groups Projects
Commit d759b214 authored by vincent  lorrain's avatar vincent lorrain
Browse files

merge main and fix

parents d93381a6 daec3e64
No related branches found
No related tags found
1 merge request!29GraphRegex interface class
Pipeline #33940 canceled
Showing
with 282 additions and 78 deletions
...@@ -27,7 +27,7 @@ void init_GenericOperator(py::module& m) { ...@@ -27,7 +27,7 @@ void init_GenericOperator(py::module& m) {
.def("compute_output_dims", &GenericOperator_Op::computeOutputDims) .def("compute_output_dims", &GenericOperator_Op::computeOutputDims)
.def("set_compute_output_dims", &GenericOperator_Op::setComputeOutputDims, py::arg("computation_function")); .def("set_compute_output_dims", &GenericOperator_Op::setComputeOutputDims, py::arg("computation_function"));
m.def("GenericOperator", &GenericOperator, py::arg("type"), py::arg("nbDataIn"), py::arg("nbIn"), py::arg("nbOut"), m.def("GenericOperator", &GenericOperator, py::arg("type"), py::arg("nb_data_in"), py::arg("nb_in"), py::arg("nb_out"),
py::arg("name") = ""); py::arg("name") = "");
} }
} // namespace Aidge } // namespace Aidge
...@@ -18,7 +18,9 @@ namespace py = pybind11; ...@@ -18,7 +18,9 @@ namespace py = pybind11;
namespace Aidge { namespace Aidge {
void init_LeakyReLU(py::module& m) { void init_LeakyReLU(py::module& m) {
py::class_<LeakyReLU_Op, std::shared_ptr<LeakyReLU_Op>, Operator, Attributes>(m, "LeakyReLU_Op", py::multiple_inheritance()); py::class_<LeakyReLU_Op, std::shared_ptr<LeakyReLU_Op>, Operator, Attributes>(m, "LeakyReLUOp", py::multiple_inheritance())
.def("get_inputs_name", &LeakyReLU_Op::getInputsName)
.def("get_outputs_name", &LeakyReLU_Op::getOutputsName);
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") = "");
} }
......
...@@ -20,7 +20,9 @@ namespace py = pybind11; ...@@ -20,7 +20,9 @@ namespace py = pybind11;
namespace Aidge { namespace Aidge {
void declare_MatMul(py::module &m) { void declare_MatMul(py::module &m) {
py::class_<MatMul_Op, std::shared_ptr<MatMul_Op>, Operator, Attributes>(m, "MatMul_Op", py::multiple_inheritance()); py::class_<MatMul_Op, std::shared_ptr<MatMul_Op>, Operator, Attributes>(m, "MatMulOp", py::multiple_inheritance())
.def("get_inputs_name", &MatMul_Op::getInputsName)
.def("get_outputs_name", &MatMul_Op::getOutputsName);
m.def("MatMul", &MatMul, py::arg("out_channels"), py::arg("name") = ""); m.def("MatMul", &MatMul, py::arg("out_channels"), py::arg("name") = "");
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
* *
********************************************************************************/ ********************************************************************************/
#ifdef PYBIND
#include <pybind11/pybind11.h> #include <pybind11/pybind11.h>
#include <pybind11/stl.h> #include <pybind11/stl.h>
...@@ -30,36 +30,27 @@ template <DimIdx_t DIM> void declare_MaxPoolingOp(py::module &m) { ...@@ -30,36 +30,27 @@ template <DimIdx_t DIM> void declare_MaxPoolingOp(py::module &m) {
m, ("MaxPoolingOp" + std::to_string(DIM) + "D").c_str(), m, ("MaxPoolingOp" + std::to_string(DIM) + "D").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> &,
bool>(),
py::arg("kernel_dims"), py::arg("kernel_dims"),
py::arg("stride_dims")); py::arg("stride_dims"),
py::arg("ceil_mode"))
m.def(("MaxPooling" + std::to_string(DIM) + "D").c_str(), [](const std::vector<DimSize_t>& kernel_dims, .def("get_inputs_name", &MaxPooling_Op<DIM>::getInputsName)
.def("get_outputs_name", &MaxPooling_Op<DIM>::getOutputsName);
m.def(("MaxPooling" + 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,
// Lambda function wrapper because PyBind fails to convert const array. bool ceil_mode) {
// So we use a vector that we convert in this function to a const DimeSize_t [DIM] array. AIDGE_ASSERT(kernel_dims.size() == DIM, "kernel_dims size [%ld] does not match DIM [%d]", kernel_dims.size(), DIM);
if (kernel_dims.size() != DIM) { AIDGE_ASSERT(stride_dims.size() == DIM, "stride_dims size [%ld] does not match DIM [%d]", stride_dims.size(), DIM);
throw std::runtime_error("kernel_dims size [" + std::to_string(kernel_dims.size()) + "] does not match DIM [" + std::to_string(DIM) +"]");
} return MaxPooling<DIM>(to_array<DIM>(kernel_dims.begin()), name, to_array<DIM>(stride_dims.begin()), ceil_mode);
if (stride_dims.size() != DIM) {
throw std::runtime_error("stride_dims size [" + std::to_string(stride_dims.size()) + "] does not match DIM [" + std::to_string(DIM) +"]");
}
DimSize_t tmp_kernel_dims_array[DIM];
for (size_t i = 0; i < DIM; ++i) {
tmp_kernel_dims_array[i] = kernel_dims[i];
}
DimSize_t tmp_stride_dims_array[DIM];
for (size_t i = 0; i < DIM; ++i) {
tmp_stride_dims_array[i] = stride_dims[i];
}
const DimSize_t (&kernel_dims_array)[DIM] = tmp_kernel_dims_array;
const DimSize_t (&stride_dims_array)[DIM] = tmp_stride_dims_array;
return MaxPooling<DIM>(to_array(kernel_dims_array), name, to_array(stride_dims_array));
}, 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),
py::arg("ceil_mode") = false);
} }
...@@ -67,10 +58,6 @@ void init_MaxPooling(py::module &m) { ...@@ -67,10 +58,6 @@ void init_MaxPooling(py::module &m) {
declare_MaxPoolingOp<1>(m); declare_MaxPoolingOp<1>(m);
declare_MaxPoolingOp<2>(m); declare_MaxPoolingOp<2>(m);
declare_MaxPoolingOp<3>(m); declare_MaxPoolingOp<3>(m);
// FIXME:
// m.def("MaxPooling1D", static_cast<NodeAPI(*)(const char*, int, int, int const
// (&)[1])>(&MaxPooling));
} }
} // namespace Aidge } // namespace Aidge
#endif
\ No newline at end of file
This diff is collapsed.
...@@ -24,6 +24,9 @@ void init_Operator(py::module& m){ ...@@ -24,6 +24,9 @@ void init_Operator(py::module& m){
.def("associate_input", &Operator::associateInput, py::arg("inputIdx"), py::arg("data")) .def("associate_input", &Operator::associateInput, py::arg("inputIdx"), py::arg("data"))
.def("set_datatype", &Operator::setDatatype, py::arg("datatype")) .def("set_datatype", &Operator::setDatatype, py::arg("datatype"))
.def("set_backend", &Operator::setBackend, py::arg("name")) .def("set_backend", &Operator::setBackend, py::arg("name"))
.def("forward", &Operator::forward)
// py::keep_alive forbide Python to garbage collect implementation will the Operator is not garbade collected !
.def("set_impl", &Operator::setImpl, py::arg("implementation"), py::keep_alive<1, 2>())
; ;
} }
} }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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