Format everyfile
authorJihoon Lee <jhoon.it.lee@samsung.com>
Wed, 8 Jul 2020 02:36:23 +0000 (11:36 +0900)
committerParichay Kapoor <pk.kapoor@samsung.com>
Wed, 8 Jul 2020 06:57:56 +0000 (12:27 +0530)
Now CI checks formatting. This patch formats every exisiting *.cpp *.h
in the project

See also: #271

**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>
22 files changed:
Applications/ReinforcementLearning/DeepQ/jni/main.cpp
Applications/Tizen_CAPI/capi_file.c
Applications/Tizen_CAPI/capi_func.c
Applications/Tizen_CAPI/main.c
Applications/Tizen_native/CustomShortcut/src/main.c
Applications/Tizen_native/CustomShortcut/src/view.c
api/capi/include/nntrainer.h
api/capi/src/nntrainer.cpp
nntrainer/include/conv2d_layer.h
nntrainer/include/input_layer.h
nntrainer/include/layer.h
nntrainer/include/optimizer.h
nntrainer/include/parse_util.h
nntrainer/include/tensor.h
nntrainer/src/conv2d_layer.cpp
nntrainer/src/layer.cpp
nntrainer/src/neuralnet.cpp
nntrainer/src/optimizer.cpp
nntrainer/src/parse_util.cpp
nntrainer/src/tensor.cpp
test/include/nntrainer_test_util.h
test/unittest/unittest_nntrainer_lazy_tensor.cpp

