ArmNN
 21.08
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 "TestLayerVisitor.hpp"
7 
8 #include <doctest/doctest.h>
9 
10 namespace armnn
11 {
12 
13 void TestLayerVisitor::CheckLayerName(const char* name)
14 {
15  if (name == nullptr)
16  {
17  CHECK(m_LayerName == nullptr);
18  }
19  else if (m_LayerName == nullptr)
20  {
21  CHECK(name == nullptr);
22  }
23  else
24  {
25  CHECK_EQ(std::string(m_LayerName), std::string(name));
26  }
27 }
28 
30 {
31  CHECK(layer != nullptr);
32 }
33 
34 void TestLayerVisitor::CheckConstTensors(const ConstTensor& expected, const ConstTensor& actual)
35 {
36  CHECK(expected.GetInfo() == actual.GetInfo());
37  CHECK(expected.GetNumDimensions() == actual.GetNumDimensions());
38  CHECK(expected.GetNumElements() == actual.GetNumElements());
39  CHECK(expected.GetNumBytes() == actual.GetNumBytes());
40  if (expected.GetNumBytes() == actual.GetNumBytes())
41  {
42  //check data is the same byte by byte
43  const unsigned char* expectedPtr = static_cast<const unsigned char*>(expected.GetMemoryArea());
44  const unsigned char* actualPtr = static_cast<const unsigned char*>(actual.GetMemoryArea());
45  for (unsigned int i = 0; i < expected.GetNumBytes(); i++)
46  {
47  CHECK(*(expectedPtr + i) == *(actualPtr + i));
48  }
49  }
50 }
51 
53  const Optional<ConstTensor>& actual)
54 {
55  CHECK(expected.has_value() == actual.has_value());
56  if (expected.has_value() && actual.has_value())
57  {
58  CheckConstTensors(expected.value(), actual.value());
59  }
60 }
61 
62 } //namespace armnn
void CheckLayerName(const char *name)
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:61
void CheckLayerPointer(const IConnectableLayer *layer)
unsigned int GetNumElements() const
Definition: Tensor.hpp:303
MemoryType GetMemoryArea() const
Definition: Tensor.hpp:305
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:327
const TensorInfo & GetInfo() const
Definition: Tensor.hpp:295
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:301
void CheckOptionalConstTensors(const Optional< ConstTensor > &expected, const Optional< ConstTensor > &actual)
unsigned int GetNumBytes() const
Definition: Tensor.hpp:302