Home | History | Annotate | Download | only in python

Lines Matching defs:Pattern

24 class Pattern(object):
29 """Returns the result of matching op/tensor against this pattern."""
33 class OpTypePattern(Pattern):
34 """A tree pattern that matches TF expressions with certain op types."""
46 name: Optional string. The name of the pattern that can be looked up in
48 inputs: Optional list of `Pattern`s or strings that specify the
49 patterns for the inputs of a matching op. If None, this pattern accepts
58 if isinstance(input_pattern, Pattern) else OpTypePattern(input_pattern)
75 # If pattern.inputs is empty, skips the rest and accepts all the inputs.
89 class OneofPattern(Pattern):
108 output tensor used by the matching op of the parent pattern. E.g., when we
132 def add(self, pattern, op, tensor):
133 self._pattern_to_op_tensor[pattern] = op, tensor
134 if pattern.name is not None:
135 if pattern.name in self._name_to_pattern:
137 'Name %s is already bound to another pattern' % pattern.name)
138 self._name_to_pattern[pattern.name] = pattern
153 pattern = self._to_pattern(pattern_or_name)
154 if pattern is None:
157 if pattern not in self._pattern_to_op_tensor:
160 return self._pattern_to_op_tensor[pattern]
178 """Checks if a particular subgraph matches a given pattern."""
180 def __init__(self, pattern):
184 pattern: The `Pattern` against which `GraphMatcher` matches
187 self._pattern = pattern
189 def _match_pattern(self, pattern, op, tensor):
190 """Returns whether an TF expression rooted at `op` matches `pattern`.
193 with key `pattern`.
196 pattern: An `Pattern`.
197 op: A `tf.Operation` to match against the pattern.
199 `pattern`'s parent. Can be None if `pattern` is already the root of the
200 pattern tree.
203 True if an TF expression rooted at `op` matches `pattern`.
205 match_result = pattern.match(op, tensor)
215 op: `tf.Operation` to match against the pattern.
218 Returns a `MatchResult` if `op` matches the pattern; otherwise, returns
230 ops: collection of `tf.Operation` to match against the pattern.
233 `MatchResult` for each `tf.Operation` that matches the pattern.
247 `MatchResult` for each `tf.Operation` in `graph` that matches the pattern.