o
    1&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   LC:\wamp64\www\opt\env\Lib\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   Z
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   Z	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   r.   c                 C   r   r   )r   r-   r   r   r   r   array_var_global>   r   r/   c                 C   r   r   )stdr   r   r   r   	array_stdA   r   r1   c                 C   r   r   )r   r0   r   r   r   r   array_std_globalD   r   r2   c                 C   r   r   )minr   r   r   r   	array_minG   r   r4   c                 C   r   r   )r   r3   r   r   r   r   array_min_globalJ   r   r5   c                 C   r   r   )r   Zaminr   r   r   r   
array_aminM   r   r6   c                 C   r   r   )maxr   r   r   r   	array_maxP   r   r8   c                 C   r   r   )r   r7   r   r   r   r   array_max_globalS   r   r9   c                 C   r   r   )r   Zamaxr   r   r   r   
array_amaxV   r   r:   c                 C   r   r   argminr   r   r   r   array_argminY   r   r=   c                 C   r   r   r   r<   r   r   r   r   array_argmin_global\   r   r?   c                 C   r   r   argmaxr   r   r   r   array_argmax_   r   rB   c                 C   r   r   r   rA   r   r   r   r   array_argmax_globalb   r   rD   c                 C   r   r   )r   medianr   r   r   r   array_median_globale   r   rF   c                 C   r   r   )r   Znanminr   r   r   r   array_nanminh   r   rG   c                 C   r   r   )r   Znanmaxr   r   r   r   array_nanmaxk   r   rH   c                 C   r   r   )r   Znanmeanr   r   r   r   array_nanmeann   r   rI   c                 C   r   r   )r   Znansumr   r   r   r   array_nansumq   r   rJ   c                 C   r   r   )r   Znanprodr   r   r   r   array_nanprodt   r   rK   c                 C   r   r   )r   Znanstdr   r   r   r   array_nanstdw   r   rL   c                 C   r   r   )r   Znanvarr   r   r   r   array_nanvarz   r   rM   c                 C   r   r   )r   Z	nanmedianr   r   r   r   array_nanmedian_global}   r   rN   c                 C      t | |S r   )r   Z
percentiler   qr   r   r   array_percentile_global      rR   c                 C   rO   r   )r   ZnanpercentilerP   r   r   r   array_nanpercentile_global   rS   rT   c                 C   r   r   )r   ptpar   r   r   array_ptp_global   r   rX   c                 C   r   r   )rU   rV   r   r   r   	array_ptp   r   rY   c                 C   rO   r   )r   ZquantilerP   r   r   r   array_quantile_global   rS   rZ   c                 C   rO   r   )r   ZnanquantilerP   r   r   r   array_nanquantile_global   rS   r[   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dtyper]   )r   aranger_   rb   r   r   ra         
   r\         )r\      r\   A)order)r   r^   reshapeflagsc_contiguousf_contiguous)rc   ra   Za1Za2a3r   rb   r   base_test_arrays   s   


rr   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 )rf   r   ).0rW   r   r   r   
<listcomp>   s    z$full_test_arrays.<locals>.<listcomp>rf                 ?   r\   )rr   r   float32	complex64Zconjappendextendrc   )rc   Z
array_listaccrW   tmpr   r   r   full_test_arrays   s   


