[util] Remove parse_util.h
authorhyeonseok lee <hs89.lee@samsung.com>
Wed, 15 Sep 2021 04:15:27 +0000 (13:15 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Wed, 15 Sep 2021 10:04:50 +0000 (19:04 +0900)
 - Deleted parse_util.h, parse_util.cpp
 - Move functions in props_util.h to util_func.h and deleted props_util.h
 - Remove unused function in util_func

Self evaluation:

Build test: [X]Passed [ ]Failed [ ]Skipped
Run test: [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: hyeonseok lee <hs89.lee@samsung.com>
30 files changed:
debian/nntrainer-dev.install
jni/Android.mk
nntrainer/app_context.cpp
nntrainer/compiler/ini_interpreter.cpp
nntrainer/graph/graph_core.cpp
nntrainer/graph/network_graph.cpp
nntrainer/layers/acti_func.cpp
nntrainer/layers/activation_layer.cpp
nntrainer/layers/common_properties.cpp
nntrainer/layers/conv2d_layer.cpp
nntrainer/layers/layer_impl.cpp
nntrainer/layers/layer_node.cpp
nntrainer/models/model_loader.cpp
nntrainer/optimizers/optimizer_devel.cpp
nntrainer/tensor/tensor.cpp
nntrainer/tensor/tensor_dim.cpp
nntrainer/utils/base_properties.cpp
nntrainer/utils/base_properties.h
nntrainer/utils/ini_wrapper.cpp
nntrainer/utils/meson.build
nntrainer/utils/node_exporter.h
nntrainer/utils/parse_util.cpp [deleted file]
nntrainer/utils/parse_util.h [deleted file]
nntrainer/utils/props_util.h [deleted file]
nntrainer/utils/util_func.cpp
nntrainer/utils/util_func.h
packaging/nntrainer.spec
test/include/nntrainer_test_util.h
test/unittest/unittest_nntrainer_layers.cpp
test/unittest/unittest_util_func.cpp

index 9f4130f8572ccd2293973f6d6e8a4b47470bb760..7d48610928a16ea191d50b0cbf3ba9e53bc81b6c 100644 (file)
@@ -2,7 +2,6 @@
 /usr/include/nntrainer/nntrainer_error.h
 /usr/include/nntrainer/common_properties.h
 /usr/include/nntrainer/base_properties.h
-/usr/include/nntrainer/props_util.h
 /usr/include/nntrainer/node_exporter.h
 # tensor headers
 /usr/include/nntrainer/tensor.h
index d35c020e9184248b15901edbab086c39781357f7..02030026662466d4f732b15082c0bca268fc2425 100644 (file)
@@ -180,7 +180,6 @@ NNTRAINER_SRCS := $(NNTRAINER_ROOT)/nntrainer/models/neuralnet.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/optimizers/sgd.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/utils/util_func.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/utils/ini_wrapper.cpp \
-                  $(NNTRAINER_ROOT)/nntrainer/utils/parse_util.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/utils/profiler.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/utils/node_exporter.cpp \
                   $(NNTRAINER_ROOT)/nntrainer/utils/base_properties.cpp \
index 2d240286dc748d33c7389fb86c92f1bf35459092..f80e7de12d604f32bbbca1950740f2fb69f7d579 100644 (file)
@@ -46,7 +46,6 @@
 #include <mse_loss_layer.h>
 #include <multiout_layer.h>
 #include <nntrainer_error.h>
-#include <parse_util.h>
 #include <permute_layer.h>
 #include <plugged_layer.h>
 #include <plugged_optimizer.h>
index 5377a1bd844aee264499c46b5e41a5590c184e20..45e19f2fd23d0d1c681bea3129f761f6bb4cc8c5 100644 (file)
@@ -21,7 +21,6 @@
 #include <layer_node.h>
 #include <nntrainer_error.h>
 #include <nntrainer_log.h>
-#include <parse_util.h>
 #include <time_dist.h>
 #include <util_func.h>
 
index a3fb5fb3a78fa69e2edb91fc4a7e2cebf11f9e35..4da00a0155f84a5317a38cd4d537a62d0109290d 100644 (file)
@@ -18,7 +18,6 @@
 #include <graph_core.h>
 #include <nntrainer_error.h>
 #include <nntrainer_log.h>
-#include <parse_util.h>
 
 namespace nntrainer {
 
index fb33e7539561b677214f3f06331c91bdac21b9a4..52661706b4340317b726eb0061dc59cf42fd56f2 100644 (file)
@@ -27,7 +27,6 @@
 #include <network_graph.h>
 #include <nntrainer_error.h>
 #include <nntrainer_log.h>
-#include <parse_util.h>
 #include <profiler.h>
 #include <rnn.h>
 #include <split_layer.h>
index 35413c5a4904f6f863b7d89165c51ba3101f3ec7..e4a21fd2d2da84b67847f6c5e7712c7a1b3dd400 100644 (file)
@@ -24,7 +24,6 @@
 #include <lazy_tensor.h>
 #include <nntrainer_error.h>
 #include <nntrainer_log.h>
-#include <parse_util.h>
 #include <tensor.h>
 #include <util_func.h>
 
index 5ac2e1c16b543318030f01e8c94c492a4718e949..7f2bfd6ae55d1f944a6d40c288cf1aff1a6a4432 100644 (file)
@@ -25,7 +25,6 @@
 #include <nntrainer_error.h>
 #include <nntrainer_log.h>
 #include <node_exporter.h>
-#include <parse_util.h>
 #include <tensor.h>
 #include <util_func.h>
 
index 0c50b5f6f824179e4199d6b7ee7c8bfe3733390f..7a7270aa3e877f5ff23cee2547019f57375db9c1 100644 (file)
@@ -13,7 +13,6 @@
 #include <common_properties.h>
 
 #include <nntrainer_error.h>
-#include <parse_util.h>
 #include <tensor_dim.h>
 
 #include <regex>
index 9d909b68684b9619627ef2e09d8086c8348040b9..6c2c1a53cea2da80420fc759009bd3ad315b06b3 100644 (file)
@@ -22,7 +22,6 @@
 #include <nntrainer_error.h>
 #include <nntrainer_log.h>
 #include <node_exporter.h>
-#include <parse_util.h>
 #include <profiler.h>
 #include <util_func.h>
 
index b24de566afcfc366eb7713867b44c2238311331e..eb3ae12fff31a2bcdb9d0f032fcddc622ad976a4 100644 (file)
@@ -19,7 +19,6 @@
 #include <nntrainer_error.h>
 #include <nntrainer_log.h>
 #include <node_exporter.h>
-#include <parse_util.h>
 #include <util_func.h>
 namespace nntrainer {
 
index 72cee0116db09b3ecff5b129fb048437785a68ca..4359a19ffc23d1cf6f28fdcc643fed4c259ba6c4 100644 (file)
@@ -18,7 +18,6 @@
 #include <nntrainer_error.h>
 #include <nntrainer_log.h>
 #include <node_exporter.h>
-#include <parse_util.h>
 #include <time_dist.h>
 #include <util_func.h>
 
index 6228ff8da95995fcc70ea393881fa800929c4078..0622499b32a855cf4564a97410034d027747c80f 100644 (file)
@@ -20,7 +20,6 @@
 #include <neuralnet.h>
 #include <nntrainer_error.h>
 #include <nntrainer_log.h>
-#include <parse_util.h>
 #include <sgd.h>
 #include <time_dist.h>
 #include <util_func.h>
index 8718c4524574f81e1f9701b702913d103b20943e..5704fb5a182613d2b38761e3c19d56f0272e10c0 100644 (file)
@@ -17,7 +17,6 @@
 
 #include <nntrainer_error.h>
 #include <optimizer_devel.h>
-#include <parse_util.h>
 #include <util_func.h>
 
 namespace nntrainer {
index 31c29163bcf5e488b68b01cd671a448ca309c7d7..098b39322a2592318d2a12fcafef3de3bf72bffd 100644 (file)
@@ -36,7 +36,6 @@
 #include <lazy_tensor.h>
 #include <nntrainer_error.h>
 #include <nntrainer_log.h>
-#include <parse_util.h>
 #include <tensor.h>
 #include <util_func.h>
 
index 13f7bdb084d60da0d6d30142ceb5f13eb6f33a86..d5e76eff2fb78f3d535bf38ffef0410e966aeb44 100644 (file)
@@ -19,8 +19,8 @@
 
 #include <nntrainer_error.h>
 #include <nntrainer_log.h>
-#include <parse_util.h>
 #include <tensor_dim.h>
+#include <util_func.h>
 
 namespace ml {
 namespace train {
index 644b273753b7b677b422a3d5ae13587205b11cbf..591e488e79b473dc1e26ae481abe2d27a646dfee 100644 (file)
@@ -10,7 +10,6 @@
  * @bug No known bugs except for NYI items
  */
 #include <base_properties.h>
-#include <parse_util.h>
 
 #include <regex>
 #include <sstream>
index 3cba6d16f33c7cfa130245978c7fcca2cba66a16..ed6d829f6a87459f437c5293cf1c2e6cf4d14981 100644 (file)
@@ -20,8 +20,8 @@
 #include <vector>
 
 #include <nntrainer_error.h>
-#include <props_util.h>
 #include <tensor_dim.h>
+#include <util_func.h>
 
 /** base and predefined structures */
 
index 2fe0015a475990fa7f97651ae8d0e82a6c18a6c2..843c21cf6082266db256a5104e13022c52af84f2 100644 (file)
@@ -15,7 +15,6 @@
 #include <regex>
 
 #include <nntrainer_error.h>
-#include <parse_util.h>
 #include <util_func.h>
 
 namespace nntrainer {
index 28d76c0b24f979d5ce152cf71b9960313627a844..5bb0c448d3b8bec2ad00e5431c4dc7c0d981fefd 100644 (file)
@@ -1,5 +1,4 @@
 util_sources = [
-  'parse_util.cpp',
   'util_func.cpp',
   'profiler.cpp',
   'ini_wrapper.cpp',
@@ -9,7 +8,6 @@ util_sources = [
 
 util_headers = [
   'base_properties.h',
-  'props_util.h',
   'node_exporter.h'
 ]
 
index 276958b6cf01af8b1dfe490836bdf21557d3c9d0..45465e95575dc5f929929c46f12635425bea2a7f 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <base_properties.h>
 #include <nntrainer_error.h>
-#include <props_util.h>
+#include <util_func.h>
 
 #ifndef __NODE_EXPORTER_H__
 #define __NODE_EXPORTER_H__
diff --git a/nntrainer/utils/parse_util.cpp b/nntrainer/utils/parse_util.cpp
deleted file mode 100644 (file)
index f168e90..0000000
+++ /dev/null
@@ -1,400 +0,0 @@
-/**
- * Copyright (C) 2020 Samsung Electronics Co., Ltd. All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *   http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * @file       parse_util.cpp
- * @date       08 April 2020
- * @brief      This is collection of math functions
- * @see                https://github.com/nnstreamer/nntrainer
- * @author     Jijoong Moon <jijoong.moon@samsung.com>
- * @bug                No known bugs except for NYI items
- *
- */
-
-#include <array>
-#include <cstring>
-#include <iostream>
-#include <sstream>
-#include <string>
-
-#include <acti_func.h>
-#include <neuralnet.h>
-#include <nntrainer_error.h>
-#include <nntrainer_log.h>
-#include <optimizer_devel.h>
-#include <parse_util.h>
-#include <pooling2d_layer.h>
-
-#define NUM_SKIP_CHAR 3
-
-namespace nntrainer {
-
-int getKeyValue(const std::string &input_str, std::string &key,
-                std::string &value) {
-  int status = ML_ERROR_NONE;
-  auto input_trimmed = input_str;
-
-  std::vector<std::string> list;
-  static const std::regex words_regex("[^\\s=]+");
-  input_trimmed.erase(
-    std::remove(input_trimmed.begin(), input_trimmed.end(), ' '),
-    input_trimmed.end());
-  auto words_begin = std::sregex_iterator(input_trimmed.begin(),
-                                          input_trimmed.end(), words_regex);
-  auto words_end = std::sregex_iterator();
-  int nwords = std::distance(words_begin, words_end);
-  if (nwords != 2) {
-    ml_loge("Error: input string must be 'key = value' format, %s given",
-            input_trimmed.c_str());
-    return ML_ERROR_INVALID_PARAMETER;
-  }
-
-  for (std::sregex_iterator i = words_begin; i != words_end; ++i) {
-    list.push_back((*i).str());
-  }
-
-  key = list[0];
-  value = list[1];
-
-  return status;
-}
-
-unsigned int parseType(std::string ll, InputType t) {
-  unsigned int ret;
-  unsigned int i;
-
-  /**
-   * @brief     Model Type String from configure file
-   *            "knn"  : K Neearest Neighbor
-   *            "regression" : Logistic Regression
-   *            "neuralnet" : Neural Network
-   */
-  std::array<std::string, 3> model_type_string = {"knn", "regression",
-                                                  "neuralnet"};
-
-  /**
-   * @brief     Weight Initialization Type String from configure file
-   *            "zeros" : Zero Initialization
-   *            "ones" : One Initialization
-   *            "lecun_normal"  : LeCun Normal Initialization
-   *            "lecun_uniform"  : LeCun Uniform Initialization
-   *            "xavier_normal"  : Xavier Normal Initialization
-   *            "xavier_uniform"  : Xavier Uniform Initialization
-   *            "he_normal"  : He Normal Initialization
-   *            "he_uniform"  : He Uniform Initialization
-   */
-  std::array<std::string, 8> weight_ini_string = {
-    "zeros",         "ones",           "lecun_normal", "lecun_uniform",
-    "xavier_normal", "xavier_uniform", "he_normal",    "he_uniform"};
-
-  /**
-   * @brief     Weight Regularization String from configure file
-   *            "L2Norm"  : squared norm regularization
-   *            "None" : none
-   */
-  std::array<std::string, 2> weight_regularizer_string = {"l2norm", "none"};
-
-  /**
-   * @brief     Weight Decay String from configure file
-   *            "L2Norm"  : squared norm regularization
-   *            "Regression" : Regression
-   */
-  std::array<std::string, 3> padding_string = {"full", "same", "valid"};
-
-  /**
-   * @brief     Pooling String from configure file
-   *            "max"  : Max Pooling
-   *            "average" : Average Pooling
-   *            "global_max" : Global Max Pooling
-   *            "global_average" : Global Average Pooling
-   */
-  std::array<std::string, 4> pooling_string = {"max", "average", "global_max",
-                                               "global_average"};
-
-  switch (t) {
-  case TOKEN_MODEL:
-    for (i = 0; i < model_type_string.size(); i++) {
-      if (!strncasecmp(model_type_string[i].c_str(), ll.c_str(),
-                       model_type_string[i].size())) {
-        return (i);
-      }
-    }
-    ret = (unsigned int)NetType::UNKNOWN;
-    break;
-  case TOKEN_ACTI:
-    for (i = 0; i < ActivationTypeStr.size(); i++) {
-      if (!strncasecmp(ActivationTypeStr[i].c_str(), ll.c_str(),
-                       ActivationTypeStr[i].size())) {
-
-        return (i);
-      }
-    }
-    ml_logw("Input activation %s cannot be identified. "
-            "Moved to NO activation layer by default.",
-            ll.c_str());
-    ret = (unsigned int)ActivationType::ACT_UNKNOWN;
-    break;
-  case TOKEN_WEIGHT_INIT:
-    for (i = 0; i < weight_ini_string.size(); i++) {
-      if (!strncasecmp(weight_ini_string[i].c_str(), ll.c_str(),
-                       weight_ini_string[i].size())) {
-        return (i);
-      }
-    }
-    ret = (unsigned int)Tensor::Initializer::NONE;
-    break;
-  case TOKEN_WEIGHT_REGULARIZER:
-    for (i = 0; i < weight_regularizer_string.size(); i++) {
-      if (!strncasecmp(weight_regularizer_string[i].c_str(), ll.c_str(),
-                       weight_regularizer_string[i].size())) {
-        return (i);
-      }
-    }
-    ret = (unsigned int)WeightRegularizer::UNKNOWN;
-    break;
-  case TOKEN_POOLING:
-    for (i = 0; i < pooling_string.size(); i++) {
-      if (!strncasecmp(pooling_string[i].c_str(), ll.c_str(),
-                       pooling_string[i].size())) {
-        return (i);
-      }
-    }
-    ret = (unsigned int)props::PoolingTypeInfo::Enum::unknown;
-    break;
-  case TOKEN_UNKNOWN:
-  default:
-    ml_loge("Error: unknown token cannot be parsed.");
-    ret = 0;
-    break;
-  }
-  return ret;
-}
-
-/**
- * @brief     Layer Properties
- * input_shape = 0
- * normalization = 1
- * standardization = 2
- * activation = 3
- * epsilon = 4
- * weight_regularizer = 5
- * weight_regularizer_constant = 6
- * unit = 7
- * weight_initializer = 8
- * bias_initializer = 9
- * filters = 10
- * kernel_size = 11
- * stride = 12
- * padding = 13
- * pool_size = 14
- * pooling = 15
- * flatten = 16
- * name = 17
- * momentum = 18
- * moving_mean_initializer = 19
- * moving_variance_initializer = 20
- * gamma_initializer = 21
- * beta_initializer = 22
- * modelfile = 23
- * input_layers = 24
- * output_layers = 25
- * trainable = 26
- * flip_direction = 27
- * random_translate = 28
- * in_dim = 29
- * out_dim = 30
- * recurrent_activation = 31
- * distribute = 32
- * split_dimension = 33
- * return_sequences = 34
- * hidden_state_activation = 35
- * dropout = 36
- * num_inputs = 37
- *
- * InputLayer has 0, 1, 2, 3 properties.
- * FullyConnectedLayer has 1, 4, 6, 7, 8, 9 properties.
- * Conv2DLayer has 0, 1, 4, 6, 7, 9, 10, 11, 12, 13 properties.
- * Pooling2DLayer has 12, 13, 14, 15 properties.
- * BatchNormalizationLayer has 0, 1, 5, 6, 7 properties.
- */
-static std::array<std::string, 39> property_string = {
-  "input_shape",
-  "normalization",
-  "standardization",
-  "activation",
-  "epsilon",
-  "weight_regularizer",
-  "weight_regularizer_constant",
-  "unit",
-  "weight_initializer",
-  "bias_initializer",
-  "filters",
-  "kernel_size",
-  "stride",
-  "padding",
-  "pool_size",
-  "pooling",
-  "flatten",
-  "name",
-  "momentum",
-  "moving_mean_initializer",
-  "moving_variance_initializer",
-  "gamma_initializer",
-  "beta_initializer",
-  "modelfile",
-  "input_layers",
-  "output_layers",
-  "trainable",
-  "flip_direction",
-  "random_translate",
-  "in_dim",
-  "out_dim",
-  "recurrent_activation",
-  "distribute",
-  "split_dimension",
-  "return_sequences",
-  "hidden_state_activation",
-  "dropout",
-  "num_inputs",
-  "unknown"};
-
-unsigned int parseLayerProperty(std::string property) {
-  unsigned int i;
-
-  for (i = 0; i < property_string.size(); i++) {
-    unsigned int size = (property_string[i].size() > property.size())
-                          ? property_string[i].size()
-                          : property.size();
-
-    if (!strncasecmp(property_string[i].c_str(), property.c_str(), size)) {
-      return (i);
-    }
-  }
-
-  return (unsigned int)Layer::PropertyType::unknown;
-}
-
-std::string propToStr(unsigned int type) { return property_string[type]; }
-
-int setUint(unsigned int &val, const std::string &str) {
-  int status = ML_ERROR_NONE;
-  try {
-    val = (unsigned int)std::stoul(str.c_str());
-  } catch (...) {
-    ml_loge("Error: Wrong Type. Must be int");
-    status = ML_ERROR_INVALID_PARAMETER;
-  }
-
-  return status;
-}
-
-int setFloat(float &val, std::string str) {
-  int status = ML_ERROR_NONE;
-  try {
-    val = std::stof(str.c_str());
-  } catch (...) {
-    ml_loge("Error: Wrong Type. Must be float");
-    status = ML_ERROR_INVALID_PARAMETER;
-  }
-  return status;
-}
-
-int setDouble(double &val, std::string str) {
-  int status = ML_ERROR_NONE;
-  try {
-    val = std::stod(str.c_str());
-  } catch (...) {
-    ml_loge("Error: Wrong Type. Must be double");
-    status = ML_ERROR_INVALID_PARAMETER;
-  }
-
-  return status;
-}
-
-int setBoolean(bool &val, std::string str) {
-  int status = ML_ERROR_NONE;
-  std::string t = "true";
-  std::string f = "false";
-
-  if (!strncasecmp(str.c_str(), t.c_str(), t.size())) {
-    val = true;
-  } else if (!strncasecmp(str.c_str(), f.c_str(), f.size())) {
-    val = false;
-  } else {
-    status = ML_ERROR_INVALID_PARAMETER;
-  }
-
-  return status;
-}
-
-int getValues(int n_str, std::string str, int *value) {
-  int status = ML_ERROR_NONE;
-  static const std::regex words_regex("[^\\s.,:;!?]+");
-  str.erase(std::remove(str.begin(), str.end(), ' '), str.end());
-  auto words_begin = std::sregex_iterator(str.begin(), str.end(), words_regex);
-  auto words_end = std::sregex_iterator();
-
-  int num = std::distance(words_begin, words_end);
-  if (num != n_str) {
-    ml_loge("Number of Data is not match");
-    return ML_ERROR_INVALID_PARAMETER;
-  }
-  int cn = 0;
-  for (std::sregex_iterator i = words_begin; i != words_end; ++i) {
-    value[cn] = std::stoi((*i).str());
-    cn++;
-  }
-  return status;
-}
-
-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));
-  vec_str << values.back();
-
-  return std::move(vec_str.str().c_str());
-}
-
-std::vector<std::string> split(const std::string &s, const std::regex &reg) {
-  std::vector<std::string> out;
-  char char_to_remove[NUM_SKIP_CHAR] = {' ', '[', ']'};
-  std::string str = s;
-  for (unsigned int i = 0; i < NUM_SKIP_CHAR; ++i) {
-    str.erase(std::remove(str.begin(), str.end(), char_to_remove[i]),
-              str.end());
-  }
-  std::regex_token_iterator<std::string::iterator> end;
-  std::regex_token_iterator<std::string::iterator> iter(str.begin(), str.end(),
-                                                        reg, -1);
-
-  while (iter != end) {
-    out.push_back(*iter);
-    ++iter;
-  }
-  return out;
-}
-
-bool istrequal(const std::string &a, const std::string &b) {
-  if (a.size() != b.size())
-    return false;
-
-  return std::equal(a.begin(), a.end(), b.begin(), [](char a_, char b_) {
-    return tolower(a_) == tolower(b_);
-  });
-}
-
-} /* namespace nntrainer */
diff --git a/nntrainer/utils/parse_util.h b/nntrainer/utils/parse_util.h
deleted file mode 100644 (file)
index 9dac3a3..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/**
- * Copyright (C) 2020 Samsung Electronics Co., Ltd. All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *   http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * @file       parse_util.h
- * @date       07 May 2020
- * @brief      This is collection of parse functions.
- * @see                https://github.com/nnstreamer/nntrainer
- * @author     Jijoong Moon <jijoong.moon@samsung.com>
- * @bug                No known bugs except for NYI items
- *
- */
-
-#ifndef __PARSE_UTIL_H__
-#define __PARSE_UTIL_H__
-#ifdef __cplusplus
-
-#include <iostream>
-#include <regex>
-#include <string>
-#include <vector>
-
-#include <ml-api-common.h>
-#include <nntrainer_error.h>
-#include <props_util.h>
-
-namespace nntrainer {
-
-/**
- * @brief     Enumeration for input configuration file parsing
- *            0. MODEL   ( Model Token )
- *            1. ACTI    ( Activation Token )
- *            2. WEIGHT_INIT  ( Weight Initializer Token )
- *            3. WEIGHT_REGULARIZER  ( Weight Decay Token )
- *            4. PADDING  ( Padding Token )
- *            5. POOLING  ( Pooling Token )
- *            6. UNKNOWN
- */
-typedef enum {
-  TOKEN_MODEL,
-  TOKEN_ACTI,
-  TOKEN_WEIGHT_INIT,
-  TOKEN_WEIGHT_REGULARIZER,
-  TOKEN_POOLING,
-  TOKEN_UNKNOWN
-} InputType;
-
-/**
- * @brief     Parsing Layer Property
- * @param[in] property string to be parsed
- * @retval    int enumerated type
- */
-unsigned int parseLayerProperty(std::string property);
-
-/**
- * @brief     Unparse Layer property to string
- * @param[in] type property type
- * @retval    string representation of the type
- */
-std::string propToStr(const unsigned int type);
-
-/**
- * @brief     Parsing Configuration Token
- * @param[in] ll string to be parsed
- * @param[in] t  Token type
- * @retval    int enumerated type
- */
-unsigned int parseType(std::string ll, InputType t);
-
-} /* namespace nntrainer */
-
-#endif /* __cplusplus */
-#endif /* __PARSE_UTIL_H__ */
diff --git a/nntrainer/utils/props_util.h b/nntrainer/utils/props_util.h
deleted file mode 100644 (file)
index f860123..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-// SPDX-License-Identifier: Apache-2.0
-/**
- * Copyright (C) 2021 Parichay Kapoor <pk.kapoor@samsung.com>
- *
- * @file       props_util.h
- * @date       26 July 2021
- * @brief      This is collection of utility function for properties.
- * @see                https://github.com/nnstreamer/nntrainer
- * @author     Jijoong Moon <jijoong.moon@samsung.com>
- * @author     Parichay Kapoor <pk.kapoor@samsung.com>
- * @bug                No known bugs except for NYI items
- *
- */
-
-#ifndef __PROPS_UTIL_H__
-#define __PROPS_UTIL_H__
-#ifdef __cplusplus
-
-#include <regex>
-#include <string>
-#include <vector>
-
-namespace nntrainer {
-
-/**
- * @brief     check str to be unsigned int and assign to variable to type T
- * @param[out] val assign variable
- * @param[in] str input string
- * @retval #ML_ERROR_NONE Successful.
- * @retval #ML_ERROR_INVALID_PARAMETER invalid parameter.
- */
-int setUint(unsigned int &val, const std::string &str);
-
-/**
- * @brief     check str to be float and assign
- * @param[out] val assign variable
- * @param[in] str input string
- * @retval #ML_ERROR_NONE Successful.
- * @retval #ML_ERROR_INVALID_PARAMETER invalid parameter.
- */
-int setFloat(float &val, std::string str);
-
-/**
- * @brief     check str to be double and assign
- * @param[out] val assign variable
- * @param[in] str input string
- * @retval #ML_ERROR_NONE Successful.
- * @retval #ML_ERROR_INVALID_PARAMETER invalid parameter.
- */
-int setDouble(double &val, std::string str);
-
-/**
- * @brief     check str to be bool and assign
- * @param[out] val assign variable
- * @param[in] str input string
- * @retval #ML_ERROR_NONE Successful.
- * @retval #ML_ERROR_INVALID_PARAMETER invalid parameter.
- */
-int setBoolean(bool &val, std::string str);
-
-/**
- * @brief     parse string and return key & value
- * @param[in] input_str input string to split with '='
- * @param[out] key key
- * @param[out] value value
- * @retval #ML_ERROR_NONE Successful.
- * @retval #ML_ERROR_INVALID_PARAMETER invalid parameter.
- */
-int getKeyValue(const std::string &input_str, std::string &key,
-                std::string &value);
-
-/**
- * @brief     join vector of int to string with delimiter ","
- * @param[in] values vector of int
- * @param[in] delimiter delimiter for the string
- * @retval    output string
- */
-const char *getValues(std::vector<int> values, const char *delimiter = ",");
-
-int getValues(int n_str, std::string str, int *value);
-
-/**
- * @brief     split string into vector with delimiter regex
- * @param[in] str string
- * @param[in] reg regular expression to use as delimiter
- * @retval    output string vector
- */
-std::vector<std::string> split(const std::string &s, const std::regex &reg);
-
-/**
- * @brief Cast insensitive string comparison
- *
- * @param a first string to compare
- * @param b second string to compare
- * @retval true if string is case-insensitive equal
- * @retval false if string is case-insensitive not equal
- */
-bool istrequal(const std::string &a, const std::string &b);
-} /* namespace nntrainer */
-
-#endif /* __cplusplus */
-#endif /* __PARSE_UTIL_H__ */
index 2eab470fc5df0c6d3c93e04bd9bfa3e1141adb9f..d80af81f0bd4b4be1b9100b82cd0829cc0565211 100644 (file)
@@ -24,6 +24,7 @@
 #include <fstream>
 #include <random>
 
+#include <nntrainer_log.h>
 #include <util_func.h>
 
 namespace nntrainer {
@@ -37,8 +38,6 @@ static std::uniform_real_distribution<float> dist(-0.5, 0.5);
 
 unsigned int getSeed() { return 0; }
 
-float random() { return dist(rng); }
-
 float sqrtFloat(float x) { return sqrt(x); };
 
 double sqrtDouble(double x) { return sqrt(x); };
@@ -47,63 +46,6 @@ float logFloat(float x) { return log(x + 1.0e-20); }
 
 float exp_util(float x) { return exp(x); }
 
-// This is 2D zero pad
-// TODO : Optimize for multi dimention padding
-void zero_pad(int batch, Tensor const &in, unsigned int const *padding,
-              Tensor &output) {
-  unsigned int c = in.channel();
-  unsigned int h = in.height();
-  unsigned int w = in.width();
-
-  unsigned int height_p = h + padding[0] * 2;
-  unsigned int width_p = w + padding[1] * 2;
-
-  unsigned int height_p_h = h + padding[0];
-  unsigned int width_p_h = w + padding[1];
-
-  output = Tensor(1, c, height_p, width_p);
-  output.setZero();
-
-  for (unsigned int j = 0; j < c; ++j) {
-    for (unsigned int k = 0; k < padding[0]; ++k) {
-      for (unsigned int l = 0; l < width_p; ++l) {
-        output.setValue(0, j, k, l, 0.0f);
-        output.setValue(0, j, k + height_p_h, l, 0.0f);
-      }
-    }
-
-    for (unsigned int l = 0; l < padding[1]; ++l) {
-      for (unsigned int k = padding[0]; k < h; ++k) {
-        output.setValue(0, j, k, l, 0.0f);
-        output.setValue(0, j, k, l + width_p_h, 0.0f);
-      }
-    }
-  }
-
-  for (unsigned int j = 0; j < c; ++j) {
-    for (unsigned int k = 0; k < h; ++k) {
-      for (unsigned int l = 0; l < w; ++l) {
-        output.setValue(0, j, k + padding[0], l + padding[1],
-                        in.getValue(batch, j, k, l));
-      }
-    }
-  }
-}
-
-// This is strip pad and return original tensor
-void strip_pad(Tensor const &in, unsigned int const *padding, Tensor &output,
-               unsigned int batch) {
-
-  for (unsigned int j = 0; j < in.channel(); ++j) {
-    for (unsigned int k = 0; k < output.height(); ++k) {
-      for (unsigned int l = 0; l < output.width(); ++l) {
-        output.setValue(batch, j, k, l,
-                        in.getValue(0, j, k + padding[0], l + padding[1]));
-      }
-    }
-  }
-}
-
 Tensor rotate_180(Tensor in) {
   Tensor output(in.getDim());
   output.setZero();
@@ -174,4 +116,83 @@ bool endswith(const std::string &target, const std::string &suffix) {
   return target.substr(spos) == suffix;
 }
 
+int getKeyValue(const std::string &input_str, std::string &key,
+                std::string &value) {
+  int status = ML_ERROR_NONE;
+  auto input_trimmed = input_str;
+
+  std::vector<std::string> list;
+  static const std::regex words_regex("[^\\s=]+");
+  input_trimmed.erase(
+    std::remove(input_trimmed.begin(), input_trimmed.end(), ' '),
+    input_trimmed.end());
+  auto words_begin = std::sregex_iterator(input_trimmed.begin(),
+                                          input_trimmed.end(), words_regex);
+  auto words_end = std::sregex_iterator();
+  int nwords = std::distance(words_begin, words_end);
+  if (nwords != 2) {
+    ml_loge("Error: input string must be 'key = value' format, %s given",
+            input_trimmed.c_str());
+    return ML_ERROR_INVALID_PARAMETER;
+  }
+
+  for (std::sregex_iterator i = words_begin; i != words_end; ++i) {
+    list.push_back((*i).str());
+  }
+
+  key = list[0];
+  value = list[1];
+
+  return status;
+}
+
+int getValues(int n_str, std::string str, int *value) {
+  int status = ML_ERROR_NONE;
+  static const std::regex words_regex("[^\\s.,:;!?]+");
+  str.erase(std::remove(str.begin(), str.end(), ' '), str.end());
+  auto words_begin = std::sregex_iterator(str.begin(), str.end(), words_regex);
+  auto words_end = std::sregex_iterator();
+
+  int num = std::distance(words_begin, words_end);
+  if (num != n_str) {
+    ml_loge("Number of Data is not match");
+    return ML_ERROR_INVALID_PARAMETER;
+  }
+  int cn = 0;
+  for (std::sregex_iterator i = words_begin; i != words_end; ++i) {
+    value[cn] = std::stoi((*i).str());
+    cn++;
+  }
+  return status;
+}
+
+std::vector<std::string> split(const std::string &s, const std::regex &reg) {
+  std::vector<std::string> out;
+  const int NUM_SKIP_CHAR = 3;
+  char char_to_remove[NUM_SKIP_CHAR] = {' ', '[', ']'};
+  std::string str = s;
+  for (unsigned int i = 0; i < NUM_SKIP_CHAR; ++i) {
+    str.erase(std::remove(str.begin(), str.end(), char_to_remove[i]),
+              str.end());
+  }
+  std::regex_token_iterator<std::string::iterator> end;
+  std::regex_token_iterator<std::string::iterator> iter(str.begin(), str.end(),
+                                                        reg, -1);
+
+  while (iter != end) {
+    out.push_back(*iter);
+    ++iter;
+  }
+  return out;
+}
+
+bool istrequal(const std::string &a, const std::string &b) {
+  if (a.size() != b.size())
+    return false;
+
+  return std::equal(a.begin(), a.end(), b.begin(), [](char a_, char b_) {
+    return tolower(a_) == tolower(b_);
+  });
+}
+
 } // namespace nntrainer
index 9106087ba77c53163686027799bb9c7a663505a3..26d5e662338acbb3345a750fac2cffd6f3a54e35 100644 (file)
@@ -25,6 +25,7 @@
 #ifdef __cplusplus
 
 #include <cstring>
+#include <regex>
 #include <sstream>
 
 #include <nntrainer_error.h>
@@ -67,11 +68,6 @@ inline void throw_status(int status) {
  */
 unsigned int getSeed();
 
-/**
- * @brief     random function
- */
-float random();
-
 /**
  * @brief     sqrt function for float type
  * @param[in] x float
@@ -98,26 +94,6 @@ float logFloat(float x);
  */
 float exp_util(float x);
 
-/**
- * @brief     apply padding
- * @param[in] batch batch index
- * @param[in] x input
- * @param[in] padding 2D padding size
- * @param[out] padded output
- */
-void zero_pad(int batch, Tensor const &in, unsigned int const *padding,
-              Tensor &output);
-
-/**
- * @brief     strip padding
- * @param[in] x input
- * @param[in] padding 2D padding size
- * @param[in] output output tensor
- * @param[in] batch batch index
- */
-void strip_pad(Tensor const &in, unsigned int const *padding, Tensor &output,
-               unsigned int batch);
-
 /**
  * @brief     rotate 180 dgree
  * @param[in] in input Tensor
@@ -223,6 +199,44 @@ T checkedOpenStream(const std::string &path, std::ios_base::openmode mode) {
   return model_file;
 }
 
+/**
+ * @brief     parse string and return key & value
+ * @param[in] input_str input string to split with '='
+ * @param[out] key key
+ * @param[out] value value
+ * @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_INVALID_PARAMETER invalid parameter.
+ */
+int getKeyValue(const std::string &input_str, std::string &key,
+                std::string &value);
+
+/**
+ * @brief     parse string and stored to int
+ * @param[in] n_str number of data
+ * @param[in] str string to parse
+ * @param[in] value int value to stored
+ * @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_INVALID_PARAMETER invalid parameter.
+ */
+int getValues(int n_str, std::string str, int *value);
+
+/**
+ * @brief     split string into vector with delimiter regex
+ * @param[in] str string
+ * @param[in] reg regular expression to use as delimiter
+ * @retval    output string vector
+ */
+std::vector<std::string> split(const std::string &s, const std::regex &reg);
+
+/**
+ * @brief Cast insensitive string comparison
+ *
+ * @param a first string to compare
+ * @param b second string to compare
+ * @retval true if string is case-insensitive equal
+ * @retval false if string is case-insensitive not equal
+ */
+bool istrequal(const std::string &a, const std::string &b);
 } /* namespace nntrainer */
 
 #endif /* __cplusplus */
index 3a7a0014a9d40e6158f4138625414afc6c201876..0696b27a1f1acb6fe6cc68953ed4b5477c598b72 100644 (file)
@@ -441,7 +441,6 @@ cp -r result %{buildroot}%{_datadir}/nntrainer/unittest/
 %{_includedir}/nntrainer/nntrainer_error.h
 %{_includedir}/nntrainer/common_properties.h
 %{_includedir}/nntrainer/base_properties.h
-%{_includedir}/nntrainer/props_util.h
 %{_includedir}/nntrainer/node_exporter.h
 # tensor headers
 %{_includedir}/nntrainer/tensor.h
index 4f4bec6c2359d6e2028ec2c11182f274649a7e8c..61c1e9d35ac81993b5723f64b130f4732d217b06 100644 (file)
@@ -34,7 +34,6 @@
 #include <neuralnet.h>
 #include <nntrainer_error.h>
 #include <nntrainer_log.h>
-#include <parse_util.h>
 #include <tensor.h>
 
 /** tolerance is reduced for packaging, but CI runs at full tolerance */
index 3743c5bb21fa22b4e942433dbf18ca42f94e607e..baaf2650d0db86a3c4d06ed0e85d540fa58885e1 100644 (file)
@@ -30,7 +30,6 @@
 #include <nntrainer_error.h>
 #include <nntrainer_test_util.h>
 #include <optimizer_factory.h>
-#include <parse_util.h>
 #include <permute_layer.h>
 #include <pooling2d_layer.h>
 #include <preprocess_flip_layer.h>
index 211b2c19dbd3175f9661eece5fd0741da9faa0f0..d7f0287b876bb05fd666100350ff2d20e5b91e49 100644 (file)
@@ -26,7 +26,6 @@
 #include <nntrainer_log.h>
 #include <nntrainer_logger.h>
 #include <nntrainer_test_util.h>
-#include <parse_util.h>
 #include <util_func.h>
 
 TEST(nntrainer_util_func, sqrtFloat_01_p) {
@@ -100,33 +99,33 @@ TEST(nntrainer_util_func, writeString_n) {
   EXPECT_THROW(nntrainer::writeString(file, str), std::runtime_error);
 }
 
-TEST(nntrainer_parse_util, throw_status_no_error_p) {
+TEST(nntrainer_util_func, throw_status_no_error_p) {
   EXPECT_NO_THROW(nntrainer::throw_status(ML_ERROR_NONE));
 }
 
-TEST(nntrainer_parse_util, throw_status_invalid_argument_n) {
+TEST(nntrainer_util_func, throw_status_invalid_argument_n) {
   EXPECT_THROW(nntrainer::throw_status(ML_ERROR_INVALID_PARAMETER),
                std::invalid_argument);
 }
 
-TEST(nntrainer_parse_util, throw_status_out_of_memory_n) {
+TEST(nntrainer_util_func, throw_status_out_of_memory_n) {
   EXPECT_THROW(nntrainer::throw_status(ML_ERROR_OUT_OF_MEMORY), std::bad_alloc);
 }
 
-TEST(nntrainer_parse_util, throw_status_timed_out_n) {
+TEST(nntrainer_util_func, throw_status_timed_out_n) {
   EXPECT_THROW(nntrainer::throw_status(ML_ERROR_TIMED_OUT), std::runtime_error);
 }
 
-TEST(nntrainer_parse_util, throw_status_permission_denied_n) {
+TEST(nntrainer_util_func, throw_status_permission_denied_n) {
   EXPECT_THROW(nntrainer::throw_status(ML_ERROR_PERMISSION_DENIED),
                std::runtime_error);
 }
 
-TEST(nntrainer_parse_util, throw_status_unknown_error_n) {
+TEST(nntrainer_util_func, throw_status_unknown_error_n) {
   EXPECT_THROW(nntrainer::throw_status(ML_ERROR_UNKNOWN), std::runtime_error);
 }
 
-TEST(nntrainer_parse_util, throw_status_default_n) {
+TEST(nntrainer_util_func, throw_status_default_n) {
   EXPECT_THROW(nntrainer::throw_status(-12345), std::runtime_error);
 }