fix abs from comparation
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
|
||||
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 };
|
||||
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 };
|
||||
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");
|
||||
hack::comparators::compare(frequencies, "/mnt/raid/projects/hack/hack/bin/examples/comparators/test.txt", 0.000'1);
|
||||
}
|
||||
|
||||
@@ -41,15 +41,14 @@ namespace hack::comparators
|
||||
size_t m_file_size; // Размер массива из файла
|
||||
size_t m_input_size; // Размер входного массива
|
||||
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>
|
||||
comp_result compare_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 epsilon = 1e-6f)
|
||||
{
|
||||
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());
|
||||
@@ -70,7 +69,7 @@ namespace hack::comparators
|
||||
}
|
||||
|
||||
// Создаём вектор для данных из файла
|
||||
std::vector<float> target(target_size);
|
||||
std::vector<T> target(target_size);
|
||||
|
||||
// Читаем данные из файла
|
||||
if (target_size > 0)
|
||||
@@ -81,10 +80,12 @@ namespace hack::comparators
|
||||
|
||||
// Сравниваем элементы с учётом погрешности
|
||||
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)
|
||||
auto def = std::fabs(target[i]) - std::fabs(in[i]);
|
||||
if (std::fabs(def) > epsilon)
|
||||
{
|
||||
hack::log()(def, target[i], in[i]);
|
||||
++res.m_mismatch_count;
|
||||
res.m_mismatch_indices.push_back(i);
|
||||
}
|
||||
@@ -92,8 +93,11 @@ namespace hack::comparators
|
||||
|
||||
res.m_is_equal = (res.m_mismatch_count == 0);
|
||||
|
||||
if (!res.m_is_equal)
|
||||
{
|
||||
log()(in);
|
||||
log()(target);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user