o
    i                     @   s\  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	 d dl
mZ d dlmZmZmZ d dlmZmZmZmZ d dlZedddZdd	 Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZG dd deZ G dd deZ!G dd de!eZ"G d d! d!e!Z#G d"d# d#e#eZ$G d$d% d%e$Z%G d&d' d'e#eZ&G d(d) d)e'Z(G d*d+ d+e(eZ)G d,d- d-e)Z*G d.d/ d/e*Z+G d0d1 d1e(eZ,G d2d3 d3e Z-G d4d5 d5e Z.G d6d7 d7eZ/G d8d9 d9e Z0G d:d; d;eZ1G d<d= d=ee Z2G d>d? d?eeZ3e4e5ed@dAG dBdC dCeeZ6dDdE Z7e8dFkr,e9  dS dS )G    N)TypingError)njit)typesutilsconfig)MemoryLeakMixinTestCasetagskip_if_32bitT)_nrtnogilc                 C      t | ||fS Nnpconcatenateabc r   W/home/ubuntu/veenaModal/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_outputs1   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   )r1   baserefcount)r8   arrexpectr   r   r   assert_array_nrt_refct@   r    z#NrtRefCtTest.assert_array_nrt_refctN)rA   rB   rC   rI   r   r   r   r   rD   ?   s    rD   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rG   r   r   r   fooG   s   
z'TestDynArray.test_empty_0d.<locals>.foo   rK   r   {   )r0   rI   r   r5   r6   r1   r2   shaper3   float64stridesfill)r8   rO   rG   r   r   r   test_empty_0dF   s   

zTestDynArray.test_empty_0dc                 C   s   t dd }d}||}| |d tjt|| | |j| | |j|f | |j	t	tj
 | |jt	tj
jf |d tjd| ~d S )Nc                 S   s$   t | }t| D ]}|||< q	|S r   )r   rM   range)nrG   ir   r   r   rO   Y   s   

z'TestDynArray.test_empty_1d.<locals>.foo   rP   rQ   )r0   rI   r   r5   r6   aranger1   r2   rR   r3   rS   rT   itemsizerU   )r8   rO   rX   rG   r   r   r   test_empty_1dX   s   

zTestDynArray.test_empty_1dc                 C   s|   dd }t |}d}d}|||}|||}| |d tj|| | |j|j | |j|j | |j|j ~d S )Nc                 S   sB   t | |ft j}t| D ]}t|D ]
}|| |||f< qq|S r   r   rM   int32rW   )mrX   rG   rY   jr   r   r   r9   n   s   z*TestDynArray.test_empty_2d.<locals>.pyfunc   rZ   rP   	r0   rI   r   r5   r6   r1   r2   rR   rT   )r8   r9   r<   r`   rX   expected_arrgot_arrr   r   r   test_empty_2dm   s   

zTestDynArray.test_empty_2dc                 C      dd }t |}d}d}d}||||}||||}| |d tj|| | |j|j | |j|j | |j|j ~d S )Nc                 S   sX   t | ||ft j}t| D ]}t|D ]}t|D ]}|| | ||||f< qqq|S r   r^   )r`   rX   prG   rY   ra   kr   r   r   r9      s   z*TestDynArray.test_empty_3d.<locals>.pyfuncrb   rZ      rP   rc   r8   r9   r<   r`   rX   rh   rd   re   r   r   r   test_empty_3d   s   	zTestDynArray.test_empty_3dc                 C   rg   )Nc                 S   sF   t | |ft j}t| D ]}t|D ]
}|| |||f< qq|| S r   r^   )r`   rX   rh   rG   rY   ra   r   r   r   r9      s   z1TestDynArray.test_empty_2d_sliced.<locals>.pyfuncrb   rZ   rj   rP   rc   rk   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 )Nrb   r3   c                      s    S r   r   r   yr   r   return_external_array      zDTestDynArray.test_return_global_array.<locals>.return_external_arrayrP   )r   onesfloat32sysgetrefcountr0   r1   r5   r6   gccollect)r8   	initrefctrq   r<   outr   ro   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 )Nrb   rn   c                      s    dd  S Nrj   r   r   ro   r   r   rq         zKTestDynArray.test_return_global_array_sliced.<locals>.return_external_arrayrj   )r   rs   rt   r0   assertIsNonerE   r5   r6   )r8   rq   r<   rz   yyr   ro   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   ro   r   r   r   r9      rr   z4TestDynArray.test_array_pass_through.<locals>.pyfuncrb   rn   )r   rs   rt   r0   r5   r6   assertIs)r8   r9   rG   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|   )r2   ro   r   r   r   r9         z;TestDynArray.test_array_pass_through_sliced.<locals>.pyfuncrb   rn   rP   rj   )
r   rs   rt   ru   rv   r0   r1   r5   r6   r2   )r8   r9   rG   ry   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   rM   rR   add)r   r   rz   r   r   r   r9     s   z=TestDynArray.test_ufunc_with_allocated_output.<locals>.pyfunc
   rP   rj      F      )r0   r   randomr5   r6   rI   reshape)r8   r9   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   rM   r2   rW   )inprz   rY   tmpra   r   r   r   r9   .  s   
