o
    i                     @   s\  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	 d dl
mZ d dlmZmZmZ d dlmZmZmZmZ d dlZedddZdd	 Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZG dd deZ G dd deZ!G dd de!eZ"G d d! d!e!Z#G d"d# d#e#eZ$G d$d% d%e$Z%G d&d' d'e#eZ&G d(d) d)e'Z(G d*d+ d+e(eZ)G d,d- d-e)Z*G d.d/ d/e*Z+G d0d1 d1e(eZ,G d2d3 d3e Z-G d4d5 d5e Z.G d6d7 d7eZ/G d8d9 d9e Z0G d:d; d;eZ1G d<d= d=ee Z2G d>d? d?eeZ3e4e5ed@dAG dBdC dCeeZ6dDdE Z7e8dFkr,e9  dS dS )G    N)TypingError)njit)typesutilsconfig)MemoryLeakMixinTestCasetagskip_if_32bitT)Z_nrtZnogilc                 C      t | ||fS NnpZconcatenateabc r   i/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/numba/tests/test_dyn_array.pynp_concatenate1      r   c                 C      t j| ||f|dS Naxisr   r   r   r   r   r   r   r   np_concatenate2      r   c                 C   r   r   r   stackr   r   r   r   	np_stack1   r   r    c                 C   r   r   r   r   r   r   r   	np_stack2   r   r!   c                 C   r   r   )r   Zhstackr   r   r   r   	np_hstack   r   r"   c                 C   r   r   )r   Zvstackr   r   r   r   	np_vstack"   r   r#   c                 C   r   r   )r   Z	row_stackr   r   r   r   np_row_stack%   r   r$   c                 C   r   r   )r   Zdstackr   r   r   r   	np_dstack(   r   r%   c                 C   r   r   )r   Zcolumn_stackr   r   r   r   np_column_stack+   r   r&   c                   @   s   e Zd ZdddZdS )BaseTestTc                 C   st   t |}|D ]1}|| }|| }| |j|j | |j|j | || |r0tj|| qtj|| qd S r   )	nrtjitassertEqualsizedtypeassertStridesEqualr   testingassert_equalZassert_allclose)selfpyfuncZargslistexactcfuncargsexpectedretr   r   r   check_outputs1   s   zBaseTest.check_outputsN)T)__name__
__module____qualname__r6   r   r   r   r   r'   /   s    r'   c                   @   s   e Zd Zdd ZdS )NrtRefCtTestc                 C   s   |  |jj| d S r   )r)   baserefcount)r/   arrexpectr   r   r   assert_array_nrt_refct@   r   z#NrtRefCtTest.assert_array_nrt_refctN)r7   r8   r9   r?   r   r   r   r   r:   ?   s    r:   c                   @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zedd Zdd Zdd Zdd  Zd!d" Zd#S )$TestDynArrayc                 C   s   t dd }| }| |d tjd| | |jd | |jd | |jttj	 | |j
d |d tjd| ~d S )Nc                  S   s   t d} d| d< | S )Nr   *   r   emptyr=   r   r   r   fooG   s   
z'TestDynArray.test_empty_0d.<locals>.foo   rA   r   {   )r(   r?   r   r-   r.   r)   r*   shaper+   float64stridesfill)r/   rE   r=   r   r   r   test_empty_0dF   s   

zTestDynArray.test_empty_0dc                 C   s   t dd }d}||}| |d tjt|| | |j| | |j|f | |j	t	tj
 | |jt	tj
jf |d tjd| ~d S )Nc                 S   s$   t | }t| D ]}|||< q	|S r   )r   rC   range)nr=   ir   r   r   rE   Y   s   

z'TestDynArray.test_empty_1d.<locals>.foo   rF   rG   )r(   r?   r   r-   r.   aranger)   r*   rH   r+   rI   rJ   itemsizerK   )r/   rE   rN   r=   r   r   r   test_empty_1dX   s   

zTestDynArray.test_empty_1dc                 C   s|   dd }t |}d}d}|||}|||}| |d tj|| | |j|j | |j|j | |j|j ~d S )Nc                 S   sB   t | |ft j}t| D ]}t|D ]
}|| |||f< qq|S r   r   rC   int32rM   )mrN   r=   rO   jr   r   r   r0   n   s   z*TestDynArray.test_empty_2d.<locals>.pyfunc   rP   rF   	r(   r?   r   r-   r.   r)   r*   rH   rJ   )r/   r0   r2   rV   rN   expected_arrgot_arrr   r   r   test_empty_2dm   s   

