blob: 758034884c313ecbbbb2811388d202f1738ae7b2 [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
Abe Mbise4bd2cb82017-09-27 18:39:19 +010031#include "tests/Types.h"
32
Anthony Barbier6ff3b192017-09-04 18:44:23 +010033#include <ostream>
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010034#include <sstream>
35#include <string>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010036
37namespace arm_compute
38{
39/** Formatted output of the Dimensions type. */
40template <typename T>
41inline ::std::ostream &operator<<(::std::ostream &os, const Dimensions<T> &dimensions)
42{
Anthony Barbier6ff3b192017-09-04 18:44:23 +010043 if(dimensions.num_dimensions() > 0)
44 {
45 os << dimensions[0];
46
47 for(unsigned int d = 1; d < dimensions.num_dimensions(); ++d)
48 {
Moritz Pflanzerc87fbf82017-07-18 14:02:10 +010049 os << "x" << dimensions[d];
Anthony Barbier6ff3b192017-09-04 18:44:23 +010050 }
51 }
52
Anthony Barbier6ff3b192017-09-04 18:44:23 +010053 return os;
54}
55
Isabella Gottardi3b77e9d2017-06-22 11:05:41 +010056/** Formatted output of the NonLinearFilterFunction type. */
57inline ::std::ostream &operator<<(::std::ostream &os, const NonLinearFilterFunction &function)
58{
59 switch(function)
60 {
61 case NonLinearFilterFunction::MAX:
62 os << "MAX";
63 break;
64 case NonLinearFilterFunction::MEDIAN:
65 os << "MEDIAN";
66 break;
67 case NonLinearFilterFunction::MIN:
68 os << "MIN";
69 break;
70 default:
71 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
72 }
73
74 return os;
75}
76
John Richardson6f4d49f2017-09-07 11:21:10 +010077inline std::string to_string(const NonLinearFilterFunction &function)
78{
79 std::stringstream str;
80 str << function;
81 return str.str();
82}
83
Isabella Gottardi3b77e9d2017-06-22 11:05:41 +010084/** Formatted output of the MatrixPattern type. */
85inline ::std::ostream &operator<<(::std::ostream &os, const MatrixPattern &pattern)
86{
87 switch(pattern)
88 {
89 case MatrixPattern::BOX:
90 os << "BOX";
91 break;
92 case MatrixPattern::CROSS:
93 os << "CROSS";
94 break;
95 case MatrixPattern::DISK:
96 os << "DISK";
97 break;
98 case MatrixPattern::OTHER:
99 os << "OTHER";
100 break;
101 default:
102 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
103 }
104
105 return os;
106}
107
John Richardson6f4d49f2017-09-07 11:21:10 +0100108inline std::string to_string(const MatrixPattern &pattern)
109{
110 std::stringstream str;
111 str << pattern;
112 return str.str();
113}
114
Anthony Barbier2a07e182017-08-04 18:20:27 +0100115/** Formatted output of the RoundingPolicy type. */
116inline ::std::ostream &operator<<(::std::ostream &os, const RoundingPolicy &rounding_policy)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100117{
Anthony Barbier2a07e182017-08-04 18:20:27 +0100118 switch(rounding_policy)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100119 {
Anthony Barbier2a07e182017-08-04 18:20:27 +0100120 case RoundingPolicy::TO_ZERO:
121 os << "TO_ZERO";
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100122 break;
Anthony Barbier2a07e182017-08-04 18:20:27 +0100123 case RoundingPolicy::TO_NEAREST_UP:
124 os << "TO_NEAREST_UP";
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100125 break;
Anthony Barbier2a07e182017-08-04 18:20:27 +0100126 case RoundingPolicy::TO_NEAREST_EVEN:
127 os << "TO_NEAREST_EVEN";
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100128 break;
129 default:
130 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
131 }
132
133 return os;
134}
135
Anthony Barbier2a07e182017-08-04 18:20:27 +0100136/** Formatted output of the WeightsInfo type. */
137inline ::std::ostream &operator<<(::std::ostream &os, const WeightsInfo &weights_info)
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100138{
Anthony Barbier2a07e182017-08-04 18:20:27 +0100139 os << weights_info.are_reshaped() << ";";
140 os << weights_info.num_kernels() << ";" << weights_info.kernel_size().first << "," << weights_info.kernel_size().second;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100141
142 return os;
143}
144
Anthony Barbier2a07e182017-08-04 18:20:27 +0100145/** Formatted output of the ROIPoolingInfo type. */
146inline ::std::ostream &operator<<(::std::ostream &os, const ROIPoolingLayerInfo &pool_info)
Sanghoon Lee70f82912017-08-24 14:21:24 +0100147{
Anthony Barbier2a07e182017-08-04 18:20:27 +0100148 os << pool_info.pooled_width() << "x" << pool_info.pooled_height() << "~" << pool_info.spatial_scale();
Georgios Pinitasd9769582017-08-03 10:19:40 +0100149 return os;
150}
151
Abe Mbise4bd2cb82017-09-27 18:39:19 +0100152inline ::std::ostream &operator<<(::std::ostream &os, const FixedPointOp &op)
153{
154 switch(op)
155 {
156 case FixedPointOp::EXP:
157 os << "EXP";
158 break;
159 case FixedPointOp::LOG:
160 os << "LOG";
161 break;
162 case FixedPointOp::INV_SQRT:
163 os << "INV_SQRT";
164 break;
165 case FixedPointOp::RECIPROCAL:
166 os << "RECIPROCAL";
167 break;
168 default:
169 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
170 }
171
172 return os;
173}
174inline std::string to_string(const FixedPointOp &op)
175{
176 std::stringstream str;
177 str << op;
178 return str.str();
179}
180
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100181/** Formatted output of the activation function type. */
182inline ::std::ostream &operator<<(::std::ostream &os, const ActivationLayerInfo::ActivationFunction &act_function)
183{
184 switch(act_function)
185 {
186 case ActivationLayerInfo::ActivationFunction::ABS:
187 os << "ABS";
188 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100189 case ActivationLayerInfo::ActivationFunction::LINEAR:
190 os << "LINEAR";
191 break;
192 case ActivationLayerInfo::ActivationFunction::LOGISTIC:
193 os << "LOGISTIC";
194 break;
195 case ActivationLayerInfo::ActivationFunction::RELU:
196 os << "RELU";
197 break;
Georgios Pinitas579c0492017-07-12 16:12:12 +0100198 case ActivationLayerInfo::ActivationFunction::BOUNDED_RELU:
199 os << "BOUNDED_RELU";
200 break;
201 case ActivationLayerInfo::ActivationFunction::LEAKY_RELU:
202 os << "LEAKY_RELU";
203 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100204 case ActivationLayerInfo::ActivationFunction::SOFT_RELU:
205 os << "SOFT_RELU";
206 break;
207 case ActivationLayerInfo::ActivationFunction::SQRT:
208 os << "SQRT";
209 break;
Anthony Barbier2a07e182017-08-04 18:20:27 +0100210 case ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU:
211 os << "LU_BOUNDED_RELU";
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100212 case ActivationLayerInfo::ActivationFunction::SQUARE:
213 os << "SQUARE";
214 break;
215 case ActivationLayerInfo::ActivationFunction::TANH:
216 os << "TANH";
217 break;
218 default:
219 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
220 }
221
222 return os;
223}
224
Anthony Barbier2a07e182017-08-04 18:20:27 +0100225inline std::string to_string(const arm_compute::ActivationLayerInfo &info)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100226{
227 std::stringstream str;
228 str << info.activation();
229 return str.str();
230}
231
Anthony Barbier2a07e182017-08-04 18:20:27 +0100232inline std::string to_string(const arm_compute::ActivationLayerInfo::ActivationFunction &function)
233{
234 std::stringstream str;
235 str << function;
236 return str.str();
237}
238
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100239/** Formatted output of the NormType type. */
240inline ::std::ostream &operator<<(::std::ostream &os, const NormType &norm_type)
241{
242 switch(norm_type)
243 {
244 case NormType::CROSS_MAP:
245 os << "CROSS_MAP";
246 break;
247 case NormType::IN_MAP_1D:
248 os << "IN_MAP_1D";
249 break;
250 case NormType::IN_MAP_2D:
251 os << "IN_MAP_2D";
252 break;
253 default:
254 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
255 }
256
257 return os;
258}
259
Anthony Barbier2a07e182017-08-04 18:20:27 +0100260inline std::string to_string(const arm_compute::NormalizationLayerInfo &info)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100261{
262 std::stringstream str;
263 str << info.type();
264 return str.str();
265}
266
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100267/** Formatted output of the PoolingType type. */
268inline ::std::ostream &operator<<(::std::ostream &os, const PoolingType &pool_type)
269{
270 switch(pool_type)
271 {
272 case PoolingType::AVG:
273 os << "AVG";
274 break;
275 case PoolingType::MAX:
276 os << "MAX";
277 break;
Georgios Pinitascdf51452017-08-31 14:21:36 +0100278 case PoolingType::L2:
279 os << "L2";
280 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100281 default:
282 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
283 }
284
285 return os;
286}
287
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100288/** Formatted output of @ref PoolingLayerInfo. */
289inline ::std::ostream &operator<<(::std::ostream &os, const PoolingLayerInfo &info)
290{
Anthony Barbier2a07e182017-08-04 18:20:27 +0100291 os << info.pool_type();
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100292
293 return os;
294}
295
296/** Formatted output of the DataType type. */
297inline ::std::ostream &operator<<(::std::ostream &os, const DataType &data_type)
298{
299 switch(data_type)
300 {
301 case DataType::UNKNOWN:
302 os << "UNKNOWN";
303 break;
304 case DataType::U8:
305 os << "U8";
306 break;
307 case DataType::QS8:
308 os << "QS8";
309 break;
310 case DataType::S8:
311 os << "S8";
312 break;
313 case DataType::U16:
314 os << "U16";
315 break;
316 case DataType::S16:
317 os << "S16";
318 break;
Gian Marco Iodicebdb6b0b2017-06-30 12:21:00 +0100319 case DataType::QS16:
320 os << "QS16";
321 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100322 case DataType::U32:
323 os << "U32";
324 break;
325 case DataType::S32:
326 os << "S32";
327 break;
328 case DataType::U64:
329 os << "U64";
330 break;
331 case DataType::S64:
332 os << "S64";
333 break;
334 case DataType::F16:
335 os << "F16";
336 break;
337 case DataType::F32:
338 os << "F32";
339 break;
340 case DataType::F64:
341 os << "F64";
342 break;
343 case DataType::SIZET:
344 os << "SIZET";
345 break;
346 default:
347 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
348 }
349
350 return os;
351}
352
Anthony Barbier2a07e182017-08-04 18:20:27 +0100353inline std::string to_string(const arm_compute::DataType &data_type)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100354{
355 std::stringstream str;
356 str << data_type;
357 return str.str();
358}
359
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100360/** Formatted output of the Format type. */
361inline ::std::ostream &operator<<(::std::ostream &os, const Format &format)
362{
363 switch(format)
364 {
365 case Format::UNKNOWN:
366 os << "UNKNOWN";
367 break;
368 case Format::U8:
369 os << "U8";
370 break;
371 case Format::S16:
372 os << "S16";
373 break;
374 case Format::U16:
375 os << "U16";
376 break;
377 case Format::S32:
378 os << "S32";
379 break;
380 case Format::U32:
381 os << "U32";
382 break;
383 case Format::F16:
384 os << "F16";
385 break;
386 case Format::F32:
387 os << "F32";
388 break;
389 case Format::UV88:
390 os << "UV88";
391 break;
392 case Format::RGB888:
393 os << "RGB888";
394 break;
395 case Format::RGBA8888:
396 os << "RGBA8888";
397 break;
398 case Format::YUV444:
399 os << "YUV444";
400 break;
401 case Format::YUYV422:
402 os << "YUYV422";
403 break;
404 case Format::NV12:
405 os << "NV12";
406 break;
407 case Format::NV21:
408 os << "NV21";
409 break;
410 case Format::IYUV:
411 os << "IYUV";
412 break;
413 case Format::UYVY422:
414 os << "UYVY422";
415 break;
416 default:
417 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
418 }
419
420 return os;
421}
422
Moritz Pflanzer7655a672017-09-23 11:57:33 +0100423inline std::string to_string(const Format &format)
424{
425 std::stringstream str;
426 str << format;
427 return str.str();
428}
429
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100430/** Formatted output of the Channel type. */
431inline ::std::ostream &operator<<(::std::ostream &os, const Channel &channel)
432{
433 switch(channel)
434 {
435 case Channel::UNKNOWN:
436 os << "UNKNOWN";
437 break;
438 case Channel::C0:
439 os << "C0";
440 break;
441 case Channel::C1:
442 os << "C1";
443 break;
444 case Channel::C2:
445 os << "C2";
446 break;
447 case Channel::C3:
448 os << "C3";
449 break;
450 case Channel::R:
451 os << "R";
452 break;
453 case Channel::G:
454 os << "G";
455 break;
456 case Channel::B:
457 os << "B";
458 break;
459 case Channel::A:
460 os << "A";
461 break;
462 case Channel::Y:
463 os << "Y";
464 break;
465 case Channel::U:
466 os << "U";
467 break;
468 case Channel::V:
469 os << "V";
470 break;
471 default:
472 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
473 }
474
475 return os;
476}
477
Anthony Barbier2a07e182017-08-04 18:20:27 +0100478/** Formatted output of the BorderMode type. */
479inline ::std::ostream &operator<<(::std::ostream &os, const BorderMode &mode)
480{
481 switch(mode)
482 {
483 case BorderMode::UNDEFINED:
484 os << "UNDEFINED";
485 break;
486 case BorderMode::CONSTANT:
487 os << "CONSTANT";
488 break;
489 case BorderMode::REPLICATE:
490 os << "REPLICATE";
491 break;
492 default:
493 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
494 }
495
496 return os;
497}
498
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100499/** Formatted output of the BorderSize type. */
500inline ::std::ostream &operator<<(::std::ostream &os, const BorderSize &border)
501{
Moritz Pflanzerc87fbf82017-07-18 14:02:10 +0100502 os << border.top << ","
503 << border.right << ","
504 << border.bottom << ","
505 << border.left;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100506
507 return os;
508}
Anthony Barbier2a07e182017-08-04 18:20:27 +0100509
510/** Formatted output of the InterpolationPolicy type. */
511inline ::std::ostream &operator<<(::std::ostream &os, const InterpolationPolicy &policy)
512{
513 switch(policy)
514 {
515 case InterpolationPolicy::NEAREST_NEIGHBOR:
516 os << "NEAREST_NEIGHBOR";
517 break;
518 case InterpolationPolicy::BILINEAR:
519 os << "BILINEAR";
520 break;
521 case InterpolationPolicy::AREA:
522 os << "AREA";
523 break;
524 default:
525 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
526 }
527
528 return os;
529}
530
531//FIXME: Check why this doesn't work and the TensorShape overload is needed
532template <typename T>
533inline std::string to_string(const Dimensions<T> &dimensions)
534{
535 std::stringstream str;
536 str << dimensions;
537 return str.str();
538}
539
540/** Formatted output of the TensorShape type. */
541inline std::string to_string(const TensorShape &shape)
542{
543 std::stringstream str;
544 str << shape;
545 return str.str();
546}
547
548/** Formatted output of the Rectangle type. */
549inline ::std::ostream &operator<<(::std::ostream &os, const Rectangle &rect)
550{
551 os << rect.width << "x" << rect.height;
552 os << "+" << rect.x << "+" << rect.y;
553
554 return os;
555}
556
557/** Formatted output of the PadStridInfo type. */
558inline ::std::ostream &operator<<(::std::ostream &os, const PadStrideInfo &pad_stride_info)
559{
560 os << pad_stride_info.stride().first << "," << pad_stride_info.stride().second;
561 os << ";";
562 os << pad_stride_info.pad().first << "," << pad_stride_info.pad().second;
563
564 return os;
565}
566
567inline std::string to_string(const PadStrideInfo &pad_stride_info)
568{
569 std::stringstream str;
570 str << pad_stride_info;
571 return str.str();
572}
573
574inline std::string to_string(const BorderMode &mode)
575{
576 std::stringstream str;
577 str << mode;
578 return str.str();
579}
580
John Richardsonb482ce12017-09-18 12:44:01 +0100581inline std::string to_string(const BorderSize &border)
582{
583 std::stringstream str;
584 str << border;
585 return str.str();
586}
587
Anthony Barbier2a07e182017-08-04 18:20:27 +0100588inline std::string to_string(const InterpolationPolicy &policy)
589{
590 std::stringstream str;
591 str << policy;
592 return str.str();
593}
594
595/** Formatted output of the ConversionPolicy type. */
596inline ::std::ostream &operator<<(::std::ostream &os, const ConvertPolicy &policy)
597{
598 switch(policy)
599 {
600 case ConvertPolicy::WRAP:
601 os << "WRAP";
602 break;
603 case ConvertPolicy::SATURATE:
604 os << "SATURATE";
605 break;
606 default:
607 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
608 }
609
610 return os;
611}
612
613inline std::string to_string(const ConvertPolicy &policy)
614{
615 std::stringstream str;
616 str << policy;
617 return str.str();
618}
619
620/** Formatted output of the Reduction Operations. */
621inline ::std::ostream &operator<<(::std::ostream &os, const ReductionOperation &op)
622{
623 switch(op)
624 {
625 case ReductionOperation::SUM_SQUARE:
626 os << "SUM_SQUARE";
627 break;
628 default:
629 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
630 }
631
632 return os;
633}
634
635inline std::string to_string(const ReductionOperation &op)
636{
637 std::stringstream str;
638 str << op;
639 return str.str();
640}
641
642inline std::string to_string(const NormType &type)
643{
644 std::stringstream str;
645 str << type;
646 return str.str();
647}
648
649inline std::string to_string(const PoolingType &type)
650{
651 std::stringstream str;
652 str << type;
653 return str.str();
654}
655
656inline std::string to_string(const PoolingLayerInfo &info)
657{
658 std::stringstream str;
659 str << info.pool_type();
660 return str.str();
661}
662
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +0100663/** Formatted output of the KeyPoint type. */
664inline ::std::ostream &operator<<(::std::ostream &os, const KeyPoint &point)
665{
666 os << "{x=" << point.x << ","
667 << "y=" << point.y << ","
668 << "strength=" << point.strength << ","
669 << "scale=" << point.scale << ","
670 << "orientation=" << point.orientation << ","
671 << "tracking_status=" << point.tracking_status << ","
672 << "error=" << point.error << "}";
673
674 return os;
675}
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100676} // namespace arm_compute
Anthony Barbierac69aa12017-07-03 17:39:37 +0100677#endif /* __ARM_COMPUTE_TEST_TYPE_PRINTER_H__ */