[layer] Update layer.h setProperty interface
authorParichay Kapoor <pk.kapoor@samsung.com>
Fri, 30 Jul 2021 05:37:45 +0000 (14:37 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Thu, 5 Aug 2021 08:35:36 +0000 (17:35 +0900)
Update the interface for the layer.h setProperty.

Signed-off-by: Parichay Kapoor <pk.kapoor@samsung.com>
api/capi/src/nntrainer.cpp
api/ccapi/include/layer.h
jni/Android.mk
nntrainer/graph/graph_node.h
nntrainer/layers/layer_node.cpp
nntrainer/layers/layer_node.h

index 853ea1b..0ed3eb9 100644 (file)
@@ -711,7 +711,10 @@ int ml_train_layer_set_property(ml_train_layer_h layer, ...) {
     l = nnlayer->layer;
   }
 
-  returnable f = [&]() { return l->setProperty(arg_list); };
+  returnable f = [&]() {
+    l->setProperty(arg_list);
+    return ML_ERROR_NONE;
+  };
   status = nntrainer_exception_boundary(f);
 
   return status;
index cf797fc..8d21725 100644 (file)
@@ -129,7 +129,7 @@ public:
    * @details   This function accepts vector of properties in the format -
    *  { std::string property_name, void * property_val, ...}
    */
-  virtual int setProperty(std::vector<std::string> values) = 0;
+  virtual void setProperty(const std::vector<std::string> &values) = 0;
 
   /**
    * @brief     Get name of the layer
@@ -166,9 +166,7 @@ template <typename T,
 std::unique_ptr<Layer> createLayer(const std::vector<std::string> &props = {}) {
   std::unique_ptr<Layer> ptr = std::make_unique<T>();
 
-  if (ptr->setProperty(props) != ML_ERROR_NONE) {
-    throw std::invalid_argument("Set properties failed for layer");
-  }
+  ptr->setProperty(props);
   return ptr;
 }
 
index f8b234f..e9b26ee 100644 (file)
@@ -171,6 +171,7 @@ NNTRAINER_SRCS := $(NNTRAINER_ROOT)/nntrainer/models/neuralnet.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/layers/layer_impl.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/graph/network_graph.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/graph/graph_core.cpp \
+                  $(NNTRAINER_ROOT)/nntrainer/optimizers/optimizer_context.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/optimizers/optimizer_devel.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/optimizers/optimizer_impl.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/optimizers/adam.cpp \
index 94e98bc..687f695 100644 (file)
@@ -58,7 +58,7 @@ public:
    * @note name of each node in the graph must be unique, and caller must ensure
    * that
    */
-  virtual int setName(const std::string &name) = 0;
+  virtual void setName(const std::string &name) = 0;
 
   /**
    * @brief     Get the Type of the underlying object
index 4596cdf..ca85806 100644 (file)
@@ -113,9 +113,8 @@ std::unique_ptr<LayerNode>
 createLayerNode(std::unique_ptr<nntrainer::Layer> &&layer,
                 const std::vector<std::string> &properties) {
   auto lnode = std::make_unique<LayerNode>(std::move(layer));
-  if (lnode->setProperty(properties) != ML_ERROR_NONE)
-    throw std::invalid_argument("Error setting layer properties.");
 
+  lnode->setProperty(properties);
   return lnode;
 }
 
@@ -132,8 +131,7 @@ LayerNode::LayerNode(std::unique_ptr<nntrainer::Layer> &&l, size_t idx) :
   }
 }
 
-int LayerNode::setProperty(std::vector<std::string> properties) {
-  int status = ML_ERROR_NONE;
+void LayerNode::setProperty(const std::vector<std::string> &properties) {
   bool already_distributed =
     !std::get<props::Distribute>(*layer_node_props).empty() &&
     std::get<props::Distribute>(*layer_node_props).get();
@@ -160,14 +158,16 @@ int LayerNode::setProperty(std::vector<std::string> properties) {
 
     std::string key;
     std::string value;
+    std::stringstream ss;
 
-    status = getKeyValue(left_properties[i], key, value);
-    NN_RETURN_STATUS();
+    if (getKeyValue(left_properties[i], key, value) != ML_ERROR_NONE) {
+      throw std::invalid_argument("Error parsing the property: " +
+                                  left_properties[i]);
+    }
 
     if (value.empty()) {
-      ml_logd("value is empty for layer: %s, key: %s, value: %s",
-              getName().c_str(), key.c_str(), value.c_str());
-      return ML_ERROR_INVALID_PARAMETER;
+      ss << "value is empty: key: " << key << ", value: " << value;
+      throw std::invalid_argument(ss.str());
     }
 
     /// @note this calls derived setProperty if available
@@ -177,8 +177,6 @@ int LayerNode::setProperty(std::vector<std::string> properties) {
   }
 
   layer->setProperty(remainder);
-
-  return status;
 }
 
 bool LayerNode::setProperty(const std::string &key, const std::string &value) {
index b243e23..81e8376 100644 (file)
@@ -93,10 +93,8 @@ public:
    * @details   This function accepts vector of properties in the format -
    *  { std::string property_name=property_val, ...}
    *
-   *  @todo update to new signature: void setProperty(const
-   * std::vector<std::string> &values)
    */
-  int setProperty(std::vector<std::string> properties) override;
+  void setProperty(const std::vector<std::string> &properties) override;
 
   /**
    * @brief     Get name of the layer
@@ -129,12 +127,8 @@ public:
    * @brief     set name of layer
    *
    * @param[in] name Name of the layer
-   * @retval #ML_ERROR_NONE Successful.
-   * @retval #ML_ERROR_INVALID_PARAMETER invalid parameter.
-   *
-   * @todo update to new signature void setName(const std::string &name)
    */
-  int setName(const std::string &name) { return setProperty({"name=" + name}); }
+  void setName(const std::string &name) { setProperty({"name=" + name}); }
 
   /**
    * @brief     Get the input connections for this node