2 * Copyright (c) 2017 ARM Limited.
4 * SPDX-License-Identifier: MIT
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:
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
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
24 #ifndef __ARM_COMPUTE_TEST_TYPE_PRINTER_H__
25 #define __ARM_COMPUTE_TEST_TYPE_PRINTER_H__
27 #include "arm_compute/core/Dimensions.h"
28 #include "arm_compute/core/Error.h"
29 #include "arm_compute/core/Strides.h"
30 #include "arm_compute/core/Types.h"
32 #include "tests/Types.h"
40 /** Formatted output of the Dimensions type. */
42 inline ::std::ostream &operator<<(::std::ostream &os, const Dimensions<T> &dimensions)
44 if(dimensions.num_dimensions() > 0)
48 for(unsigned int d = 1; d < dimensions.num_dimensions(); ++d)
50 os << "x" << dimensions[d];
57 /** Formatted output of the NonLinearFilterFunction type. */
58 inline ::std::ostream &operator<<(::std::ostream &os, const NonLinearFilterFunction &function)
62 case NonLinearFilterFunction::MAX:
65 case NonLinearFilterFunction::MEDIAN:
68 case NonLinearFilterFunction::MIN:
72 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
78 inline std::string to_string(const NonLinearFilterFunction &function)
80 std::stringstream str;
85 /** Formatted output of the MatrixPattern type. */
86 inline ::std::ostream &operator<<(::std::ostream &os, const MatrixPattern &pattern)
90 case MatrixPattern::BOX:
93 case MatrixPattern::CROSS:
96 case MatrixPattern::DISK:
99 case MatrixPattern::OTHER:
103 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
109 inline std::string to_string(const MatrixPattern &pattern)
111 std::stringstream str;
116 /** Formatted output of the RoundingPolicy type. */
117 inline ::std::ostream &operator<<(::std::ostream &os, const RoundingPolicy &rounding_policy)
119 switch(rounding_policy)
121 case RoundingPolicy::TO_ZERO:
124 case RoundingPolicy::TO_NEAREST_UP:
125 os << "TO_NEAREST_UP";
127 case RoundingPolicy::TO_NEAREST_EVEN:
128 os << "TO_NEAREST_EVEN";
131 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
137 /** Formatted output of the WeightsInfo type. */
138 inline ::std::ostream &operator<<(::std::ostream &os, const WeightsInfo &weights_info)
140 os << weights_info.are_reshaped() << ";";
141 os << weights_info.num_kernels() << ";" << weights_info.kernel_size().first << "," << weights_info.kernel_size().second;
146 /** Formatted output of the ROIPoolingInfo type. */
147 inline ::std::ostream &operator<<(::std::ostream &os, const ROIPoolingLayerInfo &pool_info)
149 os << pool_info.pooled_width() << "x" << pool_info.pooled_height() << "~" << pool_info.spatial_scale();
153 inline ::std::ostream &operator<<(::std::ostream &os, const FixedPointOp &op)
157 case FixedPointOp::ADD:
160 case FixedPointOp::SUB:
163 case FixedPointOp::MUL:
166 case FixedPointOp::EXP:
169 case FixedPointOp::LOG:
172 case FixedPointOp::INV_SQRT:
175 case FixedPointOp::RECIPROCAL:
179 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
185 inline std::string to_string(const FixedPointOp &op)
187 std::stringstream str;
192 /** Formatted output of the activation function type. */
193 inline ::std::ostream &operator<<(::std::ostream &os, const ActivationLayerInfo::ActivationFunction &act_function)
197 case ActivationLayerInfo::ActivationFunction::ABS:
200 case ActivationLayerInfo::ActivationFunction::LINEAR:
203 case ActivationLayerInfo::ActivationFunction::LOGISTIC:
206 case ActivationLayerInfo::ActivationFunction::RELU:
209 case ActivationLayerInfo::ActivationFunction::BOUNDED_RELU:
210 os << "BOUNDED_RELU";
212 case ActivationLayerInfo::ActivationFunction::LEAKY_RELU:
215 case ActivationLayerInfo::ActivationFunction::SOFT_RELU:
218 case ActivationLayerInfo::ActivationFunction::SQRT:
221 case ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU:
222 os << "LU_BOUNDED_RELU";
223 case ActivationLayerInfo::ActivationFunction::SQUARE:
226 case ActivationLayerInfo::ActivationFunction::TANH:
230 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
236 inline std::string to_string(const arm_compute::ActivationLayerInfo &info)
238 std::stringstream str;
239 str << info.activation();
243 inline std::string to_string(const arm_compute::ActivationLayerInfo::ActivationFunction &function)
245 std::stringstream str;
250 /** Formatted output of the NormType type. */
251 inline ::std::ostream &operator<<(::std::ostream &os, const NormType &norm_type)
255 case NormType::CROSS_MAP:
258 case NormType::IN_MAP_1D:
261 case NormType::IN_MAP_2D:
265 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
271 inline std::string to_string(const arm_compute::NormalizationLayerInfo &info)
273 std::stringstream str;
278 /** Formatted output of @ref NormalizationLayerInfo. */
279 inline ::std::ostream &operator<<(::std::ostream &os, const NormalizationLayerInfo &info)
285 /** Formatted output of the PoolingType type. */
286 inline ::std::ostream &operator<<(::std::ostream &os, const PoolingType &pool_type)
290 case PoolingType::AVG:
293 case PoolingType::MAX:
296 case PoolingType::L2:
300 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
306 /** Formatted output of @ref PoolingLayerInfo. */
307 inline ::std::ostream &operator<<(::std::ostream &os, const PoolingLayerInfo &info)
309 os << info.pool_type();
314 /** Formatted output of the DataType type. */
315 inline ::std::ostream &operator<<(::std::ostream &os, const DataType &data_type)
319 case DataType::UNKNOWN:
361 case DataType::SIZET:
365 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
371 inline std::string to_string(const arm_compute::DataType &data_type)
373 std::stringstream str;
378 /** Formatted output of the Format type. */
379 inline ::std::ostream &operator<<(::std::ostream &os, const Format &format)
383 case Format::UNKNOWN:
413 case Format::RGBA8888:
419 case Format::YUYV422:
431 case Format::UYVY422:
435 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
441 inline std::string to_string(const Format &format)
443 std::stringstream str;
448 /** Formatted output of the Channel type. */
449 inline ::std::ostream &operator<<(::std::ostream &os, const Channel &channel)
453 case Channel::UNKNOWN:
490 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
496 /** Formatted output of the BorderMode type. */
497 inline ::std::ostream &operator<<(::std::ostream &os, const BorderMode &mode)
501 case BorderMode::UNDEFINED:
504 case BorderMode::CONSTANT:
507 case BorderMode::REPLICATE:
511 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
517 /** Formatted output of the BorderSize type. */
518 inline ::std::ostream &operator<<(::std::ostream &os, const BorderSize &border)
520 os << border.top << ","
521 << border.right << ","
522 << border.bottom << ","
528 /** Formatted output of the InterpolationPolicy type. */
529 inline ::std::ostream &operator<<(::std::ostream &os, const InterpolationPolicy &policy)
533 case InterpolationPolicy::NEAREST_NEIGHBOR:
534 os << "NEAREST_NEIGHBOR";
536 case InterpolationPolicy::BILINEAR:
539 case InterpolationPolicy::AREA:
543 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
549 template <typename T>
550 inline std::string to_string(const Dimensions<T> &dimensions)
552 std::stringstream str;
557 inline std::string to_string(const Strides &stride)
559 std::stringstream str;
564 /** Formatted output of the TensorShape type. */
565 inline std::string to_string(const TensorShape &shape)
567 std::stringstream str;
572 /** Formatted output of the Coordinates type. */
573 inline std::string to_string(const Coordinates &coord)
575 std::stringstream str;
580 /** Formatted output of the Rectangle type. */
581 inline ::std::ostream &operator<<(::std::ostream &os, const Rectangle &rect)
583 os << rect.width << "x" << rect.height;
584 os << "+" << rect.x << "+" << rect.y;
589 /** Formatted output of the PadStridInfo type. */
590 inline ::std::ostream &operator<<(::std::ostream &os, const PadStrideInfo &pad_stride_info)
592 os << pad_stride_info.stride().first << "," << pad_stride_info.stride().second;
594 os << pad_stride_info.pad().first << "," << pad_stride_info.pad().second;
599 inline std::string to_string(const PadStrideInfo &pad_stride_info)
601 std::stringstream str;
602 str << pad_stride_info;
606 inline std::string to_string(const BorderMode &mode)
608 std::stringstream str;
613 inline std::string to_string(const BorderSize &border)
615 std::stringstream str;
620 inline std::string to_string(const InterpolationPolicy &policy)
622 std::stringstream str;
627 /** Formatted output of the ConversionPolicy type. */
628 inline ::std::ostream &operator<<(::std::ostream &os, const ConvertPolicy &policy)
632 case ConvertPolicy::WRAP:
635 case ConvertPolicy::SATURATE:
639 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
645 inline std::string to_string(const ConvertPolicy &policy)
647 std::stringstream str;
652 /** Formatted output of the Reduction Operations. */
653 inline ::std::ostream &operator<<(::std::ostream &os, const ReductionOperation &op)
657 case ReductionOperation::SUM_SQUARE:
661 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
667 inline std::string to_string(const ReductionOperation &op)
669 std::stringstream str;
674 inline std::string to_string(const NormType &type)
676 std::stringstream str;
681 inline std::string to_string(const PoolingType &type)
683 std::stringstream str;
688 inline std::string to_string(const PoolingLayerInfo &info)
690 std::stringstream str;
691 str << info.pool_type();
695 /** Formatted output of the KeyPoint type. */
696 inline ::std::ostream &operator<<(::std::ostream &os, const KeyPoint &point)
698 os << "{x=" << point.x << ","
699 << "y=" << point.y << ","
700 << "strength=" << point.strength << ","
701 << "scale=" << point.scale << ","
702 << "orientation=" << point.orientation << ","
703 << "tracking_status=" << point.tracking_status << ","
704 << "error=" << point.error << "}";
708 } // namespace arm_compute
709 #endif /* __ARM_COMPUTE_TEST_TYPE_PRINTER_H__ */