
    ϑi)                       S SK Jr  S SKJrJr  S SKrS SKJr  S SKJr  \(       a  S SK	J
r
  S SKJrJr  S SKJr   " S	 S
\5      r/ r\ S     SS jj5       r\ S     SS jj5       r\ S     SS jj5       rSS jr\  S       SS jj5       r\  S       SS jj5       r\  S       SS jj5       r  SS jr  S     SS jjrg)    )annotations)TYPE_CHECKINGoverloadN)base)core)Sequence)LiteralProtocol)	PlaceLikec                      \ rS rSrSS jrSrg)_GeneratorState   c                    g N )selfs    `/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/incubate/framework/random.pycurrent_seed_GeneratorState.current_seed   s    s    r   N)returnint)__name__
__module____qualname____firstlineno__r   __static_attributes__r   r   r   r   r      s    *r   r   c                    g r   r   device	use_indexs     r   get_rng_stater"   $   s     r   c                    g r   r   r   s     r   r"   r"   *   s      r   c                    g r   r   r   s     r   r"   r"   0   s     ),r   c                  ^ U4S jn/ nU c  [         R                  R                  5       nO[        R                  R                  U 5      n[        U[        R                  5      (       a,  UR                  U" [        R                  " 5       5      5        U$ [        U[        R                  5      (       aR  [        [        R                  " 5       5       H.  nUR                  U" [        R                  " U5      5      5        M0     U$ [        U[        R                  5      (       aR  [        [        R                   " 5       5       H.  nUR                  U" [        R"                  " U5      5      5        M0     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       HQ  nUR                  U" [        R.                  " [        R$                  " UR+                  5       U5      5      5      5        MS     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``).
    use_index(bool): If use index is True, return the index that saved in the generator
Returns:
    GeneratorState:  object.
Examples:
    .. code-block:: python
        >>> import paddle
        >>> sts = paddle.incubate.get_rng_state()
c                R   > T(       a  U R                  5       $ U R                  5       $ r   )get_state_index	get_state)	generatorr!   s    r   r(    get_rng_state.<locals>.get_stateF   s$    ,,..&&((r   :r   z5get_rng_state is not implemented for current device: )r   	framework_current_expected_place_paddler    _convert_to_place
isinstancer   CPUPlaceappenddefault_cpu_generator	CUDAPlacerangeget_cuda_device_countdefault_cuda_generatorXPUPlaceget_xpu_device_countdefault_xpu_generatorCustomPlacesumget_available_custom_deviceget_device_typesplitdefault_custom_device_generator
ValueError)r    r!   r(   
state_listplaceisdev_cnts    `      r   r"   r"   6   s    ) J~779//7%'')D$>$>$@AB6 5 
E4>>	*	*t1134Ai(C(CA(FGH 52 / 
E4==	)	)t0023Ai(B(B1(EFG 4, ) 
E4++	,	, 99;;A %%'1773<?:;
 wA88(()>)>)@!D   	 CE7K
 	
s   3/Ic                    g r   r   rB   r    r!   s      r   set_rng_staterI   q       
 r   c                    g r   r   rH   s      r   rI   rI   y   rJ   r   c                    g r   r   rH   s      r   rI   rI      rJ   r   c           	       ^ U4S jnUc  [         R                  R                  5       nOUR                  U5      n[	        U[
        R                  5      (       ar  [        U 5      [
        R                  " 5       :X  d  [        S5      e[        [
        R                  " 5       5       H"  nU" [
        R                  " U5      X   5        M$     g[	        U[
        R                  5      (       ar  [        U 5      [
        R                  " 5       :X  d  [        S5      e[        [
        R                  " 5       5       H"  nU" [
        R                  " U5      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       HE  nU" [
        R$                  " [
        R                  " UR'                  5       U5      5      X   5        MG     g[	        U[
        R(                  5      (       a:  [        U 5      S:X  d  [        S	5      eU" [
        R*                  " 5       U S   5        g[        S
U 35      e)a  

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``).
    use_index(bool): If use index is True, state_list should be the indices of the states

Returns:
    None.

Examples:
    .. code-block:: python

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

c                Z   > T(       a  U R                  U5        g U R                  U5        g r   )set_state_index	set_state)r)   stater!   s     r   rP    set_rng_state.<locals>.set_state   s"    %%e,&r   N@Length of gpu state list should be equal to the gpu device count@Length of xpu state list should be equal to the xpu device countr   :Length of custom device state list should be equal to the  device count   -Length of cpu state list should be equal to 1z5set_rng_state is not implemented for current device: )r   r,   r-   r/   r0   r   r4   lenr6   rA   r5   r7   r8   r9   r:   r;   get_all_custom_device_typeget_custom_device_countr@   r>   r1   r3   )	rB   r    r!   rP   rC   rD   	dev_typesdev_typerF   s	     `      r   rI   rI      s   8' ~779((0%((:$"<"<">>R  t1134Ad11!4jmD 5	E4==	)	):$";";"==R  t0023Ad003Z]C 4	E4++	,	,335	Q<..x8:')LWIUbc  wA44$$U%:%:%<a@ 	   
E4==	)	):!#LMM$,,.
1>CE7K
 	
r   c           	        / nUc  [         R                  R                  5       nOUR                  U5      nU c  [	        U5      n [        U[        R                  5      (       a  [        U 5      [        R                  " 5       :X  d  [        S5      e[        [        R                  " 5       5       H9  nUR                  [        R                  " U5      R                  X   5      5        M;     U$ [        U[        R                  5      (       a  [        U 5      [        R                   " 5       :X  d  [        S5      e[        [        R                   " 5       5       H9  nUR                  [        R"                  " U5      R                  X   5      5        M;     U$ [        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       H\  nUR                  [        R*                  " [        R$                  " UR-                  5       U5      5      R                  X   5      5        M^     U$ [        U[        R.                  5      (       aR  [        U 5      S:X  d  [        S5      eUR                  [        R0                  " 5       R                  U S   5      5        U$ [        SU 35      e)	a  

The register_rng_state_as_index function creates and registers a new generator state within the generator.
It enables users to manage multiple generator states via indices,
offering a convenient way to switch between these states without directly manipulating the generator's state.

Args:
    state_list(list|tuple): A list or tuple representing the RNG states for devices.
        If not provided, the function will register the current 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:
    A list of indices representing the positions at which the new states were saved within the generator.
    These indices can be used to switch between states using set_rng_state(use_index=True)


Examples:
    .. code-block:: python

        >>> import paddle
        >>> old_index = paddle.incubate.get_rng_state(use_index=True)
        >>> print(old_index)
        [0]
        >>> new_index = paddle.incubate.register_rng_state_as_index()
        >>> print(new_index)
        [1]
        >>> paddle.incubate.set_rng_state(old_index, use_index=True)
        >>> paddle.incubate.set_rng_state(new_index, use_index=True)

rS   rT   r   rU   rV   rW   rX   z@register_rng_state_index is not implemented for current device: )r   r,   _current_expected_placer/   r"   r0   r   r4   rY   r6   rA   r5   r2   r7   register_state_indexr8   r9   r:   r;   rZ   r[   r@   r>   r1   r3   )rB   r    new_state_index_listrC   rD   r\   r]   rF   s           r   register_rng_state_as_indexrb      s   H ~668((0"6*
%((:$"<"<">>R  t1134A ''++A.CCM 5R  G 
E4==	)	):$";";"==R  t0023A ''**1-BBM 4<  1 
E4++	,	,335	Q<..x8:')LWIUbc  wA ''44$$U%:%:%<a@&&z}5      
E4==	)	):!#LMM##&&(==jmL	
   NugV
 	
r   )..)r    PlaceLike | Noner!   Literal[True]r   	list[int])r    rc   r!   Literal[False]r   zlist[_GeneratorState])r    rc   r!   boolr   z!list[int] | list[_GeneratorState])NF)rB   zSequence[int]r    rc   r!   rd   r   None)rB   zSequence[_GeneratorState]r    rc   r!   rf   r   rh   )rB   z)Sequence[int] | Sequence[_GeneratorState]r    rc   r!   rg   r   rh   )NN)rB   z Sequence[_GeneratorState] | Noner    rc   r   re   )
__future__r   typingr   r   r.   r   paddle.baser   collections.abcr   r	   r
   paddle._typingr   r   __all__r"   rI   rb   r   r   r   <module>ro      s   # *   (((+( +  
?B/< 

 
@C  /=   
 
 
69,,/3,&, 
,
8v 
  #"  
	 
 
  # #)  
	 
 
  #9  
	 
 K
^ 48#\ 0\ \  \ r   