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(   r/var/www/html/construction_image-detection-poc/venv/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   >   squarestrided	hermitian	nonsquaregeneralizedsize-0c                   @   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   double_2)rX   rW   rZ   )rY   rZ         @r         ?       @y       @      @y      @      @y      @      @       @      ?r   	cdouble_2)r^   r]   y      ?      @)y      ?       y      ?      y      ?      0x0r   r   r   r?   rG   8x8   1x1   nonarray         r=   single_nsq_1)rW   rX   rY   single_nsq_2g      @r\   )rX   rW   rY   double_nsq_1double_nsq_2csingle_nsq_1)      ?      ?       @       @      @      )y      @      y      @      "@y      @       @csingle_nsq_2rp   rq   rr   y      @      "y      @      y      @       @)r^   r]   rr   cdouble_nsq_1cdouble_nsq_2cdouble_nsq_1_2y      ?      y       @       cdouble_nsq_2_28x11   1x5   5x10x44x0r<   hsinglehdoublehcsingley       @      hcdoublehempty	hnonarraymatrix_b_only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 )Nrh   ri   rf      r+   _tile3r>   rG   ri   rh   _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   


$
$
r   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
    nopNrf   )rf   ri   r   rf   r   rh   )rf   r   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)r   repeatr(   r(   r)   r   -  s    r5   l   >[= .stride__c                 S   s   g | ]}d | qS )z%+dr(   )r   jr(   r(   r)   r   6  s    r   )stridesstride_xxx_0stride_xxx_0_xrf   rf   stride_xxx_0_0)r#   r$   r%   r   	itertoolsproducttuplezipr   emptyr.   viewuint32fill	__class__r   alljoinlistr   libstride_tricks
