
    6bi,/                         S r SSKJs  Jr  SSKJr  SSKJr  SSKJ	r	  \" SSS/S9\	" S	/S9 " S
 S5      5       5       r
S rS rS rSS jrg)zContains the InputSpec class.    N)backend)keras_export)	tf_exportzkeras.layers.InputSpecz*keras.__internal__.legacy.layers.InputSpec)v1zlayers.InputSpecc                   N    \ rS rSrSr        S	S jrS rS r\S 5       r	Sr
g)
	InputSpec   a  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.

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

Args:
  dtype: Expected DataType of the input.
  shape: Shape tuple, expected shape of the input
    (may include None for unchecked 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, then 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(MyLayer, self).__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)
```
Nc	                    Ub   [         R                  " U5      R                  OS U l        [         R                  " U5      nUR
                  c  S nO[        UR                  5       5      nUb  [        U5      U l	        X l
        OX0l	        S U l
        X@l        XPl        Xl        Xpl         U=(       d    0 nU V	s0 s H  n	[        U	5      Xi   _M     sn	U l        U R                  (       a|  U R                  c  U R                  ba  U R                  (       a  U R                  OU R                  S-
  n
[%        U R                  5      nX:  a  [!        SR'                  X5      5      eg g g s  sn	f ! [         ["        4 a    [#        SU 35      ef = f)NzAArgument `axes` must be a dict with integer keys. Received: axes=   z5Axis {} is greater than the maximum allowed value: {})tfas_dtypenamedtypeTensorShaperanktupleas_listlenndimshapemax_ndimmin_ndimallow_last_axis_squeezeintaxes
ValueError	TypeErrormaxformat)selfr   r   r   r   r   r   r   r   kmax_dimmax_axiss               X/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/engine/input_spec.py__init__InputSpec.__init__K   sY    160AR[[',,t
u%::E%--/*EE
DIJIDJ  	'>$	:2D267$QQ$7DI 99$))/4==3L$(IItyy4==AEG499~H! ((.x(A  " 4M9 8I& 	""&) 	s   *E, 9E'E, 'E, ,Fc           	      6   U R                   (       a  S[        U R                   5      -   OSU R                  (       a  S[        U R                  5      -   OSU R                  (       a  S[        U R                  5      -   OSU R                  (       a  S[        U R                  5      -   OSU R
                  (       a  S[        U R
                  5      -   OSU R                  (       a  S[        U R                  5      -   OS/nSS	R                  S
 U 5       5       S3$ )Nzdtype= zshape=zndim=z	max_ndim=z	min_ndim=zaxes=z
InputSpec(z, c              3   6   #    U  H  o(       d  M  Uv   M     g 7fN ).0xs     r$   	<genexpr>%InputSpec.__repr__.<locals>.<genexpr>   s     %;Aaas   
	))r   strr   r   r   r   r   join)r    specs     r$   __repr__InputSpec.__repr__x   s    ,0JJXDJJ'B,0JJXDJJ'B*.))Ws499~%26--[3t}}--R26--[3t}}--R*.))Ws499~%
 DII%;%;;<A>>    c                     U R                   U R                  U R                  U R                  U R                  U R
                  S.$ )Nr   r   r   r   r   r   r8   )r    s    r$   
get_configInputSpec.get_config   s6    ZZZZIIII
 	
r6   c                     U " S0 UD6$ )Nr+   r+   )clsconfigs     r$   from_configInputSpec.from_config   s    }V}r6   )r   r   r   r   r   r   r   r   )NNNNNNFN)__name__
__module____qualname____firstlineno____doc__r%   r4   r9   classmethodr>   __static_attributes__r+   r6   r$   r   r      sF    'V  %+Z	?
  r6   r   c                 P   U R                   c#  U R                  c  [        R                  " S5      $ U R                  b   [        R                  " U R                  5      $ S/U R                   -  nU R                   H  nU R                  U   X'   M     [        R                  " U5      $ )a$  Returns a tf.TensorShape object that matches the shape specifications.

If the InputSpec's shape or ndim is defined, this method will return a fully
or partially-known shape. Otherwise, the returned TensorShape is None.

Args:
  spec: an InputSpec object.

Returns:
  a tf.TensorShape object
N)r   r   r   r   r   )r3   r   as      r$   to_tensor_shaperI      s     yyTZZ/~~d##		~~djj))"Ayy|EH ~~e$$r6   c                 	   U (       d  g[         R                  R                  U 5      n [        U[        5      (       a{  U  Vs/ s H  o3R
                  PM     nn[        U5      (       aP  / nU HF  nXa;  a+  [        SU S[        UR                  5       5       SU 35      eUR                  X   5        MH     Un[         R                  R                  U5      nU H2  n[        US5      (       a  M  [        SU S[        U5       SU S	35      e   [        U5      [        U 5      :w  a)  [        S
U S[        U 5       S[        U5       SU 35      e[        [!        X5      5       GH  u  nu  psUc  M  [         R"                  " UR$                  5      n	U	R&                  c    gUR(                  bY  UR*                  (       dH  U	R&                  n
XR(                  :w  a-  [        SU SU SUR(                   SU
 S[-        U	5       3
5      eUR.                  bI  UR$                  R&                  n
U
b0  XR.                  :  a!  [        SU SU SUR.                   SU
 35      eUR0                  bU  UR$                  R&                  n
U
b<  XR0                  :  a-  [        SU SU SUR0                   SU
 S[-        U	5       3
5      eUR2                  bO  UR2                  R
                  UR2                  :w  a+  [        SU SU SUR2                   SUR2                   35      eU	R5                  5       nUR6                  (       a  UR6                  R9                  5        Hh  u  p[        US5      (       a  UR:                  nUc  M'  U[=        U5         US1;  d  M=  [        SU SU SU SU S[?        UR$                  5       3
5      e   UR$                  c  GMn  U	R&                  c  GM~  UR$                  nUR*                  (       a*  U(       a  US   S:X  a  USS nU(       a  US   S:X  a  USS n[!        X5       HJ  u  nnUc  M  Uc  M  UU:w  d  M  [        SU SU SUR$                   S[?        UR$                  5       35      e   GM!     gs  snf )aq  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.
NzMissing data for input "z*". You passed a data dictionary with keys z. Expected the following keys: 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=valuez0" 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   nestflatten
isinstancedictr   allr   listkeysappendhasattrr   typer   	enumeratezipr   r   r   r   r   r   r   r   r   r   r   itemsrK   r   display_shape)
input_specinputs
layer_namer3   nameslist_inputsr   r-   input_indexr   r   shape_as_listaxisrK   
spec_shapespec_dimdims                    r$   assert_input_compatibilityrf      s   " ,J&$'12ztz2u::K%$24& 9B./ 088=w@  ""6<0  !FWW__V$F
 q'""<QC @ G9$::,bJ   6{c*o%j\C
O+< =  #F} -  &x)
 	

 #,C,C"DYa<qww'::99 )E)E::Dyy  [MZL A%%)YYK}TF C,,1%L>;  ==$77<<DD==$8 [MZL A))- 8""&)  ==$77<<DD==$8 [MZL A))- 8""& (,,1%L>	;  ::!ww||tzz) [MZL A&&*jj\ 2##$77)-  99#yy05'**!KKE$s4y)AJ * % [ EFFJV L88=w ?!!.qww!7 8	:   1 ::!ejj&<J++ ]2%6!%;$1#2$6M*R.A"5!+CRJ!$Z!?#'CO3($[MZL I..2jj\ :++8+A*BD  "@O #EA 3s   Rc                 F    [        [        U R                  5       5      5      $ r*   )r1   r   r   )r   s    r$   rZ   rZ   2  s    uU]]_%&&r6   c                     U=(       d    [         R                  " 5       n[        U [        5      (       a5  U R                  =(       d    Un[
        R                  " [        U 5      U5      $ [
        R                  " SU5      $ )z5Converts a TF-Keras InputSpec object to a TensorSpec.N)r   floatxrO   r   r   r   
TensorSpecrI   )r[   default_dtyper   s      r$   to_tensor_specrl   6  sW    !5W^^%5M*i((  1M}}_Z8%@@==}--r6   r*   )rD   tensorflow.compat.v2compatv2r   tf_keras.srcr    tensorflow.python.util.tf_exportr   r   r   rI   rf   rZ   rl   r+   r6   r$   <module>rr      sr   " $ ! !   : 6  "NO !"#n n $	
nb%.FR'.r6   