o
    i                     @   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 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 | ]}|g R i qS  r   ).0pyfunc)argsfunckwargsr   r/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/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&      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 N)reshapearrZnewshaper   r   r   array_reshape,      
r&   c                 C      t | |S r"   )npr#   r$   r   r   r   numpy_array_reshape0      r*   c                 C   r(   r"   r)   broadcast_to)r%   shaper   r   r   numpy_broadcast_to4   r+   r/   c                  G   
   t j|  S r"   )r)   Zbroadcast_shapesr   r   r   r   numpy_broadcast_shapes8   r'   r2   c                  G   r0   r"   )r)   Zbroadcast_arraysr1   r   r   r   numpy_broadcast_arrays<   r'   r3   c                 C   s   t | || S r"   r,   )r%   r.   idxr   r   r   numpy_broadcast_to_indexing@      r5   c                 C      |   S r"   )flattenar   r   r   flatten_arrayD      r;   c                 C   r7   r"   ravelr9   r   r   r   ravel_arrayH   r<   r?   c                 C   s
   |   jS r"   )r>   sizer9   r   r   r   ravel_array_sizeL   r'   rA   c                 C   
   t | S r"   )r)   r>   r9   r   r   r   numpy_ravel_arrayP   r'   rC   c                 C   r7   r"   	transposer9   r   r   r   transpose_arrayT   r<   rF   c                 C   rB   r"   r)   rE   r9   r   r   r   numpy_transpose_arrayX   r'   rH   c                 C   s   t j| |dS N)axesrG   r%   rJ   r   r   r    numpy_transpose_array_axes_kwarg[      rL   c                 C   s   t j| |d S rI   )r)   rE   copyrK   r   r   r   %numpy_transpose_array_axes_kwarg_copy_   s   rO   c                 C   r!   r"   rD   rK   r   r   r   array_transpose_axesc   r'   rP   c                 C   s   |  | S r"   )rE   rN   rK   r   r   r   array_transpose_axes_copyg   rM   rQ   c                 C   s^   t t | | d | d|f}t t |d |df}||j j}t |d}|d }|S )N   )   r      rT   )r)   r#   arangeTrE   )mnr1r2Zr_difzr   r   r   transpose_issue_4708k   s    r\   c                 C   r7   r"   )squeezer9   r   r   r   squeeze_arrayt   r<   r^   c                 C   r(   r"   )r)   expand_dims)r:   axisr   r   r   r_   x   r+   r_   c                  G   r0   r"   )r)   
