xref: /aosp_15_r20/external/armnn/src/backends/backendsCommon/test/ActivationFixture.hpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
7 #include <armnnTestUtils/TensorCopyUtils.hpp>
8 #include <armnnTestUtils/WorkloadTestUtils.hpp>
9 
10 #include <armnn/utility/NumericCast.hpp>
11 
12 #include <armnnTestUtils/TensorHelpers.hpp>
13 
14 struct ActivationFixture
15 {
ActivationFixtureActivationFixture16     ActivationFixture()
17     {
18         output.resize(batchSize * channels * height * width);
19         outputExpected.resize(batchSize * channels * height * width);
20         input.resize(batchSize * channels * height * width);
21 
22         unsigned int inputShape[]  = { batchSize, channels, height, width };
23         unsigned int outputShape[] = { batchSize, channels, height, width };
24 
25         inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32);
26         outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32);
27 
28         input = MakeRandomTensor<float>(inputTensorInfo, 21453);
29     }
30 
31     unsigned int width     = 17;
32     unsigned int height    = 29;
33     unsigned int channels  = 2;
34     unsigned int batchSize = 5;
35 
36     std::vector<float> output;
37     std::vector<float> outputExpected;
38     std::vector<float> input;
39 
40     armnn::TensorInfo inputTensorInfo;
41     armnn::TensorInfo outputTensorInfo;
42 
43     // Parameters used by some of the activation functions.
44     float a = 0.234f;
45     float b = -12.345f;
46 };
47 
48 
49 struct PositiveActivationFixture : public ActivationFixture
50 {
PositiveActivationFixturePositiveActivationFixture51     PositiveActivationFixture()
52     {
53         input = MakeRandomTensor<float>(inputTensorInfo, 2342423, 0.0f, 1.0f);
54     }
55 };