o
    0 i                     @   s  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mZ d dl	m
Z
mZ d dlmZmZmZ d dlZd dlmZ d dlmZ dd Zd	d
 Zdd Zdd Zdd ZG dd de
ejZG dd deZG dd deZG dd deZG dd de
ejZedkre   dS dS )    N)njit	vectorize)MemoryLeakMixinTestCase)TypingErrorNumbaNotImplementedErrorNumbaExperimentalFeatureWarning)dufunc)
from_dtypec                 C   s   | | S N a0a1r   r   l/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/numba/tests/npyufunc/test_dufunc.pypyuadd      r   c                 C   s   | | S r   r   r   r   r   r   pysub   r   r   c                 C   s   | | S r   r   r   r   r   r   pymult   r   r   c                 C   s   | | S r   r   r   r   r   r   pydiv   r   r   c                 C   s   | |k r| S |S r   r   r   r   r   r   pymin!   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 )
TestDUFuncc                 C   s   t j|tdddS )NT)Znopython)Ztargetoptions)r	   ZDUFuncdict)selfZpyfuncr   r   r   nopython_dufunc'   s   zTestDUFunc.nopython_dufuncc                 C   s   |  t}| |j d|_| |j | t d|_W d    n1 s'w   Y  | t |t	dddt	ddd W d    d S 1 sLw   Y  d S )NTFr      
      )
r   r   ZassertFalse_frozen
assertTrueassertRaises
ValueError	TypeErrornplinspacer   duaddr   r   r   test_frozen*   s   
 "zTestDUFunc.test_frozenc                 C   s&   |  t}| tdd|dd d S )Nr   r   )r   r   assertEqualr%   r   r   r   test_scalar4   s   
zTestDUFunc.test_scalarc                    s   |  t t fdd}tddd}|d d }|dd  }td}|||| tj|| | |d}|d}td}|||| tj|| | |d d }	td}
|||	|
 tj||	 |
 d S )	Nc                    s    | || d S r   r   )r   r   Zo0r&   r   r   npmadd;      z(TestDUFunc.test_npm_call.<locals>.npmaddr   ffffff?   r   r      r0   )	r   r   r   r#   r$   zerostestingassert_array_equalreshape)r   r+   XX0X1out0Y0Y1out1Y2out2r   r*   r   test_npm_call8   s$   





zTestDUFunc.test_npm_callc                    s   |  t t fdd}tddd}|d d }|dd  }|||}tj|| | |d}|d}|||}tj|| | |d d }	|||	}
tj||	 |
 |d	d
}| |d d S )Nc                    
    | |S r   r   r   r*   r   r   r+   Q      
z8TestDUFunc.test_npm_call_implicit_output.<locals>.npmaddr   r-   r.   r   r/   r0         ?       @g      @)	r   r   r   r#   r$   r2   r3   r4   r(   )r   r+   r5   r6   r7   r8   r9   r:   r;   r<   r=   Zout3r   r*   r   test_npm_call_implicit_outputN   s"   






z(TestDUFunc.test_npm_call_implicit_outputc                 C   s   |  t}| |jd | |jd | |j|j|j  | |jd | |jg  | |jd  |dd | |jd | |jt	|j | 
|j d S )Nr   r   r   )r   r   r(   ninnoutnargsZntypestypesidentitylenZassertIsNone	signaturer%   r   r   r   test_ufunc_propsc   s   

zTestDUFunc.test_ufunc_propsc                    sr   |  t  dd  j j j j jd} fdd}| D ]\}}t||}| 	|| d|  q!d S )Nr   r   )rD   rE   rF   rH   rJ   c                    s.   d|  d}i }t t|d i| |d S )Nz>
                def impl():
                    return duadd.z
            r&   impl)exectextwrapdedent)attrfnlr*   r   r   get_attr_fn|   s   z4TestDUFunc.test_ufunc_props_jit.<locals>.get_attr_fnz!Attribute differs from original: )
