
    &Vfc&                     p    d dl mZ d dl mZ d dlmZ  eddg           G d d                      Zd Zd	S )
    )backend)tree)keras_exportzkeras.InputSpeczkeras.layers.InputSpecc                   L    e Zd ZdZ	 	 	 	 	 	 	 	 ddZd Zd Zed             ZdS )		InputSpecaw  Specifies the rank, dtype and shape of every input to a layer.

    Layers can expose (if appropriate) an `input_spec` attribute:
    an instance of `InputSpec`, or a nested structure of `InputSpec` instances
    (one per input tensor). These objects enable the layer to run input
    compatibility checks for input structure, input rank, input shape, and
    input dtype for the first argument of `Layer.__call__`.

    A `None` entry in a shape is compatible with any dimension.

    Args:
        dtype: Expected dtype of the input.
        shape: Shape tuple, expected shape of the input
            (may include `None` for dynamic axes).
            Includes the batch size.
        ndim: Integer, expected rank of the input.
        max_ndim: Integer, maximum rank of the input.
        min_ndim: Integer, minimum rank of the input.
        axes: Dictionary mapping integer axes to
            a specific dimension value.
        allow_last_axis_squeeze: If `True`, allow inputs of rank N+1 as long
            as the last axis of the input is 1, as well as inputs of rank N-1
            as long as the last axis of the spec is 1.
        name: Expected key corresponding to this input when passing data as
            a dictionary.

    Example:

    ```python
    class MyLayer(Layer):
        def __init__(self):
            super().__init__()
            # The layer will accept inputs with
            # shape (*, 28, 28) & (*, 28, 28, 1)
            # and raise an appropriate error message otherwise.
            self.input_spec = InputSpec(
                shape=(None, 28, 28, 1),
                allow_last_axis_squeeze=True)
    ```
    NFc	                 R   |t          j        |          nd | _        |.t          j        |          | _        t          |          | _        n|| _        d | _        || _        || _        || _	        || _
        	 pi fdD             | _        n'# t          t          f$ r t          d           w xY w| j        rc| j        | j        W| j        r| j        n| j        dz
  }	t          | j                  }
