
    ёi8                        S SK Jr  S SKrS SKJrJr  SSKJrJrJr  SSK	J
r
  SSKJrJrJr  SS	KJr  SS
KJr  / r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)    )annotationsN)_C_opspir   )core	frameworkunique_name)check_variable_and_dtype)_current_expected_placein_dygraph_modein_pir_mode   )Initializer)lazy_init_helperc                  ^   ^  \ rS rSrSr S       SU 4S jjjr S     S	S jjrSrU =r$ )
NormalInitializer!   a-  Implements the Random Normal(Gaussian) distribution initializer

Args:
    loc (float|complex, optional): mean of the normal distribution. Default is 0.0.
    scale (float, optional): standard deviation of the normal distribution. Default is 1.0.
    seed (int, optional): random seed. Default is 0.

c                  > Uc   eUc   eUc   e[         TU ]  5         Xl        X l        X0l        [        U R                  [        5      (       a  U R                  R                  U R                  R                  :w  a9  [        SU R                  R                   SU R                  R                   35      eU R                  R                  U l        g g )NzVif mean is a complex number, its real part should equal imag part, but got real part: z != imag part: )
super__init___mean_std_dev_seed
isinstancecomplexrealimag
ValueError)selflocscaleseed	__class__s       \/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/nn/initializer/normal.pyr   NormalInitializer.__init__+   s        

djj'**zz$**//1 **.**//):/$**//IZ\  DJ +    c           
        [        U[        R                  5      (       a  UR                  5       (       a   S5       eU R	                  U5      n[        U[        R
                  [        R
                  45      (       d   e[        US/ SQS5        U R                  S:X  a  UR                  R                  U l        [        5       (       ai  [        5       n[        R                  " UR                  U R                   U R"                  U R                  UR$                  U5      nUR'                  U5        g[)        5       (       aY  [        5       n[        R                  " UR                  U R                   U R"                  U R                  UR$                  U5      nU$ UR+                  SSU0UR                  UR$                  U R                   U R"                  U R                  S.SS	9nXQl        U$ )
a$  Initialize the input tensor with Normal distribution.

Args:
    var(Tensor): Tensor that needs to be initialized.
    block(Block|None, optional): The block in which initialization ops
           should be added. Used in static graph only, default None.

Returns:
    The initialization op.
zCCurrently, normal initializer not support lazy init for dist param.Out)uint16float16float32float64	complex64
complex128gaussian_randomr   N)shapedtypemeanstdr"   Ttypeoutputsattrsstop_gradient)r   r   EagerParamBaseis_dist_check_blockBlockr   r
   r   programrandom_seedr   r   r   gaussianr0   r   r   r1   _share_underline_tensor_tor   	append_opop)r   varblockplaceout_varrB   s         r$   forwardNormalInitializer.forward=   s    sI4455#++--	QP	Q 
 !!%(%)//399!=>>>>  	
 ::?22DJ+-Eoo		



		G ..s3]]+-Eoo		



		G N& YY YY JJ== JJ # ! B FIr&   )r   r   r   )              ?r   )r    floatr!   rK   r"   intreturnNoneNrC   zpaddle.TensorrD   zpir.Block | NonerM   zpaddle.Tensor | None	__name__
__module____qualname____firstlineno____doc__r   rG   __static_attributes____classcell__r#   s   @r$   r   r   !   sf     AB))',):=)	) )& =AJ J)9J	J Jr&   r   c                  D   ^  \ rS rSrSr S       SU 4S jjjrSrU =r$ )Normal   a  The Random Normal (Gaussian) distribution initializer.

Args:
    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.
    name(str|None, optional): The default value is None. Normally there is no need for user to set this
        property. For more information, please refer to :ref:`api_guide_Name`. Default: None.

Returns:
    A parameter initialized by Random Normal (Gaussian) distribution.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> data = paddle.ones(shape=[3, 1, 2], dtype='float32')
        >>> weight_attr = paddle.framework.ParamAttr(
        ...     name="linear_weight",
        ...     initializer=paddle.nn.initializer.Normal(mean=0.0, std=2.0))
        >>> bias_attr = paddle.framework.ParamAttr(
        ...     name="linear_bias",
        ...     initializer=paddle.nn.initializer.Normal(mean=0.0, std=2.0))
        >>> # doctest: +SKIP('name has been used')
        >>> linear = paddle.nn.Linear(2, 2, weight_attr=weight_attr, bias_attr=bias_attr)
        >>> print(linear.weight)
        Parameter containing:
        Tensor(shape=[2, 2], dtype=float32, place=Place(cpu), stop_gradient=False,
        [[ 2.1973135 -2.2697184],
         [-1.9104223 -1.0541488]])
        >>> print(linear.bias)
        Parameter containing:
        Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=False,
        [ 0.7885926  -0.74719954])
        >>> res = linear(data)
        >>> print(res)
        Tensor(shape=[3, 1, 2], dtype=float32, place=Place(cpu), stop_gradient=False,
        [[[ 1.0754838 -4.071067 ]],
         [[ 1.0754838 -4.071067 ]],
         [[ 1.0754838 -4.071067 ]]])
c                J   > Uc   S5       eUc   S5       e[         TU ]  XSS9  g )Nmean should not be Nonestd should not be Noner   )r    r!   r"   r   r   )r   r2   r3   namer#   s       r$   r   Normal.__init__   s9     :!::8 88T15r&    )rI   rJ   N)r2   rK   r3   rK   ra   
str | NonerM   rN   rR   rS   rT   rU   rV   r   rW   rX   rY   s   @r$   r[   r[      s:    (V GK66&+69C6	6 6r&   r[   c                  n   ^  \ rS rSrSr     S           SU 4S jjjr S     S	S jjrSrU =r$ )
TruncatedNormalInitializer   aT  Implements the Random TruncatedNormal(Gaussian) distribution initializer

Note:
    It is better to set `a <= mean <= b`.
    If `mean < a - 2*std` or `mean > b + 2*std`, the distribution of values may be incorrect.

Args:
    loc (float, optional): Mean of the normal distribution. Default is :math:`0.0`.
    scale (float, optional): Standard deviation of the normal distribution. Default is :math:`1.0`.
    seed (int, optional): random seed. Default is 0.
    a (float, optional): The minimum cutoff value. Default is -2.0.
    b (float, optional): The maximum cutoff value. Default is 2.0.

c                   > Uc   eUc   eUc   eUc   eUc   e[         TU ]  5         Xl        X l        X0l        X@l        XPl        g rO   )r   r   r   r   r   _a_b)r   r    r!   r"   abr#   s         r$   r   #TruncatedNormalInitializer.__init__   s_        }}}}

r&   c                $
   U R                  U5      n[        5       R                  (       aN  [        R                  [
        R                  R                  R                  [        R                  R                  4nOM[        R                  [
        R                  R                  [
        R                  R                  R                  4n[        X5      (       d   e[        U[        R                  [        R                  45      (       d   eU R                  S:X  a  UR                  R                   U l        UR"                  [        R$                  R&                  R(                  [        R$                  R&                  R*                  4;   a  [        R$                  R&                  R,                  nUR/                  [0        R2                  " SR5                  SUR6                  S/5      5      UR8                  U[        R$                  R&                  R:                  SS9nOUR"                  nUn[=        5       (       a  [>        R@                  " UR8                  U RB                  U RD                  U R                  U RF                  U RH                  U[K        5       5      nUR"                  [        R$                  R&                  R(                  [        R$                  R&                  R*                  4;   a2  [>        RL                  " XQR"                  5      nURO                  U5        gURO                  U5        g[Q        5       (       a  [>        R@                  " UR8                  U RB                  U RD                  U R                  U RF                  U RH                  U[K        5       5      nUR"                  [        R$                  R&                  R(                  [        R$                  R&                  R*                  4;   a1  [>        RL                  " XQR"                  5      nURO                  U5        U$ URS                  SSU0UR8                  UU RB                  U RD                  U R                  U RF                  U RH                  S	.S
S9nUR"                  [        R$                  R&                  R(                  [        R$                  R&                  R*                  4;   a-  URS                  SSU0SU0UR"                  UR"                  S.S9  Xql*        U$ )a,  Initialize the input tensor with TruncatedNormal distribution.

Args:
    var(Tensor): Tensor that needs to be initialized.
    block(Block|None, optional): The block in which initialization ops
           should be added. Used in static graph only, default None.

Returns:
    The initialization op
r   .truncated_gaussian_randomtmpF)ra   r0   r1   r5   persistableNr(   )r0   r1   r2   r3   r"   rl   rm   Tr4   castX)in_dtype	out_dtype)r5   inputsr6   r7   )+r;   r   stater   Variablepaddler   r   ParameterMetaeagerTensorValuer   r<   r   r=   r>   r1   VarDescVarTypeFP16BF16FP32
create_varr	   generatejoinra   r0   DENSE_TENSORr   r   rq   r   r   rj   rk   r   rt   r@   r   rA   rB   )r   rC   rD   expectedrw   rF   var_tmprB   s           r$   rG   "TruncatedNormalInitializer.forward   s    !!%(##""

--

!!H ""

  

--H #((((%)//399!=>>>>::?22DJ 99--22DLL4H4H4M4MNN,,11I&& ))HH9388UKL ii\\))66! ' G 		IG66		



')	G yy$$))$$))  !++gyy92237  2237]]66		



')	G yy$$))$$))  !++gyy92237N 0( YY& JJ== JJ # ! B yy$$))$$))  >"CL'.}}399M	    FIr&   )rj   rk   r   r   r   )rI   rJ   r                 @)r    rK   r!   rK   r"   rL   rl   rK   rm   rK   rM   rN   rO   rP   rQ   rY   s   @r$   rg   rg      s    "   	
   
 * =At t)9t	t tr&   rg   c                  T   ^  \ rS rSrSr     S           SU 4S jjjrSrU =r$ )TruncatedNormaliX  a  The truncated normal distribution (Gaussian distribution) initializer.

Note:
    It is better to set `a <= mean <= b`.
    If `mean < a - 2*std` or `mean > b + 2*std`, the distribution of values may be incorrect.

Args:
    mean (float, optional): Mean of the normal distribution. Default is :math:`0.0`.
    std (float, optional): Standard deviation of the normal distribution. Default is :math:`1.0`.
    a (float, optional): The minimum cutoff value. Default is -2.0.
    b (float, optional): The maximum cutoff value. Default is 2.0.
    name (str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

Returns:
    A parameter initialized by truncated normal distribution (Gaussian distribution).

Examples:
    .. code-block:: python

        >>> import paddle

        >>> data = paddle.ones(shape=[3, 1, 2], dtype='float32')
        >>> weight_attr = paddle.framework.ParamAttr(
        ...     name="linear_weight",
        ...     initializer=paddle.nn.initializer.TruncatedNormal(mean=0.0, std=2.0))
        >>> bias_attr = paddle.framework.ParamAttr(
        ...     name="linear_bias",
        ...     initializer=paddle.nn.initializer.TruncatedNormal(mean=0.0, std=2.0))
        >>> # doctest: +SKIP('name has been used')
        >>> linear = paddle.nn.Linear(2, 2, weight_attr=weight_attr, bias_attr=bias_attr)
        >>> print(linear.weight)
        Parameter containing:
        Tensor(shape=[2, 2], dtype=float32, place=Place(cpu), stop_gradient=False,
        [[-1.0981836  1.4140984],
         [ 3.1390522 -2.8266568]])
        >>> print(linear.bias)
        Parameter containing:
        Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=False,
        [ -2.1546738  -1.6570673])
        >>> res = linear(data)
        >>> print(res)
        Tensor(shape=[3, 1, 2], dtype=float32, place=Place(cpu), stop_gradient=False,
        [[[-0.11380529 -3.0696259 ]],
         [[-0.11380529 -3.0696259 ]],
         [[-0.11380529 -3.0696259 ]]])
c                t   > Uc   S5       eUc   S5       eUc   S5       eUc   S5       e[         TU ]  XSX4S9  g )Nr^   r_   za should not be Nonezb should not be Noner   )r    r!   r"   rl   rm   r`   )r   r2   r3   rl   rm   ra   r#   s         r$   r   TruncatedNormal.__init__  s[     :!::8 88}444}}444}T1?r&   rc   )rI   rJ   r   r   N)r2   rK   r3   rK   rl   rK   rm   rK   ra   rd   rM   rN   re   rY   s   @r$   r   r   X  sf    -b @@ @ 	@
 @ @ 
@ @r&   r   )
__future__r   r{   r   r   baser   r   r	   base.data_feederr
   base.frameworkr   r   r   initializerr   	lazy_initr   __all__r   r[   rg   r   rc   r&   r$   <module>r      sk    #   0 0 8 
 % '
f fR06 06fX Xv<@0 <@r&   