
    J/Phc3                     *   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 d dlZdZ ej        ej                            d           e          Zej                            ej                            e                     Z!d Z"e G d	 d
e                      Z# G d de          Z$e G d de$                      Z%e G d de                      Z&e'dk    r ej(                     dS dS )    N)skip)*)utils)TestCasetagimport_dynamictemp_directoryhas_blasneeds_setuptoolszwindows onlywinc                  @    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     U/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/tests/test_pycc.pyunset_macosx_deployment_targetr      s*     "RZ//J1222 0/r   c                   $    e Zd Zed             ZdS )TestCompilerChecksc                     ddl m} t          j                            dd           d u}|r?t          j                            dd           !|                      |                       d S d S d S )Nr   )external_compiler_worksCONDA_BUILDVSINSTALLDIR)numba.pycc.platformr   r   r   get
assertTrue)selfr   is_running_conda_builds      r   test_windows_compiler_validityz1TestCompilerChecks.test_windows_compiler_validity*   s     	@?????!#t!D!DD!P! 	;z~~nd33? 7 7 9 9:::::	; 	;??r   N)__name__
__module____qualname___windows_onlyr    r   r   r   r   r   &   s/         ; ; ]; ; ;r   r   c                   :    e Zd Zd Zd Zej        d             ZdS )BasePYCCTestc                 l    t                       t          d          | _        | j        t          _        d S )N	test_pycc)r   r	   tmpdirtempfiletempdirr   s    r   setUpzBasePYCCTest.setUp;   s/    &((($[11  ;r   c                 >    d t           _        ddlm}  |             d S )Nr   )clear_export_registry)r*   r+   numba.pycc.decoratorsr/   )r   r/   s     r   tearDownzBasePYCCTest.tearDownC   s4     	@?????r   c              #   v  K   t           j                            |           	 t          |          }|V  t           j                            |           t           j                            |d            d S # t           j                            |           t           j                            |d            w xY wN)syspathappendr   removemodulespop)r   extdirnamelibs       r   check_c_extzBasePYCCTest.check_c_extN   s      	( &&CIIIHOOF###KOOD$''''' HOOF###KOOD$''''s   A7 7AB8N)r!   r"   r#   r-   r1   
contextlibcontextmanagerr=   r   r   r   r&   r&   9   sQ        ' ' '	  	  	  ( ( ( ( (r   r&   c                   z     e Zd Z fdZej        d             Zd Zd Zd Z	d Z
d Zd Zd	 Zd
 Zd Zd Z xZS )TestCCc                     t          t          |                                            |                                  ddlm} || _        t          j        | j                   d S )Nr   )compile_with_pycc)	superrA   r-   skip_if_no_external_compilernumba.testsrC   _test_module	importlibreload)r   rC   	__class__s     r   r-   zTestCC.setUp\   se    fd!!###))+++111111-*+++++r   c              #      K   | j         |_        |                                 |                     | j         |j                  5 }|V  d d d            d S # 1 swxY w Y   d S r3   )r)   
output_dircompiler=   r;   )r   ccr<   s      r   check_cc_compiledzTestCC.check_cc_compiledc   s       


dk2733 	sIII	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAc                     d|j         t          j                            |j                  dz  }|                    d          |z   }t          j        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
            )r;   r5    -c)
r!   r   r5   dirname__file__strip
subprocess
check_callr4   
executable)r   r<   codeprologs       r   check_cc_compiled_in_subprocessz&TestCC.check_cc_compiled_in_subprocessl   sj     <7??3<88: ::  ||C  4's~tT:;;;;;r   c                    | j         j        }|                     |j        d           | j         j        j        }|                     t          j                            |          |           | j         j        j	        }| 
                    t          j                            |          |           |                     t          j                            |                              d          |           t          j                            d          rO|                     |                    d          |           ddlm} |                      |            |           d S d S )Npycc_test_simplezpycc_test_simple.linuxz.sor   )find_pyext_ending)rG   rN   assertEqualr;   rL   r   r   r5   isdiroutput_fileassertFalseexistsbasename
