o
    biZ
                     @   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                       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 )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). One element of the `target_shape`
            can be -1 in which case the missing value is inferred from the
            size of the array and remaining dimensions.

    Input shape:
        Arbitrary, but required to be compatible with `target_shape`.

    Output shape:
        `(batch_size, *target_shape)`

    Example:

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

    >>> # another example with shape inference using `-1` as dimension
    >>> y = keras.layers.Reshape((-1, 2, 2))(x)
    >>> y.shape
    (None, 3, 2, 2)
    c                    sF   t  jdi | t|}|ddkrtd| || _d| _d S )N   z^The `target_shape` argument must not contain more than one `-1` value. Received: target_shape=T )super__init__tuplecount
ValueErrortarget_shapebuilt)selfr   kwargs	__class__r
   V/home/ubuntu/.local/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   )r   compute_reshape_output_shaper   )r   input_shaper
   r
   r   compute_output_shape1   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_spec9   s   
zReshape.compute_output_specc                 C   sL   t t|jdd  | jd}tdd |D }t|t|d f| S )Nr	   r   c                 s   s     | ]}|d u r
dn|V  qd S )Nr   r
   ).0dr
   r
   r   	<genexpr>E   s    
zReshape.call.<locals>.<genexpr>r   )r   r   r   r   r   r   reshape)r   r   !potentially_resolved_target_shaper
   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&   L   s   

zReshape.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.layerr   keras.src.opsr   r   r
   r
   r
   r   <module>   s    