
    ij                         d dl Z 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	 d dl
mZ  ed       G d	 d
e             Zy)    N)backend)ops)keras_export)KerasTensor)	InputSpec)Layerzkeras.layers.Flattenc                   @     e Zd ZdZd fd	Zd Zd Zd Z fdZ xZ	S )Flattenaj  Flattens the input. Does not affect the batch size.

    Note: If inputs are shaped `(batch,)` without a feature axis, then
    flattening adds an extra channel dimension and output shape is `(batch, 1)`.

    Args:
        data_format: A string, one of `"channels_last"` (default) or
            `"channels_first"`. The ordering of the dimensions in the inputs.
            `"channels_last"` corresponds to inputs with shape
            `(batch, ..., channels)` while `"channels_first"` corresponds to
            inputs with shape `(batch, channels, ...)`.
            When unspecified, uses `image_data_format` value found in your Keras
            config file at `~/.keras/keras.json` (if exists). Defaults to
            `"channels_last"`.

    Example:

    >>> x = keras.Input(shape=(10, 64))
    >>> y = keras.layers.Flatten()(x)
    >>> y.shape
    (None, 640)
    c                     t        |   di | t        j                  |      | _        t        d      | _        | j                  dk(  | _        y )N   )min_ndimchannels_first )super__init__r   standardize_data_formatdata_formatr   
input_spec_channels_first)selfr   kwargs	__class__s      w/var/www/html/emotional.easysim.app/public_html/venv/lib/python3.12/site-packages/keras/src/layers/reshaping/flatten.pyr   zFlatten.__init__$   sF    "6""::;G#Q/#//3CC    c                 h   t        j                  |      }t        |      }| j                  r,|dkD  r't        j                  |dgt        d|      d      }|dd  }t        |      dk(  rd}n*t        d |D              rd}nt        j                  |      }t        j                  ||d   |f      S )Nr   r      )axesc              3   >   K   | ]  }t        |t                 y wN)
isinstanceint.0ds     r   	<genexpr>zFlatten.call.<locals>.<genexpr>5   s     @AZ3''@s   )
r   shapelenr   	transposerangeanymathprodreshape)r   inputsinput_shaperanknon_batch_dimsflattened_dims         r   callzFlatten.call*   s    ii';D1H]]60GU1d^0GQ0GHF$QR~!#M@@@M IIn5M{{6KNM#BCCr   c                     |dd  }t        |      dk(  rd}n*t        d |D              rd }nt        j                  |      }|d   |fS )Nr   r   c              3   $   K   | ]  }|d u  
 y wr   r   r"   s     r   r%   z/Flatten.compute_output_shape.<locals>.<genexpr>@   s     3qd3s   )r(   r+   r,   r-   )r   r0   r2   r3   s       r   compute_output_shapezFlatten.compute_output_shape<   sQ    $QR~!#M3N33 !M IIn5MA..r   c                 |    | j                  |j                        }t        ||j                  |j                        S )N)r'   dtypesparse)r7   r'   r   r9   r:   )r   r/   output_shapes      r   compute_output_speczFlatten.compute_output_specK   s2    00>fll6==
 	
r   c                 H    d| j                   i}t        | 	         }i ||S )Nr   )r   r   
get_config)r   configbase_configr   s      r   r>   zFlatten.get_configQ   s0    !1!12g(*(+(((r   r   )
__name__
__module____qualname____doc__r   r4   r7   r<   r>   __classcell__)r   s   @r   r
   r
      s(    .DD$/
) )r   r
   )r,   	keras.srcr   r   keras.src.api_exportr   %keras.src.backend.common.keras_tensorr   keras.src.layers.input_specr   keras.src.layers.layerr   r
   r   r   r   <module>rK      s>       - = 1 ( $%H)e H) &H)r   