diff --git a/include/aidge/operator/And.hpp b/include/aidge/operator/And.hpp index 3739f954fb7660b2643d559eb6d272baac561abe..04a2fab1ed3569da161049ecece85a6e906e1cd8 100644 --- a/include/aidge/operator/And.hpp +++ b/include/aidge/operator/And.hpp @@ -32,6 +32,10 @@ class And_Op : public OperatorTensor, public: static const std::string Type; + /** + * @brief Compute element-wise and operation on two given inputs. + * @details supports broadcasting of both operands. + */ And_Op() : OperatorTensor(Type, {InputCategory::Data, InputCategory::Data}, 1) {} /** diff --git a/include/aidge/operator/ArgMax.hpp b/include/aidge/operator/ArgMax.hpp index 7c90cd2837f5012c51b667a4b090fd36e74f851a..1b11e211d23563d75bf943a96fa26bc84a3aa4b8 100644 --- a/include/aidge/operator/ArgMax.hpp +++ b/include/aidge/operator/ArgMax.hpp @@ -28,6 +28,9 @@ namespace Aidge { enum class ArgMaxAttr { Axis, KeepDims, SelectLastIndex }; +/** + * @brief This operator has as purpose to reduce given dimension by replacing with the Max value's index. +*/ class ArgMax_Op : public OperatorTensor, public Registrable<ArgMax_Op, std::string, std::shared_ptr<OperatorImpl>(const ArgMax_Op &)> { @@ -37,8 +40,8 @@ public: private: using Attributes_ = StaticAttributes<ArgMaxAttr, std::int32_t, - DimSize_t, - DimSize_t>; + bool, + bool>; template <ArgMaxAttr e> using attr = typename Attributes_::template attr<e>; const std::shared_ptr<Attributes_> mAttributes; @@ -46,7 +49,15 @@ private: public: ArgMax_Op() = delete; - ArgMax_Op(std::int32_t axis, DimSize_t keep_dims, DimSize_t select_last_index) + /** + * @brief constructor for ArgMax op + * @param[in] axis around which perform the operation + * @param[in] keep_dims if true we set a dimension of 1 in the place of the reduced axis and + * if false we remove the dimension completely + * @param[in] select_last_index in case we have many maximum, if true the last index is returned + * if false the first index is returned. + */ + ArgMax_Op(std::int32_t axis, bool keep_dims, bool select_last_index) : OperatorTensor(Type, {InputCategory::Data}, 1), mAttributes(std::make_shared<Attributes_>( attr<ArgMaxAttr::Axis>(axis), @@ -83,8 +94,8 @@ public: inline std::shared_ptr<Attributes> attributes() const override { return mAttributes; } inline std::int32_t& axis() const noexcept { return mAttributes -> getAttr<ArgMaxAttr::Axis>(); } - inline DimSize_t& keepDims() const noexcept { return mAttributes -> getAttr<ArgMaxAttr::KeepDims>(); } - inline DimSize_t& selectLastIndex() const noexcept { return mAttributes -> getAttr<ArgMaxAttr::SelectLastIndex>(); } + inline bool& keepDims() const noexcept { return mAttributes -> getAttr<ArgMaxAttr::KeepDims>(); } + inline bool& selectLastIndex() const noexcept { return mAttributes -> getAttr<ArgMaxAttr::SelectLastIndex>(); } static const std::vector<std::string> getInputsName() { @@ -107,8 +118,8 @@ public: * @return std::shared_ptr<Node> Node containing the Operator. */ inline std::shared_ptr<Node> ArgMax(std::int32_t axis=0, - DimSize_t keep_dims=1, - DimSize_t select_last_index=0, + bool keep_dims=true, + bool select_last_index=false, const std::string& name = "") { return std::make_shared<Node>(std::make_shared<ArgMax_Op>(axis, keep_dims, select_last_index), name); diff --git a/include/aidge/operator/ReduceMean.hpp b/include/aidge/operator/ReduceMean.hpp index 1923e49775bd7e24997fffc0a826464e1fa2c5f3..43b121be2654c1dd63116075be397e421823b9b5 100644 --- a/include/aidge/operator/ReduceMean.hpp +++ b/include/aidge/operator/ReduceMean.hpp @@ -28,6 +28,9 @@ namespace Aidge { enum class ReduceMeanAttr { Axes, KeepDims, NoopWithEmptyAxes }; +/** + * @brief This operator has as purpose to reduce given axes by replacing with the mean value. +*/ class ReduceMean_Op : public OperatorTensor, public Registrable<ReduceMean_Op, std::string, std::shared_ptr<OperatorImpl>(const ReduceMean_Op &)> { @@ -46,6 +49,14 @@ private: public: ReduceMean_Op() = delete; + /** + * @brief constructor for ReduceMean op + * @param[in] axes around which perform the operation + * @param[in] keep_dims if true we set a dimension of 1 in the place of the reduced axes and + * if false we remove the dimension completely + * @param[in] noop_with_empty_axes used when no axes are provided, if set to true, the operator does nothing + * and if false, we reduce on all axes + */ ReduceMean_Op(const std::vector<std::int32_t>& axes, bool keep_dims, bool noop_with_empty_axes); /** diff --git a/include/aidge/operator/ReduceSum.hpp b/include/aidge/operator/ReduceSum.hpp index fc1c484c2fb8c3ebb2a571832336df9470d46438..9d1220b6b2e7c1e8029ebe20b03d5501d90ae0f6 100644 --- a/include/aidge/operator/ReduceSum.hpp +++ b/include/aidge/operator/ReduceSum.hpp @@ -28,6 +28,10 @@ namespace Aidge { enum class ReduceSumAttr { Axes, KeepDims, NoopWithEmptyAxes }; + +/** + * @brief This operator has as purpose to reduce given axes by replacing with the sum value. +*/ class ReduceSum_Op : public OperatorTensor, public Registrable<ReduceSum_Op, std::string, std::shared_ptr<OperatorImpl>(const ReduceSum_Op &)> { @@ -46,6 +50,14 @@ private: public: ReduceSum_Op() = delete; + /** + * @brief constructor for ReduceSum op + * @param[in] axes around which perform the operation + * @param[in] keep_dims if true we set a dimension of 1 in the place of the reduced axes and + * if false we remove the dimension completely + * @param[in] noop_with_empty_axes used when no axes are provided, if set to true, the operator does nothing + * and if false, we reduce on all axes + */ ReduceSum_Op(const std::vector<std::int32_t>& axes, bool keep_dims, bool noop_with_empty_axes) : OperatorTensor(Type, {InputCategory::Data}, 1), mAttributes(std::make_shared<Attributes_>( diff --git a/python_binding/operator/pybind_And.cpp b/python_binding/operator/pybind_And.cpp index 29448f73bfcdbc130c8e9566c74d8ebeafd5ff12..08dddfc8168bb77086a3dd72aca45b110a4cbce9 100644 --- a/python_binding/operator/pybind_And.cpp +++ b/python_binding/operator/pybind_And.cpp @@ -19,11 +19,16 @@ namespace py = pybind11; namespace Aidge { void init_And(py::module& m) { - py::class_<And_Op, std::shared_ptr<And_Op>, OperatorTensor>(m, "AndOp", py::multiple_inheritance()) + py::class_<And_Op, std::shared_ptr<And_Op>, OperatorTensor>(m, "AndOp", py::multiple_inheritance(), + R"mydelimiter( Initialize an And operator.)mydelimiter") .def(py::init<>()) .def_static("get_inputs_name", &And_Op::getInputsName) .def_static("get_outputs_name", &And_Op::getOutputsName); declare_registrable<And_Op>(m, "AndOp"); - m.def("And", &And, py::arg("name") = ""); + m.def("And", &And, py::arg("name") = "", + R"mydelimiter( + Initialize a node containing an And operator. + :param name : name of the node. + )mydelimiter"); } } // namespace Aidge diff --git a/python_binding/operator/pybind_ArgMax.cpp b/python_binding/operator/pybind_ArgMax.cpp index 2ab7b171634264db29d8b866954be3a65b304144..3de54afd7a669347cc2b272cff9b87cf152be09a 100644 --- a/python_binding/operator/pybind_ArgMax.cpp +++ b/python_binding/operator/pybind_ArgMax.cpp @@ -27,21 +27,46 @@ namespace Aidge { void init_ArgMax(py::module &m) { const std::string pyClassName("ArgMaxOp"); py::class_<ArgMax_Op, std::shared_ptr<ArgMax_Op>, OperatorTensor>( - m, pyClassName.c_str(), py::multiple_inheritance()) - .def(py::init<std::int32_t, DimSize_t, DimSize_t>(), py::arg("axis"), py::arg("keep_dims"), py::arg("select_last_index")) + m, pyClassName.c_str(), py::multiple_inheritance(), + R"mydelimiter( + Initialize an ArgMax operator. + :param axis: The axis along which to compute the max element. The accepted range is [-r, r-1], + where r is the rank of the input tensor. + :type axis: int + :param keepdims: If True (default), retains the reduced dimensions with size 1. If False, + the reduced dimensions are removed. + :type keepdims: bool + :param select_last_index: If True, selects the last index if there are multiple occurrences + of the max value. If False (default), selects the first occurrence. + :type select_last_index: bool + )mydelimiter") + .def(py::init<std::int32_t, bool, bool>(), py::arg("axis"), py::arg("keep_dims"), py::arg("select_last_index")) .def_static("get_inputs_name", &ArgMax_Op::getInputsName) .def_static("get_outputs_name", &ArgMax_Op::getOutputsName) ; declare_registrable<ArgMax_Op>(m, pyClassName); - m.def("ArgMax", [](std::int32_t axes, - DimSize_t keepDims, - DimSize_t selectLastIndex, + m.def("ArgMax", [](std::int32_t axis, + bool keepDims, + bool selectLastIndex, const std::string& name) { - return ArgMax(axes, keepDims, selectLastIndex, name); + return ArgMax(axis, keepDims, selectLastIndex, name); }, py::arg("axis") = 0, - py::arg("keep_dims") = 1, - py::arg("select_last_index") = 0, - py::arg("name") = ""); + py::arg("keep_dims") = true, + py::arg("select_last_index") = false, + py::arg("name") = "", + R"mydelimiter( + Initialize a node containing an ArgMax operator. + :param axis: The axis along which to compute the max element. The accepted range is [-r, r-1], + where r is the rank of the input tensor. + :type axis: int + :param keepdims: If True (default), retains the reduced dimensions with size 1. If False, + the reduced dimensions are removed. + :type keepdims: bool + :param select_last_index: If True, selects the last index if there are multiple occurrences + of the max value. If False (default), selects the first occurrence. + :type select_last_index: bool + :param name : name of the node. + )mydelimiter"); } } // namespace Aidge diff --git a/python_binding/operator/pybind_ReduceMean.cpp b/python_binding/operator/pybind_ReduceMean.cpp index cd06ec64a8a7b0e227df274b679be960662a67d2..31f88d149d4d654c464b37f3b49c2839c13ea64d 100644 --- a/python_binding/operator/pybind_ReduceMean.cpp +++ b/python_binding/operator/pybind_ReduceMean.cpp @@ -27,7 +27,19 @@ namespace Aidge { void declare_ReduceMeanOp(py::module &m) { const std::string pyClassName("ReduceMeanOp"); py::class_<ReduceMean_Op, std::shared_ptr<ReduceMean_Op>, OperatorTensor>( - m, pyClassName.c_str(), py::multiple_inheritance()) + m, pyClassName.c_str(), py::multiple_inheritance(), + R"mydelimiter( + Initialize a ReduceMean operator. + :param axes: Axes along which to do the reduction. The accepted range is [-r, r-1], + where r is the rank of the input tensor. + :type axes: List[int] + :param keepdims: If True (default), retains the reduced dimensions with size 1. If False, + the reduced dimensions are removed. + :type keepdims: bool + :param noop_with_empty_axes: If True, the operator just copies the input, + if False, the operatpr reduces all the dimensions. + :type noop_with_empty_axes: bool + )mydelimiter") .def(py::init<std::vector<std::int32_t>, bool, bool>(), py::arg("axes"), py::arg("keep_dims"), py::arg("noop_with_empty_axes")) .def_static("get_inputs_name", &ReduceMean_Op::getInputsName) .def_static("get_outputs_name", &ReduceMean_Op::getOutputsName) @@ -44,7 +56,20 @@ void declare_ReduceMeanOp(py::module &m) { }, py::arg("axes") = std::vector<std::int32_t>(), py::arg("keep_dims") = true, py::arg("noop_with_empty_axes") = false, - py::arg("name") = ""); + py::arg("name") = "", + R"mydelimiter( + Initialize a node containing a ReduceMean operator. + :param axes: Axes along which to do the reduction. The accepted range is [-r, r-1], + where r is the rank of the input tensor. + :type axes: List[int] + :param keepdims: If True (default), retains the reduced dimensions with size 1. If False, + the reduced dimensions are removed. + :type keepdims: bool + :param noop_with_empty_axes: If True, the operator just copies the input, + if False, the operatpr reduces all the dimensions. + :type noop_with_empty_axes: bool + :param name : name of the node. + )mydelimiter"); } diff --git a/python_binding/operator/pybind_ReduceSum.cpp b/python_binding/operator/pybind_ReduceSum.cpp index 07372d6c019634156913bea6fb863fd76d0e7d0f..eaa57ef1c663a03cfd59ce02c13c3c7028b69e01 100644 --- a/python_binding/operator/pybind_ReduceSum.cpp +++ b/python_binding/operator/pybind_ReduceSum.cpp @@ -27,7 +27,19 @@ namespace Aidge { void init_ReduceSum(py::module &m) { const std::string pyClassName("ReduceSumOp"); py::class_<ReduceSum_Op, std::shared_ptr<ReduceSum_Op>, OperatorTensor>( - m, pyClassName.c_str(), py::multiple_inheritance()) + m, pyClassName.c_str(), py::multiple_inheritance(), + R"mydelimiter( + Initialize a ReduceMean operator. + :param axes: Axes along which to do the reduction. The accepted range is [-r, r-1], + where r is the rank of the input tensor. + :type axes: List[int] + :param keepdims: If True (default), retains the reduced dimensions with size 1. If False, + the reduced dimensions are removed. + :type keepdims: bool + :param noop_with_empty_axes: If True, the operator just copies the input, + if False, the operatpr reduces all the dimensions. + :type noop_with_empty_axes: bool + )mydelimiter") .def(py::init<std::vector<std::int32_t>, bool, bool>(), py::arg("axes"), py::arg("keep_dims"), py::arg("noop_with_empty_axes")) .def_static("get_inputs_name", &ReduceSum_Op::getInputsName) .def_static("get_outputs_name", &ReduceSum_Op::getOutputsName) @@ -42,6 +54,19 @@ void init_ReduceSum(py::module &m) { }, py::arg("axes") = std::vector<std::int32_t>(), py::arg("keep_dims") = true, py::arg("noop_with_empty_axes") = false, - py::arg("name") = ""); + py::arg("name") = "", + R"mydelimiter( + Initialize a node containing a ReduceMean operator. + :param axes: Axes along which to do the reduction. The accepted range is [-r, r-1], + where r is the rank of the input tensor. + :type axes: List[int] + :param keepdims: If True (default), retains the reduced dimensions with size 1. If False, + the reduced dimensions are removed. + :type keepdims: bool + :param noop_with_empty_axes: If True, the operator just copies the input, + if False, the operatpr reduces all the dimensions. + :type noop_with_empty_axes: bool + :param name : name of the node. + )mydelimiter"); } } // namespace Aidge