B
    ٻdu                 @   sR   d Z ddlZddlmZ dd ZG dd dZdd	 Zd
d fddZdd ZdS )zUtilities for tf.data options.    N)loggingc             C   s   d|  S )N_ )namer   r   U/var/www/html/venv/lib/python3.7/site-packages/tensorflow/python/data/util/options.py_internal_attr_name   s    r   c               @   sH   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dS )OptionsBasezoBase class for representing a set of tf.data options.

  Attributes:
    _options: Stores the option values.
  c             C   s    t | di  t | dd d S )N_options_mutableT)object__setattr__)selfr   r   r   __init__!   s    zOptionsBase.__init__c             C   sJ   t || jstS x4t| jt|jB D ]}t| |t||kr&dS q&W dS )NFT)
isinstance	__class__NotImplementedsetr	   getattr)r   otherr   r   r   r   __eq__&   s    zOptionsBase.__eq__c             C   s    t || jr| | S tS d S )N)r   r   r   r   )r   r   r   r   r   __ne__.   s    zOptionsBase.__ne__c             C   sB   | j stdt| |r(t| || ntd|t| jd S )NzMutating `tf.data.Options()` returned by `tf.data.Dataset.options()` has no effect. Use `tf.data.Dataset.with_options(options)` to set or update dataset options.z!Cannot set the property {} on {}.)	r
   
ValueErrorhasattrr   r   AttributeErrorformattype__name__)r   r   valuer   r   r   r   4   s    
zOptionsBase.__setattr__c             C   s   t | d| dS )z,Change the mutability property to `mutable`.r
   N)r   r   )r   Zmutabler   r   r   _set_mutableA   s    zOptionsBase._set_mutablec             C   s   t dt| jdS )z#Convert options to protocol buffer.z{}._to_proto()N)NotImplementedErrorr   r   r   )r   r   r   r   	_to_protoE   s    zOptionsBase._to_protoc             C   s   t dt| jdS )z#Convert protocol buffer to options.z{}._from_proto()N)r   r   r   r   )r   Zpbr   r   r   _from_protoI   s    zOptionsBase._from_protoN)r   
__module____qualname____doc__r   r   r   r   r   r    r!   r   r   r   r   r      s   r   c               C   s   t ddddgS )NZGraphRewritesenableddisableddefault)collections
namedtupler   r   r   r   graph_rewritesO   s    r*   c               C   s   d S )Nr   r   r   r   r   <lambda>T       r+   c                s*    fdd}fdd}t ||d|S )a\  Creates a type-checked property.

  Args:
    name: The name to use.
    ty: The type to use. The type of the property will be validated when it
      is set.
    docstring: The docstring to use.
    default_factory: A callable that takes no arguments and returns a default
      value to use if not set.

  Returns:
    A type-checked property.
  c                s"   | j kr  | j < | j S )N)r	   get)option)default_factoryr   r   r   get_fnc   s    
zcreate_option.<locals>.get_fnc                s0   t |s"td |t||| j < d S )Nz4Property "{}" must be of type {}, got: {} (type: {}))r   	TypeErrorr   r   r	   )r.   r   )r   tyr   r   set_fni   s
    
zcreate_option.<locals>.set_fnN)property)r   r2   Z	docstringr/   r0   r3   r   )r/   r   r2   r   create_optionT   s    r5   c        	      G   s   t | dk rtdt| d }x*| D ]"}t||s&tdt||q&W t| d tsptdt| d | }| }x| D ]}x|jD ]}t||}t||}t||}||krqq||krt	||| qt|trt	||t
|| q||krtd||| t	||| qW qW |S )a  Merges the given options, returning the result as a new options object.

  The input arguments are expected to have a matching type that derives from
  `tf.data.OptionsBase` (and thus each represent a set of options). The method
  outputs an object of the same type created by merging the sets of options
  represented by the input arguments.

  If an option is set to different values by different options objects, the
  result will match the setting of the options object that appears in the input
  list last.

  If an option is an instance of `tf.data.OptionsBase` itself, then this method
  is applied recursively to the set of options represented by this option.

  Args:
    *options_list: options to merge

  Raises:
    TypeError: if the input arguments are incompatible or not derived from
      `tf.data.OptionsBase`

  Returns:
    A new options object which is the result of merging the given options.
     z'At least one options should be providedr   z7Could not merge incompatible options of type {} and {}.zfAll options to be merged should inherit from `OptionsBase` but found option of type {} which does not.z.Changing the value of option %s from %r to %r.)lenr   r   r   r1   r   r   r	   r   setattrmerge_optionsr   warning)	Zoptions_listZresult_typeoptionsZdefault_optionsresultr   thisthatr'   r   r   r   r9   s   s<    






r9   )	r$   r(   Zabslr   r   r   r*   r5   r9   r   r   r   r   <module>   s   5