z/TestDynArray.test_allocation_mt.<locals>.pyfuncr   rP   c                    s    | |d d < d S r   r   )r   rz   r<   r   r   wrappedO  r    z0TestDynArray.test_allocation_mt.<locals>.wrappedd   	worker{0}targetr=   nameN)r0   r   r   randintcopyr5   r6   rW   
empty_like	threadingThreadformatappendstartjoinzip)r8   r9   r2   rG   
frozen_arrworkersinputsoutputsr   rY   rz   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 NrP   r   )rX   r   rz   rY   r   r   r   r9   n  s   z*TestDynArray.test_refct_mt.<locals>.pyfuncr   rn   i  c                    s    | ||d d < d S r   r   )rX   inputrz   r   r   r   r        z+TestDynArray.test_refct_mt.<locals>.wrappedr   r   r   N)r0   r   r[   floatru   rv   r   	randranger5   r6   r1   rW   rM   r   r   r   r   r   r   r   )r8   r9   r2   r   expected_refctswapctr>   r   r   swapctsr   rY   rz   r   r   r   r   test_refct_mti  s@   	








zTestDynArray.test_refct_mtc                 C   sh   t dd }|   | t}|tjjd d  W d    n1 s$w   Y  | dt|j	 d S )Nc                 S   s   t |  d S r   rL   xr   r   r   rO        z1TestDynArray.test_invalid_size_array.<locals>.foo   rj   zAllocation failed)
r   disable_leak_checkassertRaisesMemoryErrorr   size_tmaxvalassertInstr	exception)r8   rO   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
            rW   r   rp   trY   r   r   r   r9     s   z&TestDynArray.test_swap.<locals>.pyfuncr   r   rP   )
r0   r   r   ru   rv   r~   rE   r5   r6   r1   )	r8   r9   r<   r   rp   r   ry   rH   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   rp   rY   r   r   r   r9     s   z7TestDynArray.test_return_tuple_of_array.<locals>.pyfuncr   )	r0   r   r   ru   rv   r   r5   r6   r1   )	r8   r9   r<   r   ry   
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   rp   rY   rz   r   r   r   r9     s
   z?TestDynArray.test_return_tuple_of_array_created.<locals>.pyfuncr   rj   )r0   r   r   r5   r6   r1   ru   rv   )r8   r9   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   )rz   r   r   r   inner   s   z7TestDynArray.test_issue_with_return_leak.<locals>.innerc                        | S r   r   r   r   r   r   r9        z8TestDynArray.test_issue_with_return_leak.<locals>.pyfuncr   N)r0   r   r[   ru   rv   r1   )r8   r9   r<   rG   	old_refctr   r   r   test_issue_with_return_leak  s   


z(TestDynArray.test_issue_with_return_leakN)rA   rB   rC   rV   r]   rf   rl   rm   r{   r   r   r   r   r   r   r
   r   r   r   r   r   r   r   r   r   rJ   D   s&    $A=
rJ   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 )NrP   rQ   )r0   rI   r1   r2   rR   r3   rT   check_result_valuer   r   rU   r5   r6   )r8   r9   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 )NrZ   rP   rQ   negative dimensions not allowedr0   rI   r1   r2   rR   r3   rT   r   r   r   rU   r5   r6   r   
ValueErrorr   r   )r8   r9   r<   rX   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rj   rZ   rP   rQ   rj   r   r   r   )r8   r9   r<   r`   rX   r>   r?   r   r   r   r   check_2d8  s$   




zConstructorBaseTest.check_2dc                 C   sN   t |}| t}|  W d   n1 sw   Y  | dt|j dS )zAChecks that pyfunc will error, not segfaulting due to array size.Nzarray is too big)r0   r   r   r   r   r   )r8   r9   r<   er   r   r   check_alloc_sizeM  s   z$ConstructorBaseTest.check_alloc_sizeN)rA   rB   rC   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   zerosr9   r8   	__class__r   r   r   Z     zTestNdZeros.setUpc                 C      t j|| d S r   r   r5   r6   r8   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   r9   r   r   funcc  r   z!TestNdZeros.test_0d.<locals>.func)r9   r   r8   r   r   r   r   test_0da     zTestNdZeros.test_0dc                    r   )Nc                    r   r   r   rX   r   r   r   r   i  r   z!TestNdZeros.test_1d.<locals>.funcr9   r   r   r   r   r   test_1dg  r   zTestNdZeros.test_1dc                    r   )Nc                        | t jS r   r   r_   r   r   r   r   r   o  r}   z'TestNdZeros.test_1d_dtype.<locals>.funcr   r   r   r   r   test_1d_dtypem  r   zTestNdZeros.test_1d_dtypec                    s,   | j td  fdd}| | d S )Nr_   c                    
   |  S r   r   r   _dtyper9   r   r   r   w     
z0TestNdZeros.test_1d_dtype_instance.<locals>.func)r9   r   r3   r   r   r   r   r   test_1d_dtype_instances  s   
z"TestNdZeros.test_1d_dtype_instancec                    <   | j d  fdd}| | fdd}| | d S )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   rX   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.)r9   r   r   r   r   r   rA   r   r8   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')r9   r   r   r   r   r   r   r8   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`   rX   r   r   r   r     r}   z!TestNdZeros.test_2d.<locals>.funcr9   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>        rP   )	r9   r   r   	IS_32BITSr0   r   r   r   r  r8   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 Nrn   )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(  rn   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  rn   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   )r3   r9   rR   r   r   r!    s   
 z?TestNdZeros.test_alloc_size.<locals>.gen_func.<locals>.<lambda>r   rR   r3   r   )r3   rR   r   gen_func  r   z-TestNdZeros.test_alloc_size.<locals>.gen_funcrP   rj   r   @   )r9   r   intpbitwidthr   r   r8   widthr.  r   r   r   test_alloc_size  s
   "zTestNdZeros.test_alloc_size)rA   rB   rC   r   r   r   r   r   r   r  r  r  r  r  r  r&  r)  r+  r,  r4  __classcell__r   r   r   r   r   X  s$    r   c                       s.   e Zd Z fddZej fddZ  ZS )
