xref: /aosp_15_r20/external/ComputeLibrary/tests/validation/reference/Range.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2018-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 "arm_compute/core/Types.h"
25 #include "tests/validation/Helpers.h"
26 
27 namespace arm_compute
28 {
29 namespace test
30 {
31 namespace validation
32 {
33 namespace reference
34 {
35 namespace
36 {
37 template <typename T>
generate_range(SimpleTensor<T> & dst,float start,const size_t num_of_elements,float step)38 void generate_range(SimpleTensor<T> &dst, float start, const size_t num_of_elements, float step)
39 {
40     float val = start;
41     for(size_t index = 0; index < num_of_elements; index++)
42     {
43         dst[index] = static_cast<T>(val);
44         val += step;
45     }
46 }
47 } // namespace
48 
49 template <typename T>
range(SimpleTensor<T> & dst,float start,const size_t num_of_elements,float step)50 SimpleTensor<T> range(SimpleTensor<T> &dst, float start, const size_t num_of_elements, float step)
51 {
52     generate_range(dst, start, num_of_elements, step);
53     return dst;
54 }
55 
56 template <>
range(SimpleTensor<uint8_t> & dst,float start,const size_t num_of_elements,float step)57 SimpleTensor<uint8_t> range(SimpleTensor<uint8_t> &dst, float start, const size_t num_of_elements, float step)
58 {
59     if(dst.data_type() == DataType::QASYMM8)
60     {
61         SimpleTensor<float> dst_tmp{ dst.shape(), DataType::F32, 1 };
62         generate_range(dst_tmp, start, num_of_elements, step);
63         return convert_to_asymmetric<uint8_t>(dst_tmp, dst.quantization_info());
64     }
65     generate_range(dst, start, num_of_elements, step);
66     return dst;
67 }
68 template SimpleTensor<float> range(SimpleTensor<float> &dst, float start, const size_t num_of_elements, float step);
69 template SimpleTensor<half> range(SimpleTensor<half> &dst, float start, const size_t num_of_elements, float step);
70 template SimpleTensor<int8_t> range(SimpleTensor<int8_t> &dst, float start, const size_t num_of_elements, float step);
71 template SimpleTensor<uint16_t> range(SimpleTensor<uint16_t> &dst, float start, const size_t num_of_elements, float step);
72 template SimpleTensor<int16_t> range(SimpleTensor<int16_t> &dst, float start, const size_t num_of_elements, float step);
73 
74 } // namespace reference
75 } // namespace validation
76 } // namespace test
77 } // namespace arm_compute
78