U
    9%e                     @   s  d dl mZ d dlmZ d dlZd dlZd dlmZm	Z	 d dl
mZmZmZmZ d dlmZ d dlmZ d dlmZmZ d d	lmZmZmZmZ e	 Zd
e_e	 Zd
e_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/d-d. Z0d/d0 Z1d1d2 Z2d3d4 Z3d5d6 Z4d7d8 Z5d9d: Z6d;d< Z7edQd=d>Z8d?d@ Z9dAdB Z:dRdDdEZ;dFdG Z<dHdI Z=dJdK Z>dLdM Z?G dNdO dOeeZ@eAdPkreB  dS )S    )partial)permutationsN)compile_isolatedFlags)jitnjit
from_dtypetypeof)numpy_version)TypingError)typeserrors)TestCaseMemoryLeakMixinCompilationCachetagTc                    s    fdd}|S )aP  Decorator for generic check functions.
        Iterates over 'pyfuncs_to_use', calling 'func' with the iterated
        item as first argument. Example:

        @from_generic(numpy_array_reshape, array_reshape)
        def check_only_shape(pyfunc, arr, shape, expected_shape):
            # Only check Numba result to avoid Numpy bugs
            self.memory_leak_setup()
            got = generic_run(pyfunc, arr, shape)
            self.assertEqual(got.shape, expected_shape)
            self.assertEqual(got.size, arr.size)
            del got
            self.memory_leak_teardown()
    c                    s    fdd}|S )Nc                     s    fddD S )Nc                    s   g | ]}|f qS  r   ).0pyfunc)argsfunckwargsr   b/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/numba/tests/test_array_manipulation.py
<listcomp>'   s     zCfrom_generic.<locals>.decorator.<locals>.result.<locals>.<listcomp>r   r   r   )r   pyfuncs_to_user   r   result&   s    z/from_generic.<locals>.decorator.<locals>.resultr   )r   r   r   )r   r   	decorator%   s    zfrom_generic.<locals>.decoratorr   )r   r   r   r   r   from_generic   s    r   c                 C   s
   |  |S N)reshapearrZnewshaper   r   r   array_reshape,   s    r$   c                 C   s   t | |S r    )npr!   r"   r   r   r   numpy_array_reshape0   s    r&   c                 C   s   t | |S r    r%   broadcast_to)r#   shaper   r   r   numpy_broadcast_to4   s    r*   c                  G   s
   t j|  S r    )r%   Zbroadcast_shapesr   r   r   r   numpy_broadcast_shapes8   s    r,   c                  G   s
   t j|  S r    )r%   Zbroadcast_arraysr+   r   r   r   numpy_broadcast_arrays<   s    r-   c                 C   s   t | || S r    r'   )r#   r)   idxr   r   r   numpy_broadcast_to_indexing@   s    r/   c                 C   s   |   S r    )flattenar   r   r   flatten_arrayD   s    r3   c                 C   s   |   S r    ravelr1   r   r   r   ravel_arrayH   s    r6   c                 C   s
   |   jS r    )r5   sizer1   r   r   r   ravel_array_sizeL   s    r8   c                 C   s
   t | S r    )r%   r5   r1   r   r   r   numpy_ravel_arrayP   s    r9   c                 C   s   |   S r    	transposer1   r   r   r   transpose_arrayT   s    r<   c                 C   s
   t | S r    r%   r;   r1   r   r   r   numpy_transpose_arrayX   s    r>   c                 C   s   t j| |dS N)axesr=   r#   r@   r   r   r    numpy_transpose_array_axes_kwarg[   s    rB   c                 C   s   t j| |d S r?   )r%   r;   copyrA   r   r   r   %numpy_transpose_array_axes_kwarg_copy_   s    rD   c                 C   s
   |  |S r    r:   rA   r   r   r   array_transpose_axesc   s    rE   c                 C   s   |  | S r    )r;   rC   rA   r   r   r   array_transpose_axes_copyg   s    rF   c                 C   s^   t t | | d | d|f}t t |d |df}||j j}t |d}|d }|S )N   )   r      rI   )r%   r!   arangeTr;   )mnr1r2Zr_difzr   r   r   transpose_issue_4708k   s     rQ   c                 C   s   |   S r    )squeezer1   r   r   r   squeeze_arrayt   s    rS   c                 C   s   t | |S r    )r%   expand_dims)r2   axisr   r   r   rT   x   s    rT   c                  G   s
   t j|  S r    )r%   
atleast_1dr+   r   r   r   rV   |   s    rV   c                  G   s
   t j|  S r    )r%   
atleast_2dr+   r   r   r   rW      s    rW   c                  G   s
   t j|  S r    )r%   
atleast_3dr+   r   r   r   rX      s    rX   c                 C   s0   | j d d f| j dd   }tjjj| |dS )Nr   rH   rI   )strides)rY   r%   libstride_tricks
as_strided)r2   rY   r   r   r   as_strided1   s    r]   c                 C   sN   d}| j d d | j d | d |f }| j| jd f }tjjj| ||dS )NrG   rI   )r)   rY   )r)   rY   r%   rZ   r[   r\   )r2   Zwindowr)   rY   r   r   r   as_strided2   s    $r_   c                 C   s   t jjj| ||dS )N)rU   )r%   rZ   r[   sliding_window_view)xwindow_shaperU   r   r   r   r`      s    r`   c                 C   s   | j f}| j}d|||f< d S )N      ?)ra   y)r#   Zarr2dra   rd   r   r   r   	bad_index   s    re   c                 C   s   | d S )N)rI   g       @r   r#   r   r   r   bad_float_index   s    rg   Fc                 C   s   t | ||S r    )r%   Zfill_diagonal)r#   valwrapr   r   r   numpy_fill_diagonal   s    rj   c                 C   s
   t | S r    )r%   r)   rf   r   r   r   numpy_shape   s    rk   c                 C   s
   t | S r    )r%   Zflatnonzeror1   r   r   r   numpy_flatnonzero   s    rl   c                 C   s
   t | S r    )r%   Zargwherer1   r   r   r   numpy_argwhere   s    rm   c                 C   s   t | |S r    )r%   resize)r2   	new_shaper   r   r   numpy_resize   s    rp   c                       s  e Zd 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ed fd!d"Zd#d$ Zefd%d&Zefd'd(Zd)d* Zd+d, Zefd-d.Zd/d0 Zefd1d2Zd3d4 Zd5d6 Zd7d8 Zd9d: Z d;d< Z!d=d> Z"d?d@ Z#dAdB Z$dCdD Z%dEdF Z&dGdH Z'dIdJ Z(dKdL Z)dMdN Z*dOdP Z+dQdR Z,dSdT Z-dUdV Z.dWdX Z/dYdZ Z0e1d[d\ Z2d]d^ Z3d_d` Z4dadb Z5dcdd Z6dedf Z7dgdh Z8didj Z9dkdl Z:dmdn Z;dodp Z<dqdr Z=dsdt Z>dudv Z?dwdx Z@dydz ZA  ZBS ){TestArrayManipulationz4
    Check shape-changing operations on arrays.
    c                    s   t t|   t | _d S r    )superrq   setUpr   ccacheself	__class__r   r   rs      s    zTestArrayManipulation.setUpc                    s4  t tg}dd t|fdd t|fddt|fdd}t|fd	d
