5 #include <boost/test/unit_test.hpp> 16 ostr <<
"TensorInfo[ " 28 ostr <<
"TensorShape[ " 39 using namespace armnn;
43 struct TensorInfoFixture
47 unsigned int sizes[] = {6,7,8,9};
50 ~TensorInfoFixture() {};
58 BOOST_TEST(listInitializedShape == m_TensorInfo.
GetShape());
64 BOOST_TEST(m_TensorInfo.
GetShape()[0] == 6);
65 BOOST_TEST(m_TensorInfo.
GetShape()[1] == 7);
66 BOOST_TEST(m_TensorInfo.
GetShape()[2] == 8);
67 BOOST_TEST(m_TensorInfo.
GetShape()[3] == 9);
74 BOOST_TEST(copyConstructed.
GetShape()[0] == 6);
75 BOOST_TEST(copyConstructed.
GetShape()[1] == 7);
76 BOOST_TEST(copyConstructed.
GetShape()[2] == 8);
77 BOOST_TEST(copyConstructed.
GetShape()[3] == 9);
83 BOOST_TEST(copyConstructed == m_TensorInfo);
89 unsigned int sizes[] = {2,3,4,5};
92 BOOST_TEST(other != m_TensorInfo);
99 BOOST_TEST(copy == m_TensorInfo);
121 BOOST_TEST(infoA != infoB);
123 BOOST_TEST(infoA == infoB);
154 BOOST_TEST(infoA != infoB);
156 BOOST_TEST(infoA == infoB);
172 int mutableDatum = 2;
173 const int immutableDatum = 3;
178 uninitializedTensor2 = uninitializedTensor;
207 BOOST_TEST(shape[2] == 2);
209 BOOST_TEST(shape[2] == 20);
212 BOOST_TEST(constShape[2] == 2);
219 BOOST_CHECK(!tensorInfo0.HasMultipleQuantizationScales());
220 BOOST_CHECK(tensorInfo0.GetQuantizationScale() == 2.0f);
221 BOOST_CHECK(tensorInfo0.GetQuantizationOffset() == 1);
222 BOOST_CHECK(tensorInfo0.GetQuantizationScales()[0] == 2.0f);
223 BOOST_CHECK(!tensorInfo0.GetQuantizationDim().has_value());
226 std::vector<float> perAxisScales{ 3.0f, 4.0f };
228 BOOST_CHECK(tensorInfo0.HasMultipleQuantizationScales());
229 BOOST_CHECK(tensorInfo0.GetQuantizationScales() == perAxisScales);
232 tensorInfo0.SetQuantizationScale(5.0f);
233 BOOST_CHECK(!tensorInfo0.HasMultipleQuantizationScales());
234 BOOST_CHECK(tensorInfo0.GetQuantizationScales()[0] == 5.0f);
238 BOOST_CHECK(tensorInfo0.GetQuantizationDim().value() == 1);
241 perAxisScales = { 6.0f, 7.0f };
243 BOOST_CHECK(tensorInfo1.HasMultipleQuantizationScales());
244 BOOST_CHECK(tensorInfo1.GetQuantizationOffset() == 0);
245 BOOST_CHECK(tensorInfo1.GetQuantizationScales() == perAxisScales);
246 BOOST_CHECK(tensorInfo1.GetQuantizationDim().value() == 1);
251 float mutableDatum = 3.1416f;
258 float scalarValue = *
reinterpret_cast<float*
>(tensor.
GetMemoryArea());
259 BOOST_CHECK_MESSAGE(mutableDatum == scalarValue,
"Scalar value is " << scalarValue);
264 BOOST_TEST(shape_equal == shape);
265 BOOST_TEST(shape_different != shape);
272 BOOST_TEST(1 == shape[0]);
273 BOOST_TEST(1 == tensor.
GetShape()[0]);
277 float newMutableDatum = 42.f;
278 std::memcpy(tensor.
GetMemoryArea(), &newMutableDatum,
sizeof(float));
279 scalarValue = *
reinterpret_cast<float*
>(tensor.
GetMemoryArea());
280 BOOST_CHECK_MESSAGE(newMutableDatum == scalarValue,
"Scalar value is " << scalarValue);
285 float mutableDatum = 3.1416f;
299 BOOST_TEST(shape_equal == shape);
300 BOOST_TEST(shape_different != shape);
305 float mutableDatum = 3.1416f;
323 BOOST_TEST(shape_equal == shape);
324 BOOST_TEST(shape_different != shape);
329 std::vector<float> mutableDatum { 42.f, 42.f, 42.f,
337 BOOST_CHECK_MESSAGE(6 == shape.GetNumElements(),
"Number of elements is " << shape.GetNumElements());
338 BOOST_CHECK_MESSAGE(3 == shape.GetNumDimensions(),
"Number of dimensions is " << shape.GetNumDimensions());
339 BOOST_CHECK(
true == shape.GetDimensionSpecificity(0));
340 BOOST_CHECK(
false == shape.GetDimensionSpecificity(1));
341 BOOST_CHECK(
true == shape.GetDimensionSpecificity(2));
342 BOOST_CHECK(!shape.AreAllDimensionsSpecified());
343 BOOST_CHECK(shape.IsAtLeastOneDimensionSpecified());
349 BOOST_TEST(2 == shape[0]);
350 BOOST_TEST(2 == tensor.
GetShape()[0]);
354 BOOST_TEST(3 == shape[2]);
355 BOOST_TEST(3 == tensor.
GetShape()[2]);
361 BOOST_TEST(shape_equal == shape);
362 BOOST_TEST(shape_different != shape);
367 std::vector<float> mutableDatum { 42.f, 42.f, 42.f,
397 BOOST_TEST(2 == shape[0]);
398 BOOST_TEST(2 == tensor2.
GetShape()[0]);
405 BOOST_TEST(3 == shape[2]);
406 BOOST_TEST(3 == tensor2.
GetShape()[2]);
412 BOOST_TEST(shape_equal == shape);
413 BOOST_TEST(shape_different != shape);
429 BOOST_CHECK_MESSAGE( 0 == shape.GetNumDimensions(),
"Number of dimensions is " << shape.GetNumDimensions());
430 BOOST_CHECK_MESSAGE( 0 == shape.GetNumElements(),
"Number of elements is " << shape.GetNumElements());
432 BOOST_CHECK( shape.AreAllDimensionsSpecified());
436 BOOST_CHECK_MESSAGE( 0 == tensor.GetNumDimensions(),
"Number of dimensions is " << tensor.GetNumDimensions());
437 BOOST_CHECK_MESSAGE( 0 == tensor.GetNumElements(),
"Number of elements is " << tensor.GetNumElements());
438 BOOST_CHECK_MESSAGE( 0 == tensor.GetShape().GetNumDimensions(),
"Number of dimensions is " <<
439 tensor.GetShape().GetNumDimensions());
440 BOOST_CHECK_MESSAGE( 0 == tensor.GetShape().GetNumElements(),
"Number of dimensions is " <<
441 tensor.GetShape().GetNumElements());
443 BOOST_CHECK( tensor.GetShape().AreAllDimensionsSpecified());
unsigned int GetNumElements() const
Function that calculates the tensor elements by multiplying all dimension size which are Specified...
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
const TensorShape & GetShape() const
bool AreAllDimensionsSpecified() const
Checks if there is at least one dimension not specified.
Dimensionality GetDimensionality() const
Function that returns the tensor type.
BOOST_FIXTURE_TEST_CASE(ConstructShapeUsingListInitialization, TensorInfoFixture)
Optional< unsigned int > GetQuantizationDim() const
const TensorShape & GetShape() const
MemoryType GetMemoryArea() const
Copyright (c) 2021 ARM Limited and Contributors.
bool GetDimensionSpecificity(unsigned int i) const
Gets information about if the dimension size has been specified or not.
void SetShape(const TensorShape &newShape)
A tensor defined by a TensorInfo (shape and data type) and a mutable backing store.
void CheckTensor(const ConstTensor &t)
int32_t GetQuantizationOffset() const
float GetQuantizationScale() const
DataType GetDataType() const
bool has_value() const noexcept
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
void SetNumDimensions(unsigned int numDimensions, bool initDimensionsSpecificity=false)
Sets the tensor rank and therefore the Dimensionality is set to Specified if it was not...
void SetQuantizationScale(float scale)
BOOST_AUTO_TEST_CASE(CheckConvolution2dLayer)
const TensorInfo & GetInfo() const
void SetDataType(DataType type)
std::ostream & boost_test_print_type(std::ostream &ostr, const TensorInfo &right)
void SetQuantizationDim(const Optional< unsigned int > &quantizationDim)
BOOST_AUTO_TEST_SUITE_END()
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
void SetDimensionSize(unsigned int i, unsigned int dimensionSize)
Sets the size of the indicated dimension and Specificity for that dimension is set to true...
void SetQuantizationOffset(int32_t offset)
void SetQuantizationScales(const std::vector< float > &scales)
unsigned int GetNumDimensions() const
bool IsAtLeastOneDimensionSpecified() const
Checks if there is at least one dimension specified.