atleast_1dr1   r   r   r   ra   |   r'   ra   c                  G   r0   r"   )r)   
atleast_2dr1   r   r   r   rb      r'   rb   c                  G   r0   r"   )r)   
atleast_3dr1   r   r   r   rc      r'   rc   c                 C   s0   | j d d f| j dd   }tjjj| |dS )Nr   rS   rT   )strides)rd   r)   libstride_tricks
as_strided)r:   rd   r   r   r   as_strided1   s   rh   c                 C   sN   d}| j d d | j d | d |f }| j| jd f }tjjj| ||dS )NrR   rT   )r.   rd   )r.   rd   r)   re   rf   rg   )r:   Zwindowr.   rd   r   r   r   as_strided2   s   $rj   c                 C   s   t jjj| ||dS )N)r`   )r)   re   rf   sliding_window_view)xwindow_shaper`   r   r   r   rk      s   rk   c                 C   s   | j f}| j}d|||f< d S )N      ?)rl   y)r%   Zarr2drl   ro   r   r   r   	bad_index   s   rp   c                 C   s   | d S )N)rT   g       @r   r%   r   r   r   bad_float_index   s   rr   Fc                 C   s   t | ||S r"   )r)   Zfill_diagonal)r%   valwrapr   r   r   numpy_fill_diagonal   rM   ru   c                 C   rB   r"   )r)   r.   rq   r   r   r   numpy_shape   r'   rv   c                 C   rB   r"   )r)   Zflatnonzeror9   r   r   r   numpy_flatnonzero   r'   rw   c                 C   rB   r"   )r)   Zargwherer9   r   r   r   numpy_argwhere   r'   rx   c                 C   r(   r"   )r)   resize)r:   	new_shaper   r   r   numpy_resize   r+   r{   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"   )superr|   setUpr   ccacheself	__class__r   r   r~      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   r   r   r   check   s   
z7TestArrayManipulation.test_array_reshape.<locals>.checkc                    s@       | ||}|j| |j|j ~  d S r"   )r   assertEqualr.   r@   r   )r   r%   r.   expected_shaper   r   r   r   check_only_shape   s   zBTestArrayManipulation.test_array_reshape.<locals>.check_only_shapec                    L    t} | || W d    n1 sw   Y  t|jd d S )Nzincompatible shape for array)assertRaisesNotImplementedErrorr   str	exceptionr   r%   r.   raisesr   r   r   check_err_shape      zATestArrayManipulation.test_array_reshape.<locals>.check_err_shapec                    r   )Nz)total size of new array must be unchangedr   
ValueErrorr   r   r   r   r   r   r   check_err_size   r   z@TestArrayManipulation.test_array_reshape.<locals>.check_err_sizec                    r   )Nzmultiple negative shape valuesr   r   r   r   r   check_err_multiple_negative   r   zMTestArrayManipulation.test_array_reshape.<locals>.check_err_multiple_negative   )r   )      )   rR   )r   rT   rR   )rT   r   rT   rT   rR   rT   rS   rR   r   r   )   )r   r   )r   rR   rS   )rT   r   rT   rR   rT   rS   rT   r   r   )rS      r      ri   ri   )ri   r   )r   ri   r   )r   r   ri   )ri   r   )ri   r   r   )r   r   ri   ri   c                    s    | d  | d  | d  | d | dd | dd | dd | d	d
 | dd | d | d | d d S )Nr   r   )rT   r   rS   )r   7   rT   r   rS   ri   r   r   ri   r   r   )r   ri   )r   r   )ri   r   r   )r   r   r   r   rT   rT   rS   r   rq   )r   r   r   r   r   check_empty  s   





z=TestArrayManipulation.test_array_reshape.<locals>.check_empty)rR   rS   r   )	r&   r*   r    r)   rU   r#   rV   arraydisable_leak_check)r   r   r   r   r%   r   r   )r   r   r   r   r   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 ]4}||| d  t
tt|| jD ]}t	| t fdd|D }	||| | ||| |	 qqut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 d    n	1 sVw   Y  d+t|j d S ),Nc                    s&    j | t|t|f}|||S r"   r   compiler	   r   )r   r%   rJ   r   r   r   r   run:     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%   rJ   r   r   r   r   r   r   r   >  s   


z>TestArrayManipulation.test_array_transpose_axes.<locals>.checkc                    r   )Nzrepeated axis in transposer   r   r%   rJ   r   r   r   r   check_err_axis_repeatedH  r   zPTestArrayManipulation.test_array_transpose_axes.<locals>.check_err_axis_repeatedc                    r   )Nz2axis is out of bounds for array of given dimensionr   r   r   r   r   check_err_axis_oobO  r   zKTestArrayManipulation.test_array_transpose_axes.<locals>.check_err_axis_oobc                    s@    ttf  | || W d    d S 1 sw   Y  d S r"   )r   	TypeErrorr   )r   r%   rJ   r   r   r   check_err_invalid_argsV  s   "zOTestArrayManipulation.test_array_transpose_axes.<locals>.check_err_invalid_argsr   r   r   rS   rR   rT   @   r   c                    s   g | ]}|  qS r   r   r   rl   )ndimr   r   r   g      zCTestArrayManipulation.test_array_transpose_axes.<locals>.<listcomp>c                 S   s*   | ||}t | ||}tj|| d S r"   )r   r)   testingassert_equal)r   rW   rX   r   r   r   r   r   check_issue_4708k  s   
zITestArrayManipulation.test_array_transpose_axes.<locals>.check_issue_4708r   foo)r   g333333@)333333?r   r   )rS   r   r   )rR   rS   rT   rT   r   rT   )r   r   rS   )rS   r   r   )rR   rT   rS   )rT   rS   )rR   rT   rS   r   )rR   rT   rS   TZnopythonz#np.transpose does not accept tuples)rL   rO   rP   rQ   r    r)   rU   r#   rangelenr   tupler   r\   r   r   r   r   rH   r   assertInr   r   )r   r   r   r   r   r   ZarrsirJ   Zneg_axesr   er   )r   r   r   r   test_array_transpose_axes4  sp   	,



 z/TestArrayManipulation.test_array_transpose_axesc                 C   s@   t }t|}dd }| D ]\}}| |||||| qd S )Nc                   s   s6   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  g ddfV  dV  d S )NrT   rS   rR   r   )rS   r   )r   rS   )r   rR   r   r   rS   r   r   dtyperS   rT   r   rT   rR   )r   rT   rS   rR   rS   rR   )r   r   )r)   r   zerosfloatintr   r   r   r   inputs  s   
