8 #include <fmt/format.h> 10 #include <doctest/doctest.h> 17 CHECK(vec1.size() == vec2.size());
19 bool mismatch =
false;
20 for (uint32_t i = 0; i < vec1.size(); ++i)
22 if (vec1[i] != vec2[i])
24 MESSAGE(fmt::format(
"Vector value mismatch: index={} {} != {}",
35 FAIL(
"Error in CompareVector. Vectors don't match.");
39 using namespace armnn;
42 class MockPerAxisIterator :
public PerAxisIterator<const int8_t, Decoder<int8_t>>
45 MockPerAxisIterator(
const int8_t* data,
const armnn::TensorShape& tensorShape,
const unsigned int axis)
49 int8_t Get()
const override 54 virtual std::vector<float> DecodeTensor(
const TensorShape &tensorShape,
55 bool isDepthwise =
false)
override 58 return std::vector<float>{};
62 std::vector<int8_t> Loop()
64 std::vector<int8_t> vec;
65 for (uint32_t i = 0; i < m_NumElements; ++i)
68 vec.emplace_back(Get());
73 unsigned int GetAxisIndex()
77 unsigned int m_NumElements;
83 TEST_CASE(
"PerAxisIteratorTest1")
85 std::vector<int8_t> input = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
89 std::vector<int8_t> expOutput = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
90 auto iterator = MockPerAxisIterator(input.data(), tensorInfo.GetShape(), 0);
91 std::vector<int8_t> output = iterator.Loop();
96 CHECK(iterator.GetAxisIndex() == 1u);
99 CHECK(iterator.GetAxisIndex() == 0u);
102 CHECK(iterator.GetAxisIndex() == 2u);
106 TEST_CASE(
"PerAxisIteratorTest2")
108 std::vector<int8_t> input = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
112 std::vector<int8_t> expOutput = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
113 auto iterator = MockPerAxisIterator(input.data(), tensorInfo.GetShape(), 1);
114 std::vector<int8_t> output = iterator.Loop();
119 CHECK(iterator.GetAxisIndex() == 0u);
122 CHECK(iterator.GetAxisIndex() == 0u);
125 CHECK(iterator.GetAxisIndex() == 0u);
129 TEST_CASE(
"PerAxisIteratorTest3")
131 std::vector<int8_t> input = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
135 std::vector<int8_t> expOutput = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
136 auto iterator = MockPerAxisIterator(input.data(), tensorInfo.GetShape(), 2);
137 std::vector<int8_t> output = iterator.Loop();
142 CHECK(iterator.GetAxisIndex() == 0u);
145 CHECK(iterator.GetAxisIndex() == 0u);
148 CHECK(iterator.GetAxisIndex() == 1u);
152 TEST_CASE(
"PerAxisIteratorTest4")
154 std::vector<int8_t> input = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
158 std::vector<int8_t> expOutput = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
159 auto iterator = MockPerAxisIterator(input.data(), tensorInfo.GetShape(), 3);
160 std::vector<int8_t> output = iterator.Loop();
165 CHECK(iterator.GetAxisIndex() == 1u);
168 CHECK(iterator.GetAxisIndex() == 1u);
171 CHECK(iterator.GetAxisIndex() == 0u);
175 TEST_CASE(
"PerAxisIteratorTest5")
177 using namespace armnn;
178 std::vector<int8_t> input =
186 std::vector<int8_t> expOutput =
195 auto iterator = MockPerAxisIterator(input.data(), tensorInfo.GetShape(), 1);
196 std::vector<int8_t> output = iterator.Loop();
201 CHECK(iterator.GetAxisIndex() == 1u);
204 CHECK(iterator.GetAxisIndex() == 0u);
207 CHECK(iterator.GetAxisIndex() == 0u);
211 TEST_CASE(
"PerAxisIteratorTest7")
213 using namespace armnn;
214 std::vector<int8_t> input =
221 std::vector<int8_t> expOutput =
229 auto iterator = MockPerAxisIterator(input.data(), tensorInfo.GetShape(), 2);
232 CHECK(iterator.Get() == expOutput[3]);
233 CHECK(iterator.GetAxisIndex() == 1u);
236 CHECK(iterator.Get() == expOutput[6]);
237 CHECK(iterator.GetAxisIndex() == 1u);
240 CHECK(iterator.Get() == expOutput[4]);
241 CHECK(iterator.GetAxisIndex() == 0u);
244 CHECK(iterator.Get() == expOutput[3]);
245 CHECK(iterator.GetAxisIndex() == 1u);
TEST_SUITE("TestConstTensorLayerVisitor")
unsigned int GetNumElements() const
Function that calculates the tensor elements by multiplying all dimension size which are Specified...
PerAxisIterator for per-axis quantization.
void CompareVector(std::vector< T > vec1, std::vector< T > vec2)
Copyright (c) 2021 ARM Limited and Contributors.
void IgnoreUnused(Ts &&...)