zTestDynArray.test_empty_2dc                 C      dd }t |}d}d}d}||||}||||}| |d tj|| | |j|j | |j|j | |j|j ~d S )Nc                 S   sX   t | ||ft j}t| D ]}t|D ]}t|D ]}|| | ||||f< qqq|S r   rT   )rV   rN   pr=   rO   rW   kr   r   r   r0      s   z*TestDynArray.test_empty_3d.<locals>.pyfuncrX   rP      rF   rY   r/   r0   r2   rV   rN   r^   rZ   r[   r   r   r   test_empty_3d   s   	zTestDynArray.test_empty_3dc                 C   r]   )Nc                 S   sF   t | |ft j}t| D ]}t|D ]
}|| |||f< qq|| S r   rT   )rV   rN   r^   r=   rO   rW   r   r   r   r0      s   z1TestDynArray.test_empty_2d_sliced.<locals>.pyfuncrX   rP   r`   rF   rY   ra   r   r   r   test_empty_2d_sliced   s   z!TestDynArray.test_empty_2d_slicedc                    s   t jdt jd t } fdd}t|}| }| |d t  t j | t j t jdt jd t j|t jdt jd ~t	
  | |d t  ~t	
  | |t  d S )NrX   r+   c                      s    S r   r   r   yr   r   return_external_array      zDTestDynArray.test_return_global_array.<locals>.return_external_arrayrF   )r   onesfloat32sysgetrefcountr(   r)   r-   r.   gcZcollect)r/   	initrefctrg   r2   outr   re   r   test_return_global_array   s   
z%TestDynArray.test_return_global_arrayc                    s   t jdt jd  fdd}t|}| }| |j  dd  }t j|| t j|t jdt jd t j|t jdt jd d S )NrX   rd   c                      s    dd  S Nr`   r   r   re   r   r   rg         zKTestDynArray.test_return_global_array_sliced.<locals>.return_external_arrayr`   )r   ri   rj   r(   assertIsNoner;   r-   r.   )r/   rg   r2   ro   yyr   re   r   test_return_global_array_sliced   s   z,TestDynArray.test_return_global_array_slicedc                 C   sh   dd }t jdt jd}t|}||}||}t j|| t j|| | || | || d S )Nc                 S      | S r   r   re   r   r   r   r0      rh   z4TestDynArray.test_array_pass_through.<locals>.pyfuncrX   rd   )r   ri   rj   r(   r-   r.   assertIs)r/   r0   r=   r2   r4   gotr   r   r   test_array_pass_through   s   z$TestDynArray.test_array_pass_throughc                 C   s   dd }t jdt jd}t|}t|}||}| |d t| ||}| |d t| t j|||j	d   t j|| ~| |d t| ~| |t| d S )Nc                 S   s   | | j d d  S rq   )r*   re   r   r   r   r0         z;TestDynArray.test_array_pass_through_sliced.<locals>.pyfuncrX   rd   rF   r`   )
r   ri   rj   rk   rl   r(   r)   r-   r.   r*   )r/   r0   r=   rn   r2   rx   r4   r   r   r   test_array_pass_through_sliced   s   
z+TestDynArray.test_array_pass_through_slicedc                 C   s  dd }t |}tjd}tjd}tj|||||| | |||d tjddd}tjddd}tj|||||| | |||d tjdddd}tjdddd}tj|||||| | |||d d S )	Nc                 S   s   t | j}t | || |S r   )r   rC   rH   add)r   r   ro   r   r   r   r0     s   z=TestDynArray.test_ufunc_with_allocated_output.<locals>.pyfunc
   rF   r`      F      )r(   r   randomr-   r.   r?   reshape)r/   r0   r2   Zarr_aZarr_br   r   r    test_ufunc_with_allocated_output  s(   z-TestDynArray.test_ufunc_with_allocated_outputc                    s  dd }t | d}tjdd|}| }tj|| | tj|| g }g }g } fdd}tdD ]+}	tjdd|}t|}
t	j
|||
fd|	d	}|| || ||
 q8|D ]}|  qf|D ]}|  qot||D ]\}}
tj|||
 q{d
S )z
        This test exercises the array allocation in multithreaded usecase.
        This stress the freelist inside NRT.
        c                 S   s   t | j}t|jD ]}d||< qt| d D ]*}t | j}t|jD ]}| | ||< q%t|jD ]}||  || | 7  < q3q|S )Nr   r   rC   r*   rM   )inpro   rO   tmprW   r   r   r   r0   .  s   
z/TestDynArray.test_allocation_mt.<locals>.pyfuncr}   rF   c                    s    | |d d < d S r   r   )r   ro   r2   r   r   wrappedO  r   z0TestDynArray.test_allocation_mt.<locals>.wrappedd   	worker{0}targetr3   nameN)r(   r   r   randintcopyr-   r.   rM   
empty_like	threadingThreadformatappendstartjoinzip)r/   r0   r*   r=   Z
frozen_arrworkersZinputsoutputsr   rO   ro   threadr   r   r   r   test_allocation_mt(  s8   




zTestDynArray.test_allocation_mtc                    sB  dd }t | d}tj|td}t|}td}|||}tj	| || ~| 
|t| g }g }g }	 fdd}
tdD ])}t|}td}tj|
|||fd	|d
}|| || |	| qD|D ]}|  qp|D ]}|  qyt|	|D ]\}}tj	|||| q~~| 
|t| dS )zE
        This test exercises the refct in multithreaded code
        c                 S   sH   t |j}t|jD ]
}|| d ||< qt| D ]}||}}q|S NrF   r   )rN   r   ro   rO   r   r   r   r0   n  s   z*TestDynArray.test_refct_mt.<locals>.pyfuncr}   rd   i  c                    s    | ||d d < d S r   r   )rN   inputro   r   r   r   r        z+TestDynArray.test_refct_mt.<locals>.wrappedr   r   r   N)r(   r   rQ   floatrk   rl   r   	randranger-   r.   r)   rM   rC   r   r   r   r   r   r   r   )r/   r0   r*   r   Zexpected_refctZswapctr4   r   r   Zswapctsr   rO   ro   r   r   r   r   test_refct_mti  s@   	








zTestDynArray.test_refct_mtc                 C   sh   t dd }|   | t}|tjjd d  W d    n1 s$w   Y  | dt|j	 d S )Nc                 S   s   t |  d S r   rB   xr   r   r   rE        z1TestDynArray.test_invalid_size_array.<locals>.foo   r`   zAllocation failed)
r   disable_leak_checkassertRaisesMemoryErrorr   Zsize_tmaxvalassertInstr	exception)r/   rE   raisesr   r   r   test_invalid_size_array  s   
z$TestDynArray.test_invalid_size_arrayc           	      C   s   dd }t |}tjd}tjd}d}t|t|f}||||||||}}| |d j | |d j tj|| ~~| 	|t|t|f d S )Nc                 S       t |D ]}|| } }q| |fS )z5Swap array x and y for t number of times
            rM   r   rf   trO   r   r   r   r0     s   z&TestDynArray.test_swap.<locals>.pyfuncr   r   rF   )
