
    2Vh*                     l    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e	             Z
y	)
    )ops)keras_export)KerasTensor)	InputSpec)Layerzkeras.layers.Permutec                   >     e Zd ZdZ fdZd Zd Zd Z fdZ xZ	S )Permutea  Permutes the dimensions of the input according to a given pattern.

    Useful e.g. connecting RNNs and convnets.

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

    Input shape:
        Arbitrary.

    Output shape:
        Same as the input shape, but with the dimensions re-ordered according
        to the specified pattern.

    Example:

    >>> x = keras.Input(shape=(10, 64))
    >>> y = keras.layers.Permute((2, 1))(x)
    >>> y.shape
    (None, 64, 10)
    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      R/home/dcms/DCMS/lib/python3.12/site-packages/keras/src/layers/reshaping/permute.pyr   zPermute.__init__#   su    "6"$K	$<4aTQ 788))-0 
 $TYY!);<    c                 n    |d   g}| j                   D ]  }|j                  ||           t        |      S )Nr   )r   appendr   )r   input_shapeoutput_shapedims       r   compute_output_shapezPermute.compute_output_shape.   s?    #A'99 	2CC 01	2\""r   c                 |    | j                  |j                        }t        ||j                  |j                        S )N)shapedtypesparse)r"   r$   r   r%   r&   )r   inputsr    s      r   compute_output_speczPermute.compute_output_spec4   s2    00>fll6==
 	
r   c                 J    t        j                  |d| j                  z         S )N)r   )axes)r   	transposer   )r   r'   s     r   callzPermute.call:   s    }}V$*:;;r   c                 H    d| j                   i}t        | 	         }i ||S )Nr   )r   r   
get_config)r   configbase_configr   s      r   r.   zPermute.get_config=   s.    $))$g(*(+(((r   )
__name__
__module____qualname____doc__r   r"   r(   r,   r.   __classcell__)r   s   @r   r	   r	      s&    2	=#
<) )r   r	   N)	keras.srcr   keras.src.api_exportr   %keras.src.backend.common.keras_tensorr   keras.src.layers.input_specr   keras.src.layers.layerr   r	   r   r   r   <module>r;      s5     - = 1 ( $%7)e 7) &7)r   