as_strided)x
stride_setrepeats	new_shape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   )r   r   r0   r1   r@   rB   rD   r   )r   rT   r0   a_labelr1   b_labelr   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   r   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 )Nri   r5   r   .r   )r   r   r$   r   r   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 )Nrf   ).N.r   )r   solver$   r   r   r	   r   broadcast_tor   r   r*   )rE   r0   r1   rD   r   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 Nrf         ?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  rd   rh   rh   rh   rj   )rh   rh   rh   rf   )
r$   r%   aranger   r   r   r   r   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  rd   rh   r+   rf   ri   r   )r$   r%   r  r   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  rj   rf   rh   r+   ri   r   )
r$   r%   r  r   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   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   rf   rf   r5   ra   )r$   r%   zerosint_r   r   r  r   r.   r"   float64r   r   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 Nrf   r   r5   r   )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   rf   ra   rb   )r$   r%   r  r  r   r   r  r   r.   r"   r  r   r   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"  ra   rb   )r$   r%   r  r  r   r   r  r   r.   r"   r  r   r   r#   r  rE   r  r0   r  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 )Nrf   r   r5   F
compute_uvr<   )r$   r   r   svdUSVhr   r.   r6   r<   )rE   r.   r   r  r4  r5  r6  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)   r0    s    r0  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   r3  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)   r7    r   r7  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 )rj   r   Tr1  rj   rj   ra   rj   )r   rj   N)r$   r   r   r3  r<   r   r   eye)rE   r   r8  r   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 )Nrf   r   Fr1  )r$   r   r   r3  r<   svdvalsr   )rE   r   
s_from_svds_from_svdvalsr(   r(   r)   test_svdvals  s   
zTestSVD.test_svdvalsN)rM   rN   rO   r>  rB  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 )Nr   r   axes)r   ranger   r$   conj	transpose)matrF  r(   r(   r)   r<     s   z'SVDHermitianCases.do.<locals>.hermitianr   )r   r3  r   r	   r$   r   r9   r.   r   r   r<  r   r   sortr   r*   )rE   r0   r1   rD   r8  r   r9  r<   r(   r(   r)   rH     s   &,,zSVDHermitianCases.doNr   r(   r(   r(   r)   rC    r   rC  c                   @   s   e Zd ZdZdS )TestSVDHermitianTN)rM   rN   rO   r<   r(   r(   r(   r)   rL    s    rL  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)r2  r   ).r   r{   ry   r2   r3   rh   r   rf   r   fro)r   r   r   r   condr3  r   r$   r  r   summaxminr   sqrt)rE   r0   r1   rD   cr   cinvr(   r(   r)   rH     sZ   
&
&&&

zCondCases.doNr   r(   r(   r(   r)   rM    s    rM  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   rf   )r   g       r   )r   r   rY   rj   gUUUUUU?rf   r   r   rO  gUUUUU6@)r   r   r   rP  r   r$   rT  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  Nrf   rh   rO  r   r     4&kC)r$   r  onesr   r   r   r   rP  )rE   Asp_posp_negrY  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)Nrf   r   rh   r   rO  r[  r  r"  )ri   rh   rh   rf   r   rf   rf   r   r\  rh   )	r$   r]  nanr   rP  r   r#   r  isnan)rE   psr_  rY  ra  rU  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   rh   r   ra   r   )Nrf   rh   rO  r   r   r"  rf   r   )
r$   randomseedrandr   rP  r   r   r   isfinite)rE   rY  ra  rU  r(   r(   r)   test_stacked_singular7  s   zTestCond.test_stacked_singularN)
rM   rN   rO   rZ  rb  r   r   xfailri  ro  r(   r(   r(   r)   rW    s    	

rW  c                   @   r   )	PinvCasesc                 C   s<   t |}t}t||||||ddd tt|| d S )Nr{   ry   rN  r   pinvr	   r   r   r*   rE   r0   r1   rD   a_ginvr   r(   r(   r)   rH   L  s   
zPinvCases.doNr   r(   r(   r(   r)   rq  G  s    rq  c                   @   r   )TestPinvNr   r(   r(   r(   r)   rv  T  r  rv  c                   @   r   )PinvHermitianCasesc                 C   s@   t j|dd}t}t||||||ddd tt|| d S )NTrD  r{   ry   rN  rr  rt  r(   r(   r)   rH   Z  s   zPinvHermitianCases.doNr   r(   r(   r(   r)   rw  X  r   rw  c                   @   r   )TestPinvHermitianNr   r(   r(   r(   r)   rx  b  r  rx  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rf   rh   ri   )rj   rf   rf   )rh   ri   rf   r   rcondr%  z%`rtol` and `rcond` can't be both set.)match)r{  r&  )r$   r   r   r   rs  r   raisesr  )r0   r(   r(   r)   test_pinv_rtol_argf  s   "r~  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 )Nr   axisr   rf   )r   detslogdetsign	logabsdetr   r.   r"   r   r   astyper   r  r   r   reducer$   exp
atleast_1dr   r   r   )rE   r0   r1   rD   dr  r   ldadr  mr(   r(   r)   rH   v  s   




zDetCases.doNr   r(   r(   r(   r)   r  t  r   r  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   rf   )r   r   r  r"   r   r   r  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   r  r.   r  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 )Nra   r5   rW   rj  r   rf   )r$   r  r  r   r  r   r   r.   r"   r  float32r  )rE   r0   r  r(   r(   r)   r
    s    







zTestDet.test_0_sizeN)rM   rN   rO   r  r   r   r  r   r   r   r   r   r
  r(   r(   r(   r)   r    s
    
r  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 )	NFr   rz  r   rh   r  rf   r   )r$   r   r   r   r3  lstsqr   r   r   r   r   __array_wrap__r   rQ  r   r   r   r"   
issubdtyper.   floatingr*   )rE   r0   r1   rD   arrr  nr8  r   r9  r   	residualsranksvexpect_residsr(   r(   r)   rH     s0   


 

zLstsqCases.doNr   r(   r(   r(   r)   r    r   r  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  rW   r  rW   rX   r  )r  rX   r  r  rW   r  )rW   r  rW   r  r  rZ   )r  r  r  rX   rY   r  )rf   r   r   r   r   r   r   rz  rj   ri   )r$   r   Tr   r  r   )rE   r0   r1   r   r  r  r   r(   r(   r)   
test_rcond  s   
zTestLstsq.test_rcond)r  r  n_rhs))rj   rh   rh   )r   rj   rf   )r   rj   rh   )rj   r   rf   )rj   r   rh   )rj   rh   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 )Nrz  r   rb   r   r  )r$   r  r   r]  r   r  r   r   r   r   r   r   rQ  rS  )rE   r  r  r  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   rf   rh   ri   )r   g?g?g @gffffff
@zIncompatible dimensionsrz  )
r$   r   vstackr]  lenr  r   r   r   r  )rE   r   yrY  r(   r(   r)   test_incompatible_dims  s   "z TestLstsq.test_incompatible_dimsN)	rM   rN   rO   r  r   r   r  r  r  r(   r(   r(   r)   r    s
    
	r  dtc                 C   s   g | ]}t |qS r(   )r$   r.   )r   rU  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 )TestMatrixPowerrj   )ri   r   rf   rh   )rh   ri   r   rf   )rf   rh   ri   r   rf   r   rh   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 )Nrh   d   i       r   rf   ri   )rshft_1r  r   r   rshft_0rshft_2rshft_3)rE   r  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_allr  objectstackedrE   r  r  rJ  r(   r(   r)   test_power_is_zero     
z"TestMatrixPower.test_power_is_zeroc                 C   r  )Nc                 S   s&   t | d}t||  t|j| j d S )Nrf   )r   r   r.   )rJ  r  r(   r(   r)   r  &  s   

z-TestMatrixPower.test_power_is_one.<locals>.tzr  r  r(   r(   r)   test_power_is_one%  r  z!TestMatrixPower.test_power_is_onec                 C   r  )Nc                 S   s>   t | d}| jtkrtnt}t||| |  t|j| j d S )Nrh   )r   r.   r  r	   r   r   )rJ  r  mmulr(   r(   r)   r  1  s   
z-TestMatrixPower.test_power_is_two.<locals>.tzr  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 Nr   )r   r.   r  r	   r   r   r   )rJ  invmatr  r(   r(   r)   r  =  s
   
z3TestMatrixPower.test_power_is_minus_one.<locals>.tz)r  dtnoinvr  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      ?rf   )r  r  r   	TypeErrorr   rE   r  rJ  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 )Nrf   rh   )rj   ri   rh   )r   r   r   r$   r   r]  )rE   r  r(   r(   r)   test_exceptions_non_squareL  s   z*TestMatrixPower.test_exceptions_non_squarefp errors don't work in wasmrd  c                 C   s,   || j v rd S | j|}ttt|d d S r  )r  noninvr  r   r   r   r  r(   r(   r)   test_exceptions_not_invertibleQ  s   
z.TestMatrixPower.test_exceptions_not_invertibleN)rM   rN   rO   r$   r<  r  r  r  r  r  r   r  blockr  r  r.   r  r  r  r  r  r  r  r  r   r   skipifr    r  r(   r(   r(   r)   r    s$    
r  c                   @   r   )TestEigvalshCasesc                 C   s^   t |d}t |\}}|jdd t||t|jd t |d}t||t|jd d S )NLr   r  r%  r4  )r   eigvalshr  rK  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 Nrf   r   r5   lrongUPLOlowerupper)r$   r   r  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   rf   r5   r   r%  r  r  lr4  r8  )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"  ra   rb   )r$   r%   r  r  r   r   r  r   r.   r"   r  r   r   r#   r  r  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 )Nr   r  .r%  r4  )r&  err_msg)r   eighr'  r(  r  rK  r   r   r	   r$   r   r9   r.   repr)rE   r0   r1   rD   r  r  evcr  r  r  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   r  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"  ra   rb   )r$   r%   r  r  r   r   r  r   r.   r"   r  r   r   r#   r  r  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$   inexactr   realr   r  )r   r  r(   r(   r)   check_dtype  s   z_TestNormBase.check_dtype)rM   rN   rO   r  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  r5   )r   r   r   r  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 )Nre  
AllIntegerAllFloatr  divide by zero encounteredr   r   rh   rf   rX   r   rj   g      ?rW   )r$   r   	typecodesr  r   r   r  r   r   filterRuntimeWarningr.   r"   	rE   r0   exact_typesinexact_types	all_types	each_typeat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)rf   rh   ri   rj   )r   r   r   r   )r   rh   r   rj   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   rf         $@r   gQ?rh   r   gsc?r   rj   )r$   testingr   r   r  r   )r,  rK   r(   r)   _test1  s0   
z+_TestNormGeneral.test_vector.<locals>._testr5   )r   r  )rE   r0   r1   rU  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 )Nry  rj   r{   r+   r5   r   r   rf   rh   ri   c                    s$   g | ]}t  d d |f dqS Nordr   r   krY  orderr(   r)   r   P     $ z._TestNormGeneral.test_axis.<locals>.<listcomp>r  r  c                    s$   g | ]}t  |d d f dqS r  r  r  r  r(   r)   r   R  r     rj   r   rO  c                    s*   g | ]}t  d d  j|ddqS Nr  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  r  r  r  r(   r)   r   k  s    $)r   r  r$   r   rG  r   r   r   r  r   r   r   combinationsr   r  )	rE   	expected0	expected1ndr  row_axiscol_axisr  r	  r(   )rY  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 )Nrf   r  r5   rh   ri   rj   zorder {0}, axis = {1}z;Shape mismatch found {0}, expected {1}, order={2}, axis={3}r  T)r  r  keepdims)r  )rf   rf   rf   r   r   r   rO  nuc)r$   r  r  r   r   r   squeezeformatr   r   r   rG  r   r   r   r   permutations)	rE   rY  allclose_err	shape_errr	  found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   r  )r   r   r   r  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 )Nre  r  r  fdFDrX   r  r   rW   rf   rh   gLXz?r   rO  r#  gU&,t=@r+   r  )r   r$   r  r  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 )Nrf   ri   r{   r   r5   gT"@rO  r#  r  g      (@rZ   r   r\   rh   gW?"@r   gїʄ?nofror   r   )r   r  r   r   r   r   r  rX  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?ry  )r+   r   r{   )ri   rh   rf   r5   grj=Q0?rO  r#  gB+pc?g?g333333?rf   rW   r   g?rh   g&.d?r   gܸՠ?)r   r  r   r   r   rX  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 )Nry  r
  r5   rf   r  rh   ri   rj   rO  r   r#  testr   ri   r"  )rf   rh   rh   ri   r   rf   rh   )	r   r  r$   r  r   r   r  r   r   )rE   rY  r  r  r(   r(   r)   test_bad_args  s   z_TestNorm2D.test_bad_argsN)