r(   r   r   rk   rl   rs   r;   r-   r.   r)   )	r/   r0   r2   r   rf   r   rn   r>   rx   r   r   r   	test_swap  s   	 zTestDynArray.test_swapc           	      C   s   dd }t |}tjd}t|}||\}}||\}}| || | || tj|| tj|| ~~| |t| | t|t| d S )Nc                 S   s4   t | j}t|jD ]
}| | d ||< q| |fS r   r   )r   rf   rO   r   r   r   r0     s   z7TestDynArray.test_return_tuple_of_array.<locals>.pyfuncr~   )	r(   r   r   rk   rl   rw   r-   r.   r)   )	r/   r0   r2   r   rn   
expected_x
expected_ygot_xgot_yr   r   r   test_return_tuple_of_array  s   
z'TestDynArray.test_return_tuple_of_arrayc                 C   sx   dd }t |}tjd}||\}}||\}}tj|| tj|| | dt| | dt| d S )Nc                 S   s8   t | j}t|jD ]
}| | d ||< q||f}|S r   r   )r   rf   rO   ro   r   r   r   r0     s
   z?TestDynArray.test_return_tuple_of_array_created.<locals>.pyfuncr~   r`   )r(   r   r   r-   r.   r)   rk   rl   )r/   r0   r2   r   r   r   r   r   r   r   r   "test_return_tuple_of_array_created  s   z/TestDynArray.test_return_tuple_of_array_createdc                    sv   t dd   fdd}t |}td}t|}| |t|| | |t|| | |t| dS )z_
        Dispatcher returns a new reference.
        It need to workaround it for now.
        c                 S   rv   r   r   )ro   r   r   r   inner   s   z7TestDynArray.test_issue_with_return_leak.<locals>.innerc                        | S r   r   r   r   r   r   r0        z8TestDynArray.test_issue_with_return_leak.<locals>.pyfuncr}   N)r(   r   rQ   rk   rl   r)   )r/   r0   r2   r=   Z	old_refctr   r   r   test_issue_with_return_leak  s   


z(TestDynArray.test_issue_with_return_leakN)r7   r8   r9   rL   rS   r\   rb   rc   rp   ru   ry   r{   r   r   r   r
   r   r   r   r   r   r   r   r   r   r@   D   s&    $A=
r@   c                   @   ,   e Zd Zdd Zdd Zdd Zdd Zd	S )
ConstructorBaseTestc                 C   s   t |}| }| }| |d | |j|j | |j|j | |j|j | |j|j | || t	|}|
d |
d tj|| d S )NrF   rG   )r(   r?   r)   r*   rH   r+   rJ   check_result_valuer   r   rK   r-   r.   )r/   r0   r2   r4   r5   r   r   r   check_0d  s   


zConstructorBaseTest.check_0dc                 C   s   t |}d}||}||}| |d | |j|j | |j|j | |j|j | |j|j | || t	|}|
d |
d tj|| | t}|d W d    n1 sdw   Y  | t|jd d S )NrP   rF   rG   negative dimensions not allowedr(   r?   r)   r*   rH   r+   rJ   r   r   r   rK   r-   r.   r   
ValueErrorr   r   )r/   r0   r2   rN   r4   r5   cmr   r   r   check_1d#  s$   



zConstructorBaseTest.check_1dc                 C   s   t |}d\}}|||}|||}| |d | |j|j | |j|j | |j|j | |j|j | || t	|}|
d |
d tj|| | t}|dd W d    n1 siw   Y  | t|jd d S )Nr`   rP   rF   rG   r`   r   r   r   )r/   r0   r2   rV   rN   r4   r5   r   r   r   r   check_2d8  s$   




zConstructorBaseTest.check_2dc                 C   sN   t |}| t}|  W d   n1 sw   Y  | dt|j dS )zAChecks that pyfunc will error, not segfaulting due to array size.Nzarray is too big)r(   r   r   r   r   r   )r/   r0   r2   er   r   r   check_alloc_sizeM  s   z$ConstructorBaseTest.check_alloc_sizeN)r7   r8   r9   r   r   r   r   r   r   r   r   r     s
    r   c                       s   e Zd Z 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  ZS )#TestNdZerosc                       t t|   tj| _d S r   )superr   setUpr   zerosr0   r/   	__class__r   r   r   Z     zTestNdZeros.setUpc                 C      t j|| d S r   r   r-   r.   r/   r5   r4   r   r   r   r   ^  rz   zTestNdZeros.check_result_valuec                        | j   fdd}| | d S )Nc                      s    dS Nr   r   r   r0   r   r   funcc  r   z!TestNdZeros.test_0d.<locals>.func)r0   r   r/   r   r   r   r   test_0da     zTestNdZeros.test_0dc                    r   )Nc                    r   r   r   rN   r   r   r   r   i  r   z!TestNdZeros.test_1d.<locals>.funcr0   r   r   r   r   r   test_1dg  r   zTestNdZeros.test_1dc                    r   )Nc                        | t jS r   r   rU   r   r   r   r   r   o  rr   z'TestNdZeros.test_1d_dtype.<locals>.funcr   r   r   r   r   test_1d_dtypem  r   zTestNdZeros.test_1d_dtypec                    s,   | j td  fdd}| | d S )NrU   c                    
   |  S r   r   r   Z_dtyper0   r   r   r   w     
z0TestNdZeros.test_1d_dtype_instance.<locals>.func)r0   r   r+   r   r   r   r   r   test_1d_dtype_instances  s   
z"TestNdZeros.test_1d_dtype_instancec                    <   | j d  fdd}| | fdd}| | d S )NrU   c                    r   r   r   r   r   r   r   r   ~  r   z+TestNdZeros.test_1d_dtype_str.<locals>.funcc                    
    | dS )N
complex128r   r   r   r   r   r     r   r   r   r   r   r   test_1d_dtype_str{  s   
zTestNdZeros.test_1d_dtype_strc                    r   )Ni4c                    r   r   r   r   r   r   r   r     r   z@TestNdZeros.test_1d_dtype_str_alternative_spelling.<locals>.funcc                    r   )Nc8r   r   r   r   r   r     r   r   r   r   r   r   &test_1d_dtype_str_alternative_spelling  s   
z2TestNdZeros.test_1d_dtype_str_alternative_spellingc                    s&   | j d  fdd}| | d S )Nzi4, (2,3)f8c                    r   r   r   r   r   r   r   r     r   z<TestNdZeros.test_1d_dtype_str_structured_dtype.<locals>.funcr   r   r   r   r   "test_1d_dtype_str_structured_dtype  s   z.TestNdZeros.test_1d_dtype_str_structured_dtypec                    st   | j  t fdd}| t}|dd W d    n1 s w   Y  t|j}d| j j d}| || d S )Nc                    
    | |S r   r   rN   dtr   r   r   r        
z5TestNdZeros.test_1d_dtype_non_const_str.<locals>.funcr~   rU   If np.0 dtype is a string it must be a string constant.)r0   r   r   r   r   r   r7   r   r/   r   r   excstrmsgr   r   r   test_1d_dtype_non_const_str  s   
z'TestNdZeros.test_1d_dtype_non_const_strc                    sb   | j  t fdd}| t}|d W d    n1 sw   Y  t|j}| d| d S )Nc                    r   NZABCDEFr   r   r   r   r   r     r   z3TestNdZeros.test_1d_dtype_invalid_str.<locals>.funcr~   'Invalid NumPy dtype specified: 'ABCDEF')r0   r   r   r   r   r   r   r/   r   r   r   r   r   r   test_1d_dtype_invalid_str  s   

z%TestNdZeros.test_1d_dtype_invalid_strc                    r   )Nc                        | |fS r   r   rV   rN   r   r   r   r     rr   z!TestNdZeros.test_2d.<locals>.funcr0   r   r   r   r   r   test_2d  r   zTestNdZeros.test_2dc                    s   | j   fdd}| |  fdd}| | tjrDt fdd}| t |tdd W d    d S 1 s=w   Y  d S d S )	Nc                        t | t |fS r   )r   int16rU   r  r   r   r   func1     z/TestNdZeros.test_2d_shape_dtypes.<locals>.func1c                    r  r   )r   int64int8r  r   r   r   func2  r  z/TestNdZeros.test_2d_shape_dtypes.<locals>.func2c                    r   r   r   r  r   r   r   <lambda>      z2TestNdZeros.test_2d_shape_dtypes.<locals>.<lambda>        rF   )	r0   r   r   	IS_32BITSr(   r   r   r   r  r/   r  r
  r2   r   r   r   test_2d_shape_dtypes  s   

"z TestNdZeros.test_2d_shape_dtypesc                    r   )Nc                    s    | |ft jdS Nrd   )r   	complex64r  r   r   r   r     rz   z-TestNdZeros.test_2d_dtype_kwarg.<locals>.funcr  r   r   r   r   test_2d_dtype_kwarg  r   zTestNdZeros.test_2d_dtype_kwargc                    r   )Nc                        | |fddS )Nr  rd   r   r  r   r   r   r     r   z1TestNdZeros.test_2d_dtype_str_kwarg.<locals>.funcr  r   r   r   r   test_2d_dtype_str_kwarg  r   z#TestNdZeros.test_2d_dtype_str_kwargc                    r   )Nc                    r  )Nr   rd   r   r  r   r   r   r     r   zFTestNdZeros.test_2d_dtype_str_kwarg_alternative_spelling.<locals>.funcr  r   r   r   r   ,test_2d_dtype_str_kwarg_alternative_spelling  s   z8TestNdZeros.test_2d_dtype_str_kwarg_alternative_spellingc                    sV   | j  tjj} fdd}| |d|d > tj | |d|d > dftj d S )Nc                    s    fddS )Nc                      s
    S r   r   r   )r+   r0   rH   r   r   r    s   
 z?TestNdZeros.test_alloc_size.<locals>.gen_func.<locals>.<lambda>r   rH   r+   r   )r+   rH   r   gen_func  r   z-TestNdZeros.test_alloc_size.<locals>.gen_funcrF   r`   r   @   )r0   r   intpbitwidthr   r   r/   widthr  r   r   r   test_alloc_size  s
   "zTestNdZeros.test_alloc_size)r7   r8   r9   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  __classcell__r   r   r   r   r   X  s$    r   c                       s.   e Zd Z fddZej fddZ  ZS )
TestNdOnesc                    r   r   )r   r   r   r   ri   r0   r   r   r   r   r     r   zTestNdOnes.setUpc                    s   t    d S r   )r   r   r   r   r   r   r     r   z-TestNdOnes.test_1d_dtype_str_structured_dtype)r7   r8   r9   r   unittestexpectedFailurer   r  r   r   r   r   r     s    r   c                   @   s|   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd ZdS )
TestNdFullc                 C   r   r   r   r   r   r   r   r     rz   zTestNdFull.check_result_valuec                 C      dd }|  | d S )Nc                   S   s   t ddS )Nr         @r   fullr   r   r   r   r     rr   z TestNdFull.test_0d.<locals>.func)r   r   r   r   r   r        zTestNdFull.test_0dc                 C   r$  )Nc                 S      t | dS Nr%  r&  r   r   r   r   r     rr   z TestNdFull.test_1d.<locals>.funcr   r   r   r   r   r     r(  zTestNdFull.test_1dc                 C   r$  )Nc                 S      t | dt jS r*  )r   r'  bool_r   r   r   r   r     r   z&TestNdFull.test_1d_dtype.<locals>.funcr+  r   r   r   r   r     r(  zTestNdFull.test_1d_dtypec                    $   t d  fdd}| | d S )Nboolc                       t | d S r*  r&  r   rd   r   r   r   
     z/TestNdFull.test_1d_dtype_instance.<locals>.func)r   r+   r   r   r   rd   r   r        
