U
    9%e                     @   sX  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rTe9  dS )G    N)TypingError)njit)typesutilsconfig)MemoryLeakMixinTestCasetagskip_if_32bitT)Z_nrtZnogilc                 C   s   t | ||fS NnpZconcatenateabc r   Y/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/numba/tests/test_dyn_array.pynp_concatenate1   s    r   c                 C   s   t j| ||f|dS Naxisr   r   r   r   r   r   r   r   np_concatenate2   s    r   c                 C   s   t | ||fS r   r   stackr   r   r   r   	np_stack1   s    r   c                 C   s   t j| ||f|dS r   r   r   r   r   r   	np_stack2   s    r   c                 C   s   t | ||fS r   )r   Zhstackr   r   r   r   	np_hstack   s    r   c                 C   s   t | ||fS r   )r   Zvstackr   r   r   r   	np_vstack"   s    r   c                 C   s   t | ||fS r   )r   Z	row_stackr   r   r   r   np_row_stack%   s    r    c                 C   s   t | ||fS r   )r   Zdstackr   r   r   r   	np_dstack(   s    r!   c                 C   s   t | ||fS r   )r   Zcolumn_stackr   r   r   r   np_column_stack+   s    r"   c                   @   s   e Zd ZdddZdS )BaseTestTc                 C   st   t |}|D ]b}|| }|| }| |j|j | |j|j | || |r`tj|| qtj|| qd S r   )	nrtjitassertEqualsizedtypeassertStridesEqualr   testingassert_equalZassert_allclose)selfpyfuncZargslistexactcfuncargsexpectedretr   r   r   check_outputs1   s    zBaseTest.check_outputsN)T)__name__
__module____qualname__r2   r   r   r   r   r#   /   s   r#   c                   @   s   e Zd Zdd ZdS )NrtRefCtTestc                 C   s   |  |jj| d S r   )r%   baserefcount)r+   arrexpectr   r   r   assert_array_nrt_refct@   s    z#NrtRefCtTest.assert_array_nrt_refctN)r3   r4   r5   r;   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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r9   r   r   r   fooG   s    
z'TestDynArray.test_empty_0d.<locals>.foo   r=   r   {   )r$   r;   r   r)   r*   r%   r&   shaper'   float64stridesfill)r+   rA   r9   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   r?   range)nr9   ir   r   r   rA   Y   s    

z'TestDynArray.test_empty_1d.<locals>.foo   rB   rC   )r$   r;   r   r)   r*   aranger%   r&   rD   r'   rE   rF   itemsizerG   )r+   rA   rJ   r9   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   r?   int32rI   )mrJ   r9   rK   jr   r   r   r,   n   s
    z*TestDynArray.test_empty_2d.<locals>.pyfunc   rL   rB   	r$   r;   r   r)   r*   r%   r&   rD   rF   )r+   r,   r.   rR   rJ   expected_arrgot_arrr   r   r   test_empty_2dm   s    

zTestDynArray.test_empty_2dc                 C   s   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 ]6}t|D ](}t|D ]}|| | ||||f< q4q(q|S r   rP   )rR   rJ   pr9   rK   rS   kr   r   r   r,      s    z*TestDynArray.test_empty_3d.<locals>.pyfuncrT   rL      rB   rU   r+   r,   r.   rR   rJ   rY   rV   rW   r   r   r   test_empty_3d   s    	zTestDynArray.test_empty_3dc                 C   s   dd }t |}d}d}d}||||}||||}| |d tj|| | |j|j | |j|j | |j|j ~d S )Nc                 S   sF   t | |ft j}t| D ]"}t|D ]}|| |||f< q&q|| S r   rP   )rR   rJ   rY   r9   rK   rS   r   r   r   r,      s
    z1TestDynArray.test_empty_2d_sliced.<locals>.pyfuncrT   rL   r[   rB   rU   r\   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 )NrT   r'   c                      s    S r   r   r   yr   r   return_external_array   s    zDTestDynArray.test_return_global_array.<locals>.return_external_arrayrB   )r   onesfloat32sysgetrefcountr$   r%   r)   r*   gcZcollect)r+   	initrefctrb   r.   outr   r`   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 )NrT   r_   c                      s    dd  S Nr[   r   r   r`   r   r   rb      s    zKTestDynArray.test_return_global_array_sliced.<locals>.return_external_arrayr[   )r   rc   rd   r$   assertIsNoner7   r)   r*   )r+   rb   r.   ri   yyr   r`   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   | S r   r   r`   r   r   r   r,      s    z4TestDynArray.test_array_pass_through.<locals>.pyfuncrT   r_   )r   rc   rd   r$   r)   r*   assertIs)r+   r,   r9   r.   r0   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 rk   )r&   r`   r   r   r   r,      s    z;TestDynArray.test_array_pass_through_sliced.<locals>.pyfuncrT   r_   rB   r[   )
r   rc   rd   re   rf   r$   r%   r)   r*   r&   )r+   r,   r9   rh   r.   rp   r0   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   r?   rD   add)r   r   ri   r   r   r   r,     s    z=TestDynArray.test_ufunc_with_allocated_output.<locals>.pyfunc
   rB   r[      F      )r$   r   randomr)   r*   r;   reshape)r+   r,   r.   Zarr_aZarr_br   r   r    test_ufunc_with_allocated_output  s(    z-TestDynArray.test_ufunc_with_allocated_outputc                    s  dd }t | d}tjdd|}| }tj|| | tj|| g }g }g } fdd}tdD ]V}	tjdd|}t|}
t	j
|||
fd|	d	}|| || ||
 qp|D ]}|  q|D ]}|  qt||D ]\}}
tj|||
 qd
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}t | j}t|jD ]}| | ||< qJt|jD ]}||  || | 7  < qfq0|S )Nr   r   r?   r&   rI   )inpri   rK   tmprS   r   r   r   r,   .  s    
z/TestDynArray.test_allocation_mt.<locals>.pyfuncrt   rB   c                    s    | |d d < d S r   r   )r|   ri   r.   r   r   wrappedO  s    z0TestDynArray.test_allocation_mt.<locals>.wrappedd   	worker{0}targetr/   nameN)r$   r   rx   randintcopyr)   r*   rI   
empty_like	threadingThreadformatappendstartjoinzip)r+   r,   r&   r9   Z
frozen_arrworkersinputsoutputsr   rK   ri   threadr|   r   r~   r   test_allocation_mt(  s6    




zTestDynArray.test_allocation_mtc                    sD  dd }t | d}tj|td}t|}td}|||}tj	| || ~| 
|t| g }g }g }	 fdd}
tdD ]R}t|}td}tj|
|||fd	|d
}|| || |	| q|D ]}|  q|D ]}|  qt|	|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 ]}|| }}q4|S NrB   r{   )rJ   r|   ri   rK   r   r   r   r,   n  s    z*TestDynArray.test_refct_mt.<locals>.pyfuncrt   r_   i  c                    s    | ||d d < d S r   r   )rJ   inputri   r~   r   r   r     s    z+TestDynArray.test_refct_mt.<locals>.wrappedr   r   r   N)r$   r   rM   floatre   rf   rx   	randranger)   r*   r%   rI   r?   r   r   r   r   r   r   r   )r+   r,   r&   r   Zexpected_refctZswapctr0   r   r   Zswapctsr   rK   ri   r   r   r~   r   test_refct_mti  s@    	








