blob: 79d0d698d6260bc256f9592c7918c8320e294ca9 [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_REFERENCE_REFERENCE_CPP_H__
25#define __ARM_COMPUTE_TEST_REFERENCE_REFERENCE_CPP_H__
26
Isabella Gottardib797fa22017-06-23 15:02:11 +010027#include "RawTensor.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010028#include "Reference.h"
29
Isabella Gottardib797fa22017-06-23 15:02:11 +010030#include <map>
Georgios Pinitasac4e8732017-07-05 17:02:25 +010031#include <memory>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010032#include <ostream>
Georgios Pinitasd4f8c272017-06-30 16:16:19 +010033#include <vector>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034
35namespace arm_compute
36{
37class Tensor;
38
39namespace test
40{
41namespace validation
42{
43/** C++ reference implementation. */
44class ReferenceCPP final : public Reference
45{
46public:
Giorgio Arenafc2817d2017-06-27 17:26:37 +010047 /** Function to compute reference Harris corners.
48 *
49 * @param[in] src Input tensor
50 * @param[in] Gx Tensor used to compute Sobel along the x axis
51 * @param[in] Gy Tensor used to compute Sobel along the y axis
52 * @param[in] candidates Tensor used to store candidate corners
53 * @param[in] non_maxima Tensor used to store non_maxima suppressed candidate corners
54 * @param[in] threshold Minimum threshold with which to eliminate Harris Corner scores (computed using the normalized Sobel kernel).
55 * @param[in] min_dist Radial Euclidean distance for the euclidean distance stage
56 * @param[in] sensitivity Sensitivity threshold k from the Harris-Stephens equation
57 * @param[in] gradient_size The gradient window size to use on the input. The implementation supports 3, 5, and 7
58 * @param[in] block_size The block window size used to compute the Harris Corner score. The implementation supports 3, 5, and 7.
59 * @param[out] corners Array of keypoints to store the results.
60 * @param[in] border_mode Border mode to use
61 * @param[in] constant_border_value Constant value to use for borders if border_mode is set to CONSTANT.
62 *
63 */
64 static void harris_corners(RawTensor &src, RawTensor &Gx, RawTensor &Gy, const RawTensor &candidates, const RawTensor &non_maxima, float threshold, float min_dist, float sensitivity,
65 int32_t gradient_size, int32_t block_size, KeyPointArray &corners, BorderMode border_mode, uint8_t constant_border_value);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010066 /** Function to compute the integral image of a tensor.
67 *
68 * @param[in] src Input tensor.
69 * @param[out] dst Result tensor.
70 */
71 static void integral_image(const RawTensor &src, RawTensor &dst);
72 /** Function to compute the absolute difference between two tensors.
73 *
74 * @param[in] src1 First tensor.
75 * @param[in] src2 Second tensor.
76 * @param[out] dst Result tensor.
77 */
78 static void absolute_difference(const RawTensor &src1, const RawTensor &src2, RawTensor &dst);
79 /** Function to accumulate an input tensor into an output tensor.
80 *
81 * @param[in] src Input tensor.
82 * @param[in, out] dst Result tensor.
83 */
84 static void accumulate(const RawTensor &src, RawTensor &dst);
85 /** Function to accumulate a squared value from an input tensor to an output tensor.
86 *
87 * @param[in] src Input tensor.
88 * @param[in, out] dst Result tensor.
89 * @param[in] shift A uint32_t value within the range of [0, 15]
90 */
91 static void accumulate_squared(const RawTensor &src, RawTensor &dst, uint32_t shift);
92 /** Function to accumulate a weighted value from an input tensor to an output tensor.
93 *
94 * @param[in] src Input tensor.
95 * @param[in, out] dst Result tensor.
96 * @param[in] alpha A float value within the range of [0, 1]
97 */
98 static void accumulate_weighted(const RawTensor &src, RawTensor &dst, float alpha);
Isabella Gottardi3b77e9d2017-06-22 11:05:41 +010099 /** Compute non linear filter function.
100 *
101 * @param[in] src First input tensor
102 * @param[out] dst Output tensor
103 * @param[in] function Non linear function to perform
104 * @param[in] mask_size Mask size. Supported sizes: 3, 5
105 * @param[in] pattern Matrix pattern
106 * @param[in] mask The given mask.
107 * @param[in] border_mode Strategy to use for borders.
108 * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT.
109 */
110 static void non_linear_filter(const RawTensor &src, RawTensor &dst, NonLinearFilterFunction function, unsigned int mask_size,
111 MatrixPattern pattern, const uint8_t *mask, BorderMode border_mode, uint8_t constant_border_value = 0);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100112 /** Threshold of@p src to @p dst
113 *
Isabella Gottardib797fa22017-06-23 15:02:11 +0100114 * @param[in] src Input tensor.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100115 * @param[out] dst Result tensor.
116 * @param[in] threshold Threshold. When the threhold type is RANGE, this is used as the lower threshold.
117 * @param[in] false_value value to set when the condition is not respected.
118 * @param[in] true_value value to set when the condition is respected.
119 * @param[in] type Thresholding type. Either RANGE or BINARY.
120 * @param[in] upper Upper threshold. Only used when the thresholding type is RANGE.
121 */
122 static void threshold(const RawTensor &src, RawTensor &dst, uint8_t threshold, uint8_t false_value, uint8_t true_value, ThresholdType type, uint8_t upper);
Georgios Pinitas7b7858d2017-06-21 16:44:24 +0100123 /** ROI Pooling layer of @p src based on the information from @p pool_info and @p rois.
124 *
125 * @param[in] src Input tensor.
126 * @param[out] dst Result tensor.
127 * @param[in] rois Region of Interest points.
128 * @param[in] pool_info ROI Pooling Layer information.
129 */
130 static void roi_pooling_layer(const RawTensor &src, RawTensor &dst, const std::vector<ROI> &rois, const ROIPoolingLayerInfo &pool_info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100131
132private:
133 ReferenceCPP() = delete;
134 ~ReferenceCPP() = delete;
135};
136} // namespace validation
137} // namespace test
138} // namespace arm_compute
Anthony Barbierac69aa12017-07-03 17:39:37 +0100139#endif /* __ARM_COMPUTE_TEST_REFERENCE_REFERENCE_CPP_H__ */