o
    i                     @   s   d dl Zd dlmZmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlZejZejdeddd	Ze Zejd
dZejdedddddddddf Zdd Zdd Zdd Zdd ZegZG dd deZG dd deZedkr~e  dS dS )    N)float32jitnjit)	Vectorize)TypingError)TestCaseP   )dtype   
   F)orderi@           c                 C   s   | | S N )abr   r   n/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/numba/tests/npyufunc/test_ufunc.pyadd   s   r   c                 C   s   | | | | S r   r   )r   r   cdr   r   r   add_multiple_args   s   r   c                 C   s0   d}t | jd D ]}|| | ||  7 }q	|S )Ng        r   )rangeshape)r   r   resultir   r   r   
gufunc_add   s   r   c                 C   s   t |jD ]}| |}q|S r   )r   ndimreduce)ufuncargr   r   r   r   ufunc_reduce!   s   r#   c                   @   sD   e Z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 )
TestUFuncsc                 G   s   |t g|R  }| ttt | }||jf}| j||||| |d | jt||t||d | j||tj ||d | j|	||tj 	|||d dS )zTest ufunc attributesmsgN)
r   r   build_ufuncr   assertPreciseEqualr#   npsum
accumulateouter)selfclsr   r   args
vectorizerr!   infor   r   r   _test_ufunc_attributes2   s   
&z!TestUFuncs._test_ufunc_attributesc           	      C   sX   |t }|ttttt | }||jf}| j||||||| | | |d dS )zTest multiple argsr%   N)r   r   r   r'   r   r(   )	r-   r.   r   r   r   r   r0   r!   r1   r   r   r   _test_broadcasting?   s
   
*zTestUFuncs._test_broadcastingc              
   C   s|   t D ]}| |td td  qt D ]	}| |tt qt D ]}| |td d tjd d f ttjd d d d f  qd S Nr   )vectorizersr2   r   r   r)   newaxisr-   vr   r   r   test_ufunc_attributesH   s   z TestUFuncs.test_ufunc_attributesc                 C   s   t D ]}| |td td td td  qt D ]}| |tttt qt D ]3}| |td d tjd d f ttjd d d d f td d tjd d f ttjd d d d f  q&d S r4   )r5   r3   r   r   r   r   r)   r6   r7   r   r   r   test_broadcastingQ   s   $2,zTestUFuncs.test_broadcastingc                 C   sd   t D ]-}|t}|ttt | }ttjd d tjtjd d f }| |t|t|  qd S r   )	r5   r   r   r'   r   r)   r6   r(   r   )r-   r8   r0   r!   Zbroadcasting_br   r   r   test_implicit_broadcastingZ   s    z%TestUFuncs.test_implicit_broadcastingc           	   	   C   s   t d}d|j_g }d}|tddt|f |tddtdf |D ]-\}}}dd	 }| |}||| W d    n1 sDw   Y  | 	|t
|j q%d S )
Nr   Fz<ufunc 'sin' called with an explicit output that is read-onlyT)Znopython)Zforceobjzoutput array is read-onlyc                 S   s    t | j| j}t ||  d S r   )r)   onesr   r	   sin)xr   r   r   r   testo   s   zBTestUFuncs.test_ufunc_exception_on_write_to_readonly.<locals>.test)r)   r<   flagsZ	writeableappendr   r   
ValueErrorassertRaisesassertInstr	exception)	r-   ztestsexpectdecexcr&   r?   raisesr   r   r   )test_ufunc_exception_on_write_to_readonlyd   s   
z4TestUFuncs.test_ufunc_exception_on_write_to_readonlyc                 C   s   t dd }| |tddtddtj | t}|tdd W d    n1 s2w   Y  d}| |t	|j
 d S )Nc                 S   s$   |dkrd }nt d}t | |S )Nr      )r)   r<   r   )r>   yrG   r   r   r   inner{   s   
z5TestUFuncs.test_optional_type_handling.<locals>.innerrN            z(expected array(float64, 1d, C), got None)r   r(   r)   arangeZastypeZfloat64rC   	TypeErrorrD   rE   rF   )r-   rP   rL   r&   r   r   r   test_optional_type_handlingx   s   
z&TestUFuncs.test_optional_type_handlingN)
__name__
__module____qualname__r2   r3   r9   r:   r;   rM   rV   r   r   r   r   r$   0   s    			
r$   c                   @   s   e Zd Zdd Zdd ZdS )TestUFuncsMiscc                 C   H   t dd }tjtjfD ]}|d}||}||}| || qd S )Nc                 S   
   t | S r   )r)   Zexp2r>   r   r   r   foo      
z%TestUFuncsMisc.test_exp2.<locals>.foor   r   r)   Zint8Zuint16Zpy_funcr(   r-   r^   tyr>   expectedgotr   r   r   	test_exp2      

zTestUFuncsMisc.test_exp2c                 C   r[   )Nc                 S   r\   r   )r)   log2r]   r   r   r   r^      r_   z%TestUFuncsMisc.test_log2.<locals>.foor   r`   ra   r   r   r   	test_log2   rf   zTestUFuncsMisc.test_log2N)rW   rX   rY   re   rh   r   r   r   r   rZ      s    rZ   __main__)numpyr)   Znumbar   r   r   Znumba.np.ufuncr   Znumba.core.errorsr   Znumba.tests.supportr   Zunittestr	   rT   Zreshaper   copyr   r   r   r   r   r   r#   r5   r$   rZ   rW   mainr   r   r   r   <module>   s,    *	`