Skip to content
Snippets Groups Projects

aidge#199: Add documentation for Node

Closed Ghost User requested to merge hrouis/aidge_core:issue#199 into dev
Compare and
2 files
+ 95
44
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 78
35
@@ -41,6 +41,16 @@ class GraphView;
/**
* @brief Object carrying the topological information of the computational graph.
* A Node contains :
* - mName: the name of the Node, should be unique
* - mViews: a set of pointers to GraphView instances including this Node instance
* - mOperator: a pointer to the Operator associated to the node
* - mParents: a vector of parent nodes, which are its inputs
* - mIdOutParents: a vector of indexes, which tells for all the parent nodes from which of their output we take the value
* - mChildren: a vector of vector of children nodes, which lists all the recipient nodes, for all of the outputs
* - mIdInChildren: a vector of vector of indexes, which gives for all the recipient nodes in which of their input the current value is taken
* - mForward: queue of forward propagation function
* - mBackward: queue of backward propagation function
*/
class Node : public std::enable_shared_from_this<Node> {
private:
@@ -68,11 +78,13 @@ private:
std::deque<std::function<bool()>> mBackward;
public:
#ifndef DOXYGEN_SHOULD_SKIP_THIS
Node() = delete;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
/**
* @brief Construct a new Node object associated with the input Operator.
* @param op Operator giving the Node its number of connections.
* @brief Construct a new Node object associated with the inputted Operator.
* @param op The Operator of the Node, it determines its number of connections.
* @param attrs Attributes for the Node.
*/
Node(std::shared_ptr<Operator> op, std::shared_ptr<DynamicAttributes> attrs);
@@ -80,7 +92,7 @@ public:
/**
* @brief Construct a new Node object associated with the input Operator.
* @param op Operator giving the Node its number of connections.
* @param op The Operator of the Node, it determines its number of connections.
* @param name (optional) name for the Node.
*/
Node(std::shared_ptr<Operator> op, const std::string& name = "");
@@ -115,6 +127,7 @@ public:
/**
* @brief Functional operator for user-friendly connection interface using an ordered set of Connectors.
* @param ctors Ordered Connectors linking their associated Node to the input of the current Node with the same index.
* @warning length of ctors must be lower than the number of input of the Node
* @return Connector
*/
Connector operator()(const std::vector<Connector> &ctors);
@@ -132,7 +145,7 @@ public:
/**
* @brief Set the Node name.
* @warning Undefined behaviour when several Nodes have the same name.
* @warning Undefined behaviour when several Nodes have the same name, use createUniqueName to avoid complications.
* @param name New name for the node.
*/
void setName(const std::string &name);
@@ -140,9 +153,9 @@ public:
/**
* @brief Given the parameter name generate a new name which is unique
* in all the GraphView which contains this node.
* To generate the new name the method is called recursively and append
* the caracter ``_``.
* If no duplicate return name, this is the exit condition.
* @details if the inputted name is not yet used, it will be used as is
* if it is used, the returned name will be "name_X"
* name being the inputted name and X the smaller integer allowing name uniqueness
* @param name Base name to make unique.
* @return A unique name in all the GraphView which contains this one.
*/
@@ -181,22 +194,22 @@ public:
/**
* @brief Whether or not every input of the Node is linked to a Parent.
* If true then the Node is ready to be executed.
* @return true
* @return false
* @return bool
*/
bool valid() const;
/**
* @brief List of pair <Parent, ID of the data intput>. When an input is not
* linked to any Parent, the pair is <nullptr, gk_IODefaultIndex>.
* @brief List the pairs <Parent, ID of the data intput> of the Node's inputs.
* @details When an input is not linked to any Parent, the pair is <nullptr, gk_IODefaultIndex>.
* Data inputs exclude inputs expecting parameters (weights or bias).
* @return std::vector<std::pair<std::shared_ptr<Node>, IOIndex_t>>
*/
std::vector<std::pair<NodePtr, IOIndex_t>> dataInputs() const;
/**
* @brief List of pair <Parent, ID of the parent output>. When an input is not linked
* to any Parent, the pair is <nullptr, gk_IODefaultIndex>.
* @brief List the pairs <Parent, ID of the in put> of the Node's inputs.
* @details When an input is not linked to any Parent, the pair is <nullptr, gk_IODefaultIndex>.
* as opposed to dataInputs, inputs includes inputs expecting parameters (weights or biases)
* @return std::vector<std::pair<std::shared_ptr<Node>, IOIndex_t>>
*/
std::vector<std::pair<NodePtr, IOIndex_t>> inputs() const;
@@ -204,7 +217,7 @@ public:
/**
* @brief Parent and its output Tensor ID linked to the inID-th input Tensor.
* If the input is not linked to any Parent, the pair is <nullptr, gk_IODefaultIndex>.
* @param inID
* @param inID : the ID of the input that we want to know its parent
* @return std::pair<std::shared_ptr<Node>, IOIndex_t>
*/
inline std::pair<NodePtr, IOIndex_t> input(const IOIndex_t inID) const {
@@ -215,7 +228,7 @@ public:
/**
* @brief Get the lowest index in the InputData Parent list equal to the
* nullptr.
* nullptr (i.e. the ID of the first free data input).
* Data inputs exclude inputs expecting parameters (weights or bias).
* @return std::size_t
*/
@@ -231,22 +244,27 @@ public:
return (i < nbInputs()) ? i : gk_IODefaultIndex;
}
/**
* @brief Returns the number of free data inputs of the Node
* (i.e. data inputs that are not linked to an other node)
* @warning Node cannot run until all of its inputs are filled"
* @return IOIndex_t
*/
IOIndex_t getNbFreeDataInputs() const;
/**
* @brief List input ids of children linked to outputs of the node. The vector
* size is garanteed to match the number of outputs of the node. If there is
* no connection to a given output, the corresponding sub-vector will be empty.
* @brief Lists Nodes and input ids of children linked to each of the outputs of the node.
* @details Primary vector size matches the number of outputs of the node as each sub-vector
* will contain the children taking from a different output
* If there is no connection to a given output, the corresponding sub-vector will be empty.
* @return std::vector<std::vector<std::pair<std::shared_ptr<Node>,
* IOIndex_t>>>
*/
std::vector<std::vector<std::pair<NodePtr, IOIndex_t>>> outputs() const;
/**
* @brief Children and their input Tensor ID linked to the outId-th output
* Tensor.
* @param outId
* @brief Lists Nodes and input ids of children linked to specified output of the Node
* @param outId ID of the output from which we want to know the children
* @return std::vector<std::pair<std::shared_ptr<Node>, IOIndex_t>>
*/
std::vector<std::pair<NodePtr, IOIndex_t>>
@@ -254,7 +272,7 @@ public:
/**
* @brief Number of inputs, including both data and learnable parameters.
* @details [data, data, weight, bias] => 4
* @details ex: [data, data, weight, bias] => 4
* @return IOIndex_t
*/
inline IOIndex_t nbInputs() const noexcept { return getOperator()->nbInputs(); }
@@ -262,13 +280,14 @@ public:
/**
* @brief Category of a specific input (Data or Param, optional or not).
* Data inputs exclude inputs expecting parameters (weights or bias).
* @details ex: [data, data, weight, bias] => 2
* @return InputCategory
*/
inline InputCategory inputCategory(IOIndex_t idx) const {
return getOperator()->inputCategory(idx);
}
/**
/** TODO: ask more details about this back edge thingy
* @brief Returns whether the given node parent index is a back edge
* A back edge is defined by the operator and node parent index
* correspond to operator input index.
@@ -280,6 +299,7 @@ public:
/**
* @brief Number of inputs linked to a Parent's output.
* @warning Inputs that are not linked will prevent the node from functioning
* @return IOIndex_t
*/
IOIndex_t nbValidInputs() const;
@@ -319,6 +339,11 @@ public:
mViews.insert(std::weak_ptr<GraphView>(graphPtr));
}
/**
* @brief Remove the reference of this Node to the GraphView passed as argument.
* This function is internal and does not remove the reference of the GraphView to the Node.
* @param graphPtr Pointer to GraphView to remove from the list.
*/
inline void removeView(const std::shared_ptr<GraphView> &graphPtr) {
mViews.erase(graphPtr);
}
@@ -329,7 +354,7 @@ public:
* @param outId ID of the current Node output to connect to the other Node.
* Default to 0.
* @param otherInId ID of the other Node input to connect to the current Node.
* Default to the first avaible data input.
* Default to the first available data input.
*/
void addChild(NodePtr otherNode,
const IOIndex_t outId = IOIndex_t(0),
@@ -352,8 +377,10 @@ public:
std::pair<NodePtr, IOIndex_t>(nullptr, gk_IODefaultIndex));
/**
* @brief Get the list of parent Nodes. As an input is linked to a unique Node,
* if none is linked then the parent is a nullptr.
* @brief
* Get the list of parent Nodes.
* Each input can only be linked to one Node.
* If an input has no linked node, the associated parent is nullptr
* @return std::vector<std::shared_ptr<Node>>
*/
std::vector<NodePtr> getParents() const;
@@ -376,6 +403,11 @@ public:
*/
NodePtr popParent(const IOIndex_t inId);
/**
* @brief unlinks the parent from the Node and replaces it with nullptr (for coherence with remaining parents)
* @param inId Input index of the parent to be removed
* @return std::bool true if parent has been removed.
*/
bool removeParent(const IOIndex_t inId);
/**
@@ -386,6 +418,10 @@ public:
*/
std::set<NodePtr> getChildren() const;
/**
* @brief Get all sets of children of the node, grouped by which output of the Node they come from
* @returns std::vector<std::vector<std::shared_ptr<Node>>>
*/
std::vector<std::vector<NodePtr>> getOrderedChildren() const;
/**
@@ -397,7 +433,7 @@ public:
/**
* @brief Remove registered child from children list of specified output if possible.
* If so, also remove current Node from child Node from parent.
* If so, also remove current Node from child's parent.
* @param std::shared_ptr<Node> Node to remove.
* @param outId Output index. Default 0.
* @return true Child found and removed for given output index.
@@ -462,14 +498,21 @@ public:
/**
* @brief Get the set of pointers to connected node at a distance of a delta.
* @details the recution are cut
* Return a nullptr is nofing found.
* @param delta Input delta.
* @return std::shared_ptr<Node>
* @details positive value are toward children, negative toward parents (ex: -2 would give grandparents)
* Return a nullptr is nothing found.
* @param int delta Input delta.
* @param std::set<Aidge::NodePtr> nodeSee is used in the recursion to avoid looping on the same nodes,
* should be empty when calling the method
* @return std::set<Aidge::NodePtr> set of nodes within expected distance from the original node
*/
std::set<NodePtr> getNodeDelta(int delta,std::set<Aidge::NodePtr> nodeSee);
/**
* @brief Makes an object taking all relevant info of the node into some string.
* being in a string would allow these information to be easily shown.
* As it shows the node's connection it is a tool for comprehension or debugging of the Node and graph.
* thanks to pybind, this object should be accessible in python.
*/
#ifdef PYBIND
std::string repr() const {
std::string nodeString{fmt::format("Node(name='{}', optype='{}'", name(), type())};
@@ -506,8 +549,8 @@ private:
/**
* @brief Set the idInChildren parameter.
* @param inID
* @param newNodeOutID
* @param IOIndex_t inID
* @param IOIndex_t newNodeOutID
*/
void setInputId(const IOIndex_t inID, const IOIndex_t newNodeOutID);
Loading