§
    Ì²Åj  ã                   ó   — d dl mZmZmZ d dlZd dlmZ ddlmZmZm	Z	m
Z
 ddeeeej        f         defd	„Zdee         fd
„Z	 ddedeeeej        f         ddfd„Zdee         ddfd„Zdeddfd„Zdeddfd„Zdd„Zdd„Zdefd„Zg d¢ZdS )é    )ÚIterableÚListÚUnionN)ÚTensoré   )Ú
_lazy_callÚ
_lazy_initÚcurrent_deviceÚdevice_countÚxpuÚdeviceÚreturnc                 óJ  — t          ¦   «          t          | t          ¦  «        rt          j        | ¦  «        } n*t          | t
          ¦  «        rt          j        d| ¦  «        } | j        }|€t          ¦   «         }t          j        j	        |         }| 
                    ¦   «         S )aN  Return the random number generator state of the specified GPU as a ByteTensor.

    Args:
        device (torch.device or int, optional): The device to return the RNG state of.
            Default: ``'xpu'`` (i.e., ``torch.device('xpu')``, the current XPU device).

    .. warning::
        This function eagerly initializes XPU.
    r   )r	   Ú
isinstanceÚstrÚtorchr   ÚintÚindexr
   r   Údefault_generatorsÚ	get_state)r   ÚidxÚdefault_generators      úAC:\Projects\Historical\venv\Lib\site-packages\torch/xpu/random.pyÚget_rng_stater   
   sŒ   € õ �L„L€LÝ�&�#ÑÔð -Ý”˜fÑ%Ô%ˆˆÝ	�F�CÑ	 Ô	 ð -Ý”˜e VÑ,Ô,ˆØ
Œ,€CØ
€{ÝÑÔˆÝœ	Ô4°SÔ9ÐØ×&Ò&Ñ(Ô(Ð(ó    c                  óP   — d„ t          t          ¦   «         ¦  «        D ¦   «         } | S )zQReturn a list of ByteTensor representing the random number states of all devices.c                 ó,   — g | ]}t          |¦  «        ‘ŒS © )r   )Ú.0Úis     r   ú
<listcomp>z%get_rng_state_all.<locals>.<listcomp>"   s    € Ð?Ð?Ð? A�}˜QÑÔÐ?Ð?Ð?r   )Úranger   )Úresultss    r   Úget_rng_state_allr$       s&   € à?Ð?­­|©~¬~Ñ)>Ô)>Ð?Ñ?Ô?€GØ€Nr   Ú	new_statec                 óˆ  ‡‡— t           j                             ¦   «         5  |                      t           j        ¬¦  «        Šddd¦  «         n# 1 swxY w Y   t          ‰t          ¦  «        rt          j        ‰¦  «        Šn*t          ‰t          ¦  «        rt          j        d‰¦  «        Šˆˆfd„}t          |¦  «         dS )a,  Set the random number generator state of the specified GPU.

    Args:
        new_state (torch.ByteTensor): The desired state
        device (torch.device or int, optional): The device to set the RNG state.
            Default: ``'xpu'`` (i.e., ``torch.device('xpu')``, the current XPU device).
    )Úmemory_formatNr   c                  óŽ   •— ‰j         } | €t          ¦   «         } t          j        j        |          }|                     ‰¦  «         d S ©N)r   r
   r   r   r   Ú	set_state)r   r   r   Únew_state_copys     €€r   Úcbzset_rng_state.<locals>.cb7   sD   ø€ ØŒlˆØˆ;Ý Ñ"Ô"ˆCÝ!œIÔ8¸Ô=ÐØ×#Ò# NÑ3Ô3Ð3Ð3Ð3r   )
