blob: 020b559c6f4e776a052e92d9a8dcb636e52bab52 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#ifndef __ARM_COMPUTE_TEST_TYPE_PRINTER_H__
25#define __ARM_COMPUTE_TEST_TYPE_PRINTER_H__
26
27#include "arm_compute/core/Dimensions.h"
28#include "arm_compute/core/Error.h"
29#include "arm_compute/core/Types.h"
30
31#include <ostream>
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010032#include <sstream>
33#include <string>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034
35namespace arm_compute
36{
37/** Formatted output of the Dimensions type. */
38template <typename T>
39inline ::std::ostream &operator<<(::std::ostream &os, const Dimensions<T> &dimensions)
40{
Anthony Barbier6ff3b192017-09-04 18:44:23 +010041 if(dimensions.num_dimensions() > 0)
42 {
43 os << dimensions[0];
44
45 for(unsigned int d = 1; d < dimensions.num_dimensions(); ++d)
46 {
Moritz Pflanzerc87fbf82017-07-18 14:02:10 +010047 os << "x" << dimensions[d];
Anthony Barbier6ff3b192017-09-04 18:44:23 +010048 }
49 }
50
Anthony Barbier6ff3b192017-09-04 18:44:23 +010051 return os;
52}
53
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010054//FIXME: Check why this doesn't work and the TensorShape overload is needed
55template <typename T>
56inline std::string to_string(const Dimensions<T> &dimensions)
57{
58 std::stringstream str;
59 str << dimensions;
60 return str.str();
61}
62
63inline std::string to_string(const TensorShape &shape)
64{
65 std::stringstream str;
66 str << shape;
67 return str.str();
68}
69
Georgios Pinitas7b7858d2017-06-21 16:44:24 +010070/** Formatted output of the Rectangle type. */
71inline ::std::ostream &operator<<(::std::ostream &os, const Rectangle &rect)
72{
Moritz Pflanzerc87fbf82017-07-18 14:02:10 +010073 os << rect.width << "x" << rect.height;
74 os << "+" << rect.x << "+" << rect.y;
Georgios Pinitas7b7858d2017-06-21 16:44:24 +010075
76 return os;
77}
78
Anthony Barbier6ff3b192017-09-04 18:44:23 +010079/** Formatted output of the PadStridInfo type. */
80inline ::std::ostream &operator<<(::std::ostream &os, const PadStrideInfo &pad_stride_info)
81{
Moritz Pflanzerc87fbf82017-07-18 14:02:10 +010082 os << pad_stride_info.stride().first << "," << pad_stride_info.stride().second;
83 os << ";";
84 os << pad_stride_info.pad().first << "," << pad_stride_info.pad().second;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010085
86 return os;
87}
88
Georgios Pinitas7b7858d2017-06-21 16:44:24 +010089/** Formatted output of the ROIPoolingInfo type. */
90inline ::std::ostream &operator<<(::std::ostream &os, const ROIPoolingLayerInfo &pool_info)
91{
Moritz Pflanzerc87fbf82017-07-18 14:02:10 +010092 os << pool_info.pooled_width() << "x" << pool_info.pooled_height() << "~" << pool_info.spatial_scale();
Georgios Pinitas7b7858d2017-06-21 16:44:24 +010093 return os;
94}
95
Anthony Barbier6ff3b192017-09-04 18:44:23 +010096/** Formatted output of the BorderMode type. */
97inline ::std::ostream &operator<<(::std::ostream &os, const BorderMode &mode)
98{
99 switch(mode)
100 {
101 case BorderMode::UNDEFINED:
102 os << "UNDEFINED";
103 break;
104 case BorderMode::CONSTANT:
105 os << "CONSTANT";
106 break;
107 case BorderMode::REPLICATE:
108 os << "REPLICATE";
109 break;
110 default:
111 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
112 }
113
114 return os;
115}
116
Isabella Gottardi3b77e9d2017-06-22 11:05:41 +0100117/** Formatted output of the NonLinearFilterFunction type. */
118inline ::std::ostream &operator<<(::std::ostream &os, const NonLinearFilterFunction &function)
119{
120 switch(function)
121 {
122 case NonLinearFilterFunction::MAX:
123 os << "MAX";
124 break;
125 case NonLinearFilterFunction::MEDIAN:
126 os << "MEDIAN";
127 break;
128 case NonLinearFilterFunction::MIN:
129 os << "MIN";
130 break;
131 default:
132 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
133 }
134
135 return os;
136}
137
138/** Formatted output of the MatrixPattern type. */
139inline ::std::ostream &operator<<(::std::ostream &os, const MatrixPattern &pattern)
140{
141 switch(pattern)
142 {
143 case MatrixPattern::BOX:
144 os << "BOX";
145 break;
146 case MatrixPattern::CROSS:
147 os << "CROSS";
148 break;
149 case MatrixPattern::DISK:
150 os << "DISK";
151 break;
152 case MatrixPattern::OTHER:
153 os << "OTHER";
154 break;
155 default:
156 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
157 }
158
159 return os;
160}
161
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100162/** Formatted output of the InterpolationPolicy type. */
163inline ::std::ostream &operator<<(::std::ostream &os, const InterpolationPolicy &policy)
164{
165 switch(policy)
166 {
167 case InterpolationPolicy::NEAREST_NEIGHBOR:
168 os << "NEAREST_NEIGHBOR";
169 break;
170 case InterpolationPolicy::BILINEAR:
171 os << "BILINEAR";
172 break;
173 case InterpolationPolicy::AREA:
174 os << "AREA";
175 break;
176 default:
177 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
178 }
179
180 return os;
181}
182
183/** Formatted output of the ConversionPolicy type. */
184inline ::std::ostream &operator<<(::std::ostream &os, const ConvertPolicy &policy)
185{
186 switch(policy)
187 {
188 case ConvertPolicy::WRAP:
189 os << "WRAP";
190 break;
191 case ConvertPolicy::SATURATE:
192 os << "SATURATE";
193 break;
194 default:
195 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
196 }
197
198 return os;
199}
200
Georgios Pinitasd9769582017-08-03 10:19:40 +0100201/** Formatted output of the Reduction Operations. */
202inline ::std::ostream &operator<<(::std::ostream &os, const ReductionOperation &op)
203{
204 switch(op)
205 {
206 case ReductionOperation::SUM_SQUARE:
207 os << "SUM_SQUARE";
208 break;
209 default:
210 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
211 }
212
213 return os;
214}
215
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100216/** Formatted output of the activation function type. */
217inline ::std::ostream &operator<<(::std::ostream &os, const ActivationLayerInfo::ActivationFunction &act_function)
218{
219 switch(act_function)
220 {
221 case ActivationLayerInfo::ActivationFunction::ABS:
222 os << "ABS";
223 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100224 case ActivationLayerInfo::ActivationFunction::LINEAR:
225 os << "LINEAR";
226 break;
227 case ActivationLayerInfo::ActivationFunction::LOGISTIC:
228 os << "LOGISTIC";
229 break;
230 case ActivationLayerInfo::ActivationFunction::RELU:
231 os << "RELU";
232 break;
Georgios Pinitas579c0492017-07-12 16:12:12 +0100233 case ActivationLayerInfo::ActivationFunction::BOUNDED_RELU:
234 os << "BOUNDED_RELU";
235 break;
236 case ActivationLayerInfo::ActivationFunction::LEAKY_RELU:
237 os << "LEAKY_RELU";
238 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100239 case ActivationLayerInfo::ActivationFunction::SOFT_RELU:
240 os << "SOFT_RELU";
241 break;
242 case ActivationLayerInfo::ActivationFunction::SQRT:
243 os << "SQRT";
244 break;
245 case ActivationLayerInfo::ActivationFunction::SQUARE:
246 os << "SQUARE";
247 break;
248 case ActivationLayerInfo::ActivationFunction::TANH:
249 os << "TANH";
250 break;
251 default:
252 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
253 }
254
255 return os;
256}
257
Georgios Pinitasd9769582017-08-03 10:19:40 +0100258inline std::string to_string(const ReductionOperation &op)
259{
260 std::stringstream str;
261 str << op;
262 return str.str();
263}
264
Moritz Pflanzer572ade72017-07-21 17:36:33 +0100265inline std::string to_string(const ActivationLayerInfo::ActivationFunction &function)
266{
267 std::stringstream str;
268 str << function;
269 return str.str();
270}
271
Moritz Pflanzer6db73ce2017-07-19 10:18:42 +0100272inline std::string to_string(const ActivationLayerInfo &info)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100273{
274 std::stringstream str;
275 str << info.activation();
276 return str.str();
277}
278
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100279/** Formatted output of the NormType type. */
280inline ::std::ostream &operator<<(::std::ostream &os, const NormType &norm_type)
281{
282 switch(norm_type)
283 {
284 case NormType::CROSS_MAP:
285 os << "CROSS_MAP";
286 break;
287 case NormType::IN_MAP_1D:
288 os << "IN_MAP_1D";
289 break;
290 case NormType::IN_MAP_2D:
291 os << "IN_MAP_2D";
292 break;
293 default:
294 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
295 }
296
297 return os;
298}
299
Moritz Pflanzer6db73ce2017-07-19 10:18:42 +0100300inline std::string to_string(const NormType &type)
301{
302 std::stringstream str;
303 str << type;
304 return str.str();
305}
306
307inline std::string to_string(const NormalizationLayerInfo &info)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100308{
309 std::stringstream str;
310 str << info.type();
311 return str.str();
312}
313
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100314/** Formatted output of the PoolingType type. */
315inline ::std::ostream &operator<<(::std::ostream &os, const PoolingType &pool_type)
316{
317 switch(pool_type)
318 {
319 case PoolingType::AVG:
320 os << "AVG";
321 break;
322 case PoolingType::MAX:
323 os << "MAX";
324 break;
325 default:
326 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
327 }
328
329 return os;
330}
331
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100332/** Formatted output of @ref PoolingLayerInfo. */
333inline ::std::ostream &operator<<(::std::ostream &os, const PoolingLayerInfo &info)
334{
335 os << info.pool_type();
336
337 return os;
338}
339
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100340/** Formatted output of the RoundingPolicy type. */
341inline ::std::ostream &operator<<(::std::ostream &os, const RoundingPolicy &rounding_policy)
342{
343 switch(rounding_policy)
344 {
345 case RoundingPolicy::TO_ZERO:
346 os << "TO_ZERO";
347 break;
348 case RoundingPolicy::TO_NEAREST_UP:
349 os << "TO_NEAREST_UP";
350 break;
351 case RoundingPolicy::TO_NEAREST_EVEN:
352 os << "TO_NEAREST_EVEN";
353 break;
354 default:
355 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
356 }
357
358 return os;
359}
360
361/** Formatted output of the DataType type. */
362inline ::std::ostream &operator<<(::std::ostream &os, const DataType &data_type)
363{
364 switch(data_type)
365 {
366 case DataType::UNKNOWN:
367 os << "UNKNOWN";
368 break;
369 case DataType::U8:
370 os << "U8";
371 break;
372 case DataType::QS8:
373 os << "QS8";
374 break;
375 case DataType::S8:
376 os << "S8";
377 break;
378 case DataType::U16:
379 os << "U16";
380 break;
381 case DataType::S16:
382 os << "S16";
383 break;
Gian Marco Iodicebdb6b0b2017-06-30 12:21:00 +0100384 case DataType::QS16:
385 os << "QS16";
386 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100387 case DataType::U32:
388 os << "U32";
389 break;
390 case DataType::S32:
391 os << "S32";
392 break;
393 case DataType::U64:
394 os << "U64";
395 break;
396 case DataType::S64:
397 os << "S64";
398 break;
399 case DataType::F16:
400 os << "F16";
401 break;
402 case DataType::F32:
403 os << "F32";
404 break;
405 case DataType::F64:
406 os << "F64";
407 break;
408 case DataType::SIZET:
409 os << "SIZET";
410 break;
411 default:
412 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
413 }
414
415 return os;
416}
417
Moritz Pflanzer6db73ce2017-07-19 10:18:42 +0100418inline std::string to_string(const DataType &data_type)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100419{
420 std::stringstream str;
421 str << data_type;
422 return str.str();
423}
424
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100425/** Formatted output of the Format type. */
426inline ::std::ostream &operator<<(::std::ostream &os, const Format &format)
427{
428 switch(format)
429 {
430 case Format::UNKNOWN:
431 os << "UNKNOWN";
432 break;
433 case Format::U8:
434 os << "U8";
435 break;
436 case Format::S16:
437 os << "S16";
438 break;
439 case Format::U16:
440 os << "U16";
441 break;
442 case Format::S32:
443 os << "S32";
444 break;
445 case Format::U32:
446 os << "U32";
447 break;
448 case Format::F16:
449 os << "F16";
450 break;
451 case Format::F32:
452 os << "F32";
453 break;
454 case Format::UV88:
455 os << "UV88";
456 break;
457 case Format::RGB888:
458 os << "RGB888";
459 break;
460 case Format::RGBA8888:
461 os << "RGBA8888";
462 break;
463 case Format::YUV444:
464 os << "YUV444";
465 break;
466 case Format::YUYV422:
467 os << "YUYV422";
468 break;
469 case Format::NV12:
470 os << "NV12";
471 break;
472 case Format::NV21:
473 os << "NV21";
474 break;
475 case Format::IYUV:
476 os << "IYUV";
477 break;
478 case Format::UYVY422:
479 os << "UYVY422";
480 break;
481 default:
482 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
483 }
484
485 return os;
486}
487
488/** Formatted output of the Channel type. */
489inline ::std::ostream &operator<<(::std::ostream &os, const Channel &channel)
490{
491 switch(channel)
492 {
493 case Channel::UNKNOWN:
494 os << "UNKNOWN";
495 break;
496 case Channel::C0:
497 os << "C0";
498 break;
499 case Channel::C1:
500 os << "C1";
501 break;
502 case Channel::C2:
503 os << "C2";
504 break;
505 case Channel::C3:
506 os << "C3";
507 break;
508 case Channel::R:
509 os << "R";
510 break;
511 case Channel::G:
512 os << "G";
513 break;
514 case Channel::B:
515 os << "B";
516 break;
517 case Channel::A:
518 os << "A";
519 break;
520 case Channel::Y:
521 os << "Y";
522 break;
523 case Channel::U:
524 os << "U";
525 break;
526 case Channel::V:
527 os << "V";
528 break;
529 default:
530 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
531 }
532
533 return os;
534}
535
536/** Formatted output of the BorderSize type. */
537inline ::std::ostream &operator<<(::std::ostream &os, const BorderSize &border)
538{
Moritz Pflanzerc87fbf82017-07-18 14:02:10 +0100539 os << border.top << ","
540 << border.right << ","
541 << border.bottom << ","
542 << border.left;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100543
544 return os;
545}
546} // namespace arm_compute
Anthony Barbierac69aa12017-07-03 17:39:37 +0100547#endif /* __ARM_COMPUTE_TEST_TYPE_PRINTER_H__ */