t|fdd}td} |d  |d  |d  |d  |d tdd} |d  |d  |d  |d  |d |d |d |d tdd} |d  |d  |d  |d tddj} |d  |d ||d ||d ||d tddd} |d  |d  |d  |d   |d! |d" ||d# ||d$  fd%d&}tg }|| ||d'   d S )(Nc                 S   s"   t | t|t|f}|||S r    )r   r	   entry_point)r   r#   r)   cresr   r   r   generic_run   s    z=TestArrayManipulation.test_array_reshape.<locals>.generic_runc                    s8   | ||}    | ||}|| ~  d S r    memory_leak_setupassertPreciseEqualmemory_leak_teardown)r   r#   r)   expectedgotr{   rv   r   r   check   s    
z7TestArrayManipulation.test_array_reshape.<locals>.checkc                    s@       | ||}|j| |j|j ~  d S r    )r}   assertEqualr)   r7   r   )r   r#   r)   expected_shaper   r   r   r   check_only_shape   s    zBTestArrayManipulation.test_array_reshape.<locals>.check_only_shapec              	      s8    t} | || W 5 Q R X t|jd d S )Nzincompatible shape for array)assertRaisesNotImplementedErrorr   str	exceptionr   r#   r)   raisesr   r   r   check_err_shape   s
    zATestArrayManipulation.test_array_reshape.<locals>.check_err_shapec              	      s8    t} | || W 5 Q R X t|jd d S )Nz)total size of new array must be unchangedr   
ValueErrorr   r   r   r   r   r   r   check_err_size   s
    z@TestArrayManipulation.test_array_reshape.<locals>.check_err_sizec              	      s8    t} | || W 5 Q R X t|jd d S )Nzmultiple negative shape valuesr   r   r   r   r   check_err_multiple_negative   s
    zMTestArrayManipulation.test_array_reshape.<locals>.check_err_multiple_negative   )r   )      )   rG   )r   rI   rG   )rI   r   rI   rI   rG   rI   rH   rG   r   r   )   )r   r   )r   rG   rH   )rI   r   rI   rG   rI   rH   rI   r   r   )rH      r      r^   r^   )r^   r   )r   r^   r   )r   r   r^   )r^   r   )r^   r   r   )r   r   r^   r^   c                    s    | d  | d  | d  | d | dd | dd | dd | d	d
 | dd | d | d | d d S )Nr   r   )rI   r   rH   )r   7   rI   r   rH   r^   r   r   r^   r   r   )r   r^   )r   r   )r^   r   r   )r   r   r   r   rI   rI   rH   r   rf   )r   r   r   r   r   check_empty  s    





z=TestArrayManipulation.test_array_reshape.<locals>.check_empty)rG   rH   r   )	r$   r&   r   r%   rJ   r!   rK   arraydisable_leak_check)rv   r   r   r   r#   r   r   )r   r   r   r{   rv   r   test_array_reshape   sh    	































z(TestArrayManipulation.test_array_reshapec              	      s  t tttg}fddt|fdd}t|fdd}t|fdd}t|fd	d
}tdtdddtddddtdddddtddddd d dd d dd d f g}tt	|D ]j}||| d  t
tt|| jD ]@}t	| t fdd|D }	||| | ||| |	 qqttgdd }
|
dd |
dd |
dd   ||d d ||d d ||d d ||d d ||d d ||d d ||d d ||d d  ||d d! ||d d" ||d d# ||d d$ ||d d% ||d d& ||d d' ||d d( t$}td)d*ttddgf W 5 Q R X d+t|j d S ),Nc                    s&    j | t|t|f}|||S r    rt   compiler	   ry   )r   r#   r@   rz   ru   r   r   run:  s    z<TestArrayManipulation.test_array_transpose_axes.<locals>.runc                    sN   | ||} | ||} || |jj|jj |jj|jj d S r    )r~   r   flagsf_contiguousc_contiguous)r   r#   r@   r   r   r   rv   r   r   r   >  s    


z>TestArrayManipulation.test_array_transpose_axes.<locals>.checkc              	      s8    t} | || W 5 Q R X t|jd d S )Nzrepeated axis in transposer   r   r#   r@   r   r   r   r   check_err_axis_repeatedH  s
    zPTestArrayManipulation.test_array_transpose_axes.<locals>.check_err_axis_repeatedc              	      s8    t} | || W 5 Q R X t|jd d S )Nz2axis is out of bounds for array of given dimensionr   r   r   r   r   check_err_axis_oobO  s
    zKTestArrayManipulation.test_array_transpose_axes.<locals>.check_err_axis_oobc              	      s*    ttf  | || W 5 Q R X d S r    )r   	TypeErrorr   )r   r#   r@   r   r   r   check_err_invalid_argsV  s    zOTestArrayManipulation.test_array_transpose_axes.<locals>.check_err_invalid_argsr   r   r   rH   rG   rI   @   r   c                    s   g | ]}|  qS r   r   r   ra   )ndimr   r   r   g  s     zCTestArrayManipulation.test_array_transpose_axes.<locals>.<listcomp>c                 S   s*   | ||}t | ||}tj|| d S r    )r   r%   testingassert_equal)r   rL   rM   r   r   r   r   r   check_issue_4708k  s    