TestNdOnesc                    r   r   )r   r6  r   r   rs   r9   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)rA   rB   rC   r   unittestexpectedFailurer  r5  r   r   r   r   r6    s    r6  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   r:  )Nc                 S      t | dS Nr;  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   r:  )Nc                 S      t | dt jS r@  )r   r=  bool_r   r   r   r   r     r   z&TestNdFull.test_1d_dtype.<locals>.funcrA  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   rn   r   r   r   
     z/TestNdFull.test_1d_dtype_instance.<locals>.func)r   r3   r   r   r   rn   r   r        
z!TestNdFull.test_1d_dtype_instancec                 C   r:  )Nc                 S      t | ddS Nr;  rC  r<  r   r   r   r   r     rG  z*TestNdFull.test_1d_dtype_str.<locals>.funcrA  r   r   r   r   r    r>  zTestNdFull.test_1d_dtype_strc                 C   r:  )Nc                 S   rI  )Nr;  ?r<  r   r   r   r   r     rG  z?TestNdFull.test_1d_dtype_str_alternative_spelling.<locals>.funcrA  r   r   r   r   r    s   z1TestNdFull.test_1d_dtype_str_alternative_spellingc                 C   s`   t dd }| t}|ddd W d    n1 sw   Y  t|j}d}| || d S )Nc                 S      t | ||S r   r<  )rX   fvr	  r   r   r   r     r   z4TestNdFull.test_1d_dtype_non_const_str.<locals>.funcr   r;  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  r<  )rX   rM  r   r   r   r   )  r   z2TestNdFull.test_1d_dtype_invalid_str.<locals>.funcrN  r;  r  rO  r  r   r   r   r  '  s   

z$TestNdFull.test_1d_dtype_invalid_strc                 C   r:  )Nc                 S      t | |fdS r@  r<  r  r   r   r   r   4  r   z TestNdFull.test_2d.<locals>.funcr   r   r   r   r   r  3  r>  zTestNdFull.test_2dc                 C   r:  )Nc                 S      t j| |fdt jdS )Ny      ?      @rn   )r   r=  r(  r  r   r   r   r   9  r   z,TestNdFull.test_2d_dtype_kwarg.<locals>.funcrR  r   r   r   r   r)  8  r>  zTestNdFull.test_2d_dtype_kwargc                 C   s:   dd }|  | dd }|  | dd }|  | d S )Nc                 S      t | |ft dS r   )r   r=  r_   r  r   r   r   r   ?  r   z0TestNdFull.test_2d_dtype_from_type.<locals>.funcc                 S   rT  r   )r   r=  r  r  r   r   r   r   D  r   c                 S   rS  )NrP   rn   )r   r=  r  r  r   r   r   r   I  r   rR  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  O     z.TestNdFull.test_2d_shape_dtypes.<locals>.func1c                 S   rV  r@  )r   r=  r  r  r  r   r   r   r   S  rW  z.TestNdFull.test_2d_shape_dtypes.<locals>.func2c                 S   rQ  r@  r<  r  r   r   r   r!  X  s    z1TestNdFull.test_2d_shape_dtypes.<locals>.<lambda>r#  rP   )r   r   r$  r0   r   r   r   r  r%  r   r   r   r&  M  s   

"zTestNdFull.test_2d_shape_dtypesc                 C   sH   t jj}dd }| |d|d > d | |d|d > dfd d S )Nc                    s    fddS )Nc                      s   t  S r   r<  r   rR   valuer   r   r!  _  r"  z>TestNdFull.test_alloc_size.<locals>.gen_func.<locals>.<lambda>r   rX  r   rX  r   r.  ^  rG  z,TestNdFull.test_alloc_size.<locals>.gen_funcrP   rj   r   r/  )r   r0  r1  r   r2  r   r   r   r4  \  s    zTestNdFull.test_alloc_sizeN)rA   rB   rC   r   r   r   r   r   r  r  r  r  r  r)  rU  r&  r4  r   r   r   r   r9    s    r9  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 )NrK      x)rU   	TypeErrorr   r3   r\   )r8   rG   
fill_valuer   r   r   mutate_arrayg  s   z$ConstructorLikeBaseTest.mutate_arrayc              	      s    fdd}t ddd|}t dD ]I}|dkr(|dd  d}n||}|| |jdkr?||d d d	  d
|jd< t d|d< W d    n1 sXw   Y  || q||d  d S )Nc                    sn   | } | } |j|j  |j|j || || | | tj|| d S r   )	r1   r2   r3   r4   r   r^  r   r5   r6   )rG   r>   r?   r<   r9   r8   r   r   	check_arrp  s   

z5ConstructorLikeBaseTest.check_like.<locals>.check_arrr   r      )ra  r   rP   rj   rZ   )rZ   rP   rj   r   r   r   rj   F	WRITEABLErP   )	r   linspaceastyper0   r   ndimflagsr   r   )r8   r9   r3   r`  origrR   rG   r   r_  r   
check_likeo  s    




