ArmNN
 24.02
DataTypeUtils.hpp File Reference
#include <ResolveType.hpp>
#include <reference/workloads/Encoders.hpp>
#include <vector>
Include dependency graph for DataTypeUtils.hpp:

Go to the source code of this file.

Functions

template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
std::vector< T > ConvertToDataType (const std::vector< float > &input, const armnn::TensorInfo &inputTensorInfo)
 
template<typename T >
ConvertToDataType (const float &value, const armnn::TensorInfo &tensorInfo)
 

Function Documentation

◆ ConvertToDataType() [1/2]

T ConvertToDataType ( const float &  value,
const armnn::TensorInfo tensorInfo 
)

Definition at line 37 of file DataTypeUtils.hpp.

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 }

References Encoder< IType >::Set().

◆ ConvertToDataType() [2/2]

std::vector<T> ConvertToDataType ( const std::vector< float > &  input,
const armnn::TensorInfo inputTensorInfo 
)

Definition at line 17 of file DataTypeUtils.hpp.

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 }

References Encoder< IType >::Set(), and TensorInfo::SetDataType().

armnn::Encoder::Set
virtual void Set(IType right)=0
armnn::TensorInfo::SetDataType
void SetDataType(DataType type)
Definition: Tensor.hpp:201
armnn::Encoder< float >