r   r   rD   rE   rF   rH   rJ   itemsr   r(   )r   
attributesrS   rP   valZcfuncr   r*   r   test_ufunc_props_jitp   s   

	
zTestDUFunc.test_ufunc_props_jitN)
__name__
__module____qualname__r   r'   r)   r>   rC   rK   rW   r   r   r   r   r   %   s    
r   c                   @   s   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d Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zejdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zejd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5S )6TestDUFuncAtc                 G   sB   |  }|  }|j|g|R   ||g|R   | || d S r   )copyatassertPreciseEqual)r   rQ   ufuncaargsexpectedgotr   r   r   _compare_output   s
   zTestDUFuncAt._compare_outputc                    sD    j dkrt  fddn	t  fddtfdd}|S )Nr   c                    r?   r   r   r`   br_   r   r   <lambda>      
 z,TestDUFuncAt._generate_jit.<locals>.<lambda>c                        | S r   r   r`   rg   r   r   rh          c                     s
    j |  S r   r]   )ra   vecr   r   rQ      r@   z&TestDUFuncAt._generate_jit.<locals>.fnrD   r   r   )r   r_   rQ   r   r_   ro   r   _generate_jit   s   
zTestDUFuncAt._generate_jitc                    sx  t jdtd}| t j}| t j}t dd  t fdd}| |t j|g dd d	}| 	t
| || g d
d  W d    n1 sKw   Y  | |t j| g d
 t g d}| |t j| g d| d}| 	t
| || g d
g d W d    n1 sw   Y  | t
 || g d
ddgdg W d    d S 1 sw   Y  d S )Nr   dtypec                 S   s
   t | S r   )r#   negativerk   r   r   r   rh      ri   z8TestDUFuncAt.test_numpy_ufunc_at_basic.<locals>.<lambda>c                    s     | ||S r   rm   )r`   indicesrf   Znegative_vecr   r   negative_jit_2      z>TestDUFuncAt.test_numpy_ufunc_at_basic.<locals>.negative_jit_2r   r0   r   r   zsecond operand needed for ufunc)r   r0      d   r}   r}   z+second operand provided when ufunc is unaryr   r   r{   r   )r#   arangeintrr   addru   r   r   rd   assertRaisesRegexr   r\   arrayr    )r   r`   add_atZnegative_atrx   err_msgrf   r   rw   r   test_numpy_ufunc_at_basic   s*   "z&TestDUFuncAt.test_numpy_ufunc_at_basicc           
   
   C   s*  t jd }t jt jt jf}|D ]}}z	tt | W n	 ty#   Y qw |D ]e}t jd|d}t 	t jdt j
dt jddt j
dg}|jd}| |}|||| t |}	|t ju rgd |	d	< |	d< q&|	d	  d|t ju rs|n|  7  < |	d  d|t ju r|n|  7  < q&q| ||	 d S )
NComplexr   rs            y              ?r   )r#   	typecodesr   subtractmultiplyr
   rt   r   onesZconcatenateintpfulltyperr   Z	ones_liker^   )
r   r   ufuncstypecoder_   r`   indxvalueufunc_atrb   r   r   r   test_ufunc_at_inner_loop   s.   



$&z%TestDUFuncAt.test_ufunc_at_inner_loopc              
   C   s@   t jdtd}| t j}| |t j|td t jdtd d S )Nr0   rs   )r#   r1   r   rr   r   rd   slicer   r   arrr   r   r   r   test_ufunc_at_ellipsis   s
   z#TestDUFuncAt.test_ufunc_at_ellipsisc                 C   sJ   t jdt jd}t d}| t j}||| t |g dks#J d S )Nr0   rs   )r   r   r   r   r   )r#   r   Zint32r   rr   ru   all)r   r   r   r]   r   r   r   test_ufunc_at_negative   s
   

z#TestDUFuncAt.test_ufunc_at_negativec                 C   sx   t jdt jd}t jdtd}d|d< d|d< d|dd < t jdtd}| t j}|||| |d | ks:J d S )	Ni   rs   r   r   r0   r   r}   i    )r#   r1   Zint16floatrr   r   sum)r   rv   rf   r`   r   r   r   r   test_ufunc_at_large   s   z TestDUFuncAt.test_ufunc_at_largec                 C   sX   t d}t d}| t j}t jt|t jd}|||| |d t|ks*J d S )Nr   i rs   r   )r#   r1   r   rr   r   rI   Zuint8)r   r   valuesr   indexr   r   r   test_cast_index_fastpath   s   

