
    2Vh                     T    d dl mZ d dlmZ d dlmZ  ed       G d de             Zy)    )ops)keras_export)Layerzkeras.layers.UnitNormalizationc                   :     e Zd ZdZd fd	Zd Zd Z fdZ xZS )UnitNormalizationak  Unit normalization layer.

    Normalize a batch of inputs so that each input in the batch has a L2 norm
    equal to 1 (across the axes specified in `axis`).

    Example:

    >>> data = np.arange(6).reshape(2, 3)
    >>> normalized_data = keras.layers.UnitNormalization()(data)
    >>> np.sum(normalized_data[0, :] ** 2)
    1.0

    Args:
        axis: Integer or list/tuple. The axis or axes to normalize across.
            Typically, this is the features axis or axes. The left-out axes are
            typically the batch axis or axes. `-1` is the last dimension
            in the input. Defaults to `-1`.
    c                     t        |   di | t        |t        t        f      rt        |      | _        n&t        |t              r|| _        nt        d|       d| _        | j                          y )Nz[Invalid value for `axis` argument: expected an int or a list/tuple of ints. Received: axis=T )
super__init__
isinstancelisttupleaxisint	TypeErrorsupports_masking_build_at_init)selfr   kwargs	__class__s      a/home/dcms/DCMS/lib/python3.12/site-packages/keras/src/layers/normalization/unit_normalization.pyr   zUnitNormalization.__init__   so    "6"dT5M*T
DIc"DI""&) 
 !%    c                 H    t        j                  || j                  dd      S )N   g-q=)r   orderepsilon)r   	normalizer   )r   inputss     r   callzUnitNormalization.call+   s    }}V$))1eLLr   c                     t        | j                  t              r| j                  g}n| j                  }|D ];  }|t        |      k\  s|t        |       k  s!t	        d| j                   d| d       |S )NzAxis z" is out of bounds for input shape .)r   r   r   len
ValueError)r   input_shapeaxesr   s       r   compute_output_shapez&UnitNormalization.compute_output_shape.   s    dii%II;D99D 	Ds;''43{3C2C+C DII; '##.-q2 	 r   c                 ^    t         |          }|j                  d| j                  i       |S )Nr   )r
   
get_configupdater   )r   configr   s     r   r(   zUnitNormalization.get_config=   s*    #%vtyy)*r   ))	__name__
__module____qualname____doc__r   r   r&   r(   __classcell__)r   s   @r   r   r      s"    & M r   r   N)	keras.srcr   keras.src.api_exportr   keras.src.layers.layerr   r   r	   r   r   <module>r4      s/     - ( ./9 9 09r   