o
    Je1                    @   s
  d Z ddlZddlZddlZddlZddlZddlZddlZddlZ	ddlm
Z
mZmZmZmZmZmZmZ ddlmZ ddlmZmZmZmZ ddlmZ ddlmZmZmZmZmZ ddlm Z  dd	l!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ zddl,ZW n	 e-y   Y nw d
d Z.e&Z/dddZ&dd Z0dd Z1dd Z2h dZ3G dd dZ4dd Z5e	j67d g Z8e8e5de4de
ddgd d!gged"e
ddged"e4d#e
ddgd d!gged"e
ddged"e4d$e
ddgd d!gged"e
g d%g d&ged"e4d'e
d(d)gd*d+gged"e
d,d(ged"e4d-e
d(d)gd*d+gged"e
d,d(ged"e4d.e
d(d)gd*d+gged"e
g d/g d0ged"e4d1e	j9d2ed"e	j9d3ed"d4hd5e4d6e	j6:d7d7e	j6:d7e4d8e	j6:d9d9e	j6:d9e4d:d9d;gd<d=ggd;d9gg
7 Z8e8e5d>e4d?e
g d@g d&ged"e
ddged"e4dAe
ddgd d!gdBdCgged"e
g dDed"e4dEe
g d@g d&ged"e
ddged"e4dFe
ddgd d!gdBdCgged"e
g dDed"e4dGe
g dHg dIged"e
d,d(ged"e4dJe
dKdLgdMdNgdOdPgged"e
g dQed"e4dRe
g dHg dIged"e
d,d(ged"e4dSe
dKdLgdMdNgdOdPgged"e
g dQed"e4dTe
g dHg dIged"e
d,d(gdUdVgged"e4dWe
dKdLgdMdNgdOdPgged"e
d,d(gdUdVgdUdVgged"e4dXe	j6:d7dYe	j6:d7e4dZe	j6:d9d[e	j6:d9e4d\e	j6:d[d9e	j6:d[e4d]e	j6:dd=e	j6:dd4hd5e4d^e	j6:d=de	j6:d=d4hd5g7 Z8e8e5d_e4d`e
ddgddgged"de4dae
ddgddgged"de4dbe
dd)gdcd9gged"de4dde
dd)gdcd9gged"de4dee	j9d2ed"dd4hd5e4dfd9d;gd;d9ggde4dge
ddgddggde4dhe	j6:d9d9dg7 Z8didj Z;e8e; 7 Z8dkdl Z<dmdn Z=e8e= 7 Z8G dodp dpZ>G dqdr dre>Z?G dsdt dte>Z@G dudv dve>ZAG dwdx dxe>ZBG dydz dze>ZCG d{d| d|e>ZDd}d~ ZEdd ZFG dd de?eBZGG dd deGZHG dd de?eBZIG dd deIZJG dd de?eBZKG dd deKZLG dd de?eBZMG dd deMZNG dd dZOG dd de?eBZPG dd dePeOZQG dd deAeDZRG dd deReOZSG dd de?eBZTG dd deTZUG dd de?e@eBeCZVG dd deVZWG dd deAeDZXG dd deXZYG dd de?eBZZG dd deZZ[G dd de?e@Z\G dd de\Z]ej^_ddd dD G dd dZ`G dd deAeDZaG dd dZbG dd deAeDZcG dd dZdG dd dZeG dd deeZfG dd deeZgG ddĄ degefZhG ddƄ dƃZiG ddȄ deeZjG ddʄ deeZkG dd̄ deeZlG dd΄ dehejZmG ddЄ dehekZnG dd҄ dehelZoG ddԄ dԃZpddք ZqG dd؄ d؃ZrG ddڄ dڃZsdd܄ Ztej^jue+ddލdd Zvdd Zwej^jue+ddލej^jxdd ZyG dd dZzG dd dZ{G dd dZ|dd Z}ej^j~ddލdd Zej^je* ddލdd ZdS )z# Test functions for linalg module

    N)arraysingledoublecsinglecdoubledotidentitymatmul)swapaxes)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)outZin_ r&   l/home/seandotau/au.memorygallery.club/gallery/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_dtype3   
   r4   c                 C   s   t ttttttti|  S r    )r   r   r   r   r3   r&   r&   r'   get_complex_dtype8   r5   r6   c                 C   s   | t tfv rdS dS )Ngh㈵>gdy=)r   r   r3   r&   r&   r'   get_rtol=   s   r7   >   squaresize-0generalized	hermitian	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namer.   r/   	frozensettags)selfr@   r.   r/   rB   r&   r&   r'   __init__M   s
   zLinalgCase.__init__c                 C   s   || j | j| jd dS )zN
        Run the function `do` on this test case, expanding arguments
        rB   N)r.   r/   rB   )rC   dor&   r&   r'   checkX   s   zLinalgCase.checkc                 C   s   d| j  dS )Nz<LinalgCase: >)r@   rC   r&   r&   r'   __repr__^   s   zLinalgCase.__repr__N)__name__
__module____qualname__setrD   rG   rJ   r&   r&   r&   r'   r>   L   s    r>   c                 C   s,   | t v sJ d|D ]	}|j| hB |_q
|S )z^
    Add the given tag (a string) to each of the cases (a list of LinalgCase
    objects)
    zInvalid tag)all_tagsrB   )tagcasescaser&   r&   r'   	apply_tagb   s   rS     r8   r         ?       @      @      @r3   r   Zdouble_2)rV   rU   rX   )rW   rX         @r         ?       @y       @      @y      @      @y      @      @       @      ?r   Z	cdouble_2)r[   rZ   y      ?      @)y      ?       y      ?      y      ?      Z0x0r   r   r   r9   rE   Z8x8   Z1x1   Znonarray         r<   Zsingle_nsq_1)rU   rV   rW   Zsingle_nsq_2g      @rY   )rV   rU   rW   Zdouble_nsq_1Zdouble_nsq_2Zcsingle_nsq_1)      ?      ?       @       @      @      )y      @      y      @      "@y      @       @Zcsingle_nsq_2rc   rd   re   y      @      "y      @      y      @       @)r[   rZ   re   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   s  g } t D ]}t|jtjsqt|jd|j d|j g}|jd u r%d }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 rbd }nt|jgd d d|jj }t|jd	 |||j	dhB d}| 
| q| S )
Nr`   ra      r)   Z_tile3r:   rE   ra   r`   Z_tile213)CASESr"   r.   r#   r$   r   r/   r>   r@   rB   appendreshapeshape)	new_casesrR   r.   r/   new_caser&   r&   r'   _make_generalized_cases   s*   


$
$
rp   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r_   )r_   ra   r_   r`   )r_   rr   c                 S   s   g | ]
\}}t || qS r&   )abs).0r.   r/   r&   r&   r'   
<listcomp>%  s    z%_stride_comb_iter.<locals>.<listcomp>c                 S   s   g | ]}t d d |qS r    )slice)rw   repeatr&   r&   r'   rx   &  s    r3   l   >[= .Zstride__c                 S   s   g | ]}d | qS )z%+dr&   )rw   jr&   r&   r'   rx   /  s    r   )stridesZstride_xxx_0Zstride_xxx_0_xr_   r_   Zstride_xxx_0_0)r"   r#   r$   ndim	itertoolsproducttupleziprm   emptyr,   viewZuint32fill	__class__r   alljoinlistr}   libZstride_tricksZ
as_strided)xZ
stride_setZrepeats	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=   rE   )rj   r   r.   r/   r>   r@   rB   rk   )rn   rR   r.   Za_labelr/   Zb_labelro   r&   r&   r'   _make_strided_casesD  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_CASESrB   rG   rF   	Exception	traceback
format_excAssertionError)rC   requireexcluderR   emsgr&   r&   r'   check_casesX  s   


