• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <ResolveType.hpp>
9 
10 
11 #include <reference/workloads/Encoders.hpp>
12 
13 #include <vector>
14 
15 // Utility tenmplate to convert a collection of values to the correct type
16 template <armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
ConvertToDataType(const std::vector<float> & input,const armnn::TensorInfo & inputTensorInfo)17 std::vector<T> ConvertToDataType(const std::vector<float>& input,
18                                  const armnn::TensorInfo& inputTensorInfo)
19 {
20     std::vector<T> output(input.size());
21     auto outputTensorInfo = inputTensorInfo;
22     outputTensorInfo.SetDataType(ArmnnType);
23 
24     std::unique_ptr<armnn::Encoder<float>> pOutputEncoder = armnn::MakeEncoder<float>(outputTensorInfo, output.data());
25     armnn::Encoder<float>& rOutputEncoder = *pOutputEncoder;
26 
27     for (auto it = input.begin(); it != input.end(); ++it)
28     {
29         rOutputEncoder.Set(*it);
30         ++rOutputEncoder;
31     }
32     return output;
33 }
34 
35 // Utility tenmplate to convert a single value to the correct type
36 template <typename T>
ConvertToDataType(const float & value,const armnn::TensorInfo & tensorInfo)37 T ConvertToDataType(const float& value,
38                     const armnn::TensorInfo& tensorInfo)
39 {
40     std::vector<T> output(1);
41     std::unique_ptr<armnn::Encoder<float>> pEncoder = armnn::MakeEncoder<float>(tensorInfo, output.data());
42     armnn::Encoder<float>& rEncoder = *pEncoder;
43     rEncoder.Set(value);
44     return output[0];
45 }
46