z=TestArrayManipulation.test_numpy_resize_basic.<locals>.inputs)r{   r   r   )r   r   cfuncr   r:   rz   r   r   r   test_numpy_resize_basic  s   z-TestArrayManipulation.test_numpy_resize_basicc                 C   sb  |    tt}| t}|dd W d    n1 sw   Y  | dt|j | t}|t	ddgddggd W d    n1 sIw   Y  | dt|j | t
}|t	ddgddggd	 W d    n1 suw   Y  | d
t|j | t
}|t	ddgddggd W d    n1 sw   Y  | d
t|j d S )Nabcr   z#The argument "a" must be array-liker   rT   rS   rR   zBThe argument "new_shape" must be an integer or a tuple of integers)r   rR   z0All elements of `new_shape` must be non-negativer   )r   r   r{   r   r   r   r   r   r)   r   r   )r   r   r   r   r   r   test_numpy_resize_exception  s4   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%   r`   r   r   r   r   r   r     r   z3TestArrayManipulation.test_expand_dims.<locals>.runc                    s6    | |}   | |}|| ~  d S r"   r   )r%   r`   r   r   r   r   r   r   r   r     s   

z5TestArrayManipulation.test_expand_dims.<locals>.checkc                    s,   t | j d | jd D ]} | | qd S )NrT   )r   r   )r%   r`   )r   r   r   check_all_axes  s   z>TestArrayManipulation.test_expand_dims.<locals>.check_all_axesr   r   r   ri   *   )r_   r)   rU   r#   rV   r   )r   r   r%   r   )r   r   r   r   r   test_expand_dims  s   


z&TestArrayManipulation.test_expand_dimsc                 C   s   t }tdd|}td}|  }|dd W d    n1 s"w   Y  | dt|j |  }||d W d    n1 sDw   Y  | dt|j d S )NTr   r   hellorR   z#First argument "a" must be an arrayz"Argument "axis" must be an integer)r_   r   r)   rU   assertTypingErrorr   r   r   )r   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   r8   )r   r   r   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  r   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   r   r   r   check_tuple  s   z;TestArrayManipulation.check_atleast_nd.<locals>.check_tupler   y              @r   r                 ?ri   r   r   r      )rS   rS   rS   rS   )r)   r   rU   r#   rV   )r   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   "   t }tdd|}| || d S NTr   )ra   r   r   r   r   r   r   r   r   test_atleast_1d      z%TestArrayManipulation.test_atleast_1dc                 C   r   r   )rb   r   r   r   r   r   r   test_atleast_2d%  r   z%TestArrayManipulation.test_atleast_2dc                 C   r   r   )rc   r   r   r   r   r   r   test_atleast_3d*  r   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%   r   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     z5TestArrayManipulation.check_as_strided.<locals>.checkr   r   )r   rT   r   )r)   rU   r#   )r   r   r   r%   r   r   r   check_as_strided/  s   
z&TestArrayManipulation.check_as_stridedc                 C   s   |  t |  t d S r"   )r  rh   rj   r   r   r   r   test_as_strided=  s   
z%TestArrayManipulation.test_as_stridedc              	      s   fdd}t d}dD ] } d|  ||d| W d    n1 s(w   Y  qt ddd	}d
D ] } d|  ||d| W d    n1 sTw   Y  q9dD ] } d|  ||d| W d    n1 sww   Y  q\t ddddd}dD ] } d|  ||d| W d    n1 sw   Y  q d ||dd W d    d S 1 sw   Y  d S )Nc                    s2   t jjj| ||dd}t| ||} || d S )NT)	writeable)r)   re   rf   rk   r   )r%   rm   r`   r   r   r   r   r   r   B  s
   z=TestArrayManipulation.test_sliding_window_view.<locals>.checkr   )Nr   ri   r   z1d array, axis=r      
      r   z2d array, axis=)Nr   rT   rT   r   )rT   r   )r   r   r   rS   )r   )r   r   z4d array, axis=rR   rS   z2d array, repeated axes)r   rR   rR   )r   rT   r   )r)   rU   subTestr#   )r   r   arr1r`   arr2Zarr4r   r   r   test_sliding_window_viewA  s6   
	"z.TestArrayManipulation.test_sliding_window_viewc                    s   fdd} fdd}    td}tddd} d	 |d
