blob: f276f45db0d11cd2845cb73fce9b2cd919f8da76 [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
Sanghoon Lee70f82912017-08-24 14:21:24 +0100222inline std::string to_string(const ConvertPolicy &policy)
223{
224 std::stringstream str;
225 str << policy;
226 return str.str();
227}
228
Georgios Pinitasd9769582017-08-03 10:19:40 +0100229/** Formatted output of the Reduction Operations. */
230inline ::std::ostream &operator<<(::std::ostream &os, const ReductionOperation &op)
231{
232 switch(op)
233 {
234 case ReductionOperation::SUM_SQUARE:
235 os << "SUM_SQUARE";
236 break;
237 default:
238 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
239 }
240
241 return os;
242}
243
Sanghoon Lee70f82912017-08-24 14:21:24 +0100244inline std::string to_string(const ReductionOperation &op)
245{
246 std::stringstream str;
247 str << op;
248 return str.str();
249}
250
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100251/** Formatted output of the activation function type. */
252inline ::std::ostream &operator<<(::std::ostream &os, const ActivationLayerInfo::ActivationFunction &act_function)
253{
254 switch(act_function)
255 {
256 case ActivationLayerInfo::ActivationFunction::ABS:
257 os << "ABS";
258 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100259 case ActivationLayerInfo::ActivationFunction::LINEAR:
260 os << "LINEAR";
261 break;
262 case ActivationLayerInfo::ActivationFunction::LOGISTIC:
263 os << "LOGISTIC";
264 break;
265 case ActivationLayerInfo::ActivationFunction::RELU:
266 os << "RELU";
267 break;
Georgios Pinitas579c0492017-07-12 16:12:12 +0100268 case ActivationLayerInfo::ActivationFunction::BOUNDED_RELU:
269 os << "BOUNDED_RELU";
270 break;
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +0100271 case ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU:
272 os << "LU_BOUNDED_RELU";
273 break;
Georgios Pinitas579c0492017-07-12 16:12:12 +0100274 case ActivationLayerInfo::ActivationFunction::LEAKY_RELU:
275 os << "LEAKY_RELU";
276 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100277 case ActivationLayerInfo::ActivationFunction::SOFT_RELU:
278 os << "SOFT_RELU";
279 break;
280 case ActivationLayerInfo::ActivationFunction::SQRT:
281 os << "SQRT";
282 break;
283 case ActivationLayerInfo::ActivationFunction::SQUARE:
284 os << "SQUARE";
285 break;
286 case ActivationLayerInfo::ActivationFunction::TANH:
287 os << "TANH";
288 break;
289 default:
290 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
291 }
292
293 return os;
294}
295
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100296inline std::string to_string(const ActivationLayerInfo::ActivationFunction &function)
297{
298 std::stringstream str;
299 str << function;
300 return str.str();
301}
302
Moritz Pflanzer6db73ce2017-07-19 10:18:42 +0100303inline std::string to_string(const ActivationLayerInfo &info)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100304{
305 std::stringstream str;
306 str << info.activation();
307 return str.str();
308}
309
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100310/** Formatted output of the NormType type. */
311inline ::std::ostream &operator<<(::std::ostream &os, const NormType &norm_type)
312{
313 switch(norm_type)
314 {
315 case NormType::CROSS_MAP:
316 os << "CROSS_MAP";
317 break;
318 case NormType::IN_MAP_1D:
319 os << "IN_MAP_1D";
320 break;
321 case NormType::IN_MAP_2D:
322 os << "IN_MAP_2D";
323 break;
324 default:
325 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
326 }
327
328 return os;
329}
330
Moritz Pflanzer6db73ce2017-07-19 10:18:42 +0100331inline std::string to_string(const NormType &type)
332{
333 std::stringstream str;
334 str << type;
335 return str.str();
336}
337
338inline std::string to_string(const NormalizationLayerInfo &info)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100339{
340 std::stringstream str;
341 str << info.type();
342 return str.str();
343}
344
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100345/** Formatted output of the PoolingType type. */
346inline ::std::ostream &operator<<(::std::ostream &os, const PoolingType &pool_type)
347{
348 switch(pool_type)
349 {
350 case PoolingType::AVG:
351 os << "AVG";
352 break;
353 case PoolingType::MAX:
354 os << "MAX";
355 break;
356 default:
357 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
358 }
359
360 return os;
361}
362
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100363inline std::string to_string(const PoolingType &type)
364{
365 std::stringstream str;
366 str << type;
367 return str.str();
368}
369
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100370/** Formatted output of @ref PoolingLayerInfo. */
371inline ::std::ostream &operator<<(::std::ostream &os, const PoolingLayerInfo &info)
372{
Moritz Pflanzer95643d82017-08-31 17:10:18 +0100373 os << info.pool_type() << ";" << info.pool_size() << ";" << info.pad_stride_info();
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100374
375 return os;
376}
377
Georgios Pinitasdc460f12017-08-24 19:02:44 +0100378inline std::string to_string(const PoolingLayerInfo &info)
379{
380 std::stringstream str;
381 str << info.pool_type();
382 return str.str();
383}
384
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100385/** Formatted output of the RoundingPolicy type. */
386inline ::std::ostream &operator<<(::std::ostream &os, const RoundingPolicy &rounding_policy)
387{
388 switch(rounding_policy)
389 {
390 case RoundingPolicy::TO_ZERO:
391 os << "TO_ZERO";
392 break;
393 case RoundingPolicy::TO_NEAREST_UP:
394 os << "TO_NEAREST_UP";
395 break;
396 case RoundingPolicy::TO_NEAREST_EVEN:
397 os << "TO_NEAREST_EVEN";
398 break;
399 default:
400 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
401 }
402
403 return os;
404}
405
406/** Formatted output of the DataType type. */
407inline ::std::ostream &operator<<(::std::ostream &os, const DataType &data_type)
408{
409 switch(data_type)
410 {
411 case DataType::UNKNOWN:
412 os << "UNKNOWN";
413 break;
414 case DataType::U8:
415 os << "U8";
416 break;
417 case DataType::QS8:
418 os << "QS8";
419 break;
420 case DataType::S8:
421 os << "S8";
422 break;
423 case DataType::U16:
424 os << "U16";
425 break;
426 case DataType::S16:
427 os << "S16";
428 break;
Gian Marco Iodicebdb6b0b2017-06-30 12:21:00 +0100429 case DataType::QS16:
430 os << "QS16";
431 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100432 case DataType::U32:
433 os << "U32";
434 break;
435 case DataType::S32:
436 os << "S32";
437 break;
438 case DataType::U64:
439 os << "U64";
440 break;
441 case DataType::S64:
442 os << "S64";
443 break;
444 case DataType::F16:
445 os << "F16";
446 break;
447 case DataType::F32:
448 os << "F32";
449 break;
450 case DataType::F64:
451 os << "F64";
452 break;
453 case DataType::SIZET:
454 os << "SIZET";
455 break;
456 default:
457 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
458 }
459
460 return os;
461}
462
Moritz Pflanzer6db73ce2017-07-19 10:18:42 +0100463inline std::string to_string(const DataType &data_type)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100464{
465 std::stringstream str;
466 str << data_type;
467 return str.str();
468}
469
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100470/** Formatted output of the Format type. */
471inline ::std::ostream &operator<<(::std::ostream &os, const Format &format)
472{
473 switch(format)
474 {
475 case Format::UNKNOWN:
476 os << "UNKNOWN";
477 break;
478 case Format::U8:
479 os << "U8";
480 break;
481 case Format::S16:
482 os << "S16";
483 break;
484 case Format::U16:
485 os << "U16";
486 break;
487 case Format::S32:
488 os << "S32";
489 break;
490 case Format::U32:
491 os << "U32";
492 break;
493 case Format::F16:
494 os << "F16";
495 break;
496 case Format::F32:
497 os << "F32";
498 break;
499 case Format::UV88:
500 os << "UV88";
501 break;
502 case Format::RGB888:
503 os << "RGB888";
504 break;
505 case Format::RGBA8888:
506 os << "RGBA8888";
507 break;
508 case Format::YUV444:
509 os << "YUV444";
510 break;
511 case Format::YUYV422:
512 os << "YUYV422";
513 break;
514 case Format::NV12:
515 os << "NV12";
516 break;
517 case Format::NV21:
518 os << "NV21";
519 break;
520 case Format::IYUV:
521 os << "IYUV";
522 break;
523 case Format::UYVY422:
524 os << "UYVY422";
525 break;
526 default:
527 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
528 }
529
530 return os;
531}
532
533/** Formatted output of the Channel type. */
534inline ::std::ostream &operator<<(::std::ostream &os, const Channel &channel)
535{
536 switch(channel)
537 {
538 case Channel::UNKNOWN:
539 os << "UNKNOWN";
540 break;
541 case Channel::C0:
542 os << "C0";
543 break;
544 case Channel::C1:
545 os << "C1";
546 break;
547 case Channel::C2:
548 os << "C2";
549 break;
550 case Channel::C3:
551 os << "C3";
552 break;
553 case Channel::R:
554 os << "R";
555 break;
556 case Channel::G:
557 os << "G";
558 break;
559 case Channel::B:
560 os << "B";
561 break;
562 case Channel::A:
563 os << "A";
564 break;
565 case Channel::Y:
566 os << "Y";
567 break;
568 case Channel::U:
569 os << "U";
570 break;
571 case Channel::V:
572 os << "V";
573 break;
574 default:
575 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
576 }
577
578 return os;
579}
580
581/** Formatted output of the BorderSize type. */
582inline ::std::ostream &operator<<(::std::ostream &os, const BorderSize &border)
583{
Moritz Pflanzerc87fbf82017-07-18 14:02:10 +0100584 os << border.top << ","
585 << border.right << ","
586 << border.bottom << ","
587 << border.left;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100588
589 return os;
590}
591} // namespace arm_compute
Anthony Barbierac69aa12017-07-03 17:39:37 +0100592#endif /* __ARM_COMPUTE_TEST_TYPE_PRINTER_H__ */