o
    i                     @   sh  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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/d0 d0e,Z-G d1d2 d2e*eZ.G d3d4 d4e"Z/G d5d6 d6e"Z0G d7d8 d8eZ1G d9d: d:e"Z2G d;d< d<eZ3G d=d> d>ee"Z4G d?d@ d@eeZ5e6e7edAdBG dCdD dDeeZ8dEdF Z9e:dGkr2e;  dS dS )H    N)TypingError)njit)typesutilsconfig)MemoryLeakMixinTestCasetagskip_if_32bit)	PYVERSIONT)_nrtnogilc                 C      t | ||fS Nnpconcatenateabc r   X/home/ubuntu/transcripts/venv/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   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   	row_stackr   r   r   r   np_row_stack&   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_outputs2   s   zBaseTest.check_outputsN)T)__name__
__module____qualname__rA   r   r   r   r   r0   0   s    r0   c                   @   s   e Zd Zdd ZdS )NrtRefCtTestc                 C   s   |  |jj| d S r   )r2   baserefcount)r9   arrexpectr   r   r   assert_array_nrt_refctA   r!   z#NrtRefCtTest.assert_array_nrt_refctN)rB   rC   rD   rJ   r   r   r   r   rE   @   s    rE   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rH   r   r   r   fooH   s   
z'TestDynArray.test_empty_0d.<locals>.foo   rL   r   {   )r1   rJ   r   r6   r7   r2   r3   shaper4   float64stridesfill)r9   rP   rH   r   r   r   test_empty_0dG   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   rN   range)nrH   ir   r   r   rP   Z   s   

z'TestDynArray.test_empty_1d.<locals>.foo   rQ   rR   )r1   rJ   r   r6   r7   aranger2   r3   rS   r4   rT   rU   itemsizerV   )r9   rP   rY   rH   r   r   r   test_empty_1dY   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   rN   int32rX   )mrY   rH   rZ   jr   r   r   r:   o   s   z*TestDynArray.test_empty_2d.<locals>.pyfunc   r[   rQ   	r1   rJ   r   r6   r7   r2   r3   rS   rU   )r9   r:   r=   ra   rY   expected_arrgot_arrr   r   r   test_empty_2dn   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_   )ra   rY   prH   rZ   rb   kr   r   r   r:      s   z*TestDynArray.test_empty_3d.<locals>.pyfuncrc   r[      rQ   rd   r9   r:   r=   ra   rY   ri   re   rf   r   r   r   test_empty_3d   s   	zTestDynArray.test_empty_3dc                 C   rh   )Nc                 S   sF   t | |ft j}t| D ]}t|D ]
}|| |||f< qq|| S r   r_   )ra   rY   ri   rH   rZ   rb   r   r   r   r:      s   z1TestDynArray.test_empty_2d_sliced.<locals>.pyfuncrc   r[   rk   rQ   rd   rl   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 )Nrc   r4   c                      s    S r   r   r   yr   r   return_external_array      zDTestDynArray.test_return_global_array.<locals>.return_external_arrayrQ   )r   onesfloat32sysgetrefcountr1   r2   r6   r7   gccollect)r9   	initrefctrr   r=   outr   rp   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 )Nrc   ro   c                      s    dd  S Nrk   r   r   rp   r   r   rr         zKTestDynArray.test_return_global_array_sliced.<locals>.return_external_arrayrk   )r   rt   ru   r1   assertIsNonerF   r6   r7   )r9   rr   r=   r{   yyr   rp   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   rp   r   r   r   r:      rs   z4TestDynArray.test_array_pass_through.<locals>.pyfuncrc   ro   )r   rt   ru   r1   r6   r7   assertIs)r9   r:   rH   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 r}   )r3   rp   r   r   r   r:         z;TestDynArray.test_array_pass_through_sliced.<locals>.pyfuncrc   ro   rQ   rk   )
r   rt   ru   rv   rw   r1   r2   r6   r7   r3   )r9   r:   rH   rz   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   rN   rS   add)r   r   r{   r   r   r   r:     s   z=TestDynArray.test_ufunc_with_allocated_output.<locals>.pyfunc
   rQ   rk      F      )r1   r   randomr6   r7   rJ   reshape)r9   r:   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   rN   r3   rX   )inpr{   rZ   tmprb   r   r   r   r:   /  s   
z/TestDynArray.test_allocation_mt.<locals>.pyfuncr   rQ   c                    s    | |d d < d S r   r   )r   r{   r=   r   r   wrappedP  r!   z0TestDynArray.test_allocation_mt.<locals>.wrappedd   	worker{0}targetr>   nameN)r1   r   r   randintcopyr6   r7   rX   
empty_like	threadingThreadformatappendstartjoinzip)r9   r:   r3   rH   
frozen_arrworkersinputsoutputsr   rZ   r{   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 NrQ   r   )rY   r   r{   rZ   r   r   r   r:   o  s   z*TestDynArray.test_refct_mt.<locals>.pyfuncr   ro   i  c                    s    | ||d d < d S r   r   )rY   inputr{   r   r   r   r        z+TestDynArray.test_refct_mt.<locals>.wrappedr   r   r   N)r1   r   r\   floatrv   rw   r   	randranger6   r7   r2   rX   rN   r   r   r   r   r   r   r   )r9   r:   r3   r   expected_refctswapctr?   r   r   swapctsr   rZ   r{   r   r   r   r   test_refct_mtj  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   rM   xr   r   r   rP        z1TestDynArray.test_invalid_size_array.<locals>.foo   rk   zAllocation failed)
r   disable_leak_checkassertRaisesMemoryErrorr   size_tmaxvalassertInstr	exception)r9   rP   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
            rX   r   rq   trZ   r   r   r   r:     s   z&TestDynArray.test_swap.<locals>.pyfuncr   r   rQ   )
r1   r   r   rv   rw   r   rF   r6   r7   r2   )	r9   r:   r=   r   rq   r   rz   rI   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   rq   rZ   r   r   r   r:     s   z7TestDynArray.test_return_tuple_of_array.<locals>.pyfuncr   )	r1   r   r   rv   rw   r   r6   r7   r2   )	r9   r:   r=   r   rz   
expected_x
expected_ygot_xgot_yr   r   r   test_return_tuple_of_array  s   
z'TestDynArray.test_return_tuple_of_arrayc           	      C   s   dd }t |}tjd}||\}}||\}}tj|| tj|| tdv r/d}ntdv r6d}ntt| |t	| | |t	| d S )Nc                 S   s8   t | j}t|jD ]
}| | d ||< q||f}|S r   r   )r   rq   rZ   r{   r   r   r   r:     s
   z?TestDynArray.test_return_tuple_of_array_created.<locals>.pyfuncr   )r[      rQ   )r[   r   )r[      )r[      )r[      rk   )
r1   r   r   r6   r7   r   NotImplementedErrorr2   rv   rw   )	r9   r:   r=   r   r   r   r   r   expected_refcountr   r   r   "test_return_tuple_of_array_created  s   z/TestDynArray.test_return_tuple_of_array_createdc                    s   t dd   fdd}t |}td}t|}tdv r5| dt|| | dt|| ntdv rP| |t|| | |t|| ntt| |t| d	S )
z_
        Dispatcher returns a new reference.
        It need to workaround it for now.
        c                 S   r   r   r   )r{   r   r   r   inner  s   z7TestDynArray.test_issue_with_return_leak.<locals>.innerc                        | S r   r   r   r   r   r   r:        z8TestDynArray.test_issue_with_return_leak.<locals>.pyfuncr   r   rk   r   N)r1   r   r\   rv   rw   r   r2   r   )r9   r:   r=   rH   	old_refctr   r   r   test_issue_with_return_leak  s   


z(TestDynArray.test_issue_with_return_leakN)rB   rC   rD   rW   r^   rg   rm   rn   r|   r   r   r   r   r   r   r
   r   r   r   r   r   r   r   r   r   rK   E   s&    $A=
rK   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 )NrQ   rR   )r1   rJ   r2   r3   rS   r4   rU   check_result_valuer   r   rV   r6   r7   )r9   r:   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 )Nr[   rQ   rR   negative dimensions not allowedr1   rJ   r2   r3   rS   r4   rU   r   r   r   rV   r6   r7   r   
ValueErrorr   r   )r9   r:   r=   rY   r?   r@   cmr   r   r   check_1d1  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rk   r[   rQ   rR   rk   r   r   r   )r9   r:   r=   ra   rY   r?   r@   r   r   r   r   check_2dF  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)r1   r   r   r   r   r   )r9   r:   r=   er   r   r   check_alloc_size[  s   z$ConstructorBaseTest.check_alloc_sizeN)rB   rC   rD   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   zerosr:   r9   	__class__r   r   r   h     zTestNdZeros.setUpc                 C      t j|| d S r   r   r6   r7   r9   r@   r?   r   r   r   r   l  r   zTestNdZeros.check_result_valuec                        | j   fdd}| | d S )Nc                      s    dS Nr   r   r   r:   r   r   funcq  r   z!TestNdZeros.test_0d.<locals>.func)r:   r   r9   r   r   r   r   test_0do     zTestNdZeros.test_0dc                    r   )Nc                    r   r   r   rY   r   r   r   r   w  r   z!TestNdZeros.test_1d.<locals>.funcr:   r   r   r   r   r   test_1du  r   zTestNdZeros.test_1dc                    r   )Nc                        | t jS r   r   r`   r   r   r   r   r   }  r~   z'TestNdZeros.test_1d_dtype.<locals>.funcr   r   r   r   r   test_1d_dtype{  r   zTestNdZeros.test_1d_dtypec                    s,   | j td  fdd}| | d S )Nr`   c                    
   |  S r   r   r   _dtyper:   r   r   r        
z0TestNdZeros.test_1d_dtype_instance.<locals>.func)r:   r   r4   r   r   r   r  r   test_1d_dtype_instance  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_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   rY   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.)r:   r   r   r   r   r   rB   r   r9   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')r:   r   r   r   r   r   r   r9   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   ra   rY   r   r   r   r     r~   z!TestNdZeros.test_2d.<locals>.funcr:   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>        rQ   )	r:   r   r   	IS_32BITSr1   r   r   r   r'  r9   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 Nro   )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 )Nr1  ro   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                    r3  )Nr  ro   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   )r4   r:   rS   r   r   r*    s   
 z?TestNdZeros.test_alloc_size.<locals>.gen_func.<locals>.<lambda>r   rS   r4   r   )r4   rS   r   gen_func  r   z-TestNdZeros.test_alloc_size.<locals>.gen_funcrQ   rk   r   @   )r:   r   intpbitwidthr   r   r9   widthr7  r   r   r   test_alloc_size  s
   "zTestNdZeros.test_alloc_size)rB   rC   rD   r   r   r   r   r  r  r  r  r  r  r  r"  r/  r2  r4  r5  r=  __classcell__r   r   r   r   r   f  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   rt   r:   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)rB   rC   rD   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     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   rC  )Nc                 S      t | dS NrD  rE  r   r   r   r   r     r~   z TestNdFull.test_1d.<locals>.funcr   r   r   r   r   r     rG  zTestNdFull.test_1dc                 C   rC  )Nc                 S      t | dt jS rI  )r   rF  bool_r   r   r   r   r     r   z&TestNdFull.test_1d_dtype.<locals>.funcrJ  r   r   r   r   r    rG  zTestNdFull.test_1d_dtypec                    $   t d  fdd}| | d S )Nboolc                       t | d S rI  rE  r   ro   r   r   r        z/TestNdFull.test_1d_dtype_instance.<locals>.func)r   r4   r   r   r   ro   r   r       
z!TestNdFull.test_1d_dtype_instancec                 C   rC  )Nc                 S      t | ddS NrD  rL  rE  r   r   r   r   r     rP  z*TestNdFull.test_1d_dtype_str.<locals>.funcrJ  r   r   r   r   r    rG  zTestNdFull.test_1d_dtype_strc                 C   rC  )Nc                 S   rR  )NrD  ?rE  r   r   r   r   r   #  rP  z?TestNdFull.test_1d_dtype_str_alternative_spelling.<locals>.funcrJ  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   rE  )rY   fvr  r   r   r   r   )  r   z4TestNdFull.test_1d_dtype_non_const_str.<locals>.funcr   rD  r`   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  rE  )rY   rV  r   r   r   r   7  r   z2TestNdFull.test_1d_dtype_invalid_str.<locals>.funcrW  rD  r  rX  r  r   r   r   r  5  s   

z$TestNdFull.test_1d_dtype_invalid_strc                 C   rC  )Nc                 S      t | |fdS rI  rE  r   r   r   r   r   B  r   z TestNdFull.test_2d.<locals>.funcr   r   r   r   r   r"  A  rG  zTestNdFull.test_2dc                 C   rC  )Nc                 S      t j| |fdt jdS )Ny      ?      @ro   )r   rF  r1  r   r   r   r   r   G  r   z,TestNdFull.test_2d_dtype_kwarg.<locals>.funcr[  r   r   r   r   r2  F  rG  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   rF  r`   r   r   r   r   r   M  r   z0TestNdFull.test_2d_dtype_from_type.<locals>.funcc                 S   r]  r   )r   rF  r
  r   r   r   r   r   R  r   c                 S   r\  )NrQ   ro   )r   rF  r(  r   r   r   r   r   W  r   r[  r   r   r   r   test_2d_dtype_from_typeK  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 rI  )r   rF  r$  r`   r   r   r   r   r%  ]     z.TestNdFull.test_2d_shape_dtypes.<locals>.func1c                 S   r_  rI  )r   rF  r'  r(  r   r   r   r   r)  a  r`  z.TestNdFull.test_2d_shape_dtypes.<locals>.func2c                 S   rZ  rI  rE  r   r   r   r   r*  f  s    z1TestNdFull.test_2d_shape_dtypes.<locals>.<lambda>r,  rQ   )r   r   r-  r1   r   r   r   r'  r.  r   r   r   r/  [  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   rE  r   rS   valuer   r   r*  m  r+  z>TestNdFull.test_alloc_size.<locals>.gen_func.<locals>.<lambda>r   ra  r   ra  r   r7  l  rP  z,TestNdFull.test_alloc_size.<locals>.gen_funcrQ   rk   r   r8  )r   r9  r:  r   r;  r   r   r   r=  j  s    zTestNdFull.test_alloc_sizeN)rB   rC   rD   r   r   r   r  r  r  r  r  r  r"  r2  r^  r/  r=  r   r   r   r   rB    s    rB  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 )NrL      x)rV   	TypeErrorr   r4   r]   )r9   rH   
fill_valuer   r   r   mutate_arrayu  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   )	r2   r3   r4   r5   r   rg  r   r6   r7   )rH   r?   r@   r=   r:   r9   r   r   	check_arr~  s   

z5ConstructorLikeBaseTest.check_like.<locals>.check_arrr   r      )rj  r   rQ   rk   r[   )r[   rQ   rk   r   r   r   rk   F	WRITEABLErQ   )	r   linspaceastyper1   r   ndimflagsr   r   )r9   r:   r4   ri  origrS   rH   r   rh  r   
check_like}  s    




z"ConstructorLikeBaseTest.check_likeN)rB   rC   rD   rg  rr  r   r   r   r   rc  s  s    rc  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   rs  r   r   r   r:   r   r   r   r   r     r   zTestNdEmptyLike.setUpc                 C   s   d S r   r   r   r   r   r   r     rs   z"TestNdEmptyLike.check_result_valuec                    $   | j   fdd}| |tj d S )Nc                    r   r   r   rO   r   r   r   r     r   z'TestNdEmptyLike.test_like.<locals>.funcr:   rr  r   rT   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   rO   r   r   r   r     r   z2TestNdEmptyLike.test_like_structured.<locals>.func)r   r4   r$  ru   r:   rr  r9   r4   r   r   r   r   test_like_structured  s   z$TestNdEmptyLike.test_like_structuredc                    rt  )Nc                    r   r   r  rO   r   r   r   r     r~   z-TestNdEmptyLike.test_like_dtype.<locals>.funcru  r   r   r   r   test_like_dtype  rw  zTestNdEmptyLike.test_like_dtypec                    s0   t d | j fdd}| |t j d S )Nr`   c                    r  r   r   rO   r4   r:   r   r   r     r  z6TestNdEmptyLike.test_like_dtype_instance.<locals>.func)r   r4   r:   rr  rT   r   r   r{  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   rO   r{  r   r   r     r  z8TestNdEmptyLike.test_like_dtype_structured.<locals>.func)r   r4   r$  ru   r:   rr  rT   r   r   r{  r   test_like_dtype_structured  s   z*TestNdEmptyLike.test_like_dtype_structuredc                    rt  )Nc                    s    | t jdS r0  r  rO   r   r   r   r     rP  z3TestNdEmptyLike.test_like_dtype_kwarg.<locals>.funcru  r   r   r   r   test_like_dtype_kwarg  rw  z%TestNdEmptyLike.test_like_dtype_kwargc                    rt  )Nc                        | ddS )Nr`   ro   r   rO   r   r   r   r     r~   z7TestNdEmptyLike.test_like_dtype_str_kwarg.<locals>.funcru  r   r   r   r   test_like_dtype_str_kwarg  rw  z)TestNdEmptyLike.test_like_dtype_str_kwargc                    rt  )Nc                    r  )Nr  ro   r   rO   r   r   r   r     r~   zLTestNdEmptyLike.test_like_dtype_str_kwarg_alternative_spelling.<locals>.funcru  r   r   r   r   .test_like_dtype_str_kwarg_alternative_spelling  rw  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>.funcrc   r`   r  r  z'{}(array(float64, 1d, C), unicode_type))r:   r   r   r   r   rt   r   r   rB   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>.funcrc   r  )	r:   r   r   r   r   rt   r   r   r   r  r   r   r   test_like_dtype_invalid_str  s   
z+TestNdEmptyLike.test_like_dtype_invalid_str)rB   rC   rD   r   r   rv  ry  rz  r|  r}  r~  r  r  r  r  r>  r   r   r   r   rs    s    rs  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_liker:   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  ry  r   r   r   r   ry    r   z$TestNdZerosLike.test_like_structuredc                    r  r   )r   r  r}  r   r   r   r   r}  	  r   z*TestNdZerosLike.test_like_dtype_structured)rB   rC   rD   r   r   ry  r}  r>  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_liker:   expected_valuer   r   r   r   r     s   
zTestNdOnesLike.setUpc                    r  r   )r   r  ry  r   r   r   r   ry       z#TestNdOnesLike.test_like_structuredc                    r  r   )r   r  r}  r   r   r   r   r}    r  z)TestNdOnesLike.test_like_dtype_structured)	rB   rC   rD   r   r@  rA  ry  r}  r>  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   rH  )N      @r   	full_likerO   r   r   r   r   %  r~   z&TestNdFullLike.test_like.<locals>.funcrr  r   rT   r   r   r   r   rv  $     zTestNdFullLike.test_likec                 C   s2   t dt jfdt jfg}dd }| || d S )Nr   r   c                 S   rH  rI  r  rO   r   r   r   r   -  r~   z1TestNdFullLike.test_like_structured.<locals>.func)r   r4   r$  ru   rr  rx  r   r   r   ry  *  s   z#TestNdFullLike.test_like_structuredc                 C   r  )Nc                 S   rK  rI  r   r  rL  rO   r   r   r   r   2  r   z,TestNdFullLike.test_like_dtype.<locals>.funcr  r   r   r   r   rz  1  r  zTestNdFullLike.test_like_dtypec                    s(   t d  fdd}| |t j d S )NrN  c                    rO  rI  r  rO   ro   r   r   r   8  rP  z5TestNdFullLike.test_like_dtype_instance.<locals>.func)r   r4   rr  rT   r   r   ro   r   r|  6  s   
z'TestNdFullLike.test_like_dtype_instancec                 C   r  )Nc                 S   s   t j| dt jdS )NrD  ro   r  rO   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   rR  rS  r  rO   r   r   r   r   B  rP  z6TestNdFullLike.test_like_dtype_str_kwarg.<locals>.funcr  r   r   r   r   r  A  r  z(TestNdFullLike.test_like_dtype_str_kwargc                 C   r  )Nc                 S   s   t j| dddS )NrD  rT  ro   r  rO   r   r   r   r   G  r   zKTestNdFullLike.test_like_dtype_str_kwarg_alternative_spelling.<locals>.funcr  r   r   r   r   r  F  r  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   rU  r   r  )rH   rV  r  r   r   r   r   M  r   z@TestNdFullLike.test_like_dtype_non_const_str_kwarg.<locals>.funcr[   rD  r`   z?If np.full_like dtype is a string it must be a string constant.r   r   r   r   rt   r   r   r   r  r   r   r   #test_like_dtype_non_const_str_kwargK  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   rY  r  r  )rH   rV  r   r   r   r   [  r   z8TestNdFullLike.test_like_dtype_invalid_str.<locals>.funcrc   g333333@r  r  r  r   r   r   r  Y  s   

z*TestNdFullLike.test_like_dtype_invalid_strN)rB   rC   rD   r   rv  r@  rA  ry  rz  r|  r~  r  r  r  r  r   r   r   r   r    s    
r  c                   @   r   )
TestNdIdentityc                 C   s   |  |dg d S )Nr[   rA   r9   r:   r   r   r   check_identityh  r   zTestNdIdentity.check_identityc                 C   rC  )Nc                 S   
   t | S r   r   identityr   r   r   r   r   l  r  z*TestNdIdentity.test_identity.<locals>.func)r  r   r   r   r   test_identityk  rG  zTestNdIdentity.test_identityc                    s:   t jt jt jt ddfD ]  fdd}| | qd S )NrN  rL  c                    s   t |  S r   r  r   ro   r   r   r   s  r~   z0TestNdIdentity.test_identity_dtype.<locals>.func)r   r1  r$  rL  r4   r  r   r   ro   r   test_identity_dtypep  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   r  r  r   r   r   r   y     z@TestNdIdentity.test_like_dtype_non_const_str_kwarg.<locals>.funcrc   r`   z>If np.identity dtype is a string it must be a string constant.rX  r  r   r   r   r  w     

z2TestNdIdentity.test_like_dtype_non_const_str_kwargN)rB   rC   rD   r  r  r  r  r   r   r   r   r  f  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S )	TestNdEyec                 C      dd }|  |ddg d S )Nc                 S   r  r   r   eyer   r   r   r   r     r  z"TestNdEye.test_eye_n.<locals>.funcrQ   r  r  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 )NrQ   c                 S      t j| |dS r0  r  )rY   r4   r   r   r   r     rP  z(TestNdEye.test_eye_n_dtype.<locals>.funcr  r  )r   r
  r1  rA   )r9   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  rY   ra   r   r   r   r     r~   z$TestNdEye.test_eye_n_m.<locals>.func)rQ   rk   r[   rk   )r   r[   r  r   r   r   r   test_eye_n_m  r  zTestNdEye.test_eye_n_mc                 C   s   |  |g d d S )N))rQ   rk   r   )r[   rc   rQ   )r[   rc   r   )rc   r[   )rc   r[   )rc   r[   r   r  r   r   r   r   check_eye_n_m_k  r!   zTestNdEye.check_eye_n_m_kc                 C   rC  )Nc                 S   rU  r   r  rY   ra   rj   r   r   r   r     rP  z&TestNdEye.test_eye_n_m_k.<locals>.funcr  r   r   r   r   test_eye_n_m_k  rG  zTestNdEye.test_eye_n_m_kc                 C   rC  )Nc                 S   s   t j| ||t jdS N)NMrj   r4   )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  rG  zTestNdEye.test_eye_n_m_k_dtypec                    rM  )Nr$  c                    s   t j| || dS r  r  r  ro   r   r   r     r   z5TestNdEye.test_eye_n_m_k_dtype_instance.<locals>.func)r   r4   r  r   r   ro   r   test_eye_n_m_k_dtype_instance  rQ  z'TestNdEye.test_eye_n_m_k_dtype_instanceN)
rB   rC   rD   r  r  r  r  r  r  r  r   r   r   r   r    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  r   r[   rc   c                 S   r  r   r   diag)qr   r   r   r     r  zTestNdDiag.setUp.<locals>.funcr   c                 S   r  )Nrj   r  )r  rj   r   r   r   
func_kwarg  rP  z$TestNdDiag.setUp.<locals>.func_kwarg)r   )r   array	transposevectorsr\   r   	matriciespyr1   jitpy_kwjit_kw)r9   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   )r2   r3   r4   r   r6   r7   )r9   r:   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  r9   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  )rX   r  r  r  r  r9   rj   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  )Nrc   r  )rX   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      ?r[   r  )r   r  r1   r  r   re  r   r  )r9   r  r=   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.*)r1   r  assertRaisesRegexr   )r9   r=   r  r   r   r   r   test_bad_shape  s
   

"zTestNdDiag.test_bad_shapeN)rB   rC   rD   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   rm  r  r   r   r   r:     r~   z,TestLinspace.test_linspace_2.<locals>.pyfunc))r   rc   )rQ   r   )            @)                    @      @)rk   rQ   )      ?      ?              ?r  r  r   r   r   test_linspace_2     zTestLinspace.test_linspace_2c                 C   r  )Nc                 S   rU  r   r  rY   ra   ri   r   r   r   r:     rP  z,TestLinspace.test_linspace_3.<locals>.pyfunc))r   rc   	   )rQ   rc   r[   )r  r  r   )r  r  r   )rk   rQ   r   )r  r  r   )rQ   g}Ô%ITrQ   r  r  r   r   r   test_linspace_3  r  zTestLinspace.test_linspace_3c                 C   s8   t dd }d\}}}| |||||||| d S )Nc                 S   rU  r   r  r  r   r   r   rP     r   z0TestLinspace.test_linspace_accuracy.<locals>.foo)g        r  r   )r1   assertPreciseEqualpy_func)r9   rP   rY   ra   ri   r   r   r   test_linspace_accuracy  s   

"z#TestLinspace.test_linspace_accuracyN)rB   rC   rD   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 r0  rM   rS   ro   r   r   r:     rP  z7TestNpyEmptyKeyword._test_with_dtype_kw.<locals>.pyfuncrQ   r   r  r1   r2   r4   rS   r9   r4   r:   shapesr=   sr?   r   r   ro   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 Nr1  )r   r`   ru   r1  r4   r  r9   r4   r   r   r   test_with_dtype_kws%     z'TestNpyEmptyKeyword.test_with_dtype_kwsc                    r  )Nc                    r  )Nr6  rM   r  ro   r   r   r:   *  rP  zATestNpyEmptyKeyword._test_with_shape_and_dtype_kw.<locals>.pyfuncr  r  r  r   ro   r   _test_with_shape_and_dtype_kw)  r  z1TestNpyEmptyKeyword._test_with_shape_and_dtype_kwc                 C   r  r   )r   r`   ru   r1  r4   r  r  r   r   r   test_with_shape_and_dtype_kws6  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   rM   r   r   r   r   r:   <  r   z6TestNpyEmptyKeyword.test_empty_no_args.<locals>.pyfunc)r1   r   r   )r9   r:   r=   r   r   r   test_empty_no_args:  s
   "z&TestNpyEmptyKeyword.test_empty_no_argsN)rB   rC   rD   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   r  r   r   r  argr   r   r   r:   J  r  z#TestNpArray.test_0d.<locals>.pyfuncrL   ro   r  )r1   r  r   r  r9  r9   r:   r=   r   r   r   r   r   I  s   zTestNpArray.test_0dc                 C   r  )Nc                 S      t j| t jdS r0  )r   r  r$  r	  r   r   r   r:   T  r   z.TestNpArray.test_0d_with_dtype.<locals>.pyfunc)rL   )r  r  r  r   r   r   test_0d_with_dtypeS  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   r:   Z  r  z#TestNpArray.test_1d.<locals>.pyfunc)rk   r[   rL   )r  y              @rL   r   )r1   r  r   r9  r  rT   r  r   r   r   r   Y  s   zTestNpArray.test_1dc                 C   ,   dd }|  |ddgfddgfddg d S )	Nc                 S   r  r0  )r   r  ru   r	  r   r   r   r:   i  r   z.TestNpArray.test_1d_with_dtype.<locals>.pyfuncrk   rL   r  r  )rQ   r  rL   r   r  r  r   r   r   test_1d_with_dtypeh     zTestNpArray.test_1d_with_dtypec                 C   r  )	Nc                 S   s   t j| ddS )Nru   ro   r  r	  r   r   r   r:   t  rP  z2TestNpArray.test_1d_with_str_dtype.<locals>.pyfuncrk   rL   r  r  r  r  r  r  r   r   r   test_1d_with_str_dtypes  r  z"TestNpArray.test_1d_with_str_dtypec                 C   r  )Nc                 S   r  r0  r  )r
  r  r   r   r   r     r   z:TestNpArray.test_1d_with_non_const_str_dtype.<locals>.func)r   r[   r`   z;If np.array dtype is a string it must be a string constant.rX  r  r   r   r    test_1d_with_non_const_str_dtype~  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   r  r   r  r	  r   r   r   r:     r  z#TestNpArray.test_2d.<locals>.pyfuncr  r[   rc   rQ   rk   r[   rc   rQ   r  r[   rD  r  rD  r  ))      ?rk   )r  rD  r  )r   r   )r1   r  r   r9  rT   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  r0  )r   r  r`   r	  r   r   r   r:     r   z.TestNpArray.test_2d_with_dtype.<locals>.pyfuncr  r  rQ   rk   r[   rc   )r1   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   r:     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 shaperQ   rk   zrcannot convert Tuple(int64, Record(a[type=int32;offset=0],b[type=float32;offset=4];8;False)) to a homogeneous type)r   r  )r   f4ro   r   r  )r1   
contextlibcontextmanagerr   r  r'  r4   r   )r9   r:   r=   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   r  r   r  )objr   r   r   r     r  z(TestNpArray.test_bad_array.<locals>.funcz,.*The argument "object" must be array-like.*r   r  r   r9   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   rc   r"  r#  r   r   r   test_bad_dtype  s   
"zTestNpArray.test_bad_dtypeN)rB   rC   rD   r   r  r   r  r  r  r"  r  r   r$  r%  r   r   r   r   r  G  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   )rc   r[   rk   r   F)orderr   .r   r\   r   r   r9   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   )r9   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   rh  r   r   check  s
   z(TestNpConcatenate.test_3d.<locals>.checkc                    s    t dD ]	} | ||| qd S )Nr[   r   r   )r5  r   r   check_all_axes  s   z1TestNpConcatenate.test_3d.<locals>.check_all_axesrQ   r   r   r   rk   )rQ   rk   r  r   )r   rk   r2  r   )	r    r1   r.  Trn  r   rT   r   r1  )r9   r6  r   r   r   r  r   r   r   )r=   r5  r:   r9   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   r3  )r   r   r   r?   r   rh  r   r   r5  #  s   z0TestNpConcatenate.test_3d_no_axis.<locals>.checkrQ   r   )r   r1   r.  r7  r   r1  )r9   r5  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   )r[   r   r   rL   z8all the input arrays must have same number of dimensionsz(input arrays must have compatible dtypesz.zero-dimensional arrays cannot be concatenatedrQ   %expecting a non-empty tuple of arrays)r   r1   r   r\   r   rn  r4   r(  r  assertTypingErrorr   r   r   )r9   r:   r=   r   r   r   r  r   r   r   r   test_typing_errorsC  s8   






z$TestNpConcatenate.test_typing_errorsN)rB   rC   rD   __doc__r.  r  r  r1  r8  r9  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.  j  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 shaper0  )r9   r   r   r   r   assert_invalid_sizesr  s   z TestNpStack.assert_invalid_sizesc                 C   s8   || }|| }|  |j|j | | |  d S r   )r2   rS   r  flatten)r9   r:   r=   r>   r?   r   r   r   r   check_stacky  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   )rB  r   r   r   r>   rh  r   r   r5    r`  z#TestNpStack.check_3d.<locals>.checkc                    s    D ]	} | ||| qd S r   r   rC  )r5  generate_starargsr   r   r6    s   
z,TestNpStack.check_3d.<locals>.check_all_axes)r.  r7  rn  r   rT   )
r9   r:   r=   rD  r6  r   r   r   r  r   r   )r=   r5  rD  r:   r9   r   check_3d  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)	r9   r=   rD  r   r   r   r  r   r>   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 )Nr[   r2  r   r   r   r   r   rD    s
   z.TestNpStack.test_3d.<locals>.generate_starargsN)r%   r1   rE  rH  r9   r:   r=   rD  r   r   r   r8    s
   zTestNpStack.test_3dc                 C   rI  )z"
        stack(3d arrays)
        c                   s       dV  d S r   r   r   r   r   r   rD       
z6TestNpStack.test_3d_no_axis.<locals>.generate_starargsN)r$   r1   rE  rH  rJ  r   r   r   r9    s
   zTestNpStack.test_3d_no_axisc                 C   sB   t }t|}td}td}td}| |||||f dS )z"
        stack(0d arrays)
        rL                TN)r$   r1   r   r  rB  r9   r:   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   rK  r   r   r   r   r   r   rD    rL  z4TestNpStack.check_xxstack.<locals>.generate_starargsrL   rM  TN)rE  r   r  rB  )r9   r:   r=   rD  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   )rk   rc   r   )r'   r1   rO  r   r\   rB  r   r9   r:   r=   r   r   r   r   r   test_hstack  s   
zTestNpStack.test_hstackc                 C   s   t tg}|D ];}t|}| || td}|d }| |||||f tdd}tddd }| |||||f qd S )Nr   r   rj  r  r   )rc   rk   r   )r)   r+   r1   rO  r   r\   rB  r   )r9   	functionsr:   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-   r1   rO  r   r\   rB  r   rP  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 )Nrc   r   r   rc   r[   rL   )rQ   rQ   rQ   )
r/   r1   r   r\   r   rB  rF  r   r  r<  rN  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   rU  rQ   r;  )r$   r'   r)   r-   r/   r1   r   r\   r   r<  r   r   r   )r9   r:   r=   r   r   r   r   r   test_bad_arrays"  s   
zTestNpStack.test_bad_arraysN)rB   rC   rD   r>  r.  r  r  r@  rB  rE  rH  r8  r9  r   rO  rQ  rS  rT  rV  rW  r   r   r   r   r?  d  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   r:   .  s   z%benchmark_refct_speed.<locals>.pyfuncr   i'  c                           d S r   r   r   )r:   r   r   rq   r   r   bench_pyfunc;  r   z+benchmark_refct_speed.<locals>.bench_pyfuncc                      rX  r   r   r   )r=   r   r   rq   r   r   bench_cfunc>  r   z*benchmark_refct_speed.<locals>.bench_cfunc)r1   r   r   r   	benchmarkprint)rY  rZ  python_time
numba_timer   )r=   r:   r   r   rq   r   benchmark_refct_speed-  s   

r_  __main__)<r  rv   numpyr   r   rer   rx   numba.core.errorsr   numbar   
numba.corer   r   r   numba.tests.supportr   r   r	   r
   numba.core.utilsr   r@  r1   r   r    r$   r%   r'   r)   r+   r-   r/   r0   rE   rK   r   r   r?  rB  objectrc  rs  r  r  r  r  r  r  r  r  r  r&  
skipUnlesshasattrr?  r_  rB   mainr   r   r   r   <module>   sn       ]G q.\G!,H0   I