zTestDynArray.test_refct_mtc              	   C   sT   t dd }|   | t}|tjjd d  W 5 Q R X | dt|j	 d S )Nc                 S   s   t |  d S r   r>   xr   r   r   rA     s    z1TestDynArray.test_invalid_size_array.<locals>.foo   r[   zAllocation failed)
r   disable_leak_checkassertRaisesMemoryErrorr   Zsize_tmaxvalassertInstr	exception)r+   rA   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   s    t |D ]}||  } }q| |fS )z5Swap array x and y for t number of times
            rI   r   ra   trK   r   r   r   r,     s    z&TestDynArray.test_swap.<locals>.pyfuncr   r   rB   )
r$   r   rx   re   rf   rl   r7   r)   r*   r%   )	r+   r,   r.   r   ra   r   rh   r:   rp   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   ra   rK   r   r   r   r,     s    z7TestDynArray.test_return_tuple_of_array.<locals>.pyfuncru   )	r$   r   rx   re   rf   ro   r)   r*   r%   )	r+   r,   r.   r   rh   
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   ra   rK   ri   r   r   r   r,     s
    z?TestDynArray.test_return_tuple_of_array_created.<locals>.pyfuncru   r[   )r$   r   rx   r)   r*   r%   re   rf   )r+   r,   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   s   | S r   r   )ri   r   r   r   inner   s    z7TestDynArray.test_issue_with_return_leak.<locals>.innerc                    s    | S r   r   r   r   r   r   r,     s    z8TestDynArray.test_issue_with_return_leak.<locals>.pyfuncrt   N)r$   r   rM   re   rf   r%   )r+   r,   r.   r9   Z	old_refctr   r   r   test_issue_with_return_leak  s    


z(TestDynArray.test_issue_with_return_leakN)r3   r4   r5   rH   rO   rX   r]   r^   rj   rn   rq   rr   rz   r   r   r
   r   r   r   r   r   r   r   r   r   r<   D   s$   $A=
r<   c                   @   s,   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 )NrB   rC   )r$   r;   r%   r&   rD   r'   rF   check_result_valuer   r   rG   r)   r*   )r+   r,   r.   r0   r1   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 5 Q R X | t|jd d S )NrL   rB   rC   negative dimensions not allowedr$   r;   r%   r&   rD   r'   rF   r   r   r   rG   r)   r*   r   
ValueErrorr   r   )r+   r,   r.   rJ   r0   r1   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 5 Q R X | t|jd d S )Nr[   rL   rB   rC   r[   r   r   r   )r+   r,   r.   rR   rJ   r0   r1   r   r   r   r   check_2d8  s"    




zConstructorBaseTest.check_2dc              	   C   s:   t |}| t}|  W 5 Q R X | dt|j dS )zAChecks that pyfunc will error, not segfaulting due to array size.zarray is too bigN)r$   r   r   r   r   r   )r+   r,   r.   er   r   r   check_alloc_sizeM  s    z$ConstructorBaseTest.check_alloc_sizeN)r3   r4   r5   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                    s   t t|   tj| _d S r   )superr   setUpr   zerosr,   r+   	__class__r   r   r   Z  s    zTestNdZeros.setUpc                 C   s   t j|| d S r   r   r)   r*   r+   r1   r0   r   r   r   r   ^  s    zTestNdZeros.check_result_valuec                    s    | j   fdd}| | d S )Nc                      s    dS Nr   r   r   r,   r   r   funcc  s    z!TestNdZeros.test_0d.<locals>.func)r,   r   r+   r   r   r   r   test_0da  s    zTestNdZeros.test_0dc                    s    | j   fdd}| | d S )Nc                    s    | S r   r   rJ   r   r   r   r   i  s    z!TestNdZeros.test_1d.<locals>.funcr,   r   r   r   r   r   test_1dg  s    zTestNdZeros.test_1dc                    s    | j   fdd}| | d S )Nc                    s    | t jS r   r   rQ   r   r   r   r   r   o  s    z'TestNdZeros.test_1d_dtype.<locals>.funcr   r   r   r   r   test_1d_dtypem  s    zTestNdZeros.test_1d_dtypec                    s,   | j td  fdd}| | d S )NrQ   c                    s
   |  S r   r   r   Z_dtyper,   r   r   r   w  s    z0TestNdZeros.test_1d_dtype_instance.<locals>.func)r,   r   r'   r   r   r   r   r   test_1d_dtype_instances  s    
z"TestNdZeros.test_1d_dtype_instancec                    s<   | j d  fdd}| | fdd}| | d S )NrQ   c                    s
   |  S r   r   r   r   r   r   r   ~  s    z+TestNdZeros.test_1d_dtype_str.<locals>.funcc                    s
    | dS )N
