o
    hsE                    @   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	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	 e0y   Y nw dd Z1e)Z2dddZ)dd Z3dd Z4dd Z5h dZ6G dd dZ7dd Z8e
j9:d g Z;e;e8de7dedd gd!d"gged#ed dged#e7d$edd gd!d"gged#ed dged#e7d%edd gd!d"gged#eg d&g d'ged#e7d(ed)d*gd+d,gged#ed-d)ged#e7d.ed)d*gd+d,gged#ed-d)ged#e7d/ed)d*gd+d,gged#eg d0g d1ged#e7d2e
j<d3ed#e
j<d4ed#d5hd6e7d7e
j9=d8d8e
j9=d8e7d9e
j9=d:d:e
j9=d:e7d;d:d<gd=d>ggd<d:gg
7 Z;e;e8d?e7d@eg dAg d'ged#ed dged#e7dBedd gd!d"gdCdDgged#eg dEed#e7dFeg dAg d'ged#ed dged#e7dGedd gd!d"gdCdDgged#eg dEed#e7dHeg dIg dJged#ed-d)ged#e7dKedLdMgdNdOgdPdQgged#eg dRed#e7dSeg dIg dJged#ed-d)ged#e7dTedLdMgdNdOgdPdQgged#eg dRed#e7dUeg dIg dJged#ed-d)gdVdWgged#e7dXedLdMgdNdOgdPdQgged#ed-d)gdVdWgdVdWgged#e7dYe
j9=d8dZe
j9=d8e7d[e
j9=d:d\e
j9=d:e7d]e
j9=d\d:e
j9=d\e7d^e
j9=dd>e
j9=dd5hd6e7d_e
j9=d>de
j9=d>d5hd6g7 Z;e;e8d`e7daedd gd dgged#de7dbedd gd dgged#de7dcedd*gddd:gged#de7deedd*gddd:gged#de7dfe
j<d3ed#dd5hd6e7dgd:d<gd<d:ggde7dhedd gd dggde7die
j9=d:d:dg7 Z;djdk Z>e;e> 7 Z;dldm Z?dndo Z@e;e@ 7 Z;G dpdq dqZAG drds dseAZBG dtdu dueAZCG dvdw dweAZDG dxdy dyeAZEG dzd{ d{eAZFG d|d} d}eAZGd~d ZHG dd deBeEZIG dd deIZJG dd deBeEZKG dd deKZLG dd deBeEZMG dd deMZNG dd deBeEZOG dd deOZPG dd dZQG dd deBeEZRG dd deReQZSG dd deDeGZTG dd deTeQZUG dd deBeEZVG dd deVZWG dd deBeCeEeFZXG dd deXZYG dd deDeGZZG dd deZZ[dd Z\G dd deBeEZ]G dd de]Z^G dd deBeCZ_G dd de_Z`ejabddd dD G dd dZcG dd deDeGZdG dd dZeG dd deDeGZfG dd dZgG dd dZhG dd dehZiG ddÄ dehZjG ddń dejeiZkG ddǄ dǃZlG ddɄ dehZmG dd˄ dehZnG dd̈́ dehZoG ddτ dekemZpG ddф dekenZqG ddӄ dekeoZrG ddՄ dՃZsddׄ ZtG ddل dكZuG ddۄ dۃZvG dd݄ d݃Zwdd߄ Zxejajye.dddd Zzejajye{ d:kdddd Z|ejajye.ddejaj}dd Z~G dd dZG dd dZG dd dZdd Zejajdddd Zejaje- dddd Zdd Zdd Zdd Zdd Zd 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 |u S tju S N)type
isinstancenpndarray)outin_ r(   d/home/www/facesmatcher.com/frenv_anti/lib/python3.10/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_dtype5   
   r6   c                 C   s   t ttttttti|  S r!   )r   r   r   r   r5   r(   r(   r)   get_complex_dtype:   r7   r8   c                 C   s   | t tfv rdS dS )Ngh㈵>gdy=)r   r   r5   r(   r(   r)   get_rtol?   s   r9   >   	hermitiangeneralizedsize-0square	nonsquarestridedc                   @   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namer0   r1   	frozensettags)selfrB   r0   r1   rD   r(   r(   r)   __init__O   s
   zLinalgCase.__init__c                 C   s   || j | j| jd dS )zN
        Run the function `do` on this test case, expanding arguments
        rD   N)r0   r1   rD   )rE   dor(   r(   r)   checkZ   s   zLinalgCase.checkc                 C   s   d| j  dS )Nz<LinalgCase: >)rB   rE   r(   r(   r)   __repr__`   s   zLinalgCase.__repr__N)__name__
__module____qualname__setrF   rI   rL   r(   r(   r(   r)   r@   N   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_tagsrD   )tagcasescaser(   r(   r)   	apply_tagd   s   rU     r=   r         ?       @      @      @r5   r   Zdouble_2)rX   rW   rZ   )rY   rZ         @r         ?       @y       @      @y      @      @y      @      @       @      ?r   Z	cdouble_2)r]   r\   y      ?      @)y      ?       y      ?      y      ?      Z0x0r   r   r   r<   rG   Z8x8   Z1x1   Znonarray         r>   Zsingle_nsq_1)rW   rX   rY   Zsingle_nsq_2g      @r[   )rX   rW   rY   Zdouble_nsq_1Zdouble_nsq_2Zcsingle_nsq_1)      ?      ?       @       @      @      )y      @      y      @      "@y      @       @Zcsingle_nsq_2re   rf   rg   y      @      "y      @      y      @       @)r]   r\   rg   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   sn  g } t D ]}t|jtjsqt|jd|j d|j g}|jd u r%d }n|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 rld }n4|jjdkrt|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 )Nrb   rc   ra      r+   Z_tile3r;   rG   rc   rb   Z_tile213)CASESr#   r0   r$   r%   r   r1   ndimr@   rB   rD   appendreshapeshape)	new_casesrT   r0   r1   new_caser(   r(   r)   _make_generalized_cases   s6   


$
$
ru   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r*d	|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r| jd dkrt| 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rt| j}d|d< d|d< tjjj| |d}|dfV  q1dS )z<
    Generate cartesian product of strides for all axes
    ZnopNra   )ra   rc   rl   ra   rm   rb   )ra   rw   c                 S   s   g | ]
\}}t || qS r(   )abs).0r0   r1   r(   r(   r)   
<listcomp>,  s    z%_stride_comb_iter.<locals>.<listcomp>c                 S   s   g | ]}t d d |qS r!   )slice)rz   repeatr(   r(   r)   r{   -  s    r5   l   >[= .Zstride__c                 S   s   g | ]}d | qS )z%+dr(   )rz   jr(   r(   r)   r{   6  s    r   )stridesZstride_xxx_0Zstride_xxx_0_xra   ra   Zstride_xxx_0_0)r#   r$   r%   ro   	itertoolsproducttupleziprr   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  sL   








r   c               	   C   sn   g } t D ]0}t|jD ](\}}t|jD ]\}}t|jd | d | |||jdhB d}| | qqq| S )Nr~   r?   rG   )rn   r   r0   r1   r@   rB   rD   rp   )rs   rT   r0   Za_labelr1   Zb_labelrt   r(   r(   r)   _make_strided_casesK  s   
r   c                   @   s"   e Zd ZeZe e fddZdS )LinalgTestCasec                 C   sv   | j D ]5}|j|@ |krq|j|@ rqz|| j W q ty8 } zd|d}|t 7 }t||d}~ww 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_CASESrD   rI   rH   	Exception	traceback
format_excAssertionError)rE   requireexcluderT   emsgr(   r(   r)   check_cases_  s   


zLinalgTestCase.check_casesN)rM   rN   rO   rn   r   rP   r   r(   r(   r(   r)   r   \  s    r   c                   @      e Zd Zdd Zdd ZdS )LinalgSquareTestCasec                 C      | j dhddhd d S )Nr=   r;   r<   r   r   r   rK   r(   r(   r)   test_sq_casesu     
z"LinalgSquareTestCase.test_sq_casesc                 C      | j ddhdhd d S )Nr=   r<   r;   r   r   rK   r(   r(   r)   test_empty_sq_casesy     

z(LinalgSquareTestCase.test_empty_sq_casesN)rM   rN   rO   r   r   r(   r(   r(   r)   r   s      r   c                   @   r   )LinalgNonsquareTestCasec                 C   r   )Nr>   r;   r<   r   r   rK   r(   r(   r)   test_nonsq_cases  r   z(LinalgNonsquareTestCase.test_nonsq_casesc                 C   r   )Nr>   r<   r;   r   r   rK   r(   r(   r)   test_empty_nonsq_cases  r   z.LinalgNonsquareTestCase.test_empty_nonsq_casesN)rM   rN   rO   r   r   r(   r(   r(   r)   r   ~  r   r   c                   @   r   )HermitianTestCasec                 C   r   )Nr:   r;   r<   r   r   rK   r(   r(   r)   test_herm_cases  r   z!HermitianTestCase.test_herm_casesc                 C   r   )Nr:   r<   r;   r   r   rK   r(   r(   r)   test_empty_herm_cases  r   z'HermitianTestCase.test_empty_herm_casesN)rM   rN   rO   r   r   r(   r(   r(   r)   r     r   r   c                   @   ,   e Zd Zejjdd Zejjdd ZdS )LinalgGeneralizedSquareTestCasec                 C   r   )Nr;   r=   r<   r   r   rK   r(   r(   r)   test_generalized_sq_cases     

z9LinalgGeneralizedSquareTestCase.test_generalized_sq_casesc                 C      | j h dd d S )N>   r<   r;   r=   r   r   rK   r(   r(   r)   test_generalized_empty_sq_cases     z?LinalgGeneralizedSquareTestCase.test_generalized_empty_sq_casesN)rM   rN   rO   pytestmarkslowr   r   r(   r(   r(   r)   r     
    
r   c                   @   r   )"LinalgGeneralizedNonsquareTestCasec                 C   r   )Nr;   r>   r<   r   r   rK   r(   r(   r)   test_generalized_nonsq_cases  r   z?LinalgGeneralizedNonsquareTestCase.test_generalized_nonsq_casesc                 C   r   )N>   r<   r>   r;   r   r   rK   r(   r(   r)   "test_generalized_empty_nonsq_cases  r   zELinalgGeneralizedNonsquareTestCase.test_generalized_empty_nonsq_casesN)rM   rN   rO   r   r   r   r   r   r(   r(   r(   r)   r     r   r   c                   @   r   )HermitianGeneralizedTestCasec                 C   r   )Nr;   r:   r<   r   r   rK   r(   r(   r)   test_generalized_herm_cases  r   z8HermitianGeneralizedTestCase.test_generalized_herm_casesc                 C   s   | j h ddhd d S )N>   r<   r;   r:   noner   r   rK   r(   r(   r)   !test_generalized_empty_herm_cases  r   z>HermitianGeneralizedTestCase.test_generalized_empty_herm_casesN)rM   rN   rO   r   r   r   r   r   r(   r(   r(   r)   r     r   r   c                 C   sH   t | } | jdkrtj| j| jd}t| jd |d< |S t| jd S )Nrc   r5   rm   .r   )r   ro   r$   r   rr   r.   r   )r0   rr(   r(   r)   identity_like_generalized  s   
r   c                   @      e Zd Zdd ZdS )
SolveCasesc                 C   sj   t ||}t|jdkr"t||d d }tt||j| n
t||}t|| t	t
|| d S )Nra   ).N.r   )r   solver$   r   ro   r	   r   broadcast_torr   r   r*   )rE   r0   r1   rD   r   Zadotxr(   r(   r)   rH     s   

zSolveCases.doNrM   rN   rO   rH   r(   r(   r(   r)   r         r   c                   @   B   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 Nra         ?r5   )r$   r   r   r   r   r.   rE   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s(J t ddd|}t||}|jdksAJ t ddd|}tt	tj|| d S )	Nc                   @      e Zd ZdS )z)TestSolve.test_1_d.<locals>.ArraySubclassNrM   rN   rO   r(   r(   r(   r)   ArraySubclass      r   r`   rb   rb   rb   rd   )rb   rb   rb   ra   )
r$   r%   arangerq   r   r   r   rr   r   
ValueError)rE   r   r0   r1   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                   @   r   )z,TestSolve.test_0_size.<locals>.ArraySubclassNr   r(   r(   r(   r)   r     r   r   r`   rb   r+   ra   rc   r   )r$   r%   r   rq   r   r   r   r   r   r#   r   r   r   rE   r   r0   r1   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                   @   r   )z.TestSolve.test_0_size_k.<locals>.ArraySubclassNr   r(   r(   r(   r)   r     r   r   rd   ra   rb   r+   rc   r   )
r$   r%   r   rq   r   r   r   r   r   r#   r   r(   r(   r)   test_0_size_k
  s   ""
"8
zTestSolve.test_0_size_kN)rM   rN   rO   r   r   parametrizer   r   r   r   r   r   r   r   r(   r(   r(   r)   r     s    
!r   c                   @   r   )InvCasesc                 C   s0   t |}tt||t| tt|| d S r!   )r   invr   r	   r   r   r*   )rE   r0   r1   rD   Za_invr(   r(   r)   rH     s
   

zInvCases.doNr   r(   r(   r(   r)   r     r   r   c                   @   2   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                   @   r   )z*TestInv.test_0_size.<locals>.ArraySubclassNr   r(   r(   r(   r)   r   .  r   r   r   ra   ra   r5   r^   )r$   r%   zerosint_r   r   r   r   r.   r"   float64r   rr   r#   	complex64rE   r   r0   resr(   r(   r)   r   ,  s   

zTestInv.test_0_sizeNrM   rN   rO   r   r   r   r   r   r   r   r   r   r(   r(   r(   r)   r   &  s    
r   c                   @   r   )EigvalsCasesc                 C   s&   t |}t |\}}t|| d S r!   )r   eigvalseigr   )rE   r0   r1   rD   evevaluesevectorsr(   r(   r)   rH   ?  s   
zEigvalsCases.doNr   r(   r(   r(   r)   r   =  r   r   c                   @   r   )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 Nra   r   r5   rl   )r$   r   r   r   r   r.   r8   r   r(   r(   r)   r   F  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                   @   r   )z.TestEigvals.test_0_size.<locals>.ArraySubclassNr   r(   r(   r(   r)   r   O  r   r   r   r5   r   ra   r^   r_   )r$   r%   r   r   r   r   r   r   r.   r"   r   r   rr   r#   r   r   r(   r(   r)   r   M     

zTestEigvals.test_0_sizeNr   r(   r(   r(   r)   r   E  s    
r   c                   @   r   )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   r9   r.   r   r*   )rE   r0   r1   rD   r   r   r   r(   r(   r)   rH   b  s   

 zEigCases.doNr   r(   r(   r(   r)   r   `  r   r   c                   @   r   )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.   r8   rE   r.   r   wvr(   r(   r)   r   l  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                   @   r   )z*TestEig.test_0_size.<locals>.ArraySubclassNr   r(   r(   r(   r)   r   z  r   r   r   r5   r   r^   r_   )r$   r%   r   r   r   r   r   r   r.   r"   r   r   rr   r#   r   rE   r   r0   r   Zres_vr(   r(   r)   r   x     zTestEig.test_0_sizeNr   r(   r(   r(   r)   r   k  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 )Nra   r   r5   F
compute_uvr:   )r$   r   r   svdUSVhr   r.   r6   r:   )rE   r.   r   r   r  r  r  r   r(   r(   r)   r     s   
zSVDBaseTests.test_typesN)rM   rN   rO   r:   r   r   r   r   r   r   r   r   r(   r(   r(   r)   r     s    r   c                   @   r   )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   r9   r.   r   r*   )rE   r0   r1   rD   ur   vtr(   r(   r)   rH     s   &zSVDCases.doNr   r(   r(   r(   r)   r    r   r  c                   @   r   )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 )rd   r   Tr  rd   rd   r^   rd   )r   rd   N)r$   r   r   r  r:   r   rr   eye)rE   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 )Nra   r   Fr  )r$   r   r   r  r:   Zsvdvalsr   )rE   r   Z
s_from_svdZs_from_svdvalsr(   r(   r)   test_svdvals  s   
zTestSVD.test_svdvalsN)rM   rN   rO   r  r  r(   r(   r(   r)   r
    s    r
  c                   @   r   )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 )Nrm   rl   axes)r   rangero   r$   conj	transpose)matr  r(   r(   r)   r:     s   z'SVDHermitianCases.do.<locals>.hermitianrl   )r   r  r   r	   r$   r   r9   r.   r   r   r  rr   r   sortr   r*   )rE   r0   r1   rD   r  r   r	  r:   r(   r(   r)   rH     s   &,,zSVDHermitianCases.doNr   r(   r(   r(   r)   r    r   r  c                   @   s   e Zd ZdZdS )TestSVDHermitianTN)rM   rN   rO   r:   r(   r(   r(   r)   r    s    r  c                   @   r   )	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 )Nr<   F)r  r   ).rl   ri   rh   r2   r3   rb   rm   ra   rl   fro)r   r   r   r   condr  r   r$   r   ry   summaxminr   sqrt)rE   r0   r1   rD   cr   Zcinvr(   r(   r)   rH     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)rW   r   ra   )r   g       r   )r   r   rY   rd   gUUUUUU?ra   rl   r   r  gUUUUU6@)r   r   r   r  r   r$   r   rE   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 qt||D ]
\}}t|| q-d S )Nr   Nra   rb   r  rl   rm     4&kC)r$   r   onesr   r   r   r   r  )rE   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 |d  ||v r^t|d d	k t|d
 d	k q8tt |d   tt |d
   q8d S )N)Nra   rl   rb   rm   r  r&  r   r   )rc   rb   rb   ra   r   ra   ra   r   r'  rb   )	r$   r(  nanr   r  r   r#   r   isnan)rE   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|d t j t|d t j tt 	|d  tt 	|d  qd S )	NrV   rb   r   r^   r   )Nra   rb   r  rl   rm   r   ra   r   )
