
    Αi&                        S SK Jr  S SKJr  S SKrS SKJr  \(       a  S SKJr  / r	SS jr
 S   SS jjrSS jr S     SS	 jjr    SS
 jrSS jrSS jrSS jr " S S5      rg)    )annotations)TYPE_CHECKINGN)core)Sequencec           	        [        U 5      n [        R                  " 5       (       aK  [        [        R
                  " 5       5       H(  n[        R                  " U5      R                  U 5        M*     Od[        R                  " 5       (       aJ  [        [        R                  " 5       5       H(  n[        R                  " U5      R                  U 5        M*     [        R                  R                  5       n[        U[        R                  5      (       a  [        [        R                   " 5        Vs/ s H(  nUR#                  5       UR%                  S5      S   :H  PM*     sn5      n[        U5       HK  n[        R&                  " [        R                  " UR#                  5       U5      5      R                  U 5        MM     [        R(                  " 5       R                  U 5      $ s  snf )aV  

Sets the seed for global default generator, which manages the random number generation.

Args:
    seed(int): The random seed to set. It is recommend to set a large int number.

Returns:
    Generator: The global default generator object.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> gen = paddle.seed(102)

:r   )intpaddleis_compiled_with_cudaranger   get_cuda_device_countdefault_cuda_generatormanual_seedis_compiled_with_xpuget_xpu_device_countdefault_xpu_generator	framework_current_expected_place
isinstanceCustomPlacesumget_available_custom_deviceget_device_typesplitdefault_custom_device_generatordefault_cpu_generator)seediplacesdev_cnts        W/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/framework/random.pyr   r      s`   * t9D##%%t1134A''*66t< 5		$	$	&	&t0023A&&q)55d; 4446E%++,, 99;;A %%'1773<?:;
 wA00""5#8#8#:A>k$   %%'33D99s   ./G"c           	        / nU c  [         R                  R                  5       nO[         R                  R	                  U 5      n[        U[         R                  5      (       a4  UR                  [        R                  " 5       R                  5       5        U$ [        U[         R                  5      (       aZ  [        [        R                  " 5       5       H6  nUR                  [        R                  " U5      R                  5       5        M8     U$ [        U[         R                  5      (       aZ  [        [        R                   " 5       5       H6  nUR                  [        R"                  " U5      R                  5       5        M8     U$ [        U[         R$                  5      (       a  ['        [        R(                  " 5        Vs/ s H(  nUR+                  5       UR-                  S5      S   :H  PM*     sn5      n[        U5       HY  nUR                  [        R.                  " [        R$                  " UR+                  5       U5      5      R                  5       5        M[     U$ [1        SU 35      es  snf )a  
Get all random states of random generators of specified device.

Args:
    device(str): This parameter determines the specific running device.
        It can be ``cpu``, ``gpu``, ``xpu``, Default is None.
        If None, return the generators of current device (specified by ``set_device``).

Returns:
    list[GeneratorState], object.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> sts = paddle.get_rng_state()
r   r   z5get_rng_state is not implemented for current device: )r
   r   _current_expected_place_device_convert_to_placer   CPUPlaceappendr   r   	get_state	CUDAPlacer   r   r   XPUPlacer   r   r   r   r   r   r   r   
ValueError)r%   
state_listr   r   r    r!   s         r"   get_rng_stater.   H   s   ( J~  99;//7%))$446@@BC2 1 
E6++	,	,t1134Ad99!<FFHI 5. + 
E6??	+	+t0023Ad88;EEGH 4( % 
E6--	.	. 99;;A %%'1773<?:;
 wA44$$U%:%:%<a@)+   	 CE7K
 	
s   /I2c                     / n [         R                  " 5       (       aX  [        [        R                  " 5       5       H6  nU R                  [        R                  " U5      R                  5       5        M8     U $ )z

Get random state of cuda generators.

Args:
    None.

Returns:
    GeneratorState:  object.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> sts = paddle.get_cuda_rng_state()

)r
   r   r   r   r   r(   r   r)   r-   r   s     r"   get_cuda_rng_stater1      sZ    $ J##%%t1134Ad99!<FFHI 5     c                Z   Uc  [         R                  R                  5       nO[         R                  R	                  U5      n[        U[         R                  5      (       az  [        U 5      [        R                  " 5       :X  d  [        S5      e[        [        R                  " 5       5       H*  n[        R                  " U5      R                  X   5        M,     g[        U[         R                  5      (       az  [        U 5      [        R                  " 5       :X  d  [        S5      e[        [        R                  " 5       5       H*  n[        R                   " U5      R                  X   5        M,     g[        U[         R"                  5      (       a  [        R$                  " 5       nUS   n[        R&                  " U5      n[        U 5      U:X  d  [        SU S35      e[        U5       HM  n[        R(                  " [         R"                  " UR+                  5       U5      5      R                  X   5        MO     g[        U[        R,                  5      (       aB  [        U 5      S:X  d  [        S5      e[        R.                  " 5       R                  U S   5        g[        S	U 35      e)
a9  

Sets generator state for all device generators.

Args:
    state_list(list|tuple): The device states to set back to device generators. state_list is obtained from get_rng_state().
    device(str): This parameter determines the specific running device.
        It can be ``cpu``, ``gpu``, ``xpu``, Default is None.
        If None, return the generators of current device (specified by ``set_device``).

Returns:
    None.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> sts = paddle.get_rng_state()
        >>> paddle.set_rng_state(sts)

Nz@Length of gpu state list should be equal to the gpu device countz@Length of xpu state list should be equal to the xpu device countr   z:Length of custom device state list should be equal to the z device count   z-Length of cpu state list should be equal to 1z5set_rng_state is not implemented for current device: )r
   r   r$   r%   r&   r   r*   lenr   r   r,   r   r   	set_stater+   r   r   r   get_all_custom_device_typeget_custom_device_countr   r   r'   r   )r-   r%   r   r   	dev_typesdev_typer!   s          r"   set_rng_stater;      s	   2 ~  99;//7%))**:$"<"<">>R  t1134A''*44Z]C 5	E6??	+	+:$";";"==R  t0023A&&q)33JMB 4	E6--	.	.335	Q<..x8:')LWIUbc  wA00""5#8#8#:A>i
&   
E4==	)	):!#LMM""$..z!}=CE7K
 	
r2   c                ,   [         R                  " 5       (       az  [        U 5      [        R                  " 5       :X  d  [        S5      e[        [        R                  " 5       5       H*  n[        R                  " U5      R                  X   5        M,     gg)ad  

Sets generator state for all cuda generators.

Args:
    state_list(list|tuple): The cuda states to set back to cuda generators. state_list is obtained from get_cuda_rng_state().

Returns:
    None.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> sts = paddle.get_cuda_rng_state()
        >>> paddle.set_cuda_rng_state(sts)

zBLength of cuda state list should be equal to the cuda device countN)	r
   r   r5   r   r   r,   r   r   r6   r0   s     r"   set_cuda_rng_stater=      sr    * ##%%:$"<"<">>T  t1134A''*44Z]C 5 &r2   c                    U [         R                  R                  5       l        U [         R                  R	                  5       l        [         R                  R                  5       nUR                  U 5        g)a3  
Sets global seed for generating random numbers.

NOTE(zhiqiu): This is the original implementation of seed. Keeps it temporally
since CUDA generator is not developed, so we need it in the unittest.

Args:
    seed(int): The random seed to set. It is recommend to set a large int number.

Returns:
    None
N)r
   staticdefault_main_programrandom_seeddefault_startup_programProgramglobal_seed)r   programs     r"   _manual_program_seedrF      sN     8<FMM&&(4:>FMM))+7mm##%Gr2   c                0    [         R                  " X5        g N)r   set_random_seed_generator)namer   s     r"   rI   rI     s    ""4.r2   c                .    [         R                  " U 5      $ rH   )r   get_random_seed_generator)rJ   s    r"   rL   rL     s    ))$//r2   c                  *    \ rS rSr S   SS jjrSrg)	Generatori  Nc                    [         R                  R                  U5      n[        U[        R
                  5      (       a  [        R                  " 5       $ [        U[        R                  5      (       a$  [        R                  " UR                  5       5      $ [        U[        R                  5      (       a$  [        R                  " UR                  5       5      $ [        U[        R                  5      (       a  [        R                  " U5      $ g)at  
Generator is a random number generator.

Args:
    device(str|int|paddle.core.Place): The device type to create the generator on.
        It can be ``cpu``, ``gpu``, ``xpu``, or a paddle.core.Place instance.
        default is None, which means using current device.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> g_cpu = paddle.Generator()
N)r
   r%   device_to_placer   r   r'   r   r*   r   gpu_device_idr+   r   r   r   )clsr%   r   s      r"   __new__Generator.__new__  s    " --f5eT]]++--//t~~....u/B/B/DEEt}}----e.A.A.CDDt//0077>> 1r2    rH   )r%   zstr | int | paddle.core.Placereturnzcore.Generator)__name__
__module____qualname____firstlineno__rS   __static_attributes__rU   r2   r"   rN   rN     s    59?2?	? ?r2   rN   )r   r	   rV   paddle.base.core.GeneratorrH   )r%   
str | NonerV   %list[paddle.base.core.GeneratorState])rV   r^   )r-   )Sequence[paddle.base.core.GeneratorState]r%   r]   rV   None)r-   r_   rV   r`   )r   r	   rV   r`   )rJ   strr   r	   rV   r`   )rJ   ra   rV   r\   )
__future__r   typingr   r
   paddle.baser   collections.abcr   __all__r   r.   r1   r;   r=   rF   rI   rL   rN   rU   r2   r"   <module>rg      s    #    (
):Z 44*4n8 ?
9?
?
 
?
DD9D	D<&/0? ?r2   