complex128r   r   r   r   r   r     s    r   r   r   r   r   test_1d_dtype_str{  s    
zTestNdZeros.test_1d_dtype_strc                    s<   | j d  fdd}| | fdd}| | d S )Ni4c                    s
   |  S r   r   r   r   r   r   r     s    z@TestNdZeros.test_1d_dtype_str_alternative_spelling.<locals>.funcc                    s
    | dS )Nc8r   r   r   r   r   r     s    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                    s
   |  S r   r   r   r   r   r   r     s    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              	      s`   | j  t fdd}| t}|dd W 5 Q R X t|j}d| j j d}| || d S )Nc                    s
    | |S r   r   rJ   dtr   r   r   r     s    z5TestNdZeros.test_1d_dtype_non_const_str.<locals>.funcru   rQ   If np.0 dtype is a string it must be a string constant.)r,   r   r   r   r   r   r3   r   r+   r   r   excstrmsgr   r   r   test_1d_dtype_non_const_str  s    
z'TestNdZeros.test_1d_dtype_non_const_strc              	      sN   | j  t fdd}| t}|d W 5 Q R X t|j}| d| d S )Nc                    s
    | dS NZABCDEFr   r   r   r   r   r     s    z3TestNdZeros.test_1d_dtype_invalid_str.<locals>.funcru   'Invalid NumPy dtype specified: 'ABCDEF')r,   r   r   r   r   r   r   r+   r   r   r   r   r   r   test_1d_dtype_invalid_str  s    
z%TestNdZeros.test_1d_dtype_invalid_strc                    s    | j   fdd}| | d S )Nc                    s    | |fS r   r   rR   rJ   r   r   r   r     s    z!TestNdZeros.test_2d.<locals>.funcr,   r   r   r   r   r   test_2d  s    zTestNdZeros.test_2dc              	      sr   | j   fdd}| |  fdd}| | tjrnt fdd}| t |tdd W 5 Q R X d S )	Nc                    s    t | t |fS r   )r   int16rQ   r   r   r   r   func1  s    z/TestNdZeros.test_2d_shape_dtypes.<locals>.func1c                    s    t | t |fS r   )r   int64int8r   r   r   r   func2  s    z/TestNdZeros.test_2d_shape_dtypes.<locals>.func2c                    s    | |fS r   r   r   r   r   r   <lambda>      z2TestNdZeros.test_2d_shape_dtypes.<locals>.<lambda>        rB   )	r,   r   r   	IS_32BITSr$   r   r   r   r   r+   r   r   r.   r   r   r   test_2d_shape_dtypes  s    

z TestNdZeros.test_2d_shape_dtypesc                    s    | j   fdd}| | d S )Nc                    s    | |ft jdS Nr_   )r   	complex64r   r   r   r   r     s    z-TestNdZeros.test_2d_dtype_kwarg.<locals>.funcr   r   r   r   r   test_2d_dtype_kwarg  s    zTestNdZeros.test_2d_dtype_kwargc                    s    | j   fdd}| | d S )Nc                    s    | |fddS )Nr   r_   r   r   r   r   r   r     s    z1TestNdZeros.test_2d_dtype_str_kwarg.<locals>.funcr   r   r   r   r   test_2d_dtype_str_kwarg  s    z#TestNdZeros.test_2d_dtype_str_kwargc                    s    | j   fdd}| | d S )Nc                    s    | |fddS )Nr   r_   r   r   r   r   r   r     s    zFTestNdZeros.test_2d_dtype_str_kwarg_alternative_spelling.<locals>.funcr   r   r   r   r   ,test_2d_dtype_str_kwarg_alternative_spelling  s    z8TestNdZeros.test_2d_dtype_str_kwarg_alternative_spellingc                    sV   | j  tjj} fdd}| |d|d > tj | |d|d > dftj d S )Nc                    s    fddS )Nc                      s
    S r   r   r   )r'   r,   rD   r   r   r     r   z?TestNdZeros.test_alloc_size.<locals>.gen_func.<locals>.<lambda>r   rD   r'   r   )r'   rD   r   gen_func  s    z-TestNdZeros.test_alloc_size.<locals>.gen_funcrB   r[   r   @   )r,   r   intpbitwidthr   r   r+   widthr   r   r   r   test_alloc_size  s
    zTestNdZeros.test_alloc_size)r3   r4   r5   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r   r   r   r   r   X  s"   r   c                       s.   e Zd Z fddZej fddZ  ZS )
TestNdOnesc                    s   t t|   tj| _d S r   )r   r  r   r   rc   r,   r   r   r   r   r     s    zTestNdOnes.setUpc                    s   t    d S r   )r   r   r   r   r   r   r     s    z-TestNdOnes.test_1d_dtype_str_structured_dtype)r3   r4   r5   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   s   t j|| d S r   r   r   r   r   r   r     s    zTestNdFull.check_result_valuec                 C   s   dd }|  | d S )Nc                   S   s   t ddS )Nr         @r   fullr   r   r   r   r     s    z TestNdFull.test_0d.<locals>.func)r   r   r   r   r   r     s    zTestNdFull.test_0dc                 C   s   dd }|  | d S )Nc                 S   s   t | dS Nr  r  r   r   r   r   r     s    z TestNdFull.test_1d.<locals>.funcr   r   r   r   r   r     s    zTestNdFull.test_1dc                 C   s   dd }|  | d S )Nc                 S   s   t | dt jS r	  )r   r  bool_r   r   r   r   r     s    z&TestNdFull.test_1d_dtype.<locals>.funcr
  r   r   r   r   r     s    zTestNdFull.test_1d_dtypec                    s$   t d  fdd}| | d S )Nboolc                    s   t | d S r	  r  r   r_   r   r   r   
  s    z/TestNdFull.test_1d_dtype_instance.<locals>.func)r   r'   r   r   r   r_   r   r     s    
z!TestNdFull.test_1d_dtype_instancec                 C   s   dd }|  | d S )Nc                 S   s   t | ddS Nr  r  r  r   r   r   r   r     s    z*TestNdFull.test_1d_dtype_str.<locals>.funcr
  r   r   r   r   r     s    zTestNdFull.test_1d_dtype_strc                 C   s   dd }|  | d S )Nc                 S   s   t | ddS )Nr  ?r  r   r   r   r   r     s    z?TestNdFull.test_1d_dtype_str_alternative_spelling.<locals>.funcr
  r   r   r   r   r     s    z1TestNdFull.test_1d_dtype_str_alternative_spellingc              	   C   sL   t dd }| t}|ddd W 5 Q R X t|j}d}| || d S )Nc                 S   s   t | ||S r   r  )rJ   fvr   r   r   r   r     s    z4TestNdFull.test_1d_dtype_non_const_str.<locals>.funcru   r  rQ   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   sF   t dd }| t}|dd W 5 Q R X t|j}| d| d S )Nc                 S   s   t | |dS r   r  )rJ   r  r   r   r   r   )  s    z2TestNdFull.test_1d_dtype_invalid_str.<locals>.funcr  r  r   r  r   r   r   r   r   '  s    

z$TestNdFull.test_1d_dtype_invalid_strc                 C   s   dd }|  | d S )Nc                 S   s   t | |fdS r	  r  r   r   r   r   r   4  s    z TestNdFull.test_2d.<locals>.funcr   r   r   r   r   r   3  s    zTestNdFull.test_2dc                 C   s   dd }|  | d S )Nc                 S   s   t j| |fdt jdS )Ny      ?      @r_   )r   r  r   r   r   r   r   r   9  s    z,TestNdFull.test_2d_dtype_kwarg.<locals>.funcr  r   r   r   r   r   8  s    zTestNdFull.test_2d_dtype_kwargc                 C   s:   dd }|  | dd }|  | dd }|  | d S )Nc                 S   s   t | |ft dS r   )r   r  rQ   r   r   r   r   r   ?  s    z0TestNdFull.test_2d_dtype_from_type.<locals>.funcc                 S   s   t | |ft dS r   )r   r  r   r   r   r   r   r   D  s    c                 S   s   t j| |fdt jdS )NrB   r_   )r   r  r   r   r   r   r   r   I  s    r  r   r   r   r   test_2d_dtype_from_type=  s    

z"TestNdFull.test_2d_dtype_from_typec              	   C   s`   dd }|  | dd }|  | tjr\tdd }| t |tdd W 5 Q R X d S )	Nc                 S   s   t t | t |fdS r	  )r   r  r   rQ   r   r   r   r   r   O  s    z.TestNdFull.test_2d_shape_dtypes.<locals>.func1c                 S   s   t t | t |fdS r	  )r   r  r   r   r   r   r   r   r   S  s    z.TestNdFull.test_2d_shape_dtypes.<locals>.func2c                 S   s   t | |fdS r	  r  r   r   r   r   r   X  r   z1TestNdFull.test_2d_shape_dtypes.<locals>.<lambda>r   rB   )r   r   r   r$   r   r   r   r   r   r   r   r   r   M  s    