zITestArrayManipulation.test_array_transpose_axes.<locals>.check_issue_4708r   foo)r   g333333@)333333?r   r   )rH   r   r   )rG   rH   rI   rI   r   rI   )r   r   rH   )rH   r   r   )rG   rI   rH   )rI   rH   )rG   rI   rH   r   )rG   rI   rH   TZnopythonz#np.transpose does not accept tuples)rB   rD   rE   rF   r   r%   rJ   r!   rangelenr   tupler   rQ   r   r   r   r   r>   r   assertInr   r   )rv   r   r   r   r   r   Zarrsir@   Zneg_axesr   er   )r   r   rv   r   test_array_transpose_axes4  sl    	,



(z/TestArrayManipulation.test_array_transpose_axesc                 C   s@   t }t|}dd }| D ] \}}| |||||| qd S )Nc                   s   s8  t ddgddggdfV  t ddgddggdfV  t ddgddggdfV  t ddgddggdfV  t ddgddggd	fV  t ddgddggd
fV  t jdtddfV  t ddgddggdfV  t ddgddggdfV  t jdtddfV  t jg tddfV  ddddgdfV  dV  d S )NrI   rH   rG   r   )rH   r   )r   rH   )r   rG   r   r   rH   r   r   dtyperH   rI   r   rI   rG   rH   rG   )r   r   )r%   r   zerosfloatintr   r   r   r   inputs  s    z=TestArrayManipulation.test_numpy_resize_basic.<locals>.inputs)rp   r   r~   )rv   r   cfuncr   r2   ro   r   r   r   test_numpy_resize_basic  s
    z-TestArrayManipulation.test_numpy_resize_basicc              	   C   s  |    tt}| t}|dd W 5 Q R X | dt|j | t"}|t	ddgddggd W 5 Q R X | dt|j | t
"}|t	ddgddggd	 W 5 Q R X | d
t|j | t
"}|t	ddgddggd W 5 Q R X | d
t|j d S )Nabcr   z#The argument "a" must be array-liker   rI   rH   rG   zBThe argument "new_shape" must be an integer or a tuple of integers)r   rG   z0All elements of `new_shape` must be non-negativer   )r   r   rp   r   r   r   r   r   r%   r   r   )rv   r   r   r   r   r   test_numpy_resize_exception  s,    &&&z1TestArrayManipulation.test_numpy_resize_exceptionc                    s   t fddfdd  fdd}td}|| tdd	}|| ||j ||d d d
  td}|| d S )Nc                    s&   j  t| t|f}|| |S r    r   )r#   rU   rz   r   rv   r   r   r     s    z3TestArrayManipulation.test_expand_dims.<locals>.runc                    s6    | |}   | |}|| ~  d S r    r|   )r#   rU   r   r   r   r   rv   r   r   r     s    

z5TestArrayManipulation.test_expand_dims.<locals>.checkc                    s,   t | j d | jd D ]} | | qd S )NrI   )r   r   )r#   rU   )r   r   r   check_all_axes  s    z>TestArrayManipulation.test_expand_dims.<locals>.check_all_axesr   r   r   r^   *   )rT   r%   rJ   r!   rK   r   )rv   r   r#   r   )r   r   r   rv   r   test_expand_dims  s    


z&TestArrayManipulation.test_expand_dimsc              	   C   s   t }tdd|}td}|  }|dd W 5 Q R X | dt|j |  }||d W 5 Q R X | dt|j d S )NTr   r   hellorG   z#First argument "a" must be an arrayz"Argument "axis" must be an integer)rT   r   r%   rJ   assertTypingErrorr   r   r   )rv   r   r   r#   r   r   r   r   test_expand_dims_exceptions  s    


z1TestArrayManipulation.test_expand_dims_exceptionsc                    s(  fdd fdd} fdd}t d}t d}|| ||| t d	}t d
d }|d d d }	|| ||||	 t d
d}
|
j}|
d d d }||
 ||
|| t dd}|j}|d d d }|| |||| t dd}|| ||||| d S )Nc                    s$     | |  |  |  d S r    )ZassertStridesEqualr~   r0   )r   r   ru   r   r   check_result  s    z<TestArrayManipulation.check_atleast_nd.<locals>.check_resultc                    s    | |  d S r    r   )arg)r   r   r   r   r   check_single  s    z<TestArrayManipulation.check_atleast_nd.<locals>.check_singlec                     sF   |  } |  } t|t| t||D ]\}}|| q.d S r    )r   r   zip)r   Zexpected_tupleZ	got_tupler   r   r   r   r   rv   r   r   check_tuple  s
    z;TestArrayManipulation.check_atleast_nd.<locals>.check_tupler   y              @r   r                 ?r^   r   r   r      )rH   rH   rH   rH   )r%   r   rJ   r!   rK   )rv   r   r   r   r   Za1Za2b1b2Zb3c1c2c3Zd1Zd2Zd3r   r   r   r   check_atleast_nd  s2    



z&TestArrayManipulation.check_atleast_ndc                 C   s"   t }tdd|}| || d S NTr   )rV   r   r   rv   r   r   r   r   r   test_atleast_1d   s    z%TestArrayManipulation.test_atleast_1dc                 C   s"   t }tdd|}| || d S r   )rW   r   r   r   r   r   r   test_atleast_2d%  s    z%TestArrayManipulation.test_atleast_2dc                 C   s"   t }tdd|}| || d S r   )rX   r   r   r   r   r   r   test_atleast_3d*  s    z%TestArrayManipulation.test_atleast_3dc                    sP    fdd fdd}t d}|| ||d ||d d S )Nc                    s   j  t| f}|| S r    r   )r#   rz   r   r   r   r   0  s    z3TestArrayManipulation.check_as_strided.<locals>.runc                    s     | }| } || d S r    r~   )r#   r   r   r   r   r   r   3  s    z5TestArrayManipulation.check_as_strided.<locals>.checkr   r   )r   rI   r   )r%   rJ   r!   )rv   r   r   r#   r   r   r   check_as_strided/  s    
z&TestArrayManipulation.check_as_stridedc                 C   s   |  t |  t d S r    )r   r]   r_   ru   r   r   r   test_as_strided=  s    
z%TestArrayManipulation.test_as_stridedc              
      s,   fdd}t d}dD ],} d|  ||d| W 5 Q R X qt ddd	}d
D ],} d|  ||d| W 5 Q R X q^dD ],} d|  ||d| W 5 Q R X qt ddddd}dD ],} d|  ||d| W 5 Q R X q؈ d ||dd W 5 Q R X d S )Nc                    s2   t jjj| ||dd}t| ||} || d S )NT)	writeable)r%   rZ   r[   r`   r~   )r#   rb   rU   r   r   ru   r   r   r   B  s       z=TestArrayManipulation.test_sliding_window_view.<locals>.checkr   )Nr   r^   r   z1d array, axis=r      
      r   z2d array, axis=)Nr   rI   rI   r   )rI   r   )r   r   r   rH   )r   )r   r   z4d array, axis=rG   rH   z2d array, repeated axes)r   rG   rG   )r   rI   r   )r%   rJ   subTestr!   )rv   r   arr1rU   arr2Zarr4r   ru   r   test_sliding_window_viewA  s$    	
z.TestArrayManipulation.test_sliding_window_viewc              	      sz   fdd} fdd}    td}tddd} d	 |d
|dd  W 5 Q R X  d |d
|dd  W 5 Q R X  d |d|dd  W 5 Q R X  d |d|dd  W 5 Q R X  d |d|dd  W 5 Q R X  d |d|dd W 5 Q R X  d |d|dd W 5 Q R X  d |d|dd W 5 Q R X  d |d|dd W 5 Q R X  d  |d|d!d" W 5 Q R X  d# |d|d!d$ W 5 Q R X  d% |d&|d  W 5 Q R X  d' |d&|d( W 5 Q R X  d) |d&|d* W 5 Q R X  d+ |d,|dd( W 5 Q R X  d- |d,|dd* W 5 Q R X d S ).Nc              	      s4     t}t|  W 5 Q R X  | t|j d S r    )r   r   r`   r   r   r   msgr   r   ru   r   r   _raisesf  s    zFTestArrayManipulation.test_sliding_window_view_errors.<locals>._raisesc              	      s6     tj}t|  W 5 Q R X  | t|j d S r    )r   r   r   r`   r   r   r   r   ru   r   r   _typing_errork  s    zLTestArrayManipulation.test_sliding_window_view_errors.<locals>._typing_errorr   r   r   r   z1d window shape too largezwindow_shape cannot be largerr   z2d window shape too large)r      z1d window negative sizez&`window_shape` cannot contain negativer^   z2d window with a negative size)r   r   z1d array, 2d window shapez%matching length window_shape and axis)r   rH   z$2d window shape, only one axis givenrI   z1d window shape, 2 axes givenr   r   z1d array, second axiszArgument axis out of boundsr   z1d array, axis -2r   z2d array, fourth axis)r   r   r   rG   z2d array, axis -3r   zwindow_shape=Nonez3window_shape must be an integer or tuple of integerzwindow_shape=float@zwindow_shape=tuple(float))r  z
axis=floatz1axis must be None, an integer or tuple of integerzaxis=tuple(float))r   r%   rJ   r!   r   )rv   r  r  r   r   r   ru   r   test_sliding_window_view_errorse  sv    
            z5TestArrayManipulation.test_sliding_window_view_errorsCc           
      C   s   t ddd}|dkr |j}t}t|}|dkr@|jdd}| |j| t	||f|d}|j
}||}||}	t j||	 d S )N	   rG   FA)layoutr   )r%   rJ   r!   rK   r3   r	   rC   r   r  r   ry   r   r   )
rv   r   r  r2   r   
arraytype1crr   r   r   r   r   r   test_flatten_array  s    z(TestArrayManipulation.test_flatten_arrayc                 C   s,   | j td | j tdd | j tdd d S )Nr  r
  )r   r  r  )r  no_pyobj_flagsru   r   r   r   test_flatten_array_npm  s    z,TestArrayManipulation.test_flatten_array_npmc                    s  fdd}t |tt |t  fdd}|tddddd |tdjddd	d
d	d |tddddd d d d df dd |tdddddd |tdjdddd	d
d	d |tdddddd d d d d d df dd d S )Nc           
         s   t |}|j| t| |f d}|j}| |}||}tj|| |jj	|jj	k}|jj	|jj	k}	||dk ||	 d S )Nr  r  )
r	   r   r  r   ry   r%   r   r   ctypesdata)
r   r2   assume_layoutr  r  r   r   r   Z	py_copiedZ	nb_copied)r   rv   r   r   generic_check  s    z=TestArrayManipulation.test_ravel_array.<locals>.generic_checkc                     s   | |  | | d S r    r   r   )check_functioncheck_methodr   r   r     s    
z5TestArrayManipulation.test_ravel_array.<locals>.checkr	  rG   r  )r  r
  order   rH   r   r  $   )r   r6   r9   r%   rJ   r!   )rv   r   r  r   r   )r  r  r   rv   r   test_ravel_array  s    

. z&TestArrayManipulation.test_ravel_arrayc           	      C   sV   t ddd}t}t|}t||f|d}|j}||}||}t j|| d S Nr	  rG   r  )	r%   rJ   r!   r8   r	   r   ry   r   r   	rv   r   r2   r   r  r  r   r   r   r   r   r   test_ravel_array_size  s    z+TestArrayManipulation.test_ravel_array_sizec                 C   s   | j td d S Nr  )r  r  ru   r   r   r   test_ravel_array_npm  s    z*TestArrayManipulation.test_ravel_array_npmc                 C   s   | j td d S r!  )r   r  ru   r   r   r   test_ravel_array_size_npm  s    z/TestArrayManipulation.test_ravel_array_size_npmc                    s"   t ttg fdd}|  d S )Nc                    sR   t ddd}t|}t| |f d}|j}| |}||}t j|| d S r  )r%   rJ   r!   r	   r   ry   r   r   )r   r2   r  r  r   r   r   r  r   r   r     s    z9TestArrayManipulation.test_transpose_array.<locals>.check)r   r<   r>   )rv   r   r   r   r  r   test_transpose_array  s    
z*TestArrayManipulation.test_transpose_arrayc                 C   s   | j td d S r!  )r$  r  ru   r   r   r   test_transpose_array_npm  s    z.TestArrayManipulation.test_transpose_array_npmc           	      C   s\   t dddddd}t}t|}t||f|d}|j}||}||}t j|| d S )Nr   rH   rI   rG   r   r  )	r%   rJ   r!   rS   r	   r   ry   r   r   r  r   r   r   test_squeeze_array  s    z(TestArrayManipulation.test_squeeze_arrayc              	   C   s:   |  tj}| jtd W 5 Q R X | dt|j d S )Nr  rR   )r   r   r   r&  r  r   r   r   rv   r   r   r   r   test_squeeze_array_npm  s    z,TestArrayManipulation.test_squeeze_array_npmc                 C   sh  t dd }t dd }tdd}td tjftjtd ftdtjdftjdtd ftdttjdfdtjtftjtdtjdfdtd tjftjtdttjdfdtjtjtftjdtjtftd	dtjd ftjdtd fg}|j}|}|j}|}|D ]f}	|||	}
|||	}tj	|
| t
|}||	 }|| |	|}
|| |	|}tj	|
| qd S )
Nc                 S   s   | | S r    r   )r2   r.   r   r   r   np_new_axis_getitem  s    z@TestArrayManipulation.test_add_axis.<locals>.np_new_axis_getitemc                 S   s   || |< | S r    r   )r2   r.   itemr   r   r   np_new_axis_setitem  s    z@TestArrayManipulation.test_add_axis.<locals>.np_new_axis_setitemiH  )r   r   r      rI   rH   rG   )r   r%   rJ   r!   sliceZnewaxisEllipsispy_funcr   r   Z
zeros_likerC   )rv   r)  r+  r2   Z	idx_casesZpyfunc_getitemZcfunc_getitemZpyfunc_setitemZcfunc_setitemr.   r   r   Za_emptyr*  r   r   r   test_add_axis  s@    





z#TestArrayManipulation.test_add_axisc              	   C   sj   |   F}ttdtjfdtjfg}ttjdd}tt||ft	d W 5 Q R X | 
dt|j d S )Nra   rd   rH   r  r  zUnsupported array index type)r   r   r%   r   int32r   Arrayr   re   r  r   r   r   )rv   r   r  Z
arraytype2r   r   r   test_bad_index_npmF  s    

z(TestArrayManipulation.test_bad_index_npmc              	   C   sB   |   }ttttjddf W 5 Q R X | dt|j d S )NrH   r  z$Unsupported array index type float64)	r   r   rg   r   r2  float64r   r   r   r'  r   r   r   test_bad_float_index_npmO  s    
z.TestArrayManipulation.test_bad_float_index_npmc                    s   t tdddd  dd } fdd} fd	d
}fdd}|dD ]}| D ]}||| q\qR|dD ]}| D ]}||| qqvtdgd dd}||d ||dddg ||tdddg d S )NTr   c                 s   sX   | | fV  d|  | fV  | d|  fV  d|  d d|  d fV  | | | | fV  dV  d S )NrH   rI   )rI   rI   rI   r   )rM   r   r   r   _shape_variationsZ  s    
zITestArrayManipulation.test_fill_diagonal_basic.<locals>._shape_variationsc                   s   s   dV  dV  t jV  t j V  dV  t dV  dV  ddgV  t ddd	d
dV  t t dd	d	V  t dd	d	d d d V  d S )NrI   gA`"	@Tr   r   r   r	  6   rG   rH   r^   )r%   naninfrJ   r!   asfortranarrayr   r   r   r   _val_variationsh  s    