z!TestNdFull.test_1d_dtype_instancec                 C   r$  )Nc                 S      t | ddS Nr%  r-  r&  r   r   r   r   r     r1  z*TestNdFull.test_1d_dtype_str.<locals>.funcr+  r   r   r   r   r     r(  zTestNdFull.test_1d_dtype_strc                 C   r$  )Nc                 S   r3  )Nr%  ?r&  r   r   r   r   r     r1  z?TestNdFull.test_1d_dtype_str_alternative_spelling.<locals>.funcr+  r   r   r   r   r     s   z1TestNdFull.test_1d_dtype_str_alternative_spellingc                 C   s`   t dd }| t}|ddd W d    n1 sw   Y  t|j}d}| || d S )Nc                 S      t | ||S r   r&  )rN   fvr   r   r   r   r     r   z4TestNdFull.test_1d_dtype_non_const_str.<locals>.funcr~   r%  rU   z:If np.full dtype is a string it must be a string constant.r   r   r   r   r   r   r   r   r   r   r     s   

z&TestNdFull.test_1d_dtype_non_const_strc                 C   sZ   t dd }| t}|dd W d    n1 sw   Y  t|j}| d| d S )Nc                 S      t | |dS r   r&  )rN   r7  r   r   r   r   )  r   z2TestNdFull.test_1d_dtype_invalid_str.<locals>.funcr8  r%  r   r9  r   r   r   r   r   '  s   

z$TestNdFull.test_1d_dtype_invalid_strc                 C   r$  )Nc                 S      t | |fdS r*  r&  r  r   r   r   r   4  r   z TestNdFull.test_2d.<locals>.funcr   r   r   r   r   r  3  r(  zTestNdFull.test_2dc                 C   r$  )Nc                 S      t j| |fdt jdS )Ny      ?      @rd   )r   r'  r  r  r   r   r   r   9  r   z,TestNdFull.test_2d_dtype_kwarg.<locals>.funcr<  r   r   r   r   r  8  r(  zTestNdFull.test_2d_dtype_kwargc                 C   s:   dd }|  | dd }|  | dd }|  | d S )Nc                 S      t | |ft dS r   )r   r'  rU   r  r   r   r   r   ?  r   z0TestNdFull.test_2d_dtype_from_type.<locals>.funcc                 S   r>  r   )r   r'  r   r  r   r   r   r   D  r   c                 S   r=  )NrF   rd   )r   r'  r	  r  r   r   r   r   I  r   r<  r   r   r   r   test_2d_dtype_from_type=  s   

z"TestNdFull.test_2d_dtype_from_typec                 C   sz   dd }|  | dd }|  | tjr;tdd }| t |tdd W d    d S 1 s4w   Y  d S d S )	Nc                 S      t t | t |fdS r*  )r   r'  r  rU   r  r   r   r   r  O     z.TestNdFull.test_2d_shape_dtypes.<locals>.func1c                 S   r@  r*  )r   r'  r  r	  r  r   r   r   r
  S  rA  z.TestNdFull.test_2d_shape_dtypes.<locals>.func2c                 S   r;  r*  r&  r  r   r   r   r  X  s    z1TestNdFull.test_2d_shape_dtypes.<locals>.<lambda>r  rF   )r   r   r  r(   r   r   r   r  r  r   r   r   r  M  s   

"zTestNdFull.test_2d_shape_dtypesc                 C   sH   t jj}dd }| |d|d > d | |d|d > dfd d S )Nc                    s    fddS )Nc                      s   t  S r   r&  r   rH   valuer   r   r  _  r  z>TestNdFull.test_alloc_size.<locals>.gen_func.<locals>.<lambda>r   rB  r   rB  r   r  ^  r1  z,TestNdFull.test_alloc_size.<locals>.gen_funcrF   r`   r   r  )r   r  r  r   r  r   r   r   r  \  s    zTestNdFull.test_alloc_sizeN)r7   r8   r9   r   r   r   r   r   r   r   r   r   r  r  r?  r  r  r   r   r   r   r#    s    r#  c                   @   s   e Zd Zdd Zdd ZdS )ConstructorLikeBaseTestc              	   C   s@   z| d W d S  ttfy   d|jj }| | Y d S w )NrA      x)rK   	TypeErrorr   r+   rR   )r/   r=   Z
fill_valuer   r   r   mutate_arrayg  s   z$ConstructorLikeBaseTest.mutate_arrayc              	      s    fdd}t ddd|}t dD ]I}|dkr(|dd  d}n||}|| |jdkr?||d d d	  d
|jd< t d|d< W d    n1 sXw   Y  || q||d  d S )Nc                    sn   | } | } |j|j  |j|j || || | | tj|| d S r   )	r)   r*   r+   r,   r   rG  r   r-   r.   )r=   r4   r5   r2   r0   r/   r   r   	check_arrp  s   

z5ConstructorLikeBaseTest.check_like.<locals>.check_arrr   r~      )rJ  r   rF   r`   rP   )rP   rF   r`   r   r   r   r`   FZ	WRITEABLErF   )	r   linspaceastyper(   r   ndimflagsr   r   )r/   r0   r+   rI  origrH   r=   r   rH  r   
check_likeo  s    




z"ConstructorLikeBaseTest.check_likeN)r7   r8   r9   rG  rQ  r   r   r   r   rD  e  s    rD  c                       st   e Zd Z 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  ZS )TestNdEmptyLikec                    r   r   )r   rR  r   r   r   r0   r   r   r   r   r     r   zTestNdEmptyLike.setUpc                 C   s   d S r   r   r   r   r   r   r     rh   z"TestNdEmptyLike.check_result_valuec                    $   | j   fdd}| |tj d S )Nc                    r   r   r   rD   r   r   r   r     r   z'TestNdEmptyLike.test_like.<locals>.funcr0   rQ  r   rI   r   r   r   r   	test_like     zTestNdEmptyLike.test_likec                    s<   t dt jfdt jfg}| j  fdd}| || d S )Nr   r   c                    r   r   r   rD   r   r   r   r     r   z2TestNdEmptyLike.test_like_structured.<locals>.func)r   r+   r  rj   r0   rQ  r/   r+   r   r   r   r   test_like_structured  s   z$TestNdEmptyLike.test_like_structuredc                    rS  )Nc                    r   r   r   rD   r   r   r   r     rr   z-TestNdEmptyLike.test_like_dtype.<locals>.funcrT  r   r   r   r   test_like_dtype  rV  zTestNdEmptyLike.test_like_dtypec                    s0   t d | j fdd}| |t j d S )NrU   c                    r   r   r   rD   r+   r0   r   r   r     r   z6TestNdEmptyLike.test_like_dtype_instance.<locals>.func)r   r+   r0   rQ  rI   r   r   rZ  r   test_like_dtype_instance  s   
z(TestNdEmptyLike.test_like_dtype_instancec                    s@   t dt jfdt jfg | j fdd}| |t j d S )Nr   r   c                    r   r   r   rD   rZ  r   r   r     r   z8TestNdEmptyLike.test_like_dtype_structured.<locals>.func)r   r+   r  rj   r0   rQ  rI   r   r   rZ  r   test_like_dtype_structured  s   z*TestNdEmptyLike.test_like_dtype_structuredc                    rS  )Nc                    s    | t jdS r  r   rD   r   r   r   r     r1  z3TestNdEmptyLike.test_like_dtype_kwarg.<locals>.funcrT  r   r   r   r   test_like_dtype_kwarg  rV  z%TestNdEmptyLike.test_like_dtype_kwargc                    rS  )Nc                        | ddS )NrU   rd   r   rD   r   r   r   r     rr   z7TestNdEmptyLike.test_like_dtype_str_kwarg.<locals>.funcrT  r   r   r   r   test_like_dtype_str_kwarg  rV  z)TestNdEmptyLike.test_like_dtype_str_kwargc                    rS  )Nc                    r^  )Nr   rd   r   rD   r   r   r   r     rr   zLTestNdEmptyLike.test_like_dtype_str_kwarg_alternative_spelling.<locals>.funcrT  r   r   r   r   .test_like_dtype_str_kwarg_alternative_spelling  rV  z>TestNdEmptyLike.test_like_dtype_str_kwarg_alternative_spellingc                    s   | j  t fdd}| t}|tdd W d    n1 s#w   Y  t|j}d| j j d}| 	|| | 	d
 j| d S )Nc                    r   r   r   r   r   r   r   r     r   z;TestNdEmptyLike.test_like_dtype_non_const_str.<locals>.funcrX   rU   r   r   z'{}(array(float64, 1d, C), unicode_type))r0   r   r   r   r   ri   r   r   r7   r   r   r   r   r   r   test_like_dtype_non_const_str  s   

z-TestNdEmptyLike.test_like_dtype_non_const_strc                    sh   | j  t fdd}| t}|td W d    n1 s"w   Y  t|j}| d| d S )Nc                    r   r   r   r   r   r   r   r     r   z9TestNdEmptyLike.test_like_dtype_invalid_str.<locals>.funcrX   r   )	r0   r   r   r   r   ri   r   r   r   r   r   r   r   test_like_dtype_invalid_str  s   
z+TestNdEmptyLike.test_like_dtype_invalid_str)r7   r8   r9   r   r   rU  rX  rY  r[  r\  r]  r_  r`  ra  rb  r  r   r   r   r   rR    s    rR  c                       s<   e Zd Z fddZdd Z fddZ fddZ  ZS )	TestNdZerosLikec                    r   r   )r   rc  r   r   Z
zeros_liker0   r   r   r   r   r     r   zTestNdZerosLike.setUpc                 C   r   r   r   r   r   r   r   r     rz   z"TestNdZerosLike.check_result_valuec                       t t|   d S r   )r   rc  rX  r   r   r   r   rX    rz   z$TestNdZerosLike.test_like_structuredc                    rd  r   )r   rc  r\  r   r   r   r   r\    rz   z*TestNdZerosLike.test_like_dtype_structured)r7   r8   r9   r   r   rX  r\  r  r   r   r   r   rc    s
    rc  c                       s@   e Zd Z fddZej fddZej fddZ  ZS )TestNdOnesLikec                    s    t t|   tj| _d| _d S r   )r   re  r   r   Z	ones_liker0   Zexpected_valuer   r   r   r   r     s   