rM   rN   rO   r$   r   r-  r/  r1  r2  r7  r(   r(   r(   r)   r,    s    3r,  c                   @   r   )	_TestNormNr   r(   r(   r(   r)   r8    r  r8  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   ri   r  gL)@rh   r  )r$   r  
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   ri   r  l        r{   r  )r$   r   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rh   r5   y      @      @r   y            @rf   gV;'@ri   r  r:  r  	   r{   )	r$   r   clongdoubler/   r   r   r  
complex128r  )rE   r  r  r(   r(   r)   test_complex_high_ord$  s   z,TestNorm_NonSystematic.test_complex_high_ordN)rM   rN   rO   r<  r>  rC  r(   r(   r(   r)   r9    s    r9  c                   @      e Zd ZejZdZdS )_TestNormDoubleBaser,   N)rM   rN   rO   r$   r   r  r  r(   r(   r(   r)   rE  2      rE  c                   @   rD  )_TestNormSingleBaser+   N)rM   rN   rO   r$   r  r  r  r(   r(   r(   r)   rG  7  rF  rG  c                   @   rD  )_TestNormInt64Baser,   N)rM   rN   rO   r$   int64r  r  r(   r(   r(   r)   rH  <  rF  rH  c                   @   r   )TestNormDoubleNr   r(   r(   r(   r)   rJ  A  r  rJ  c                   @   r   )TestNormSingleNr   r(   r(   r(   r)   rK  E  r  rK  c                   @   r   )TestNormInt64Nr   r(   r(   r(   r)   rL  I  r  rL  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 )Nrj   r  r   r   ri   r;  r   )rf   r   r   r   rf   )rj   )ri   rj   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 )Nrj   TrD  rf   r;  r   r  rN  ri   g:0yE>g|"BE>)r<   rO  g;䡈E>)r   r   r$   r<  r]  r  )rE   rP  r(   r(   r)   test_symmetric_rankh  s   
z"TestMatrixRank.test_symmetric_rankN)rM   rN   rO   rR  rS  r(   r(   r(   r)   rM  M  s    rM  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r  )(   r:  sizerf   rh   r   r@  rj   r{   ri   rd   )r$   rk  RandomStaterG  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.   r   rS  r   qrQRr   r#   r   r   r  rH  r$   r<  triu)rE   r0   a_typea_dtyper  r  r  r  rc  rd  q1r1r2r(   r(   r)   check_qr  s:   

