Compare commits
16 Commits
9c867b0e01
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 7aded906b7 | |||
| 943af9408c | |||
| 28906c37b2 | |||
| ba5d76c49c | |||
| 7cb97ff8d9 | |||
| bf2d4efcba | |||
| 53adbf4d6e | |||
| 1432186387 | |||
| 308f49f014 | |||
| a448728a3d | |||
| 7586d07243 | |||
| 44f7c2246e | |||
| 503ea9fb44 | |||
| 4690993b73 | |||
| b663bcfb8f | |||
| e019235297 |
10
bin/examples/comparators/main.cpp
Normal file
10
bin/examples/comparators/main.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "hack/comparators/comparators.hpp"
|
||||
|
||||
auto main(int argc, char *argv[]) -> int
|
||||
{
|
||||
std::vector<float> frequencies = { 0, -0.000920129, 0.00195607, -0.00334136, 0.00524956, -0.0085677, 0.0140421, -0.0279224, 0.0594694, -0.468169, -1.3376, -2.26262, -3.03318, 3.08953, -3.11554, 3.12384, -3.12944, 3.13217, -3.1343, 3.13554, -3.13658, 3.13726, -3.13786, 3.13827, -3.13865, 3.13892, -3.13918, 3.13937, -3.13955, 3.13969, -3.13983, 3.13994, -3.14004, 3.14012, -3.14021, 3.14028, -3.14034, 3.1404, -3.14045, 3.1405, -3.14054, 3.14058, -3.14062, 3.14066, -3.14069, 3.14072, -3.14075, 3.14077, -3.1408, 3.14082, -3.14084, 3.14086, -3.14088, 3.1409, -3.14092, 3.14094, -3.14095, 3.14097, -3.14098, 3.141, -3.14101, 3.14102, -3.14103, 3.14104, -3.14105, 3.14107, -3.14108, 3.14109, -3.14109, 3.1411, -3.14111, 3.14111, -3.14113, 3.14114, -3.14113, 3.14116, -3.14116, 3.14116, -3.14117, 3.14118, -3.14118, 3.14119, -3.1412, 3.1412, -3.14121, 3.14121, -3.14122, 3.14122, -3.14123, 3.14123, -3.14124, 3.14125, -3.14125, 3.14125, -3.14125, 3.14126, -3.14126, 3.14127, -3.14127, 3.14127, -3.14128, 3.14129, -3.14128, 3.14128, -3.14129, 3.14131, -3.14129, 3.14131, -3.14131, 3.14131, -3.14132, 3.14131, -3.14131, 3.14132, -3.14132, 3.14132, -3.14134, 3.14136, -3.14131, 3.14133, -3.14135, 3.14133, -3.14135, 3.14134, -3.14136, 3.14133, -3.14137, 3.14135, -3.14135, 3.14135, -3.14136, 3.14137, -3.14136, 3.14136, -3.14138, 3.14136, -3.14139, 3.14137, -3.14137, 3.14137, -3.1414, 3.1414, -3.14137, 3.14139, -3.14138, 3.14138, -3.14138, 3.14139, -3.14139, 3.14141, -3.1414, 3.14142, -3.1414, 3.1414, -3.14142, 3.14141, -3.1414, 3.14142, -3.14141, 3.1414, -3.14141, 3.14142, -3.14143, 3.14141, -3.14141, 3.14143, -3.14142, 3.14141, -3.14143, 3.14142, -3.14141, 3.14142, -3.14143, 3.14141, -3.14143, 3.14146, -3.14142, 3.14144, -3.14142, 3.14144, -3.14143, 3.14145, -3.14143, 3.14146, -3.14144, 3.14144, -3.14146, 3.14142, -3.14145, 3.14148, -3.14144, 3.14146, -3.14146, 3.14144, -3.14145, 3.14144, -3.14148, 3.14143, -3.14148, 3.14145, -3.14145, 3.14146, -3.14145, 3.14143, -3.14147, 3.14145, -3.14145, 3.14145, -3.14147, 3.14147, -3.14145, 3.14147, -3.14147, 3.14146, -3.14148, 3.14146, -3.14148, 3.14147, -3.14145, 3.14147, -3.14145, 3.14146, -3.14146, 3.14147, -3.14148, 3.14147, -3.14149, 3.14147, -3.14147, 3.14152, -3.14148, 3.14149, -3.14148, 3.14151, -3.1415, 3.14151, -3.14152, 3.14149, -3.14154, 3.14149, -3.14148, 3.14148, -3.14149, 3.1415, -3.14144, 3.14144, -3.14152, 3.1415, -3.14149, 3.1415, -3.1415, 3.14153, -3.14149, 3.14151, -3.14147, 3.14148, -3.1415, 3.14151, -3.14147, 3.14152, -3.1415, 3.14153, -3.14152, 3.14151, -3.14148, 3.14149, -3.14158, 3.14157, -3.14148, 3.14143, -3.14151, 3.14149, -3.14149, 3.14151, -3.1415, 3.14156, -3.14151, 3.14155, -3.14152, 3.14146, -3.14148, 3.14153, -3.14153, 3.14147, -3.14154, 3.14153, -3.14153, 3.14156, -3.14151, 3.14153, -3.14148, 3.14153, -3.14147, 3.14152, -3.14146, 3.14151, -3.14151, 3.14153, -3.14154, 3.14156, -3.14152, 3.14151, -3.14154, 3.14157, -3.14152, 3.1415, -3.14149, -3.14157, -3.14147, -3.14159, -3.14152, 3.14146, -3.14159, 3.14149, -3.14157, 3.14146, -3.14153, 3.14154, -3.14151, 3.14148, -3.14153, 3.14154, -3.14151, 3.14155, -3.14153, -3.14156, -3.14149, 3.14146, -3.14153, 3.14142, 3.14153, 3.14152, -3.14158, 3.14143, 3.14159, 3.14159, -3.14156, 3.14152, -3.14152, 3.14156, -3.1415, 3.14154, -3.14148, 3.14146, -3.14151, 3.14151, -3.14153, 3.14159, -3.14151, 3.14149, -3.14153, 3.14155, -3.14155, 3.14154, -3.1415, 3.14155, -3.14155, 3.14158, -3.14152, 3.14154, -3.14155, 3.14154, -3.14153, 3.14151, 3.14157, 3.14146, -3.14155, 3.14155, -3.14155, -3.14159, -3.14154, 3.14158, -3.14142, 3.14157, 3.14158, 3.14142, -3.14152, 3.14159, -3.14151, 3.14155, -3.1415, -3.14159, -3.14149, -3.14158, -3.14154, 3.1415, -3.14156, 3.14155, -3.14159, 3.1415, -3.14156, 3.1415, 3.14158, -3.14159, -3.1415, 3.14153, 3.14157, 3.1415, -3.14151, -3.14159, -3.14159, 3.14151, -3.14157, 3.14152, -3.14158, 3.14156, -3.14154, -3.14152, -3.14158, -3.14159, -3.14156, 3.14155, -3.14155, -3.14146, -3.14153, 3.14148, -3.14157, -3.14158, -3.14153, 3.14152, 3.14158, 3.14159, -3.14156, -3.14154, 3.14158, 3.14156, -3.14144, 3.14155, -3.14158, 3.14151, 3.14158, 3.14149, -3.14158, 3.14151, 3.14157, 3.14154, 3.14145, 3.14134, 3.14146, -3.14127, -3.14151, -3.14154, -3.1415, 3.14156, -3.14155, -3.14154, 3.14158, 3.14153, -3.14159, 3.14153, 3.14155, -3.14159, 3.14157, 3.14155, 3.14152, 3.14153, 3.14153, 3.14157, 3.14156, 3.14152, 3.14158, 3.14159, -3.14158, -3.14159, 3.14156, 3.14154, 3.14157, -3.14155, -3.14154, 3.14156, 3.14151, 3.14148, -3.14156, 3.14158, 3.1415, 3.14157, 3.14156, 3.14153, 3.14155, 3.14155, 3.14159, 3.14154, -3.14157, 3.14159, -3.14155, -3.14154, 3.14157, -3.14159, -3.14156, 3.14159, 3.14158, 3.14153, 3.14153, 3.14158, -3.14158, -3.14153, -3.14159, -3.14153, -3.14153, -3.14153, -3.14159, -3.14111, -3.14159, 3.14135, -3.14159, 3.14153, -3.14159, -3.14159, -3.14159, -3.14153, 3.14153, 3.14153, 3.14159 };
|
||||
float c_array[] = { 0, -0.000920188, 0.00195607, -0.00334141, 0.00524961, -0.0085677, 0.0140421, -0.0279224, 0.0594694, -0.468169, -1.3376, -2.26262, -3.03318, 3.08953, -3.11554, 3.12384, -3.12944, 3.13217, -3.1343, 3.13554, -3.13658, 3.13726, -3.13786, 3.13827, -3.13865, 3.13892, -3.13918, 3.13937, -3.13955, 3.13969, -3.13983, 3.13994, -3.14004, 3.14012, -3.14021, 3.14028, -3.14034, 3.1404, -3.14045, 3.1405, -3.14054, 3.14058, -3.14062, 3.14066, -3.14069, 3.14072, -3.14075, 3.14078, -3.1408, 3.14082, -3.14084, 3.14087, -3.14088, 3.14091, -3.14092, 3.14094, -3.14095, 3.14097, -3.14098, 3.141, -3.14101, 3.14102, -3.14103, 3.14105, -3.14105, 3.14106, -3.14107, 3.14109, -3.14109, 3.1411, -3.14111, 3.14112, -3.14113, 3.14114, -3.14114, 3.14116, -3.14116, 3.14116, -3.14117, 3.14118, -3.14118, 3.14119, -3.1412, 3.1412, -3.14121, 3.14122, -3.14122, 3.14121, -3.14122, 3.14123, -3.14124, 3.14124, -3.14125, 3.14125, -3.14125, 3.14126, -3.14126, 3.14126, -3.14127, 3.14127, -3.14128, 3.14129, -3.14129, 3.14128, -3.14129, 3.14131, -3.14129, 3.1413, -3.14131, 3.14131, -3.14132, 3.14131, -3.14131, 3.14133, -3.14132, 3.14132, -3.14133, 3.14133, -3.14131, 3.14135, -3.14135, 3.14133, -3.14137, 3.14134, -3.14135, 3.14133, -3.14137, 3.14135, -3.14136, 3.14135, -3.14136, 3.14138, -3.14137, 3.14136, -3.14138, 3.14137, -3.1414, 3.14134, -3.14139, 3.14138, -3.14139, 3.14139, -3.14136, 3.1414, -3.14139, 3.14139, -3.14138, 3.14139, -3.1414, 3.14141, -3.14139, 3.14141, -3.1414, 3.14141, -3.14141, 3.14141, -3.14141, 3.14142, -3.1414, 3.14139, -3.14143, 3.14143, -3.14141, 3.14142, -3.14139, 3.14144, -3.1414, 3.14142, -3.14142, 3.14143, -3.14143, 3.14139, -3.14142, 3.1414, -3.14144, 3.14145, -3.14143, 3.14145, -3.14141, 3.14143, -3.14143, 3.14147, -3.14144, 3.14146, -3.14145, 3.14143, -3.14147, 3.14146, -3.14146, 3.14148, -3.14145, 3.14147, -3.14145, 3.14143, -3.14145, 3.14146, -3.14142, 3.14142, -3.1415, 3.14144, -3.14144, 3.14145, -3.14144, 3.14142, -3.14146, 3.14145, -3.14145, 3.14145, -3.14148, 3.14146, -3.14143, 3.1415, -3.14147, 3.14148, -3.14149, 3.14147, -3.14148, 3.14148, -3.14148, 3.14148, -3.14147, 3.14147, -3.14144, 3.14146, -3.14148, 3.14146, -3.14149, 3.14147, -3.14148, 3.14155, -3.14146, 3.14151, -3.1415, 3.14152, -3.14145, 3.14152, -3.14149, 3.1415, -3.14151, 3.14147, -3.14149, 3.14147, -3.14148, 3.14147, -3.14149, 3.14144, -3.14152, 3.14153, -3.14149, 3.14153, -3.14147, 3.14149, -3.14151, 3.14151, -3.1415, 3.14149, -3.1415, 3.14154, -3.14149, 3.14154, -3.14149, 3.14156, -3.14151, 3.14153, -3.14151, 3.14149, -3.14158, 3.14155, -3.14148, 3.14142, -3.14152, 3.14152, -3.14146, 3.1415, -3.14154, 3.14155, -3.14149, 3.14152, -3.14153, 3.14149, -3.14151, 3.14152, -3.1415, 3.14153, -3.14154, 3.14154, -3.14153, 3.14153, -3.14151, 3.1415, -3.14152, 3.14151, -3.14152, 3.14151, -3.14146, 3.14156, -3.14154, 3.14153, -3.14153, 3.14159, -3.14151, 3.14151, -3.14151, 3.14155, -3.14152, 3.14151, -3.14151, 3.14156, -3.14151, -3.14155, -3.14151, 3.14149, -3.14157, 3.1415, -3.14159, 3.14145, -3.14156, 3.14152, -3.14153, 3.14149, -3.14154, 3.14151, -3.1415, 3.14153, -3.14156, 3.14159, -3.14147, 3.14147, -3.14154, 3.14152, -3.14159, 3.14156, -3.14156, 3.14146, -3.14157, 3.14159, -3.14154, 3.14153, -3.14154, 3.14156, -3.14148, 3.14151, -3.14148, 3.1415, -3.14151, 3.14158, -3.14155, 3.14158, -3.1415, 3.14147, -3.14157, 3.14156, -3.14157, 3.1415, -3.14153, 3.14156, -3.14157, 3.14157, -3.14148, 3.14155, -3.14155, 3.14158, 3.14153, 3.14153, 3.14158, 3.14143, -3.14156, 3.14157, -3.14153, 3.14158, -3.14155, 3.14152, -3.14142, 3.14143, 3.14146, 3.1415, -3.14151, 3.14158, -3.1415, 3.14156, -3.14149, -3.14159, -3.14149, -3.14156, -3.14157, -3.14158, -3.14155, 3.14157, -3.14159, 3.14157, -3.14155, 3.14142, -3.14156, 3.14143, -3.14153, 3.14158, -3.14158, 3.14149, -3.14159, -3.14157, 3.14159, 3.14149, 3.14157, 3.14149, -3.14155, 3.14152, -3.14152, 3.14155, -3.14156, 3.14157, -3.14157, -3.14157, -3.14151, -3.14149, 3.14159, 3.1415, -3.14156, -3.14156, -3.1415, 3.14155, 3.14159, -3.14159, 3.14156, -3.14153, -3.14154, 3.14155, -3.14154, 3.14148, -3.14156, 3.14148, 3.14158, 3.14152, -3.14157, 3.14149, 3.14158, 3.14158, 3.14148, 3.14143, 3.14153, -3.1414, -3.14155, 3.14151, -3.14159, -3.14159, -3.14157, -3.14152, 3.14157, 3.1415, 3.14159, 3.14154, 3.14157, 3.14156, 3.14157, 3.14156, -3.14159, 3.14151, 3.14153, 3.1415, -3.14158, -3.14156, -3.14156, 3.14153, -3.14152, 3.14157, 3.14159, 3.14156, -3.14156, -3.14158, -3.14153, -3.14155, 3.14152, 3.14144, 3.14156, 3.14152, 3.14157, -3.14154, 3.14148, -3.14157, 3.14157, 3.14154, 3.14158, 3.14155, -3.14154, 3.14155, -3.14156, 3.14156, 3.14155, 3.14159, -3.14159, -3.14159, 3.14158, -3.14159, -3.14156, -3.14156, 3.14155, -3.14153, -3.14156, -3.14144, -3.14147, -3.14147, -3.14135, -3.14111, -3.14159, -3.14147, -3.14159, 3.14147, 3.14153, -3.14153, -3.14153, -3.14153, 3.14147, -3.14159, 3.14159 };
|
||||
|
||||
hack::comparators::source(c_array, frequencies.size(), "/mnt/raid/projects/hack/hack/bin/examples/comparators/test.txt");
|
||||
hack::comparators::compare(frequencies, "/mnt/raid/projects/hack/hack/bin/examples/comparators/test.txt", 0.000'1);
|
||||
}
|
||||
@@ -21,7 +21,6 @@ auto main(int argc, char *argv[]) -> int
|
||||
}
|
||||
catch(hack::exception& e)
|
||||
{
|
||||
hack::log().no_info();
|
||||
hack::error()(e);
|
||||
hack::log()(e);
|
||||
hack::log().reset();
|
||||
|
||||
@@ -4,11 +4,12 @@
|
||||
#include <map>
|
||||
#include "hack/logger/logger.hpp"
|
||||
#include "hack/patterns/ring_buffer.hpp"
|
||||
#include "hack/utils/timestamp.hpp"
|
||||
|
||||
auto main(int argc, char *argv[]) -> int
|
||||
{
|
||||
std::string str = "hi";
|
||||
hack::log()(str);
|
||||
|
||||
int i = 1;
|
||||
double d = 2.0;
|
||||
float f = 3.f;
|
||||
@@ -31,16 +32,17 @@ auto main(int argc, char *argv[]) -> int
|
||||
for (int i = 0; i < 10; ++i) rb.put(i);
|
||||
|
||||
hack::log().set_devider(", ");
|
||||
hack::log().no_func();
|
||||
hack::log()(1, i, 3.1f, f, 4.3, d, "asdf");
|
||||
|
||||
hack::log().set_devider(" = ");
|
||||
hack::log().on_full_path();
|
||||
hack::log()(1, i, 3.1f, f, 4.3, d, "asdf");
|
||||
hack::log().reset();
|
||||
hack::log()(1, i, 3.1f, f, 4.3, d, "asdf");
|
||||
hack::log().set_devider(", ");
|
||||
hack::log().no_func();
|
||||
hack::log().no_file();
|
||||
hack::log().no_row();
|
||||
hack::log().on_func();
|
||||
hack::log().on_file(false);
|
||||
hack::log().on_row(false);
|
||||
hack::log()(vs);
|
||||
hack::log()(l);
|
||||
hack::log()(df);
|
||||
@@ -59,6 +61,7 @@ auto main(int argc, char *argv[]) -> int
|
||||
hack::log().set_devider(", ");
|
||||
hack::log()(sti, 123, true);
|
||||
hack::log().reset();
|
||||
hack::log().on_full_path();
|
||||
hack::log()("log", 123, sti, false, 1.8f, vs);
|
||||
|
||||
hack::warn()("warn");
|
||||
@@ -67,7 +70,6 @@ auto main(int argc, char *argv[]) -> int
|
||||
hack::log()(rb);
|
||||
|
||||
hack::log()(str.c_str());
|
||||
hack::log()(str);
|
||||
|
||||
std::filesystem::path p { "/test/file/path.txt" };
|
||||
hack::log()(p);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "hack/math/max.hpp"
|
||||
#include "hack/math/math.hpp"
|
||||
#include "hack/logger/logger.hpp"
|
||||
|
||||
auto main(int argc, char *argv[]) -> int
|
||||
@@ -8,6 +8,9 @@ auto main(int argc, char *argv[]) -> int
|
||||
hack::log()(hack::math::max(4, 5));
|
||||
hack::log()(hack::math::max(c, b));
|
||||
|
||||
hack::log()(hack::math::min(4, 5));
|
||||
hack::log()(hack::math::min(c, b));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ executable(
|
||||
# 'examples/patterns/main.cpp',
|
||||
'examples/logger/main.cpp',
|
||||
# 'examples/exception/main.cpp',
|
||||
# 'examples/comparators/main.cpp',
|
||||
dependencies : deps,
|
||||
cpp_args: args,
|
||||
include_directories : inc
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
Вся работа с аудио на данный момент крутиться во круг wav.
|
||||
Т.е. что-то типа - воспроизвести/записать в mp3 или что-то подобное требует своей реализации, которой
|
||||
буду заниматься по мерее её необходимости !!!
|
||||
буду заниматься по мере её необходимости !!!
|
||||
|
||||
166
src/hack/comparators/comparators.hpp
Normal file
166
src/hack/comparators/comparators.hpp
Normal file
@@ -0,0 +1,166 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
#include <math.h>
|
||||
#include "hack/logger/logger.hpp"
|
||||
|
||||
namespace hack::comparators
|
||||
{
|
||||
template<typename T>
|
||||
inline void source(const T* array, size_t size, const std::filesystem::path& path)
|
||||
{
|
||||
// Проверяем, что указатель не нулевой
|
||||
if (!array) throw std::invalid_argument("Array pointer cannot be null");
|
||||
|
||||
// Открываем файл для записи в бинарном режиме
|
||||
std::ofstream file(path, std::ios::binary);
|
||||
if (!file.is_open()) throw std::runtime_error("Cannot open file for writing: " + path.string());
|
||||
|
||||
// Записываем размер массива (количество элементов)
|
||||
file.write(reinterpret_cast<const char*>(&size), sizeof(size_t));
|
||||
|
||||
// Записываем данные массива
|
||||
file.write(reinterpret_cast<const char*>(array), size * sizeof(T));
|
||||
|
||||
// Проверяем успешность записи
|
||||
if (!file) throw std::runtime_error("Failed to write data to file: " + path.string());
|
||||
|
||||
log().set_devider("");
|
||||
log()("Array saved to: ", path.filename(), " (size: ", size, ", type: ", typeid(T).name(), ")" );
|
||||
log().reset();
|
||||
}
|
||||
|
||||
namespace {
|
||||
struct comp_result
|
||||
{
|
||||
bool m_is_equal; // Результат сравнения
|
||||
size_t m_file_size; // Размер массива из файла
|
||||
size_t m_input_size; // Размер входного массива
|
||||
size_t m_mismatch_count; // Количество несовпадающих элементов
|
||||
std::vector<std::size_t> m_mismatch_indices; // Индексы несовпадений
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
comp_result compare_array_with_file(const std::vector<T>& in, const std::filesystem::path& path, float relative_epsilon = 1e-6f, /* 0.0001% */ float absolute_epsilon = 1e-12f) /* для чисел близких к нулю */
|
||||
{
|
||||
comp_result res{};
|
||||
|
||||
// Открываем файл для чтения в бинарном режиме
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
if (!file.is_open()) throw std::runtime_error("Cannot open file for reading: " + path.string());
|
||||
|
||||
// Читаем размер массива из файла
|
||||
size_t target_size = 0;
|
||||
file.read(reinterpret_cast<char*>(&target_size), sizeof(size_t));
|
||||
if (!file) throw std::runtime_error("Failed to read array size from file: " + path.string());
|
||||
|
||||
res.m_file_size = target_size;
|
||||
res.m_input_size = in.size();
|
||||
|
||||
// Сравниваем размеры
|
||||
if (target_size != in.size())
|
||||
{
|
||||
hack::log()("Size mismatch: file has", target_size, "elements, input has", in.size(), "elements");
|
||||
res.m_is_equal = false;
|
||||
return res;
|
||||
}
|
||||
|
||||
// Создаём вектор для данных из файла
|
||||
std::vector<T> target(target_size);
|
||||
|
||||
// Читаем данные из файла
|
||||
if (target_size > 0)
|
||||
{
|
||||
file.read(reinterpret_cast<char*>(target.data()), target_size * sizeof(T));
|
||||
if (!file) throw std::runtime_error("Failed to read data from file: " + path.string());
|
||||
}
|
||||
|
||||
// Сравниваем элементы с учётом погрешностей
|
||||
res.m_mismatch_count = 0;
|
||||
|
||||
for (std::size_t i = 0; i < target_size; ++i)
|
||||
{
|
||||
// Вычисляем абсолютную разность
|
||||
float diff = std::fabs(static_cast<float>(target[i]) - static_cast<float>(in[i]));
|
||||
|
||||
// Максимальное абсолютное значение из двух чисел
|
||||
float max_abs = std::max(std::fabs(static_cast<float>(target[i])),
|
||||
std::fabs(static_cast<float>(in[i])));
|
||||
|
||||
bool is_equal = false;
|
||||
|
||||
// Выбираем стратегию сравнения
|
||||
if (max_abs < absolute_epsilon)
|
||||
{
|
||||
// Оба числа очень маленькие (близки к нулю)
|
||||
// Используем абсолютную погрешность
|
||||
is_equal = (diff <= absolute_epsilon);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Используем относительную погрешность
|
||||
float relative_diff = diff / max_abs;
|
||||
is_equal = (relative_diff <= relative_epsilon);
|
||||
}
|
||||
|
||||
if (!is_equal)
|
||||
{
|
||||
++res.m_mismatch_count;
|
||||
res.m_mismatch_indices.push_back(i);
|
||||
|
||||
// Ограничиваем вывод для слишком большого количества несовпадений
|
||||
if (res.m_mismatch_count >= 100 && res.m_mismatch_count % 1000 == 0)
|
||||
hack::log()("Mismatch count reached", res.m_mismatch_count, "at index", i);
|
||||
}
|
||||
}
|
||||
|
||||
res.m_is_equal = (res.m_mismatch_count == 0);
|
||||
|
||||
// Финальный отчет
|
||||
if (!res.m_is_equal)
|
||||
{
|
||||
hack::log()("FALSE:", res.m_mismatch_count, "mismatches out of", target_size, "elements (", (100.0f * res.m_mismatch_count / target_size), "%)");
|
||||
|
||||
// Показываем первые 10 индексов несовпадений
|
||||
size_t examples_to_show = std::min(size_t(10), res.m_mismatch_indices.size());
|
||||
hack::log()("First", examples_to_show, "mismatch indices:");
|
||||
for (size_t j = 0; j < examples_to_show; ++j)
|
||||
{
|
||||
size_t idx = res.m_mismatch_indices[j];
|
||||
hack::log()(" [", idx, "] file:", target[idx], "vs input:", in[idx], "diff:", std::fabs(target[idx] - in[idx]));
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void compare(const std::vector<T>& in, const std::filesystem::path& path, float epsilon = 1e-6f)
|
||||
{
|
||||
auto r = compare_array_with_file(in, path, epsilon);
|
||||
log().set_devider("");
|
||||
log()("result: ", r.m_is_equal == true ? "TRUE " : "FALSE ");
|
||||
if (!r.m_is_equal)
|
||||
{
|
||||
log()("total errors: ", r.m_mismatch_count);
|
||||
log()("source size: ", r.m_file_size, " target size: ", r.m_input_size);
|
||||
log()("mismatch indices: ", r.m_mismatch_indices);
|
||||
}
|
||||
log().reset();
|
||||
|
||||
try
|
||||
{
|
||||
if (std::filesystem::exists(path))
|
||||
std::filesystem::remove(path);
|
||||
}
|
||||
catch (const std::filesystem::filesystem_error& e)
|
||||
{
|
||||
error()("Failed to delete file: ", e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <forward_list>
|
||||
@@ -265,10 +264,11 @@ namespace hack::concepts
|
||||
template<typename Container, typename Key>
|
||||
concept can_find = requires(Container c, Key&& key) { c.find(std::forward<Key>(key)); };
|
||||
|
||||
// для логирования собственных структур
|
||||
// для логирования собственных структур
|
||||
// мало где используется, только в логере для проверки и выдачи сообщения
|
||||
template<typename T>
|
||||
concept has_get_logger_data = requires(T t) {
|
||||
concept has_get_logger_data = requires(T t)
|
||||
{
|
||||
{ t.get_logger_data() };
|
||||
};
|
||||
}
|
||||
|
||||
@@ -12,51 +12,21 @@
|
||||
#include "hack/exception/exception.hpp"
|
||||
|
||||
// HERE
|
||||
// и нужно сделать реализацию где выводлится все в одной линии но при помощи цикла
|
||||
// и нужно сделать реализацию где выводится все в одной линии но при помощи цикла
|
||||
// типа такого:
|
||||
// for (auto i : range) hack::log(hack::log::line)(i);
|
||||
namespace hack
|
||||
{
|
||||
class logger : public hack::patterns::singleton<logger>
|
||||
{
|
||||
public:
|
||||
void set_location(std::source_location location) { m_location = location; }
|
||||
void set_devider(std::string devider) { m_devider = devider; }
|
||||
void no_file() { m_no_file = true; }
|
||||
void no_func() { m_no_func = true; };
|
||||
void no_row() { m_no_row = true; }
|
||||
void no_info() { no_file(); no_func(); no_row(); }
|
||||
void bool_as_number() { m_bool_as_number = true; }
|
||||
void reset()
|
||||
{
|
||||
m_no_file = m_base_config.m_no_file;
|
||||
m_no_func = m_base_config.m_no_func;
|
||||
m_no_row = m_base_config.m_no_row;
|
||||
m_devider = m_base_config.m_devider;
|
||||
m_bool_as_number = m_base_config.m_bool_as_number;
|
||||
}
|
||||
|
||||
public:
|
||||
void on_log() { m_type = type::LOG; }
|
||||
void on_warn() { m_type = type::WARN; }
|
||||
void on_error() { m_type = type::ERROR; }
|
||||
|
||||
public:
|
||||
template<typename... Args>
|
||||
void operator() (const Args&... args)
|
||||
{
|
||||
m_count = sizeof...(Args);
|
||||
prepare();
|
||||
print_impl(args...);
|
||||
}
|
||||
|
||||
private:
|
||||
// настройки по умолчанию
|
||||
struct config
|
||||
{
|
||||
bool m_no_file = false; // показывать/не показывать название файла/пути в выоде логов
|
||||
bool m_no_func = false; // показывать/не показывать название функции в выоде логов
|
||||
bool m_no_row = false; // показывать/не показывать номер строки в выоде логов
|
||||
bool m_on_file = true; // показывать/не показывать название файла/пути в выоде логов
|
||||
bool m_on_full_path = false; // показывать/не показывать название файла/пути в выоде логов
|
||||
bool m_on_func = false; // показывать/не показывать название функции в выоде логов
|
||||
bool m_on_row = true; // показывать/не показывать номер строки в выоде логов
|
||||
bool m_bool_as_number = false; // показывет bool как число или как текст (0, false);
|
||||
std::string m_devider = " "; // разделитель по умолчанию
|
||||
} m_base_config;
|
||||
@@ -68,6 +38,40 @@ namespace hack
|
||||
ERROR
|
||||
} m_type;
|
||||
|
||||
private:
|
||||
std::source_location m_location;
|
||||
std::size_t m_count = 0;
|
||||
std::string m_devider = m_base_config.m_devider;
|
||||
bool m_on_func = m_base_config.m_on_func;
|
||||
bool m_on_full_path = m_base_config.m_on_full_path;
|
||||
bool m_on_file = m_base_config.m_on_file;
|
||||
bool m_on_row = m_base_config.m_on_row;
|
||||
bool m_bool_as_number = m_base_config.m_bool_as_number;
|
||||
|
||||
public:
|
||||
void set_location(std::source_location location) { m_location = location; }
|
||||
void set_devider(std::string devider) { m_devider = devider; }
|
||||
void on_file(bool v = true) { m_on_file = v; }
|
||||
void on_full_path(bool v = true) { m_on_full_path = v; }
|
||||
void on_func(bool v = true) { m_on_func = v; };
|
||||
void on_row(bool v = true) { m_on_row = v; }
|
||||
void on_info() { on_file(); on_func(); on_row(); on_full_path(); }
|
||||
void bool_as_number(bool v = true) { m_bool_as_number = v; }
|
||||
void reset()
|
||||
{
|
||||
m_on_file = m_base_config.m_on_file;
|
||||
m_on_full_path = m_base_config.m_on_full_path;
|
||||
m_on_func = m_base_config.m_on_func;
|
||||
m_on_row = m_base_config.m_on_row;
|
||||
m_devider = m_base_config.m_devider;
|
||||
m_bool_as_number = m_base_config.m_bool_as_number;
|
||||
}
|
||||
|
||||
public:
|
||||
void on_log() { m_type = type::LOG; }
|
||||
void on_warn() { m_type = type::WARN; }
|
||||
void on_error() { m_type = type::ERROR; }
|
||||
|
||||
private:
|
||||
void prepare()
|
||||
{
|
||||
@@ -78,20 +82,25 @@ namespace hack
|
||||
ss << utils::color::bold << utils::color::green << "[ok] " << utils::color::reset;
|
||||
break;
|
||||
case type::WARN:
|
||||
ss << utils::color::bold << utils::color::magenta << "[WARN]" << utils::color::reset;
|
||||
ss << utils::color::bold << utils::color::magenta << "[WR] " << utils::color::reset;
|
||||
break;
|
||||
case type::ERROR:
|
||||
ss << utils::color::bold << utils::color::red << "[ERROR]" << utils::color::reset;
|
||||
ss << utils::color::bold << utils::color::red << "[ER] " << utils::color::reset;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!m_no_file)
|
||||
ss << utils::color::green << m_location.file_name() << ":" << utils::color::reset;
|
||||
if (m_on_file)
|
||||
{
|
||||
if (m_on_full_path)
|
||||
ss << utils::color::green << m_location.file_name() << ":" << utils::color::reset;
|
||||
else
|
||||
ss << utils::color::green << std::filesystem::path{ m_location.file_name() }.filename().string() << ":" << utils::color::reset;
|
||||
}
|
||||
|
||||
if (!m_no_func)
|
||||
if (m_on_func)
|
||||
ss << utils::color::italic << utils::color::yellow<< m_location.function_name() << utils::color::reset;
|
||||
|
||||
if (!m_no_row)
|
||||
if (m_on_row)
|
||||
ss << utils::color::bold << utils::color::blue << "[" << m_location.line() << "] " << utils::color::reset;
|
||||
|
||||
std::cout << ss.str();
|
||||
@@ -107,15 +116,15 @@ namespace hack
|
||||
|
||||
void print_impl() { std::cout << std::endl; }
|
||||
|
||||
// для строк
|
||||
template<concepts::is_string T>
|
||||
// для всех чисел
|
||||
template<concepts::is_number T>
|
||||
void print_t(const T& data)
|
||||
{
|
||||
std::cout << data << (m_count != 0 ? m_devider : "");
|
||||
}
|
||||
|
||||
// для всех чисел
|
||||
template<concepts::is_number T>
|
||||
// для строк
|
||||
template<concepts::is_string T>
|
||||
void print_t(const T& data)
|
||||
{
|
||||
std::cout << data << (m_count != 0 ? m_devider : "");
|
||||
@@ -125,7 +134,7 @@ namespace hack
|
||||
{
|
||||
std::cout << path.string() << (m_count != 0 ? m_devider : "");
|
||||
}
|
||||
|
||||
|
||||
// для bool
|
||||
template<concepts::is_bool T>
|
||||
void print_t(const T& data)
|
||||
@@ -220,7 +229,7 @@ namespace hack
|
||||
// для пользовательских типов
|
||||
// у них должен быть отпределен метод get_logger_data()
|
||||
// возвращающий один из обработанных типов
|
||||
template<concepts::not_supported T>
|
||||
template<concepts::has_get_logger_data T>
|
||||
void print_t(const T& rb)
|
||||
{
|
||||
static_assert(concepts::has_get_logger_data<T>, "Type must have get_logger_data() method that returns value_type");
|
||||
@@ -250,18 +259,9 @@ namespace hack
|
||||
std::cout << key << ": ";
|
||||
|
||||
if (value.type() == typeid(std::string))
|
||||
{
|
||||
// HERE
|
||||
// хотельсь бы написать так:
|
||||
// print_t(std::any_cast<std::string>(value));
|
||||
// но по какой-то причине на эту запись ругается clangd
|
||||
// Client clangd quit with exit code 0 and signal 11. Check log for errors: /home/chatlanin/.local/state/nvim/lsp.log
|
||||
// когда они это порявят напишем а пока... пише так:
|
||||
print_t(std::any_cast<std::string>(value).c_str());
|
||||
}
|
||||
print_t(std::any_cast<std::string>(value));
|
||||
else if (value.type() == typeid(std::filesystem::path))
|
||||
print_t(std::any_cast<std::filesystem::path>(value).c_str());
|
||||
// конец HERE выше
|
||||
|
||||
else if (value.type() == typeid(int))
|
||||
print_t(std::any_cast<int>(value));
|
||||
@@ -271,6 +271,7 @@ namespace hack
|
||||
print_t(std::any_cast<float>(value));
|
||||
else if (value.type() == typeid(bool))
|
||||
print_t(std::any_cast<bool>(value));
|
||||
|
||||
// vector
|
||||
else if (value.type() == typeid(std::vector<std::string>))
|
||||
print_t(std::any_cast<std::vector<std::string>>(value));
|
||||
@@ -280,6 +281,7 @@ namespace hack
|
||||
print_t(std::any_cast<std::vector<double>>(value));
|
||||
else if (value.type() == typeid(std::vector<float>))
|
||||
print_t(std::any_cast<std::vector<float>>(value));
|
||||
|
||||
// map
|
||||
else if (value.type() == typeid(std::map<std::string, std::string>))
|
||||
print_t(std::any_cast<std::map<std::string, std::string>>(value));
|
||||
@@ -298,14 +300,14 @@ namespace hack
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::source_location m_location;
|
||||
std::size_t m_count = 0;
|
||||
std::string m_devider = m_base_config.m_devider;
|
||||
bool m_no_func = m_base_config.m_no_func;
|
||||
bool m_no_file = m_base_config.m_no_file;
|
||||
bool m_no_row = m_base_config.m_no_row;
|
||||
bool m_bool_as_number = m_base_config.m_bool_as_number;
|
||||
public:
|
||||
template<typename... Args>
|
||||
void operator() (const Args&... args)
|
||||
{
|
||||
m_count = sizeof...(Args);
|
||||
prepare();
|
||||
print_impl(args...);
|
||||
}
|
||||
};
|
||||
|
||||
// основная функция вызова логера
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
#include <algorithm>
|
||||
|
||||
namespace hack::math
|
||||
{
|
||||
@@ -11,6 +10,12 @@ namespace hack::math
|
||||
template<typename T, typename U, typename RT = std::common_type_t<T, U>>
|
||||
inline RT max(T a, U b)
|
||||
{
|
||||
return std::max(a, b);
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
template<typename T, typename U, typename RT = std::common_type_t<T, U>>
|
||||
inline RT min(T a, U b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
}
|
||||
@@ -6,15 +6,15 @@ namespace hack::patterns
|
||||
struct no_copy
|
||||
{
|
||||
no_copy() = default;
|
||||
no_copy(const no_copy&&) = delete;
|
||||
no_copy operator=(const no_copy&&) = delete;
|
||||
no_copy(const no_copy&) = delete; // Было: const no_copy&&
|
||||
no_copy& operator=(const no_copy&) = delete; // Было: const no_copy&&
|
||||
};
|
||||
|
||||
struct no_move
|
||||
{
|
||||
no_move() = default;
|
||||
no_move(no_move&&) = delete;
|
||||
no_move operator=(no_move&&) = delete;
|
||||
no_move(no_move&&) = delete; // Было: no_move&&
|
||||
no_move& operator=(no_move&&) = delete; // Было: no_move&&
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -5,6 +5,7 @@ headers = [
|
||||
'hack/audio/play.hpp',
|
||||
'hack/audio/save.hpp',
|
||||
|
||||
'hack/comparators/comparators.hpp',
|
||||
|
||||
'hack/concepts/concepts.hpp',
|
||||
|
||||
@@ -13,7 +14,7 @@ headers = [
|
||||
|
||||
'hack/logger/logger.hpp',
|
||||
|
||||
'hack/math/max.hpp',
|
||||
'hack/math/math.hpp',
|
||||
|
||||
'hack/range/sort.hpp',
|
||||
'hack/range/save_to_file.hpp',
|
||||
|
||||
Reference in New Issue
Block a user