blob: 3ef5fc1cc59d3de1d967c6a356708bba5dd38f35 [file] [log] [blame]
Moritz Pflanzer3ce3ff42017-07-21 17:41:02 +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 */
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010024#include "tests/validation/Helpers.h"
Moritz Pflanzer3ce3ff42017-07-21 17:41:02 +010025
26namespace arm_compute
27{
28namespace test
29{
30namespace validation
31{
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +010032void fill_mask_from_pattern(uint8_t *mask, int cols, int rows, MatrixPattern pattern)
33{
34 unsigned int v = 0;
35 std::mt19937 gen(library->seed());
36 std::bernoulli_distribution dist(0.5);
37
38 for(int r = 0; r < rows; ++r)
39 {
40 for(int c = 0; c < cols; ++c, ++v)
41 {
42 uint8_t val = 0;
43
44 switch(pattern)
45 {
46 case MatrixPattern::BOX:
47 val = 255;
48 break;
49 case MatrixPattern::CROSS:
50 val = ((r == (rows / 2)) || (c == (cols / 2))) ? 255 : 0;
51 break;
52 case MatrixPattern::DISK:
53 val = (((r - rows / 2.0f + 0.5f) * (r - rows / 2.0f + 0.5f)) / ((rows / 2.0f) * (rows / 2.0f)) + ((c - cols / 2.0f + 0.5f) * (c - cols / 2.0f + 0.5f)) / ((cols / 2.0f) *
54 (cols / 2.0f))) <= 1.0f ? 255 : 0;
55 break;
56 case MatrixPattern::OTHER:
57 val = (dist(gen) ? 0 : 255);
58 break;
59 default:
60 return;
61 }
62
63 mask[v] = val;
64 }
65 }
66
67 if(pattern == MatrixPattern::OTHER)
68 {
69 std::uniform_int_distribution<uint8_t> distribution_u8(0, ((cols * rows) - 1));
70 mask[distribution_u8(gen)] = 255;
71 }
72}
73
Moritz Pflanzer3ce3ff42017-07-21 17:41:02 +010074TensorShape calculate_depth_concatenate_shape(const std::vector<TensorShape> &input_shapes)
75{
76 ARM_COMPUTE_ERROR_ON(input_shapes.empty());
77
78 TensorShape out_shape = input_shapes[0];
79
80 size_t max_x = 0;
81 size_t max_y = 0;
82 size_t depth = 0;
83
84 for(const auto &shape : input_shapes)
85 {
86 max_x = std::max(shape.x(), max_x);
87 max_y = std::max(shape.y(), max_y);
88 depth += shape.z();
89 }
90
91 out_shape.set(0, max_x);
92 out_shape.set(1, max_y);
93 out_shape.set(2, depth);
94
95 return out_shape;
96}
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +010097
98HarrisCornersParameters harris_corners_parameters()
99{
100 HarrisCornersParameters params;
101
102 std::mt19937 gen(library->seed());
103 std::uniform_real_distribution<float> threshold_dist(0.f, 0.01f);
104 std::uniform_real_distribution<float> sensitivity(0.04f, 0.15f);
105 std::uniform_real_distribution<float> euclidean_distance(0.f, 30.f);
106 std::uniform_int_distribution<uint8_t> int_dist(0, 255);
107
108 params.threshold = threshold_dist(gen);
109 params.sensitivity = sensitivity(gen);
110 params.min_dist = euclidean_distance(gen);
111 params.constant_border_value = int_dist(gen);
112
113 return params;
114}
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000115
116SimpleTensor<float> convert_from_asymmetric(const SimpleTensor<uint8_t> &src)
117{
118 const QuantizationInfo &quantization_info = src.quantization_info();
119 SimpleTensor<float> dst{ src.shape(), DataType::F32, 1, 0 };
120 for(int i = 0; i < src.num_elements(); ++i)
121 {
122 dst[i] = quantization_info.dequantize(src[i]);
123 }
124 return dst;
125}
126
127SimpleTensor<uint8_t> convert_to_asymmetric(const SimpleTensor<float> &src, const QuantizationInfo &quantization_info)
128{
129 SimpleTensor<uint8_t> dst{ src.shape(), DataType::QASYMM8, 1, 0, quantization_info };
130 for(int i = 0; i < src.num_elements(); ++i)
131 {
132 dst[i] = quantization_info.quantize(src[i]);
133 }
134 return dst;
135}
Moritz Pflanzer3ce3ff42017-07-21 17:41:02 +0100136} // namespace validation
137} // namespace test
138} // namespace arm_compute