o
    i                     @   s*  d dl mZmZ d dlZd dlmZmZ d dlm	Z	 d dl
mZ d dl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/d0 Z%d1d2 Z&d3d4 Z'd5d6 Z(d7d8 Z)d9d: Z*d;d< Z+d=d> Z,d?d@ Z-dAdB Z.dCdD Z/dEdF Z0dGdH Z1dIdJ Z2dKdL Z3dMdN Z4dOdP Z5dQdR Z6dSdT Z7dUdV Z8dWdX Z9dYdZ Z:d[d\ Z;d]d^ Z<d_d` Z=dadb Z>dcdd Z?dedf Z@G dgdh dheeZAeAB  G didj djeeZCeCD  eEdkkreF  dS dS )l    )productcombinations_with_replacementN)jittypeof)compile_isolated)numpy_version)TestCaseMemoryLeakMixintagc                 C      |   S N)allarr r   p/var/www/html/eduruby.in/lip-sync/lip-sync-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   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_prod0   r   r'   c                 C   r   r   )r   r&   r   r   r   r   array_prod_global3   r   r(   c                 C   r   r   )meanr   r   r   r   
array_mean6   r   r*   c                 C   r   r   )r   r)   r   r   r   r   array_mean_global9   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_stdB   r   r0   c                 C   r   r   )r   r/   r   r   r   r   array_std_globalE   r   r1   c                 C   r   r   )minr   r   r   r   	array_minH   r   r3   c                 C   r   r   )r   r2   r   r   r   r   array_min_globalK   r   r4   c                 C   r   r   )r   Zaminr   r   r   r   
array_aminN   r   r5   c                 C   r   r   )maxr   r   r   r   	array_maxQ   r   r7   c                 C   r   r   )r   r6   r   r   r   r   array_max_globalT   r   r8   c                 C   r   r   )r   Zamaxr   r   r   r   
array_amaxW   r   r9   c                 C   r   r   argminr   r   r   r   array_argminZ   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   rA   c                 C   r   r   r   r@   r   r   r   r   array_argmax_globalc   r   rC   c                 C   r   r   )r   medianr   r   r   r   array_median_globalf   r   rE   c                 C   r   r   )r   Znanminr   r   r   r   array_nanmini   r   rF   c                 C   r   r   )r   Znanmaxr   r   r   r   array_nanmaxl   r   rG   c                 C   r   r   )r   Znanmeanr   r   r   r   array_nanmeano   r   rH   c                 C   r   r   )r   Znansumr   r   r   r   array_nansumr   r   rI   c                 C   r   r   )r   Znanprodr   r   r   r   array_nanprodu   r   rJ   c                 C   r   r   )r   Znanstdr   r   r   r   array_nanstdx   r   rK   c                 C   r   r   )r   Znanvarr   r   r   r   array_nanvar{   r   rL   c                 C   r   r   )r   Z	nanmedianr   r   r   r   array_nanmedian_global~   r   rM   c                 C      t | |S r   )r   Z
percentiler   qr   r   r   array_percentile_global      rQ   c                 C   rN   r   )r   ZnanpercentilerO   r   r   r   array_nanpercentile_global   rR   rS   c                 C   r   r   )r   ptpar   r   r   array_ptp_global   r   rW   c                 C   r   r   )rT   rU   r   r   r   	array_ptp   r   rX   c                 C   rN   r   )r   ZquantilerO   r   r   r   array_quantile_global   rR   rY   c                 C   rN   r   )r   ZnanquantilerO   r   r   r   array_nanquantile_global   rR   rZ   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^   ra   r   r   r`         
   r[         )r[      r[   A)order)r   r]   reshapeflagsc_contiguousf_contiguous)rb   r`   Za1Za2a3r   ra   r   base_test_arrays   s   


rq   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 )re   r   ).0rV   r   r   r   
<listcomp>   s    z$full_test_arrays.<locals>.<listcomp>re                 ?   r[   )rq   r   float32	complex64Zconjappendextendrb   )rb   Z
array_listaccrV   tmpr   r   r   full_test_arrays   s   


