[LayerNode] Add print function
authorJihoon Lee <jhoon.it.lee@samsung.com>
Mon, 24 May 2021 10:14:33 +0000 (19:14 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Thu, 27 May 2021 06:33:35 +0000 (15:33 +0900)
This patch adds simple print function to be used for debugging
Note that, input_layers are from `layer_internal` for now, but it's
private so it is commented out

**Self evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test: [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Jihoon Lee <jhoon.it.lee@samsung.com>
nntrainer/layers/layer_node.cpp
nntrainer/layers/layer_node.h

index 19553c1..1c820a1 100644 (file)
@@ -22,4 +22,23 @@ std::unique_ptr<LayerNode> createLayerNode(const std::string &type) {
   return std::make_unique<LayerNode>(createLayer(type));
 }
 
+std::ostream &operator<<(std::ostream &out, const LayerNode &l) {
+  out << "[" << l.getName() << '/' << l.getType() << "]\n";
+  auto print_vector = [&out](const std::vector<std::string> &layers,
+                             const std::string &title) {
+    out << title << "[" << layers.size() << "] ";
+    for (auto &layer : layers) {
+      out << layer << ' ';
+    }
+    out << '\n';
+  };
+
+  print_vector(l.input_layers, " input_layers");
+  print_vector(l.output_layers, "output_layers");
+  /// comment intended here,
+  // print_vector(l.getObject()->input_layers, " input_layers");
+  // print_vector(l.getObject()->output_layers, "output_layers");
+  return out;
+}
+
 }; // namespace nntrainer
index 3116b82..6b854a1 100644 (file)
@@ -92,6 +92,16 @@ public:
    * @note      This name might be changed once this layer is added to the model
    * to keep the name unique to the model
    */
+  const std::string getName() const noexcept { return layer->getName(); }
+
+  /**
+   * @brief     Get name of the layer
+   *
+   * @retval    name of the layer
+   * @note      This name is unique to this layer in a model
+   * @note      This name might be changed once this layer is added to the model
+   * to keep the name unique to the model
+   */
   std::string getName() noexcept { return layer->getName(); }
 
   /**
@@ -127,6 +137,11 @@ public:
   int event_key;
 #endif
 
+  /**
+   * @brief   Overriding output stream for layers and it's derived class
+   */
+  friend std::ostream &operator<<(std::ostream &out, const LayerNode &l);
+
 private:
   // TODO: make this unique_ptr once getObject API is removed
   std::shared_ptr<nntrainer::Layer>