zTestNdFull.test_2d_shape_dtypesc                 C   sH   t jj}dd }| |d|d > d | |d|d > dfd d S )Nc                    s    fddS )Nc                      s   t  S r   r  r   rD   valuer   r   r   _  r   z>TestNdFull.test_alloc_size.<locals>.gen_func.<locals>.<lambda>r   r  r   r  r   r   ^  s    z,TestNdFull.test_alloc_size.<locals>.gen_funcrB   r[   r   r   )r   r   r   r   r   r   r   r   r   \  s    zTestNdFull.test_alloc_sizeN)r3   r4   r5   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r   r   r    s   r  c                   @   s   e Zd Zdd Zdd ZdS )ConstructorLikeBaseTestc              	   C   sB   z| d W n. ttfk
r<   d|jj }| | Y nX d S )Nr=      x)rG   	TypeErrorr   r'   rN   )r+   r9   Z
fill_valuer   r   r   mutate_arrayg  s
    z$ConstructorLikeBaseTest.mutate_arrayc              
      s    fdd}t ddd|}t dD ]~}|dkrP|dd  d}n
||}|| |jdkr~||d d d	  d
|jd< t d|d< W 5 Q R X || q0||d  d S )Nc                    sn   | } | } |j|j  |j|j || || | | tj|| d S r   )	r%   r&   r'   r(   r   r  r   r)   r*   )r9   r0   r1   r.   r,   r+   r   r   	check_arrp  s    

z5ConstructorLikeBaseTest.check_like.<locals>.check_arrr   ru      )r  r   )rB   r[   rL   )rL   rB   r[   r   r   r   r[   FZ	WRITEABLErB   )	r   linspaceastyper$   ry   ndimflagsr   r   )r+   r,   r'   r  origrD   r9   r   r  r   
check_likeo  s    



z"ConstructorLikeBaseTest.check_likeN)r3   r4   r5   r  r"  r   r   r   r   r  e  s   r  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                    s   t t|   tj| _d S r   )r   r#  r   r   r   r,   r   r   r   r   r     s    zTestNdEmptyLike.setUpc                 C   s   d S r   r   r   r   r   r   r     s    z"TestNdEmptyLike.check_result_valuec                    s$   | j   fdd}| |tj d S )Nc                    s    | S r   r   r@   r   r   r   r     s    z'TestNdEmptyLike.test_like.<locals>.funcr,   r"  r   rE   r   r   r   r   	test_like  s    zTestNdEmptyLike.test_likec                    s<   t dt jfdt jfg}| j  fdd}| || d S )Nr   r   c                    s    | S r   r   r@   r   r   r   r     s    z2TestNdEmptyLike.test_like_structured.<locals>.func)r   r'   r   rd   r,   r"  r+   r'   r   r   r   r   test_like_structured  s    z$TestNdEmptyLike.test_like_structuredc                    s$   | j   fdd}| |tj d S )Nc                    s    | t jS r   r   r@   r   r   r   r     s    z-TestNdEmptyLike.test_like_dtype.<locals>.funcr$  r   r   r   r   test_like_dtype  s    zTestNdEmptyLike.test_like_dtypec                    s0   t d | j fdd}| |t j d S )NrQ   c                    s
   |  S r   r   r@   r'   r,   r   r   r     s    z6TestNdEmptyLike.test_like_dtype_instance.<locals>.func)r   r'   r,   r"  rE   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                    s
   |  S r   r   r@   r)  r   r   r     s    z8TestNdEmptyLike.test_like_dtype_structured.<locals>.func)r   r'   r   rd   r,   r"  rE   r   r   r)  r   test_like_dtype_structured  s    z*TestNdEmptyLike.test_like_dtype_structuredc                    s$   | j   fdd}| |tj d S )Nc                    s    | t jdS r   r   r@   r   r   r   r     s    z3TestNdEmptyLike.test_like_dtype_kwarg.<locals>.funcr$  r   r   r   r   test_like_dtype_kwarg  s    z%TestNdEmptyLike.test_like_dtype_kwargc                    s$   | j   fdd}| |tj d S )Nc                    s    | ddS )NrQ   r_   r   r@   r   r   r   r     s    z7TestNdEmptyLike.test_like_dtype_str_kwarg.<locals>.funcr$  r   r   r   r   test_like_dtype_str_kwarg  s    z)TestNdEmptyLike.test_like_dtype_str_kwargc                    s$   | j   fdd}| |tj d S )Nc                    s    | ddS )Nr   r_   r   r@   r   r   r   r     s    zLTestNdEmptyLike.test_like_dtype_str_kwarg_alternative_spelling.<locals>.funcr$  r   r   r   r   .test_like_dtype_str_kwarg_alternative_spelling  s    z>TestNdEmptyLike.test_like_dtype_str_kwarg_alternative_spellingc              	      sz   | j  t fdd}| t}|tdd W 5 Q R X t|j}d| j j d}| 	|| | 	d
 j| d S )Nc                    s
    | |S r   r   r   r   r   r   r     s    z;TestNdEmptyLike.test_like_dtype_non_const_str.<locals>.funcrT   rQ   r   r   z'{}(array(float64, 1d, C), unicode_type))r,   r   r   r   r   rc   r   r   r3   r   r   r   r   r   r   test_like_dtype_non_const_str  s    

z-TestNdEmptyLike.test_like_dtype_non_const_strc              	      sT   | j  t fdd}| t}|td W 5 Q R X t|j}| d| d S )Nc                    s
    | dS r   r   r   r   r   r   r     s    z9TestNdEmptyLike.test_like_dtype_invalid_str.<locals>.funcrT   r   )	r,   r   r   r   r   rc   r   r   r   r   r   r   r   test_like_dtype_invalid_str  s    
