1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15
16 #ifndef TENSORFLOW_LITE_DELEGATES_GPU_COMMON_TRANSFORMATIONS_MATCHING_H_
17 #define TENSORFLOW_LITE_DELEGATES_GPU_COMMON_TRANSFORMATIONS_MATCHING_H_
18
19 // A file provides predicates to match subgraphs.
20
21 #include <algorithm>
22 #include <iterator>
23 #include <string>
24 #include <vector>
25
26 namespace tflite {
27 namespace gpu {
28
29 // Returns true if a container of nodes contains nodes that all match given
30 // operation_types.
31 template <typename T>
MatchesByOperationType(const T & nodes,const std::vector<std::string> & types)32 bool MatchesByOperationType(const T& nodes,
33 const std::vector<std::string>& types) {
34 if (nodes.size() != types.size()) return false;
35 return std::mismatch(nodes.begin(), nodes.end(), types.begin(),
36 [&](typename T::value_type a, const std::string& b) {
37 return a->operation.type == b;
38 })
39 .first == nodes.end();
40 }
41
42 } // namespace gpu
43 } // namespace tflite
44
45 #endif // TENSORFLOW_LITE_DELEGATES_GPU_COMMON_TRANSFORMATIONS_MATCHING_H_
46