MCPcopy Create free account
hub / github.com/ARM-software/armnn / ToFloatArray

Function ToFloatArray

src/armnnUtils/TensorUtils.cpp:307–346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

305
306template<typename PrimitiveType>
307std::unique_ptr<float[]> ToFloatArray(const std::vector<PrimitiveType>& data, const armnn::TensorInfo& tensorInfo)
308{
309 CheckSizes(data, tensorInfo);
310
311 std::unique_ptr<float[]> returnBuffer(new float[tensorInfo.GetNumElements()]);
312
313 if (tensorInfo.HasPerAxisQuantization())
314 {
315 unsigned int axis = tensorInfo.GetQuantizationDim().value();
316 auto axisDimensionality = tensorInfo.GetShape()[axis];
317 auto axisFactor = armnnUtils::GetNumElementsAfter(tensorInfo.GetShape(), axis);
318
319 for (unsigned int i = 0; i < tensorInfo.GetNumElements(); ++i)
320 {
321 unsigned int axisIndex;
322
323 if (i < axisFactor)
324 {
325 axisIndex = 0;
326 }
327 else
328 {
329 axisIndex = (i / axisFactor) % axisDimensionality;
330 }
331 returnBuffer[i] = Dequantize<PrimitiveType>(data[i],
332 tensorInfo.GetQuantizationScales()[axisIndex],
333 tensorInfo.GetQuantizationOffset());
334 }
335 }
336 else
337 {
338 for (unsigned int i = 0; i < tensorInfo.GetNumElements(); ++i)
339 {
340 returnBuffer[i] = Dequantize<PrimitiveType>(data[i],
341 tensorInfo.GetQuantizationScale(),
342 tensorInfo.GetQuantizationOffset());
343 }
344 }
345 return returnBuffer;
346}
347
348std::unique_ptr<float[]> ToFloatArray(const std::vector<uint8_t>& data, const armnn::TensorInfo& tensorInfo)
349{

Callers 3

CreateConstTensorPtrMethod · 0.85

Calls 15

CheckSizesFunction · 0.85
GetNumElementsAfterFunction · 0.85
formatEnum · 0.85
GetDataTypeNameFunction · 0.85
GetQuantizationDimMethod · 0.80
GetQuantizationScalesMethod · 0.80
GetNumElementsMethod · 0.45
valueMethod · 0.45
GetShapeMethod · 0.45
GetQuantizationOffsetMethod · 0.45

Tested by

no test coverage detected