// // Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #pragma once #include "BaseIterator.hpp" #include namespace armnn { template inline std::unique_ptr> MakeEncoder(const TensorInfo& info, void* data = nullptr); template<> inline std::unique_ptr> MakeEncoder(const TensorInfo& info, void* data) { switch(info.GetDataType()) { case armnn::DataType::QAsymmS8: { return std::make_unique( static_cast(data), info.GetQuantizationScale(), info.GetQuantizationOffset()); } case armnn::DataType::QAsymmU8: { return std::make_unique( static_cast(data), info.GetQuantizationScale(), info.GetQuantizationOffset()); } case DataType::QSymmS8: { if (info.HasPerAxisQuantization()) { std::pair> params = armnnUtils::GetPerAxisParams(info); return std::make_unique( static_cast(data), params.second, params.first); } else { return std::make_unique( static_cast(data), info.GetQuantizationScale(), info.GetQuantizationOffset()); } } case armnn::DataType::QSymmS16: { if (info.HasPerAxisQuantization()) { unsigned int axis = info.GetQuantizationDim().value(); auto axisDimensionality = info.GetShape()[axis]; std::pair> params = armnnUtils::GetPerAxisParams(info); return std::make_unique( static_cast(data), params.second, params.first, axisDimensionality); } else { return std::make_unique( static_cast(data), info.GetQuantizationScale(), info.GetQuantizationOffset()); } } case armnn::DataType::Signed32: { return std::make_unique(static_cast(data)); } case armnn::DataType::Float16: { return std::make_unique(static_cast(data)); } case armnn::DataType::Float32: { return std::make_unique(static_cast(data)); } default: { throw InvalidArgumentException("Unsupported target Data Type!"); break; } } return nullptr; } template<> inline std::unique_ptr> MakeEncoder(const TensorInfo& info, void* data) { switch(info.GetDataType()) { case armnn::DataType::Signed64: { return std::make_unique(static_cast(data)); } default: { throw InvalidArgumentException("Cannot encode from double. Unsupported target Data Type!"); break; } } return nullptr; } template<> inline std::unique_ptr> MakeEncoder(const TensorInfo& info, void* data) { switch(info.GetDataType()) { case armnn::DataType::Boolean: { return std::make_unique(static_cast(data)); } default: { throw InvalidArgumentException("Cannot encode from boolean. Unsupported target Data Type!"); break; } } return nullptr; } template<> inline std::unique_ptr> MakeEncoder(const TensorInfo& info, void* data) { switch(info.GetDataType()) { case DataType::Signed32: { return std::make_unique(static_cast(data)); } default: { throw InvalidArgumentException("Cannot encode from int32. Unsupported Data Type!"); break; } } return nullptr; } } //namespace armnn