From c01e57f12b8a845c9b03e79322918af71235f8c1 Mon Sep 17 00:00:00 2001
From: Olivier BICHLER <olivier.bichler@cea.fr>
Date: Sun, 18 Feb 2024 18:58:19 +0100
Subject: [PATCH] Minor changes

---
 include/aidge/graph/GraphView.hpp |  5 +++++
 src/graph/GraphView.cpp           | 10 ++++++----
 src/operator/OperatorTensor.cpp   |  1 +
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/include/aidge/graph/GraphView.hpp b/include/aidge/graph/GraphView.hpp
index d3b022463..a8c61ac1d 100644
--- a/include/aidge/graph/GraphView.hpp
+++ b/include/aidge/graph/GraphView.hpp
@@ -98,6 +98,11 @@ public:
      */
     void save(std::string path, bool verbose = false, bool showProducers = true) const;
 
+    /**
+     * Check that a node is in the current GraphView.
+     * @param nodePtr Node to check
+     * @return bool True is nodePtr belongs to the GraphView.
+    */
     inline bool inView(NodePtr nodePtr) const {
         return mNodes.find(nodePtr) != mNodes.end();
     }
diff --git a/src/graph/GraphView.cpp b/src/graph/GraphView.cpp
index a5bc01878..57e3cc911 100644
--- a/src/graph/GraphView.cpp
+++ b/src/graph/GraphView.cpp
@@ -401,6 +401,8 @@ void Aidge::GraphView::setInputId(Aidge::IOIndex_t /*inID*/,
 }
 
 void Aidge::GraphView::add(std::shared_ptr<Node> node, bool includeLearnableParam) {
+  AIDGE_ASSERT(node != nullptr, "Trying to add non-existant node!");
+
   // first node to be added to the graph is the root node by default
   if (mRootNode == nullptr) {
     mRootNode = node;
@@ -442,7 +444,7 @@ std::pair<std::vector<Aidge::NodePtr>, size_t> Aidge::GraphView::getRankedNodes(
 
     for (auto childs : curNode->getOrderedChildren()) {
       for (auto child : childs) {
-        if (nodesToRank.find(child) != nodesToRank.end()) {
+        if (child != nullptr && nodesToRank.find(child) != nodesToRank.end()) {
           rankedNodes.push_back(child);
           nodesToRank.erase(child);
         }
@@ -450,7 +452,7 @@ std::pair<std::vector<Aidge::NodePtr>, size_t> Aidge::GraphView::getRankedNodes(
     }
 
     for (auto parent : curNode->getParents()) {
-      if (nodesToRank.find(parent) != nodesToRank.end()) {
+      if (parent != nullptr && nodesToRank.find(parent) != nodesToRank.end()) {
         rankedNodes.push_back(parent);
         nodesToRank.erase(parent);
       }
@@ -538,7 +540,7 @@ bool Aidge::GraphView::add(std::set<std::shared_ptr<Node>> otherNodes, bool incl
 
     for (auto childs : curNode->getOrderedChildren()) {
       for (auto child : childs) {
-        if (nodesToRank.find(child) != nodesToRank.end()) {
+        if (child != nullptr && nodesToRank.find(child) != nodesToRank.end()) {
           rankedNodes.push_back(child);
           nodesToRank.erase(child);
 
@@ -551,7 +553,7 @@ bool Aidge::GraphView::add(std::set<std::shared_ptr<Node>> otherNodes, bool incl
     }
 
     for (auto parent : curNode->getParents()) {
-      if (nodesToRank.find(parent) != nodesToRank.end()) {
+      if (parent != nullptr && nodesToRank.find(parent) != nodesToRank.end()) {
         rankedNodes.push_back(parent);
         nodesToRank.erase(parent);
 
diff --git a/src/operator/OperatorTensor.cpp b/src/operator/OperatorTensor.cpp
index 262f90788..d3593cc61 100644
--- a/src/operator/OperatorTensor.cpp
+++ b/src/operator/OperatorTensor.cpp
@@ -152,6 +152,7 @@ void Aidge::OperatorTensor::setDataType(const DataType& dataType) const {
     }
 
     for (IOIndex_t i = nbData(); i < nbInputs(); ++i) {
+        AIDGE_ASSERT(getInput(i) != nullptr, "Missing input#{} for operator {}", i, type());
         getInput(i)->setDataType(dataType);
     }
 }
\ No newline at end of file
-- 
GitLab