blob: ed7933caccddf2fb3f5681cd4ae060578121b3e5 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#ifndef __ARM_COMPUTE_TEST_TYPE_PRINTER_H__
25#define __ARM_COMPUTE_TEST_TYPE_PRINTER_H__
26
27#include "arm_compute/core/Dimensions.h"
28#include "arm_compute/core/Error.h"
29#include "arm_compute/core/Types.h"
30
31#include <ostream>
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010032#include <sstream>
33#include <string>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034
35namespace arm_compute
36{
37/** Formatted output of the Dimensions type. */
38template <typename T>
39inline ::std::ostream &operator<<(::std::ostream &os, const Dimensions<T> &dimensions)
40{
Anthony Barbier6ff3b192017-09-04 18:44:23 +010041 if(dimensions.num_dimensions() > 0)
42 {
43 os << dimensions[0];
44
45 for(unsigned int d = 1; d < dimensions.num_dimensions(); ++d)
46 {
Moritz Pflanzerc87fbf82017-07-18 14:02:10 +010047 os << "x" << dimensions[d];
Anthony Barbier6ff3b192017-09-04 18:44:23 +010048 }
49 }
50
Anthony Barbier6ff3b192017-09-04 18:44:23 +010051 return os;
52}
53
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010054//FIXME: Check why this doesn't work and the TensorShape overload is needed
55template <typename T>
56inline std::string to_string(const Dimensions<T> &dimensions)
57{
58 std::stringstream str;
59 str << dimensions;
60 return str.str();
61}
62
63inline std::string to_string(const TensorShape &shape)
64{
65 std::stringstream str;
66 str << shape;
67 return str.str();
68}
69
Georgios Pinitas7b7858d2017-06-21 16:44:24 +010070/** Formatted output of the Rectangle type. */
71inline ::std::ostream &operator<<(::std::ostream &os, const Rectangle &rect)
72{
Moritz Pflanzerc87fbf82017-07-18 14:02:10 +010073 os << rect.width << "x" << rect.height;
74 os << "+" << rect.x << "+" << rect.y;
Georgios Pinitas7b7858d2017-06-21 16:44:24 +010075
76 return os;
77}
78
Anthony Barbier6ff3b192017-09-04 18:44:23 +010079/** Formatted output of the PadStridInfo type. */
80inline ::std::ostream &operator<<(::std::ostream &os, const PadStrideInfo &pad_stride_info)
81{
Moritz Pflanzerc87fbf82017-07-18 14:02:10 +010082 os << pad_stride_info.stride().first << "," << pad_stride_info.stride().second;
83 os << ";";
84 os << pad_stride_info.pad().first << "," << pad_stride_info.pad().second;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010085
86 return os;
87}
88
Georgios Pinitas7b7858d2017-06-21 16:44:24 +010089/** Formatted output of the ROIPoolingInfo type. */
90inline ::std::ostream &operator<<(::std::ostream &os, const ROIPoolingLayerInfo &pool_info)
91{
Moritz Pflanzerc87fbf82017-07-18 14:02:10 +010092 os << pool_info.pooled_width() << "x" << pool_info.pooled_height() << "~" << pool_info.spatial_scale();
Georgios Pinitas7b7858d2017-06-21 16:44:24 +010093 return os;
94}
95
Anthony Barbier6ff3b192017-09-04 18:44:23 +010096/** Formatted output of the BorderMode type. */
97inline ::std::ostream &operator<<(::std::ostream &os, const BorderMode &mode)
98{
99 switch(mode)
100 {
101 case BorderMode::UNDEFINED:
102 os << "UNDEFINED";
103 break;
104 case BorderMode::CONSTANT:
105 os << "CONSTANT";
106 break;
107 case BorderMode::REPLICATE:
108 os << "REPLICATE";
109 break;
110 default:
111 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
112 }
113
114 return os;
115}
116
Isabella Gottardi3b77e9d2017-06-22 11:05:41 +0100117/** Formatted output of the NonLinearFilterFunction type. */
118inline ::std::ostream &operator<<(::std::ostream &os, const NonLinearFilterFunction &function)
119{
120 switch(function)
121 {
122 case NonLinearFilterFunction::MAX:
123 os << "MAX";
124 break;
125 case NonLinearFilterFunction::MEDIAN:
126 os << "MEDIAN";
127 break;
128 case NonLinearFilterFunction::MIN:
129 os << "MIN";
130 break;
131 default:
132 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
133 }
134
135 return os;
136}
137
138/** Formatted output of the MatrixPattern type. */
139inline ::std::ostream &operator<<(::std::ostream &os, const MatrixPattern &pattern)
140{
141 switch(pattern)
142 {
143 case MatrixPattern::BOX:
144 os << "BOX";
145 break;
146 case MatrixPattern::CROSS:
147 os << "CROSS";
148 break;
149 case MatrixPattern::DISK:
150 os << "DISK";
151 break;
152 case MatrixPattern::OTHER:
153 os << "OTHER";
154 break;
155 default:
156 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
157 }
158
159 return os;
160}
161
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100162/** Formatted output of the InterpolationPolicy type. */
163inline ::std::ostream &operator<<(::std::ostream &os, const InterpolationPolicy &policy)
164{
165 switch(policy)
166 {
167 case InterpolationPolicy::NEAREST_NEIGHBOR:
168 os << "NEAREST_NEIGHBOR";
169 break;
170 case InterpolationPolicy::BILINEAR:
171 os << "BILINEAR";
172 break;
173 case InterpolationPolicy::AREA:
174 os << "AREA";
175 break;
176 default:
177 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
178 }
179
180 return os;
181}
182
183/** Formatted output of the ConversionPolicy type. */
184inline ::std::ostream &operator<<(::std::ostream &os, const ConvertPolicy &policy)
185{
186 switch(policy)
187 {
188 case ConvertPolicy::WRAP:
189 os << "WRAP";
190 break;
191 case ConvertPolicy::SATURATE:
192 os << "SATURATE";
193 break;
194 default:
195 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
196 }
197
198 return os;
199}
200
201/** Formatted output of the activation function type. */
202inline ::std::ostream &operator<<(::std::ostream &os, const ActivationLayerInfo::ActivationFunction &act_function)
203{
204 switch(act_function)
205 {
206 case ActivationLayerInfo::ActivationFunction::ABS:
207 os << "ABS";
208 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100209 case ActivationLayerInfo::ActivationFunction::LINEAR:
210 os << "LINEAR";
211 break;
212 case ActivationLayerInfo::ActivationFunction::LOGISTIC:
213 os << "LOGISTIC";
214 break;
215 case ActivationLayerInfo::ActivationFunction::RELU:
216 os << "RELU";
217 break;
Georgios Pinitas579c0492017-07-12 16:12:12 +0100218 case ActivationLayerInfo::ActivationFunction::BOUNDED_RELU:
219 os << "BOUNDED_RELU";
220 break;
221 case ActivationLayerInfo::ActivationFunction::LEAKY_RELU:
222 os << "LEAKY_RELU";
223 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100224 case ActivationLayerInfo::ActivationFunction::SOFT_RELU:
225 os << "SOFT_RELU";
226 break;
227 case ActivationLayerInfo::ActivationFunction::SQRT:
228 os << "SQRT";
229 break;
230 case ActivationLayerInfo::ActivationFunction::SQUARE:
231 os << "SQUARE";
232 break;
233 case ActivationLayerInfo::ActivationFunction::TANH:
234 os << "TANH";
235 break;
236 default:
237 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
238 }
239
240 return os;
241}
242
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100243inline std::string to_string(const arm_compute::ActivationLayerInfo &info)
244{
245 std::stringstream str;
246 str << info.activation();
247 return str.str();
248}
249
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100250/** Formatted output of the NormType type. */
251inline ::std::ostream &operator<<(::std::ostream &os, const NormType &norm_type)
252{
253 switch(norm_type)
254 {
255 case NormType::CROSS_MAP:
256 os << "CROSS_MAP";
257 break;
258 case NormType::IN_MAP_1D:
259 os << "IN_MAP_1D";
260 break;
261 case NormType::IN_MAP_2D:
262 os << "IN_MAP_2D";
263 break;
264 default:
265 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
266 }
267
268 return os;
269}
270
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100271inline std::string to_string(const arm_compute::NormalizationLayerInfo &info)
272{
273 std::stringstream str;
274 str << info.type();
275 return str.str();
276}
277
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100278/** Formatted output of the PoolingType type. */
279inline ::std::ostream &operator<<(::std::ostream &os, const PoolingType &pool_type)
280{
281 switch(pool_type)
282 {
283 case PoolingType::AVG:
284 os << "AVG";
285 break;
286 case PoolingType::MAX:
287 os << "MAX";
288 break;
289 default:
290 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
291 }
292
293 return os;
294}
295
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100296/** Formatted output of @ref PoolingLayerInfo. */
297inline ::std::ostream &operator<<(::std::ostream &os, const PoolingLayerInfo &info)
298{
299 os << info.pool_type();
300
301 return os;
302}
303
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100304/** Formatted output of the RoundingPolicy type. */
305inline ::std::ostream &operator<<(::std::ostream &os, const RoundingPolicy &rounding_policy)
306{
307 switch(rounding_policy)
308 {
309 case RoundingPolicy::TO_ZERO:
310 os << "TO_ZERO";
311 break;
312 case RoundingPolicy::TO_NEAREST_UP:
313 os << "TO_NEAREST_UP";
314 break;
315 case RoundingPolicy::TO_NEAREST_EVEN:
316 os << "TO_NEAREST_EVEN";
317 break;
318 default:
319 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
320 }
321
322 return os;
323}
324
325/** Formatted output of the DataType type. */
326inline ::std::ostream &operator<<(::std::ostream &os, const DataType &data_type)
327{
328 switch(data_type)
329 {
330 case DataType::UNKNOWN:
331 os << "UNKNOWN";
332 break;
333 case DataType::U8:
334 os << "U8";
335 break;
336 case DataType::QS8:
337 os << "QS8";
338 break;
339 case DataType::S8:
340 os << "S8";
341 break;
342 case DataType::U16:
343 os << "U16";
344 break;
345 case DataType::S16:
346 os << "S16";
347 break;
Gian Marco Iodicebdb6b0b2017-06-30 12:21:00 +0100348 case DataType::QS16:
349 os << "QS16";
350 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100351 case DataType::U32:
352 os << "U32";
353 break;
354 case DataType::S32:
355 os << "S32";
356 break;
357 case DataType::U64:
358 os << "U64";
359 break;
360 case DataType::S64:
361 os << "S64";
362 break;
363 case DataType::F16:
364 os << "F16";
365 break;
366 case DataType::F32:
367 os << "F32";
368 break;
369 case DataType::F64:
370 os << "F64";
371 break;
372 case DataType::SIZET:
373 os << "SIZET";
374 break;
375 default:
376 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
377 }
378
379 return os;
380}
381
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100382inline std::string to_string(const arm_compute::DataType &data_type)
383{
384 std::stringstream str;
385 str << data_type;
386 return str.str();
387}
388
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100389/** Formatted output of the Format type. */
390inline ::std::ostream &operator<<(::std::ostream &os, const Format &format)
391{
392 switch(format)
393 {
394 case Format::UNKNOWN:
395 os << "UNKNOWN";
396 break;
397 case Format::U8:
398 os << "U8";
399 break;
400 case Format::S16:
401 os << "S16";
402 break;
403 case Format::U16:
404 os << "U16";
405 break;
406 case Format::S32:
407 os << "S32";
408 break;
409 case Format::U32:
410 os << "U32";
411 break;
412 case Format::F16:
413 os << "F16";
414 break;
415 case Format::F32:
416 os << "F32";
417 break;
418 case Format::UV88:
419 os << "UV88";
420 break;
421 case Format::RGB888:
422 os << "RGB888";
423 break;
424 case Format::RGBA8888:
425 os << "RGBA8888";
426 break;
427 case Format::YUV444:
428 os << "YUV444";
429 break;
430 case Format::YUYV422:
431 os << "YUYV422";
432 break;
433 case Format::NV12:
434 os << "NV12";
435 break;
436 case Format::NV21:
437 os << "NV21";
438 break;
439 case Format::IYUV:
440 os << "IYUV";
441 break;
442 case Format::UYVY422:
443 os << "UYVY422";
444 break;
445 default:
446 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
447 }
448
449 return os;
450}
451
452/** Formatted output of the Channel type. */
453inline ::std::ostream &operator<<(::std::ostream &os, const Channel &channel)
454{
455 switch(channel)
456 {
457 case Channel::UNKNOWN:
458 os << "UNKNOWN";
459 break;
460 case Channel::C0:
461 os << "C0";
462 break;
463 case Channel::C1:
464 os << "C1";
465 break;
466 case Channel::C2:
467 os << "C2";
468 break;
469 case Channel::C3:
470 os << "C3";
471 break;
472 case Channel::R:
473 os << "R";
474 break;
475 case Channel::G:
476 os << "G";
477 break;
478 case Channel::B:
479 os << "B";
480 break;
481 case Channel::A:
482 os << "A";
483 break;
484 case Channel::Y:
485 os << "Y";
486 break;
487 case Channel::U:
488 os << "U";
489 break;
490 case Channel::V:
491 os << "V";
492 break;
493 default:
494 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
495 }
496
497 return os;
498}
499
500/** Formatted output of the BorderSize type. */
501inline ::std::ostream &operator<<(::std::ostream &os, const BorderSize &border)
502{
Moritz Pflanzerc87fbf82017-07-18 14:02:10 +0100503 os << border.top << ","
504 << border.right << ","
505 << border.bottom << ","
506 << border.left;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100507
508 return os;
509}
510} // namespace arm_compute
Anthony Barbierac69aa12017-07-03 17:39:37 +0100511#endif /* __ARM_COMPUTE_TEST_TYPE_PRINTER_H__ */