o
    i3                     @   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mZ d dl	T d dl
Zd dlmZ d dlmZ d dlmZmZmZmZmZmZmZ d dlZdZeejd eZejej e!Z"dd	 Z#eG d
d deZ$G dd deZ%eeG dd de%Z&eeG dd deZ'e(dkre)  dS dS )    N)skip)*)utils)TestCasetagimport_dynamictemp_directoryhas_blasneeds_setuptoolsskip_if_py313_on_windowszwindows onlywinc                   C   s   dt jv rt jd= dS dS )zVUnset MACOSX_DEPLOYMENT_TARGET because we are not building portable
    libraries
    MACOSX_DEPLOYMENT_TARGETN)osenviron r   r   R/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/numba/tests/test_pycc.pyunset_macosx_deployment_target   s   
r   c                   @   s   e Zd Zedd ZdS )TestCompilerChecksc                 C   sL   ddl m} tjdd d u}|r"tjdd d ur$| |  d S d S d S )Nr   )external_compiler_worksCONDA_BUILDVSINSTALLDIR)numba.pycc.platformr   r   r   get
assertTrue)selfr   is_running_conda_buildr   r   r   test_windows_compiler_validity*   s   z1TestCompilerChecks.test_windows_compiler_validityN)__name__
__module____qualname___windows_onlyr   r   r   r   r   r   &   s    r   c                   @   s*   e Zd Zdd Zdd Zejdd ZdS )BasePYCCTestc                 C   s   t   td| _| jt_d S )N	test_pycc)r   r   tmpdirtempfiletempdirr   r   r   r   setUp;   s   
zBasePYCCTest.setUpc                 C   s   d t _ddlm} |  d S )Nr   )clear_export_registry)r$   r%   numba.pycc.decoratorsr(   )r   r(   r   r   r   tearDownC   s   
zBasePYCCTest.tearDownc              
   c   sZ    t j| zt|}|V  W t j| t j|d  d S t j| t j|d  w N)syspathappendr   removemodulespop)r   extdirnamelibr   r   r   check_c_extN   s   zBasePYCCTest.check_c_extN)r   r   r   r'   r*   
contextlibcontextmanagerr5   r   r   r   r   r!   9   s
    r!   c                       sz   e Zd Z fddZejdd Zdd Zdd Zd	d
 Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Z  ZS )TestCCc                    s8   t t|   |   ddlm} || _t| j d S )Nr   )compile_with_pycc)	superr8   r'   skip_if_no_external_compilernumba.testsr9   _test_module	importlibreload)r   r9   	__class__r   r   r'   ]   s
   zTestCC.setUpc                 c   sN    | j |_|  | | j |j}|V  W d    d S 1 s w   Y  d S r+   )r#   
output_dircompiler5   r3   )r   ccr4   r   r   r   check_cc_compiledd   s   "zTestCC.check_cc_compiledc                 C   s>   d|j tj|jd }|d| }ttj	d|g d S )Na  if 1:
            import sys
            import types
            # to disable numba package
            sys.modules['numba'] = types.ModuleType('numba')
            try:
                from numba import njit
            except ImportError:
                pass
            else:
                raise RuntimeError('cannot disable numba package')

            sys.path.insert(0, %(path)r)
            import %(name)s as lib
            )r3   r-    -c)
r   r   r-   dirname__file__strip
subprocess
check_callr,   
executable)r   r4   codeprologr   r   r   check_cc_compiled_in_subprocessm   s   z&TestCC.check_cc_compiled_in_subprocessc                 C   s   | j j}| |jd | j jj}| tj|| | j jj	}| 
tj|| | tj|d| tjdrT| |d| ddlm} | | | d S d S )Npycc_test_simplezpycc_test_simple.linuxz.sor   )find_pyext_ending)r=   rD   assertEqualr3   rB   r   r   r-   isdiroutput_fileassertFalseexistsbasename
startswithr,   platformendswithr   rS   assertIn)r   rD   dfrS   r   r   r   test_cc_properties   s   

zTestCC.test_cc_propertiesc              	   C   s   |  | jjW}|dd}| |d |dd}| |d |d}| |d | | d  | 	t
 |dd	 W d    n1 sIw   Y  W d    d S W d    d S 1 saw   Y  d S )
N{   A  ;  i  g    lVA         r   )rE   r=   rD   multiassertPreciseEqualmultfsquareassertIsget_noneassertRaisesZeroDivisionErrordiv)r   r4   resr   r   r   test_compile   s   
"zTestCC.test_compilec                 C   sf   | j j}||_| |}|dd}| |d | |jjd W d    d S 1 s,w   Y  d S )Nra   rb   rc   rQ   )r=   rD   
target_cpurE   rg   rh   rT   r   )r   cpu_namerD   r4   rp   r   r   r   check_compile_for_cpu   s   "zTestCC.check_compile_for_cpuc                 C   s   |  t  d S r+   )rt   llget_host_cpu_namer&   r   r   r   test_compile_for_cpu   s   zTestCC.test_compile_for_cpuc                 C      |  d d S )Nhost)rt   r&   r   r   r   test_compile_for_cpu_host   s   z TestCC.test_compile_for_cpu_hostc                 C   s2  |  | jj}|dd}| |d ddtdfD ]}||}| |d qddtdfD ]}|	|}| |d	 q2|
d
}| |d | |d|d |d}tjd }| || |tdgd }| |d dd|i }| || W d    d S 1 sw   Y  d S )N         y              y              ?         @       @      ?g      <*   r      aR  if 1:
                from numpy.testing import assert_equal, assert_allclose
                res = lib.power(2, 7)
                assert res == 128
                res = lib.random(42)
                assert_allclose(res, %(expected)s)
                res = lib.spacing(1.0)
                assert_allclose(res, 2**-52)
                expected)rE   r=   cc_helperlibpowerrh   np
