o
    Z۷i!                     @   s&  d dl mZmZ d dlZd dlmZmZmZ d dl	m
Z
 d dlmZmZmZmZ d dl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d$d% Z d&d' Z!d(d) Z"d*d+ Z#d,d- Z$d.d/ Z%d0d1 Z&d2d3 Z'd4d5 Z(d6d7 Z)d8d9 Z*d:d; Z+d<d= Z,d>d? Z-d@dA Z.dBdC Z/dDdE Z0dFdG Z1dHdI Z2dJdK Z3dLdM Z4dNdO Z5dPdQ Z6dRdS Z7dTdU Z8dVdW Z9dXdY Z:dZd[ Z;d\d] Z<d^d_ Z=d`da Z>dbdc Z?ddde Z@G dfdg dgeeZAeAB  G dhdi dieeZCeCD  eEdjkreF  dS dS )k    )productcombinations_with_replacementN)jitnjittypeof)numpy_version)TestCaseMemoryLeakMixintagskip_if_numpy_2c                 C      |   S N)allarr r   W/home/ubuntu/vllm_env/lib/python3.10/site-packages/numba/tests/test_array_reductions.py	array_all      r   c                 C   
   t | S r   )npr   r   r   r   r   array_all_global      
r   c                 C   r   r   )anyr   r   r   r   	array_any   r   r   c                 C   r   r   )r   r   r   r   r   r   array_any_global   r   r   c                 C   r   r   )cumprodr   r   r   r   array_cumprod   r   r   c                 C   r   r   )r   r   r   r   r   r   array_cumprod_global   r   r   c                 C   r   r   )r   
nancumprodr   r   r   r   array_nancumprod   r   r    c                 C   r   r   )cumsumr   r   r   r   array_cumsum    r   r"   c                 C   r   r   )r   r!   r   r   r   r   array_cumsum_global#   r   r#   c                 C   r   r   )r   	nancumsumr   r   r   r   array_nancumsum&   r   r%   c                 C   r   r   )sumr   r   r   r   	array_sum)   r   r'   c                 C   r   r   )r   r&   r   r   r   r   array_sum_global,   r   r(   c                 C   r   r   )prodr   r   r   r   
array_prod/   r   r*   c                 C   r   r   )r   r)   r   r   r   r   array_prod_global2   r   r+   c                 C   r   r   )meanr   r   r   r   
array_mean5   r   r-   c                 C   r   r   )r   r,   r   r   r   r   array_mean_global8   r   r.   c                 C   r   r   )varr   r   r   r   	array_var;   r   r0   c                 C   r   r   )r   r/   r   r   r   r   array_var_global>   r   r1   c                 C   r   r   )stdr   r   r   r   	array_stdA   r   r3   c                 C   r   r   )r   r2   r   r   r   r   array_std_globalD   r   r4   c                 C   r   r   )minr   r   r   r   	array_minG   r   r6   c                 C   r   r   )r   r5   r   r   r   r   array_min_globalJ   r   r7   c                 C   r   r   )r   aminr   r   r   r   
array_aminM   r   r9   c                 C   r   r   )maxr   r   r   r   	array_maxP   r   r;   c                 C   r   r   )r   r:   r   r   r   r   array_max_globalS   r   r<   c                 C   r   r   )r   amaxr   r   r   r   
array_amaxV   r   r>   c                 C   r   r   argminr   r   r   r   array_argminY   r   rA   c                 C   r   r   r   r@   r   r   r   r   array_argmin_global\   r   rC   c                 C   r   r   argmaxr   r   r   r   array_argmax_   r   rF   c                 C   r   r   r   rE   r   r   r   r   array_argmax_globalb   r   rH   c                 C   r   r   )r   medianr   r   r   r   array_median_globale   r   rJ   c                 C   r   r   )r   nanminr   r   r   r   array_nanminh   r   rL   c                 C   r   r   )r   nanmaxr   r   r   r   array_nanmaxk   r   rN   c                 C   r   r   )r   nanmeanr   r   r   r   array_nanmeann   r   rP   c                 C   r   r   )r   nansumr   r   r   r   array_nansumq   r   rR   c                 C   r   r   )r   nanprodr   r   r   r   array_nanprodt   r   rT   c                 C   r   r   )r   nanstdr   r   r   r   array_nanstdw   r   rV   c                 C   r   r   )r   nanvarr   r   r   r   array_nanvarz   r   rX   c                 C   r   r   )r   	nanmedianr   r   r   r   array_nanmedian_global}   r   rZ   c                 C      t | |S r   )r   
percentiler   qr   r   r   array_percentile_global      r_   c                 C   r[   r   )r   nanpercentiler]   r   r   r   array_nanpercentile_global   r`   rb   c                 C   r   r   )r   ptpar   r   r   array_ptp_global   r   rf   c                 C   r   r   )rc   rd   r   r   r   	array_ptp   r   rg   c                 C   r[   r   )r   quantiler]   r   r   r   array_quantile_global   r`   ri   c                 C   r[   r   )r   nanquantiler]   r   r   r   array_nanquantile_global   r`   rk   c                    sr    t jkr
dd }n fdd}|d}|ddd}|dd d d jd	d
d}|jjs2|jjr4J |||gS )Nc                 S   s&   | d dksJ t ddg| d  S )N   r      )r   bool_nr   r   r   factory   s   z!base_test_arrays.<locals>.factoryc                    s   t j|  dd S )Ndtyperm   )r   arangero   rr   r   r   rq         
   rl         )rl      rl   A)order)r   rn   reshapeflagsc_contiguousf_contiguous)rs   rq   a1a2a3r   rr   r   base_test_arrays   s   