zTestQR.check_qrr  r  )ri   r   r4  ra   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_  )
rS  r$   r   rk  r   rb  r   r.   r   r   )rE   r  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 )Nrf   rh   ri   rj   r{   r+   r5   rm  r_  r5  r?  r   )	r   r$   r   r   rb  r   r.   r   r  )rE   r0   rn  ro  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 )	Nrf   rh   ri   rj   r{   r+   fd              ?)r   r  rk  r  )rE   r0   r1   r  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 )	Nr   r^  r_  r   rh   .ra  r   )r"   r.   r   rS  r   rb  r   r#   r   r	   r$   r   r   r
   rH  re  )rE   r0   rf  rg  r  r  r  qr   I_matstack_I_matrh  ri  rj  r(   r(   r)   check_qr_stacked  sL   
""zTestQR.check_qr_stackedrV  ))ri   rj   )rj   ri   r;  rl  r4  
outer_size)r  r?  )rh   ri   rj   r  c                 C   sX   t jd}|j|| d|}|j|| d|}| | | |d|   d S )N{   rU  rs  )r$   rk  default_rngrX  r  rz  )rE   r{  rV  r  rY  rY  r  r(   r(   r)   test_stacked_inputs  s
   

zTestQR.test_stacked_inputsN)rM   rN   rO   r$   r   rk  r   r   r  rp  rq  rv  rz  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 )TestCholeskyr   )r   r  ri   ri   )2   r  )ri   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 )Nrf   rs  )r   r   r   r5   r  i  r    
)atolr  r   )axis1axis2)r$   rk  rl  randnr  complexfloatingr   rG  r  r	   rI  rH  r   r   choleskyr   finfoepsr   diagonalr   r   isreal)
rE   r   r.   r  r0   trU  r1   r  r  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   )rf   r   r   )r$   r%   r  r  r   r   r  r   r   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  r  rH  )rE   r0   r(   r(   r)   test_upper_lower_arg[  s   z!TestCholesky.test_upper_lower_argN)rM   rN   rO   r   r   r  r$   r  r  r  rB  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 )	TestOuterri   r  r6  )r   rh   rj   z$Input arrays must be one-dimensionalN)rM   rN   rO   r$   r  arr1arr2r   r	  r   r   outerr   r  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   rj   r5   r5  =)sys	byteorderr$   r  r  r<  r   r.   newbyteorderbyteswapr   r   r  r  rs  r   )nativedttr  n_arrsw_arrroutiner  r(   r(   r)   test_byteorder_checkx  s   
r  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 )Nrf   rh   ri   rj   )rj   rj   rh   rh   .ra   )r$   r   r  r   r   r   r  )
invertiblenon_invertibler   r(   r(   r)    test_generalized_raise_multiloop  s   r  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   rf   ra   rW   zDORGQR parameter number 5zNumpy xerbla not linked in.)osforkOSErrorAttributeErrorr   skipcloseresource	setrlimitRLIMIT_COREr$   r   lapack_litexerblar  r   _exit	EX_CONFIGr   dorgqrrA   waitWEXITSTATUS)	XERBLA_OKpidr  r0   r   statusr(   r(   r)   test_xerbla_override  sF   


r  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.QtWidgets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)r  r  r  )textwrapdedentr%  
subprocess
check_callr  
executable)bad_libstemplater  coder(   r(   r)   test_sdot_bug_8577  s   
r  c                   @   sd   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )TestMultiDotc              	   C   sl   t jd}t jd}t jd}tt|||g||| tt|||gt |t || d S Nr+   rh   rh   r+   r$   rk  r   r   r   )rE   rY  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  )rE   rY  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  rh   rf   r  )rE   rY  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 )Nrh   r  r  r  r?  r$   rk  r   r   r   )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 )Nr  r  rh   )r+   r  )rE   rY  r  r  D1dr(   r(   r)   test_vector_as_last_argument  r  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 )Nrh   r  r  r(   r  )rE   r  r  r  r  r(   r(   r)   &test_vector_as_first_and_last_argument$  r  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 )Nr  r  r&   r$   rk  r  r   r   r   )rE   rY  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+   r  r  )rE   rY  r  r&   r  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 )Nr  r  r  )r+   rf   r  r  )rE   rY  r  r  r  r&   r  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)   #   )r     )r  r{   )r{   r:  )r:     )r  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   rf   rf   ri   ri   ri   )r   r   rh   ri   ri   ri   )r   r   r   ri   ri   ri   )r   r   r   r   rj   r{   )r   r   r   r   r   r{   )r   r   r   r   r   r   r5   rf   T)return_costsr   )r$   rk  r   intr   r   re  )rE   arrays
m_expected
s_expectedr   r  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$   rk  rK   r(   r(   r)   test_too_few_input_arrayso  s   z&TestMultiDot.test_too_few_input_arraysN)rM   rN   rO   r  r  r  r  r  r  r  r  r  r  r  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rj   r+   rd   rh   rh   ri   ri   rh   rf   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  r  r(   r(   r)   test_non_square_handlingv  s   
"z&TestTensorinv.test_non_square_handlingz
shape, ind)rj   r+   rd   ri   rh   )   rd   ri   rf   c                 C   sN   t d}||_tj||d}|j|d  |jd |  }|j}t|| d S )Nr  r0   r  )r$   r<  r   r   r  r   )rE   r   r  r0   ainvr	  actualr(   r(   r)   test_tensorinv_shape~  s   
z"TestTensorinv.test_tensorinv_shaper  r   r   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<  r   r   r  r   r  )rE   r  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  rf   r  )	r$   r<  r   r   r  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)   r  t  s     


r  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, axesr  Nr  )r   rh   c                 C   sR   t t t|jd d }tj|||d W d    d S 1 s"w   Y  d S Nrh   rE  )r   r   r$   r]  r   r   r  )rE   r0   rF  r1   r(   r(   r)   r    s   
"z(TestTensorsolve.test_non_square_handlingr   ))rh   ri   r+   )ri   rj   rj   ri   )r   ri   ri   r   c                 C   sN   t jj| }t |jd d }t j||}tt j||t	|jd| d S r   )
r$   rk  r  r]  r   r   r  r   r  r  )rE   r   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 )Nrf   r   rh   r{   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        rf   r5   )r   r   )r$   r  r  r]  r   r   )r  r0   r1   rU  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       rf   r5   r   r   infor  r  r  l        )
r$   r  r   r  dgeqrfr  r   r  itemr   )
r.   lapack_routiner  r  ldar0   workro  results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<   ri   rj   r{   )r   r+   r,      )r     r  &   )rT  .   4   :   )r$   r  r   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  r   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  rf   )r   rh   r   ry  r
  )r   r+   r   z8input arrays must be \(arrays of\) 3-dimensional vectors)	r$   r  r   r   crossr   r   r   r  )r   r  r	  r8  r,  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+   r5  7   r"  rE  )r$   r  r   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+   r5  r{      r  )r$   r  r   r   r	   r  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+   r5  z$array must be at least 2-dimensionalr   )	r$   r  r   r   matrix_transposer  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  ^)ː,@ri   r3   Tr"  )r$   r  r   r   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'  ri   r(  r   r  )g|a2@gsh|? @gDioI#@Tr)  r   r  r5   )r$   r  r   r   vector_normr   r  r   fullr   r   r  r(   r(   r)   test_vector_normC	  s   r.  )r+   r,   )__doc__r  r  r   	threadingr   r  r  r   numpyr$   r   r   r   r   r   r   r   r	   numpy._corer
   numpy.exceptionsr   r   r   r   r   r   numpy.linalgr   r   r   r   r   numpy.linalg._linalgr   numpy.testingr   r   r   r   r   r   r   r   r   r    numpy.linalg.lapack_liteImportErrorr*   r/   r6   r8   r9   rQ   r@   rU   rk  rl  r   r   rm  r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r   r$  r)  r0  r7  r:  rC  rL  rM  rW  rq  rv  rw  rx  r~  r  r  r  r  r   r  r  r  r  r  r  r  r  r,  r8  r9  rE  rG  rH  rJ  rK  rL  rM  r\  r]  r  r  r  r  r  active_countr  r   r  r  r  r  r  r  r  rp  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" )

	