startswithr4   platformendswithr   r_   assertIn)r   rN   dfr_   s        r   test_cc_propertieszTestCC.test_cc_properties   s9   !"4555  +a((!,,,  ,**A...((++667JKKQOOO<""7++ 	2OOAJJu--q111 >=====MM++--q11111	2 	2r   c                 \   |                      | j        j                  5 }|                    dd          }|                     |d           |                    dd          }|                     |d           |                    d          }|                     |d           |                     |                                d            | 	                    t                    5  |                    dd	           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )
N{   A  ;  i  g    lVA         r   )rO   rG   rN   multiassertPreciseEqualmultfsquareassertIsget_noneassertRaisesZeroDivisionErrordiv)r   r<   ress      r   test_compilezTestCC.test_compile   s   ##D$5$899 		S))C%%C##C333))C%%C##C777**Q--C##C,,,MM#,,..$///""#455  1              		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		s6   CD!&D	=D!	D	D!D	D!!D%(D%c                     | j         j        }||_        |                     |          5 }|                    dd          }|                     |d           |                     |j        j        d           d d d            d S # 1 swxY w Y   d S )Nrn   ro   rp   r]   )rG   rN   
target_cpurO   rt   ru   r`   r"   )r   cpu_namerN   r<   r}   s        r   check_compile_for_cpuzTestCC.check_compile_for_cpu   s    ! ##B'' 	G3))C%%C##C333SY13EFFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	Gs   ABB
Bc                 R    |                      t          j                               d S r3   )r   llget_host_cpu_namer,   s    r   test_compile_for_cpuzTestCC.test_compile_for_cpu   s%    ""2#7#9#9:::::r   c                 0    |                      d           d S )Nhost)r   r,   s    r   test_compile_for_cpu_hostz TestCC.test_compile_for_cpu_host   s    ""6*****r   c                 $   |                      | j        j                  5 }|                    dd          }|                     |d           ddt          j        d          fD ]-}|                    |          }|                     |d           .ddt          j        d          fD ]-}|	                    |          }|                     |d	           .|
                    d
          }|                     |d           |                     |                    d          |                    d                     |                    d          }t
          j                            d                                          }|                     ||           |                    t          j        dgdz                      }|                     |d           dd|iz  }|                     ||           d d d            d S # 1 swxY w 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)rO   rG   cc_helperlibpowerru   np
complex128sqrtfloat64np_sqrtspacingassertNotEqualrandomRandomStaterandom_samplesizer[   r   r<   r}   valr   rY   s         r   test_compile_helperlibzTestCC.test_compile_helperlib   s2   ##D$5$BCC 	<s))Aq//C##C---GR]2%6%67 1 1hhsmm''R00003
1. 2 2kk#&&''S1111++c""C##C000 

2

2???**R..Cy,,R00>>@@H##C222((2:qcAg..//C##C+++ "8,-D 00d;;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s   GHH	H	c                    |                      | j        j                  5 }|                     |                    d          d           |                    d          }|                     t          |          g d           t          r+|	                    d          }|                     |d           t          j        g d          }|                    |          }t          j        |          }|                     ||           dt          t          	          z  }|                     ||           d d d            d S # 1 swxY w Y   d S )
Nrs   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
   )rO   rG   cc_nrtru   zero_scalarzerosr`   listr
   
vector_dotr   r   
np_argsortargsortdictr[   r   s         r   test_compile_nrtzTestCC.test_compile_nrt   s{   ##D$5$<== 	<##COOA$6$6<<<))A,,CT#YY			222 3nnQ''''T222*11122C..%%Cz#H##C222 H---.D 00d;;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s   DEE
E
c                    |                      | j        j                  5 }|                                }|                     |t          d                     |                    d          }|                     |t          d                     d}|                     ||           d d d            d S # 1 swxY w 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"))
                )rO   rG   r   hash_literal_str_Aru   hashhash_strr[   )r   r<   r}   rY   s       r   test_hashingzTestCC.test_hashing   s    ##D$5$<== 	<((**C##Cc333,,s##C##Cc333D 00d;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s   BB55B9<B9c                    |                      | j        j                  5 }t          j        dt          j                  }|                    |          }||z  }|                     ||           d d d            d S # 1 swxY w Y   d S )Nr   )dtype)rO   rG   r   r   arangeintpdict_usecaseru   )r   r<   arrgotexpects        r   test_c_extension_usecasezTestCC.test_c_extension_usecase   s    ##D$5$<== 	1)Crw///C""3''C3YF##C000		1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1s   AA>>BB)r!   r"   r#   r-   r>   r?   rO   r[   rl   r~   r   r   r   r   r   r   r   __classcell__rJ   s   @r   rA   rA   Y   s        , , , , ,   < < <(2 2 2&
 
 