r   c                 C   s   t | }| tjkr|dd |D 7 }| tjkrAg }|D ] }|d d| d  }t|d d d |d d d< || q|| |D ]}|jt| ksOJ qC|S )Nc                 S   s   g | ]}|d  qS )rv   r   ).0re   r   r   r   
<listcomp>   s    z$full_test_arrays.<locals>.<listcomp>rv                 ?   rl   )r   r   float32	complex64conjappendextendrs   )rs   
array_listaccre   tmpr   r   r   full_test_arrays   s   


r   c                 C   s    t | }| |}||}||fS r   )r   )compare_func
test_arraycfuncnumpy_resultnumba_resultr   r   r   run_comparative   s   r   c                       s  e Zd ZdZ fddZdd Zef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&d' Zd(d) Zed*d+ Zd,d- Zd.d/ Zdd1d2Zd3d4 Zd5d6 Z d7d8 Z!d9d: Z"d;d< Z#d=d> Z$d?d@ Z%dAdB Z&dCdD Z'dEdF Z(dGdH Z)dIdJ Z*dKdL Z+dMdN Z,dOdP Z-dQdR Z.ddTdUZ/dVdW Z0dXdY Z1dZd[ Z2d\d] Z3d^d_ Z4d`da Z5dbdc Z6ddde Z7dfdg Z8dhdi Z9djdk Z:dldm Z;dndo Z<dpdq Z=drds Z>dtdu Z?dvdw Z@dxdy ZAdzd{ ZBd|d} ZCd~d ZDdd ZEdd ZFdd ZGeHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXeYdd ZZ  Z[S )TestArrayReductionszQ
    Test array reduction methods and functions such as .sum(), .max(), etc.
    c                    s   t t|   tjd d S )N*   )superr   setUpr   randomseedself	__class__r   r   r      s   zTestArrayReductions.setUpc                    s   t dd  fdd}tg d}|| tddg}|| tg d}|| tg d	}|| tg d
}|| tg d}|| tg d}|| tg d}|| tddg}|| d S )NTnopythonc                    s    j |  | fi  d S r   assertPreciseEqualr   r   kwargspyfuncr   r   r   check   s    z8TestArrayReductions.check_reduction_basic.<locals>.check)      ?       @               r         r   r   )r         @inf)r   r   -inf)r   r   r   r   )nanr   r   r         @)r   r   r   r   r   r   r   )g      @r   r   r   r   )r   r   float64)r   r   r   r   r   r   r   r   check_reduction_basic   s(   z)TestArrayReductions.check_reduction_basicc                    s   t dd  fdd}tddtdtdg}|| d	|d
< || d|d
< || |d}|| ||d d d  d S )NTr   c                        |  |  d S r   r   r   r   r   r   r   r   r         z1TestArrayReductions.test_all_basic.<locals>.checkr   r   r   r   r   rm         ?rl   rl   ry   r   r   r   floatr}   r   r   r   r   r   r   r   test_all_basic   s   
z"TestArrayReductions.test_all_basicc                    s   t dd  fdd}tg d}|| td|d< || td|d< || d	|d< || |d
}|| ||d d d  d S )NTr   c                    r   r   r   r   r   r   r   r      r   z1TestArrayReductions.test_any_basic.<locals>.check)r   r   r   r   r   rl   r   r   r   ry   r   r   r   r   r   test_any_basic   s   
z"TestArrayReductions.test_any_basicc                 C      |  t d S r   )r   r'   r   r   r   r   test_sum_basic     z"TestArrayReductions.test_sum_basicc                 C   r   r   )r   r-   r   r   r   r   test_mean_basic  r   z#TestArrayReductions.test_mean_basicc                 C      | j tdd d S Ndouble)prec)r   r0   r   r   r   r   test_var_basic  ru   z"TestArrayReductions.test_var_basicc                 C   r   r   )r   r3   r   r   r   r   test_std_basic  r   z"TestArrayReductions.test_std_basicc                 C   r   r   )r   r6   r   r   r   r   test_min_basic  r   z"TestArrayReductions.test_min_basicc                 C   r   r   )r   r;   r   r   r   r   test_max_basic  r   z"TestArrayReductions.test_max_basicc                 C   r   r   )r   rA   r   r   r   r   test_argmin_basic  r   z%TestArrayReductions.test_argmin_basicc                 C   r   r   )r   rF   r   r   r   r   test_argmax_basic  r   z%TestArrayReductions.test_argmax_basicc                 C   r   r   )r   rL   r   r   r   r   test_nanmin_basic  r   z%TestArrayReductions.test_nanmin_basicc                 C   r   r   )r   rN   r   r   r   r   test_nanmax_basic  r   z%TestArrayReductions.test_nanmax_basicc                 C   r   r   )r   rP   r   r   r   r   test_nanmean_basic   r   z&TestArrayReductions.test_nanmean_basicc                 C   r   r   )r   rR   r   r   r   r   test_nansum_basic#  r   z%TestArrayReductions.test_nansum_basicc                 C   r   r   )r   rT   r   r   r   r   test_nanprod_basic&  r   z&TestArrayReductions.test_nanprod_basicc                 C   r   r   )r   rV   r   r   r   r   test_nanstd_basic)  r   z%TestArrayReductions.test_nanstd_basicc                 C   r   r   )r   rX   r   r   r   r   test_nanvar_basic,  ru   z%TestArrayReductions.test_nanvar_basicc                    sz   t dd  fddfdd}|tdd D ]}|| qfd	d
}|tdd D ]}|| q4d S )NTr   c                    s    | } | } || d S r   r   )r   expectedgotr   r   r   r   1     z5TestArrayReductions.check_median_basic.<locals>.checkc                    (    |  |  d}  |   | j d S )N)	      r}   Trd   r   r   r   	check_odd7     
z9TestArrayReductions.check_median_basic.<locals>.check_odd?   g      %@c                    r   )N)      r   rd   r   r   r   
check_even@  r   z:TestArrayReductions.check_median_basic.<locals>.check_even@   )r   r   rt   )r   r   array_variationsr   re   r   r   )r   r   r   r   r   check_median_basic/  s   

z&TestArrayReductions.check_median_basicc                 c   sx    | V  | d d d   } | V  tj|  | V  d| | d dk< | V  tj| | d dk< | V  tj| d d < | V  d S )Nry         @r   rm   rl   )copyr   r   shuffler   rd   r   r   r   _array_variationsH  s   
z%TestArrayReductions._array_variationsc                 C   s   t }dd }| || d S )Nc                 s   sL    | V  | d d d   } | V  tj|  | V  d| | d dk< | V  d S )Nry   r   r   rm   )r   r   r   r   rd   r   r   r   
variationsZ  s   
z9TestArrayReductions.test_median_basic.<locals>.variations)rJ   r   )r   r   r   r   r   r   test_median_basicW  s   
z%TestArrayReductions.test_median_basicc                    s  t dd d" fdd	}jdddd}td|d	d d d
 }||| ||d |||d  ||| tjtj tjg}j|d|j	d d< j
| j
| ||| |  }|  }||| |t|t| jg dd}td|d}||| tdd }tj |dd tj ||d tj ||d d tddd}td| }tj ||g d tddddd}td| }tj ||jd td| }tj ||jd tddd}tj ||d d t ||d  tj g ddd  tg d!} ||d g tj|tg d! d S )#NTr   -q=c                    X   | |} | |}t |}t |rj|||d d S j|| || |d d S N)abs_tolr   isfiniter   r   re   r^   r   r   r   finiter   r   r   r   i     




z@TestArrayReductions.check_percentile_and_quantile.<locals>.check   rz   r      ry   rl   rv   )rm   rl   rz   r   rw            ?r   r   g      ?rx   r   )      ?r   r   )g      @      @g      &@ih     )r   r   rl   )r   r   g      ?)rz   r   )rm   rl   rz   rm   )rl   rz   r   rm   )r   )r   r   randnr}   r   linspacer   r   choiceflatr   flattentolisttuplert   testingassert_equalarrayshape
assertTrueisscalar)r   r   q_upper_boundr   re   r^   
not_finitexr   r   r   check_percentile_and_quantilef  sN   





z1TestArrayReductions.check_percentile_and_quantiled   c           
         s   t dd d fdd	}d fdd	}dd	 }d
d| d| |f}ddtjtjtj f}||D ]}||| q6|dkrE|}	n|}	td}td}|	|| d}|d }|	|| d S )NTr   +=c                    r   r   r   r   r   r   r   r     r   z>TestArrayReductions.check_percentile_edge_cases.<locals>.checkc                    s0   | | tj} | |}j|||d d S r   )astyper   r   r   )re   r^   r   r   r   r   r   r   convert_to_float_and_check  s   
zSTestArrayReductions.check_percentile_edge_cases.<locals>.convert_to_float_and_checkc                 s   s2    t ddD ]}t| |D ]}t|V  qqd S )Nrm   rv   )ranger   r   r  )elementsicombr   r   r   _array_combinations  s   zLTestArrayReductions.check_percentile_edge_cases.<locals>._array_combinationsr   皙?g?rm   ry   rw   rl   )r  )r   r   r   r   r  )
r   r   r  r   r  r  r^   element_poolre   _checkr   r   r   check_percentile_edge_cases  s"   


z/TestArrayReductions.check_percentile_edge_casesc                    s   t dd|  fdd}  td}||d ||d ||dd	tjf  }tdd
 }d} || W d    n1 sGw   Y  dt|j d S )NTr   c                    J    t} | | W d    n1 sw   Y  dt|j d S )Nz)Percentiles must be in the range [0, 100]assertRaises
ValueErrorassertEqualstr	exceptionre   r^   raisesr   r   r   r   	check_err     zBTestArrayReductions.check_percentile_exceptions.<locals>.check_errrw   )rm   rv   i   rm   rv   r   r  Not supported for complex dtype	r   disable_leak_checkr   rt   r   assertTypingErrorassertInr!  r"  r   r   r&  re   er^   r   r%  r   check_percentile_exceptions     	



z/TestArrayReductions.check_percentile_exceptionsc                    s   t dd|  fdd}  td}||d ||d ||ddtjf  }tdd	 }d} || W d    n1 sGw   Y  d
t|j d S )NTr   c                    r  )Nz%Quantiles must be in the range [0, 1]r  r#  r%  r   r   r&    r'  z@TestArrayReductions.check_quantile_exceptions.<locals>.check_errrw   g      )r  r  g?r  r   r*  r+  r/  r   r%  r   check_quantile_exceptions  r2  z-TestArrayReductions.check_quantile_exceptionsc                 C   .   t }| j|dd | j|dd | | d S Nr  r  )r_   r  r  r1  r   r   r   r   r   test_percentile_basic	     z)TestArrayReductions.test_percentile_basicc                 C   r4  r5  )rb   r  r  r1  r7  r   r   r   test_nanpercentile_basic  r9  z,TestArrayReductions.test_nanpercentile_basicc                 C   r4  Nrm   r6  )ri   r  r  r3  r7  r   r   r   test_quantile_basic  r9  z'TestArrayReductions.test_quantile_basicc                 C   r4  r;  )rk   r  r  r3  r7  r   r   r   test_nanquantile_basic  r9  z*TestArrayReductions.test_nanquantile_basicc                 C   s   t }| || j d S r   )rZ   r   r   r7  r   r   r   test_nanmedian_basic!  s   z(TestArrayReductions.test_nanmedian_basicc                 C   s\   t jdt jd}t|}| |jd | |jd t|ft}| t 	||| d S Nrv   rr   rm   C)
r   rt   int32r   r   ndimlayoutr   r(   r&   r   r   arrtyr   r   r   r   test_array_sum_global%  s   z)TestArrayReductions.test_array_sum_globalc                 C   s^   t jdt jdd }t|}| |jd | |jd t|ft}| |	 || d S r?  )
r   rt   rA  r   r   rB  rC  r   r*   r)   rD  r   r   r   test_array_prod_int_1d.  s   z*TestArrayReductions.test_array_prod_int_1dc                 C   s`   t jdt jdd }t|}| |jd | |jd t|ft}t j	
| || d S )Nrv   rr   r  rm   r@  )r   rt   r   r   r   rB  rC  r   r*   r  assert_allcloser)   rD  r   r   r   test_array_prod_float_1d7  s   z,TestArrayReductions.test_array_prod_float_1dc                 C   s^   t jdt jd}t|}| |jd | |jd t|ft}t j	
t ||| d S r?  )r   rt   rA  r   r   rB  rC  r   r+   r  rH  r)   rD  r   r   r   test_array_prod_global@  s   z*TestArrayReductions.test_array_prod_globalc                 C   s|   t jddt jd}t||\}}| || t ddd}t||\}}| || |d}t||\}}| || d S )Nrl   rv   rr   r   r   )rz   rl   )r   rt   int16r   r   r   r}   )r   r   r   r   r   r   r   r   check_cumulativeI  s   
z$TestArrayReductions.check_cumulativec                 C   r   r   )rL  r"   r   r   r   r   test_array_cumsumT  r   z%TestArrayReductions.test_array_cumsumc                 C   r   r   )rL  r#   r   r   r   r   test_array_cumsum_globalW  r   z,TestArrayReductions.test_array_cumsum_globalc                 C   r   r   )rL  r   r   r   r   r   test_array_cumprodZ  r   z&TestArrayReductions.test_array_cumprodc                 C   r   r   )rL  r   r   r   r   r   test_array_cumprod_global]  r   z-TestArrayReductions.test_array_cumprod_globalFc                 C   s   |rdnd}t |d d}t||\}}| || t dd d}t||\}}| || |d}t||\}}| || dS )	zH
        Check that integer overflows are avoided (issue #931).
        rl   rv   i@  rK  l            int64uint64N)r   rt   r  r   r   )r   r   is_prodn_itemsr   nprnbrr   r   r   check_aggregation_magnitude`  s   
z/TestArrayReductions.check_aggregation_magnitudec                 C      |  t |  t d S r   )rW  r'   r(   r   r   r   r   test_sum_magnitudes     
z&TestArrayReductions.test_sum_magnitudec                 C   rX  r   )rW  r"   r#   r   r   r   r   test_cumsum_magnitudew  rZ  z)TestArrayReductions.test_cumsum_magnitudec                 C   r   NT)rS  )rW  r%   r   r   r   r   test_nancumsum_magnitude{  ru   z,TestArrayReductions.test_nancumsum_magnitudec                 C       | j tdd | j tdd d S r\  )rW  r*   r+   r   r   r   r   test_prod_magnitude~     z'TestArrayReductions.test_prod_magnitudec                 C   r^  r\  )rW  r   r   r   r   r   r   test_cumprod_magnitude  r`  z*TestArrayReductions.test_cumprod_magnitudec                 C   r   r\  )rW  r    r   r   r   r   test_nancumprod_magnitude  ru   z-TestArrayReductions.test_nancumprod_magnitudec                 C   rX  r   )rW  r-   r.   r   r   r   r   test_mean_magnitude  rZ  z'TestArrayReductions.test_mean_magnitudec                 C   rX  r   )rW  r0   r1   r   r   r   r   test_var_magnitude  rZ  z&TestArrayReductions.test_var_magnitudec                 C   rX  r   )rW  r3   r4   r   r   r   r   test_std_magnitude  rZ  z&TestArrayReductions.test_std_magnitudec                 C   s   t |}tdd|}| |||| | ||d d ||d d  |d d d  }| |||| tj| | |||| d|jvrhtdt	|dD ]}d||< qW| |||| |
|d | |||| d S )NTr   ry   rI   rm   rl   NaT)r   r   r   r   r   r   r   __name__r  lenfillrs   )r   r   r   rE  r   r  r   r   r   _do_check_nptimedelta  s   $

