
    2Vh                         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      R/home/dcms/DCMS/lib/python3.12/site-packages/keras/src/layers/reshaping/flatten.pyr   zFlatten.__init__$   sF    "6""::;G#Q/#//3CC    c                    |j                   }t        |      }| j                  r,|dkD  r't        j                  |dgt        d|      d      }t        d | j                  |      D              }t        j                  ||      S )Nr   r      )axesc              3   (   K   | ]
  }||nd  y w)Nr   ).0dims     r   	<genexpr>zFlatten.call.<locals>.<genexpr>2   s!      
 ?C*
s   )	shapelenr   r   	transposerangetuplecompute_output_shapereshape)r   inputsinput_shaperankoutput_shapes        r   callzFlatten.call*   s|    ll;D1H]]60GU1d^0GQ0GHF 
00=
 
 {{6<00r   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Nr   )r    ds     r   r"   z/Flatten.compute_output_shape.<locals>.<genexpr><   s     3qd3s   )r$   anymathprod)r   r+   non_batch_dimsflattened_dims       r   r(   zFlatten.compute_output_shape8   sQ    $QR~!#M3N33 !M IIn5MA..r   c                 |    | j                  |j                        }t        ||j                  |j                        S )N)r#   dtypesparse)r(   r#   r   r9   r:   )r   r*   r-   s      r   compute_output_speczFlatten.compute_output_specG   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_configM   s0    !1!12g(*(+(((r   r1   )
__name__
__module____qualname____doc__r   r.   r(   r;   r=   __classcell__)r   s   @r   r
   r
      s'    .D1/
) )r   r
   )r4   	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>rJ      s>       - = 1 ( $%D)e D) &D)r   