r$   randomseedrandr   r  r   r   r   isfinite)rE   r$  r*  r!  r(   r(   r)   test_stacked_singular7  s   zTestCond.test_stacked_singularN)
rM   rN   rO   r%  r+  r   r   xfailr1  r7  r(   r(   r(   r)   r"    s    	

r"  c                   @   r   )	PinvCasesc                 C   s<   t |}t}t||||||ddd tt|| d S )Nri   rh   r  r   pinvr	   r   r   r*   rE   r0   r1   rD   Za_ginvr   r(   r(   r)   rH   L  s   
zPinvCases.doNr   r(   r(   r(   r)   r9  G  s    r9  c                   @   r   )TestPinvNr   r(   r(   r(   r)   r=  T  r   r=  c                   @   r   )PinvHermitianCasesc                 C   s@   t j|dd}t}t||||||ddd tt|| d S )NTr  ri   rh   r  r:  r<  r(   r(   r)   rH   Z  s   zPinvHermitianCases.doNr   r(   r(   r(   r)   r>  X  r   r>  c                   @   r   )TestPinvHermitianNr   r(   r(   r(   r)   r?  b  r   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    d S 1 s;w   Y  d S )
Nra   rb   rc   )rd   ra   ra   )rb   rc   ra   r   rcondr   z%`rtol` and `rcond` can't be both set.)match)rB  r   )r$   r   r   r   r;  r   Zraisesr   )r0   r(   r(   r)   test_pinv_rtol_argf  s   "rD  c                   @   r   )DetCasesc                 C   s   t |}t |}|j|j}}t|jjtt	fv r#t|
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 )Nrl   axisr   ra   )r   detslogdetsignZ	logabsdetr   r.   r"   r   r   astyper   r   r   r   reducer$   expZ
atleast_1dry   r   r   )rE   r0   r1   rD   dr   r   ldadr   mr(   r(   r)   rH   v  s   




zDetCases.doNr   r(   r(   r(   r)   rE  t  r   rE  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   ra   )r   r   rH  r"   r   r   rI  r   rK   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   rH  r.   rI  r6   )rE   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^   r5   rW   r2  r   ra   )r$   r   r   r   rH  r   r   r.   r"   rI  float32r   )rE   r0   r   r(   r(   r)   r     s    







zTestDet.test_0_sizeN)rM   rN   rO   rT  r   r   r   r   r   r   r   r   r   r(   r(   r(   r)   rR    s
    
rR  c                   @   r   )
LstsqCasesc                 C   sL  t |}|j\}}t|d\}}}	tj||dd\}
}}}|dkr+t|
dk  ||kr=t|t	||
 t