r}   c                 C   s    t | }| |}||}||fS r   )r   )Zcompare_func
test_arraycfuncZnumpy_resultZ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Z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   r]         ?r\   r\   ri   r   r   r   floatrm   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   r\   r   r   r   ri   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   r.   r   r   r   r   test_var_basic  re   z"TestArrayReductions.test_var_basicc                 C   r   r   )r   r1   r   r   r   r   test_std_basic  r   z"TestArrayReductions.test_std_basicc                 C   r   r   )r   r4   r   r   r   r   test_min_basic  r   z"TestArrayReductions.test_min_basicc                 C   r   r   )r   r8   r   r   r   r   test_max_basic  r   z"TestArrayReductions.test_max_basicc                 C   r   r   )r   r=   r   r   r   r   test_argmin_basic  r   z%TestArrayReductions.test_argmin_basicc                 C   r   r   )r   rB   r   r   r   r   test_argmax_basic  r   z%TestArrayReductions.test_argmax_basicc                 C   r   r   )r   rG   r   r   r   r   test_nanmin_basic  r   z%TestArrayReductions.test_nanmin_basicc                 C   r   r   )r   rH   r   r   r   r   test_nanmax_basic  r   z%TestArrayReductions.test_nanmax_basicc                 C   r   r   )r   rI   r   r   r   r   test_nanmean_basic   r   z&TestArrayReductions.test_nanmean_basicc                 C   r   r   )r   rJ   r   r   r   r   test_nansum_basic#  r   z%TestArrayReductions.test_nansum_basicc                 C   r   r   )r   rK   r   r   r   r   test_nanprod_basic&  r   z&TestArrayReductions.test_nanprod_basicc                 C   r   r   )r   rL   r   r   r   r   test_nanstd_basic)  r   z%TestArrayReductions.test_nanstd_basicc                 C   r   r   )r   rM   r   r   r   r   test_nanvar_basic,  re   z%TestArrayReductions.test_nanvar_basicc                    s   t dd  fddtg  fdd}|tdd D ]}|| q%fd	d
}|tdd D ]}|| q;d 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)	      rm   TrV   r   r   r   	check_odd:     
z9TestArrayReductions.check_median_basic.<locals>.check_odd?   g      %@c                    r   )N)      r   rV   r   r   r   
check_evenC  r   z:TestArrayReductions.check_median_basic.<locals>.check_even@   )r   r   arrayrd   )r   r   Zarray_variationsr   rW   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 )Nri         @r   r]   r\   )copyr   r   shuffler   rV   r   r   r   _array_variationsK  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 )Nri   r   r   r]   )r   r   r   r   rV   r   r   r   
variations]  s   
z9TestArrayReductions.test_median_basic.<locals>.variations)rF   r   )r   r   r   r   r   r   test_median_basicZ  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   rW   rQ   r   r   r   Zfiniter   r   r   r   l     




z@TestArrayReductions.check_percentile_and_quantile.<locals>.check   rj   r      ri   r\   rf   )r]   r\   rj   r   rg            ?r   r   g      ?rh   r   )      ?r   r   )g      @      @g      &@ih     )r   r   r\   )r   r   g      ?)rj   r   )r]   r\   rj   r]   )r\   rj   r   r]   )r   )r   r   Zrandnrm   r   linspacer   r   choiceZflatr   flattentolisttuplerd   testingZassert_equalr   shape
assertTrueZisscalar)r   r   q_upper_boundr   rW   rQ   Z
not_finitexr   r   r   check_percentile_and_quantilei  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   )rW   rQ   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 )Nr]   rf   )ranger   r   r   )elementsicombr   r   r   _array_combinations  s   zLTestArrayReductions.check_percentile_edge_cases.<locals>._array_combinationsr   皙?g?r]   ri   rg   r\   )r   )r   r   r   r   r   )
r   r   r   r   r   r   rQ   Zelement_poolrW   _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rW   rQ   Zraisesr   r   r   r   	check_err     zBTestArrayReductions.check_percentile_exceptions.<locals>.check_errrg   )r]   rf   i   r]   rf   ru   r   Not supported for complex dtype	r   disable_leak_checkr   rd   r   assertTypingErrorassertInr  r  r   r   r  rW   erQ   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_errrg   g      )r   r   g?r   ru   r	  r
  r  r   r  r   check_quantile_exceptions  r  z-TestArrayReductions.check_quantile_exceptionsc                 C   .   t }| j|dd | j|dd | | d S Nr   r   )rR   r   r   r  r   r   r   r   r   test_percentile_basic     z)TestArrayReductions.test_percentile_basicc                 C   r  r  )rT   r   r   r  r  r   r   r   test_nanpercentile_basic  r  z,TestArrayReductions.test_nanpercentile_basicc                 C   r  Nr]   r  )rZ   r   r   r  r  r   r   r   test_quantile_basic  r  z'TestArrayReductions.test_quantile_basicc                 C   r  r  )r[   r   r   r  r  r   r   r   test_nanquantile_basic  r  z*TestArrayReductions.test_nanquantile_basicc                 C   s   t }| || j d S r   )rN   r   r   r  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 Nrf   rb   r]   C)
