ó
V¾÷Xc           @` sè  d  Z  d d l m Z d d l m Z d d l m Z d d l Z d d l m Z d d l m Z d d l	 m
 Z
 d d	 l m Z d
 d d d d d d d d d d d d d d d d d g Z e e j d ƒ ƒ Z d „  Z d „  Z d „  Z d  „  Z d! „  Z d" „  Z d# „  Z d$ „  Z d% „  Z e d d d& „ Z e d d d' „ Z d( „  Z d1 e  e d d d) „ Z! e  d d2 d d* „ Z" e  d d3 e d+ „ Z# e  e  d e d d d, „ Z$ e  e  d e d d d- „ Z% d. „  Z& d/ „  Z' d0 „  Z( d S(4   s<   Various ways of selecting operations and tensors in a graph.i    (   t   absolute_import(   t   division(   t   print_functionN(   t	   iteritems(   t   string_types(   t   util(   t   opst   can_be_regext
   make_regext	   filter_tst   filter_ts_from_regext
   filter_opst   filter_ops_from_regext   get_name_scope_opst
   check_ciost   get_ops_iost   compute_boundary_tst   get_within_boundary_opst   get_forward_walk_opst   get_backward_walk_opst   get_walks_intersection_opst   get_walks_union_opst
   select_opst	   select_tst   select_ops_and_tst    c         C` s   t  |  t t f ƒ S(   s;   Return True if obj can be turned into a regular expression.(   t
   isinstanceR   t   _RE_TYPE(   t   obj(    (    sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyR   5   s    c         C` sN   t  |  ƒ s* t d j t |  ƒ ƒ ƒ ‚ n  t |  t ƒ rF t j |  ƒ S|  Sd S(   sÛ   Return a compiled regular expression.

  Args:
    obj: a string or a regular expression.
  Returns:
    A compiled regular expression.
  Raises:
    ValueError: if obj could not be converted to a regular expression.
  s%   Expected a string or a regex, got: {}N(   R   t
   ValueErrort   formatt   typeR   R   t   ret   compile(   R   (    (    sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyR   :   s
    
c         C` sp   t  j |  ƒ }  g  } t ƒ  } xK |  D]C } x: | j D]/ } | | k r5 | j | ƒ | j | ƒ q5 q5 Wq% W| S(   s  Compute the list of unique input tensors of all the op in ops.

  Args:
    ops: an object convertible to a list of `tf.Operation`.
  Returns:
    The list of unique input tensors of all the op in ops.
  Raises:
    TypeError: if ops cannot be converted to a list of `tf.Operation`.
  (   R   t   make_list_of_opt   sett   inputst   appendt   add(   R   t   tst   ts_sett   opt   t(    (    sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyt   _get_input_tsM   s    
	c         C` s7   t  j |  ƒ }  g  } x |  D] } | | j 7} q W| S(   s  Compute the list of unique output tensors of all the op in ops.

  Args:
    ops: an object convertible to a list of tf.Operation.
  Returns:
    The list of unique output tensors of all the op in ops.
  Raises:
    TypeError: if ops cannot be converted to a list of tf.Operation.
  (   R   R"   t   outputs(   R   R'   R)   (    (    sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyt   _get_output_tsb   s
    
c         C` si   t  j |  ƒ }  t |  ƒ } t  j | t |  ƒ ƒ | t k	 re g  | D] } | | ƒ rD | ^ qD } n  | S(   sv  Get all the tensors which are input or output of an op in ops.

  Args:
    ops: an object convertible to a list of `tf.Operation`.
    positive_filter: a function deciding whether to keep a tensor or not.
      If `True`, all the tensors are returned.
  Returns:
    A list of `tf.Tensor`.
  Raises:
    TypeError: if ops cannot be converted to a list of `tf.Operation`.
  (   R   R"   R+   t   concatenate_uniqueR-   t   True(   R   t   positive_filterR'   R*   (    (    sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyR	   s   s    (c         ` s4   t  j |  ƒ }  t | ƒ ‰  t |  d ‡  f d †  ƒS(   sŒ  Get all the tensors linked to ops that match the given regex.

  Args:
    ops: an object convertible to a list of tf.Operation.
    regex: a regular expression matching the tensors' name.
      For example, "^foo(/.*)?:\d+$" will match all the tensors in the "foo"
      scope.
  Returns:
    A list of tf.Tensor.
  Raises:
    TypeError: if ops cannot be converted to a list of tf.Operation.
  R0   c         ` s   ˆ  j  |  j ƒ S(   N(   t   searcht   name(   R)   (   t	   regex_obj(    sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyt   <lambda>–   s    (   R   R"   R   R	   (   R   t   regex(    (   R3   sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyR
   ‡   s    c         C` sG   t  j |  ƒ }  | t k	 rC g  |  D] } | | ƒ r" | ^ q" }  n  |  S(   sf  Get the ops passing the given filter.

  Args:
    ops: an object convertible to a list of tf.Operation.
    positive_filter: a function deciding where to keep an operation or not.
      If True, all the operations are returned.
  Returns:
    A list of selected tf.Operation.
  Raises:
    TypeError: if ops cannot be converted to a list of tf.Operation.
  (   R   R"   R/   (   R   R0   R)   (    (    sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyR   ™   s    (c         ` s1   t  j |  ƒ }  t | ƒ ‰  t |  ‡  f d †  ƒ S(   sŽ  Get all the operations that match the given regex.

  Args:
    ops: an object convertible to a list of `tf.Operation`.
    regex: a regular expression matching the operation's name.
      For example, `"^foo(/.*)?$"` will match all the operations in the "foo"
      scope.
  Returns:
    A list of `tf.Operation`.
  Raises:
    TypeError: if ops cannot be converted to a list of `tf.Operation`.
  c         ` s   ˆ  j  |  j ƒ S(   N(   R1   R2   (   R)   (   R3   (    sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyR4   º   s    (   R   R"   R   R   (   R   R5   (    (   R3   sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyR   «   s    c         C` s9   | r# | d d k r# | d  } n  t  |  d j | ƒ ƒ S(   s  Get all the operations under the given scope path.

  Args:
    ops: an object convertible to a list of tf.Operation.
    scope: a scope path.
  Returns:
    A list of tf.Operation.
  Raises:
    TypeError: if ops cannot be converted to a list of tf.Operation.
  iÿÿÿÿt   /s
   ^{}(/.*)?$(   R   R   (   R   t   scope(    (    sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyR   ½   s    c         C` sÈ   | d k	 rf t | t j ƒ s< t d j t | ƒ ƒ ƒ ‚ n  | d k	 rW t d ƒ ‚ n  t }  | } n? | d k	 r¥ t | t j ƒ s¥ t d j t | ƒ ƒ ƒ ‚ q¥ n  | d k	 r¾ | j	 ƒ  n  |  | f S(   s›  Do various check on control_inputs and control_outputs.

  Args:
    control_inputs: A boolean indicating whether control inputs are enabled.
    control_outputs: An instance of util.ControlOutputs or None. If not None,
      control outputs are enabled.
    control_ios:  An instance of util.ControlOutputs or None. If not None, both
      control inputs and control outputs are enabled. This is equivalent to set
      control_inputs to True and control_outputs to the util.ControlOutputs
      instance.
  Returns:
    A tuple `(control_inputs, control_outputs)` where:
      `control_inputs` is a boolean indicating whether to use control inputs.
      `control_outputs` is an instance of util.ControlOutputs or None
  Raises:
    ValueError: if control_inputs is an instance of util.ControlOutputs but
      control_outputs is not None
    TypeError: if control_outputs is not None and is not a util.ControlOutputs.
  s'   Expected a util.ControlOutputs, got: {}s6   control_outputs should be None when using control_ios.N(
   t   NoneR   R   t   ControlOutputst	   TypeErrorR   R   R   R/   t   update(   t   control_inputst   control_outputst   control_ios(    (    sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyR   Í   s    			c         C` sÙ   t  | | | ƒ \ } } t j |  ƒ }  g  } x¥ |  D] } t j | g  | j D] } | j ^ qM ƒ x' | j D] } t j | | j ƒ  ƒ qm W| d k	 rµ t j | | j	 | ƒ ƒ n  | r4 t j | | j
 ƒ q4 q4 W| S(   sì  Return all the `tf.Operation` which are connected to an op in ops.

  Args:
    ops: an object convertible to a list of `tf.Operation`.
    control_inputs: A boolean indicating whether control inputs are enabled.
    control_outputs: An instance of `util.ControlOutputs` or `None`. If not
      `None`, control outputs are enabled.
    control_ios:  An instance of `util.ControlOutputs` or `None`. If not `None`,
      both control inputs and control outputs are enabled. This is equivalent to
      set `control_inputs` to `True` and `control_outputs` to the
      `util.ControlOutputs` instance.
  Returns:
    All the `tf.Operation` surrounding the given ops.
  Raises:
    TypeError: if `ops` cannot be converted to a list of `tf.Operation`.
  N(   R   R   R"   R.   R$   R)   R,   t	   consumersR8   t   getR<   (   R   R<   R=   R>   t   resR)   R*   (    (    sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyR   ó   s    	)c         C` s  t  j |  ƒ }  t |  ƒ } t |  ƒ } t | ƒ } t |  ƒ } g  } g  } x\ | D]T } | | k rj qR n  | j | ƒ t | j ƒ  ƒ } | | r™ qR n  | j | ƒ qR Wt | ƒ }	 t | ƒ }
 g  | D] } | |
 k rÉ | ^ qÉ } g  | D] } | |	 k rî | ^ qî } | | | f S(   s#  Compute the tensors at the boundary of a set of ops.

  This function looks at all the tensors connected to the given ops (in/out)
  and classify them into three categories:
  1) input tensors: tensors whose generating operation is not in ops.
  2) output tensors: tensors whose consumer operations are not in ops
  3) inside tensors: tensors which are neither input nor output tensors.

  Note that a tensor can be both an inside tensor and an output tensor if it is
  consumed by operations both outside and inside of `ops`.

  Args:
    ops: an object convertible to a list of tf.Operation.
  Returns:
    A tuple `(outside_input_ts, outside_output_ts, inside_ts)` where:
      `outside_input_ts` is a Python list of input tensors;
      `outside_output_ts` is a python list of output tensors;
      `inside_ts` is a python list of inside tensors.
    Since a tensor can be both an inside tensor and an output tensor,
    `outside_output_ts` and `inside_ts` might intersect.
  Raises:
    TypeError: if ops cannot be converted to a list of tf.Operation.
  (   R   R"   R+   R-   t	   frozensetR%   R?   (   R   t   input_tst	   output_tst   output_ts_sett   ops_sett	   inside_tst   only_inside_tsR*   R?   t   inside_ts_sett   only_inside_ts_sett   outside_output_tst   outside_input_ts(    (    sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyR     s(    
%%c         C` s5  t  | | | ƒ \ } } t j |  ƒ }  t j | d t ƒ} t t j | ƒ ƒ } t | ƒ } | | @rv t d ƒ ‚ n  t | ƒ } x | rt ƒ  }	 t | | | ƒ }
 xR |
 D]J } | | k rÅ q­ n  | | k rê | r÷ | j | ƒ q÷ q­ |	 j | ƒ q­ W| j |	 ƒ |	 } q… Wg  |  D] } | | k r| ^ qS(   s€  Return all the `tf.Operation` within the given boundary.

  Args:
    ops: an object convertible to a list of `tf.Operation`. those ops define the
      set in which to perform the operation (if a `tf.Graph` is given, it
      will be converted to the list of all its operations).
    seed_ops: the operations from which to start expanding.
    boundary_ops: the ops forming the boundary.
    inclusive: if `True`, the result will also include the boundary ops.
    control_inputs: A boolean indicating whether control inputs are enabled.
    control_outputs: An instance of `util.ControlOutputs` or `None`. If not
      `None`, control outputs are enabled.
    control_ios:  An instance of `util.ControlOutputs` or `None`. If not
      `None`, both control inputs and control outputs are enabled. This is
      equivalent to set control_inputs to True and control_outputs to
      the `util.ControlOutputs` instance.
  Returns:
    All the `tf.Operation` surrounding the given ops.
  Raises:
    TypeError: if `ops` or `seed_ops` cannot be converted to a list of
      `tf.Operation`.
    ValueError: if the boundary is intersecting with the seeds.
  t   allow_graphs(   Boundary is intersecting with the seeds.(	   R   R   R"   t   FalseR#   R   R   R&   R;   (   R   t   seed_opst   boundary_opst	   inclusiveR<   R=   R>   RA   t   wavet   new_wavet   ops_ioR)   (    (    sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyR   H  s,    	
		
c         ` s-  t  t | ƒ \ } } t j |  ƒ s0 |  g }  n  |  s: g  St |  d t j ƒ rw t j |  d t ƒ} t j | ƒ }  n t j	 |  d t ƒ}  t
 |  ƒ }  t
 t j | ƒ ƒ } ˆ  rá t j	 ˆ  d t ƒ‰  t
 ˆ  ƒ ‰  |  ˆ  M}  n  ‡  f d †  } t |  ƒ } t |  ƒ }	 xð |	 rút ƒ  }
 xÄ |	 D]¼ } xb | j D]W } | | k rIq1n  x< | j ƒ  D]. } | | k rV| | ƒ rV|
 j | ƒ qVqVWq1W| d k	 r!xB | j | ƒ D]. } | | k r¨| | ƒ r¨|
 j | ƒ q¨q¨Wq!q!Wt j | |
 ƒ |
 }	 qW| s)g  | D] } | |  k r| ^ q} n  | S(   s  Do a forward graph walk and return all the visited ops.

  Args:
    seed_ops: an iterable of operations from which the forward graph
      walk starts. If a list of tensors is given instead, the seed_ops are set
      to be the consumers of those tensors.
    inclusive: if True the given seed_ops are also part of the resulting set.
    within_ops: an iterable of `tf.Operation` within which the search is
      restricted. If `within_ops` is `None`, the search is performed within
      the whole graph.
    stop_at_ts: an iterable of tensors at which the graph walk stops.
    control_outputs: a `util.ControlOutputs` instance or None.
      If not `None`, it will be used while walking the graph forward.
  Returns:
    A Python set of all the `tf.Operation` ahead of `seed_ops`.
  Raises:
    TypeError: if `seed_ops` or `within_ops` cannot be converted to a list of
      `tf.Operation`.
  i    RM   c         ` s   ˆ  d  k p |  ˆ  k S(   N(   R8   (   R)   (   t
   within_ops(    sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyt	   is_within©  s    N(   R   RN   R   t   is_iterableR   t   tf_opst   Tensort   make_list_of_tt   get_consuming_opsR"   RB   t   listR#   R,   R?   R&   R8   R@   R.   (   RO   RQ   RU   t
   stop_at_tsR=   t   _R'   RV   t   resultRR   RS   R)   t   new_tt   new_op(    (   RU   sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyR     sH    		
(c         ` s  t  j |  ƒ s |  g }  n  |  s% g  St |  d t j ƒ rb t  j |  d t ƒ} t  j | ƒ }  n t  j |  d t ƒ}  t	 t  j | ƒ ƒ } t	 t  j |  ƒ ƒ }  ˆ  rÕ t  j ˆ  d t ƒ‰  t	 ˆ  ƒ ‰  |  ˆ  M}  n  ‡  f d †  } t
 |  ƒ } t |  ƒ } xÖ | rÔt ƒ  }	 xª | D]¢ }
 xT |
 j D]I } | | k r=q%n  | j | k r%| | j ƒ r%|	 j | j ƒ q%q%W| rx< |
 j D]. } | | k r‚| | ƒ r‚|	 j | ƒ q‚q‚WqqWt  j | |	 ƒ |	 } qÿ W| sg  | D] }
 |
 |  k râ|
 ^ qâ} n  | S(   sM  Do a backward graph walk and return all the visited ops.

  Args:
    seed_ops: an iterable of operations from which the backward graph
      walk starts. If a list of tensors is given instead, the seed_ops are set
      to be the generators of those tensors.
    inclusive: if True the given seed_ops are also part of the resulting set.
    within_ops: an iterable of `tf.Operation` within which the search is
      restricted. If `within_ops` is `None`, the search is performed within
      the whole graph.
    stop_at_ts: an iterable of tensors at which the graph walk stops.
    control_inputs: if True, control inputs will be used while moving backward.
  Returns:
    A Python set of all the `tf.Operation` behind `seed_ops`.
  Raises:
    TypeError: if `seed_ops` or `within_ops` cannot be converted to a list of
      `tf.Operation`.
  i    RM   c         ` s   ˆ  d  k p |  ˆ  k S(   N(   R8   (   R)   (   RU   (    sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyRV   ê  s    (   R   RW   R   RX   RY   RZ   RN   t   get_generating_opsR"   RB   R\   R#   R$   R)   R&   R<   R.   (   RO   RQ   RU   R]   R<   R'   RV   R_   RR   RS   R)   R`   Ra   (    (   RU   sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyR   Â  sD    		
(c         C` sw   t  | | | ƒ \ } } t |  d | d | d | ƒ} t | d | d | d | ƒ}	 g  | D] }
 |
 |	 k r[ |
 ^ q[ S(   sÿ  Return the intersection of a forward and a backward walk.

  Args:
    forward_seed_ops: an iterable of operations from which the forward graph
      walk starts. If a list of tensors is given instead, the seed_ops are set
      to be the consumers of those tensors.
    backward_seed_ops: an iterable of operations from which the backward graph
      walk starts. If a list of tensors is given instead, the seed_ops are set
      to be the generators of those tensors.
    forward_inclusive: if True the given forward_seed_ops are also part of the
      resulting set.
    backward_inclusive: if True the given backward_seed_ops are also part of the
      resulting set.
    within_ops: an iterable of tf.Operation within which the search is
      restricted. If within_ops is None, the search is performed within
      the whole graph.
    control_inputs: A boolean indicating whether control inputs are enabled.
    control_outputs: An instance of util.ControlOutputs or None. If not None,
      control outputs are enabled.
    control_ios:  An instance of util.ControlOutputs or None. If not None, both
      control inputs and control outputs are enabled. This is equivalent to set
      control_inputs to True and control_outputs to the util.ControlOutputs
      instance.
  Returns:
    A Python set of all the tf.Operation in the intersection of a forward and a
      backward walk.
  Raises:
    TypeError: if `forward_seed_ops` or `backward_seed_ops` or `within_ops`
      cannot be converted to a list of `tf.Operation`.
  RQ   RU   R=   R<   (   R   R   R   (   t   forward_seed_opst   backward_seed_opst   forward_inclusivet   backward_inclusiveRU   R<   R=   R>   t   forward_opst   backward_opsR)   (    (    sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyR     s    &			c   
      C` sd   t  | | | ƒ \ } } t |  d | d | d | ƒ} t | d | d | d | ƒ}	 t j | |	 ƒ S(   sÈ  Return the union of a forward and a backward walk.

  Args:
    forward_seed_ops: an iterable of operations from which the forward graph
      walk starts. If a list of tensors is given instead, the seed_ops are set
      to be the consumers of those tensors.
    backward_seed_ops: an iterable of operations from which the backward graph
      walk starts. If a list of tensors is given instead, the seed_ops are set
      to be the generators of those tensors.
    forward_inclusive: if True the given forward_seed_ops are also part of the
      resulting set.
    backward_inclusive: if True the given backward_seed_ops are also part of the
      resulting set.
    within_ops: restrict the search within those operations. If within_ops is
      None, the search is done within the whole graph.
    control_inputs: A boolean indicating whether control inputs are enabled.
    control_outputs: An instance of util.ControlOutputs or None. If not None,
      control outputs are enabled.
    control_ios:  An instance of util.ControlOutputs or None. If not None, both
      control inputs and control outputs are enabled. This is equivalent to set
      control_inputs to True and control_outputs to the util.ControlOutputs
      instance.
  Returns:
    A Python set of all the tf.Operation in the union of a forward and a
      backward walk.
  Raises:
    TypeError: if forward_seed_ops or backward_seed_ops or within_ops cannot be
      converted to a list of tf.Operation.
  RQ   RU   R=   R<   (   R   R   R   R   R.   (
   Rc   Rd   Re   Rf   RU   R<   R=   R>   Rg   Rh   (    (    sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyR   7  s    %			c          O` s&  d } d } t } xº t | ƒ D]¬ \ } } | d k r} | } | d k	 rË t | t j ƒ rË t d j t | ƒ ƒ ƒ ‚ qË q | d k r’ | } q | d k r§ | } q | d k r¶ q t	 d j | ƒ ƒ ‚ q Wg  } xJ|  D]B} t
 | ƒ r¦| d k r	t	 d ƒ ‚ n  t | ƒ }	 |	 j j d ƒ r-qÜ n  | rL|	 j j d	 ƒ rLqÜ n  t | |	 ƒ }
 xÀ |
 D]= } | | k rb| d k sŒ| | ƒ rŸ| j | ƒ qŸqbqbWqÜ t j | d
 t ƒ} | d k	 rïg  | D] } | | ƒ rÎ| ^ qÎ} n  g  | D] } | | k rö| ^ qö} | | 7} qÜ W| S(   sÇ  Helper to select operations.

  Args:
    *args: list of 1) regular expressions (compiled or not) or  2) (array of)
      `tf.Operation`. `tf.Tensor` instances are silently ignored.
    **kwargs: 'graph': `tf.Graph` in which to perform the regex query.This is
      required when using regex.
      'positive_filter': an elem if selected only if `positive_filter(elem)` is
        `True`. This is optional.
      'restrict_ops_regex': a regular expression is ignored if it doesn't start
        with the substring "(?#ops)".
  Returns:
    A list of `tf.Operation`.
  Raises:
    TypeError: if the optional keyword argument graph is not a `tf.Graph`
      or if an argument in args is not an (array of) `tf.Operation`
      or an (array of) `tf.Tensor` (silently ignored) or a string
      or a regular expression.
    ValueError: if one of the keyword arguments is unexpected or if a regular
      expression is used without passing a graph as a keyword argument.
  t   graphs   Expected a tf.Graph, got: {}R0   t   restrict_ops_regext   restrict_ts_regexs   Wrong keywords argument: {}.s.   Use the keyword argument 'graph' to use regex.s   (?#ts)s   (?#ops)t	   ignore_tsN(   R8   RN   R   R   RX   t   GraphR:   R   R   R   R   R   t   patternt
   startswithR   R%   R   R"   R/   (   t   argst   kwargsRi   R0   Rj   t   kt   vR   t   argR5   t   ops_t   op_t   ops_auxR)   (    (    sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyR   k  sH    !		(%c          O` s&  d } d } t } xº t | ƒ D]¬ \ } } | d k r} | } | d k	 rË t | t j ƒ rË t d j t | ƒ ƒ ƒ ‚ qË q | d k r’ | } q | d k r§ | } q | d k r¶ q t	 d j | ƒ ƒ ‚ q Wg  } xJ|  D]B} t
 | ƒ r¦| d k r	t	 d ƒ ‚ n  t | ƒ }	 |	 j j d ƒ r-qÜ n  | rL|	 j j d	 ƒ rLqÜ n  t | |	 ƒ }
 xÀ |
 D]= } | | k rb| d k sŒ| | ƒ rŸ| j | ƒ qŸqbqbWqÜ t j | d
 t ƒ} | d k	 rïg  | D] } | | ƒ rÎ| ^ qÎ} n  g  | D] } | | k rö| ^ qö} | | 7} qÜ W| S(   s¿  Helper to select tensors.

  Args:
    *args: list of 1) regular expressions (compiled or not) or  2) (array of)
      `tf.Tensor`. `tf.Operation` instances are silently ignored.
    **kwargs: 'graph': `tf.Graph` in which to perform the regex query.This is
      required when using regex.
      'positive_filter': an elem if selected only if `positive_filter(elem)` is
        `True`. This is optional.
      'restrict_ts_regex': a regular expression is ignored if it doesn't start
        with the substring "(?#ts)".
  Returns:
    A list of `tf.Tensor`.
  Raises:
    TypeError: if the optional keyword argument graph is not a `tf.Graph`
      or if an argument in args is not an (array of) `tf.Tensor`
      or an (array of) `tf.Operation` (silently ignored) or a string
      or a regular expression.
    ValueError: if one of the keyword arguments is unexpected or if a regular
      expression is used without passing a graph as a keyword argument.
  Ri   s   Expected a tf.Graph, got {}R0   Rk   Rj   s   Wrong keywords argument: {}.s.   Use the keyword argument 'graph' to use regex.s   (?#ops)s   (?#ts)t
   ignore_opsN(   R8   RN   R   R   RX   Rm   R:   R   R   R   R   R   Rn   Ro   R
   R%   R   RZ   R/   (   Rp   Rq   Ri   R0   Rk   Rr   Rs   R'   Rt   R5   t   ts_t   t_t   ts_auxR*   (    (    sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyR   ­  sH    !		(%c          O` s4   t  d t |  | Ž } t d t |  | Ž } | | f S(   sü  Helper to select operations and tensors.

  Args:
    *args: list of 1) regular expressions (compiled or not) or  2) (array of)
      `tf.Operation` 3) (array of) tf.Tensor. Regular expressions matching
      tensors must start with the comment `"(?#ts)"`, for instance:
      `"(?#ts)^foo/.*"`.
    **kwargs: 'graph': `tf.Graph` in which to perform the regex query.This is
      required when using regex.
      'positive_filter': an elem if selected only if `positive_filter(elem)` is
        `True`. This is optional.
  Returns:
    A tuple `(ops, ts)` where:
      `ops` is a list of `tf.Operation`, and
      `ts` is a list of `tf.Tensor`
  Raises:
    TypeError: if the optional keyword argument graph is not a `tf.Graph`
      or if an argument in args is not an (array of) `tf.Tensor`
      or an (array of) `tf.Operation` or a string or a regular expression.
    ValueError: if one of the keyword arguments is unexpected or if a regular
      expression is used without passing a graph as a keyword argument.
  Rj   Rk   (   R   RN   R   R/   (   Rp   Rq   R   R'   (    (    sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyR   ï  s    (    (    (    ()   t   __doc__t
   __future__R    R   R   R    t   sixR   R   t   tensorflow.contrib.graph_editorR   t   tensorflow.python.frameworkR   RX   t   __all__R   R!   R   R   R   R+   R-   R	   R
   R   R   R   RN   R8   R   R   R   R/   R   R   R   R   R   R   R   R   (    (    (    sh   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/graph_editor/select.pyt   <module>   sˆ   										& 	62@>0-	B	B