cpp : Removed redundant keywords and replaced macros with constant expressions

This commit is contained in:
saundersp
2025-08-21 01:38:41 +02:00
parent c55dd14a89
commit 014326b1e3
8 changed files with 92 additions and 90 deletions

View File

@@ -31,7 +31,7 @@ std::tuple<np::Array<int32_t>, np::Array<uint16_t>, np::Array<uint8_t>, np::Arra
for (const char* const folder_name : { "models", "out" })
std::filesystem::create_directory(folder_name);
const std::chrono::system_clock::time_point preproc_timestamp = perf_counter_ns();
const std::chrono::time_point<std::chrono::high_resolution_clock> preproc_timestamp = perf_counter_ns();
const std::array<int32_t, 3> preproc_gaps = { 49, -18, 29 };
header(preproc_gaps, { "Preprocessing", "Time spent (ns)", "Formatted time spent" });
@@ -113,7 +113,7 @@ std::tuple<np::Array<int32_t>, np::Array<uint16_t>, np::Array<uint8_t>, np::Arra
print(X_test_feat_argsort.shape);
print(X_test_feat_argsort, { IDX_INSPECT, IDX_INSPECT + IDX_INSPECT_OFFSET });
#endif
const long long time_spent = duration_ns(perf_counter_ns() - preproc_timestamp);
const int64_t time_spent = duration_ns(perf_counter_ns() - preproc_timestamp);
formatted_line(preproc_gaps, "", "", "", "");
formatted_row(preproc_gaps, { "Preprocessing summary", thousand_sep(time_spent).c_str(), format_time_ns(time_spent).c_str() });
footer(preproc_gaps);
@@ -154,7 +154,7 @@ std::array<std::array<np::Array<float64_t>, 2>, TS.size()> train(const np::Array
#endif
models[i++] = { alphas, final_classifiers };
}
const long long time_spent = duration_ns(perf_counter_ns() - training_timestamp);
const int64_t time_spent = duration_ns(perf_counter_ns() - training_timestamp);
formatted_line(training_gaps, "", "", "", "");
formatted_row(training_gaps, { "Training summary", thousand_sep(time_spent).c_str(), format_time_ns(time_spent).c_str() });
footer(training_gaps);
@@ -177,15 +177,15 @@ void testing_and_evaluating(const std::array<std::array<np::Array<float64_t>, 2>
std::array<std::array<float64_t, 8>, TS.size()> results;
size_t i = 0;
long long total_train_timestamp = 0;
long long total_test_timestamp = 0;
int64_t total_train_timestamp = 0;
int64_t total_test_timestamp = 0;
for (const auto& [ alphas, final_classifiers ] : models) {
char title[BUFFER_SIZE] = { 0 };
snprintf(title, BUFFER_SIZE, "ViolaJones T = %-4i (%s)", TS[i], LABEL);
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 long long t_pred_train = duration_ns(perf_counter_ns() - start);
const int64_t t_pred_train = duration_ns(perf_counter_ns() - start);
total_train_timestamp += t_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);
@@ -194,7 +194,7 @@ void testing_and_evaluating(const std::array<std::array<np::Array<float64_t>, 2>
start = perf_counter_ns();
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(perf_counter_ns() - start);
const int64_t t_pred_test = duration_ns(perf_counter_ns() - start);
total_test_timestamp += t_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);
@@ -242,7 +242,7 @@ void unit_test(void) {
++n_total;
const std::chrono::system_clock::time_point start = perf_counter_ns();
const bool state = fnc();
const long long time_spent = duration_ns(perf_counter_ns() - start);
const int64_t time_spent = duration_ns(perf_counter_ns() - start);
if(state){
formatted_row(unit_gaps, { title, "Passed", thousand_sep(time_spent).c_str(), format_time_ns(time_spent).c_str() });
++n_success;
@@ -330,7 +330,7 @@ void unit_test(void) {
}
}
const long long time_spent = duration_ns(perf_counter_ns() - unit_timestamp);
const int64_t time_spent = duration_ns(perf_counter_ns() - unit_timestamp);
if (n_total == 0)
formatted_row(unit_gaps, { "Unit testing summary", "No files", thousand_sep(time_spent).c_str(), format_time_ns(time_spent).c_str() });