a
    LfE                    @   s
  d Z ddlZddlZddlZddlZddlZddlZddlZddlZ	ddlm
Z
mZmZmZ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mZmZ ddlmZ ddlmZmZmZmZm Z  dd	l!m"Z" dd
l#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- zddl.ZW n e/y    Y n0 dd Z0e(Z1dddZ(dd Z2dd Z3dd Z4h dZ5G dd dZ6dd Z7e	j89d g Z:e:e7de6de
dd gd!d"gged#e
d dged#e6d$e
dd gd!d"gged#e
d dged#e6d%e
dd gd!d"gged#e
g d&g d'ged#e6d(e
d)d*gd+d,gged#e
d-d)ged#e6d.e
d)d*gd+d,gged#e
d-d)ged#e6d/e
d)d*gd+d,gged#e
g d0g d1ged#e6d2e	j;d3ed#e	j;d4ed#d5hd6e6d7e	j8<d8d8e	j8<d8e6d9e	j8<d:d:e	j8<d:e6d;d:d<gd=d>ggd<d:gg
7 Z:e:e7d?e6d@e
g dAg d'ged#e
d dged#e6dBe
dd gd!d"gdCdDgged#e
g dEed#e6dFe
g dAg d'ged#e
d dged#e6dGe
dd gd!d"gdCdDgged#e
g dEed#e6dHe
g dIg dJged#e
d-d)ged#e6dKe
dLdMgdNdOgdPdQgged#e
g dRed#e6dSe
g dIg dJged#e
d-d)ged#e6dTe
dLdMgdNdOgdPdQgged#e
g dRed#e6dUe
g dIg dJged#e
d-d)gdVdWgged#e6dXe
dLdMgdNdOgdPdQgged#e
d-d)gdVdWgdVdWgged#e6dYe	j8<d8dZe	j8<d8e6d[e	j8<d:d\e	j8<d:e6d]e	j8<d\d:e	j8<d\e6d^e	j8<dd>e	j8<dd5hd6e6d_e	j8<d>de	j8<d>d5hd6g7 Z:e:e7d`e6dae
dd gd dgged#de6dbe
dd gd dgged#de6dce
dd*gddd:gged#de6dee
dd*gddd:gged#de6dfe	j;d3ed#dd5hd6e6dgd:d<gd<d:ggde6dhe
dd gd dggde6die	j8<d:d:dg7 Z:djdk Z=e:e= 7 Z:dldm Z>dndo Z?e:e? 7 Z:G dpdq dqZ@G drds dse@ZAG dtdu due@ZBG dvdw dwe@ZCG dxdy dye@ZDG dzd{ d{e@ZEG d|d} d}e@ZFd~d ZGG dd deAeDZHG dd deHZIG dd deAeDZJG dd deJZKG dd deAeDZLG dd deLZMG dd deAeDZNG dd deNZOG dd dZPG dd deAeDZQG dd deQePZRG dd deCeFZSG dd deSePZTG dd deAeDZUG dd deUZVG dd deAeBeDeEZWG dd deWZXG dd deCeFZYG dd deYZZdd Z[G dd deAeDZ\G dd de\Z]G dd deAeBZ^G dd de^Z_ej`addd dD G dd dZbG dd deCeFZcG dd dZdG dd deCeFZeG dd dZfG dd dZgG dd degZhG ddÄ degZiG ddń deiehZjG ddǄ dǃZkG ddɄ degZlG dd˄ degZmG dd̈́ degZnG ddτ dejelZoG ddф dejemZpG ddӄ dejenZqG ddՄ dՃZrddׄ ZsG ddل dكZtG ddۄ dۃZuG dd݄ d݃Zvdd߄ Zwej`jxe-dddd Zydd Zzej`jxe-ddej`j{dd Z|G dd dZ}G dd dZ~G dd dZdd Zej`jdddd Zej`je, dddd Zdd Zdd Zdd Zdd Zdd  Zdd Zdd Zdd ZdS (  z# Test functions for linalg module

    N)arraysingledoublecsinglecdoubledotidentitymatmul)swapaxes)	AxisError)multiply
atleast_2dinfasarray)linalg)matrix_powernormmatrix_rank	multi_dotLinAlgError)_multi_dot_matrix_chain_order)
assert_assert_equalassert_raisesassert_array_equalassert_almost_equalassert_allclosesuppress_warningsassert_raises_regexHAS_LAPACK64IS_WASMc                 C   s"   t | t|tjrt |ntju S N)type
isinstancenpndarray)outZin_ r'   W/var/www/ai-form-bot/venv/lib/python3.9/site-packages/numpy/linalg/tests/test_linalg.pyconsistent_subclass"   s    r)         c                 K   s8   t | jjttfv r|}n|}t| |fd|i| d S )Ndecimal)r   dtyper"   r   r   old_assert_almost_equal)absingle_decimaldouble_decimalkwr,   r'   r'   r(   r   ,   s    r   c                 C   s   t t tttt tti|  S r!   )r   r   r   r   r-   r'   r'   r(   get_real_dtype4   s
    r5   c                 C   s   t ttttttti|  S r!   )r   r   r   r   r4   r'   r'   r(   get_complex_dtype9   s
    r6   c                 C   s   | t tfv rdS dS d S )Ngh㈵>gdy=)r   r   r4   r'   r'   r(   get_rtol>   s    r7   >   size-0strided	nonsquaresquare	hermitiangeneralizedc                   @   s*   e Zd Ze fddZdd Zdd ZdS )
LinalgCasec                 C   s.   t t|t || _|| _|| _t|| _dS )z
        A bundle of arguments to be passed to a test case, with an identifying
        name, the operands a and b, and a set of tags to filter the tests
        N)r   r#   strnamer/   r0   	frozensettags)selfr@   r/   r0   rB   r'   r'   r(   __init__N   s
    zLinalgCase.__init__c                 C   s   || j | j| jd dS )zN
        Run the function `do` on this test case, expanding arguments
        rB   N)r/   r0   rB   )rC   dor'   r'   r(   checkY   s    zLinalgCase.checkc                 C   s   d| j  dS )Nz<LinalgCase: >)r@   rC   r'   r'   r(   __repr___   s    zLinalgCase.__repr__N)__name__
