blob: 394ee9d87c6b3759d445472afa9cffb747e26c56 [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 Pinitasdc460f12017-08-24 19:02:44 +010089inline std::string to_string(const PadStrideInfo &pad_stride_info)
90{
91 std::stringstream str;
92 str << pad_stride_info;
93 return str.str();
94}
95
Georgios Pinitas7b7858d2017-06-21 16:44:24 +010096/** Formatted output of the ROIPoolingInfo type. */
97inline ::std::ostream &operator<<(::std::ostream &os, const ROIPoolingLayerInfo &pool_info)
98{
Moritz Pflanzerc87fbf82017-07-18 14:02:10 +010099 os << pool_info.pooled_width() << "x" << pool_info.pooled_height() << "~" << pool_info.spatial_scale();
Georgios Pinitas7b7858d2017-06-21 16:44:24 +0100100 return os;
101}
102
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100103/** Formatted output of the BorderMode type. */
104inline ::std::ostream &operator<<(::std::ostream &os, const BorderMode &mode)
105{
106 switch(mode)
107 {
108 case BorderMode::UNDEFINED:
109 os << "UNDEFINED";
110 break;
111 case BorderMode::CONSTANT:
112 os << "CONSTANT";
113 break;
114 case BorderMode::REPLICATE:
115 os << "REPLICATE";
116 break;
117 default:
118 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
119 }
120
121 return os;
122}
123
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100124inline std::string to_string(const BorderMode &mode)
125{
126 std::stringstream str;
127 str << mode;
128 return str.str();
129}
130
Isabella Gottardi3b77e9d2017-06-22 11:05:41 +0100131/** Formatted output of the NonLinearFilterFunction type. */
132inline ::std::ostream &operator<<(::std::ostream &os, const NonLinearFilterFunction &function)
133{
134 switch(function)
135 {
136 case NonLinearFilterFunction::MAX:
137 os << "MAX";
138 break;
139 case NonLinearFilterFunction::MEDIAN:
140 os << "MEDIAN";
141 break;
142 case NonLinearFilterFunction::MIN:
143 os << "MIN";
144 break;
145 default:
146 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
147 }
148
149 return os;
150}
151
152/** Formatted output of the MatrixPattern type. */
153inline ::std::ostream &operator<<(::std::ostream &os, const MatrixPattern &pattern)
154{
155 switch(pattern)
156 {
157 case MatrixPattern::BOX:
158 os << "BOX";
159 break;
160 case MatrixPattern::CROSS:
161 os << "CROSS";
162 break;
163 case MatrixPattern::DISK:
164 os << "DISK";
165 break;
166 case MatrixPattern::OTHER:
167 os << "OTHER";
168 break;
169 default:
170 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
171 }
172
173 return os;
174}
175
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100176/** Formatted output of the InterpolationPolicy type. */
177inline ::std::ostream &operator<<(::std::ostream &os, const InterpolationPolicy &policy)
178{
179 switch(policy)
180 {
181 case InterpolationPolicy::NEAREST_NEIGHBOR:
182 os << "NEAREST_NEIGHBOR";
183 break;
184 case InterpolationPolicy::BILINEAR:
185 os << "BILINEAR";
186 break;
187 case InterpolationPolicy::AREA:
188 os << "AREA";
189 break;
190 default:
191 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
192 }
193
194 return os;
195}
196
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100197inline std::string to_string(const InterpolationPolicy &policy)
198{
199 std::stringstream str;
200 str << policy;
201 return str.str();
202}
203
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100204/** Formatted output of the ConversionPolicy type. */
205inline ::std::ostream &operator<<(::std::ostream &os, const ConvertPolicy &policy)
206{
207 switch(policy)
208 {
209 case ConvertPolicy::WRAP:
210 os << "WRAP";
211 break;
212 case ConvertPolicy::SATURATE:
213 os << "SATURATE";
214 break;
215 default:
216 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
217 }
218
219 return os;
220}
221
Georgios Pinitasd9769582017-08-03 10:19:40 +0100222/** Formatted output of the Reduction Operations. */
223inline ::std::ostream &operator<<(::std::ostream &os, const ReductionOperation &op)
224{
225 switch(op)
226 {
227 case ReductionOperation::SUM_SQUARE:
228 os << "SUM_SQUARE";
229 break;
230 default:
231 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
232 }
233
234 return os;
235}
236
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100237/** Formatted output of the activation function type. */
238inline ::std::ostream &operator<<(::std::ostream &os, const ActivationLayerInfo::ActivationFunction &act_function)
239{
240 switch(act_function)
241 {
242 case ActivationLayerInfo::ActivationFunction::ABS:
243 os << "ABS";
244 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100245 case ActivationLayerInfo::ActivationFunction::LINEAR:
246 os << "LINEAR";
247 break;
248 case ActivationLayerInfo::ActivationFunction::LOGISTIC:
249 os << "LOGISTIC";
250 break;
251 case ActivationLayerInfo::ActivationFunction::RELU:
252 os << "RELU";
253 break;
Georgios Pinitas579c0492017-07-12 16:12:12 +0100254 case ActivationLayerInfo::ActivationFunction::BOUNDED_RELU:
255 os << "BOUNDED_RELU";
256 break;
257 case ActivationLayerInfo::ActivationFunction::LEAKY_RELU:
258 os << "LEAKY_RELU";
259 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100260 case ActivationLayerInfo::ActivationFunction::SOFT_RELU:
261 os << "SOFT_RELU";
262 break;
263 case ActivationLayerInfo::ActivationFunction::SQRT:
264 os << "SQRT";
265 break;
266 case ActivationLayerInfo::ActivationFunction::SQUARE:
267 os << "SQUARE";
268 break;
269 case ActivationLayerInfo::ActivationFunction::TANH:
270 os << "TANH";
271 break;
272 default:
273 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
274 }
275
276 return os;
277}
278
Georgios Pinitasd9769582017-08-03 10:19:40 +0100279inline std::string to_string(const ReductionOperation &op)
280{
281 std::stringstream str;
282 str << op;
283 return str.str();
284}
285
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100286inline std::string to_string(const ActivationLayerInfo::ActivationFunction &function)
287{
288 std::stringstream str;
289 str << function;
290 return str.str();
291}
292
Moritz Pflanzer6db73ce2017-07-19 10:18:42 +0100293inline std::string to_string(const ActivationLayerInfo &info)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100294{
295 std::stringstream str;
296 str << info.activation();
297 return str.str();
298}
299
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100300/** Formatted output of the NormType type. */
301inline ::std::ostream &operator<<(::std::ostream &os, const NormType &norm_type)
302{
303 switch(norm_type)
304 {
305 case NormType::CROSS_MAP:
306 os << "CROSS_MAP";
307 break;
308 case NormType::IN_MAP_1D:
309 os << "IN_MAP_1D";
310 break;
311 case NormType::IN_MAP_2D:
312 os << "IN_MAP_2D";
313 break;
314 default:
315 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
316 }
317
318 return os;
319}
320
Moritz Pflanzer6db73ce2017-07-19 10:18:42 +0100321inline std::string to_string(const NormType &type)
322{
323 std::stringstream str;
324 str << type;
325 return str.str();
326}
327
328inline std::string to_string(const NormalizationLayerInfo &info)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100329{
330 std::stringstream str;
331 str << info.type();
332 return str.str();
333}
334
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100335/** Formatted output of the PoolingType type. */
336inline ::std::ostream &operator<<(::std::ostream &os, const PoolingType &pool_type)
337{
338 switch(pool_type)
339 {
340 case PoolingType::AVG:
341 os << "AVG";
342 break;
343 case PoolingType::MAX:
344 os << "MAX";
345 break;
346 default:
347 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
348 }
349
350 return os;
351}
352
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100353inline std::string to_string(const PoolingType &type)
354{
355 std::stringstream str;
356 str << type;
357 return str.str();
358}
359
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100360/** Formatted output of @ref PoolingLayerInfo. */
361inline ::std::ostream &operator<<(::std::ostream &os, const PoolingLayerInfo &info)
362{
363 os << info.pool_type();
364
365 return os;
366}
367
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100368inline std::string to_string(const PoolingLayerInfo &info)
369{
370 std::stringstream str;
371 str << info.pool_type();
372 return str.str();
373}
374
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100375/** Formatted output of the RoundingPolicy type. */
376inline ::std::ostream &operator<<(::std::ostream &os, const RoundingPolicy &rounding_policy)
377{
378 switch(rounding_policy)
379 {
380 case RoundingPolicy::TO_ZERO:
381 os << "TO_ZERO";
382 break;
383 case RoundingPolicy::TO_NEAREST_UP:
384 os << "TO_NEAREST_UP";
385 break;
386 case RoundingPolicy::TO_NEAREST_EVEN:
387 os << "TO_NEAREST_EVEN";
388 break;
389 default:
390 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
391 }
392
393 return os;
394}
395
396/** Formatted output of the DataType type. */
397inline ::std::ostream &operator<<(::std::ostream &os, const DataType &data_type)
398{
399 switch(data_type)
400 {
401 case DataType::UNKNOWN:
402 os << "UNKNOWN";
403 break;
404 case DataType::U8:
405 os << "U8";
406 break;
407 case DataType::QS8:
408 os << "QS8";
409 break;
410 case DataType::S8:
411 os << "S8";
412 break;
413 case DataType::U16:
414 os << "U16";
415 break;
416 case DataType::S16:
417 os << "S16";
418 break;
Gian Marco Iodicebdb6b0b2017-06-30 12:21:00 +0100419 case DataType::QS16:
420 os << "QS16";
421 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100422 case DataType::U32:
423 os << "U32";
424 break;
425 case DataType::S32:
426 os << "S32";
427 break;
428 case DataType::U64:
429 os << "U64";
430 break;
431 case DataType::S64:
432 os << "S64";
433 break;
434 case DataType::F16:
435 os << "F16";
436 break;
437 case DataType::F32:
438 os << "F32";
439 break;
440 case DataType::F64:
441 os << "F64";
442 break;
443 case DataType::SIZET:
444 os << "SIZET";
445 break;
446 default:
447 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
448 }
449
450 return os;
451}
452
Moritz Pflanzer6db73ce2017-07-19 10:18:42 +0100453inline std::string to_string(const DataType &data_type)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100454{
455 std::stringstream str;
456 str << data_type;
457 return str.str();
458}
459
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100460/** Formatted output of the Format type. */
461inline ::std::ostream &operator<<(::std::ostream &os, const Format &format)
462{
463 switch(format)
464 {
465 case Format::UNKNOWN:
466 os << "UNKNOWN";
467 break;
468 case Format::U8:
469 os << "U8";
470 break;
471 case Format::S16:
472 os << "S16";
473 break;
474 case Format::U16:
475 os << "U16";
476 break;
477 case Format::S32:
478 os << "S32";
479 break;
480 case Format::U32:
481 os << "U32";
482 break;
483 case Format::F16:
484 os << "F16";
485 break;
486 case Format::F32:
487 os << "F32";
488 break;
489 case Format::UV88:
490 os << "UV88";
491 break;
492 case Format::RGB888:
493 os << "RGB888";
494 break;
495 case Format::RGBA8888:
496 os << "RGBA8888";
497 break;
498 case Format::YUV444:
499 os << "YUV444";
500 break;
501 case Format::YUYV422:
502 os << "YUYV422";
503 break;
504 case Format::NV12:
505 os << "NV12";
506 break;
507 case Format::NV21:
508 os << "NV21";
509 break;
510 case Format::IYUV:
511 os << "IYUV";
512 break;
513 case Format::UYVY422:
514 os << "UYVY422";
515 break;
516 default:
517 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
518 }
519
520 return os;
521}
522
523/** Formatted output of the Channel type. */
524inline ::std::ostream &operator<<(::std::ostream &os, const Channel &channel)
525{
526 switch(channel)
527 {
528 case Channel::UNKNOWN:
529 os << "UNKNOWN";
530 break;
531 case Channel::C0:
532 os << "C0";
533 break;
534 case Channel::C1:
535 os << "C1";
536 break;
537 case Channel::C2:
538 os << "C2";
539 break;
540 case Channel::C3:
541 os << "C3";
542 break;
543 case Channel::R:
544 os << "R";
545 break;
546 case Channel::G:
547 os << "G";
548 break;
549 case Channel::B:
550 os << "B";
551 break;
552 case Channel::A:
553 os << "A";
554 break;
555 case Channel::Y:
556 os << "Y";
557 break;
558 case Channel::U:
559 os << "U";
560 break;
561 case Channel::V:
562 os << "V";
563 break;
564 default:
565 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
566 }
567
568 return os;
569}
570
571/** Formatted output of the BorderSize type. */
572inline ::std::ostream &operator<<(::std::ostream &os, const BorderSize &border)
573{
Moritz Pflanzerc87fbf82017-07-18 14:02:10 +0100574 os << border.top << ","
575 << border.right << ","
576 << border.bottom << ","
577 << border.left;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100578
579 return os;
580}
581} // namespace arm_compute
Anthony Barbierac69aa12017-07-03 17:39:37 +0100582#endif /* __ARM_COMPUTE_TEST_TYPE_PRINTER_H__ */