zLinalgTestCase.check_casesN)rK   rL   rM   rj   r   rN   r   r&   r&   r&   r'   r   U  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 )Nr8   r:   r9   r   r   r   rI   r&   r&   r'   test_sq_casesn     
z"LinalgSquareTestCase.test_sq_casesc                 C      | j ddhdhd d S )Nr8   r9   r:   r   r   rI   r&   r&   r'   test_empty_sq_casesr     

z(LinalgSquareTestCase.test_empty_sq_casesN)rK   rL   rM   r   r   r&   r&   r&   r'   r   l      r   c                   @   r   )LinalgNonsquareTestCasec                 C   r   )Nr<   r:   r9   r   r   rI   r&   r&   r'   test_nonsq_casesy  r   z(LinalgNonsquareTestCase.test_nonsq_casesc                 C   r   )Nr<   r9   r:   r   r   rI   r&   r&   r'   test_empty_nonsq_cases}  r   z.LinalgNonsquareTestCase.test_empty_nonsq_casesN)rK   rL   rM   r   r   r&   r&   r&   r'   r   w  r   r   c                   @   r   )HermitianTestCasec                 C   r   )Nr;   r:   r9   r   r   rI   r&   r&   r'   test_herm_cases  r   z!HermitianTestCase.test_herm_casesc                 C   r   )Nr;   r9   r:   r   r   rI   r&   r&   r'   test_empty_herm_cases  r   z'HermitianTestCase.test_empty_herm_casesN)rK   rL   rM   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:   r8   r9   r   r   rI   r&   r&   r'   test_generalized_sq_cases     

z9LinalgGeneralizedSquareTestCase.test_generalized_sq_casesc                 C      | j h dd d S )N>   r8   r9   r:   r   r   rI   r&   r&   r'   test_generalized_empty_sq_cases     z?LinalgGeneralizedSquareTestCase.test_generalized_empty_sq_casesN)rK   rL   rM   pytestmarkslowr   r   r&   r&   r&   r'   r     
    
r   c                   @   r   )"LinalgGeneralizedNonsquareTestCasec                 C   r   )Nr:   r<   r9   r   r   rI   r&   r&   r'   test_generalized_nonsq_cases  r   z?LinalgGeneralizedNonsquareTestCase.test_generalized_nonsq_casesc                 C   r   )N>   r9   r:   r<   r   r   rI   r&   r&   r'   "test_generalized_empty_nonsq_cases  r   zELinalgGeneralizedNonsquareTestCase.test_generalized_empty_nonsq_casesN)rK   rL   rM   r   r   r   r   r   r&   r&   r&   r'   r     r   r   c                   @   r   )HermitianGeneralizedTestCasec                 C   r   )Nr:   r;   r9   r   r   rI   r&   r&   r'   test_generalized_herm_cases  r   z8HermitianGeneralizedTestCase.test_generalized_herm_casesc                 C   s   | j h ddhd d S )N>   r9   r:   r;   noner   r   rI   r&   r&   r'   !test_generalized_empty_herm_cases  r   z>HermitianGeneralizedTestCase.test_generalized_empty_herm_casesN)rK   rL   rM   r   r   r   r   r   r&   r&   r&   r'   r     r   r   c                 C   s   t | } | jdkrZ| j|jkr| jd d |jdd   }n| j|jd kr.| jd d }ntdtj|t| |d}tjt	t
| jd d  D ]}t| | || ||< qJ|S t| |S )Nra   rs   r_   zNot implemented...r3   rt   )r   r   rm   
ValueErrorr#   r   Zcommon_typer   r   mapranger   )r.   r/   r   rcr&   r&   r'   dot_generalized  s   

