blob: c955584c76f599c82208d85ef3c548f8022c9046 [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
Georgios Pinitas6f669f02017-09-26 12:32:57 +0100267/** Formatted output of @ref NormalizationLayerInfo. */
268inline ::std::ostream &operator<<(::std::ostream &os, const NormalizationLayerInfo &info)
269{
270 os << info.type();
271 return os;
272}
273
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100274/** Formatted output of the PoolingType type. */
275inline ::std::ostream &operator<<(::std::ostream &os, const PoolingType &pool_type)
276{
277 switch(pool_type)
278 {
279 case PoolingType::AVG:
280 os << "AVG";
281 break;
282 case PoolingType::MAX:
283 os << "MAX";
284 break;
Georgios Pinitascdf51452017-08-31 14:21:36 +0100285 case PoolingType::L2:
286 os << "L2";
287 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100288 default:
289 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
290 }
291
292 return os;
293}
294
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100295/** Formatted output of @ref PoolingLayerInfo. */
296inline ::std::ostream &operator<<(::std::ostream &os, const PoolingLayerInfo &info)
297{
Anthony Barbier2a07e182017-08-04 18:20:27 +0100298 os << info.pool_type();
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100299
300 return os;
301}
302
303/** Formatted output of the DataType type. */
304inline ::std::ostream &operator<<(::std::ostream &os, const DataType &data_type)
305{
306 switch(data_type)
307 {
308 case DataType::UNKNOWN:
309 os << "UNKNOWN";
310 break;
311 case DataType::U8:
312 os << "U8";
313 break;
314 case DataType::QS8:
315 os << "QS8";
316 break;
317 case DataType::S8:
318 os << "S8";
319 break;
320 case DataType::U16:
321 os << "U16";
322 break;
323 case DataType::S16:
324 os << "S16";
325 break;
Gian Marco Iodicebdb6b0b2017-06-30 12:21:00 +0100326 case DataType::QS16:
327 os << "QS16";
328 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100329 case DataType::U32:
330 os << "U32";
331 break;
332 case DataType::S32:
333 os << "S32";
334 break;
335 case DataType::U64:
336 os << "U64";
337 break;
338 case DataType::S64:
339 os << "S64";
340 break;
341 case DataType::F16:
342 os << "F16";
343 break;
344 case DataType::F32:
345 os << "F32";
346 break;
347 case DataType::F64:
348 os << "F64";
349 break;
350 case DataType::SIZET:
351 os << "SIZET";
352 break;
353 default:
354 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
355 }
356
357 return os;
358}
359
Anthony Barbier2a07e182017-08-04 18:20:27 +0100360inline std::string to_string(const arm_compute::DataType &data_type)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100361{
362 std::stringstream str;
363 str << data_type;
364 return str.str();
365}
366
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100367/** Formatted output of the Format type. */
368inline ::std::ostream &operator<<(::std::ostream &os, const Format &format)
369{
370 switch(format)
371 {
372 case Format::UNKNOWN:
373 os << "UNKNOWN";
374 break;
375 case Format::U8:
376 os << "U8";
377 break;
378 case Format::S16:
379 os << "S16";
380 break;
381 case Format::U16:
382 os << "U16";
383 break;
384 case Format::S32:
385 os << "S32";
386 break;
387 case Format::U32:
388 os << "U32";
389 break;
390 case Format::F16:
391 os << "F16";
392 break;
393 case Format::F32:
394 os << "F32";
395 break;
396 case Format::UV88:
397 os << "UV88";
398 break;
399 case Format::RGB888:
400 os << "RGB888";
401 break;
402 case Format::RGBA8888:
403 os << "RGBA8888";
404 break;
405 case Format::YUV444:
406 os << "YUV444";
407 break;
408 case Format::YUYV422:
409 os << "YUYV422";
410 break;
411 case Format::NV12:
412 os << "NV12";
413 break;
414 case Format::NV21:
415 os << "NV21";
416 break;
417 case Format::IYUV:
418 os << "IYUV";
419 break;
420 case Format::UYVY422:
421 os << "UYVY422";
422 break;
423 default:
424 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
425 }
426
427 return os;
428}
429
Moritz Pflanzer7655a672017-09-23 11:57:33 +0100430inline std::string to_string(const Format &format)
431{
432 std::stringstream str;
433 str << format;
434 return str.str();
435}
436
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100437/** Formatted output of the Channel type. */
438inline ::std::ostream &operator<<(::std::ostream &os, const Channel &channel)
439{
440 switch(channel)
441 {
442 case Channel::UNKNOWN:
443 os << "UNKNOWN";
444 break;
445 case Channel::C0:
446 os << "C0";
447 break;
448 case Channel::C1:
449 os << "C1";
450 break;
451 case Channel::C2:
452 os << "C2";
453 break;
454 case Channel::C3:
455 os << "C3";
456 break;
457 case Channel::R:
458 os << "R";
459 break;
460 case Channel::G:
461 os << "G";
462 break;
463 case Channel::B:
464 os << "B";
465 break;
466 case Channel::A:
467 os << "A";
468 break;
469 case Channel::Y:
470 os << "Y";
471 break;
472 case Channel::U:
473 os << "U";
474 break;
475 case Channel::V:
476 os << "V";
477 break;
478 default:
479 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
480 }
481
482 return os;
483}
484
Anthony Barbier2a07e182017-08-04 18:20:27 +0100485/** Formatted output of the BorderMode type. */
486inline ::std::ostream &operator<<(::std::ostream &os, const BorderMode &mode)
487{
488 switch(mode)
489 {
490 case BorderMode::UNDEFINED:
491 os << "UNDEFINED";
492 break;
493 case BorderMode::CONSTANT:
494 os << "CONSTANT";
495 break;
496 case BorderMode::REPLICATE:
497 os << "REPLICATE";
498 break;
499 default:
500 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
501 }
502
503 return os;
504}
505
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100506/** Formatted output of the BorderSize type. */
507inline ::std::ostream &operator<<(::std::ostream &os, const BorderSize &border)
508{
Moritz Pflanzerc87fbf82017-07-18 14:02:10 +0100509 os << border.top << ","
510 << border.right << ","
511 << border.bottom << ","
512 << border.left;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100513
514 return os;
515}
Anthony Barbier2a07e182017-08-04 18:20:27 +0100516
517/** Formatted output of the InterpolationPolicy type. */
518inline ::std::ostream &operator<<(::std::ostream &os, const InterpolationPolicy &policy)
519{
520 switch(policy)
521 {
522 case InterpolationPolicy::NEAREST_NEIGHBOR:
523 os << "NEAREST_NEIGHBOR";
524 break;
525 case InterpolationPolicy::BILINEAR:
526 os << "BILINEAR";
527 break;
528 case InterpolationPolicy::AREA:
529 os << "AREA";
530 break;
531 default:
532 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
533 }
534
535 return os;
536}
537
Abe Mbise925ca0f2017-10-02 19:16:33 +0100538//FIXME: Check why this doesn't work and the TensorShape and Coordinates overload are needed
Anthony Barbier2a07e182017-08-04 18:20:27 +0100539template <typename T>
540inline std::string to_string(const Dimensions<T> &dimensions)
541{
542 std::stringstream str;
543 str << dimensions;
544 return str.str();
545}
546
547/** Formatted output of the TensorShape type. */
548inline std::string to_string(const TensorShape &shape)
549{
550 std::stringstream str;
551 str << shape;
552 return str.str();
553}
554
Abe Mbise925ca0f2017-10-02 19:16:33 +0100555/** Formatted output of the Coordinates type. */
556inline std::string to_string(const Coordinates &coord)
557{
558 std::stringstream str;
559 str << coord;
560 return str.str();
561}
562
Anthony Barbier2a07e182017-08-04 18:20:27 +0100563/** Formatted output of the Rectangle type. */
564inline ::std::ostream &operator<<(::std::ostream &os, const Rectangle &rect)
565{
566 os << rect.width << "x" << rect.height;
567 os << "+" << rect.x << "+" << rect.y;
568
569 return os;
570}
571
572/** Formatted output of the PadStridInfo type. */
573inline ::std::ostream &operator<<(::std::ostream &os, const PadStrideInfo &pad_stride_info)
574{
575 os << pad_stride_info.stride().first << "," << pad_stride_info.stride().second;
576 os << ";";
577 os << pad_stride_info.pad().first << "," << pad_stride_info.pad().second;
578
579 return os;
580}
581
582inline std::string to_string(const PadStrideInfo &pad_stride_info)
583{
584 std::stringstream str;
585 str << pad_stride_info;
586 return str.str();
587}
588
589inline std::string to_string(const BorderMode &mode)
590{
591 std::stringstream str;
592 str << mode;
593 return str.str();
594}
595
John Richardsonb482ce12017-09-18 12:44:01 +0100596inline std::string to_string(const BorderSize &border)
597{
598 std::stringstream str;
599 str << border;
600 return str.str();
601}
602
Anthony Barbier2a07e182017-08-04 18:20:27 +0100603inline std::string to_string(const InterpolationPolicy &policy)
604{
605 std::stringstream str;
606 str << policy;
607 return str.str();
608}
609
610/** Formatted output of the ConversionPolicy type. */
611inline ::std::ostream &operator<<(::std::ostream &os, const ConvertPolicy &policy)
612{
613 switch(policy)
614 {
615 case ConvertPolicy::WRAP:
616 os << "WRAP";
617 break;
618 case ConvertPolicy::SATURATE:
619 os << "SATURATE";
620 break;
621 default:
622 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
623 }
624
625 return os;
626}
627
628inline std::string to_string(const ConvertPolicy &policy)
629{
630 std::stringstream str;
631 str << policy;
632 return str.str();
633}
634
635/** Formatted output of the Reduction Operations. */
636inline ::std::ostream &operator<<(::std::ostream &os, const ReductionOperation &op)
637{
638 switch(op)
639 {
640 case ReductionOperation::SUM_SQUARE:
641 os << "SUM_SQUARE";
642 break;
643 default:
644 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
645 }
646
647 return os;
648}
649
650inline std::string to_string(const ReductionOperation &op)
651{
652 std::stringstream str;
653 str << op;
654 return str.str();
655}
656
657inline std::string to_string(const NormType &type)
658{
659 std::stringstream str;
660 str << type;
661 return str.str();
662}
663
664inline std::string to_string(const PoolingType &type)
665{
666 std::stringstream str;
667 str << type;
668 return str.str();
669}
670
671inline std::string to_string(const PoolingLayerInfo &info)
672{
673 std::stringstream str;
674 str << info.pool_type();
675 return str.str();
676}
677
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +0100678/** Formatted output of the KeyPoint type. */
679inline ::std::ostream &operator<<(::std::ostream &os, const KeyPoint &point)
680{
681 os << "{x=" << point.x << ","
682 << "y=" << point.y << ","
683 << "strength=" << point.strength << ","
684 << "scale=" << point.scale << ","
685 << "orientation=" << point.orientation << ","
686 << "tracking_status=" << point.tracking_status << ","
687 << "error=" << point.error << "}";
688
689 return os;
690}
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100691} // namespace arm_compute
Anthony Barbierac69aa12017-07-03 17:39:37 +0100692#endif /* __ARM_COMPUTE_TEST_TYPE_PRINTER_H__ */