G G G; ; ;+ + +< < <@< < <@< < < 1 1 1 1 1 1 1r   rA   c                   B     e Zd Z fdZd Zd Zd Zd Zd Zd Z	 xZ
S )TestDistutilsSupportc                    t                                                       |                                  t                       t	          d          | _        t          j                            t          d          }t          j                            | j        d          | _
        t          j        || j
                   d S )Ntest_pycc_distutilspycc_distutils_usecasework)rD   r-   rE   r   r	   r)   r   r5   join	base_pathusecase_dirshutilcopytree)r   
source_dirrJ   s     r   r-   zTestDistutilsSupport.setUp  s    ))+++&((( %%:;;W\\)-EFF
7<<V<<
D$455555r   c                     dd l }t          j                            t          j                            t          j                            |j                                      }t          t          j                                      dd          r|t          j	        z   d         z   d<   n|d<    fd} ||ddg           d} |d|g           d S )	Nr   
PYTHONPATH c                 F   t          j        t          j        g| z   j        t           j        t           j                  }|                                \  }}|                                }|dk    r.	                    d|
                    dd          z             d S d S N)cwdstdoutstderrenvr   z+python failed with the following output:
%szutf-8ignorerV   Popenr4   rX   r   PIPESTDOUTcommunicatewaitfaildecodeargspout_rcr   r   s        r   
run_pythonz7TestDistutilsSupport.check_setup_py.<locals>.run_python$       #.!1D!8%)%5(2(2(9%(	* * *A
 ]]__FCBQww		HJJw99: ; ; ; ; ; wr   	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]
            rR   
numbar   r5   abspathrS   rT   r   r   r   pathsepr   setup_py_filer   
numba_pathr   rY   r   s   `     @r   check_setup_pyz#TestDistutilsSupport.check_setup_py      W__RW__%'W__U^%D%D&F &F G G
2:77<$$ 	+ *RZ 7#l:K KC *C
	; 
	; 
	; 
	; 
	; 
	; 	
M;<=== 	
D$<     r   c                     dd l }t          j                            t          j                            t          j                            |j                                      }t          t          j                                      dd          r|t          j	        z   d         z   d<   n|d<    fd} ||ddg           d} |d|g           d S )	Nr   r   r   c                 F   t          j        t          j        g| z   j        t           j        t           j                  }|                                \  }}|                                }|dk    r.	                    d|
                    dd          z             d S d S r   r   r   s        r   r   z>TestDistutilsSupport.check_setup_nested_py.<locals>.run_pythonD  r   r   r   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]
            rR   r   r   s   `     @r   check_setup_nested_pyz*TestDistutilsSupport.check_setup_nested_py9  r   r   c                 0    |                      d           d S )Nzsetup_distutils.pyr   r,   s    r   test_setup_py_distutilsz,TestDistutilsSupport.test_setup_py_distutilsY  s    011111r   c                 0    |                      d           d S )Nzsetup_distutils_nested.pyr   r,   s    r   test_setup_py_distutils_nestedz3TestDistutilsSupport.test_setup_py_distutils_nested\  s    ""#>?????r   c                 0    |                      d           d S )Nzsetup_setuptools.pyr   r,   s    r   test_setup_py_setuptoolsz-TestDistutilsSupport.test_setup_py_setuptools_  s    122222r   c                 0    |                      d           d S )Nzsetup_setuptools_nested.pyr   r,   s    r   test_setup_py_setuptools_nestedz4TestDistutilsSupport.test_setup_py_setuptools_nestedb  s    ""#?@@@@@r   )r!   r"   r#   r-   r   r   r   r   r   r   r   r   s   @r   r   r   	  s        6 6 6 6 6! ! !@! ! !@2 2 2@ @ @3 3 3A A A A A A Ar   r   __main__))r>   rH   r   r   rV   r4   r*   unittestr   ctypesnumpyr   llvmlite.bindingbindingr   
numba.corer   numba.tests.supportr   r   r   r	   r
   r   _skip_reasonskipIfrg   rf   r$   r5   rS   r   rT   r   r   r   r&   rA   r   r!   mainr   r   r   <module>r
     sj           				      



                           = = = = = = = = = = = = = = = =  CL$;$;E$B$B B ,. . GOOBGOOH5566	3 3 3 ; ; ; ; ; ; ; ;$( ( ( ( (8 ( ( (@ l1 l1 l1 l1 l1\ l1 l1 l1^ YA YA YA YA YA8 YA YA YAx zHMOOOOO r   