r   c                 C   sH   t | } | jdkrtj| j| jd}t| jd |d< |S t| jd S )Nra   r3   rt   .r   )r   r   r#   r   rm   r,   r   )r.   r   r&   r&   r'   identity_like_generalized  s   
r   c                   @      e Zd Zdd ZdS )
SolveCasesc                 C   s.   t ||}t|t|| tt|| d S r    )r   solver   r   r   r(   )rC   r.   r/   rB   r   r&   r&   r'   rF     s   zSolveCases.doNrK   rL   rM   rF   r&   r&   r&   r'   r         r   c                   @   s:   e Zd Zejdeeee	gdd Z
dd Zdd ZdS )		TestSolver,   c                 C   s2   t jddgddgg|d}tt||j| d S Nr_         ?r3   )r#   r   r   r   r   r,   rC   r,   r   r&   r&   r'   
test_types  s   zTestSolve.test_typesc              	   C   s.  G dd dt j}t dddd}t d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dd|}t||d d ddf }t|d d ddddf |d d ddf }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                   @      e Zd ZdS )z,TestSolve.test_0_size.<locals>.ArraySubclassNrK   rL   rM   r&   r&   r&   r'   ArraySubclass      r   r^   r`   r)   r_   ra   r   )r#   r$   arangerl   r   r   r   r   r   r"   r   r   r   rC   r   r.   r/   expectedresultr&   r&   r'   test_0_size  s*   "8
(& 2
 *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   rb   r_   r`   r)   ra   r   )
r#   r$   r   rl   r   r   r   r   r   r"   r   r&   r&   r'   test_0_size_k  s   ""
"8
zTestSolve.test_0_size_kN)rK   rL   rM   r   r   parametrizer   r   r   r   r   r   r   r&   r&   r&   r'   r     s
    
!r   c                   @   r   )InvCasesc                 C   s0   t |}tt||t| tt|| d S r    )r   invr   r   r   r   r(   )rC   r.   r/   rB   Za_invr&   r&   r'   rF     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   r_   r_   r3   r\   )r#   r$   zerosint_r   r   r   r   r,   r!   float64r   rm   r"   	complex64rC   r   r.   resr&   r&   r'   r      s   

zTestInv.test_0_sizeNrK   rL   rM   r   r   r   r   r   r   r   r   r   r&   r&   r&   r'   r     s    
r   c                   @   r   )EigvalsCasesc                 C   s&   t |}t |\}}t|| d S r    )r   eigvalseigr   )rC   r.   r/   rB   evevaluesevectorsr&   r&   r'   rF   3  s   
zEigvalsCases.doNr   r&   r&   r&   r'   r   1  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 Nr_   r   r3   rs   )r#   r   r   r   r   r,   r6   r   r&   r&   r'   r   :  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   C  r   r   r   r3   r   r_   r\   r]   )r#   r$   r   r   r   r   r   r   r,   r!   r   r   rm   r"   r   r   r&   r&   r'   r   A     

zTestEigvals.test_0_sizeNr   r&   r&   r&   r'   r   9  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   r7   r,   r   r(   )rC   r.   r/   rB   r   r   r   r&   r&   r'   rF   V  s   

 zEigCases.doNr   r&   r&   r&   r'   r   T  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,   r6   rC   r,   r   wvr&   r&   r'   r   `  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   n  r   r   r   r3   r   r\   r]   )r#   r$   r   r   r   r   r   r   r,   r!   r   r   rm   r"   r   rC   r   r.   r   Zres_vr&   r&   r'   r   l     zTestEig.test_0_sizeNr   r&   r&   r&   r'   r   _  s    
r   c                   @   s.   e Zd ZdZejdeee	e
gdd ZdS )SVDBaseTestsFr,   c                 C   s   t jddgddgg|d}t|}|j|j|j}}}t|j| t|jt	| t|j| tj|d| j
d}t|jt	| d S )Nr_   r   r3   F
compute_uvr;   )r#   r   r   svdUSVhr   r,   r4   r;   )rC   r,   r   r   r  r  r  r   r&   r&   r'   r     s   
zSVDBaseTests.test_typesN)rK   rL   rM   r;   r   r   r   r   r   r   r   r   r&   r&   r&   r'   r     s    r   c                   @   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   r7   r,   r   r(   )rC   r.   r/   rB   ur   vtr&   r&   r'   rF     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 )rb   r   Tr   rb   rb   r\   rb   )r   rb   N)r#   r   r   r  r;   r   rm   eye)rC   r   r  r   Zvhr&   r&   r'   test_empty_identity  s   

zTestSVD.test_empty_identityN)rK   rL   rM   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 )Nrt   rs   axes)r   r   r   r#   conj	transpose)matr  r&   r&   r'   r;     s   z'SVDHermitianCases.do.<locals>.hermitianrs   )r   r  r   r   r#   r   r7   r,   r   r	   broadcast_tor
  rm   r   sortr   r(   )rC   r.   r/   rB   r  r   r  r;   r&   r&   r'   rF     s   &,,zSVDHermitianCases.doNr   r&   r&   r&   r'   r    r   r  c                   @   s   e Zd ZdZdS )TestSVDHermitianTN)rK   rL   rM   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 )Nr9   F)r   ).r   ).rs   rg   rf   r0   r1   r`   rt   r_   rs   fro)r   r   r   r   condr  r   r#   r   rv   summaxminr   sqrt)rC   r.   r/   rB   r   r   Zcinvr&   r&   r'   rF     sZ   
&
&&&

zCondCases.doNr   r&   r&   r&   r'   r    s    r  c                   @   s>   e Zd Zdd Zdd Zejjddddd	d
 Zdd Z	dS )TestCondc                 C   s   t g dg dg dg}tt|td tt|t d tt|dd tt|dd tt|d	td
 d S )N)rU   r   r_   )r   g       r   )r   r   rW   rb   gUUUUUU?r_   rs   r   r  gUUUUU6@)r   r   r   r  r   r#   r  rC   Ar&   r&   r'   test_basic_nonsvd  s   zTestCond.test_basic_nonsvdc                 C   st   t dt dg}g d}ddg}t||D ]\}}tt||dk qt||D ]
\}}t|| q-d S )Nr`   r`   Nr_   r`   r  rs   rt     4&kC)r#   r   onesr   r   r   r   r  )rC   ZAsp_posZp_negr   pr&   r&   r'   test_singular  s   zTestCond.test_singularTFz/Platform/LAPACK-dependent failure, see gh-18914)runreasonc                 C   s   g d}g d}t d}t j|d< |D ]}t||}tt|t j tt | qt d}t j|d< |D ]:}t||}tt |d  ||v r^t|d d	k t|d
 d	k q8tt |d   tt |d
   q8d S )N)Nr_   rs   r`   rt   r  r#  r"  r   )ra   r`   r`   r_   r   r_   r_   r   r$  r`   )	r#   r%  nanr   r  r   r"   Zfloat_isnan)rC   Zpsr&  r   r'  r   r&   r&   r'   test_nan
  s&   