zTestNdOnesLike.setUpc                    rd  r   )r   re  rX  r   r   r   r   rX       z#TestNdOnesLike.test_like_structuredc                    rd  r   )r   re  r\  r   r   r   r   r\    rf  z)TestNdOnesLike.test_like_dtype_structured)	r7   r8   r9   r   r!  r"  rX  r\  r  r   r   r   r   re    s    re  c                   @   sb   e Zd Zdd Zdd Zejdd Zdd Zd	d
 Z	dd Z
dd Zdd Zdd Zdd ZdS )TestNdFullLikec                 C   r   r   r   r   r   r   r   r     rz   z!TestNdFullLike.check_result_valuec                 C      dd }|  |tj d S )Nc                 S   r)  )N      @r   	full_likerD   r   r   r   r     rr   z&TestNdFullLike.test_like.<locals>.funcrQ  r   rI   r   r   r   r   rU       zTestNdFullLike.test_likec                 C   s2   t dt jfdt jfg}dd }| || d S )Nr   r   c                 S   r)  r*  rj  rD   r   r   r   r     rr   z1TestNdFullLike.test_like_structured.<locals>.func)r   r+   r  rj   rQ  rW  r   r   r   rX    s   z#TestNdFullLike.test_like_structuredc                 C   rh  )Nc                 S   r,  r*  r   rk  r-  rD   r   r   r   r   $  r   z,TestNdFullLike.test_like_dtype.<locals>.funcrl  r   r   r   r   rY  #  rm  zTestNdFullLike.test_like_dtypec                    s(   t d  fdd}| |t j d S )Nr/  c                    r0  r*  rj  rD   rd   r   r   r   *  r1  z5TestNdFullLike.test_like_dtype_instance.<locals>.func)r   r+   rQ  rI   r   r   rd   r   r[  (  s   
z'TestNdFullLike.test_like_dtype_instancec                 C   rh  )Nc                 S   s   t j| dt jdS )Nr%  rd   rn  rD   r   r   r   r   /  rz   z2TestNdFullLike.test_like_dtype_kwarg.<locals>.funcrl  r   r   r   r   r]  .  rm  z$TestNdFullLike.test_like_dtype_kwargc                 C   rh  )Nc                 S   r3  r4  rj  rD   r   r   r   r   4  r1  z6TestNdFullLike.test_like_dtype_str_kwarg.<locals>.funcrl  r   r   r   r   r_  3  rm  z(TestNdFullLike.test_like_dtype_str_kwargc                 C   rh  )Nc                 S   s   t j| dddS )Nr%  r5  rd   rj  rD   r   r   r   r   9  r   zKTestNdFullLike.test_like_dtype_str_kwarg_alternative_spelling.<locals>.funcrl  r   r   r   r   r`  8  rm  z=TestNdFullLike.test_like_dtype_str_kwarg_alternative_spellingc                 C   sf   t dd }| t}|tddd W d    n1 sw   Y  t|j}d}| || d S )Nc                 S   r6  r   rj  )r=   r7  r   r   r   r   r   ?  r   z@TestNdFullLike.test_like_dtype_non_const_str_kwarg.<locals>.funcrP   r%  rU   z?If np.full_like dtype is a string it must be a string constant.r   r   r   r   ri   r   r   r   r   r   r   r   #test_like_dtype_non_const_str_kwarg=  s   

z2TestNdFullLike.test_like_dtype_non_const_str_kwargc                 C   s`   t dd }| t}|tdd W d    n1 sw   Y  t|j}| d| d S )Nc                 S   r:  r   rj  )r=   r7  r   r   r   r   M  r   z8TestNdFullLike.test_like_dtype_invalid_str.<locals>.funcrX   g333333@r   ro  r   r   r   r   rb  K  s   

z*TestNdFullLike.test_like_dtype_invalid_strN)r7   r8   r9   r   rU  r!  r"  rX  rY  r[  r]  r_  r`  rp  rb  r   r   r   r   rg    s    
rg  c                   @   r   )
TestNdIdentityc                 C   s   |  |dg d S )NrP   r6   r/   r0   r   r   r   check_identityZ  rz   zTestNdIdentity.check_identityc                 C   r$  )Nc                 S   
   t | S r   r   identityr   r   r   r   r   ^  r   z*TestNdIdentity.test_identity.<locals>.func)ru  r   r   r   r   test_identity]  r(  zTestNdIdentity.test_identityc                    s:   t jt jt jt ddfD ]  fdd}| | qd S )Nr/  r-  c                    s   t |  S r   rw  r   rd   r   r   r   e  rr   z0TestNdIdentity.test_identity_dtype.<locals>.func)r   r  r  r-  r+   ru  r   r   rd   r   test_identity_dtypeb  s   z"TestNdIdentity.test_identity_dtypec                 C   ^   t dd }| t}|dd W d    n1 sw   Y  t|j}d}| || d S )Nc                 S      t | |S r   rw  r   r   r   r   r   k     z@TestNdIdentity.test_like_dtype_non_const_str_kwarg.<locals>.funcrX   rU   z>If np.identity dtype is a string it must be a string constant.r9  r   r   r   r   rp  i     