z%TestDUFuncAt.test_cast_index_fastpathc              	   C   sz   t dt dt ddf}|D ])}t d}t t dd}| t j}|||| t j	|t 
|d|  qd S )Nr   r   rA   i  r   )r#   r   float64r1   repeatr   rr   r   r2   r3   Z	full_like)r   r   r   r   r   r   r   r   r   #test_ufunc_at_scalar_value_fastpath  s   
z0TestDUFuncAt.test_ufunc_at_scalar_value_fastpathc                 C   s  t ddd}t g dg dg dg}| t j}||td t g df| | |t g dg dg d	g t d
ddd}t g d}||td td t g df| | |t g dg dg dgg dg dg dgg dg dg dgg t ddd}t g dg dg dg}||t g dtd f| | |t g dg dg dg t d
ddd}t g d}||td t g dtd f| | |t g dg dg dgg dg dg dgg dg dg dgg t ddd}t g d}||dt g df| | |t g dg d g d!g t d
ddd}t g d}||t g ddtd f| | |t g dg d g d!gg d"g d#g d$gg d%g d&g d'gg t d
ddd}t g d}| t j}||td td td f| | |t g d(g d)g dgg d*g d+g dgg d%g d,g dgg d S )-N	   r{   r|   )   r   r   ),  r   r   r   r   r   )r      f   )r{        )r   i_  4     )r}   r   r   )r   i     )r   i     )r        )        )   i     )r   i     )        )   i     r   r   r   )i  r   i  )      r   )   r   i]  )j   r   r   )r   r      )   r   if  )s      i=  )r      r.   )   r   io  )|      iF  r   r{   r   r0   )r         )   r   ic  )r         )r         )v      i@  )r         )r         )r}   r   i.  )g      i1  )m      i7  )p      i:  )y      iC  )	r#   r   r4   r   rr   r   r   asarrayr^   )r   r`   rf   r   r   r   r   test_ufunc_at_multiD  s   
$

$

 


z!TestDUFuncAt.test_ufunc_at_multiDc                 C   s   t d}| t j}||dd | |t d | t ||dd W d    n1 s0w   Y  t d}||dd | |t g d | t ||g d W d    d S 1 sbw   Y  d S )Nr   r   r   r{   )r   r   r   )	r#   r   rr   r   r^   r    r   r   r!   )r   r`   r   rf   r   r   r   test_ufunc_at_0Df  s   

"zTestDUFuncAt.test_ufunc_at_0Dc                 C   s@   t d}| t j}||g dd | |t g d d S )Nr   )r   r   r{   r   g      @)
r   r   i>  .   r   r0   r   r   r   r   )r#   r   rr   powerr^   r   )r   r`   Zpower_atr   r   r   test_ufunc_at_dtypesx  s   
z!TestDUFuncAt.test_ufunc_at_dtypesc                 C   sL   t d}|d dk}| t j}|||g d | |t g d d S )Nr   r   r   )r   r   r   r   r   )
r   r   r   r{   r   r0   r   r   r   r   )r#   r   rr   equalr^   r   )r   r`   r   equal_atr   r   r   test_ufunc_at_boolean  s
   