zTestCond.test_nanc                 C   s   t jd t jdddd}d|d< d|d< dD ]*}t||}t|d t j t|d t j tt 	|d  tt 	|d  qd S )	NrT   r`   r   r\   r~   )Nr_   r`   r  rs   rt   r   r_   r   )
r#   randomseedrandr   r  r   r   r   isfinite)rC   r   r'  r   r&   r&   r'   test_stacked_singular%  s   zTestCond.test_stacked_singularN)
rK   rL   rM   r!  r(  r   r   xfailr.  r4  r&   r&   r&   r'   r    s    	

r  c                   @   r   )	PinvCasesc                 C   s<   t |}t}t||||||ddd tt|| d S )Nrg   rf   r  r   pinvr   r   r   r(   rC   r.   r/   rB   Za_ginvr   r&   r&   r'   rF   :  s   
zPinvCases.doNr   r&   r&   r&   r'   r6  5  s    r6  c                   @   r   )TestPinvNr   r&   r&   r&   r'   r:  B  r   r:  c                   @   r   )PinvHermitianCasesc                 C   s@   t j|dd}t}t||||||ddd tt|| d S )NTr  rg   rf   r  r7  r9  r&   r&   r'   rF   H  s   zPinvHermitianCases.doNr   r&   r&   r&   r'   r;  F  r   r;  c                   @   r   )TestPinvHermitianNr   r&   r&   r&   r'   r<  P  r   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 )Nrs   axisr   r_   )r   detslogdetsignZ	logabsdetr   r,   r!   r   r   astyper   r   r   r   reducer#   expZ
atleast_1drv   r   r   )rC   r.   r/   rB   dr   r   ldadr   mr&   r&   r'   rF   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   r_   )r   r   r@  r!   r   r   rA  r   rI   r&   r&   r'   	test_zeroj  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,   rA  r4   )rC   r,   r   phr   r&   r&   r'   r   w  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\   r3   rU   r/  r   r_   )r#   r   r   r   r@  r   r   r,   r!   rA  float32r   )rC   r.   r   r&   r&   r'   r     s    







zTestDet.test_0_sizeN)rK   rL   rM   rL  r   r   r   r   r   r   r   r   r   r&   r&   r&   r'   rJ  i  s
    
rJ  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 )	NFrs   Zrcondr   r`   r>  r_   rq   )r#   r   rm   r   r  lstsqr   r   r   r   r   Z__array_wrap__rv   r  r   r   r   r!   
issubdtyper,   floatingr(   )rC   r.   r/   rB   arrrI  nr  r   r  r   	residualsranksvZexpect_residsr&   r&   r'   rF     s0   


 

zLstsqCases.doNr   r&   r&   r&   r'   rO    r   rO  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 K}|td}t||\}}}}t|dk tj||dd	\}}}}t|dk tj||d d	\}}}}t|d
k tt	|dk W d    d S 1 sjw   Y  d S )N)rK  rU   rK  rU   rV   rK  )rK  rV   rK  rK  rU   rK  )rU   rK  rU   rK  rK  rX   )rK  rK  rK  rV   rW   rK  )r_   r   r   r   r   r   z`rcond` parameter will changerb   rs   rP  ra   r_   )
r#   r   Tr   recordFutureWarningr   rQ  r   len)	rC   r.   r/   supr   r   rV  rW  r   r&   r&   r'   test_future_rcond  s$   
"zTestLstsq.test_future_rcond)rI  rU  n_rhs))rb   r`   r`   )r   rb   r_   )r   rb   r`   )rb   r   r_   )rb   r   r`   )rb   r`   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 )NrP  r   r]   rt   r>  )r#   r   rl   r%  r   rQ  r   r   r   rm   r   r   r  r  )rC   rI  rU  r`  r.   r/   r   rV  rW  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   r_   r`   ra   )rs   g?g?g @gffffff
@zIncompatible dimensionsrP  )
r#   r   Zvstackr%  r]  rZ  r   r   r   rQ  )rC   r   yr   r&   r&   r'   test_incompatible_dims  s   "z TestLstsq.test_incompatible_dimsN)	rK   rL   rM   r_  r   r   r   ra  rc  r&   r&   r&   r'   rY    s
    
	rY  dtc                 C   s   g | ]}t |qS r&   )r#   r,   )rw   r   r&   r&   r'   rx     s    rx   z?bBhHiIqQefdgFDGOc                   @   s   e Zd ZedZeg d Zeg d Zeg d ZeeeegZ	e
