13 #include <boost/test/unit_test.hpp> 20 template<armnn::DataType ArmnnTypeInput>
21 INetworkPtr CreateElementwiseUnaryNetwork(
const TensorShape& inputShape,
22 const TensorShape& outputShape,
24 const float qScale = 1.0f,
25 const int32_t qOffset = 0)
27 using namespace armnn;
32 IConnectableLayer* elementwiseUnaryLayer = net->AddElementwiseUnaryLayer(descriptor,
"elementwiseUnary");
34 TensorInfo inputTensorInfo(inputShape, ArmnnTypeInput, qScale, qOffset);
35 IConnectableLayer* input = net->AddInputLayer(boost::numeric_cast<LayerBindingId>(0));
36 Connect(input, elementwiseUnaryLayer, inputTensorInfo, 0, 0);
38 TensorInfo outputTensorInfo(outputShape, ArmnnTypeInput, qScale, qOffset);
40 Connect(elementwiseUnaryLayer, output, outputTensorInfo, 0, 0);
47 void ElementwiseUnarySimpleEndToEnd(
const std::vector<BackendId>& backends,
49 const std::vector<float> expectedOutput)
51 using namespace armnn;
53 const float qScale = IsQuantizedType<TInput>() ? 0.25f : 1.0f;
54 const int32_t qOffset = IsQuantizedType<TInput>() ? 50 : 0;
60 INetworkPtr net = CreateElementwiseUnaryNetwork<ArmnnInType>(inputShape, outputShape, operation, qScale, qOffset);
62 BOOST_TEST_CHECKPOINT(
"create a network");
64 const std::vector<float> input({ 1, -1, 1, 1, 5, -5, 5, 5,
65 -3, 3, 3, 3, 4, 4, -4, 4 });
68 std::vector<TInput> qInputData = armnnUtils::QuantizedVector<TInput>(input, qScale, qOffset);
69 std::vector<TInput> qExpectedOutput = armnnUtils::QuantizedVector<TInput>(expectedOutput, qScale, qOffset);
71 std::map<int, std::vector<TInput>> inputTensorData = {{ 0, qInputData }};
72 std::map<int, std::vector<TInput>> expectedOutputData = {{ 0, qExpectedOutput }};
74 EndToEndLayerTestImpl<ArmnnInType, ArmnnInType>(move(net), inputTensorData, expectedOutputData, backends);
typename ResolveTypeImpl< DT >::Type ResolveType
A ElementwiseUnaryDescriptor for the ElementwiseUnaryLayer.
static INetworkPtr Create()
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
void Connect(armnn::IConnectableLayer *from, armnn::IConnectableLayer *to, const armnn::TensorInfo &tensorInfo, unsigned int fromIndex, unsigned int toIndex)
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.