z"TestDUFuncAt.test_ufunc_at_booleanc                 C   sH   t jddd}| t j}||g d | |t jg dt jd d S )Nr   Zu4rs   rz   )
r   r   r   r{   r   l    r   r   r   r   )r#   r   rr   invertr^   r   Zuint32)r   r`   Z	invert_atr   r   r   test_ufunc_at_boolean2  s   z#TestDUFuncAt.test_ufunc_at_boolean2c                 C   s\   t d}|d d d f d d ddf }| t j}||ddgd | |t d d S )Nr   r   r   r{   )r#   r   rr   r   r^   )r   origr`   r   r   r   r   test_ufunc_at_advanced  s
   
 z#TestDUFuncAt.test_ufunc_at_advancedc                 C   s`   t g dt d }t g dt d }| t j}|||d | |g d d S )Nr   i)r   r   r{   r   fr{   )r   r   r   r   )r#   r   rt   Znewbyteorderrr   r   r^   )r   r   r   r   r   r   r   test_ufunc_at_advanced_2  s
   z%TestDUFuncAt.test_ufunc_at_advanced_2c                 C   sv   t jddgtd}| t j}| t ||ddgd W d    n1 s'w   Y  | |t jddgtd d S )Nr`   r   rs   r   )r#   r   objectrr   r   r    r   r^   )r   r   r   r   r   r   test_ufunc_at_advanced_3  s   z%TestDUFuncAt.test_ufunc_at_advanced_3c                 C   sN   |  tj}| t |tddg W d    d S 1 s w   Y  d S )Nr   r   )rr   r#   modfr    r   r   )r   Zmodf_atr   r   r   test_ufunc_at_advanced_4  s   "z%TestDUFuncAt.test_ufunc_at_advanced_4c                 C   sB   |  tj}tg d}||dgd | |tg d d S )Nr~   r   )rr   r#   maximumr   r^   )r   Z
maximum_atr`   r   r   r   test_ufunc_at_advanced_5  s   z%TestDUFuncAt.test_ufunc_at_advanced_5c              	   C   s  t jd t jd  }t jt jt jt jt jf}|D ]q}|dv rqz	tt | W n	 t	y1   Y qw |D ]T}t 
dd|}t g dt j}t jg d|jd}| }t||D ]\}	}
|||	 |
||	< q]| |}|||| t j|| t |g dksJ q4qd S )	NZ
AllIntegerFloat)er   r   )r   r   r   r   )r   r0   r   r   rs   )r#   r   r   r   divideminimumr   r
   rt   r   r   Zastyper   r   r\   ziprr   r2   r3   r   )r   Zdtypesr   rt   r_   r`   Zindxsvalsrb   r   vr   r   r   r   test_ufunc_at_negative_indexes  s.   
z+TestDUFuncAt.test_ufunc_at_negative_indexesc                 C   sd   t d}t d}| t j}d}| t| ||dg| W d    d S 1 s+w   Y  d S )N)r   r   r   )r   r   r   z1does not support ufunc with non-trivial signaturer   )r#   r   rr   matmulr   r   )r   r`   rf   Z	matmul_atr   r   r   r    test_ufunc_at_not_none_signature  s   

"z-TestDUFuncAt.test_ufunc_at_not_none_signaturec                 C   s^   t jdtd}| t j}| t ||ddgddg W d    d S 1 s(w   Y  d S )Nr   rs   r   r   )r#   r   strrr   r   r    r   r   r   r   r   test_ufunc_at_no_loop_for_op  s
   "z)TestDUFuncAt.test_ufunc_at_no_loop_for_opc                 C   s<   t dg}| t j}||dgdg |d dksJ d S )Nr   r   )r#   r   rr   r   )r   r   r   r   r   r   test_ufunc_at_output_casting  s   z)TestDUFuncAt.test_ufunc_at_output_castingc                 C   s`   t d}| t j}d}| t| ||ddgg d W d    d S 1 s)w   Y  d S )Nr0   z=operands could not be broadcast together with remapped shapesr   r   r~   )r#   r   rr   r   r   r!   )r   r   r   msgr   r   r   test_ufunc_at_broadcast_failure  s   
