
    ёi(                    *   S SK Jr  S SKrS SKrSSKJrJr  SSKJ	r	  SSK
Jr  SSKJr  SS	KJrJr  SS
KJrJr  SSKJr  SSKJr  SSKJrJr  SS jr   S         SS jjr   S         SS jjr   S         S S jjr   S         S S jjr  S!       S"S jjr   S!       S#S jjr!    S$           S%S jjr"      S&S jr#    S'S jr$    S'S jr% S(     S)S jjr&    S'S jr' S(     S*S jjr(g)+    )annotationsN   )in_dygraph_modein_pir_mode   ConstantDirac)calculate_gain)KaimingNormalKaimingUniform)NormalTruncatedNormal
OrthogonalUniform)XavierNormalXavierUniformc                6   U R                   nU(       a  [        U5      S:X  a  S=p#X#4$ [        U5      S:X  a	  US   =p#X#4$ [        U5      S:X  a  US   nUS   nX#4$ [        R                  " USS 5      n[	        US   U-  5      n[	        US   U-  5      nX#4$ )a  Compute the fan_in and the fan_out for layers

This method computes the fan_in and the fan_out
for neural network layers, if not specified. It is
not possible to perfectly estimate fan_in and fan_out.
This method will estimate it correctly for matrix multiply and
convolutions.

Args:
    var: variable for which fan_in and fan_out have to be computed.

Returns:
    tuple of two integers (fan_in, fan_out).
r   r   r   N)shapelennpprodint)varr   fan_infan_outreceptive_field_sizes        N/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/nn/init.py_calculate_fan_in_and_fan_outr"       s     IIECJ!O  
Uq 8#  
Uqq(   "wwuQRy1U1X 445eAh!556    c                &    [        XUS9nU" U 5      $ )a_  Modify tensor inplace using Kaiming uniform method.

Args:
    tensor (Tensor):  Paddle Tensor.
    a (float, optional): The negative slope of the rectifier used after this layer.
        Defaults to 0.
    mode (str, optional): Mode to compute the fan. Choose from ["fan_in", "fan_out"].
        When set to 'fan_in', the fan_in parameter is used for initialization.
        When set to 'fan_out', the out_features of trainable Tensor will be used.
        Default is 'fan_in'.
    nonlinearity (str, optional): Nonlinearity method name. Defaults to "leaky_relu".

Returns:
    Tensor: Initialized tensor.
negative_slopenonlinearitymode)r   tensorar(   r'   inits        r!   kaiming_uniform_r-   C   s    * $D <r#   c                &    [        XUS9nU" U 5      $ )a^  Modify tensor inplace using Kaiming normal method.

Args:
    tensor (Tensor):  Paddle Tensor.
    a (float, optional): The negative slope of the rectifier used after this layer.
        Defaults to 0.
    mode (str, optional): Mode to compute the fan. Choose from ["fan_in", "fan_out"].
        When set to 'fan_in', the fan_in parameter is used for initialization.
        When set to 'fan_out', the out_features of trainable Tensor will be used.
        Default is 'fan_in'.
    nonlinearity (str, optional): Nonlinearity method name. Defaults to "leaky_relu".

Returns:
    Tensor: Initialized tensor.
r%   )r   r)   s        r!   kaiming_normal_r/   _   s    * 4PD<r#   c                (    [        UUUS9nU" U 5      $ )a  Modify tensor inplace using Xavier uniform method.

Args:
    tensor (Tensor):  Paddle Tensor.
    gain (float, optional): Scaling Tensor. Default is 1.0.
    fan_in (float|None, optional): fan_in for Xavier initialization, which is
            inferred from the Tensor. Default is None.
    fan_out (float|None, optional): fan_out for Xavier initialization, which is
             inferred from the Tensor. Default is None.

Returns:
    Tensor: Initialized tensor.
gainr   r   )r   r*   r2   r   r   r,   s        r!   xavier_uniform_r4   y   s#    & D <r#   c                (    [        UUUS9nU" U 5      $ )a  Modify tensor inplace using Xavier normal method.

Args:
    tensor (Tensor):  Paddle Tensor.
    gain (float, optional): Scaling Tensor. Default is 1.0.
    fan_in (float|None, optional): fan_in for Xavier initialization, which is
            inferred from the Tensor. Default is None.
    fan_out (float|None, optional): fan_out for Xavier initialization, which is
             inferred from the Tensor. Default is None.

Returns:
    Tensor: Initialized tensor.
r1   )r   r3   s        r!   xavier_normal_r6      s#    & D <r#   c                $    [        XS9nU" U 5      $ )aB  Modify tensor inplace using uniform method.

Args:
    tensor (Tensor):  Paddle Tensor.
    low (float, optional): Lower boundary of the uniform distribution. Default is :math:`-1.0`.
    high (float, optional): Upper boundary of the uniform distribution. Default is :math:`1.0`.

Returns:
    Tensor: Initialized tensor.
)lowhighr   )r*   r+   br,   s       r!   uniform_r;      s     q!D<r#   c                $    [        XS9nU" U 5      $ )a0  Modify tensor inplace using normal method.

