std::map<TfLiteType, Comparator> comparators;
+ comparators[kTfLiteInt32] = [this](int id, ::tflite::Interpreter &interp,
+ ::tflite::Interpreter &nnapi) {
+ std::vector<nnfw::util::tensor::Diff<int32_t>> diffs;
+
+ const auto expected = nnfw::support::tflite::TensorView<int32_t>::make(interp, id);
+ const auto obtained = nnfw::support::tflite::TensorView<int32_t>::make(nnapi, id);
+
+ assert(expected.shape() == obtained.shape());
+
+ using nnfw::util::tensor::zip;
+ using nnfw::util::tensor::Index;
+
+ zip(expected.shape(), expected, obtained)
+ << [&](const Index &index, int32_t expected_value, int32_t obtained_value) {
+ if (expected_value != obtained_value)
+ {
+ diffs.emplace_back(index, expected_value, obtained_value);
+ }
+ };
+
+ // TODO Unify summary generation code
+ if (diffs.size() == 0)
+ {
+ std::cout << " Tensor #" << id << ": MATCHED" << std::endl;
+ }
+ else
+ {
+ std::cout << " Tensor #" << id << ": UNMATCHED" << std::endl;
+ std::cout << " " << diffs.size() << " diffs are detected" << std::endl;
+ }
+
+ if (diffs.size() > 0 && _verbose != 0)
+ {
+ std::cout << " ---- Details ---" << std::endl;
+ for (const auto &diff : diffs)
+ {
+ std::cout << " Diff at [" << nnfw::util::tensor::IndexFormatter(diff.index) << "]"
+ << std::endl;
+ std::cout << " expected: " << diff.expected << std::endl;
+ std::cout << " obtained: " << diff.obtained << std::endl;
+ }
+ }
+
+ return diffs.size() == 0;
+ };
+
comparators[kTfLiteFloat32] = [this](int id, ::tflite::Interpreter &interp,
::tflite::Interpreter &nnapi) {
const auto expected = nnfw::support::tflite::TensorView<float>::make(interp, id);