r   rd   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   rd   r   r   r   r!  r"  r   r(   r'   r#  r   r   r   test_array_prod_int_1d1  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 )Nrf   rb   r   r]   r  )r   rd   rw   r   r   r!  r"  r   r(   r   assert_allcloser'   r#  r   r   r   test_array_prod_float_1d:  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   rd   r   r   r   r!  r"  r   r)   r   r'  r'   r#  r   r   r   test_array_prod_globalC  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 )Nr\   rf   rb   r   r   )rj   r\   )r   rd   int16r   r   r   rm   )r   r   r   r   r   r   r   r   check_cumulativeL  s   
z$TestArrayReductions.check_cumulativec                 C   r   r   )r+  r!   r   r   r   r   test_array_cumsumW  r   z%TestArrayReductions.test_array_cumsumc                 C   r   r   )r+  r"   r   r   r   r   test_array_cumsum_globalZ  r   z,TestArrayReductions.test_array_cumsum_globalc                 C   r   r   )r+  r   r   r   r   r   test_array_cumprod]  r   z&TestArrayReductions.test_array_cumprodc                 C   r   r   )r+  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).
        r\   rf   i@  r*  l            Zint64Zuint64N)r   rd   r   r   r   )r   r   is_prodZn_itemsr   nprnbrr   r   r   check_aggregation_magnitudec  s   
z/TestArrayReductions.check_aggregation_magnitudec                 C      |  t |  t d S r   )r3  r%   r&   r   r   r   r   test_sum_magnitudev     
z&TestArrayReductions.test_sum_magnitudec                 C   r4  r   )r3  r!   r"   r   r   r   r   test_cumsum_magnitudez  r6  z)TestArrayReductions.test_cumsum_magnitudec                 C   r   NT)r0  )r3  r#   r   r   r   r   test_nancumsum_magnitude~  re   z,TestArrayReductions.test_nancumsum_magnitudec                 C       | j tdd | j tdd d S r8  )r3  r(   r)   r   r   r   r   test_prod_magnitude     z'TestArrayReductions.test_prod_magnitudec                 C   r:  r8  )r3  r   r   r   r   r   r   test_cumprod_magnitude  r<  z*TestArrayReductions.test_cumprod_magnitudec                 C   r   r8  )r3  r   r   r   r   r   test_nancumprod_magnitude  re   z-TestArrayReductions.test_nancumprod_magnitudec                 C   r4  r   )r3  r+   r,   r   r   r   r   test_mean_magnitude  r6  z'TestArrayReductions.test_mean_magnitudec                 C   r4  r   )r3  r.   r/   r   r   r   r   test_var_magnitude  r6  z&TestArrayReductions.test_var_magnitudec                 C   r4  r   )r3  r1   r2   r   r   r   r   test_std_magnitude  r6  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   ri   rE   r]   r\   ZNaT)r   r   r   r   r   r   r   __name__r   lenfillrc   )r   r   r   r$  r   r   r   r   r   _do_check_nptimedelta  s   $

z)TestArrayReductions._do_check_nptimedeltac                 C   "   t djdd}| || d S )Nrf   zM8[Y]rb   r   rd   r   rE  r   r   r   r   r   r   check_npdatetime     z$TestArrayReductions.check_npdatetimec                 C   rF  )Nrf   zm8[s]rb   rG  rH  r   r   r   check_nptimedelta  rJ  z%TestArrayReductions.check_nptimedeltac                 C      |  t | t d S r   )rI  r4   rK  r   r   r   r   test_min_npdatetime  r6  z'TestArrayReductions.test_min_npdatetimec                 C   rL  r   )rI  r8   rK  r   r   r   r   test_max_npdatetime  r6  z'TestArrayReductions.test_max_npdatetimec                 C   rL  r   )rI  r=   rK  r   r   r   r   test_argmin_npdatetime  r6  z*TestArrayReductions.test_argmin_npdatetimec                 C   rL  r   )rI  rB   rK  r   r   r   r   test_argmax_npdatetime  r6  z*TestArrayReductions.test_argmax_npdatetimec                 C   r   r   )rK  rF   r   r   r   r   test_median_npdatetime  r   z*TestArrayReductions.test_median_npdatetimec                 C   r   r   )rK  r%   r   r   r   r   test_sum_npdatetime  r   z'TestArrayReductions.test_sum_npdatetimec                 C   r   r   )rK  r!   r   r   r   r   test_cumsum_npdatetime  r   z*TestArrayReductions.test_cumsum_npdatetimec                 C   r   r   )rK  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   rW   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 )Nr\   F)replace)sizer   putr   r   r   r   )rW   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 )Nri   rj   <   r   rg   )TTTFr]   rf   r   gfffff@@rb   )r   r   rm   r   r   rd   asfortranarrayrw   r   r   r   r   a_variations  s   "z>TestArrayReductions.check_nan_cumulative.<locals>.a_variationsrf   r\   r   rg   r   r   r   r   ru   ri   rj   )r   r   r   r   r   fullr   rm   )r   r   r   r[  r^  rW   partsr   r   r   check_nan_cumulative  s   
 z(TestArrayReductions.check_nan_cumulativec                 C   rL  r   )r+  r   ra  r   r   r   r   test_nancumprod_basic  r6  z)TestArrayReductions.test_nancumprod_basicc                 C   rL  r   )r+  r#   ra  r   r   r   r   test_nancumsum_basic  r6  z(TestArrayReductions.test_nancumsum_basicc                    sB   t tdd  fdd}dd }| D ]}|| qd S )NTr   c                    rU  r   r   rV  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 )Nrf   g皙@rg   )r   r\   rg   r]   )rd  gffffffr   r   r   r\   ri   r   r   g      @y      ?      @))gffffff@r   gffffff)g333333@g@g@r]   ru   )r   rd   r   r   r   r_  r   rm   r]  r   ZRandomStater   rV   r   r   r   r^  
  s2   