__module____qualname__setrD   rG   rJ   r'   r'   r'   r(   r>   M   s   r>   c                 C   s,   | t v sJ d|D ]}|j| hB |_q|S )z^
    Add the given tag (a string) to each of the cases (a list of LinalgCase
    objects)
    zInvalid tag)all_tagsrB   )tagZcasescaser'   r'   r(   	apply_tagc   s    rR     r;   r         ?       @      @      @r4   r   Zdouble_2)rU   rT   rW   )rV   rW         @r         ?       @y       @      @y      @      @y      @      @       @      ?r   Z	cdouble_2)rZ   rY   y      ?      @)y      ?       y      ?      y      ?      Z0x0r   r   r   r8   rE   Z8x8   Z1x1   Znonarray         r:   Zsingle_nsq_1)rT   rU   rV   Zsingle_nsq_2g      @rX   )rU   rT   rV   Zdouble_nsq_1Zdouble_nsq_2Zcsingle_nsq_1)      ?      ?       @       @      @      )y      @      y      @      "@y      @       @Zcsingle_nsq_2rb   rc   rd   y      @      "y      @      y      @       @)rZ   rY   rd   Zcdouble_nsq_1Zcdouble_nsq_2Zcdouble_nsq_1_2y      ?      y       @       Zcdouble_nsq_2_2Z8x11   Z1x5   Z5x1Z0x4Z4x0r<   ZhsingleZhdoubleZhcsingley       @      ZhcdoubleZhemptyZ	hnonarrayZmatrix_b_onlyZhmatrix_1x1c                  C   sr  g } t D ]b}t|jtjsqt|jd|j d|j g}|jd u rLd }n2|jjdkr`|j}nt|jd|j d|j g}t|j	d |||j
dhB d}| | t|jgd d d	|jj }|jd u rd }nj|jjdkr t|jgd d |jd
  d	|jjdd   }n$t|jgd d d	|jj }t|j	d |||j
dhB d}| | q| S )Nr_   r`   r^      r*   Z_tile3r=   rE   r`   r_   Z_tile213)CASESr#   r/   r$   r%   r   r0   ndimr>   r@   rB   appendreshapeshape)	new_casesrQ   r/   r0   new_caser'   r'   r(   _make_generalized_cases   s6    



$
 $
rr   c                 c   s  t | tjs| dfV  dS dg| j }d|d< | jdkr@d|d< | jdkrRd	|d
< tjt| D ]}dd t| j|D }tdd |D }tj	|| j
d}|tjd || }| |d< || j}tt|| k |dddd |D  fV  | jdkrF| jd dkrFt| j}d|d< tjjj| |d}|dfV  | jdkr| jd dkrt| j}d|d< tjjj| |d}|dfV  | jdkr`| jdd dkr`t| j}d|d< d|d< tjjj| |d}|dfV  q`dS )z<
    Generate cartesian product of strides for all axes
    ZnopNr^   )r^   r`   ri   r^   rj   r_   )r^   rt   c                 S   s   g | ]\}}t || qS r'   )abs).0r/   r0   r'   r'   r(   
<listcomp>+      z%_stride_comb_iter.<locals>.<listcomp>c                 S   s   g | ]}t d d |qS r!   )slice)rw   repeatr'   r'   r(   rx   ,  ry   r4   l   >[= .Zstride__c                 S   s   g | ]}d | qS )z%+dr'   )rw   jr'   r'   r(   rx   5  ry   r   )stridesZstride_xxx_0Zstride_xxx_0_xr^   r^   Zstride_xxx_0_0)r#   r$   r%   rl   	itertoolsproducttuplezipro   emptyr-   viewZuint32fill	__class__r   alljoinlistr~   libZstride_tricksZ
as_strided)xZ
stride_setZrepeatsZ	new_shapeZslicesxisr'   r'   r(   _stride_comb_iter  sF    







r   c               	   C   sn   g } t D ]`}t|jD ]P\}}t|jD ]<\}}t|jd | d | |||jdhB d}| | q(qq| S )Nr|   r9   rE   )rk   r   r/   r0   r>   r@   rB   rm   )rp   rQ   r/   Za_labelr0   Zb_labelrq   r'   r'   r(   _make_strided_casesJ  s    
r   c                   @   s"   e Zd ZeZe e fddZdS )LinalgTestCasec                 C   s   | j D ]x}|j|@ |krq|j|@ r&qz|| j W q ty| } z.d|d}|t 7 }t||W Y d}~qd}~0 0 qdS )zx
        Run func on each of the cases with all of the tags in require, and none
        of the tags in exclude
        zIn test case: z

N)
TEST_CASESrB   rG   rF   	Exception	traceback
format_excAssertionError)rC   requireexcluderQ   emsgr'   r'   r(   check_cases^  s    

zLinalgTestCase.check_casesN)rK   rL   rM   rk   r   rN   r   r'   r'   r'   r(   r   [  s   r   c                   @   s   e Zd Zdd Zdd ZdS )LinalgSquareTestCasec                 C   s   | j dhddhd d S )Nr;   r=   r8   r   r   r   rI   r'   r'   r(   test_sq_casest  s    z"LinalgSquareTestCase.test_sq_casesc                 C   s   | j ddhdhd d S )Nr;   r8   r=   r   r   rI   r'   r'   r(   test_empty_sq_casesx  s    
z(LinalgSquareTestCase.test_empty_sq_casesN)rK   rL   rM   r   r   r'   r'   r'   r(   r   r  s   r   c                   @   s   e Zd Zdd Zdd ZdS )LinalgNonsquareTestCasec                 C   s   | j dhddhd d S )Nr:   r=   r8   r   r   rI   r'   r'   r(   test_nonsq_cases  s    z(LinalgNonsquareTestCase.test_nonsq_casesc                 C   s   | j ddhdhd d S )Nr:   r8   r=   r   r   rI   r'   r'   r(   test_empty_nonsq_cases  s    
z.LinalgNonsquareTestCase.test_empty_nonsq_casesN)rK   rL   rM   r   r   r'   r'   r'   r(   r   }  s   r   c                   @   s   e Zd Zdd Zdd ZdS )HermitianTestCasec                 C   s   | j dhddhd d S )Nr<   r=   r8   r   r   rI   r'   r'   r(   test_herm_cases  s    z!HermitianTestCase.test_herm_casesc                 C   s   | j ddhdhd d S )Nr<   r8   r=   r   r   rI   r'   r'   r(   test_empty_herm_cases  s    
z'HermitianTestCase.test_empty_herm_casesN)rK   rL   rM   r   r   r'   r'   r'   r(   r     s   r   c                   @   s,   e Zd Zejjdd Zejjdd ZdS )LinalgGeneralizedSquareTestCasec                 C   s   | j ddhdhd d S )Nr=   r;   r8   r   r   rI   r'   r'   r(   test_generalized_sq_cases  s    
z9LinalgGeneralizedSquareTestCase.test_generalized_sq_casesc                 C   s   | j h dd d S )N>   r=   r;   r8   r   r   rI   r'   r'   r(   test_generalized_empty_sq_cases  s    z?LinalgGeneralizedSquareTestCase.test_generalized_empty_sq_casesN)rK   rL   rM   pytestmarkslowr   r   r'   r'   r'   r(   r     s   
r   c                   @   s,   e Zd Zejjdd Zejjdd ZdS )"LinalgGeneralizedNonsquareTestCasec                 C   s   | j ddhdhd d S )Nr=   r:   r8   r   r   rI   r'   r'   r(   test_generalized_nonsq_cases  s    
z?LinalgGeneralizedNonsquareTestCase.test_generalized_nonsq_casesc                 C   s   | j h dd d S )N>   r=   r8   r:   r   r   rI   r'   r'   r(   "test_generalized_empty_nonsq_cases  s    zELinalgGeneralizedNonsquareTestCase.test_generalized_empty_nonsq_casesN)rK   rL   rM   r   r   r   r   r   r'   r'   r'   r(   r     s   
r   c                   @   s,   e Zd Zejjdd Zejjdd ZdS )HermitianGeneralizedTestCasec                 C   s   | j ddhdhd d S )Nr=   r<   r8   r   r   rI   r'   r'   r(   test_generalized_herm_cases  s    
z8HermitianGeneralizedTestCase.test_generalized_herm_casesc                 C   s   | j h ddhd d S )N>   r=   r<   r8   noner   r   rI   r'   r'   r(   !test_generalized_empty_herm_cases  s    
z>HermitianGeneralizedTestCase.test_generalized_empty_herm_casesN)rK   rL   rM   r   r   r   r   r   r'   r'   r'   r(   r     s   
r   c                 C   sL   t | } | jdkr:tj| j| jd}t| jd |d< |S t| jd S d S )Nr`   r4   rj   .r   )r   rl   r$   r   ro   r-   r   )r/   rr'   r'   r(   identity_like_generalized  s    
r   c                   @   s   e Zd Zdd ZdS )
SolveCasesc                 C   sj   t ||}t|jdkrDt||d d }tt||j| nt||}t|| t	t
|| d S )Nr^   ).N.r   )r   solver$   r   rl   r	   r   broadcast_toro   r   r)   )rC   r/   r0   rB   r   Zadotxr'   r'   r(   rF     s    

zSolveCases.doNrK   rL   rM   rF   r'   r'   r'   r(   r     s   r   c                   @   sB   e Zd Zejdeeee	gdd Z
dd Zdd Zdd	 Zd
S )	TestSolver-   c                 C   s2   t jddgddgg|d}tt||j| d S Nr^         ?r4   )r$   r   r   r   r   r-   rC   r-   r   r'   r'   r(   
test_types  s    zTestSolve.test_typesc                 C   s   G dd dt j}t dddd}t d|}t||}|jdksPJ t ddd|}t||}|jdksJ t ddd|}tt	tj|| d S )	Nc                   @   s   e Zd ZdS )z)TestSolve.test_1_d.<locals>.ArraySubclassNrK   rL   rM   r'   r'   r'   r(   ArraySubclass  s   r   r]   r_   r_   r_   ra   )r_   r_   r_   r^   )
r$   r%   arangern   r   r   r   ro   r   
ValueError)rC   r   r/   r0   resultr'   r'   r(   test_1_d  s    zTestSolve.test_1_dc              	   C   s  G dd dt j}t dddd}t dddd|}t||d d ddd d f }t|d d ddddf |d d ddd d f }t|| tt	|| t
tjtj|d d ddddf | t
ttj||d d ddd d f  t dddd}t
ttj|| t
ttj|dd |dd  t d|}t||d d ddf }t|d d ddddf |dd }t|| tt	|| t ddd}t
ttj|| t
ttj|dd |dd  t
ttj|d d ddddf | d S )	Nc                   @   s   e Zd ZdS )z,TestSolve.test_0_size.<locals>.ArraySubclassNr   r'   r'   r'   r(   r     s   r   r]   r_   r*   r^   r`   r   )r$   r%   r   rn   r   r   r   r   r   r#   r   r   r   rC   r   r/   r0   expectedr   r'   r'   r(   test_0_size  s*    "8
(& *
 zTestSolve.test_0_sizec                 C   s  G dd dt j}t dddd}t dddd|}t||d d d d ddf }t||d d d d ddf }t|| tt	|| t||d d ddddf }t|d d ddddf |d d ddddf }t|| tt	|| d S )	Nc                   @   s   e Zd ZdS )z.TestSolve.test_0_size_k.<locals>.ArraySubclassNr   r'   r'   r'   r(   r     s   r   ra   r^   r_   r*   r`   r   )
r$   r%   r   rn   r   r   r   r   r   r#   r   r'   r'   r(   test_0_size_k	  s    ""
"8
zTestSolve.test_0_size_kN)rK   rL   rM   r   r   parametrizer   r   r   r   r   r   r   r   r'   r'   r'   r(   r     s
   