|dd  W d    n1 s5w   Y   d |d
|dd  W d    n1 sQw   Y   d |d|dd  W d    n1 smw   Y   d |d|dd  W d    n1 sw   Y   d |d|dd  W d    n1 sw   Y   d |d|dd W d    n1 sw   Y   d |d|dd W d    n1 sw   Y   d |d|dd W d    n1 sw   Y   d |d|dd W d    n	1 sw   Y   d  |d|d!d" W d    n	1 s3w   Y   d# |d|d!d$ W d    n	1 sPw   Y   d% |d&|d  W d    n	1 slw   Y   d' |d&|d( W d    n	1 sw   Y   d) |d&|d* W d    n	1 sw   Y   d+ |d,|dd( W d    n	1 sw   Y   d- |d,|dd* W d    d S 1 sw   Y  d S ).Nc                    sH     t}t|  W d    n1 sw   Y   | t|j d S r"   )r   r   rk   r   r   r   msgr   r   r   r   r   _raisesf  s   
zFTestArrayManipulation.test_sliding_window_view_errors.<locals>._raisesc                    sJ     tj}t|  W d    n1 sw   Y   | t|j d S r"   )r   r   r   rk   r   r   r   r  r   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 negativeri   z2d window with a negative size)r   r   z1d array, 2d window shapez%matching length window_shape and axis)r	  rS   z$2d window shape, only one axis givenrT   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   rR   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)   rU   r#   r  )r   r  r  r  r  r   r   r   test_sliding_window_view_errorse  s~   
$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	   rR   FA)layoutr   )r)   rU   r#   rV   r;   r	   rN   r   r  r   r   r   r   )
r   r   r  r:   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_flagsr   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   r   r)   r   r   ctypesdata)
r   r:   assume_layoutr   r!  r   r   r   Z	py_copiedZ	nb_copied)r   r   r   r   generic_check  s   z=TestArrayManipulation.test_ravel_array.<locals>.generic_checkc                     s    | i |  | i | d S r"   r   r   )check_functioncheck_methodr   r   r     s   z5TestArrayManipulation.test_ravel_array.<locals>.checkr  rR   r  )r'  r  order   rS   r   r  $   )r   r?   rC   r)   rU   r#   )r   r   r(  r   r   )r)  r*  r   r   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  rR   r  )	r)   rU   r#   rA   r	   r   r   r   r   	r   r   r:   r   r   r!  r   r   r   r   r   r   test_ravel_array_size  s   z+TestArrayManipulation.test_ravel_array_sizec                 C      | j td d S Nr  )r/  r#  r   r   r   r   test_ravel_array_npm  r6   z*TestArrayManipulation.test_ravel_array_npmc                 C   r3  r4  )r2  r#  r   r   r   r   test_ravel_array_size_npm  r6   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 r0  )r)   rU   r#   r	   r   r   r   r   )r   r:   r   r!  r   r   r   r  r   r   r     s   z9TestArrayManipulation.test_transpose_array.<locals>.check)r    rF   rH   )r   r   r   r   r  r   test_transpose_array  s   

