Public Types | Public Member Functions | Static Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
ngraph::pattern::Matcher Class Reference

#include <matcher.hpp>

Collaboration diagram for ngraph::pattern::Matcher:
Collaboration graph
[legend]

Public Types

using PatternMap = ngraph::pattern::PatternMap
 

Public Member Functions

 Matcher (const std::shared_ptr< Node > pattern_node, std::nullptr_t name)=delete
 
 Matcher (Output< Node > &pattern_node)
 
 Matcher (Output< Node > &pattern_node, const std::string &name)
 
 Matcher (const Output< Node > &pattern_node, const std::string &name, bool strict_mode)
 Constructs a Matcher object. More...
 
 Matcher (std::shared_ptr< Node > pattern_node)
 
 Matcher (std::shared_ptr< Node > pattern_node, const std::string &name)
 
 Matcher (std::shared_ptr< Node > pattern_node, const std::string &name, bool strict_mode)
 
bool match (const Output< Node > &graph_value)
 Matches a pattern to graph_node. More...
 
bool match (std::shared_ptr< Node > graph_node)
 
bool match (const Output< Node > &graph_value, const PatternMap &previous_matches)
 Matches a pattern to graph_node. More...
 
bool match (const Output< Node > &graph_value, const PatternValueMap &previous_matches)
 
bool is_contained_match (const NodeVector &exclusions={}, bool ignore_unused=true)
 
const NodeVector get_matched_nodes ()
 
const OutputVector & get_matched_values () const
 
OutputVector & get_matched_values ()
 
void reset ()
 
const std::string & get_name ()
 
std::shared_ptr< Nodeget_pattern ()
 
Output< Nodeget_pattern_value ()
 
std::shared_ptr< Nodeget_match_root ()
 
Output< Nodeget_match_value ()
 
PatternMap get_pattern_map () const
 
PatternValueMap & get_pattern_value_map ()
 
PatternValueMaps & get_pattern_value_maps ()
 
size_t add_node (Output< Node > node)
 Low-level helper to match recurring patterns. More...
 
virtual bool match_value (const ngraph::Output< Node > &pattern_value, const ngraph::Output< Node > &graph_value)
 
bool is_strict_mode ()
 
virtual bool match_arguments (Node *pattern_node, const std::shared_ptr< Node > &graph_node)
 
void capture (const std::set< Node * > &static_nodes)
 
void clear_state ()
 
size_t get_number_of_recurrent_matches () const
 
NodeVector get_bound_nodes_for_pattern (const Output< Node > &pattern) const
 
size_t get_number_of_bound_labels () const
 
MatcherState start_match ()
 Try a match.
 

Static Public Member Functions

template<typename T >
static std::shared_ptr< T > unique_match (std::shared_ptr< Node > node)
 

Data Fields

Output< Nodem_match_root
 
Output< Nodem_pattern_node
 
PatternValueMap m_pattern_map
 
PatternValueMaps m_pattern_value_maps
 
OutputVector m_matched_list
 

Protected Member Functions

bool match_permutation (const OutputVector &pattern_args, const OutputVector &args)
 

Protected Attributes

std::string m_name {"unnamed"}
 
bool m_strict_mode {false}
 

Detailed Description

Matcher looks for node patterns in a computation graph. The patterns are described by an automaton that is described by an extended computation graph. The matcher executes by attempting to match the start node of the pattern to a computation graph value (output of a Node). In addition to determing if a match occurs, a pattern node may add graph nodes to a list of matched nodes, associate nodes with graph values, and start submatches. Submatches add match state changes to the enclosing match if the submatch succeeds; otherwise the state is reverted.

The default match behavior of a pattern node with a graph nodes is that the computation graph value is added to the end of the matched value list and the match succeeds if the node/pattern types match and the input values match. In the case of a commutative node, the inputs can match in any order. If the matcher is in strict mode, the graph value element type and shape must also match.

Pattern nodes that have different match behavior are in ngraph::pattern::op and have descriptions of their match behavior.

Constructor & Destructor Documentation

◆ Matcher()

ngraph::pattern::Matcher::Matcher ( const Output< Node > &  pattern_node,
const std::string &  name,
bool  strict_mode 
)
inline

Constructs a Matcher object.

Parameters
pattern_nodeis a pattern sub graph that will be matched against input graphs
nameis a string which is used for logging and disabling a matcher
strict_modeforces a matcher to consider shapes and ET of nodes

Member Function Documentation

◆ add_node()

size_t ngraph::pattern::Matcher::add_node ( Output< Node node)

Low-level helper to match recurring patterns.

Parameters
graphis a graph to be matched against
patternis a recurring pattern
rpatternspecifies a node to recur from next
patternsa map from labels to matches

◆ match() [1/2]

bool ngraph::pattern::Matcher::match ( const Output< Node > &  graph_value)

Matches a pattern to graph_node.

Parameters
graph_valueis an input graph to be matched against

◆ match() [2/2]

bool ngraph::pattern::Matcher::match ( const Output< Node > &  graph_value,
const PatternMap &  previous_matches 
)

Matches a pattern to graph_node.

Parameters
graph_valueis an input graph to be matched against
previous_matchescontains previous mappings from labels to nodes to use

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