Compute Library  18.05
Graph Class Referencefinal

Graph class. More...

#include <Graph.h>

Public Member Functions

 Graph ()=default
 
 Graph (GraphID id, std::string name)
 Constructor. More...
 
 Graph (const Graph &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
Graphoperator= (const Graph &)=delete
 Prevent instances of this class from being copy assigned (As this class contains pointers) More...
 
 Graph (Graph &&)=default
 Allow instances of this class to be moved. More...
 
Graphoperator= (Graph &&)=default
 Allow instances of this class to be move assigned. More...
 
template<typename NT , typename... Ts>
NodeID add_node (Ts &&...args)
 Adds a node to the graph. More...
 
bool remove_node (NodeID nid)
 Remove the node with the given ID. More...
 
EdgeID add_connection (NodeID source, size_t source_idx, NodeID sink, size_t sink_idx)
 Adds a connection between two nodes. More...
 
bool remove_connection (EdgeID eid)
 Removes an edge (connection) More...
 
std::string name () const
 Returns graph name. More...
 
GraphID id () const
 Returns graph id. More...
 
const std::vector< NodeID > & inputs ()
 Returns graph input nodes. More...
 
std::vector< std::unique_ptr< INode > > & nodes ()
 Returns nodes of graph. More...
 
const std::vector< std::unique_ptr< INode > > & nodes () const
 Returns nodes of graph. More...
 
const std::vector< std::unique_ptr< Edge > > & edges () const
 Returns edges of graph. More...
 
std::vector< std::unique_ptr< Tensor > > & tensors ()
 Returns tensors of graph. More...
 
const std::vector< std::unique_ptr< Tensor > > & tensors () const
 Returns tensors of graph. More...
 
const INodenode (NodeID id) const
 Get node object given its id. More...
 
INodenode (NodeID id)
 Get node object given its id. More...
 
const Edgeedge (EdgeID id) const
 Get edge object given its id. More...
 
Edgeedge (EdgeID id)
 Get edge object given its id. More...
 
const Tensortensor (TensorID id) const
 Get tensor object given its id. More...
 
Tensortensor (TensorID id)
 Get tensor object given its id. More...
 

Detailed Description

Graph class.

Represents a multiple source - multiple sink directed graph

Definition at line 50 of file Graph.h.

Constructor & Destructor Documentation

Graph ( )
default
Graph ( GraphID  id,
std::string  name 
)

Constructor.

Parameters
[in]idGraph identification number. Can be used to differentiate between graphs. Default value 0
[in]nameGraph name. Default value empty string
Graph ( const Graph )
delete

Prevent instances of this class from being copied (As this class contains pointers)

Graph ( Graph &&  )
default

Allow instances of this class to be moved.

Member Function Documentation

EdgeID add_connection ( NodeID  source,
size_t  source_idx,
NodeID  sink,
size_t  sink_idx 
)

Adds a connection between two nodes.

Parameters
[in]sourceID of the source node
[in]source_idxOutput index of the source node
[in]sinkID of the sink node
[in]sink_idxInput index of the sink node
Returns
ID of this connection
NodeID add_node ( Ts &&...  args)
inline

Adds a node to the graph.

Note
Models a single output node
Template Parameters
NTNode operation
TsArguments to operation
Parameters
argsNode arguments
Returns
ID of the node

Definition at line 230 of file Graph.h.

References INode::forward_descriptors(), arm_compute::graph::Input, Graph::node(), INode::set_graph(), INode::set_id(), and INode::type().

231 {
232  std::lock_guard<arm_compute::Mutex> lock(_mtx);
233 
234  // Create node
235  NodeID nid = _nodes.size();
236  auto node = support::cpp14::make_unique<NT>(std::forward<Ts>(args)...);
237  node->set_graph(this);
238  node->set_id(nid);
239 
240  // Keep track of input nodes
241  if(node->type() == NodeType::Input)
242  {
243  _tagged_nodes[NodeType::Input].push_back(nid);
244  }
245 
246  // Associate a new tensor with each output
247  for(auto &output : node->_outputs)
248  {
249  output = create_tensor();
250  }
251 
252  // Propagate node shape if possible
254 
255  // Add node to the graph nodes
256  _nodes.push_back(std::move(node));
257 
258  return nid;
259 }
const INode * node(NodeID id) const
Get node object given its id.
void set_graph(Graph *g)
Sets the graph that this node is registered to.
void set_id(NodeID id)
Sets the node id.
unsigned int NodeID
Definition: Types.h:57
virtual bool forward_descriptors()=0
Forwards descriptor information to outputs if possible.
virtual NodeType type() const =0
Returns node&#39;s type.
const Edge* edge ( EdgeID  id) const

Get edge object given its id.

Warning
Can be nullptr if node was removed during the mutation steps of the graph
Parameters
[in]idEdge ID
Returns
The actual edge object

Referenced by arm_compute::graph::detail::all_inputs_are_visited(), and arm_compute::graph::bfs().

Edge* edge ( EdgeID  id)

Get edge object given its id.

Warning
Can be nullptr if node was removed during the mutation steps of the graph
Parameters
[in]idEdge ID
Returns
The actual edge object
const std::vector<std::unique_ptr<Edge> >& edges ( ) const

Returns edges of graph.

Warning
Edges can be nullptr if they have been removed during the mutation steps of the graph
Returns
Edges of graph
GraphID id ( ) const

Returns graph id.

Returns
Graph id
const std::vector<NodeID>& inputs ( )

Returns graph input nodes.

Returns
vector containing the graph inputs

Referenced by arm_compute::graph::bfs().

std::string name ( ) const

Returns graph name.

Returns
Graph name
const INode* node ( NodeID  id) const

Get node object given its id.

Warning
Can be nullptr if node was removed during the mutation steps of the graph
Parameters
[in]idNode ID
Returns
The actual node object

Referenced by Graph::add_node(), arm_compute::graph::bfs(), and BranchLayer::create_layer().

INode* node ( NodeID  id)

Get node object given its id.

Warning
Can be nullptr if node was removed during the mutation steps of the graph
Parameters
[in]idNode ID
Returns
The actual node object
std::vector<std::unique_ptr<INode> >& nodes ( )

Returns nodes of graph.

Warning
Nodes can be nullptr if they have been removed during the mutation steps of the graph
Returns
Nodes of graph

Referenced by arm_compute::graph::bfs().

const std::vector<std::unique_ptr<INode> >& nodes ( ) const

Returns nodes of graph.

Warning
Nodes can be nullptr if they have been removed during the mutation steps of the graph
Returns
Nodes of graph
Graph& operator= ( const Graph )
delete

Prevent instances of this class from being copy assigned (As this class contains pointers)

Graph& operator= ( Graph &&  )
default

Allow instances of this class to be move assigned.

bool remove_connection ( EdgeID  eid)

Removes an edge (connection)

Parameters
[in]eidConnection to remove
Returns
True if the removal took place else false
bool remove_node ( NodeID  nid)

Remove the node with the given ID.

Parameters
[in]nidID of the node to remove
Returns
True if the removal took place else false
const Tensor* tensor ( TensorID  id) const

Get tensor object given its id.

Warning
Can be nullptr if tensor was removed during the mutation steps of the graph
Parameters
[in]idTensor ID
Returns
The actual tensor object

Referenced by arm_compute::graph::get_tensor_descriptor().

Tensor* tensor ( TensorID  id)

Get tensor object given its id.

Warning
Can be nullptr if tensor was removed during the mutation steps of the graph
Parameters
[in]idTensor ID
Returns
The actual tensor object
std::vector<std::unique_ptr<Tensor> >& tensors ( )

Returns tensors of graph.

Warning
Tensor can be nullptr if they have been removed during the mutation steps of the graph
Returns
Tensors of graph
const std::vector<std::unique_ptr<Tensor> >& tensors ( ) const

Returns tensors of graph.

Warning
Tensor can be nullptr if they have been removed during the mutation steps of the graph
Returns
Tensors of graph

The documentation for this class was generated from the following file: