o
    8ήc                     @   sT  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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 d.d/ d/e'eZ+G d0d1 d1eZ,G d2d3 d3eZ-G d4d5 d5eZ.G d6d7 d7eZ/G d8d9 d9eZ0G d:d; d;eeZ1G d<d= d=eeZ2e3e4ed>d?G d@dA dAeeZ5dBdC Z6e7dDkr(e8  dS dS )E    N)TypingError)njit)typesutilsconfig)MemoryLeakMixinTestCasetagskip_if_32bitT)_nrtnogilc                 C      t | ||fS Nnpconcatenateabc r   A/tmp/pip-target-vg8gfxp4/lib/python/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   hstackr   r   r   r   	np_hstack   r   r&   c                 C   r   r   )r   vstackr   r   r   r   	np_vstack"   r   r(   c                 C   r   r   )r   dstackr   r   r   r   	np_dstack%   r   r*   c                 C   r   r   )r   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_equalassert_allclose)selfpyfuncargslistexactcfuncargsexpectedretr   r   r   check_outputs.   s   zBaseTest.check_outputsN)T)__name__
__module____qualname__r>   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)r6   arrexpectr   r   r   assert_array_nrt_refct=   r    z#NrtRefCtTest.assert_array_nrt_refctN)r?   r@   rA   rG   r   r   r   r   rB   <   s    rB   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rE   r   r   r   fooD   s   
z'TestDynArray.test_empty_0d.<locals>.foo   rI   r   {   )r.   rG   r   r3   r4   r/   r0   shaper1   float64stridesfill)r6   rM   rE   r   r   r   test_empty_0dC   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   rK   range)nrE   ir   r   r   rM   V   s   

z'TestDynArray.test_empty_1d.<locals>.foo   rN   rO   )r.   rG   r   r3   r4   aranger/   r0   rP   r1   rQ   rR   itemsizerS   )r6   rM   rV   rE   r   r   r   test_empty_1dU   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   rK   int32rU   )mrV   rE   rW   jr   r   r   r7   k   s   z*TestDynArray.test_empty_2d.<locals>.pyfunc   rX   rN   	r.   rG   r   r3   r4   r/   r0   rP   rR   )r6   r7   r:   r^   rV   expected_arrgot_arrr   r   r   test_empty_2dj   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   r\   )r^   rV   prE   rW   r_   kr   r   r   r7      s   z*TestDynArray.test_empty_3d.<locals>.pyfuncr`   rX      rN   ra   r6   r7   r:   r^   rV   rf   rb   rc   r   r   r   test_empty_3d   s   	zTestDynArray.test_empty_3dc                 C   re   )Nc                 S   sF   t | |ft j}t| D ]}t|D ]
}|| |||f< qq|| S r   r\   )r^   rV   rf   rE   rW   r_   r   r   r   r7      s   z1TestDynArray.test_empty_2d_sliced.<locals>.pyfuncr`   rX   rh   rN   ra   ri   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 )Nr`   r1   c                      s    S r   r   r   yr   r   return_external_array      zDTestDynArray.test_return_global_array.<locals>.return_external_arrayrN   )r   onesfloat32sysgetrefcountr.   r/   r3   r4   gccollect)r6   	initrefctro   r:   outr   rm   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 )Nr`   rl   c                      s    dd  S Nrh   r   r   rm   r   r   ro         zKTestDynArray.test_return_global_array_sliced.<locals>.return_external_arrayrh   )r   rq   rr   r.   assertIsNonerC   r3   r4   )r6   ro   r:   rx   yyr   rm   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   rm   r   r   r   r7      rp   z4TestDynArray.test_array_pass_through.<locals>.pyfuncr`   rl   )r   rq   rr   r.   r3   r4   assertIs)r6   r7   rE   r:   r<   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 rz   )r0   rm   r   r   r   r7         z;TestDynArray.test_array_pass_through_sliced.<locals>.pyfuncr`   rl   rN   rh   )
r   rq   rr   rs   rt   r.   r/   r3   r4   r0   )r6   r7   rE   rw   r:   r   r<   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   rK   rP   add)r   r   rx   r   r   r   r7     s   z=TestDynArray.test_ufunc_with_allocated_output.<locals>.pyfunc
   rN   rh      F      )r.   r   randomr3   r4   rG   reshape)r6   r7   r:   arr_a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   rK   r0   rU   )inprx   rW   tmpr_   r   r   r   r7   +  s   
z/TestDynArray.test_allocation_mt.<locals>.pyfuncr   rN   c                    s    | |d d < d S r   r   )r   rx   r:   r   r   wrappedL  r    z0TestDynArray.test_allocation_mt.<locals>.wrappedd   	worker{0}targetr;   nameN)r.   r   r   randintcopyr3   r4   rU   
empty_like	threadingThreadformatappendstartjoinzip)r6   r7   r0   rE   
frozen_arrworkersinputsoutputsr   rW   rx   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 NrN   r   )rV   r   rx   rW   r   r   r   r7   k  s   z*TestDynArray.test_refct_mt.<locals>.pyfuncr   rl   i  c                    s    | ||d d < d S r   r   )rV   inputrx   r   r   r   r        z+TestDynArray.test_refct_mt.<locals>.wrappedr   r   r   N)r.   r   rY   floatrs   rt   r   	randranger3   r4   r/   rU   rK   r   r   r   r   r   r   r   )r6   r7   r0   r   expected_refctswapctr<   r   r   swapctsr   rW   rx   r   r   r   r   test_refct_mtf  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   rJ   xr   r   r   rM        z1TestDynArray.test_invalid_size_array.<locals>.foo   rh   zAllocation failed)
r   disable_leak_checkassertRaisesMemoryErrorr   size_tmaxvalassertInstr	exception)r6   rM   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
            rU   r   rn   trW   r   r   r   r7     s   z&TestDynArray.test_swap.<locals>.pyfuncr   r   rN   )
r.   r   r   rs   rt   r|   rC   r3   r4   r/   )	r6   r7   r:   r   rn   r   rw   rF   r   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   rn   rW   r   r   r   r7     s   z7TestDynArray.test_return_tuple_of_array.<locals>.pyfuncr   )	r.   r   r   rs   rt   r   r3   r4   r/   )	r6   r7   r:   r   rw   
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   rn   rW   rx   r   r   r   r7     s
   z?TestDynArray.test_return_tuple_of_array_created.<locals>.pyfuncr   rh   )r.   r   r   r3   r4   r/   rs   rt   )r6   r7   r:   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   r   r   r   )rx   r   r   r   inner  s   z7TestDynArray.test_issue_with_return_leak.<locals>.innerc                        | S r   r   r   r   r   r   r7        z8TestDynArray.test_issue_with_return_leak.<locals>.pyfuncr   N)r.   r   rY   rs   rt   r/   )r6   r7   r:   rE   	old_refctr   r   r   test_issue_with_return_leak  s   


z(TestDynArray.test_issue_with_return_leakN)r?   r@   rA   rT   r[   rd   rj   rk   ry   r~   r   r   r   r   r   r
   r   r   r   r   r   r   r   r   r   rH   A   s&    $A=
rH   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 )NrN   rO   )r.   rG   r/   r0   rP   r1   rR   check_result_valuer   r   rS   r3   r4   )r6   r7   r:   r<   r=   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 )NrX   rN   rO   negative dimensions not allowedr.   rG   r/   r0   rP   r1   rR   r   r   r   rS   r3   r4   r   
ValueErrorr   r   )r6   r7   r:   rV   r<   r=   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rh   rX   rN   rO   rh   r   r   r   )r6   r7   r:   r^   rV   r<   r=   r   r   r   r   check_2d5  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   )r6   r7   r:   er   r   r   check_alloc_sizeJ  s   z$ConstructorBaseTest.check_alloc_sizeN)r?   r@   rA   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   zerosr7   r6   	__class__r   r   r   W     zTestNdZeros.setUpc                 C      t j|| d S r   r   r3   r4   r6   r=   r<   r   r   r   r   [  r   zTestNdZeros.check_result_valuec                        | j   fdd}| | d S )Nc                      s    dS Nr   r   r   r7   r   r   func`  r   z!TestNdZeros.test_0d.<locals>.func)r7   r   r6   r   r   r   r   test_0d^     zTestNdZeros.test_0dc                    r   )Nc                    r   r   r   rV   r   r   r   r   f  r   z!TestNdZeros.test_1d.<locals>.funcr7   r   r   r   r   r   test_1dd  r   zTestNdZeros.test_1dc                    r   )Nc                        | t jS r   r   r]   r   r   r   r   r   l  r{   z'TestNdZeros.test_1d_dtype.<locals>.funcr   r   r   r   r   test_1d_dtypej  r   zTestNdZeros.test_1d_dtypec                    s,   | j td  fdd}| | d S )Nr]   c                    
   |  S r   r   r   _dtyper7   r   r   r   t     
z0TestNdZeros.test_1d_dtype_instance.<locals>.func)r7   r   r1   r   r   r   r   r   test_1d_dtype_instancep  s   
z"TestNdZeros.test_1d_dtype_instancec                    <   | j d  fdd}| | fdd}| | d S )Nr]   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_strx  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   rV   dtr   r   r   r        
z5TestNdZeros.test_1d_dtype_non_const_str.<locals>.funcr   r]   If np.0 dtype is a string it must be a string constant.)r7   r   r   r   r   r   r?   r   r6   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   NABCDEFr   r   r   r   r   r     r  z3TestNdZeros.test_1d_dtype_invalid_str.<locals>.funcr   'Invalid NumPy dtype specified: 'ABCDEF')r7   r   r   r   r   r   r   r6   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   r^   rV   r   r   r   r     r{   z!TestNdZeros.test_2d.<locals>.funcr7   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   int16r]   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>        rN   )	r7   r   r   	IS_32BITSr.   r   r   r   r  r6   r  r  r:   r   r   r   test_2d_shape_dtypes  s   

"z TestNdZeros.test_2d_shape_dtypesc                    r   )Nc                    s    | |ft jdS Nrl   )r   	complex64r  r   r   r   r     r   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&  rl   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  rl   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   )r1   r7   rP   r   r   r    s   
 z?TestNdZeros.test_alloc_size.<locals>.gen_func.<locals>.<lambda>r   rP   r1   r   )r1   rP   r   gen_func  r   z-TestNdZeros.test_alloc_size.<locals>.gen_funcrN   rh   r   @   )r7   r   intpbitwidthr   r   r6   widthr,  r   r   r   test_alloc_size  s
   "zTestNdZeros.test_alloc_size)r?   r@   rA   r   r   r   r   r   r   r   r  r  r  r  r  r$  r'  r)  r*  r2  __classcell__r   r   r   r   r   U  s$    r   c                       s.   e Zd Z fddZej fddZ  ZS )
TestNdOnesc                    r   r   )r   r4  r   r   rq   r7   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)r?   r@   rA   r   unittestexpectedFailurer  r3  r   r   r   r   r4    s    r4  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     r   zTestNdFull.check_result_valuec                 C      dd }|  | d S )Nc                   S   s   t ddS )Nr         @r   fullr   r   r   r   r     r{   z TestNdFull.test_0d.<locals>.func)r   r   r   r   r   r        zTestNdFull.test_0dc                 C   r8  )Nc                 S      t | dS Nr9  r:  r   r   r   r   r     r{   z TestNdFull.test_1d.<locals>.funcr   r   r   r   r   r     r<  zTestNdFull.test_1dc                 C   r8  )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   rl   r   r   r        z/TestNdFull.test_1d_dtype_instance.<locals>.func)r   r1   r   r   r   rl   r   r        
z!TestNdFull.test_1d_dtype_instancec                 C   r8  )Nc                 S      t | ddS Nr9  rA  r:  r   r   r   r   r     rE  z*TestNdFull.test_1d_dtype_str.<locals>.funcr?  r   r   r   r   r     r<  zTestNdFull.test_1d_dtype_strc                 C   r8  )Nc                 S   rG  )Nr9  ?r:  r   r   r   r   r     rE  z?TestNdFull.test_1d_dtype_str_alternative_spelling.<locals>.funcr?  r   r   r   r   r    s   z1TestNdFull.test_1d_dtype_str_alternative_spellingc                 C   sv   t dd }| t}|ddd W d    n1 sw   Y  t|j}| d| d}t|}| || d S )Nc                 S      t | ||S r   r:  )rV   fvr  r   r   r   r     r   z4TestNdFull.test_1d_dtype_non_const_str.<locals>.func)r   r9  r]   No matchz9\bfull\(UniTuple\(int.*? x 1\), float64, unicode_type\)\B	r   r   r   r   r   r   recompileassertRegexr6   r   r   r  restrregexr   r   r   r    s   


z&TestNdFull.test_1d_dtype_non_const_strc                 C   `   t dd }| t}|tdd W d    n1 sw   Y  t|j}| d| d S )Nc                 S      t | |dS r  r:  )rV   rK  r   r   r   r   '  r   z2TestNdFull.test_1d_dtype_invalid_str.<locals>.funcr`   r9  r  r   r   r   r   rq   r   r   r   r  r   r   r   r  %     

z$TestNdFull.test_1d_dtype_invalid_strc                 C   r8  )Nc                 S      t | |fdS r>  r:  r  r   r   r   r   2  r   z TestNdFull.test_2d.<locals>.funcr   r   r   r   r   r  1  r<  zTestNdFull.test_2dc                 C   r8  )Nc                 S      t j| |fdt jdS )Ny      ?      @rl   )r   r;  r&  r  r   r   r   r   7  r   z,TestNdFull.test_2d_dtype_kwarg.<locals>.funcrY  r   r   r   r   r'  6  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;  r]   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   B  r   c                 S   rZ  )NrN   rl   )r   r;  r  r  r   r   r   r   G  r   rY  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  r]   r  r   r   r   r  M     z.TestNdFull.test_2d_shape_dtypes.<locals>.func1c                 S   r]  r>  )r   r;  r  r  r  r   r   r   r  Q  r^  z.TestNdFull.test_2d_shape_dtypes.<locals>.func2c                 S   rX  r>  r:  r  r   r   r   r  V  s    z1TestNdFull.test_2d_shape_dtypes.<locals>.<lambda>r!  rN   )r   r   r"  r.   r   r   r   r  r#  r   r   r   r$  K  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   rP   valuer   r   r  ]  r   z>TestNdFull.test_alloc_size.<locals>.gen_func.<locals>.<lambda>r   r_  r   r_  r   r,  \  rE  z,TestNdFull.test_alloc_size.<locals>.gen_funcrN   rh   r   r-  )r   r.  r/  r   r0  r   r   r   r2  Z  s    zTestNdFull.test_alloc_sizeN)r?   r@   rA   r   r   r   r   r   r   r  r  r  r  r'  r\  r$  r2  r   r   r   r   r7    s    r7  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 )NrI      x)rS   	TypeErrorr   r1   rZ   )r6   rE   
fill_valuer   r   r   mutate_arraye  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/   r0   r1   r2   r   re  r   r3   r4   )rE   r<   r=   r:   r7   r6   r   r   	check_arrn  s   

z5ConstructorLikeBaseTest.check_like.<locals>.check_arrr   r      )rh  r   rN   rh   rX   )rX   rN   rh   r   r   r   rh   F	WRITEABLErN   )	r   linspaceastyper.   r   ndimflagsr   r   )r6   r7   r1   rg  origrP   rE   r   rf  r   
check_likem  s    




z"ConstructorLikeBaseTest.check_likeN)r?   r@   rA   re  rp  r   r   r   r   ra  c  s    ra  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   rq  r   r   r   r7   r   r   r   r   r     r   zTestNdEmptyLike.setUpc                 C   s   d S r   r   r   r   r   r   r     rp   z"TestNdEmptyLike.check_result_valuec                    $   | j   fdd}| |tj d S )Nc                    r   r   r   rL   r   r   r   r     r   z'TestNdEmptyLike.test_like.<locals>.funcr7   rp  r   rQ   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   rL   r   r   r   r     r   z2TestNdEmptyLike.test_like_structured.<locals>.func)r   r1   r  rr   r7   rp  r6   r1   r   r   r   r   test_like_structured  s   z$TestNdEmptyLike.test_like_structuredc                    rr  )Nc                    r   r   r   rL   r   r   r   r     r{   z-TestNdEmptyLike.test_like_dtype.<locals>.funcrs  r   r   r   r   test_like_dtype  ru  zTestNdEmptyLike.test_like_dtypec                    s0   t d | j fdd}| |t j d S )Nr]   c                    r   r   r   rL   r1   r7   r   r   r     r   z6TestNdEmptyLike.test_like_dtype_instance.<locals>.func)r   r1   r7   rp  rQ   r   r   ry  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   rL   ry  r   r   r     r   z8TestNdEmptyLike.test_like_dtype_structured.<locals>.func)r   r1   r  rr   r7   rp  rQ   r   r   ry  r   test_like_dtype_structured  s   z*TestNdEmptyLike.test_like_dtype_structuredc                    rr  )Nc                    s    | t jdS r%  r   rL   r   r   r   r     rE  z3TestNdEmptyLike.test_like_dtype_kwarg.<locals>.funcrs  r   r   r   r   test_like_dtype_kwarg  ru  z%TestNdEmptyLike.test_like_dtype_kwargc                    rr  )Nc                        | ddS )Nr]   rl   r   rL   r   r   r   r     r{   z7TestNdEmptyLike.test_like_dtype_str_kwarg.<locals>.funcrs  r   r   r   r   test_like_dtype_str_kwarg  ru  z)TestNdEmptyLike.test_like_dtype_str_kwargc                    rr  )Nc                    r}  )Nr  rl   r   rL   r   r   r   r     r{   zLTestNdEmptyLike.test_like_dtype_str_kwarg_alternative_spelling.<locals>.funcrs  r   r   r   r   .test_like_dtype_str_kwarg_alternative_spelling  ru  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>.funcr`   r]   r	  r
  z'{}(array(float64, 1d, C), unicode_type))r7   r   r   r   r   rq   r   r   r?   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>.funcr`   r  )	r7   r   r   r   r   rq   r   r   r   r  r   r   r   test_like_dtype_invalid_str  s   
z+TestNdEmptyLike.test_like_dtype_invalid_str)r?   r@   rA   r   r   rt  rw  rx  rz  r{  r|  r~  r  r  r  r3  r   r   r   r   rq    s    rq  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   r  r   r   
zeros_liker7   r   r   r   r   r     r   zTestNdZerosLike.setUpc                 C   r   r   r   r   r   r   r   r     r   z"TestNdZerosLike.check_result_valuec                       t t|   d S r   )r   r  rw  r   r   r   r   rw    r   z$TestNdZerosLike.test_like_structuredc                    r  r   )r   r  r{  r   r   r   r   r{    r   z*TestNdZerosLike.test_like_dtype_structured)r?   r@   rA   r   r   rw  r{  r3  r   r   r   r   r    s
    r  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   r  r   r   	ones_liker7   expected_valuer   r   r   r   r     s   
zTestNdOnesLike.setUpc                    r  r   )r   r  rw  r   r   r   r   rw       z#TestNdOnesLike.test_like_structuredc                    r  r   )r   r  r{  r   r   r   r   r{  
  r  z)TestNdOnesLike.test_like_dtype_structured)	r?   r@   rA   r   r5  r6  rw  r{  r3  r   r   r   r   r    s    r  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     r   z!TestNdFullLike.check_result_valuec                 C      dd }|  |tj d S )Nc                 S   r=  )N      @r   	full_likerL   r   r   r   r     r{   z&TestNdFullLike.test_like.<locals>.funcrp  r   rQ   r   r   r   r   rt       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>  r  rL   r   r   r   r     r{   z1TestNdFullLike.test_like_structured.<locals>.func)r   r1   r  rr   rp  rv  r   r   r   rw    s   z#TestNdFullLike.test_like_structuredc                 C   r  )Nc                 S   r@  r>  r   r  rA  rL   r   r   r   r   "  r   z,TestNdFullLike.test_like_dtype.<locals>.funcr  r   r   r   r   rx  !  r  zTestNdFullLike.test_like_dtypec                    s(   t d  fdd}| |t j d S )NrC  c                    rD  r>  r  rL   rl   r   r   r   (  rE  z5TestNdFullLike.test_like_dtype_instance.<locals>.func)r   r1   rp  rQ   r   r   rl   r   rz  &  s   
z'TestNdFullLike.test_like_dtype_instancec                 C   r  )Nc                 S   s   t j| dt jdS )Nr9  rl   r  rL   r   r   r   r   -  r   z2TestNdFullLike.test_like_dtype_kwarg.<locals>.funcr  r   r   r   r   r|  ,  r  z$TestNdFullLike.test_like_dtype_kwargc                 C   r  )Nc                 S   rG  rH  r  rL   r   r   r   r   2  rE  z6TestNdFullLike.test_like_dtype_str_kwarg.<locals>.funcr  r   r   r   r   r~  1  r  z(TestNdFullLike.test_like_dtype_str_kwargc                 C   r  )Nc                 S   s   t j| dddS )Nr9  rI  rl   r  rL   r   r   r   r   7  r   zKTestNdFullLike.test_like_dtype_str_kwarg_alternative_spelling.<locals>.funcr  r   r   r   r   r  6  r  z=TestNdFullLike.test_like_dtype_str_kwarg_alternative_spellingc                 C   sn   t dd }| t}|tddd W d    n1 sw   Y  t|j}| d| | d| d S )Nc                 S   rJ  r   r  )rE   rK  r  r   r   r   r   =  r   z@TestNdFullLike.test_like_dtype_non_const_str_kwarg.<locals>.funcrX   r9  r]   rL  z7full_like(array(float64, 1d, C), float64, unicode_type)rV  r  r   r   r   #test_like_dtype_non_const_str_kwarg;  s   

z2TestNdFullLike.test_like_dtype_non_const_str_kwargc                 C   rT  )Nc                 S   rU  r  r  )rE   rK  r   r   r   r   K  r   z8TestNdFullLike.test_like_dtype_invalid_str.<locals>.funcr`   g333333@r  rV  r  r   r   r   r  I  rW  z*TestNdFullLike.test_like_dtype_invalid_strN)r?   r@   rA   r   rt  r5  r6  rw  rx  rz  r|  r~  r  r  r  r   r   r   r   r    s    
r  c                   @   r   )
TestNdIdentityc                 C   s   |  |dg d S )NrX   r>   r6   r7   r   r   r   check_identityX  r   zTestNdIdentity.check_identityc                 C   r8  )Nc                 S   
   t | S r   r   identityr   r   r   r   r   \  r   z*TestNdIdentity.test_identity.<locals>.func)r  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 )NrC  rA  c                    s   t |  S r   r  r   rl   r   r   r   c  r{   z0TestNdIdentity.test_identity_dtype.<locals>.func)r   r&  r  rA  r1   r  r   r   rl   r   test_identity_dtype`  s   z"TestNdIdentity.test_identity_dtypec                 C   sp   t dd }| t}|dd W d    n1 sw   Y  t|j}| d| td}| || d S )Nc                 S      t | |S r   r  r  r   r   r   r   i  s   z@TestNdIdentity.test_like_dtype_non_const_str_kwarg.<locals>.funcr`   r]   rL  z$\bidentity\(int.*?, unicode_type\)\BrM  )r6   r   r   r  rS  r   r   r   r  g  s   


z2TestNdIdentity.test_like_dtype_non_const_str_kwargN)r?   r@   rA   r  r  r  r  r   r   r   r   r  V  s
    r  c                   @   D   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   r  r   r   eyer   r   r   r   r   y  r   z"TestNdEye.test_eye_n.<locals>.funcrN   r  r  r   r   r   r   
test_eye_nx     zTestNdEye.test_eye_nc                 C   s8   d t jt dfD ]}|fdd}| |ddg q	d S )NrN   c                 S      t j| |dS r%  r  )rV   r1   r   r   r   r     rE  z(TestNdEye.test_eye_n_dtype.<locals>.funcr  r  )r   r   r&  r>   )r6   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  rV   r^   r   r   r   r     r{   z$TestNdEye.test_eye_n_m.<locals>.func)rN   rh   rX   rh   )r   rX   r  r   r   r   r   test_eye_n_m  r  zTestNdEye.test_eye_n_mc                 C   s   |  |g d d S )N))rN   rh   r   )rX   r`   rN   )rX   r`   r   )r`   rX   )r`   rX   )r`   rX   r   r  r   r   r   r   check_eye_n_m_k  r    zTestNdEye.check_eye_n_m_kc                 C   r8  )Nc                 S   rJ  r   r  rV   r^   rg   r   r   r   r     rE  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   r8  )Nc                 S   s   t j| ||t jdS N)NMrg   r1   )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                    rB  )Nr  c                    s   t j| || dS r  r  r  rl   r   r   r     r   z5TestNdEye.test_eye_n_m_k_dtype_instance.<locals>.func)r   r1   r  r   r   rl   r   test_eye_n_m_k_dtype_instance  rF  z'TestNdEye.test_eye_n_m_k_dtype_instanceN)
r?   r@   rA   r  r  r  r  r  r  r  r   r   r   r   r  v  s    r  c                   @   r  )
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 )Nri     rX   r`   c                 S   r  r   r   diag)qr   r   r   r     r   zTestNdDiag.setUp.<locals>.funcr   c                 S   r  )Nrg   r  )r  rg   r   r   r   
func_kwarg  rE  z$TestNdDiag.setUp.<locals>.func_kwarg)r   )r   array	transposevectorsrY   r   	matriciespyr.   jitpy_kwjit_kw)r6   vhvvva3x4a4x3r   r  r   r   r   r     s   



zTestNdDiag.setUpc                 O   sN   ||i |}||i |}|  |j|j |  |j|j tj|| d S r   )r/   r0   r1   r   r3   r4   )r6   r7   nrtfuncr;   kwargsr<   computedr   r   r   
check_diag  s
   zTestNdDiag.check_diagc                 C   "   | j D ]}| | j| j| qd S r   )r  r  r  r  r6   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  )rU   r  r  r  r  r6   rg   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  )Nr`   r  )rU   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      ?rX   r  )r   r  r.   r  r   rc  r   r  )r6   r  r:   dfuncr   r   r   test_error_handling  s   


"zTestNdDiag.test_error_handlingN)
r?   r@   rA   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   rk  r  r   r   r   r7     r{   z,TestLinspace.test_linspace_2.<locals>.pyfunc))r   r`   )rN   r   )            @)                    @      @)rh   rN   )      ?      ?              ?r  r  r   r   r   test_linspace_2     zTestLinspace.test_linspace_2c                 C   r  )Nc                 S   rJ  r   r  rV   r^   rf   r   r   r   r7     rE  z,TestLinspace.test_linspace_3.<locals>.pyfunc))r   r`   	   )rN   r`   rX   )r  r  r   )r  r  r   )rh   rN   r   )r  r  r   )rN   g}Ô%ITrN   r  r  r   r   r   test_linspace_3  r  zTestLinspace.test_linspace_3c                 C   s8   t dd }d\}}}| |||||||| d S )Nc                 S   rJ  r   r  r  r   r   r   rM     r   z0TestLinspace.test_linspace_accuracy.<locals>.foo)g        r  r   )r.   assertPreciseEqualpy_func)r6   rM   rV   r^   rf   r   r   r   test_linspace_accuracy  s   

"z#TestLinspace.test_linspace_accuracyN)r?   r@   rA   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%  rJ   rP   rl   r   r   r7     rE  z7TestNpyEmptyKeyword._test_with_dtype_kw.<locals>.pyfuncrN   r   r  r.   r/   r1   rP   r6   r1   r7   shapesr:   sr<   r   r   rl   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   r]   rr   r&  r1   r  r6   r1   r   r   r   test_with_dtype_kws     z'TestNpyEmptyKeyword.test_with_dtype_kwsc                    r  )Nc                    r  )Nr+  rJ   r  rl   r   r   r7     rE  zATestNpyEmptyKeyword._test_with_shape_and_dtype_kw.<locals>.pyfuncr  r  r  r   rl   r   _test_with_shape_and_dtype_kw  r  z1TestNpyEmptyKeyword._test_with_shape_and_dtype_kwc                 C   r  r  )r   r]   rr   r&  r1   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   rJ   r   r   r   r   r7   %  r   z6TestNpyEmptyKeyword.test_empty_no_args.<locals>.pyfunc)r.   r   r   )r6   r7   r:   r   r   r   test_empty_no_args#  s
   "z&TestNpyEmptyKeyword.test_empty_no_argsN)r?   r@   rA   r  r  r  r  r   r   r   r   r   r     s    r  c                   @   sT   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S )TestNpArrayc                 C   sN   dd }t |}|d}| |tjdtjd |d}| |td d S )Nc                 S   r  r   r   r  argr   r   r   r7   3  r   z#TestNpArray.test_0d.<locals>.pyfuncrI   rl   r  )r.   r  r   r  r.  r6   r7   r:   r   r   r   r   r   2  s   zTestNpArray.test_0dc                 C   r  )Nc                 S      t j| t jdS r%  )r   r  r  r  r   r   r   r7   =  r   z.TestNpArray.test_0d_with_dtype.<locals>.pyfunc)rI   )r  r  r  r   r   r   test_0d_with_dtype<  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   r  r   r  r  r   r   r   r7   C  r   z#TestNpArray.test_1d.<locals>.pyfunc)rh   rX   rI   )r  y              @rI   r   )r.   r  r   r.  r  rQ   r  r   r   r   r   B  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  rr   r  r   r   r   r7   R  r   z.TestNpArray.test_1d_with_dtype.<locals>.pyfuncrh   rI   r  r  )rN   r  rI   r   r  r  r   r   r   test_1d_with_dtypeQ     zTestNpArray.test_1d_with_dtypec                 C   r  )	Nc                 S   s   t j| ddS )Nrr   rl   r  r  r   r   r   r7   ]  rE  z2TestNpArray.test_1d_with_str_dtype.<locals>.pyfuncrh   rI   r  r  r	  r
  r  r  r   r   r   test_1d_with_str_dtype\  r  z"TestNpArray.test_1d_with_str_dtypec                 C   st   t dd }| t}|dd W d    n1 sw   Y  t|j}| d| d}t|}| || d S )Nc                 S   r  r%  r  )r  r  r   r   r   r   i  r   z:TestNpArray.test_1d_with_non_const_str_dtype.<locals>.func)r   rX   r]   rL  z7\barray\(UniTuple\(int.*? x 2\), dtype=unicode_type\)\BrM  rQ  r   r   r    test_1d_with_non_const_str_dtypeg  s   


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   r  r   r  r  r   r   r   r7   w  r   z#TestNpArray.test_2d.<locals>.pyfuncr  rX   r`   rN   rh   rX   r`   rN   r  rX   r9  r  r9  r  ))      ?rh   )r  r9  r  )r   r   )r.   r  r   r.  rQ   r  r   r   r   r  v  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  r]   r  r   r   r   r7     r   z.TestNpArray.test_2d_with_dtype.<locals>.pyfuncr  r  rN   rh   rX   r`   )r.   r  r   r]   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   r  r   r  r  r   r   r   r7     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 shaperN   rh   zrcannot convert Tuple(int64, Record(a[type=int32;offset=0],b[type=float32;offset=4];8;False)) to a homogeneous type)r   r  )r   f4rl   r   r  )r.   
contextlibcontextmanagerr   r  r  r1   r   )r6   r7   r:   r  stvalr   r   r   test_raises  s"   

"zTestNpArray.test_raisesN)r?   r@   rA   r   r  r   r  r  r  r  r  r  r   r   r   r   r  0  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   )r`   rX   rh   r   F)orderr   .r   rY   r   r   r6   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   )r6   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   axr<   r   rf  r   r   check  s
   z(TestNpConcatenate.test_3d.<locals>.checkc                    s    t dD ]	} | ||| qd S )NrX   r   r   )r*  r   r   check_all_axes  s   z1TestNpConcatenate.test_3d.<locals>.check_all_axesrN   r   r   r   rh   )rN   rh   r  r   )r   rh   r'  r   )	r   r.   r#  Trl  r   rQ   r   r&  )r6   r+  r   r   r   r  r   r   r   )r:   r*  r7   r6   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   r<   r   rf  r   r   r*    s   z0TestNpConcatenate.test_3d_no_axis.<locals>.checkrN   r   )r   r.   r#  r,  r   r&  )r6   r*  r   r   r   r  r   r   rf  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 S )N   )rX   r   r   rI   z8all the input arrays must have same number of dimensionsz(input arrays must have compatible dtypesz.zero-dimensional arrays cannot be concatenated)r   r.   r   rY   r   rl  r1   r  r  assertTypingErrorr   r   r   )r6   r7   r:   r   r   r   r  r   r   r   r   test_typing_errors  s0   





z$TestNpConcatenate.test_typing_errorsN)r?   r@   rA   __doc__r#  r  r  r&  r-  r.  r1  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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%  )r6   r   r   r   r   assert_invalid_sizesE  s   z TestNpStack.assert_invalid_sizesc                 C   s8   || }|| }|  |j|j | | |  d S r   )r/   rP   r  flatten)r6   r7   r:   r;   r<   r   r   r   r   check_stackL  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   )r6  r   r   r   r;   rf  r   r   r*  W  r^  z#TestNpStack.check_3d.<locals>.checkc                    s    D ]	} | ||| qd S r   r   r7  )r*  generate_starargsr   r   r+  Z  s   
z,TestNpStack.check_3d.<locals>.check_all_axes)r#  r,  rl  r   rQ   )
r6   r7   r:   r8  r+  r   r   r   r  r   r   )r:   r*  r8  r7   r6   r   check_3dV  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#  r4  next)	r6   r:   r8  r   r   r   r  r   r;   r   r   r   check_runtime_errorsp  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 )NrX   r'  r   r   r   r   r   r8    s
   z.TestNpStack.test_3d.<locals>.generate_starargsN)r$   r.   r9  r<  r6   r7   r:   r8  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   r8       
z6TestNpStack.test_3d_no_axis.<locals>.generate_starargsN)r#   r.   r9  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)
        rI                TN)r#   r.   r   r  r6  r6   r7   r:   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   r8    r@  z4TestNpStack.check_xxstack.<locals>.generate_starargsrI   rA  TN)r9  r   r  r6  )r6   r7   r:   r8  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   rh  r   r   r   )rh   r`   r   )r&   r.   rC  r   rY   r6  r   r6   r7   r:   r   r   r   r   r   test_hstack  s   
zTestNpStack.test_hstackc                 C   sz   t }t|}| || td}|d }| |||||f tdd}tddd }| |||||f d S )Nr   r   rh  r  r   )r`   rh   r   )r(   r.   rC  r   rY   r6  r   rD  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.   rC  r   rY   r6  r   rD  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 )Nr`   r   r  )r`   rX   rI   )rN   rN   rN   )
r,   r.   r   rY   r   r6  r:  r   r  r0  rB  r   r   r   test_column_stack  s    




"zTestNpStack.test_column_stackN)r?   r@   rA   r2  r#  r  r  r4  r6  r9  r<  r-  r.  r   rC  rE  rF  rG  rH  r   r   r   r   r3  7  s     

r3  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   r7     s   z%benchmark_refct_speed.<locals>.pyfuncr   i'  c                           d S r   r   r   )r7   r   r   rn   r   r   bench_pyfunc   r   z+benchmark_refct_speed.<locals>.bench_pyfuncc                      rI  r   r   r   )r:   r   r   rn   r   r   bench_cfunc  r   z*benchmark_refct_speed.<locals>.bench_cfunc)r.   r   r   r   	benchmarkprint)rJ  rK  python_time
numba_timer   )r:   r7   r   r   rn   r   benchmark_refct_speed  s   

rP  __main__)9r  rs   numpyr   r   rN  r   ru   numba.core.errorsr   numbar   
numba.corer   r   r   numba.tests.supportr   r   r	   r
   r5  r.   r   r   r#   r$   r&   r(   r*   r,   r-   rB   rH   r   r   r4  r7  objectra  rq  r  r  r  r  r  r  r  r  r  r  
skipUnlesshasattrr3  rP  r?   mainr   r   r   r   <module>   sj       PG r.\G ,B0   ;
