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)Layer)operation_utilszkeras.layers.Reshapec                       sL   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Z fddZ	  Z
S )Reshapea"  Layer that reshapes inputs into the given shape.

    Args:
        target_shape: Target shape. Tuple of integers, does not include the
            samples dimension (batch size).

    Input shape:
        Arbitrary, although all dimensions in the input shape must be
        known/fixed. Use the keyword argument `input_shape` (tuple of integers,
        does not include the samples/batch size axis) when using this layer as
        the first layer in a model.

    Output shape:
        `(batch_size, *target_shape)`

    Example:

    >>> x = keras.Input(shape=(12,))
    >>> y = keras.layers.Reshape((3, 4))(x)
    >>> y.shape
    (None, 3, 4)

    >>> # also supports shape inference using `-1` as dimension
    >>> y = keras.layers.Reshape((-1, 2, 2))(x)
    >>> y.shape
    (None, 3, 2, 2)
    c                    s    t  jdi | t|| _d S )N )super__init__tupletarget_shape)selfr   kwargs	__class__r   ]/var/www/html/chatgem/venv/lib/python3.10/site-packages/keras/src/layers/reshaping/reshape.pyr
   &   s   zReshape.__init__c                 C   s$   |d gt |dd  | jdR S )Nr      r   )r   compute_reshape_output_shaper   )r   input_shaper   r   r   compute_output_shape*   s   zReshape.compute_output_shapec                 C   s   |  |j}t||j|jdS )N)shapedtypesparse)r   r   r   r   r   )r   inputsoutput_shaper   r   r   compute_output_spec2   s   
zReshape.compute_output_specc                 C   s0   t |dd  | jd}tdd |D | _d S )Nr   r   c                 s   s     | ]}|d u r
dn|V  qd S )Nr   ).0dr   r   r   	<genexpr><   s    
z Reshape.build.<locals>.<genexpr>)r   r   r   r   _resolved_target_shape)r   r   sample_output_shaper   r   r   build8   s   zReshape.buildc                 C   s   t |t |d f| j S )Nr   )r   reshaper   r    )r   r   r   r   r   call@   s   zReshape.callc                    s    d| j i}t  }i ||S )Nr   )r   r	   
get_config)r   configbase_configr   r   r   r%   E   s   

zReshape.get_config)__name__
__module____qualname____doc__r
   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.layerr   keras.src.opsr   r   r   r   r   r   <module>   s    