!r   c                   @   s   e Zd Zdd ZdS )InvCasesc                 C   s0   t |}tt||t| tt|| d S r!   )r   invr   r	   r   r   r)   )rC   r/   r0   rB   Za_invr'   r'   r(   rF     s
    

zInvCases.doNr   r'   r'   r'   r(   r     s   r   c                   @   s2   e Zd Zejdeeee	gdd Z
dd ZdS )TestInvr-   c                 C   s0   t jddgddgg|d}tt|j| d S r   )r$   r   r   r   r   r-   r   r'   r'   r(   r   &  s    zTestInv.test_typesc                 C   s   G dd dt j}t jdt jd|}t|}t|jj	t j
u  t|j|j tt|| t jdt jd|}t|}t|jj	t ju  t|j|j tt|| d S )Nc                   @   s   e Zd ZdS )z*TestInv.test_0_size.<locals>.ArraySubclassNr   r'   r'   r'   r(   r   -  s   r   r   r^   r^   r4   r[   )r$   r%   zerosint_r   r   r   r   r-   r"   float64r   ro   r#   	complex64rC   r   r/   resr'   r'   r(   r   +  s    

zTestInv.test_0_sizeNrK   rL   rM   r   r   r   r   r   r   r   r   r   r'   r'   r'   r(   r   %  s   
r   c                   @   s   e Zd Zdd ZdS )EigvalsCasesc                 C   s&   t |}t |\}}t|| d S r!   )r   eigvalseigr   )rC   r/   r0   rB   evevaluesevectorsr'   r'   r(   rF   >  s    
zEigvalsCases.doNr   r'   r'   r'   r(   r   <  s   r   c                   @   s2   e Zd Zejdeeee	gdd Z
dd ZdS )TestEigvalsr-   c                 C   s`   t jddgddgg|d}tt|j| t jddgddgg|d}tt|jt| d S Nr^   r   r4   ri   )r$   r   r   r   r   r-   r6   r   r'   r'   r(   r   E  s    zTestEigvals.test_typesc                 C   s   G dd dt j}t jdt jd|}t|}t|jj	t j
u  td|j tt|t j t jdt jd|}t|}t|jj	t ju  td|j tt|t j d S )Nc                   @   s   e Zd ZdS )z.TestEigvals.test_0_size.<locals>.ArraySubclassNr   r'   r'   r'   r(   r   N  s   r   r   r4   r   r^   r[   r\   )r$   r%   r   r   r   r   r   r   r-   r"   r   r   ro   r#   r   r   r'   r'   r(   r   L  s    

zTestEigvals.test_0_sizeNr   r'   r'   r'   r(   r   D  s   
r   c                   @   s   e Zd Zdd ZdS )EigCasesc                 C   sb   t |}|j|j }}tt||t|t|dd d d f  t|j	d t
t|| d S )N.rtol)r   r   eigenvalueseigenvectorsr   r	   r$   r   r7   r-   r   r)   )rC   r/   r0   rB   r   r   r   r'   r'   r(   rF   a  s    

 zEigCases.doNr   r'   r'   r'   r(   r   _  s   r   c                   @   s2   e Zd Zejdeeee	gdd Z
dd ZdS )TestEigr-   c                 C   s   t jddgddgg|d}t j|\}}t|j| t|j| t jddgddgg|d}t j|\}}t|jt| t|jt| d S r   )r$   r   r   r   r   r-   r6   rC   r-   r   wvr'   r'   r(   r   k  s    zTestEig.test_typesc                 C   s   G dd dt j}t jdt jd|}t|\}}t|jj	t j
u  t|jj	t j
u  t|j|j td|j tt|t j t jdt jd|}t|\}}t|jj	t ju  t|jj	t ju  t|j|j td|j tt|t j d S )Nc                   @   s   e Zd ZdS )z*TestEig.test_0_size.<locals>.ArraySubclassNr   r'   r'   r'   r(   r   y  s   r   r   r4   r   r[   r\   )r$   r%   r   r   r   r   r   r   r-   r"   r   r   ro   r#   r   rC   r   r/   r   Zres_vr'   r'   r(   r   w  s    zTestEig.test_0_sizeNr   r'   r'   r'   r(   r   j  s   
r   c                   @   s.   e Zd ZdZejdeee	e
gdd ZdS )SVDBaseTestsFr-   c                 C   s   t jddgddgg|d}t|}|j|j|j  }}}t|j| t|jt	| t|j| tj|d| j
d}t|jt	| d S )Nr^   r   r4   F
compute_uvr<   )r$   r   r   svdUSVhr   r-   r5   r<   )rC   r-   r   r   r   r   r   r   r'   r'   r(   r     s    
zSVDBaseTests.test_typesN)rK   rL   rM   r<   r   r   r   r   r   r   r   r   r'   r'   r'   r(   r     s   r   c                   @   s   e Zd Zdd ZdS )SVDCasesc              	   C   sp   t |d\}}}t|tt|t|dd d d f  t|t|jd tt	|| tt	|| d S )NF.r   )
r   r   r   r	   r$   r   r7   r-   r   r)   )rC   r/   r0   rB   ur   vtr'   r'   r(   rF     s    &zSVDCases.doNr   r'   r'   r'   r(   r     s   r   c                   @   s   e Zd Zdd Zdd ZdS )TestSVDc                 C   s   t d}tj|d| jd\}}}t|jd t|jd t|t d t d}tj|d| jd\}}}t|jd t|jd t|t d dS )	z6 Empty input should put an identity matrix in u or vh )ra   r   Tr   ra   ra   r[   ra   )r   ra   N)r$   r   r   r   r<   r   ro   eye)rC   r   r   r   Zvhr'   r'   r(   test_empty_identity  s    

zTestSVD.test_empty_identityc                 C   s@   t ddgddgg}tj|d| jd}t|}t|| d S )Nr^   r   Fr   )r$   r   r   r   r<   Zsvdvalsr   )rC   r   Z
s_from_svdZs_from_svdvalsr'   r'   r(   test_svdvals  s    
zTestSVD.test_svdvalsN)rK   rL   rM   r   r   r'   r'   r'   r(   r     s   r   c                   @   s   e Zd Zdd ZdS )SVDHermitianCasesc              	   C   s   t j|ddd\}}}t|tt|t|dd d d f  t|t|jd dd }tt|||t	t
|jd |j tt|||t	t
|jd |j tt|dd d df | tt|| tt|| d S )	NFTr<   .r   c                 S   s<   t t| j}|d |d  |d< |d< ttj| |dS )Nrj   ri   axes)r   rangerl   r$   conj	transpose)matr   r'   r'   r(   r<     s    z'SVDHermitianCases.do.<locals>.hermitianri   )r   r   r   r	   r$   r   r7   r-   r   r   r   ro   r   sortr   r)   )rC   r/   r0   rB   r   r   r   r<   r'   r'   r(   rF     s    &,,zSVDHermitianCases.doNr   r'   r'   r'   r(   r     s   r   c                   @   s   e Zd ZdZdS )TestSVDHermitianTN)rK   rL   rM   r<   r'   r'   r'   r(   r    s   r  c                   @   s   e Zd Zdd ZdS )	CondCasesc                 C   s  t |}d|v r"tttj| d S tj|dd}tt||d |d  ddd tt|d	|d |d  ddd tt|d
|d |d  ddd tj|}tt|dt	|
d
dt	|
d
d ddd tt|dt	|
d
dt	|
d
d ddd tt|tjt	|
ddt	|
dd ddd tt|tj t	|
ddt	|
dd ddd tt|dtt	|d	 
d
dt	|d	 
d
d ddd d S )Nr8   F)r   r   ).ri   rf   re   r1   r2   r_   rj   r^   ri   fro)r   r   r   r   condr   r   r$   r   rv   summaxminr   sqrt)rC   r/   r0   rB   cr   Zcinvr'   r'   r(   rF     sZ    
&
&&&
zCondCases.doNr   r'   r'   r'   r(   r    s   r  c                   @   s>   e Zd Zdd Zdd Zejjddddd	d
 Zdd Z	dS )TestCondc                 C   s   t g dg dg dg}tt|td tt|t d tt|dd tt|dd tt|d	td
 d S )N)rT   r   r^   )r   g       r   )r   r   rV   ra   gUUUUUU?r^   ri   r   r  gUUUUU6@)r   r   r   r  r   r$   r  rC   Ar'   r'   r(   test_basic_nonsvd  s    zTestCond.test_basic_nonsvdc                 C   st   t dt dg}g d}ddg}t||D ]\}}tt||dk q0t||D ]\}}t|| qZd S )Nr   Nr^   r_   r  ri   rj     4&kC)r$   r   onesr   r   r   r   r  )rC   ZAsp_posZp_negr  pr'   r'   r(   test_singular  s    zTestCond.test_singularTFz/Platform/LAPACK-dependent failure, see gh-18914)runreasonc                 C   s   g d}g d}t d}t j|d< |D ].}t||}tt|t j tt | q(t d}t j|d< |D ]t}t||}tt |d  ||v rt|d d	k t|d
 d	k qptt |d   tt |d
   qpd S )N)Nr^   ri   r_   rj   r  r  r   r   )r`   r_   r_   r^   r   r^   r^   r   r  r_   )	r$   r  nanr   r  r   r#   r   isnan)rC   Zpsr  r  r  r  r'   r'   r(   test_nan  s$    



zTestCond.test_nanc                 C   s   t jd t jdddd}d|d< d|d< dD ]T}t||}t|d t j t|d t j tt 	|d  tt 	|d  q2d S )	NrS   r_   r   r[   r   )Nr^   r_   r  ri   rj   r   r^   r   )
r$   randomseedrandr   r  r   r   r   isfinite)rC   r  r  r  r'   r'   r(   test_stacked_singular6  s    zTestCond.test_stacked_singularN)
rK   rL   rM   r  r  r   r   xfailr  r"  r'   r'   r'   r(   r    s   	

r  c                   @   s   e Zd Zdd ZdS )	PinvCasesc                 C   s<   t |}t}t||||||ddd tt|| d S )Nrf   re   r  r   pinvr	   r   r   r)   rC   r/   r0   rB   Za_ginvr   r'   r'   r(   rF   K  s    
zPinvCases.doNr   r'   r'   r'   r(   r$  F  s   r$  c                   @   s   e Zd ZdS )TestPinvNr   r'   r'   r'   r(   r(  S  s   r(  c                   @   s   e Zd Zdd ZdS )PinvHermitianCasesc                 C   s@   t j|dd}t}t||||||ddd tt|| d S )NTr   rf   re   r  r%  r'  r'   r'   r(   rF   Y  s    zPinvHermitianCases.doNr   r'   r'   r'   r(   r)  W  s   r)  c                   @   s   e Zd ZdS )TestPinvHermitianNr   r'   r'   r'   r(   r*  a  s   r*  c                  C   s   t g dg dg dg} tt jj| ddt jj| dd tjtdd" t jj| ddd	 W d    n1 st0    Y  d S )
Nr^   r_   r`   )ra   r^   r^   )r_   r`   r^   r   rcondr   z%`rtol` and `rcond` can't be both set.)match)r-  r   )r$   r   r   r   r&  r   Zraisesr   )r/   r'   r'   r(   test_pinv_rtol_arge  s    r/  c                   @   s   e Zd Zdd ZdS )DetCasesc                 C   s   t |}t |}|j|j }}t|jjtt	fv rFt|
t	}nt|
t}t |}	t|tj|	dd t|t| tj|	dd t|}t|}|dk}
tt||
 d t||
  t  d S )Nri   axisr   r^   )r   detslogdetsignZ	logabsdetr   r-   r"   r   r   astyper   r   r   r   reducer$   expZ
atleast_1drv   r   r   )rC   r/   r0   rB   dr   r   ldadr   mr'   r'   r(   rF   u  s    




zDetCases.doNr   r'   r'   r'   r(   r0  s  s   r0  c                   @   s:   e Zd Zdd Zejdeee	e
gdd Zdd ZdS )	TestDetc                 C   s   t tdggd t ttdggt t tdggd t ttdggt t tdggdt f t ttdggd t t ttdggd t t tdggdt f t ttdggd t t ttdggd t d S )N        y                r   r^   )r   r   r3  r"   r   r   r4  r   rI   r'   r'   r(   	test_zero  s    zTestDet.test_zeror-   c                 C   s^   t jddgddgg|d}tt j|j| t j|\}}t|jt| t|j| d S r   )r$   r   r   r   r3  r-   r4  r5   )rC   r-   r   phr   r'   r'   r(   r     s
    zTestDet.test_typesc                 C   s   t jdt jd}t|}t|d t|jjt ju  t	|}t|d t|d jjt ju  t|d jjt j
u  t jdt jd}t|}t|d t|jjt ju  t	|}t|d t|d jjt ju  t|d jjt ju  d S )Nr[   r4   rT   r  r   r^   )r$   r   r   r   r3  r   r   r-   r"   r4  float32r   )rC   r/   r   r'   r'   r(   r     s     







zTestDet.test_0_sizeN)rK   rL   rM   r?  r   r   r   r   r   r   r   r   r   r'   r'   r'   r(   r=    s   
r=  c                   @   s   e Zd Zdd ZdS )
LstsqCasesc                 C   sL  t |}|j\}}t|d\}}}	tj||dd\}
}}}|dkrVt|
dk  ||krzt|t	||
 t
|| n
t
|| t||| ||kr||krt tt 	||
| d jdd}t |}t |jdkrd|_t
|j|j nt g t|
}t|| tt |jt j tt|
| tt|| d S )	NFri   r,  r   r_   r1  r^   rs   )r$   r   ro   r   r   lstsqr   r   r   r   r   Z__array_wrap__rv   r  rl   r   r   r"   
issubdtyper-   floatingr)   )rC   r/   r0   rB   arrr<  nr   r   r   r   	residualsranksvZexpect_residsr'   r'   r(   rF     s2    




zLstsqCases.doNr   r'   r'   r'   r(   rB    s   rB  c                   @   s:   e Zd Zdd Zejg dg ddd Zdd Zd	S )
	TestLstsqc                 C   s   t g dg dg dg dgj}t g d}tj||dd\}}}}t|dk t||\}}}}t|d	k tj||d d\}}}}t|d	k d S )
N)r>  rT   r>  rT   rU   r>  )r>  rU   r>  r>  rT   r>  )rT   r>  rT   r>  r>  rW   )r>  r>  r>  rU   rV   r>  )r^   r   r   r   r   r   ri   r,  ra   r`   )r$   r   Tr   rC  r   )rC   r/   r0   r   rH  rI  r   r'   r'   r(   
test_rcond  s    
zTestLstsq.test_rcond)r<  rG  n_rhs))ra   r_   r_   )r   ra   r^   )r   ra   r_   )ra   r   r^   )ra   r   r_   )ra   r_   r   r   r   r   c                 C   s   t || ||}t ||f}tj||d d\}}}}	|dkrTt|dk  t|j	||f t|j	||krx|fnd ||kr|dkr|t 
|| }
t||
|
 jdd t|t|| t|	j	t||f d S )Nr,  r   r\   rj   r1  )r$   r   rn   r  r   rC  r   r   r   ro   r   r   r  r
  )rC   r<  rG  rN  r/   r0   r   rH  rI  r   r   r'   r'   r(   test_empty_a_b  s    
zTestLstsq.test_empty_a_bc                 C   st   t g d}t g d}t |t t|gj}ttd  tj	||d d W d    n1 sf0    Y  d S )N)r   r^   r_   r`   )ri   g?g?g @gffffff
@zIncompatible dimensionsr,  )
r$   r   Zvstackr  lenrL  r   r   r   rC  )rC   r   yr  r'   r'   r(   test_incompatible_dims  s
    z TestLstsq.test_incompatible_dimsN)	rK   rL   rM   rM  r   r   r   rP  rS  r'   r'   r'   r(   rK    s   	
rK  dtc                 C   s   g | ]}t |qS r'   )r$   r-   )rw   r  r'   r'   r(   rx     ry   rx   z?bBhHiIqQefdgFDGOc                   @   s   e Zd ZedZeg d Zeg d Zeg d ZeeeegZ	e
ddgddggZeegggd Zeeded	ed
gZdd Zdd Zdd Zdd Zdd Zdd Zdd Zejjedddd ZdS )TestMatrixPowerra   )r`   r   r^   r_   )r_   r`   r   r^   )r^   r_   r`   r   r^   r   r_   r   gGc                 C   s   | j |}tt|dd d d d | j tt|dd d d d | j  tt|dd d d d | j tt|dd d d d | j d S )Nr_   d   i       r   r^   r`   )rshft_1r6  r   r   rshft_0rshft_2rshft_3)rC   rT  Zrshftr'   r'   r(   test_large_power  s    z TestMatrixPower.test_large_powerc                 C   s>   dd }| j D ]*}||| |tkr|| j| qd S )Nc                 S   s*   t | d}t|t|  t|j| j d S )Nr   )r   r   r   r-   )Mmzr'   r'   r(   tz  s    
z.TestMatrixPower.test_power_is_zero.<locals>.tz	rshft_allr6  objectstackedrC   rT  ra  r  r'   r'   r(   test_power_is_zero  s
    
z"TestMatrixPower.test_power_is_zeroc                 C   s>   dd }| j D ]*}||| |tkr|| j| qd S )Nc                 S   s&   t | d}t||  t|j| j d S )Nr^   )r   r   r-   )r  r`  r'   r'   r(   ra  %  s    

z-TestMatrixPower.test_power_is_one.<locals>.tzrb  rf  r'   r'   r(   test_power_is_one$  s
    
z!TestMatrixPower.test_power_is_onec                 C   s>   dd }| j D ]*}||| |tkr|| j| qd S )Nc                 S   s>   t | d}| jtkrtnt}t||| |  t|j| j d S )Nr_   )r   r-   rd  r	   r   r   )r  r`  mmulr'   r'   r(   ra  0  s    
z-TestMatrixPower.test_power_is_two.<locals>.tzrb  rf  r'   r'   r(   test_power_is_two/  s
    
z!TestMatrixPower.test_power_is_twoc                 C   s0   dd }| j D ]}|| jvr||| qd S )Nc                 S   s4   t | d}| jtkrtnt}t||| t|  d S Nri   )r   r-   rd  r	   r   r   r   )r  Zinvmatri  r'   r'   r(   ra  <  s
    
z3TestMatrixPower.test_power_is_minus_one.<locals>.tz)rc  dtnoinvr6  rf  r'   r'   r(   test_power_is_minus_one;  s    

z'TestMatrixPower.test_power_is_minus_onec                 C   s.   | j |}ttt|d ttt|dg d S )Ng      ?r^   )r[  r6  r   	TypeErrorr   rC   rT  r  r'   r'   r(   test_exceptions_bad_powerF  s    z)TestMatrixPower.test_exceptions_bad_powerc                 C   sP   t tttdg|d t tttdgdgg|d t tttd|d d S )Nr^   r_   )ra   r`   r_   )r   r   r   r$   r   r  )rC   rT  r'   r'   r(   test_exceptions_non_squareK  s    z*TestMatrixPower.test_exceptions_non_squarefp errors don't work in wasmr  c                 C   s,   || j v rd S | j|}ttt|d d S rk  )rl  noninvr6  r   r   r   ro  r'   r'   r(   test_exceptions_not_invertibleP  s    
z.TestMatrixPower.test_exceptions_not_invertibleN)rK   rL   rM   r$   r   r[  rZ  r\  r]  rc  r   rt  blockre  rd  r-   rl  r^  rg  rh  rj  rm  rp  rq  r   r   skipifr    ru  r'   r'   r'   r(   rU    s"   
rU  c                   @   s   e Zd Zdd ZdS )TestEigvalshCasesc                 C   s^   t |d}t |\}}|jdd t||t|jd t |d}t||t|jd d S )NLri   r1  r   r   )r   eigvalshr   r  r   r7   r-   )rC   r/   r0   rB   r   r   r   ev2r'   r'   r(   rF   Z  s    zTestEigvalshCases.doNr   r'   r'   r'   r(   rx  X  s   rx  c                   @   sB   e Zd Zejdeeee	gdd Z
dd Zdd Zdd	 Zd
S )TestEigvalshr-   c                 C   s:   t jddgddgg|d}t j|}t|jt| d S r   )r$   r   r   rz  r   r-   r5   )rC   r-   r   r   r'   r'   r(   r   g  s    zTestEigvalsh.test_typesc                 C   sX   t jddgddggt jd}ttt jj|dd ttt jj|d ttt jj|d d S Nr^   r   r4   ZlrongZUPLOlowerupper)r$   r   rA  r   r   r   rz  rC   r   r'   r'   r(   test_invalidm  s    zTestEigvalsh.test_invalidc                 C   s   t jddgddggt jd}t jddgddggt jd}t jddgt jd}tt j}t j|}t|||d t jj|dd}t|||d t jj|dd}t|||d t jj|d	d}t|||d t jj|d
d}t|||d d S Nr   r^   r4   ri   r   ry  r~  lr   r   )r$   r   r   r7   r   rz  r   )rC   KloKuptgtr   r   r'   r'   r(   	test_UPLOs  s    
zTestEigvalsh.test_UPLOc                 C   s   G dd dt j}t jdt jd|}t|}t|jj	t j
u  td|j tt|t j t jdt jd|}t|}t|jj	t ju  td|j tt|t j d S )Nc                   @   s   e Zd ZdS )z/TestEigvalsh.test_0_size.<locals>.ArraySubclassNr   r'   r'   r'   r(   r     s   r   r   r4   r   r[   r\   )r$   r%   r   r   r   r   rz  r   r-   r"   r   r   ro   r#   r   rA  r   r'   r'   r(   r     s    

zTestEigvalsh.test_0_sizeNrK   rL   rM   r   r   r   r   r   r   r   r   r  r  r   r'   r'   r'   r(   r|  f  s
   
r|  c                   @   s   e Zd Zdd ZdS )TestEighCasesc                 C   s   t |}|j|j }}t |\}}|jdd t|| tt||t	
|dd d d f t	
| t|jd t |d\}	}
t|	| tt||
t	
|	dd d d f t	
|
 t|jt|d d S )Nri   r1  .r   r   )r   err_msg)r   eighr   r   r   r  r   r   r	   r$   r   r7   r-   repr)rC   r/   r0   rB   r   r   Zevcr   r   r{  Zevc2r'   r'   r(   rF     s    


 

 zTestEighCases.doNr   r'   r'   r'   r(   r    s   r  c                   @   sB   e Zd Zejdeeee	gdd Z
dd Zdd Zdd	 Zd
S )TestEighr-   c                 C   sJ   t jddgddgg|d}t j|\}}t|jt| t|j| d S r   )r$   r   r   r  r   r-   r5   r   r'   r'   r(   r     s    zTestEigh.test_typesc                 C   sX   t jddgddggt jd}ttt jj|dd ttt jj|d ttt jj|d d S r}  )r$   r   rA  r   r   r   r  r  r'   r'   r(   r    s    zTestEigh.test_invalidc                 C   s   t jddgddggt jd}t jddgddggt jd}t jddgt jd}tt j}t j|\}}t|||d t jj|dd\}}t|||d t jj|dd\}}t|||d t jj|d	d\}}t|||d t jj|d
d\}}t|||d d S r  )r$   r   r   r7   r   r  r   )rC   r  r  r  r   r   r   r'   r'   r(   r    s    
zTestEigh.test_UPLOc                 C   s   G dd dt j}t jdt jd|}t|\}}t|jj	t j
u  t|jj	t j
u  t|j|j td|j tt|t j t jdt jd|}t|\}}t|jj	t ju  t|jj	t ju  t|j|j td|j tt|t j d S )Nc                   @   s   e Zd ZdS )z+TestEigh.test_0_size.<locals>.ArraySubclassNr   r'   r'   r'   r(   r     s   r   r   r4   r   r[   r\   )r$   r%   r   r   r   r   r  r   r-   r"   r   r   ro   r#   r   rA  r   r'   r'   r(   r     s    zTestEigh.test_0_sizeNr  r'   r'   r'   r(   r    s
   
r  c                   @   s    e Zd ZdZdZedd ZdS )_TestNormBaseNc                 C   s:   t | jjtjr"t|j| jj ntt |jjtj d S r!   )	
issubclassr-   r"   r$   Zinexactr   realr   rE  )r   r   r'   r'   r(   check_dtype  s    z_TestNormBase.check_dtype)rK   rL   rM   rT  decstaticmethodr  r'   r'   r'   r(   r    s   r  c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )_TestNormGeneralc                 C   sF   t tg d t ttg | jdd t tttg | jdd d S )Nr>  r4   )r   r   r   rT  r   rI   r'   r'   r(   
test_empty  s    z_TestNormGeneral.test_emptyc           	   	   C   s  t g d}t jd }t jd }|| }|D ]N}||}t|t j }| || t|d t <}|	t
d t|d}| || t|d W d    n1 s0    Y  t|d}| || t|d t|d	}| || t|d
 t|d}| || t||jd
|jd  t|d}| || t||jd
|jd  t|t j}| || t|d q.d S )Nr  
AllIntegerZAllFloatr>  divide by zero encounteredri   r   r_   r^   rU   r   ra   g      ?rT   )r$   r   	typecodesr6  r   r   r  r   r   filterRuntimeWarningr-   r"   	rC   r/   Zexact_typesZinexact_typesZ	all_typesZ	each_typeatZansupr'   r'   r(   test_vector_return_type  s:    





(





z(_TestNormGeneral.test_vector_return_typec                    sv   g d}g d}g d} fdd}|||fD ]}|| q.t | jdt | jdt | jdfD ]}|| qdd S )N)r^   r_   r`   ra   )ri   rj   ru   rt   )ri   r_   ru   ra   c                    s   t jjt| d jd t jjt| td jd t jjt| t d jd t jjt| dd jd t jjt| dd jd t jjt| d	d jd t jjt| d
d jd t jjt| dd jd d S )Ng6ҭ@r,   rW   rT   r^         $@ri   gQ?r_   rj   gsc?r   ra   )r$   testingr   r   r  r   )r   rI   r'   r(   _test0  s0    z+_TestNormGeneral.test_vector.<locals>._testr4   )r   rT  )rC   r/   r0   r  r  r   r'   rI   r(   test_vector+  s    
z_TestNormGeneral.test_vectorc           	   	      s  t g dg dg| jd d dddddtjtj fD ]h fd	d
t jd D }tt dd|  fdd
t jd D }tt dd| q4tjdd| jd	dddj
}d ddddtjtj dfD ]؉tt| |dD ]}|\}}|dk r||7 }|dk r"||7 }||kr@ttt|d qt|d}|||  ||k rfdd
tj D }n fdd
tj D }t|| qqd S )Nr+  ra   rf   r*   r4   ri   r   r^   r_   r`   c                    s$   g | ]}t  d d |f dqS Nordr   rw   kr  orderr'   r(   rx   O  ry   z._TestNormGeneral.test_axis.<locals>.<listcomp>r  r2  c                    s$   g | ]}t  |d d f dqS r  r  r  r  r'   r(   rx   Q  ry      ra   rj   r  c                    s*   g | ]"}t  d d  j|ddqS Nr1  r  )r   taker  Bk_indexr  r'   r(   rx   g  s   c                    s,   g | ]$}t  d d  j|djdqS r  )r   r  rL  r  r  r'   r(   rx   j  s   )r   rT  r$   r   r   ro   r   r   r   rn   rl   r   combinationsr   r   )	rC   Z	expected0Z	expected1ndr2  Zrow_axisZcol_axisrG  r   r'   )r  r  r  r  r(   	test_axisI  s6    



z_TestNormGeneral.test_axisc           	   
   C   s  t jdd| jdddd}d}d}t|d d d	}t|d d d
d}tt |||d d d d}t|j	|k||j	|d d  d dddddt j
t j
 fD ]}t|jD ]v}t|||d	}t|||d
d}tt |||||d t|j	}d||< t|}t|j	|k||j	||| qqd ddddt j
t j
 ddf	D ]}tt|jdD ]}t|||d	}t|||d
d}tt |||||d t|j	}d||d < d||d < t|}t|j	|k||j	||| qTq>d S )Nr^   r  r4   r_   r`   ra   zorder {0}, axis = {1}z;Shape mismatch found {0}, expected {1}, order={2}, axis={3}r  T)r  r2  keepdims)r  )r^   r^   r^   ri   r   rj   r  nuc)r$   r   rT  rn   r   r   Zsqueezeformatr   ro   r   r   rl   r   r   r   permutations)	rC   r  Zallclose_errZ	shape_errr   foundZexpected_shaper  r  r'   r'   r(   test_keepdimsn  sN    




 


z_TestNormGeneral.test_keepdimsN)rK   rL   rM   r  r  r  r  r  r'   r'   r'   r(   r    s
   )%r  c                   @   s:   e Zd ZejZdd Zdd Zdd Zdd Zd	d
 Z	dS )_TestNorm2Dc                 C   s    t t| jg g| jdd d S )Nr4   r>  )r   r   r   rT  rI   r'   r'   r(   test_matrix_empty  s    z_TestNorm2D.test_matrix_emptyc           	   	   C   s  |  g dg dg}tjd }d}|| }|D ]N}||}t|tj }| || t|d t <}|	t
d t|d}| || t|d W d    n1 s0    Y  t|d	}| || t|d t|d
}| || t|d t|d}| || t|d t|tj}| || t|d t|d}| || t|d t|d}| || tjj|ddd q0d S )Nr  r   r  ZfdFDrU   r  ri   rT   r^   r_   gLXz?rj   r  r  gU&,t=@r*   r  )r   r$   r  r6  r   r   r  r   r   r  r  r  r  r'   r'   r(   test_matrix_return_type  s@    




(









z#_TestNorm2D.test_matrix_return_typec                 C   s   | j ddgddgg| jd}tt|d tt|dd tt|dd	 tt|td
 tt|t d tt|dd	 tt|dd tt|dd tt|dd ttt|d ttt|d ttt|d d S )Nr^   r`   rf   rg   r4   gT"@r  r  r  g      (@rW   ri   rX   r_   gW?"@rj   gїʄ?Znofroru   r   )r   rT  r   r   r   r   r   r  r'   r'   r(   test_matrix_2x2  s    z_TestNorm2D.test_matrix_2x2c                 C   s   d| j g dg dg dg| jd }tt|d tt|dd tt|dd	 tt|td
 tt|t d tt|dd tt|dd tt|dd tt|dd d S )Ng?r+  )r*   r   rf   )r`   r_   r^   r4   grj=Q0?r  r  gB+pc?g?g333333?r^   rT   ri   g?r_   g&.d?rj   gܸՠ?)r   rT  r   r   r   r  r'   r'   r(   test_matrix_3x3  s     z_TestNorm2D.test_matrix_3x3c                 C   s  | j g dg dg| jd}tjdd| jdddd}ttt|d	d
 ttt|dd
 tttddgd	d  tttddgdd  tttddgdd  dD ]4}ttt||d  ttt||d ttt||d qttt|d d ttt|d d ttt|d d d S )Nr+  r  r4   r^   r  r_   r`   ra   r  r   r  testr   r`   r   )r^   r_   r_   r`   r   r^   r_   )	r   rT  r$   r   rn   r   r   r   r   )rC   r  r  r  r'   r'   r(   test_bad_args  s    z_TestNorm2D.test_bad_argsN)
rK   rL   rM   r$   r   r  r  r  r  r  r'   r'   r'   r(   r    s   3r  c                   @   s   e Zd ZdS )	_TestNormNr   r'   r'   r'   r(   r    s   r  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestNorm_NonSystematicc                 C   s*   t jdt jd}tt|ddddd d S )N
   r4   r`   r  gL)@r_   r  )r$   r   Z
longdoubler.   r   r  r'   r'   r(   test_longdouble_norm  s    z+TestNorm_NonSystematic.test_longdouble_normc                 C   s,   t jdgt jd}tt|ddddd d S )Ni   r4   r`   r  l        rf   r  )r$   r   Zint32r.   r   r  r'   r'   r(   test_intmin  s    z"TestNorm_NonSystematic.test_intminc                 C   s   t jdt jd}d|d< d|d< d}tt jj|dd	|d
d |t j}tt jj|dd	|dd |t j}tt jj|dd	|dd d S )Nr_   r4   y      @      @r   y            @r^   gV;'@r`   r  r  r  	   rf   )	r$   r   Zclongdoubler.   r   r   r6  
complex128r   )rC   r9  r   r'   r'   r(   test_complex_high_ord#  s    z,TestNorm_NonSystematic.test_complex_high_ordN)rK   rL   rM   r  r  r  r'   r'   r'   r(   r    s   r  c                   @   s   e Zd ZejZdZdS )_TestNormDoubleBaser+   N)rK   rL   rM   r$   r   rT  r  r'   r'   r'   r(   r  1  s   r  c                   @   s   e Zd ZejZdZdS )_TestNormSingleBaser*   N)rK   rL   rM   r$   rA  rT  r  r'   r'   r'   r(   r  6  s   r  c                   @   s   e Zd ZejZdZdS )_TestNormInt64Baser+   N)rK   rL   rM   r$   Zint64rT  r  r'   r'   r'   r(   r  ;  s   r  c                   @   s   e Zd ZdS )TestNormDoubleNr   r'   r'   r'   r(   r  @  s   r  c                   @   s   e Zd ZdS )TestNormSingleNr   r'   r'   r'   r(   r  D  s   r  c                   @   s   e Zd ZdS )TestNormInt64Nr   r'   r'   r'   r(   r  H  s   r  c                   @   s   e Zd Zdd Zdd ZdS )TestMatrixRankc                 C   s   t dttd td}d|d< t t|d t ttdd t tg dd t ttd	d t tdgd t|tdtdg}t t|tg d
 t tdd ttd t|ddd W d    n1 s0    Y  d S )Nra   r>  ri   ri   r`   r   r   )r^   r   r   r   r^   )ra   )r`   ra   r   z#`tol` and `rtol` can't be both set.g{Gz?)tolr   )r   r   r$   r   r   r   r   r   )rC   Imsr'   r'   r(   test_matrix_rankN  s    
zTestMatrixRank.test_matrix_rankc                 C   s   t dttddd t dttddd t dttddd td}d|d< t d	t|dd d
|d< t dt|ddd t d	t|ddd d S )Nra   Tr   r^   r   r   r>  r  r`   g:0yE>g|"BE>)r<   r  g;䡈E>)r   r   r$   r   r  r   )rC   r  r'   r'   r(   test_symmetric_rankg  s    
z"TestMatrixRank.test_symmetric_rankN)rK   rL   rM   r  r  r'   r'   r'   r(   r  L  s   r  c                  C   s   t jd} tdD ]}| jdd}|d d df |d d df  |d d df< tt|d |d d d	f |d d d
f  |d d df< tt|d qd S )Ni3rX  )(   r  sizer^   r_   r   r  ra   rf   r`   r]   )r$   r  ZRandomStater   normalr   r   )rngiXr'   r'   r(   test_reduced_ranku  s    ,,r  c                	   @   s   e Zd ZejZdd Zejddgg ddd Z	dd	 Z
d
d Zdd Zejdg dejdg dejdejejejejgdd ZdS )TestQRc                 C   s  t |}|j}|j\}}t||}tj|dd}|j|j }}	t|j|k t|	j|k tt	|| tt	|	| t|j||fk t|	j||fk t
t||	| t
t|j |t| t
t|	|	 tj|dd\}
}t|
j|k t|j|k tt	|
| tt	|| t|
j||fk t|j||fk t
t|
|| t
t|
j |
t| t
t|| tj|dd}t|j|k tt	|| t
|| d S )Ncompletemodereducedr   )r"   r-   ro   r
  r   qrQRr   r#   r   r   rL  r   r$   r   triu)rC   r/   a_typea_dtyper<  rG  r  r   r  r  q1r1r2r'   r'   r(   check_qr  s:    