|| nt
|| t||| ||kr}||kr}t tt 	||
| d jdd}t |}t |jdkr|d|_t
|j|j n
t g t|
}t|| tt |jt j tt|
| tt|| d S )	NFrl   rA  r   rb   rF  ra   rv   )r$   r   rr   r   r  lstsqr   r   r   r   r   Z__array_wrap__ry   r  ro   r   r   r"   
issubdtyper.   floatingr*   )rE   r0   r1   rD   arrrQ  nr  r   r	  r   	residualsranksvZexpect_residsr(   r(   r)   rH     s0   


 

zLstsqCases.doNr   r(   r(   r(   r)   rW    r   rW  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)rS  rW   rS  rW   rX   rS  )rS  rX   rS  rS  rW   rS  )rW   rS  rW   rS  rS  rZ   )rS  rS  rS  rX   rY   rS  )ra   r   r   r   r   r   rl   rA  rd   rc   )r$   r   Tr   rX  r   )rE   r0   r1   r   r]  r^  r   r(   r(   r)   
test_rcond  s   
zTestLstsq.test_rcond)rQ  r\  n_rhs))rd   rb   rb   )r   rd   ra   )r   rd   rb   )rd   r   ra   )rd   r   rb   )rd   rb   r   r   r   r   c                 C   s   t || ||}t ||f}tj||d d\}}}}	|dkr*t|dk  t|j	||f t|j	||kr<|fnd ||krZ|dkrZ|t 
|| }
t||
|
 jdd t|t|| t|	j	t||f d S )NrA  r   r_   rm   rF  )r$   r   rq   r(  r   rX  r   r   r   rr   r   r   r  r  )rE   rQ  r\  rc  r0   r1   r   r]  r^  r   r   r(   r(   r)   test_empty_a_b  s   
zTestLstsq.test_empty_a_bc                 C   sv   t g d}t g d}t |t t|gj}ttd tj	||d d W d    d S 1 s4w   Y  d S )N)r   ra   rb   rc   )rl   g?g?g @gffffff
@zIncompatible dimensionsrA  )
r$   r   Zvstackr(  lenra  r   r   r   rX  )rE   r   yr$  r(   r(   r)   test_incompatible_dims  s   "z TestLstsq.test_incompatible_dimsN)	rM   rN   rO   rb  r   r   r   re  rh  r(   r(   r(   r)   r`    s
    
	r`  dtc                 C   s   g | ]}t |qS r(   )r$   r.   )rz   r!  r(   r(   r)   r{     s    r{   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 )TestMatrixPowerrd   )rc   r   ra   rb   )rb   rc   r   ra   )ra   rb   rc   r   ra   r   rb   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 )Nrb   d   i       r   ra   rc   )rshft_1rK  r   r   rshft_0rshft_2rshft_3)rE   ri  Zrshftr(   r(   r)   test_large_power  s   z TestMatrixPower.test_large_powerc                 C   >   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_allrK  objectstackedrE   ri  rw  r  r(   r(   r)   test_power_is_zero     
z"TestMatrixPower.test_power_is_zeroc                 C   rt  )Nc                 S   s&   t | d}t||  t|j| j d S )Nra   )r   r   r.   )r  rv  r(   r(   r)   rw  &  s   

z-TestMatrixPower.test_power_is_one.<locals>.tzrx  r|  r(   r(   r)   test_power_is_one%  r~  z!TestMatrixPower.test_power_is_onec                 C   rt  )Nc                 S   s>   t | d}| jtkrtnt}t||| |  t|j| j d S )Nrb   )r   r.   rz  r	   r   r   )r  rv  mmulr(   r(   r)   rw  1  s   
z-TestMatrixPower.test_power_is_two.<locals>.tzrx  r|  r(   r(   r)   test_power_is_two0  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 Nrl   )r   r.   rz  r	   r   r   r   )r  Zinvmatr  r(   r(   r)   rw  =  s
   
z3TestMatrixPower.test_power_is_minus_one.<locals>.tz)ry  dtnoinvrK  r|  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      ?ra   )rp  rK  r   	TypeErrorr   rE   ri  r  r(   r(   r)   test_exceptions_bad_powerG  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 )Nra   rb   )rd   rc   rb   )r   r   r   r$   r   r(  )rE   ri  r(   r(   r)   test_exceptions_non_squareL  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 r  )r  noninvrK  r   r   r   r  r(   r(   r)   test_exceptions_not_invertibleQ  s   
z.TestMatrixPower.test_exceptions_not_invertibleN)rM   rN   rO   r$   r  rp  ro  rq  rr  ry  r   r  blockr{  rz  r.   r  rs  r}  r  r  r  r  r  r   r   skipifr    r  r(   r(   r(   r)   rj    s$    
rj  c                   @   r   )TestEigvalshCasesc                 C   s^   t |d}t |\}}|jdd t||t|jd t |d}t||t|jd d S )NLrl   rF  r   r  )r   eigvalshr   r  r   r9   r.   )rE   r0   r1   rD   r   r   r   ev2r(   r(   r)   rH   [  s   zTestEigvalshCases.doNr   r(   r(   r(   r)   r  Y  r   r  c                   @   r   )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   r  r   r.   r6   )rE   r.   r   r   r(   r(   r)   r   h  s   zTestEigvalsh.test_typesc                 C   X   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 Nra   r   r5   ZlrongZUPLOlowerupper)r$   r   rV  r   r   r   r  rE   r   r(   r(   r)   test_invalidn     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   ra   r5   rl   r   r  r  lr  r  )r$   r   r   r9   r   r  r   )rE   KloKuptgtr   r   r(   r(   r)   	test_UPLOt  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                   @   r   )z/TestEigvalsh.test_0_size.<locals>.ArraySubclassNr   r(   r(   r(   r)   r     r   r   r   r5   r   r^   r_   )r$   r%   r   r   r   r   r  r   r.   r"   r   r   rr   r#   r   rV  r   r(   r(   r)   r     r   zTestEigvalsh.test_0_sizeNrM   rN   rO   r   r   r   r   r   r   r   r   r  r  r   r(   r(   r(   r)   r  g  s    
r  c                   @   r   )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 )Nrl   rF  .r   r  )r   err_msg)r   eighr   r   r   r  r   r   r	   r$   r   r9   r.   repr)rE   r0   r1   rD   r   r   Zevcr   r   r  Zevc2r(   r(   r)   rH     s   


 

 
zTestEighCases.doNr   r(   r(   r(   r)   r    r   r  c                   @   r   )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.   r6   r   r(   r(   r)   r     s   zTestEigh.test_typesc                 C   r  r  )r$   r   rV  r   r   r   r  r  r(   r(   r)   r    r  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   r9   r   r  r   )rE   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                   @   r   )z+TestEigh.test_0_size.<locals>.ArraySubclassNr   r(   r(   r(   r)   r     r   r   r   r5   r   r^   r_   )r$   r%   r   r   r   r   r  r   r.   r"   r   r   rr   r#   r   rV  r   r(   r(   r)   r     r   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 d S tt |jjtj d S r!   )	
issubclassr.   r"   r$   Zinexactr   realr   rZ  )r   r   r(   r(   r)   check_dtype  s   z_TestNormBase.check_dtype)rM   rN   rO   ri  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 )NrS  r5   )r   r   r   ri  r   rK   r(   r(   r)   
test_empty  s    z_TestNormGeneral.test_emptyc           	   	   C   s  t g d}t jd }t jd }|| }|D ]}||}t|t j }| || t|d t }|	t
d t|d}| || t|d W d    n1 sTw   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AllFloatrS  divide by zero encounteredrl   r   rb   ra   rX   r   rd   g      ?rW   )r$   r   	typecodesrK  r   r   r  r   r   filterRuntimeWarningr.   r"   	rE   r0   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 ]}|| q2d S )N)ra   rb   rc   rd   )rl   rm   rx   rw   )rl   rb   rx   rd   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-   rZ   rW   ra         $@rl   gQ?rb   rm   gsc?r   rd   )r$   testingr   r   r  r   )r   rK   r(   r)   _test1  s0   
z+_TestNormGeneral.test_vector.<locals>._testr5   )r   ri  )rE   r0   r1   r!  r  r   r(   rK   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 ]4 fd	d
t jd D }tt dd|  fdd
t jd D }tt dd| qtjdd| jd	dddj
}d ddddtjtj dfD ]htt| |dD ][}|\}}|dk r||7 }|dk r||7 }||krttt|d qyt|d}|||  ||k rfdd
tj D }nfdd
tj D }t|| qyqmd S )Nr@  rd   ri   r+   r5   rl   r   ra   rb   rc   c                    s$   g | ]}t  d d |f dqS Nordr   rz   kr$  orderr(   r)   r{   P     $ z._TestNormGeneral.test_axis.<locals>.<listcomp>r  rG  c                    s$   g | ]}t  |d d f dqS r  r  r  r  r(   r)   r{   R  r     rd   rm   r  c                    s*   g | ]}t  d d  j|ddqS NrF  r  )r   taker  Bk_indexr  r(   r)   r{   h  s    "c                    s,   g | ]}t  d d  j|djdqS r  )r   r  ra  r  r  r(   r)   r{   k  s    $)r   ri  r$   r   r  rr   r   r   r   rq   ro   r   combinationsr   r   )	rE   Z	expected0Z	expected1ndrG  Zrow_axisZcol_axisr\  r   r(   )r$  r  r  r  r)   	test_axisJ  s:   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 ]C}t|jD ];}t|||d	}t|||d
d}tt |||||d t|j	}d||< t|}t|j	|k||j	||| qTqMd ddddt j
t j
 ddf	D ]O}tt|jdD ]C}t|||d	}t|||d
d}tt |||||d t|j	}d||d < d||d < t|}t|j	|k||j	||| qqd S )Nra   r  r5   rb   rc   rd   zorder {0}, axis = {1}z;Shape mismatch found {0}, expected {1}, order={2}, axis={3}r  T)r  rG  keepdims)r  )ra   ra   ra   rl   r   rm   r  nuc)r$   r   ri  rq   r   r   Zsqueezeformatr   rr   r   r  ro   r   r   r   permutations)	rE   r$  Zallclose_errZ	shape_errr   foundZexpected_shaper  r  r(   r(   r)   test_keepdimso  sT   




 


z_TestNormGeneral.test_keepdimsN)rM   rN   rO   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 )Nr5   rS  )r   r   r   ri  rK   r(   r(   r)   test_matrix_empty  s    z_TestNorm2D.test_matrix_emptyc           	   	   C   s  |  g dg dg}tjd }d}|| }|D ]}||}t|tj }| || t|d t }|	t
d t|d}| || t|d W d    n1 sUw   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 qd S )Nr.  r   r  ZfdFDrX   r  rl   rW   ra   rb   gLXz?rm   r  r  gU&,t=@r+   r  )r   r$   r  rK  r   r   r  r   r   r  r  r  r  r(   r(   r)   test_matrix_return_type  sD   













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 )Nra   rc   ri   rj   r5   gT"@r  r  r  g      (@rZ   rl   r[   rb   gW?"@rm   gїʄ?Znofrorx   r   )r   ri  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   ri   )rc   rb   ra   r5   grj=Q0?r  r  gB+pc?g?g333333?ra   rW   rl   g?rb   g&.d?rm   gܸՠ?)r   ri  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 ]}ttt||d  ttt||d ttt||d qLttt|d d ttt|d d ttt|d d d S )Nr@  r  r5   ra   r  rb   rc   rd   r  r   r  testr   rc   r   )ra   rb   rb   rc   r   ra   rb   )	r   ri  r$   r   rq   r   r   r   r   )rE   r$  r  r  r(   r(   r)   test_bad_args  s   z_TestNorm2D.test_bad_argsN)
rM   rN   rO   r$   r   r  r  r  r  r  r(   r(   r(   r)   r    s    3r  c                   @   r   )	_TestNormNr   r(   r(   r(   r)   r    r   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
   r5   rc   r  gL)@rb   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   r5   rc   r  l        ri   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rb   r5   y      @      @r   y            @ra   gV;'@rc   r  r  r  	   ri   )	r$   r   Zclongdoubler/   r   r   rK  
complex128r   )rE   rN  r   r(   r(   r)   test_complex_high_ord$  s   z,TestNorm_NonSystematic.test_complex_high_ordN)rM   rN   rO   r  r  r  r(   r(   r(   r)   r    s    r  c                   @      e Zd ZejZdZdS )_TestNormDoubleBaser,   N)rM   rN   rO   r$   r   ri  r  r(   r(   r(   r)   r  2      r  c                   @   r  )_TestNormSingleBaser+   N)rM   rN   rO   r$   rV  ri  r  r(   r(   r(   r)   r  7  r  r  c                   @   r  )_TestNormInt64Baser,   N)rM   rN   rO   r$   Zint64ri  r  r(   r(   r(   r)   r  <  r  r  c                   @   r   )TestNormDoubleNr   r(   r(   r(   r)   r  A  r   r  c                   @   r   )TestNormSingleNr   r(   r(   r(   r)   r  E  r   r  c                   @   r   )TestNormInt64Nr   r(   r(   r(   r)   r  I  r   r  c                   @   r   )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    d S 1 sxw   Y  d S )Nrd   rS  rl   rl   rc   r  r   )ra   r   r   r   ra   )rd   )rc   rd   r   z#`tol` and `rtol` can't be both set.g{Gz?)tolr   )r   r   r$   r  r   r   r   r   )rE   Imsr(   r(   r)   test_matrix_rankO  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 )Nrd   Tr  ra   r  r   rS  r  rc   g:0yE>g|"BE>)r:   r  g;䡈E>)r   r   r$   r  r(  r   )rE   r  r(   r(   r)   test_symmetric_rankh  s   
z"TestMatrixRank.test_symmetric_rankN)rM   rN   rO   r  r  r(   r(   r(   r)   r  M  s    r  c                  C   s   t jd} tdD ]B}| 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rm  )(   r  sizera   rb   r   r  rd   ri   rc   r`   )r$   r3  ZRandomStater  normalr   r   )rngiXr(   r(   r)   test_reduced_rankv  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.   rr   r  r   qrQRr   r#   r   r   ra  r  r$   r  triu)rE   r0   a_typea_dtyperQ  r\  r  r   r  r	  q1r1r2r(   r(   r)   check_qr  s:   

zTestQR.check_qrrQ  r\  )rc   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   rr   )rE   rQ  r\  r  r0   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 )Nra   rb   rc   rd   ri   r+   r5   r  r  r  r  rk   )	r   r$   r   r   r  r   r.   rr   ra  )rE   r0   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 ]}||}||}| | | | | |j qdD ]$}dd||  }dd||  }| | | | | |j q:d S )	Nra   rb   rc   rd   ri   r+   fd              ?)r   rK  r  ra  )rE   r0   r1   ri  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 )	Nrm   r  r  rl   rb   .r  r   )r"   r.   rr   r  r   r  r   r#   r   r	   r$   r   r   r
   r  r
  )rE   r0   r  r  rQ  r\  r  qr   ZI_matZstack_I_matr  r  r  r(   r(   r)   check_qr_stacked  sL   
""zTestQR.check_qr_stackedr  ))rc   rd   )rd   rc   r  r  r  
outer_size)r   r  )rb   rc   rd   ri  c                 C   sX   t jd}|j|| d|}|j|| d|}| | | |d|   d S )N{   r  r  )r$   r3  Zdefault_rngr  rK  r  )rE   r  r  ri  r  r$  r  r(   r(   r)   test_stacked_inputs  s
   

zTestQR.test_stacked_inputsN)rM   rN   rO   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 )TestCholeskyrr   )r   r   rc   rc   )2   r#  )rc   r  r  r.   r  FTc           
      C   s6  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}|rSt 	|