z*TestArrayManipulation.test_transpose_arrayc                 C   r3  r4  )r7  r#  r   r   r   r   test_transpose_array_npm  r6   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   rS   rT   rR   r   r  )	r)   rU   r#   r^   r	   r   r   r   r   r1  r   r   r   test_squeeze_array  s   z(TestArrayManipulation.test_squeeze_arrayc                 C   sN   |  tj}| jtd W d    n1 sw   Y  | dt|j d S )Nr  r]   )r   r   r   r9  r#  r   r   r   r   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 ]3}	|||	}
|||	}tj	|
| t
|}||	 }|| |	|}
|| |	|}tj	|
| q~d S )
Nc                 S   s   | | S r"   r   )r:   r4   r   r   r   np_new_axis_getitem  s   z@TestArrayManipulation.test_add_axis.<locals>.np_new_axis_getitemc                 S   s   || |< | S r"   r   )r:   r4   itemr   r   r   np_new_axis_setitem  s   z@TestArrayManipulation.test_add_axis.<locals>.np_new_axis_setitemiH  )r   r   r      rT   rS   rR   )r   r)   rU   r#   sliceZnewaxisEllipsispy_funcr   r   Z
zeros_likerN   )r   r<  r>  r:   Z	idx_casesZpyfunc_getitemZcfunc_getitemZpyfunc_setitemZcfunc_setitemr4   r   r   Za_emptyr=  r   r   r   test_add_axis  sB   





z#TestArrayManipulation.test_add_axisc                 C   s~   |   (}ttdtjfdtjfg}ttjdd}tt||ft	d W d    n1 s/w   Y  | 
dt|j d S )Nrl   ro   rS   r  r  zUnsupported array index type)r   r   r)   r   int32r   Arrayr   rp   r#  r   r   r   )r   r   r   Z
arraytype2r   r   r   test_bad_index_npmF  s   