z+TestNdEmptyLike.test_like_dtype_invalid_str)r3   r4   r5   r   r   r%  r'  r(  r*  r+  r,  r-  r.  r/  r0  r  r   r   r   r   r#    s   r#  c                       s<   e Zd Z fddZdd Z fddZ fddZ  ZS )	TestNdZerosLikec                    s   t t|   tj| _d S r   )r   r1  r   r   Z
zeros_liker,   r   r   r   r   r     s    zTestNdZerosLike.setUpc                 C   s   t j|| d S r   r   r   r   r   r   r     s    z"TestNdZerosLike.check_result_valuec                    s   t t|   d S r   )r   r1  r'  r   r   r   r   r'    s    z$TestNdZerosLike.test_like_structuredc                    s   t t|   d S r   )r   r1  r+  r   r   r   r   r+    s    z*TestNdZerosLike.test_like_dtype_structured)r3   r4   r5   r   r   r'  r+  r  r   r   r   r   r1    s   r1  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   r2  r   r   Z	ones_liker,   Zexpected_valuer   r   r   r   r     s    zTestNdOnesLike.setUpc                    s   t t|   d S r   )r   r2  r'  r   r   r   r   r'    s    z#TestNdOnesLike.test_like_structuredc                    s   t t|   d S r   )r   r2  r+  r   r   r   r   r+    s    z)TestNdOnesLike.test_like_dtype_structured)	r3   r4   r5   r   r  r  r'  r+  r  r   r   r   r   r2    s
   r2  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   s   t j|| d S r   r   r   r   r   r   r     s    z!TestNdFullLike.check_result_valuec                 C   s   dd }|  |tj d S )Nc                 S   s   t | dS )N      @r   	full_liker@   r   r   r   r     s    z&TestNdFullLike.test_like.<locals>.funcr"  r   rE   r   r   r   r   r%    s    zTestNdFullLike.test_likec                 C   s2   t dt jfdt jfg}dd }| || d S )Nr   r   c                 S   s   t | dS r	  r5  r@   r   r   r   r     s    z1TestNdFullLike.test_like_structured.<locals>.func)r   r'   r   rd   r"  r&  r   r   r   r'    s    z#TestNdFullLike.test_like_structuredc                 C   s   dd }|  |tj d S )Nc                 S   s   t | dt jS r	  r   r6  r  r@   r   r   r   r   $  s    z,TestNdFullLike.test_like_dtype.<locals>.funcr7  r   r   r   r   r(  #  s    zTestNdFullLike.test_like_dtypec                    s(   t d  fdd}| |t j d S )Nr  c                    s   t | d S r	  r5  r@   r_   r   r   r   *  s    z5TestNdFullLike.test_like_dtype_instance.<locals>.func)r   r'   r"  rE   r   r   r_   r   r*  (  s    
z'TestNdFullLike.test_like_dtype_instancec                 C   s   dd }|  |tj d S )Nc                 S   s   t j| dt jdS )Nr  r_   r8  r@   r   r   r   r   /  s    z2TestNdFullLike.test_like_dtype_kwarg.<locals>.funcr7  r   r   r   r   r,  .  s    z$TestNdFullLike.test_like_dtype_kwargc                 C   s   dd }|  |tj d S )Nc                 S   s   t | ddS r  r5  r@   r   r   r   r   4  s    z6TestNdFullLike.test_like_dtype_str_kwarg.<locals>.funcr7  r   r   r   r   r-  3  s    z(TestNdFullLike.test_like_dtype_str_kwargc                 C   s   dd }|  |tj d S )Nc                 S   s   t j| dddS )Nr  r  r_   r5  r@   r   r   r   r   9  s    zKTestNdFullLike.test_like_dtype_str_kwarg_alternative_spelling.<locals>.funcr7  r   r   r   r   r.  8  s    z=TestNdFullLike.test_like_dtype_str_kwarg_alternative_spellingc              	   C   sR   t dd }| t}|tddd W 5 Q R X t|j}d}| || d S )Nc                 S   s   t | ||S r   r5  )r9   r  r   r   r   r   r   ?  s    z@TestNdFullLike.test_like_dtype_non_const_str_kwarg.<locals>.funcrL   r  rQ   z?If np.full_like dtype is a string it must be a string constant.r   r   r   r   rc   r   r   r   r   r   r   r   #test_like_dtype_non_const_str_kwarg=  s    

z2TestNdFullLike.test_like_dtype_non_const_str_kwargc              	   C   sL   t dd }| t}|tdd W 5 Q R X t|j}| d| d S )Nc                 S   s   t | |dS r   r5  )r9   r  r   r   r   r   M  s    z8TestNdFullLike.test_like_dtype_invalid_str.<locals>.funcrT   g333333@r   r9  r   r   r   r   r0  K  s    

z*TestNdFullLike.test_like_dtype_invalid_strN)r3   r4   r5   r   r%  r  r  r'  r(  r*  r,  r-  r.  r:  r0  r   r   r   r   r3    s   
r3  c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestNdIdentityc                 C   s   |  |dg d S )NrL   r2   r+   r,   r   r   r   check_identityZ  s    zTestNdIdentity.check_identityc                 C   s   dd }|  | d S )Nc                 S   s
   t | S r   r   identityr   r   r   r   r   ^  s    z*TestNdIdentity.test_identity.<locals>.func)r?  r   r   r   r   test_identity]  s    zTestNdIdentity.test_identityc                    s:   t jt jt jt ddfD ]  fdd}| | qd S )Nr  r  c                    s   t |  S r   r@  r   r_   r   r   r   e  s    z0TestNdIdentity.test_identity_dtype.<locals>.func)r   r   r   r  r'   r?  r   r   r_   r   test_identity_dtypeb  s
    z"TestNdIdentity.test_identity_dtypec              	   C   sJ   t dd }| t}|dd W 5 Q R X t|j}d}| || d S )Nc                 S   s   t | |S r   r@  r   r   r   r   r   k  s    z@TestNdIdentity.test_like_dtype_non_const_str_kwarg.<locals>.funcrT   rQ   z>If np.identity dtype is a string it must be a string constant.r  r   r   r   r   r:  i  s    

z2TestNdIdentity.test_like_dtype_non_const_str_kwargN)r3   r4   r5   r?  rB  rC  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   s   dd }|  |ddg d S )Nc                 S   s
   t | S r   r   eyer   r   r   r   r   |  s    z"TestNdEye.test_eye_n.<locals>.funcrB   r<  r=  r   r   r   r   