zGTestArrayManipulation.test_fill_diagonal_basic.<locals>._val_variationsc                 3   s<    | D ].}t j|t jdV  t t j|t jdV  qd S )Nr   )r%   r   r4  r:  ones)rM   r)   r6  r   r   #_multi_dimensional_array_variationsv  s    z[TestArrayManipulation.test_fill_diagonal_basic.<locals>._multi_dimensional_array_variationsc                 3   sL    | D ]>}t jtdd |D t jd}tdd |D }|| V  qd S )Nc                 S   s   g | ]}|d  qS rH   r   r   r   r   r   r   ~  s     zwTestArrayManipulation.test_fill_diagonal_basic.<locals>._multi_dimensional_array_variations_strided.<locals>.<listcomp>r   c                 s   s   | ]}t d |d dV  qdS )r   rH   N)r-  r   r   r   r   	<genexpr>  s     zvTestArrayManipulation.test_fill_diagonal_basic.<locals>._multi_dimensional_array_variations_strided.<locals>.<genexpr>)r%   r   r   r4  )rM   r)   tmpZslicerr=  r   r   +_multi_dimensional_array_variations_strided|  s    zcTestArrayManipulation.test_fill_diagonal_basic.<locals>._multi_dimensional_array_variations_stridedc                    s\   dD ]R}|   }|   }|d kr&i }nd|i}||f|  ||f| || qd S )N)NTFri   )rC   r~   )r#   rh   ri   r2   bparamsr   r   rv   r   r   _check_fill_diagonal  s    zLTestArrayManipulation.test_fill_diagonal_basic.<locals>._check_fill_diagonalrG   r	  F)rj   r   r%   r   r!   )rv   r;  r>  rB  rF  r#   rh   r   )r6  r   r   rv   r   test_fill_diagonal_basicV  s"    


z.TestArrayManipulation.test_fill_diagonal_basicc              
      sT  t }tdd| d}  tg tdfD ]6}t} || W 5 Q R X dt|j	ks2t
