Skip to content
Snippets Groups Projects
Commit 0ea59366 authored by Maxence Naud's avatar Maxence Naud
Browse files

[Upd] GraphView files

parent 5b042ee3
No related branches found
No related tags found
No related merge requests found
...@@ -96,7 +96,7 @@ public: ...@@ -96,7 +96,7 @@ public:
bool inView(const NodePtr& nodePtr) const; bool inView(const NodePtr& nodePtr) const;
inline NodePtr getRootNode() const noexcept { inline NodePtr rootNode() const noexcept {
return mRootNode; return mRootNode;
} }
......
...@@ -9,11 +9,17 @@ ...@@ -9,11 +9,17 @@
* *
********************************************************************************/ ********************************************************************************/
#include <algorithm> #include <algorithm> // std::find, std::set_difference, std::set_intersection
#include <cassert> #include <cassert>
#include <iterator> #include <cstddef> // std::size_t
#include <utility> #include <cstdio> // std::fopen, std::fprintf, std::fclose
#include <numeric> #include <iterator> // std::inserter, std::distance, std::next
#include <map>
#include <memory> // std::shared_ptr, std::static_pointer_cast, std::make_shared
#include <set>
#include <string> // std::to_string
#include <utility> // std::pair, std::make_pair
#include <vector>
#include "aidge/utils/Types.h" #include "aidge/utils/Types.h"
#include "aidge/graph/GraphView.hpp" #include "aidge/graph/GraphView.hpp"
...@@ -71,16 +77,12 @@ void Aidge::GraphView::save(std::string path, bool verbose, bool showProducers) ...@@ -71,16 +77,12 @@ void Aidge::GraphView::save(std::string path, bool verbose, bool showProducers)
// Start by creating every node // Start by creating every node
for (const std::shared_ptr<Node> &node_ptr : mNodes) { for (const std::shared_ptr<Node> &node_ptr : mNodes) {
const std::string currentType = node_ptr->type(); const std::string currentType = node_ptr->type();
if (typeCounter.find(currentType) == typeCounter.end())
typeCounter[currentType] = 0;
++typeCounter[currentType]; ++typeCounter[currentType];
std::string givenName = const std::string givenName = (node_ptr->name().empty()) ?
(node_ptr->name().empty()) "<em>" + currentType + "#" + std::to_string(typeCounter[currentType]) + "</em>" :
? "<em>" + currentType + "#" + std::to_string(typeCounter[currentType]) + "</em>" "\"" + node_ptr->name() + "\\n<sub><em>( " + currentType + "#" + std::to_string(typeCounter[currentType]) + " )</em></sub>\"";
: "\"" + node_ptr->name() + "\\n<sub><em>( " + currentType + "#" + std::to_string(typeCounter[currentType]) + " )</em></sub>\""; namePtrTable[node_ptr] = (currentType + "_" + std::to_string(typeCounter[currentType]));
namePtrTable[node_ptr] =
(currentType + "_" + std::to_string(typeCounter[currentType]));
if (node_ptr == mRootNode) { if (node_ptr == mRootNode) {
std::fprintf(fp, "%s(%s):::rootCls\n", namePtrTable[node_ptr].c_str(), std::fprintf(fp, "%s(%s):::rootCls\n", namePtrTable[node_ptr].c_str(),
...@@ -100,13 +102,13 @@ void Aidge::GraphView::save(std::string path, bool verbose, bool showProducers) ...@@ -100,13 +102,13 @@ void Aidge::GraphView::save(std::string path, bool verbose, bool showProducers)
continue; continue;
} }
IOIndex_t outputIdx = 0; IOIndex_t outputIdx = 0;
for (auto childs : node_ptr->getOrderedChildren()) { for (const auto& childs : node_ptr->getOrderedChildren()) {
for (auto child : childs) { for (const auto& child : childs) {
if (child != nullptr) { if (child != nullptr) {
IOIndex_t inputIdx = 0; IOIndex_t inputIdx = 0;
for (auto parent : child->inputs()) { for (auto parent : child->inputs()) {
if (parent.first == node_ptr && parent.second == outputIdx) { if (parent.first == node_ptr && parent.second == outputIdx) {
if (mNodes.find(child) != mNodes.end()) { if (mNodes.find(child) != mNodes.cend()) {
std::fprintf(fp, "%s-->|%u&rarr;%u|%s\n", namePtrTable[node_ptr].c_str(), std::fprintf(fp, "%s-->|%u&rarr;%u|%s\n", namePtrTable[node_ptr].c_str(),
outputIdx, inputIdx, namePtrTable[child].c_str()); outputIdx, inputIdx, namePtrTable[child].c_str());
} }
...@@ -540,7 +542,7 @@ bool Aidge::GraphView::add(std::pair<NodePtr, std::set<NodePtr>> nodes, bool inc ...@@ -540,7 +542,7 @@ bool Aidge::GraphView::add(std::pair<NodePtr, std::set<NodePtr>> nodes, bool inc
bool Aidge::GraphView::add(std::shared_ptr<GraphView> graph) { bool Aidge::GraphView::add(std::shared_ptr<GraphView> graph) {
// set the rootNode to the other graphView rootNode if no rootNode yet // set the rootNode to the other graphView rootNode if no rootNode yet
mRootNode = mRootNode ? mRootNode : graph->getRootNode(); mRootNode = mRootNode ? mRootNode : graph->rootNode();
return add(graph->getNodes(), false); return add(graph->getNodes(), false);
} }
...@@ -741,10 +743,10 @@ bool Aidge::GraphView::replace(const std::set<Aidge::NodePtr>& oldNodes, const s ...@@ -741,10 +743,10 @@ bool Aidge::GraphView::replace(const std::set<Aidge::NodePtr>& oldNodes, const s
auto newG = std::make_shared<GraphView>("newG"); auto newG = std::make_shared<GraphView>("newG");
newG->add(newNodes, false); newG->add(newNodes, false);
const auto oldOI = oldG->getOrderedInputs(); const auto& oldOI = oldG->getOrderedInputs();
const auto oldOO = oldG->getOrderedOutputs(); const auto& oldOO = oldG->getOrderedOutputs();
const auto newOI = newG->getOrderedInputs(); const auto& newOI = newG->getOrderedInputs();
const auto newOO = newG->getOrderedOutputs(); const auto& newOO = newG->getOrderedOutputs();
std::vector<std::pair<std::shared_ptr<Node>, IOIndex_t>> inputParents = std::vector<std::pair<std::shared_ptr<Node>, IOIndex_t>>(oldOI.size()); std::vector<std::pair<std::shared_ptr<Node>, IOIndex_t>> inputParents = std::vector<std::pair<std::shared_ptr<Node>, IOIndex_t>>(oldOI.size());
std::vector<std::pair<std::shared_ptr<Node>, IOIndex_t>> outputChildren = std::vector<std::pair<std::shared_ptr<Node>, IOIndex_t>>(oldOO.size()); std::vector<std::pair<std::shared_ptr<Node>, IOIndex_t>> outputChildren = std::vector<std::pair<std::shared_ptr<Node>, IOIndex_t>>(oldOO.size());
......
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