Compare commits
6 Commits
1432186387
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 943af9408c | |||
| 28906c37b2 | |||
| ba5d76c49c | |||
| 7cb97ff8d9 | |||
| bf2d4efcba | |||
| 53adbf4d6e |
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
auto main(int argc, char *argv[]) -> int
|
auto main(int argc, char *argv[]) -> int
|
||||||
{
|
{
|
||||||
std::vector<float> frequencies = { 30.81, 138.59, 146.83, 155.56, 164.81, 174.61, 185.00, 196.00, 207.65, 220.00, 233.08, 246.94 };
|
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[] = { 130.81, 138.59, 146.83, 155.56, 164.81, 174.61, 185.00, 196.00, 207.65, 220.00, 233.08, 246.94 };
|
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::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");
|
hack::comparators::compare(frequencies, "/mnt/raid/projects/hack/hack/bin/examples/comparators/test.txt", 0.000'1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,12 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include "hack/logger/logger.hpp"
|
#include "hack/logger/logger.hpp"
|
||||||
#include "hack/patterns/ring_buffer.hpp"
|
#include "hack/patterns/ring_buffer.hpp"
|
||||||
#include "hack/utils/timestamp.hpp"
|
|
||||||
|
|
||||||
auto main(int argc, char *argv[]) -> int
|
auto main(int argc, char *argv[]) -> int
|
||||||
{
|
{
|
||||||
std::string str = "hi";
|
std::string str = "hi";
|
||||||
|
hack::log()(str);
|
||||||
|
|
||||||
int i = 1;
|
int i = 1;
|
||||||
double d = 2.0;
|
double d = 2.0;
|
||||||
float f = 3.f;
|
float f = 3.f;
|
||||||
@@ -69,7 +70,6 @@ auto main(int argc, char *argv[]) -> int
|
|||||||
hack::log()(rb);
|
hack::log()(rb);
|
||||||
|
|
||||||
hack::log()(str.c_str());
|
hack::log()(str.c_str());
|
||||||
hack::log()(str);
|
|
||||||
|
|
||||||
std::filesystem::path p { "/test/file/path.txt" };
|
std::filesystem::path p { "/test/file/path.txt" };
|
||||||
hack::log()(p);
|
hack::log()(p);
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ executable(
|
|||||||
# 'examples/math/main.cpp',
|
# 'examples/math/main.cpp',
|
||||||
# 'examples/range/main.cpp',
|
# 'examples/range/main.cpp',
|
||||||
# 'examples/patterns/main.cpp',
|
# 'examples/patterns/main.cpp',
|
||||||
# 'examples/logger/main.cpp',
|
'examples/logger/main.cpp',
|
||||||
# 'examples/exception/main.cpp',
|
# 'examples/exception/main.cpp',
|
||||||
'examples/comparators/main.cpp',
|
# 'examples/comparators/main.cpp',
|
||||||
dependencies : deps,
|
dependencies : deps,
|
||||||
cpp_args: args,
|
cpp_args: args,
|
||||||
include_directories : inc
|
include_directories : inc
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
Вся работа с аудио на данный момент крутиться во круг wav.
|
Вся работа с аудио на данный момент крутиться во круг wav.
|
||||||
Т.е. что-то типа - воспроизвести/записать в mp3 или что-то подобное требует своей реализации, которой
|
Т.е. что-то типа - воспроизвести/записать в mp3 или что-то подобное требует своей реализации, которой
|
||||||
буду заниматься по мерее её необходимости !!!
|
буду заниматься по мере её необходимости !!!
|
||||||
|
|||||||
@@ -37,16 +37,15 @@ namespace hack::comparators
|
|||||||
namespace {
|
namespace {
|
||||||
struct comp_result
|
struct comp_result
|
||||||
{
|
{
|
||||||
bool m_is_equal; // Результат сравнения
|
bool m_is_equal; // Результат сравнения
|
||||||
size_t m_file_size; // Размер массива из файла
|
size_t m_file_size; // Размер массива из файла
|
||||||
size_t m_input_size; // Размер входного массива
|
size_t m_input_size; // Размер входного массива
|
||||||
size_t m_mismatch_count; // Количество несовпадающих элементов
|
size_t m_mismatch_count; // Количество несовпадающих элементов
|
||||||
std::vector<size_t> m_mismatch_indices; // Индексы несовпадений
|
std::vector<std::size_t> m_mismatch_indices; // Индексы несовпадений
|
||||||
};
|
};
|
||||||
|
|
||||||
// epsilon - допустимая погрешность для float
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
comp_result compare_float_array_with_file(const std::vector<T>& in, const std::filesystem::path& path, float epsilon = 0.000'01)
|
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{};
|
comp_result res{};
|
||||||
|
|
||||||
@@ -65,35 +64,76 @@ namespace hack::comparators
|
|||||||
// Сравниваем размеры
|
// Сравниваем размеры
|
||||||
if (target_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;
|
res.m_is_equal = false;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Создаём вектор для данных из файла
|
// Создаём вектор для данных из файла
|
||||||
std::vector<float> target(target_size);
|
std::vector<T> target(target_size);
|
||||||
|
|
||||||
// Читаем данные из файла
|
// Читаем данные из файла
|
||||||
if (target_size > 0)
|
if (target_size > 0)
|
||||||
{
|
{
|
||||||
file.read(reinterpret_cast<char*>(target.data()), target_size * sizeof(float));
|
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());
|
if (!file) throw std::runtime_error("Failed to read data from file: " + path.string());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Сравниваем элементы с учётом погрешности
|
// Сравниваем элементы с учётом погрешностей
|
||||||
res.m_mismatch_count = 0;
|
res.m_mismatch_count = 0;
|
||||||
for (size_t i = 0; i < target_size; ++i)
|
|
||||||
|
for (std::size_t i = 0; i < target_size; ++i)
|
||||||
{
|
{
|
||||||
if (std::fabs(target[i] - in[i]) > epsilon)
|
// Вычисляем абсолютную разность
|
||||||
|
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_count;
|
||||||
res.m_mismatch_indices.push_back(i);
|
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);
|
res.m_is_equal = (res.m_mismatch_count == 0);
|
||||||
|
|
||||||
log()(in);
|
// Финальный отчет
|
||||||
log()(target);
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -102,7 +142,7 @@ namespace hack::comparators
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
inline void compare(const std::vector<T>& in, const std::filesystem::path& path, float epsilon = 1e-6f)
|
inline void compare(const std::vector<T>& in, const std::filesystem::path& path, float epsilon = 1e-6f)
|
||||||
{
|
{
|
||||||
auto r = compare_float_array_with_file(in, path, epsilon);
|
auto r = compare_array_with_file(in, path, epsilon);
|
||||||
log().set_devider("");
|
log().set_devider("");
|
||||||
log()("result: ", r.m_is_equal == true ? "TRUE " : "FALSE ");
|
log()("result: ", r.m_is_equal == true ? "TRUE " : "FALSE ");
|
||||||
if (!r.m_is_equal)
|
if (!r.m_is_equal)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <iostream>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <forward_list>
|
#include <forward_list>
|
||||||
@@ -265,10 +264,11 @@ namespace hack::concepts
|
|||||||
template<typename Container, typename Key>
|
template<typename Container, typename Key>
|
||||||
concept can_find = requires(Container c, Key&& key) { c.find(std::forward<Key>(key)); };
|
concept can_find = requires(Container c, Key&& key) { c.find(std::forward<Key>(key)); };
|
||||||
|
|
||||||
// для логирования собственных структур
|
// для логирования собственных структур
|
||||||
// мало где используется, только в логере для проверки и выдачи сообщения
|
// мало где используется, только в логере для проверки и выдачи сообщения
|
||||||
template<typename T>
|
template<typename T>
|
||||||
concept has_get_logger_data = requires(T t) {
|
concept has_get_logger_data = requires(T t)
|
||||||
|
{
|
||||||
{ t.get_logger_data() };
|
{ t.get_logger_data() };
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,13 +12,42 @@
|
|||||||
#include "hack/exception/exception.hpp"
|
#include "hack/exception/exception.hpp"
|
||||||
|
|
||||||
// HERE
|
// HERE
|
||||||
// и нужно сделать реализацию где выводлится все в одной линии но при помощи цикла
|
// и нужно сделать реализацию где выводится все в одной линии но при помощи цикла
|
||||||
// типа такого:
|
// типа такого:
|
||||||
// for (auto i : range) hack::log(hack::log::line)(i);
|
// for (auto i : range) hack::log(hack::log::line)(i);
|
||||||
namespace hack
|
namespace hack
|
||||||
{
|
{
|
||||||
class logger : public hack::patterns::singleton<logger>
|
class logger : public hack::patterns::singleton<logger>
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
// настройки по умолчанию
|
||||||
|
struct config
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
|
||||||
|
enum class type
|
||||||
|
{
|
||||||
|
LOG,
|
||||||
|
WARN,
|
||||||
|
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:
|
public:
|
||||||
void set_location(std::source_location location) { m_location = location; }
|
void set_location(std::source_location location) { m_location = location; }
|
||||||
void set_devider(std::string devider) { m_devider = devider; }
|
void set_devider(std::string devider) { m_devider = devider; }
|
||||||
@@ -43,34 +72,6 @@ namespace hack
|
|||||||
void on_warn() { m_type = type::WARN; }
|
void on_warn() { m_type = type::WARN; }
|
||||||
void on_error() { m_type = type::ERROR; }
|
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_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;
|
|
||||||
|
|
||||||
enum class type
|
|
||||||
{
|
|
||||||
LOG,
|
|
||||||
WARN,
|
|
||||||
ERROR
|
|
||||||
} m_type;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void prepare()
|
void prepare()
|
||||||
{
|
{
|
||||||
@@ -115,15 +116,15 @@ namespace hack
|
|||||||
|
|
||||||
void print_impl() { std::cout << std::endl; }
|
void print_impl() { std::cout << std::endl; }
|
||||||
|
|
||||||
// для строк
|
// для всех чисел
|
||||||
template<concepts::is_string T>
|
template<concepts::is_number T>
|
||||||
void print_t(const T& data)
|
void print_t(const T& data)
|
||||||
{
|
{
|
||||||
std::cout << data << (m_count != 0 ? m_devider : "");
|
std::cout << data << (m_count != 0 ? m_devider : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
// для всех чисел
|
// для строк
|
||||||
template<concepts::is_number T>
|
template<concepts::is_string T>
|
||||||
void print_t(const T& data)
|
void print_t(const T& data)
|
||||||
{
|
{
|
||||||
std::cout << data << (m_count != 0 ? m_devider : "");
|
std::cout << data << (m_count != 0 ? m_devider : "");
|
||||||
@@ -228,7 +229,7 @@ namespace hack
|
|||||||
// для пользовательских типов
|
// для пользовательских типов
|
||||||
// у них должен быть отпределен метод get_logger_data()
|
// у них должен быть отпределен метод get_logger_data()
|
||||||
// возвращающий один из обработанных типов
|
// возвращающий один из обработанных типов
|
||||||
template<concepts::not_supported T>
|
template<concepts::has_get_logger_data T>
|
||||||
void print_t(const T& rb)
|
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");
|
static_assert(concepts::has_get_logger_data<T>, "Type must have get_logger_data() method that returns value_type");
|
||||||
@@ -258,18 +259,9 @@ namespace hack
|
|||||||
std::cout << key << ": ";
|
std::cout << key << ": ";
|
||||||
|
|
||||||
if (value.type() == typeid(std::string))
|
if (value.type() == typeid(std::string))
|
||||||
{
|
print_t(std::any_cast<std::string>(value));
|
||||||
// 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());
|
|
||||||
}
|
|
||||||
else if (value.type() == typeid(std::filesystem::path))
|
else if (value.type() == typeid(std::filesystem::path))
|
||||||
print_t(std::any_cast<std::filesystem::path>(value).c_str());
|
print_t(std::any_cast<std::filesystem::path>(value).c_str());
|
||||||
// конец HERE выше
|
|
||||||
|
|
||||||
else if (value.type() == typeid(int))
|
else if (value.type() == typeid(int))
|
||||||
print_t(std::any_cast<int>(value));
|
print_t(std::any_cast<int>(value));
|
||||||
@@ -279,6 +271,7 @@ namespace hack
|
|||||||
print_t(std::any_cast<float>(value));
|
print_t(std::any_cast<float>(value));
|
||||||
else if (value.type() == typeid(bool))
|
else if (value.type() == typeid(bool))
|
||||||
print_t(std::any_cast<bool>(value));
|
print_t(std::any_cast<bool>(value));
|
||||||
|
|
||||||
// vector
|
// vector
|
||||||
else if (value.type() == typeid(std::vector<std::string>))
|
else if (value.type() == typeid(std::vector<std::string>))
|
||||||
print_t(std::any_cast<std::vector<std::string>>(value));
|
print_t(std::any_cast<std::vector<std::string>>(value));
|
||||||
@@ -288,6 +281,7 @@ namespace hack
|
|||||||
print_t(std::any_cast<std::vector<double>>(value));
|
print_t(std::any_cast<std::vector<double>>(value));
|
||||||
else if (value.type() == typeid(std::vector<float>))
|
else if (value.type() == typeid(std::vector<float>))
|
||||||
print_t(std::any_cast<std::vector<float>>(value));
|
print_t(std::any_cast<std::vector<float>>(value));
|
||||||
|
|
||||||
// map
|
// map
|
||||||
else if (value.type() == typeid(std::map<std::string, std::string>))
|
else if (value.type() == typeid(std::map<std::string, std::string>))
|
||||||
print_t(std::any_cast<std::map<std::string, std::string>>(value));
|
print_t(std::any_cast<std::map<std::string, std::string>>(value));
|
||||||
@@ -306,15 +300,14 @@ namespace hack
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
public:
|
||||||
std::source_location m_location;
|
template<typename... Args>
|
||||||
std::size_t m_count = 0;
|
void operator() (const Args&... args)
|
||||||
std::string m_devider = m_base_config.m_devider;
|
{
|
||||||
bool m_on_func = m_base_config.m_on_func;
|
m_count = sizeof...(Args);
|
||||||
bool m_on_full_path = m_base_config.m_on_full_path;
|
prepare();
|
||||||
bool m_on_file = m_base_config.m_on_file;
|
print_impl(args...);
|
||||||
bool m_on_row = m_base_config.m_on_row;
|
}
|
||||||
bool m_bool_as_number = m_base_config.m_bool_as_number;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// основная функция вызова логера
|
// основная функция вызова логера
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ namespace hack::patterns
|
|||||||
struct no_copy
|
struct no_copy
|
||||||
{
|
{
|
||||||
no_copy() = default;
|
no_copy() = default;
|
||||||
no_copy(const no_copy&&) = delete;
|
no_copy(const no_copy&) = delete; // Было: const no_copy&&
|
||||||
no_copy operator=(const no_copy&&) = delete;
|
no_copy& operator=(const no_copy&) = delete; // Было: const no_copy&&
|
||||||
};
|
};
|
||||||
|
|
||||||
struct no_move
|
struct no_move
|
||||||
{
|
{
|
||||||
no_move() = default;
|
no_move() = default;
|
||||||
no_move(no_move&&) = delete;
|
no_move(no_move&&) = delete; // Было: no_move&&
|
||||||
no_move operator=(no_move&&) = delete;
|
no_move& operator=(no_move&&) = delete; // Было: no_move&&
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|||||||
Reference in New Issue
Block a user