r   Ú_CÚ_DisableFuncTorchÚcloneÚcontiguous_formatr   r   r   r   r   )r%   r   r,   r+   s    ` @r   Úset_rng_stater1   &   s  øø€ õ 
Œ×	#Ò	#Ñ	%Ô	%ð Pð PØ"ŸšµuÔ7N˜ÑOÔOˆðPð Pð Pñ Pô Pð Pð Pð Pð Pð Pð Pøøøð Pð Pð Pð På�&�#ÑÔð -Ý”˜fÑ%Ô%ˆˆÝ	�F�CÑ	 Ô	 ð -Ý”˜e VÑ,Ô,ˆð4ð 4ð 4ð 4ð 4ð 4õ ˆr�N„N€N€N€Ns   ¡!AÁAÁAÚ
new_statesc                 óP   — t          | ¦  «        D ]\  }}t          ||¦  «         ŒdS )z›Set the random number generator state of all devices.

    Args:
        new_states (Iterable of torch.ByteTensor): The desired state for each device.
    N)Ú	enumerater1   )r2   r    Ústates      r   Úset_rng_state_allr6   A   s<   € õ ˜jÑ)Ô)ð  ð  ‰ˆˆ5Ý�e˜QÑÔÐÐð ð  r   Úseedc                 óR   ‡ — t          ‰ ¦  «        Š ˆ fd„}t          |d¬¦  «         dS )aˆ  Set the seed for generating random numbers for the current GPU.

    It's safe to call this function if XPU is not available; in that case, it is silently ignored.

    Args:
        seed (int): The desired seed.

    .. warning::
        If you are working with a multi-GPU model, this function is insufficient
        to get determinism.  To seed all GPUs, use :func:`manual_seed_all`.
    c                  ó|   •— t          ¦   «         } t          j        j        |          }|                     ‰¦  «         d S r)   )r
   r   r   r   Úmanual_seed)r   r   r7   s     €r   r,   zmanual_seed.<locals>.cbY   s8   ø€ ÝÑÔˆÝ!œIÔ8¸Ô=ÐØ×%Ò% dÑ+Ô+Ð+Ð+Ð+r   T)r7   N©r   r   ©r7   r,   s   ` r   r:   r:   K   sD   ø€ õ ˆt‰9Œ9€Dð,ð ,ð ,ð ,ð ,õ
 ˆr˜ÐÑÔÐÐÐr   c                 óR   ‡ — t          ‰ ¦  «        Š ˆ fd„}t          |d¬¦  «         dS )zÑSet the seed for generating random numbers on all GPUs.

    It's safe to call this function if XPU is not available; in that case, it is silently ignored.

    Args:
        seed (int): The desired seed.
    c                  óœ   •— t          t          ¦   «         ¦  «        D ].} t          j        j        |          }|                     ‰¦  «         Œ/d S r)   )r"   r   r   r   r   r:   )r    r   r7   s     €r   r,   zmanual_seed_all.<locals>.cbk   sO   ø€ Ý•|‘~”~Ñ&Ô&ð 	0ð 	0ˆAÝ %¤	Ô <¸QÔ ?ÐØ×)Ò)¨$Ñ/Ô/Ð/Ð/ð	0ð 	0r   T)Úseed_allNr;   r<   s   ` r   Úmanual_seed_allr@   a   sD   ø€ õ ˆt‰9Œ9€Dð0ð 0ð 0ð 0ð 0õ
 ˆr˜DÐ!Ñ!Ô!Ð!Ð!Ð!r   c                  ó*   — d„ } t          | ¦  «         dS )ao  Set the seed for generating random numbers to a random number for the current GPU.

    It's safe to call this function if XPU is not available; in that case, it is silently ignored.

    .. warning::
        If you are working with a multi-GPU model, this function will only initialize
        the seed on one GPU.  To initialize all GPUs, use :func:`seed_all`.
    c                  óx   — t          ¦   «         } t          j        j        |          }|                     ¦   «          d S r)   )r
   r   r   r   r7   ©r   r   s     r   r,   zseed.<locals>.cb}   s5   € ÝÑÔˆÝ!œIÔ8¸Ô=ÐØ×ÒÑ Ô Ð Ð Ð r   N©r   ©r,   s    r   r7   r7   s   s"   € ð!ð !ð !õ
 ˆr�N„N€N€N€Nr   c                  ó*   — d„ } t          | ¦  «         dS )z³Set the seed for generating random numbers to a random number on all GPUs.

    It's safe to call this function if XPU is not available; in that case, it is silently ignored.
    c                  óü   — d} d}t          t          ¦   «         ¦  «        D ][}t          j        j        |         }|s+|                     ¦   «          |                     ¦   «         } d}ŒF|                     | ¦  «         Œ\d S )Nr   FT)r"   r   r   r   r   r7   Úinitial_seedr:   )Úrandom_seedÚseededr    r   s       r   r,   zseed_all.<locals>.cb‹   sŠ   € ØˆØˆÝ•|‘~”~Ñ&Ô&ð 	;ð 	;ˆAÝ %¤	Ô <¸QÔ ?ÐØð ;Ø!×&Ò&Ñ(Ô(Ð(Ø/×<Ò<Ñ>Ô>�Ø��à!×-Ò-¨kÑ:Ô:Ð:Ð:ð	;ð 	;r   NrD   rE   s    r   r?   r?   …   s"   € ð
;ð 
;ð 
;õ ˆr�N„N€N€N€Nr   c                  ó�   — t          ¦   «          t          ¦   «         } t          j        j        |          }|                     ¦   «         S )zxReturn the current random seed of the current GPU.

    .. warning::
        This function eagerly initializes XPU.
    )r	   r
   r   r   r   rH   rC   s     r   rH   rH   š   s:   € õ �L„L€LÝ
Ñ
Ô
€CÝœ	Ô4°SÔ9ÐØ×)Ò)Ñ+Ô+Ð+r   )	r   r$   r1   r6   r:   r@   r7   r?   rH   )r   )r   N)Útypingr   r   r   r   r   Ú r   r	   r
   r   r   r   r   r   r$   r1   r6   r:   r@   r7   r?   rH   Ú__all__r   r   r   ú<module>rO      s¿  ðà (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ð (à €€€Ø Ð Ð Ð Ð Ð à BÐ BÐ BÐ BÐ BÐ BÐ BÐ BÐ BÐ BÐ BÐ Bð)ð )˜%  S¨%¬,Ð 6Ô7ð )ÀFð )ð )ð )ð )ð,˜4 œ<ð ð ð ð ð @Eðð ØðØ$ S¨#¨u¬|Ð%;Ô<ðà	ðð ð ð ð6  (¨6Ô"2ð  °tð  ð  ð  ð  ð�cð ˜dð ð ð ð ð,"˜#ð " $ð "ð "ð "ð "ð$ð ð ð ð$ð ð ð ð*	,�cð 	,ð 	,ð 	,ð 	,ð
ð 
ð 
€€€r   