"z,TestDUFuncAt.test_ufunc_at_broadcast_failurec                 C   sN   t d}tdd }| t|jd ||ddg | t|jd d S )Nr0   c                 S   s   | d S )Nr   r   xr   r   r   inc     z/TestDUFuncAt.test_ufunc_at_dynamic.<locals>.incr   r   r{   )r#   r   r   r(   rI   rG   r]   assertGreater)r   r   r  r   r   r   test_ufunc_at_dynamic  s   

z"TestDUFuncAt.test_ufunc_at_dynamicc                 C   s   t d}| t j}tjdd}tdt ||ddgd W d    n1 s*w   Y  | t	|d | 
dt|d j d S )	Nr0   T)recordalwaysr   r{   r   z ufunc.at feature is experimental)r#   r   rr   r   warningscatch_warningssimplefilterr   r  rI   ZassertInr  message)r   r   r   wr   r   r   "test_ufunc_at_experimental_warning  s   
z/TestDUFuncAt.test_ufunc_at_experimental_warningN)rX   rY   rZ   rd   rr   r   r   r   r   r   r   r   r   r   r   r   r   r   unittestexpectedFailurer   r   r   r   r  r  r  r  r  r  r  r   r   r   r   r[      s:    $	
U	

	r[   c                   @   st   e Zd ZdddZej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 )TestDUFuncReduceNumPyTestsNc                    sN    j dkrt|d fddnt|d fddtd	fdd	}|S )
Nr   rH   c                    r?   r   r   re   rg   r   r   rh     ri   z:TestDUFuncReduceNumPyTests._generate_jit.<locals>.<lambda>c                    rj   r   r   rk   rg   r   r   rh     rl   r   c                    s    j | ||dS Naxisinitialreduce)r   r  r  rn   r   r   rQ     r,   z4TestDUFuncReduceNumPyTests._generate_jit.<locals>.fn)r   Nrp   )r   r_   rH   rQ   r   rq   r   rr     s   
z(TestDUFuncReduceNumPyTests._generate_jitc                 C   s0   |  tj}tjd}|d}| || d S )Nr{   )rr   r#   r   r   r^   )r   Zpower_reducerb   rc   r   r   r   test_numpy_scalar_reduction"  s   z6TestDUFuncReduceNumPyTests.test_numpy_scalar_reductionc                 C   s  dd }| j tjdd}d|d< d|d< |||d d	d |||d
d	g d |||dd	g d |||dd	ddg |||dd	g dg dg dg |||dd	g dg dg |||dd	g dg dg |||dd	| d|d< d|d< |||d d	d |||d
d	g d |||dd	g d |||dd	ddg |||dd	g dg dg dg |||dd	g dg dg |||dd	g dg dg |||dd	| d|d< d|d< |||d d	d |||d
d	g d |||dd	g d |||dd	ddg |||dd	g dg dg dg |||dd	g dg dg |||dd	g dg dg |||dd	| d S )Nc                 S   s   t j| | d S r   )r#   r2   Zassert_equalre   r   r   r   compare_output+  s   zOTestDUFuncReduceNumPyTests.check_identityless_reduction.<locals>.compare_outputreorderabler  r   .r   )r   r   r   r  r   r   )r   r   r   r   r   r   )r   r   r   r   r   )r   r   r   r   r   )r   r   r   r   r   r   r   )r   r   r   )r   r   r   )r   r   r   r   )rr   r#   r   )r   r`   r"  Zminimum_reducer   r   r   check_identityless_reduction*  sd   z7TestDUFuncReduceNumPyTests.check_identityless_reductionc                 C      t jddd}| | d S )Nr   r{   r   Corderr#   emptyr)  r   r`   r   r   r   (test_numpy_identityless_reduction_cordera     zCTestDUFuncReduceNumPyTests.test_numpy_identityless_reduction_corderc                 C   r*  )Nr+  Fr-  r/  r1  r   r   r   (test_numpy_identityless_reduction_fordere  r3  zCTestDUFuncReduceNumPyTests.test_numpy_identityless_reduction_forderc                 C   s$   t jddddd}| | d S )N)r   r   r{   r,  r-  r   r   r#   r0  Zswapaxesr)  r1  r   r   r   ,test_numpy_identityless_reduction_otherorderi  s   zGTestDUFuncReduceNumPyTests.test_numpy_identityless_reduction_otherorderc                 C   s>   t jddddd}|dd dd dd f }| | d S )N)r{   r0   r   r,  r-  r   r   r6  r1  r   r   r   +test_numpy_identityless_reduction_noncontigm  s   zFTestDUFuncReduceNumPyTests.test_numpy_identityless_reduction_noncontigc                 C   sP   t jddd}|dd  jdd}d|_|dd dd dd f }| | d S )N)i  i1rs   r   Zf8r   )r#   r0  viewshaper)  r1  r   r   r   5test_numpy_identityless_reduction_noncontig_unalignedr  s
   zPTestDUFuncReduceNumPyTests.test_numpy_identityless_reduction_noncontig_unalignedc              	   C   sB  |  tj}|  tj}|  tj}| |tg ddd | |tg tjdtj | |tg tj dtj  | |tdgddd | |tdgddd | |tdgddd | |tdgddd d}||fD ]!}| t	| |tg d d W d    n1 sw   Y  q}d S )Nr   r  g        r0   r   &zero-size array to reduction operation)