ddgddggZeegggd Zeeded	ed
gZdd Zdd Zdd Zdd Zdd Zdd Zdd Zejjedddd ZdS )TestMatrixPowerrb   )ra   r   r_   r`   )r`   ra   r   r_   )r_   r`   ra   r   r_   r   r`   r   gGc                 C   s   | j |}tt|dd d d d | j tt|dd d d d | j  tt|dd d d d | j tt|dd d d d | j d S )Nr`   d   i       r   r_   ra   )rshft_1rC  r   r   rshft_0rshft_2rshft_3)rC   rd  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_allrC  objectstackedrC   rd  rr  r  r&   r&   r'   test_power_is_zero     
z"TestMatrixPower.test_power_is_zeroc                 C   ro  )Nc                 S   s&   t | d}t||  t|j| j d S )Nr_   )r   r   r,   )r  rq  r&   r&   r'   rr  	  s   

z-TestMatrixPower.test_power_is_one.<locals>.tzrs  rw  r&   r&   r'   test_power_is_one  ry  z!TestMatrixPower.test_power_is_onec                 C   ro  )Nc                 S   s>   t | d}| jtkrtnt}t||| |  t|j| j d S )Nr`   )r   r,   ru  r	   r   r   )r  rq  mmulr&   r&   r'   rr    s   
z-TestMatrixPower.test_power_is_two.<locals>.tzrs  rw  r&   r&   r'   test_power_is_two  s   
z!TestMatrixPower.test_power_is_twoc                 C   s0   dd }| j D ]}|| jvr||| qd S )Nc                 S   s4   t | d}| jtkrtnt}t||| t|  d S Nrs   )r   r,   ru  r	   r   r   r   )r  Zinvmatr{  r&   r&   r'   rr     s
   
z3TestMatrixPower.test_power_is_minus_one.<locals>.tz)rt  dtnoinvrC  rw  r&   r&   r'   test_power_is_minus_one  s   

z'TestMatrixPower.test_power_is_minus_onec                 C   s.   | j |}ttt|d ttt|dg d S )Ng      ?r_   )rk  rC  r   	TypeErrorr   rC   rd  r  r&   r&   r'   test_exceptions_bad_power*  s   z)TestMatrixPower.test_exceptions_bad_powerc                 C   sP   t tttdg|d t tttdgdgg|d t tttd|d d S )Nr_   r`   )rb   ra   r`   )r   r   r   r#   r   r%  )rC   rd  r&   r&   r'   test_exceptions_non_square/  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~  noninvrC  r   r   r   r  r&   r&   r'   test_exceptions_not_invertible4  s   
z.TestMatrixPower.test_exceptions_not_invertibleN)rK   rL   rM   r#   r
  rk  rj  rl  rm  rt  r   r  blockrv  ru  r,   r~  rn  rx  rz  r|  r  r  r  r   r   skipifr   r  r&   r&   r&   r'   re    s$    
re  c                   @   r   )TestEigvalshCasesc                 C   s^   t |d}t |\}}|jdd t||t|jd t |d}t||t|jd d S )NLrs   r>  r   r  )r   eigvalshr   r  r   r7   r,   )rC   r.   r/   rB   r   r   r   ev2r&   r&   r'   rF   >  s   zTestEigvalshCases.doNr   r&   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 )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,   r4   )rC   r,   r   r   r&   r&   r'   r   K  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 Nr_   r   r3   ZlrongZUPLOlowerupper)r#   r   rN  r   r   r   r  rC   r   r&   r&   r'   test_invalidQ     zTestEigvalsh.test_invalidc                 C   s   t jddgddggt jd}t jddgddggt jd}t jddgt jd}tt j}t j|}t|||d t jj|dd}t|||d t jj|dd}t|||d t jj|d	d}t|||d t jj|d
d}t|||d d S Nr   r_   r3   rs   r   r  r  lr  r  )r#   r   r   r7   r   r  r   )rC   KloKuptgtr   r   r&   r&   r'   	test_UPLOW  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   o  r   r   r   r3   r   r\   r]   )r#   r$   r   r   r   r   r  r   r,   r!   r   r   rm   r"   r   rN  r   r&   r&   r'   r   m  r   zTestEigvalsh.test_0_sizeNrK   rL   rM   r   r   r   r   r   r   r   r   r  r  r   r&   r&   r&   r'   r  J  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 )Nrs   r>  .r   r  )r   err_msg)r   eighr   r   r   r  r   r   r   r#   r   r7   r,   repr)rC   r.   r/   rB   r   r   Zevcr   r   r  Zevc2r&   r&   r'   rF     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,   r4   r   r&   r&   r'   r     s   zTestEigh.test_typesc                 C   r  r  )r#   r   rN  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   r7   r   r  r   )rC   r  r  r  r   r   r   r&   r&   r'   r    s   
zTestEigh.test_UPLOc                 C   s   G dd dt j}t jdt jd|}t|\}}t|jj	t j
u  t|jj	t j
u  t|j|j td|j tt|t j t jdt jd|}t|\}}t|jj	t ju  t|jj	t ju  t|j|j td|j tt|t j d S )Nc                   @   r   )z+TestEigh.test_0_size.<locals>.ArraySubclassNr   r&   r&   r&   r'   r     r   r   r   r3   r   r\   r]   )r#   r$   r   r   r   r   r  r   r,   r!   r   r   rm   r"   r   rN  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   rS  )r   r   r&   r&   r'   check_dtype  s   z_TestNormBase.check_dtype)rK   rL   rM   rd  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 )NrK  r3   )r   r   r   rd  r   rI   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AllFloatrK  divide by zero encounteredrs   r   r`   r_   rV   r   rb   g      ?rU   )r#   r   	typecodesrC  r   r   r  r   r   filterRuntimeWarningr,   r!   	rC   r.   Zexact_typesZinexact_typesZ	all_typesZ	each_typeatZanr^  r&   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)r_   r`   ra   rb   )rs   rt   ru   rr   )rs   r`   ru   rb   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+   rX   rU   r_         $@rs   gQ?r`   rt   gsc?r   rb   )r#   testingr   r   r  r   )r   rI   r&   r'   _test  s0   
z+_TestNormGeneral.test_vector.<locals>._testr3   )r   rd  )rC   r.   r/   r   r  r   r&   rI   r'   test_vector  s   

