
    J/Ph                     f   d dl Zd dlmZ d dlmZmZmZ d dlm	Z	 d dl
mZmZ d dlmZmZ d Zd Zd	 Z ed
           G d de                      ZdZd Z ed           G d dej                              ZeD ]Z eedez   ee                     edk    r ej                     dS dS )    N)types)skip_on_cudasimunittestCUDATestCase)cuda)	libdevicecompile_ptx)	functionscreate_signaturec                     t          j        d          }|t          |          k     r)t          j        ||                   \  }}|| |<   |||<   d S d S N   )r   gridlenr   sincos)scxisrcrs         f/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/cuda/tests/cudapy/test_libdevice.py
use_sincosr   	   sS    	!A3q66zz!!A$''B!! z    c                     t          j        d          }|t          |          k     r)t          j        ||                   \  }}|| |<   |||<   d S d S r   )r   r   r   r   frexp)fracexpr   r   fracrexprs         r   	use_frexpr!      sR    	!A3q66zzoad++tQA zr   c                     t          j        d          }|t          |          k     r-t          j        ||         ||         ||                   | |<   d S d S r   )r   r   r   r   sad)rr   yzr   s        r   use_sadr'      sL    	!A3q66zz}QqT1Q41..! zr   z0Libdevice functions are not supported on cudasimc                   $    e Zd ZdZd Zd Zd ZdS )TestLibdevicea(  
    Some tests of libdevice function wrappers that check the returned values.

    These are mainly to check that the generation of the implementations
    results in correct typing and lowering for each type of function return
    (e.g. scalar return, UniTuple return, Tuple return, etc.).
    c                    t          j        dt           j                  }t          j        |          }t          j        |          }t	          j        t                    } |d         |||           t           j                            t          j	        |          |           t           j                            t          j
        |          |           d S )Nd   )dtype       )nparangefloat64
zeros_liker   jitr   testingassert_allclosecossin)selfarrsrescrescufuncs        r   test_sincoszTestLibdevice.test_sincos,   s    i2:...}S!!}S!!*%%udD#&&&

""26#;;555

""26#;;55555r   c                    t          j        dddt           j                  }t          j        |          }t          j        |j        t           j                  }t          j        t                    } |d         |||           t          j
        |          \  }}t           j                            ||           t           j                            ||           d S )Ng      ?g      $@r+   )startstopnumr,   )shaper,   r-   )r0   linspacer2   r3   zerosrC   int32r   r4   r!   r   r5   assert_array_equal)r9   r:   fracresexpresr=   frac_expect
exp_expects          r   
test_frexpzTestLibdevice.test_frexp8   s    k$CrzJJJ-$$	:::)$$ugvs+++"$(3--Z

%%k7;;;

%%j&99999r   c                 x   t          j        ddd          }t          j        dd          }t          j        dd          }t          j        |          }t          j        t
                    } |d         ||||           t           j                            t          j        ||z
            |z   |           d S )	Nr         2         s   r-   )	r0   r1   r3   r   r4   r'   r5   rG   abs)r9   r   r%   r&   r$   r=   s         r   test_sadzTestLibdevice.test_sadF   s    Iaa  Ib#Ib#M!'""uaAq!!!

%%bfQUmma&7;;;;;r   N)__name__
__module____qualname____doc__r>   rL   rU    r   r   r)   r)   "   sK         
6 
6 
6: : :
< 
< 
< 
< 
<r   r)   z{from numba.cuda import libdevice

def pyfunc(%(pyargs)s):
    ret = libdevice.%(func)s(%(funcargs)s)
    %(retvars)s = ret
c                       fd}|S )z@
    Generates a test function for each libdevice function.
    c                 <   dd          }t          t          |          }t                   \  }}t          ||          }d                    d t          |          D                       }t          |j        t          j	        t          j
        f          rd                    d t          t          |j                            D                       }|d|z   z  }d                    d t          t          |j                            D                       }nd|z   }d}||||d}	t          |	z  }
i }t          |
t                      |           |d	         }d
 |D             }t          |j        t          j	        t          j
        f          rd |j        D             }||z   }n$|                    d|j        d d d                    t#          |          }t%          ||          \  }}|                     d|           |                     d|           d S )N   z, c                 ,    g | ]\  }}|j         d |z  S )za%d)is_ptr).0r   args      r   
<listcomp>z@make_test_call.<locals>._test_call_functions.<locals>.<listcomp>o   s6     * * *FAs!j*eai * * *r   c                     g | ]}d |z  S )zr%drZ   r`   r   s     r   rb   z@make_test_call.<locals>._test_call_functions.<locals>.<listcomp>y   s(      =  =  =a	  =  =  =r   c                     g | ]}d |z  S )zr%d[0]rZ   rd   s     r   rb   z@make_test_call.<locals>._test_call_functions.<locals>.<listcomp>   s(     !> !> !>!A !> !> !>r   zr0, zr0[0])funcpyargsfuncargsretvarspyfuncc                 *    g | ]}|j         	|j        S rZ   )r_   ty)r`   ra   s     r   rb   z@make_test_call.<locals>._test_call_functions.<locals>.<listcomp>   s!    ===c=36===r   c                 $    g | ]}|d d d         S r   rZ   )r`   rets     r   rb   z@make_test_call.<locals>._test_call_functions.<locals>.<listcomp>   s"    ===cSSqS===r   r   r   zld.paramz	st.global)getattrr   r
   r   join	enumerate
isinstancereturn_typer   TupleUniTupleranger   function_templateexecglobalsinserttupler	   assertIn)r9   apinameapifuncrettyargssigrh   rg   ri   dcodelocalsrj   	pyreturnsptxrestylibnames                   r   _test_call_functionsz,make_test_call.<locals>._test_call_functionsf   sI   !""+)W--(tud++ 99 * *ioo * * * + + coU^'DEE 	YY  =  = %c#/&:&: ; ; =  =  = > >F dXo%F ii !> !>!&s3?';';!<!<!> !> !> ? ?GG h&FG " # # !1$ T799f%%%! >=T===coU^'DEE 	3==S_===I'FFMM!S_SSqS1222v 00
U
 	j#&&& 	k3'''''r   rZ   )r   r   s   ` r   make_test_callr   a   s*    
@( @( @( @( @(D  r   z.Compilation to PTX is not supported on cudasimc                       e Zd ZdZdS )TestLibdeviceCompilationa:  
    Class for holding all tests of compiling calls to libdevice functions. We
    generate the actual tests in this class (as opposed to using subTest and
    one test within this class) because there are a lot of tests, and it makes
    the test suite appear frozen to test them all as subTests in one test.
    N)rV   rW   rX   rY   rZ   r   r   r   r      s           r   r   ztest_%s__main__)numpyr0   
numba.corer   numba.cuda.testingr   r   r   numbar   
numba.cudar   r	   numba.cuda.libdevicefuncsr
   r   r   r!   r'   r)   rw   r   TestCaser   r   setattrrV   mainrZ   r   r   <module>r      s             F F F F F F F F F F       - - - - - - - - A A A A A A A A    / / / CDD-< -< -< -< -<L -< -< ED-<j G  G  G T ABB    x0   CB  % %GG$i'&9N7##% % % % zHMOOOOO r   