fix show
This commit is contained in:
@@ -55,35 +55,35 @@ namespace hack::comparators
|
|||||||
if (!file.is_open()) throw std::runtime_error("Cannot open file for reading: " + path.string());
|
if (!file.is_open()) throw std::runtime_error("Cannot open file for reading: " + path.string());
|
||||||
|
|
||||||
// Читаем размер массива из файла
|
// Читаем размер массива из файла
|
||||||
size_t file_size = 0;
|
size_t target_size = 0;
|
||||||
file.read(reinterpret_cast<char*>(&file_size), sizeof(size_t));
|
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());
|
if (!file) throw std::runtime_error("Failed to read array size from file: " + path.string());
|
||||||
|
|
||||||
res.m_file_size = file_size;
|
res.m_file_size = target_size;
|
||||||
res.m_input_size = in.size();
|
res.m_input_size = in.size();
|
||||||
|
|
||||||
// Сравниваем размеры
|
// Сравниваем размеры
|
||||||
if (file_size != in.size())
|
if (target_size != in.size())
|
||||||
{
|
{
|
||||||
res.m_is_equal = false;
|
res.m_is_equal = false;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Создаём вектор для данных из файла
|
// Создаём вектор для данных из файла
|
||||||
std::vector<float> file_array(file_size);
|
std::vector<float> target(target_size);
|
||||||
|
|
||||||
// Читаем данные из файла
|
// Читаем данные из файла
|
||||||
if (file_size > 0)
|
if (target_size > 0)
|
||||||
{
|
{
|
||||||
file.read(reinterpret_cast<char*>(file_array.data()), file_size * sizeof(float));
|
file.read(reinterpret_cast<char*>(target.data()), target_size * sizeof(float));
|
||||||
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 < file_size; ++i)
|
for (size_t i = 0; i < target_size; ++i)
|
||||||
{
|
{
|
||||||
if (std::fabs(file_array[i] - in[i]) > epsilon)
|
if (std::fabs(target[i] - in[i]) > epsilon)
|
||||||
{
|
{
|
||||||
++res.m_mismatch_count;
|
++res.m_mismatch_count;
|
||||||
res.m_mismatch_indices.push_back(i);
|
res.m_mismatch_indices.push_back(i);
|
||||||
@@ -92,6 +92,9 @@ namespace hack::comparators
|
|||||||
|
|
||||||
res.m_is_equal = (res.m_mismatch_count == 0);
|
res.m_is_equal = (res.m_mismatch_count == 0);
|
||||||
|
|
||||||
|
log()(in);
|
||||||
|
log()(target);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user