o
    ic                     @   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   ]/home/ubuntu/transcripts/venv/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!   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)nopython)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?   flags	writeableappendr   r   
ValueErrorassertRaisesassertInstr	exception)	r-   ztestsexpectdecexcr&   rB   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   )rA   yrK   r   r   r   inner{   s   
z5TestUFuncs.test_optional_type_handling.<locals>.innerrR            z(expected array(float64, 1d, C), got None)r   r(   r)   arangeastypefloat64rG   	TypeErrorrH   rI   rJ   )r-   rT   rP   r&   r   r   r   test_optional_type_handlingx   s   
z&TestUFuncs.test_optional_type_handlingN)
__name__
__module____qualname__r2   r3   r9   r:   r<   rQ   r\   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)   exp2rA   r   r   r   foo      
z%TestUFuncsMisc.test_exp2.<locals>.foor   r   r)   int8uint16py_funcr(   r-   re   tyrA   expectedgotr   r   r   	test_exp2      

zTestUFuncsMisc.test_exp2c                 C   ra   )Nc                 S   rb   r   )r)   log2rd   r   r   r   re      rf   z%TestUFuncsMisc.test_log2.<locals>.foor   rg   rk   r   r   r   	test_log2   rp   zTestUFuncsMisc.test_log2N)r]   r^   r_   ro   rr   r   r   r   r   r`      s    r`   __main__)numpyr)   numbar   r   r   numba.np.ufuncr   numba.core.errorsr   numba.tests.supportr   unittestr	   rX   reshaper   copyr   r   r   r   r   r   r#   r5   r$   r`   r]   mainr   r   r   r   <module>   s,    *	`