
    ёi!                        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  / 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   )Initializerc                  t   ^  \ 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$ )
UniformInitializer    a  Implements the random uniform distribution initializer

Args:
    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`.
    seed (int, optional): Random seed. Default is 0.
    diag_num (int, optional): the number of diagonal elements to initialize.
        If set to 0, diagonal initialization will be not performed. Default is 0.
    diag_step (int, optional): Step size between two diagonal elements,
        which is generally the width of the square matrix. Default is 0.
    diag_val (float, optional): the value of the diagonal element to be initialized,
        default 1.0. It takes effect only if the diag_num is greater than 0. Default is :math:`1.0`.

c                   > Uc   eUc   eX!:  d   eUc   eUc   eUc   eUc   eUS:  d  US:  a  US:  a  US:  d   e[         TU ]  5         Xl        X l        X0l        X@l        XPl        X`l        g )Nr   )super__init___low_high_seed	_diag_num
_diag_step	_diag_val)selflowhighseeddiag_num	diag_stepdiag_val	__class__s          ]/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/nn/initializer/uniform.pyr   UniformInitializer.__init__0   s     {{###$$$###a<9q=a<IM11	

!#!    c                   [        U[        R                  5      (       a  UR                  5       (       a   S5       eU R	                  U5      n[        U[        R
                  [        R
                  45      (       d   e[        5       (       d  [        US/ SQS5        U R                  S:X  a  UR                  R                  U l	        UR                  [        R                  R                  R                   :X  a  [        R                  R                  R"                  nUR%                  [&        R(                  " SR+                  SUR,                  S/5      5      UR.                  U[        R                  R                  R0                  SS	9nOUR                  nUn[        5       (       a  [2        R4                  " UR.                  UU R6                  U R8                  U R                  UR:                  R=                  5       (       a  UR:                  O	[?        5       5      nUR                  [        R                  R                  R                   :X  a2  [2        R@                  " XAR                  5      nURC                  U5        g
URC                  U5        g
[E        5       (       Ga  UR                  [        RF                  RH                  :X  a  [        RF                  RJ                  nOUR                  n[2        R4                  " UR.                  UU R6                  U R8                  U R                  [?        5       5      nUR                  [        RF                  RH                  :X  aH  UR                  [        RF                  RH                  :w  a   [2        R@                  " XAR                  5      $ U$ URM                  S0 SU0UR.                  UU R6                  U R8                  U R                  U RN                  U RP                  U RR                  S.SS9nUR                  [        R                  R                  R                   :X  a-  URM                  SSU0SU0UR                  UR                  S.S9  Xal*        U$ )a$  Initialize the input tensor with Uniform 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
zDCurrently, uniform initializer not support lazy init for dist param.Out)uint16float16float32float64uniform_randomr   .tmpF)nameshapedtypetypepersistableN)r1   r2   minmaxr   r    r!   r"   T)r3   inputsoutputsattrsstop_gradientcastX)in_dtype	out_dtype)r3   r7   r8   r9   )+
isinstancer   EagerParamBaseis_dist_check_blockBlockr   r   r
   r   programrandom_seedr2   r   VarDescVarTypeFP16FP32
create_varr	   generatejoinr0   r1   DENSE_TENSORr   uniformr   r   place_typer   r;   _share_underline_tensor_tor   DataTypeFLOAT16FLOAT32	append_opr   r   r   op)r   varblockr>   out_varvar_tmprV   s          r$   forwardUniformInitializer.forwardJ   sU    sI4455#++--	
 S	
 

 !!%(%)//399!=>>>>  $; 	 ::?22DJ 99,,111,,11I&& ))HH.%@A ii\\))66! ' G 		IGnn				



 YY__..		4K4MG yyDLL00555 ++gyy92237  2237]]yyDMM111 MM11	II	nn				



')G 		T]]222MMT]]%:%::{{7II66N%( YY&99:: JJ $!% $	 # ! B" yyDLL00555>"CL'.}}399M	    FIr&   )r   r   r   r   r   r   )            ?r   r   r   r^   )r   floatr   r_   r   intr    r`   r!   r`   r"   r_   returnNone)N)rW   zpaddle.TensorrX   zpir.Block | Nonera   zpaddle.Tensor | None)	__name__
__module____qualname____firstlineno____doc__r   r[   __static_attributes____classcell__r#   s   @r$   r   r       s    " "" " 	"
 " " " 
" "6 =Am m)9m	m mr&   r   c                  D   ^  \ rS rSrSr S       SU 4S jjjrSrU =r$ )Uniform   a  The uniform distribution initializer.

Args:
    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`.
    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 uniform distribution.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> paddle.seed(1)
        >>> data = paddle.ones(shape=[3, 1, 2], dtype='float32')
        >>> weight_attr = paddle.framework.ParamAttr(
        ...     name="linear_weight",
        ...     initializer=paddle.nn.initializer.Uniform(low=-0.5, high=0.5))
        >>> bias_attr = paddle.framework.ParamAttr(
        ...     name="linear_bias",
        ...     initializer=paddle.nn.initializer.Uniform(low=-0.5, high=0.5))
        >>> 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,
        [[-0.48212373,  0.26492310],
         [ 0.17605734, -0.45379421]])

        >>> print(linear.bias)
        Parameter containing:
        Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=False,
        [-0.11236754,  0.46462214])

        >>> res = linear(data)
        >>> print(res)
        Tensor(shape=[3, 1, 2], dtype=float32, place=Place(cpu), stop_gradient=False,
        [[[-0.41843393,  0.27575102]],
         [[-0.41843393,  0.27575102]],
         [[-0.41843393,  0.27575102]]])
c           	     h   > Uc   S5       eUc   S5       eX!:  d   S5       e[         TU ]  XSSSSS9  g )Nzlow should not be Nonezhigh should not be Nonez%high should greater or equal than lowr   r^   )r   r   r   r    r!   r"   )r   r   )r   r   r   r0   r#   s       r$   r   Uniform.__init__   sT     8 88:!::{CCC{Qa# 	 	
r&    )r]   r^   N)r   r_   r   r_   r0   z
str | Nonera   rb   )rc   rd   re   rf   rg   r   rh   ri   rj   s   @r$   rl   rl      s:    (V HL

',
:D
	
 
r&   rl   )
__future__r   paddler   r   baser   r   r	   base.data_feederr
   base.frameworkr   r   r   initializerr   __all__r   rl   rp   r&   r$   <module>rx      sI    #   0 0 8 
 %
W Wt3
  3
r&   