r|   c                 C   s.   t |}t| |g}| |}||}||fS r   )r   r   entry_point)Zcompare_func
test_arrayarrtycresZ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 ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWeXdd ZY  ZZS )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   cfunc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[   rh   r   r   r   floatrl   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   rh   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
  rd   z"TestArrayReductions.test_var_basicc                 C   r   r   )r   r0   r   r   r   r   test_std_basic  r   z"TestArrayReductions.test_std_basicc                 C   r   r   )r   r3   r   r   r   r   test_min_basic  r   z"TestArrayReductions.test_min_basicc                 C   r   r   )r   r7   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   rA   r   r   r   r   test_argmax_basic  r   z%TestArrayReductions.test_argmax_basicc                 C   r   r   )r   rF   r   r   r   r   test_nanmin_basic  r   z%TestArrayReductions.test_nanmin_basicc                 C   r   r   )r   rG   r   r   r   r   test_nanmax_basic  r   z%TestArrayReductions.test_nanmax_basicc                 C   r   r   )r   rH   r   r   r   r   test_nanmean_basic"  r   z&TestArrayReductions.test_nanmean_basicc                 C   r   r   )r   rI   r   r   r   r   test_nansum_basic%  r   z%TestArrayReductions.test_nansum_basicc                 C   r   r   )r   rJ   r   r   r   r   test_nanprod_basic(  r   z&TestArrayReductions.test_nanprod_basicc                 C   r   r   )r   rK   r   r   r   r   test_nanstd_basic+  r   z%TestArrayReductions.test_nanstd_basicc                 C   r   r   )r   rL   r   r   r   r   test_nanvar_basic.  rd   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   3     z5TestArrayReductions.check_median_basic.<locals>.checkc                    (    |  |  d}  |   | j d S )N)	      rl   TrU   r   r   r   	check_odd9     
z9TestArrayReductions.check_median_basic.<locals>.check_odd?   g      %@c                    r   )N)      r   rU   r   r   r   
check_evenB  r   z:TestArrayReductions.check_median_basic.<locals>.check_even@   )r   r   rc   )r   r   Zarray_variationsr   rV   r   r   )r   r   r   r   r   check_median_basic1  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 )Nrh         @r   r\   r[   )copyr   r   shuffler   rU   r   r   r   _array_variationsJ  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 )Nrh   r   r   r\   )r   r   r   r   rU   r   r   r   
variations\  s   
z9TestArrayReductions.test_median_basic.<locals>.variations)rE   r   )r   r   r   r   r   r   test_median_basicY  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   rV   rP   r   r   r   Zfiniter   r   r   r   k     




z@TestArrayReductions.check_percentile_and_quantile.<locals>.check   ri   r      rh   r[   re   )r\   r[   ri   r   rf            ?r   r   g      ?rg   r   )      ?r   r   )g      @      @g      &@ih     )r   r   r[   )r   r   g      ?)ri   r   )r\   r[   ri   r\   )r[   ri   r   r\   )r   )r   r   Zrandnrl   r   linspacer   r   choiceZflatr   flattentolisttuplerc   testingZassert_equalarrayshape
assertTrueZisscalar)r   r   q_upper_boundr   rV   rP   Z
not_finitexr   r   r   check_percentile_and_quantileh  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   )rV   rP   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\   re   )ranger   r   r   )elementsicombr   r   r   _array_combinations  s   zLTestArrayReductions.check_percentile_edge_cases.<locals>._array_combinationsr   皙?g?r\   rh   rf   r[   )r   )r   r   r   r   r   )
r   r   r   r   r   r   rP   Zelement_poolrV   _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rV   rP   Zraisesr   r   r   r   	check_err     zBTestArrayReductions.check_percentile_exceptions.<locals>.check_errrf   )r\   re   i   r\   re   rt   r   Not supported for complex dtype	r   disable_leak_checkr   rc   r   assertTypingErrorassertInr  r  r   r   r  rV   erP   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_errrf   g      )r   r   g?r   rt   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   )rQ   r   r   r  r   r   r   r   r   test_percentile_basic     z)TestArrayReductions.test_percentile_basicc                 C   r  r  )rS   r   r   r  r  r   r   r   test_nanpercentile_basic  r  z,TestArrayReductions.test_nanpercentile_basicc                 C   r  Nr\   r  )rY   r   r   r  r  r   r   r   test_quantile_basic  r  z'TestArrayReductions.test_quantile_basicc                 C   r  r  )rZ   r   r   r  r  r   r   r   test_nanquantile_basic  r  z*TestArrayReductions.test_nanquantile_basicc                 C   s   t }| || j d S r   )rM   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t|g}|j	}| t 
||| d S Nre   ra   r\   C)r   rc   int32r   r  ndimlayoutr   r%   r}   r#   r   r   r   r   r   r   r   r   test_array_sum_global'  s   z)TestArrayReductions.test_array_sum_globalc                 C   sb   t jdt jdd }t|}| |jd | |jd tt|g}|j	}| |
 || d S r   )r   rc   r"  r   r  r#  r$  r   r'   r}   r&   r%  r   r   r   test_array_prod_int_1d2  s   z*TestArrayReductions.test_array_prod_int_1dc                 C   sd   t jdt jdd }t|}| |jd | |jd tt|g}|j	}t j