z(TestArrayManipulation.test_bad_index_npmc                 C   sV   |   }ttttjddf W d    n1 sw   Y  | dt|j d S )NrS   r  z$Unsupported array index type float64)	r   r   rr   r   rE  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.q)|dD ]}| D ]}||| q@q;tdgd dd}||d ||g d ||tg d d S )NTr   c                 s   sZ    | | fV  d|  | fV  | d|  fV  d|  d d|  d fV  | | | | fV  dV  d S )NrS   rT   rT   rT   rT   r   )rX   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 )NrT   gA`"	@Tr   r   r   r  6   rR   rS   ri   )r)   naninfrU   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   rG  rN  ones)rX   r.   rJ  r   r   #_multi_dimensional_array_variationsv  s
   z[TestArrayManipulation.test_fill_diagonal_basic.<locals>._multi_dimensional_array_variationsc                 3   sN     | 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 rS   r   r   r   r   r   r   ~  r   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   rS   N)r@  r   r   r   r   	<genexpr>  s    zvTestArrayManipulation.test_fill_diagonal_basic.<locals>._multi_dimensional_array_variations_strided.<locals>.<genexpr>)r)   r   r   rG  )rX   r.   tmpZslicerrQ  r   r   +_multi_dimensional_array_variations_strided|  s   zcTestArrayManipulation.test_fill_diagonal_basic.<locals>._multi_dimensional_array_variations_stridedc                    sd   dD ]-}|   }|   }|d u ri }nd|i}||fi |  ||fi | || qd S )N)NTFrt   )rN   r   )r%   rs   rt   r:   bparamsr   r   r   r   r   _check_fill_diagonal  s   zLTestArrayManipulation.test_fill_diagonal_basic.<locals>._check_fill_diagonalrR   r  F)FTFTFT)ru   r   r)   r   r#   )r   rO  rR  rV  rZ  r%   rs   r   )rJ  r   r   r   r   test_fill_diagonal_basicV  s&   


z.TestArrayManipulation.test_fill_diagonal_basicc              	      sx  t }tdd| d}  tg tdfD ]%}t} || W d    n1 s0w   Y  dt|j	v s>J qt
}td} || dt|j	 W d    n1 sbw   Y   fdd	}tjd
tjd}tj}||| dtjg}||| tjg dtjd}||| tjd
tjd}g d}||| d}||| tdg}||| d S )NTr   rT   r   z'The first argument must be at least 2-D)rR   rR   r   z/All dimensions of input must be of equal lengthc                    sJ    t} | | W d    n1 sw   Y  dt|j d S )Nz'Unable to safely conform val to a.dtyper   )r%   rs   r   r   r   r   r   _assert_raises  s   zPTestArrayManipulation.test_fill_diagonal_exception_cases.<locals>._assert_raisesrR   rR   r   ffffff
@)rT   rS   g    _B)gffffff?g@}Ô%Igp=Tra  )ru   r   r   r)   r   rP  r   r   r   r   r   r   r   rD  rL  rM  int64Zfloat32)r   r   rs   r:   r   r^  r%   r   r]  r   "test_fill_diagonal_exception_cases  s:   







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 ]\}}|||}|||}| || qmd S )NTr   r   r   r   rR   rT   rS  rT   rS   rR   rR   r   r   rS   r   r   r   r   rS   rS   )r/   r   r)   r   rP  rU   r   )r   r   r   r&  input_arrayr.   r   r   r   r   r   test_broadcast_to  s2   

z'TestArrayManipulation.test_broadcast_toc                 C   sd   t }tdd|}tdddg}d}|D ]}|||}|||}| || | |jd  qd S )NTr   {   r   Z	WRITEABLE)r/   r   r)   r   r   ZassertFalser   )r   r   r   r   r.   r%   r   r   r   r   r   test_broadcast_to_0d_array  s   


z0TestArrayManipulation.test_broadcast_to_0d_arrayc           	      C   sr  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 d    n1 sw   Y  | |t	|j
 qd S )NTr   r   r   z/Cannot broadcast a non-scalar to a scalar arrayr   rd  )ri  z=operands could not be broadcast together with remapped shapesrS  r   r   r   rT   rT   zDinput operand has more dimensions than allowed by the axis remappingrf  ri   z4all elements of broadcast shape must be non-negativer   )ri   rS   g?g@z7The second argument "shape" must be a tuple of integersr   z-The first argument "array" must be array-likerR   )rS   r:   z*object cannot be interpreted as an integer)r/   r   r)   r   r   r   r   r   r   r   r   )	r   r   r   r&  r%   Ztarget_shapeerrr  r   r   r   r   test_broadcast_to_raises  sz   $z.TestArrayManipulation.test_broadcast_to_raisesc                 C   s*   t dd }| }| }| || d S )Nc                   S   s   t ddS )Nr:   r   r,   r   r   r   r   _broadcast_to_16  s   zMTestArrayManipulation.test_broadcast_to_corner_cases.<locals>._broadcast_to_1)r   rB  r   )r   ro  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   rS   r   rf  r	  r   r
  )r/   r   r)   r   rD  r   sum)r   r   r   rg  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   rS   rf  r   )r5   r   r)   rP  r   )	r   r   r   r&  rg  r.   r4   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-   r@   r.   rd   )r%   retr   r   r   r   W  s   z@TestArrayManipulation.test_broadcast_to_array_attrs.<locals>.foorR   )r   r)   rU   rB  r   )r   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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ddgg}|D ]}|| }|| }| |t | || qYd S )NTr   r   r?  r   rk  )rR   r   ))r   r?  r   r   rT   rw  )r   rT   r?  rx  r   rR   rT   r  r   r  r   r   rd  rS   r  )r2   r   ZassertIsInstancer   r   )r   r   r   r&  input_shaper   r   r   r   r   test_broadcast_shapesb  sH   z+TestArrayManipulation.test_broadcast_shapesc              	   C   s   t }tdd|}|   ddgddgg ddd	gg d
ddgg}|D ]$}| t}||  W d    n1 s9w   Y  | dt|j q#d S )NTr   rd  r   r   rS  rd  rd  r   rT   rR   r   rS   rR   rR   )r   ry  r  )r	  r   rS   =shape mismatch: objects cannot be broadcast to a single shaper2   r   r   r   r   r   r   r   )r   r   r   r&  rz  r   r   r   r   test_broadcast_shapes_raises  s$   
z2TestArrayManipulation.test_broadcast_shapes_raisesc                 C   sf   t }tdd|}|   | t}|ddd W d    n1 s#w   Y  | dt|j d S )NTr   r   rS   r   z#negative dimensions are not allowedr  )r   r   r   r   r   r   r   (test_broadcast_shapes_negative_dimension  s   z>TestArrayManipulation.test_broadcast_shapes_negative_dimensionc              	   C   st   t }tdd|}|   g d}|D ]$}| t}||  W d    n1 s)w   Y  | dt|j qd S )NTr   ))r   )r   )g333333@)stringr   r:   )rT   r  z#must be either an int or tuple[int])r2   r   r   r   r   r   r   r   )r   r   r   Zinps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 d    n1 sIw   Y  dt|j d S )NTr   c                    s    | } | } || d S r"   r  )rl   r   r   rY  r   r   r     r  z/TestArrayManipulation.test_shape.<locals>.check)r   r   r   )r   r   r   rT   FrS   rR   r   r   re  r:   z+The argument to np.shape must be array-like)	rv   r   r)   emptyr   r   r   r   r   )r   r   tr%   r   r   rY  r   
test_shape  s   

"

z TestArrayManipulation.test_shapec                    J   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   rS   r  r+  r   rT   r   )r)   rU   fullr   randomrandnabsr#   r9   r   r   r   a_variations  s   zBTestArrayManipulation.test_flatnonzero_basic.<locals>.a_variations)rw   r   r   r   r   r   r  r:   r   r   r   r   r   test_flatnonzero_basic  s   
z,TestArrayManipulation.test_flatnonzero_basicc                    r  )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 g d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   rS   r   r  rT   )g      r  rn   r  r  r   g      ?r  r  r+  r   )r)   rU   r  r   r  r  r#   r9   r   r   r   r    s   
z?TestArrayManipulation.test_argwhere_basic.<locals>.a_variations)rx   r   r   r  r   r   r   test_argwhere_basic  s   
z)TestArrayManipulation.test_argwhere_basicc                   c   sh    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)rl  )r`  g@)g      @gffffff@)r  rn   r  g      r   rT   rS   rR   r   FTr[  y       @      ?Za_string )r)   rL  r   r   r   r   array_like_variations  s   
z+TestArrayManipulation.array_like_variationsc                 C   @   t }tdd|}|  D ]}||}||}| || qd S r   )rw   r   r  r   r   r   r   r:   r   r   r   r   r   test_flatnonzero_array_like  s   z1TestArrayManipulation.test_flatnonzero_array_likec                 C   r  r   )rx   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      g | ]}t |qS r   r)   r   r   sr   r   r   r   /      zOTestArrayManipulation.broadcast_arrays_assert_correct_shape.<locals>.<listcomp>c                 S      g | ]}|j qS r   r.   r   r:   r   r   r   r   2      r3   r   r   r   )	r   input_shapesr   r   r   inarrays	outarraysr   r   r   r   r   %broadcast_arrays_assert_correct_shape)  s   z;TestArrayManipulation.broadcast_arrays_assert_correct_shapec                 C   sd   t }tdd|}g d}|D ] }|g}| || ||g}| || |||g}| || qd S )NTr   )	r   rd  r  r  r  )rR   r   r   ry  r_  )r3   r   r  )r   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
 | qEd S )Nr   rd  r   r_  ry  rk  r  r   r  ri   r  r   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 | qhd S )Nr   rd  r_  ry  r   rk  r   r   r   r  r  ri   r  r  r   r   r   Dtest_broadcast_arrays_two_compatible_by_prepending_ones_input_shapesm  s2   



















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 ]\}}|| }d	d
 |D }|gt| }| || qd S )NTr   Fr   rT   rS   r   rS  c                 S   r  r   r  r  r   r   r   r     r  zLTestArrayManipulation.test_broadcast_arrays_scalar_input.<locals>.<listcomp>r  )	r   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   )ri  i  )i  rS  c                 S   r  r   r  r  r   r   r   r     r  zKTestArrayManipulation.test_broadcast_arrays_tuple_input.<locals>.<listcomp>)r3   r   r   r   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   rS   r   r   c                 S   r  r   r  r  r   r   r   r     r  zOTestArrayManipulation.test_broadcast_arrays_non_array_input.<locals>.<listcomp>)r3   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   sx   t }tdd|}|   | t}tdd}d}||| W d    n1 s,w   Y  | dt	|j
 d S )NTr   r   r   zMismatch of argument types)r3   r   r   r   r   r)   rU   r#   r   r   r   )r   r   r   r   r%   rW  r   r   r   /test_broadcast_arrays_invalid_mixed_input_types     zETestArrayManipulation.test_broadcast_arrays_invalid_mixed_input_typesc                 C   sx   t }tdd|}|   | t}tjdtjd}d}||| W d    n1 s,w   Y  | dt	|j
 d S )NTr   rR   r   zhello worldzArgument "1" must be array-like)r3   r   r   r   r   r)   r   rb  r   r   r   )r   r   r   r   r%   r  r   r   r   #test_broadcast_arrays_invalid_input  r  z9TestArrayManipulation.test_broadcast_arrays_invalid_inputc              
   C   s   t }tdd|}|   ddgddgg ddd	gg}|D ]7}||d d d
 fD ]+}| t}dd |D }||  W d    n1 sEw   Y  | dt|j q(qd S )NTr   rd  r   r   rS  r|  r}  r~  ri   c                 S   r  r   r  r  r   r   r   r     r  zdTestArrayManipulation.test_broadcast_arrays_incompatible_shapes_raise_valueerror.<locals>.<listcomp>r  )r3   r   r   r   r   r   r   r   )r   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   p   dd }|}t dd|}|tg dg dg dgd}|tg dg dg dgd}tj|| d S )	Nc                 S   j   | j \}}t| |||f}t|dd}| }t|d|f}|d d|  ||d d d d f< |S Nr   rT   ri   )r.   r)   r-   swapaxesr8   r#   rl   ro   rcr:   rW  ccdr   r   r   unfold_flatten     