index 93c9f9926382593e46cbeae3b3e1f0d8688ac21e..44d28fbb7859f365990e44c2e76765e15e99ec1c 100644 (file)
@@ -325,7 +325,7 @@ int main(int argc, char **argv) {
          */
         nntrainer::Tensor test =
           mainNet.forwarding(nntrainer::Tensor({input}), status);
-        floatdata = test.getData();
+        float *data = test.getData();
         unsigned int len = test.getDim().getDataLen();
         std::vector<float> temp(data, data + len);
         action.push_back(argmax(temp));
@@ -424,7 +424,7 @@ int main(int argc, char **argv) {
          */
         nntrainer::Tensor NQ =
           targetNet.forwarding(nntrainer::Tensor(next_inbatch), status);
-        floatnqa = NQ.getData();
+        float *nqa = NQ.getData();
 
         /**
          * @brief     Update Q values & udpate mainNetwork
index 780b395127975683b2c6df0880da34da86799144..e721bf7e9f388e837ebb4016ce8b253bfed44bb5 100644 (file)
@@ -24,8 +24,8 @@
  *
  */
 
-#include <stdio.h>
 #include <nntrainer.h>
+#include <stdio.h>
 
 #define NN_RETURN_STATUS()         \
   do {                             \
@@ -34,9 +34,7 @@
     }                              \
   } while (0)
 
-int
-main (int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
 
   int status = ML_ERROR_NONE;
 
@@ -46,71 +44,72 @@ main (int argc, char *argv[])
   ml_nnopt_h optimizer;
 
   /* model create */
-  status = ml_nnmodel_construct (&model);
-  NN_RETURN_STATUS ();
+  status = ml_nnmodel_construct(&model);
+  NN_RETURN_STATUS();
   /* input layer create */
-  status = ml_nnlayer_create (&layers[0], ML_LAYER_TYPE_INPUT);
-  NN_RETURN_STATUS ();
+  status = ml_nnlayer_create(&layers[0], ML_LAYER_TYPE_INPUT);
+  NN_RETURN_STATUS();
 
   /* set property for input layer */
   status =
-      ml_nnlayer_set_property (layers[0], "input_shape= 32:1:1:62720",
-      "normalization=true", "bias_init_zero=true", NULL);
-  NN_RETURN_STATUS ();
+    ml_nnlayer_set_property(layers[0], "input_shape= 32:1:1:62720",
+                            "normalization=true", "bias_init_zero=true", NULL);
+  NN_RETURN_STATUS();
 
   /* add input layer into model */
-  status = ml_nnmodel_add_layer (model, layers[0]);
-  NN_RETURN_STATUS ();
+  status = ml_nnmodel_add_layer(model, layers[0]);
+  NN_RETURN_STATUS();
 
   /* create fully connected layer */
-  status = ml_nnlayer_create (&layers[1], ML_LAYER_TYPE_FC);
-  NN_RETURN_STATUS ();
+  status = ml_nnlayer_create(&layers[1], ML_LAYER_TYPE_FC);
+  NN_RETURN_STATUS();
 
   /* set property for fc layer */
-  status = ml_nnlayer_set_property (layers[1], "unit= 10", "activation=softmax",
-      "bias_init_zero=true", "weight_decay=l2norm",
-      "weight_decay_lambda=0.005", "weight_ini=xavier_uniform", NULL);
-  NN_RETURN_STATUS ();
+  status = ml_nnlayer_set_property(layers[1], "unit= 10", "activation=softmax",
+                                   "bias_init_zero=true", "weight_decay=l2norm",
+                                   "weight_decay_lambda=0.005",
+                                   "weight_ini=xavier_uniform", NULL);
+  NN_RETURN_STATUS();
 
   /* add fc layer into model */
-  status = ml_nnmodel_add_layer (model, layers[1]);
-  NN_RETURN_STATUS ();
+  status = ml_nnmodel_add_layer(model, layers[1]);
+  NN_RETURN_STATUS();
 
   /* create optimizer */
-  status = ml_nnoptimizer_create (&optimizer, "adam");
-  NN_RETURN_STATUS ();
+  status = ml_nnoptimizer_create(&optimizer, "adam");
+  NN_RETURN_STATUS();
 
   /* set property for optimizer */
-  status =
-      ml_nnoptimizer_set_property (optimizer, "learning_rate=0.0001",
-      "decay_rate=0.96", "decay_steps=1000", "beta1=0.9", "beta2=0.9999",
-      "epsilon=1e-7", NULL);
-  NN_RETURN_STATUS ();
+  status = ml_nnoptimizer_set_property(
+    optimizer, "learning_rate=0.0001", "decay_rate=0.96", "decay_steps=1000",
+    "beta1=0.9", "beta2=0.9999", "epsilon=1e-7", NULL);
+  NN_RETURN_STATUS();
 
   /* compile model with cross entropy loss function */
-  status = ml_nnmodel_compile (model, optimizer, "loss=cross", NULL);
-  NN_RETURN_STATUS ();
+  status = ml_nnmodel_compile(model, optimizer, "loss=cross", NULL);
+  NN_RETURN_STATUS();
 
-  /* train model with data files : epochs = 10 and store model file named "model.bin" */
-  status =
-      ml_nnmodel_train_with_file (model, "epochs=10", "batch_size=32",
-      "train_data=trainingSet.dat", "val_data=trainingSet.dat",
-      "label_data=label.dat", "buffer_size=100", "model_file=model.bin", NULL);
-  NN_RETURN_STATUS ();
+  /* train model with data files : epochs = 10 and store model file named
+   * "model.bin" */
+  status = ml_nnmodel_train_with_file(
+    model, "epochs=10", "batch_size=32", "train_data=trainingSet.dat",
+    "val_data=trainingSet.dat", "label_data=label.dat", "buffer_size=100",
+    "model_file=model.bin", NULL);
+  NN_RETURN_STATUS();
 
   /* delete layers */
-  status = ml_nnlayer_delete (layers[0]);
-  NN_RETURN_STATUS ();
+  status = ml_nnlayer_delete(layers[0]);
+  NN_RETURN_STATUS();
 
-  status = ml_nnlayer_delete (layers[1]);
-  NN_RETURN_STATUS ();
+  status = ml_nnlayer_delete(layers[1]);
+  NN_RETURN_STATUS();
 
   /* delete optimizer */
-  status = ml_nnoptimizer_delete (optimizer);
-  NN_RETURN_STATUS ();
+  status = ml_nnoptimizer_delete(optimizer);
+  NN_RETURN_STATUS();
 
   /* delete model */
-  status = ml_nnmodel_destruct (model);
-  NN_RETURN_STATUS ();
+  status = ml_nnmodel_destruct(model);
+  NN_RETURN_STATUS();
   return 0;
 }
index 8b6f708cafd27812656caf33a5e756dd181123dc..a76a9b023c3cc5a37750d00e60863e48dad19426 100644 (file)
@@ -31,15 +31,13 @@ static bool *valduplicate;
 static bool alloc_train = false;
 static bool alloc_val = false;
 
-bool gen_data_train (float *outVec, float *outLabel, int *status);
-bool gen_data_val (float *outVec, float *outLabel, int *status);
-bool file_exists (const char *filename);
+bool gen_data_train(float *outVec, float *outLabel, int *status);
+bool gen_data_val(float *outVec, float *outLabel, int *status);
+bool file_exists(const char *filename);
 
-bool
-file_exists (const char *filename)
-{
+bool file_exists(const char *filename) {
   struct stat buffer;
-  return (stat (filename, &buffer) == 0);
+  return (stat(filename, &buffer) == 0);
 }
 
 #define NN_RETURN_STATUS()         \
@@ -55,14 +53,12 @@ file_exists (const char *filename)
  * @param[in] max : maximum value
  * @retval    min < random value < max
  */
-static int
-range_random (int min, int max)
-{
+static int range_random(int min, int max) {
   int n = max - min + 1;
   int remainder = RAND_MAX % n;
   int x;
   do {
-    x = rand ();
+    x = rand();
   } while (x >= RAND_MAX - remainder);
   return min + x % n;
 }
@@ -75,10 +71,8 @@ range_random (int min, int max)
  * @param[in] id th data to get
  * @retval true/false false : end of data
  */
-static bool
-get_data (const char *file_name, float *outVec, float *outLabel,
-    int id, int file_length)
-{
+static bool get_data(const char *file_name, float *outVec, float *outLabel,
+                     int id, int file_length) {
   uint64_t position;
   FILE *F;
   unsigned int i;
@@ -87,34 +81,34 @@ get_data (const char *file_name, float *outVec, float *outLabel,
   if (id < 0)
     return false;
 
-  position = (feature_size + num_class) * id * sizeof (float);
+  position = (feature_size + num_class) * id * sizeof(float);
   if (position > file_length || position > ULLONG_MAX) {
     return false;
   }
 
-  F = fopen (file_name, "rb");
+  F = fopen(file_name, "rb");
   if (F == NULL) {
-    printf ("Cannot open %s\n", file_name);
+    printf("Cannot open %s\n", file_name);
     return false;
   }
-  fseek (F, position, SEEK_SET);
+  fseek(F, position, SEEK_SET);
 
   for (i = 0; i < feature_size; i++) {
     float f;
-    ret = fread ((void *) (&f), sizeof (float), 1, F);
+    ret = fread((void *)(&f), sizeof(float), 1, F);
     if (!ret)
       return false;
     outVec[i] = f;
   }
   for (i = 0; i < num_class; i++) {
     float f;
-    ret = fread ((void *) (&f), sizeof (float), 1, F);
+    ret = fread((void *)(&f), sizeof(float), 1, F);
     if (!ret)
       return false;
     outLabel[i] = f;
   }
 
-  fclose (F);
+  fclose(F);
 
   return true;
 }
@@ -126,9 +120,7 @@ get_data (const char *file_name, float *outVec, float *outLabel,
  * @param[out] status for error handling
  * @retval true/false
  */
-bool
-gen_data_train (float *outVec, float *outLabel, int *status)
-{
+bool gen_data_train(float *outVec, float *outLabel, int *status) {
   int memI[mini_batch];
   long file_size;
   unsigned int count = 0;
@@ -138,21 +130,20 @@ gen_data_train (float *outVec, float *outLabel, int *status)
 
   const char *file_name = "trainingSet.dat";
 
-  if (!file_exists (file_name)) {
-    printf ("%s does not exists\n", file_name);
+  if (!file_exists(file_name)) {
+    printf("%s does not exists\n", file_name);
     return false;
   }
 
-  file = fopen (file_name, "r");
-  fseek (file, 0, SEEK_END);
-  file_size = ftell (file);
-  fclose (file);
+  file = fopen(file_name, "r");
+  fseek(file, 0, SEEK_END);
+  file_size = ftell(file);
+  fclose(file);
   data_size =
-      (unsigned int) (file_size / ((num_class +
-              feature_size) * sizeof (float)));
+    (unsigned int)(file_size / ((num_class + feature_size) * sizeof(float)));
 
   if (!alloc_train) {
-    duplicate = (bool *) malloc (sizeof (bool) * data_size);
+    duplicate = (bool *)malloc(sizeof(bool) * data_size);
     for (i = 0; i < data_size; ++i) {
       duplicate[i] = false;
     }
@@ -166,17 +157,17 @@ gen_data_train (float *outVec, float *outLabel, int *status)
 
   if (count < mini_batch) {
     if (duplicate == NULL) {
-      printf ("Error: memory allocation.\n");
+      printf("Error: memory allocation.\n");
       return false;
     }
-    free (duplicate);
+    free(duplicate);
     alloc_train = false;
     return false;
   }
 
   count = 0;
   while (count < mini_batch) {
-    int nomI = range_random (0, data_size - 1);
+    int nomI = range_random(0, data_size - 1);
     if (!duplicate[nomI]) {
       memI[count] = nomI;
       duplicate[nomI] = true;
@@ -188,7 +179,7 @@ gen_data_train (float *outVec, float *outLabel, int *status)
     float o[feature_size];
     float l[num_class];
 
-    get_data (file_name, o, l, memI[i], file_size);
+    get_data(file_name, o, l, memI[i], file_size);
 
     for (j = 0; j < feature_size; ++j)
       outVec[i * feature_size + j] = o[j];
@@ -206,9 +197,7 @@ gen_data_train (float *outVec, float *outLabel, int *status)
  * @param[out] status for error handling
  * @retval true/false false : end of data
  */
-bool
-gen_data_val (float *outVec, float *outLabel, int *status)
-{
+bool gen_data_val(float *outVec, float *outLabel, int *status) {
 
   int memI[mini_batch];
   unsigned int i, j;
@@ -218,16 +207,15 @@ gen_data_val (float *outVec, float *outLabel, int *status)
 
   const char *file_name = "trainingSet.dat";
 
-  FILE *file = fopen (file_name, "r");
-  fseek (file, 0, SEEK_END);
-  file_size = ftell (file);
-  fclose (file);
+  FILE *file = fopen(file_name, "r");
+  fseek(file, 0, SEEK_END);
+  file_size = ftell(file);
+  fclose(file);
   data_size =
-      (unsigned int) (file_size / ((num_class +
-              feature_size) * sizeof (float)));
+    (unsigned int)(file_size / ((num_class + feature_size) * sizeof(float)));
 
   if (!alloc_val) {
-    valduplicate = (bool *) malloc (sizeof (bool) * data_size);
+    valduplicate = (bool *)malloc(sizeof(bool) * data_size);
     for (i = 0; i < data_size; ++i) {
       valduplicate[i] = false;
     }
@@ -240,14 +228,14 @@ gen_data_val (float *outVec, float *outLabel, int *status)
   }
 
   if (count < mini_batch) {
-    free (valduplicate);
+    free(valduplicate);
     alloc_val = false;
     return false;
   }
 
   count = 0;
   while (count < mini_batch) {
-    int nomI = range_random (0, data_size - 1);
+    int nomI = range_random(0, data_size - 1);
     if (!valduplicate[nomI]) {
       memI[count] = nomI;
       valduplicate[nomI] = true;
@@ -259,7 +247,7 @@ gen_data_val (float *outVec, float *outLabel, int *status)
     float o[feature_size];
     float l[num_class];
 
-    get_data (file_name, o, l, memI[i], file_size);
+    get_data(file_name, o, l, memI[i], file_size);
 
     for (j = 0; j < feature_size; ++j)
       outVec[i * feature_size + j] = o[j];
@@ -270,9 +258,7 @@ gen_data_val (float *outVec, float *outLabel, int *status)
   return true;
 }
 
-int
-main (int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
 
   int status = ML_ERROR_NONE;
 
@@ -282,72 +268,71 @@ main (int argc, char *argv[])
   ml_nnopt_h optimizer;
 
   /* model create */
-  status = ml_nnmodel_construct (&model);
-  NN_RETURN_STATUS ();
+  status = ml_nnmodel_construct(&model);
+  NN_RETURN_STATUS();
   /* input layer create */
-  status = ml_nnlayer_create (&layers[0], ML_LAYER_TYPE_INPUT);
-  NN_RETURN_STATUS ();
+  status = ml_nnlayer_create(&layers[0], ML_LAYER_TYPE_INPUT);
+  NN_RETURN_STATUS();
 
   /* set property for input layer */
   status =
-      ml_nnlayer_set_property (layers[0], "input_shape= 32:1:1:62720",
-      "normalization=true", "bias_init_zero=true", NULL);
-  NN_RETURN_STATUS ();
+    ml_nnlayer_set_property(layers[0], "input_shape= 32:1:1:62720",
+                            "normalization=true", "bias_init_zero=true", NULL);
+  NN_RETURN_STATUS();
 
   /* add input layer into model */
-  status = ml_nnmodel_add_layer (model, layers[0]);
-  NN_RETURN_STATUS ();
+  status = ml_nnmodel_add_layer(model, layers[0]);
+  NN_RETURN_STATUS();
 
   /* create fully connected layer */
-  status = ml_nnlayer_create (&layers[1], ML_LAYER_TYPE_FC);
-  NN_RETURN_STATUS ();
+  status = ml_nnlayer_create(&layers[1], ML_LAYER_TYPE_FC);
+  NN_RETURN_STATUS();
 
   /* set property for fc layer */
-  status = ml_nnlayer_set_property (layers[1], "unit= 10", "activation=softmax",
-      "bias_init_zero=true", "weight_decay=l2norm",
-      "weight_decay_lambda=0.005", "weight_ini=xavier_uniform", NULL);
-  NN_RETURN_STATUS ();
+  status = ml_nnlayer_set_property(layers[1], "unit= 10", "activation=softmax",
+                                   "bias_init_zero=true", "weight_decay=l2norm",
+                                   "weight_decay_lambda=0.005",
+                                   "weight_ini=xavier_uniform", NULL);
+  NN_RETURN_STATUS();
 
   /* add fc layer into model */
-  status = ml_nnmodel_add_layer (model, layers[1]);
-  NN_RETURN_STATUS ();
+  status = ml_nnmodel_add_layer(model, layers[1]);
+  NN_RETURN_STATUS();
 
   /* create optimizer */
-  status = ml_nnoptimizer_create (&optimizer, "adam");
-  NN_RETURN_STATUS ();
+  status = ml_nnoptimizer_create(&optimizer, "adam");
+  NN_RETURN_STATUS();
 
   /* set property for optimizer */
-  status =
-      ml_nnoptimizer_set_property (optimizer, "learning_rate=0.0001",
-      "decay_rate=0.96", "decay_steps=1000", "beta1=0.9", "beta2=0.9999",
-      "epsilon=1e-7", NULL);
-  NN_RETURN_STATUS ();
+  status = ml_nnoptimizer_set_property(
+    optimizer, "learning_rate=0.0001", "decay_rate=0.96", "decay_steps=1000",
+    "beta1=0.9", "beta2=0.9999", "epsilon=1e-7", NULL);
+  NN_RETURN_STATUS();
 
   /* compile model with cross entropy loss function */
-  status = ml_nnmodel_compile (model, optimizer, "loss=cross", NULL);
-  NN_RETURN_STATUS ();
+  status = ml_nnmodel_compile(model, optimizer, "loss=cross", NULL);
+  NN_RETURN_STATUS();
 
   /* train model with data files : epochs = 10 and store model file named
    * "model.bin" */
-  status =
-      ml_nnmodel_train_with_generator (model, gen_data_train, gen_data_val,
-      NULL, "epochs=10", "batch_size=32", "model_file=model.bin",
-      "buffer_size = 32", NULL);
-  NN_RETURN_STATUS ();
+  status = ml_nnmodel_train_with_generator(
+    model, gen_data_train, gen_data_val, NULL, "epochs=10", "batch_size=32",
+    "model_file=model.bin", "buffer_size = 32", NULL);
+  NN_RETURN_STATUS();
 
   /* delete layers */
-  status = ml_nnlayer_delete (layers[0]);
-  NN_RETURN_STATUS ();
+  status = ml_nnlayer_delete(layers[0]);
+  NN_RETURN_STATUS();
 
-  status = ml_nnlayer_delete (layers[1]);
-  NN_RETURN_STATUS ();
+  status = ml_nnlayer_delete(layers[1]);
+  NN_RETURN_STATUS();
 
   /* delete optimizer */
-  status = ml_nnoptimizer_delete (optimizer);
-  NN_RETURN_STATUS ();
+  status = ml_nnoptimizer_delete(optimizer);
+  NN_RETURN_STATUS();
 
   /* delete model */
-  status = ml_nnmodel_destruct (model);
-  NN_RETURN_STATUS ();
+  status = ml_nnmodel_destruct(model);
+  NN_RETURN_STATUS();
   return 0;
 }
index 4983195790d06057eb6303cfe7adcc3ae47096be..cb35d6b5ad6a0772bc77235dc9d0782ba31ee3fc 100644 (file)
 
 #include <nntrainer.h>
 
-int
-main (int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
   int status = ML_ERROR_NONE;
   ml_nnmodel_h handle = NULL;
   const char *config_file = "./Tizen_CAPI_config.ini";
-  status = ml_nnmodel_construct (&handle);
+  status = ml_nnmodel_construct(&handle);
   if (status != ML_ERROR_NONE)
     return status;
-  status = ml_nnmodel_compile_with_conf (config_file, handle);
+  status = ml_nnmodel_compile_with_conf(config_file, handle);
   if (status != ML_ERROR_NONE)
     return status;
-  status = ml_nnmodel_train_with_file (handle);
+  status = ml_nnmodel_train_with_file(handle);
   if (status != ML_ERROR_NONE)
     return status;
-  status = ml_nnmodel_destruct (handle);
+  status = ml_nnmodel_destruct(handle);
   if (status != ML_ERROR_NONE)
     return status;
   return status;
index 07bfeb47055af4d8c1c64b0c64109fa9647a2944..1580fd661431f34d57560da647326a98b1b92728 100644 (file)
@@ -26,7 +26,7 @@ static bool app_create(void *data) {
 
   snprintf(ad->edj_path, sizeof(ad->edj_path), "%s%s", res_path, EDJ_PATH);
   free(res_path);
-  
+
   view_init(ad);
 
   if (view_routes_to(ad, "home", &ad->home))
@@ -47,7 +47,8 @@ static void app_resume(void *data) {
   /* Take necessary actions when application becomes visible. */
 }
 
-static void app_terminate(void *data) { /* Release all resources. */ }
+static void app_terminate(void *data) { /* Release all resources. */
+}
 
 static void ui_app_lang_changed(app_event_info_h event_info, void *user_data) {
   /*APP_EVENT_LANGUAGE_CHANGED*/
index 6a1733a21c4c378e8612065b4e288d330078e007..1d3634011469b400786e072d5725add9e3377c3c 100644 (file)
@@ -125,11 +125,11 @@ int view_routes_to(appdata_s *ad, const char *group_name,
                                  ad);
 
   nf_it = elm_naviframe_item_push(ad->naviframe, NULL, NULL, NULL, ad->layout,
-                              "empty");
+                                  "empty");
   if (nf_it == NULL)
     return APP_ERROR_INVALID_PARAMETER;
 
-  if(data != NULL)
+  if (data != NULL)
     *data = nf_it;
 
   return APP_ERROR_NONE;
index 674488973bbdbda426efc0ebe49f0bb7591c0e0c..4211f0649b5e20dd19bb7a50721c4d284b971e61 100644 (file)
@@ -93,7 +93,8 @@ int ml_nnmodel_compile_with_conf(const char *model_conf, ml_nnmodel_h model);
  * @details Use this function to initialize neural network model
  * @since_tizen 6.x
  * @param[in] model The NNTrainer model handler from the given description.
- * @param[in] optimizer The NNTrainer optimizer handler from the given description.
+ * @param[in] optimizer The NNTrainer optimizer handler from the given
+ * description.
  * @param[in] ... hyper parmeter for compile model
  * @return @c 0 on success. Otherwise a negative error value.
  * @retval #ML_ERROR_NONE Successful.
@@ -224,9 +225,9 @@ int ml_nnoptimizer_delete(ml_nnopt_h opt);
  * @retval #ML_ERROR_NONE Successful.
  * @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
  */
-int ml_nnoptimizer_set_property(ml_nnopt_h opt,...);
+int ml_nnoptimizer_set_property(ml_nnopt_h opt, ...);
 
- /**
+/**
  * @}
  */
 #ifdef __cplusplus
index 1377af8c5dbf7f553b534f3cd8ca4e1daa85d974..009a0a1c6069a91773c03ebd30e9716b37db76ea 100644 (file)
@@ -377,9 +377,7 @@ int ml_nnoptimizer_set_property(ml_nnopt_h opt, ...) {
   std::shared_ptr<nntrainer::Optimizer> Opt;
   Opt = nnopt->optimizer;
 
-  returnable f = [&]() {
-    return Opt->setProperty(arg_list);
-  };
+  returnable f = [&]() { return Opt->setProperty(arg_list); };
 
   status = nntrainer_exception_boundary(f);
 
index 4adc35cded18c46dff47b68691a5d245803d9c06..0216bab69c29b4dfb37f09dccfa814b404f48675 100644 (file)
@@ -42,7 +42,9 @@ public:
     stride{1, 1},
     padding{0, 0},
     normalization(false),
-    standardization(false) { setType(LAYER_CONV2D); };
+    standardization(false) {
+    setType(LAYER_CONV2D);
+  };
 
   /**
    * @brief     Destructor of Conv 2D Layer
index a94bb9fe93e15884ee3807c71540abcd46786449..f9c588ca904e313667cd2cfbaef21e2b49a2db97 100644 (file)
@@ -42,9 +42,9 @@ public:
   /**
    * @brief     Constructor of InputLayer
    */
-  InputLayer() :
-    normalization(false),
-    standardization(false) { setType(LAYER_IN); };
+  InputLayer() : normalization(false), standardization(false) {
+    setType(LAYER_IN);
+  };
 
   /**
    * @brief     Destructor of InputLayer
index 4089302c0935a58800f1de28b9d58f859d56dfbd..bf5819dd030f4112b0be126841d1a22f6b2b13a8 100644 (file)
@@ -117,18 +117,18 @@ typedef enum {
  */
 class Layer {
 public:
-  Layer()
-    last_layer(false),
-      bias_init_zero(false),
-      type(LAYER_UNKNOWN),
-      loss(0.0),
-      cost(COST_UNKNOWN),
-      activation_type(ACT_NONE),
-      bn_follow(false),
-      weight_decay(),
-      weight_ini_type(WEIGHT_XAVIER_UNIFORM),
-      flatten(false),
-      trainable(true) {}
+  Layer() :
+    last_layer(false),
+    bias_init_zero(false),
+    type(LAYER_UNKNOWN),
+    loss(0.0),
+    cost(COST_UNKNOWN),
+    activation_type(ACT_NONE),
+    bn_follow(false),
+    weight_decay(),
+    weight_ini_type(WEIGHT_XAVIER_UNIFORM),
+    flatten(false),
+    trainable(true) {}
 
   /**
    * @brief     Destructor of Layer Class
@@ -308,13 +308,17 @@ public:
    * @brief     get gradients
    * @retval    shared ptr of vector of all tensors
    */
-  std::shared_ptr<std::vector<Tensor>> getGradients() { return getObjFromRef(gradients); }
+  std::shared_ptr<std::vector<Tensor>> getGradients() {
+    return getObjFromRef(gradients);
+  }
 
   /**
    * @brief     get weights
    * @retval    shared ptr of vector of all tensors
    */
-  std::shared_ptr<std::vector<Tensor>> getWeights() { return getObjFromRef(weights); }
+  std::shared_ptr<std::vector<Tensor>> getWeights() {
+    return getObjFromRef(weights);
+  }
 
   /**
    * @brief     get if the output of this layer must be flatten
@@ -364,7 +368,6 @@ public:
   };
 
 protected:
-
   /**
    * @brief     check if current layer's weight decay type is l2norm
    * @return    bool is weightdecay type is L2 Norm
@@ -464,8 +467,8 @@ private:
   /**
    * @brief     Convert vector of reference to vector of objects
    */
-  std::shared_ptr<std::vector<Tensor>> getObjFromRef(
-      std::vector<std::reference_wrapper<Tensor>> &elements);
+  std::shared_ptr<std::vector<Tensor>>
+  getObjFromRef(std::vector<std::reference_wrapper<Tensor>> &elements);
 };
 } // namespace nntrainer
 
index 552d8164a7caa26bbb30f7e7c5503c574676cce5..5f1f6ae7dab64c0e36504f44e299dcd2c1f18c42 100644 (file)
@@ -74,10 +74,10 @@ typedef struct _OptParam {
     decay_rate(1.0),
     decay_steps(1.0),
     continue_train(false) {
-      if (type == OptType::sgd) {
-        learning_rate = 0.01;
-      }
+    if (type == OptType::sgd) {
+      learning_rate = 0.01;
     }
+  }
 } OptParam;
 
 class Optimizer {
@@ -175,7 +175,8 @@ public:
    * @param[in] iteration nth epoch number
    */
   void apply_gradients(std::vector<std::reference_wrapper<Tensor>> &weights,
-      std::vector<std::reference_wrapper<Tensor>> &gradients, int iteration);
+                       std::vector<std::reference_wrapper<Tensor>> &gradients,
+                       int iteration);
 
   /**
    * @brief     Property Enumeration
index b132e9ae649c3af6e0d5900e6499109c75bb6a40..5e7a42f770d7e8eb49c51d2a40a81d47ed8af165 100644 (file)
@@ -144,7 +144,7 @@ int getKeyValue(std::string input_str, std::string &key, std::string &value);
  * @param[in] delimiter delimiter for the string
  * @retval    output string
  */
-const char* getValues(std::vector<int> values, const char* delimiter = ",");
+const char *getValues(std::vector<int> values, const char *delimiter = ",");
 
 int getValues(int n_str, std::string str, int *value);
 
index aef0f0d84b800c053f5b768c2a8686f834fefe38..36146593412862228ffea8162ab4ea070ea7e071 100644 (file)
@@ -52,8 +52,7 @@ public:
     dim(d),
     strides{{1, 2, 3}},
     is_contiguous(true),
-    data(new float[d.getDataLen()], std::default_delete<float[]>())
-    {
+    data(new float[d.getDataLen()], std::default_delete<float[]>()) {
     // todo: initialize appropriate strides
     if (buf == nullptr) {
       setZero();
index 2fd105cb939d377eede1d2aba8b3fd040079aba7..5d40a945c0ea7686b8088f10e7a80e98cf8169ab 100644 (file)
@@ -209,10 +209,10 @@ Tensor Conv2DLayer::backwarding(Tensor derivative, int iteration) {
     //  Update K / bias
     for (unsigned int i = 0; i < filter_size; ++i) {
       Tensor djdw = delK[i]
-        .chain()
-        .applyIf(this->isWeightDecayL2Norm(), _LIFT(add_i),
-            filters[i], weight_decay.lambda)
-        .run();
+                      .chain()
+                      .applyIf(this->isWeightDecayL2Norm(), _LIFT(add_i),
+                               filters[i], weight_decay.lambda)
+                      .run();
 
       gradients.push_back(djdw);
       gradients.push_back(delBias[i]);
index b6f341f53fd4b934fd979b6b06f8ec388efa12d7..824c57e5d7bb2a150c0c6e584645b5207e63ae67 100644 (file)
@@ -110,7 +110,8 @@ int Layer::setCost(CostType c) {
   return status;
 }
 
-std::shared_ptr<std::vector<Tensor>> Layer::getObjFromRef(std::vector<std::reference_wrapper<Tensor>> &elements) {
+std::shared_ptr<std::vector<Tensor>>
+Layer::getObjFromRef(std::vector<std::reference_wrapper<Tensor>> &elements) {
   std::vector<Tensor> ele;
   for (auto iter = elements.begin(); iter != elements.end(); ++iter)
     ele.push_back(*iter);
index afbc30f85fb52ae1208adf8fa1e9f446ef531352..bef88dab8e48e9aa2eaf00005c1b6a0ecb5a8ab1 100644 (file)
@@ -186,12 +186,12 @@ int NeuralNetwork::init() {
   NN_INI_RETURN_STATUS();
 
   OptParam popt(opt.getType());
-  popt.learning_rate = iniparser_getdouble(ini, "Network:Learning_rate",
-      popt.learning_rate);
-  popt.decay_steps = iniparser_getint(ini, "Network:Decay_steps",
-      popt.decay_steps);
-  popt.decay_rate = iniparser_getdouble(ini, "Network:Decay_rate",
-      popt.decay_rate);
+  popt.learning_rate =
+    iniparser_getdouble(ini, "Network:Learning_rate", popt.learning_rate);
+  popt.decay_steps =
+    iniparser_getint(ini, "Network:Decay_steps", popt.decay_steps);
+  popt.decay_rate =
+    iniparser_getdouble(ini, "Network:Decay_rate", popt.decay_rate);
   popt.beta1 = iniparser_getdouble(ini, "Network:beta1", popt.beta1);
   popt.beta2 = iniparser_getdouble(ini, "Network:beta2", popt.beta2);
   popt.epsilon = iniparser_getdouble(ini, "Network:epsilon", popt.epsilon);
@@ -281,7 +281,7 @@ int NeuralNetwork::init() {
         std::make_shared<Conv2DLayer>();
 
       std::string input_shape_str = iniparser_getstring(
-          ini, (layer_name + ":Input_Shape").c_str(), unknown);
+        ini, (layer_name + ":Input_Shape").c_str(), unknown);
 
       if (input_shape_str.compare("Unknown") != 0) {
         TensorDim d;
@@ -306,41 +306,42 @@ int NeuralNetwork::init() {
         NN_INI_RETURN_STATUS();
       }
 
-      status =
-        getValues(CONV2D_DIM,
-            iniparser_getstring(
-              ini, (layer_name + ":kernel_size").c_str(), unknown),
-            (int *)size);
+      status = getValues(CONV2D_DIM,
+                         iniparser_getstring(
+                           ini, (layer_name + ":kernel_size").c_str(), unknown),
+                         (int *)size);
       NN_INI_RETURN_STATUS();
       status = conv2d_layer->setSize(size, Layer::PropertyType::kernel_size);
       NN_INI_RETURN_STATUS();
 
-      status = getValues(
-          CONV2D_DIM,
-          iniparser_getstring(ini, (layer_name + ":stride").c_str(), getValues({1,1})),
-          (int *)size);
+      status =
+        getValues(CONV2D_DIM,
+                  iniparser_getstring(ini, (layer_name + ":stride").c_str(),
+                                      getValues({1, 1})),
+                  (int *)size);
       NN_INI_RETURN_STATUS();
       status = conv2d_layer->setSize(size, Layer::PropertyType::stride);
       NN_INI_RETURN_STATUS();
 
-      status = getValues(CONV2D_DIM,
-          iniparser_getstring(
-            ini, (layer_name + ":padding").c_str(), getValues({0,0})),
-          (int *)size);
-      
+      status =
+        getValues(CONV2D_DIM,
+                  iniparser_getstring(ini, (layer_name + ":padding").c_str(),
+                                      getValues({0, 0})),
+                  (int *)size);
+
       NN_INI_RETURN_STATUS();
       status = conv2d_layer->setSize(size, Layer::PropertyType::padding);
       NN_INI_RETURN_STATUS();
 
       status = conv2d_layer->setFilter(
-          iniparser_getint(ini, (layer_name + ":filter").c_str(), 0));
+        iniparser_getint(ini, (layer_name + ":filter").c_str(), 0));
       NN_INI_RETURN_STATUS();
 
       conv2d_layer->setBiasZero(b_zero);
       conv2d_layer->setWeightInit((WeightIniType)parseType(
-            iniparser_getstring(ini, (layer_name + ":WeightIni").c_str(),
-              "xavier_uniform"),
-            TOKEN_WEIGHTINI));
+        iniparser_getstring(ini, (layer_name + ":WeightIni").c_str(),
+                            "xavier_uniform"),
+        TOKEN_WEIGHTINI));
 
       status = parseWeightDecay(ini, layer_name, weight_decay);
       NN_INI_RETURN_STATUS();
index 62d527e3e5e863a1b8745cf82137c6c7e12ab04f..60b14a6813e48def53f1f4c579c36e8a369c9de3 100644 (file)
@@ -112,7 +112,7 @@ void Optimizer::apply_gradients(
   int idx = 0;
   std::vector<std::reference_wrapper<Tensor>>::iterator w_iter, g_iter;
   for (w_iter = weights.begin(), g_iter = gradients.begin();
-      w_iter != weights.end(); ++w_iter, ++g_iter) {
+       w_iter != weights.end(); ++w_iter, ++g_iter) {
     Tensor &x = *w_iter;
     Tensor x_grad = *g_iter;
 
index 020a4fa8f978018cf4cb025c565e25dd4a269d84..233cfeb569936cd0d223239a872f8a9a0eb27c8f 100644 (file)
@@ -186,7 +186,8 @@ unsigned int parseType(std::string ll, InputType t) {
       }
     }
     ml_logw("Input activation %s cannot be identified. "
-        "Moved to NO activation layer by default.", ll.c_str());
+            "Moved to NO activation layer by default.",
+            ll.c_str());
     ret = (unsigned int)ActiType::ACT_NONE;
     break;
   case TOKEN_LAYER:
@@ -273,10 +274,10 @@ unsigned int parseLayerProperty(std::string property) {
    * BatchNormalizationLayer has 0, 1, 5, 6, 7 properties.
    */
   std::array<std::string, 18> property_string = {
-    "input_shape", "bias_init_zero",  "normalization", "standardization",
-    "activation",  "epsilon",    "weight_decay",  "weight_decay_lambda",
-    "unit",        "weight_ini", "filter",        "kernel_size",
-    "stride",      "padding",    "pooling_size",  "pooling",
+    "input_shape", "bias_init_zero", "normalization", "standardization",
+    "activation",  "epsilon",        "weight_decay",  "weight_decay_lambda",
+    "unit",        "weight_ini",     "filter",        "kernel_size",
+    "stride",      "padding",        "pooling_size",  "pooling",
     "flatten",     "unknown"};
 
   for (i = 0; i < property_string.size(); i++) {
@@ -426,14 +427,14 @@ int getValues(int n_str, std::string str, int *value) {
   return status;
 }
 
-const char* getValues(std::vector<int> values, const char* delimiter) {
+const char *getValues(std::vector<int> values, const char *delimiter) {
   std::stringstream vec_str;
 
   if (values.empty())
     return "unknown";
 
   std::copy(values.begin(), values.end() - 1,
-      std::ostream_iterator<int>(vec_str, delimiter));
+            std::ostream_iterator<int>(vec_str, delimiter));
   vec_str << values.back();
 
   return std::move(vec_str.str().c_str());
index c71ee334ff4c7899ec6f4ce0f78dae7f9af52c91..dcd31d5e2cd9d73fb1351b1fc3f05686f0edc61c 100644 (file)
@@ -63,7 +63,7 @@ static auto rng = [] {
 
 Tensor &Tensor::operator=(const Tensor &rhs) {
   using std::swap;
-  
+
   Tensor tmp(rhs);
   swap(*this, tmp);
   return *this;
@@ -120,8 +120,8 @@ void Tensor::setValue(unsigned int batch, unsigned int c, unsigned int h,
     throw std::runtime_error("cannot set value of non-contiguous tensor");
   }
 
-  getData()[batch * dim.getFeatureLen() +
-            c * dim.height() * dim.width() + h * dim.width() + w] = value;
+  getData()[batch * dim.getFeatureLen() + c * dim.height() * dim.width() +
+            h * dim.width() + w] = value;
 }
 
 template <typename T> void Tensor::setDist(T dist) {
@@ -155,7 +155,7 @@ Tensor::Tensor(
   dim.height(d[0][0].size());
   dim.width(d[0][0][0].size());
   data = std::shared_ptr<float>(new float[dim.getDataLen()],
-                                 std::default_delete<float[]>());
+                                std::default_delete<float[]>());
   is_contiguous = true;
 
   for (unsigned int i = 0; i < dim.batch(); ++i)
index 5e170ddc45e613dce4dd5e490c7b4525bd5d66cc..ed5888db3ca32e1d3376bf6a2562ba669f1789c2 100644 (file)
@@ -26,9 +26,9 @@
 #ifdef __cplusplus
 
 #include "nntrainer_log.h"
-#include <tensor.h>
 #include <fstream>
 #include <gtest/gtest.h>
+#include <tensor.h>
 
 #define tolerance 10e-5
 
@@ -215,7 +215,7 @@ const std::string config_str2 = "[Network]"
  * @brief return a tensor filled with contant value with dimension
  */
 nntrainer::Tensor constant(float value, unsigned int batch, unsigned channel,
-                           unsigned height, unsigned width) ;
+                           unsigned height, unsigned width);
 
 /**
  * @brief replace string and save in file
index 88a68bc0cb82e13bcc7a67f62b119b86dd03216a..2f6b7fa1cb6b9d87f4e046fafa6dd30efbdfa25c 100644 (file)
@@ -100,7 +100,8 @@ TEST_F(nntrainer_LazyTensorOpsTest, LazyTensorOps_04_p) {
 // chain and add_i(float) add_i(Tensor)
 TEST_F(nntrainer_LazyTensorOpsTest, LazyTensorOps_05_p) {
   expected = original.add(6.1);
-  EXPECT_TRUE(target.chain().add_i(2.1).add_i(constant_(2.0), 2).run() == expected);
+  EXPECT_TRUE(target.chain().add_i(2.1).add_i(constant_(2.0), 2).run() ==
+              expected);
 }
 
 // chain and add_i(float) subtract(float)
@@ -157,15 +158,15 @@ TEST_F(nntrainer_LazyTensorOpsTest, LazyTensorOps_08_p) {
 
 TEST_F(nntrainer_LazyTensorOpsTest, ApplyIf_01_p) {
 
-  EXPECT_TRUE(target.chain().applyIf(true, _LIFT(add_i), constant_(4.0), 0.5).run() ==
-          original.add(2.0));
+  EXPECT_TRUE(
+    target.chain().applyIf(true, _LIFT(add_i), constant_(4.0), 0.5).run() ==
+    original.add(2.0));
 
   EXPECT_TRUE(target.chain().applyIf(true, _LIFT(add_i), 2.0f).run() ==
-          original.add(2.0));
+              original.add(2.0));
 
   EXPECT_TRUE(target.chain().applyIf(true, _LIFT(add_i), 2.0).run() ==
-          original.add(2.0));
-
+              original.add(2.0));
 }
 
 TEST_F(nntrainer_LazyTensorOpsTest, ApplyIf_01_n) {