
    AVh                     z   d 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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Z"ddZ#ddZ$ e	jJ                  e	jL                  jN                  ejP                  e#e$        e	jJ                  e	jL                  jR                  ejP                  e#e$        e	jJ                  e	jL                  jT                  ejP                  e#e$        e	jJ                  e	jL                  jV                  ejP                  e#e$        e	jJ                  e	jL                  jX                  ejP                  e#e$        e	jJ                  e	jL                  jZ                  ejP                  e#e$        e	jJ                  e	jL                  j\                  ejP                  e#e$        G d dej^                  ej`                        Z1 e
jd                  e1e1jf                         y) zRefVariable class.    )attr_value_pb2)variable_pb2)context)dtypes)indexed_slices)ops)tensor_conversion_registry)tensor_shape)	array_ops)gen_array_ops)gen_state_ops)resource_variable_ops)resource_variables_toggle)	state_ops)variable_scope)variable_v1)	variables)
tf_logging)base)core)compat)
deprecatedNc                 b   | J |j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  d	d      }|j                  d
d      }	|j                  dd      }
|j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|t        j                         j                  }|t	        j
                         }|xs t        j                         }|r5|j                  dd      }t        j                  |||||||	|||||||      S t        |||||||	|||
||||      S )zDefault variable creator.Ninitial_value	trainablecollectionsvalidate_shapeTcaching_devicenamevariable_defdtypeexpected_shapeimport_scope
constraintuse_resourcesynchronizationaggregationshapedistribute_strategy)r   r   r   r   r   r   r!   r$   r    r#   r)   r&   r'   r(   )r   r   r   r   r   r   r!   r$   r    r"   r#   r&   r'   r(   )getr   get_variable_scoper%   r   resource_variables_enabledr   executing_eagerlyr   ResourceVariableRefVariable)next_creatorkwargsr   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   s                     R/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/ops/ref_variable.pydefault_variable_creatorr3   )   s   			**_d3-jjd+)

=$/+::.5.::.5.	FD	!$ND1,
**Wd
#%::.5.ND1,zz,-*ND1,JJ0$7/

=$/+
**Wd
#%!446CCL,GGIL<!:!:!<, **%:DA 11#%%!!/'   #%%!%!'     c                 &    | j                  |      S )zFConverts Variable and ResourceVariable to VariableDef for collections.export_scope)to_proto)vr7   s     r2   _to_proto_fnr:   d   s    	
	..r4   c                     | j                   r!t        j                  j                  | |      S t        j
                  j                  | |      S )z@Creates Variable or ResourceVariable from VariableDef as needed.r#   )is_resourcer   r.   
from_protor   
VariableV1)r9   r#   s     r2   _from_proto_fnr@   i   sH    ]] 11<<	 = & &				*	*1<	*	HHr4   )
proto_typer8   r>   c                      e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 d:dZd Z	 	 	 	 	 	 	 	 	 	 	 	 d;dZd<dZd Zd Z	d	 Z
d
 Zd Zed        Zed        Zed        Zd<dZed        Zed        Zd=dZd=dZd=dZd>dZd>dZd>dZd>dZd>dZd>dZd>dZd>dZd<dZd<dZ d<dZ!d<d Z"d<d!Z#d" Z$ e%dd#      d$        Z&e'd?d%       Z(d&Z)ed'        Z*ed(e+jX                  fd)       Z-ed*        Z.ed(e/j`                  fd+       Z1ed(e+jX                  fd,       Z2ed(e+jf                  fd-       Z4ed.        Z5ed/        Z6d<d0Z7d1 Z8d2 Z9d3 Z:d4 Z;d5 Z<d6 Z=d7 Z>d8 Z?d9 Z@y)@r/   z&Ref-based implementation of variables.Nc                     d| _         |r!|rt        d      | j                  ||
       y| j                  ||||||||	||||       y)a  Creates a new variable with value `initial_value`.

    The new variable is added to the graph collections listed in `collections`,
    which defaults to `[GraphKeys.GLOBAL_VARIABLES]`.

    If `trainable` is `True` the variable is also added to the graph collection
    `GraphKeys.TRAINABLE_VARIABLES`.

    This constructor creates both a `variable` Op and an `assign` Op to set the
    variable to its initial value.

    Args:
      initial_value: A `Tensor`, or Python object convertible to a `Tensor`,
        which is the initial value for the Variable. The initial value must have
        a shape specified unless `validate_shape` is set to False. Can also be a
        callable with no argument that returns the initial value when called. In
        that case, `dtype` must be specified. (Note that initializer functions
        from init_ops.py must first be bound to a shape before being used here.)
      trainable: If `True`, also adds the variable to the graph collection
        `GraphKeys.TRAINABLE_VARIABLES`. This collection is used as the default
        list of variables to use by the `Optimizer` classes. Defaults to `True`,
        unless `synchronization` is set to `ON_READ`, in which case it defaults
        to `False`.
      collections: List of graph collections keys. The new variable is added to
        these collections. Defaults to `[GraphKeys.GLOBAL_VARIABLES]`.
      validate_shape: If `False`, allows the variable to be initialized with a
        value of unknown shape. If `True`, the default, the shape of
        `initial_value` must be known.
      caching_device: Optional device string describing where the Variable
        should be cached for reading.  Defaults to the Variable's device. If not
        `None`, caches on another device.  Typical use is to cache on the device
        where the Ops using the Variable reside, to deduplicate copying through
        `Switch` and other conditional statements.
      name: Optional name for the variable. Defaults to `'Variable'` and gets
        uniquified automatically.
      variable_def: `VariableDef` protocol buffer. If not `None`, recreates the
        Variable object with its contents, referencing the variable's nodes in
        the graph, which must already exist. The graph is not changed.
        `variable_def` and the other arguments are mutually exclusive.
      dtype: If set, initial_value will be converted to the given type. If
        `None`, either the datatype will be kept (if `initial_value` is a
        Tensor), or `convert_to_tensor` will decide.
      expected_shape: A TensorShape. If set, initial_value is expected to have
        this shape.
      import_scope: Optional `string`. Name scope to add to the `Variable.` Only
        used when initializing from protocol buffer.
      constraint: An optional projection function to be applied to the variable
        after being updated by an `Optimizer` (e.g. used to implement norm
        constraints or value constraints for layer weights). The function must
        take as input the unprojected Tensor representing the value of the
        variable and return the Tensor for the projected value (which must have
        the same shape). Constraints are not safe to use when doing asynchronous
        distributed training.
      synchronization: Indicates when a distributed a variable will be
        aggregated. Accepted values are constants defined in the class
        `tf.VariableSynchronization`. By default the synchronization is set to
        `AUTO` and the current `DistributionStrategy` chooses when to
        synchronize.
      aggregation: Indicates how a distributed variable will be aggregated.
        Accepted values are constants defined in the class
        `tf.VariableAggregation`.
      shape: (optional) The shape of this variable. If None, the shape of
        `initial_value` will be used. When setting this argument to
        `tf.TensorShape(None)` (representing an unspecified shape), the variable
        can be assigned with values of different shapes.

    Raises:
      ValueError: If both `variable_def` and initial_value are specified.
      ValueError: If the initial value is not specified, or does not have a
        shape and `validate_shape` is `True`.
      RuntimeError: If eager execution is enabled.
    Tz6variable_def and initial_value are mutually exclusive.r<   )r   r   r   r   r   r   r!   r"   r$   r&   r'   r(   N)_in_graph_mode