q2t,}td} || dt|j	 W 5 Q R X  fdd	}tjd
tjd}tj}||| dtjg}||| tjdddgtjd}||| tjd
tjd}dddg}||| d}||| tdg}||| d S )NTr   rI   r   z'The first argument must be at least 2-D)rG   rG   r   z/All dimensions of input must be of equal lengthc              	      s6    t} | | W 5 Q R X dt|j d S )Nz'Unable to safely conform val to a.dtyper   )r#   rh   r   r   rv   r   r   _assert_raises  s    zPTestArrayManipulation.test_fill_diagonal_exception_cases.<locals>._assert_raisesrG   rG   r   ffffff
@rH   g    _Bgffffff?g@g}Ô%Igp=T)rj   r   r   r%   r   r<  r   r   r   r   AssertionErrorr   r   r   r1  r8  r9  int64Zfloat32)rv   r   rh   r2   r   rI  r#   r   rH  r   "test_fill_diagonal_exception_cases  s6    








z8TestArrayManipulation.test_fill_diagonal_exception_casesc                 C   s  t }tdd|}tddgtddgtddgtddgtddgtdd	gtd
dgtd
dgtd
dgtddgtddgtddgtddgtddgtddgddgddgg}|D ](\}}|||}|||}| || qd S )NTr   r   r   r   rG   rI   r?  rI   rH   rG   rG   r   r   rH   r   r   r   r   rH   rH   )r*   r   r%   r   r<  rJ   r~   )rv   r   r   r  input_arrayr)   r   r   r   r   r   test_broadcast_to  s0    

z'TestArrayManipulation.test_broadcast_toc                 C   sd   t }tdd|}tdddg}d}|D ]4}|||}|||}| || | |jd  q*d S )NTr   {   r   Z	WRITEABLE)r*   r   r%   r   r~   ZassertFalser   )rv   r   r   r   r)   r#   r   r   r   r   r   test_broadcast_to_0d_array  s    