z_TestNormGeneral.test_vectorc           	   	      s  t g dg dg| jd d dddddtjtj fD ]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 )Nr_   r`   ra   rb   rg   r)   r3   rs   r   r_   r`   ra   c                    s$   g | ]}t  d d |f dqS Nordr   rw   kr   orderr&   r'   rx   3     $ z._TestNormGeneral.test_axis.<locals>.<listcomp>r  r?  c                    s$   g | ]}t  |d d f dqS r  r  r  r  r&   r'   rx   5  r     rb   rt   r  c                    s*   g | ]}t  d d  j|ddqS Nr>  r  )r   taker  Bk_indexr  r&   r'   rx   K  s    "c                    s,   g | ]}t  d d  j|djdqS r  )r   r  rZ  r  r  r&   r'   rx   N  s    $)r   rd  r#   Infr   rm   r   r   r   rl   r   r   combinationsr   r   )	rC   Z	expected0Z	expected1ndr?  Zrow_axisZcol_axisrU  r   r&   )r   r  r  r  r'   	test_axis-  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 )Nr_   r  r3   r`   ra   rb   zorder {0}, axis = {1}z;Shape mismatch found {0}, expected {1}, order={2}, axis={3}r  T)r  r?  Zkeepdims)r  )r_   r_   r_   rs   r   rt   r  nuc)r#   r   rd  rl   r   r   Zsqueezeformatr   rm   r  r   r   r   r   r   permutations)	rC   r   Zallclose_errZ	shape_errr   foundZexpected_shaper  r  r&   r&   r'   test_keepdimsR  sT   




 


z_TestNormGeneral.test_keepdimsN)rK   rL   rM   r  r  r  r  r  r&   r&   r&   r'   r    s    )%r  c                   @   s:   e Zd ZejZdd Zdd Zdd Zdd Zd	d
 Z	dS )_TestNorm2Dc                 C   s    t t| jg g| jdd d S )Nr3   rK  )r   r   r   rd  rI   r&   r&   r'   test_matrix_empty  s    z_TestNorm2D.test_matrix_emptyc           	   	   C   s  |  g dg dg}tjd }d}|| }|D ]}||}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fdFDrV   r  rs   rU   r_   r`   gLXz?rt   r  r  gU&,t=@r)   r  )r   r#   r  rC  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 )Nr_   ra   rg   rh   r3   gT"@r  r  r  g      (@rX   rs   rY   r`   gW?"@rt   gїʄ?Znofroru   r   )r   rd  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   rg   )ra   r`   r_   r3   grj=Q0?r  r  gB+pc?g?g333333?r_   rU   rs   g?r`   g&.d?rt   gܸՠ?)r   rd  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jt|d d ttjt|d d ttt|d d d S )Nr  r  r3   r_   r  r`   ra   rb   r  r   r  testr   ra   r   )r_   r`   r`   ra   )r   r_   r`   )	r   rd  r#   r   rl   r   r   r   Z	AxisError)rC   r   r  r  r&   r&   r'   test_bad_args  s   z_TestNorm2D.test_bad_argsN)
rK   rL   rM   r#   r   r  r  r  r  r  r&   r&   r&   r'   r  }  s    3r  c                   @   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
   r3   ra   r  gL)@r`   r  )r#   r   Z
longdoubler-   r   r  r&   r&   r'   test_longdouble_norm  s   z+TestNorm_NonSystematic.test_longdouble_normc                 C   s,   t jdgt jd}tt|ddddd d S )Ni   r3   ra   r  l        rg   r  )r#   r   Zint32r-   r   r  r&   r&   r'   test_intmin  s   z"TestNorm_NonSystematic.test_intminc                 C   s   t jdt jd}d|d< d|d< d}tt jj|dd	|d
d |t j}tt jj|dd	|dd |t j}tt jj|dd	|dd d S )Nr`   r3   y      @      @r   y            @r_   gV;'@ra   r  r  r  	   rg   )	r#   r   Zclongdoubler-   r   r   rC  
complex128r   )rC   rF  r   r&   r&   r'   test_complex_high_ord  s   z,TestNorm_NonSystematic.test_complex_high_ordN)rK   rL   rM   r  r  r  r&   r&   r&   r'   r    s    r  c                   @      e Zd ZejZdZdS )_TestNormDoubleBaser*   N)rK   rL   rM   r#   r   rd  r  r&   r&   r&   r'   r        r  c                   @   r  )_TestNormSingleBaser)   N)rK   rL   rM   r#   rN  rd  r  r&   r&   r&   r'   r    r  r  c                   @   r  )_TestNormInt64Baser*   N)rK   rL   rM   r#   Zint64rd  r  r&   r&   r&   r'   r    r  r  c                   @   r   )TestNormDoubleNr   r&   r&   r&   r'   r  $  r   r  c                   @   r   )TestNormSingleNr   r&   r&   r&   r'   r  (  r   r  c                   @   r   )TestNormInt64Nr   r&   r&   r&   r'   r  ,  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 d S )Nrb   rK  rs   rs   ra   r	  r   )r_   r   r   r   r_   )rb   )ra   rb   r   )r   r   r#   r
  r   r   )rC   Imsr&   r&   r'   test_matrix_rank2  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 )Nrb   Tr  r_   r	  r   rK  r  ra   g:0yE>g|"BE>)r;   Ztolg;䡈E>)r   r   r#   r
  r%  r   )rC   r  r&   r&   r'   test_symmetric_rankF  s   
