o
    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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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   ^/home/ubuntu/transcripts/venv/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"      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)nopython)targetoptions)r	   DUFuncdict)self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   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_scalar5   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   o0r,   r   r   npmadd<      z(TestDUFunc.test_npm_call.<locals>.npmaddr   ffffff?   r!   r"      r7   )	r   r   r   r)   r*   zerostestingassert_array_equalreshape)r   r2   XX0X1out0Y0Y1out1Y2out2r   r1   r   test_npm_call9   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   r1   r   r   r2   R      
z8TestDUFunc.test_npm_call_implicit_output.<locals>.npmaddr   r4   r5   r!   r6   r7         ?       @g      @)	r   r   r   r)   r*   r9   r:   r;   r.   )r   r2   r<   r=   r>   r?   r@   rA   rB   rC   rD   out3r   r1   r   test_npm_call_implicit_outputO   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nargsntypestypesidentitylenassertIsNone	signaturer+   r   r   r   test_ufunc_propsd   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"   )rL   rM   rN   rQ   rT   c                    s.   d|  d}i }t t|d i| |d S )Nz>
                def impl():
                    return duadd.z
            r,   impl)exectextwrapdedent)attrfnlr1   r   r   get_attr_fn}   s   z4TestDUFunc.test_ufunc_props_jit.<locals>.get_attr_fnz!Attribute differs from original: )
r   r   rL   rM   rN   rQ   rT   itemsr   r.   )r   
attributesr]   rZ   valcfuncr   r1   r   test_ufunc_props_jitq   s   

	
zTestDUFunc.test_ufunc_props_jitN)
__name__
__module____qualname__r   r-   r/   rE   rK   rU   rb   r   r   r   r   r   &   s    
r   c                   @   s4   e Zd Zejd
ddZdd Zdd Zdd	 ZdS )TestDUFuncMethodsBaseNc                    s   |dv sJ |dkr1 j dkrt|d fddnt|d fddtdfd	d
	}|S |dkrT j dkr>tdt|d fddtdfdd
	}|S  j dkret|d fddnt|d fddtfdd
}|S )N)reducereduceatatrg   r"   rQ   c                    rF   r   r   abufuncr   r   <lambda>      
 z5TestDUFuncMethodsBase._generate_jit.<locals>.<lambda>c                        | S r   r   rl   rn   r   r   rp          r   c                        j | ||dS Naxisinitialrg   arrayrx   ry   vecr   r   r[      r3   z/TestDUFuncMethodsBase._generate_jit.<locals>.fnrh   ,reduceat only supported for binary functionsc                    rF   r   r   rk   rn   r   r   rp      rq   c                    s     | ||||S r   rh   )r|   indicesrx   dtypeoutr}   r   r   r[      s   c                    rF   r   r   rk   rn   r   r   rp      rq   c                    rr   r   r   rs   rn   r   r   rp      rt   c                     s
    j |  S r   ri   )argsr}   r   r   r[      rG   r   N)r   NN)rL   r   r   r'   )r   ro   kindrQ   r[   r   ro   r~   r   _generate_jit   s*   


z#TestDUFuncMethodsBase._generate_jitc                 C      | j |d|dS )Nrg   rj   r   r   ro   rQ   r   r   r   _reduce   r   zTestDUFuncMethodsBase._reducec                 C   r   )Nrh   rj   r   r   r   r   r   	_reduceat   r   zTestDUFuncMethodsBase._reduceatc                 C   s   |  |dS )Nri   r   )r   ro   r   r   r   _at   s   zTestDUFuncMethodsBase._atr   )	rc   rd   re   	functoolscacher   r   r   r   r   r   r   r   rf      s     rf   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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-d. Zd/d0 Zd1d2 Zd3S )4TestDUFuncAtc                 G   sB   |  }|  }|j|g|R   ||g|R   | || d S r   )copyri   assertPreciseEqual)r   r[   ro   rl   r   expectedgotr   r   r   _compare_output   s
   zTestDUFuncAt._compare_outputc                    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!   r   c                 S   
   t | S r   r)   negativers   r   r   r   rp      rq   z8TestDUFuncAt.test_numpy_ufunc_at_basic.<locals>.<lambda>c                    s     | ||S r   r   )rl   r   rm   negative_vecr   r   negative_jit_2      z>TestDUFuncAt.test_numpy_ufunc_at_basic.<locals>.negative_jit_2r"   r7   r"   r    zsecond operand needed for ufunc)r"   r7      d   r   r   z+second operand provided when ufunc is unaryr    r"   r   r"   )r)   arangeintr   addr   r   r   r   assertRaisesRegexr   r   r|   r&   )r   rl   add_atnegative_atr   err_msgrm   r   r   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!   r            y              ?r    )r)   	typecodesr   subtractmultiplyr
   r   r   onesconcatenateintpfulltyper   	ones_liker   )
