/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
$(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 \
#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>
#include <layer_node.h>
#include <nntrainer_error.h>
#include <nntrainer_log.h>
-#include <parse_util.h>
#include <time_dist.h>
#include <util_func.h>
#include <graph_core.h>
#include <nntrainer_error.h>
#include <nntrainer_log.h>
-#include <parse_util.h>
namespace nntrainer {
#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>
#include <lazy_tensor.h>
#include <nntrainer_error.h>
#include <nntrainer_log.h>
-#include <parse_util.h>
#include <tensor.h>
#include <util_func.h>
#include <nntrainer_error.h>
#include <nntrainer_log.h>
#include <node_exporter.h>
-#include <parse_util.h>
#include <tensor.h>
#include <util_func.h>
#include <common_properties.h>
#include <nntrainer_error.h>
-#include <parse_util.h>
#include <tensor_dim.h>
#include <regex>
#include <nntrainer_error.h>
#include <nntrainer_log.h>
#include <node_exporter.h>
-#include <parse_util.h>
#include <profiler.h>
#include <util_func.h>
#include <nntrainer_error.h>
#include <nntrainer_log.h>
#include <node_exporter.h>
-#include <parse_util.h>
#include <util_func.h>
namespace nntrainer {
#include <nntrainer_error.h>
#include <nntrainer_log.h>
#include <node_exporter.h>
-#include <parse_util.h>
#include <time_dist.h>
#include <util_func.h>
#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>
#include <nntrainer_error.h>
#include <optimizer_devel.h>
-#include <parse_util.h>
#include <util_func.h>
namespace nntrainer {
#include <lazy_tensor.h>
#include <nntrainer_error.h>
#include <nntrainer_log.h>
-#include <parse_util.h>
#include <tensor.h>
#include <util_func.h>
#include <nntrainer_error.h>
#include <nntrainer_log.h>
-#include <parse_util.h>
#include <tensor_dim.h>
+#include <util_func.h>
namespace ml {
namespace train {
* @bug No known bugs except for NYI items
*/
#include <base_properties.h>
-#include <parse_util.h>
#include <regex>
#include <sstream>
#include <vector>
#include <nntrainer_error.h>
-#include <props_util.h>
#include <tensor_dim.h>
+#include <util_func.h>
/** base and predefined structures */
#include <regex>
#include <nntrainer_error.h>
-#include <parse_util.h>
#include <util_func.h>
namespace nntrainer {
util_sources = [
- 'parse_util.cpp',
'util_func.cpp',
'profiler.cpp',
'ini_wrapper.cpp',
util_headers = [
'base_properties.h',
- 'props_util.h',
'node_exporter.h'
]
#include <base_properties.h>
#include <nntrainer_error.h>
-#include <props_util.h>
+#include <util_func.h>
#ifndef __NODE_EXPORTER_H__
#define __NODE_EXPORTER_H__
+++ /dev/null
-/**
- * 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 ®) {
- 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 */
+++ /dev/null
-/**
- * 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__ */
+++ /dev/null
-// 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 ®);
-
-/**
- * @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__ */
#include <fstream>
#include <random>
+#include <nntrainer_log.h>
#include <util_func.h>
namespace nntrainer {
unsigned int getSeed() { return 0; }
-float random() { return dist(rng); }
-
float sqrtFloat(float x) { return sqrt(x); };
double sqrtDouble(double x) { return sqrt(x); };
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();
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 ®) {
+ 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
#ifdef __cplusplus
#include <cstring>
+#include <regex>
#include <sstream>
#include <nntrainer_error.h>
*/
unsigned int getSeed();
-/**
- * @brief random function
- */
-float random();
-
/**
* @brief sqrt function for float type
* @param[in] x float
*/
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
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 ®);
+
+/**
+ * @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 */
%{_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
#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 */
#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>
#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) {
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);
}