diff --git a/include/aidge/graph/GraphView.hpp b/include/aidge/graph/GraphView.hpp index de245ab55351e0e3255596f23a7872612de78d42..f47efe5336c67b38f535ec291bbff5d463d1fd54 100644 --- a/include/aidge/graph/GraphView.hpp +++ b/include/aidge/graph/GraphView.hpp @@ -69,7 +69,7 @@ private: public: /** * @brief Constructs a GraphView object with a given name - * @params string name : name given to the GraphView + * @param string name : name given to the GraphView */ GraphView(const std::string& name="") : mName(name) @@ -79,7 +79,7 @@ public: /** * @brief equality operator, tests if the current GraphView and the gv GraphView have the same Nodes - * @params GraphView &gv GraphView that shall be compared to the current one + * @param GraphView gv: GraphView that shall be compared to the current one * @returns bool True if both GraphView have the same set of Nodes */ bool operator==(const GraphView &gv) const @@ -89,7 +89,7 @@ public: /** * @brief Allows to find a Node in the GraphView using the Node's name - * @params string The name of the Node we are looking for + * @param string nodeName: The name of the Node we are looking for * @returns NodePtr Pointer of the Node that is found * @details Returns nullptr if the Node isn't found */ @@ -100,7 +100,7 @@ public: /////////////////////////////////////////////////////// /** * @brief Functional operator for user-friendly connection interface using an ordered set of Connectors. - * @param ctors + * @param Connector ctors: a Connector * @return Connector */ Connector operator()(const std::vector<Connector> ctors); @@ -110,14 +110,14 @@ public: /////////////////////////////////////////////////////// public: /** - * @brief Name of the GraphView. - * @return std::string + * @brief Gives the name of the GraphView. + * @return std::string the name of the graphView */ inline std::string name() const noexcept { return mName; } /** * @brief Set the GraphView name. - * @param name New name for the GraphView. + * @param string name: New name for the GraphView. */ inline void setName(const std::string &name) { mName = name; } @@ -130,9 +130,9 @@ public: /** * @brief Save the GraphView as a Mermaid graph in a .md file at the * specified location. - * @param path: Path where the file should be put - * @param verbose If true give more informations in the console during the saving process - * @param showProducers if true, shows additional informations + * @param string path: Path where the file should be put + * @param bool verbose: If true give more informations in the console during the saving process + * @param bool showProducers: if true, shows additional informations */ void save(const std::string& path, bool verbose = false, bool showProducers = true) const; @@ -140,20 +140,20 @@ public: * @brief Logs the output of all nodes of the graph in a directory * @details in the specified directory, it will create a subdirectory for each Node of the GraphView * In that sub-directory, each output of the Node will be saved in a different .log file - * @param string dirName Path of the directory where the logs shall be stocked + * @param string dirName: Path of the directory where the logs shall be stocked */ void logOutputs(const std::string& dirName) const; /** * @brief Check that a node is in the current GraphView. - * @param nodePtr Node to check + * @param NodePtr nodePtr: Node to check * @return bool True if nodePtr belongs to the GraphView. */ bool inView(const NodePtr& nodePtr) const; /** * Check that a node is in the current GraphView. - * @param nodeName Name of the node to test the existence of. + * @param string nodeName: Name of the node to test the existence of. * @return true if the GraphView contains a Node with the name ``nodeName``. */ bool inView(const std::string& nodeName) const; @@ -168,7 +168,7 @@ public: /** * Changes the rootNode of the GraphView - * @param NodePtr of the new rootNode + * @param NodePtr node: pointer of the new rootNode */ void setRootNode(NodePtr node); @@ -183,13 +183,13 @@ public: std::set<NodePtr> outputNodes() const; /** @brief Assess if the given Node is an input Node of the GraphView object. - * @param Node The tested Node + * @param NodePtr nodePtr: The tested Node * @return bool True if the Node is an input of the GraphView, False otherwise */ bool isInputNode(const NodePtr& nodePtr) const; /** @brief Assess if the given Node is an output Node of the GraphView object. - * @param Node The tested Node + * @param NodePtr nodePtr: The tested Node * @return bool True if the Node is an output of the GraphView, False otherwise */ bool isOutputNode(const NodePtr& nodePtr) const; @@ -198,7 +198,7 @@ public: * @brief Orders the inputs of the GraphView * @details The inputs will be ordered in the same order as they come in the std::vector. * Inputs missing from this vector will then be added as per their previous order. - * @param std::vector<std::pair<NodePtr, IOIndex_t>>& inputs set of inputs in the wanted order + * @param std::vector<std::pair<NodePtr, IOIndex_t>>& inputs: set of inputs in the wanted order */ void setOrderedInputs(const std::vector<std::pair<NodePtr, IOIndex_t>>& inputs); @@ -206,7 +206,7 @@ public: * @brief Orders the outputs of the GraphView * @details The outputs will be ordered in the same order as they come in the std::vector. * Outputs missing from this vector will then be added as per their previous order. - * @param std::vector<std::pair<NodePtr, IOIndex_t>>& outputs set of outputs in the wanted order + * @param std::vector<std::pair<NodePtr, IOIndex_t>>& outputs: set of outputs in the wanted order */ void setOrderedOutputs(const std::vector<std::pair<NodePtr, IOIndex_t>>& outputs); @@ -223,7 +223,7 @@ public: * otherwise a runtime exception is thrown. * The returned order is biased toward left-to-right child order both * for topological and post-dfs order. - * @param reversed returns a topological order of the reversed graph + * @param bool reversed: returns a topological order of the reversed graph * @return the ordered list of nodes */ std::vector<Aidge::NodePtr> getOrderedNodes(bool reversed = false) const; @@ -254,7 +254,7 @@ public: /** * @brief List all dataInput connections (within and outside) of the specified GraphView node named "name". * Data inputs exclude inputs expecting parameters (weights or bias). - * @param name Name of the Node. + * @param string name: Name of the Node. * @return std::vector<std::pair<NodePtr, IOIndex_t>> */ inline auto dataInputs(const std::string name) const { return mNodeRegistry.at(name)->dataInputs(); } @@ -270,6 +270,7 @@ public: /** * @TODO @warning what if the node isn't found? where is the try catch of the .at? * @brief List all input connections (within and outside) of the specified GraphView node named "name". + * @param string name: name of the graphView's node * @return std::vector<std::pair<NodePtr, IOIndex_t>> */ std::vector<std::pair<NodePtr, IOIndex_t>> inputs(const std::string& name) const; @@ -285,7 +286,7 @@ public: /** * @brief List all output connections (within and outside) of the specified GraphView node named "name". - * @param nodeName Name of the Node of which to show the output. + * @param string nodeName: Name of the Node of which to show the output. * @return std::vector<std::vector<std::pair<NodePtr, IOIndex_t>>> */ std::vector<std::vector<std::pair<NodePtr, IOIndex_t>>> outputs(const std::string& nodeName) const; @@ -302,10 +303,10 @@ public: * compatible with the selected kernel. * If not, add a Transpose Operator. * - Propagate Tensor dimensions through the consecutive Operators. - @params backend: Backend used, default is cpu - @params Aidge Datatype: datatype used, default is float32 - @params device: Device to be set - @params dims: vector of vector of DimSize_t: dims + @param string backend: Backend used, default is cpu + @param Datatype datatype: datatype used, default is float32 + @param DeviceIdx_t device: Device to be set + @param std::vector<std::vector<DimSize_t>> dims: vector of vector of dimensions of the inputs of the graphView */ void compile(const std::string& backend = "cpu", const Aidge::DataType datatype = DataType::Float32, @@ -320,24 +321,24 @@ public: * - Updates are made in node dependencies order, because if dims have changed * at any point in the graph, it must de propagated correctly to all succeeding nodes; * - It handles cyclic dependencies correctly (currently only induced by the Memorize_Op). - * @param dims: vector of vector of dimensions of the inputs of the graphView + * @param std::vector<std::vector<DimSize_t>> dims: vector of vector of dimensions of the inputs of the graphView * @return bool Whether it succeeded or not (failure can either raise an exception or return false) */ bool forwardDims(const std::vector<std::vector<DimSize_t>>& dims = {}, bool allowDataDependency = false); /** @brief Set the same backend for each Operator of the GraphView object's Nodes. - * @param string: backend Backend name to be set - * @param DeviceIdx_t: device Backend device to be set + * @param string backend: Backend name to be set + * @param DeviceIdx_t device: Backend device to be set */ void setBackend(const std::string& backend, const DeviceIdx_t device = 0) const; /** @brief Set the same data type for each Operator of the GraphView object's Nodes. - * @param DataType: datatype DataType to be set + * @param DataType datatype: DataType to be set */ void setDataType(const DataType& datatype) const; /** @brief Set the same data format for each Operator of the GraphView object's Nodes. - * @param DataFormat: dataformat DataFormat to be set + * @param DataFormat dataformat: DataFormat to be set */ void setDataFormat(const DataFormat& dataformat) const; @@ -354,7 +355,7 @@ public: /** * @brief Get parents Nodes of the specified Node. - * @param nodeName Name of the Node. + * @param string nodeName: Name of the Node. * @return std::vector<NodePtr> */ std::vector<NodePtr> getParents(const std::string nodeName) const; @@ -377,14 +378,14 @@ public: * @brief Get children Nodes of the specified Node. * @details the children will be ordered in a vector of vector of Node, * each sub-vector containing the children from one of the Node's output - * @param nodeName Name of the Node. + * @param string nodeName: Name of the Node. * @return std::vector<std::vector<NodePtr>> */ std::vector<std::vector<NodePtr>> getChildren(const std::string nodeName) const; /** * @brief Get children Nodes of the specified Node. - * @param otherNode The Node + * @param NodePtr otherNode: The Node * @return std::vector<std::vector<NodePtr>> */ std::set<NodePtr> getChildren(const NodePtr otherNode) const; // TODO change it for a vector<vector> ? @@ -397,7 +398,7 @@ public: /** * @brief Get the Node with the corresponding name if it is in the GraphView. - * @param nodeName Name of the node. + * @param string nodeName: Name of the node. * @return NodePtr returns a nullptr if the one asked for * was not found. */ @@ -424,18 +425,18 @@ public: /** // todo comment is in code * Get the nodes name according to the GraphView nodes ranking. - * @param format The formatting string to be used with fmt::format(). + * @param string format: The formatting string to be used with fmt::format(). * @details The usable positional arguments are the following: * {0} node name, {1} node type, {2} rank, {3} type rankf - * @param markNonUnicity If true, non unique ranking is prefixed with "?" + * @param bool markNonUnicity: If true, non unique ranking is prefixed with "?" * @return std::map<NodePtr, std::string> A map with the corresponding names */ std::map<NodePtr, std::string> getRankedNodesName(const std::string& format, bool markNonUnicity = true) const; /** * @brief Remove a Node from the current GraphView scope without affecting its connections. - * @param nodePtr Node to remove - * @param includeLearnableParam Whether learnable parameters should also be removed. Default true. + * @param NodePrt nodePtr: Node to remove + * @param bool includeLearnableParam: Whether learnable parameters should also be removed. Default true. * learnable params are removed only if they aren't used by other Nodes */ void remove(NodePtr nodePtr, bool includeLearnableParam = true); @@ -450,52 +451,50 @@ public: * If the Node is named, it is added in the registery as well * @details If the GraphView has no root Node (most likely this GraphView is empty) * the added Node becomes the GraphView's root Node - * @param otherNode Node to add. - * @param includeLearnableParam Include non-data inputs, like weights and biases + * @param NodePtr otherNode: Node to add. + * @param bool includeLearnableParam: Include non-data inputs, like weights and biases * in the GraphView automatically. Default: true. */ void add(NodePtr otherNode, bool includeLearnableParam = true); /** * @brief Include a set of Nodes to the current GraphView object. - * @param otherNodes Nodes to add to the GraphView - * @param includeLearnableParam Include non-data inputs, like weights and biases + * @param std::set<NodePtr> otherNodes: Nodes to add to the GraphView + * @param bool includeLearnableParam: Include non-data inputs, like weights and biases * in the GraphView automatically. Default: true. * @return true if graph ordering is unique (meaning inputs/outputs order is well defined). */ - bool add(std::set<NodePtr> otherNodes, - bool includeLearnableParam = true); + bool add(std::set<NodePtr> otherNodes, bool includeLearnableParam = true); - /** + /** TODO: this seem broken * @brief Include a set of Nodes to the current GraphView object. - * The first element of the otherNodes pair is the new RootNode of the GraphView and - * the second is the remaining nodes to add. - * @param otherNodes - * @param includeLearnableParam + * if the graphView has no rootNode, the first element of the otherNodes pair is the new RootNode of the + * GraphView and the second is the remaining nodes to add. + * @param std::pair<NodePtr, std::set<NodePtr>> otherNodes: + * @param bool includeLearnableParam: Include non-data inputs, like weights and biases + * in the GraphView automatically. Default: true. * @return true if graph ordering is unique (meaning inputs/outputs order is well defined). */ - bool add(std::pair<NodePtr, std::set<NodePtr>> otherNodes, - bool includeLearnableParam = true); + bool add(std::pair<NodePtr, std::set<NodePtr>> otherNodes, bool includeLearnableParam = true); /** * @brief Include every Node inside another GraphView to the current GraphView. * @details If the current GraphView has no RootNode it takes the RootNode of the new GraphView - * @param other_graph GraphView containing the Nodes to include. + * @param std::shared_ptr<GraphView> other_graph: GraphView containing the Nodes to include. * @return true if graph ordering is unique (meaning inputs/outputs order is well defined). */ - bool add(std::shared_ptr<GraphView> otherGraph, - bool includeLearnableParam = true); + bool add(std::shared_ptr<GraphView> otherGraph, bool includeLearnableParam = true); /** * @brief Include a Node in the current GraphView and link it to another * already contained Node as its child. * - * @param toOtherNode Pointer to the Node to add. - * @param fromOutNode Pointer to the already included Node the new Node will + * @param NodePtr toOtherNode: Pointer to the Node to add. + * @param NodePtr fromOutNode: Pointer to the already included Node the new Node will * be linked to (it will become a parent of the new Node). If the GraphView * only has one output Node, then default to this Node. - * @param fromTensor Ouput Tensor ID of the already included Node. Default to 0. - * @param toTensor Input Tensor ID of the new Node. Default to gk_IODefaultIndex, meaning + * @param IOIndex_t fromTensor: Ouput Tensor ID of the already included Node. Default to 0. + * @param IOIndex_t toTensor: Input Tensor ID of the new Node. Default to gk_IODefaultIndex, meaning * first available data input for the Node. */ void addChild(NodePtr toOtherNode, NodePtr fromOutNode = nullptr, @@ -506,13 +505,13 @@ public: * @brief Include a Node in the current GraphView and link it to another * already contained Node as its child. * - * @param toOtherNode Pointer to the Node to add. - * @param fromOutNodeName Name of the already included Node the new Node will + * @param NodePtr toOtherNode: Pointer to the Node to add. + * @param string fromOutNodeName: Name of the already included Node the new Node will * be linked to (it will become a parent of the new Node). As a name is * optional, ensure such Node is in the GraphView or it will send back an * error message. - * @param fromTensor Ouput Tensor ID of the already included Node. Default to 0. - * @param toTensor Input Tensor ID of the new Node. Default to gk_IODefaultIndex, meaning + * @param IOIndex_t fromTensor: Ouput Tensor ID of the already included Node. Default to 0. + * @param IOIndex_t toTensor: Input Tensor ID of the new Node. Default to gk_IODefaultIndex, meaning * first available data input for the Node. */ inline void addChild(NodePtr toOtherNode, const std::string& fromOutNodeName, @@ -527,8 +526,8 @@ public: // todo this shouldn't be public but a friend * @brief (from my comprehension) This function is made only to be used in Node's setName. * This method update the registry with the new Node's Name - * @param node The Node that is updated - * @param newName The new name of the Node that shall soon be updated + * @param std::shared_ptr<Node>& node: The Node that is updated + * @param string newName: The new name of the Node that shall soon be updated */ inline void updateNodeName(const std::shared_ptr<Node>& node, const std::string& newName){ if (!newName.empty()) { @@ -549,11 +548,11 @@ public: /** * @brief Include a GraphView content in the current GraphView and link * the two sets by linking one Node from each GraphView. - * @param toOtherView Pointer to the GraphView whose content should be added. - * @param fromOutNode Pair of pointer to Node and Tensor ID for specifying the + * @param std::shared_ptr<GraphView> toOtherView: Pointer to the GraphView whose content should be added. + * @param std::pair<NodePtr, IOIndex_t> fromOutNode: Pair of pointer to Node and Tensor ID for specifying the * connection. If the GraphView including the other one has only one output * Node, then it defaults to the first output Tensor of this Node. - * @param toNode Pair of pointer to Node and Tensor ID for specifying the + * @param std::pair<NodePtr, IOIndex_t> toNode: Pair of pointer to Node and Tensor ID for specifying the * connection. If the GraphView whose content is included has only one input * Node, then it defaults to the first available data input Tensor of this Node. */ @@ -566,10 +565,9 @@ public: /** //@todo not implemented * @brief Swap two Node instances if possible. - * @param node - * @param otherNode - * @return true - * @return false + * @param Node node: The Node to be swapped + * @param Node otherNode: the other Node to be swapped with + * @return bool: False as not implemented */ bool swap(Node &node, Node &otherNode); @@ -581,11 +579,11 @@ public: * @brief Insert a node (newParentNode) as a parent of the passed node (childNode) * and as a child of the current parent of the Node. * - * @param childNode Node that gets a new parent. - * @param newParentNode Inserted Node. - * @param childInputTensorIdx Index of the input Tensor for the childNode linked to the inserted Node output. - * @param newParentInputTensorIdx Index of the input Tensor for the newParentNode linked to the former parent of childNode. - * @param newParentOutputTensorIdx Index of the output Tensor for the newParentNode linked to the childNode's input Tensor. + * @param NodePtr childNode: Node that gets a new parent. + * @param NodePtr newParentNode: Inserted Node. + * @param IOIndex_t childInputTensorIdx: Index of the input Tensor for the childNode linked to the inserted Node output. + * @param IOIndex_t newParentInputTensorIdx: Index of the input Tensor for the newParentNode linked to the former parent of childNode. + * @param IOIndex_t newParentOutputTensorIdx: Index of the output Tensor for the newParentNode linked to the childNode's input Tensor. */ void insertParent(NodePtr childNode, NodePtr newParentNode, @@ -608,17 +606,22 @@ public: * - same number of input/output connections in oldNodes, parents and children are linked according * to these connections IDs * - different number of input/output connections in oldNodes => return false - * @param oldNodes - * @param newNodes - * @return true replacement has been performed - * @return false no replacement has been performed + * @param std::set<NodePtr> oldNodes: set of Nodes to be replaced + * @param std::set<NodePtr> newNodes: New set of Nodes replacing the old one + * @return bool: status of the replacement (True if it succeeded, false if it failed or didn't happen) */ static bool replace(const std::set<NodePtr>& oldNodes, const std::set<NodePtr>& newNodes); + + /** + * @see replace + * @param std::shared_ptr<GraphView> oldG: graphView to be replaced + * @param std::shared_ptr<GraphView> newG: New graphView replacing the old one + */ static bool replace(const std::shared_ptr<GraphView>& oldG, const std::shared_ptr<GraphView>& newG); /** * @brief Clone the GraphView with shared Operators. It is a new GraphView, with cloned Nodes, but the new Nodes refer to the same Operators as the original ones. - * @return std::shared_ptr<GraphView> + * @return std::shared_ptr<GraphView> The cloned graphView */ inline std::shared_ptr<GraphView> cloneSharedOperators() const { return cloneCallback(&Node::cloneSharedOperators); @@ -626,7 +629,8 @@ public: /** * @brief Clone the GraphView with shared Producers. All the other Operators are copied. - * @return std::shared_ptr<GraphView> + * Every attribute is copied, even Operator pointer except for Producers for which it is shared. + * @return std::shared_ptr<GraphView> The cloned graphView */ inline std::shared_ptr<GraphView> cloneSharedProducers() const { return cloneCallback(&Node::cloneSharedProducers); @@ -634,7 +638,7 @@ public: /** * @brief Clone the GraphView. Everything is cloned: Nodes and Operators. - * @return std::shared_ptr<GraphView> + * @return std::shared_ptr<GraphView> The cloned graphView */ inline std::shared_ptr<GraphView> clone() const { return cloneCallback(&Node::clone); @@ -646,15 +650,15 @@ public: * When a Node is removed, the clone() method automatically finds the next valid parent in line, going backward in * the graph and connects it if that makes sense without ambiguity (effectively treating the removed Node as an * identity operation). - * @param cloneNode Callback function to clone a node - * @return std::shared_ptr<GraphView> + * @param cloneNode: Callback function to clone a node (see in Node) + * @return std::shared_ptr<GraphView> The cloned graphView */ std::shared_ptr<GraphView> cloneCallback(NodePtr(*cloneNode)(NodePtr)) const; /** * @brief Get the sum of the number of free dataInput connection for all inputNodes of the GraphView object. * Data inputs exclude inputs expecting parameters (weights or bias). - * @return IOIndex_t + * @return IOIndex_t: number of free data inputs */ IOIndex_t getNbFreeDataInputs() const; @@ -688,7 +692,7 @@ private: * @brief Automatically update GraphView inputs/outputs with a new Node, checking if * it this Node becomes an input/output for the graph and if previous inputs are still * inputs/outputs after adding this node. - * @param nodePtr + * @param nodePtr newNode: recently added Node that needs updating */ //@todo see in code comment void updateInputsOutputsNew(NodePtr newNode); @@ -696,7 +700,7 @@ private: /** * @brief Automatically updates GraphView inputs/outputs with a Node removed, checking if this Node was an * input/output for the graph and if this node's children and parents become new inputs/outputs for the graph. - * @param nodePtr deletedNode the deleted //todo has the node already been delettesd or not yet? if it has been, does it keep its information? if it hasn't, one must ensure to properly delete it afterward to aavoid discrepencies + * @param nodePtr deletedNode: the deleted Node //todo has the node already been delettesd or not yet? if it has been, does it keep its information? if it hasn't, one must ensure to properly delete it afterward to aavoid discrepencies */ void updateInputsOutputsDelete(NodePtr deletedNode); @@ -708,7 +712,7 @@ private: /** * Create a GraphView containing all nodes with a path to given Node. - * @param node Initial node to construct the graph. + * @param std::shared_ptr<Node> node: Initial node to construct the graph. * @return GraphView GraphView containing all nodes with a path to node. */ std::shared_ptr<GraphView> getConnectedGraphView(std::shared_ptr<Node> node);