2 * Copyright (c) 2017-2018 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/CL/CLTypes.h"
28 #include "arm_compute/core/Dimensions.h"
29 #include "arm_compute/core/Error.h"
30 #include "arm_compute/core/HOGInfo.h"
31 #include "arm_compute/core/Size2D.h"
32 #include "arm_compute/core/Strides.h"
33 #include "arm_compute/core/TensorInfo.h"
34 #include "arm_compute/core/Types.h"
36 #include "tests/Types.h"
44 /** Formatted output of the Dimensions type. */
46 inline ::std::ostream &operator<<(::std::ostream &os, const Dimensions<T> &dimensions)
48 if(dimensions.num_dimensions() > 0)
52 for(unsigned int d = 1; d < dimensions.num_dimensions(); ++d)
54 os << "x" << dimensions[d];
61 /** Formatted output of the NonLinearFilterFunction type. */
62 inline ::std::ostream &operator<<(::std::ostream &os, const NonLinearFilterFunction &function)
66 case NonLinearFilterFunction::MAX:
69 case NonLinearFilterFunction::MEDIAN:
72 case NonLinearFilterFunction::MIN:
76 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
82 inline std::string to_string(const NonLinearFilterFunction &function)
84 std::stringstream str;
89 /** Formatted output of the MatrixPattern type. */
90 inline ::std::ostream &operator<<(::std::ostream &os, const MatrixPattern &pattern)
94 case MatrixPattern::BOX:
97 case MatrixPattern::CROSS:
100 case MatrixPattern::DISK:
103 case MatrixPattern::OTHER:
107 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
113 inline std::string to_string(const MatrixPattern &pattern)
115 std::stringstream str;
120 /** Formatted output of the RoundingPolicy type. */
121 inline ::std::ostream &operator<<(::std::ostream &os, const RoundingPolicy &rounding_policy)
123 switch(rounding_policy)
125 case RoundingPolicy::TO_ZERO:
128 case RoundingPolicy::TO_NEAREST_UP:
129 os << "TO_NEAREST_UP";
131 case RoundingPolicy::TO_NEAREST_EVEN:
132 os << "TO_NEAREST_EVEN";
135 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
141 /** Formatted output of the WeightsInfo type. */
142 inline ::std::ostream &operator<<(::std::ostream &os, const WeightsInfo &weights_info)
144 os << weights_info.are_reshaped() << ";";
145 os << weights_info.num_kernels() << ";" << weights_info.kernel_size().first << "," << weights_info.kernel_size().second;
150 /** Formatted output of the ROIPoolingInfo type. */
151 inline ::std::ostream &operator<<(::std::ostream &os, const ROIPoolingLayerInfo &pool_info)
153 os << pool_info.pooled_width() << "x" << pool_info.pooled_height() << "~" << pool_info.spatial_scale();
157 /** Formatted output of the QuantizationInfo type. */
158 inline ::std::ostream &operator<<(::std::ostream &os, const QuantizationInfo &quantization_info)
160 os << "Scale:" << quantization_info.scale << "~"
161 << "Offset:" << quantization_info.offset;
165 inline std::string to_string(const QuantizationInfo &quantization_info)
167 std::stringstream str;
168 str << quantization_info;
172 inline ::std::ostream &operator<<(::std::ostream &os, const FixedPointOp &op)
176 case FixedPointOp::ADD:
179 case FixedPointOp::SUB:
182 case FixedPointOp::MUL:
185 case FixedPointOp::EXP:
188 case FixedPointOp::LOG:
191 case FixedPointOp::INV_SQRT:
194 case FixedPointOp::RECIPROCAL:
198 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
204 inline std::string to_string(const FixedPointOp &op)
206 std::stringstream str;
211 /** Formatted output of the activation function type. */
212 inline ::std::ostream &operator<<(::std::ostream &os, const ActivationLayerInfo::ActivationFunction &act_function)
216 case ActivationLayerInfo::ActivationFunction::ABS:
219 case ActivationLayerInfo::ActivationFunction::LINEAR:
222 case ActivationLayerInfo::ActivationFunction::LOGISTIC:
225 case ActivationLayerInfo::ActivationFunction::RELU:
228 case ActivationLayerInfo::ActivationFunction::BOUNDED_RELU:
229 os << "BOUNDED_RELU";
231 case ActivationLayerInfo::ActivationFunction::LEAKY_RELU:
234 case ActivationLayerInfo::ActivationFunction::SOFT_RELU:
237 case ActivationLayerInfo::ActivationFunction::SQRT:
240 case ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU:
241 os << "LU_BOUNDED_RELU";
243 case ActivationLayerInfo::ActivationFunction::SQUARE:
246 case ActivationLayerInfo::ActivationFunction::TANH:
250 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
256 inline std::string to_string(const arm_compute::ActivationLayerInfo &info)
258 std::stringstream str;
259 str << info.activation();
263 inline std::string to_string(const arm_compute::ActivationLayerInfo::ActivationFunction &function)
265 std::stringstream str;
270 /** Formatted output of the NormType type. */
271 inline ::std::ostream &operator<<(::std::ostream &os, const NormType &norm_type)
275 case NormType::CROSS_MAP:
278 case NormType::IN_MAP_1D:
281 case NormType::IN_MAP_2D:
285 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
291 inline std::string to_string(const arm_compute::NormalizationLayerInfo &info)
293 std::stringstream str;
294 str << info.type() << ":NormSize=" << info.norm_size();
298 /** Formatted output of @ref NormalizationLayerInfo. */
299 inline ::std::ostream &operator<<(::std::ostream &os, const NormalizationLayerInfo &info)
301 os << info.type() << ":NormSize=" << info.norm_size();
305 /** Formatted output of the PoolingType type. */
306 inline ::std::ostream &operator<<(::std::ostream &os, const PoolingType &pool_type)
310 case PoolingType::AVG:
313 case PoolingType::MAX:
316 case PoolingType::L2:
320 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
326 /** Formatted output of @ref PoolingLayerInfo. */
327 inline ::std::ostream &operator<<(::std::ostream &os, const PoolingLayerInfo &info)
329 os << info.pool_type();
334 inline std::string to_string(const RoundingPolicy &rounding_policy)
336 std::stringstream str;
337 str << rounding_policy;
341 /** Formatted output of the DataType type. */
342 inline ::std::ostream &operator<<(::std::ostream &os, const DataType &data_type)
346 case DataType::UNKNOWN:
355 case DataType::QASYMM8:
391 case DataType::SIZET:
395 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
401 inline std::string to_string(const arm_compute::DataType &data_type)
403 std::stringstream str;
408 /** Formatted output of the Format type. */
409 inline ::std::ostream &operator<<(::std::ostream &os, const Format &format)
413 case Format::UNKNOWN:
443 case Format::RGBA8888:
449 case Format::YUYV422:
461 case Format::UYVY422:
465 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
471 inline std::string to_string(const Format &format)
473 std::stringstream str;
478 /** Formatted output of the Channel type. */
479 inline ::std::ostream &operator<<(::std::ostream &os, const Channel &channel)
483 case Channel::UNKNOWN:
520 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
526 inline std::string to_string(const Channel &channel)
528 std::stringstream str;
533 /** Formatted output of the BorderMode type. */
534 inline ::std::ostream &operator<<(::std::ostream &os, const BorderMode &mode)
538 case BorderMode::UNDEFINED:
541 case BorderMode::CONSTANT:
544 case BorderMode::REPLICATE:
548 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
554 /** Formatted output of the BorderSize type. */
555 inline ::std::ostream &operator<<(::std::ostream &os, const BorderSize &border)
557 os << border.top << ","
558 << border.right << ","
559 << border.bottom << ","
565 /** Formatted output of the InterpolationPolicy type. */
566 inline ::std::ostream &operator<<(::std::ostream &os, const InterpolationPolicy &policy)
570 case InterpolationPolicy::NEAREST_NEIGHBOR:
571 os << "NEAREST_NEIGHBOR";
573 case InterpolationPolicy::BILINEAR:
576 case InterpolationPolicy::AREA:
580 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
586 /** Formatted output of the SamplingPolicy type. */
587 inline ::std::ostream &operator<<(::std::ostream &os, const SamplingPolicy &policy)
591 case SamplingPolicy::CENTER:
594 case SamplingPolicy::TOP_LEFT:
598 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
604 /** Formatted output of the TensorInfo type. */
605 inline std::string to_string(const TensorInfo &info)
607 std::stringstream str;
608 str << "{Shape=" << info.tensor_shape() << ","
609 << "Type=" << info.data_type() << ","
610 << "Channels=" << info.num_channels() << ","
611 << "FixedPointPos=" << info.fixed_point_position() << "}";
615 template <typename T>
616 inline std::string to_string(const Dimensions<T> &dimensions)
618 std::stringstream str;
623 inline std::string to_string(const Strides &stride)
625 std::stringstream str;
630 /** Formatted output of the TensorShape type. */
631 inline std::string to_string(const TensorShape &shape)
633 std::stringstream str;
638 /** Formatted output of the Coordinates type. */
639 inline std::string to_string(const Coordinates &coord)
641 std::stringstream str;
646 /** Formatted output of the Rectangle type. */
647 inline ::std::ostream &operator<<(::std::ostream &os, const Rectangle &rect)
649 os << rect.width << "x" << rect.height;
650 os << "+" << rect.x << "+" << rect.y;
655 /** Formatted output of the PadStridInfo type. */
656 inline ::std::ostream &operator<<(::std::ostream &os, const PadStrideInfo &pad_stride_info)
658 os << pad_stride_info.stride().first << "," << pad_stride_info.stride().second;
660 os << pad_stride_info.pad_left() << "," << pad_stride_info.pad_right() << ","
661 << pad_stride_info.pad_top() << "," << pad_stride_info.pad_bottom();
666 inline std::string to_string(const PadStrideInfo &pad_stride_info)
668 std::stringstream str;
669 str << pad_stride_info;
673 inline std::string to_string(const BorderMode &mode)
675 std::stringstream str;
680 inline std::string to_string(const BorderSize &border)
682 std::stringstream str;
687 inline std::string to_string(const InterpolationPolicy &policy)
689 std::stringstream str;
694 inline std::string to_string(const SamplingPolicy &policy)
696 std::stringstream str;
701 /** Formatted output of the ConversionPolicy type. */
702 inline ::std::ostream &operator<<(::std::ostream &os, const ConvertPolicy &policy)
706 case ConvertPolicy::WRAP:
709 case ConvertPolicy::SATURATE:
713 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
719 inline std::string to_string(const ConvertPolicy &policy)
721 std::stringstream str;
726 /** Formatted output of the Reduction Operations. */
727 inline ::std::ostream &operator<<(::std::ostream &os, const ReductionOperation &op)
731 case ReductionOperation::SUM_SQUARE:
735 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
741 inline std::string to_string(const ReductionOperation &op)
743 std::stringstream str;
748 inline std::string to_string(const NormType &type)
750 std::stringstream str;
755 inline std::string to_string(const PoolingType &type)
757 std::stringstream str;
762 inline std::string to_string(const PoolingLayerInfo &info)
764 std::stringstream str;
765 str << "{Type=" << info.pool_type() << ","
766 << "IsGlobalPooling=" << info.is_global_pooling();
767 if(!info.is_global_pooling())
770 << "PoolSize=" << info.pool_size().width << "," << info.pool_size().height << ","
771 << "PadStride=" << info.pad_stride_info();
777 /** Formatted output of the KeyPoint type. */
778 inline ::std::ostream &operator<<(::std::ostream &os, const KeyPoint &point)
780 os << "{x=" << point.x << ","
781 << "y=" << point.y << ","
782 << "strength=" << point.strength << ","
783 << "scale=" << point.scale << ","
784 << "orientation=" << point.orientation << ","
785 << "tracking_status=" << point.tracking_status << ","
786 << "error=" << point.error << "}";
791 /** Formatted output of the PhaseType type. */
792 inline ::std::ostream &operator<<(::std::ostream &os, const PhaseType &phase_type)
796 case PhaseType::SIGNED:
799 case PhaseType::UNSIGNED:
803 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
809 inline std::string to_string(const arm_compute::PhaseType &type)
811 std::stringstream str;
816 /** Formatted output of the MagnitudeType type. */
817 inline ::std::ostream &operator<<(::std::ostream &os, const MagnitudeType &magnitude_type)
819 switch(magnitude_type)
821 case MagnitudeType::L1NORM:
824 case MagnitudeType::L2NORM:
828 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
834 inline std::string to_string(const arm_compute::MagnitudeType &type)
836 std::stringstream str;
841 /** Formatted output of the GradientDimension type. */
842 inline ::std::ostream &operator<<(::std::ostream &os, const GradientDimension &dim)
846 case GradientDimension::GRAD_X:
849 case GradientDimension::GRAD_Y:
852 case GradientDimension::GRAD_XY:
856 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
862 inline std::string to_string(const arm_compute::GradientDimension &type)
864 std::stringstream str;
869 /** Formatted output of the HOGNormType type. */
870 inline ::std::ostream &operator<<(::std::ostream &os, const HOGNormType &norm_type)
874 case HOGNormType::L1_NORM:
877 case HOGNormType::L2_NORM:
880 case HOGNormType::L2HYS_NORM:
884 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
890 inline std::string to_string(const HOGNormType &type)
892 std::stringstream str;
897 /** Formatted output of the Size2D type. */
898 inline ::std::ostream &operator<<(::std::ostream &os, const Size2D &size)
900 os << size.width << "x" << size.height;
905 inline std::string to_string(const Size2D &type)
907 std::stringstream str;
912 /** Formatted output of the Size2D type. */
913 inline ::std::ostream &operator<<(::std::ostream &os, const HOGInfo &hog_info)
915 os << "{CellSize=" << hog_info.cell_size() << ","
916 << "BlockSize=" << hog_info.block_size() << ","
917 << "DetectionWindowSize=" << hog_info.detection_window_size() << ","
918 << "BlockStride=" << hog_info.block_stride() << ","
919 << "NumBins=" << hog_info.num_bins() << ","
920 << "NormType=" << hog_info.normalization_type() << ","
921 << "L2HystThreshold=" << hog_info.l2_hyst_threshold() << ","
922 << "PhaseType=" << hog_info.phase_type() << "}";
927 /** Formatted output of the HOGInfo type. */
928 inline std::string to_string(const HOGInfo &type)
930 std::stringstream str;
935 inline ::std::ostream &operator<<(::std::ostream &os, const ConvolutionMethod &conv_method)
939 case ConvolutionMethod::GEMM:
942 case ConvolutionMethod::DIRECT:
945 case ConvolutionMethod::WINOGRAD:
949 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
955 inline std::string to_string(const ConvolutionMethod &conv_method)
957 std::stringstream str;
962 inline ::std::ostream &operator<<(::std::ostream &os, const GPUTarget &gpu_target)
966 case GPUTarget::GPU_ARCH_MASK:
967 os << "GPU_ARCH_MASK";
969 case GPUTarget::MIDGARD:
972 case GPUTarget::BIFROST:
975 case GPUTarget::T600:
978 case GPUTarget::T700:
981 case GPUTarget::T800:
988 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
994 inline std::string to_string(const GPUTarget &gpu_target)
996 std::stringstream str;
1000 } // namespace arm_compute
1001 #endif /* __ARM_COMPUTE_TEST_TYPE_PRINTER_H__ */