zTestQR.check_qrr<  rG  )r`   r   r  r[   c                 C   st   t ||}t||f}| | tjj|dd\}}t|jtj t|jtj t|j	||f t|j	|f d S )Nrawr  )
r
  r$   r   r  r   r  r   r-   r   ro   )rC   r<  rG  r  r/   htaur'   r'   r(   test_qr_empty  s    

zTestQR.test_qr_emptyc                 C   s   | j ddgddgddggtjd}tj|dd	\}}t|jtjk t|jtjk t|jd
k t|jdk tj|jdd	\}}t|jtjk t|jtjk t|jdk t|jdk d S )Nr^   r_   r`   ra   rf   r*   r4   r  r  r  r  rh   )	r   r$   r   r   r  r   r-   ro   rL  )rC   r/   r  r  r'   r'   r(   test_mode_raw  s    "zTestQR.test_mode_rawc                 C   s   |  ddgddgg}|  ddgddgddgg}dD ]8}||}||}| | | | | |j q6dD ]H}dd||  }dd||  }| | | | | |j qtd S )	Nr^   r_   r`   ra   rf   r*   fd              ?)r   r6  r  rL  )rC   r/   r0   rT  m1m2r'   r'   r(   test_mode_all_but_economic  s    





z!TestQR.test_mode_all_but_economicc                 C   sf  t |}|j}|jdd  \}}t||}tj|dd\}}t|j|k t|j|k tt|| tt|| t|jdd  ||fk t|jdd  ||fk tt	||| t
|jd }	t
|	|jd d |jd fd  }
tt	t|dd ||
 tt
|dd d d d f | tj|dd\}}t|j|k t|j|k tt|| tt|| t|jdd  ||fk t|jdd  ||fk tt	||| t
|jd }	t
|	|jd d |jd fd  }
tt	t|dd ||
 tt
|dd d d d f | tj|dd}t|j|k tt|| t|| d S )	Nrj   r  r  ri   r_   .r  r   )r"   r-   ro   r
  r   r  r   r#   r   r	   r$   r   r   r
   r   r  )rC   r/   r  r  r<  rG  r  qr   ZI_matZstack_I_matr  r  r  r'   r'   r(   check_qr_stacked  sL    
""zTestQR.check_qr_stackedr  ))r`   ra   )ra   r`   r   r  r  
outer_size)r   r  )r_   r`   ra   rT  c                 C   sX   t jd}|j|| d|}|j|| d|}| | | |d|   d S )N{   r  r  )r$   r  Zdefault_rngr  r6  r  )rC   r  r  rT  r  r  r  r'   r'   r(   test_stacked_inputs  s
    

zTestQR.test_stacked_inputsN)rK   rL   rM   r$   r   r  r   r   r   r  r  r  r  r   r   r   r   r  r'   r'   r'   r(   r    s   (
-r  c                   @   sf   e Zd Zejdg dejdejejej	ej
fejdddgdd Zd	d
 Zdd ZdS )TestCholeskyro   )r   r   r`   r`   )2   r  )r`   r  r  r-   r  FTc           
      C   s^  t jd t jj| }t |t jr:|dt jj|   }ttt|}d|dd < t 	|
| |}t j||d}t jj||d}|rt 	|
| |}nt 	||
| }t  * d|jd  t |j }W d    n1 s0    Y  t|||| d	| d
| d
| d t j|ddd}	tt t |	 tt |	dk d S )Nr^   r  )ri   rj   rj   r4   r  i  r    
)atolr  ri   )Zaxis1Zaxis2)r$   r  r  randnrD  Zcomplexfloatingr   r   rQ  r	   r   r   r   r   choleskyZ_no_nep50_warningro   Zfinfoepsr   diagonalr   r   Zisreal)
rC   ro   r-   r  r/   tr  r0   r  r9  r'   r'   r(   test_basic_property&  s$    	
8&z TestCholesky.test_basic_propertyc                 C   s   G dd dt j}t jdt jd|}t|}t|j|j t	|j
jt ju  t	t|t j t jdt jd|}t|}t|j|j t	|j
jt ju  t	t|t j d S )Nc                   @   s   e Zd ZdS )z/TestCholesky.test_0_size.<locals>.ArraySubclassNr   r'   r'   r'   r(   r   K  s   r   r   r4   )r^   r   r   )r$   r%   r   r   r   r   r  r   ro   r   r-   r"   r   r#   r   r   r'   r'   r(   r   J  s    

zTestCholesky.test_0_sizec                 C   sT   t ddgddgg}tt|tj|dd ttj|ddt|j  d S )Ny      ?        y               y               @y      @        Fr  T)r$   r   r   r   r  rL  r   )rC   r/   r'   r'   r(   test_upper_lower_argZ  s    z!TestCholesky.test_upper_lower_argN)rK   rL   rM   r   r   r   r$   rA  r   r   r  r  r   r  r'   r'   r'   r(   r  $  s   r  c                   @   s   e Zd ZedZedZeg dg dg dgZe	ej
eee eed, ej
eddejf e W d   n1 s0    Y  dS )	TestOuterr`   rO  r  )r   r_   ra   z$Input arrays must be one-dimensionalN)rK   rL   rM   r$   r   Zarr1Zarr2r   r   r   r   outerr   r   Znewaxisr'   r'   r'   r(   r  f  s   

r  c                  C   s   t jdkrd} nd} tjtjfD ]}tjd|d}||j| }||jd	 }t
|jjd tjtjtjfD ](}||}t||| t||| qxq d S )Nlittle<rH   ra   r4   r   =)sys	byteorderr$   rA  r   r   r   r-   Znewbyteorderbyteswapr   r   r   r3  r&  r   )nativeZdttrF  Zn_arrZsw_arrZroutiner   r'   r'   r(   test_byteorder_checkw  s    
r  rr  rs  c                  C   sl   t ddgddgg} t ddgddgg}t g ddd d }| |d< ||d< tt jjt jj| d S )Nr^   r_   r`   ra   )ra   ra   r_   r_   .r[   )r$   r   r   r   r   r   r   )Z
invertibleZnon_invertibler   r'   r'   r(    test_generalized_raise_multiloop  s    r  c                  C   sL  d} zt  }W n  ttfy0   td Y n0 |dkr"t d t d dd l}||j	d zt
jj  W n. ty   Y n ty   t t j Y n0 z0t
dgg}t
jjddd|d||dd	 W n< ty } z"dt|v rt |  W Y d }~n
d }~0 0 t t j n&t  \}}t || krHtd d S )	N   zNot POSIX or fork failed.r   r^   r[   rT   zDORGQR parameter number 5zNumpy xerbla not linked in.)osforkOSErrorAttributeErrorr   skipcloseresourceZ	setrlimitZRLIMIT_COREr$   r   lapack_liteZxerblar   r   _exit	EX_CONFIGr   Zdorgqrr?   waitWEXITSTATUS)Z	XERBLA_OKpidr%  r/   r   statusr'   r'   r(   test_xerbla_override  s<    


 r-  zCannot start subprocessc                  C   sd   ddg} t d}| D ]H}|jdd|d}ttjd|g |jdd|d}ttjd|g qd S )	NzPyQt5.QtWidgetsZIPythonz
    import sys
    {before}
    try:
        import {bad_lib}
    except ImportError:
        sys.exit(0)
    {after}
    x = np.ones(2, dtype=np.float32)
    sys.exit(0 if np.allclose(x.dot(x), 2.0) else 1)
    zimport numpy as np )beforeafterbad_libz-c)r0  r/  r1  )textwrapdedentr  
subprocess
check_callr  
executable)Zbad_libstemplater1  coder'   r'   r(   test_sdot_bug_8577  s    
r9  c                   @   sd   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )TestMultiDotc              	   C   sl   t jd}t jd}t jd}tt|||g||| tt|||gt |t || d S Nr*   r_   r_   r*   r$   r  r   r   r   )rC   r  r  Cr'   r'   r(   (test_basic_function_with_three_arguments  s
     z5TestMultiDot.test_basic_function_with_three_argumentsc                 C   sN   t jd}t jd}tt||g|| tt||gt || d S r;  r>  )rC   r  r  r'   r'   r(   &test_basic_function_with_two_arguments  s    z3TestMultiDot.test_basic_function_with_two_argumentsc                 C   s\   t jd}t jd}t jd}t jd}tt||||g|||| d S )Nr<  r=  r_   r^   r>  )rC   r  r  r?  Dr'   r'   r(   9test_basic_function_with_dynamic_programming_optimization  s
    zFTestMultiDot.test_basic_function_with_dynamic_programming_optimizationc                 C   sL   t jd}t jd}t jd}t jd}tt||||gjd d S )Nr_   r=  r<  r   r  r$   r  r   r   ro   )rC   A1dr  r?  rC  r'   r'   r(   test_vector_as_first_argument  s
    z*TestMultiDot.test_vector_as_first_argumentc                 C   sL   t jd}t jd}t jd}t jd}tt||||gjd d S )Nr<  r=  r_   )r*   rE  )rC   r  r  r?  D1dr'   r'   r(   test_vector_as_last_argument  s
    z)TestMultiDot.test_vector_as_last_argumentc                 C   sL   t jd}t jd}t jd}t jd}tt||||gjd d S )Nr_   r=  r<  r'   rE  )rC   rF  r  r?  rH  r'   r'   r(   &test_vector_as_first_and_last_argument!  s
    z3TestMultiDot.test_vector_as_first_and_last_argumentc              	   C   s   t jd}t jd}t jd}t d}t|||g|d}||u sLJ t|||| t|t |t || d S )Nr<  r=  r&   r$   r  r   r   r   r   )rC   r  r  r?  r&   retr'   r'   r(   test_three_arguments_and_out+  s    
z)TestMultiDot.test_three_arguments_and_outc                 C   sd   t jd}t jd}t d}t||g|d}||u s>J t||| t|t || d S )Nr<  r=  )r*   r*   rK  rL  )rC   r  r  r&   rM  r'   r'   r(   test_two_arguments_and_out8  s    
z'TestMultiDot.test_two_arguments_and_outc                 C   sz   t jd}t jd}t jd}t jd}t d}t||||g|d}||u sZJ t||||| d S )Nr<  r=  rB  )r*   r^   rK  rL  )rC   r  r  r?  rC  r&   rM  r'   r'   r(   -test_dynamic_programming_optimization_and_outB  s    
z:TestMultiDot.test_dynamic_programming_optimization_and_outc              	   C   s  t jdt jdt jdt jdt jdt jdg}t g dg dg d	g d
g dg dg}t jg dg dg dg dg dg dgtd}|d8 }t|dd\}}tt |d ddd f t |d ddd f  tt |t | d S )N)   #   )rR     )rS  rf   )rf   r  )r     )rT  r  )r>  g     @g     þ@g    O@g    1@g    @)r>  r>  g     @g     @g     ջ@g     @)r>  r>  r>  g     p@g     @g     @)r>  r>  r>  r>  g     @@g     X@)r>  r>  r>  r>  r>  g     @)r>  r>  r>  r>  r>  r>  )r   r^   r^   r`   r`   r`   )r   r   r_   r`   r`   r`   )r   r   r   r`   r`   r`   )r   r   r   r   ra   rf   )r   r   r   r   r   rf   )r   r   r   r   r   r   r4   r^   T)Zreturn_costsri   )r$   r  r   intr   r   r  )rC   ZarraysZ
m_expectedZ
s_expectedr   r<  r'   r'   r(   test_dynamic_programming_logicN  s:    







z+TestMultiDot.test_dynamic_programming_logicc                 C   s&   t ttg  t tttjdg d S )Nr  )r   r   r   r$   r  rI   r'   r'   r(   test_too_few_input_arraysl  s    z&TestMultiDot.test_too_few_input_arraysN)rK   rL   rM   r@  rA  rD  rG  rI  rJ  rN  rO  rP  rV  rW  r'   r'   r'   r(   r:    s   
	