z"ConstructorLikeBaseTest.check_likeN)rA   rB   rC   r^  ri  r   r   r   r   rZ  e  s    rZ  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   rj  r   r   r   r9   r   r   r   r   r     r   zTestNdEmptyLike.setUpc                 C   s   d S r   r   r   r   r   r   r     rr   z"TestNdEmptyLike.check_result_valuec                    $   | j   fdd}| |tj d S )Nc                    r   r   r   rN   r   r   r   r     r   z'TestNdEmptyLike.test_like.<locals>.funcr9   ri  r   rS   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   rN   r   r   r   r     r   z2TestNdEmptyLike.test_like_structured.<locals>.func)r   r3   r  rt   r9   ri  r8   r3   r   r   r   r   test_like_structured  s   z$TestNdEmptyLike.test_like_structuredc                    rk  )Nc                    r   r   r   rN   r   r   r   r     r}   z-TestNdEmptyLike.test_like_dtype.<locals>.funcrl  r   r   r   r   test_like_dtype  rn  zTestNdEmptyLike.test_like_dtypec                    s0   t d | j fdd}| |t j d S )Nr_   c                    r   r   r   rN   r3   r9   r   r   r     r   z6TestNdEmptyLike.test_like_dtype_instance.<locals>.func)r   r3   r9   ri  rS   r   r   rr  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   rN   rr  r   r   r     r   z8TestNdEmptyLike.test_like_dtype_structured.<locals>.func)r   r3   r  rt   r9   ri  rS   r   r   rr  r   test_like_dtype_structured  s   z*TestNdEmptyLike.test_like_dtype_structuredc                    rk  )Nc                    s    | t jdS r'  r   rN   r   r   r   r     rG  z3TestNdEmptyLike.test_like_dtype_kwarg.<locals>.funcrl  r   r   r   r   test_like_dtype_kwarg  rn  z%TestNdEmptyLike.test_like_dtype_kwargc                    rk  )Nc                        | ddS )Nr_   rn   r   rN   r   r   r   r     r}   z7TestNdEmptyLike.test_like_dtype_str_kwarg.<locals>.funcrl  r   r   r   r   test_like_dtype_str_kwarg  rn  z)TestNdEmptyLike.test_like_dtype_str_kwargc                    rk  )Nc                    rv  )Nr  rn   r   rN   r   r   r   r     r}   zLTestNdEmptyLike.test_like_dtype_str_kwarg_alternative_spelling.<locals>.funcrl  r   r   r   r   .test_like_dtype_str_kwarg_alternative_spelling  rn  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>.funcrb   r_   r  r  z'{}(array(float64, 1d, C), unicode_type))r9   r   r   r   r   rs   r   r   rA   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>.funcrb   r  )	r9   r   r   r   r   rs   r   r   r   r  r   r   r   test_like_dtype_invalid_str  s   
z+TestNdEmptyLike.test_like_dtype_invalid_str)rA   rB   rC   r   r   rm  rp  rq  rs  rt  ru  rw  rx  ry  rz  r5  r   r   r   r   rj    s    rj  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_liker9   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{  rp  r   r   r   r   rp    r   z$TestNdZerosLike.test_like_structuredc                    r}  r   )r   r{  rt  r   r   r   r   rt    r   z*TestNdZerosLike.test_like_dtype_structured)rA   rB   rC   r   r   rp  rt  r5  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_liker9   expected_valuer   r   r   r   r     s   
zTestNdOnesLike.setUpc                    r}  r   )r   r~  rp  r   r   r   r   rp       z#TestNdOnesLike.test_like_structuredc                    r}  r   )r   r~  rt  r   r   r   r   rt    r  z)TestNdOnesLike.test_like_dtype_structured)	rA   rB   rC   r   r7  r8  rp  rt  r5  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_likerN   r   r   r   r     r}   z&TestNdFullLike.test_like.<locals>.funcri  r   rS   r   r   r   r   rm       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  rN   r   r   r   r     r}   z1TestNdFullLike.test_like_structured.<locals>.func)r   r3   r  rt   ri  ro  r   r   r   rp    s   z#TestNdFullLike.test_like_structuredc                 C   r  )Nc                 S   rB  r@  r   r  rC  rN   r   r   r   r   $  r   z,TestNdFullLike.test_like_dtype.<locals>.funcr  r   r   r   r   rq  #  r  zTestNdFullLike.test_like_dtypec                    s(   t d  fdd}| |t j d S )NrE  c                    rF  r@  r  rN   rn   r   r   r   *  rG  z5TestNdFullLike.test_like_dtype_instance.<locals>.func)r   r3   ri  rS   r   r   rn   r   rs  (  s   
z'TestNdFullLike.test_like_dtype_instancec                 C   r  )Nc                 S   s   t j| dt jdS )Nr;  rn   r  rN   r   r   r   r   /  r   z2TestNdFullLike.test_like_dtype_kwarg.<locals>.funcr  r   r   r   r   ru  .  r  z$TestNdFullLike.test_like_dtype_kwargc                 C   r  )Nc                 S   rI  rJ  r  rN   r   r   r   r   4  rG  z6TestNdFullLike.test_like_dtype_str_kwarg.<locals>.funcr  r   r   r   r   rw  3  r  z(TestNdFullLike.test_like_dtype_str_kwargc                 C   r  )Nc                 S   s   t j| dddS )Nr;  rK  rn   r  rN   r   r   r   r   9  r   zKTestNdFullLike.test_like_dtype_str_kwarg_alternative_spelling.<locals>.funcr  r   r   r   r   rx  8  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   rL  r   r  )rG   rM  r	  r   r   r   r   ?  r   z@TestNdFullLike.test_like_dtype_non_const_str_kwarg.<locals>.funcrZ   r;  r_   z?If np.full_like dtype is a string it must be a string constant.r   r   r   r   rs   r   r   r   r  r   r   r   #test_like_dtype_non_const_str_kwarg=  s   