z8TestArrayReductions.test_ptp_basic.<locals>.a_variations)rX   r   )r   r   r^  rW   r   r   r   test_ptp_basic  s   

z"TestArrayReductions.test_ptp_basicc                 C   s<   t }tdd|}td}||}||}| || d S )NTr   rf   )rY   r   r   rd   r   )r   r   r   rW   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                    rU  r   r   rV  r   r   r   r   7  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  rg   r   rh   ru   )r   r   r   rm   )real_nanimag_nanrealimagr   r   r   
make_array<  s   z8TestArrayReductions.test_ptp_complex.<locals>.make_arrayr\   )repeatr   ri  r   ru   )r   r   y      ?      )Z
fill_value)FF)rX   r   r   r   Zonesrd   r_  )r   r   ro  rk  rl  comprm  rn  r   r   r   test_ptp_complex3  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)rX   r   r  r  r   r   r  r  r  r   r   )r   r   r   r  msgr   r   r   test_ptp_exceptionsS  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                    rU  r   r   rV  r   r   r   r   l  r   z=TestArrayReductions.test_min_max_complex_basic.<locals>.checkrf  rf   (   ri   r   r\   ru   )r5   r9   r   r   r   r   r   r   r   rx   Z
complex128r   )r   pyfuncsr   rm  rn  rW   _rc   r   r   r   test_min_max_complex_basicf  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                    rU  r   r   rV  r   r   r   r     r   zCTestArrayReductions.test_nanmin_nanmax_complex_basic.<locals>.checkrf  rf   ru  ri   r   rg   r   r\   r   rh   ru   )	rG   rH   r   r   r   r   r   r   r   )r   rv  r   rm  rn  rW   rw  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                    rU  r   r   rV  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)r]   r   r   r\   ))rf  r   i)rg      irj   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   )rG   rH   r   )r   rv  r   r^  rW   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      rj   r   r   r\   rj   r   r]   r   x   r   rg   rf   r   r]   r]   r\   r]   r   r   r   3   c                 S      g | ]}|d   qS re  r   rs   r   r   r   r   rt         
zATestArrayReductions.test_argmax_axis_1d_2d_4d.<locals>.<listcomp>c                 S      g | ]}|fd dqS )c                 S      t j| |dS NaxisrC   rW   Z_axisr   r   r   <lambda>      zJTestArrayReductions.test_argmax_axis_1d_2d_4d.<locals>.<listcomp>.<lambda>r   rs   r  r   r   r   rt         
c                 S      g | ]	}t d d|qS Tr   r   rs   r   r   r   r   rt         	r   r   rd   rm   listr   r!  r   py_func	r   arr1darr2dZarr4dr   ZaxesZpy_functionsZ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   r\   rj   Tr   c                 S   rO   r   rC   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_raisesr]   r   rd   rm   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   rO   r   rC   r  r   r   r   r    r  zGTestArrayReductions.test_argmax_axis_must_be_integer.<locals>.jitargmaxfooaxis must be an integerr   rd   r   r  r  r  r  )r   r   r  r  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   r\   rj   c                        j ddS Nr   r  r@   r   r  r   r   rA     rS   z;TestArrayReductions.test_argmax_method_axis.<locals>.argmaxTr   r   rd   rm   r   r   r   rA   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   rb   r\   rj   c                    r  r  r@   r   r  r   r   rA     rS   z;TestArrayReductions.test_argmax_return_type.<locals>.argmaxTr   r   rd   Zuint8rm   r   r   r  r   r  r   test_argmax_return_type  
   