z)TestArrayReductions._do_check_nptimedeltac                 C   "   t djdd}| || d S )Nrv   zM8[Y]rr   r   rt   r  rj  r   r   r   r   r   r   check_npdatetime     z$TestArrayReductions.check_npdatetimec                 C   rk  )Nrv   zm8[s]rr   rl  rm  r   r   r   check_nptimedelta  ro  z%TestArrayReductions.check_nptimedeltac                 C      |  t | t d S r   )rn  r6   rp  r   r   r   r   test_min_npdatetime  rZ  z'TestArrayReductions.test_min_npdatetimec                 C   rq  r   )rn  r;   rp  r   r   r   r   test_max_npdatetime  rZ  z'TestArrayReductions.test_max_npdatetimec                 C   rq  r   )rn  rA   rp  r   r   r   r   test_argmin_npdatetime  rZ  z*TestArrayReductions.test_argmin_npdatetimec                 C   rq  r   )rn  rF   rp  r   r   r   r   test_argmax_npdatetime  rZ  z*TestArrayReductions.test_argmax_npdatetimec                 C   r   r   )rp  rJ   r   r   r   r   test_median_npdatetime  r   z*TestArrayReductions.test_median_npdatetimec                 C   r   r   )rp  r'   r   r   r   r   test_sum_npdatetime  r   z'TestArrayReductions.test_sum_npdatetimec                 C   r   r   )rp  r"   r   r   r   r   test_cumsum_npdatetime  r   z*TestArrayReductions.test_cumsum_npdatetimec                 C   r   r   )rp  r-   r   r   r   r   test_mean_npdatetime  r   z(TestArrayReductions.test_mean_npdatetimec                    s   t dd  fdd}dd }dd }| D ]}|| |||tj q|tg  |td	tj ttjd
tjddddddg	}|d|d d d   }|dd}|| d S )NTr   c                        | } | } || d S r   r   re   r   r   r   r   r   r     r   z7TestArrayReductions.check_nan_cumulative.<locals>.checkc                 S   s2   | j d }t| tjjt| j |ddtj | S )Nrl   F)replace)sizer   putr   r   r  r   )re   pr   r   r   _set_some_values_to_nan  s   
$zITestArrayReductions.check_nan_cumulative.<locals>._set_some_values_to_nanc                   s   s    t ddddddV  t t jddgV  t g dV  t ddV  t t dd	d
 V  t jddt jdd d d V  d S )Nry   rz   <   r   rw   )TTTFrm   rv   r   gfffff@@rr   )r   r   r}   r  r   rt   asfortranarrayr   r   r   r   r   a_variations  s   "z>TestArrayReductions.check_nan_cumulative.<locals>.a_variationsrv   rl   r   rw   r   r   r   r   r   ry   rz   )r   r  r   r   r  fullr   r}   )r   r   r   r  r  re   partsr   r   r   check_nan_cumulative  s   
 z(TestArrayReductions.check_nan_cumulativec                 C   rq  r   )rL  r    r  r   r   r   r   test_nancumprod_basic  rZ  z)TestArrayReductions.test_nancumprod_basicc                 C   rq  r   )rL  r%   r  r   r   r   r   test_nancumsum_basic  rZ  z(TestArrayReductions.test_nancumsum_basicc                    sB   t tdd  fdd}dd }| D ]}|| qd S )NTr   c                    rz  r   r   r{  r   r   r   r     r   z1TestArrayReductions.test_ptp_basic.<locals>.checkc                  s   s$   t dV  t dt jdgV  t t j dgV  dV  dV  t ddV  g dV  t ddd	d
dd} | V  t | V  | d d d V  t j	
d|  | V  dV  dV  t j V  dV  dt jgV  dt jgV  dV  t dt jV  dt jd  V  t jt jd  V  t jV  d S )Nrv   g皙@rw   )r   rl   rw   rm   )r  gffffffr  r   r   rl   ry   r   r   g      @y      ?      @))gffffff@r   gffffff)g333333@g@g@rm   r   )r   rt   r  r   r   r  r   r}   r  r   RandomStater   rd   r   r   r   r    s2   