| |}nt 	||
| }d|jd  t |j }t|||| d	| d
| d
| d t j|ddd}	tt t |	 tt |	dk d S )Nra   r  )rl   rm   rm   r5   r  i  r    
)atolr  rl   )Zaxis1Zaxis2)r$   r3  r4  randnrY  Zcomplexfloatingr   r  rf  r	   r  r  r   r   choleskyrr   Zfinfoepsr   diagonalr   r   Zisreal)
rE   rr   r.   r  r0   tr!  r1   r'  rN  r(   r(   r)   test_basic_property'  s"   	&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                   @   r   )z/TestCholesky.test_0_size.<locals>.ArraySubclassNr   r(   r(   r(   r)   r   L  r   r   r   r5   )ra   r   r   )r$   r%   r   r   r   r   r)  r   rr   r   r.   r"   r   r#   r   r   r(   r(   r)   r   K  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)  ra  r  )rE   r0   r(   r(   r)   test_upper_lower_arg[  s   z!TestCholesky.test_upper_lower_argN)rM   rN   rO   r   r   r   r$   rV  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   dS 1 sEw   Y  dS )	TestOuterrc   rd  r  )r   rb   rd   z$Input arrays must be one-dimensionalN)rM   rN   rO   r$   r   Zarr1Zarr2r   r   r   r   outerr   r   Znewaxisr(   r(   r(   r)   r/  g  s    

