blob: 7d7dcbfe2f4302815b2119f61141865bebbe6542 [file] [log] [blame]
Vidhya Sudhan Loganathan5e96be72018-12-18 14:17:00 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2019 Arm Limited.
Vidhya Sudhan Loganathan5e96be72018-12-18 14:17:00 +00003 *
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
27namespace arm_compute
28{
29namespace test
30{
31namespace validation
32{
33namespace reference
34{
35namespace
36{
37template <typename T>
38void 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
49template <typename T>
50SimpleTensor<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
56template <>
57SimpleTensor<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);
Michele Di Giorgio4aff98f2019-08-28 16:27:26 +010063 return convert_to_asymmetric<uint8_t>(dst_tmp, dst.quantization_info());
Vidhya Sudhan Loganathan5e96be72018-12-18 14:17:00 +000064 }
65 generate_range(dst, start, num_of_elements, step);
66 return dst;
67}
68template SimpleTensor<float> range(SimpleTensor<float> &dst, float start, const size_t num_of_elements, float step);
69template SimpleTensor<half> range(SimpleTensor<half> &dst, float start, const size_t num_of_elements, float step);
70template SimpleTensor<int8_t> range(SimpleTensor<int8_t> &dst, float start, const size_t num_of_elements, float step);
71template SimpleTensor<uint16_t> range(SimpleTensor<uint16_t> &dst, float start, const size_t num_of_elements, float step);
72template 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