rr   r#   r   r   r   r^   r   infr   r!   )r   
add_reduceZ
min_reduce
max_reducer  funcr   r   r   test_numpy_initial_reductiony  s*   z7TestDUFuncReduceNumPyTests.test_numpy_initial_reductionc                 C   s   t d}| t j}t jj|dd}||dd}| || | |jd d}| t| ||dd W d    n1 s?w   Y  t d}| t| ||dd W d    n1 s`w   Y  t jj|ddd}||ddd}| || d S )	N)r   r0   r   r$  )r   r>  r   )r   r   r0   r  )	r#   r1   rr   Ztrue_divider   r^   r;  r   r!   )r   r   Ztrue_divide_reducerb   rc   r  r   r   r   'test_numpy_empty_reduction_and_identity  s"   

zBTestDUFuncReduceNumPyTests.test_numpy_empty_reduction_and_identityc                 C   s   t g dg dg}| t j}||dd}| |t g d ||dd}| |t ddg ||d	d}| || d S )
N)       @rB   rB   )rA   g      ?g      ?r   r$  )rE  g      @rE  r   rB   rE  r   )r#   r   rr   r   r^   r   )r   r`   Zdivide_reduceresr   r   r   *test_identityless_reduction_nonreorderable  s   zETestDUFuncReduceNumPyTests.test_identityless_reduction_nonreorderablec                    s  dd } fdd}dd } j tjdd} tjjd  |||d	d	 |||d
d	 |||d	d
 |||d
d
 ||g  |tddd  j tjd
d}|||d	d	 |||d
d	 |||d	d
 |||d
d
 |tjg tjd |tddd d S )Nc                 _   s   | |i | d S r   r   r   ra   kwargsr   r   r   ok  s   z<TestDUFuncReduceNumPyTests.test_reduce_zero_axis.<locals>.okc                    s>     t | |i | W d    d S 1 sw   Y  d S r   )r    r!   rH  r   r   r   err  s   "z=TestDUFuncReduceNumPyTests.test_reduce_zero_axis.<locals>.errc              
   S   sp  | |t ||fdd | |t ||fdd | |t |d |d |fdd | |t |d ||d fdd | |t ||d |d fdd | |t |d ||d fdd | |t |d |d |d |d |d fdd | |t d	||fd
