fdc1a310b6f49a868131c2ada6b05ae1187a4d02
[platform/core/ml/nnfw.git] / runtime / libs / tflite / include / tflite / Diff.h
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *    http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file     Diff.h
19  * @brief    This file contains classes for testing correctess of implementation
20  * @ingroup  COM_AI_RUNTIME
21  */
22
23 #ifndef __NNFW_TFLITE_DIFF_H__
24 #define __NNFW_TFLITE_DIFF_H__
25
26 #include "tensorflow/lite/interpreter.h"
27
28 #include "misc/RandomGenerator.h"
29 #include "misc/tensor/Index.h"
30 #include "misc/tensor/Diff.h"
31 #include "misc/tensor/Shape.h"
32 #include "misc/tensor/Comparator.h"
33
34 #include "tflite/TensorView.h"
35
36 #include <functional>
37 #include <vector>
38
39 /**
40  * @brief Class to define TfLite interpreter match application
41  */
42 class TfLiteInterpMatchApp
43 {
44 public:
45   /**
46    * @brief Construct a new TfLiteInterpMatchApp object with Comparator
47    * @param[in] comparator   Comparator object for tensor comparation
48    */
49   TfLiteInterpMatchApp(const nnfw::misc::tensor::Comparator &comparator)
50       : _verbose{false}, _comparator(comparator)
51   {
52     // DO NOTHING
53   }
54
55 public:
56   /**
57    * @brief Get reference verbose for debugging information
58    * @return Reference of verbose value
59    */
60   int &verbose(void) { return _verbose; }
61
62 private:
63   int _verbose;
64
65 public:
66   /**
67    * @brief Run two interpreter and return the output matching
68    * @param[in] pure   Interpreter object of expected(with TfLite)
69    * @param[in] nnapi  Interpreter object of obtained(through NNAPI)
70    * @return  @c true if two Interpreter results are same, otherwise @c false
71    */
72   bool run(::tflite::Interpreter &pure, ::tflite::Interpreter &nnapi) const;
73   /**
74    * @brief Compare two TensorView values and return the match result
75    * @param[in] expected  TensorView object to read expected values
76    * @param[in] obtained  TensorView object to read obtained values
77    * @param[in] id        Tensor ID value used for debug message
78    * @return  @c true if two TensorView values are same, otherwise @c false
79    */
80   template <typename T>
81   bool compareSingleTensorView(const nnfw::tflite::TensorView<T> &expected,
82                                const nnfw::tflite::TensorView<T> &obtained, int id) const;
83
84 private:
85   const nnfw::misc::tensor::Comparator &_comparator;
86 };
87
88 #endif // __NNFW_TFLITE_DIFF_H__