arm_compute v18.05
[platform/upstream/armcl.git] / utils / TypePrinter.h
1 /*
2  * Copyright (c) 2017-2018 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/CL/CLTypes.h"
28 #include "arm_compute/core/Dimensions.h"
29 #include "arm_compute/core/Error.h"
30 #include "arm_compute/core/GPUTarget.h"
31 #include "arm_compute/core/HOGInfo.h"
32 #include "arm_compute/core/Size2D.h"
33 #include "arm_compute/core/Strides.h"
34 #include "arm_compute/core/TensorInfo.h"
35 #include "arm_compute/core/Types.h"
36
37 #include "tests/Types.h"
38
39 #include <ostream>
40 #include <sstream>
41 #include <string>
42
43 namespace arm_compute
44 {
45 /** Formatted output of the Dimensions type.
46  *
47  * @param[out] os         Output stream.
48  * @param[in]  dimensions Type to output.
49  *
50  * @return Modified output stream.
51  */
52 template <typename T>
53 inline ::std::ostream &operator<<(::std::ostream &os, const Dimensions<T> &dimensions)
54 {
55     if(dimensions.num_dimensions() > 0)
56     {
57         os << dimensions[0];
58
59         for(unsigned int d = 1; d < dimensions.num_dimensions(); ++d)
60         {
61             os << "x" << dimensions[d];
62         }
63     }
64
65     return os;
66 }
67
68 /** Formatted output of the NonLinearFilterFunction type.
69  *
70  * @param[out] os       Output stream.
71  * @param[in]  function Type to output.
72  *
73  * @return Modified output stream.
74  */
75 inline ::std::ostream &operator<<(::std::ostream &os, const NonLinearFilterFunction &function)
76 {
77     switch(function)
78     {
79         case NonLinearFilterFunction::MAX:
80             os << "MAX";
81             break;
82         case NonLinearFilterFunction::MEDIAN:
83             os << "MEDIAN";
84             break;
85         case NonLinearFilterFunction::MIN:
86             os << "MIN";
87             break;
88         default:
89             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
90     }
91
92     return os;
93 }
94
95 /** Formatted output of the NonLinearFilterFunction type.
96  *
97  * @param[in] function Type to output.
98  *
99  * @return Formatted string.
100  */
101 inline std::string to_string(const NonLinearFilterFunction &function)
102 {
103     std::stringstream str;
104     str << function;
105     return str.str();
106 }
107
108 /** Formatted output of the MatrixPattern type.
109  *
110  * @param[out] os      Output stream.
111  * @param[in]  pattern Type to output.
112  *
113  * @return Modified output stream.
114  */
115 inline ::std::ostream &operator<<(::std::ostream &os, const MatrixPattern &pattern)
116 {
117     switch(pattern)
118     {
119         case MatrixPattern::BOX:
120             os << "BOX";
121             break;
122         case MatrixPattern::CROSS:
123             os << "CROSS";
124             break;
125         case MatrixPattern::DISK:
126             os << "DISK";
127             break;
128         case MatrixPattern::OTHER:
129             os << "OTHER";
130             break;
131         default:
132             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
133     }
134
135     return os;
136 }
137
138 /** Formatted output of the MatrixPattern type.
139  *
140  * @param[in] pattern Type to output.
141  *
142  * @return Formatted string.
143  */
144 inline std::string to_string(const MatrixPattern &pattern)
145 {
146     std::stringstream str;
147     str << pattern;
148     return str.str();
149 }
150
151 /** Formatted output of the RoundingPolicy type.
152  *
153  * @param[out] os              Output stream.
154  * @param[in]  rounding_policy Type to output.
155  *
156  * @return Modified output stream.
157  */
158 inline ::std::ostream &operator<<(::std::ostream &os, const RoundingPolicy &rounding_policy)
159 {
160     switch(rounding_policy)
161     {
162         case RoundingPolicy::TO_ZERO:
163             os << "TO_ZERO";
164             break;
165         case RoundingPolicy::TO_NEAREST_UP:
166             os << "TO_NEAREST_UP";
167             break;
168         case RoundingPolicy::TO_NEAREST_EVEN:
169             os << "TO_NEAREST_EVEN";
170             break;
171         default:
172             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
173     }
174
175     return os;
176 }
177
178 /** Formatted output of the WeightsInfo type.
179  *
180  * @param[out] os           Output stream.
181  * @param[in]  weights_info Type to output.
182  *
183  * @return Modified output stream.
184  */
185 inline ::std::ostream &operator<<(::std::ostream &os, const WeightsInfo &weights_info)
186 {
187     os << weights_info.are_reshaped() << ";";
188     os << weights_info.num_kernels() << ";" << weights_info.kernel_size().first << "," << weights_info.kernel_size().second;
189
190     return os;
191 }
192
193 /** Formatted output of the ROIPoolingInfo type.
194  *
195  * @param[out] os        Output stream.
196  * @param[in]  pool_info Type to output.
197  *
198  * @return Modified output stream.
199  */
200 inline ::std::ostream &operator<<(::std::ostream &os, const ROIPoolingLayerInfo &pool_info)
201 {
202     os << pool_info.pooled_width() << "x" << pool_info.pooled_height() << "~" << pool_info.spatial_scale();
203     return os;
204 }
205
206 /** Formatted output of the QuantizationInfo type.
207  *
208  * @param[out] os                Output stream.
209  * @param[in]  quantization_info Type to output.
210  *
211  * @return Modified output stream.
212  */
213 inline ::std::ostream &operator<<(::std::ostream &os, const QuantizationInfo &quantization_info)
214 {
215     os << "Scale:" << quantization_info.scale << "~"
216        << "Offset:" << quantization_info.offset;
217     return os;
218 }
219
220 /** Formatted output of the QuantizationInfo type.
221  *
222  * @param[in] quantization_info Type to output.
223  *
224  * @return Formatted string.
225  */
226 inline std::string to_string(const QuantizationInfo &quantization_info)
227 {
228     std::stringstream str;
229     str << quantization_info;
230     return str.str();
231 }
232
233 /** Formatted output of the FixedPointOp type.
234  *
235  * @param[out] os Output stream.
236  * @param[in]  op Type to output.
237  *
238  * @return Modified output stream.
239  */
240 inline ::std::ostream &operator<<(::std::ostream &os, const FixedPointOp &op)
241 {
242     switch(op)
243     {
244         case FixedPointOp::ADD:
245             os << "ADD";
246             break;
247         case FixedPointOp::SUB:
248             os << "SUB";
249             break;
250         case FixedPointOp::MUL:
251             os << "MUL";
252             break;
253         case FixedPointOp::EXP:
254             os << "EXP";
255             break;
256         case FixedPointOp::LOG:
257             os << "LOG";
258             break;
259         case FixedPointOp::INV_SQRT:
260             os << "INV_SQRT";
261             break;
262         case FixedPointOp::RECIPROCAL:
263             os << "RECIPROCAL";
264             break;
265         default:
266             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
267     }
268
269     return os;
270 }
271
272 /** Formatted output of the FixedPointOp type.
273  *
274  * @param[in] op Type to output.
275  *
276  * @return Formatted string.
277  */
278 inline std::string to_string(const FixedPointOp &op)
279 {
280     std::stringstream str;
281     str << op;
282     return str.str();
283 }
284
285 /** Formatted output of the activation function type.
286  *
287  * @param[out] os           Output stream.
288  * @param[in]  act_function Type to output.
289  *
290  * @return Modified output stream.
291  */
292 inline ::std::ostream &operator<<(::std::ostream &os, const ActivationLayerInfo::ActivationFunction &act_function)
293 {
294     switch(act_function)
295     {
296         case ActivationLayerInfo::ActivationFunction::ABS:
297             os << "ABS";
298             break;
299         case ActivationLayerInfo::ActivationFunction::LINEAR:
300             os << "LINEAR";
301             break;
302         case ActivationLayerInfo::ActivationFunction::LOGISTIC:
303             os << "LOGISTIC";
304             break;
305         case ActivationLayerInfo::ActivationFunction::RELU:
306             os << "RELU";
307             break;
308         case ActivationLayerInfo::ActivationFunction::BOUNDED_RELU:
309             os << "BOUNDED_RELU";
310             break;
311         case ActivationLayerInfo::ActivationFunction::LEAKY_RELU:
312             os << "LEAKY_RELU";
313             break;
314         case ActivationLayerInfo::ActivationFunction::SOFT_RELU:
315             os << "SOFT_RELU";
316             break;
317         case ActivationLayerInfo::ActivationFunction::SQRT:
318             os << "SQRT";
319             break;
320         case ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU:
321             os << "LU_BOUNDED_RELU";
322             break;
323         case ActivationLayerInfo::ActivationFunction::SQUARE:
324             os << "SQUARE";
325             break;
326         case ActivationLayerInfo::ActivationFunction::TANH:
327             os << "TANH";
328             break;
329         default:
330             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
331     }
332
333     return os;
334 }
335
336 /** Formatted output of the activation function info type.
337  *
338  * @param[in] info Type to output.
339  *
340  * @return Formatted string.
341  */
342 inline std::string to_string(const arm_compute::ActivationLayerInfo &info)
343 {
344     std::stringstream str;
345     if(info.enabled())
346     {
347         str << info.activation();
348     }
349     return str.str();
350 }
351
352 /** Formatted output of the activation function type.
353  *
354  * @param[in] function Type to output.
355  *
356  * @return Formatted string.
357  */
358 inline std::string to_string(const arm_compute::ActivationLayerInfo::ActivationFunction &function)
359 {
360     std::stringstream str;
361     str << function;
362     return str.str();
363 }
364
365 /** Formatted output of the NormType type.
366  *
367  * @param[out] os        Output stream.
368  * @param[in]  norm_type Type to output.
369  *
370  * @return Modified output stream.
371  */
372 inline ::std::ostream &operator<<(::std::ostream &os, const NormType &norm_type)
373 {
374     switch(norm_type)
375     {
376         case NormType::CROSS_MAP:
377             os << "CROSS_MAP";
378             break;
379         case NormType::IN_MAP_1D:
380             os << "IN_MAP_1D";
381             break;
382         case NormType::IN_MAP_2D:
383             os << "IN_MAP_2D";
384             break;
385         default:
386             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
387     }
388
389     return os;
390 }
391
392 /** Formatted output of @ref NormalizationLayerInfo.
393  *
394  * @param[in] info Type to output.
395  *
396  * @return Formatted string.
397  */
398 inline std::string to_string(const arm_compute::NormalizationLayerInfo &info)
399 {
400     std::stringstream str;
401     str << info.type() << ":NormSize=" << info.norm_size();
402     return str.str();
403 }
404
405 /** Formatted output of @ref NormalizationLayerInfo.
406  *
407  * @param[out] os   Output stream.
408  * @param[in]  info Type to output.
409  *
410  * @return Modified output stream.
411  */
412 inline ::std::ostream &operator<<(::std::ostream &os, const NormalizationLayerInfo &info)
413 {
414     os << info.type() << ":NormSize=" << info.norm_size();
415     return os;
416 }
417
418 /** Formatted output of the PoolingType type.
419  *
420  * @param[out] os        Output stream.
421  * @param[in]  pool_type Type to output.
422  *
423  * @return Modified output stream.
424  */
425 inline ::std::ostream &operator<<(::std::ostream &os, const PoolingType &pool_type)
426 {
427     switch(pool_type)
428     {
429         case PoolingType::AVG:
430             os << "AVG";
431             break;
432         case PoolingType::MAX:
433             os << "MAX";
434             break;
435         case PoolingType::L2:
436             os << "L2";
437             break;
438         default:
439             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
440     }
441
442     return os;
443 }
444
445 /** Formatted output of @ref PoolingLayerInfo.
446  *
447  * @param[out] os   Output stream.
448  * @param[in]  info Type to output.
449  *
450  * @return Modified output stream.
451  */
452 inline ::std::ostream &operator<<(::std::ostream &os, const PoolingLayerInfo &info)
453 {
454     os << info.pool_type();
455
456     return os;
457 }
458
459 /** Formatted output of @ref RoundingPolicy.
460  *
461  * @param[in] rounding_policy Type to output.
462  *
463  * @return Formatted string.
464  */
465 inline std::string to_string(const RoundingPolicy &rounding_policy)
466 {
467     std::stringstream str;
468     str << rounding_policy;
469     return str.str();
470 }
471
472 /** Formatted output of the DataLayout type.
473  *
474  * @param[out] os          Output stream.
475  * @param[in]  data_layout Type to output.
476  *
477  * @return Modified output stream.
478  */
479 inline ::std::ostream &operator<<(::std::ostream &os, const DataLayout &data_layout)
480 {
481     switch(data_layout)
482     {
483         case DataLayout::UNKNOWN:
484             os << "UNKNOWN";
485             break;
486         case DataLayout::NHWC:
487             os << "NHWC";
488             break;
489         case DataLayout::NCHW:
490             os << "NCHW";
491             break;
492         default:
493             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
494     }
495
496     return os;
497 }
498
499 /** Formatted output of the DataLayout type.
500  *
501  * @param[in] data_layout Type to output.
502  *
503  * @return Formatted string.
504  */
505 inline std::string to_string(const arm_compute::DataLayout &data_layout)
506 {
507     std::stringstream str;
508     str << data_layout;
509     return str.str();
510 }
511
512 /** Formatted output of the DataType type.
513  *
514  * @param[out] os        Output stream.
515  * @param[in]  data_type Type to output.
516  *
517  * @return Modified output stream.
518  */
519 inline ::std::ostream &operator<<(::std::ostream &os, const DataType &data_type)
520 {
521     switch(data_type)
522     {
523         case DataType::UNKNOWN:
524             os << "UNKNOWN";
525             break;
526         case DataType::U8:
527             os << "U8";
528             break;
529         case DataType::QS8:
530             os << "QS8";
531             break;
532         case DataType::QASYMM8:
533             os << "QASYMM8";
534             break;
535         case DataType::S8:
536             os << "S8";
537             break;
538         case DataType::U16:
539             os << "U16";
540             break;
541         case DataType::S16:
542             os << "S16";
543             break;
544         case DataType::QS16:
545             os << "QS16";
546             break;
547         case DataType::U32:
548             os << "U32";
549             break;
550         case DataType::S32:
551             os << "S32";
552             break;
553         case DataType::U64:
554             os << "U64";
555             break;
556         case DataType::S64:
557             os << "S64";
558             break;
559         case DataType::F16:
560             os << "F16";
561             break;
562         case DataType::F32:
563             os << "F32";
564             break;
565         case DataType::F64:
566             os << "F64";
567             break;
568         case DataType::SIZET:
569             os << "SIZET";
570             break;
571         default:
572             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
573     }
574
575     return os;
576 }
577
578 /** Formatted output of the DataType type.
579  *
580  * @param[in] data_type Type to output.
581  *
582  * @return Formatted string.
583  */
584 inline std::string to_string(const arm_compute::DataType &data_type)
585 {
586     std::stringstream str;
587     str << data_type;
588     return str.str();
589 }
590
591 /** Formatted output of the Format type.
592  *
593  * @param[out] os     Output stream.
594  * @param[in]  format Type to output.
595  *
596  * @return Modified output stream.
597  */
598 inline ::std::ostream &operator<<(::std::ostream &os, const Format &format)
599 {
600     switch(format)
601     {
602         case Format::UNKNOWN:
603             os << "UNKNOWN";
604             break;
605         case Format::U8:
606             os << "U8";
607             break;
608         case Format::S16:
609             os << "S16";
610             break;
611         case Format::U16:
612             os << "U16";
613             break;
614         case Format::S32:
615             os << "S32";
616             break;
617         case Format::U32:
618             os << "U32";
619             break;
620         case Format::F16:
621             os << "F16";
622             break;
623         case Format::F32:
624             os << "F32";
625             break;
626         case Format::UV88:
627             os << "UV88";
628             break;
629         case Format::RGB888:
630             os << "RGB888";
631             break;
632         case Format::RGBA8888:
633             os << "RGBA8888";
634             break;
635         case Format::YUV444:
636             os << "YUV444";
637             break;
638         case Format::YUYV422:
639             os << "YUYV422";
640             break;
641         case Format::NV12:
642             os << "NV12";
643             break;
644         case Format::NV21:
645             os << "NV21";
646             break;
647         case Format::IYUV:
648             os << "IYUV";
649             break;
650         case Format::UYVY422:
651             os << "UYVY422";
652             break;
653         default:
654             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
655     }
656
657     return os;
658 }
659
660 /** Formatted output of the Format type.
661  *
662  * @param[in] format Type to output.
663  *
664  * @return Formatted string.
665  */
666 inline std::string to_string(const Format &format)
667 {
668     std::stringstream str;
669     str << format;
670     return str.str();
671 }
672
673 /** Formatted output of the Channel type.
674  *
675  * @param[out] os      Output stream.
676  * @param[in]  channel Type to output.
677  *
678  * @return Modified output stream.
679  */
680 inline ::std::ostream &operator<<(::std::ostream &os, const Channel &channel)
681 {
682     switch(channel)
683     {
684         case Channel::UNKNOWN:
685             os << "UNKNOWN";
686             break;
687         case Channel::C0:
688             os << "C0";
689             break;
690         case Channel::C1:
691             os << "C1";
692             break;
693         case Channel::C2:
694             os << "C2";
695             break;
696         case Channel::C3:
697             os << "C3";
698             break;
699         case Channel::R:
700             os << "R";
701             break;
702         case Channel::G:
703             os << "G";
704             break;
705         case Channel::B:
706             os << "B";
707             break;
708         case Channel::A:
709             os << "A";
710             break;
711         case Channel::Y:
712             os << "Y";
713             break;
714         case Channel::U:
715             os << "U";
716             break;
717         case Channel::V:
718             os << "V";
719             break;
720         default:
721             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
722     }
723
724     return os;
725 }
726
727 /** Formatted output of the Channel type.
728  *
729  * @param[in] channel Type to output.
730  *
731  * @return Formatted string.
732  */
733 inline std::string to_string(const Channel &channel)
734 {
735     std::stringstream str;
736     str << channel;
737     return str.str();
738 }
739
740 /** Formatted output of the BorderMode type.
741  *
742  * @param[out] os   Output stream.
743  * @param[in]  mode Type to output.
744  *
745  * @return Modified output stream.
746  */
747 inline ::std::ostream &operator<<(::std::ostream &os, const BorderMode &mode)
748 {
749     switch(mode)
750     {
751         case BorderMode::UNDEFINED:
752             os << "UNDEFINED";
753             break;
754         case BorderMode::CONSTANT:
755             os << "CONSTANT";
756             break;
757         case BorderMode::REPLICATE:
758             os << "REPLICATE";
759             break;
760         default:
761             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
762     }
763
764     return os;
765 }
766
767 /** Formatted output of the BorderSize type.
768  *
769  * @param[out] os     Output stream.
770  * @param[in]  border Type to output.
771  *
772  * @return Modified output stream.
773  */
774 inline ::std::ostream &operator<<(::std::ostream &os, const BorderSize &border)
775 {
776     os << border.top << ","
777        << border.right << ","
778        << border.bottom << ","
779        << border.left;
780
781     return os;
782 }
783
784 /** Formatted output of the InterpolationPolicy type.
785  *
786  * @param[out] os     Output stream.
787  * @param[in]  policy Type to output.
788  *
789  * @return Modified output stream.
790  */
791 inline ::std::ostream &operator<<(::std::ostream &os, const InterpolationPolicy &policy)
792 {
793     switch(policy)
794     {
795         case InterpolationPolicy::NEAREST_NEIGHBOR:
796             os << "NEAREST_NEIGHBOR";
797             break;
798         case InterpolationPolicy::BILINEAR:
799             os << "BILINEAR";
800             break;
801         case InterpolationPolicy::AREA:
802             os << "AREA";
803             break;
804         default:
805             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
806     }
807
808     return os;
809 }
810
811 /** Formatted output of the SamplingPolicy type.
812  *
813  * @param[out] os     Output stream.
814  * @param[in]  policy Type to output.
815  *
816  * @return Modified output stream.
817  */
818 inline ::std::ostream &operator<<(::std::ostream &os, const SamplingPolicy &policy)
819 {
820     switch(policy)
821     {
822         case SamplingPolicy::CENTER:
823             os << "CENTER";
824             break;
825         case SamplingPolicy::TOP_LEFT:
826             os << "TOP_LEFT";
827             break;
828         default:
829             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
830     }
831
832     return os;
833 }
834
835 /** Formatted output of the TensorInfo type.
836  *
837  * @param[in] info Type to output.
838  *
839  * @return Formatted string.
840  */
841 inline std::string to_string(const TensorInfo &info)
842 {
843     std::stringstream str;
844     str << "{Shape=" << info.tensor_shape() << ","
845         << "Type=" << info.data_type() << ","
846         << "Channels=" << info.num_channels() << ","
847         << "FixedPointPos=" << info.fixed_point_position() << "}";
848     return str.str();
849 }
850
851 /** Formatted output of the Dimensions type.
852  *
853  * @param[in] dimensions Type to output.
854  *
855  * @return Formatted string.
856  */
857 template <typename T>
858 inline std::string to_string(const Dimensions<T> &dimensions)
859 {
860     std::stringstream str;
861     str << dimensions;
862     return str.str();
863 }
864
865 /** Formatted output of the Strides type.
866  *
867  * @param[in] stride Type to output.
868  *
869  * @return Formatted string.
870  */
871 inline std::string to_string(const Strides &stride)
872 {
873     std::stringstream str;
874     str << stride;
875     return str.str();
876 }
877
878 /** Formatted output of the TensorShape type.
879  *
880  * @param[in] shape Type to output.
881  *
882  * @return Formatted string.
883  */
884 inline std::string to_string(const TensorShape &shape)
885 {
886     std::stringstream str;
887     str << shape;
888     return str.str();
889 }
890
891 /** Formatted output of the Coordinates type.
892  *
893  * @param[in] coord Type to output.
894  *
895  * @return Formatted string.
896  */
897 inline std::string to_string(const Coordinates &coord)
898 {
899     std::stringstream str;
900     str << coord;
901     return str.str();
902 }
903
904 /** Formatted output of the Rectangle type.
905  *
906  * @param[out] os   Output stream.
907  * @param[in]  rect Type to output.
908  *
909  * @return Modified output stream.
910  */
911 inline ::std::ostream &operator<<(::std::ostream &os, const Rectangle &rect)
912 {
913     os << rect.width << "x" << rect.height;
914     os << "+" << rect.x << "+" << rect.y;
915
916     return os;
917 }
918
919 /** Formatted output of the PadStrideInfo type.
920  *
921  * @param[out] os              Output stream.
922  * @param[in]  pad_stride_info Type to output.
923  *
924  * @return Modified output stream.
925  */
926 inline ::std::ostream &operator<<(::std::ostream &os, const PadStrideInfo &pad_stride_info)
927 {
928     os << pad_stride_info.stride().first << "," << pad_stride_info.stride().second;
929     os << ";";
930     os << pad_stride_info.pad_left() << "," << pad_stride_info.pad_right() << ","
931        << pad_stride_info.pad_top() << "," << pad_stride_info.pad_bottom();
932
933     return os;
934 }
935
936 /** Formatted output of the PadStrideInfo type.
937  *
938  * @param[in] pad_stride_info Type to output.
939  *
940  * @return Formatted string.
941  */
942 inline std::string to_string(const PadStrideInfo &pad_stride_info)
943 {
944     std::stringstream str;
945     str << pad_stride_info;
946     return str.str();
947 }
948
949 /** Formatted output of the BorderMode type.
950  *
951  * @param[in] mode Type to output.
952  *
953  * @return Formatted string.
954  */
955 inline std::string to_string(const BorderMode &mode)
956 {
957     std::stringstream str;
958     str << mode;
959     return str.str();
960 }
961
962 /** Formatted output of the BorderSize type.
963  *
964  * @param[in] border Type to output.
965  *
966  * @return Formatted string.
967  */
968 inline std::string to_string(const BorderSize &border)
969 {
970     std::stringstream str;
971     str << border;
972     return str.str();
973 }
974
975 /** Formatted output of the InterpolationPolicy type.
976  *
977  * @param[in] policy Type to output.
978  *
979  * @return Formatted string.
980  */
981 inline std::string to_string(const InterpolationPolicy &policy)
982 {
983     std::stringstream str;
984     str << policy;
985     return str.str();
986 }
987
988 /** Formatted output of the SamplingPolicy type.
989  *
990  * @param[in] policy Type to output.
991  *
992  * @return Formatted string.
993  */
994 inline std::string to_string(const SamplingPolicy &policy)
995 {
996     std::stringstream str;
997     str << policy;
998     return str.str();
999 }
1000
1001 /** Formatted output of the ConvertPolicy type.
1002  *
1003  * @param[out] os     Output stream.
1004  * @param[in]  policy Type to output.
1005  *
1006  * @return Modified output stream.
1007  */
1008 inline ::std::ostream &operator<<(::std::ostream &os, const ConvertPolicy &policy)
1009 {
1010     switch(policy)
1011     {
1012         case ConvertPolicy::WRAP:
1013             os << "WRAP";
1014             break;
1015         case ConvertPolicy::SATURATE:
1016             os << "SATURATE";
1017             break;
1018         default:
1019             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
1020     }
1021
1022     return os;
1023 }
1024
1025 inline std::string to_string(const ConvertPolicy &policy)
1026 {
1027     std::stringstream str;
1028     str << policy;
1029     return str.str();
1030 }
1031
1032 /** Formatted output of the Reduction Operations.
1033  *
1034  * @param[out] os Output stream.
1035  * @param[in]  op Type to output.
1036  *
1037  * @return Modified output stream.
1038  */
1039 inline ::std::ostream &operator<<(::std::ostream &os, const ReductionOperation &op)
1040 {
1041     switch(op)
1042     {
1043         case ReductionOperation::SUM_SQUARE:
1044             os << "SUM_SQUARE";
1045             break;
1046         default:
1047             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
1048     }
1049
1050     return os;
1051 }
1052
1053 /** Formatted output of the Reduction Operations.
1054  *
1055  * @param[in] op Type to output.
1056  *
1057  * @return Formatted string.
1058  */
1059 inline std::string to_string(const ReductionOperation &op)
1060 {
1061     std::stringstream str;
1062     str << op;
1063     return str.str();
1064 }
1065
1066 /** Formatted output of the Norm Type.
1067  *
1068  * @param[in] type Type to output.
1069  *
1070  * @return Formatted string.
1071  */
1072 inline std::string to_string(const NormType &type)
1073 {
1074     std::stringstream str;
1075     str << type;
1076     return str.str();
1077 }
1078
1079 /** Formatted output of the Pooling Type.
1080  *
1081  * @param[in] type Type to output.
1082  *
1083  * @return Formatted string.
1084  */
1085 inline std::string to_string(const PoolingType &type)
1086 {
1087     std::stringstream str;
1088     str << type;
1089     return str.str();
1090 }
1091
1092 /** Formatted output of the Pooling Layer Info.
1093  *
1094  * @param[in] info Type to output.
1095  *
1096  * @return Formatted string.
1097  */
1098 inline std::string to_string(const PoolingLayerInfo &info)
1099 {
1100     std::stringstream str;
1101     str << "{Type=" << info.pool_type() << ","
1102         << "IsGlobalPooling=" << info.is_global_pooling();
1103     if(!info.is_global_pooling())
1104     {
1105         str << ","
1106             << "PoolSize=" << info.pool_size().width << "," << info.pool_size().height << ","
1107             << "PadStride=" << info.pad_stride_info();
1108     }
1109     str << "}";
1110     return str.str();
1111 }
1112
1113 /** Formatted output of the KeyPoint type.
1114  *
1115  * @param[out] os    Output stream
1116  * @param[in]  point Type to output.
1117  *
1118  * @return Modified output stream.
1119  */
1120 inline ::std::ostream &operator<<(::std::ostream &os, const KeyPoint &point)
1121 {
1122     os << "{x=" << point.x << ","
1123        << "y=" << point.y << ","
1124        << "strength=" << point.strength << ","
1125        << "scale=" << point.scale << ","
1126        << "orientation=" << point.orientation << ","
1127        << "tracking_status=" << point.tracking_status << ","
1128        << "error=" << point.error << "}";
1129
1130     return os;
1131 }
1132
1133 /** Formatted output of the PhaseType type.
1134  *
1135  * @param[out] os         Output stream
1136  * @param[in]  phase_type Type to output.
1137  *
1138  * @return Modified output stream.
1139  */
1140 inline ::std::ostream &operator<<(::std::ostream &os, const PhaseType &phase_type)
1141 {
1142     switch(phase_type)
1143     {
1144         case PhaseType::SIGNED:
1145             os << "SIGNED";
1146             break;
1147         case PhaseType::UNSIGNED:
1148             os << "UNSIGNED";
1149             break;
1150         default:
1151             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
1152     }
1153
1154     return os;
1155 }
1156
1157 /** Formatted output of the PhaseType type.
1158  *
1159  * @param[in] type Type to output.
1160  *
1161  * @return Formatted string.
1162  */
1163 inline std::string to_string(const arm_compute::PhaseType &type)
1164 {
1165     std::stringstream str;
1166     str << type;
1167     return str.str();
1168 }
1169
1170 /** Formatted output of the MagnitudeType type.
1171  *
1172  * @param[out] os             Output stream
1173  * @param[in]  magnitude_type Type to output.
1174  *
1175  * @return Modified output stream.
1176  */
1177 inline ::std::ostream &operator<<(::std::ostream &os, const MagnitudeType &magnitude_type)
1178 {
1179     switch(magnitude_type)
1180     {
1181         case MagnitudeType::L1NORM:
1182             os << "L1NORM";
1183             break;
1184         case MagnitudeType::L2NORM:
1185             os << "L2NORM";
1186             break;
1187         default:
1188             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
1189     }
1190
1191     return os;
1192 }
1193
1194 /** Formatted output of the MagnitudeType type.
1195  *
1196  * @param[in] type Type to output.
1197  *
1198  * @return Formatted string.
1199  */
1200 inline std::string to_string(const arm_compute::MagnitudeType &type)
1201 {
1202     std::stringstream str;
1203     str << type;
1204     return str.str();
1205 }
1206
1207 /** Formatted output of the GradientDimension type.
1208  *
1209  * @param[out] os  Output stream
1210  * @param[in]  dim Type to output
1211  *
1212  * @return Modified output stream.
1213  */
1214 inline ::std::ostream &operator<<(::std::ostream &os, const GradientDimension &dim)
1215 {
1216     switch(dim)
1217     {
1218         case GradientDimension::GRAD_X:
1219             os << "GRAD_X";
1220             break;
1221         case GradientDimension::GRAD_Y:
1222             os << "GRAD_Y";
1223             break;
1224         case GradientDimension::GRAD_XY:
1225             os << "GRAD_XY";
1226             break;
1227         default:
1228             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
1229     }
1230
1231     return os;
1232 }
1233
1234 /** Formatted output of the GradientDimension type.
1235  *
1236  * @param[in] type Type to output
1237  *
1238  * @return Formatted string.
1239  */
1240 inline std::string to_string(const arm_compute::GradientDimension &type)
1241 {
1242     std::stringstream str;
1243     str << type;
1244     return str.str();
1245 }
1246
1247 /** Formatted output of the HOGNormType type.
1248  *
1249  * @param[out] os        Output stream
1250  * @param[in]  norm_type Type to output
1251  *
1252  * @return Modified output stream.
1253  */
1254 inline ::std::ostream &operator<<(::std::ostream &os, const HOGNormType &norm_type)
1255 {
1256     switch(norm_type)
1257     {
1258         case HOGNormType::L1_NORM:
1259             os << "L1_NORM";
1260             break;
1261         case HOGNormType::L2_NORM:
1262             os << "L2_NORM";
1263             break;
1264         case HOGNormType::L2HYS_NORM:
1265             os << "L2HYS_NORM";
1266             break;
1267         default:
1268             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
1269     }
1270
1271     return os;
1272 }
1273
1274 /** Formatted output of the HOGNormType type.
1275  *
1276  * @param[in] type Type to output
1277  *
1278  * @return Formatted string.
1279  */
1280 inline std::string to_string(const HOGNormType &type)
1281 {
1282     std::stringstream str;
1283     str << type;
1284     return str.str();
1285 }
1286
1287 /** Formatted output of the Size2D type.
1288  *
1289  * @param[out] os   Output stream
1290  * @param[in]  size Type to output
1291  *
1292  * @return Modified output stream.
1293  */
1294 inline ::std::ostream &operator<<(::std::ostream &os, const Size2D &size)
1295 {
1296     os << size.width << "x" << size.height;
1297
1298     return os;
1299 }
1300
1301 /** Formatted output of the Size2D type.
1302  *
1303  * @param[in] type Type to output
1304  *
1305  * @return Formatted string.
1306  */
1307 inline std::string to_string(const Size2D &type)
1308 {
1309     std::stringstream str;
1310     str << type;
1311     return str.str();
1312 }
1313
1314 /** Formatted output of the HOGInfo type.
1315  *
1316  * @param[out] os       Output stream
1317  * @param[in]  hog_info Type to output
1318  *
1319  * @return Modified output stream.
1320  */
1321 inline ::std::ostream &operator<<(::std::ostream &os, const HOGInfo &hog_info)
1322 {
1323     os << "{CellSize=" << hog_info.cell_size() << ","
1324        << "BlockSize=" << hog_info.block_size() << ","
1325        << "DetectionWindowSize=" << hog_info.detection_window_size() << ","
1326        << "BlockStride=" << hog_info.block_stride() << ","
1327        << "NumBins=" << hog_info.num_bins() << ","
1328        << "NormType=" << hog_info.normalization_type() << ","
1329        << "L2HystThreshold=" << hog_info.l2_hyst_threshold() << ","
1330        << "PhaseType=" << hog_info.phase_type() << "}";
1331
1332     return os;
1333 }
1334
1335 /** Formatted output of the HOGInfo type.
1336  *
1337  * @param[in] type Type to output
1338  *
1339  * @return Formatted string.
1340  */
1341 inline std::string to_string(const HOGInfo &type)
1342 {
1343     std::stringstream str;
1344     str << type;
1345     return str.str();
1346 }
1347
1348 /** Formatted output of the ConvolutionMethod type.
1349  *
1350  * @param[out] os          Output stream
1351  * @param[in]  conv_method Type to output
1352  *
1353  * @return Modified output stream.
1354  */
1355 inline ::std::ostream &operator<<(::std::ostream &os, const ConvolutionMethod &conv_method)
1356 {
1357     switch(conv_method)
1358     {
1359         case ConvolutionMethod::GEMM:
1360             os << "GEMM";
1361             break;
1362         case ConvolutionMethod::DIRECT:
1363             os << "DIRECT";
1364             break;
1365         case ConvolutionMethod::WINOGRAD:
1366             os << "WINOGRAD";
1367             break;
1368         default:
1369             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
1370     }
1371
1372     return os;
1373 }
1374
1375 /** Formatted output of the ConvolutionMethod type.
1376  *
1377  * @param[in] conv_method Type to output
1378  *
1379  * @return Formatted string.
1380  */
1381 inline std::string to_string(const ConvolutionMethod &conv_method)
1382 {
1383     std::stringstream str;
1384     str << conv_method;
1385     return str.str();
1386 }
1387
1388 /** Formatted output of the GPUTarget type.
1389  *
1390  * @param[out] os         Output stream
1391  * @param[in]  gpu_target Type to output
1392  *
1393  * @return Modified output stream.
1394  */
1395 inline ::std::ostream &operator<<(::std::ostream &os, const GPUTarget &gpu_target)
1396 {
1397     switch(gpu_target)
1398     {
1399         case GPUTarget::GPU_ARCH_MASK:
1400             os << "GPU_ARCH_MASK";
1401             break;
1402         case GPUTarget::MIDGARD:
1403             os << "MIDGARD";
1404             break;
1405         case GPUTarget::BIFROST:
1406             os << "BIFROST";
1407             break;
1408         case GPUTarget::T600:
1409             os << "T600";
1410             break;
1411         case GPUTarget::T700:
1412             os << "T700";
1413             break;
1414         case GPUTarget::T800:
1415             os << "T800";
1416             break;
1417         case GPUTarget::G71:
1418             os << "G71";
1419             break;
1420         case GPUTarget::G72:
1421             os << "G72";
1422             break;
1423         case GPUTarget::G51:
1424             os << "G51";
1425             break;
1426         case GPUTarget::G51BIG:
1427             os << "G51BIG";
1428             break;
1429         case GPUTarget::G51LIT:
1430             os << "G51LIT";
1431             break;
1432         case GPUTarget::TNOX:
1433             os << "TNOX";
1434             break;
1435         case GPUTarget::TTRX:
1436             os << "TTRX";
1437             break;
1438         case GPUTarget::TBOX:
1439             os << "TBOX";
1440             break;
1441         default:
1442             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
1443     }
1444
1445     return os;
1446 }
1447
1448 /** Formatted output of the GPUTarget type.
1449  *
1450  * @param[in] gpu_target Type to output
1451  *
1452  * @return Formatted string.
1453  */
1454 inline std::string to_string(const GPUTarget &gpu_target)
1455 {
1456     std::stringstream str;
1457     str << gpu_target;
1458     return str.str();
1459 }
1460
1461 /** Formatted output of the DetectionWindow type.
1462  *
1463  * @param[out] os               Output stream
1464  * @param[in]  detection_window Type to output
1465  *
1466  * @return Modified output stream.
1467  */
1468 inline ::std::ostream &operator<<(::std::ostream &os, const DetectionWindow &detection_window)
1469 {
1470     os << "{x=" << detection_window.x << ","
1471        << "y=" << detection_window.y << ","
1472        << "width=" << detection_window.width << ","
1473        << "height=" << detection_window.height << ","
1474        << "idx_class=" << detection_window.idx_class << ","
1475        << "score=" << detection_window.score << "}";
1476
1477     return os;
1478 }
1479
1480 /** Formatted output of the DetectionWindow type.
1481  *
1482  * @param[in] detection_window Type to output
1483  *
1484  * @return Formatted string.
1485  */
1486 inline std::string to_string(const DetectionWindow &detection_window)
1487 {
1488     std::stringstream str;
1489     str << detection_window;
1490     return str.str();
1491 }
1492
1493 /** Formatted output of the Termination type.
1494  *
1495  * @param[out] os          Output stream
1496  * @param[in]  termination Type to output
1497  *
1498  * @return Modified output stream.
1499  */
1500 inline ::std::ostream &operator<<(::std::ostream &os, const Termination &termination)
1501 {
1502     switch(termination)
1503     {
1504         case Termination::TERM_CRITERIA_EPSILON:
1505             os << "TERM_CRITERIA_EPSILON";
1506             break;
1507         case Termination::TERM_CRITERIA_ITERATIONS:
1508             os << "TERM_CRITERIA_ITERATIONS";
1509             break;
1510         case Termination::TERM_CRITERIA_BOTH:
1511             os << "TERM_CRITERIA_BOTH";
1512             break;
1513         default:
1514             ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
1515     }
1516
1517     return os;
1518 }
1519
1520 /** Formatted output of the Termination type.
1521  *
1522  * @param[in] termination Type to output
1523  *
1524  * @return Formatted string.
1525  */
1526 inline std::string to_string(const Termination &termination)
1527 {
1528     std::stringstream str;
1529     str << termination;
1530     return str.str();
1531 }
1532
1533 /** Formatted output of the WinogradInfo type. */
1534 inline ::std::ostream &operator<<(::std::ostream &os, const WinogradInfo &info)
1535 {
1536     os << "{OutputTileSize=" << info.output_tile_size << ","
1537        << "KernelSize=" << info.kernel_size << ","
1538        << "PadStride=" << info.convolution_info << ","
1539        << "OutputDataLayout=" << info.output_data_layout << "}";
1540
1541     return os;
1542 }
1543
1544 inline std::string to_string(const WinogradInfo &type)
1545 {
1546     std::stringstream str;
1547     str << type;
1548     return str.str();
1549 }
1550 } // namespace arm_compute
1551 #endif /* __ARM_COMPUTE_TEST_TYPE_PRINTER_H__ */