
    2VhL+                     z    d dl mZ d dlmZ d dlmZ  ed       G d d             ZddZ ed	d
g      d        Zy)    )tree)keras_export)	auto_namezkeras.KerasTensorc                      e Zd ZdZ	 	 	 	 	 d9dZed        Zej                  d        Zed        Zej                  d        Zed        Z	e	j                  d	        Z	ed
        Z
e
j                  d        Z
ed        Zd Zd:dZd Zd Zd Zd Zd;dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd  Zd! Z d" Z!d# Z"d$ Z#d% Z$d& Z%d' Z&d( Z'd) Z(d* Z)d+ Z*d, Z+d- Z,d. Z-d/ Z.d0 Z/d1 Z0d2 Z1d3 Z2d4 Z3d5 Z4d6 Z5d7 Z6d:d8Z7y)<KerasTensora  Symbolic tensor -- encapsulates a shape and a dtype.

    You can use `KerasTensor` instances to build computation
    graphs of Keras operations, such as `keras.Function`
    objects or Functional `keras.models.Model` objects.

    Example:

    >>> x = keras.KerasTensor(shape=(3, 4), dtype="float32")
    >>> x.shape
    (3, 4)
    >>> x.dtype
    float32

    Calling a Keras operation (including a layer or a model)
    on a `KerasTensor` instance will return another `KerasTensor`
    instance with the appropriate shape and dtype. This is
    called a "symbolic call" (since there is no actual data
    involved). The computation of the correct output shape and
    dtype is called "static shape inference".
    Nc                 L   ddl m} |j                  |      | _        |j	                  |      | _        t        |      | _        t        |      | _        | j                  r| j                  rt        d      |xs t        | j                  j                        | _        || _        y )Nr   )backendzIKerasTensor cannot have `sparse=True` and `ragged=True` at the same time.)	keras.srcr	   standardize_shape_shapestandardize_dtype_dtypebool_sparse_ragged
ValueErrorr   	__class____name__namerecord_history)selfshapedtypesparseraggedr   r   r	   s           U/home/dcms/DCMS/lib/python3.12/site-packages/keras/src/backend/common/keras_tensor.py__init__zKerasTensor.__init__   s     	&//6//6F|F|<<DLL!  >Idnn&=&=>	,    c                     | j                   S N)r   r   s    r   r   zKerasTensor.shape5       {{r   c                     t        d      )NzlThe `shape` attribute of KerasTensor is immutable. One should create a new instance of KerasTensor for this.AttributeErrorr   values     r   r   zKerasTensor.shape9       =
 	
r   c                     | j                   S r    )r   r!   s    r   r   zKerasTensor.dtype@   r"   r   c                     t        d      )NzlThe `dtype` attribute of KerasTensor is immutable. One should create a new instance of KerasTensor for this.r$   r&   s     r   r   zKerasTensor.dtypeD   r(   r   c                     | j                   S r    )r   r!   s    r   r   zKerasTensor.sparseK       ||r   c                     t        d      )NzmThe `sparse` attribute of KerasTensor is immutable. One should create a new instance of KerasTensor for this.r$   r&   s     r   r   zKerasTensor.sparseO   r(   r   c                     | j                   S r    )r   r!   s    r   r   zKerasTensor.raggedV   r,   r   c                     t        d      )NzmThe `ragged` attribute of KerasTensor is immutable. One should create a new instance of KerasTensor for this.r$   r&   s     r   r   zKerasTensor.raggedZ   r(   r   c                 ,    t        | j                        S r    )lenr   r!   s    r   ndimzKerasTensor.ndima   s    4::r   c                 <    ddl m}  |j                  |      |       S Nr   ops)r
   r6   Reshape)r   newshaper6   s      r   reshapezKerasTensor.reshapee   s    !$s{{8$T**r   c                 <    ddl m}  |j                  |      |       S r4   )r
   r6   Squeeze)r   axisr6   s      r   squeezezKerasTensor.squeezej   s    ! s{{4 &&r   c                     t        d      )NzA KerasTensor is symbolic: it's a placeholder for a shape an a dtype. It doesn't have any actual numerical value. You cannot convert it to an int.r   r!   s    r   __int__zKerasTensor.__int__o   s    /
 	
r   c                     t        d      )NzA KerasTensor is symbolic: it's a placeholder for a shape an a dtype. It doesn't have any actual numerical value. You cannot convert it to a float.r?   r!   s    r   	__float__zKerasTensor.__float__v   s    0
 	
r   c                     t        d      )NzA KerasTensor is symbolic: it's a placeholder for a shape an a dtype. It doesn't have any actual numerical value. You cannot convert it to a NumPy array.r?   r!   s    r   	__array__zKerasTensor.__array__}   s    6
 	
