
    ~Wh!                         d Z ddlmc 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	e                      Z ed
          dd            ZdS )z'Layer that concatenates several inputs.    N)backend)_Merge)tf_utils)keras_exportzkeras.layers.Concatenatec                   |     e Zd ZdZd
 fd	Zej        d             Zd Zej        d             Z	ddZ
 fd	Z xZS )Concatenatea  Layer that concatenates a list of inputs.

    It takes as input a list of tensors, all of the same shape except
    for the concatenation axis, and returns a single tensor that is the
    concatenation of all inputs.

    >>> x = np.arange(20).reshape(2, 2, 5)
    >>> print(x)
    [[[ 0  1  2  3  4]
      [ 5  6  7  8  9]]
     [[10 11 12 13 14]
      [15 16 17 18 19]]]
    >>> y = np.arange(20, 30).reshape(2, 1, 5)
    >>> print(y)
    [[[20 21 22 23 24]]
     [[25 26 27 28 29]]]
    >>> tf.keras.layers.Concatenate(axis=1)([x, y])
    <tf.Tensor: shape=(2, 3, 5), dtype=int64, numpy=
    array([[[ 0,  1,  2,  3,  4],
            [ 5,  6,  7,  8,  9],
            [20, 21, 22, 23, 24]],
           [[10, 11, 12, 13, 14],
            [15, 16, 17, 18, 19],
            [25, 26, 27, 28, 29]]])>

    >>> x1 = tf.keras.layers.Dense(8)(np.arange(10).reshape(5, 2))
    >>> x2 = tf.keras.layers.Dense(8)(np.arange(10, 20).reshape(5, 2))
    >>> concatted = tf.keras.layers.Concatenate()([x1, x2])
    >>> concatted.shape
    TensorShape([5, 16])

    c                 d     t                      j        di | || _        d| _        d| _        dS )a.  Instantiates a Concatenate layer.

        >>> x = np.arange(20).reshape(2, 2, 5)
        >>> print(x)
        [[[ 0  1  2  3  4]
          [ 5  6  7  8  9]]
         [[10 11 12 13 14]
          [15 16 17 18 19]]]
        >>> y = np.arange(20, 30).reshape(2, 1, 5)
        >>> print(y)
        [[[20 21 22 23 24]]
         [[25 26 27 28 29]]]
        >>> tf.keras.layers.Concatenate(axis=1)([x, y])
        <tf.Tensor: shape=(2, 3, 5), dtype=int64, numpy=
        array([[[ 0,  1,  2,  3,  4],
                [ 5,  6,  7,  8,  9],
                [20, 21, 22, 23, 24]],
               [[10, 11, 12, 13, 14],
                [15, 16, 17, 18, 19],
                [25, 26, 27, 28, 29]]])>

        Args:
          axis: Axis along which to concatenate.
          **kwargs: standard layer keyword arguments.
        TFN )super__init__axissupports_masking_reshape_required)selfr   kwargs	__class__s      f/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/keras/layers/merging/concatenate.pyr   zConcatenate.__init__?   s?    4 	""6"""	 $!&    c                   	 t          |          dk     st          |d         t                    st          d|           t	          d |D                       rd S d |D             }t                      }t          t          |                    D ]8}||         | j        = |                    t          ||                              9t          |          dk    rd| }t          d |D                       }t          |          dk    rt          |          |\  }t          |          D ]A	t          	fd|D                       }t          |          dk    rt          |          @d S d S )	N   r   z\A `Concatenate` layer should be called on a list of at least 1 input. Received: input_shape=c              3      K   | ]}|d u V  	d S Nr   .0shapes     r   	<genexpr>z$Concatenate.build.<locals>.<genexpr>f   s&      66u}666666r   c                 ,    g | ]}t          |          S r   )listr   s     r   
<listcomp>z%Concatenate.build.<locals>.<listcomp>h   s     F F Fe F F Fr   ztA `Concatenate` layer requires inputs with matching shapes except for the concatenation axis. Received: input_shape=c              3   4   K   | ]}t          |          V  d S r   )lenr   s     r   r   z$Concatenate.build.<locals>.<genexpr>u   s(      ::uE

::::::r   c              3   8   K   | ]}|         
|         V  d S r   r   )r   r   r   s     r   r   z$Concatenate.build.<locals>.<genexpr>}   s=       " "T{. $K...." "r   )	r"   
isinstancetuple
ValueErrorallsetranger   add)
r   input_shapereduced_inputs_shapes	shape_setierr_msgranksrankunique_dimsr   s
            @r   buildzConcatenate.build^   s    {az+a.%'H'HI;FI I   66+66666 	F F F+ F F FEE	s01122 	; 	;A%a(3MM% 5a 899::::y>>Q7)47 7  ::	:::::E5zzQ )))GTd 	. 	. " " " " "!*" " "  
 {##a''$W--- () 	. 	.r   c                 8    t          j        || j                  S )Nr   )r   concatenater   )r   inputss     r   _merge_functionzConcatenate._merge_function   s    "6	::::r   c                    t          |t          t          f          r"t          |d         t          t          f          st          d|           |}t          |d                   }|dd          D ]H}|| j                 || j                 d || j        <    n!|| j        xx         || j                 z  cc<   It          |          S )Nr   zRA `Concatenate` layer should be called on a list of inputs. Received: input_shape=r   )r$   r%   r   r&   r   )r   r+   input_shapesoutput_shaper   s        r   compute_output_shapez Concatenate.compute_output_shape   s    ;66 
	;q>E4=99
	 7)47 7   #LO,,!!""% 	8 	8EDI&.%	2B2J*.TY'###uTY'77####\"""r   Nc                 `   |d S t          |t          t          f          st          d|           t          |t          t          f          st          d|           t	          |          t	          |          k    r5t          d| dt	          |           d| dt	          |                     t          d |D                       rd S g }t          ||          D ]\  }}|*|                    t          j	        |d                     1t          j        |          t          j        |          k     r*|                    t          j        |d	
                     |                    |           t          j        || j        
          }t          j        |d	d          S )Nz'`mask` should be a list. Received mask=z,`inputs` should be a list. Received: inputs=zLThe lists `inputs` and `mask` should have the same length. Received: inputs=z of length z, and mask=c              3      K   | ]}|d u V  	d S r   r   )r   ms     r   r   z+Concatenate.compute_mask.<locals>.<genexpr>   s&      ''QqDy''''''r   bool)dtyper	   r5   F)r   keepdims)r$   r%   r   r&   r"   r'   zipappendtf	ones_liker   ndimexpand_dimsr6   r   )r   r7   maskmasksinput_imask_iconcatenateds          r   compute_maskzConcatenate.compute_mask   s   <4$.. 	OMtMMNNN&5$-00 	GvGG   t99F##5$*5 57:6{{5 55 5),T5 5  
 ''$''''' 	4 "6400 	% 	%OGV~R\'@@@AAAAf%%W(=(===R^F<<<====V$$$$*5tyAAA{<b5AAAAr   c                     d| j         i}t                                                      }t          t	          |                                          t	          |                                          z             S )Nr   )r   r   
get_configdictr   items)r   configbase_configr   s      r   rP   zConcatenate.get_config   s_    DI
 gg((**D**,,--V\\^^0D0DDEEEr   r	   r   )__name__
__module____qualname____doc__r   r   shape_type_conversionr3   r8   r<   rN   rP   __classcell__)r   s   @r   r   r      s         B' ' ' ' ' '> #$. $. $#$.L; ; ; ## # $##*B B B BBF F F F F F F F Fr   r   zkeras.layers.concatenater	   c                 0     t          dd|i||           S )av  Functional interface to the `Concatenate` layer.

    >>> x = np.arange(20).reshape(2, 2, 5)
    >>> print(x)
    [[[ 0  1  2  3  4]
      [ 5  6  7  8  9]]
     [[10 11 12 13 14]
      [15 16 17 18 19]]]
    >>> y = np.arange(20, 30).reshape(2, 1, 5)
    >>> print(y)
    [[[20 21 22 23 24]]
     [[25 26 27 28 29]]]
    >>> tf.keras.layers.concatenate([x, y],
    ...                             axis=1)
    <tf.Tensor: shape=(2, 3, 5), dtype=int64, numpy=
    array([[[ 0,  1,  2,  3,  4],
          [ 5,  6,  7,  8,  9],
          [20, 21, 22, 23, 24]],
         [[10, 11, 12, 13, 14],
          [15, 16, 17, 18, 19],
          [25, 26, 27, 28, 29]]])>

    Args:
        inputs: A list of input tensors.
        axis: Concatenation axis.
        **kwargs: Standard layer keyword arguments.

    Returns:
        A tensor, the concatenation of the inputs alongside axis `axis`.
    r   r   )r   )r7   r   r   s      r   r6   r6      s(    @ ,;++D+F++F333r   rU   )rY   tensorflow.compat.v2compatv2rE   kerasr   keras.layers.merging.base_merger   keras.utilsr    tensorflow.python.util.tf_exportr   r   r6   r   r   r   <module>rd      s    . - " ! ! ! ! ! ! ! !       2 2 2 2 2 2             : 9 9 9 9 9 ())gF gF gF gF gF& gF gF *)gFT ())4 4 4 *)4 4 4r   