
    ܙd9                     <   d dl Z d dlZd dlmZ d dlmc mc mZ	 d dl
mZmZ d dlmZmZ d dlmZmZ d dlmc mZ d dlZ e            Zde_         e            Z ej        e	j        d           G d d	e                      Zed
k    r ej                     dS dS )    N)jit)typeserrors)compile_isolatedFlags)TestCasetagTz4CFFI not supported -- please install the cffi modulec                       e Zd ZdZd Zd ZefdZd Zd Z	d Z
efdZd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )TestCFFIFc                 R    t          j                     t          j                     d S N)modinitinit_oolselfs    5lib/python3.11/site-packages/numba/tests/test_cffi.pysetUpzTestCFFI.setUp   s    


    c                 "   t          j        t          j                            t          j                            }|                     t          |j                  d           |                     |j        d         t          j
                   d S )N   r   )cffi_supportmap_typer   ffitypeofcffi_sinassertEquallenargsr   double)r   	signatures     r   test_type_mapzTestCFFI.test_type_map    sg     )#'..*F*FGG	Y^,,a000*EL99999r   c                     t          |t          j        g|          }|j        }dD ]*}|                      ||           ||                     +d S )Nflags)g333333r   g?gQ	@)r   r   r    entry_pointassertPreciseEqual)r   pyfuncr%   crescfuncxs         r   _test_functionzTestCFFI._test_function%   sd    eDDD ) 	9 	9A##FF1IIuuQxx8888	9 	9r   c                 D    |                      t          j                   d S r   )r-   r   use_cffi_sinr   s    r   test_sin_functionzTestCFFI.test_sin_function,   s    C,-----r   c                     t           j        }t          |dt                    }|j        }|                      |            d           |                      |            d           d S )N r$   T)r   use_cffi_boolean_truer   no_pyobj_flagsr'   r   )r   r)   r*   r+   s       r   test_bool_function_oolzTestCFFI.test_bool_function_ool/   sd    *.AAA 4((($'''''r   c                 R    |                      t          j        t                     d S Nr$   )r-   r   r/   r4   r   s    r   test_sin_function_npmzTestCFFI.test_sin_function_npm6   s$    C,NCCCCCr   c                 D    |                      t          j                   d S r   )r-   r   use_cffi_sin_ool)r   r%   s     r   test_sin_function_oolzTestCFFI.test_sin_function_ool9   s    C011111r   c                 R    |                      t          j        t                     d S r7   )r-   r   r:   r4   r   s    r   test_sin_function_npm_oolz"TestCFFI.test_sin_function_npm_ool<   s$    C0GGGGGr   c                 D    |                      t          j                   d S r   )r-   r   use_two_funcsr   s    r   test_two_funcszTestCFFI.test_two_funcs?   s    C-.....r   c                 D    |                      t          j                   d S r   )r-   r   use_two_funcs_oolr   s    r   test_two_funcs_oolzTestCFFI.test_two_funcs_oolC   s    C122222r   c                 ^   t           j        } t          d          |          }t           j        t           j        dft           j        t           j        dft           j        t           j        dft           j        t           j        dft           j        t           j        dft           j        t           j        dft           j        t           j        dft           j        t           j        dft           j        t           j        dft           j        t           j        dft           j        t           j        dft           j        t           j        dffD ]6\  }}} ||||          } ||||          }|                     ||           7|                     t          |j	                  d|j	                   d S )NTnopythong      ?g      r   )
r   use_func_pointerr   r   cffi_coscffi_sin_oolcffi_cos_oolr   r   	overloads)r   r)   r+   fafbr,   expectedgots           r   test_function_pointerzTestCFFI.test_function_pointerF   sZ   %"T"""6**\3<-\3<.\3<-\3<.s/5s/6s/5s/6\3+S1\3+T2\3+S1\3+T24 	, 	,KRQ vb"a((H%B""CS(++++U_--q%/BBBBBr   c                     t           j        } t          d          |          }|                      |             |                       d S )NTrE   )r   use_user_defined_symbolsr   r   )r   r)   r+   s      r   test_user_defined_symbolsz"TestCFFI.test_user_defined_symbols\   sL    -"T"""6**5577+++++r   c                      |||           t           j                            |t          j        |                     d S r   )nptestingassert_allclosesin)r   r+   r,   ys       r   check_vector_sinzTestCFFI.check_vector_sina   s7    a

""1bfQii00000r   c                     t          j        d                              |          }t          j        |          } t	          d          |          }|                     |||           d S )N
   TrE   )rU   arangeastype
zeros_liker   rZ   )r   r)   dtyper,   rY   r+   s         r   _test_from_buffer_numpy_arrayz&TestCFFI._test_from_buffer_numpy_arraye   sd    IbMM  ''M!"T"""6**eQ*****r   c                 Z    |                      t          j        t          j                   d S r   )ra   r   vector_sin_float32rU   float32r   s    r   test_from_buffer_float32z!TestCFFI.test_from_buffer_float32k   #    **3+A2:NNNNNr   c                 Z    |                      t          j        t          j                   d S r   )ra   r   vector_sin_float64rU   float64r   s    r   test_from_buffer_float64z!TestCFFI.test_from_buffer_float64n   rf   r   c                    d}t          j        |          t          j        |dz  |dz            dz  z   }t          j        |          } t          d          t          j                  } |||           t           j                            |j        |            t          d          t          j	                  } |||           t           j                            |j
        |           d S )Nr\         y              ?TrE   )rU   r]   zerosr   r   vector_extract_realrV   assert_equalrealvector_extract_imagimag)r   nr,   rY   