| || d S )Nre   ra   r   r\   r!  )r   rc   rv   r   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   sb   t jdt jd}t|}| |jd | |jd tt|g}|j	}t j
t ||| d S r   )r   rc   r"  r   r  r#  r$  r   r(   r}   r   r(  r&   r%  r   r   r   test_array_prod_globalH  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[   re   ra   r   r   )ri   r[   )r   rc   int16r   r   r   rl   )r   r   r   r   r   r   r   r   check_cumulativeS  s   
z$TestArrayReductions.check_cumulativec                 C   r   r   )r,  r    r   r   r   r   test_array_cumsum^  r   z%TestArrayReductions.test_array_cumsumc                 C   r   r   )r,  r!   r   r   r   r   test_array_cumsum_globala  r   z,TestArrayReductions.test_array_cumsum_globalc                 C   r   r   )r,  r   r   r   r   r   test_array_cumprodd  r   z&TestArrayReductions.test_array_cumprodc                 C   r   r   )r,  r   r   r   r   r   test_array_cumprod_globalg  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[   re   i@  r+  l            Zint64Zuint64N)r   rc   r   r   r   )r   r   is_prodZn_itemsr   nprnbrr   r   r   check_aggregation_magnitudej  s   
z/TestArrayReductions.check_aggregation_magnitudec                 C      |  t |  t d S r   )r4  r$   r%   r   r   r   r   test_sum_magnitude}     
z&TestArrayReductions.test_sum_magnitudec                 C   r5  r   )r4  r    r!   r   r   r   r   test_cumsum_magnitude  r7  z)TestArrayReductions.test_cumsum_magnitudec                 C   r   NT)r1  )r4  r"   r   r   r   r   test_nancumsum_magnitude  rd   z,TestArrayReductions.test_nancumsum_magnitudec                 C       | j tdd | j tdd d S r9  )r4  r'   r(   r   r   r   r   test_prod_magnitude     z'TestArrayReductions.test_prod_magnitudec                 C   r;  r9  )r4  r   r   r   r   r   r   test_cumprod_magnitude  r=  z*TestArrayReductions.test_cumprod_magnitudec                 C   r   r9  )r4  r   r   r   r   r   test_nancumprod_magnitude  rd   z-TestArrayReductions.test_nancumprod_magnitudec                 C   r5  r   )r4  r*   r+   r   r   r   r   test_mean_magnitude  r7  z'TestArrayReductions.test_mean_magnitudec                 C   r5  r   )r4  r-   r.   r   r   r   r   test_var_magnitude  r7  z&TestArrayReductions.test_var_magnitudec                 C   r5  r   )r4  r0   r1   r   r   r   r   test_std_magnitude  r7  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   rh   rD   r\   r[   ZNaT)r   r   r   r   r   r   r   __name__r   lenfillrb   )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 )Nre   zM8[Y]ra   r   rc   r   rF  r   r   r   r   r   r   check_npdatetime     z$TestArrayReductions.check_npdatetimec                 C   rG  )Nre   zm8[s]ra   rH  rI  r   r   r   check_nptimedelta  rK  z%TestArrayReductions.check_nptimedeltac                 C      |  t | t d S r   )rJ  r3   rL  r   r   r   r   test_min_npdatetime  r7  z'TestArrayReductions.test_min_npdatetimec                 C   rM  r   )rJ  r7   rL  r   r   r   r   test_max_npdatetime  r7  z'TestArrayReductions.test_max_npdatetimec                 C   rM  r   )rJ  r<   rL  r   r   r   r   test_argmin_npdatetime  r7  z*TestArrayReductions.test_argmin_npdatetimec                 C   rM  r   )rJ  rA   rL  r   r   r   r   test_argmax_npdatetime  r7  z*TestArrayReductions.test_argmax_npdatetimec                 C   r   r   )rL  rE   r   r   r   r   test_median_npdatetime  r   z*TestArrayReductions.test_median_npdatetimec                 C   r   r   )rL  r$   r   r   r   r   test_sum_npdatetime  r   z'TestArrayReductions.test_sum_npdatetimec                 C   r   r   )rL  r    r   r   r   r   test_cumsum_npdatetime  r   z*TestArrayReductions.test_cumsum_npdatetimec                 C   r   r   )rL  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   rV   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   )rV   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 )Nrh   ri   <   r   rf   )TTTFr\   re   r   gfffff@@ra   )r   r   rl   r   r   rc   asfortranarrayrv   r   r   r   r   a_variations  s   "z>TestArrayReductions.check_nan_cumulative.<locals>.a_variationsre   r[   r   rf   r   r   r   r   rt   rh   ri   )r   r   r   r   r   fullr   rl   )r   r   r   r\  r_  rV   partsr   r   r   check_nan_cumulative  s   
 z(TestArrayReductions.check_nan_cumulativec                 C   rM  r   )r,  r   rb  r   r   r   r   test_nancumprod_basic   r7  z)TestArrayReductions.test_nancumprod_basicc                 C   rM  r   )r,  r"   rb  r   r   r   r   test_nancumsum_basic  r7  z(TestArrayReductions.test_nancumsum_basicc                    sB   t tdd  fdd}dd }| D ]}|| qd S )NTr   c                    rV  r   r   rW  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 )Nre   g皙@rf   )r   r[   rf   r\   )re  gffffffr   r   r   r[   rh   r   r   g      @y      ?      @))gffffff@r   gffffff)g333333@g@g@r\   rt   )r   rc   r   r   r   r`  r   rl   r^  r   ZRandomStater   rU   r   r   r   r_    s2   