z2TestNdIdentity.test_like_dtype_non_const_str_kwargN)r7   r8   r9   ru  ry  rz  rp  r   r   r   r   rq  X  s
    rq  c                   @   sD   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dS )	TestNdEyec                 C      dd }|  |ddg d S )Nc                 S   rv  r   r   eyer   r   r   r   r   |  r   z"TestNdEye.test_eye_n.<locals>.funcrF   rr  rs  r   r   r   r   
test_eye_n{     zTestNdEye.test_eye_nc                 C   s8   d t jt dfD ]}|fdd}| |ddg q	d S )NrF   c                 S      t j| |dS r  r  )rN   r+   r   r   r   r     r1  z(TestNdEye.test_eye_n_dtype.<locals>.funcr  rr  )r   r   r  r6   )r/   r   r   r   r   r   test_eye_n_dtype  s   zTestNdEye.test_eye_n_dtypec                 C      dd }|  |g d d S )Nc                 S   r|  r   r  rN   rV   r   r   r   r     rr   z$TestNdEye.test_eye_n_m.<locals>.func)rF   r`   rP   r`   )r   rP   rs  r   r   r   r   test_eye_n_m  r  zTestNdEye.test_eye_n_mc                 C   s   |  |g d d S )N))rF   r`   r   )rP   rX   rF   )rP   rX   r   )rX   rP   )rX   rP   )rX   rP   r~   rs  r   r   r   r   check_eye_n_m_k  r   zTestNdEye.check_eye_n_m_kc                 C   r$  )Nc                 S   r6  r   r  rN   rV   r_   r   r   r   r     r1  z&TestNdEye.test_eye_n_m_k.<locals>.funcr  r   r   r   r   test_eye_n_m_k  r(  zTestNdEye.test_eye_n_m_kc                 C   r$  )Nc                 S   s   t j| ||t jdS N)NMr_   r+   )r   r  r  r  r   r   r   r     r   z,TestNdEye.test_eye_n_m_k_dtype.<locals>.funcr  r   r   r   r   test_eye_n_m_k_dtype  r(  zTestNdEye.test_eye_n_m_k_dtypec                    r.  )Nr  c                    s   t j| || dS r  r  r  rd   r   r   r     rz   z5TestNdEye.test_eye_n_m_k_dtype_instance.<locals>.func)r   r+   r  r   r   rd   r   test_eye_n_m_k_dtype_instance  r2  z'TestNdEye.test_eye_n_m_k_dtype_instanceN)
r7   r8   r9   r  r  r  r  r  r  r  r   r   r   r   r  y  s    r  c                   @   sL   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dS )
TestNdDiagc                 C   s   t g d}t g dg}t |}|||g| _t ddd}t ddd}||g| _dd }|| _t|| _	d
dd	}|| _
t|| _d S )NrK     rP   rX   c                 S   rv  r   r   Zdiag)qr   r   r   r     r   zTestNdDiag.setUp.<locals>.funcr   c                 S   r  )Nr_   r  )r  r_   r   r   r   
func_kwarg  r1  z$TestNdDiag.setUp.<locals>.func_kwarg)r   )r   arrayZ	transposevectorsrQ   r   	matriciespyr(   jitpy_kwjit_kw)r/   vZhvvvZa3x4Za4x3r   r  r   r   r   r     s   



zTestNdDiag.setUpc                 O   sN   ||i |}||i |}|  |j|j |  |j|j tj|| d S r   )r)   r*   r+   r   r-   r.   )r/   r0   Znrtfuncr3   kwargsr4   Zcomputedr   r   r   
check_diag  s
   zTestNdDiag.check_diagc                 C   "   | j D ]}| | j| j| qd S r   )r  r  r  r  r/   dr   r   r   test_diag_vect_create     
z TestNdDiag.test_diag_vect_createc                 C   6   t ddD ]}| jD ]}| j| j| j||d q
qd S )Nir}   r  )rM   r  r  r  r  r/   r_   r  r   r   r   test_diag_vect_create_kwarg  
   
z&TestNdDiag.test_diag_vect_create_kwargc                 C   r  r   )r  r  r  r  r  r   r   r   test_diag_extract  r  zTestNdDiag.test_diag_extractc                 C   r  )NrX   r  )rM   r  r  r  r  r  r   r   r   test_diag_extract_kwarg  r  z"TestNdDiag.test_diag_extract_kwargc                 C   s   t dggg}t| j}| t |  W d    n1 s w   Y  | t || W d    n1 s9w   Y  | t t| j}||dd W d    d S 1 sZw   Y  d S )N      ?rP   r  )r   r  r(   r  r   rF  r   r  )r/   r  r2   Zdfuncr   r   r   test_error_handling  s   


"zTestNdDiag.test_error_handlingc                 C   sH   t | j}d}| t|}|d  W d    d S 1 sw   Y  d S )Nz'.*The argument "v" must be array-like.*)r(   r  assertRaisesRegexr   )r/   r2   r   r   r   r   r   test_bad_shape  s
   

"zTestNdDiag.test_bad_shapeN)r7   r8   r9   r   r  r  r  r  r  r  r  r   r   r   r   r    s    	r  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestLinspacec                 C   r  )Nc                 S   r|  r   r   rL  r  r   r   r   r0     rr   z,TestLinspace.test_linspace_2.<locals>.pyfunc))r   rX   )rF   r   )            @)                    @      @)r`   rF   )      ?      ?              ?rs  rt  r   r   r   test_linspace_2     zTestLinspace.test_linspace_2c                 C   r  )Nc                 S   r6  r   r  rN   rV   r^   r   r   r   r0     r1  z,TestLinspace.test_linspace_3.<locals>.pyfunc))r   rX   	   )rF   rX   rP   )r  r  r   )r  r  r   )r`   rF   r   )r  r  r~   )rF   g}Ô%ITrF   rs  rt  r   r   r   test_linspace_3  r  zTestLinspace.test_linspace_3c                 C   s8   t dd }d\}}}| |||||||| d S )Nc                 S   r6  r   r  r  r   r   r   rE     r   z0TestLinspace.test_linspace_accuracy.<locals>.foo)g        r  r   )r(   assertPreciseEqualZpy_func)r/   rE   rN   rV   r^   r   r   r   test_linspace_accuracy  s   

"z#TestLinspace.test_linspace_accuracyN)r7   r8   r9   r  r  r  r   r   r   r   r    s    r  c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestNpyEmptyKeywordc                    Z    fdd}g d}t |}|D ]}||}||}| |j|j | |j|j qd S )Nc                       t j|  dS r  rB   rH   rd   r   r   r0     r1  z7TestNpyEmptyKeyword._test_with_dtype_kw.<locals>.pyfuncrF   r~   r  r(   r)   r+   rH   r/   r+   r0   Zshapesr2   sr4   rx   r   rd   r   _test_with_dtype_kw
     z'TestNpyEmptyKeyword._test_with_dtype_kwc                 C   ,   t jt jt jt dfD ]}| | qd S Nr  )r   rU   rj   r  r+   r  r/   r+   r   r   r   test_with_dtype_kws     z'TestNpyEmptyKeyword.test_with_dtype_kwsc                    r  )Nc                    r  )Nr  rB   r  rd   r   r   r0     r1  zATestNpyEmptyKeyword._test_with_shape_and_dtype_kw.<locals>.pyfuncr  r  r  r   rd   r   _test_with_shape_and_dtype_kw  r  z1TestNpyEmptyKeyword._test_with_shape_and_dtype_kwc                 C   r  r  )r   rU   rj   r  r+   r  r  r   r   r   test_with_shape_and_dtype_kws(  r  z1TestNpyEmptyKeyword.test_with_shape_and_dtype_kwsc                 C   sF   dd }t |}| t |  W d    d S 1 sw   Y  d S )Nc                   S   s   t  S r   rB   r   r   r   r   r0   .  r   z6TestNpyEmptyKeyword.test_empty_no_args.<locals>.pyfunc)r(   r   r   )r/   r0   r2   r   r   r   test_empty_no_args,  s
   "z&TestNpyEmptyKeyword.test_empty_no_argsN)r7   r8   r9   r  r  r  r  r  r   r   r   r   r  	  s    r  c                   @   sd   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )TestNpArrayc                 C   sN   dd }t |}|d}| |tjdtjd |d}| |td d S )Nc                 S   rv  r   r   r  argr   r   r   r0   <  r   z#TestNpArray.test_0d.<locals>.pyfuncrA   rd   r  )r(   r  r   r  r  r/   r0   r2   rx   r   r   r   r   ;  s   zTestNpArray.test_0dc                 C   r  )Nc                 S      t j| t jdS r  )r   r  r  r  r   r   r   r0   F  r   z.TestNpArray.test_0d_with_dtype.<locals>.pyfunc)rA   )ri  rs  rt  r   r   r   test_0d_with_dtypeE  s   zTestNpArray.test_0d_with_dtypec                 C   sn   dd }t |}|g d}| |tg d |d}| |tg d |d}| |td d S )Nc                 S   rv  r   r  r  r   r   r   r0   L  r   z#TestNpArray.test_1d.<locals>.pyfunc)r`   rP   rA   )r  y              @rA   r   )r(   r  r   r  r  rI   r  r   r   r   r   K  s   zTestNpArray.test_1dc                 C   ,   dd }|  |ddgfddgfddg d S )	Nc                 S   r  r  )r   r  rj   r  r   r   r   r0   [  r   z.TestNpArray.test_1d_with_dtype.<locals>.pyfuncr`   rA   ri  r  )rF   ri  rA   r   rs  rt  r   r   r   test_1d_with_dtypeZ     zTestNpArray.test_1d_with_dtypec                 C   r  )	Nc                 S   s   t j| ddS )Nrj   rd   r  r  r   r   r   r0   f  r1  z2TestNpArray.test_1d_with_str_dtype.<locals>.pyfuncr`   rA   ri  r  r  r  rs  rt  r   r   r   test_1d_with_str_dtypee  r  z"TestNpArray.test_1d_with_str_dtypec                 C   r{  )Nc                 S   r  r  r  )r  r   r   r   r   r   r  r   z:TestNpArray.test_1d_with_non_const_str_dtype.<locals>.func)r~   rP   rU   z;If np.array dtype is a string it must be a string constant.r9  r   r   r   r    test_1d_with_non_const_str_dtypep  r~  z,TestNpArray.test_1d_with_non_const_str_dtypec                 C   s  dd }t |}|ddg}| |tddgddgg |d	d
g}| |tddgddgg |ddgddgf}| |tddgddgg |ddgddgf}| |tddgddgg |d}| |tddgddgg |d}| |td d S )Nc                 S   rv  r   r  r  r   r   r   r0     r   z#TestNpArray.test_2d.<locals>.pyfuncr  rP   rX   rF   r`   rP   rX   rF   r  rP   r%  r  r%  ri  ))      ?r`   )ri  r%  r  )r   r   )r(   r  r   r  rI   r  r   r   r   r  ~  s   zTestNpArray.test_2dc                 C   s>   dd }t |}|ddg}| |tddgddgg d S )	Nc                 S   r  r  )r   r  rU   r  r   r   r   r0     r   z.TestNpArray.test_2d_with_dtype.<locals>.pyfuncr  r  rF   r`   rP   rX   )r(   r  r   rU   r  r   r   r   test_2d_with_dtype  s   "zTestNpArray.test_2d_with_dtypec                    s   dd }t |}tj fdd}|d |tdg W d    n1 s(w   Y  |d |tdtd	gf W d    n1 sIw   Y  |d
$ tddg}tjd|dd }|dtd|ff W d    d S 1 syw   Y  d S )Nc                 S   rv  r   r  r  r   r   r   r0     r   z'TestNpArray.test_raises.<locals>.pyfuncc                 3   sH      t}d V  W d    n1 sw   Y   | t|j d S r   )r   r   r   r   r   )r   r   r   r   r   check_raises  s
   z-TestNpArray.test_raises.<locals>.check_raisesz;array(float64, 1d, C) not allowed in a homogeneous sequencer  zOtype Tuple(int64, reflected list(int64)<iv=None>) does not have a regular shaperF   r`   zrcannot convert Tuple(int64, Record(a[type=int32;offset=0],b[type=float32;offset=4];8;False)) to a homogeneous type)r   r   )r   Zf4rd   r   r  )r(   
contextlibcontextmanagerr   r  r  r+   r   )r/   r0   r2   r  stvalr   r   r   test_raises  s"   

"zTestNpArray.test_raisesc                 C   sJ   t dd }d}| t|}|d  W d    d S 1 sw   Y  d S )Nc                 S   rv  r   r  )objr   r   r   r     r   z(TestNpArray.test_bad_array.<locals>.funcz,.*The argument "object" must be array-like.*r   r  r   r/   r   r   r   r   r   r   test_bad_array  s   

"zTestNpArray.test_bad_arrayc                 C   sL   t dd }d}| t|}|dd W d    d S 1 sw   Y  d S )Nc                 S   r|  r   r  )r  r   r   r   r   r     r}  z(TestNpArray.test_bad_dtype.<locals>.funcz>.*The argument "dtype" must be a data-type if it is provided.*r~   rX   r  r  r   r   r   test_bad_dtype  s   
"zTestNpArray.test_bad_dtypeN)r7   r8   r9   r   r  r   r  r  r  r  r  r  r  r  r   r   r   r   r  9  s    
	r  c                   @   s>   e Zd ZdZdd Zejdd Zdd Zdd	 Z	d
d Z
dS )TestNpConcatenatez%
    Tests for np.concatenate().
    c                 C   ^   t dd}|d }|d jdd}|d d d d }|d dd d df }|||||fS N   )rX   rP   r`   r}   F)orderr   .r   rQ   r   r   r/   r   r   r   r  r   r   r   r   
