2 * Copyright (c) 2016, 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 #include "arm_compute/runtime/Pyramid.h"
26 #include "arm_compute/core/Error.h"
27 #include "arm_compute/core/PyramidInfo.h"
28 #include "arm_compute/core/TensorInfo.h"
29 #include "arm_compute/core/TensorShape.h"
30 #include "support/ToolchainSupport.h"
34 using namespace arm_compute;
36 void Pyramid::init(const PyramidInfo &info)
38 internal_init(info, false);
41 void Pyramid::init_auto_padding(const PyramidInfo &info)
43 internal_init(info, true);
46 void Pyramid::internal_init(const PyramidInfo &info, bool auto_padding)
49 _pyramid = arm_compute::support::cpp14::make_unique<Tensor[]>(_info.num_levels());
51 size_t w = _info.width();
52 size_t h = _info.height();
55 bool is_orb_scale = (SCALE_PYRAMID_ORB == _info.scale());
56 TensorShape tensor_shape = _info.tensor_shape();
58 // Note: Look-up table used by the OpenVX sample implementation
59 const float c_orbscale[4] = { 0.5f,
61 SCALE_PYRAMID_ORB * SCALE_PYRAMID_ORB,
62 SCALE_PYRAMID_ORB *SCALE_PYRAMID_ORB * SCALE_PYRAMID_ORB
65 for(size_t i = 0; i < _info.num_levels(); ++i)
67 TensorInfo tensor_info(tensor_shape, _info.format());
71 tensor_info.auto_padding();
74 (_pyramid.get() + i)->allocator()->init(tensor_info);
78 float orb_scale = c_orbscale[(i + 1) % 4];
79 w = static_cast<int>(std::ceil(static_cast<float>(ref_w) * orb_scale));
80 h = static_cast<int>(std::ceil(static_cast<float>(ref_h) * orb_scale));
82 if(0 == ((i + 1) % 4))
90 w = (w + 1) * _info.scale();
91 h = (h + 1) * _info.scale();
94 // Update tensor_shape
95 tensor_shape.set(0, w);
96 tensor_shape.set(1, h);
100 void Pyramid::allocate()
102 ARM_COMPUTE_ERROR_ON(_pyramid == nullptr);
104 for(size_t i = 0; i < _info.num_levels(); ++i)
106 (_pyramid.get() + i)->allocator()->allocate();
110 const PyramidInfo *Pyramid::info() const
115 Tensor *Pyramid::get_pyramid_level(size_t index) const
117 ARM_COMPUTE_ERROR_ON(index >= _info.num_levels());
119 return (_pyramid.get() + index);