r   c                     t        d      )Na%  A KerasTensor cannot be used as input to a JAX function. A KerasTensor is a symbolic placeholder for a shape and dtype, used when constructing Keras Functional models or Keras Functions. You can only use it as input to a Keras layer or a Keras operation (from the namespaces `keras.layers` and `keras.ops`). You are likely doing something like:

```
x = Input(...)
...
jax_fn(x)  # Invalid.
```

What you should do instead is wrap `jax_fn` in a layer:

```
class MyLayer(Layer):
    def call(self, x):
        return jax_fn(x)

x = MyLayer()(x)
```
r?   r!   s    r   __jax_array__zKerasTensor.__jax_array__       
 	
r   c                     t        d      )Na)  A KerasTensor cannot be used as input to a TensorFlow function. A KerasTensor is a symbolic placeholder for a shape and dtype, used when constructing Keras Functional models or Keras Functions. You can only use it as input to a Keras layer or a Keras operation (from the namespaces `keras.layers` and `keras.ops`). You are likely doing something like:

```
x = Input(...)
...
tf_fn(x)  # Invalid.
```

What you should do instead is wrap `tf_fn` in a layer:

```
class MyLayer(Layer):
    def call(self, x):
        return tf_fn(x)

x = MyLayer()(x)
```
r?   )r   r   r   s      r   __tf_tensor__zKerasTensor.__tf_tensor__   rG   r   c                     d| j                    d| j                   d| j                   d| j                   d| j                   dS )Nz<KerasTensor shape=z, dtype=z	, sparse=z	, ragged=z, name=>)r   r   r   r   r   r!   s    r   __repr__zKerasTensor.__repr__   sG    !$**Xdjj\ Bkk])DKK=		{!M	
r   c                     t        d      )Nz7Iterating over a symbolic KerasTensor is not supported.)NotImplementedErrorr!   s    r   __iter__zKerasTensor.__iter__   s    !E
 	
r   c                     t        d      )Nz3A symbolic KerasTensor cannot be used as a boolean.)	TypeErrorr!   s    r   __bool__zKerasTensor.__bool__   s    MNNr   c                 N    ddl m} |j                         j                  | |      S r4   r
   r6   Addsymbolic_callr   otherr6   s      r   __add__zKerasTensor.__add__       !wwy&&tU33r   c                 N    ddl m} |j                         j                  ||       S r4   rT   rW   s      r   __radd__zKerasTensor.__radd__       !wwy&&ud33r   c                 N    ddl m} |j                         j                  | |      S r4   r
   r6   SubtractrV   rW   s      r   __sub__zKerasTensor.__sub__       !||~++D%88r   c                 N    ddl m} |j                         j                  ||       S r4   r_   rW   s      r   __rsub__zKerasTensor.__rsub__       !||~++E488r   c                 N    ddl m} |j                         j                  | |      S r4   r
   r6   MultiplyrV   rW   s      r   __mul__zKerasTensor.__mul__   rb   r   c                 N    ddl m} |j                         j                  ||       S r4   rg   rW   s      r   __rmul__zKerasTensor.__rmul__   re   r   c                 N    ddl m} |j                         j                  | |      S r4   r
   r6   MatmulrV   rW   s      r   
__matmul__zKerasTensor.__matmul__       !zz|))$66r   c                 N    ddl m} |j                         j                  ||       S r4   rm   rW   s      r   __rmatmul__zKerasTensor.__rmatmul__       !zz|))%66r   c                 N    ddl m} |j                         j                  | |      S r4   r
   r6   DividerV   rW   s      r   __div__zKerasTensor.__div__   rp   r   c                 N    ddl m} |j                         j                  ||       S r4   ru   rW   s      r   __rdiv__zKerasTensor.__rdiv__   rs   r   c                 N    ddl m} |j                         j                  | |      S r4   r
   r6   
