Ë
    ˆ\;jÂ!  ã                   ó\   — d dl Z d dl mZ d dlmZ g Zd„ Zdd„Zd„ Zdd„Zd„ Z	d	„ Z
d
„ Zd„ Zy)é    N)Úbase)Úcorec           	      óŠ  — t        | «      } t        j                  «       rGt        t        j                  «       «      D ]&  }t        j
                  |«      j                  | «       Œ( nZt        j                  «       rFt        t        j                  «       «      D ]&  }t        j                  |«      j                  | «       Œ( t        j                  j                  «       }t        |t        j                  «      r¤t        t        j                   «       D �cg c]'  }|j#                  «       |j%                  d«      d   k(  ‘Œ) c}«      }t        |«      D ]H  }t        j&                  t        j                  |j#                  «       |«      «      j                  | «       ŒJ t        j(                  «       j                  | «      S c c}w )a~  

    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   )Úintr   Úis_compiled_with_cudaÚrangeÚget_cuda_device_countÚdefault_cuda_generatorÚmanual_seedÚis_compiled_with_xpuÚget_xpu_device_countÚdefault_xpu_generatorr   Ú	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        ú`G:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\paddle/framework/random.pyr   r      sU  € ô* ˆt‹9€Dä×!Ñ!Ô#Ü”t×1Ñ1Ó3Ö4ˆAÜ×'Ñ'¨Ó*×6Ñ6°tÕ<ñ 5ä	×	"Ñ	"Ô	$Ü”t×0Ñ0Ó2Ö3ˆAÜ×&Ñ& qÓ)×5Ñ5°dÕ;ð 4ä�N‰N×2Ñ2Ó4€EÜ�%œ×)Ñ)Ô*Üô ×9Ñ9Ô;óá;�Að ×%Ñ%Ó'¨1¯7©7°3«<¸©?Ó:Ø;ñó
ˆô �w–ˆAÜ×0Ñ0Ü× Ñ  ×!6Ñ!6Ó!8¸!Ó<óç‰k˜$Õð  ô ×%Ñ%Ó'×3Ñ3°DÓ9Ð9ùòs   Ä,G c           	      ó¢  — g }| €t         j                  j                  «       }nt        j                  j                  | «      }t        |t        j                  «      r3|j                  t        j                  «       j                  «       «       |S t        |t        j                  «      rVt        t        j                  «       «      D ]4  }|j                  t        j                  |«      j                  «       «       Œ6 |S t        |t        j                   «      rVt        t        j"                  «       «      D ]4  }|j                  t        j$                  |«      j                  «       «       Œ6 |S t        |t        j&                  «      r´t)        t        j*                  «       D �cg c]'  }|j-                  «       |j/                  d«      d   k(  ‘Œ) c}«      }t        |«      D ]V  }|j                  t        j0                  t        j&                  |j-                  «       |«      «      j                  «       «       ŒX |S t3        d|› �«      ‚c c}w )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:
        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   r   ÚpaddleÚdeviceÚ_convert_to_placer   r   ÚCPUPlaceÚappendr   Ú	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+   C   sÜ  € ð$ €JØ€~Ü—‘×6Ñ6Ó8‰ä—‘×/Ñ/°Ó7ˆä�%œŸ™Ô'Ø×Ñœ$×4Ñ4Ó6×@Ñ@ÓBÔCð2 Ðô1 
�Eœ4Ÿ>™>Ô	*Ü”t×1Ñ1Ó3Ö4ˆAØ×Ñœd×9Ñ9¸!Ó<×FÑFÓHÕIð 5ð. Ðô+ 
�Eœ4Ÿ=™=Ô	)Ü”t×0Ñ0Ó2Ö3ˆAØ×Ñœd×8Ñ8¸Ó;×EÑEÓGÕHð 4ð( Ðô% 
�Eœ4×+Ñ+Ô	,Üô ×9Ñ9Ô;óá;�Að ×%Ñ%Ó'¨1¯7©7°3«<¸©?Ó:Ø;ñó
ˆô �w–ˆAØ×ÑÜ×4Ñ4Ü×$Ñ$ U×%:Ñ%:Ó%<¸aÓ@óç‘)“+õð  ð Ðô	 ØCÀEÀ7ÐKó
ð 	
ùòs   Æ%,Ic                  óÚ   — g } t        j                  «       rTt        t        j                  «       «      D ]4  }| j	                  t        j
                  |«      j                  «       «       Œ6 | S )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   s     r   Úget_cuda_rng_stater.   x   sW   € ð$ €JÜ×!Ñ!Ô#Ü”t×1Ñ1Ó3Ö4ˆAØ×Ñœd×9Ñ9¸!Ó<×FÑFÓHÕIð 5ð Ðó    c           	      óV  — |€t         j                  j                  «       }n|j                  |«      }t	        |t
        j                  «      rut        | «      t        j                  «       k(  st        d«      ‚t        t        j                  «       «      D ])  }t        j                  |«      j                  | |   «       Œ+ yt	        |t
        j                  «      rut        | «      t        j                  «       k(  st        d«      ‚t        t        j                  «       «      D ])  }t        j                  |«      j                  | |   «       Œ+ yt	        |t
        j                   «      rÓt#        t        j$                  «       D �cg c]'  }|j'                  «       |j)                  d«      d   k(  ‘Œ) c}«      }t        | «      |k(  st        d|j+                  «       › d�«      ‚t        |«      D ]K  }t        j,                  t        j                   |j'                  «       |«      «      j                  | |   «       ŒM yt	        |t
        j.                  «      r@t        | «      dk(  st        d	«      ‚t        j0                  «       j                  | d   «       yt        d
|› �«      ‚c c}w )aq  

    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 shoule be equal to the gpu device countz@Length of xpu state list shoule be equal to the xpu device countr   r   z:Length of custom device state list shoule be equal to the z device counté   z-Length of cpu state list shoule be equal to 1z5set_rng_state is not implemented for current device: )r   r   r   r#   r   r   r'   Úlenr
   r)   r	   r   Ú	set_stater(   r   r   r   r   r   r   r   Úget_dtype_typer   r$   r   )r*   r"   r   r   r   r   s         r   Úset_rng_stater5   ’   s/  € ð, €~Ü—‘×6Ñ6Ó8‰à×(Ñ(¨Ó0ˆä�%œŸ™Ô(Ü�:‹¤$×"<Ñ"<Ó">Ò>ÜØRóð ô ”t×1Ñ1Ó3Ö4ˆAÜ×'Ñ'¨Ó*×4Ñ4°ZÀ±]ÕCñ 5ä	�Eœ4Ÿ=™=Ô	)Ü�:‹¤$×";Ñ";Ó"=Ò=ÜØRóð ô ”t×0Ñ0Ó2Ö3ˆAÜ×&Ñ& qÓ)×3Ñ3°J¸q±MÕBñ 4ä	�Eœ4×+Ñ+Ô	,Üô ×9Ñ9Ô;óá;�Að ×%Ñ%Ó'¨1¯7©7°3«<¸©?Ó:Ø;ñó
ˆô �:‹ 'Ò)ÜØLÈU×MaÑMaÓMcÐLdÐdqÐróð ô �w–ˆAÜ×0Ñ0Ü× Ñ  ×!6Ñ!6Ó!8¸!Ó<óç‰i˜
 1™Õ&ñ  ô 
�Eœ4Ÿ=™=Ô	)Ü�:‹ !Ò#ÜÐLÓMÐMÜ×"Ñ"Ó$×.Ñ.¨z¸!©}Õ=äØCÀEÀ7ÐKó
ð 	
ùò%s   Æ,J&c                 ó  — t        j                  «       rut        | «      t        j                  «       k(  st	        d«      ‚t        t        j                  «       «      D ])  }t        j                  |«      j                  | |   «       Œ+ yy)a�  

    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 shoule be equal to the cuda device countN)r   r   r2   r
   r)   r	   r   r3   r-   s     r   Úset_cuda_rng_stater7   Ô   sq   € ô& ×!Ñ!Ô#Ü�:‹¤$×"<Ñ"<Ó">Ò>ÜØTóð ô ”t×1Ñ1Ó3Ö4ˆAÜ×'Ñ'¨Ó*×4Ñ4°ZÀ±]ÕCñ 5ð $r/   c                 óî   — | t         j                  j                  «       _        | t         j                  j	                  «       _        t         j                  j                  «       }|j                  | «       y)aQ  
    Sets global seed for generating random numbers.

    NOTE(zhiqiu): This is the original implemention 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_seedr@   ð   sN   € ð 8<„F‡M�M×&Ñ&Ó(Ô4Ø:>„F‡M�M×)Ñ)Ó+Ô7Ü�m‰m×#Ñ#Ó%€GØ×Ñ˜Õr/   c                 ó0   — t        j                  | |«       y ©N)r   Úset_random_seed_generator)Únamer   s     r   rC   rC     s   € Ü×"Ñ" 4¨Õ.r/   c                 ó,   — t        j                  | «      S rB   )r   Úget_random_seed_generator)rD   s    r   rF   rF     s   € Ü×)Ñ)¨$Ó/Ð/r/   rB   )r!   r   Úpaddle.baser   Ú__all__r   r+   r.   r5   r7   r@   rC   rF   © r/   r   Ú<module>rJ      sA   ðó  Ý Ý à
€ò):óX2òjó4?
òDDò8ò&/ó0r/   