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/TensorInfo.h"
31 #include "arm_compute/core/Types.h"
33 #include "tests/Types.h"
41 /** Formatted output of the Dimensions type. */
43 inline ::std::ostream &operator<<(::std::ostream &os, const Dimensions<T> &dimensions)
45 if(dimensions.num_dimensions() > 0)
49 for(unsigned int d = 1; d < dimensions.num_dimensions(); ++d)
51 os << "x" << dimensions[d];
58 /** Formatted output of the NonLinearFilterFunction type. */
59 inline ::std::ostream &operator<<(::std::ostream &os, const NonLinearFilterFunction &function)
63 case NonLinearFilterFunction::MAX:
66 case NonLinearFilterFunction::MEDIAN:
69 case NonLinearFilterFunction::MIN:
73 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
79 inline std::string to_string(const NonLinearFilterFunction &function)
81 std::stringstream str;
86 /** Formatted output of the MatrixPattern type. */
87 inline ::std::ostream &operator<<(::std::ostream &os, const MatrixPattern &pattern)
91 case MatrixPattern::BOX:
94 case MatrixPattern::CROSS:
97 case MatrixPattern::DISK:
100 case MatrixPattern::OTHER:
104 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
110 inline std::string to_string(const MatrixPattern &pattern)
112 std::stringstream str;
117 /** Formatted output of the RoundingPolicy type. */
118 inline ::std::ostream &operator<<(::std::ostream &os, const RoundingPolicy &rounding_policy)
120 switch(rounding_policy)
122 case RoundingPolicy::TO_ZERO:
125 case RoundingPolicy::TO_NEAREST_UP:
126 os << "TO_NEAREST_UP";
128 case RoundingPolicy::TO_NEAREST_EVEN:
129 os << "TO_NEAREST_EVEN";
132 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
138 /** Formatted output of the WeightsInfo type. */
139 inline ::std::ostream &operator<<(::std::ostream &os, const WeightsInfo &weights_info)
141 os << weights_info.are_reshaped() << ";";
142 os << weights_info.num_kernels() << ";" << weights_info.kernel_size().first << "," << weights_info.kernel_size().second;
147 /** Formatted output of the ROIPoolingInfo type. */
148 inline ::std::ostream &operator<<(::std::ostream &os, const ROIPoolingLayerInfo &pool_info)
150 os << pool_info.pooled_width() << "x" << pool_info.pooled_height() << "~" << pool_info.spatial_scale();
154 /** Formatted output of the QuantizationInfo type. */
155 inline ::std::ostream &operator<<(::std::ostream &os, const QuantizationInfo &quantization_info)
157 os << "Scale:" << quantization_info.scale << "~"
158 << "Offset:" << quantization_info.offset;
162 inline std::string to_string(const QuantizationInfo &quantization_info)
164 std::stringstream str;
165 str << quantization_info;
169 inline ::std::ostream &operator<<(::std::ostream &os, const FixedPointOp &op)
173 case FixedPointOp::ADD:
176 case FixedPointOp::SUB:
179 case FixedPointOp::MUL:
182 case FixedPointOp::EXP:
185 case FixedPointOp::LOG:
188 case FixedPointOp::INV_SQRT:
191 case FixedPointOp::RECIPROCAL:
195 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
201 inline std::string to_string(const FixedPointOp &op)
203 std::stringstream str;
208 /** Formatted output of the activation function type. */
209 inline ::std::ostream &operator<<(::std::ostream &os, const ActivationLayerInfo::ActivationFunction &act_function)
213 case ActivationLayerInfo::ActivationFunction::ABS:
216 case ActivationLayerInfo::ActivationFunction::LINEAR:
219 case ActivationLayerInfo::ActivationFunction::LOGISTIC:
222 case ActivationLayerInfo::ActivationFunction::RELU:
225 case ActivationLayerInfo::ActivationFunction::BOUNDED_RELU:
226 os << "BOUNDED_RELU";
228 case ActivationLayerInfo::ActivationFunction::LEAKY_RELU:
231 case ActivationLayerInfo::ActivationFunction::SOFT_RELU:
234 case ActivationLayerInfo::ActivationFunction::SQRT:
237 case ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU:
238 os << "LU_BOUNDED_RELU";
240 case ActivationLayerInfo::ActivationFunction::SQUARE:
243 case ActivationLayerInfo::ActivationFunction::TANH:
247 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
253 inline std::string to_string(const arm_compute::ActivationLayerInfo &info)
255 std::stringstream str;
256 str << info.activation();
260 inline std::string to_string(const arm_compute::ActivationLayerInfo::ActivationFunction &function)
262 std::stringstream str;
267 /** Formatted output of the NormType type. */
268 inline ::std::ostream &operator<<(::std::ostream &os, const NormType &norm_type)
272 case NormType::CROSS_MAP:
275 case NormType::IN_MAP_1D:
278 case NormType::IN_MAP_2D:
282 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
288 inline std::string to_string(const arm_compute::NormalizationLayerInfo &info)
290 std::stringstream str;
295 /** Formatted output of @ref NormalizationLayerInfo. */
296 inline ::std::ostream &operator<<(::std::ostream &os, const NormalizationLayerInfo &info)
302 /** Formatted output of the PoolingType type. */
303 inline ::std::ostream &operator<<(::std::ostream &os, const PoolingType &pool_type)
307 case PoolingType::AVG:
310 case PoolingType::MAX:
313 case PoolingType::L2:
317 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
323 /** Formatted output of @ref PoolingLayerInfo. */
324 inline ::std::ostream &operator<<(::std::ostream &os, const PoolingLayerInfo &info)
326 os << info.pool_type();
331 inline std::string to_string(const RoundingPolicy &rounding_policy)
333 std::stringstream str;
334 str << rounding_policy;
338 /** Formatted output of the DataType type. */
339 inline ::std::ostream &operator<<(::std::ostream &os, const DataType &data_type)
343 case DataType::UNKNOWN:
352 case DataType::QASYMM8:
388 case DataType::SIZET:
392 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
398 inline std::string to_string(const arm_compute::DataType &data_type)
400 std::stringstream str;
405 /** Formatted output of the Format type. */
406 inline ::std::ostream &operator<<(::std::ostream &os, const Format &format)
410 case Format::UNKNOWN:
440 case Format::RGBA8888:
446 case Format::YUYV422:
458 case Format::UYVY422:
462 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
468 inline std::string to_string(const Format &format)
470 std::stringstream str;
475 /** Formatted output of the Channel type. */
476 inline ::std::ostream &operator<<(::std::ostream &os, const Channel &channel)
480 case Channel::UNKNOWN:
517 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
523 /** Formatted output of the BorderMode type. */
524 inline ::std::ostream &operator<<(::std::ostream &os, const BorderMode &mode)
528 case BorderMode::UNDEFINED:
531 case BorderMode::CONSTANT:
534 case BorderMode::REPLICATE:
538 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
544 /** Formatted output of the BorderSize type. */
545 inline ::std::ostream &operator<<(::std::ostream &os, const BorderSize &border)
547 os << border.top << ","
548 << border.right << ","
549 << border.bottom << ","
555 /** Formatted output of the InterpolationPolicy type. */
556 inline ::std::ostream &operator<<(::std::ostream &os, const InterpolationPolicy &policy)
560 case InterpolationPolicy::NEAREST_NEIGHBOR:
561 os << "NEAREST_NEIGHBOR";
563 case InterpolationPolicy::BILINEAR:
566 case InterpolationPolicy::AREA:
570 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
576 /** Formatted output of the SamplingPolicy type. */
577 inline ::std::ostream &operator<<(::std::ostream &os, const SamplingPolicy &policy)
581 case SamplingPolicy::CENTER:
584 case SamplingPolicy::TOP_LEFT:
588 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
594 /** Formatted output of the TensorInfo type. */
595 inline std::string to_string(const TensorInfo &info)
597 std::stringstream str;
598 str << "{Shape=" << info.tensor_shape() << ","
599 << "Type=" << info.data_type() << ","
600 << "Channels=" << info.num_channels() << ","
601 << "FixedPointPos=" << info.fixed_point_position() << "}";
605 template <typename T>
606 inline std::string to_string(const Dimensions<T> &dimensions)
608 std::stringstream str;
613 inline std::string to_string(const Strides &stride)
615 std::stringstream str;
620 /** Formatted output of the TensorShape type. */
621 inline std::string to_string(const TensorShape &shape)
623 std::stringstream str;
628 /** Formatted output of the Coordinates type. */
629 inline std::string to_string(const Coordinates &coord)
631 std::stringstream str;
636 /** Formatted output of the Rectangle type. */
637 inline ::std::ostream &operator<<(::std::ostream &os, const Rectangle &rect)
639 os << rect.width << "x" << rect.height;
640 os << "+" << rect.x << "+" << rect.y;
645 /** Formatted output of the PadStridInfo type. */
646 inline ::std::ostream &operator<<(::std::ostream &os, const PadStrideInfo &pad_stride_info)
648 os << pad_stride_info.stride().first << "," << pad_stride_info.stride().second;
650 os << pad_stride_info.pad_left() << "," << pad_stride_info.pad_right() << ","
651 << pad_stride_info.pad_top() << "," << pad_stride_info.pad_bottom();
656 inline std::string to_string(const PadStrideInfo &pad_stride_info)
658 std::stringstream str;
659 str << pad_stride_info;
663 inline std::string to_string(const BorderMode &mode)
665 std::stringstream str;
670 inline std::string to_string(const BorderSize &border)
672 std::stringstream str;
677 inline std::string to_string(const InterpolationPolicy &policy)
679 std::stringstream str;
684 inline std::string to_string(const SamplingPolicy &policy)
686 std::stringstream str;
691 /** Formatted output of the ConversionPolicy type. */
692 inline ::std::ostream &operator<<(::std::ostream &os, const ConvertPolicy &policy)
696 case ConvertPolicy::WRAP:
699 case ConvertPolicy::SATURATE:
703 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
709 inline std::string to_string(const ConvertPolicy &policy)
711 std::stringstream str;
716 /** Formatted output of the Reduction Operations. */
717 inline ::std::ostream &operator<<(::std::ostream &os, const ReductionOperation &op)
721 case ReductionOperation::SUM_SQUARE:
725 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
731 inline std::string to_string(const ReductionOperation &op)
733 std::stringstream str;
738 inline std::string to_string(const NormType &type)
740 std::stringstream str;
745 inline std::string to_string(const PoolingType &type)
747 std::stringstream str;
752 inline std::string to_string(const PoolingLayerInfo &info)
754 std::stringstream str;
755 str << "{Type=" << info.pool_type() << ","
756 << "IsGlobalPooling=" << info.is_global_pooling();
757 if(!info.is_global_pooling())
760 << "PoolSize=" << info.pool_size() << ","
761 << "PadStride=" << info.pad_stride_info();
767 /** Formatted output of the KeyPoint type. */
768 inline ::std::ostream &operator<<(::std::ostream &os, const KeyPoint &point)
770 os << "{x=" << point.x << ","
771 << "y=" << point.y << ","
772 << "strength=" << point.strength << ","
773 << "scale=" << point.scale << ","
774 << "orientation=" << point.orientation << ","
775 << "tracking_status=" << point.tracking_status << ","
776 << "error=" << point.error << "}";
781 /** Formatted output of the PhaseType type. */
782 inline ::std::ostream &operator<<(::std::ostream &os, const PhaseType &phase_type)
786 case PhaseType::SIGNED:
789 case PhaseType::UNSIGNED:
793 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
799 inline std::string to_string(const arm_compute::PhaseType &type)
801 std::stringstream str;
806 /** Formatted output of the MagnitudeType type. */
807 inline ::std::ostream &operator<<(::std::ostream &os, const MagnitudeType &magnitude_type)
809 switch(magnitude_type)
811 case MagnitudeType::L1NORM:
814 case MagnitudeType::L2NORM:
818 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
824 inline std::string to_string(const arm_compute::MagnitudeType &type)
826 std::stringstream str;
831 /** Formatted output of the GradientDimension type. */
832 inline ::std::ostream &operator<<(::std::ostream &os, const GradientDimension &dim)
836 case GradientDimension::GRAD_X:
839 case GradientDimension::GRAD_Y:
842 case GradientDimension::GRAD_XY:
846 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
852 inline std::string to_string(const arm_compute::GradientDimension &type)
854 std::stringstream str;
858 } // namespace arm_compute
859 #endif /* __ARM_COMPUTE_TEST_TYPE_PRINTER_H__ */