ValueError_init_from_proto_init_from_args)selfr   r   r   r   r   r   r    r!   r"   r#   r$   r&   r'   r(   s                  r2   __init__zRefVariable.__init__   sq    p D	 & ' 	'
L|D %!''')!  r4   c                 n   t        j                         rj| j                  s^d| j                  d| j	                         d| j
                  j                  dt        j                  | j                         d      d	S d| j                  d| j	                         d| j
                  j                  dS )Nz<tf.Variable 'z' shape=z dtype=z, numpy=T)is_repr>)	r   r-   rD   r   	get_shaper!   r   
numpy_text
read_valuerH   s    r2   __repr__zRefVariable.__repr__	  sv      "4+>+>
))T^^%tzz
..*D
9; ;
 ))T^^%tzz8 8r4   c           
         |}|t        d      t        |      }|t        j                  j                  g}t        |t        t        t        f      st        d|dt        |            |	t        |	      st        d      t        j                         j                  | _        t        |t        j                        r7| j                          |j                  j                   | _        |j$                  }t'        j(                  |
|||      \  }
}}|
| _        || _        || _        |rCt        j                  j0                  |vr't        |      t        j                  j0                  gz   }t        j2                         5  t5        j6                         rt9        d      t        j:                  |d|rg n|g      5 }|rt        j<                  |      }t?        j@                  t>        j@                  jC                  tE        jF                  d|z        g	      
      }t        j                         jI                  d|i      5  t        j:                  d      5  t        jJ                  d      5   |       }t        |t        j                        r7| j                          |j                  j                   | _        |j$                  }t        jL                  |d|      | _'        |0|r| jN                  jQ                         ntS        jT                         }ddd       ddd       tW        jX                  || jN                  jZ                  j\                  |      | _/        ddd       nt        jL                  |d|      | _'        | jN                  j`                  jc                         t        d|z        |0|r| jN                  jQ                         ntS        jT                         }tW        jX                  || jN                  jZ                  j\                  |      | _/        | j^                  jd                  | _3        |rB| jN                  jQ                         }|ji                         st        d| jN                  z        tW        jj                  | j^                  t'        jl                  || jN                        |      j`                  | _7        |Et        jJ                  |      5  tq        jr                  | j^                  d      | _:        ddd       nXt        jv                  | j^                  j`                        5  tq        jr                  | j^                  d      | _:        ddd       ddd       t        jx                  ||        ddd       || _=        d| _>        |	| _?        y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   lxY w# 1 sw Y   xxY w# 1 sw Y   |xY w# 1 sw Y   jxY w)a>  Creates a new variable from arguments.

    Args:
      initial_value: A `Tensor`, or Python object convertible to a `Tensor`,
        which is the initial value for the Variable. The initial value must have
        a shape specified unless `validate_shape` is set to False. Can also be a
        callable with no argument that returns the initial value when called.
        (Note that initializer functions from init_ops.py must first be bound to
        a shape before being used here.)
      trainable: If `True`, also adds the variable to the graph collection
        `GraphKeys.TRAINABLE_VARIABLES`. This collection is used as the default
        list of variables to use by the `Optimizer` classes. Defaults to `True`,
        unless `synchronization` is set to `ON_READ`, in which case it defaults
        to `False`.
      collections: List of graph collections keys. The new variable is added to
        these collections. Defaults to `[GraphKeys.GLOBAL_VARIABLES]`.
      validate_shape: If `False`, allows the variable to be initialized with a
        value of unknown shape. If `True`, the default, the shape of
        `initial_value` must be known.
      caching_device: Optional device string or function describing where the
        Variable should be cached for reading.  Defaults to the Variable's
        device.  If not `None`, caches on another device.  Typical use is to
        cache on the device where the Ops using the Variable reside, to
        deduplicate copying through `Switch` and other conditional statements.
      name: Optional name for the variable. Defaults to `'Variable'` and gets
        uniquified automatically.
      dtype: If set, initial_value will be converted to the given type. If None,
        either the datatype will be kept (if initial_value is a Tensor) or
        float32 will be used (if it is a Python object convertible to a Tensor).
      expected_shape: Deprecated. Ignored.
      constraint: An optional projection function to be applied to the variable
        after being updated by an `Optimizer` (e.g. used to implement norm
        constraints or value constraints for layer weights). The function must
        take as input the unprojected Tensor representing the value of the
        variable and return the Tensor for the projected value (which must have
        the same shape). Constraints are not safe to use when doing asynchronous
        distributed training.
      synchronization: Indicates when a distributed a variable will be
        aggregated. Accepted values are constants defined in the class
        `tf.VariableSynchronization`. By default the synchronization is set to
        `AUTO` and the current `DistributionStrategy` chooses when to
        synchronize.
      aggregation: Indicates how a distributed variable will be aggregated.
        Accepted values are constants defined in the class
        `tf.VariableAggregation`.
      shape: (optional) The shape of this variable. If None, the shape of
        `initial_value` will be used. When setting this argument to
        `tf.TensorShape(None)` (representing an unspecified shape), the variable
        can be assigned with values of different shapes.

    Raises:
      ValueError: If the initial value is not specified, or does not have a
        shape and `validate_shape` is `True`.
      RuntimeError: If lifted into the eager context.
    Nz initial_value must be specified.zPcollections argument to Variable constructor must be a list, tuple, or set. Got z	 of type z-The `constraint` argument must be a callable.zReference variables are not supported when eager execution is enabled. Please run `tf.compat.v1.enable_resource_variables()` to switch to resource variables.Variablezloc:@%s)s)list_classInitializerr   )r   r!   r   zInitializer for variable %s is from inside a control-flow construct, such as a loop or conditional. When creating a variable inside a loop or conditional, use a lambda as the initializer.z-initial_value must have a shape specified: %sr   read)@rE   callabler   	GraphKeysGLOBAL_VARIABLES
isinstancerU   tuplesettypeget_default_graph
_graph_key	trackableCheckpointInitialValue_maybe_initialize_trackablecheckpoint_positionrestore_uid_update_uidwrapped_valuer   .validate_synchronization_aggregation_trainable_synchronization_aggregation
_trainableTRAINABLE_VARIABLES
init_scoper   r-   RuntimeError
name_scopename_from_scope_namer   	AttrValue	ListValuer   as_bytes_attr_scopedeviceconvert_to_tensor_initial_valuerM   r
   unknown_shaper   variable_op_v2r!   
base_dtype	_variableop_get_control_flow_contextr   _nameis_fully_definedassign-_try_guard_against_uninitialized_dependencies_initializer_opr   identity	_snapshotcolocate_withadd_to_collections_caching_device_save_slice_info_constraint)rH   r   r   r   r   r   r   r!   r"   r$   r&   r'   r(   _init_from_fn	true_nameattrinitial_value_shapes                     r2   rG   zRefVariable._init_from_args  so   H 	A9::M*L]]334kkD%#56)4d;6GIJ J hz&:FGG ++-88DO-!A!AB
&&(&::FFd#11m 	@@[)T	; ,O[) ,D#DDOS]]66kI%)J)J(KKk		 V0		"	"	$,- 	- >>$
 ,"=/C NMFJ ..t4)))!++55__Y%:;< 6 >?$ $$&22Hd3CD H. I

40@ I+omM9+K+KL002#0#D#D#P#P  - ; ;$'$9$9oU%Dd! & ''113+7+E+E+G I I '55t**00;;$HDNH H& !$ 5 5/!@$
   ##==?K "&&' '
 ] " ##--/'3'A'A'C 
 %33T((..99F$.
 ^^((
  $ 3 3 = = ?
$557L!001 2 2  )//NNCCd))+)	 + ,.2	 	 %zz.) M&//VLDNM M   !2!23 M&//VLDNM[NM^ 
[$/mV0p *D D!DMI I I IH H|M MM M[NM NMV0 V0s   <X ?B	W4WW	4B(V5W	$AW'F
W41'W2W4
'W(1W49X 5V?:W	WWWW4W%!W4(W1-W44W=	9X  X	c                    t        |t        j                        sJ t        j                         }|j                  t        j                  |j                  |            | _        | j                  j                  | _
        |j                  t        j                  |j                  |            | _        t        |d      rB|j                  r6|j                  t        j                  |j                  |            | _        nd| _        t!        j"                  |j$                  |j&                  |j(                  |j                        \  }}}|| _        || _        || _        |j                  t        j                  |j0                  |            | _        |j5                  d      r1t         j6                  j9                  |j:                  |      | _        nd| _        d| _        d| _         y)a  Recreates the Variable object from a `VariableDef` protocol buffer.

    Args:
      variable_def: `VariableDef` protocol buffer, describing a variable whose
        nodes already exists in the graph.
      import_scope: Optional `string`. Name scope to add.
    r<   initial_value_nameNsave_slice_info_def)r   r#   )!r^   r   VariableDefr   rb   as_graph_elementprepend_name_scopevariable_namer~   r   r   initializer_namer   hasattrr   rz   r   rk   r&   r'   r   rl   rm   rn   snapshot_namer   HasFieldrS   SaveSliceInfor   r   r   r   )rH   r    r#   gr&   r'   r   s          r2   rF   zRefVariable._init_from_proto  s    lL$<$<===A''&&\	CDDN $$DJ--))	FGD 	23''..

 
 --LJKd !d@@((,*B*B""L$>$>	@ ,O[) ,D#DDO''&&\	CDDN 23'00>>*>># ? %d #dDDr4   c                     | j                   S )z1Conversion function for Graph.as_graph_element().r~   rP   s    r2   _as_graph_elementzRefVariable._as_graph_element  s    >>r4   c                     | j                   S )a  Returns the last snapshot of this variable.

    You usually do not need to call this method as all ops that need the value
    of the variable call it automatically through a `convert_to_tensor()` call.

    Returns a `Tensor` which holds the value of the variable.  You can not
    assign a new value to this tensor as it is not a reference to the variable.

    To avoid copies, if the consumer of the returned value is on the same device
    as the variable, this actually returns the live value of the variable, not
    a copy.  Updates to the variable are seen by the consumer.  If the consumer
    is on a different device it will get a copy of the variable.

    Returns:
      A `Tensor` containing the value of the variable.
    )r   rP   s    r2   valuezRefVariable.value  s    " >>r4   c                 D    t        j                  | j                  d      S )zReturns the value of this variable, read in the current context.

    Can be different from value() if it's on another device, with control
    dependencies, etc.

    Returns:
      A `Tensor` containing the value of the variable.
    rZ   rX   )r   r   r~   rP   s    r2   rO   zRefVariable.read_value  s     dnn6::r4   c                     | j                   S )a  Returns a reference to this variable.

    You usually do not need to call this method as all ops that need a reference
    to the variable call it automatically.

    Returns is a `Tensor` which holds a reference to the variable.  You can
    assign a new value to the variable by passing the tensor to an assign op.
    See `tf.Variable.value` if you want to get the value of the
    variable.

    Returns:
      A `Tensor` that is a reference to the variable.
    r   rP   s    r2   _refzRefVariable._ref  s     >>r4   c                     | j                         j                  |       | j                         j                  |       y)zxOverrides the shape for this variable.

    Args:
      shape: the `TensorShape` representing the overridden shape.
    N)r   	set_shaper   )rH   r(   s     r2   r   zRefVariable.set_shape/  s,     	IIK% JJL5!r4   c                     | j                   S N)rn   rP   s    r2   r   zRefVariable.trainable8  s    ??r4   c                     | j                   S r   )rl   rP   s    r2   r&   zRefVariable.synchronization<  s       r4   c                     | j                   S r   )rm   rP   s    r2   r'   zRefVariable.aggregation@  s    r4   c                 :    | j                   j                  |      S )a  In a session, computes and returns the value of this variable.

    This is not a graph construction method, it does not add ops to the graph.

    This convenience method requires a session where the graph
    containing this variable has been launched. If no session is
    passed, the default session is used.  See `tf.compat.v1.Session` for more
    information on launching a graph and on sessions.

    ```python
    v = tf.Variable([1, 2])
    init = tf.compat.v1.global_variables_initializer()

    with tf.compat.v1.Session() as sess:
        sess.run(init)
        # Usage passing the session explicitly.
        print(v.eval(sess))
        # Usage with the default session.  The 'with' block
        # above makes 'sess' the default session.
        print(v.eval())
    ```

    Args:
      session: The session to use to evaluate this variable. If none, the
        default session is used.

    Returns:
      A numpy `ndarray` with a copy of the value of this variable.
    )session)r~   eval)rH   r   s     r2   r   zRefVariable.evalD  s    < >>w//r4   c                     | j                   S )aL  Returns the Tensor used as the initial value for the variable.

    Note that this is different from `initialized_value()` which runs
    the op that initializes the variable before returning its value.
    This method returns the tensor that is used by the op that initializes
    the variable.

    Returns:
      A `Tensor`.
    )rz   rP   s    r2   r   zRefVariable.initial_valued  s     r4   c                     | j                   S )zReturns the constraint function associated with this variable.

    Returns:
      The constraint function that was passed to the variable constructor.
      Can be `None` if no constraint was passed.
    )r   rP   s    r2   r$   zRefVariable.constraintr  s     r4   c                 h    t        j                  | j                  |||      }|r|S |j                  S )a(  Assigns a new value to the variable.

    This is essentially a shortcut for `assign(self, value)`.

    Args:
      value: A `Tensor`. The new value for this variable.
      use_locking: If `True`, use locking during the assignment.
      name: The name of the operation to be created
      read_value: if True, will return something which evaluates to the new
        value of the variable; if False will return the assign op.

    Returns:
      A `Tensor` that will hold the new value of this variable after
      the assignment has completed.
    use_lockingr   )r   r   r~   r   )rH   r   r   r   rO   r   s         r2   r   zRefVariable.assign|  s4      ;TCFm99r4   c                 h    t        j                  | j                  |||      }|r|S |j                  S )a&  Adds a value to this variable.

     This is essentially a shortcut for `assign_add(self, delta)`.

    Args:
      delta: A `Tensor`. The value to add to this variable.
      use_locking: If `True`, use locking during the operation.
      name: The name of the operation to be created
      read_value: if True, will return something which evaluates to the new
        value of the variable; if False will return the assign op.

    Returns:
      A `Tensor` that will hold the new value of this variable after
      the addition has completed.
    r   )r   
assign_addr~   r   rH   deltar   r   rO   r   s         r2   r   zRefVariable.assign_add  4      !!;TCFm99r4   c                 h    t        j                  | j                  |||      }|r|S |j                  S )a6  Subtracts a value from this variable.

    This is essentially a shortcut for `assign_sub(self, delta)`.

    Args:
      delta: A `Tensor`. The value to subtract from this variable.
      use_locking: If `True`, use locking during the operation.
      name: The name of the operation to be created
      read_value: if True, will return something which evaluates to the new
        value of the variable; if False will return the assign op.

    Returns:
      A `Tensor` that will hold the new value of this variable after
      the subtraction has completed.
    r   )r   
assign_subr~   r   r   s         r2   r   zRefVariable.assign_sub  r   r4   c                     t        |t        j                        st        d|z        t	        j
                  | j                  |j                  |j                  ||      S )a  Subtracts `tf.IndexedSlices` from this variable.

    Args:
      sparse_delta: `tf.IndexedSlices` to be subtracted from this variable.
      use_locking: If `True`, use locking during the operation.
      name: the name of the operation.

    Returns:
      A `Tensor` that will hold the new value of this variable after
      the scattered subtraction has completed.

    Raises:
      TypeError: if `sparse_delta` is not an `IndexedSlices`.
    %sparse_delta is not IndexedSlices: %sr   )	r^   r   IndexedSlices	TypeErrorr   scatter_subr~   indicesvaluesrH   sparse_deltar   r   s       r2   r   zRefVariable.scatter_sub  W     lN$@$@A=LMM$$ r4   c                     t        |t        j                        st        d|z        t	        j
                  | j                  |j                  |j                  ||      S )a  Adds `tf.IndexedSlices` to this variable.

    Args:
      sparse_delta: `tf.IndexedSlices` to be added to this variable.
      use_locking: If `True`, use locking during the operation.
      name: the name of the operation.

    Returns:
      A `Tensor` that will hold the new value of this variable after
      the scattered addition has completed.

    Raises:
      TypeError: if `sparse_delta` is not an `IndexedSlices`.
    r   r   )	r^   r   r   r   r   scatter_addr~   r   r   r   s       r2   r   zRefVariable.scatter_add  r   r4   c                     t        |t        j                        st        d|z        t	        j
                  | j                  |j                  |j                  ||      S )a  Updates this variable with the max of `tf.IndexedSlices` and itself.

    Args:
      sparse_delta: `tf.IndexedSlices` to use as an argument of max with this
        variable.
      use_locking: If `True`, use locking during the operation.
      name: the name of the operation.

    Returns:
      A `Tensor` that will hold the new value of this variable after
      the scattered maximization has completed.

    Raises:
      TypeError: if `sparse_delta` is not an `IndexedSlices`.
    r   r   )	r^   r   r   r   r   scatter_maxr~   r   r   r   s       r2   r   zRefVariable.scatter_max  W      lN$@$@A=LMM$$ r4   c                     t        |t        j                        st        d|z        t	        j
                  | j                  |j                  |j                  ||      S )a  Updates this variable with the min of `tf.IndexedSlices` and itself.

    Args:
      sparse_delta: `tf.IndexedSlices` to use as an argument of min with this
        variable.
      use_locking: If `True`, use locking during the operation.
      name: the name of the operation.

    Returns:
      A `Tensor` that will hold the new value of this variable after
      the scattered minimization has completed.

    Raises:
      TypeError: if `sparse_delta` is not an `IndexedSlices`.
    r   r   )	r^   r   r   r   r   scatter_minr~   r   r   r   s       r2   r   zRefVariable.scatter_min  r   r4   c                     t        |t        j                        st        d|z        t	        j
                  | j                  |j                  |j                  ||      S )a  Multiply this variable by `tf.IndexedSlices`.

    Args:
      sparse_delta: `tf.IndexedSlices` to multiply this variable by.
      use_locking: If `True`, use locking during the operation.
      name: the name of the operation.

    Returns:
      A `Tensor` that will hold the new value of this variable after
      the scattered multiplication has completed.

    Raises:
      TypeError: if `sparse_delta` is not an `IndexedSlices`.
    r   r   )	r^   r   r   r   r   scatter_mulr~   r   r   r   s       r2   r   zRefVariable.scatter_mul   r   r4   c                     t        |t        j                        st        d|z        t	        j
                  | j                  |j                  |j                  ||      S )a  Divide this variable by `tf.IndexedSlices`.

    Args:
      sparse_delta: `tf.IndexedSlices` to divide this variable by.
      use_locking: If `True`, use locking during the operation.
      name: the name of the operation.

    Returns:
      A `Tensor` that will hold the new value of this variable after
      the scattered division has completed.

    Raises:
      TypeError: if `sparse_delta` is not an `IndexedSlices`.
    r   r   )	r^   r   r   r   r   scatter_divr~   r   r   r   s       r2   r   zRefVariable.scatter_div8  r   r4   c                     t        |t        j                        st        d|z        t	        j
                  | j                  |j                  |j                  ||      S )a  Assigns `tf.IndexedSlices` to this variable.

    Args:
      sparse_delta: `tf.IndexedSlices` to be assigned to this variable.
      use_locking: If `True`, use locking during the operation.
      name: the name of the operation.

    Returns:
      A `Tensor` that will hold the new value of this variable after
      the scattered assignment has completed.

    Raises:
      TypeError: if `sparse_delta` is not an `IndexedSlices`.
    r   r   )	r^   r   r   r   r   scatter_updater~   r   r   r   s       r2   r   zRefVariable.scatter_updateP  sW     lN$@$@A=LMM'' r4   c                 ^    t        j                  | |j                  |j                  ||      S )at  Assigns `tf.IndexedSlices` to this variable batch-wise.

    Analogous to `batch_gather`. This assumes that this variable and the
    sparse_delta IndexedSlices have a series of leading dimensions that are the
    same for all of them, and the updates are performed on the last dimension of
    indices. In other words, the dimensions should be the following:

    `num_prefix_dims = sparse_delta.indices.ndims - 1`
    `batch_dim = num_prefix_dims + 1`
    `sparse_delta.updates.shape = sparse_delta.indices.shape + var.shape[
         batch_dim:]`

    where

    `sparse_delta.updates.shape[:num_prefix_dims]`
    `== sparse_delta.indices.shape[:num_prefix_dims]`
    `== var.shape[:num_prefix_dims]`

    And the operation performed can be expressed as:

    `var[i_1, ..., i_n,
         sparse_delta.indices[i_1, ..., i_n, j]] = sparse_delta.updates[
            i_1, ..., i_n, j]`

    When sparse_delta.indices is a 1D tensor, this operation is equivalent to
    `scatter_update`.

    To avoid this operation one can looping over the first `ndims` of the
    variable and using `scatter_update` on the subtensors that result of slicing
    the first dimension. This is a valid option for `ndims = 1`, but less
    efficient than this implementation.

    Args:
      sparse_delta: `tf.IndexedSlices` to be assigned to this variable.
      use_locking: If `True`, use locking during the operation.
      name: the name of the operation.

    Returns:
      A `Tensor` that will hold the new value of this variable after
      the scattered assignment has completed.

    Raises:
      TypeError: if `sparse_delta` is not an `IndexedSlices`.
    r   )r   batch_scatter_updater   r   r   s       r2   r   z RefVariable.batch_scatter_updateh  s3    Z )) r4   c                 J    t        j                  | j                  ||d|      S )a  Applies sparse subtraction to individual values or slices in a Variable.

    `ref` is a `Tensor` with rank `P` and `indices` is a `Tensor` of rank `Q`.

    `indices` must be integer tensor, containing indices into `ref`.
    It must be shape `[d_0, ..., d_{Q-2}, K]` where `0 < K <= P`.

    The innermost dimension of `indices` (with length `K`) corresponds to
    indices into elements (if `K = P`) or slices (if `K < P`) along the `K`th
    dimension of `ref`.

    `updates` is `Tensor` of rank `Q-1+P-K` with shape:

    ```
    [d_0, ..., d_{Q-2}, ref.shape[K], ..., ref.shape[P-1]].
    ```

    For example, say we want to add 4 scattered elements to a rank-1 tensor to
    8 elements. In Python, that update would look like this:

    ```python
        ref = tf.Variable([1, 2, 3, 4, 5, 6, 7, 8])
        indices = tf.constant([[4], [3], [1] ,[7]])
        updates = tf.constant([9, 10, 11, 12])
        op = ref.scatter_nd_sub(indices, updates)
        with tf.compat.v1.Session() as sess:
          print sess.run(op)
    ```

    The resulting update to ref would look like this:

        [1, -9, 3, -6, -6, 6, 7, -4]

    See `tf.scatter_nd` for more details about how to make updates to
    slices.

    Args:
      indices: The indices to be used in the operation.
      updates: The values to be used in the operation.
      name: the name of the operation.

    Returns:
      A `Tensor` that will hold the new value of this variable after
      the scattered subtraction has completed.
    Tr   )r   scatter_nd_subr~   rH   r   updatesr   s       r2   r   zRefVariable.scatter_nd_sub  )    \ ''dG Gr4   c                 J    t        j                  | j                  ||d|      S )a  Applies sparse addition to individual values or slices in a Variable.

    `ref` is a `Tensor` with rank `P` and `indices` is a `Tensor` of rank `Q`.

    `indices` must be integer tensor, containing indices into `ref`.
    It must be shape `[d_0, ..., d_{Q-2}, K]` where `0 < K <= P`.

    The innermost dimension of `indices` (with length `K`) corresponds to
    indices into elements (if `K = P`) or slices (if `K < P`) along the `K`th
    dimension of `ref`.

    `updates` is `Tensor` of rank `Q-1+P-K` with shape:

    ```
    [d_0, ..., d_{Q-2}, ref.shape[K], ..., ref.shape[P-1]].
    ```

    For example, say we want to add 4 scattered elements to a rank-1 tensor to
    8 elements. In Python, that update would look like this:

    ```python
        ref = tf.Variable([1, 2, 3, 4, 5, 6, 7, 8])
        indices = tf.constant([[4], [3], [1] ,[7]])
        updates = tf.constant([9, 10, 11, 12])
        add = ref.scatter_nd_add(indices, updates)
        with tf.compat.v1.Session() as sess:
          print sess.run(add)
    ```

    The resulting update to ref would look like this:

        [1, 13, 3, 14, 14, 6, 7, 20]

    See `tf.scatter_nd` for more details about how to make updates to
    slices.

    Args:
      indices: The indices to be used in the operation.
      updates: The values to be used in the operation.
      name: the name of the operation.

    Returns:
      A `Tensor` that will hold the new value of this variable after
      the scattered addition has completed.
    Tr   )r   scatter_nd_addr~   r   s       r2   r   zRefVariable.scatter_nd_add  r   r4   c                 J    t        j                  | j                  ||d|      S )a  Applies sparse assignment to individual values or slices in a Variable.

    `ref` is a `Tensor` with rank `P` and `indices` is a `Tensor` of rank `Q`.

    `indices` must be integer tensor, containing indices into `ref`.
    It must be shape `[d_0, ..., d_{Q-2}, K]` where `0 < K <= P`.

    The innermost dimension of `indices` (with length `K`) corresponds to
    indices into elements (if `K = P`) or slices (if `K < P`) along the `K`th
    dimension of `ref`.

    `updates` is `Tensor` of rank `Q-1+P-K` with shape:

    ```
    [d_0, ..., d_{Q-2}, ref.shape[K], ..., ref.shape[P-1]].
    ```

    For example, say we want to add 4 scattered elements to a rank-1 tensor to
    8 elements. In Python, that update would look like this:

    ```python
        ref = tf.Variable([1, 2, 3, 4, 5, 6, 7, 8])
        indices = tf.constant([[4], [3], [1] ,[7]])
        updates = tf.constant([9, 10, 11, 12])
        op = ref.scatter_nd_update(indices, updates)
        with tf.compat.v1.Session() as sess:
          print sess.run(op)
    ```

    The resulting update to ref would look like this:

        [1, 11, 3, 10, 9, 6, 7, 12]

    See `tf.scatter_nd` for more details about how to make updates to
    slices.

    Args:
      indices: The indices to be used in the operation.
      updates: The values to be used in the operation.
      name: the name of the operation.

    Returns:
      A `Tensor` that will hold the new value of this variable after
      the scattered assignment has completed.
    Tr   )r   scatter_nd_updater~   r   s       r2   r   zRefVariable.scatter_nd_update  s)    \ **dG Gr4   c                 J    t        j                  | j                  ||d|      S )a  Updates this variable with the max of `tf.IndexedSlices` and itself.

    `ref` is a `Tensor` with rank `P` and `indices` is a `Tensor` of rank `Q`.

    `indices` must be integer tensor, containing indices into `ref`.
    It must be shape `[d_0, ..., d_{Q-2}, K]` where `0 < K <= P`.

    The innermost dimension of `indices` (with length `K`) corresponds to
    indices into elements (if `K = P`) or slices (if `K < P`) along the `K`th
    dimension of `ref`.

    `updates` is `Tensor` of rank `Q-1+P-K` with shape:

    ```
    [d_0, ..., d_{Q-2}, ref.shape[K], ..., ref.shape[P-1]].
    ```

    See `tf.scatter_nd` for more details about how to make updates to
    slices.

    Args:
      indices: The indices to be used in the operation.
      updates: The values to be used in the operation.
      name: the name of the operation.

    Returns:
      A `Tensor` that will hold the new value of this variable after
      the scattered addition has completed.
    Tr   )r   scatter_nd_maxr~   r   s       r2   r   zRefVariable.scatter_nd_max/  (    < ''dG Gr4   c                 J    t        j                  | j                  ||d|      S )a  Updates this variable with the min of `tf.IndexedSlices` and itself.

    `ref` is a `Tensor` with rank `P` and `indices` is a `Tensor` of rank `Q`.

    `indices` must be integer tensor, containing indices into `ref`.
    It must be shape `[d_0, ..., d_{Q-2}, K]` where `0 < K <= P`.

    The innermost dimension of `indices` (with length `K`) corresponds to
    indices into elements (if `K = P`) or slices (if `K < P`) along the `K`th
    dimension of `ref`.

    `updates` is `Tensor` of rank `Q-1+P-K` with shape:

    ```
    [d_0, ..., d_{Q-2}, ref.shape[K], ..., ref.shape[P-1]].
    ```

    See `tf.scatter_nd` for more details about how to make updates to
    slices.

    Args:
      indices: The indices to be used in the operation.
      updates: The values to be used in the operation.
      name: the name of the operation.

    Returns:
      A `Tensor` that will hold the new value of this variable after
      the scattered addition has completed.
    Tr   )r   scatter_nd_minr~   r   s       r2   r   zRefVariable.scatter_nd_minP  r   r4   c                 ^    t        j                  | j                         |||||||||	|
      S )N)refbeginendstridesr   r   
begin_maskend_maskellipsis_masknew_axis_maskshrink_axis_mask)r   strided_slice_assignr   )rH   r   r   r   r   r   r   r   r   r   r   s              r2   _strided_slice_assignz!RefVariable._strided_slice_assignq  s>     --IIK##)+ +r4   zPrefer Dataset.range instead.c                 D    t        j                  | j                  |      S )a  Increments this variable until it reaches `limit`.

    When that Op is run it tries to increment the variable by `1`. If
    incrementing the variable would bring it above `limit` then the Op raises
    the exception `OutOfRangeError`.

    If no error is raised, the Op outputs the value of the variable before
    the increment.

    This is essentially a shortcut for `count_up_to(self, limit)`.

    Args:
      limit: value at which incrementing the variable raises an error.

    Returns:
      A `Tensor` that will hold the variable value before the increment. If no
      other Op modifies this variable, the values produced will all be
      distinct.
    )limit)r   count_up_tor~   )rH   r   s     r2   r   zRefVariable.count_up_to  s    *   u==r4   c                     |}|rK|j                  | j                        s0t        d|j                  d| j                  j                  d      |r| j	                         S | j                         S )z7Utility function for converting a Variable to a Tensor.z0Incompatible type conversion requested to type 'z' for variable of type '')is_compatible_withr!   rE   r   r   r   )r9   r!   r   as_refr   s        r2   _TensorConversionFunctionz%RefVariable._TensorConversionFunction  s\     	AU--agg6!JJ67 7 VVXoWWYr4   d   c                     | j                   S )zThe name of this variable.)r   rP   s    r2   r   zRefVariable.name  s     ::r4   returnc                     | j                   S )z,The initializer operation for this variable.)r   rP   s    r2   initializerzRefVariable.initializer  s     r4   c                 .    | j                   j                  S )zThe device of this variable.)r~   rx   rP   s    r2   rx   zRefVariable.device  s     >>   r4   c                 .    | j                   j                  S )zThe `DType` of this variable.)r~   r!   rP   s    r2   r!   zRefVariable.dtype       >>r4   c                 .    | j                   j                  S )z!The `Operation` of this variable.)r~   r   rP   s    r2   r   zRefVariable.op  s     >>r4   c                 .    | j                   j                  S )zThe `Graph` of this variable.)r~   graphrP   s    r2   r  zRefVariable.graph  r   r4   c                      y)zBThe `tf.distribute.Strategy` that this variable was created under.N rP   s    r2   _distribute_strategyz RefVariable._distribute_strategy  s     r4   c                 6    | j                   j                         S )zMThe `TensorShape` of this variable.

    Returns:
      A `TensorShape`.
    )r~   rM   rP   s    r2   r(   zRefVariable.shape  s     >>##%%r4   c                     |&| j                   j                  j                  |      rft        j                         }t        j                  | j                   j                  |      |_        | j                  /t        j                  | j                  j                  |      |_	        | j                  |_
        | j                  j                  |_        | j                  j                  |_        t        j                  | j                  j                  |      |_        t        j                  | j                   j                  |      |_        | j$                  r5|j&                  j)                  | j$                  j+                  |             |S y)a  Converts a `Variable` to a `VariableDef` protocol buffer.

    Args:
      export_scope: Optional `string`. Name scope to remove.

    Returns:
      A `VariableDef` protocol buffer, or `None` if the `Variable` is not
      in the specified name scope.
    Nr6   )r~   r   
startswithr   r   r   strip_name_scoper   rz   r   r   r&   r   r'   r   r   r   r   r   r   	MergeFromr8   )rH   r7   var_defs      r2   r8   zRefVariable.to_proto  s;    	 3 3 > >| L((*g!224>>3F3F3?Ag				(%(%9%9$$l&4"..g $ 4 4 : :g ,,22g!$!5!5d6F6F6K6K6B"Dg!224>>3F3F3?Ag			##--!!***E	Gnr4   c                 V    t        j                  t         j                  dd       | |z   S )NzVariable += will be deprecated. Use variable.assign_add if you want assignment to the variable value or 'x = x + y' if you want a new python Tensor object.   logginglog_first_nWARNrH   others     r2   __iadd__zRefVariable.__iadd__  +     3457 %<r4   c                 V    t        j                  t         j                  dd       | |z
  S )NzVariable -= will be deprecated. Use variable.assign_sub if you want assignment to the variable value or 'x = x - y' if you want a new python Tensor object.r  r  r  s     r2   __isub__zRefVariable.__isub__  r  r4   c                 V    t        j                  t         j                  dd       | |z  S )NzVariable *= will be deprecated. Use `var.assign(var * other)` if you want assignment to the variable value or `x = x * y` if you want a new python Tensor object.r  r  r  s     r2   __imul__zRefVariable.__imul__	  +    	345	7
 %<r4   c                 V    t        j                  t         j                  dd       | |z  S NzVariable /= will be deprecated. Use `var.assign(var / other)` if you want assignment to the variable value or `x = x / y` if you want a new python Tensor object.r  r  r  s     r2   __idiv__zRefVariable.__idiv__  r  r4   c                 V    t        j                  t         j                  dd       | |z  S r  r  r  s     r2   __itruediv__zRefVariable.__itruediv__  r  r4   c                 V    t        j                  t         j                  dd       | |z  S r  r  r  s     r2   __irealdiv__zRefVariable.__irealdiv__!  r  r4   c                 V    t        j                  t         j                  dd       | |z  S )NzVariable **= will be deprecated. Use `var.assign(var ** other)` if you want assignment to the variable value or `x = x ** y` if you want a new python Tensor object.r  r  r  s     r2   __ipow__zRefVariable.__ipow__)  s+    	345	7
 ;r4   c                 &    t         j                  | iS )z+Implements Trackable._serialize_to_tensors.)rd   VARIABLE_VALUE_KEYrP   s    r2   _serialize_to_tensorsz!RefVariable._serialize_to_tensors1  s    (($//r4   c                     |t         j                     }t        j                  | || j	                         j                               S )z+Implements Trackable._restore_from_tensors.rY   )rd   r$  r   r   rM   r   )rH   restored_tensorsrestored_tensors      r2   _restore_from_tensorsz!RefVariable._restore_from_tensors5  s>    &y'C'CDO~~'88:< <r4   )NNNTNNNNNNNNNN)NNNTNNNNNNNNr   )FNT)FN)NNF)A__name__
__module____qualname____doc__rI   rQ   rG   rF   r   r   rO   r   r   propertyr   r&   r'   r   r   r$   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   staticmethodr   __array_priority__r   r   	Operationr   rx   r   DTyper!   r   Graphr  r  r(   r8   r  r  r  r  r  r   r"  r%  r)  r  r4   r2   r/   r/      s   . m^8 %) $"&%)%) %)!%&*"& |"|+Z&	; "   ! !  0@    ,,,00220002h/Gb/Gb/GbGBGB+  d34> 5>. 
 
&    3==     ! !  V\\     #--    SYY       & &@0<r4   r/   r   )4r-  tensorflow.core.frameworkr   r   tensorflow.python.eagerr   tensorflow.python.frameworkr   r   r   r	   r
   tensorflow.python.opsr   r   r   r   r   r   r   r   r   tensorflow.python.platformr   r  tensorflow.python.trackabler   rd   tensorflow.python.typesr   tensorflow.python.utilr   "tensorflow.python.util.deprecationr   r3   r:   r@   register_proto_functionr\   r]   r   ro   MOVING_AVERAGE_VARIABLESLOCAL_VARIABLESMODEL_VARIABLESGLOBAL_STEPMETRIC_VARIABLESr?   Tensorr/   #register_tensor_conversion_functionr   r  r4   r2   <module>rE     s    4 2 + . 6 + B 4 + / / 7 ; + 0 - + < 9 ( ) 98v/
I   MM""''	
   MM%%''	
   MM**''	
   MM!!''	
   MM!!''	
   MM''	
   MM""''	d<+(($++ d<R% ?  > >668r4   