z8TestArrayReductions.test_ptp_basic.<locals>.a_variations)rf   r   )r   r   r  re   r   r   r   test_ptp_basic  s   

z"TestArrayReductions.test_ptp_basicc                 C   s<   t }tdd|}td}||}||}| || d S )NTr   rv   )rg   r   r   rt   r   )r   r   r   re   r   r   r   r   r   test_ptp_method$  s   
z#TestArrayReductions.test_ptp_methodc                    s   t tdd  fdd}ddd}tddgdd	D ]\}}|||}|| qtd
}tdd}|d|  }|| |d|  }|| tjddd}|| d S )NTr   c                    rz  r   r   r{  r   r   r   r   4  r   z3TestArrayReductions.test_ptp_complex.<locals>.checkFc                 S   sT   t ddd}| rt j|dd< t ddd}|r t j|dd< |d	|  ddS )
Nr      r   r(  rw   r   rx   r   )r   r   r   r}   )real_nanimag_nanrealimagr   r   r   
make_array9  s   z8TestArrayReductions.test_ptp_complex.<locals>.make_arrayrl   )repeatr   r  r   r   )r   r   y      ?      )
fill_value)FF)rf   r   r   r   onesrt   r  )r   r   r  r  r  compr  r  r   r   r   test_ptp_complex0  s   
	