z"TestMatrixRank.test_symmetric_rankN)rK   rL   rM   r  r  r&   r&   r&   r'   r  0  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rh  )(   r  sizer_   r`   r   r  rb   rg   ra   r^   )r#   r0  ZRandomStater   normalr   r   )rngiXr&   r&   r'   test_reduced_rankT  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,   rm   r  r   qrQRr   r"   r   r   rZ  r  r#   r
  triu)rC   r.   a_typea_dtyperI  rU  r  r   r  r  q1r1r2r&   r&   r'   check_qre  s:   

zTestQR.check_qrrI  rU  )ra   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   rm   )rC   rI  rU  r  r.   htaur&   r&   r'   test_qr_empty  s   

zTestQR.test_qr_emptyc                 C   s   | j ddgddgddggtjd}tj|dd	\}}t|jtjk t|jtjk t|jd
k t|jdk tj|jdd	\}}t|jtjk t|jtjk t|jdk t|jdk d S )Nr_   r`   ra   rb   rg   r)   r3   r  r  r  r  ri   )	r   r#   r   r   r  r   r,   rm   rZ  )rC   r.   r  r  r&   r&   r'   test_mode_raw  s   "zTestQR.test_mode_rawc                 C   s   |  ddgddgg}|  ddgddgddgg}dD ]}||}||}| | | | | |j qdD ]$}dd||  }dd||  }| | | | | |j q:d S )	Nr_   r`   ra   rb   rg   r)   fd              ?)r   rC  r
  rZ  )rC   r.   r/   rd  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 )	Nrt   r  r  rs   r`   .r   r   )r!   r,   rm   r  r   r  r   r"   r   r	   r#   r   r  r
   r  r  )rC   r.   r  r  rI  rU  r  qr   ZI_matZstack_I_matr  r  r	  r&   r&   r'   check_qr_stacked  sL   
""zTestQR.check_qr_stackedr  ))ra   rb   )rb   ra   r	  r  r  
outer_size)r"  r  )r`   ra   rb   rd  c                 C   sP   t jj|| d|}t jj|| d|}| | | |d|   d S )Nr  r  )r#   r0  r  rC  r  )rC   r  r  rd  r   r  r&   r&   r'   test_stacked_inputs  s   

zTestQR.test_stacked_inputsN)rK   rL   rM   r#   r   r
  r   r   r   r  r  r  r  r   r   r   r   r  r&   r&   r&   r'   r  a  s    (
-r  c                   @   sL   e Zd Zejdg dejdejejej	ej
fdd Zdd ZdS )	TestCholeskyrm   )r~   r"  ra   ra   )2   r  )ra   r  r  r,   c                 C   s  t jd t jj| }t |t jr|dt jj|   }ttt|}d|dd < t 	|
| |}t j||d}t j|}t 	||
| }t   d|jd  t |j }W d    n1 sjw   Y  t|||| d| d	| d	| d
 d S )Nr_   r  )rs   rt   rt   r3   i  r    
)atolr  )r#   r0  r1  randnrR  Zcomplexfloatingr   r   r]  r	   r  r  r   r   choleskyZ_no_nep50_warningrm   ZfinfoZepsr   )rC   rm   r,   r.   tr   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      r   r   r   r3   )r_   r   r   )r#   r$   r   r   r   r   r!  r   rm   r   r,   r!   r   r"   r   r   r&   r&   r'   r     s   

zTestCholesky.test_0_sizeN)rK   rL   rM   r   r   r   r#   rN  r   r   r  r#  r   r&   r&   r&   r'   r    s    r  c                  C   s   t jdkrd} nd} tjtjfD ]9}tjd|d}|| }|d }t|j	jd t
jt
jt
jfD ]}||}t||| t||| q4qd S )Nlittle<rH   rb   r3   r  =)sys	byteorderr#   rN  r   r
  Znewbyteorderbyteswapr   r,   r   r   r@  r8  r   )nativeZdttrT  Zn_arrZsw_arrZroutiner   r&   r&   r'   test_byteorder_check0  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 )Nr_   r`   ra   rb   )rb   rb   r`   r`   .r\   )r#   r   r   r   r   r   r   )Z