$zITestArrayManipulation.test_readonly_after_flatten.<locals>.unfold_flattenTr   rI  rS   rS   rS   rR   rR   rR   rS   r   r)   r   r   Zassert_array_equal)r   r  r   r   res_nbres_pyr   r   r   test_readonly_after_flatten     	""z1TestArrayManipulation.test_readonly_after_flattenc                 C   r  )	Nc                 S   r  r  )r.   r)   r-   r  r>   r#   r  r   r   r   unfold_ravel  r  zETestArrayManipulation.test_readonly_after_ravel.<locals>.unfold_ravelTr   rI  r  r  rS   r  )r   r  r   r   r  r  r   r   r   test_readonly_after_ravel  r  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  r_  r  r+  Fc                 S   s   |   }|S r"   r=   )r:   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)   rU   r#   rN   r   r  r   
assertTrue)	r   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__r~   r   r   r   r   r   r   r   r   r  r  r  r  r  r  enable_pyobj_flagsr"  r$  r/  r2  r5  r6  r7  r8  r9  r;  rC  rF  rH  r\  rc  rh  rj  rn  rp  rs  rt  rv  r{  r  r  r  r  r  r  staticmethodr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  __classcell__r   r   r   r   r|      s~    p^/$D#,	H.#0	*

	!r|   __main__r"   )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/   r2   r3   r5   r;   r?   rA   rC   rF   rH   rL   rO   rP   rQ   r\   r^   r_   ra   rb   rc   rh   rj   rk   rp   rr   ru   rv   rw   rx   r{   r|   r  mainr   r   r   r   <module>   s|    	
          m