d | |t d	||fdd | |t |d	|fdd | |t d	||fdd | |t d	||fdd d S )Nr   r$  r   r   r'  r&  r{   r   r   r%  )r#   r1   )expectrB  nmr   r   r   t  s    """"z;TestDUFuncReduceNumPyTests.test_reduce_zero_axis.<locals>.tr#  r     r   r   r   r   r$  rs   )	rr   r#   r   r(   rH   r1   r   r   int64)r   rJ  rL  rP  Zmaximum_reducer@  r   rK  r   test_reduce_zero_axis  s$   
z0TestDUFuncReduceNumPyTests.test_reduce_zero_axisr   )rX   rY   rZ   rr   r  r  r!  r)  r2  r5  r7  r8  r<  rC  rD  rG  rT  r   r   r   r   r    s    

7r  c                   @   sp   e Zd ZdddZd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 )TestDUFuncReduceNc           
         s   t  fdd}tdtdddtddddg}|D ]}t|jD ]}|||||}|||||}	| ||	 q(q!d S )Nc                    s    j | |||dS )N)r  rt   r  r  )r`   r  rt   r  rg   r   r   foo  s
   z+TestDUFuncReduce._check_reduce.<locals>.foor0   r   r   (   )r   r#   r   r4   rangendimpy_funcr^   )
r   r_   rt   r  rV  inputsr   r  rb   rc   r   rg   r   _check_reduce  s   zTestDUFuncReduce._check_reducec                    s   t fdd fdd}dj dtjd|dd	d
dtjd|dg}|D ]) td jd D ]}tjt j|dD ]|  qEq9dD ]|  qPq/d S )Nc                    s   j | | dS r  r  r`   r  )r  r_   r   r   rV    r,   z0TestDUFuncReduce._check_reduce_axis.<locals>.fooc                     s   z  }W n> tyF } z2|jd  t  }W d    n1 s/w   Y  W Y d }~d S W Y d }~d S d }~ww  }|| d S )Nr   )rZ  r!   r(   ra   r   r   r^   )ra   rb   r   rc   )r   r  exc_msgrV  r   r   r   _check  s   8
z3TestDUFuncReduce._check_reduce_axis.<locals>._checkzreduction operation 'z:' is not reorderable, so at most one axis may be specifiedrW  rs   r0   r   r   r   r   )r)r   N)	r   rX   r#   r   r4   rX  rY  	itertoolscombinations)r   r_   rt   r  r_  r[  r   r   )r   r  r^  rV  r  r   r_   r   _check_reduce_axis  s    z#TestDUFuncReduce._check_reduce_axisc                 C   s.   t dddt}| | | j|tjd d S )Nint64(int64, int64)r   r  rs   )r   r   r\  rc  r#   rS  r%   r   r   r   test_add_reduce/  s   
z TestDUFuncReduce.test_add_reducec                 C   s   t dddt}| | d S )Nrd  r   r  )r   r   r\  )r   Zdumulr   r   r   test_mul_reduce4  s   z TestDUFuncReduce.test_mul_reducec                 C   sX   t dd dt}t dd dt}| | | j|tjd | | | j|tjd d S )Nrd  r  rs   )r   r   r   r\  rc  r#   rS  )r   ZdusubZdudivr   r   r   test_non_associative_reduce8  s   