Args:
    tensor (Tensor):  Paddle Tensor.
    mean (float|complex, optional): mean of the normal distribution. Default is 0.0.
    std (float, optional): standard deviation of the normal distribution. Default is 1.0.

Returns:
    Tensor: Initialized tensor.
)meanstd)r   )r*   r=   r>   r,   s       r!   normal_r?      s     t%D<r#   c                &    [        XX4S9nU" U 5      $ )a  Modify tensor inplace using truncated normal method.

Args:
    tensor (Tensor):  Paddle Tensor.
    mean (float|complex, optional): mean of the normal distribution. Default is 0.0.
    std (float, optional): standard deviation of the normal distribution. Default is 1.0.
    a (float, optional): The minimum cutoff value. Default is -2.0.
    b (float, optional): The maximum cutoff value. Default is 2.0.

Returns:
    Tensor: Initialized tensor.
)r=   r>   r+   r:   )r   )r*   r=   r>   r+   r:   r,   s         r!   trunc_normal_rA      s    & 8D<r#   c                $    [        US9nU" U 5      $ )zModify tensor inplace using constant method.

Args:
    tensor (Tensor):  Paddle Tensor.
    value (float32|float64, optional): constant value to initialize the parameter.

Returns:
    Tensor: Initialized tensor.
valuer   )r*   valr,   s      r!   	constant_rF      s     #D<r#   c                $    [        SS9nU" U 5      $ )zFill the input Tensor with the scalar value 1.

Args:
    tensor (Tensor):  Paddle Tensor.

Returns:
    Tensor: Initialized tensor.
      ?rC   r   r*   r,   s     r!   ones_rJ          #D<r#   c                $    [        SS9nU" U 5      $ )zFill the input Tensor with the scalar value 0.

Args:
    tensor (Tensor):  Paddle Tensor.

Returns:
    Tensor: Initialized tensor.
        rC   r   rI   s     r!   zeros_rN     rK   r#   c                $    [        US9nU" U 5      $ )a  Initialize the 3D/4D/5D Tensor with Dirac delta function.

Args:
    tensor (Tensor):  Paddle Tensor.
    groups (int|None, optional): 0-dimension of the Tensor will be divided by groups,
        each group has the same value. Default: 1.
Returns:
    Tensor: Initialized tensor.
)groupsr
   )r*   rP   r,   s      r!   dirac_rQ   #  s     D<r#   c                   [        U R                  5      S:w  a"  [        S[        U R                  5       S35      e[        5       (       aL  [        R
                  " U R                  S   U R                  S   U R                  S9nUR                  U 5        g[        5       (       a<  [        R
                  " U R                  S   U R                  S   U R                  S9nU$ [        S5      e)	zFill the 2-dimensional input Tensor with the identity matrix.

Args:
    tensor (Tensor):  Paddle Tensor.
Returns:
    Tensor: Initialized tensor.
r   z+Only support 2 dimensional tensor, but got .r   r   )dtypeNz-Only support run in dygraph mode or PIR mode.)
r   r   AssertionErrorr   paddleeyerT   _share_underline_tensor_tor   NotImplementedError)r*   
new_tensors     r!   eye_r[   5  s     6<<A9#fll:K9LAN
 	
 ZZLLOV\\!_FLL

 	--f5	ZZLLOV\\!_FLL

 !;
 	
r#   c                $    [        US9nU" U 5      $ )zFill the input Tensor with a (semi) orthogonal matrix.

Args:
    tensor (Tensor):  Paddle Tensor.
    gain(float, optional): The multiplication coefficient for initialized tensor. Default: 1.0.
Returns:
    Tensor: Initialized tensor.
)r2   r   )r*   r2   r,   s      r!   orthogonal_r]   V  s     4 D<r#   )r   paddle.Tensorreturnztuple[int, int])r   r   
leaky_relu)
r*   r^   r+   floatr(   strr'   rb   r_   paddle.Tensor | None)rH   NN)
r*   r^   r2   ra   r   float | Noner   rd   r_   rc   )rM   rH   )r*   r^   r+   ra   r:   ra   r_   rc   )r*   r^   r=   ra   r>   ra   r_   rc   )rM   rH   g       g       @)r*   r^   r=   ra   r>   ra   r+   ra   r:   ra   r_   rc   )r*   r^   rE   ra   r_   rc   )r*   r^   r_   rc   )r   )r*   r^   rP   r   r_   rc   )r*   r^   r2   ra   r_   rc   ))
__future__r   numpyr   rV   base.frameworkr   r   initializer.constantr	   initializer.diracr   initializer.initializerr   initializer.kaimingr   r   initializer.normalr   r   initializer.orthogonalr   initializer.uniformr   initializer.xavierr   r   r"   r-   r/   r4   r6   r;   r?   rA   rF   rJ   rN   rQ   r[   r]    r#   r!   <module>rq      s}   #   9 * $ 3 > 7 . ( ; J $	  	
 < $	  	
 8  	
  	
 <  	
  	
 <   	, 
 
 	, 
 
 	
  0	 $ $  $


F 
 r#   