ó
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 Z d d l m Z d d l m	 Z	 d d l m
 Z
 d d	 l m Z d d
 l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d  e f d! „  ƒ  YZ  d" e f d# „  ƒ  YZ! d$ e j" d$ d% d& g ƒ f d' „  ƒ  YZ# e# d( d ƒ Z% d) e# f d* „  ƒ  YZ& d+ e f d, „  ƒ  YZ' d d d d- e% d d. „ Z( d d- e% d d/ „ Z) e d0 d1 ƒ d- d d2 „ ƒ Z* d d3 d d4 „ Z+ d3 d d5 „ Z, e d0 d6 ƒ d3 d d7 „ ƒ Z- d8 e f d9 „  ƒ  YZ. d: e f d; „  ƒ  YZ/ d S(<   s   Lookup table Operations.i    (   t   absolute_import(   t   division(   t   print_functionN(   t   dtypes(   t   ops(   t   sparse_tensor(   t   tensor_shape(   t	   array_ops(   t   control_flow_ops(   t   gen_data_flow_ops(   t   math_ops(   t
   string_ops(   t   BaseSaverBuilder(   t   compat(   t
   deprecatedt   LookupInterfacec           B` st   e  Z d  Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z d	 d „ Z
 d	 d „ Z d „  Z RS(
   s>   Represent a lookup table that persists across different steps.c         C` s1   t  j | ƒ |  _ t  j | ƒ |  _ | |  _ d S(   s²   Construct a lookup table interface.

    Args:
      key_dtype: The table key type.
      value_dtype: The table value type.
      name: A name for the operation (optional).
    N(   R   t   as_dtypet
   _key_dtypet   _value_dtypet   _name(   t   selft	   key_dtypet   value_dtypet   name(    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyt   __init__)   s    c         C` s   |  j  S(   s   The table key dtype.(   R   (   R   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR   5   s    c         C` s   |  j  S(   s   The table value dtype.(   R   (   R   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR   :   s    c         C` s   |  j  S(   s   The name of the table.(   R   (   R   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR   ?   s    c         C` s
   t  ‚ d S(   s   The table initialization op.N(   t   NotImplementedError(   R   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyt   initD   s    c         C` s
   t  ‚ d S(   s-   Compute the number of elements in this table.N(   R   (   R   R   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyt   sizeI   s    c         C` s
   t  ‚ d S(   s=   Looks up `keys` in a table, outputs the corresponding values.N(   R   (   R   t   keysR   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyt   lookupM   s    c         C` sZ   | |  j  k r+ t d |  j  | f ƒ ‚ n  | |  j k rV t d |  j | f ƒ ‚ n  d S(   s"  Check that the given key_dtype and value_dtype matches the table dtypes.

    Args:
      key_dtype: The key data type to check.
      value_dtype: The value data type to check.

    Raises:
      TypeError: when 'key_dtype' or 'value_dtype' doesn't match the table data
        types.
    s*   Invalid key dtype, expected %s but got %s.s,   Invalid value dtype, expected %s but got %s.N(   R   t	   TypeErrorR   (   R   R   R   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyt   check_table_dtypesQ   s    N(   t   __name__t
   __module__t   __doc__R   t   propertyR   R   R   R   t   NoneR   R   R   (    (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR   &   s   	t   InitializableLookupTableBasec           B` s\   e  Z d  Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z d d „ Z	 d d „ Z
 RS(   sj   Initializable lookup table interface.

  An initializable lookup tables persist across different steps.
  c         C` s‹   t  t |  ƒ j | j | j | j j j d ƒ d ƒ | |  _ t	 j
 | d |  j ƒ|  _ |  j j ƒ  j t j ƒ  ƒ | j |  ƒ |  _ d S(   sô  Construct a table object from a table reference.

    If requires a table initializer object (subclass of `TableInitializerBase`).
    It provides the table key and value types, as well as the op to initialize
    the table. The caller is responsible to execute the initialization op.

    Args:
      table_ref: The table reference, i.e. the output of the lookup table ops.
      default_value: The value to use if a key is missing in the table.
      initializer: The table initializer to use.
    t   /iÿÿÿÿt   dtypeN(   t   superR%   R   R   R   t   opR   t   splitt
   _table_refR   t   convert_to_tensorR   t   _default_valuet	   get_shapet
   merge_withR   t   scalart
   initializet   _init(   R   t	   table_reft   default_valuet   initializer(    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR   j   s    	c         C` s   |  j  S(   s#   Get the underlying table reference.(   R+   (   R   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR3      s    c         C` s   |  j  S(   s   The default value of the table.(   R-   (   R   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR4   „   s    c         C` s   |  j  S(   s   The table initialization op.(   R2   (   R   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR   ‰   s    c         C` sE   t  j | d |  j |  j g ƒ  } t j |  j d | ƒSWd QXd S(   sÃ   Compute the number of elements in this table.

    Args:
      name: A name for the operation (optional).

    Returns:
      A scalar tensor containing the number of elements in this table.
    s   %s_SizeR   N(   R   t
   name_scopeR   R+   R	   t   _lookup_table_size(   R   R   t   scope(    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR   Ž   s    	c      
   C` sç   | } t  | t j ƒ r$ | j } n  | j |  j k rU t d |  j | j f ƒ ‚ n  t j | d |  j	 |  j
 g ƒ ( } t j |  j
 | |  j d | ƒ} Wd QX| j | j ƒ  ƒ t  | t j ƒ rß t j | j | | j ƒ S| Sd S(   sÏ  Looks up `keys` in a table, outputs the corresponding values.

    The `default_value` is used for keys not present in the table.

    Args:
      keys: Keys to look up. May be either a `SparseTensor` or dense `Tensor`.
      name: A name for the operation (optional).

    Returns:
      A `SparseTensor` if keys are sparse, otherwise a dense `Tensor`.

    Raises:
      TypeError: when `keys` or `default_value` doesn't match the table data
        types.
    s2   Signature mismatch. Keys must be dtype %s, got %s.s	   %s_LookupR   N(   t
   isinstanceR   t   SparseTensort   valuesR'   R   R   R   R6   R   R+   R	   t   _lookup_table_findR-   t	   set_shapeR.   t   indicest   dense_shape(   R   R   R   t
   key_tensorR8   R;   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR      s    !N(   R    R!   R"   R   R#   R3   R4   R   R$   R   R   (    (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR%   d   s   	t	   HashTablec           B` s   e  Z d  Z d d d „ Z RS(   s  A generic hash table implementation.

  Example usage:

  ```python
  table = tf.contrib.lookup.HashTable(
      tf.contrib.lookup.KeyValueTensorInitializer(keys, values), -1)
  out = table.lookup(input_tensor).
  table.init.run()
  print out.eval()
  ```
  c         C` sk   t  j | d | g ƒ M } t j d | d | j d | j d | ƒ } t t |  ƒ j | | | ƒ Wd QXd S(   sP  Creates a non-initialized `HashTable` object.

    Creates a table, the type of its keys and values are specified by the
    initializer.
    Before using the table you will have to initialize it. After initialization
    the table will be immutable.

    Args:
      initializer: The table initializer to use.
      default_value: The value to use if a key is missing in the table.
      shared_name: If non-empty, this table will be shared under
        the given name across multiple sessions.
      name: A name for the operation (optional).

    Returns:
      A `HashTable` object.
    t
   hash_tablet   shared_nameR   R   R   N(	   R   R6   R	   t   _hash_tableR   R   R(   RA   R   (   R   R5   R4   RC   R   R8   R3   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR   Ñ   s    				N(   R    R!   R"   R$   R   (    (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyRA   Ã   s   t   TableInitializerBasec           B` s>   e  Z d  Z d „  Z e d „  ƒ Z e d „  ƒ Z d „  Z RS(   s)   Base class for lookup table initializers.c         C` s(   t  j | ƒ |  _ t  j | ƒ |  _ d S(   s‹   Construct a table initializer object.

    Args:
      key_dtype: Type of the table keys.
      value_dtype: Type of the table values.
    N(   R   R   R   R   (   R   R   R   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR   ò   s    c         C` s   |  j  S(   s   The expected table key dtype.(   R   (   R   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR   ü   s    c         C` s   |  j  S(   s   The expected table value dtype.(   R   (   R   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR     s    c         C` s
   t  ‚ d S(   s$   Returns the table initialization op.N(   R   (   R   t   table(    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR1     s    (   R    R!   R"   R   R#   R   R   R1   (    (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyRE   ï   s
   	
t   KeyValueTensorInitializerc           B` s)   e  Z d  Z d d d d „ Z d „  Z RS(   s5   Table initializers given `keys` and `values` tensors.c      
   C` s’   t  j | d | | g ƒ L } t  j | d | d d ƒ|  _ t  j | d | d d ƒ|  _ | |  _ Wd QXt t |  ƒ j |  j j	 |  j j	 ƒ d S(   sr  Constructs a table initializer object based on keys and values tensors.

    Args:
      keys: The tensor for the keys.
      values: The tensor for the values.
      key_dtype: The `keys` data type. Used when `keys` is a python array.
      value_dtype: The `values` data type. Used when `values` is a python array.
      name: A name for the operation (optional).
    t   key_value_initR'   R   R   R;   N(
   R   R6   R,   t   _keyst   _valuesR   R(   RG   R   R'   (   R   R   R;   R   R   R   R8   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR     s    
c      
   C` s~   | j  |  j j |  j j ƒ t j |  j d | g ƒ+ } t j | j	 |  j |  j d | ƒ} Wd QXt j
 t j j | ƒ | S(   s,  Initializes the given `table` with `keys` and `values` tensors.

    Args:
      table: The table to initialize.

    Returns:
      The operation that initializes the table.

    Raises:
      TypeError: when the keys and values data types do not match the table
      key and value data types.
    R;   R   N(   R   RI   R'   RJ   R   R6   R   R	   t   _initialize_tableR3   t   add_to_collectiont	   GraphKeyst   TABLE_INITIALIZERS(   R   RF   R8   t   init_op(    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR1   "  s    	N(   R    R!   R"   R$   R   R1   (    (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyRG     s   t   TextFileIndexc           B` s   e  Z d  Z d Z RS(   iþÿÿÿiÿÿÿÿ(   R    R!   t
   WHOLE_LINEt   LINE_NUMBER(    (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyRP   ;  s   t   TextFileInitializerc           B` s)   e  Z d  Z d d d d „ Z d „  Z RS(   sÓ  Table initializers from a text file.

  This initializer assigns one entry in the table for each line in the file.

  The key and value type of the table to initialize is given by `key_dtype` and
  `value_dtype`.

  The key and value content to get from each line is specified by
  the `key_index` and `value_index`.
    - TextFileIndex.LINE_NUMBER means use the line number starting from zero,
      expects data type int64.
    - TextFileIndex.WHOLE_LINE means use the whole line content, expects data
      type string.
    - A value >=0 means use the index (starting at zero) of the split line based
      on `delimiter`.

  For example if we have a file with the following content:

  ```
  emerson 10
  lake 20
  palmer 30
  ```

  The following snippet initializes a table with the first column as keys and
  second column as values:
  - emerson -> 10
  - lake -> 20
  - palmer -> 30

  ```python
  table = tf.contrib.lookup.HashTable(tf.contrib.lookup.TextFileInitializer(
      "test.txt", tf.string, 0, tf.int64, 1, delimiter=" "), -1)
  ...
  table.init.run()
  ```

  Similarly to initialize the whole line as keys and the line number as values.
  - emerson 10 -> 0
  - lake 20 -> 1
  - palmer 30 -> 2

  ```python
  table = tf.contrib.lookup.HashTable(tf.contrib.lookup.TextFileInitializer(
      "test.txt", tf.string, tf.contrib.lookup.TextFileIndex.WHOLE_LINE,
      tf.int64, tf.contrib.lookup.TextFileIndex.LINE_NUMBER, delimiter=" "), -1)
  ...
  table.init.run()
  ```
  s   	c	   	   	   C` sï  t  | t j ƒ r- | r- t d | ƒ ‚ n  t j | ƒ } t j | ƒ } | d k  rj t d | ƒ ‚ n  | t j k r¤ | t j k r¤ t d t j | f ƒ ‚ n  | t j	 k rÞ | t j
 k rÞ t d t j
 | f ƒ ‚ n  | d k  rý t d | ƒ ‚ n  | t j k r7| t j k r7t d t j | f ƒ ‚ n  | t j	 k rq| t j
 k rqt d t j
 | f ƒ ‚ n  | d	 k	 rœ| d k rœt d | ƒ ‚ n  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ t t |  ƒ j | | ƒ d	 S(
   sÒ  Constructs a table initializer object to populate from a text file.

    It generates one key-value pair per line. The type of table key and
    value are specified by `key_dtype` and `value_dtype`, respectively.
    Similarly the content of the key and value are specified by the key_index
    and value_index.

    - TextFileIndex.LINE_NUMBER means use the line number starting from zero,
      expects data type int64.
    - TextFileIndex.WHOLE_LINE means use the whole line content, expects data
      type string.
    - A value >=0 means use the index (starting at zero) of the split line based
      on `delimiter`.

    Args:
      filename: The filename of the text file to be used for initialization.
        The path must be accessible from wherever the graph is initialized
        (eg. trainer or eval workers). The filename may be a scalar `Tensor`.
      key_dtype: The `key` data type.
      key_index: the index that represents information of a line to get the
        table 'key' values from.
      value_dtype: The `value` data type.
      value_index: the index that represents information of a line to get the
        table 'value' values from.'
      vocab_size: The number of elements in the file, if known.
      delimiter: The delimiter to separate fields in a line.
      name: A name for the operation (optional).

    Raises:
      ValueError: when the filename is empty, or when the table key and value
      data types do not match the expected data types.
    s   Filename required for %s.iþÿÿÿs   Invalid key index %s.s2   Signature mismatch. Keys must be dtype %s, got %s.s   Invalid value index %s.s4   Signature mismatch. Values must be dtype %s, got %s.i    s   Invalid vocab_size %s.N(   R9   R   t   Tensort
   ValueErrorR   R   RP   RR   t   int64RQ   t   stringR$   t	   _filenamet
   _key_indext   _value_indext   _vocab_sizet
   _delimiterR   R(   RS   R   (	   R   t   filenameR   t	   key_indexR   t   value_indext
   vocab_sizet	   delimiterR   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR   t  s:    )						c         C` sÐ   | j  |  j |  j ƒ t j |  j d | g ƒ m } t j |  j t j	 d d ƒ} t
 j | j | |  j |  j |  j d k r‚ d n |  j |  j d | ƒ} Wd QXt j t j j | ƒ t j t j j | ƒ | S(   s  Initializes the table from a text file.

    Args:
      table: The table to be initialized.

    Returns:
      The operation that initializes the table.

    Raises:
      TypeError: when the keys and values data types do not match the table
      key and value data types.
    t   text_file_initR   t   asset_filepathiÿÿÿÿN(   R   R   R   R   R6   R   R,   RX   R   RW   R	   t    _initialize_table_from_text_fileR3   RY   RZ   R[   R$   R\   RL   RM   RN   t   ASSET_FILEPATHS(   R   RF   R8   R]   RO   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR1   Â  s     			N(   R    R!   R"   R$   R   R1   (    (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyRS   @  s
   2Ft   TextFileStringTableInitializerc           B` s,   e  Z d  Z e j e j d d d d „ Z RS(   sD   Table initializer for `int64` IDs to string tables from a text file.s   	t   text_file_string_table_initc         C` s>   t  t |  ƒ j | t j | t j | d | d | d | ƒd S(   sÁ  Constructs an initializer for an id-to-string table from a text file.

    It populates a table that its key and value types are int64 and string,
    respectively. It generates one key-value pair per line.
    The content of the key and value are specified by `key_column_index`
    and `value_column_index`.

    - TextFileIndex.LINE_NUMBER means use the line number starting from zero,
      expects data type int64.
    - TextFileIndex.WHOLE_LINE means use the whole line content, expects data
      type string.
    - A value >=0 means use the index (starting at zero) of the split line based
      on `delimiter`.

    Args:
      filename: The filename of the text file to be used for initialization.
        The path must be accessible from wherever the graph is initialized
        (eg. trainer or eval workers). The filename may be a scalar `Tensor`.
      key_column_index: The column index from the text file to get the keys
        from. The default is 0 that represents the whole line content.
      value_column_index: The column index from the text file to get the
        values from. The default is to use the line number, starting from zero.
      vocab_size: The number of elements in the file, if known.
      delimiter: The delimiter to separate fields in a line.
      name: Optional name for the op.

    Raises:
      TypeError: when the filename is empty, or when the table key and value
      data types do not match the expected data types.
    R`   Ra   R   N(   R(   Rf   R   R   RV   RW   (   R   R]   t   key_column_indext   value_column_indexR`   Ra   R   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR   æ  s    %N(   R    R!   R"   RP   RR   RQ   R$   R   (    (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyRf   ã  s   t   TextFileIdTableInitializerc           B` s,   e  Z d  Z e j e j d d d d „ Z RS(   sD   Table initializer for string to `int64` IDs tables from a text file.s   	t   text_file_id_table_initc         C` s>   t  t |  ƒ j | t j | t j | d | d | d | ƒd S(   sÃ  Constructs an initializer for an string-to-id table from a text file.

    It populates a table that its key and value types are string and int64,
    respectively. It generates one key-value pair per line.
    The content of the key and value are specified by the key_index
    and value_index.

    - TextFileIndex.LINE_NUMBER means use the line number starting from zero,
      expects data type int64.
    - TextFileIndex.WHOLE_LINE means use the whole line content, expects data
      type string.
    - A value >=0 means use the index (starting at zero) of the split line based
      on `delimiter`.

    Args:
      filename: The filename of the text file to be used for initialization.
        The path must be accessible from wherever the graph is initialized
        (eg. trainer or eval workers). The filename may be a scalar `Tensor`.
      key_column_index: The column index from the text file to get the `key`
        values from. The default is to use the line number, starting from zero.
      value_column_index: The column index from the text file ro get the `value`
        values from. The default is 0 that represents the whole line content.
      vocab_size: The number of elements in the file, if known.
      delimiter: The delimiter to separate fields in a line.
      name: Optional name for the op.

    Raises:
      TypeError: when the filename is empty, or when the table key and value
      data types do not match the expected data types.
    R`   Ra   R   N(   R(   Rj   R   R   RW   RV   (   R   R]   Rh   Ri   R`   Ra   R   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR     s    %N(   R    R!   R"   RP   RQ   RR   R$   R   (    (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyRj     s   t
   HasherSpect   hashert   keyc           B` s   e  Z d  Z d Z RS(   s‘  A structure for the spec of the hashing function to use for hash buckets.

  `hasher` is the name of the hashing function to use (eg. "fasthash",
  "stronghash").
  `key` is optional and specify the key to use for the hash function if
  supported, currently only used by a strong hash.

  Fields:
    hasher: The hasher name to use.
    key: The key to be used by the hashing function, if required.
  (    (   R    R!   R"   t	   __slots__(    (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyRl   G  s   t   fasthasht   StrongHashSpecc           B` s   e  Z d  Z d Z d „  Z RS(   s7  A structure to specify a key of the strong keyed hash spec.

  The strong hash requires a `key`, which is a list of 2 unsigned integer
  numbers. These should be non-zero; random numbers generated from random.org
  would be a fine choice.

  Fields:
    key: The key to be used by the keyed hashing function.
  c         C` sˆ   t  | ƒ d k r+ t d t  | ƒ ƒ ‚ n  t | d t j ƒ sY t | d t j ƒ rl t d | ƒ ‚ n  t |  t ƒ j |  d | ƒ S(   Ni   s   key must have size 2, got %s.i    i   s0   Invalid key %s. Must be unsigned integer values.t
   stronghash(	   t   lenRU   R9   R   t   integral_typesR   R(   Rq   t   __new__(   t   clsRn   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyRu   e  s    (    (   R    R!   R"   Ro   Ru   (    (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyRq   Y  s   	t   IdTableWithHashBucketsc           B` sM   e  Z d  Z e d d „ Z e d „  ƒ Z d d „ Z d „  Z	 d d „ Z
 RS(   sY  String to Id table wrapper that assigns out-of-vocabulary keys to buckets.

  For example, if an instance of `IdTableWithHashBuckets` is initialized with a
  string-to-id table that maps:
  - emerson -> 0
  - lake -> 1
  - palmer -> 2

  The `IdTableWithHashBuckets` object will performs the following mapping:
  - emerson -> 0
  - lake -> 1
  - palmer -> 2
  - <other term> -> bucket id between 3 and 3 + num_oov_buckets, calculated by:
    hash(<term>) % num_oov_buckets + vocab_size

  If input_tensor is ["emerson", "lake", "palmer", "king", "crimson"],
  the lookup result is [0, 1, 2, 4, 7]

  If `table` is None, only out-of-vocabulary buckets are used.

  Example usage:

  ```python
  num_oov_buckets = 3
  input_tensor = tf.constant(["emerson", "lake", "palmer", "king", "crimnson"])
  table = tf.IdTableWithHashBuckets(
      tf.HashTable(tf.TextFileIdTableInitializer(filename), default_value),
      num_oov_buckets)
  out = table.lookup(input_tensor).
  table.init.run()
  print out.eval()
  ```

  The hash function used for generating out-of-vocabulary buckets ID is handled
  by `hasher_spec`.
  c         C` sé   | r | j  d ƒ } n  | rR | j t j t j ƒ | |  _ | pL |  j j } n0 | d k rm t d ƒ ‚ n  d |  _ | p d } | |  _	 t
 | t ƒ s­ t d | ƒ ‚ n  | |  _ t t |  ƒ j t j t j | j d ƒ d ƒ d S(   sø  Construct a `IdTableWithHashBuckets` object.

    Args:
      table: Table that maps string to ids.
      num_oov_buckets: Number of buckets to use for out-of-vocabulary keys.
      hasher_spec: A `HasherSpec` to specify the hash function to use for
        assignation of out-of-vocabulary buckets  (optional).
      name: A name for the operation (optional).

    Raises:
      ValueError: when `table` in None and `num_oov_buckets` is not positive.
      TypeError: when `hasher_spec` is invalid.
    R&   i    s0   oov_buckets must be > 0 if no table is supplied.t   hash_buckets.   hasher_spec must be of type HasherSpec, got %siÿÿÿÿN(   t   rstripR   R   RW   RV   t   _tableR   RU   R$   t   _num_oov_bucketsR9   Rl   R   t   _hasher_specR(   Rw   R   R*   (   R   RF   t   num_oov_bucketst   hasher_specR   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR   –  s"    				c         C` s:   |  j  r |  j  j St j d d ƒ  t j ƒ  SWd QXd S(   s   The table initialization op.R   N(   Rz   R   R   R6   R$   R   t   no_op(   R   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR   ¿  s    	
c         C` sg   t  j | d |  j ƒ H } |  j r: |  j j | ƒ } n t  j d d t j ƒ} | |  j SWd QXd S(   s-   Compute the number of elements in this table.s   %s_Sizei    R'   N(	   R   R6   R   Rz   R   R,   R   RV   R{   (   R   R   R8   t   tsize(    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR   Ç  s
    	c         C` s   t  | t ƒ s" t d | ƒ ‚ n  | j d k r8 t j S| j d k rN t j S| j d k rv t j t j	 d | j
 ƒSt d | j ƒ ‚ d S(   sC   Returns the string_to_hash_bucket op to use based on `hasher_spec`.s)   hasher_spec must be of type HasherSpec %sRp   t   legacyRr   Rn   s   Unknown hasher %sN(   R9   Rl   R   Rm   R   t   string_to_hash_bucket_fastt   string_to_hash_buckett	   functoolst   partialt   string_to_hash_bucket_strongRn   RU   (   R   R~   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyt   _get_string_to_hash_bucket_fnÐ  s    c   	   
   C` so  | j  |  j k r1 t d |  j | j  f ƒ ‚ n  | } t | t j ƒ rU | j } n  |  j d k r |  j j	 | d | ƒ} nÁ t
 j | d |  j ƒ ¦ } |  j |  j ƒ } | | d |  j d d ƒ} |  j r4|  j j	 | ƒ } t j | |  j j ƒ  ƒ } t j | |  j j ƒ } t j | | | d | ƒ} n | } Wd QXt | t j ƒ rkt j | j | | j ƒ S| S(   s³  Looks up `keys` in the table, outputs the corresponding values.

    It assigns out-of-vocabulary keys to buckets based in their hashes.

    Args:
      keys: Keys to look up. May be either a `SparseTensor` or dense `Tensor`.
      name: Optional name for the op.

    Returns:
      A `SparseTensor` if keys are sparse, otherwise a dense `Tensor`.

    Raises:
      TypeError: when `keys` doesn't match the table key data type.
    s2   Signature mismatch. Keys must be dtype %s, got %s.i    R   s	   %s_Lookupt   num_bucketsRx   N(   R'   R   R   R9   R   R:   R;   R{   Rz   R   R   R6   R   R‡   R|   R
   t   addR   t	   not_equalR4   R   t   whereR>   R?   (	   R   R   R   t   string_valuest   idsR8   t   str_to_hash_buckett   bucketst   is_id_non_default(    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR   Ý  s0    			N(   R    R!   R"   t   FastHashSpecR$   R   R#   R   R   R‡   R   (    (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyRw   p  s   $%		iÿÿÿÿc         C` sA  |  s t  d ƒ ‚ n  | d k  r4 t  d | ƒ ‚ n  | d k	 r_ | d k  r_ t  d | ƒ ‚ n  t j | d ƒ Ê } d } d } t j d d ƒ x }	 | rº d	 |  | t j t j f } n d
 |  t j t j f } t |  d | d d ƒ}
 t |
 | d | d |	 ƒ} Wd QX| r3t	 | d | d | d | ƒ} n  | SWd QXd S(   s=  Returns a lookup table that converts a string tensor into int64 IDs.

  This operation constructs a lookup table to convert tensor of strings into
  int64 IDs. The mapping can be initialized from a vocabulary file specified in
  `vocabulary_file`, where the whole line is the key and the zero-based line
  number is the ID.

  Any lookup of an out-of-vocabulary token will return a bucket ID based on its
  hash if `num_oov_buckets` is greater than zero. Otherwise it is assigned the
  `default_value`.
  The bucket ID range is `[vocabulary size, vocabulary size + num_oov_buckets]`.

  The underlying table must be initialized by calling
  `tf.tables_initializer.run()` or `table.init.run()` once.

  Sample Usages:

  If we have a vocabulary file "test.txt" with the following content:

  ```
  emerson
  lake
  palmer
  ```

  ```python
  features = tf.constant(["emerson", "lake", "and", "palmer"])
  table = tf.contrib.lookup.string_to_index_table_from_file(
      vocabulary_file="test.txt", num_oov_buckets=1)
  ids = table.lookup(features)
  ...
  tf.tables_initializer().run()

  ids.eval()  ==> [0, 1, 3, 2]  # where 3 is the out-of-vocabulary bucket
  ```

  Args:
    vocabulary_file: The vocabulary filename.
    num_oov_buckets: The number of out-of-vocabulary buckets.
    vocab_size: Number of the elements in the vocabulary, if known.
    default_value: The value to use for out-of-vocabulary feature values.
      Defaults to -1.
    hasher_spec: A `HasherSpec` to specify the hash function to use for
      assignation of out-of-vocabulary buckets.
    name: A name for this op (optional).

  Returns:
    The lookup table to map a string `Tensor` to index `int64` `Tensor`.

  Raises:
    ValueError: If `vocabulary_file` is not set.
    ValueError: If `num_oov_buckets` is negative or `vocab_size` is not greater
      than zero.
  s"   vocabulary_file must be specified.i    s8   num_oov_buckets must be greater or equal than 0, got %d.i   s*   vocab_size must be greater than 0, got %d.t   string_to_indext    RB   s   hash_table_%s_%d_%s_%ss   hash_table_%s_%s_%sR`   R   t
   table_initRC   NR}   R~   (
   RU   R$   R   R6   RP   RQ   RR   Rj   RA   Rw   (   t   vocabulary_fileR}   R`   R4   R~   R   t   feat_to_id_scopeRF   RC   t   hash_table_scopeR   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyt   string_to_index_table_from_file  s:    <	c         C` s#  |  d
 k r t d ƒ ‚ n  | d k  r: t d | ƒ ‚ n  t j | d ƒ Ñ } t j |  t j ƒ } t j | ƒ } t	 j
 t	 j | ƒ t j ƒ } d }	 t j d
 d ƒ C }
 t | | t j t j d d ƒ} t | | d	 |	 d |
 ƒ} Wd
 QX| rt | d | d | d | ƒ} n  | SWd
 QXd
 S(   s"  Returns a lookup table that converts a string tensor into int64 IDs.

  This operation constructs a lookup table to convert tensor of strings into
  int64 IDs. The mapping can be initialized from a string `mapping` 1-D tensor
  where each element is a key and corresponding index within the tensor is the
  value.

  Any lookup of an out-of-vocabulary token will return a bucket ID based on its
  hash if `num_oov_buckets` is greater than zero. Otherwise it is assigned the
  `default_value`.
  The bucket ID range is `[mapping size, mapping size + num_oov_buckets]`.

  The underlying table must be initialized by calling
  `tf.tables_initializer.run()` or `table.init.run()` once.

  Elements in `mapping` cannot have duplicates, otherwise when executing the
  table initializer op, it will throw a `FailedPreconditionError`.

  Sample Usages:

  ```python
  mapping_strings = t.constant(["emerson", "lake", "palmer")
  table = tf.contrib.lookup.string_to_index_table_from_tensor(
      mapping=mapping_strings, num_oov_buckets=1, default_value=-1)
  features = tf.constant(["emerson", "lake", "and", "palmer"])
  ids = table.lookup(features)
  ...
  tf.tables_initializer().run()

  ids.eval()  ==> [0, 1, 4, 2]
  ```

  Args:
    mapping: A 1-D string `Tensor` that specifies the mapping of strings to
      indices.
    num_oov_buckets: The number of out-of-vocabulary buckets.
    default_value: The value to use for out-of-vocabulary feature values.
      Defaults to -1.
    hasher_spec: A `HasherSpec` to specify the hash function to use for
      assignation of out-of-vocabulary buckets.
    name: A name for this op (optional).

  Returns:
    The lookup table to map a string `Tensor` to index `int64` `Tensor`.

  Raises:
    ValueError: `mapping` is invalid.
    ValueError: If `num_oov_buckets` is negative.
  s   mapping must be specified.i    s8   num_oov_buckets must be greater or equal than 0, got %d.R’   R“   RB   R   R”   RC   NR}   R~   (   R$   RU   R   R6   R,   R   RW   R   R   R
   t   castt   rangeRV   RG   RA   Rw   (   t   mappingR}   R4   R~   R   R–   R   t   num_elementsR;   RC   R—   R   RF   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyt!   string_to_index_table_from_tensorn  s,    6s
   2017-01-07s˜   This op will be removed after the deprecation date. Please switch to string_to_index_table_from_tensor and call the lookup method of the returned table.c         C` s(   t  d | d | d | ƒ } | j |  ƒ S(   sb  Maps `tensor` of strings into `int64` indices based on `mapping`.

  This operation converts `tensor` of strings into `int64` indices.
  The mapping is initialized from a string `mapping` tensor where each element
  is a key and corresponding index within the tensor is the value.

  Any entry in the input which does not have a corresponding entry in 'mapping'
  (an out-of-vocabulary entry) is assigned the `default_value`

  Elements in `mapping` cannot be duplicated, otherwise the initialization
  will throw a FailedPreconditionError.

  The underlying table must be initialized by calling
  `tf.tables_initializer.run()` once.

  For example:

  ```python
  mapping_strings = t.constant(["emerson", "lake", "palmer")
  feats = tf.constant(["emerson", "lake", "and", "palmer"])
  ids = tf.contrib.lookup.string_to_index(
      feats, mapping=mapping_strings, default_value=-1)
  ...
  tf.tables_initializer().run()

  ids.eval()  ==> [0, 1, -1, 2]
  ```

  Args:
    tensor: A 1-D input `Tensor` with the strings to map to indices.
    mapping: A 1-D string `Tensor` that specifies the mapping of strings to
      indices.
    default_value: The `int64` value to use for out-of-vocabulary strings.
      Defaults to -1.
    name: A name for this op (optional).

  Returns:
    The mapped indices. It has the same shape and tensor type (dense or sparse)
    as `tensor`.
  R›   R4   R   (   R   R   (   t   tensorR›   R4   R   RF   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR’   À  s    -t   UNKc         C` sÔ   |  s t  d ƒ ‚ n  | d k	 r@ | d k  r@ t  d | ƒ ‚ n  t j | d ƒ | } d } | r€ d |  | t j t j f } n d |  t j t j f } t |  d | d	 d
 ƒ} t | | d | d	 | ƒSWd QXd S(   sœ  Returns a lookup table that maps a `Tensor` of indices into strings.

  This operation constructs a lookup table to map int64 indices into string
  values. The table is initialized from a vocabulary file specified in
  `vocabulary_file`, where the whole line is the value and the
  zero-based line number is the index.

  Any input which does not have a corresponding index in the vocabulary file
  (an out-of-vocabulary entry) is assigned the `default_value`

  The underlying table must be initialized by calling
  `tf.tables_initializer.run()` or `table.init.run()` once.

  Sample Usages:

  If we have a vocabulary file "test.txt" with the following content:

  ```
  emerson
  lake
  palmer
  ```

  ```python
  indices = tf.constant([1, 5], tf.int64)
  table = tf.contrib.lookup.index_to_string_from_file(
      vocabulary_file="test.txt", default_value="UNKNOWN")
  values = table.lookup(indices)
  ...
  tf.tables_initializer().run()

  values.eval() ==> ["lake", "UNKNOWN"]
  ```

  Args:
    vocabulary_file: The vocabulary filename.
    vocab_size: Number of the elements in the vocabulary, if known.
    default_value: The value to use for out-of-vocabulary indices.
    name: A name for this op (optional).

  Returns:
    The lookup table to map a string values associated to a given index `int64`
    `Tensors`.

  Raises:
    ValueError: when `vocabulary_file` is empty.
    ValueError: when `vocab_size` is invalid.
  s"   vocabulary_file must be specified.i   s*   vocab_size must be greater than 0, got %d.t   index_to_stringR“   s   hash_table_%s_%d_%s_%ss   hash_table_%s_%s_%sR`   R   R”   RC   N(	   RU   R$   R   R6   RP   RR   RQ   Rf   RA   (   R•   R`   R4   R   R8   RC   R   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyt   index_to_string_table_from_fileò  s     4	c   	      C` s¼   |  d k r t d ƒ ‚ n  t j | d ƒ ‰ } t j |  t j ƒ } t j | ƒ } t	 j
 t	 j | ƒ t j ƒ } d } t | | t j t j d d ƒ} t | | d | d | ƒSWd QXd S(   s“  Returns a lookup table that maps a `Tensor` of indices into strings.

  This operation constructs a lookup table to map int64 indices into string
  values. The mapping is initialized from a string `mapping` 1-D `Tensor` where
  each element is a value and the corresponding index within the tensor is the
  key.

  Any input which does not have a corresponding index in 'mapping'
  (an out-of-vocabulary entry) is assigned the `default_value`

  The underlying table must be initialized by calling
  `tf.tables_initializer.run()` or `table.init.run()` once.

  Elements in `mapping` cannot have duplicates, otherwise when executing the
  table initializer op, it will throw a `FailedPreconditionError`.

  Sample Usages:

  ```python
  mapping_string = t.constant(["emerson", "lake", "palmer")
  indices = tf.constant([1, 5], tf.int64)
  table = tf.contrib.lookup.index_to_string_from_tensor(
      mapping_string, default_value="UNKNOWN")
  values = table.lookup(indices)
  ...
  tf.tables_initializer().run()

  values.eval() ==> ["lake", "UNKNOWN"]
  ```

  Args:
    mapping: A 1-D string `Tensor` that specifies the strings to map from
      indices.
    default_value: The value to use for out-of-vocabulary indices.
    name: A name for this op (optional).

  Returns:
    The lookup table to map a string values associated to a given index `int64`
    `Tensors`.

  Raises:
    ValueError: when `mapping` is not set.
  s   mapping must be specified.R    R“   R   R”   RC   N(   R$   RU   R   R6   R,   R   RW   R   R   R
   R™   Rš   RV   RG   RA   (	   R›   R4   R   R8   R;   Rœ   R   RC   R   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyt!   index_to_string_table_from_tensor?  s    -s˜   This op will be removed after the deprecation date. Please switch to index_to_string_table_from_tensor and call the lookup method of the returned table.c         C` s(   t  d | d | d | ƒ } | j |  ƒ S(   só  Maps `tensor` of indices into string values based on `mapping`.

  This operation converts `int64` indices into string values. The mapping is
  initialized from a string `mapping` tensor where each element is a value and
  the corresponding index within the tensor is the key.

  Any input which does not have a corresponding index in 'mapping'
  (an out-of-vocabulary entry) is assigned the `default_value`

  The underlying table must be initialized by calling
  `tf.tables_initializer.run()` once.

  For example:

  ```python
  mapping_string = t.constant(["emerson", "lake", "palmer")
  indices = tf.constant([1, 5], tf.int64)
  values = tf.contrib.lookup.index_to_string(
      indices, mapping=mapping_string, default_value="UNKNOWN")
  ...
  tf.tables_initializer().run()

  values.eval() ==> ["lake", "UNKNOWN"]
  ```

  Args:
    tensor: A `int64` `Tensor` with the indices to map to strings.
    mapping: A 1-D string `Tensor` that specifies the strings to map from
      indices.
    default_value: The string value to use for out-of-vocabulary indices.
    name: A name for this op (optional).

  Returns:
    The strings values associated to the indices. The resultant dense
    feature value tensor has the same shape as the corresponding `indices`.
  R›   R4   R   (   R¢   R   (   Rž   R›   R4   R   RF   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR    {  s    )t   MutableHashTablec           B` si   e  Z d  Z d	 d e d „ Z d	 d „ Z d	 d „ Z d	 d „ Z d	 d „ Z	 d e
 j f d „  ƒ  YZ RS(
   sÙ  A generic mutable hash table implementation.

  Data can be inserted by calling the insert method. It does not support
  initialization via the init method.

  Example usage:

  ```python
  table = tf.contrib.lookup.MutableHashTable(key_dtype=tf.string,
                                             value_dtype=tf.int64,
                                             default_value=-1)
  table.insert(keys, values)
  out = table.lookup(query_keys)
  print out.eval()
  ```
  R£   c   	      C` s'  t  j | d | ƒ|  _ |  j j ƒ  |  _ | o9 | d k } |  j j ƒ  j d k r„ t j d | d | d | d | d | ƒ |  _	 n< t j
 d | d | d | d | d |  j j ƒ  d | ƒ |  _	 t t |  ƒ j | | |  j	 j j j d	 ƒ d
 ƒ | r#t j |  | ƒ } t  j t  j j | ƒ n  d S(   sH  Creates an empty `MutableHashTable` object.

    Creates a table, the type of its keys and values are specified by key_dtype
    and value_dtype, respectively.

    Args:
      key_dtype: the type of the key tensors.
      value_dtype: the type of the value tensors.
      default_value: The value to use if a key is missing in the table.
      shared_name: If non-empty, this table will be shared under
        the given name across multiple sessions.
      name: A name for the operation (optional).
      checkpoint: if True, the contents of the table are saved to and restored
        from checkpoints. If `shared_name` is empty for a checkpointed table, it
        is shared using the table node name.

    Returns:
      A `MutableHashTable` object.

    Raises:
      ValueError: If checkpoint is True and no name was specified.
    R'   i    RC   t   use_node_name_sharingR   R   R   t   value_shapeR&   iÿÿÿÿN(   R   R,   R-   R.   t   _value_shapeR$   t   ndimsR	   t   _mutable_hash_tableR+   t   _mutable_hash_table_of_tensorsR(   R£   R   R)   R   R*   t	   _SaveableRL   RM   t   SAVEABLE_OBJECTS(	   R   R   R   R4   RC   R   t
   checkpointR¤   t   saveable(    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR   »  s0    		c         C` sE   t  j | d |  j |  j g ƒ  } t j |  j d | ƒSWd QXd S(   sÃ   Compute the number of elements in this table.

    Args:
      name: A name for the operation (optional).

    Returns:
      A scalar tensor containing the number of elements in this table.
    s   %s_SizeR   N(   R   R6   R   R+   R	   R7   (   R   R   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR   ù  s    	c      
   C` s£   | j  |  j k r1 t d |  j | j  f ƒ ‚ n  t j | d |  j |  j | g ƒ ( } t j |  j | |  j	 d | ƒ} Wd QX| j
 | j ƒ  j |  j ƒ ƒ | S(   sé  Looks up `keys` in a table, outputs the corresponding values.

    The `default_value` is used for keys not present in the table.

    Args:
      keys: Keys to look up. Can be a tensor of any shape. Must match the
        table's key_dtype.
      name: A name for the operation (optional).

    Returns:
      A tensor containing the values in the same shape as `keys` using the
        table's value type.

    Raises:
      TypeError: when `keys` do not match the table data types.
    s2   Signature mismatch. Keys must be dtype %s, got %s.s   %s_lookup_table_findR   N(   R'   R   R   R   R6   R   R+   R	   R<   R-   R=   R.   t   concatenateR¦   (   R   R   R   R;   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR     s    	c      
   C` sm   |  j  | j | j ƒ t j | d |  j |  j | | g ƒ ) } t j |  j | | d | ƒ} | SWd QXd S(   sÙ  Associates `keys` with `values`.

    Args:
      keys: Keys to insert. Can be a tensor of any shape. Must match the
        table's key type.
      values: Values to be associated with keys. Must be a tensor of the same
        shape as `keys` and match the table's value type.
      name: A name for the operation (optional).

    Returns:
      The created Operation.

    Raises:
      TypeError: when `keys` or `values` doesn't match the table data
        types.
    s   %s_lookup_table_insertR   N(   R   R'   R   R6   R   R+   R	   t   _lookup_table_insert(   R   R   R;   R   R)   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyt   insert'  s    c      
   C` s~   t  j | d |  j |  j g ƒ 1 } t j |  j |  j |  j d | ƒ\ } } Wd QX| j | j	 ƒ  j
 |  j ƒ ƒ | | f S(   s  Returns tensors of all keys and values in the table.

    Args:
      name: A name for the operation (optional).

    Returns:
      A pair of tensors with the first tensor containing all keys and the
        second tensors containing all values in the table.
    s   %s_lookup_table_export_valuesR   N(   R   R6   R   R+   R	   t   _lookup_table_exportR   R   R=   R.   R®   R¦   (   R   R   t   exported_keyst   exported_values(    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyt   export@  s    
	Rª   c           B` s    e  Z d  Z d „  Z d „  Z RS(   s3   SaveableObject implementation for MutableHashTable.c         C` si   | j  ƒ  } t j | d d | d ƒ t j | d d | d ƒ g } t t j |  ƒ j | | | ƒ d  S(   Ni    R“   s   -keysi   s   -values(   R´   R   t   SaveSpecR(   R£   Rª   R   (   R   RF   R   t   tensorst   specs(    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR   Z  s     c         C` s!   t  j |  j j | d | d ƒ S(   Ni    i   (   R	   t   _lookup_table_importR)   R+   (   R   t   restored_tensorst   unused_restored_shapes(    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyt   restorec  s    (   R    R!   R"   R   R»   (    (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyRª   W  s   		N(   R    R!   R"   R$   t   TrueR   R   R   R°   R´   R   t   SaveableObjectRª   (    (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR£   ©  s   8 t   MutableDenseHashTablec           B` sl   e  Z d  Z d	 d	 d e d „ Z d	 d „ Z d	 d „ Z d	 d „ Z d	 d „ Z	 d e
 j f d „  ƒ  YZ RS(
   s¼  A generic mutable hash table implementation using tensors as backing store.

  Data can be inserted by calling the insert method. It does not support
  initialization via the init method.

  It uses "open addressing" with quadratic reprobing to resolve collisions.
  Compared to `MutableHashTable` the insert and lookup operations in a
  `MutableDenseHashTable` are typically faster, but memory usage can be higher.
  However, `MutableDenseHashTable` does not require additional memory for
  temporary tensors created during checkpointing and restore operations.

  Example usage:

  ```python
  table = tf.contrib.lookup.MutableDenseHashTable(key_dtype=tf.int64,
                                                  value_dtype=tf.int64,
                                                  default_value=-1,
                                                  empty_key=0)
  table.insert(keys, values)
  out = table.lookup(query_keys)
  print out.eval()
  ```
  R¾   c	         C` sô   t  j | d | ƒ|  _ |  j j ƒ  |  _ | o9 | d k }	 t  j | d | ƒ} t j d | d | d |	 d | d |  j d | d | ƒ |  _ t	 t
 |  ƒ j | | |  j j j j d	 ƒ d
 ƒ | rð t
 j |  | ƒ }
 t  j t  j j |
 ƒ n  d S(   s  Creates an empty `MutableDenseHashTable` object.

    Creates a table, the type of its keys and values are specified by key_dtype
    and value_dtype, respectively.

    Args:
      key_dtype: the type of the key tensors.
      value_dtype: the type of the value tensors.
      default_value: The value to use if a key is missing in the table.
      empty_key: the key to use to represent empty buckets internally. Must not
        be used in insert or lookup operations.
      initial_num_buckets: the initial number of buckets.
      shared_name: If non-empty, this table will be shared under
        the given name across multiple sessions.
      name: A name for the operation (optional).
      checkpoint: if True, the contents of the table are saved to and restored
        from checkpoints. If `shared_name` is empty for a checkpointed table, it
        is shared using the table node name.

    Returns:
      A `MutableHashTable` object.

    Raises:
      ValueError: If checkpoint is True and no name was specified.
    R'   t	   empty_keyRC   R¤   R   R¥   t   initial_num_bucketsR   R&   iÿÿÿÿN(   R   R,   R-   R.   R¦   R$   R	   t   _mutable_dense_hash_tableR+   R(   R¾   R   R)   R   R*   Rª   RL   RM   R«   (   R   R   R   R4   R¿   RÀ   RC   R   R¬   R¤   R­   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR   „  s$    "		#c         C` sE   t  j | d |  j |  j g ƒ  } t j |  j d | ƒSWd QXd S(   sÃ   Compute the number of elements in this table.

    Args:
      name: A name for the operation (optional).

    Returns:
      A scalar tensor containing the number of elements in this table.
    s   %s_SizeR   N(   R   R6   R   R+   R	   R7   (   R   R   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR   À  s    	c      
   C` sã   | j  |  j k r1 t d |  j | j  f ƒ ‚ n  t j | d |  j |  j | g ƒ ( } t j |  j | |  j	 d | ƒ} Wd QX| j
 ƒ  j d k	 rß | j
 ƒ  j d k rß | j t j | j
 ƒ  j d g ƒ j |  j ƒ ƒ n  | S(   sé  Looks up `keys` in a table, outputs the corresponding values.

    The `default_value` is used for keys not present in the table.

    Args:
      keys: Keys to look up. Can be a tensor of any shape. Must match the
        table's key_dtype.
      name: A name for the operation (optional).

    Returns:
      A tensor containing the values in the same shape as `keys` using the
        table's value type.

    Raises:
      TypeError: when `keys` do not match the table data types.
    s2   Signature mismatch. Keys must be dtype %s, got %s.s   %s_lookup_table_findR   Ni    (   R'   R   R   R   R6   R   R+   R	   R<   R-   R.   R§   R$   R=   R   t   TensorShapet   dimsR®   R¦   (   R   R   R   R;   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR   Î  s    !*c      
   C` sm   |  j  | j | j ƒ t j | d |  j |  j | | g ƒ ) } t j |  j | | d | ƒ} | SWd QXd S(   sÙ  Associates `keys` with `values`.

    Args:
      keys: Keys to insert. Can be a tensor of any shape. Must match the
        table's key type.
      values: Values to be associated with keys. Must be a tensor of the same
        shape as `keys` and match the table's value type.
      name: A name for the operation (optional).

    Returns:
      The created Operation.

    Raises:
      TypeError: when `keys` or `values` doesn't match the table data
        types.
    s   %s_lookup_table_insertR   N(   R   R'   R   R6   R   R+   R	   R¯   (   R   R   R;   R   R)   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR°   ï  s    c      
   C` s~   t  j | d |  j |  j g ƒ 1 } t j |  j |  j |  j d | ƒ\ } } Wd QX| j | j	 ƒ  j
 |  j ƒ ƒ | | f S(   s  Returns tensors of all keys and values in the table.

    Args:
      name: A name for the operation (optional).

    Returns:
      A pair of tensors with the first tensor containing all keys and the
        second tensors containing all values in the table.
    s   %s_lookup_table_export_valuesR   N(   R   R6   R   R+   R	   R±   R   R   R=   R.   R®   R¦   (   R   R   R²   R³   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR´     s    
*Rª   c           B` s    e  Z d  Z d „  Z d „  Z RS(   s8   SaveableObject implementation for MutableDenseHashTable.c         C` si   | j  ƒ  } t j | d d | d ƒ t j | d d | d ƒ g } t t j |  ƒ j | | | ƒ d  S(   Ni    R“   s   -keysi   s   -values(   R´   R   Rµ   R(   R¾   Rª   R   (   R   RF   R   R¶   R·   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR     s     c         C` s!   t  j |  j j | d | d ƒ S(   Ni    i   (   R	   R¸   R)   R+   (   R   R¹   Rº   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR»   (  s    (   R    R!   R"   R   R»   (    (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyRª     s   		N(   R    R!   R"   R$   R¼   R   R   R   R°   R´   R   R½   Rª   (    (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyR¾   i  s   	4!(0   R"   t
   __future__R    R   R   t   collectionsR„   t   tensorflow.python.frameworkR   R   R   R   t   tensorflow.python.opsR   R   R	   R
   R   t    tensorflow.python.training.saverR   t   tensorflow.python.utilR   t"   tensorflow.python.util.deprecationR   t   objectR   R%   RA   RE   RG   RP   RS   Rf   Rj   t
   namedtupleRl   R$   R‘   Rq   Rw   R˜   R   R’   R¡   R¢   R    R£   R¾   (    (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/lookup/lookup_ops.pyt   <module>   sh   >_,0£22(›_N	/J<	*À