r:  c                   @   sv   e Zd Zejdeddfeddfgdd Zejdd	d
gdd Z	ejdddgdd Z
dd ZdS )TestTensorinvzarr, indra   r*   r]   r_   r_   r`   r`   r_   r^   c                 C   s:   t t tj||d W d    n1 s,0    Y  d S )Nind)r   r   r   	tensorinv)rC   rF  r\  r'   r'   r(   test_non_square_handlings  s    
z&TestTensorinv.test_non_square_handlingz
shape, ind)ra   r*   r]   r`   r_   )   r]   r`   r^   c                 C   sN   t d}||_tj||d}|j|d  |jd |  }|j}t|| d S )Nra  r/   r\  )r$   r   ro   r   r]  r   )rC   ro   r\  r/   ainvr   actualr'   r'   r(   test_tensorinv_shape{  s    
z"TestTensorinv.test_tensorinv_shaper\  r   rj   c                 C   sJ   t d}d|_tt tj||d W d    n1 s<0    Y  d S )Nra  r_  rb  )r$   r   ro   r   r   r   r]  )rC   r\  r/   r'   r'   r(   test_tensorinv_ind_limit  s    

z&TestTensorinv.test_tensorinv_ind_limitc                 C   sJ   t d}d|_tj|dd}t d}tt ||dt j|| d S )Nra  r`  r^   r[  )	r$   r   ro   r   r]  r  r   	tensordottensorsolve)rC   r/   rc  r0   r'   r'   r(   test_tensorinv_result  s
    

z#TestTensorinv.test_tensorinv_resultN)rK   rL   rM   r   r   r   r$   r  r^  re  rf  ri  r'   r'   r'   r(   rX  q  s   


rX  c                   @   sT   e Zd Zejdeddfeddfgdd Zejdg d	d
d Z	dS )TestTensorsolveza, axesrY  NrZ  )r   r_   c                 C   sP   t t4 t|jd d }tj|||d W d    n1 sB0    Y  d S Nr_   r   )r   r   r$   r  ro   r   rh  )rC   r/   r   r0   r'   r'   r(   r^    s    
z(TestTensorsolve.test_non_square_handlingro   ))r_   r`   r*   )r`   ra   ra   r`   )r   r`   r`   r   c                 C   sN   t jj| }t |jd d }t j||}tt j||t	|jd| d S rk  )
r$   r  r  r  ro   r   rh  r   rg  rQ  )rC   ro   r/   r0   r   r'   r'   r(   test_tensorsolve_result  s    z'TestTensorsolve.test_tensorsolve_result)
rK   rL   rM   r   r   r   r$   r  r^  rl  r'   r'   r'   r(   rj    s   
rj  c                  C   sR   t jddgddggdd} ttd t|  W d    n1 sD0    Y  d S )Nr^   rj   r_   rf   Zfloat16r4   zunsupported in linalg)r$   r   r   rn  r   r  )rF  r'   r'   r(   test_unsupported_commontype  s    rm  z,Bad memory reports lead to OOM in ci testingc                  C   sR   d} t jd| gt jd}t jddgt jd}d|d< t ||}t|d d d S )N        r^   r4   )r   ri   )r$   r   rA  r  r   r   )rG  r/   r0   r  r'   r'   r(   test_blas64_dot  s    ro  z*Numpy not compiled with 64-bit BLAS/LAPACKc            
   	   C   s   t j} t jjj}d}d}|}t jddg| d}t jdg| d}t jdg| d}|||||||dd}t|d d t|d | t|d | t| }	t	d	|	  k od
k n   d S )Nl       r^   r4   ri   r   infor<  rG  rn  l        )
r$   r   r   r&  Zdgeqrfr   r   rU  itemr   )
r-   Zlapack_routiner<  rG  Zldar/   Zworkr  resultsZlworkr'   r'   r(   !test_blas64_geqrf_lwork_smoketest  s    
rs  c                  C   sF   t dd} t j| }t g dg dg dg}t|| d S )N<   r`   ra   rf   )r   r*   r+      )rT     rY  &   )r  .   4   :   )r$   r   rn   r   r  r   r   r   rd  r   r'   r'   r(   test_diagonal  s    r}  c                  C   s8   t dd} t j| }t g d}t|| d S )Nrt  ru  )$   t      )r$   r   rn   r   tracer   r   r|  r'   r'   r(   
test_trace  s    r  c                  C   s   t dd} t j| | d }t g dg dg dg}t|| g d}g d}t j||}tg d}t|| ttd2 | d d dd f }t j|| W d    n1 s0    Y  d S )	Nr  r  r^   )ri   r_   ri   r+  r  )ru   r*   ru   z8input arrays must be \(arrays of\) 3-dimensional vectors)	r$   r   rn   r   crossr   r   r   r   )r   rd  r   r   r   Zx_2dimr'   r'   r(   
test_cross  s&    

r  c                  C   sH   t dd} t j| | dks&J t jj| | ddgddksDJ d S )Nr*   r  7   r   r   )r$   r   rn   r   rg  )r   r'   r'   r(   test_tensordot	  s    r  c                  C   sD   t dd} t j| | j}t ddgddgg}t|| d S )Nr*   r  rf      r  )r$   r   rn   r   r	   rL  r   r   r|  r'   r'   r(   test_matmul	  s    r  c                  C   sr   t dd} t j| }| j}t|| ttd( t j| d d df  W d    n1 sd0    Y  d S )Nr*   r  z$array must be at least 2-dimensionalr   )	r$   r   rn   r   Zmatrix_transposerL  r   r   r   r|  r'   r'   r(   test_matrix_transpose(	  s    
r  c                  C   s\   t dd} t j| }t|t ddd t jj| dd}t|t dggdd d S )Nr  r  ^)ː,@r`   r2   Tr  )r$   r   rn   r   Zmatrix_normr   r   r   )r   rd  r'   r'   r(   test_matrix_norm5	  s
    r  c                  C   s   t dd} t j| }t|t ddd t jj| dd}t|t g ddd t jj| d	d
}t jdddd}t	|j
|j
 t||dd d S )Nr  r  r  r`   r  r   r1  )g|a2@gsh|? @gDioI#@Tr  r   r   r4   )r$   r   rn   r   Zvector_normr   r   r   fullr   ro   r|  r'   r'   r(   test_vector_norm@	  s    r  )r*   r+   )__doc__r  r  r   r   r2  r4  r   numpyr$   r   r   r   r   r   r   r   r	   Znumpy._corer
   Znumpy.exceptionsr   r   r   r   r   r   Znumpy.linalgr   r   r   r   r   Znumpy.linalg._linalgr   Znumpy.testingr   r   r   r   r   r   r   r   r   r    Znumpy.linalg.lapack_liteImportErrorr)   r.   r5   r6   r7   rO   r>   rR   r  r  rk   r   r   rr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r$  r(  r)  r*  r/  r0  r=  rB  rK  r   r   rU  rx  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rw  r  r-  r   r9  r:  rX  rj  rm  r#  ro  r#  rs  r}  r  r  r  r  r  r  r  r'   r'   r'   r(   <module>   s(  (0	

#




9 !
0

K	$.C
*1V6; x) #B
1" )
	



