o
    iZ                     @   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   _/home/ubuntu/transcripts/venv/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dd	 Z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d.d/ Zd0d1 Zed2d3 Zd4d5 Z d6d7 Z!dd9d: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.dSdT Z/dUdV Z0dWdX Z1dYdZ Z2dd\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 ZKeLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\e]dd Z^  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                       t ddt  fdd}|tg d |tg d |tg d |tg d  } d	 W d    d S 1 sFw   Y  d S )
NTr   c                        t | } | }|| d S r   )r   r   argexpectedgotr   r   r   r   r         z1TestArrayReductions.test_array_all.<locals>.checkTTTTFTr   r   r   r   r   r   hello)r   r   r   arrayassertTypingErrorr   r   er   r   r   test_array_all   s   

"z"TestArrayReductions.test_array_allc                       t ddt  fdd}|td |td |td |td |tj |tj |tj  |d |tg d	 |tg d
 |tg d |tg d  } g d W d    d S 1 sxw   Y  d S )NTr   c                    r   r   )r   r   r   r   r   r   r     r   z.TestArrayReductions.test_np_all.<locals>.checkr   皙?Fr   r   r   r   r   rm   rl   rz   )	r   r   r   r   rn   r   r   r   r   r   r   r   r   test_np_all  "   


"zTestArrayReductions.test_np_allc                    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                    r   )
NTr   c                    r   r   )r   r   r   r   r   r   r   2  r   z1TestArrayReductions.test_array_any.<locals>.checkr   r   r   r   r   )r   r   r   r   r   r   r   r   r   test_array_any0  s   

"z"TestArrayReductions.test_array_anyc                    r   )NTr   c                    r   r   )r   r   r   r   r   r   r   C  r   z.TestArrayReductions.test_np_any.<locals>.checkr   r   Fr   r   r   r   r   r   )	r   r   r   r   rn   r   r   r   r   r   r   r   r   test_np_any@  r   zTestArrayReductions.test_np_anyc                 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_basicc  ru   z"TestArrayReductions.test_var_basicc                 C   r   r   )r   r3   r   r   r   r   test_std_basicf  r   z"TestArrayReductions.test_std_basicc                 C   r   r   )r   r6   r   r   r   r   test_min_basici  r   z"TestArrayReductions.test_min_basicc                 C   r   r   )r   r;   r   r   r   r   test_max_basicl  r   z"TestArrayReductions.test_max_basicc                 C   r   r   )r   rA   r   r   r   r   test_argmin_basico  r   z%TestArrayReductions.test_argmin_basicc                 C   r   r   )r   rF   r   r   r   r   test_argmax_basicr  r   z%TestArrayReductions.test_argmax_basicc                 C   r   r   )r   rL   r   r   r   r   test_nanmin_basicu  r   z%TestArrayReductions.test_nanmin_basicc                 C   r   r   )r   rN   r   r   r   r   test_nanmax_basicx  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                    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   r   r   r   r   r   r     r   z5TestArrayReductions.check_median_basic.<locals>.checkc                    (    |  |  d}  |   | j d S )N)	      r}   Trd   r   r   r   	check_odd     
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   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_variations  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   
variations  s   
z9TestArrayReductions.test_median_basic.<locals>.variations)rJ   r   )r   r   r  r   r   r   test_median_basic  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        




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  r   rm   )rl   rz   r   rm   )r  )r   r   randnr}   r   linspacer   r   choiceflatr   flattentolisttuplert   testingassert_equalr   shape
assertTrueisscalar)r   r   q_upper_boundr   re   r^   
not_finitexr   r   r   check_percentile_and_quantile  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   皙?r   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^   raisesr   r   r   	check_err6     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   r   assertInr6  r7  r   r   r:  re   r   r^   r   r   r   check_percentile_exceptions3     	



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                    r1  )Nz%Quantiles must be in the range [0, 1]r2  r8  r   r   r   r:  P  r;  z@TestArrayReductions.check_quantile_exceptions.<locals>.check_errrw   g      )r-  r-  g?r-  r   r>  r?  rB  r   r   r   check_quantile_exceptionsM  rD  z-TestArrayReductions.check_quantile_exceptionsc                 C   .   t }| j|dd | j|dd | | d S Nr$  r   )r_   r#  r0  rC  r   r   r   r   r   test_percentile_basicg     z)TestArrayReductions.test_percentile_basicc                 C   rF  rG  )rb   r#  r0  rC  rI  r   r   r   test_nanpercentile_basicm  rK  z,TestArrayReductions.test_nanpercentile_basicc                 C   rF  Nrm   rH  )ri   r#  r0  rE  rI  r   r   r   test_quantile_basics  rK  z'TestArrayReductions.test_quantile_basicc                 C   rF  rM  )rk   r#  r0  rE  rI  r   r   r   test_nanquantile_basicy  rK  z*TestArrayReductions.test_nanquantile_basicc                 C   s   t }| || j d S r   )rZ   r   r   rI  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   r5  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 rQ  )
r   rt   rS  r   r5  rT  rU  r   r*   r)   rV  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   rR  )r   rt   r   r   r5  rT  rU  r   r*   r  assert_allcloser)   rV  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 rQ  )r   rt   rS  r   r5  rT  rU  r   r+   r  rZ  r)   rV  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_cumulative  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_global  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).
        rl   rv   i@  r]  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   )ri  r'   r(   r   r   r   r   test_sum_magnitude     
