
    }YhA                     (   d dl mZ d dlmZ d dlZd dlmZ ddlmZmZm	Z	m
Z
mZ g d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dS )    )Iterable)UnionN)Tensor   )
_lazy_call
_lazy_initcurrent_devicedevice_countis_initialized)	get_rng_stateget_rng_state_allset_rng_stateset_rng_state_allmanual_seedmanual_seed_allseedseed_allinitial_seedcudadevicereturnc                 J   t                       t          | t                    rt          j        |           } n*t          | t
                    rt          j        d|           } | j        }|t                      }t          j        j	        |         }|
                                S )aR  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: ``'cuda'`` (i.e., ``torch.device('cuda')``, the current CUDA device).

    .. warning::
        This function eagerly initializes CUDA.
    r   )r   
isinstancestrtorchr   intindexr	   r   default_generators	get_state)r   idxdefault_generators      c/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/torch/cuda/random.pyr   r      s     LLL&# .f%%	FC	 	  .ff--
,C
{
5c:&&(((    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>0   s     ???A}Q???r#   )ranger
   )resultss    r"   r   r   .   s&    ??|~~)>)>???GNr#   	new_statec                     t                      sVt          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: ``'cuda'`` (i.e., ``torch.device('cuda')``, the current CUDA device).
    )memory_formatNr   c                      j         } | t                      } t          j        j        |          }|                               d S N)r   r	   r   r   r   	set_state)r    r!   r   r,   s     r"   cbzset_rng_state.<locals>.cbH   sD    l; ""C!J9#>##I.....r#   )r   r   _C_DisableFuncTorchclonecontiguous_formatr   r   r   r   r   )r,   r   r2   s   `` r"   r   r   4   s     OX'')) 	O 	O "e6MNNI	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O &# .f%%	FC	 	  .ff--/ / / / / / rNNNNNs   !AA #A 
new_statesc                 P    t          |           D ]\  }}t          ||           dS )zSet the random number generator state of all devices.

    Args:
        new_states (Iterable of torch.ByteTensor): The desired state for each device.
    N)	enumerater   )r7   r(   states      r"   r   r   R   s<     j))    5eQ   r#   r   c                 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 CUDA 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 r0   )r	   r   r   r   r   )r    r!   r   s     r"   r2   zmanual_seed.<locals>.cbk   s8    !J9#>%%d+++++r#   T)r   Nr   r   r   r2   s   ` r"   r   r   \   sD     t99D, , , , ,
 rr#   c                 R     t                       fd}t          |d           dS )zSet the seed for generating random numbers on all GPUs.

    It's safe to call this function if CUDA 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 r0   )r*   r
   r   r   r   r   )r(   r!   r   s     r"   r2   zmanual_seed_all.<locals>.cb~   sO    |~~&& 	0 	0A %
 =a @))$////	0 	0r#   T)r   Nr=   r>   s   ` r"   r   r   s   sD     t99D0 0 0 0 0
 rD!!!!!!r#   c                  *    d } t          |            dS )at  Set the seed for generating random numbers to a random number for the current GPU.

    It's safe to call this function if CUDA 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 r0   )r	   r   r   r   r   r    r!   s     r"   r2   zseed.<locals>.cb   s5    !J9#>     r#   Nr   r2   s    r"   r   r      s"    ! ! !
 rNNNNNr#   c                  *    d } t          |            dS )zSet the seed for generating random numbers to a random number on all GPUs.

    It's safe to call this function if CUDA 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   r   r   r   )random_seedseededr(   r!   s       r"   r2   zseed_all.<locals>.cb   s    |~~&& 	; 	;A %
 =a @ ;!&&(((/<<>>!--k::::	; 	;r#   NrD   rE   s    r"   r   r      s"    
; 
; 
; rNNNNNr#   c                      t                       t                      } t          j        j        |          }|                                S )zyReturn the current random seed of the current GPU.

    .. warning::
        This function eagerly initializes CUDA.
    )r   r	   r   r   r   r   rC   s     r"   r   r      s:     LLL


C
5c:))+++r#   )r   )r   N)collections.abcr   typingr   r   r    r   r   r	   r
   r   __all__r   r   r   r   listr   r   r   r   r   r   r   r   r&   r#   r"   <module>rP      s   $ $ $ $ $ $              R R R R R R R R R R R R R R
 
 
) )%S%, 67 )V ) ) ) ),4<     @F $S#u|%;<	   < (6"2  t        c d    ."# "$ " " " "&   &   ,	,c 	, 	, 	, 	, 	, 	,r#   