B
    Ò»ˆd—  ã               @   sD   d Z ddlZddlZdZe dddg¡Zdd„ Zd	d
„ Zdd„ ZdS )z2Common values and methods for TensorFlow Debugger.é    Nzgrpc://ÚRunKeyZ
feed_namesZfetch_namesc             C   s   t | dƒr| jS t| ƒS )a±  Obtain the name or string representation of a graph element.

  If the graph element has the attribute "name", return name. Otherwise, return
  a __str__ representation of the graph element. Certain graph elements, such as
  `SparseTensor`s, do not have the attribute "name".

  Args:
    elem: The graph element in question.

  Returns:
    If the attribute 'name' is available, return the name. Otherwise, return
    str(fetch).
  Úname)Úhasattrr   Ústr)Úelem© r   úT/var/www/html/venv/lib/python3.7/site-packages/tensorflow/python/debug/lib/common.pyÚget_graph_element_name   s    r	   c             C   sn   g }t | ttfƒr0xV| D ]}| t|ƒ¡ qW n:t | tƒr\x.| D ]}| t| | ƒ¡ q@W n| t| ƒ¡ |S )a~  Get a flattened list of the names in run() call feeds or fetches.

  Args:
    feeds_or_fetches: Feeds or fetches of the `Session.run()` call. It maybe
      a Tensor, an Operation or a Variable. It may also be nested lists, tuples
      or dicts. See doc of `Session.run()` for more details.

  Returns:
    (list of str) A flattened list of fetch names from `feeds_or_fetches`.
  )Ú
isinstanceÚlistÚtupleÚextendÚget_flattened_namesÚdictÚappendr	   )Zfeeds_or_fetchesÚlinesÚitemÚkeyr   r   r   r   +   s    


r   c             C   s   t  tt| ƒt|ƒƒ¡S )a†  Summarize the names of feeds and fetches as a RunKey JSON string.

  Args:
    feed_dict: The feed_dict given to the `Session.run()` call.
    fetches: The fetches from the `Session.run()` call.

  Returns:
    A JSON Array consisting of two items. They first items is a flattened
    Array of the names of the feeds. The second item is a flattened Array of
    the names of the fetches.
  )ÚjsonÚdumpsr   r   )Z	feed_dictZfetchesr   r   r   Úget_run_keyF   s    r   )	Ú__doc__Úcollectionsr   ZGRPC_URL_PREFIXÚ
namedtupler   r	   r   r   r   r   r   r   Ú<module>   s   