blob: 4f424d943879a9538814f5512c118592322d7024 [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 {
John Richardson70f946b2017-10-02 16:52:16 +0100156 case FixedPointOp::ADD:
157 os << "ADD";
158 break;
159 case FixedPointOp::SUB:
160 os << "SUB";
161 break;
162 case FixedPointOp::MUL:
163 os << "MUL";
164 break;
Abe Mbise4bd2cb82017-09-27 18:39:19 +0100165 case FixedPointOp::EXP:
166 os << "EXP";
167 break;
168 case FixedPointOp::LOG:
169 os << "LOG";
170 break;
171 case FixedPointOp::INV_SQRT:
172 os << "INV_SQRT";
173 break;
174 case FixedPointOp::RECIPROCAL:
175 os << "RECIPROCAL";
176 break;
177 default:
178 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
179 }
180
181 return os;
182}
John Richardson70f946b2017-10-02 16:52:16 +0100183
Abe Mbise4bd2cb82017-09-27 18:39:19 +0100184inline std::string to_string(const FixedPointOp &op)
185{
186 std::stringstream str;
187 str << op;
188 return str.str();
189}
190
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100191/** Formatted output of the activation function type. */
192inline ::std::ostream &operator<<(::std::ostream &os, const ActivationLayerInfo::ActivationFunction &act_function)
193{
194 switch(act_function)
195 {
196 case ActivationLayerInfo::ActivationFunction::ABS:
197 os << "ABS";
198 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100199 case ActivationLayerInfo::ActivationFunction::LINEAR:
200 os << "LINEAR";
201 break;
202 case ActivationLayerInfo::ActivationFunction::LOGISTIC:
203 os << "LOGISTIC";
204 break;
205 case ActivationLayerInfo::ActivationFunction::RELU:
206 os << "RELU";
207 break;
Georgios Pinitas579c0492017-07-12 16:12:12 +0100208 case ActivationLayerInfo::ActivationFunction::BOUNDED_RELU:
209 os << "BOUNDED_RELU";
210 break;
211 case ActivationLayerInfo::ActivationFunction::LEAKY_RELU:
212 os << "LEAKY_RELU";
213 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100214 case ActivationLayerInfo::ActivationFunction::SOFT_RELU:
215 os << "SOFT_RELU";
216 break;
217 case ActivationLayerInfo::ActivationFunction::SQRT:
218 os << "SQRT";
219 break;
Anthony Barbier2a07e182017-08-04 18:20:27 +0100220 case ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU:
221 os << "LU_BOUNDED_RELU";
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100222 case ActivationLayerInfo::ActivationFunction::SQUARE:
223 os << "SQUARE";
224 break;
225 case ActivationLayerInfo::ActivationFunction::TANH:
226 os << "TANH";
227 break;
228 default:
229 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
230 }
231
232 return os;
233}
234
Anthony Barbier2a07e182017-08-04 18:20:27 +0100235inline std::string to_string(const arm_compute::ActivationLayerInfo &info)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100236{
237 std::stringstream str;
238 str << info.activation();
239 return str.str();
240}
241
Anthony Barbier2a07e182017-08-04 18:20:27 +0100242inline std::string to_string(const arm_compute::ActivationLayerInfo::ActivationFunction &function)
243{
244 std::stringstream str;
245 str << function;
246 return str.str();
247}
248
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100249/** Formatted output of the NormType type. */
250inline ::std::ostream &operator<<(::std::ostream &os, const NormType &norm_type)
251{
252 switch(norm_type)
253 {
254 case NormType::CROSS_MAP:
255 os << "CROSS_MAP";
256 break;
257 case NormType::IN_MAP_1D:
258 os << "IN_MAP_1D";
259 break;
260 case NormType::IN_MAP_2D:
261 os << "IN_MAP_2D";
262 break;
263 default:
264 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
265 }
266
267 return os;
268}
269
Anthony Barbier2a07e182017-08-04 18:20:27 +0100270inline std::string to_string(const arm_compute::NormalizationLayerInfo &info)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100271{
272 std::stringstream str;
273 str << info.type();
274 return str.str();
275}
276
Georgios Pinitas6f669f02017-09-26 12:32:57 +0100277/** Formatted output of @ref NormalizationLayerInfo. */
278inline ::std::ostream &operator<<(::std::ostream &os, const NormalizationLayerInfo &info)
279{
280 os << info.type();
281 return os;
282}
283
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100284/** Formatted output of the PoolingType type. */
285inline ::std::ostream &operator<<(::std::ostream &os, const PoolingType &pool_type)
286{
287 switch(pool_type)
288 {
289 case PoolingType::AVG:
290 os << "AVG";
291 break;
292 case PoolingType::MAX:
293 os << "MAX";
294 break;
Georgios Pinitascdf51452017-08-31 14:21:36 +0100295 case PoolingType::L2:
296 os << "L2";
297 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100298 default:
299 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
300 }
301
302 return os;
303}
304
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100305/** Formatted output of @ref PoolingLayerInfo. */
306inline ::std::ostream &operator<<(::std::ostream &os, const PoolingLayerInfo &info)
307{
Anthony Barbier2a07e182017-08-04 18:20:27 +0100308 os << info.pool_type();
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100309
310 return os;
311}
312
313/** Formatted output of the DataType type. */
314inline ::std::ostream &operator<<(::std::ostream &os, const DataType &data_type)
315{
316 switch(data_type)
317 {
318 case DataType::UNKNOWN:
319 os << "UNKNOWN";
320 break;
321 case DataType::U8:
322 os << "U8";
323 break;
324 case DataType::QS8:
325 os << "QS8";
326 break;
327 case DataType::S8:
328 os << "S8";
329 break;
330 case DataType::U16:
331 os << "U16";
332 break;
333 case DataType::S16:
334 os << "S16";
335 break;
Gian Marco Iodicebdb6b0b2017-06-30 12:21:00 +0100336 case DataType::QS16:
337 os << "QS16";
338 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100339 case DataType::U32:
340 os << "U32";
341 break;
342 case DataType::S32:
343 os << "S32";
344 break;
345 case DataType::U64:
346 os << "U64";
347 break;
348 case DataType::S64:
349 os << "S64";
350 break;
351 case DataType::F16:
352 os << "F16";
353 break;
354 case DataType::F32:
355 os << "F32";
356 break;
357 case DataType::F64:
358 os << "F64";
359 break;
360 case DataType::SIZET:
361 os << "SIZET";
362 break;
363 default:
364 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
365 }
366
367 return os;
368}
369
Anthony Barbier2a07e182017-08-04 18:20:27 +0100370inline std::string to_string(const arm_compute::DataType &data_type)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100371{
372 std::stringstream str;
373 str << data_type;
374 return str.str();
375}
376
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100377/** Formatted output of the Format type. */
378inline ::std::ostream &operator<<(::std::ostream &os, const Format &format)
379{
380 switch(format)
381 {
382 case Format::UNKNOWN:
383 os << "UNKNOWN";
384 break;
385 case Format::U8:
386 os << "U8";
387 break;
388 case Format::S16:
389 os << "S16";
390 break;
391 case Format::U16:
392 os << "U16";
393 break;
394 case Format::S32:
395 os << "S32";
396 break;
397 case Format::U32:
398 os << "U32";
399 break;
400 case Format::F16:
401 os << "F16";
402 break;
403 case Format::F32:
404 os << "F32";
405 break;
406 case Format::UV88:
407 os << "UV88";
408 break;
409 case Format::RGB888:
410 os << "RGB888";
411 break;
412 case Format::RGBA8888:
413 os << "RGBA8888";
414 break;
415 case Format::YUV444:
416 os << "YUV444";
417 break;
418 case Format::YUYV422:
419 os << "YUYV422";
420 break;
421 case Format::NV12:
422 os << "NV12";
423 break;
424 case Format::NV21:
425 os << "NV21";
426 break;
427 case Format::IYUV:
428 os << "IYUV";
429 break;
430 case Format::UYVY422:
431 os << "UYVY422";
432 break;
433 default:
434 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
435 }
436
437 return os;
438}
439
Moritz Pflanzer7655a672017-09-23 11:57:33 +0100440inline std::string to_string(const Format &format)
441{
442 std::stringstream str;
443 str << format;
444 return str.str();
445}
446
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100447/** Formatted output of the Channel type. */
448inline ::std::ostream &operator<<(::std::ostream &os, const Channel &channel)
449{
450 switch(channel)
451 {
452 case Channel::UNKNOWN:
453 os << "UNKNOWN";
454 break;
455 case Channel::C0:
456 os << "C0";
457 break;
458 case Channel::C1:
459 os << "C1";
460 break;
461 case Channel::C2:
462 os << "C2";
463 break;
464 case Channel::C3:
465 os << "C3";
466 break;
467 case Channel::R:
468 os << "R";
469 break;
470 case Channel::G:
471 os << "G";
472 break;
473 case Channel::B:
474 os << "B";
475 break;
476 case Channel::A:
477 os << "A";
478 break;
479 case Channel::Y:
480 os << "Y";
481 break;
482 case Channel::U:
483 os << "U";
484 break;
485 case Channel::V:
486 os << "V";
487 break;
488 default:
489 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
490 }
491
492 return os;
493}
494
Anthony Barbier2a07e182017-08-04 18:20:27 +0100495/** Formatted output of the BorderMode type. */
496inline ::std::ostream &operator<<(::std::ostream &os, const BorderMode &mode)
497{
498 switch(mode)
499 {
500 case BorderMode::UNDEFINED:
501 os << "UNDEFINED";
502 break;
503 case BorderMode::CONSTANT:
504 os << "CONSTANT";
505 break;
506 case BorderMode::REPLICATE:
507 os << "REPLICATE";
508 break;
509 default:
510 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
511 }
512
513 return os;
514}
515
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100516/** Formatted output of the BorderSize type. */
517inline ::std::ostream &operator<<(::std::ostream &os, const BorderSize &border)
518{
Moritz Pflanzerc87fbf82017-07-18 14:02:10 +0100519 os << border.top << ","
520 << border.right << ","
521 << border.bottom << ","
522 << border.left;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100523
524 return os;
525}
Anthony Barbier2a07e182017-08-04 18:20:27 +0100526
527/** Formatted output of the InterpolationPolicy type. */
528inline ::std::ostream &operator<<(::std::ostream &os, const InterpolationPolicy &policy)
529{
530 switch(policy)
531 {
532 case InterpolationPolicy::NEAREST_NEIGHBOR:
533 os << "NEAREST_NEIGHBOR";
534 break;
535 case InterpolationPolicy::BILINEAR:
536 os << "BILINEAR";
537 break;
538 case InterpolationPolicy::AREA:
539 os << "AREA";
540 break;
541 default:
542 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
543 }
544
545 return os;
546}
547
Abe Mbise925ca0f2017-10-02 19:16:33 +0100548//FIXME: Check why this doesn't work and the TensorShape and Coordinates overload are needed
Anthony Barbier2a07e182017-08-04 18:20:27 +0100549template <typename T>
550inline std::string to_string(const Dimensions<T> &dimensions)
551{
552 std::stringstream str;
553 str << dimensions;
554 return str.str();
555}
556
557/** Formatted output of the TensorShape type. */
558inline std::string to_string(const TensorShape &shape)
559{
560 std::stringstream str;
561 str << shape;
562 return str.str();
563}
564
Abe Mbise925ca0f2017-10-02 19:16:33 +0100565/** Formatted output of the Coordinates type. */
566inline std::string to_string(const Coordinates &coord)
567{
568 std::stringstream str;
569 str << coord;
570 return str.str();
571}
572
Anthony Barbier2a07e182017-08-04 18:20:27 +0100573/** Formatted output of the Rectangle type. */
574inline ::std::ostream &operator<<(::std::ostream &os, const Rectangle &rect)
575{
576 os << rect.width << "x" << rect.height;
577 os << "+" << rect.x << "+" << rect.y;
578
579 return os;
580}
581
582/** Formatted output of the PadStridInfo type. */
583inline ::std::ostream &operator<<(::std::ostream &os, const PadStrideInfo &pad_stride_info)
584{
585 os << pad_stride_info.stride().first << "," << pad_stride_info.stride().second;
586 os << ";";
587 os << pad_stride_info.pad().first << "," << pad_stride_info.pad().second;
588
589 return os;
590}
591
592inline std::string to_string(const PadStrideInfo &pad_stride_info)
593{
594 std::stringstream str;
595 str << pad_stride_info;
596 return str.str();
597}
598
599inline std::string to_string(const BorderMode &mode)
600{
601 std::stringstream str;
602 str << mode;
603 return str.str();
604}
605
John Richardsonb482ce12017-09-18 12:44:01 +0100606inline std::string to_string(const BorderSize &border)
607{
608 std::stringstream str;
609 str << border;
610 return str.str();
611}
612
Anthony Barbier2a07e182017-08-04 18:20:27 +0100613inline std::string to_string(const InterpolationPolicy &policy)
614{
615 std::stringstream str;
616 str << policy;
617 return str.str();
618}
619
620/** Formatted output of the ConversionPolicy type. */
621inline ::std::ostream &operator<<(::std::ostream &os, const ConvertPolicy &policy)
622{
623 switch(policy)
624 {
625 case ConvertPolicy::WRAP:
626 os << "WRAP";
627 break;
628 case ConvertPolicy::SATURATE:
629 os << "SATURATE";
630 break;
631 default:
632 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
633 }
634
635 return os;
636}
637
638inline std::string to_string(const ConvertPolicy &policy)
639{
640 std::stringstream str;
641 str << policy;
642 return str.str();
643}
644
645/** Formatted output of the Reduction Operations. */
646inline ::std::ostream &operator<<(::std::ostream &os, const ReductionOperation &op)
647{
648 switch(op)
649 {
650 case ReductionOperation::SUM_SQUARE:
651 os << "SUM_SQUARE";
652 break;
653 default:
654 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
655 }
656
657 return os;
658}
659
660inline std::string to_string(const ReductionOperation &op)
661{
662 std::stringstream str;
663 str << op;
664 return str.str();
665}
666
667inline std::string to_string(const NormType &type)
668{
669 std::stringstream str;
670 str << type;
671 return str.str();
672}
673
674inline std::string to_string(const PoolingType &type)
675{
676 std::stringstream str;
677 str << type;
678 return str.str();
679}
680
681inline std::string to_string(const PoolingLayerInfo &info)
682{
683 std::stringstream str;
684 str << info.pool_type();
685 return str.str();
686}
687
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +0100688/** Formatted output of the KeyPoint type. */
689inline ::std::ostream &operator<<(::std::ostream &os, const KeyPoint &point)
690{
691 os << "{x=" << point.x << ","
692 << "y=" << point.y << ","
693 << "strength=" << point.strength << ","
694 << "scale=" << point.scale << ","
695 << "orientation=" << point.orientation << ","
696 << "tracking_status=" << point.tracking_status << ","
697 << "error=" << point.error << "}";
698
699 return os;
700}
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100701} // namespace arm_compute
Anthony Barbierac69aa12017-07-03 17:39:37 +0100702#endif /* __ARM_COMPUTE_TEST_TYPE_PRINTER_H__ */