// // Copyright © 2019 Arm Ltd. All rights reserved. // SPDX-License-Identifier: MIT // #pragma once #include "CommonTestUtils.hpp" #include #include #include #include #include namespace { template INetworkPtr CreateElementwiseUnaryNetwork(const TensorShape& inputShape, const TensorShape& outputShape, UnaryOperation operation, const float qScale = 1.0f, const int32_t qOffset = 0) { using namespace armnn; INetworkPtr net(INetwork::Create()); ElementwiseUnaryDescriptor descriptor(operation); IConnectableLayer* elementwiseUnaryLayer = net->AddElementwiseUnaryLayer(descriptor, "elementwiseUnary"); TensorInfo inputTensorInfo(inputShape, ArmnnTypeInput, qScale, qOffset); IConnectableLayer* input = net->AddInputLayer(armnn::numeric_cast(0)); Connect(input, elementwiseUnaryLayer, inputTensorInfo, 0, 0); TensorInfo outputTensorInfo(outputShape, ArmnnTypeInput, qScale, qOffset); IConnectableLayer* output = net->AddOutputLayer(0, "output"); Connect(elementwiseUnaryLayer, output, outputTensorInfo, 0, 0); return net; } template> void ElementwiseUnarySimpleEndToEnd(const std::vector& backends, UnaryOperation operation, const std::vector expectedOutput) { using namespace armnn; const float qScale = IsQuantizedType() ? 0.25f : 1.0f; const int32_t qOffset = IsQuantizedType() ? 50 : 0; const TensorShape& inputShape = { 2, 2, 2, 2 }; const TensorShape& outputShape = { 2, 2, 2, 2 }; // Builds up the structure of the network INetworkPtr net = CreateElementwiseUnaryNetwork(inputShape, outputShape, operation, qScale, qOffset); CHECK(net); const std::vector input({ 1, -1, 1, 1, 5, -5, 5, 5, -3, 3, 3, 3, 4, 4, -4, 4 }); // quantize data std::vector qInputData = armnnUtils::QuantizedVector(input, qScale, qOffset); std::vector qExpectedOutput = armnnUtils::QuantizedVector(expectedOutput, qScale, qOffset); std::map> inputTensorData = {{ 0, qInputData }}; std::map> expectedOutputData = {{ 0, qExpectedOutput }}; EndToEndLayerTestImpl(move(net), inputTensorData, expectedOutputData, backends); } } // anonymous namespace