z$TestArrayReductions.test_ptp_complexc                 C   s   t }tdd|}|   |  }|td W d    n1 s#w   Y  d}| |t|j | 	t
}|tg  W d    n1 sJw   Y  d}| |t|j d S )NTr   )TTFz+Boolean dtype is unsupported (as per NumPy)z&zero-size array reduction not possible)rf   r   r,  r-  r   r  r.  r!  r"  r  r  )r   r   r   r0  msgr   r   r   test_ptp_exceptionsP  s   
z'TestArrayReductions.test_ptp_exceptionsc                    s   t tf}|D ]`tdd  fdd}tddd}|d |d d	< |d
 }||d  }|| tdD ]-}j| j| jtj	tj
g}||d  }|d |d d	< ||| q8qd S )NTr   c                    rz  r   r   r{  r   r   r   r   i  r   z=TestArrayReductions.test_min_max_complex_basic.<locals>.checkr  rv   (   ry   r   rl   r   )r7   r<   r   r   r   r  r   r   r   r   
complex128r  )r   pyfuncsr   r  r  re   _rs   r   r   r   test_min_max_complex_basicc  s$   z.TestArrayReductions.test_min_max_complex_basicc                    s   t tf}|D ]atdd  fdd}tddd}|d |d d	< tj|d
d< |d }tj|dd< ||d  }|| tdD ] }j| j| ||d  }|d |d d	< || qFqd S )NTr   c                    rz  r   r   r{  r   r   r   r     r   zCTestArrayReductions.test_nanmin_nanmax_complex_basic.<locals>.checkr  rv   r  ry   r   rw   r   rl   r   rx   r   )	rL   rN   r   r   r   r   r  r   r   )r   r  r   r  r  re   r  r   r   r    test_nanmin_nanmax_complex_basic|  s&   
z4TestArrayReductions.test_nanmin_nanmax_complex_basicc                    sP   t tf} fdd}dd }|D ]tdd | D ]}|| qqd S )Nc                    rz  r   r   r{  r   r   r   r     r   zFTestArrayReductions.test_nanmin_nanmax_non_array_inputs.<locals>.checkc                   s   sh    g dV  dV  t dV  dV  dV  dV  t jdddfV  t jt jt j gV  t jd	fd
gV  d S )N)rm   r   r   rl   ))r  r   i)rw      irz   r   gA`"	@Fgr   g?)ggffffff!@)r   r  r   r   r   r   r   r   r    s   
zMTestArrayReductions.test_nanmin_nanmax_non_array_inputs.<locals>.a_variationsTr   )rL   rN   r   )r   r  r   r  re   r   r   r   #test_nanmin_nanmax_non_array_inputs  s   

z7TestArrayReductions.test_nanmin_nanmax_non_array_inputsc           	      C      t g d}t ddd}|d  d7  < t ddddd	d
 }|d  d7  < |d  d8  < |||fD ]1}tt|jdd t|jD  }dd |D }dd |D }|D ]}| |||| q]q:d S )Nr      rz   r   r   rl   rz   r   rm   r  x   r   rw   rv   r   rm   rm   rl   rm   r   r   r   3   c                 S      g | ]}|d   qS r  r   r   r  r   r   r   r         
zATestArrayReductions.test_argmax_axis_1d_2d_4d.<locals>.<listcomp>c                 S      g | ]}|fd dqS )c                 S      t j| |dS NaxisrG   re   _axisr   r   r   <lambda>      zJTestArrayReductions.test_argmax_axis_1d_2d_4d.<locals>.<listcomp>.<lambda>r   r   r  r   r   r   r         
c                 S      g | ]	}t d d|qS Tr   r   r   r   r   r   r   r         	r   r  rt   r}   listr  rB  r   py_func	r   arr1darr2darr4dr   axespy_functionsc_functionsr   r   r   r   test_argmax_axis_1d_2d_4d  (   z-TestArrayReductions.test_argmax_axis_1d_2d_4dc                    p   t d}t ddd}tdddd   fdd	}||d
 ||d ||d ||d   d S )Nr   rl   rz   Tr   c                 S   r[   r   rG   r   r  r   r   r   	jitargmax     zDTestArrayReductions.test_argmax_axis_out_of_range.<locals>.jitargmaxc                    t    td  | | W d    n1 sw   Y   td  | | W d    d S 1 s3w   Y  d S Nzaxis.*out of boundsassertRaisesRegexr  r  r  r  r   r   r   assert_raises     "zHTestArrayReductions.test_argmax_axis_out_of_range.<locals>.assert_raisesrm   r   rt   r}   r   r,  r   r  r  r  r   r  r   test_argmax_axis_out_of_range  s   





z1TestArrayReductions.test_argmax_axis_out_of_rangec                 C   d   t d}tdddd }|  }||d W d    n1 s"w   Y  | dt|j d S )Nr   Tr   c                 S   r[   r   rG   r  r   r   r   r    r  zGTestArrayReductions.test_argmax_axis_must_be_integer.<locals>.jitargmaxfooaxis must be an integerr   rt   r   r-  r.  r!  r"  )r   r   r  r0  r   r   r    test_argmax_axis_must_be_integer     


z4TestArrayReductions.test_argmax_axis_must_be_integerc                    @   t ddd  fdd}| | tdd|  d S )Nr   rl   rz   c                        j ddS Nr   r  rD   r   r  r   r   rE     r`   z;TestArrayReductions.test_argmax_method_axis.<locals>.argmaxTr   r   rt   r}   r   r   r   rE   r   r  r   test_argmax_method_axis  
   
