o
    2h*                     @   sX   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 de	Z
d	S )
    )ops)keras_export)KerasTensor)	InputSpec)Layerzkeras.layers.Permutec                       sD   e Zd ZdZ fddZdd Zdd Zdd	 Z fd
dZ  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                    sb   t  jdi | t|| _t|ttdt|d kr$td| t	t| jd d| _
d S )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__r
   ]/var/www/html/chatgem/venv/lib/python3.10/site-packages/keras/src/layers/reshaping/permute.pyr   #   s   
zPermute.__init__c                 C   s,   |d g}| j D ]	}|||  qt|S )Nr   )r   appendr   )r   input_shapeoutput_shapedimr
   r
   r   compute_output_shape.   s   

zPermute.compute_output_shapec                 C   s   |  |j}t||j|jdS )N)shapedtypesparse)r   r   r   r    r!   )r   inputsr   r
   r
   r   compute_output_spec4   s   
zPermute.compute_output_specc                 C   s   t j|d| j dS )N)r   )axes)r   	transposer   )r   r"   r
   r
   r   call:   s   zPermute.callc                    s    d| j i}t  }i ||S )Nr   )r   r   
get_config)r   configbase_configr   r
   r   r'   =   s   

zPermute.get_config)
__name__
__module____qualname____doc__r   r   r#   r&   r'   __classcell__r
   r
   r   r   r      s    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
   r   <module>   s    