
    0h                     r    d Z ddlZddlmc mZ ddlmZ ddlm	Z	 ddl
mZ  ed       G d de             Zy)	zContains the Permute layer.    N)Layer)	InputSpec)keras_exportzkeras.layers.Permutec                   8     e Zd ZdZ fdZd Zd Z fdZ xZS )Permuteaf  Permutes the dimensions of the input according to a given pattern.

    Useful e.g. connecting RNNs and convnets.

    Example:

    ```python
    model = Sequential()
    model.add(Permute((2, 1), input_shape=(10, 64)))
    # now: model.output_shape == (None, 64, 10)
    # note: `None` is the batch dimension
    ```

    Args:
      dims: Tuple of integers. Permutation pattern does not include the
        samples dimension. Indexing starts at 1.
        For instance, `(2, 1)` permutes the first and second dimensions
        of the input.

    Input shape:
      Arbitrary. Use the keyword argument `input_shape`
      (tuple of integers, does not include the samples axis)
      when using this layer as the first layer in a model.

    Output shape:
      Same as the input shape, but with the dimensions re-ordered according
      to the specified pattern.
    c           	         t        |   di | t        |      | _        t	        |      t        t        dt        |      dz               k7  rt        d|       t        t        | j                        dz         | _
        y )N   zInvalid permutation argument `dims` for Permute Layer. The set of indices in `dims` must be consecutive and start from 1. Received dims=)ndim )super__init__tupledimssortedlistrangelen
ValueErrorr   
input_spec)selfr   kwargs	__class__s      _/var/www/html/engine/venv/lib/python3.12/site-packages/tf_keras/src/layers/reshaping/permute.pyr   zPermute.__init__<   su    "6"$K	$<4aTQ 788))-0 
 $TYY!);<    c                     t        j                  |      j                         }t        j                  |      }t	        | j
                        D ]  \  }}||   }|||dz   <    t        j                  |      S )Nr	   )tfTensorShapeas_listcopy	enumerater   )r   input_shapeoutput_shapeidim
target_dims         r   compute_output_shapezPermute.compute_output_shapeG   sl    nn[199;yy-		* 	-FAs$S)J",LQ	- ~~l++r   c                 J    t        j                  |d| j                  z         S )N)r   )perm)r   	transposer   )r   inputss     r   callzPermute.callO   s    ||F		)9::r   c                     d| j                   i}t        | 	         }t        t	        |j                               t	        |j                               z         S )Nr   )r   r   
get_configdictr   items)r   configbase_configr   s      r   r-   zPermute.get_configR   sG    $))$g(*D**,-V\\^0DDEEr   )	__name__
__module____qualname____doc__r   r&   r+   r-   __classcell__)r   s   @r   r   r      s#    :	=,;F Fr   r   )r5   r   tensorflow.compat.v2compatv2r   tf_keras.src.engine.base_layerr   tf_keras.src.engine.input_specr    tensorflow.python.util.tf_exportr   r   r   r   r   <module>r=      sD    "  ! ! 0 4 : $%7Fe 7F &7Fr   