complex128sqrtfloat64np_sqrtspacingassertNotEqualrandomRandomStaterandom_samplesizerP   r   r4   rp   valr   rN   r   r   r   test_compile_helperlib   s,   



	"zTestCC.test_compile_helperlibc                 C   s   |  | jjR}| |dd |d}| t|g d tr-|	d}| |d t
g d}||}t
|}| || dttd	 }| || W d    d S 1 s\w   Y  d S )
Nrf   g        r   )r   r   r   r   g      >@)r   g      @r   g      @r   aB  if 1:
                from numpy.testing import assert_equal
                from numpy import float64, argsort
                res = lib.zero_scalar(1)
                assert res == 0.0
                res = lib.zeros(3)
                assert list(res) == [0, 0, 0]
                if %(has_blas)s:
                    res = lib.vector_dot(4)
                    assert res == 30.0
                val = float64([2., 5., 1., 3., 4.])
                res = lib.np_argsort(val)
                expected = argsort(val)
                assert_equal(res, expected)
                )r	   )rE   r=   cc_nrtrh   zero_scalarzerosrT   listr	   
vector_dotr   r   
np_argsortargsortdictrP   r   r   r   r   test_compile_nrt   s    



"zTestCC.test_compile_nrtc                 C   sv   |  | jj*}| }| |td |d}| |td d}| || W d    d S 1 s4w   Y  d S )NAzif 1:
                from numpy.testing import assert_equal
                res = lib.hash_literal_str_A()
                assert_equal(res, hash("A"))
                res = lib.hash_str("A")
                assert_equal(res, hash("A"))
                )rE   r=   r   hash_literal_str_Arh   hashhash_strrP   )r   r4   rp   rN   r   r   r   test_hashing   s   
"zTestCC.test_hashingc                 C   sb   |  | jj }tjdtjd}||}|| }| || W d    d S 1 s*w   Y  d S )Nr}   )dtype)rE   r=   r   r   arangeintpdict_usecaserh   )r   r4   arrgotexpectr   r   r   test_c_extension_usecase  s   
"zTestCC.test_c_extension_usecase)r   r   r   r'   r6   r7   rE   rP   r`   rq   rt   rw   rz   r   r   r   r   __classcell__r   r   r@   r   r8   Y   s    
	  r8   c                       sL   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	  Z
S )TestDistutilsSupportc                    sT   t    |   t  td| _tjt	d}tj| jd| _
t|| j
 d S )Ntest_pycc_distutilspycc_distutils_usecasework)r:   r'   r;   r   r   r#   r   r-   join	base_pathusecase_dirshutilcopytree)r   
source_dirr@   r   r   r'     s   

zTestDistutilsSupport.setUpc                       dd l }tjtjtj|j}ttj  ddr*|tj	  d   d< n| d<  fdd}||ddg d}|d	|g d S )
Nr   
PYTHONPATH c                    \   t jtjg|  jt jt j d}| \}}| }|dkr,	d|
dd  d S d S N)cwdstdoutstderrenvr   z+python failed with the following output:
%szutf-8ignorerK   Popenr,   rM   r   PIPESTDOUTcommunicatewaitfaildecodeargspout_rcr   r   r   r   
run_python&     

z7TestDistutilsSupport.check_setup_py.<locals>.run_python	build_ext	--inplacezif 1:
            import pycc_compiled_module as lib
            assert lib.get_const() == 42
            res = lib.ones(3)
            assert list(res) == [1.0, 1.0, 1.0]
            rG   
numbar   r-   abspathrH   rI   r   r   r   pathsepr   setup_py_filer   
numba_pathr   rN   r   r   r   check_setup_py     
z#TestDistutilsSupport.check_setup_pyc                    r   )
Nr   r   r   c                    r   r   r   r   r   r   r   r   F  r   z>TestDistutilsSupport.check_setup_nested_py.<locals>.run_pythonr   r   zif 1:
            import nested.pycc_compiled_module as lib
            assert lib.get_const() == 42
            res = lib.ones(3)
            assert list(res) == [1.0, 1.0, 1.0]
            rG   r   r   r   r   r   check_setup_nested_py;  r   z*TestDistutilsSupport.check_setup_nested_pyc                 C   rx   )Nzsetup_distutils.pyr   r&   r   r   r   test_setup_py_distutils[     z,TestDistutilsSupport.test_setup_py_distutilsc                 C   rx   )Nzsetup_distutils_nested.pyr   r&   r   r   r   test_setup_py_distutils_nested^  r   z3TestDistutilsSupport.test_setup_py_distutils_nestedc                 C   rx   )Nzsetup_setuptools.pyr   r&   r   r   r   test_setup_py_setuptoolsa  r   z-TestDistutilsSupport.test_setup_py_setuptoolsc                 C   rx   )Nzsetup_setuptools_nested.pyr   r&   r   r   r   test_setup_py_setuptools_nestedd  r   z4TestDistutilsSupport.test_setup_py_setuptools_nested)r   r   r   r'   r   r   r   r   r   r   r   r   r   r@   r   r   
  s      r   __main__)*r6   r>   r   r   rK   r,   r$   unittestr   ctypesnumpyr   llvmlite.bindingbindingru   
numba.corer   numba.tests.supportr   r   r   r   r	   r
   r   _skip_reasonskipIfr[   rZ   r    r-   rH   r   rI   r   r   r   r!   r8   r   r   mainr   r   r   r   <module>   sB    $  0\