
    &Vf)                         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  ed           G d d                      ZdS )    N)backend)dtype_policies)tree)keras_export)any_symbolic_tensors)Node)python_utils)traceback_utils)	auto_namezkeras.Operationc                        e Zd ZddZej        d             Zd Zd Zd Z	d Z
 fdZej        d	             Zed
             Zd Zed             Zed             Zd Zd Zd Zd Zd Z xZS )	OperationNc                    |t          | j        j                  }t          |t                    rd|v r#t          d| dt          |           d          t          j        |          | _	        || _
        g | _        g | _        d S )N/zRArgument `name` must be a string and cannot contain character `/`. Received: name=z
 (of type ))r   	__class____name__
isinstancestr
ValueErrortyper   get_dtype_policyname_inbound_nodes_outbound_nodes)selfdtyper   s      T/var/www/html/software/conda/lib/python3.11/site-packages/keras/src/ops/operation.py__init__zOperation.__init__   s    <T^455D$$$ 	t@"&@ @26t**@ @ @  
 ,/66	 !    c                    t          j                    rqt          ||          r| j        }n.t	          | j        t          j                  r| j        }n| j	        }t          j
        || j        j         d          } ||i |S t          ||          r | j        |i |S t	          | j        t          j                  r | j        |i |S  | j	        |i |S )Nz.call())object_name)r
   is_traceback_filtering_enabledr   symbolic_callr   r   r   QuantizedDTypePolicyquantized_callcall!inject_argument_info_in_tracebackr   r   )r   argskwargscall_fns       r   __call__zOperation.__call__   s   9;; 	,#D&11 (,&(K  ( #1GG"iG%G $ 7@@@  G 7D+F+++  f-- 	7%4%t6v666d(.*MNN 	.&4&777749d-f---r    c                 F     | j         |i |}t          | |||           |S )N)	operation	call_argscall_kwargsoutputs)compute_output_specr   )r   r)   r*   r1   s       r   r$   zOperation.symbolic_call:   sB    *$*D;F;; 	d	
 	
 	
 	
 r    c                     t           NNotImplementedErrorr   r)   r*   s      r   r'   zOperation.callH       !!r    c                     t           r4   r5   r7   s      r   r&   zOperation.quantized_callK   r8   r    c                 B   	 t          j        | j        g|R i |S # t          $ rx}t	          |t
                    r|t          d| j         d| j        j	         d| j        j	         d| j        j	         d| 
          }|
                    |j                  d d }~ww xY w)Nz;Could not automatically infer the output shape / dtype of 'z' (of type z). Either the `z<.call()` method is incorrect, or you need to implement the `zM.compute_output_spec() / compute_output_shape()` method. Error encountered:

)r   r2   r'   	Exceptionr   	TypeErrorRuntimeErrorr   r   r   with_traceback__traceback__)r   r)   r*   enew_es        r   r2   zOperation.compute_output_specN   s    	F.tyJ4JJJ6JJJ 	F 	F 	F!Y'' F$1	1 1.2n.E1 1#'>#:1 1 /	1 1 ./1 1  **1?;;E	Fs    
BA3BBc                 ~   t          j        | j                  j        }|                    t          t          |dt          |          dz            |                               t          t          |           
                    |           }t          t          t          t          t          d          f}	 t!          j        |          }d}|D ]}t%          ||          sd} nn# t&          $ r d}Y nw xY w	 d|_        |rddlm}	  |	j        di ||_        nd|_        d|_        n# t2          $ r Y nw xY w|S )aJ  We override __new__ to saving serializable constructor arguments.

        These arguments are used to auto-generate an object serialization
        config, which enables user-created subclasses to be serializable
        out of the box in most cases without forcing the user
        to manually implement `get_config()`.
           NTFr   )serialization_lib )inspectgetfullargspecr   r)   updatedictziplensuperr   __new__r   intfloatboolr   r   flattenr   r<   _lockkeras.src.savingrD   SerializableDict_auto_configRecursionError)clsr)   r*   	arg_namesinstancesupported_typesflat_arg_valuesauto_configvaluerD   r   s             r   rM   zOperation.__new__`   s    *3<88=	d3ySYY]):;TBBCCDDDC((0055 UD$t**=	 "l622OK(  !%99 "'KE  	  	  	 KKK	 	"HN ->>>>>>(J(9(J ) )) )%% )-%!HNN 	 	 	 D		
 s$   9/C) )C87C8<0D- -
D:9D:c                    d| j         i}t          j        | j                  s|S t	          | dd          t          |                                          }|                    | j        j	                   t          j        | j                  }|j        dk    r>||                    |j        dd                   z
  D ]}|                    |d           |S t#          t%          j        d| j        j         d                    )zReturns the config of the object.

        An object config is a Python dictionary (serializable)
        containing the information needed to re-instantiate it.
        r   rU   Nr*   rC   z
        Object a   was created by passing
        non-serializable argument values in `__init__()`,
        and therefore the object must override `get_config()` in
        order to be serializable. Please implement `get_config()`.

        Example:

        class CustomLayer(keras.layers.Layer):
            def __init__(self, arg1, arg2, **kwargs):
                super().__init__(**kwargs)
                self.arg1 = arg1
                self.arg2 = arg2

            def get_config(self):
                config = super().get_config()
                config.update({
                    "arg1": self.arg1,
                    "arg2": self.arg2,
                })
                return config)r   r	   
is_default
get_configgetattrsetkeysrH   rU   configrF   rG   r   varkwintersectionr)   popr6   textwrapdedentr   r   )r   rd   	xtra_argsargspeckeys        r   r`   zOperation.get_config   s    DI
 &t77 	M 4..:FKKMM**IMM$+2333,T];;G}(($y'='=gl122>N'O'OO * *CJJsD))))M%!'! ! !   r    c           	      r    	  | di |S # t           $ r"}t          d| j         d| d|           d}~ww xY w)a  Creates a layer from its config.

        This method is the reverse of `get_config`,
        capable of instantiating the same layer from the config
        dictionary. It does not handle layer connectivity
        (handled by Network), nor weights (handled by `set_weights`).

        Args:
            config: A Python dictionary, typically the
                output of get_config.

        Returns:
            A layer instance.
        z Error when deserializing class 'z' using config=z.

