o
    0 in                     @   s   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZdada	da
dddZdd Zd ae jdd Zd	d
 Zdd Zdd Zdd ZdS )    NTc                 C   s   t  atj  atj jja	tj 
  tj jjt	usJ | s.t   tj   tj   d S t d tj d tj d d S )Nc   d   e   )randomgetstate_old_python_random_statenumpyZ	get_state_old_numpy_random_statecupy
_generator_random_states_old_cupy_random_statesZreset_statesseed)Zdeterministic r   `/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/cupy/testing/_random.pydo_setup   s   




r   c                   C   s0   t t tj t ttj j_	d ad ad ad S N)
r   setstater   r   Z	set_stater	   r   r
   r   r   r   r   r   r   do_teardown)   s   

r   c                   C   s   t dksJ dd S )Nr   z?_setup_random() and _teardown_random() must be called in pairs.)_nest_countr   r   r   r   _check_teardown;   s   r   c                  C   s4   t dkrtttjdd} t|   t d7 a dS )zHSets up the deterministic random states of ``numpy`` and ``cupy``.

    r   Z!CUPY_TEST_RANDOM_NONDETERMINISTIC0   N)r   boolintosenvirongetr   )Znondeterministicr   r   r   _setup_randomA   s   

r   c                   C   s.   t dksJ dt d8 a t dkrt  dS dS )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   r   _teardown_randomM   s
   
r   c                   C   s   t dksJ dtjdS )Nr   zrandom is not set upi)r   r   r   randintr   r   r   r   generate_seedX   s   r!   c                  C   s   dd } | S )zDecorator that fixes random numbers in a test.

    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``.
    c                    s   t  tjr jdrt  fdd}|S t  tr<t t	j
r< }dd }dd }||j|_||j|_|S td )	NZtest_c                    s2   t   z | g|R i | W t  d S t  w r   )r   r   )selfargskwimplr   r   	test_funcn   s   z0fix_random.<locals>.decorator.<locals>.test_funcc                        fdd}|S )Nc                    s   t    |  d S r   )r   r"   fr   r   func{   s   z?fix_random.<locals>.decorator.<locals>.wrap_setUp.<locals>.funcr   r+   r,   r   r*   r   
wrap_setUpz   s   z1fix_random.<locals>.decorator.<locals>.wrap_setUpc                    r(   )Nc                    s   z
 |  W t   d S t   w r   )r   r)   r*   r   r   r,      s   
zBfix_random.<locals>.decorator.<locals>.wrap_tearDown.<locals>.funcr   r-   r   r*   r   wrap_tearDown   s   z4fix_random.<locals>.decorator.<locals>.wrap_tearDownzCan't apply fix_random to {})
isinstancetypesFunctionType__name__
startswith	functoolswrapstype
issubclassunittestZTestCaseZsetUpZtearDown
ValueErrorformat)r&   r'   klassr.   r/   r   r%   r   	decoratorj   s   
zfix_random.<locals>.decoratorr   )r=   r   r   r   
fix_random]   s   $r>   )T)atexitr5   r   r   r   r1   r9   r
   r   r	   r   r   r   r   registerr   r   r   r!   r>   r   r   r   r   <module>   s(    

