From 5e5c5f7fd083787e4aeab748e3070a524ae03abb Mon Sep 17 00:00:00 2001 From: Heiko Thiel Date: Thu, 18 Apr 2019 23:09:20 +0200 Subject: [PATCH] Changes are done by run-clang-tidy -header-filter='.*' -checks='-*,modernize-use-nullptr' -fix --- .../pcl/ml/impl/dt/decision_tree_trainer.hpp | 4 +- ml/include/pcl/ml/svm_wrapper.h | 12 +- ml/src/permutohedral.cpp | 2 +- ml/src/svm.cpp | 140 +++++++++--------- ml/src/svm_wrapper.cpp | 36 ++--- 5 files changed, 97 insertions(+), 97 deletions(-) diff --git a/ml/include/pcl/ml/impl/dt/decision_tree_trainer.hpp b/ml/include/pcl/ml/impl/dt/decision_tree_trainer.hpp index 2a31a98f0a8..2127c1dffa3 100644 --- a/ml/include/pcl/ml/impl/dt/decision_tree_trainer.hpp +++ b/ml/include/pcl/ml/impl/dt/decision_tree_trainer.hpp @@ -44,8 +44,8 @@ pcl::DecisionTreeTrainerdata); size += old->len; - old->data = 0; + old->data = nullptr; old->len = 0; } @@ -265,7 +265,7 @@ void Cache::swap_index (int i, int j) lru_delete (h); free (h->data); size += h->len; - h->data = 0; + h->data = nullptr; h->len = 0; } } @@ -388,7 +388,7 @@ Kernel::Kernel (int l, svm_node * const * x_, const svm_parameter& param) x_square[i] = dot (x[i], x[i]); } else - x_square = 0; + x_square = nullptr; } Kernel::~Kernel() @@ -992,7 +992,7 @@ int Solver::select_working_set (int &out_i, int &out_j) int i = Gmax_idx; - const Qfloat *Q_i = NULL; + const Qfloat *Q_i = nullptr; if (i != -1) // NULL Q_i not accessed: Gmax=-INF if i=-1 Q_i = Q->get_Q (i, active_size); @@ -1262,8 +1262,8 @@ int Solver_NU::select_working_set (int &out_i, int &out_j) int ip = Gmaxp_idx; int in = Gmaxn_idx; - const Qfloat *Q_ip = NULL; - const Qfloat *Q_in = NULL; + const Qfloat *Q_ip = nullptr; + const Qfloat *Q_in = nullptr; if (ip != -1) // NULL Q_ip not accessed: Gmaxp=-INF if ip=-1 Q_ip = Q->get_Q (ip, active_size); @@ -2427,8 +2427,8 @@ svm_model *svm_train (const svm_problem *prob, const svm_parameter *param) svm_model *model = Malloc (svm_model, 1); model->param = *param; model->free_sv = 0; // XXX - model->probA = NULL; - model->probB = NULL; + model->probA = nullptr; + model->probB = nullptr; if (param->svm_type == ONE_CLASS || param->svm_type == EPSILON_SVR || @@ -2436,10 +2436,10 @@ svm_model *svm_train (const svm_problem *prob, const svm_parameter *param) { // regression or one-class-svm model->nr_class = 2; - model->label = NULL; - model->nSV = NULL; - model->probA = NULL; - model->probB = NULL; + model->label = nullptr; + model->nSV = nullptr; + model->probA = nullptr; + model->probB = nullptr; model->sv_coef = Malloc (double *, 1); if (param->probability && @@ -2484,9 +2484,9 @@ svm_model *svm_train (const svm_problem *prob, const svm_parameter *param) // classification int l = prob->l; int nr_class; - int *label = NULL; - int *start = NULL; - int *count = NULL; + int *label = nullptr; + int *start = nullptr; + int *count = nullptr; int *perm = Malloc (int, l); // group training data of the same class @@ -2530,7 +2530,7 @@ svm_model *svm_train (const svm_problem *prob, const svm_parameter *param) decision_function *f = Malloc (decision_function, nr_class * (nr_class - 1) / 2); - double *probA = NULL, *probB = NULL; + double *probA = nullptr, *probB = nullptr; if (param->probability) { @@ -2609,8 +2609,8 @@ svm_model *svm_train (const svm_problem *prob, const svm_parameter *param) } else { - model->probA = NULL; - model->probB = NULL; + model->probA = nullptr; + model->probB = nullptr; } int total_sv = 0; @@ -2723,9 +2723,9 @@ void svm_cross_validation (const svm_problem *prob, const svm_parameter *param, if ( (param->svm_type == C_SVC || param->svm_type == NU_SVC) && nr_fold < l) { - int *start = NULL; - int *label = NULL; - int *count = NULL; + int *start = nullptr; + int *label = nullptr; + int *count = nullptr; svm_group_classes (prob, &nr_class, &label, &start, &count, perm); // random shuffle and then data grouped by fold using the array perm @@ -2866,7 +2866,7 @@ int svm_get_nr_class (const svm_model *model) void svm_get_labels (const svm_model *model, int* label) { - if (model->label != NULL) + if (model->label != nullptr) for (int i = 0;i < model->nr_class;i++) label[i] = model->label[i]; } @@ -2874,7 +2874,7 @@ void svm_get_labels (const svm_model *model, int* label) double svm_get_svr_probability (const svm_model *model) { if ( (model->param.svm_type == EPSILON_SVR || model->param.svm_type == NU_SVR) && - model->probA != NULL) + model->probA != nullptr) return model->probA[0]; else { @@ -2997,7 +2997,7 @@ double svm_predict_probability ( const svm_model *model, const svm_node *x, double *prob_estimates) { if ( (model->param.svm_type == C_SVC || model->param.svm_type == NU_SVC) && - model->probA != NULL && model->probB != NULL) + model->probA != nullptr && model->probB != nullptr) { int nr_class = model->nr_class; double *dec_values = Malloc (double, nr_class * (nr_class - 1) / 2); @@ -3042,19 +3042,19 @@ double svm_predict_probability ( static const char *svm_type_table[] = { - "c_svc", "nu_svc", "one_class", "epsilon_svr", "nu_svr", NULL + "c_svc", "nu_svc", "one_class", "epsilon_svr", "nu_svr", nullptr }; static const char *kernel_type_table[] = { - "linear", "polynomial", "rbf", "sigmoid", "precomputed", NULL + "linear", "polynomial", "rbf", "sigmoid", "precomputed", nullptr }; int svm_save_model (const char *model_file_name, const svm_model *model) { FILE *fp = fopen (model_file_name, "we"); - if (fp == NULL) + if (fp == nullptr) return -1; const svm_parameter& param = model->param; @@ -3173,21 +3173,21 @@ int svm_save_model (const char *model_file_name, const svm_model *model) return 0; } -static char *line = NULL; +static char *line = nullptr; static int max_line_len; static char* readline (FILE *input) { - if (fgets (line, max_line_len, input) == NULL) - return NULL; + if (fgets (line, max_line_len, input) == nullptr) + return nullptr; - while (strrchr (line, '\n') == NULL) + while (strrchr (line, '\n') == nullptr) { max_line_len *= 2; line = static_cast (realloc (line, max_line_len)); int len = int (strlen (line)); - if (fgets (line + len, max_line_len - len, input) == NULL) + if (fgets (line + len, max_line_len - len, input) == nullptr) break; } @@ -3198,8 +3198,8 @@ svm_model *svm_load_model (const char *model_file_name) { FILE *fp = fopen (model_file_name, "rbe"); - if (fp == NULL) - return NULL; + if (fp == nullptr) + return nullptr; // read parameters @@ -3207,15 +3207,15 @@ svm_model *svm_load_model (const char *model_file_name) svm_parameter& param = model->param; - model->rho = NULL; + model->rho = nullptr; - model->probA = NULL; + model->probA = nullptr; - model->probB = NULL; + model->probB = nullptr; - model->label = NULL; + model->label = nullptr; - model->nSV = NULL; + model->nSV = nullptr; model->scaling = Malloc (struct svm_node, 1); @@ -3241,14 +3241,14 @@ svm_model *svm_load_model (const char *model_file_name) } } - if (svm_type_table[i] == NULL) + if (svm_type_table[i] == nullptr) { fprintf (stderr, "unknown svm type.\n"); free (model->rho); free (model->label); free (model->nSV); free (model); - return NULL; + return nullptr; } } else @@ -3266,14 +3266,14 @@ svm_model *svm_load_model (const char *model_file_name) } } - if (kernel_type_table[i] == NULL) + if (kernel_type_table[i] == nullptr) { fprintf (stderr, "unknown kernel function.\n"); free (model->rho); free (model->label); free (model->nSV); free (model); - return NULL; + return nullptr; } } else @@ -3346,9 +3346,9 @@ svm_model *svm_load_model (const char *model_file_name) res = fscanf (fp, "%10000[^\n]", buff); idx = strtok (buff, ":"); - while (idx != NULL) + while (idx != nullptr) { - char *val = strtok (NULL, " \t"); + char *val = strtok (nullptr, " \t"); int pre_ii = ii; ii = atoi (idx); @@ -3366,7 +3366,7 @@ svm_model *svm_load_model (const char *model_file_name) model->scaling[ii].value = atof (val); ++ii; - idx = strtok (NULL, ":"); + idx = strtok (nullptr, ":"); //printf("%d e %f\n",model->scaling[ii-1].index,model->scaling[ii-1].value); } @@ -3393,7 +3393,7 @@ svm_model *svm_load_model (const char *model_file_name) free (model->label); free (model->nSV); free (model); - return NULL; + return nullptr; } } @@ -3409,15 +3409,15 @@ svm_model *svm_load_model (const char *model_file_name) char *p, *endptr, *idx, *val; - while (readline (fp) != NULL) + while (readline (fp) != nullptr) { p = strtok (line, ":"); while (true) { - p = strtok (NULL, ":"); + p = strtok (nullptr, ":"); - if (p == NULL) + if (p == nullptr) break; ++elements; @@ -3437,7 +3437,7 @@ svm_model *svm_load_model (const char *model_file_name) model->SV = Malloc (svm_node*, l); - svm_node *x_space = NULL; + svm_node *x_space = nullptr; if (l > 0) x_space = Malloc (svm_node, elements); @@ -3454,7 +3454,7 @@ svm_model *svm_load_model (const char *model_file_name) for (int k = 1;k < m;k++) { - p = strtok (NULL, " \t"); + p = strtok (nullptr, " \t"); model->sv_coef[k][i] = strtod (p, &endptr); } @@ -3462,10 +3462,10 @@ svm_model *svm_load_model (const char *model_file_name) while (true) { - idx = strtok (NULL, ":"); - val = strtok (NULL, " \t"); + idx = strtok (nullptr, ":"); + val = strtok (nullptr, " \t"); - if (val == NULL) + if (val == nullptr) break; x_space[j].index = int (strtol (idx, &endptr, 10)); @@ -3487,7 +3487,7 @@ svm_model *svm_load_model (const char *model_file_name) //printf("%d e %f\n",model->scaling[j-2].index,model->scaling[j-2].value); if (ferror (fp) != 0 || fclose (fp) != 0) - return NULL; + return nullptr; model->free_sv = 1; // XXX @@ -3496,7 +3496,7 @@ svm_model *svm_load_model (const char *model_file_name) void svm_free_model_content (svm_model* model_ptr) { - if (model_ptr->free_sv && model_ptr->l > 0 && model_ptr->SV != NULL) + if (model_ptr->free_sv && model_ptr->l > 0 && model_ptr->SV != nullptr) free (static_cast (model_ptr->SV[0])); if (model_ptr->sv_coef) @@ -3507,34 +3507,34 @@ void svm_free_model_content (svm_model* model_ptr) free (model_ptr->SV); - model_ptr->SV = NULL; + model_ptr->SV = nullptr; free (model_ptr->sv_coef); - model_ptr->sv_coef = NULL; + model_ptr->sv_coef = nullptr; free (model_ptr->rho); - model_ptr->rho = NULL; + model_ptr->rho = nullptr; free (model_ptr->label); - model_ptr->label = NULL; + model_ptr->label = nullptr; free (model_ptr->probA); - model_ptr->probA = NULL; + model_ptr->probA = nullptr; free (model_ptr->probB); - model_ptr->probB = NULL; + model_ptr->probB = nullptr; free (model_ptr->nSV); - model_ptr->nSV = NULL; + model_ptr->nSV = nullptr; } void svm_free_and_destroy_model (svm_model** model_ptr_ptr) { - if (model_ptr_ptr != NULL && *model_ptr_ptr != NULL) + if (model_ptr_ptr != nullptr && *model_ptr_ptr != nullptr) { svm_free_model_content (*model_ptr_ptr); free (*model_ptr_ptr); - *model_ptr_ptr = NULL; + *model_ptr_ptr = nullptr; } } @@ -3671,20 +3671,20 @@ const char *svm_check_parameter (const svm_problem *prob, const svm_parameter *p free (count); } - return NULL; + return nullptr; } int svm_check_probability_model (const svm_model *model) { return ( (model->param.svm_type == C_SVC || model->param.svm_type == NU_SVC) && - model->probA != NULL && model->probB != NULL) || + model->probA != nullptr && model->probB != nullptr) || ( (model->param.svm_type == EPSILON_SVR || model->param.svm_type == NU_SVR) && - model->probA != NULL); + model->probA != nullptr); } void svm_set_print_string_function (void (*print_func) (const char *)) { - if (print_func == NULL) + if (print_func == nullptr) svm_print_string = &print_string_stdout; else svm_print_string = print_func; diff --git a/ml/src/svm_wrapper.cpp b/ml/src/svm_wrapper.cpp index e6a44e5ee2a..9e90fb74824 100755 --- a/ml/src/svm_wrapper.cpp +++ b/ml/src/svm_wrapper.cpp @@ -57,18 +57,18 @@ inline T module (T a) char* pcl::SVM::readline (FILE *input) { - if (fgets (line_, max_line_len_, input) == NULL) - return NULL; + if (fgets (line_, max_line_len_, input) == nullptr) + return nullptr; // Find the endline. If not found extend the max_line_len_ - while (strrchr (line_ , '\n') == NULL) + while (strrchr (line_ , '\n') == nullptr) { max_line_len_ *= 2; line_ = static_cast (realloc (line_, max_line_len_)); int len = int (strlen (line_)); // if the new read part of the string is unavailable, break the while - if (fgets (line_ + len, max_line_len_ - len, input) == NULL) + if (fgets (line_ + len, max_line_len_ - len, input) == nullptr) break; } @@ -274,7 +274,7 @@ pcl::SVMTrain::trainClassifier () { SVMModel* out; out = static_cast (svm_train (&prob_, ¶m_)); - if (out == NULL) + if (out == nullptr) { PCL_ERROR ("[pcl::%s::trainClassifier] Error taining the classifier model.\n", getClassName ().c_str ()); return false; @@ -295,7 +295,7 @@ pcl::SVM::loadProblem (const char *filename, svm_problem &prob) char *endptr; char *idx, *val, *label; - if (fp == NULL) + if (fp == nullptr) { PCL_ERROR ("[pcl::%s] Can't open input file %s.\n", getClassName ().c_str (), filename); return false; @@ -307,7 +307,7 @@ pcl::SVM::loadProblem (const char *filename, svm_problem &prob) line_ = Malloc (char, max_line_len_); // readline function writes one line in var. "line_" - while (readline (fp) != NULL) + while (readline (fp) != nullptr) { // "\t" cuts the tab or space. // strtok splits the string into tokens @@ -318,9 +318,9 @@ pcl::SVM::loadProblem (const char *filename, svm_problem &prob) while (true) { // split the next element - p = strtok (NULL, " \t"); + p = strtok (nullptr, " \t"); - if (p == NULL || *p == '\n') // check '\n' as ' ' may be after the last feature + if (p == nullptr || *p == '\n') // check '\n' as ' ' may be after the last feature break; ++elements; @@ -355,9 +355,9 @@ pcl::SVM::loadProblem (const char *filename, svm_problem &prob) // check if the first element is really a label - if (pch == NULL) + if (pch == nullptr) { - if (label == NULL) // empty line + if (label == nullptr) // empty line exitInputError (i + 1); labelled_training_set_ = true; @@ -387,11 +387,11 @@ pcl::SVM::loadProblem (const char *filename, svm_problem &prob) if (k++ == 0 && isUnlabelled) idx = strtok (line_, ": \t\n"); else - idx = strtok (NULL, ":"); // indice + idx = strtok (nullptr, ":"); // indice - val = strtok (NULL, " \t"); // valore + val = strtok (nullptr, " \t"); // valore - if (val == NULL) + if (val == nullptr) break; // exit with the last element //std::cout << idx << ":" << val<< " "; @@ -531,7 +531,7 @@ pcl::SVMClassify::loadClassifierModel (const char *filename) { SVMModel *out; out = static_cast (svm_load_model (filename)); - if (out == NULL) + if (out == nullptr) { PCL_ERROR ("[pcl::%s::loadClassifierModel] Can't open classifier model %s.\n", getClassName ().c_str (), filename); return false; @@ -601,7 +601,7 @@ pcl::SVMClassify::classificationTest () int svm_type = svm_get_svm_type (&model_); int nr_class = svm_get_nr_class (&model_); - double *prob_estimates = NULL; + double *prob_estimates = nullptr; prediction_.clear (); @@ -718,7 +718,7 @@ pcl::SVMClassify::classification () int svm_type = svm_get_svm_type (&model_); int nr_class = svm_get_nr_class (&model_); - double *prob_estimates = NULL; + double *prob_estimates = nullptr; prediction_.clear(); @@ -796,7 +796,7 @@ pcl::SVMClassify::classification (pcl::SVMData in) int svm_type = svm_get_svm_type (&model_); int nr_class = svm_get_nr_class (&model_); - double *prob_estimates = NULL; + double *prob_estimates = nullptr; svm_node *buff; buff = Malloc (struct svm_node, in.SV.size() + 10);