"r/  c                  C   s   t jdkrd} nd} tjtjfD ]A}tjd|d}||j| }||jd	 }t
|jjd tjtjtjfD ]}||}t||| t||| q<qd S )Nlittle<rJ   rd   r5   r  =)sys	byteorderr$   rV  r   r  r   r.   Znewbyteorderbyteswapr   r   r   rH  r;  r   )nativeZdttr[  Zn_arrZsw_arrZroutiner   r(   r(   r)   test_byteorder_checkx  s   
r8  r  r  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 )Nra   rb   rc   rd   )rd   rd   rb   rb   .r^   )r$   r   r   r   r   r   r   )Z
invertibleZnon_invertibler   r(   r(   r)    test_generalized_raise_multiloop  s   r9  z?skipping test that uses fork because there are multiple threadsc                  C   sL  d} zt  }W n ttfy   td Y nw |dkrt d t d dd l}||j	d zt
jj  W n tyC   Y n tyQ   t t j Y nw zt
dgg}t
jjddd|d||dd	 W n ty } zdt|v r}t |  W Y d }~nd }~ww t t j d S t  \}}t || krtd d S d S )	N   zNot POSIX or fork failed.r   ra   r^   rW   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dorgqrrA   waitWEXITSTATUS)Z	XERBLA_OKpidrA  r0   r   statusr(   r(   r)   test_xerbla_override  sF   


rI  zCannot start subprocessc                  C   sd   ddg} t d}| D ]$}|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)rL  rK  rM  )textwrapdedentr  
subprocess
check_callr4  
executable)Zbad_libstemplaterM  coder(   r(   r)   test_sdot_bug_8577  s   
rU  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+   rb   rb   r+   r$   r3  r   r   r   )rE   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 rW  rZ  )rE   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 )NrX  rY  rb   ra   rZ  )rE   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 )Nrb   rY  rX  r   r  r$   r3  r   r   rr   )rE   A1dr  r[  r_  r(   r(   r)   test_vector_as_first_argument  
   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 )NrX  rY  rb   )r+   ra  )rE   r$  r  r[  D1dr(   r(   r)   test_vector_as_last_argument  rd  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 )Nrb   rY  rX  r(   ra  )rE   rb  r  r[  re  r(   r(   r)   &test_vector_as_first_and_last_argument$  rd  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 s&J t|||| t|t |t || d S )NrX  rY  r&   r$   r3  r   r   r   r   )rE   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 )NrX  rY  )r+   r+   rh  ri  )rE   r$  r  r&   rj  r(   r(   r)   test_two_arguments_and_out;  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 s-J t||||| d S )NrX  rY  r^  )r+   ra   rh  ri  )rE   r$  r  r[  r_  r&   rj  r(   r(   r)   -test_dynamic_programming_optimization_and_outE  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)   #   )ro     )rp  ri   )ri   r  )r     )rq  r  )rS  g     @g     þ@g    O@g    1@g    @)rS  rS  g     @g     @g     ջ@g     @)rS  rS  rS  g     p@g     @g     @)rS  rS  rS  rS  g     @@g     X@)rS  rS  rS  rS  rS  g     @)rS  rS  rS  rS  rS  rS  )r   ra   ra   rc   rc   rc   )r   r   rb   rc   rc   rc   )r   r   r   rc   rc   rc   )r   r   r   r   rd   ri   )r   r   r   r   r   ri   )r   r   r   r   r   r   r5   ra   T)Zreturn_costsrl   )r$   r3  r   intr   r   r
  )rE   ZarraysZ
