11 #include <boost/numeric/conversion/cast.hpp> 21 void AssertIfNullsOrDuplicates(
const C& container,
const std::string& errorMessage)
23 using T =
typename C::value_type;
24 std::unordered_set<T> duplicateSet;
25 std::for_each(container.begin(), container.end(), [&duplicateSet, &errorMessage](
const T& i)
31 BOOST_ASSERT_MSG(i, errorMessage.c_str());
34 BOOST_ASSERT_MSG(duplicateSet.find(i) == duplicateSet.end(), errorMessage.c_str());
36 duplicateSet.insert(i);
45 , m_Layers(graph.begin(), graph.end())
51 : m_InputSlots{inputs}
52 , m_OutputSlots{outputs}
59 : m_InputSlots(subgraph.m_InputSlots.
begin(), subgraph.m_InputSlots.
end())
60 , m_OutputSlots(subgraph.m_OutputSlots.
begin(), subgraph.m_OutputSlots.
end())
61 , m_Layers(subgraph.m_Layers.
begin(), subgraph.m_Layers.
end())
67 : m_InputSlots(
std::move(subgraph.m_InputSlots))
68 , m_OutputSlots(
std::move(subgraph.m_OutputSlots))
69 , m_Layers(
std::move(subgraph.m_Layers))
77 , m_Layers{boost::polymorphic_downcast<Layer*>(layer)}
79 unsigned int numInputSlots = layer->GetNumInputSlots();
80 m_InputSlots.resize(numInputSlots);
81 for (
unsigned int i = 0; i < numInputSlots; i++)
83 m_InputSlots.at(i) = boost::polymorphic_downcast<InputSlot*>(&(layer->GetInputSlot(i)));
86 unsigned int numOutputSlots = layer->GetNumOutputSlots();
87 m_OutputSlots.resize(numOutputSlots);
88 for (
unsigned int i = 0; i < numOutputSlots; i++)
90 m_OutputSlots.at(i) = boost::polymorphic_downcast<OutputSlot*>(&(layer->GetOutputSlot(i)));
98 m_InputSlots = std::move(other.m_InputSlots);
99 m_OutputSlots = std::move(other.m_OutputSlots);
100 m_Layers = std::move(other.m_Layers);
107 void SubgraphView::CheckSubgraph()
110 AssertIfNullsOrDuplicates(m_InputSlots,
"Sub-graphs cannot contain null or duplicate input slots");
113 AssertIfNullsOrDuplicates(m_OutputSlots,
"Sub-graphs cannot contain null or duplicate output slots");
116 AssertIfNullsOrDuplicates(m_Layers,
"Sub-graphs cannot contain null or duplicate layers");
126 return m_OutputSlots;
131 return m_InputSlots.at(index);
136 return m_InputSlots.at(index);
141 return m_OutputSlots.at(index);
146 return m_OutputSlots.at(index);
166 return m_Layers.begin();
171 return m_Layers.end();
176 return m_Layers.begin();
181 return m_Layers.end();
196 m_InputSlots.clear();
197 m_OutputSlots.clear();
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Layers::iterator Iterator
SubgraphView & operator=(SubgraphView &&other)
Move-assignment operator.
std::vector< OutputSlot * > OutputSlots
unsigned int GetNumInputSlots() const
Copyright (c) 2020 ARM Limited.
void IgnoreUnused(Ts &&...)
The SubgraphView class represents a subgraph of a Graph.
const OutputSlot * GetOutputSlot(unsigned int index) const
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
std::vector< InputSlot * > InputSlots
SubgraphView(Graph &graph)
Constructs a sub-graph from the entire given graph.
const InputSlots & GetInputSlots() const
ConstIterator cend() const
const InputSlot * GetInputSlot(unsigned int index) const
const OutputSlots & GetOutputSlots() const
const Layers & GetLayers() const
ConstIterator cbegin() const
std::list< Layer * > Layers
Layers::const_iterator ConstIterator
unsigned int GetNumOutputSlots() const