real_cfunc
imag_cfuncs         r   test_from_buffer_structz TestCFFI.test_from_buffer_structq   s    IaLL29QUAE22R77HQKK'S$'''(?@@

1a

***'S$'''(?@@

1a

*****r   c                    t           j        } t          d          |          }t          j        dt	          d                    }t          j        ddgt          |          z            }|                     |||           d S )NTrE   fr\   r   )r   rc   r   arrayranger   rZ   )r   r)   r+   r,   rY   s        r   test_from_buffer_pyarrayz!TestCFFI.test_from_buffer_pyarray|   sv    '"T"""6**KU2YY''KaS3q66\**eQ*****r   c                    t           j        } t          d          |          }t          j        d                              t          j                  d d d         }t          j        |          }|                     t          j
                  5 } |||           d d d            n# 1 swxY w Y   |                     dt          |j                             d S )NTrE   r\   rl   z3from_buffer() unsupported on non-contiguous buffers)r   rc   r   rU   r]   r^   rd   r_   assertRaisesr   TypingErrorassertInstr	exception)r   r)   r+   r,   rY   raisess         r   test_from_buffer_errorzTestCFFI.test_from_buffer_error   s   '"T"""6**IbMM  ,,SSqS1M!v122 	fE!QKKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	K&*++	- 	- 	- 	- 	-s   B,,B03B0c                 B   t          j        ddgdt           j                  }t          j        |          }t          j        ddgddggdt           j                  }t          j        |          }t          j        ddgdt           j                  }t          j        |          }t          j        ddgddggdt           j                  }t          j        |          }|                    d          }	t
          j        }
 t          d	
          |
          }|                     |||            |||           t          j	        |          }ddg|d<   t           j
                            ||           |                     |||           |                     t          j                  5 } |||           d d d            n# 1 swxY w Y   t           j
                            ||	           |                     dt!          |j                             d S )Nr   rl   C)orderr`   rm      FKTrE   r   zAfrom_buffer() only supports multidimensional arrays with C layout)rU   rz   rd   r_   copyr   rc   r   rZ   rX   rV   rW   r~   r   r   r   r   r   )r   c1c1_zerosc2c2_zerosf1f1_zerosf2f2_zerosf2_copyr)   r+   sin_c2r   s                 r   "test_from_buffer_numpy_multi_arrayz+TestCFFI.test_from_buffer_numpy_multi_array   s)   Xq!fCrz:::=$$X1v1v&cDDD=$$Xq!fCrz:::=$$X1v1v&cDDD=$$''#,,'"T"""6**eR222b(Fq	

""8V444eR222v122 	 fE"h	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 

""2w///Y&*++	- 	- 	- 	- 	-s   3GGGc                    t           j        t          d          fd            t          d          fd            }d}|                      ||           |           |dz             z              dS )zj
        Issue #2263

        Linkage error due to multiple definition of global tracking symbol.
        TrE   c                      |           S r   r2   )r,   my_sins    r   innerz2TestCFFI.test_indirect_multiple_use.<locals>.inner   s    6!99r   c                 8     |            | dz             z   S )Nr   r2   )r,   r   r   s    r   fooz0TestCFFI.test_indirect_multiple_use.<locals>.foo   s"    588ffQUmm++r   g+?r   N)r   r   r   r   )r   r   r,   r   r   s      @@r   test_indirect_multiple_usez#TestCFFI.test_indirect_multiple_use   s      
d				 	 	 	 
		 
d				, 	, 	, 	, 	, 
		, QVVAE]]!:;;;;;r   N)__name__
__module____qualname___numba_parallel_test_r   r"   enable_pyobj_flagsr-   r0   r5   r8   r;   r=   r@   rC   rP   rS   rZ   ra   re   rj   rw   r|   r   r   r   r2   r   r   r   r      sz        "  : : :
 ,> 9 9 9 9. . .( ( (D D D += 2 2 2 2H H H/ / /3 3 3C C C,, , ,
1 1 1+ + +O O OO O O	+ 	+ 	++ + +	- 	- 	-- - -8< < < < <r   r   __main__) rz   numpyrU   numbar   numba.core.typing.cffi_utilscoretyping
cffi_utilsr   
numba.corer   r   numba.core.compilerr   r   numba.tests.supportr   r	   numba.tests.cffi_usecasestestscffi_usecasesr   unittestr   enable_pyobjectr4   
skipUnless	SUPPORTEDr   r   mainr2   r   r   <module>r      sa              3 3 3 3 3 3 3 3 3 3 3 3 $ $ $ $ $ $ $ $ 7 7 7 7 7 7 7 7 - - - - - - - - ' ' ' ' ' ' ' ' '  UWW %)  " \+KM Mh< h< h< h< h<x h< h<M Mh<V zHMOOOOO r   