test_eye_n{  s    zTestNdEye.test_eye_nc                 C   s8   d t jt dfD ] }|fdd}| |ddg qd S )NrB   c                 S   s   t j| |dS r   rE  )rJ   r'   r   r   r   r     s    z(TestNdEye.test_eye_n_dtype.<locals>.funcrG  r<  )r   r   r   r2   )r+   r   r   r   r   r   test_eye_n_dtype  s    zTestNdEye.test_eye_n_dtypec                 C   s   dd }|  |dddg d S )Nc                 S   s   t | |S r   rE  rJ   rR   r   r   r   r     s    z$TestNdEye.test_eye_n_m.<locals>.funcrB   r[   rL   r[   )r   rL   r=  r   r   r   r   test_eye_n_m  s    zTestNdEye.test_eye_n_mc              	   C   s   |  |ddddddg d S )N)rB   r[   r   )rL   rT   rB   )rL   rT   r   )rT   rL   )rT   rL   )rT   rL   ru   r=  r   r   r   r   check_eye_n_m_k  s    zTestNdEye.check_eye_n_m_kc                 C   s   dd }|  | d S )Nc                 S   s   t | ||S r   rE  rJ   rR   rZ   r   r   r   r     s    z&TestNdEye.test_eye_n_m_k.<locals>.funcrP  r   r   r   r   test_eye_n_m_k  s    zTestNdEye.test_eye_n_m_kc                 C   s   dd }|  | d S )Nc                 S   s   t j| ||t jdS N)NMrZ   r'   )r   rF  r   rQ  r   r   r   r     s    z,TestNdEye.test_eye_n_m_k_dtype.<locals>.funcrR  r   r   r   r   test_eye_n_m_k_dtype  s    zTestNdEye.test_eye_n_m_k_dtypec                    s$   t d  fdd}| | d S )Nr   c                    s   t j| || dS rT  rE  rQ  r_   r   r   r     s    z5TestNdEye.test_eye_n_m_k_dtype_instance.<locals>.func)r   r'   rP  r   r   r_   r   test_eye_n_m_k_dtype_instance  s    
z'TestNdEye.test_eye_n_m_k_dtype_instanceN)
r3   r4   r5   rH  rI  rM  rP  rS  rW  rX  r   r   r   r   rD  y  s   rD  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 dddg}t dddgg}t |}|||g| _t ddd}t ddd}||g| _dd }|| _t|| _	dd	d
}|| _
t|| _d S )NrB   r[   rL      rT   c                 S   s
   t | S r   r   Zdiag)qr   r   r   r     s    zTestNdDiag.setUp.<locals>.funcr   c                 S   s   t j| |dS )NrZ   r[  )r\  rZ   r   r   r   
func_kwarg  s    z$TestNdDiag.setUp.<locals>.func_kwarg)r   )r   arrayZ	transposevectorsrM   ry   	matriciespyr$   jitpy_kwjit_kw)r+   vZhvvvZa3x4Za4x3r   r^  r   r   r   r     s    



zTestNdDiag.setUpc                 O   sF   |||}|||}|  |j|j |  |j|j tj|| d S r   )r%   r&   r'   r   r)   r*   )r+   r,   Znrtfuncr/   kwargsr0   Zcomputedr   r   r   
check_diag  s
    