z&TestArrayReductions.test_sum_magnitudec                 C   rj  r   )ri  r"   r#   r   r   r   r   test_cumsum_magnitude  rl  z)TestArrayReductions.test_cumsum_magnitudec                 C   r   NT)re  )ri  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 rn  )ri  r*   r+   r   r   r   r   test_prod_magnitude     z'TestArrayReductions.test_prod_magnitudec                 C   rp  rn  )ri  r   r   r   r   r   r   test_cumprod_magnitude  rr  z*TestArrayReductions.test_cumprod_magnitudec                 C   r   rn  )ri  r    r   r   r   r   test_nancumprod_magnitude  ru   z-TestArrayReductions.test_nancumprod_magnitudec                 C   rj  r   )ri  r-   r.   r   r   r   r   test_mean_magnitude  rl  z'TestArrayReductions.test_mean_magnitudec                 C   rj  r   )ri  r0   r1   r   r   r   r   test_var_magnitude  rl  z&TestArrayReductions.test_var_magnitudec                 C   rj  r   )ri  r3   r4   r   r   r   r   test_std_magnitude  rl  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   rW  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&  r|  r   r   r   r   r   r   check_npdatetime     z$TestArrayReductions.check_npdatetimec                 C   r}  )Nrv   zm8[s]rr   r~  r  r   r   r   check_nptimedelta  r  z%TestArrayReductions.check_nptimedeltac                 C      |  t | t d S r   )r  r6   r  r   r   r   r   test_min_npdatetime  rl  z'TestArrayReductions.test_min_npdatetimec                 C   r  r   )r  r;   r  r   r   r   r   test_max_npdatetime  rl  z'TestArrayReductions.test_max_npdatetimec                 C   r  r   )r  rA   r  r   r   r   r   test_argmin_npdatetime  rl  z*TestArrayReductions.test_argmin_npdatetimec                 C   r  r   )r  rF   r  r   r   r   r   test_argmax_npdatetime!  rl  z*TestArrayReductions.test_argmax_npdatetimec                 C   r   r   )r  rJ   r   r   r   r   test_median_npdatetime%  r   z*TestArrayReductions.test_median_npdatetimec                 C   r   r   )r  r'   r   r   r   r   test_sum_npdatetime(  r   z'TestArrayReductions.test_sum_npdatetimec                 C   r   r   )r  r"   r   r   r   r   test_cumsum_npdatetime+  r   z*TestArrayReductions.test_cumsum_npdatetimec                 C   r   r   )r  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   4  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_nan9  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_cumulative1  s   
 z(TestArrayReductions.check_nan_cumulativec                 C   r  r   )r^  r    r  r   r   r   r   test_nancumprod_basicT  rl  z)TestArrayReductions.test_nancumprod_basicc                 C   r  r   )r^  r%   r  r   r   r   r   test_nancumsum_basicX  rl  z(TestArrayReductions.test_nancumsum_basicc                    sB   t tdd  fdd}dd }| D ]}|| qd S )NTr   c                    r  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  e  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                    r  r   r   r  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<  rw   r   rx   r   )r   r  r   r}   )real_nanimag_nanrealimagr   r   r   
