cpp : more robust code and added more documentation

This commit is contained in:
saundersp
2024-04-27 21:08:33 +02:00
parent 45f0f6ab8e
commit c7d21e1014
10 changed files with 355 additions and 319 deletions

View File

@ -112,9 +112,9 @@ template <typename T, size_t N, typename F, typename... Args>
std::array<np::Array<T>, N> state_saver(const char* const step_name, const int32_t& column_width, const std::vector<const char*>& filenames, const bool& force_redo, const bool& save_state, const char* const out_dir, const F& fnc, Args &&...args) noexcept {
char filepath[BUFFER_SIZE] = { 0 };
bool abs = false;
for (const char* filename : filenames){
sprintf(filepath, "%s/%s.bin", out_dir, filename);
if (!fs::exists(filepath)) {
for (const char* const filename : filenames){
snprintf(filepath, BUFFER_SIZE, "%s/%s.bin", out_dir, filename);
if (!std::filesystem::exists(filepath)) {
abs = true;
break;
}
@ -130,8 +130,8 @@ std::array<np::Array<T>, N> state_saver(const char* const step_name, const int32
fflush(stderr);
#endif
size_t i = 0;
for (const char* filename : filenames){
sprintf(filepath, "%s/%s.bin", out_dir, filename);
for (const char* const filename : filenames){
snprintf(filepath, BUFFER_SIZE, "%s/%s.bin", out_dir, filename);
save<T>(bin[i++], filepath);
}
#if __DEBUG == false
@ -145,8 +145,8 @@ std::array<np::Array<T>, N> state_saver(const char* const step_name, const int32
fflush(stderr);
#endif
size_t i = 0;
for (const char* filename : filenames){
bin[i++] = std::move(load<T>(filepath));
for (const char* const filename : filenames){
snprintf(filepath, BUFFER_SIZE, "%s/%s.bin", out_dir, filename);
}
formatted_row<3>({ column_width, -18, 29 }, { step_name, "None", "loaded saved state" });
@ -156,7 +156,7 @@ std::array<np::Array<T>, N> state_saver(const char* const step_name, const int32
np::Array<uint16_t> argsort_2d_cpu(const np::Array<int32_t>&) noexcept;
np::Array<uint8_t> build_features(const uint16_t&, const uint16_t&) noexcept;
np::Array<int> select_percentile(const np::Array<uint8_t>&, const np::Array<uint8_t>&) noexcept;
np::Array<int32_t> select_percentile(const np::Array<uint8_t>&, const np::Array<uint8_t>&) noexcept;
np::Array<uint8_t> classify_viola_jones(const np::Array<float64_t>&, const np::Array<float64_t>&, const np::Array<int32_t>&) noexcept;
np::Array<float64_t> init_weights(const np::Array<uint8_t>&) noexcept;
std::tuple<int32_t, float64_t, np::Array<float64_t>> select_best(const np::Array<float64_t>&, const np::Array<float64_t>&, const np::Array<int32_t>&,