z,TestDUFuncReduce.test_non_associative_reducec                 C   s$   t dddt}| j|tjd d S )Nfloat64(float64, int64)r   r  rs   )r   r   r\  r#   r   r%   r   r   r   test_reduce_dtype@  s   z"TestDUFuncReduce.test_reduce_dtypec                 C   s2   t dddt}| j|dd | j|tjd d S )Nrd  r#  r  r   r=  rs   )r   r   r\  rc  r#   rS  )r   Zduminr   r   r   test_min_reduceD  s   z TestDUFuncReduce.test_min_reducec                 C   s&   t dddt}| j|tjdd d S )Nrd  r   r  r}   )rt   r  r   r   r\  r#   rS  r%   r   r   r   test_add_reduce_initialI  s   z(TestDUFuncReduce.test_add_reduce_initialc                 C   s    t dt}| j|tjd d S )Nrd  rs   rk  r%   r   r   r   &test_add_reduce_no_initial_or_identityN  s   z7TestDUFuncReduce.test_add_reduce_no_initial_or_identityc                    s^   t dddt t fdd}d}| t| |d W d    d S 1 s(w   Y  d S )Nrh  r   r  c                    s
     | S r   r  rk   r*   r   r   rV  V  r@   z0TestDUFuncReduce.test_invalid_input.<locals>.fooz-The first argument "array" must be array-liker`   )r   r   r   r   r   )r   rV  r^  r   r*   r   test_invalid_inputS  s   
"z#TestDUFuncReduce.test_invalid_inputc                    sh   t dddt t fdd}tdddd	}d
}|D ]} ||}|||}| || qd S )Nrd  r   r  c                        j | |dS Nr$  r  r]  r*   r   r   rV  a  ry   z7TestDUFuncReduce.test_dufunc_negative_axis.<locals>.foorW  r0   r   r   )r   r   )r   r   )r   )r   r   )r   r   r   r#   r   r4   r   r^   )r   rV  r`   casesr  rb   rc   r   r*   r   test_dufunc_negative_axis^  s   
z*TestDUFuncReduce.test_dufunc_negative_axisc              	      s   t dddt t fdd}tdddd	}d
}|D ]}d}| t| ||| W d    n1 s8w   Y  qd}|D ]}| td ||| W d    n1 sZw   Y  qBd S )Nrd  r   r  c                    ro  rp  r  r]  r*   r   r   rV  o  ry   z6TestDUFuncReduce.test_dufunc_invalid_axis.<locals>.foorW  r0   r   r   )rR  r(  )r   rr  )r   r   )r   r   zduplicate value in 'axis')r{   )r   ru  zInvalid axis)r   r   r   r#   r   r4   r   r!   )r   rV  r`   rs  r  r  r   r*   r   test_dufunc_invalid_axisl  s$   z)TestDUFuncReduce.test_dufunc_invalid_axis)NNr   )rX   rY   rZ   r\  rc  re  rf  rg  ri  rj  rl  rm  rn  rt  rv  r   r   r   r   rU    s    

 rU  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestDUFuncPicklingc                    sh   t |}t |  d}| d| | || t fdd}|d}| d| | || d S )N{   c                    rj   r   r   r	  Zrebuiltr   r   rV    r  z%TestDUFuncPickling.check.<locals>.fooiA  )pickledumpsloadsr(   ZassertIsInstancer   )r   identresult_typebufr`  rV  r   ry  r   check  s   

zTestDUFuncPickling.checkc                 C   s$   t dd }| j|ttjfd d S )Nc                 S      | S r   r   x1r   r   r   r}       z3TestDUFuncPickling.test_unrestricted.<locals>.identr~  )r   r  r   r#   integerr   r}  r   r   r   test_unrestricted  s   
z$TestDUFuncPickling.test_unrestrictedc                 C   s$   t dgdd }| j|td d S )Nzfloat64(float64)c                 S   r  r   r   r  r   r   r   r}    r  z1TestDUFuncPickling.test_restricted.<locals>.identr  )r   r  r   r  r   r   r   test_restricted  s   
z"TestDUFuncPickling.test_restrictedN)rX   rY   rZ   r  r  r  r   r   r   r   rw    s    rw  __main__)!ra  rz  rN   r  numpyr#   Znumbar   r   Znumba.tests.supportr   r   Znumba.core.errorsr   r   r   r  Znumba.np.ufuncr	   Znumba.np.numpy_supportr
   r   r   r   r   r   r   r[   r  rU  rw  rX   mainr   r   r   r   <module>   s:    m    h "