m_expectedZ
s_expectedr   rQ  r(   r(   r)   test_dynamic_programming_logicQ  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$   r3  rK   r(   r(   r)   test_too_few_input_arrayso  s   z&TestMultiDot.test_too_few_input_arraysN)rM   rN   rO   r\  r]  r`  rc  rf  rg  rk  rl  rm  rs  rt  r(   r(   r(   r)   rV    s    
	



rV  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rd   r+   r`   rb   rb   rc   rc   rb   ra   c                 C   s<   t t tj||d W d    d S 1 sw   Y  d S )Nind)r   r   r   	tensorinv)rE   r[  ry  r(   r(   r)   test_non_square_handlingv  s   
"z&TestTensorinv.test_non_square_handlingz
shape, ind)rd   r+   r`   rc   rb   )   r`   rc   ra   c                 C   sN   t d}||_tj||d}|j|d  |jd |  }|j}t|| d S )Nr~  r0   ry  )r$   r  rr   r   rz  r   )rE   rr   ry  r0   ainvr   actualr(   r(   r)   test_tensorinv_shape~  s   
z"TestTensorinv.test_tensorinv_shapery  r   rm   c                 C   sL   t d}d|_tt tj||d W d    d S 1 sw   Y  d S )Nr~  r|  r  )r$   r  rr   r   r   r   rz  )rE   ry  r0   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 )Nr~  r}  ra   rx  )	r$   r  rr   r   rz  r(  r   	tensordottensorsolve)rE   r0   r  r1   r(   r(   r)   test_tensorinv_result  s
   

"z#TestTensorinv.test_tensorinv_resultN)rM   rN   rO   r   r   r   r$   r(  r{  r  r  r  r(   r(   r(   r)   ru  t  s     


ru  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, axesrv  Nrw  )r   rb   c                 C   sR   t t t|jd d }tj|||d W d    d S 1 s"w   Y  d S Nrb   r  )r   r   r$   r(  rr   r   r  )rE   r0   r  r1   r(   r(   r)   r{    s   
"z(TestTensorsolve.test_non_square_handlingrr   ))rb   rc   r+   )rc   rd   rd   rc   )r   rc   rc   r   c                 C   sN   t jj| }t |jd d }t j||}tt j||t	|jd| d S r  )
r$   r3  r(  r(  rr   r   r  r   r  rf  )rE   rr   r0   r1   r   r(   r(   r)   test_tensorsolve_result  s    z'TestTensorsolve.test_tensorsolve_result)
rM   rN   rO   r   r   r   r$   r(  r{  r  r(   r(   r(   r)   r    s    
r  c                  C   sT   t jddgddggdd} ttd t|  W d    d S 1 s#w   Y  d S )Nra   rm   rb   ri   Zfloat16r5   zunsupported in linalg)r$   r   r   r  r   r)  )r[  r(   r(   r)   test_unsupported_commontype  s   "r  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        ra   r5   )r   rl   )r$   r   rV  r(  r   r   )r\  r0   r1   r!  r(   r(   r)   test_blas64_dot  s   r  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 oZd
k  d S    d S )Nl       ra   r5   rl   r   inforQ  r\  r  l        )
r$   r   r   rB  Zdgeqrfr   r   rr  itemr   )
r.   Zlapack_routinerQ  r\  Zldar0   Zworkr  resultsZlworkr(   r(   r)   !test_blas64_geqrf_lwork_smoketest  s   
&r  c                  C   sF   t dd} t j| }t g dg dg dg}t|| d S )N<   rc   rd   ri   )r   r+   r,      )rq     rn  &   )r  .   4   :   )r$   r   rq   r   r+  r   r   r   r  r   r(   r(   r)   test_diagonal  s   r  c                  C   s8   t dd} t j| }t g d}t|| d S )Nr  r  )$   t      )r$   r   rq   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 | d d dd f }t j|| W d    d S 1 s`w   Y  d S )	Nr  r"  ra   )rl   rb   rl   r@  r  )rx   r+   rx   z8input arrays must be \(arrays of\) 3-dimensional vectors)	r$   r   rq   r   crossr   r   r   r   )r   r  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s"J d S )Nr+   r  7   r   r  )r$   r   rq   r   r  )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  ri      r#  )r$   r   rq   r   r	   ra  r   r   r  r(   r(   r)   test_matmul!	  s   r  c                  C   st   t dd} t j| }| j}t|| ttd t j| d d df  W d    d S 1 s3w   Y  d S )Nr+   r  z$array must be at least 2-dimensionalr   )	r$   r   rq   r   Zmatrix_transposera  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"  ^)ː,@rc   r3   Tr  )r$   r   rq   r   Zmatrix_normr   r   r   )r   r  r(   r(   r)   test_matrix_norm8	  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  rc   r  r   rF  )g|a2@gsh|? @gDioI#@Tr  r   r   r5   )r$   r   rq   r   Zvector_normr   r   r   fullr   rr   r  r(   r(   r)   test_vector_normC	  s   r  )r+   r,   )__doc__r;  r4  r   	threadingr   rN  rP  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/   r6   r8   r9   rQ   r@   rU   r3  r4  rn   r   r5  ru   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"  r9  r=  r>  r?  rD  rE  rR  rW  r`  r   r   rj  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r!  r/  r8  r  r9  active_countrI  r   rU  rV  ru  r  r  r?  r  r8  r  r  r  r  r  r  r  r  r  r(   r(   r(   r)   <module>   s6   (0	

#




9 
!0

K	$.C
*1V6; x) #B


1" )

	