r   r   ufuncstypecodero   rl   indxvalueufunc_atr   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 )Nr7   r   )r)   r8   r   r   r   r   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 )Nr7   r   )r   r   r   r   r   )r)   r   int32r   r   r   all)r   r   r   ri   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   r   r!   r   r7   r    r   i    )r)   r8   int16floatr   r   sum)r   r   rm   rl   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 r   r   )r)   r8   r   r   r   rR   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   rH   i  r"   )r)   r   float64r8   repeatr   r   r   r9   r:   	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      r5   )   r   io  )|      iF  r   r   r   r7   )r         )   r   ic  )r         )r         )v      i@  )r         )r         )r   r   i.  )g      i1  )m      i7  )p      i:  )y      iC  )	r)   r   r;   r|   r   r   r   asarrayr   )r   rl   rm   r   r   r   r   test_ufunc_at_multiD4  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|   r   r   r   r&   r   r   r'   )r   rl   r   rm   r   r   r   test_ufunc_at_0D  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   r7   r   r   r   r   )r)   r   r   powerr   r|   )r   rl   power_atr   r   r   test_ufunc_at_dtypes  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    r7   r    r   r    r   )r)   r   r   equalr   r|   )r   rl   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!   u4r   r   )
r   r    r"   r   r   l    r   r   r   r   )r)   r   r   invertr   r|   uint32)r   rl   	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   r   r   r   )r   origrl   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|   r   newbyteorderr   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 )Nrl   r    r   r   )r)   r|   objectr   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    )r   r)   modfr&   r   r   )r   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   )r   r)   maximumr|   r   )r   
maximum_atrl   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 )	N
AllIntegerFloat)er   r!   )r   r    r   r"   )r    r7   r"   r!   r   )r)   r   r   r   divideminimumr+  r
   r   r   r   astyper|   r   r   zipr   r9   r:   r   )r   dtypesr   r   ro   rl   indxsvalsr   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   r   matmulr   r   )r   rl   rm   	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!   r   r   r    )r)   r   strr   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|   r   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 )Nr7   z=operands could not be broadcast together with remapped shapesr   r    r   )r)   r   r   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 )Nr7   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.   rR   rP   ri   assertGreater)r   r   rD  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 )	Nr7   T)recordalwaysr   r   r!   z ufunc.at feature is experimental)r)   r   r   r   warningscatch_warningssimplefilterr   rF  rR   assertInr=  message)r   r   r   wr   r   r   "test_ufunc_at_experimental_warning)  s   