z8TestArrayReductions.test_ptp_basic.<locals>.a_variations)rW   r   )r   r   r_  rV   r   r   r   test_ptp_basic  s   

z"TestArrayReductions.test_ptp_basicc                 C   s<   t }tdd|}td}||}||}| || d S )NTr   re   )rX   r   r   rc   r   )r   r   r   rV   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                    rV  r   r   rW  r   r   r   r   =  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	  rf   r   rg   rt   )r   r   r   rl   )real_nanimag_nanrealimagr   r   r   
make_arrayB  s   z8TestArrayReductions.test_ptp_complex.<locals>.make_arrayr[   )repeatr   rj  r   rt   )r   r   y      ?      )Z
fill_value)FF)rW   r   r   r   Zonesrc   r`  )r   r   rp  rl  rm  comprn  ro  r   r   r   test_ptp_complex9  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)rW   r   r  r  r   r   r  r  r  r   r  )r   r   r   r  msgr   r   r   test_ptp_exceptionsY  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                    rV  r   r   rW  r   r   r   r   r  r   z=TestArrayReductions.test_min_max_complex_basic.<locals>.checkrg  re   (   rh   r   r[   rt   )r4   r8   r   r   r   r   r   r   r   rw   Z
complex128r   )r   pyfuncsr   rn  ro  rV   _rb   r   r   r   test_min_max_complex_basicl  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                    rV  r   r   rW  r   r   r   r     r   zCTestArrayReductions.test_nanmin_nanmax_complex_basic.<locals>.checkrg  re   rv  rh   r   rf   r   r[   r   rg   rt   )	rF   rG   r   r   r   r   r   r   r   )r   rw  r   rn  ro  rV   rx  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                    rV  r   r   rW  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[   ))rg  r   i)rf      iri   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   )rF   rG   r   )r   rw  r   r_  rV   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      ri   r   r   r[   ri   r   r\   r   x   r   rf   re   r   r\   r\   r[   r\   r   r   r   3   c                 S      g | ]}|d   qS rf  r   rr   r   r   r   r   rs         
zATestArrayReductions.test_argmax_axis_1d_2d_4d.<locals>.<listcomp>c                 S      g | ]}|fd dqS )c                 S      t j| |dS NaxisrB   rV   Z_axisr   r   r   <lambda>      zJTestArrayReductions.test_argmax_axis_1d_2d_4d.<locals>.<listcomp>.<lambda>r   rr   r  r   r   r   rs         
c                 S      g | ]	}t d d|qS Tr   r   rr   r   r   r   r   rs         	r   r   rc   rl   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[   ri   Tr   c                 S   rN   r   rB   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   rc   rl   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   rN   r   rB   r  r   r   r   r    r  zGTestArrayReductions.test_argmax_axis_must_be_integer.<locals>.jitargmaxfooaxis must be an integerr   rc   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[   ri   c                        j ddS Nr   r  r?   r   r  r   r   r@     rR   z;TestArrayReductions.test_argmax_method_axis.<locals>.argmaxTr   r   rc   rl   r   r   r   r@   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   ra   r[   ri   c                    r  r  r?   r   r  r   r   r@     rR   z;TestArrayReductions.test_argmax_return_type.<locals>.argmaxTr   r   rc   Zuint8rl   r   r   r  r   r  r   test_argmax_return_type  
   
z+TestArrayReductions.test_argmax_return_typec           	      C   r}  )Nr~  r   r[   ri   r  r   r  r   rf   re   r  r  r  c                 S   r  rf  r   r  r   r   r   rs     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   rs     r  c                 S   r  r  r  r  r   r   r   rs     r  r  r  r   r   r   test_argmin_axis_1d_2d_4d  r  z-TestArrayReductions.test_argmin_axis_1d_2d_4dc                    r  )Nr   r[   ri   Tr   c                 S   rN   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   rN   r   r=   r  r   r   r   r  2  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[   ri   c                    r  r  r:   r   r  r   r   r;   =  rR   z;TestArrayReductions.test_argmin_method_axis.<locals>.argminTr   r  r   r;   r   r  r   test_argmin_method_axis:  r  z+TestArrayReductions.test_argmin_method_axisc                    r  )	Nr   ra   r[   ri   c                    r  r  r:   r   r  r   r   r;   G  rR   z;TestArrayReductions.test_argmin_return_type.<locals>.argminTr   r  r  r   r  r   test_argmin_return_typeC  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&   ri   single)rt  r   ulps)rC  r   Ziscomplexobjr   r   )r   ZredFuncZ	testArrayZtestNamer  r2  r3  Zred_funcr   r   new_test_functionu  s   


z]TestArrayReductions.install_generated_tests.<locals>.install_tests.<locals>.new_test_function)r|   r   formatrC  rb   namer#  setattr)ZdtypesfuncsdtZtest_arraysr~   	test_namer  clsr  r   install_testsj  s   zBTestArrayReductions.install_generated_tests.<locals>.install_testsrh   )$r$   r%   r'   r(   r*   r+   r-   r.   r0   r1   r   r   r   r   r3   r4   r9   r5   r7   r8   rG   rF   rI   r<   r>   rA   rC   rH   rK   rL   rJ   r   r"  rv   r]   rw   )r  Zreduction_funcsZreduction_funcs_rspaceZdtypes_to_testr  r   r  r   install_generated_testsM  s,   
z+TestArrayReductions.install_generated_tests)r   )F)[rC  
__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/  r0  r4  r6  r8  r:  r<  r>  r?  r@  rA  rB  rF  rJ  rL  rN  rO  rP  rQ  rR  rS  rT  rU  rb  rc  rd  rh  ri  rs  ru  ry  rz  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   rt  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)dictrA   rC   r<   r>   r7   r3   itemsr  rC  rX  r  )r  Z	fn_to_msgZ	empty_seqZop_no_identr   name_templatefnrt  r  Zlmsgr  r   r   r   install  s"   

z%TestArrayReductionsExceptions.installN)	rC  r  r  r   rc   r  r  r  r  r   r   r   r   r    s
    

r  __main__)G	itertoolsr   r   numpyr   Znumbar   r   Znumba.core.compilerr   Znumba.np.numpy_supportr   Znumba.tests.supportr   r	   r
   Zunittestr   r   r   r   r   r   r   r    r!   r"   r$   r%   r'   r(   r*   r+   r-   r.   r0   r1   r3   r4   r5   r7   r8   r9   r<   r>   rA   rC   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rQ   rS   rW   rX   rY   rZ   rq   r|   r   r   r  r  r  rC  mainr   r   r   r   <module>   s    	       R'
