
    
9j3                        S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	Sq
SqSqS
S jrS rS q\R                   S 5       rS rS rS rS	 rg)    )annotationsNc                   [         R                  " 5       q[        R                   R	                  5       q[        R                   R                  R                  q	[        R                   R                  5         [        R                   R                  R                  [        Ld   eU (       dR  [         R                  " 5         [        R                   R                  5         [        R                   R                  5         g [         R                  " S5        [        R                   R                  S5        [        R                   R                  S5        g )Nc   d   e   )randomgetstate_old_python_random_statenumpy	get_state_old_numpy_random_statecupy
_generator_random_states_old_cupy_random_statesreset_statesseed)deterministics    N/home/wildlama/miniconda3/lib/python3.13/site-packages/cupy/testing/_random.pydo_setupr      s      &0#ll446"kk44CCKK KK""11#$ % $ B#    c                     [         R                  " [        5        [        R                   R	                  [
        5        [        [        R                   R                  l	        S qS qS qg N)
r   setstater
   r   	set_stater   r   r   r   r    r   r   do_teardownr   +   sH     OO,-	LL23,CDKK)#""r   c                 &    [         S:X  d   S5       eg )Nr   z?_setup_random() and _teardown_random() must be called in pairs.)_nest_countr   r   r   _check_teardownr    =   s    ! : 9 :r   c                     [         S:X  aB  [        [        [        R                  R                  SS5      5      5      n [        U (       + 5        [         S-  q g)zHSets up the deterministic random states of ``numpy`` and ``cupy``.

    r   !CUPY_TEST_RANDOM_NONDETERMINISTIC0   N)r   boolintosenvirongetr   )nondeterministics    r   _setup_randomr+   C   sH    
 aBJJNN/%6 !7 8%%&1Kr   c                 b    [         S:  d   S5       e[         S-  q [         S:X  a  [        5         gg)zMTears down the deterministic random states set up by ``_setup_random``.

    r   z!_setup_random has not been calledr$   N)r   r   r   r   r   _teardown_randomr-   O   s2    
 ?????1Ka r   c                 b    [         S:  d   S5       e[        R                  R                  S5      $ )Nr   zrandom is not set upi)r   r   r   randintr   r   r   generate_seedr0   Z   s)    ?222?<<
++r   c                    ^ SSK mU4S jn U $ )a  Decorator that fixes random numbers in a test.

.. note:: free-threading
    The function version of this decorator currently will never run
    the test in free-threading (it is rarely used).
    The class version does run it, but results must be considered
    unpredictable in general, since tests would share the same global
    random state.

This decorator can be applied to either a test case class or a test method.
It should not be applied within ``condition.retry`` or
``condition.repeat``.
r   Nc                
  >^  [        T [        R                  5      (       a]  T R                  R	                  S5      (       a=  [
        R                  " T 5      TR                  R                  SS9U 4S j5       5       nU$ [        T [        5      (       aW  [        T [        R                  5      (       a8  T nS nS nU" UR                  5      Ul        U" UR                  5      Ul        U$ [        SR!                  T 5      5      e)Ntest_zfix_random seeds globals.)reasonc                f   > [        5          T" U /UQ70 UD6  [        5         g ! [        5         f = fr   )r+   r-   )selfargskwimpls      r   	test_func0fix_random.<locals>.decorator.<locals>.test_funcx   s/     '+++$&$&s   $ 0c                   ^  U 4S jnU$ )Nc                *   > [        5         T" U 5        g r   )r+   r6   fs    r   func?fix_random.<locals>.decorator.<locals>.wrap_setUp.<locals>.func   s    !OdGr   r   r?   r@   s   ` r   
wrap_setUp1fix_random.<locals>.decorator.<locals>.wrap_setUp   s     r   c                   ^  U 4S jnU$ )Nc                J   >  T" U 5        [        5         g ! [        5         f = fr   )r-   r>   s    r   r@   Bfix_random.<locals>.decorator.<locals>.wrap_tearDown.<locals>.func   s    +$(*(*s    "r   rB   s   ` r   wrap_tearDown4fix_random.<locals>.decorator.<locals>.wrap_tearDown   s    +
 r   zCan't apply fix_random to {})
isinstancetypesFunctionType__name__
startswith	functoolswrapsmarkthread_unsafetype
issubclassunittestTestCasesetUptearDown
ValueErrorformat)r9   r:   klassrC   rH   pytests   `    r   	decoratorfix_random.<locals>.decoratort   s    tU//00((11__T"[[&&.I&J' K #' d##
49J9J(K(KE %U[[1EK*5>>:ENL<CCDIJJr   )r\   )r]   r\   s    @r   
fix_randomr_   _   s     #KJ r   )T)
__future__r   atexitrO   r   r'   r   rK   rU   r   r
   r   r   r   r   r   registerr    r+   r-   r0   r_   r   r   r   <module>rc      sq    "    	         0	#  : :
	,
:r   