1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
12 #include <unordered_set>
13 #include <unordered_map>
20 #include <ie_layers.h>
22 #include <vpu/utils/extra.hpp>
23 #include <vpu/utils/containers.hpp>
27 namespace ie = InferenceEngine;
34 void printTo(std::ostream& os, const T& val) noexcept;
36 template <typename T1, typename T2>
37 void printTo(std::ostream& os, const std::pair<T1, T2>& p) noexcept;
40 void printTo(std::ostream& os, const std::vector<T>& cont) noexcept;
42 template <typename T, size_t COUNT>
43 void printTo(std::ostream& os, const std::array<T, COUNT>& cont) noexcept;
46 void printTo(std::ostream& os, const std::set<T>& cont) noexcept;
48 template <typename T, class H>
49 void printTo(std::ostream& os, const std::unordered_set<T, H>& cont) noexcept;
51 template <typename K, typename V>
52 void printTo(std::ostream& os, const std::map<K, V>& map) noexcept;
54 template <typename K, typename V, class H>
55 void printTo(std::ostream& os, const std::unordered_map<K, V, H>& map) noexcept;
57 template <typename T, int Capacity>
58 void printTo(std::ostream& os, const SmallVector<T, Capacity>& cont) noexcept;
61 void printTo(std::ostream& os, const Any& any) noexcept;
64 void printTo(std::ostream& os, const AttributesMap& attrs) noexcept;
70 void formatPrint(std::ostream& os, const char* str) noexcept;
72 template <typename T, typename... Args>
73 void formatPrint(std::ostream& os, const char* str, const T& value, const Args&... args) noexcept;
79 template <typename... Args>
80 std::string formatString(const char* str, const Args&... args) noexcept;
87 std::string toString(const T& val) noexcept;
94 void printTo(std::ostream& os, const T& val) noexcept {
98 std::cerr << "[VPU] Unknown error while printing\n";
103 template <typename T1, typename T2>
104 void printTo(std::ostream& os, const std::pair<T1, T2>& p) noexcept {
106 os << "[" << std::endl;
109 printTo(os, p.first);
113 printTo(os, p.second);
118 std::cerr << "[VPU] Unknown error while printing\n";
123 template <class Cont>
124 void printContainer(std::ostream& os, const Cont& cont) noexcept {
129 for (const auto& val : cont) {
131 if (ind + 1 < cont.size()) {
143 std::cerr << "[VPU] Unknown error while printing\n";
148 template <typename T>
149 void printTo(std::ostream& os, const std::vector<T>& cont) noexcept {
150 printContainer(os, cont);
153 template <typename T, size_t COUNT>
154 void printTo(std::ostream& os, const std::array<T, COUNT>& cont) noexcept {
155 printContainer(os, cont);
158 template <typename T>
159 void printTo(std::ostream& os, const std::set<T>& cont) noexcept {
160 printContainer(os, cont);
163 template <typename T, class H>
164 void printTo(std::ostream& os, const std::unordered_set<T, H>& cont) noexcept {
165 printContainer(os, cont);
169 void printMap(std::ostream& os, const Map& map) noexcept {
171 os << "[" << std::endl;
174 for (const auto& p : map) {
175 printTo(os, p.first);
177 printTo(os, p.second);
188 std::cerr << "[VPU] Unknown error while printing\n";
193 template <typename K, typename V>
194 void printTo(std::ostream& os, const std::map<K, V>& map) noexcept {
198 template <typename K, typename V, class H>
199 void printTo(std::ostream& os, const std::unordered_map<K, V, H>& map) noexcept {
203 template <typename T, int Capacity>
204 void printTo(std::ostream& os, const SmallVector<T, Capacity>& cont) noexcept {
205 printContainer(os, cont);
208 template <typename T, typename... Args>
209 void formatPrint(std::ostream& os, const char* str, const T& value, const Args&... args) noexcept {
213 if (*(str + 1) == '%') {
217 formatPrint(os, str + 2, args...);
225 std::cerr << "[VPU] Unknown error while printing\n";
229 std::cerr << "[VPU] Extra arguments provided to formatPrint\n";
233 template <typename T>
234 std::string toString(const T& val) noexcept {
235 std::ostringstream os;
240 template <typename... Args>
241 std::string formatString(const char* str, const Args&... args) noexcept {
242 std::ostringstream os;
243 formatPrint(os, str, args...);