_3d_arrays     zTestNpConcatenate._3d_arraysc                 c   sL    |  t}d V  W d    n1 sw   Y  | d| t|j d S )Nz*input sizes over dimension %d do not matchr   r   r   r   r   )r/   r   r   r   r   r   assert_invalid_sizes_over_dim  s   
z/TestNpConcatenate.assert_invalid_sizes_over_dimc              	      s  t t  fddfdd} \}}}}}|||| |||| ||j|j|j ||j|j|j ||j|j|j ||j|j|j |dd  ||d d d dd ||d d dd f |dd |||d d d d dd f d	d |||tj|   d
D ]"}d  |dd  ||| W d    n1 sw   Y  qdD ]&}d  ||d d dd f || W d    n1 sw   Y  qd S )Nc                    sB   |d| fD ]}| |||d} | |||d} || qd S )Nr   r  )r   r   r   r   axr4   rx   rH  r   r   check  s
   z(TestNpConcatenate.test_3d.<locals>.checkc                    s    t dD ]	} | ||| qd S )NrP   r   r   )r  r   r   check_all_axes  s   z1TestNpConcatenate.test_3d.<locals>.check_all_axesrF   r   r   r   r`   )rF   r`   r  r   )r   r`   r  r   )	r   r(   r   TrM  r   rI   r   r  )r/   r  r   r   r   r  r   r   r   )r2   r  r0   r/   r   test_3d  s6   " & zTestNpConcatenate.test_3dc                    s   t t  fdd} \}}}}}|||| |||| ||j|j|j ||j|j|j ||j|j|j ||j|j|j ||dd  ||d d d    d  ||d d dd f | W d    d S 1 syw   Y  d S )Nc                    s(   | ||} | ||} || d S r   r  )r   r   r   r4   rx   rH  r   r   r    s   z0TestNpConcatenate.test_3d_no_axis.<locals>.checkrF   r   )r   r(   r   r	  r   r  )r/   r  r   r   r   r  r   r   rH  r   test_3d_no_axis  s   "z!TestNpConcatenate.test_3d_no_axisc                 C   s^  t }t|}td}|d}|tdtjfg}td}| 	 }|||| W d    n1 s6w   Y  | 
dt|j | 	 }|||| W d    n1 sYw   Y  | 
dt|j | 	 }|||| W d    n1 s|w   Y  | 
dt|j | 	 }||d| W d    n1 sw   Y  | 
d	t|j d S )
N   )rP   r~   r   rA   z8all the input arrays must have same number of dimensionsz(input arrays must have compatible dtypesz.zero-dimensional arrays cannot be concatenatedrF   %expecting a non-empty tuple of arrays)r   r(   r   rQ   r   rM  r+   r	  r  assertTypingErrorr   r   r   )r/   r0   r2   r   r   r   r  r   r   r   r   test_typing_errors5  s8   






z$TestNpConcatenate.test_typing_errorsN)r7   r8   r9   __doc__r   r  r  r  r
  r  r  r   r   r   r   r    s    
2$r  r   z"this Numpy doesn't have np.stack()c                   @   s   e Zd ZdZdd Zejdd Zdd Zdd	 Z	d
d Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )TestNpStackz
    Tests for np.stack().
    c                 C   r  r  r  r  r   r   r   r   \  r  zTestNpStack._3d_arraysc                 c   sH    |  t}d V  W d    n1 sw   Y  | dt|j d S )Nz)all input arrays must have the same shaper  )r/   r   r   r   r   assert_invalid_sizesd  s   z TestNpStack.assert_invalid_sizesc                 C   s8   || }|| }|  |j|j | | |  d S r   )r)   rH   r  flatten)r/   r0   r2   r3   r4   rx   r   r   r   check_stackk  s   zTestNpStack.check_stackc           
         s    fddfdd}  \}}}}}	|||| |||| ||j|j|j ||j|j|j ||j|j|j ||j|	j|j |||tj| d S )Nc                    s     | ||f|  d S r   )r  r   r   r   r3   rH  r   r   r  v  rA  z#TestNpStack.check_3d.<locals>.checkc                    s    D ]	} | ||| qd S r   r   r  )r  generate_starargsr   r   r  y  s   
z,TestNpStack.check_3d.<locals>.check_all_axes)r   r	  rM  r   rI   )
r/   r0   r2   r  r  r   r   r   r  r   r   )r2   r  r  r0   r/   r   check_3du  s   zTestNpStack.check_3dc           	      C   sv   |    |   |  \}}}}}|   t| }||d d ||g|R   W d    d S 1 s4w   Y  d S )Nr   )assert_no_memory_leakr   r   r  next)	r/   r2   r  r   r   r   r  r   r3   r   r   r   check_runtime_errors  s   

"z TestNpStack.check_runtime_errorsc                 C   2   t }t|}dd }| ||| | || dS )z(
        stack(3d arrays, axis)
        c                  s   s(    t dD ]} | fV  d|  fV  qd S )NrP   r  r   r   r   r   r   r    s
   z.TestNpStack.test_3d.<locals>.generate_starargsN)r!   r(   r  r  r/   r0   r2   r  r   r   r   r
    s
   zTestNpStack.test_3dc                 C   r  )z"
        stack(3d arrays)
        c                   s       dV  d S r   r   r   r   r   r   r       
z6TestNpStack.test_3d_no_axis.<locals>.generate_starargsN)r    r(   r  r  r  r   r   r   r    s
   zTestNpStack.test_3d_no_axisc                 C   sB   t }t|}td}td}td}| |||||f dS )z"
        stack(0d arrays)
        rA                TN)r    r(   r   r  r  r/   r0   r2   r   r   r   r   r   r   r     s   


zTestNpStack.test_0dc                 C   sL   dd }|  ||| td}td}td}| |||||f dS )zC
        3d and 0d tests for hstack(), vstack(), dstack().
        c                   s   r  r   r   r   r   r   r   r    r  z4TestNpStack.check_xxstack.<locals>.generate_starargsrA   r  TN)r  r   r  r  )r/   r0   r2   r  r   r   r   r   r   r   check_xxstack  s   


zTestNpStack.check_xxstackc                 C   s   t }t|}| || td}tdd }| |||||f tdd}tddd }| |||||f d S )Nr~   rJ  r}   r   r   )r`   rX   r   )r"   r(   r!  r   rQ   r  r   r/   r0   r2   r   r   r   r   r   test_hstack  s   
zTestNpStack.test_hstackc                 C   s   t tfD ];}t|}| || td}|d }| |||||f tdd}tddd }| |||||f qd S )Nr~   r}   rJ  r  r   )rX   r`   r   )r#   r$   r(   r!  r   rQ   r  r   r"  r   r   r   test_vstack  s   
zTestNpStack.test_vstackc                 C   sn   t }t|}| || td}|d }| |||||f tdd}|d }| |||||f d S )Nr~   r}   r  r  r   )r%   r(   r!  r   rQ   r  r   r"  r   r   r   test_dstack  s   
zTestNpStack.test_dstackc                 C   s   t }t|}td}|d }tdd}| |||||f |   |   td}| 	  ||||f W d    n1 sDw   Y  |d}| 	  ||||f W d    d S 1 sew   Y  d S )NrX   r}   r  rX   rP   rA   )rF   rF   rF   )
r&   r(   r   rQ   r   r  r  r   r  r  r   r   r   r   test_column_stack  s    




"zTestNpStack.test_column_stackc              	   C   sv   t ttttfD ]1}t|}tdd}| 	 }||d| W d    n1 s*w   Y  | 
dt|j qd S )Nr  r&  rF   r  )r    r"   r#   r%   r&   r(   r   rQ   r   r  r   r   r   )r/   r0   r2   r   r   r   r   r   test_bad_arrays  s   
zTestNpStack.test_bad_arraysN)r7   r8   r9   r  r   r  r  r  r  r  r  r
  r  r   r!  r#  r$  r%  r'  r(  r   r   r   r   r  V  s"    

r  c                     sx   dd t  tjdtjddfdd}  fdd}t| }t|}t| t| d S )	Nc                 S   r   )z1Swap array x and y for t number of times
        r   r   r   r   r   r0     s   z%benchmark_refct_speed.<locals>.pyfuncr   i'  c                           d S r   r   r   )r0   r   r   rf   r   r   bench_pyfunc,  r   z+benchmark_refct_speed.<locals>.bench_pyfuncc                      r)  r   r   r   )r2   r   r   rf   r   r   bench_cfunc/  r   z*benchmark_refct_speed.<locals>.bench_cfunc)r(   r   r   r   Z	benchmarkprint)r*  r+  Zpython_timeZ
numba_timer   )r2   r0   r   r   rf   r   benchmark_refct_speed  s   

r-  __main__):r  rk   numpyr   r   rer   rm   Znumba.core.errorsr   Znumbar   Z
numba.corer   r   r   Znumba.tests.supportr   r   r	   r
   r!  r(   r   r   r    r!   r"   r#   r$   r%   r&   r'   r:   r@   r   r   r   r#  objectrD  rR  rc  re  rg  rq  r  r  r  r  r  r  Z
skipUnlesshasattrr  r-  r7   mainr   r   r   r   <module>   sl       PG q.\G!,H0   H