Exception encountered: NrE   )r;   r<   r   )rW   rd   r@   s      r   from_configzOperation.from_config   s~     	3====  	 	 	B3< B B B B>?B B  	s   
 
616c                     d| j          dS )Nz<Operation name=>)r   r   s    r   __repr__zOperation.__repr__   s    .$)....r    c                 0    |                      ddd          S )zRetrieves the input tensor(s) of a symbolic operation.

        Only returns the tensor(s) corresponding to the *first time*
        the operation was called.

        Returns:
            Input tensor or list of input tensors.
        r   input_tensorsinput_get_node_attribute_at_indexrq   s    r   ru   zOperation.input   s     00OWMMMr    c                 0    |                      ddd          S )zRetrieves the output tensor(s) of a layer.

        Only returns the tensor(s) corresponding to the *first time*
        the operation was called.

        Returns:
            Output tensor or list of output tensors.
        r   output_tensorsoutputrv   rq   s    r   rz   zOperation.output   s     004DhOOOr    c           
      f   | j         st          d| j         d| d          t          | j                   |k    s+t          d| d| dt          | j                    d          t	          | j         |         |          }t          |t                    rt          |          dk    r|d	         S |S )
a  Private utility to retrieves an attribute (e.g. inputs) from a node.

        This is used to implement the properties:
        - output
        - input

        Args:
            node_index: Integer index of the node from which
                to retrieve the attribute.
            attr: Exact node attribute name.
            attr_name: Human-readable attribute name, for error messages.

        Returns:
            The operation's attribute `attr` at the node of index `node_index`.
        z
The layer z/ has never been called and thus has no defined .zAsked to get z	 at node z, but the operation has only z inbound nodes.rC   r   )r   r   r   rK   ra   r   list)r   
node_indexattr	attr_namevaluess        r   rw   z&Operation._get_node_attribute_at_index   s      " 	8TY 8 8+48 8 8   4&''*44=	 = == =t*++= = =  
 ,Z8$??fd## 	Fq(8(8!9Mr    c                     dS )5Can be overridden for per backend post build actions.NrE   rq   s    r   _post_buildzOperation._post_build      r    c                 
    ||fS )r   rE   )r   r   r]   s      r   _setattr_hookzOperation._setattr_hook  s    U{r    c                     dS )z5Can be overridden for per backend post track actions.NrE   r   variables     r   _post_track_variablezOperation._post_track_variable  r   r    c                     dS )z7Can be overridden for per backend post untrack actions.NrE   r   s     r   _post_untrack_variablez Operation._post_untrack_variable   r   r    )NN)r   
__module____qualname__r   r
   filter_tracebackr,   r$   r'   r&   r2   rM   r	   defaultr`   classmethodrn   rr   propertyru   rz   rw   r   r   r   r   __classcell__)r   s   @r   r   r      s}       " " " " %. . &%.4  " " "" " "F F F$( ( ( ( (T 2 2 2h   [./ / / 	N 	N X	N 	P 	P X	P  D            r    r   )rF   rh   	keras.srcr   r   r   keras.src.api_exportr   %keras.src.backend.common.keras_tensorr   keras.src.ops.noder   keras.src.utilsr	   r
   keras.src.utils.namingr   r   rE   r    r   <module>r      s           $ $ $ $ $ $       - - - - - - F F F F F F # # # # # # ( ( ( ( ( ( + + + + + + , , , , , ,   R R R R R R R ! R R Rr    