eliminate redundant code with get_split_blob_name method
authorJeff Donahue <jeff.donahue@gmail.com>
Sat, 15 Feb 2014 23:52:48 +0000 (15:52 -0800)
committerJeff Donahue <jeff.donahue@gmail.com>
Sat, 15 Feb 2014 23:52:48 +0000 (15:52 -0800)
include/caffe/util/insert_splits.hpp
src/caffe/util/insert_splits.cpp

index f8aae28..5bf49f1 100644 (file)
@@ -16,6 +16,9 @@ void insert_splits(const NetParameter& param, NetParameter* param_split);
 void configure_split_layer(const string& blob_name,
     const int split_count, LayerConnection* split_layer_connection);
 
+void get_split_blob_name(const string& blob_name, const int split_index,
+    string* split_blob_name);
+
 }  // namespace caffe
 
 #endif  // CAFFE_UTIL_INSERT_SPLITS_HPP_
index c963dc8..2638f8c 100644 (file)
@@ -54,12 +54,9 @@ void insert_splits(const NetParameter& param, NetParameter* param_split) {
       const string& blob_name = layer_connection->bottom(j);
       const int split_count = blob_name_to_bottom_count[blob_name];
       if (split_count > 1) {
-        const int suffix_max_length = 16;
-        char split_suffix[suffix_max_length];
-        const int suffix_length = snprintf(split_suffix, suffix_max_length,
-            "_split_%d", blob_name_to_bottom_split_idx[blob_name]++);
-        CHECK_LT(suffix_length, suffix_max_length);
-        const string& split_blob_name = blob_name + split_suffix;
+        string split_blob_name;
+        get_split_blob_name(blob_name,
+            blob_name_to_bottom_split_idx[blob_name]++, &split_blob_name);
         layer_connection->set_bottom(j, split_blob_name);
       }
     }
@@ -86,14 +83,20 @@ void configure_split_layer(const string& blob_name,
   split_layer_param->set_name(blob_name + "_split");
   split_layer_param->set_type("split");
   for (int k = 0; k < split_count; ++k) {
-    const int suffix_max_length = 16;
-    char split_suffix[suffix_max_length];
-    const int suffix_length = snprintf(split_suffix, suffix_max_length,
-        "_split_%d", k);
-    CHECK_LT(suffix_length, suffix_max_length);
-    const string& split_blob_name = blob_name + split_suffix;
+    string split_blob_name;
+    get_split_blob_name(blob_name, k, &split_blob_name);
     split_layer_connection->add_top(split_blob_name);
   }
 }
 
+void get_split_blob_name(const string& blob_name, const int split_index,
+    string* split_blob_name) {
+  const int suffix_max_length = 16;
+  char split_suffix[suffix_max_length];
+  const int suffix_length = snprintf(split_suffix, suffix_max_length,
+      "_split_%d", split_index);
+  CHECK_LT(suffix_length, suffix_max_length);
+  *split_blob_name = blob_name + split_suffix;
+}
+
 }  // namespace caffe