z0TestArrayManipulation.test_broadcast_to_0d_arrayc           	      C   s`  t }tdd|}tddtdgtddtdgtddtdgddtdgddtdgtddtd	gtdd
td	gtddtd	gtddtd	gtddtdgtddtdgtddtdgtddtdgtddtdgtddtdgddtdgddtdgg}|   |D ]@\}}}}| |}||| W 5 Q R X | |t	|j
 qd S )NTr   r   r   z/Cannot broadcast a non-scalar to a scalar arrayr   rO  )rT  z=operands could not be broadcast together with remapped shapesr?  r   r   r   rI   rI   zDinput operand has more dimensions than allowed by the axis remappingrQ  r^   z4all elements of broadcast shape must be non-negativer   )r^   rH   g?g@z7The second argument "shape" must be a tuple of integersr   z-The first argument "array" must be array-likerG   )rH   r2   z*object cannot be interpreted as an integer)r*   r   r%   r   r   r   r   r   r   r   r   )	rv   r   r   r  r#   Ztarget_shapeerrr  r   r   r   r   test_broadcast_to_raises  sv    $z.TestArrayManipulation.test_broadcast_to_raisesc                 C   s*   t dd }| }| }| || d S )Nc                   S   s   t ddS )Nr2   r   r'   r   r   r   r   _broadcast_to_16  s    zMTestArrayManipulation.test_broadcast_to_corner_cases.<locals>._broadcast_to_1)r   r/  r~   )rv   rZ  r   r   r   r   r   test_broadcast_to_corner_cases5  s
    
z4TestArrayManipulation.test_broadcast_to_corner_casesc                 C   s\   t }tdd|}tjdtjd}d}|||}d|d< | | d | | d d S )	NTr   rH   r   rQ  r   r   r   )r*   r   r%   r   r1  r   sum)rv   r   r   rR  r)   viewr   r   r   test_broadcast_to_change_view>  s    
z3TestArrayManipulation.test_broadcast_to_change_viewc           	      C   s\   t }tdd|}tdddgg}|D ].\}}}||||}||||}| || q(d S )NTr   rH   rQ  r   )r/   r   r%   r<  r~   )	rv   r   r   r  rR  r)   r.   r   r   r   r   r   test_broadcast_to_indexingI  s    z0TestArrayManipulation.test_broadcast_to_indexingc                 C   s8   t dd }td}||}||}| || d S )Nc                 S   s   t | d}||j|j|jfS )Nr   )r%   r(   r7   r)   rY   )r#   retr   r   r   r   W  s    z@TestArrayManipulation.test_broadcast_to_array_attrs.<locals>.foorG   )r   r%   rJ   r/  r~   )rv   r   r#   r   r   r   r   r   test_broadcast_to_array_attrsT  s    


z3TestArrayManipulation.test_broadcast_to_array_attrsc                 C   s   t }tdd|}dgddgdgdgdgddgdd	dd
gd	gddgddgddgddgddgddgddgddgddgddgddgddgddgddgddgddgddgddgddgg}|D ],}|| }|| }| |t | || qd S )NTr   r   )r,  r   rV  )rG   r   )r   r,  )r   r   rI   )r   rI   r,  r   rG   rI   r   r   r   r   r   rO  rH   r   )r,   r   ZassertIsInstancer   r~   )rv   r   r   r  input_shaper   r   r   r   r   test_broadcast_shapesb  sF    
z+TestArrayManipulation.test_broadcast_shapesc              
   C   s   t }tdd|}|   ddgddgdddgddgd	d
ddgddgg}|D ]4}| t}||  W 5 Q R X | dt|j qLd S )NTr   rO  r   r   r?  rI   rG   r   rH   rG   rG   r   rb  r   )r   r   rH   =shape mismatch: objects cannot be broadcast to a single shaper,   r   r   r   r   r   r   r   )rv   r   r   r  rc  r   r   r   r   test_broadcast_shapes_raises  s     
z2TestArrayManipulation.test_broadcast_shapes_raisesc              	   C   sR   t }tdd|}|   | t}|ddd W 5 Q R X | dt|j d S )NTr   r   rH   r   z#negative dimensions are not allowedrh  )rv   r   r   r   r   r   r   (test_broadcast_shapes_negative_dimension  s    z>TestArrayManipulation.test_broadcast_shapes_negative_dimensionc              
   C   sf   t }tdd|}|   dddddg}|D ]4}| t}||  W 5 Q R X | dt|j q,d S )	NTr   )r   )r   )g333333@)stringr   r2   )rI   rl  z#must be either an int or tuple[int])r,   r   r   r   r   r   r   r   )rv   r   r   ZinpsZinpr   r   r   r   "test_broadcast_shapes_invalid_type  s    z8TestArrayManipulation.test_broadcast_shapes_invalid_typec              	      s   t tdd  fdd}dD ]}t|}|| q&dddgddgd	d
ggddfD ]}|| q\t} d W 5 Q R X dt|j d S )NTr   c                    s    | } | } || d S r    r   )ra   r   r   rE  r   r   r     s    z/TestArrayManipulation.test_shape.<locals>.check)r   r   r   )r   r   r   rI   FrH   rG   r   r   rP  r2   z+The argument to np.shape must be array-like)	rk   r   r%   emptyr   r   r   r   r   )rv   r   tr#   r   r   rE  r   
test_shape  s    

"
z TestArrayManipulation.test_shapec                    sJ   t }tdd|} fdd}| D ] }||}||} || q$d S )NTr   c                  3   s   t ddV  t jdddV  t g V   jd} d| t | dk< | V  | dddV  | jd	d
ddV  | dddd d
 V  | d V  d S )Nr   r   r   Z
fill_valued           皙?r   2   rH   r
  r  r   rI   r   )r%   rJ   fullr   randomrandnabsr!   r1   ru   r   r   a_variations  s    zBTestArrayManipulation.test_flatnonzero_basic.<locals>.a_variations)rl   r   r~   rv   r   r   rz  r2   r   r   r   ru   r   test_flatnonzero_basic  s    
z,TestArrayManipulation.test_flatnonzero_basicc                    sJ   t }tdd|} fdd}| D ] }||}||} || q$d S )NTr   c                  3   s   t dddkV  t jdddV  t jdddV  t g V  t ddd	gV   jd
} | dkV  | ddddkV  | jdddddkV  | dddd d dkV  | | d kV  | |  kV  d S )Nr   r   rH   r   rq  rI   g      rs  rc   rr  rt  r   g      ?ru  r
  r  r   )r%   rJ   rv  r   rw  rx  r!   r1   ru   r   r   rz    s    
z?TestArrayManipulation.test_argwhere_basic.<locals>.a_variations)rm   r   r~   r{  r   ru   r   test_argwhere_basic  s    
z)TestArrayManipulation.test_argwhere_basicc                   c   sf   dV  dV  ddgddgfV  dV  t jV  dV  dV  dV  d	V  d
V  dV  d V  dV  dV  d S )N)rW  )rK  g@)g      @gffffff@)rs  rc   rs  g      r   rI   rH   rG   r   FT)TFTy       @      ?Za_string )r%   r8  r   r   r   r   array_like_variations  s    z+TestArrayManipulation.array_like_variationsc                 C   s@   t }tdd|}|  D ] }||}||}| || qd S r   )rl   r   r  r~   rv   r   r   r2   r   r   r   r   r   test_flatnonzero_array_like  s    z1TestArrayManipulation.test_flatnonzero_array_likec                 C   s@   t }tdd|}|  D ] }||}||}| || qd S r   )rm   r   r  r~   r  r   r   r   test_argwhere_array_like!  s    z.TestArrayManipulation.test_argwhere_array_likec           	      C   sT   t }tdd|}dd |D }|| }|gt| }dd |D }| || d S )NTr   c                 S   s   g | ]}t |qS r   r%   r   r   sr   r   r   r   /  s     zOTestArrayManipulation.broadcast_arrays_assert_correct_shape.<locals>.<listcomp>c                 S   s   g | ]
}|j qS r   r)   r   r2   r   r   r   r   2  s     r-   r   r   r~   )	rv   input_shapesr   r   r   inarrays	outarraysr   r   r   r   r   %broadcast_arrays_assert_correct_shape)  s    z;TestArrayManipulation.broadcast_arrays_assert_correct_shapec              	   C   sr   t }tdd|}ddddddd	d
dg	}|D ]@}|g}| || ||g}| || |||g}| || q,d S )NTr   r   rO  r   r  r   )rG   r   r   rb  rJ  )r-   r   r  )rv   r   r   r  r)   r  Zinput_shapes2Zinput_shapes3r   r   r   'test_broadcast_arrays_same_input_shapes5  s&    
z=TestArrayManipulation.test_broadcast_arrays_same_input_shapesc                 C   s   ddgdgddgdgddgdgddgdgddgdgddgdgddgdgddgdgd	dgdgdd	gdgddgdgddgdgdd	gd	gg}|D ]*\}}|  || |  |d d d
 | qd S )Nr   rO  r   rJ  rb  rV  r   r   r   r^   r  rv   r  r  r   r   r   r   9test_broadcast_arrays_two_compatible_by_ones_input_shapesS  s"    












zOTestArrayManipulation.test_broadcast_arrays_two_compatible_by_ones_input_shapesc                 C   s   ddgdgddgdgddgdgddgdgddgdgddgdgddgdgddgdgddgdgddgdgddgdgdd	gd	gdd
gd	gdd	gd	gdd	gd	gddgdgdd
gd
gddgdgddgdgdd
gd
gg}|D ]*\}}|  || |  |d d d | qd S )Nr   rO  rJ  rb  r   rV  r   r   r   r   r   r^   r  r  r   r   r   Dtest_broadcast_arrays_two_compatible_by_prepending_ones_input_shapesm  s0    



















zZTestArrayManipulation.test_broadcast_arrays_two_compatible_by_prepending_ones_input_shapesc           	      C   sv   t }tdd|}ddgdgddgdgddgdgg}|D ]8\}}|| }d	d
 |D }|gt| }| || q8d S )NTr   Fr   rI   rH   r   r?  c                 S   s   g | ]
}|j qS r   r  r  r   r   r   r     s     zLTestArrayManipulation.test_broadcast_arrays_scalar_input.<locals>.<listcomp>r  )	rv   r   r   r  r  r   r  r   r   r   r   r   "test_broadcast_arrays_scalar_input  s    


z8TestArrayManipulation.test_broadcast_arrays_scalar_inputc                 C   sB   t }tdd|}|dd}ddg}dd |D }| || d S )NTr   )rT  i  )i  r?  c                 S   s   g | ]
}|j qS r   r  r  r   r   r   r     s     zKTestArrayManipulation.test_broadcast_arrays_tuple_input.<locals>.<listcomp>)r-   r   r~   rv   r   r   r  r   r   r   r   r   !test_broadcast_arrays_tuple_input  s    
z7TestArrayManipulation.test_broadcast_arrays_tuple_inputc                 C   sT   t }tdd|}|tdtjdtjd}ddg}dd |D }| || d S )NTr   rH   r   r   c                 S   s   g | ]
}|j qS r   r  r  r   r   r   r     s     zOTestArrayManipulation.test_broadcast_arrays_non_array_input.<locals>.<listcomp>)r-   r   r%   Zintpr   r~   r  r   r   r   %test_broadcast_arrays_non_array_input  s    z;TestArrayManipulation.test_broadcast_arrays_non_array_inputc              	   C   sd   t }tdd|}|   | t$}tdd}d}||| W 5 Q R X | dt	|j
 d S )NTr   r   r   zMismatch of argument types)r-   r   r   r   r   r%   rJ   r!   r   r   r   )rv   r   r   r   r#   rC  r   r   r   /test_broadcast_arrays_invalid_mixed_input_types  s    zETestArrayManipulation.test_broadcast_arrays_invalid_mixed_input_typesc              	   C   sd   t }tdd|}|   | t$}tjdtjd}d}||| W 5 Q R X | dt	|j
 d S )NTr   rG   r   zhello worldzArgument "1" must be array-like)r-   r   r   r   r   r%   r   rM  r   r   r   )rv   r   r   r   r#   r  r   r   r   #test_broadcast_arrays_invalid_input  s    z9TestArrayManipulation.test_broadcast_arrays_invalid_inputc                 C   s   t }tdd|}|   ddgddgdddgddgg}|D ]Z}||d d d	 fD ]B}| t}d
d |D }||  W 5 Q R X | dt|j qRq<d S )NTr   rO  r   r   r?  re  rf  r^   c                 S   s   g | ]}t |qS r   r  r  r   r   r   r     s     zdTestArrayManipulation.test_broadcast_arrays_incompatible_shapes_raise_valueerror.<locals>.<listcomp>rg  )r-   r   r   r   r   r   r   r   )rv   r   r   r  r  r)   r   r  r   r   r   :test_broadcast_arrays_incompatible_shapes_raise_valueerror  s     zPTestArrayManipulation.test_broadcast_arrays_incompatible_shapes_raise_valueerrorc                 C   s|   dd }|}t dd|}|tdddgdddgdddggd}|tdddgdddgdddggd}tj|| d S )Nc                 S   sj   | j \}}t| |||f}t|dd}| }t|d|f}|d d|  ||d d d d f< |S Nr   rI   r^   )r)   r%   r(   swapaxesr0   r!   ra   rd   rcr2   rC  ccdr   r   r   unfold_flatten  s    
$zITestArrayManipulation.test_readonly_after_flatten.<locals>.unfold_flattenTr   rI   rH   rG   r   r%   r   r   Zassert_array_equal)rv   r  r   r   res_nbres_pyr   r   r   test_readonly_after_flatten  s    	((z1TestArrayManipulation.test_readonly_after_flattenc                 C   s|   dd }|}t dd|}|tdddgdddgdddggd}|tdddgdddgdddggd}tj|| d S )Nc                 S   sj   | j \}}t| |||f}t|dd}| }t|d|f}|d d|  ||d d d d f< |S r  )r)   r%   r(   r  r5   r!   r  r   r   r   unfold_ravel  s    
$zETestArrayManipulation.test_readonly_after_ravel.<locals>.unfold_ravelTr   rI   rH   rG   r  )rv   r  r   r   r  r  r   r   r   test_readonly_after_ravel  s    	((z/TestArrayManipulation.test_readonly_after_ravelc           	      C   s   |    tdd }|jdd}d|j_d|j_dd }|}tdd	|}||}||}d
}| |jj | d}| |jj| d S )Nr	  rJ  r
  r  Fc                 S   s   |   }|S r    r4   )r2   r   r   r   r   try_ravel_w_copy  s    zKTestArrayManipulation.test_mutability_after_ravel.<locals>.try_ravel_w_copyTr   zCNo copy was performed, so the resulting array must not be writeablez?A copy was performed, yet the resulting array is not modifiable)	r   r%   rJ   r!   rC   r   r   r   
assertTrue)	rv   Za_cZa_fr  r   r   Zret_cZret_fr  r   r   r   test_mutability_after_ravel  s    z1TestArrayManipulation.test_mutability_after_ravel)C__name__
__module____qualname____doc__rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r  enable_pyobj_flagsr  r  r  r   r"  r#  r$  r%  r&  r(  r0  r3  r5  rG  rN  rS  rU  rY  r[  r^  r_  ra  rd  ri  rj  rm  rp  r|  r}  staticmethodr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  __classcell__r   r   rw   r   rq      s|   p^/$D#,	H.#0	*

	!rq   __main__)N)F)C	functoolsr   	itertoolsr   numpyr%   ZunittestZnumba.core.compilerr   r   Znumbar   r   r   r	   Znumba.np.numpy_supportr
   Znumba.core.errorsr   Z
numba.corer   r   Znumba.tests.supportr   r   r   r   r  Zenable_pyobjectr  Znrtr   r$   r&   r*   r,   r-   r/   r3   r6   r8   r9   r<   r>   rB   rD   rE   rF   rQ   rS   rT   rV   rW   rX   r]   r_   r`   re   rg   rj   rk   rl   rm   rp   rq   r  mainr   r   r   r   <module>   sx   	
          m
