ArmNN
 21.02
TestLayerVisitor.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include <boost/test/unit_test.hpp>
7 #include "TestLayerVisitor.hpp"
8 
9 namespace armnn
10 {
11 
12 void TestLayerVisitor::CheckLayerName(const char* name)
13 {
14  if (name == nullptr)
15  {
16  BOOST_CHECK(m_LayerName == nullptr);
17  }
18  else if (m_LayerName == nullptr)
19  {
20  BOOST_CHECK(name == nullptr);
21  }
22  else
23  {
24  BOOST_CHECK_EQUAL(m_LayerName, name);
25  }
26 }
27 
29 {
30  BOOST_CHECK(layer != nullptr);
31 }
32 
33 void TestLayerVisitor::CheckConstTensors(const ConstTensor& expected, const ConstTensor& actual)
34 {
35  BOOST_CHECK(expected.GetInfo() == actual.GetInfo());
36  BOOST_CHECK(expected.GetNumDimensions() == actual.GetNumDimensions());
37  BOOST_CHECK(expected.GetNumElements() == actual.GetNumElements());
38  BOOST_CHECK(expected.GetNumBytes() == actual.GetNumBytes());
39  if (expected.GetNumBytes() == actual.GetNumBytes())
40  {
41  //check data is the same byte by byte
42  const unsigned char* expectedPtr = static_cast<const unsigned char*>(expected.GetMemoryArea());
43  const unsigned char* actualPtr = static_cast<const unsigned char*>(actual.GetMemoryArea());
44  for (unsigned int i = 0; i < expected.GetNumBytes(); i++)
45  {
46  BOOST_CHECK(*(expectedPtr + i) == *(actualPtr + i));
47  }
48  }
49 }
50 
52  const Optional<ConstTensor>& actual)
53 {
54  BOOST_CHECK(expected.has_value() == actual.has_value());
55  if (expected.has_value() && actual.has_value())
56  {
57  CheckConstTensors(expected.value(), actual.value());
58  }
59 }
60 
61 } //namespace armnn
void CheckLayerName(const char *name)
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:62
void CheckLayerPointer(const IConnectableLayer *layer)
unsigned int GetNumElements() const
Definition: Tensor.hpp:290
MemoryType GetMemoryArea() const
Definition: Tensor.hpp:292
Copyright (c) 2021 ARM Limited and Contributors.
void CheckConstTensors(const ConstTensor &expected, const ConstTensor &actual)
bool has_value() const noexcept
Definition: Optional.hpp:53
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Definition: Tensor.hpp:314
const TensorInfo & GetInfo() const
Definition: Tensor.hpp:282
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:288
void CheckOptionalConstTensors(const Optional< ConstTensor > &expected, const Optional< ConstTensor > &actual)
unsigned int GetNumBytes() const
Definition: Tensor.hpp:289