z2TestNdFullLike.test_like_dtype_non_const_str_kwargc                 C   s`   t dd }| t}|tdd W d    n1 sw   Y  t|j}| d| d S )Nc                 S   rP  r  r  )rG   rM  r   r   r   r   M  r   z8TestNdFullLike.test_like_dtype_invalid_str.<locals>.funcrb   g333333@r  r  r  r   r   r   rz  K  s   

z*TestNdFullLike.test_like_dtype_invalid_strN)rA   rB   rC   r   rm  r7  r8  rp  rq  rs  ru  rw  rx  r  rz  r   r   r   r   r    s    
r  c                   @   r   )
TestNdIdentityc                 C   s   |  |dg d S )NrZ   r@   r8   r9   r   r   r   check_identityZ  r   zTestNdIdentity.check_identityc                 C   r:  )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 )NrE  rC  c                    s   t |  S r   r  r   rn   r   r   r   e  r}   z0TestNdIdentity.test_identity_dtype.<locals>.func)r   r(  r  rC  r3   r  r   r   rn   r   test_identity_dtypeb  s   z"TestNdIdentity.test_identity_dtypec                 C   ^   t dd }| t}|dd W d    n1 sw   Y  t|j}d}| || d S )Nc                 S      t | |S r   r  r  r   r   r   r   k     z@TestNdIdentity.test_like_dtype_non_const_str_kwarg.<locals>.funcrb   r_   z>If np.identity dtype is a string it must be a string constant.rO  r  r   r   r   r  i     

z2TestNdIdentity.test_like_dtype_non_const_str_kwargN)rA   rB   rC   r  r  r  r  r   r   r   r   r  X  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rP   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 )NrP   c                 S      t j| |dS r'  r  )rX   r3   r   r   r   r     rG  z(TestNdEye.test_eye_n_dtype.<locals>.funcr  r  )r   r  r(  r@   )r8   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  rX   r`   r   r   r   r     r}   z$TestNdEye.test_eye_n_m.<locals>.func)rP   rj   rZ   rj   )r   rZ   r  r   r   r   r   test_eye_n_m  r  zTestNdEye.test_eye_n_mc                 C   s   |  |g d d S )N))rP   rj   r   )rZ   rb   rP   )rZ   rb   r   )rb   rZ   )rb   rZ   )rb   rZ   r   r  r   r   r   r   check_eye_n_m_k  r    zTestNdEye.check_eye_n_m_kc                 C   r:  )Nc                 S   rL  r   r  rX   r`   ri   r   r   r   r     rG  z&TestNdEye.test_eye_n_m_k.<locals>.funcr  r   r   r   r   test_eye_n_m_k  r>  zTestNdEye.test_eye_n_m_kc                 C   r:  )Nc                 S   s   t j| ||t jdS N)NMri   r3   )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                    rD  )Nr  c                    s   t j| || dS r  r  r  rn   r   r   r     r   z5TestNdEye.test_eye_n_m_k_dtype_instance.<locals>.func)r   r3   r  r   r   rn   r   test_eye_n_m_k_dtype_instance  rH  z'TestNdEye.test_eye_n_m_k_dtype_instanceN)
rA   rB   rC   r  r  r  r  r  r  r  r   r   r   r   r  y  s    r  c                   @   sL   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dS )
TestNdDiagc                 C   s   t g d}t g dg}t |}|||g| _t ddd}t ddd}||g| _dd }|| _t|| _	d
dd	}|| _
t|| _d S )Nrb     rZ   rb   c                 S   r  r   r   diag)qr   r   r   r     r   zTestNdDiag.setUp.<locals>.funcr   c                 S   r  )Nri   r  )r  ri   r   r   r   
func_kwarg  rG  z$TestNdDiag.setUp.<locals>.func_kwarg)r   )r   array	transposevectorsr[   r   	matriciespyr0   jitpy_kwjit_kw)r8   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   )r1   r2   r3   r   r5   r6   )r8   r9   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  r8   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  )rW   r  r  r  r  r8   ri   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  )Nrb   r  )rW   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      ?rZ   r  )r   r  r0   r  r   r\  r   r  )r8   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.*)r0   r  assertRaisesRegexr   )r8   r<   r  r   r   r   r   test_bad_shape  s
   

"zTestNdDiag.test_bad_shapeN)rA   rB   rC   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   rd  r  r   r   r   r9     r}   z,TestLinspace.test_linspace_2.<locals>.pyfunc))r   rb   )rP   r   )            @)                    @      @)rj   rP   )      ?      ?              ?r  r  r   r   r   test_linspace_2     zTestLinspace.test_linspace_2c                 C   r  )Nc                 S   rL  r   r  rX   r`   rh   r   r   r   r9     rG  z,TestLinspace.test_linspace_3.<locals>.pyfunc))r   rb   	   )rP   rb   rZ   )r  r  r   )r  r  r   )rj   rP   r   )r  r  r   )rP   g}Ô%ITrP   r  r  r   r   r   test_linspace_3  r  zTestLinspace.test_linspace_3c                 C   s8   t dd }d\}}}| |||||||| d S )Nc                 S   rL  r   r  r  r   r   r   rO     r   z0TestLinspace.test_linspace_accuracy.<locals>.foo)g        r  r   )r0   assertPreciseEqualpy_func)r8   rO   rX   r`   rh   r   r   r   test_linspace_accuracy  s   

"z#TestLinspace.test_linspace_accuracyN)rA   rB   rC   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'  rL   rR   rn   r   r   r9     rG  z7TestNpyEmptyKeyword._test_with_dtype_kw.<locals>.pyfuncrP   r   r  r0   r1   r3   rR   r8   r3   r9   shapesr<   sr>   r   r   rn   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_   rt   r(  r3   r  r8   r3   r   r   r   test_with_dtype_kws     z'TestNpyEmptyKeyword.test_with_dtype_kwsc                    r  )Nc                    r  )Nr-  rL   r  rn   r   r   r9     rG  zATestNpyEmptyKeyword._test_with_shape_and_dtype_kw.<locals>.pyfuncr  r  r  r   rn   r   _test_with_shape_and_dtype_kw  r  z1TestNpyEmptyKeyword._test_with_shape_and_dtype_kwc                 C   r  r  )r   r_   rt   r(  r3   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   rL   r   r   r   r   r9   .  r   z6TestNpyEmptyKeyword.test_empty_no_args.<locals>.pyfunc)r0   r   r   )r8   r9   r<   r   r   r   test_empty_no_args,  s
   "z&TestNpyEmptyKeyword.test_empty_no_argsN)rA   rB   rC   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   r9   <  r   z#TestNpArray.test_0d.<locals>.pyfuncrK   rn   r  )r0   r  r   r  r0  r8   r9   r<   r   r   r   r   r   ;  s   zTestNpArray.test_0dc                 C   r  )Nc                 S      t j| t jdS r'  )r   r  r  r  r   r   r   r9   F  r   z.TestNpArray.test_0d_with_dtype.<locals>.pyfunc)rK   )r  r  r  r   r   r   test_0d_with_dtypeE  s   zTestNpArray.test_0d_with_dtypec                 C   sn   dd }t |}|g d}| |tg d |d}| |tg d |d}| |td d S )Nc                 S   r  r   r   r  r   r   r   r9   L  r   z#TestNpArray.test_1d.<locals>.pyfunc)rj   rZ   rK   )r  y              @rK   r   )r0   r  r   r0  r  rS   r  r   r   r   r   K  s   zTestNpArray.test_1dc                 C   ,   dd }|  |ddgfddgfddg d S )	Nc                 S   r  r'  )r   r  rt   r  r   r   r   r9   [  r   z.TestNpArray.test_1d_with_dtype.<locals>.pyfuncrj   rK   r  r  )rP   r  rK   r   r  r  r   r   r   test_1d_with_dtypeZ     zTestNpArray.test_1d_with_dtypec                 C   r  )	Nc                 S   s   t j| ddS )Nrt   rn   r   r  r   r   r   r9   f  rG  z2TestNpArray.test_1d_with_str_dtype.<locals>.pyfuncrj   rK   r  r  r  r  r  r  r   r   r   test_1d_with_str_dtypee  r
  z"TestNpArray.test_1d_with_str_dtypec                 C   r  )Nc                 S   r  r'  r   )r  r	  r   r   r   r   r  r   z:TestNpArray.test_1d_with_non_const_str_dtype.<locals>.func)r   rZ   r_   z;If np.array dtype is a string it must be a string constant.rO  r  r   r   r    test_1d_with_non_const_str_dtypep  r  z,TestNpArray.test_1d_with_non_const_str_dtypec                 C   s  dd }t |}|ddg}| |tddgddgg |d	d
g}| |tddgddgg |ddgddgf}| |tddgddgg |ddgddgf}| |tddgddgg |d}| |tddgddgg |d}| |td d S )Nc                 S   r  r   r   r  r   r   r   r9     r   z#TestNpArray.test_2d.<locals>.pyfuncr  rZ   rb   rP   rj   rZ   rb   rP   r  rZ   r;  r  r;  r  ))      ?rj   )r  r;  r  )r   r   )r0   r  r   r0  rS   r  r   r   r   r  ~  s   zTestNpArray.test_2dc                 C   s>   dd }t |}|ddg}| |tddgddgg d S )	Nc                 S   r  r'  )r   r  r_   r  r   r   r   r9     r   z.TestNpArray.test_2d_with_dtype.<locals>.pyfuncr  r  rP   rj   rZ   rb   )r0   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   r9     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 shaperP   rj   zrcannot convert Tuple(int64, Record(a[type=int32;offset=0],b[type=float32;offset=4];8;False)) to a homogeneous type)r   r  )r   f4rn   r   r  )r0   
contextlibcontextmanagerr   r  r  r3   r   )r8   r9   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   r8   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   rb   r  r  r   r   r   test_bad_dtype  s   
"zTestNpArray.test_bad_dtypeN)rA   rB   rC   r   r  r   r	  r  r  r  r  r  r  r  r   r   r   r   r  9  s    
	r  c                   @   s>   e Zd ZdZdd Zejdd Zdd Zdd	 Z	d
d Z
dS )TestNpConcatenatez%
    Tests for np.concatenate().
    c                 C   ^   t dd}|d }|d jdd}|d d d d }|d dd d df }|||||fS N   )rb   rZ   rj   r   F)orderr   .r   r[   r   r   r8   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   )r8   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   r_  r   r   check  s
   z(TestNpConcatenate.test_3d.<locals>.checkc                    s    t dD ]	} | ||| qd S )NrZ   r   r   )r-  r   r   check_all_axes  s   z1TestNpConcatenate.test_3d.<locals>.check_all_axesrP   r   r   r   rj   )rP   rj   r  r   )r   rj   r*  r   )	r   r0   r&  Tre  r   rS   r   r)  )r8   r.  r   r   r   r  r   r   r   )r<   r-  r9   r8   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   r_  r   r   r-    s   z0TestNpConcatenate.test_3d_no_axis.<locals>.checkrP   r   )r   r0   r&  r/  r   r)  )r8   r-  r   r   r   r  r   r   r_  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   )rZ   r   r   rK   z8all the input arrays must have same number of dimensionsz(input arrays must have compatible dtypesz.zero-dimensional arrays cannot be concatenatedrP   %expecting a non-empty tuple of arrays)r   r0   r   r[   r   re  r3   r  r  assertTypingErrorr   r   r   )r8   r9   r<   r   r   r   r  r   r   r   r   test_typing_errors5  s8   






z$TestNpConcatenate.test_typing_errorsN)rA   rB   rC   __doc__r&  r  r  r)  r0  r1  r5  r   r   r   r   r    s    
2$r  r"   z"this Numpy doesn't have np.stack()c                   @   s   e Zd ZdZdd Zejdd Zdd Zdd	 Z	d
d Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )TestNpStackz
    Tests for np.stack().
    c                 C   r  r   r$  r%  r   r   r   r&  \  r'  zTestNpStack._3d_arraysc                 c   sH    |  t}d V  W d    n1 sw   Y  | dt|j d S )Nz)all input arrays must have the same shaper(  )r8   r   r   r   r   assert_invalid_sizesd  s   z TestNpStack.assert_invalid_sizesc                 C   s8   || }|| }|  |j|j | | |  d S r   )r1   rR   r  flatten)r8   r9   r<   r=   r>   r   r   r   r   check_stackk  s   zTestNpStack.check_stackc           
         s    fddfdd}  \}}}}}	|||| |||| ||j|j|j ||j|j|j ||j|j|j ||j|	j|j |||tj| d S )Nc                    s     | ||f|  d S r   )r:  r   r   r   r=   r_  r   r   r-  v  rW  z#TestNpStack.check_3d.<locals>.checkc                    s    D ]	} | ||| qd S r   r   r;  )r-  generate_starargsr   r   r.  y  s   
z,TestNpStack.check_3d.<locals>.check_all_axes)r&  r/  re  r   rS   )
r8   r9   r<   r<  r.  r   r   r   r  r   r   )r<   r-  r<  r9   r8   r   check_3du  s   zTestNpStack.check_3dc           	      C   sv   |    |   |  \}}}}}|   t| }||d d ||g|R   W d    d S 1 s4w   Y  d S )Nr   )assert_no_memory_leakr   r&  r8  next)	r8   r<   r<  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 )NrZ   r*  r   r   r   r   r   r<    s
   z.TestNpStack.test_3d.<locals>.generate_starargsN)r$   r0   r=  r@  r8   r9   r<   r<  r   r   r   r0    s
   zTestNpStack.test_3dc                 C   rA  )z"
        stack(3d arrays)
        c                   s       dV  d S r   r   r   r   r   r   r<       
z6TestNpStack.test_3d_no_axis.<locals>.generate_starargsN)r#   r0   r=  r@  rB  r   r   r   r1    s
   zTestNpStack.test_3d_no_axisc                 C   sB   t }t|}td}td}td}| |||||f dS )z"
        stack(0d arrays)
        rK                TN)r#   r0   r   r  r:  r8   r9   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   rC  r   r   r   r   r   r   r<    rD  z4TestNpStack.check_xxstack.<locals>.generate_starargsrK   rE  TN)r=  r   r  r:  )r8   r9   r<   r<  r   r   r   r   r   r   check_xxstack  s   


zTestNpStack.check_xxstackc                 C   s   t }t|}| || td}tdd }| |||||f tdd}tddd }| |||||f d S )Nr   ra  r   r   r   )rj   rb   r   )r&   r0   rG  r   r[   r:  r   r8   r9   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   ra  r  r   )rb   rj   r   )r(   r*   r0   rG  r   r[   r:  r   )r8   	functionsr9   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,   r0   rG  r   r[   r:  r   rH  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 )Nrb   r   r  rb   rZ   rK   )rP   rP   rP   )
r.   r0   r   r[   r   r:  r>  r   r  r4  rF  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  rM  rP   r3  )r#   r&   r(   r,   r.   r0   r   r[   r   r4  r   r   r   )r8   r9   r<   r   r   r   r   r   test_bad_arrays  s   
zTestNpStack.test_bad_arraysN)rA   rB   rC   r6  r&  r  r  r8  r:  r=  r@  r0  r1  r   rG  rI  rK  rL  rN  rO  r   r   r   r   r7  V  s"    

r7  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   r9      s   z%benchmark_refct_speed.<locals>.pyfuncr   i'  c                           d S r   r   r   )r9   r   r   rp   r   r   bench_pyfunc-  r   z+benchmark_refct_speed.<locals>.bench_pyfuncc                      rP  r   r   r   )r<   r   r   rp   r   r   bench_cfunc0  r   z*benchmark_refct_speed.<locals>.bench_cfunc)r0   r   r   r   	benchmarkprint)rQ  rR  python_time
numba_timer   )r<   r9   r   r   rp   r   benchmark_refct_speed  s   

rW  __main__):r  ru   numpyr   r   rer   rw   numba.core.errorsr   numbar   
numba.corer   r   r   numba.tests.supportr   r   r	   r
   r7  r0   r   r   r#   r$   r&   r(   r*   r,   r.   r/   rD   rJ   r   r   r6  r9  objectrZ  rj  r{  r~  r  r  r  r  r  r  r  r  
skipUnlesshasattrr7  rW  rA   mainr   r   r   r   <module>   sl       PG q.\G!,H0   I
