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);
109 int mutableDatum = 2;
110 const int immutableDatum = 3;
115 uninitializedTensor2 = uninitializedTensor;
144 BOOST_TEST(shape[2] == 2);
146 BOOST_TEST(shape[2] == 20);
149 BOOST_TEST(constShape[2] == 2);
156 BOOST_CHECK(!tensorInfo0.HasMultipleQuantizationScales());
157 BOOST_CHECK(tensorInfo0.GetQuantizationScale() == 2.0f);
158 BOOST_CHECK(tensorInfo0.GetQuantizationOffset() == 1);
159 BOOST_CHECK(tensorInfo0.GetQuantizationScales()[0] == 2.0f);
160 BOOST_CHECK(!tensorInfo0.GetQuantizationDim().has_value());
163 std::vector<float> perAxisScales{ 3.0f, 4.0f };
165 BOOST_CHECK(tensorInfo0.HasMultipleQuantizationScales());
166 BOOST_CHECK(tensorInfo0.GetQuantizationScales() == perAxisScales);
169 tensorInfo0.SetQuantizationScale(5.0f);
170 BOOST_CHECK(!tensorInfo0.HasMultipleQuantizationScales());
171 BOOST_CHECK(tensorInfo0.GetQuantizationScales()[0] == 5.0f);
175 BOOST_CHECK(tensorInfo0.GetQuantizationDim().value() == 1);
178 perAxisScales = { 6.0f, 7.0f };
180 BOOST_CHECK(tensorInfo1.HasMultipleQuantizationScales());
181 BOOST_CHECK(tensorInfo1.GetQuantizationOffset() == 0);
182 BOOST_CHECK(tensorInfo1.GetQuantizationScales() == perAxisScales);
183 BOOST_CHECK(tensorInfo1.GetQuantizationDim().value() == 1);
188 float mutableDatum = 3.1416f;
195 float scalarValue = *
reinterpret_cast<float*
>(tensor.
GetMemoryArea());
196 BOOST_CHECK_MESSAGE(mutableDatum == scalarValue,
"Scalar value is " << scalarValue);
201 BOOST_TEST(shape_equal == shape);
202 BOOST_TEST(shape_different != shape);
209 BOOST_TEST(1 == shape[0]);
210 BOOST_TEST(1 == tensor.
GetShape()[0]);
214 float newMutableDatum = 42.f;
215 std::memcpy(tensor.
GetMemoryArea(), &newMutableDatum,
sizeof(float));
216 scalarValue = *
reinterpret_cast<float*
>(tensor.
GetMemoryArea());
217 BOOST_CHECK_MESSAGE(newMutableDatum == scalarValue,
"Scalar value is " << scalarValue);
222 float mutableDatum = 3.1416f;
236 BOOST_TEST(shape_equal == shape);
237 BOOST_TEST(shape_different != shape);
242 float mutableDatum = 3.1416f;
260 BOOST_TEST(shape_equal == shape);
261 BOOST_TEST(shape_different != shape);
266 std::vector<float> mutableDatum { 42.f, 42.f, 42.f,
274 BOOST_CHECK_MESSAGE(6 == shape.GetNumElements(),
"Number of elements is " << shape.GetNumElements());
275 BOOST_CHECK_MESSAGE(3 == shape.GetNumDimensions(),
"Number of dimensions is " << shape.GetNumDimensions());
276 BOOST_CHECK(
true == shape.GetDimensionSpecificity(0));
277 BOOST_CHECK(
false == shape.GetDimensionSpecificity(1));
278 BOOST_CHECK(
true == shape.GetDimensionSpecificity(2));
279 BOOST_CHECK(!shape.AreAllDimensionsSpecified());
280 BOOST_CHECK(shape.IsAtLeastOneDimensionSpecified());
286 BOOST_TEST(2 == shape[0]);
287 BOOST_TEST(2 == tensor.
GetShape()[0]);
291 BOOST_TEST(3 == shape[2]);
292 BOOST_TEST(3 == tensor.
GetShape()[2]);
298 BOOST_TEST(shape_equal == shape);
299 BOOST_TEST(shape_different != shape);
304 std::vector<float> mutableDatum { 42.f, 42.f, 42.f,
334 BOOST_TEST(2 == shape[0]);
335 BOOST_TEST(2 == tensor2.
GetShape()[0]);
342 BOOST_TEST(3 == shape[2]);
343 BOOST_TEST(3 == tensor2.
GetShape()[2]);
349 BOOST_TEST(shape_equal == shape);
350 BOOST_TEST(shape_different != shape);
366 BOOST_CHECK_MESSAGE( 0 == shape.GetNumDimensions(),
"Number of dimensions is " << shape.GetNumDimensions());
367 BOOST_CHECK_MESSAGE( 0 == shape.GetNumElements(),
"Number of elements is " << shape.GetNumElements());
369 BOOST_CHECK( shape.AreAllDimensionsSpecified());
373 BOOST_CHECK_MESSAGE( 0 == tensor.GetNumDimensions(),
"Number of dimensions is " << tensor.GetNumDimensions());
374 BOOST_CHECK_MESSAGE( 0 == tensor.GetNumElements(),
"Number of elements is " << tensor.GetNumElements());
375 BOOST_CHECK_MESSAGE( 0 == tensor.GetShape().GetNumDimensions(),
"Number of dimensions is " <<
376 tensor.GetShape().GetNumDimensions());
377 BOOST_CHECK_MESSAGE( 0 == tensor.GetShape().GetNumElements(),
"Number of dimensions is " <<
378 tensor.GetShape().GetNumElements());
380 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)
const TensorShape & GetShape() const
MemoryType GetMemoryArea() const
Copyright (c) 2020 ARM Limited.
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
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)
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.