make_array  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_complex  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   rA  r6  r7  r3  r4  )r   r   r   r   msgr   r   r   test_ptp_exceptions  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                    r  r   r   r  r   r   r   r     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_basic  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                    r  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                    r  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(  rT  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assertRaisesRegexr4  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   rA  r6  r7  )r   r   r  r   r   r   r    test_argmax_axis_must_be_integer9     


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   G  r`   z;TestArrayReductions.test_argmax_method_axis.<locals>.argmaxTr   r   rt   r}   r   r   r   rE   r   r  r   test_argmax_method_axisD  
   
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   Q  r`   z;TestArrayReductions.test_argmax_return_type.<locals>.argmaxTr   r   rt   uint8r}   r   r   r  r   r  r   test_argmax_return_typeM  
   
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   a  r  zATestArrayReductions.test_argmin_axis_1d_2d_4d.<locals>.<listcomp>c                 S   r  )c                 S   r  r  rB   r  r   r   r   r  e  r  zJTestArrayReductions.test_argmin_axis_1d_2d_4d.<locals>.<listcomp>.<lambda>r   r  r   r   r   r   d  r  c                 S   r  r  r  r  r   r   r   r   h  r  r  r  r   r   r   test_argmin_axis_1d_2d_4dW  r  z-TestArrayReductions.test_argmin_axis_1d_2d_4dc                    r  )Nr  rl   rz   Tr   c                 S   r[   r   rB   r  r   r   r   	jitargminr  r  zDTestArrayReductions.test_argmin_axis_out_of_range.<locals>.jitargminc                    r  r  r  r  r  r   r   r   r  v  r  zHTestArrayReductions.test_argmin_axis_out_of_range.<locals>.assert_raisesrm   r  r  r  r  r   r  r   test_argmin_axis_out_of_rangen  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  r   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@     r`   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  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)ry  r   iscomplexobjr   r   )r   redFunc	testArraytestNamer
  rg  rh  red_funcr   r   new_test_function  s   


z]TestArrayReductions.install_generated_tests.<locals>.install_tests.<locals>.new_test_function)r   r   formatry  rs   namerT  setattr)dtypesfuncsdttest_arraysr   	test_namer  clsr  r   install_tests  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   rS  r   rn   r   )r  reduction_funcsreduction_funcs_rspacedtypes_to_testr  r   r  r   install_generated_tests  s,   
z+TestArrayReductions.install_generated_tests)r$  )F)`ry  
__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   r   r   r   r   staticmethodr   r  r#  r0  rC  rE  rJ  rL  rN  rO  rP  rX  rY  r[  r\  r^  r_  r`  ra  rb  ri  rk  rm  ro  rq  rs  rt  ru  rv  rw  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  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   r3  BaseException	zero_sizer4  rA  r6  r7  )r   r   r  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}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  ry  r  r  )r  	fn_to_msg	empty_seqop_no_identr"  name_templatefnr  r  lmsgr0  r   r   r   install  s"   

z%TestArrayReductionsExceptions.installN)	ry  r!  r"  r   rt   r)  r*  r%  r9  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'  r9  ry  mainr   r   r   r   <module>   s            *'
