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

Add __setattr__ and __getattr__ methods for Attributes. This recquired a...

Add __setattr__ and __getattr__ methods for Attributes. This recquired a change in the order of derived class declaration, see https://github.com/pybind/pybind11/issues/3804
parent f28a09ed
No related branches found
No related tags found
2 merge requests!105version 0.2.0,!73Quality of life
Pipeline #37459 passed
This commit is part of merge request !73. Comments created here will be created in the context of that merge request.
Showing
with 20 additions and 19 deletions
...@@ -26,7 +26,7 @@ namespace py = pybind11; ...@@ -26,7 +26,7 @@ namespace py = pybind11;
namespace Aidge { namespace Aidge {
template <DimIdx_t DIM> void declare_AvgPoolingOp(py::module &m) { template <DimIdx_t DIM> void declare_AvgPoolingOp(py::module &m) {
py::class_<AvgPooling_Op<DIM>, std::shared_ptr<AvgPooling_Op<DIM>>, OperatorTensor, Attributes>( py::class_<AvgPooling_Op<DIM>, std::shared_ptr<AvgPooling_Op<DIM>>, Attributes, OperatorTensor>(
m, ("AvgPoolingOp" + std::to_string(DIM) + "D").c_str(), m, ("AvgPoolingOp" + 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> &,
......
...@@ -21,7 +21,7 @@ namespace Aidge { ...@@ -21,7 +21,7 @@ namespace Aidge {
template <DimSize_t DIM> template <DimSize_t DIM>
void declare_BatchNormOp(py::module& m) { void declare_BatchNormOp(py::module& m) {
py::class_<BatchNorm_Op<DIM>, std::shared_ptr<BatchNorm_Op<DIM>>, OperatorTensor, Attributes>(m, ("BatchNormOp" + std::to_string(DIM) + "D").c_str(), py::multiple_inheritance()) py::class_<BatchNorm_Op<DIM>, std::shared_ptr<BatchNorm_Op<DIM>>, Attributes, OperatorTensor>(m, ("BatchNormOp" + std::to_string(DIM) + "D").c_str(), py::multiple_inheritance())
.def("get_inputs_name", &BatchNorm_Op<DIM>::getInputsName) .def("get_inputs_name", &BatchNorm_Op<DIM>::getInputsName)
.def("get_outputs_name", &BatchNorm_Op<DIM>::getOutputsName); .def("get_outputs_name", &BatchNorm_Op<DIM>::getOutputsName);
......
...@@ -19,7 +19,7 @@ namespace py = pybind11; ...@@ -19,7 +19,7 @@ namespace py = pybind11;
namespace Aidge { namespace Aidge {
void init_Concat(py::module& m) { void init_Concat(py::module& m) {
py::class_<Concat_Op, std::shared_ptr<Concat_Op>, OperatorTensor, Attributes>(m, "ConcatOp", py::multiple_inheritance()) py::class_<Concat_Op, std::shared_ptr<Concat_Op>, Attributes, OperatorTensor>(m, "ConcatOp", py::multiple_inheritance())
.def("get_inputs_name", &Concat_Op::getInputsName) .def("get_inputs_name", &Concat_Op::getInputsName)
.def("get_outputs_name", &Concat_Op::getOutputsName); .def("get_outputs_name", &Concat_Op::getOutputsName);
......
...@@ -24,7 +24,7 @@ namespace py = pybind11; ...@@ -24,7 +24,7 @@ namespace py = pybind11;
namespace Aidge { namespace Aidge {
template <DimIdx_t DIM> void declare_ConvOp(py::module &m) { template <DimIdx_t DIM> void declare_ConvOp(py::module &m) {
py::class_<Conv_Op<DIM>, std::shared_ptr<Conv_Op<DIM>>, OperatorTensor, Attributes>( py::class_<Conv_Op<DIM>, std::shared_ptr<Conv_Op<DIM>>, Attributes, OperatorTensor>(
m, ("ConvOp" + std::to_string(DIM) + "D").c_str(), m, ("ConvOp" + std::to_string(DIM) + "D").c_str(),
py::multiple_inheritance()) py::multiple_inheritance())
.def(py::init<DimSize_t, .def(py::init<DimSize_t,
......
...@@ -26,7 +26,7 @@ namespace py = pybind11; ...@@ -26,7 +26,7 @@ namespace py = pybind11;
namespace Aidge { namespace Aidge {
template <DimIdx_t DIM> void declare_ConvDepthWiseOp(py::module &m) { template <DimIdx_t DIM> void declare_ConvDepthWiseOp(py::module &m) {
py::class_<ConvDepthWise_Op<DIM>, std::shared_ptr<ConvDepthWise_Op<DIM>>, OperatorTensor, Attributes>( py::class_<ConvDepthWise_Op<DIM>, std::shared_ptr<ConvDepthWise_Op<DIM>>, Attributes, OperatorTensor>(
m, ("ConvDepthWiseOp" + std::to_string(DIM) + "D").c_str(), m, ("ConvDepthWiseOp" + std::to_string(DIM) + "D").c_str(),
py::multiple_inheritance()) py::multiple_inheritance())
.def(py::init<const DimSize_t, .def(py::init<const DimSize_t,
......
...@@ -20,7 +20,7 @@ namespace py = pybind11; ...@@ -20,7 +20,7 @@ namespace py = pybind11;
namespace Aidge { namespace Aidge {
void declare_FC(py::module &m) { void declare_FC(py::module &m) {
py::class_<FC_Op, std::shared_ptr<FC_Op>, OperatorTensor, Attributes>(m, "FCOp", py::multiple_inheritance()) py::class_<FC_Op, std::shared_ptr<FC_Op>, Attributes, OperatorTensor>(m, "FCOp", py::multiple_inheritance())
.def("get_inputs_name", &FC_Op::getInputsName) .def("get_inputs_name", &FC_Op::getInputsName)
.def("get_outputs_name", &FC_Op::getOutputsName); .def("get_outputs_name", &FC_Op::getOutputsName);
......
...@@ -19,7 +19,7 @@ namespace py = pybind11; ...@@ -19,7 +19,7 @@ namespace py = pybind11;
namespace Aidge { namespace Aidge {
void init_Gather(py::module& m) { void init_Gather(py::module& m) {
py::class_<Gather_Op, std::shared_ptr<Gather_Op>, OperatorTensor, Attributes>(m, "GatherOp", py::multiple_inheritance()) py::class_<Gather_Op, std::shared_ptr<Gather_Op>, Attributes, OperatorTensor>(m, "GatherOp", py::multiple_inheritance())
.def("get_inputs_name", &Gather_Op::getInputsName) .def("get_inputs_name", &Gather_Op::getInputsName)
.def("get_outputs_name", &Gather_Op::getOutputsName); .def("get_outputs_name", &Gather_Op::getOutputsName);
......
...@@ -21,7 +21,7 @@ namespace py = pybind11; ...@@ -21,7 +21,7 @@ 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>, OperatorTensor, DynamicAttributes>(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_readonly_static("identity", &GenericOperator_Op::Identity)
.def("compute_output_dims", &GenericOperator_Op::computeOutputDims) .def("compute_output_dims", &GenericOperator_Op::computeOutputDims)
......
...@@ -18,7 +18,7 @@ namespace py = pybind11; ...@@ -18,7 +18,7 @@ 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>, OperatorTensor, Attributes>(m, "LeakyReLUOp", py::multiple_inheritance()) py::class_<LeakyReLU_Op, std::shared_ptr<LeakyReLU_Op>, Attributes, OperatorTensor>(m, "LeakyReLUOp", py::multiple_inheritance())
.def("get_inputs_name", &LeakyReLU_Op::getInputsName) .def("get_inputs_name", &LeakyReLU_Op::getInputsName)
.def("get_outputs_name", &LeakyReLU_Op::getOutputsName); .def("get_outputs_name", &LeakyReLU_Op::getOutputsName);
......
...@@ -20,7 +20,7 @@ namespace py = pybind11; ...@@ -20,7 +20,7 @@ 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>, OperatorTensor, Attributes>(m, "MatMulOp", py::multiple_inheritance()) py::class_<MatMul_Op, std::shared_ptr<MatMul_Op>, Attributes, OperatorTensor>(m, "MatMulOp", py::multiple_inheritance())
.def("get_inputs_name", &MatMul_Op::getInputsName) .def("get_inputs_name", &MatMul_Op::getInputsName)
.def("get_outputs_name", &MatMul_Op::getOutputsName); .def("get_outputs_name", &MatMul_Op::getOutputsName);
......
...@@ -26,7 +26,7 @@ namespace py = pybind11; ...@@ -26,7 +26,7 @@ namespace py = pybind11;
namespace Aidge { namespace Aidge {
template <DimIdx_t DIM> void declare_MaxPoolingOp(py::module &m) { template <DimIdx_t DIM> void declare_MaxPoolingOp(py::module &m) {
py::class_<MaxPooling_Op<DIM>, std::shared_ptr<MaxPooling_Op<DIM>>, OperatorTensor, Attributes>( py::class_<MaxPooling_Op<DIM>, std::shared_ptr<MaxPooling_Op<DIM>>, Attributes, OperatorTensor>(
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> &,
......
...@@ -25,7 +25,7 @@ namespace py = pybind11; ...@@ -25,7 +25,7 @@ namespace py = pybind11;
namespace Aidge { namespace Aidge {
template <DimIdx_t DIM> void declare_PadOp(py::module &m) { template <DimIdx_t DIM> void declare_PadOp(py::module &m) {
py::class_<Pad_Op<DIM>, std::shared_ptr<Pad_Op<DIM>>, Operator, Attributes>( py::class_<Pad_Op<DIM>, std::shared_ptr<Pad_Op<DIM>>, Attributes, Operator>(
m, ("PadOp" + std::to_string(DIM) + "D").c_str(), m, ("PadOp" + std::to_string(DIM) + "D").c_str(),
py::multiple_inheritance()) py::multiple_inheritance())
.def(py::init<const std::array<DimSize_t, 2*DIM> &, .def(py::init<const std::array<DimSize_t, 2*DIM> &,
......
...@@ -30,7 +30,7 @@ void declare_Producer(py::module &m) { ...@@ -30,7 +30,7 @@ void declare_Producer(py::module &m) {
void init_Producer(py::module &m) { void init_Producer(py::module &m) {
py::class_<Producer_Op, std::shared_ptr<Producer_Op>, OperatorTensor, Attributes>( py::class_<Producer_Op, std::shared_ptr<Producer_Op>, Attributes, OperatorTensor>(
m, m,
"ProducerOp", "ProducerOp",
py::multiple_inheritance()) py::multiple_inheritance())
......
...@@ -24,7 +24,7 @@ namespace py = pybind11; ...@@ -24,7 +24,7 @@ namespace py = pybind11;
namespace Aidge { namespace Aidge {
template <DimIdx_t DIM> void declare_ReduceMeanOp(py::module &m) { template <DimIdx_t DIM> void declare_ReduceMeanOp(py::module &m) {
py::class_<ReduceMean_Op<DIM>, std::shared_ptr<ReduceMean_Op<DIM>>, OperatorTensor, Attributes>( py::class_<ReduceMean_Op<DIM>, std::shared_ptr<ReduceMean_Op<DIM>>, Attributes, OperatorTensor>(
m, ("ReduceMeanOp" + std::to_string(DIM) + "D").c_str(), py::multiple_inheritance()) m, ("ReduceMeanOp" + std::to_string(DIM) + "D").c_str(), py::multiple_inheritance())
.def("get_inputs_name", &ReduceMean_Op<DIM>::getInputsName) .def("get_inputs_name", &ReduceMean_Op<DIM>::getInputsName)
.def("get_outputs_name", &ReduceMean_Op<DIM>::getOutputsName) .def("get_outputs_name", &ReduceMean_Op<DIM>::getOutputsName)
......
...@@ -19,7 +19,7 @@ namespace py = pybind11; ...@@ -19,7 +19,7 @@ namespace py = pybind11;
namespace Aidge { namespace Aidge {
void init_Softmax(py::module& m) { void init_Softmax(py::module& m) {
py::class_<Softmax_Op, std::shared_ptr<Softmax_Op>, OperatorTensor, Attributes>(m, "SoftmaxOp", py::multiple_inheritance()) py::class_<Softmax_Op, std::shared_ptr<Softmax_Op>, Attributes, OperatorTensor>(m, "SoftmaxOp", py::multiple_inheritance())
.def("get_inputs_name", &Softmax_Op::getInputsName) .def("get_inputs_name", &Softmax_Op::getInputsName)
.def("get_outputs_name", &Softmax_Op::getOutputsName); .def("get_outputs_name", &Softmax_Op::getOutputsName);
......
...@@ -25,9 +25,9 @@ ...@@ -25,9 +25,9 @@
namespace py = pybind11; namespace py = pybind11;
namespace Aidge { namespace Aidge {
template <DimIdx_t DIM> template <DimIdx_t DIM>
void declare_Transpose(py::module &m) { void declare_Transpose(py::module &m) {
py::class_<Transpose_Op<DIM>, std::shared_ptr<Transpose_Op<DIM>>, OperatorTensor, Attributes>( py::class_<Transpose_Op<DIM>, std::shared_ptr<Transpose_Op<DIM>>, Attributes, OperatorTensor>(
m, ("TransposeOp" + std::to_string(DIM) + "D").c_str(), py::multiple_inheritance()) m, ("TransposeOp" + std::to_string(DIM) + "D").c_str(), py::multiple_inheritance())
.def("get_inputs_name", &Transpose_Op<DIM>::getInputsName) .def("get_inputs_name", &Transpose_Op<DIM>::getInputsName)
.def("get_outputs_name", &Transpose_Op<DIM>::getOutputsName); .def("get_outputs_name", &Transpose_Op<DIM>::getOutputsName);
......
...@@ -22,11 +22,12 @@ void init_Attributes(py::module& m){ ...@@ -22,11 +22,12 @@ void init_Attributes(py::module& m){
.def("get_attr_type", &Attributes::getAttrType, py::arg("name")) .def("get_attr_type", &Attributes::getAttrType, py::arg("name"))
.def("get_attrs_name", &Attributes::getAttrsName) .def("get_attrs_name", &Attributes::getAttrsName)
.def("get_attr", &Attributes::getAttrPy, py::arg("name")) .def("get_attr", &Attributes::getAttrPy, py::arg("name"))
.def("set_attr", &Attributes::setAttrPy, py::arg("name"), py::arg("value")); .def("__getattr__", &Attributes::getAttrPy, py::arg("name"))
.def("set_attr", &Attributes::setAttrPy, py::arg("name"), py::arg("value"))
.def("__setattr__", &Attributes::setAttrPy, py::arg("name"), py::arg("value"));
py::class_<DynamicAttributes, std::shared_ptr<DynamicAttributes>, Attributes>(m, "DynamicAttributes") py::class_<DynamicAttributes, std::shared_ptr<DynamicAttributes>, Attributes>(m, "DynamicAttributes")
.def("add_attr", &DynamicAttributes::addAttrPy, py::arg("name"), py::arg("value")) .def("add_attr", &DynamicAttributes::addAttrPy, py::arg("name"), py::arg("value"))
.def("set_attr", &DynamicAttributes::setAttrPy, py::arg("name"), py::arg("value"))
.def("del_attr", &DynamicAttributes::delAttr, py::arg("name")); .def("del_attr", &DynamicAttributes::delAttr, py::arg("name"));
m.def("test_DynamicAttributes_binding", &test_DynamicAttributes_binding); m.def("test_DynamicAttributes_binding", &test_DynamicAttributes_binding);
......
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