z/TestDUFuncAt.test_ufunc_at_experimental_warningN)rc   rd   re   r   r   r   r   r   r   r   r   r  r  r  r  r  r   unittestexpectedFailurer%  r'  r*  r-  r9  r<  r>  r?  rA  rG  rP  r   r   r   r   r      s8    $	
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"   rj   c                    rF   r   r   rk   rn   r   r   rp   <  rq   z:TestDUFuncReduceNumPyTests._generate_jit.<locals>.<lambda>c                    rr   r   r   rs   rn   r   r   rp   >  rt   r   c                    ru   rv   rz   r{   r}   r   r   r[   @  r3   z4TestDUFuncReduceNumPyTests._generate_jit.<locals>.fnr   )rL   r   r   )r   ro   rQ   r[   r   r   r   r   :  s   
z(TestDUFuncReduceNumPyTests._generate_jitc                 C   s0   |  tj}tjd}|d}| || d S )Nr   )r   r)   r  rg   r   )r   power_reducer   r   r   r   r   test_numpy_scalar_reductionE  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)   r9   assert_equalrk   r   r   r   compare_outputN  s   zOTestDUFuncReduceNumPyTests.check_identityless_reduction.<locals>.compare_outputreorderablerj   r    .r   )r    r   r   rx   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)   r2  )r   rl   rW  minimum_reducer   r   r   check_identityless_reductionM  sd   z7TestDUFuncReduceNumPyTests.check_identityless_reductionc                 C      t jddd}| | d S )Nr"   r   r   Corderr)   emptyr_  r   rl   r   r   r   (test_numpy_identityless_reduction_corder     zCTestDUFuncReduceNumPyTests.test_numpy_identityless_reduction_corderc                 C   r`  )Nra  Frc  re  rg  r   r   r   (test_numpy_identityless_reduction_forder  ri  zCTestDUFuncReduceNumPyTests.test_numpy_identityless_reduction_forderc                 C   s$   t jddddd}| | d S )N)r"   r   r   rb  rc  r    r"   r)   rf  swapaxesr_  rg  r   r   r   ,test_numpy_identityless_reduction_otherorder  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   r7   r   rb  rc  r    r"   rl  rg  r   r   r   +test_numpy_identityless_reduction_noncontig  s   zFTestDUFuncReduceNumPyTests.test_numpy_identityless_reduction_noncontigc                 C   sT   t jddd}|dd  jdd}|d}|dd dd dd f }| | d S )N)i  i1r   r    f8r   )r)   rf  viewr;   r_  rg  r   r   r   5test_numpy_identityless_reduction_noncontig_unaligned  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   ry   g        r7   r   &zero-size array to reduction operation)
r   r)   r   r2  r+  r   r  infr   r'   )r   
add_reduce
min_reduce
max_reducer@  funcr   r   r   test_numpy_initial_reduction  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   r7   r    rY  )r   ru  r   )r   r   r7   rw   )	r)   r8   r   true_dividerg   r   shaper   r'   )r   r   true_divide_reducer   r   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)       @rI   rI   )rH   g      ?g      ?r   rY  )r  g      @r  r    rI   r  r   )r)   r|   r   r1  r   r  )r   rl   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#  r   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'   r  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    rY  r   r"   r\  r[  r   r   r!   rZ  )r)   r8   )expectrz  nmr   r   r   t  s    """"z;TestDUFuncReduceNumPyTests.test_reduce_zero_axis.<locals>.trX  rj      r   r   r   r   rY  r   )	r   r)   r+  r.   rQ   r8   r   r|   int64)r   r  r  r  maximum_reducerw  r   r  r   test_reduce_zero_axis  s$   
z0TestDUFuncReduceNumPyTests.test_reduce_zero_axisr   )rc   rd   re   r   rQ  rR  rU  r_  rh  rk  rn  ro  rs  r{  r  r  r  r   r   r   r   rS  6  s    

7rS  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)rx   r   ry   rz   )rl   rx   r   ry   rn   r   r   foo   s
   z+TestDUFuncReduce._check_reduce.<locals>.foor7   r   r"   (   )r   r)   r   r;   rangendimpy_funcr   )
r   ro   r   ry   r  inputsr|   rx   r   r   r   rn   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 rv   rz   rl   rx   )ry   ro   r   r   r  4  r3   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   )r  r'   r.   r   r   r   r   )r   r   r0  r   )r|   rx   exc_msgr  r   r   r   _check8  s   8
z3TestDUFuncReduce._check_reduce_axis.<locals>._checkzreduction operation 'z:' is not reorderable, so at most one axis may be specifiedr  r   r7   r   r"   r!   r    )r)r   N)	r   rc   r)   r   r;   r  r  	itertoolscombinations)r   ro   r   ry   r  r  r!  r   )r|   rx   r  r  ry   r   ro   r   _check_reduce_axis2  s    z#TestDUFuncReduce._check_reduce_axisc                 C   s.   t dddt}| | | j|tjd d S )Nint64(int64, int64)r   rj   r   )r   r   r  r  r)   r  r+   r   r   r   test_add_reduceR  s   
z TestDUFuncReduce.test_add_reducec                 C   s   t dddt}| | d S )Nr  r    rj   )r   r   r  )r   dumulr   r   r   test_mul_reduceW  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 )Nr  rj   r   )r   r   r   r  r  r)   r  )r   dusubdudivr   r   r   test_non_associative_reduce[  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   rj   r   )r   r   r  r)   r   r+   r   r   r   test_reduce_dtypec  s   z"TestDUFuncReduce.test_reduce_dtypec                 C   s2   t dddt}| j|dd | j|tjd d S )Nr  rX  rj   r!   rt  r   )r   r   r  r  r)   r  )r   duminr   r   r   test_min_reduceg  s   z TestDUFuncReduce.test_min_reducec                 C   s&   t dddt}| j|tjdd d S )Nr  r   rj   r   )r   ry   r   r   r  r)   r  r+   r   r   r   test_add_reduce_initiall  s   z(TestDUFuncReduce.test_add_reduce_initialc                 C   s    t dt}| j|tjd d S )Nr  r   r  r+   r   r   r   &test_add_reduce_no_initial_or_identityq  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 )Nr  r   rj   c                    s
     | S r   rz   rs   r1   r   r   r  y  rG   z0TestDUFuncReduce.test_invalid_input.<locals>.fooz-The first argument "array" must be array-likerl   )r   r   r   r   r   )r   r  r  r   r1   r   test_invalid_inputv  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 )Nr  r   rj   c                        j | |dS NrY  rz   r  r1   r   r   r    r   z7TestDUFuncReduce.test_dufunc_negative_axis.<locals>.foor  r7   r   r"   )r   r   )r   r   )r   )r    r   )r   r   r   r)   r   r;   rg   r   )r   r  rl   casesrx   r   r   r   r1   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 )Nr  r   rj   c                    r  r  rz   r  r1   r   r   r    r   z6TestDUFuncReduce.test_dufunc_invalid_axis.<locals>.foor  r7   r   r"   )r  r]  )r   r  )r   r   )r   r"   zduplicate value in 'axis')r   )r   r  zInvalid axis)r   r   r   r)   r   r;   r   r'   )r   r  rl   r  rx   r@  r   r1   r   test_dufunc_invalid_axis  s$   z)TestDUFuncReduce.test_dufunc_invalid_axis)NNr   )rc   rd   re   r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r    s    

 r  c                   @   s   e Z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dd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )TestDUFuncReduceAtc           	      K   s\   t |d}| ||}| }| }|j||fi | |||fi | | || d S )NrQ   )getattrr   r   rh   r   )	r   ro   rl   idxr  rQ   r[   r   r   r   r   r   r     s   
z"TestDUFuncReduceAt._compare_outputc                 C   sr   t d}t g d}| t jd}||||d | t g d| ||||d | t g d| d S )Nr   r   r   r    r"   r   r   )r   r   r   r   )r   r   r   r   )r)   r   r  r   r   r   )r   r   r  rw  r   r   r   test_reduceat_out_kw  s   
z'TestDUFuncReduceAt.test_reduceat_out_kwc              	   C   s   t dddt ddddt df}t g dt g df}d	}|D ]}|D ]}|D ]}| jt j|||d
 q1q-q)d S )Nr   r   r  r7   r"   r   r   r   r   r    r"   r   r  )r    r   r   rY  )r)   r   r;   r   r  r   r   )r   arraysr   rx   r|   r  axr   r   r   test_reduceat_axis_kw  s   z(TestDUFuncReduceAt.test_reduceat_axis_kwc              	   C   s~   t d}t g d}| t jd}dD ]'}d| d|j }| t| |||| W d    n1 s7w   Y  qd S )Nr  r  r   )r"   r  zaxis z) is out of bounds for array of dimension )r)   r   r  r   r   r  r   r'   )r   r   r  add_reduceatr  r@  r   r   r   test_reduceat_invalid_axis  s   
z-TestDUFuncReduceAt.test_reduceat_invalid_axisc                 C   sr   |  tjd}g d}g d}tj||}|||}| || d}d}tj||}|||}| || d S )Nr   r"  r   )r   r)   r   rh   r   )r   r  rl   r  r   r   r   r   r    test_reduceat_cast_args_to_array  s   

z3TestDUFuncReduceAt.test_reduceat_cast_args_to_arrayc                 C   s&   t d}g d}| t j|| d S )Nr   )r   r   r    r7   r"   r   r   r   )r)   r   r   r   r   rC  r  r   r   r   test_reduceat_basic  s   
z&TestDUFuncReduceAt.test_reduceat_basicc                 C   s2   t ddddd}g d}| t j|| d S )Nr   r   r   r   r  )r)   r*   r;   r   r   r  r   r   r   test_reduceat_basic_2d  s   z)TestDUFuncReduceAt.test_reduceat_basic_2dc              	   C   sR   d}t |}t ttt |d t |d d  }| t j|| d S )Nr   r"   )r)   r   r|   listr4  ravelr   r   )r   LrC  r  r   r   r   test_reduceat_shifting_sum  s   
0z-TestDUFuncReduceAt.test_reduceat_shifting_sumc                 C   s  t jdt jd}t jdt jd}| jt j|t d|d | jt j|t d|d | || t jdt jd}dd tdD |dd d f< t jdt jd}dd tdD |dd d f< | jt j|t d|d	d
 | jt j|t d|d	d
 | || d S )Nr   r   r  )r"   r   c                 S      g | ]}d qS r"   r   .0r!  r   r   r   
<listcomp>       zOTestDUFuncReduceAt.test_reduceat_int_array_reduceat_inplace.<locals>.<listcomp>r   c                 S   r  r  r   r  r   r   r   r    r  r   )r   rx   )r)   r   r  r   r   r   r   r  )r   r   r   r   r   r   (test_reduceat_int_array_reduceat_inplace  s   z;TestDUFuncReduceAt.test_reduceat_int_array_reduceat_inplacec              	   C   s|   |  tjd}dD ]2}td}td}|r|tj}| t ||ddg|d W d    n1 s6w   Y  q	d S )Nr   )TFr7   r   r  )r   r)   r   r   r3  r   r&   r'   )r   r  	with_castr   r   r   r   r    test_reduceat_out_shape_mismatch  s   

z3TestDUFuncReduceAt.test_reduceat_out_shape_mismatchc                 C   s   t g d}t g d}| t jd}t j||}|||}| || | |j|j t d}t j	g t j
d}| jt j||dd | jt j||dd dS )	z&Reduceat should work with empty arraysi4rq  r   )r7   r"   r   rY  r    N)r)   r|   r   r   rh   r   r.   r   r   r  r   r   )r   r   rC  r  r   r   r  r   r   r   test_reduceat_empty  s   

z&TestDUFuncReduceAt.test_reduceat_emptyc                 C   sf   |  tjd}td}tddd}| td ||| W d    d S 1 s,w   Y  d S )Nr   r7   r!   r"   zhave at most 1 dimension)r   r)   r   r   r;   r   r   )r   r  rl   r  r   r   r   test_reduceat_error_ndim_2(  s   
"z-TestDUFuncReduceAt.test_reduceat_error_ndim_2c                    sj   t dd  t fdd}td}d}| t| ||g d W d    d S 1 s.w   Y  d S )Nc                 S   r   r   r   rs   r   r   r   neg3  rG   zGTestDUFuncReduceAt.test_reduceat_error_non_binary_function.<locals>.negc                    s     | |S r   r   )rl   r  r  r   r   neg_reduceat7  s   zPTestDUFuncReduceAt.test_reduceat_error_non_binary_function.<locals>.neg_reduceatr7   r   r   )r   r   r)   r   r   r   )r   r  rl   r@  r   r  r   'test_reduceat_error_non_binary_function1  s   

"z:TestDUFuncReduceAt.test_reduceat_error_non_binary_functionc                 C   s  |  tjd}| td |dg d W d    n1 sw   Y  | td |tdd W d    n1 s=w   Y  | td |tdg dd	d
 W d    n1 s_w   Y  | td |tdg ddd W d    d S 1 sw   Y  d S )Nr   z"array" must be array-likeabcr   z"indices" must be array-liker7   abcdzoutput must be an arrayr   r  z"axis" must be an integer)r    rY  )r   r)   r   r   r   r   )r   r  r   r   r   "test_reduceat_error_argument_types@  s   "z5TestDUFuncReduceAt.test_reduceat_error_argument_typesN)rc   rd   re   r   r  rQ  rR  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r    s     		
	r  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                    rr   r   r   rB  rebuiltr   r   r  [  rE  z%TestDUFuncPickling.check.<locals>.fooiA  )pickledumpsloadsr.   assertIsInstancer   )r   identresult_typebufr  r  r   r  r   checkQ  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  d     z3TestDUFuncPickling.test_unrestricted.<locals>.identr  )r   r  r   r)   integerr   r  r   r   r   test_unrestrictedc  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  k  r  z1TestDUFuncPickling.test_restricted.<locals>.identr  )r   r  r   r  r   r   r   test_restrictedj  s   
z"TestDUFuncPickling.test_restrictedN)rc   rd   re   r  r  r  r   r   r   r   r  P  s    r  __main__)$r   r  r  rX   rJ  numpyr)   numbar   r   numba.tests.supportr   r   numba.core.errorsr   r   r   rQ  numba.np.ufuncr	   numba.np.numpy_supportr
   r   r   r   r   r   r   rf   r   rS  r  r  r  rc   mainr   r   r   r   <module>   s@    m-  x h  ."