ArmNN
 20.02
CommonTestUtils.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <Graph.hpp>
9 #include <SubgraphView.hpp>
10 #include <SubgraphViewSelector.hpp>
11 
13 
15 
16 #include <test/TestUtils.hpp>
17 
18 #include <algorithm>
19 
20 // Checks that two collections have the exact same contents (in any order)
21 // The given collections do not have to contain duplicates
22 // Cannot use std::sort here because std lists have their own std::list::sort method
23 template <typename CollectionType>
24 bool AreEqual(const CollectionType& lhs, const CollectionType& rhs)
25 {
26  if (lhs.size() != rhs.size())
27  {
28  return false;
29  }
30 
31  auto lhs_it = std::find_if(lhs.begin(), lhs.end(), [&rhs](auto& item)
32  {
33  return std::find(rhs.begin(), rhs.end(), item) == rhs.end();
34  });
35 
36  return lhs_it == lhs.end();
37 }
38 
39 // Checks that the given collection contains the specified item
40 template <typename CollectionType>
41 bool Contains(const CollectionType& collection, const typename CollectionType::value_type& item)
42 {
43  return std::find(collection.begin(), collection.end(), item) != collection.end();
44 }
45 
46 // Checks that the given map contains the specified key
47 template <typename MapType>
48 bool Contains(const MapType& map, const typename MapType::key_type& key)
49 {
50  return map.find(key) != map.end();
51 }
52 
53 template <typename ConvolutionLayer>
54 void SetWeightAndBias(ConvolutionLayer* layer, const armnn::TensorInfo& weightInfo, const armnn::TensorInfo& biasInfo)
55 {
56  layer->m_Weight = std::make_unique<armnn::ScopedCpuTensorHandle>(weightInfo);
57  layer->m_Bias = std::make_unique<armnn::ScopedCpuTensorHandle>(biasInfo);
58 
59  layer->m_Weight->Allocate();
60  layer->m_Bias->Allocate();
61 }
62 
63 armnn::SubgraphView::InputSlots CreateInputsFrom(const std::vector<armnn::Layer*>& layers);
64 
65 armnn::SubgraphView::OutputSlots CreateOutputsFrom(const std::vector<armnn::Layer*>& layers);
66 
70 
72 
73 armnn::TensorShape MakeTensorShape(unsigned int batches,
74  unsigned int channels,
75  unsigned int height,
76  unsigned int width,
77  armnn::DataLayout layout);
DataLayout
Definition: Types.hpp:49
armnn::SubgraphView::InputSlots CreateInputsFrom(const std::vector< armnn::Layer *> &layers)
armnn::SubgraphView::SubgraphViewPtr CreateSubgraphViewFrom(armnn::SubgraphView::InputSlots &&inputs, armnn::SubgraphView::OutputSlots &&outputs, armnn::SubgraphView::Layers &&layers)
armnn::IBackendInternalUniquePtr CreateBackendObject(const armnn::BackendId &backendId)
bool AreEqual(const CollectionType &lhs, const CollectionType &rhs)
armnn::TensorShape MakeTensorShape(unsigned int batches, unsigned int channels, unsigned int height, unsigned int width, armnn::DataLayout layout)
std::vector< OutputSlot * > OutputSlots
armnn::SubgraphView::OutputSlots CreateOutputsFrom(const std::vector< armnn::Layer *> &layers)
std::unique_ptr< SubgraphView > SubgraphViewPtr
bool Contains(const CollectionType &collection, const typename CollectionType::value_type &item)
std::vector< InputSlot * > InputSlots
void SetWeightAndBias(ConvolutionLayer *layer, const armnn::TensorInfo &weightInfo, const armnn::TensorInfo &biasInfo)
std::unique_ptr< IBackendInternal > IBackendInternalUniquePtr
std::list< Layer * > Layers