z+TestArrayReductions.test_argmax_method_axisc                    F   t jdt jddd  fdd}| | tdd|  d S )	Nr   rr   rl   rz   c                    r  r  rD   r   r  r   r   rE     r`   z;TestArrayReductions.test_argmax_return_type.<locals>.argmaxTr   r   rt   uint8r}   r   r   r  r   r  r   test_argmax_return_type  
   
z+TestArrayReductions.test_argmax_return_typec           	      C   r  )Nr  r   rl   rz   r  r  r  r   rw   rv   r  r  r  c                 S   r  r  r   r  r   r   r   r     r  zATestArrayReductions.test_argmin_axis_1d_2d_4d.<locals>.<listcomp>c                 S   r  )c                 S   r  r  rB   r  r   r   r   r    r  zJTestArrayReductions.test_argmin_axis_1d_2d_4d.<locals>.<listcomp>.<lambda>r   r  r   r   r   r     r  c                 S   r  r  r  r  r   r   r   r   
  r  r  r  r   r   r   test_argmin_axis_1d_2d_4d  r  z-TestArrayReductions.test_argmin_axis_1d_2d_4dc                    r  )Nr   rl   rz   Tr   c                 S   r[   r   rB   r  r   r   r   	jitargmin  r  zDTestArrayReductions.test_argmin_axis_out_of_range.<locals>.jitargminc                    r  r  r  r  r  r   r   r   r    r  zHTestArrayReductions.test_argmin_axis_out_of_range.<locals>.assert_raisesrm   r  r  r  r  r   r  r   test_argmin_axis_out_of_range  s   





z1TestArrayReductions.test_argmin_axis_out_of_rangec                 C   r  )Nr   Tr   c                 S   r[   r   rB   r  r   r   r   r  )  r  zGTestArrayReductions.test_argmin_axis_must_be_integer.<locals>.jitargminr  r  r  )r   r   r  r0  r   r   r    test_argmin_axis_must_be_integer&  r  z4TestArrayReductions.test_argmin_axis_must_be_integerc                    r  )Nr   rl   rz   c                    r  r  r?   r   r  r   r   r@   4  r`   z;TestArrayReductions.test_argmin_method_axis.<locals>.argminTr   r  r   r@   r   r  r   test_argmin_method_axis1  r  z+TestArrayReductions.test_argmin_method_axisc                    r  )	Nr   rr   rl   rz   c                    r  r  r?   r   r  r   r   r@   >  r`   z;TestArrayReductions.test_argmin_return_type.<locals>.argminTr   r  r  r   r  r   test_argmin_return_type:  r  z+TestArrayReductions.test_argmin_return_typec                    s   t ttttttttt	t
ttttttttttttg}ttttg}|tttg7 }|tg7 }tj tj!tj"tj#g} fdd}||d d | ||| d S )Nc                    sd   | D ]-}t |}t||D ]!\ }d}| j|jj|j} ||f fdd	}t|| qqd S )Nztest_{0}_{1}_{2}dc                    sB   d}d j v rt|rd}t||\}}| j|||d|d d S )Nrm   r)   rz   single)r  r   ulps)rg  r   iscomplexobjr   r   )r   redFunc	testArraytestNamer  rU  rV  red_funcr   r   new_test_functionl  s   


z]TestArrayReductions.install_generated_tests.<locals>.install_tests.<locals>.new_test_function)r   r   formatrg  rs   namerB  setattr)dtypesfuncsdttest_arraysr   	test_namer  clsr  r   install_testsa  s   zBTestArrayReductions.install_generated_tests.<locals>.install_testsry   )$r'   r(   r*   r+   r-   r.   r0   r1   r3   r4   r   r   r   r   r6   r7   r>   r9   r;   r<   rN   rL   rR   rA   rC   rF   rH   rP   rV   rX   rT   r   rA  r   rn   r   )r	  reduction_funcsreduction_funcs_rspacedtypes_to_testr
  r   r  r   install_generated_testsD  s,   
z+TestArrayReductions.install_generated_tests)r  )F)\rg  
__module____qualname____doc__r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   staticmethodr   r   r  r  r1  r3  r8  r:  r<  r=  r>  rF  rG  rI  rJ  rL  rM  rN  rO  rP  rW  rY  r[  r]  r_  ra  rb  rc  rd  re  rj  rn  rp  rr  rs  rt  ru  rv  rw  rx  ry  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  classmethodr  __classcell__r   r   r   r   r      s    

A.				
#&
 	
	
r   c                   @   s*   e Zd ZedZdd Zedd ZdS )TestArrayReductionsExceptionsr   c                 C   s   t dd|}| t || j W d    n1 sw   Y  | t}|| j W d    n1 s6w   Y  | |t|j d S )NTr   )r   r  BaseException	zero_sizer  r.  r!  r"  )r   r   r  r   r0  r   r   r   check_exception  s   z-TestArrayReductionsExceptions.check_exceptionc                 C   s   t  }d}d}ttttfD ]}|||< qttttfD ]}|||< qd}| D ]'\}}||j	}||j	}	|	
dd
dd}	||	fdd}
t| ||
 q'd S )	Nz'attempt to get {0} of an empty sequencez*zero-size array to reduction operation {0}ztest_zero_size_array_{0}array_ _globalc                 S   s   |  || d S r   )r  )r   funcmessager   r   r   test_fn  s   z6TestArrayReductionsExceptions.install.<locals>.test_fn)dictrF   rH   rA   rC   r;   r6   itemsr   rg  r|  r  )r	  	fn_to_msg	empty_seqop_no_identr  name_templatefnr  r  lmsgr  r   r   r   install  s"   

z%TestArrayReductionsExceptions.installN)	rg  r  r  r   rt   r  r  r  r'  r   r   r   r   r    s
    

r  __main__)G	itertoolsr   r   numpyr   numbar   r   r   numba.np.numpy_supportr   numba.tests.supportr   r	   r
   r   unittestr   r   r   r   r   r   r    r"   r#   r%   r'   r(   r*   r+   r-   r.   r0   r1   r3   r4   r6   r7   r9   r;   r<   r>   rA   rC   rF   rH   rJ   rL   rN   rP   rR   rT   rV   rX   rZ   r_   rb   rf   rg   ri   rk   r   r   r   r   r  r  r'  rg  mainr   r   r   r   <module>   s           K'
