Skip to content
Snippets Groups Projects
Commit 5a0111b7 authored by Octave Perrin's avatar Octave Perrin
Browse files

update python bind

parent d7078383
No related branches found
No related tags found
No related merge requests found
Pipeline #60908 passed
...@@ -24,27 +24,45 @@ namespace Aidge { ...@@ -24,27 +24,45 @@ namespace Aidge {
void init_Node(py::module& m) { void init_Node(py::module& m) {
py::class_<Node, std::shared_ptr<Node>>(m, "Node") py::class_<Node, std::shared_ptr<Node>>(m, "Node")
.def(py::init<std::shared_ptr<Operator>, const std::string&>(), py::arg("op"), py::arg("name") = "") .def(py::init<std::shared_ptr<Operator>, const std::string&>(), py::arg("op"), py::arg("name") = "")
.def("name", &Node::name, .def("name", &Node::name,
R"mydelimiter( R"mydelimiter(
Name of the Node. Name of the Node.
:return: The name of the Node
:rtype: string
)mydelimiter") )mydelimiter")
.def("clone", (NodePtr (Node::*)() const) &Node::clone, .def("clone", (NodePtr (Node::*)() const) &Node::clone,
R"mydelimiter( R"mydelimiter(
Clone the Node and its Operator. The new Node has no connection. Clone the Node and its Operator. The new Node has no connection.
:return: The new cloned Node
:rtype: Node
)mydelimiter") )mydelimiter")
.def("type", &Node::type, .def("type", &Node::type,
R"mydelimiter( R"mydelimiter(
Type of the node. Type of the node.
:return: the type of the Node's operator
:rtype: string
)mydelimiter") )mydelimiter")
.def("attributes", &Node::attributes, .def("attributes", &Node::attributes,
R"mydelimiter( R"mydelimiter(
Get attributes. Get attributes.
:return: The attributes of the Node
:rtype: DynamicAttributes
)mydelimiter") )mydelimiter")
.def("get_operator", &Node::getOperator, .def("get_operator", &Node::getOperator,
R"mydelimiter( R"mydelimiter(
Get the Operator object of the Node. Get the Operator object of the Node.
:return: The Node's Operator
:rtype: Operator
)mydelimiter") )mydelimiter")
.def("set_name", &Node::setName, py::arg("name"), .def("set_name", &Node::setName, py::arg("name"),
...@@ -53,7 +71,6 @@ void init_Node(py::module& m) { ...@@ -53,7 +71,6 @@ void init_Node(py::module& m) {
:param name: New name for the node. :param name: New name for the node.
:type name: str :type name: str
:rtype: str
)mydelimiter") )mydelimiter")
.def("create_unique_name", &Node::createUniqueName, py::arg("base_name"), .def("create_unique_name", &Node::createUniqueName, py::arg("base_name"),
...@@ -62,6 +79,7 @@ void init_Node(py::module& m) { ...@@ -62,6 +79,7 @@ void init_Node(py::module& m) {
:param base_name: proposed name for the node. :param base_name: proposed name for the node.
:type base_name: str :type base_name: str
:return: A name that is not yet in use in any of the Node's GraphViews
:rtype: str :rtype: str
)mydelimiter") )mydelimiter")
...@@ -130,6 +148,8 @@ void init_Node(py::module& m) { ...@@ -130,6 +148,8 @@ void init_Node(py::module& m) {
.def("outputs", &Node::outputs, .def("outputs", &Node::outputs,
R"mydelimiter( R"mydelimiter(
Get, for each output of the Node, a list of the children Node and the associated input index connected to it. Get, for each output of the Node, a list of the children Node and the associated input index connected to it.
The parent list size matches the number of outputs of the node.
Each sub-list size will match the number of children connected to the n-th output (i.e. if 3 nodes are connected to the 3rd output parent_list[2].size() == 3).
:return: List of a list of connections. When an output is not linked to any child, its list a empty. :return: List of a list of connections. When an output is not linked to any child, its list a empty.
:rtype: list[list[tuple[Node, int]]] :rtype: list[list[tuple[Node, int]]]
...@@ -148,8 +168,9 @@ void init_Node(py::module& m) { ...@@ -148,8 +168,9 @@ void init_Node(py::module& m) {
.def("get_nb_inputs", &Node::nbInputs, .def("get_nb_inputs", &Node::nbInputs,
R"mydelimiter( R"mydelimiter(
Number of inputs of the Node. Gives the number of inputs of the Node.
:return: The number of inputs of the Node
:rtype: int :rtype: int
)mydelimiter") )mydelimiter")
...@@ -158,13 +179,15 @@ void init_Node(py::module& m) { ...@@ -158,13 +179,15 @@ void init_Node(py::module& m) {
Category of a specific input (Data or Param, optional or not). Category of a specific input (Data or Param, optional or not).
Data inputs exclude inputs expecting parameters (weights or bias). Data inputs exclude inputs expecting parameters (weights or bias).
:return: The inputCategory of the idx-th input of the Node
:rtype: InputCategory :rtype: InputCategory
)mydelimiter") )mydelimiter")
.def("get_nb_outputs", &Node::nbOutputs, .def("get_nb_outputs", &Node::nbOutputs,
R"mydelimiter( R"mydelimiter(
Number of outputs of the Node. Gives the number of outputs of the Node.
:return: the number our outputs of the Node
:rtype: int :rtype: int
)mydelimiter") )mydelimiter")
...@@ -172,22 +195,39 @@ void init_Node(py::module& m) { ...@@ -172,22 +195,39 @@ void init_Node(py::module& m) {
R"mydelimiter( R"mydelimiter(
Get the pointer to parent of the specified input index. Get the pointer to parent of the specified input index.
This pointer is nullptr if no parent is linked to that input. This pointer is nullptr if no parent is linked to that input.
:return: The parent of the specified input
:rtype: Node
)mydelimiter") )mydelimiter")
.def("get_parents", &Node::getParents,R"mydelimiter( .def("get_parents", &Node::getParents,R"mydelimiter(
Get the list of parent Nodes. Get the list of parent Nodes.
Each input can only be linked to one Node. Each input can only be linked to one Node.
If an input has no linked node, the associated parent is nullptr If an input has no linked node, the associated parent is nullptr
:return: The list of parent Nodes
:rtype: List[Node]
)mydelimiter") )mydelimiter")
.def("get_children", (std::set<std::shared_ptr<Node>> (Node::*)() const) &Node::getChildren, .def("get_children", (std::set<std::shared_ptr<Node>> (Node::*)() const) &Node::getChildren,
R"mydelimiter( R"mydelimiter(
Returns a set of all children of the Node Get the set of children Nodes linked to the current Node.
The returned set does not include any nullptr as an output.
Node that are several times child of this one (several of its input come from this Node) appear only once
:return: The set of children of the Node
:rtype: Set{Node}
)mydelimiter") )mydelimiter")
.def("get_ordered_children", &Node::getOrderedChildren, .def("get_ordered_children", &Node::getOrderedChildren,
R"mydelimiter( R"mydelimiter(
Get ordered children. Get all children of the node
The parent vector size matches the number of outputs of the node.
Each sub-vector size will match the number of children connected to the n-th output
(i.e. if 3 nodes are connected to the 3rd output parent_vec[2].size() == 3).
:return:The list (main list,size=number of outputs) of lists (one per output of the Node) of children
:rtype: List[List[Node]]
)mydelimiter") )mydelimiter")
.def("__call__", .def("__call__",
......
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