|
|	k    r't          d                    |
|	                    d S d S d S )Nc                 <    i | ]}t          |          |         S  )int).0kaxess     X/var/www/html/software/conda/lib/python3.11/site-packages/keras/src/layers/input_spec.py
<dictcomp>z&InputSpec.__init__.<locals>.<dictcomp>K   s%    777QQa777    zAArgument `axes` must be a dict with integer keys. Received: axes=   z5Axis {} is greater than the maximum allowed value: {})r   standardize_dtypedtypestandardize_shapeshapelenndimmax_ndimmin_ndimnameallow_last_axis_squeezer   
ValueError	TypeErrormaxformat)selfr   r   r   r   r   r   r   r   max_dimmax_axiss         `    r   __init__zInputSpec.__init__1   sp    160AG%e,,,t 	
  2599DJE

DIIDIDJ  	'>$	:2D7777$777DIII& 	 	 	)"&) )  	 9 	$)/4=3L$(I@tyy4=AEG49~~H'!! ((.x(A(A  		 	3L3L "!s   :B $B6c           	         | j         rdt          | j                   z   nd| j        rdt          | j                  z   nd| j        rdt          | j                  z   nd| j        rdt          | j                  z   nd| j        rdt          | j                  z   nd| j        rdt          | j                  z   ndg}dd	                    d
 |D                        dS )Nzdtype= zshape=zndim=z	max_ndim=z	min_ndim=zaxes=z
InputSpec(z, c              3      K   | ]}||V  	d S )Nr
   )r   xs     r   	<genexpr>z%InputSpec.__repr__.<locals>.<genexpr>d   s'      %;%;A%;a%;%;%;%;%;%;r   ))r   strr   r   r   r   r   join)r!   specs     r   __repr__zInputSpec.__repr__[   s    ,0J>XDJ''B,0J>XDJ''B*.);Ws49~~%%26-G[3t}----R26-G[3t}----R*.);Ws49~~%%
 ?DII%;%;%;%;%;;;>>>>r   c                 P    | j         | j        | j        | j        | j        | j        dS )Nr   r   r   r   r   r   r0   )r!   s    r   
get_configzInputSpec.get_configf   s/    ZZII
 
 	
r   c                      | di |S )Nr
   r
   )clsconfigs     r   from_configzInputSpec.from_configp   s    s}}V}}r   )NNNNNNFN)	__name__
__module____qualname____doc__r$   r.   r1   classmethodr5   r
   r   r   r   r      s        ' 'V  %( ( ( (T	? 	? 	?
 
 
   [  r   r   c                 z   | sdS t          j        |           } t          |t                    rzd | D             }t	          |          r_g }|D ]X}||vr7t          d| dt          |                                           d|           |                    ||                    Y|}t          j        |          }t          |           t          |          k    r3t          d| dt          |            dt          |           d	          |D ]8}t          |d
          s&t          d| dt          |           d| d          9t          |          t          |           k    r5t          d| dt          |            dt          |           d|           t          t          ||                     D ]\  }\  }}|t          j        |j                  }	t          |	          }
|j        5|j        s.|
|j        k    r#t          d| d| d|j         d|
 d|	 
          |j        -|
+|
|j        k    r t          d| d| d|j         d|
           |j        0|
.|
|j        k     r#t          d| d| d|j         d|
 d|	 
          |j        Dt          j        |j                  }||j        k    r t          d| d| d|j         d|           |j        rK|j                                        D ]1\  }}|*|	|         |dhvrt          d| d| d| d| d|	 
          2|j        ~|j        }|j        r0|	r|	d         d k    r
|	dd         }	|r|d         d k    r
|dd         }t          ||	          D ]/\  }}|(|&||k    r t          d| d| d!|j         d"|	           0dS )#a  Checks compatibility between the layer and provided inputs.

    This checks that the tensor(s) `inputs` verify the input assumptions
    of a layer (if any). If not, a clear and actional exception gets raised.

    Args:
        input_spec: An InputSpec instance, list of InputSpec instances, a nested
            structure of InputSpec instances, or None.
        inputs: Input tensor, list of input tensors, or a nested structure of
            input tensors.
        layer_name: String, name of the layer (for error message formatting).

    Raises:
        ValueError: in case of mismatch between
            the provided inputs and the expectations of the layer.
    Nc                     g | ]	}|j         
S r
   )r   )r   r-   s     r   
<listcomp>z.assert_input_compatibility.<locals>.<listcomp>   s    222t222r   zMissing data for input "z*". You passed a data dictionary with keys z. Expected the following keys: zLayer 'z' expected z input(s). Received z	 instead.r   z*Inputs to a layer should be tensors. Got 'z' (of type z) as input for layer 'z'.zLayer "z
" expects z input(s), but it received z! input tensors. Inputs received: zInput z of layer "z0" is incompatible with the layer: expected ndim=z, found ndim=z. Full shape received: z4" is incompatible with the layer: expected max_ndim=z4" is incompatible with the layer: expected min_ndim=z1" is incompatible with the layer: expected dtype=z, found dtype=z0" is incompatible with the layer: expected axis z of input shape to have value z , but received input with shape r   z1" is incompatible with the layer: expected shape=z, found shape=)r   flatten
isinstancedictallr   listkeysappendr   hasattrtype	enumeratezipr   r   r   r   r   r   r   r   r   r   items)
input_specinputs
layer_namenameslist_inputsr   r(   input_indexr-   r   r   r   axisvalue
spec_shapespec_dimdims                    r   assert_input_compatibilityrV   u   s   "  j))J&$ !22z222u:: 	!K 1 1v%%$@4 @ @..@ @ 9>@ @   ""6$<0000 F\&!!F
:#f++%%/j / /S__ / /F/ / /
 
 	
  	 	
 q'"" 	JQ J J GGJ J;EJ J J  	 6{{c*oo%%)j ) )C
OO ) ) #F) ) &) )
 
 	

 #,C
,C,C"D"D I IYa<)!'225zz9 )E ty   4[ 4 4Z 4 4%)Y4 4=A4 4 -24 4   =$D4=$8$8 )[ ) )Z ) ))-) ) #') )   =$D4=$8$8 4[ 4 4Z 4 4)-4 4 #'4 4 -2	4 4   :!-ag66E
"" +[ + +Z + +&*j+ + $)+ +   9 	#y00  e$t= * * %) ) ) ) )FJ) )8=) ) "'	) )   :!J+ 1 'U2Y!^^!#2#JE 1*R.A"5"5!+CRCJ!$Z!7!7  #'CO3(3[ 3 3Z 3 3.2j3 3 ,13 3  II Ir   N)	keras.srcr   r   keras.src.api_exportr   r   rV   r
   r   r   <module>rY      s                - - - - - -  ":;<<k k k k k k k =<k\E E E E Er   