zTestNdDiag.check_diagc                 C   s"   | j D ]}| | j| j| qd S r   )r`  ri  rb  rc  r+   dr   r   r   test_diag_vect_create  s    
z TestNdDiag.test_diag_vect_createc                 C   s6   t ddD ]&}| jD ]}| j| j| j||d qq
d S )Nirt   r]  )rI   r`  ri  rd  re  r+   rZ   rk  r   r   r   test_diag_vect_create_kwarg  s    
z&TestNdDiag.test_diag_vect_create_kwargc                 C   s"   | j D ]}| | j| j| qd S r   )ra  ri  rb  rc  rj  r   r   r   test_diag_extract  s    
zTestNdDiag.test_diag_extractc                 C   s6   t ddD ]&}| jD ]}| j| j| j||d qq
d S )NrT   r]  )rI   ra  ri  rd  re  rm  r   r   r   test_diag_extract_kwarg  s    
z"TestNdDiag.test_diag_extract_kwargc              	   C   s   t dggg}t| j}| t |  W 5 Q R X | t || W 5 Q R X | t t| j}||dd W 5 Q R X d S )N      ?rL   r]  )r   r_  r$   rb  r   r  r   rd  )r+   rk  r.   Zdfuncr   r   r   test_error_handling  s    

zTestNdDiag.test_error_handlingc              	   C   s2   t | j}d}| t|}|d  W 5 Q R X d S )Nz'.*The argument "v" must be array-like.*)r$   rb  assertRaisesRegexr   )r+   r.   r   r   r   r   r   test_bad_shape  s    
zTestNdDiag.test_bad_shapeN)r3   r4   r5   r   ri  rl  rn  ro  rq  rs  ru  r   r   r   r   rY    s   	rY  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestLinspacec              	   C   s$   dd }|  |ddddddg d S )	Nc                 S   s   t | |S r   r   r  rJ  r   r   r   r,     s    z,TestLinspace.test_linspace_2.<locals>.pyfunc)r   rT   )rB   r   )            @)                    @      @)r[   rB   )      ?      ?              ?r=  r>  r   r   r   test_linspace_2  s     zTestLinspace.test_linspace_2c              
   C   s&   dd }|  |ddddddd	g d S )
Nc                 S   s   t | ||S r   rw  rJ   rR   rY   r   r   r   r,     s    z,TestLinspace.test_linspace_3.<locals>.pyfunc)r   rT   	   )rB   rT   rL   )rx  ry  r   )rz  r{  rw   )r[   rB   r   )r|  r}  ru   )rB   g}Ô%ITrB   r=  r>  r   r   r   test_linspace_3  s      zTestLinspace.test_linspace_3c                 C   s8   t dd }d\}}}| |||||||| d S )Nc                 S   s   t | ||S r   rw  r  r   r   r   rA     s    z0TestLinspace.test_linspace_accuracy.<locals>.foo)g        rr  r   )r$   assertPreciseEqualZpy_func)r+   rA   rJ   rR   rY   r   r   r   test_linspace_accuracy  s    

z#TestLinspace.test_linspace_accuracyN)r3   r4   r5   r~  r  r  r   r   r   r   rv    s   rv  c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestNpyEmptyKeywordc                    s\    fdd}dddg}t |}|D ]4}||}||}| |j|j | |j|j q"d S )Nc                    s   t j|  dS r   r>   rD   r_   r   r   r,     s    z7TestNpyEmptyKeyword._test_with_dtype_kw.<locals>.pyfuncrB   ru   r  r$   r%   r'   rD   r+   r'   r,   Zshapesr.   sr0   rp   r   r_   r   _test_with_dtype_kw
  s    
z'TestNpyEmptyKeyword._test_with_dtype_kwc                 C   s,   t jt jt jt dfD ]}| | qd S Nr   )r   rQ   rd   r   r'   r  r+   r'   r   r   r   test_with_dtype_kws  s    z'TestNpyEmptyKeyword.test_with_dtype_kwsc                    s\    fdd}dddg}t |}|D ]4}||}||}| |j|j | |j|j q"d S )Nc                    s   t j|  dS )Nr   r>   r  r_   r   r   r,     s    zATestNpyEmptyKeyword._test_with_shape_and_dtype_kw.<locals>.pyfuncrB   ru   r  r  r  r   r_   r   _test_with_shape_and_dtype_kw  s    
z1TestNpyEmptyKeyword._test_with_shape_and_dtype_kwc                 C   s,   t jt jt jt dfD ]}| | qd S r  )r   rQ   rd   r   r'   r  r  r   r   r   test_with_shape_and_dtype_kws(  s    z1TestNpyEmptyKeyword.test_with_shape_and_dtype_kwsc              	   C   s0   dd }t |}| t |  W 5 Q R X d S )Nc                   S   s   t  S r   r>   r   r   r   r   r,   .  s    z6TestNpyEmptyKeyword.test_empty_no_args.<locals>.pyfunc)r$   r   r   )r+   r,   r.   r   r   r   test_empty_no_args,  s    z&TestNpyEmptyKeyword.test_empty_no_argsN)r3   r4   r5   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   s
   t | S r   r   r_  argr   r   r   r,   <  s    z#TestNpArray.test_0d.<locals>.pyfuncr=   r_   ry  )r$   r  r   r_  r   r+   r,   r.   rp   r   r   r   r   ;  s    zTestNpArray.test_0dc                 C   s   dd }|  |ddg d S )Nc                 S   s   t j| t jdS r   )r   r_  r   r  r   r   r   r,   F  s    z.TestNpArray.test_0d_with_dtype.<locals>.pyfunc)r=   )r4  r=  r>  r   r   r   test_0d_with_dtypeE  s    zTestNpArray.test_0d_with_dtypec                 C   st   dd }t |}|dddg}| |tdddg |d}| |tdddg |d	}| |td	 d S )
Nc                 S   s
   t | S r   r  r  r   r   r   r,   L  s    z#TestNpArray.test_1d.<locals>.pyfuncr[   rL   r=   )rr                @r=   rr  r  r   )r$   r  r   r   r_  rE   r  r   r   r   r   K  s    zTestNpArray.test_1dc                 C   s,   dd }|  |ddgfddgfddg d S )	Nc                 S   s   t j| t jdS r   )r   r_  rd   r  r   r   r   r,   [  s    z.TestNpArray.test_1d_with_dtype.<locals>.pyfuncr[   r=   r4  rr  )rB   r4  r=   r   r=  r>  r   r   r   test_1d_with_dtypeZ  s    zTestNpArray.test_1d_with_dtypec                 C   s,   dd }|  |ddgfddgfddg d S )	Nc                 S   s   t j| ddS )Nrd   r_   r  r  r   r   r   r,   f  s    z2TestNpArray.test_1d_with_str_dtype.<locals>.pyfuncr[   r=   r4  rr  r  r  r=  r>  r   r   r   test_1d_with_str_dtypee  s    z"TestNpArray.test_1d_with_str_dtypec              	   C   sJ   t dd }| t}|dd W 5 Q R X t|j}d}| || d S )Nc                 S   s   t j| |dS r   r  )r  r   r   r   r   r   r  s    z:TestNpArray.test_1d_with_non_const_str_dtype.<locals>.func)ru   rL   rQ   z;If np.array dtype is a string it must be a string constant.r  r   r   r   r    test_1d_with_non_const_str_dtypep  s    

z,TestNpArray.test_1d_with_non_const_str_dtypec                 C   s  dd }t |}|ddg}| |tddgddgg |d	d
g}| |tddgddgg |ddgddgf}| |tddgddgg |ddgddgf}| |tddgddgg |d}| |tddgddgg |d}| |td d S )Nc                 S   s
   t | S r   r  r  r   r   r   r,     s    z#TestNpArray.test_2d.<locals>.pyfuncrK  rL   rT   rB   r[   rL   rT   rB   ry  rL   r  ry  r  r4  ))      ?r[   )r4  r  r  )r   r   )r$   r  r   r   rE   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   s   t j| t jdS r   )r   r_  rQ   r  r   r   r   r,     s    z.TestNpArray.test_2d_with_dtype.<locals>.pyfuncr  r  rB   r[   rL   rT   )r$   r  r   rQ   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 5 Q R X |d  |tdtd	gf W 5 Q R X |d
< tddg}tjd|dd }|dtd|ff W 5 Q R X d S )Nc                 S   s
   t | S r   r  r  r   r   r   r,     s    z'TestNpArray.test_raises.<locals>.pyfuncc              	   3   s2     t}d V  W 5 Q R X  | 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 sequencerr  zOtype Tuple(int64, reflected list(int64)<iv=None>) does not have a regular shaperB   r[   zrcannot convert Tuple(int64, Record(a[type=int32;offset=0],b[type=float32;offset=4];8;False)) to a homogeneous type)r   r   )r   Zf4r_   r   rK  )r$   
contextlibcontextmanagerr   r_  r   r'   r   )r+   r,   r.   r  stvalr   r   r   test_raises  s    

$zTestNpArray.test_raisesc              	   C   s4   t dd }d}| t|}|d  W 5 Q R X d S )Nc                 S   s
   t | S r   r  )objr   r   r   r     s    z(TestNpArray.test_bad_array.<locals>.funcz,.*The argument "object" must be array-like.*r   rt  r   r+   r   r   r   r   r   r   test_bad_array  s
    
zTestNpArray.test_bad_arrayc              	   C   s6   t dd }d}| t|}|dd W 5 Q R X d S )Nc                 S   s   t | |S r   r  )r  r   r   r   r   r     s    z(TestNpArray.test_bad_dtype.<locals>.funcz>.*The argument "dtype" must be a data-type if it is provided.*ru   rT   r  r  r   r   r   test_bad_dtype  s
    
zTestNpArray.test_bad_dtypeN)r3   r4   r5   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   s^   t dd}|d }|d jdd}|d d d d }|d dd d df }|||||fS N   )rT   rL   r[   rt   F)orderr   .r   rM   ry   r   r+   r   r   r   rk  r   r   r   r   
_3d_arrays  s    zTestNpConcatenate._3d_arraysc              	   c   s6   |  t}d V  W 5 Q R X | d| t|j d S )Nz*input sizes over dimension %d do not matchr   r   r   r   r   )r+   r   r   r   r   r   assert_invalid_sizes_over_dim  s
    
z/TestNpConcatenate.assert_invalid_sizes_over_dimc              
      s  t t  fddfdd} \}}}}}|||| |||| ||j|j|j ||j|j|j ||j|j|j ||j|j|j |dd  ||d d d dd ||d d dd f |dd |||d d d d dd f d	d |||tj|   d
D ]2}d  |dd  ||| W 5 Q R X q"dD ]:}d$  ||d d dd f || W 5 Q R X qZd S )Nc                    sB   |d| fD ]0}| |||d} | |||d} || qd S )Nr   r  )r   r   r   r   Zaxr0   rp   r  r   r   check  s    z(TestNpConcatenate.test_3d.<locals>.checkc                    s    t dD ]} | ||| qd S )NrL   r   r   )r  r   r   check_all_axes  s    z1TestNpConcatenate.test_3d.<locals>.check_all_axesrB   r   r   r   r[   )rB   r[   rN  r   )r   r[   r  r   )	r   r$   r  Tr  r   rE   r   r  )r+   r  r   r   r   rk  r   r   r   )r.   r  r,   r+   r   test_3d  s,    " &$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 5 Q R X d S )Nc                    s(   | ||} | ||} || d S r   r  )r   r   r   r0   rp   r  r   r   r    s    z0TestNpConcatenate.test_3d_no_axis.<locals>.checkrB   r   )r   r$   r  r  r   r  )r+   r  r   r   r   rk  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 5 Q R X | 
dt|j | 	 }|||| W 5 Q R X | 
dt|j | 	 }|||| W 5 Q R X | 
dt|j | 	 }||d| W 5 Q R X | 
d	t|j d S )
N   )rL   ru   r   r=   z8all the input arrays must have same number of dimensionsz(input arrays must have compatible dtypesz.zero-dimensional arrays cannot be concatenatedrB   %expecting a non-empty tuple of arrays)r   r$   r   rM   ry   r  r'   r   r_  assertTypingErrorr   r   r   )r+   r,   r.   r   r   r   rk  r   r   r   r   test_typing_errors5  s0    






z$TestNpConcatenate.test_typing_errorsN)r3   r4   r5   __doc__r  r  r  r  r  r  r  r   r   r   r   r    s   
2$r  r   z"this Numpy doesn't have np.stack()c                   @   s   e Zd ZdZdd Zejdd Zdd Zdd	 Z	d
d Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )TestNpStackz
    Tests for np.stack().
    c                 C   s^   t dd}|d }|d jdd}|d d d d }|d dd d df }|||||fS r  r  r  r   r   r   r  \  s    zTestNpStack._3d_arraysc              	   c   s2   |  t}d V  W 5 Q R X | dt|j d S )Nz)all input arrays must have the same shaper  )r+   r   r   r   r   assert_invalid_sizesd  s
    z TestNpStack.assert_invalid_sizesc                 C   s8   || }|| }|  |j|j | | |  d S r   )r%   rD   r  flatten)r+   r,   r.   r/   r0   rp   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  s    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  r  r   rE   )
r+   r,   r.   r  r  r   r   r   rk  r   r   )r.   r  r  r,   r+   r   check_3du  s    zTestNpStack.check_3dc           	   	   C   s^   |    |   |  \}}}}}|  * t| }||d d ||f|  W 5 Q R X d S )Nr   )assert_no_memory_leakr   r  r  next)	r+   r.   r  r   r   r   rk  r   r/   r   r   r   check_runtime_errors  s    

z TestNpStack.check_runtime_errorsc                 C   s2   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 )NrL   r  r   r   r   r   r   r    s    z.TestNpStack.test_3d.<locals>.generate_starargsN)r   r$   r  r  r+   r,   r.   r  r   r   r   r    s
    zTestNpStack.test_3dc                 C   s2   t }t|}dd }| ||| | || dS )z"
        stack(3d arrays)
        c                   s   s
   dV  d S r   r   r   r   r   r   r    s    z6TestNpStack.test_3d_no_axis.<locals>.generate_starargsN)r   r$   r  r  r  r   r   r   r    s
    zTestNpStack.test_3d_no_axisc                 C   sB   t }t|}td}td}td}| |||||f dS )z"
        stack(0d arrays)
        r=                TN)r   r$   r   r_  r  r+   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   s
   dV  d S r   r   r   r   r   r   r    s    z4TestNpStack.check_xxstack.<locals>.generate_starargsr=   r  TN)r  r   r_  r  )r+   r,   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 )Nru   r  rt   r   r   )r[   rT   r   )r   r$   r  r   rM   r  ry   r+   r,   r.   r   r   r   r   r   test_hstack  s    
zTestNpStack.test_hstackc                 C   s   t tfD ]v}t|}| || td}|d }| |||||f tdd}tddd }| |||||f qd S )Nru   rt   r  rL  r   )rT   r[   r   )r   r    r$   r  r   rM   r  ry   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 )Nru   rt   rZ  r  r   )r!   r$   r  r   rM   r  ry   r  r   r   r   test_dstack  s    
zTestNpStack.test_dstackc              	   C   s   t }t|}td}|d }tdd}| |||||f |   |   td}| 	  ||||f W 5 Q R X |d}| 	  ||||f W 5 Q R X d S )NrT   rt   rZ  rT   rL   r=   )rB   rB   rB   )
r"   r$   r   rM   ry   r  r  r   r_  r  r  r   r   r   test_column_stack  s    




zTestNpStack.test_column_stackc              
   C   sb   t ttttfD ]N}t|}tdd}| 	 }||d| W 5 Q R X | 
dt|j qd S )NrZ  r  rB   r  )r   r   r   r!   r"   r$   r   rM   ry   r  r   r   r   )r+   r,   r.   r   r   r   r   r   test_bad_arrays  s    
zTestNpStack.test_bad_arraysN)r3   r4   r5   r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r   r   r   r   r  V  s    

r  c                     sx   dd t  tjdtjddfdd}  fdd}t| }t|}t| t| d S )	Nc                 S   s    t |D ]}||  } }q| |fS )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                      s     d S r   r   r   )r,   r   r   ra   r   r   bench_pyfunc,  s    z+benchmark_refct_speed.<locals>.bench_pyfuncc                      s     d S r   r   r   )r.   r   r   ra   r   r   bench_cfunc/  s    z*benchmark_refct_speed.<locals>.bench_cfunc)r$   r   rx   r   Z	benchmarkprint)r  r  Zpython_timeZ
numba_timer   )r.   r,   r   r   ra   r   benchmark_refct_speed  s    

r  __main__):r  re   numpyr   rx   rer   rg   Znumba.core.errorsr   Znumbar   Z
numba.corer   r   r   Znumba.tests.supportr   r   r	   r
   r  r$   r   r   r   r   r   r   r    r!   r"   r#   r6   r<   r   r   r  r  objectr  r#  r1  r2  r3  r;  rD  rY  rv  r  r  r  Z
skipUnlesshasattrr  r  r3   mainr   r   r   r   <module>   sh      PG q.\G!,H0   H