invertibleZnon_invertibler   r&   r&   r'    test_generalized_raise_multiloopE  s   r,  c                  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   r_   r\   rU   zDORGQR parameter number 5zNumpy xerbla not linked in.)osforkOSErrorAttributeErrorr   skipcloseresourceZ	setrlimitZRLIMIT_COREr#   r   lapack_liteZxerblar   r   _exit	EX_CONFIGr   Zdorgqrr?   waitWEXITSTATUS)Z	XERBLA_OKpidr4  r.   r   statusr&   r&   r'   test_xerbla_overrideT  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.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)r?  r>  r@  )textwrapdedentr  
subprocess
check_callr'  
executable)Zbad_libstemplater@  coder&   r&   r'   test_sdot_bug_8577  s   
rH  c                   @   sd   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )TestMultiDotc              	   C   sl   t jd}t jd}t jd}tt|||g||| tt|||gt |t || d S Nr)   r`   r`   r)   r#   r0  r   r   r   )rC   r   r  Cr&   r&   r'   (test_basic_function_with_three_arguments  s
    (z5TestMultiDot.test_basic_function_with_three_argumentsc                 C   sN   t jd}t jd}tt||g|| tt||gt || d S rJ  rM  )rC   r   r  r&   r&   r'   &test_basic_function_with_two_arguments  s   z3TestMultiDot.test_basic_function_with_two_argumentsc                 C   s\   t jd}t jd}t jd}t jd}tt||||g|||| d S )NrK  rL  r`   r_   rM  )rC   r   r  rN  Dr&   r&   r'   9test_basic_function_with_dynamic_programming_optimization  s
   ,zFTestMultiDot.test_basic_function_with_dynamic_programming_optimizationc                 C   sL   t jd}t jd}t jd}t jd}tt||||gjd d S )Nr`   rL  rK  r"  r  r#   r0  r   r   rm   )rC   A1dr  rN  rR  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 )NrK  rL  r`   )r)   rT  )rC   r   r  rN  D1dr&   r&   r'   test_vector_as_last_argument  rW  z)TestMultiDot.test_vector_as_last_argumentc                 C   sL   t jd}t jd}t jd}t jd}tt||||gjd d S )Nr`   rL  rK  r&   rT  )rC   rU  r  rN  rX  r&   r&   r'   &test_vector_as_first_and_last_argument  rW  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 )NrK  rL  r%   r#   r0  r   r   r   r   )rC   r   r  rN  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 )NrK  rL  )r)   r)   r[  r\  )rC   r   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 )NrK  rL  rQ  )r)   r_   r[  r\  )rC   r   r  rN  rR  r%   r]  r&   r&   r'   -test_dynamic_programming_optimization_and_out  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)   #   )rb     )rc  rg   )rg   r  )r     )rd  r  )rK  g     @g     þ@g    O@g    1@g    @)rK  rK  g     @g     @g     ջ@g     @)rK  rK  rK  g     p@g     @g     @)rK  rK  rK  rK  g     @@g     X@)rK  rK  rK  rK  rK  g     @)rK  rK  rK  rK  rK  rK  )r   r_   r_   ra   ra   ra   )r   r   r`   ra   ra   ra   )r   r   r   ra   ra   ra   )r   r   r   r   rb   rg   )r   r   r   r   r   rg   )r   r   r   r   r   r   r3   r_   T)Zreturn_costsrs   )r#   r0  r   intr   r   r  )rC   ZarraysZ
m_expectedZ
s_expectedr   rI  r&   r&   r'   test_dynamic_programming_logic  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#   r0  rI   r&   r&   r'   test_too_few_input_arrays%  s   z&TestMultiDot.test_too_few_input_arraysN)rK   rL   rM   rO  rP  rS  rV  rY  rZ  r^  r_  r`  rf  rg  r&   r&   r&   r'   rI    s    
	



rI  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rb   r)   r^   r`   r`   ra   ra   r`   r_   c                 C   s<   t t tj||d W d    d S 1 sw   Y  d S )Nind)r   r   r   	tensorinv)rC   rT  rl  r&   r&   r'   test_non_square_handling,  s   
"z&TestTensorinv.test_non_square_handlingz
shape, ind)rb   r)   r^   ra   r`   )   r^   ra   r_   c                 C   sN   t d}||_tj||d}|j|d  |jd |  }|j}t|| d S )Nrq  r.   rl  )r#   r
  rm   r   rm  r   )rC   rm   rl  r.   ainvr   actualr&   r&   r'   test_tensorinv_shape4  s   
z"TestTensorinv.test_tensorinv_shaperl  r   rt   c                 C   sL   t d}d|_tt tj||d W d    d S 1 sw   Y  d S )Nrq  ro  rr  )r#   r
  rm   r   r   r   rm  )rC   rl  r.   r&   r&   r'   test_tensorinv_ind_limitA  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 )Nrq  rp  r_   rk  )	r#   r
  rm   r   rm  r%  r   	tensordottensorsolve)rC   r.   rs  r/   r&   r&   r'   test_tensorinv_resultJ  s
   

"z#TestTensorinv.test_tensorinv_resultN)rK   rL   rM   r   r   r   r#   r%  rn  ru  rv  ry  r&   r&   r&   r'   rh  *  s     


rh  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, axesri  Nrj  )r   r`   c                 C   sR   t t t|jd d }tj|||d W d    d S 1 s"w   Y  d S Nr`   r  )r   r   r#   r%  rm   r   rx  )rC   r.   r  r/   r&   r&   r'   rn  U  s   
"z(TestTensorsolve.test_non_square_handlingrm   ))r`   ra   r)   )ra   rb   rb   ra   )r   ra   ra   r   c                 C   sN   t jj| }t |jd d }t j||}tt j||t	|jd| d S r{  )
r#   r0  r   r%  rm   r   rx  r   rw  r]  )rC   rm   r.   r/   r   r&   r&   r'   test_tensorsolve_result^  s    z'TestTensorsolve.test_tensorsolve_result)
rK   rL   rM   r   r   r   r#   r%  rn  r|  r&   r&   r&   r'   rz  S  s    
rz  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 )Nr_   rt   r`   rg   Zfloat16r3   zunsupported in linalg)r#   r   r   r  r   r!  )rT  r&   r&   r'   test_unsupported_commontypeh  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        r_   r3   )r   rs   )r#   r   rN  r%  r   r   )rU  r.   r/   r   r&   r&   r'   test_blas64_dots  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       r_   r3   rs   r   inforI  rU  r~  l        )
r#   r   r   r5  Zdgeqrfr   r   re  itemr   )
r,   Zlapack_routinerI  rU  Zldar.   Zworkr  resultsZlworkr&   r&   r'   !test_blas64_geqrf_lwork_smoketest}  s   
&r  )r)   r*   )__doc__r.  r'  r   r   rA  rC  r   numpyr#   r   r   r   r   r   r   r   r	   Z
numpy.corer
   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-   r4   r6   r7   rO   r>   rS   r0  r1  rj   r   r2  rp   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r6  r:  r;  r<  r=  rJ  rO  rY  r   r   re  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r+  r  r,  r<  r   rH  rI  rh  rz  r}  r2  r  r5  r  r&   r&   r&   r'   <module>   s   (0
	

#




9 
0

:	$.C
*4V6; x$ ".
1" )

	