
    wi.:              	          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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e G d	 d
e                                  Z&e G d de                      Z'eee G d de'                                              Z(eee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_setuptoolsskip_if_py313plus_on_windowsskip_if_linux_aarch64skip_if_freethreadingz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     e/root/.openclaw/workspace/chatterbox_venv_py311/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.decoratorsr2   )r!   r2   s     r   tearDownzBasePYCCTest.tearDownF   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_extQ   s      	( &&CIIIHOOF###KOOD$''''' HOOF###KOOD$''''s   A7 7AB8N)r$   r%   r&   r0   r4   
contextlibcontextmanagerr@   r   r   r   r)   r)   ;   sQ        ' ' '	  	  	  ( ( ( ( (r   r)   c                        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d Z xZS )TestCCc                     t          t          |                                            |                                  ddlm} || _        t          j        | j                   d S )Nr   )compile_with_pycc)	superrD   r0   skip_if_no_external_compilernumba.testsrF   _test_module	importlibreload)r!   rF   	__class__s     r   r0   zTestCC.setUpa   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 r6   )r,   
output_dircompiler@   r>   )r!   ccr?   s      r   check_cc_compiledzTestCC.check_cc_compiledh   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>   r8    -c)
r$   r   r8   dirname__file__strip
subprocess
check_callr7   
executable)r!   r?   codeprologs       r   check_cc_compiled_in_subprocessz&TestCC.check_cc_compiled_in_subprocessq   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)rJ   rQ   assertEqualr>   rO   r    r   r8   isdiroutput_fileassertFalseexistsbasename
startswithr7   platformendswithr   rb   assertIn)r!   rQ   dfrb   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   )rR   rJ   rQ   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 )Nrq   rr   rs   r`   )rJ   rQ   
target_cpurR   rw   rx   rc   r%   )r!   cpu_namerQ   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 r6   )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)rR   rJ   cc_helperlibpowerrx   np
complex128sqrtfloat64np_sqrtspacingassertNotEqualrandomRandomStaterandom_samplesizer^   r!   r?   r   valr   r\   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 )
Nrv   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
   )rR   rJ   cc_nrtrx   zero_scalarzerosrc   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"))
                )rR   rJ   r   hash_literal_str_Arx   hashhash_strr^   )r!   r?   r   r\   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)rR   rJ   r   r   arangeintpdict_usecaserx   )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c                    |                      | j        j                  5 }t          j        dt          j                  }t          j        dt          j                  }|                    ||           |                     ||           t          j        dt          j                  }|	                    ||           |                     ||           t          j        dt          j                  }t          j        dt          j                  }| 
                    t                    5 }|                    ||           ddd           n# 1 swxY w Y   |                     d|j         d|j         t          |j                             t          j        dt          j                  }t          j        dt          j                  }| 
                    t                    5 }|	                    ||           ddd           n# 1 swxY w Y   |                     d|j         d|j         t          |j                             ddd           dS # 1 swxY w Y   dS )	zSee https://github.com/numba/numba/issues/9948

        Dynamic exception uses a symbol that in PYCC compilation must become
        linkonce_odr linkage to prevent symbol collision.
        )r   r   r   )r   r   Nzcannot assign slice of shape z from input of shape )r      )r   rt   )rR   rJ   	cc_dynexcr   r   r   onesdo_setitem1rx   do_setitem2r}   
ValueErrorrl   shapestr	exception)r!   r?   abraisess        r   test_dynamic_exczTestCC.test_dynamic_exc  s    ##D$5$?@@ 	'Crz222Abj111AOOAq!!!##Aq)))rz222AOOAq!!!##Aq))) rz222Abj111A"":.. &&1%%%& & & & & & & & & & & & & & & MM, , ,"#', ,F$%%' ' '
 rz222Abj111A"":.. &&1%%%& & & & & & & & & & & & & & & MM, , ,"#', ,F$%%' ' '7	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	's[   DI&3E
I&E	I&E	BI&3H
I&H	I&H	;I&&I*-I*)r$   r%   r&   r0   rA   rB   rR   r^   ro   r   r   r   r   r   r   r   r   r   __classcell__rM   s   @r   rD   rD   \   s       
, , , , ,   < < <(2 2 2&
 
 
G G G; ; ;+ + +< < <@< < <@< < < 1 1 1$' $' $' $' $' $' $'r   rD   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)rG   r0   rH   r   r	   r,   r   r8   join	base_pathusecase_dirshutilcopytree)r!   
source_dirrM   s     r   r0   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rY   Popenr7   r[   r   PIPESTDOUTcommunicatewaitfaildecodeargspout_rcr   r!   s        r   
run_pythonz7TestDistutilsSupport.check_setup_py.<locals>.run_pythonR       #.!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]
            rU   
numbar   r8   abspathrV   rW   r   r   r   pathsepr!   setup_py_filer   
numba_pathr   r\   r   s   `     @r   check_setup_pyz#TestDistutilsSupport.check_setup_pyG      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_pythonr  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]
            rU   r   r   s   `     @r   check_setup_nested_pyz*TestDistutilsSupport.check_setup_nested_pyg  r  r   c                 0    |                      d           d S )Nzsetup_distutils.pyr  r/   s    r   test_setup_py_distutilsz,TestDistutilsSupport.test_setup_py_distutils  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_nested  s    ""#?@@@@@r   )r$   r%   r&   r0   r  r  r	  r  r  r  r   r   s   @r   r   r   4  s        6 6 6 6 6! ! !@! ! !@2 2 2@ @ @3 3 3A A A A A A Ar   r   __main__),rA   rK   r   r   rY   r7   r-   unittestr   ctypesnumpyr   llvmlite.bindingbindingr   
numba.corer   numba.tests.supportr   r   r   r	   r
   r   r   r   r   _skip_reasonskipIfrj   ri   r'   r8   rV   r   rW   r   r   r   r)   rD   r   r$   mainr   r   r   <module>r     s           				      



                           O O O O O O O O O O O O O O O O O O O O O O  CL$;$;E$B$B B ,. . GOOBGOOH5566	3 3 3 ; ; ; ; ; ; ;  ;$ ( ( ( ( (8 ( ( (@ R' R' R' R' R'\ R' R'   R'j YA YA YA YA YA8 YA YA    YAx zHMOOOOO r   