o
    i                     @   s   d dl Z d dlZd dlmZ d dlm  m  mZ	 d dl
mZmZ d dlmZmZ d dlmZmZmZ d dlm  mZ d dlZe Zde_e ZeG dd deZed	kr^e  dS dS )
    N)jit)typeserrors)compile_isolatedFlags)TestCaseskip_unless_cffitagTc                   @   s   e Zd ZdZdd Zdd ZefddZdd	 Zd
d Z	dd Z
ef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d$d% Zd&d' Zd(d) Zd*d+ Zd,S )-TestCFFIFc                 C   s   t   t   d S N)modinitZinit_oolself r   d/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/numba/tests/test_cffi.pysetUp   s   zTestCFFI.setUpc                 C   s>   t tjtj}| t|jd | |jd t	j
 d S )N   r   )cffi_supportZmap_typer   ffiZtypeofcffi_sinassertEquallenargsr   double)r   	signaturer   r   r   test_type_map   s   zTestCFFI.test_type_mapc                 C   s:   t |tjg|d}|j}dD ]}| |||| qd S )Nflags)g333333r   g?gQ	@)r   r   r   entry_pointZassertPreciseEqual)r   pyfuncr   crescfuncxr   r   r   _test_function$   s
   zTestCFFI._test_functionc                 C      |  tj d S r   )r%   r   use_cffi_sinr   r   r   r   test_sin_function+      zTestCFFI.test_sin_functionc                 C   s:   t j}t|dtd}|j}| | d | | d d S )Nr   r   T)r   Zuse_cffi_boolean_truer   no_pyobj_flagsr    r   )r   r!   r"   r#   r   r   r   test_bool_function_ool.   s
   zTestCFFI.test_bool_function_oolc                 C      | j tjtd d S Nr   )r%   r   r'   r*   r   r   r   r   test_sin_function_npm5      zTestCFFI.test_sin_function_npmc                 C   r&   r   )r%   r   use_cffi_sin_ool)r   r   r   r   r   test_sin_function_ool8   r)   zTestCFFI.test_sin_function_oolc                 C   r,   r-   )r%   r   r0   r*   r   r   r   r   test_sin_function_npm_ool;   r/   z"TestCFFI.test_sin_function_npm_oolc                 C   r&   r   )r%   r   Zuse_two_funcsr   r   r   r   test_two_funcs>   s   zTestCFFI.test_two_funcsc                 C   r&   r   )r%   r   Zuse_two_funcs_oolr   r   r   r   test_two_funcs_oolB   r)   zTestCFFI.test_two_funcs_oolc                 C   s   t j}td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 ]\}}}||||}||||}| || qT| t|j	d|j	 d S )NTZnopythong      ?g      r   )
r   Zuse_func_pointerr   r   Zcffi_cosZcffi_sin_oolZcffi_cos_oolr   r   Z	overloads)r   r!   r#   faZfbr$   expectedgotr   r   r   test_function_pointerE   s&   zTestCFFI.test_function_pointerc                 C   s(   t j}tdd|}| | |  d S )NTr5   )r   Zuse_user_defined_symbolsr   r   )r   r!   r#   r   r   r   test_user_defined_symbols[   s   z"TestCFFI.test_user_defined_symbolsc                 C   s"   ||| t j|t | d S r   )nptestingassert_allclosesin)r   r#   r$   yr   r   r   check_vector_sin`   s   
zTestCFFI.check_vector_sinc                 C   s:   t d|}t |}tdd|}| ||| d S )N
   Tr5   )r;   arangeastype
zeros_liker   r@   )r   r!   dtyper$   r?   r#   r   r   r   _test_from_buffer_numpy_arrayd   s   
z&TestCFFI._test_from_buffer_numpy_arrayc                 C      |  tjtj d S r   )rF   r   vector_sin_float32r;   float32r   r   r   r   test_from_buffer_float32j   r/   z!TestCFFI.test_from_buffer_float32c                 C   rG   r   )rF   r   Zvector_sin_float64r;   Zfloat64r   r   r   r   test_from_buffer_float64m   r/   z!TestCFFI.test_from_buffer_float64c                 C   s   d}t |t |d |d d  }t |}tddtj}||| t j|j| tddtj	}||| t j|j
| d S )NrA         y              ?Tr5   )r;   rB   Zzerosr   r   Zvector_extract_realr<   Zassert_equalrealZvector_extract_imagimag)r   nr$   r?   Z
real_cfuncZ
imag_cfuncr   r   r   test_from_buffer_structp   s   "


z TestCFFI.test_from_buffer_structc                 C   sL   t j}tdd|}tdtd}tddgt| }| ||| d S )NTr5   frA   r   )r   rH   r   arrayranger   r@   )r   r!   r#   r$   r?   r   r   r   test_from_buffer_pyarray{   s
   z!TestCFFI.test_from_buffer_pyarrayc                 C   s   t j}tdd|}tdtjd d d }t|}| t	j
}||| W d    n1 s3w   Y  | dt|j d S )NTr5   rA   rL   z3from_buffer() unsupported on non-contiguous buffers)r   rH   r   r;   rB   rC   rI   rD   assertRaisesr   TypingErrorassertInstr	exception)r   r!   r#   r$   r?   raisesr   r   r   test_from_buffer_error   s   
zTestCFFI.test_from_buffer_errorc                 C   sR  t jddgdt jd}t |}t jddgddggdt jd}t |}t jddgdt jd}t |}t jddgddggdt jd}t |}|d}	tj}
td	d
|
}| ||| ||| t 	|}ddg|d< t j
|| | ||| | tj}||| W d    n1 sw   Y  t j
||	 | dt|j d S )Nr   rL   C)orderrE   rM      FKTr5   r   zAfrom_buffer() only supports multidimensional arrays with C layout)r;   rS   rI   rD   copyr   rH   r   r@   r>   r<   r=   rV   r   rW   rX   rY   rZ   )r   c1Zc1_zerosc2Zc2_zerosf1Zf1_zerosf2Zf2_zerosZf2_copyr!   r#   Zsin_c2r[   r   r   r   "test_from_buffer_numpy_multi_array   s0   






z+TestCFFI.test_from_buffer_numpy_multi_arrayc                    s\   t jtddfdd tdd fdd}d}| ||||d   d	S )
zj
        Issue #2263

        Linkage error due to multiple definition of global tracking symbol.
        Tr5   c                    s    | S r   r   r$   )my_sinr   r   inner   s   z2TestCFFI.test_indirect_multiple_use.<locals>.innerc                    s    | | d  S )Nr   r   rh   rj   ri   r   r   foo   s   z0TestCFFI.test_indirect_multiple_use.<locals>.foog+?r   N)r   r   r   r   )r   rl   r$   r   rk   r   test_indirect_multiple_use   s   $z#TestCFFI.test_indirect_multiple_useN)__name__
__module____qualname__Z_numba_parallel_test_r   r   enable_pyobj_flagsr%   r(   r+   r.   r1   r2   r3   r4   r9   r:   r@   rF   rJ   rK   rQ   rU   r\   rg   rm   r   r   r   r   r
      s.    r
   __main__)rS   numpyr;   Znumbar   Znumba.core.typing.cffi_utilscoretypingZ
cffi_utilsr   Z
numba.corer   r   Znumba.core.compilerr   r   Znumba.tests.supportr   r   r	   Znumba.tests.cffi_usecasestestsZcffi_usecasesr   Zunittestrq   Zenable_pyobjectr*   r
   rn   mainr   r   r   r   <module>   s$     ,