cpp : disambiguated auto keyword

This commit is contained in:
saundersp 2023-07-15 03:35:31 +02:00
parent 4cd659ea8c
commit 18afd40782
5 changed files with 11 additions and 11 deletions

View File

@ -58,9 +58,9 @@ T benchmark_function(const char* step_name, const F& fnc, Args &&...args) noexce
printf("%s...\r", step_name); printf("%s...\r", step_name);
fflush(stdout); // manual flush is mandatory, otherwise it will not be shown immediately because the output is buffered fflush(stdout); // manual flush is mandatory, otherwise it will not be shown immediately because the output is buffered
#endif #endif
const auto start = time(); const std::chrono::system_clock::time_point start = perf_counter_ns();
const T res = fnc(std::forward<Args>(args)...); const T res = fnc(std::forward<Args>(args)...);
const long long timespent = duration_ns(time() - start); const long long timespent = duration_ns(perf_counter_ns() - start);
printf("| %-49s | %18s | %-29s |\n", step_name, thousand_sep(timespent).c_str(), format_time_ns(timespent).c_str()); printf("| %-49s | %18s | %-29s |\n", step_name, thousand_sep(timespent).c_str(), format_time_ns(timespent).c_str());
return res; return res;
} }
@ -71,9 +71,9 @@ void benchmark_function_void(const char* step_name, const F& fnc, Args &&...args
printf("%s...\r", step_name); printf("%s...\r", step_name);
fflush(stdout); // manual flush is mandatory, otherwise it will not be shown immediately because the output is buffered fflush(stdout); // manual flush is mandatory, otherwise it will not be shown immediately because the output is buffered
#endif #endif
const auto start = time(); const std::chrono::system_clock::time_point start = perf_counter_ns();
fnc(std::forward<Args>(args)...); fnc(std::forward<Args>(args)...);
const long long timespent = duration_ns(time() - start); const long long timespent = duration_ns(perf_counter_ns() - start);
printf("| %-49s | %18s | %-29s |\n", step_name, thousand_sep(timespent).c_str(), format_time_ns(timespent).c_str()); printf("| %-49s | %18s | %-29s |\n", step_name, thousand_sep(timespent).c_str(), format_time_ns(timespent).c_str());
} }

View File

@ -65,7 +65,7 @@ namespace np {
// #if __DEBUG // #if __DEBUG
// print("Shape created (initializer)"); // print("Shape created (initializer)");
// #endif // #endif
const auto* begin = dims.begin(); const size_t* begin = dims.begin();
for(size_t i = 0; i < length; ++i){ for(size_t i = 0; i < length; ++i){
data[i] = begin[i]; data[i] = begin[i];
#if __DEBUG #if __DEBUG

View File

@ -159,17 +159,17 @@ void testing_and_evaluating(const np::Array<int32_t>& X_train_feat, const np::Ar
const np::Array<float64_t> alphas = load<float64_t>(alphas_title); const np::Array<float64_t> alphas = load<float64_t>(alphas_title);
const np::Array<float64_t> final_classifiers = load<float64_t>(final_classifiers_title); const np::Array<float64_t> final_classifiers = load<float64_t>(final_classifiers_title);
auto start = time(); std::chrono::system_clock::time_point start = perf_counter_ns();
const np::Array<uint8_t> y_pred_train = classify_viola_jones(alphas, final_classifiers, X_train_feat); const np::Array<uint8_t> y_pred_train = classify_viola_jones(alphas, final_classifiers, X_train_feat);
const long long t_pred_train = duration_ns(time() - start); const long long t_pred_train = duration_ns(perf_counter_ns() - start);
const float64_t e_acc = accuracy_score(y_train, y_pred_train); const float64_t e_acc = accuracy_score(y_train, y_pred_train);
const float64_t e_f1 = f1_score(y_train, y_pred_train); const float64_t e_f1 = f1_score(y_train, y_pred_train);
float64_t e_FN, e_FP; float64_t e_FN, e_FP;
std::tie(std::ignore, e_FN, e_FP, std::ignore) = confusion_matrix(y_train, y_pred_train); std::tie(std::ignore, e_FN, e_FP, std::ignore) = confusion_matrix(y_train, y_pred_train);
start = time(); start = perf_counter_ns();
const np::Array<uint8_t> y_pred_test = classify_viola_jones(alphas, final_classifiers, X_test_feat); const np::Array<uint8_t> y_pred_test = classify_viola_jones(alphas, final_classifiers, X_test_feat);
const long long t_pred_test = duration_ns(time() - start); const long long t_pred_test = duration_ns(perf_counter_ns() - start);
const float64_t t_acc = accuracy_score(y_test, y_pred_test); const float64_t t_acc = accuracy_score(y_test, y_pred_test);
const float64_t t_f1 = f1_score(y_test, y_pred_test); const float64_t t_f1 = f1_score(y_test, y_pred_test);
float64_t t_FN, t_FP; float64_t t_FN, t_FP;

View File

@ -114,7 +114,7 @@ std::string thousand_sep(uint64_t k) noexcept {
std::string s = "", n = std::to_string(k); std::string s = "", n = std::to_string(k);
uint8_t c = 0; uint8_t c = 0;
for (const auto& n_i : n) { for (const char& n_i : n) {
++c; ++c;
s.push_back(n_i); s.push_back(n_i);
if (c == 3) { if (c == 3) {

View File

@ -4,7 +4,7 @@
#include <string> #include <string>
#define duration_ns(a) std::chrono::duration_cast<std::chrono::nanoseconds>(a).count() #define duration_ns(a) std::chrono::duration_cast<std::chrono::nanoseconds>(a).count()
#define time() std::chrono::high_resolution_clock::now() #define perf_counter_ns() std::chrono::high_resolution_clock::now()
std::string format_time(uint64_t) noexcept; std::string format_time(uint64_t) noexcept;
std::string format_time_ns(uint64_t) noexcept; std::string format_time_ns(uint64_t) noexcept;