TrueDividerV   rW   s      r   __truediv__zKerasTensor.__truediv__       !~~--dE::r   c                 N    ddl m} |j                         j                  ||       S r4   r{   rW   s      r   __rtruediv__zKerasTensor.__rtruediv__       !~~--eT::r   c                 L    ddl m} |j                         j                  |       S r4   )r
   r6   NegativerV   r   r6   s     r   __neg__zKerasTensor.__neg__       !||~++D11r   c                 L    ddl m} |j                         j                  |       S r4   )r
   r6   AbsoluterV   r   s     r   __abs__zKerasTensor.__abs__  r   r   c                 N    ddl m} |j                         j                  | |      S r4   r
   r6   PowerrV   rW   s      r   __pow__zKerasTensor.__pow__  s    !yy{((u55r   c                 N    ddl m} |j                         j                  ||       S r4   r   rW   s      r   __rpow__zKerasTensor.__rpow__  s    !yy{((55r   c                 N    ddl m} |j                         j                  | |      S r4   r
   r6   FloorDividerV   rW   s      r   __floordiv__zKerasTensor.__floordiv__  s    ! ..tU;;r   c                 N    ddl m} |j                         j                  ||       S r4   r   rW   s      r   __rfloordiv__zKerasTensor.__rfloordiv__  s    ! ..ud;;r   c                 N    ddl m} |j                         j                  | |      S r4   r
   r6   ModrV   rW   s      r   __mod__zKerasTensor.__mod__  rZ   r   c                 N    ddl m} |j                         j                  ||       S r4   r   rW   s      r   __rmod__zKerasTensor.__rmod__  r]   r   c                 N    ddl m} |j                         j                  | |      S r4   )r
   r6   LessrV   rW   s      r   __lt__zKerasTensor.__lt__$  s    !xxz''e44r   c                 N    ddl m} |j                         j                  | |      S r4   )r
   r6   	LessEqualrV   rW   s      r   __le__zKerasTensor.__le__)      !}},,T599r   c                 N    ddl m} |j                         j                  | |      S r4   )r
   r6   GreaterrV   rW   s      r   __gt__zKerasTensor.__gt__.  s    !{{}**477r   c                 N    ddl m} |j                         j                  | |      S r4   )r
   r6   GreaterEqualrV   rW   s      r   __ge__zKerasTensor.__ge__3  s!    !!//e<<r   c                 N    ddl m} |j                         j                  | |      S r4   )r
   r6   NotEqualrV   rW   s      r   __ne__zKerasTensor.__ne__8  rb   r   c                 N    ddl m} |j                         j                  | |      S r4   r
   r6   
LogicalAndrV   rW   s      r   __and__zKerasTensor.__and__=  r~   r   c                 N    ddl m} |j                         j                  ||       S r4   r   rW   s      r   __rand__zKerasTensor.__rand__B  r   r   c                 N    ddl m} |j                         j                  | |      S r4   r
   r6   	LogicalOrrV   rW   s      r   __or__zKerasTensor.__or__G  r   r   c                 N    ddl m} |j                         j                  ||       S r4   r   rW   s      r   __ror__zKerasTensor.__ror__L  s    !}},,UD99r   c                 L    ddl m} |j                         j                  |       S r4   )r
   r6   
LogicalNotrV   r   s     r   
__invert__zKerasTensor.__invert__Q  s    !~~--d33r   c                 N    ddl m} |j                         j                  | |      S r4   r
   r6   
LogicalXorrV   rW   s      r   __xor__zKerasTensor.__xor__V  r~   r   c                 N    ddl m} |j                         j                  ||       S r4   r   rW   s      r   __rxor__zKerasTensor.__rxor__[  r   r   c                 N    ddl m} |j                         j                  | |      S r4   )r
   r6   GetItemrV   )r   keyr6   s      r   __getitem__zKerasTensor.__getitem__`  s    !{{}**455r   c                 \    ddl m} |xs d}|j                  |      j                  |       S )Nr   r5   )decimals)r
   r6   RoundrV   )r   ndigitsr6   r   s       r   	__round__zKerasTensor.__round__e  s*    !<ayy(y+99$??r   )float32FFTNr    NN)8r   
__module____qualname____doc__r   propertyr   setterr   r   r   r2   r9   r=   r@   rB   rD   rF   rI   rL   rO   rR   rY   r\   ra   rd   ri   rk   ro   rr   rw   ry   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      s   2 -.   \\
 
   \\
 
   ]]
 
   ]]
 
  +
'




.
.


O4
4
9
9
9
9
7
7
7
7
;
;
2
2
6
6
<
<
4
4
5
:
8
=
9
;
;
:
:
4
;
;
6
@r   r   Nc                 x    | xs d} |xs i }t        j                  | |f      D ]  }t        |t              s y y)Nr   TF)r   flatten
isinstancer   )argskwargsxs      r   any_symbolic_tensorsr   l  sB    :2D\rF\\4.) a% r   zkeras.utils.is_keras_tensorzkeras.backend.is_keras_tensorc                 "    t        | t              S )a|  Returns whether `x` is a Keras tensor.

    A "Keras tensor" is a *symbolic tensor*, such as a tensor
    that was created via `Input()`. A "symbolic tensor"
    can be understood as a placeholder -- it does not
    contain any actual numerical data, only a shape and dtype.
    It can be used for building Functional models, but it
    cannot be used in actual computations.
    )r   r   )r   s    r   is_keras_tensorr   u  s     a%%r   r   )	r
   r   keras.src.api_exportr   keras.src.utils.namingr   r   r   r   r   r   r   <module>r      sZ     - , !"b@ b@ #b@J ,.MNO
& P
&r   