32{
33 if (first.size() != second.size())
34 {
35 throw std::runtime_error("Can not compare vectors of different sizes");
36 }
37
38 double output_errors = 0.;
39 size_t num_output_errors = 0;
40
41 for (size_t sample_index = 0; sample_index < first.size(); ++sample_index)
42 {
43 assert(first[sample_index].
size() == second[sample_index].
size());
44 for (size_t out_index = 0; out_index < first[sample_index].size(); ++out_index)
45 {
46 const Buffer &first_elementary = first[sample_index][out_index];
47 const Buffer &second_elementary = second[sample_index][out_index];
48 assert(first_elementary.size() == second_elementary.size());
49 size_t cur_size = first_elementary.size() /
luci::size(loco::DataType::FLOAT32);
50
51 double output_error = 0.;
52
53 const float *first_floats = reinterpret_cast<const float *>(first_elementary.data());
54 const float *second_floats = reinterpret_cast<const float *>(second_elementary.data());
55 for (
size_t index = 0;
index < cur_size;
index++)
56 {
57 double ref_value =
static_cast<double>(*(first_floats +
index));
58 double cur_value =
static_cast<double>(*(second_floats +
index));
59 output_error += std::fabs(ref_value - cur_value);
60 }
61 if (cur_size != 0)
62 {
63 output_errors += (output_error / cur_size);
64 num_output_errors += 1;
65 }
66 }
67 }
68
69 if (num_output_errors == 0)
70 {
71 throw std::runtime_error("Nothing to compare");
72 }
73
74 return static_cast<float>(output_errors / num_output_errors);
75}
uint32_t size(loco::DataType data_type)
Returns the size of the data type.
loco::GraphInputIndex index(const TFPlaceholder *node)
std::vector< char > Buffer