blob: 3f0498015a3f9da5f446fc54b832cb009da932bd [file] [log] [blame]
Manuel Bottini5209be52019-02-13 16:34:56 +00001/*
2 * Copyright (c) 2019 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#include "ComputeAllAnchors.h"
25
26#include "arm_compute/core/Types.h"
27#include "arm_compute/core/utils/misc/ShapeCalculator.h"
28#include "arm_compute/core/utils/misc/Utility.h"
29#include "tests/validation/Helpers.h"
30
31namespace arm_compute
32{
33namespace test
34{
35namespace validation
36{
37namespace reference
38{
39template <typename T>
40SimpleTensor<T> compute_all_anchors(const SimpleTensor<T> &anchors, const ComputeAnchorsInfo &info)
41{
42 const int num_anchors = anchors.shape()[1];
43 const auto width = int(info.feat_width());
44 const auto height = int(info.feat_height());
45 const float stride = 1. / info.spatial_scale();
46
47 SimpleTensor<T> all_anchors(TensorShape(4, width * height * num_anchors), anchors.data_type());
48 const T *anchors_ptr = anchors.data();
49 T *all_anchors_ptr = all_anchors.data();
50
51 // Iterate over the input grid and anchors
52 for(int y = 0; y < height; y++)
53 {
54 for(int x = 0; x < width; x++)
55 {
56 for(int a = 0; a < num_anchors; a++)
57 {
58 const T shift_x = T(x) * T(stride);
59 const T shift_y = T(y) * T(stride);
60 const size_t anchor_id = a + x * num_anchors + y * width * num_anchors;
61 // x1
62 all_anchors_ptr[anchor_id * 4] = anchors_ptr[4 * a] + shift_x;
63 // y1
64 all_anchors_ptr[anchor_id * 4 + 1] = anchors_ptr[4 * a + 1] + shift_y;
65 // x2
66 all_anchors_ptr[anchor_id * 4 + 2] = anchors_ptr[4 * a + 2] + shift_x;
67 // y2
68 all_anchors_ptr[anchor_id * 4 + 3] = anchors_ptr[4 * a + 3] + shift_y;
69 }
70 }
71 }
72 return all_anchors;
73}
74template SimpleTensor<float> compute_all_anchors(const SimpleTensor<float> &anchors, const ComputeAnchorsInfo &info);
75template SimpleTensor<half> compute_all_anchors(const SimpleTensor<half> &anchors, const ComputeAnchorsInfo &info);
76} // namespace reference
77} // namespace validation
78} // namespace test
79} // namespace arm_compute