z+TestArrayReductions.test_argmax_return_typec           	      C   r|  )Nr}  r   r\   rj   r  r   r  r   rg   rf   r  r  r  c                 S   r  re  r   r  r   r   r   rt     r  zATestArrayReductions.test_argmin_axis_1d_2d_4d.<locals>.<listcomp>c                 S   r  )c                 S   r  r  r>   r  r   r   r   r  
  r  zJTestArrayReductions.test_argmin_axis_1d_2d_4d.<locals>.<listcomp>.<lambda>r   r  r   r   r   rt   	  r  c                 S   r  r  r  r  r   r   r   rt     r  r  r  r   r   r   test_argmin_axis_1d_2d_4d  r  z-TestArrayReductions.test_argmin_axis_1d_2d_4dc                    r  )Nr   r\   rj   Tr   c                 S   rO   r   r>   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_raisesr]   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   rO   r   r>   r  r   r   r   r  ,  r  zGTestArrayReductions.test_argmin_axis_must_be_integer.<locals>.jitargminr  r  r  )r   r   r  r  r   r   r    test_argmin_axis_must_be_integer)  r  z4TestArrayReductions.test_argmin_axis_must_be_integerc                    r  )Nr   r\   rj   c                    r  r  r;   r   r  r   r   r<   7  rS   z;TestArrayReductions.test_argmin_method_axis.<locals>.argminTr   r  r   r<   r   r  r   test_argmin_method_axis4  r  z+TestArrayReductions.test_argmin_method_axisc                    r  )	Nr   rb   r\   rj   c                    r  r  r;   r   r  r   r   r<   A  rS   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 )Nr]   r'   rj   single)rs  r   ulps)rB  r   Ziscomplexobjr   r   )r   ZredFuncZ	testArrayZtestNamer  r1  r2  Zred_funcr   r   new_test_functiono  s   


z]TestArrayReductions.install_generated_tests.<locals>.install_tests.<locals>.new_test_function)r}   r   formatrB  rc   namer!  setattr)ZdtypesfuncsdtZtest_arraysr~   	test_namer  clsr  r   install_testsd  s   zBTestArrayReductions.install_generated_tests.<locals>.install_testsri   )$r%   r&   r(   r)   r+   r,   r.   r/   r1   r2   r   r   r   r   r4   r5   r:   r6   r8   r9   rH   rG   rJ   r=   r?   rB   rD   rI   rL   rM   rK   r   r   rw   r^   rx   )r  Zreduction_funcsZreduction_funcs_rspaceZdtypes_to_testr  r   r  r   install_generated_testsG  s,   
z+TestArrayReductions.install_generated_tests)r   )F)\rB  
__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   r  r  r  r  r  r  r  r%  r&  r(  r)  r+  r,  r-  r.  r/  r3  r5  r7  r9  r;  r=  r>  r?  r@  rA  rE  rI  rK  rM  rN  rO  rP  rQ  rR  rS  rT  ra  rb  rc  rg  r   rh  rr  rt  rx  ry  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   rs  r   r  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}Zarray_ Z_globalc                 S   s   |  || d S r   )r  )r   funcmessager   r   r   test_fn  s   z6TestArrayReductionsExceptions.install.<locals>.test_fn)dictrB   rD   r=   r?   r8   r4   itemsr  rB  rW  r  )r  Z	fn_to_msgZ	empty_seqZop_no_identr   name_templatefnrs  r  Zlmsgr  r   r   r   install  s"   

z%TestArrayReductionsExceptions.installN)	rB  r  r  r   rd   r  r  r  r  r   r   r   r   r    s
    

r  __main__)G	itertoolsr   r   numpyr   Znumbar   r   r   Znumba.np.numpy_supportr   Znumba.tests.supportr   r	   r
   r   Zunittestr   r   r   r   r   r   r   r!   r"   r#   r%   r&   r(   r)   r+   r,   r.   r/   r1   r2   r4   r5   r6   r8   r9   r:   r=   r?   rB   rD   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rR   rT   rX   rY   rZ   r[   rr   r}   r   r   r  r  r  rB  mainr   r   r   r   <module>   s           N'
