o
    tBh(.                    @   sN
  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* d
d Z+e&Z,dddZ&dd Z-dd Z.dd Z/h dZ0G dd dZ1dd Z2e	j34d g Z5e5e2de1de
ddgd d!gged"e
ddged"e1d#e
ddgd d!gged"e
ddged"e1d$e
ddgd d!gged"e
g d%g d&ged"e1d'e
d(d)gd*d+gged"e
d,d(ged"e1d-e
d(d)gd*d+gged"e
d,d(ged"e1d.e
d(d)gd*d+gged"e
g d/g d0ged"e1d1e	j6d2ed"e	j6d3ed"d4hd5e1d6e	j37d7d7e	j37d7e1d8e	j37d9d9e	j37d9e1d:d9d;gd<d=ggd;d9gg
7 Z5e5e2d>e1d?e
g d@g d&ged"e
ddged"e1dAe
ddgd d!gdBdCgged"e
g dDed"e1dEe
g d@g d&ged"e
ddged"e1dFe
ddgd d!gdBdCgged"e
g dDed"e1dGe
g dHg dIged"e
d,d(ged"e1dJe
dKdLgdMdNgdOdPgged"e
g dQed"e1dRe
g dHg dIged"e
d,d(ged"e1dSe
dKdLgdMdNgdOdPgged"e
g dQed"e1dTe
g dHg dIged"e
d,d(gdUdVgged"e1dWe
dKdLgdMdNgdOdPgged"e
d,d(gdUdVgdUdVgged"e1dXe	j37d7dYe	j37d7e1dZe	j37d9d[e	j37d9e1d\e	j37d[d9e	j37d[e1d]e	j37dd=e	j37dd4hd5e1d^e	j37d=de	j37d=d4hd5g7 Z5e5e2d_e1d`e
ddgddgged"de1dae
ddgddgged"de1dbe
dd)gdcd9gged"de1dde
dd)gdcd9gged"de1dee	j6d2ed"dd4hd5e1dfd9d;gd;d9ggde1dge
ddgddggde1dhe	j37d9d9dg7 Z5didj Z8e5e8 7 Z5dkdl Z9dmdn Z:e5e: 7 Z5G dodp dpZ;G dqdr dre;Z<G dsdt dte;Z=G dudv dve;Z>G dwdx dxe;Z?G dydz dze;Z@G d{d| d|e;ZAd}d~ ZBdd ZCG dd de<e?ZDG dd deDZEG dd de<e?ZFG dd deFZGG dd de<e?ZHG dd deHZIG dd de<e?ZJG dd deJZKG dd dZLG dd de<e?ZMG dd deMeLZNG dd de>eAZOG dd deOeLZPG dd de<e?ZQG dd deQZRG dd de<e=e?e@ZSG dd deSZTG dd de>eAZUG dd deUZVG dd de<e?ZWG dd deWZXG dd de<e=ZYG dd deYZZej[\ddd dD G dd dZ]G dd de>eAZ^G dd dZ_G dd de>eAZ`G dd dZaG dd dZbG dd debZcG dd debZdG ddĄ dedecZeG ddƄ dƃZfG ddȄ debZgG ddʄ debZhG dd̄ debZiG dd΄ deeegZjG ddЄ deeehZkG dd҄ deeeiZlG ddԄ dԃZmddք ZnG dd؄ d؃ZoG ddڄ dڃZpdd܄ Zqddބ Zrdd Zsej[jtdd ZuG dd dZvG dd dZwG dd dZxdd Zyej[jzdddd Z{ej[j|e* dddd Z}d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_LAPACK64c                 C   s$   t | t|tjrt |u S tju S N)type
isinstancenpndarray)outin_ r&   u/var/www/html/riverr-enterprise-integrations-main/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_dtype,   
   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_dtype1   r5   r6   c                 C   s   | t tfv rdS dS )Ngh㈵>gdy=)r   r   r3   r&   r&   r'   get_rtol6   s   r7   >   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namer.   r/   	frozensettags)selfr@   r.   r/   rB   r&   r&   r'   __init__F   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'   checkQ   s   zLinalgCase.checkc                 C   s   d| j  dS )Nz<LinalgCase: >)r@   rC   r&   r&   r'   __repr__W   s   zLinalgCase.__repr__N)__name__
__module____qualname__setrD   rG   rJ   r&   r&   r&   r'   r>   E   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_tag[   s   rS     r8   r         ?       @      @      @r3   r   double_2)rV   rU   rX   )rW   rX         @r         ?       @y       @      @y      @      @y      @      @       @      ?r   	cdouble_2)r\   r[   y      ?      @)y      ?       y      ?      y      ?      0x0r   r   r   r=   rE   8x8   1x1   nonarray         r;   single_nsq_1)rU   rV   rW   single_nsq_2g      @rZ   )rV   rU   rW   double_nsq_1double_nsq_2csingle_nsq_1)      ?      ?       @       @      @      )y      @      y      @      "@y      @       @csingle_nsq_2rn   ro   rp   y      @      "y      @      y      @       @)r\   r[   rp   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   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 )
Nrf   rg      r)   _tile3r<   rE   rg   rf   _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*   


$
$
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rd   )rd   rg   rd   rf   )rd   r   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)r   repeatr&   r&   r'   r     s    r3   l   >[= .stride__c                 S   s   g | ]}d | qS )z%+dr&   )r   jr&   r&   r'   r   (  s    r   )stridesstride_xxx_0stride_xxx_0_xrd   rd   stride_xxx_0_0)r!   r"   r#   ndim	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   r9   rE   )r   r   r.   r/   r>   r@   rB   r   )r   rR   r.   a_labelr/   b_labelr   r&   r&   r'   _make_strided_cases=  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_casesQ  s   


zLinalgTestCase.check_casesN)rK   rL   rM   r   r   rN   r   r&   r&   r&   r'   r   N  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<   r=   r   r   r   rI   r&   r&   r'   test_sq_casesg     
z"LinalgSquareTestCase.test_sq_casesc                 C      | j ddhdhd d S )Nr8   r=   r<   r   r   rI   r&   r&   r'   test_empty_sq_casesk     

z(LinalgSquareTestCase.test_empty_sq_casesN)rK   rL   rM   r   r   r&   r&   r&   r'   r   e      r   c                   @   r   )LinalgNonsquareTestCasec                 C   r   )Nr;   r<   r=   r   r   rI   r&   r&   r'   test_nonsq_casesr  r   z(LinalgNonsquareTestCase.test_nonsq_casesc                 C   r   )Nr;   r=   r<   r   r   rI   r&   r&   r'   test_empty_nonsq_casesv  r   z.LinalgNonsquareTestCase.test_empty_nonsq_casesN)rK   rL   rM   r   r   r&   r&   r&   r'   r   p  r   r   c                   @   r   )HermitianTestCasec                 C   r   )Nr:   r<   r=   r   r   rI   r&   r&   r'   test_herm_cases}  r   z!HermitianTestCase.test_herm_casesc                 C   r   )Nr:   r=   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   r=   r   r   rI   r&   r&   r'   test_generalized_sq_cases     

z9LinalgGeneralizedSquareTestCase.test_generalized_sq_casesc                 C      | j h dd d S )N>   r8   r<   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;   r=   r   r   rI   r&   r&   r'   test_generalized_nonsq_cases  r   z?LinalgGeneralizedNonsquareTestCase.test_generalized_nonsq_casesc                 C   r   )N>   r;   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:   r=   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>   r:   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 )Nrg   r   rd   zNot implemented...r3   r   )r   r   r   
ValueErrorr"   r   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 )Nrg   r3   r   .r   )r   r   r"   r   r   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 Nrd         ?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  rb   rf   r)   rd   rg   r   )r"   r#   aranger   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  rh   rd   rf   r)   rg   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)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   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   rd   rd   r3   r_   )r"   r#   zerosint_r   r   r  r   r,   r    float64r   r   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   ,  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 Nrd   r   r3   r   )r"   r   r   r   r  r,   r6   r   r&   r&   r'   r   3  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  <  r  r  r  r3   r   rd   r_   r`   )r"   r#   r  r  r   r   r  r   r,   r    r  r   r   r!   r  r  r&   r&   r'   r  :     

zTestEigvals.test_0_sizeNr  r&   r&   r&   r'   r  2  s    
r  c                   @   r   )EigCasesc                 C   sX   t |\}}tt||t|t|dd d d f  t|jd tt	|| d S )N.rtol)
r   r  r   r   r"   r   r7   r,   r   r(   )rC   r.   r/   rB   r  r  r&   r&   r'   rF   O  s   
 zEigCases.doNr   r&   r&   r&   r'   r!  M  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   X  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  f  r  r  r  r3   r  r_   r`   )r"   r#   r  r  r   r   r  r   r,   r    r  r   r   r!   r  rC   r  r.   r  res_vr&   r&   r'   r  d     zTestEig.test_0_sizeNr  r&   r&   r&   r'   r$  W  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   sx   t jddgddgg|d}t|\}}}t|j| t|jt| t|j| tj|d| jd}t|jt| d S )Nrd   r   r3   F
compute_uvr:   )r"   r   r   svdr   r,   r4   r:   )rC   r,   r   ur   vhr&   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   r/  r   vtr&   r&   r'   rF     s   &zSVDCases.doNr   r&   r&   r&   r'   r1    r   r1  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 )rh   r   Tr,  rh   rh   r_   rh   )r   rh   N)r"   r   r   r.  r:   r   r   eye)rC   r   r/  r   r0  r&   r&   r'   test_empty_identity  s   

zTestSVD.test_empty_identityN)rK   rL   rM   r6  r&   r&   r&   r'   r3    s    r3  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   r   r   r"   conj	transpose)matr:  r&   r&   r'   r:     s   z'SVDHermitianCases.do.<locals>.hermitianr   )r   r.  r   r   r"   r   r7   r,   r   r	   broadcast_tor5  r   r   sortr   r(   )rC   r.   r/   rB   r/  r   r2  r:   r&   r&   r'   rF     s   &,,zSVDHermitianCases.doNr   r&   r&   r&   r'   r7    r   r7  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 )Nr=   F)r-  ).r   ).r   ry   rw   r0   r1   rf   r   rd   r   fro)r   r   r   r   condr.  r   r"   r  r   summaxminr   sqrt)rC   r.   r/   rB   r   r   cinvr&   r&   r'   rF     sZ   
&
&&&

zCondCases.doNr   r&   r&   r&   r'   rA    s    rA  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   rd   )r   g       r   )r   r   rW   rh   gUUUUUU?rd   r   r   rC  gUUUUU6@)r   r   r   rD  r   r"   rH  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rf   rf   Nrd   rf   rC  r   r     4&kC)r"   r  onesr   r   r   r   rD  )rC   Asp_posp_negrL  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)Nrd   r   rf   r   rC  rO  rN  r  )rg   rf   rf   rd   r   rd   rd   r   rP  rf   )	r"   rQ  nanr   rD  r   r!   float_isnan)rC   psrS  rL  rU  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   rf   r   r_   r   )Nrd   rf   rC  r   r   r  rd   r   )
r"   randomseedrandr   rD  r   r   r   isfinite)rC   rL  rU  r   r&   r&   r'   test_stacked_singular  s   zTestCond.test_stacked_singularN)
rK   rL   rM   rM  rV  r   r   xfailr^  rd  r&   r&   r&   r'   rJ    s    	

rJ  c                   @   r   )	PinvCasesc                 C   s<   t |}t}t||||||ddd tt|| d S )Nry   rw   rB  r   pinvr   r   r   r(   rC   r.   r/   rB   a_ginvr   r&   r&   r'   rF   1  s   
zPinvCases.doNr   r&   r&   r&   r'   rf  ,  s    rf  c                   @   r   )TestPinvNr   r&   r&   r&   r'   rk  9  r  rk  c                   @   r   )PinvHermitianCasesc                 C   s@   t j|dd}t}t||||||ddd tt|| d S )NTr8  ry   rw   rB  rg  ri  r&   r&   r'   rF   ?  s   zPinvHermitianCases.doNr   r&   r&   r&   r'   rl  =  r   rl  c                   @   r   )TestPinvHermitianNr   r&   r&   r&   r'   rm  G  r  rm  c                   @   r   )DetCasesc           
      C   s   t |}t |\}}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   rd   )r   detslogdetr   r,   r    r   r   astyper   r  r   r   reducer"   exp
atleast_1dr   r   r   )
rC   r.   r/   rB   dr   ldadr  mr&   r&   r'   rF   M  s   



zDetCases.doNr   r&   r&   r&   r'   rn  K  r   rn  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   rd   )r   r   rq  r    r   r   rr  r   rI   r&   r&   r'   	test_zero`  s    zTestDet.test_zeror,   c                 C   s^   t jddgddgg|d}tt j|j| t j|\}}t|jt| t|j| d S r   )r"   r   r   r   rq  r,   rr  r4   )rC   r,   r   phr   r&   r&   r'   r   m  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   rd   )r"   r  r  r   rq  r   r   r,   r    rr  float32r  )rC   r.   r  r&   r&   r'   r  u  s    







zTestDet.test_0_sizeN)rK   rL   rM   r}  r   r   r	  r   r   r   r   r   r  r&   r&   r&   r'   r{  _  s
    
r{  c                   @   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   rcondr   rf   ro  rd   r   )r"   r   r   r   r.  lstsqr   r   r   r   r   __array_wrap__r   rE  r   r   r   r    
issubdtyper,   floatingr(   )rC   r.   r/   rB   arrrz  nr/  r   r2  r   	residualsranksvexpect_residsr&   r&   r'   rF     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 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)r|  rU   r|  rU   rV   r|  )r|  rV   r|  r|  rU   r|  )rU   r|  rU   r|  r|  rX   )r|  r|  r|  rV   rW   r|  )rd   r   r   r   r   r   z`rcond` parameter will changerh   r   r  rg   rd   )
r"   r   Tr   recordFutureWarningr   r  r   len)	rC   r.   r/   supr&  r   r  r  r   r&   r&   r'   test_future_rcond  s$   
"zTestLstsq.test_future_rcond)rz  r  n_rhs))rh   rf   rf   )r   rh   rd   )r   rh   rf   )rh   r   rd   )rh   r   rf   )rh   rf   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 )Nr  r   r`   r   ro  )r"   r  r   rQ  r   r  r   r   r   r   r   r   rE  rG  )rC   rz  r  r  r.   r/   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   rd   rf   rg   )r   g?g?g @gffffff
@zIncompatible dimensionsr  )
r"   r   vstackrQ  r  r  r   r   r   r  )rC   r   yrL  r&   r&   r'   test_incompatible_dims  s   "z TestLstsq.test_incompatible_dimsN)	rK   rL   rM   r  r   r   r	  r  r  r&   r&   r&   r'   r    s
    
	r  dtc                 C   s   g | ]}t |qS r&   )r"   r,   )r   r   r&   r&   r'   r     s    r   z?bBhHiIqQefdgFDGOc                   @   s   e Zd ZedZeg d Zeg d Zeg d ZeeeegZ	e
ddgddggZeegggd Zeeded	ed
gZdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )TestMatrixPowerrh   )rg   r   rd   rf   )rf   rg   r   rd   )rd   rf   rg   r   rd   r   rf   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 )Nrf   d   i       r   rd   rg   )rshft_1rs  r   r   rshft_0rshft_2rshft_3)rC   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_allrs  objectstackedrC   r  r  r=  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 )Nrd   )r   r   r,   )r=  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 )Nrf   )r   r,   r  r	   r   r   )r=  r  mmulr&   r&   r'   r  
  s   
z-TestMatrixPower.test_power_is_two.<locals>.tzr  r  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 Nr   )r   r,   r  r	   r   r   r   )r=  invmatr  r&   r&   r'   r    s
   
z3TestMatrixPower.test_power_is_minus_one.<locals>.tz)r  dtnoinvrs  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      ?rd   )r  rs  r   	TypeErrorr   rC   r  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 )Nrd   rf   )rh   rg   rf   )r   r   r   r"   r   rQ  )rC   r  r&   r&   r'   test_exceptions_non_square%  s   z*TestMatrixPower.test_exceptions_non_squarec                 C   s,   || j v rd S | j|}ttt|d d S r  )r  noninvrs  r   r   r   r  r&   r&   r'   test_exceptions_not_invertible*  s   
z.TestMatrixPower.test_exceptions_not_invertibleN)rK   rL   rM   r"   r5  r  r  r  r  r  r   r  blockr  r  r,   r  r  r  r  r  r  r  r  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   ro  r"  U)r   eigvalshr  r?  r   r7   r,   )rC   r.   r/   rB   r  r  r  ev2r&   r&   r'   rF   3  s   zTestEigvalshCases.doNr   r&   r&   r&   r'   r  1  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   @  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 Nrd   r   r3   lrongUPLOlowerupper)r"   r   r  r   r   r   r  rC   r   r&   r&   r'   test_invalidF     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   rd   r3   r   r"  r  r  lr  r/  )r"   r   r   r7   r   r  r   )rC   KloKuptgtr#  r&  r&   r&   r'   	test_UPLOL  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  d  r  r  r  r3   r  r_   r`   )r"   r#   r  r  r   r   r  r   r,   r    r  r   r   r!   r  r  r  r&   r&   r'   r  b  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  ?  s    
r  c                   @   r   )TestEighCasesc           
      C   s   t |\}}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   ro  .r"  r  )r#  err_msg)r   eighr  r?  r   r   r   r"   r   r7   r,   repr)
rC   r.   r/   rB   r  evcr  r  r  evc2r&   r&   r'   rF   w  s   

 

 
zTestEighCases.doNr   r&   r&   r&   r'   r  u  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   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   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   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)rK   rL   rM   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|  r3   )r   r   r   r  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 )NrY  
AllIntegerAllFloatr|  divide by zero encounteredr   r   rf   rd   rV   r   rh   g      ?rU   )r"   r   	typecodesrs  r   r   r  r   r   filterRuntimeWarningr,   r    	rC   r.   exact_typesinexact_types	all_types	each_typeat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)rd   rf   rg   rh   )r   r   r   r   )r   rf   r   rh   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   rd         $@r   gQ?rf   r   gsc?r   rh   )r"   testingr   r   r  r   )r'  rI   r&   r'   _test  s0   
z+_TestNormGeneral.test_vector.<locals>._testr3   )r   r  )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rd   rf   rg   rh   ry   r)   r3   r   r   rd   rf   rg   c                    s$   g | ]}t  d d |f dqS Nordr   r   krL  orderr&   r'   r   '     $ z._TestNormGeneral.test_axis.<locals>.<listcomp>r  rp  c                    s$   g | ]}t  |d d f dqS r  r  r  r  r&   r'   r   )  r     rh   r   rC  c                    s*   g | ]}t  d d  j|ddqS Nro  r  )r   taker  Bk_indexr  r&   r'   r   ?  s    "c                    s,   g | ]}t  d d  j|djdqS r  )r   r  r  r  r  r&   r'   r   B  s    $)r   r  r"   Infr   r   r   r   r  r   r   r   combinationsr   r   )	rC   	expected0	expected1ndrp  row_axiscol_axisr  r  r&   )rL  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 )Nrd   r  r3   rf   rg   rh   zorder {0}, axis = {1}z;Shape mismatch found {0}, expected {1}, order={2}, axis={3}r  T)r  rp  keepdims)r  )rd   rd   rd   r   r   r   rC  nuc)r"   r  r  r   r   r   squeezeformatr   r   r  r   r   r   r   r   permutations)	rC   rL  allclose_err	shape_errr  foundexpected_shaper  r   r&   r&   r'   test_keepdimsF  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   r|  )r   r   r   r  rI   r&   r&   r'   test_matrix_emptyv  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 )NrY  r  r  fdFDrV   r  r   rU   rd   rf   gLXz?r   rC  r  gU&,t=@r)   r  )r   r"   r  rs  r   r   r  r   r   r  r  r  r  r&   r&   r'   test_matrix_return_typey  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 )Nrd   rg   ry   r   r3   gT"@rC  r  r  g      (@rX   r   rZ   rf   gW?"@r   gїʄ?nofror   r   )r   r  r   r   r   r   r   rK  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   ry   )rg   rf   rd   r3   grj=Q0?rC  r  gB+pc?g?g333333?rd   rU   r   g?rf   g&.d?r   gܸՠ?)r   r  r   r   r   rK  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   rd   r  rf   rg   rh   rC  r   r  testr   rg   r  )rd   rf   rf   rg   )r   rd   rf   )	r   r  r"   r  r   r   r   r   	AxisError)rC   rL  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  q  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   rg   r  gL)@rf   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   r3   rg   r  l        ry   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rf   r3   y      @      @r   y            @rd   gV;'@rg   r  r+  r  	   ry   )	r"   r   clongdoubler-   r   r   rs  
complex128r  )rC   rw  r  r&   r&   r'   test_complex_high_ord  s   z,TestNorm_NonSystematic.test_complex_high_ordN)rK   rL   rM   r-  r/  r4  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   r  r  r&   r&   r&   r'   r6  	      r6  c                   @   r5  )_TestNormSingleBaser)   N)rK   rL   rM   r"   r  r  r  r&   r&   r&   r'   r8    r7  r8  c                   @   r5  )_TestNormInt64Baser*   N)rK   rL   rM   r"   int64r  r  r&   r&   r&   r'   r9    r7  r9  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 )Nrh   r|  r   r   rg   r4  r   )rd   r   r   r   rd   )rh   )rg   rh   r   )r   r   r"   r5  r  r   )rC   Imsr&   r&   r'   test_matrix_rank&  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 )Nrh   Tr8  rd   r4  r   r|  r?  rg   g:0yE>g|"BE>)r:   tolg;䡈E>)r   r   r"   r5  rQ  r  )rC   r@  r&   r&   r'   test_symmetric_rank:  s   
z"TestMatrixRank.test_symmetric_rankN)rK   rL   rM   rB  rD  r&   r&   r&   r'   r>  $  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r  )(   r+  sizerd   rf   r   r1  rh   ry   rg   rb   )r"   r`  RandomStater   normalr   r   )rngiXr&   r&   r'   test_reduced_rankH  s   ,,rM  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\}}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   rG  r   qrr   r!   r   r   r  r;  r"   r5  triu)rC   r.   a_typea_dtyperz  r  r   qr   q1r1r2r&   r&   r'   check_qrY  s8   

zTestQR.check_qrrz  r  )rg   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rawrP  )
rG  r"   r   r[  r   rS  r   r,   r   r   )rC   rz  r  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 )Nrd   rf   rg   rh   ry   r)   r3   r]  rP  r&  r0  r   )	r   r"   r   r   rS  r   r,   r   r  )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 )	Nrd   rf   rg   rh   ry   r)   fd              ?)r   rs  r[  r  )rC   r.   r/   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   rO  rP  r   rf   .rR  r   )r    r,   r   rG  r   rS  r   r!   r   r	   r"   r   r>  r
   r;  rT  )rC   r.   rU  rV  rz  r  r   rW  r   I_matstack_I_matrX  rY  rZ  r&   r&   r'   check_qr_stacked  sL   
""zTestQR.check_qr_stackedrG  ))rg   rh   )rh   rg   r4  r\  r%  
outer_size)rN  r0  )rf   rg   rh   r  c                 C   sP   t jj|| d|}t jj|| d|}| | | |d|   d S )NrF  rc  )r"   r`  rI  rs  ri  )rC   rj  rG  r  rL  r	  r&   r&   r'   test_stacked_inputs  s   

zTestQR.test_stacked_inputsN)rK   rL   rM   r"   r   r[  r   r   r	  r`  ra  rf  ri  r   r   r   r   rk  r&   r&   r&   r'   rN  U  s    '
-rN  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 )	TestCholeskyr   )r   rN  rg   rg   )2   rn  )rg   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| d| d| d|jd	  t |j d
 d S )Nrd   rc  )r   r   r   r3    
i  r   )r  atol)r"   r`  ra  randnr  complexfloatingr   r   r  r	   r<  r;  r   r   choleskyr   r   finfoeps)rC   r   r,   r.   tr   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   )rd   r   r   )r"   r#   r  r  r   r   rt  r   r   r   r,   r    r  r!   r  r  r&   r&   r'   r    s   

zTestCholesky.test_0_sizeN)rK   rL   rM   r   r   r	  r"   r  r  r  r3  rx  r  r&   r&   r&   r'   rl    s    rl  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   rh   r3   S=)sys	byteorderr"   r  r  r5  newbyteorderbyteswapr   r,   r   r  rq  rh  r   )nativedttr  n_arrsw_arrroutiner  r&   r&   r'   test_byteorder_check#  s   

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 )Nrd   rf   rg   rh   )rh   rh   rf   rf   .r_   )r"   r   r  r   r   r   r  )
invertiblenon_invertibler   r&   r&   r'    test_generalized_raise_multiloop8  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   rd   r_   rU   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   dorgqrr?   waitWEXITSTATUS)	XERBLA_OKpidr  r.   r   statusr&   r&   r'   test_xerbla_overrideF  sF   


r  c                  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_8577w  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)   rf   rf   r)   r"   r`  r   r   r   )rC   rL  r	  Cr&   r&   r'   (test_basic_function_with_three_arguments  s
    (z5TestMultiDot.test_basic_function_with_three_argumentsc                 C   sN   t jd}t jd}tt||g|| tt||gt || d S r  r  )rC   rL  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  rf   rd   r  )rC   rL  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 )Nrf   r  r  rN  r0  r"   r`  r   r   r   )rC   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  rf   )r)   r  )rC   rL  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 )Nrf   r  r  r&   r  )rC   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"   r`  r  r   r   r   )rC   rL  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  )rC   rL  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)   rd   r  r  )rC   rL  r	  r  r  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)   #   )r     )r  ry   )ry   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   rd   rd   rg   rg   rg   )r   r   rf   rg   rg   rg   )r   r   r   rg   rg   rg   )r   r   r   r   rh   ry   )r   r   r   r   r   ry   )r   r   r   r   r   r   r3   rd   T)return_costsr   )r"   r`  r   intr   r   rT  )rC   arrays
m_expected
s_expectedr   rz  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 )Nrm  )r   r   r   r"   r`  rI   r&   r&   r'   test_too_few_input_arrays  s   z&TestMultiDot.test_too_few_input_arraysN)rK   rL   rM   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rh   r)   rb   rf   rf   rg   rg   rf   rd   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   r  r  r&   r&   r'   test_non_square_handling  s   
"z&TestTensorinv.test_non_square_handlingz
shape, ind)rh   r)   rb   rg   rf   )   rb   rg   rd   c                 C   sN   t d}||_tj||d}|j|d  |jd |  }|j}t|| d S )Nr  r.   r  )r"   r5  r   r   r  r   )rC   r   r  r.   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"   r5  r   r   r   r   r  )rC   r  r.   r&   r&   r'   test_tensorinv_ind_limit2  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  rd   r  )	r"   r5  r   r   r  rQ  r   	tensordottensorsolve)rC   r.   r  r/   r&   r&   r'   test_tensorinv_result;  s
   

"z#TestTensorinv.test_tensorinv_resultN)rK   rL   rM   r   r   r	  r"   rQ  r  r  r  r  r&   r&   r&   r'   r    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   rf   c                 C   sR   t t t|jd d }tj|||d W d    d S 1 s"w   Y  d S Nrf   r9  )r   r   r"   rQ  r   r   r  )rC   r.   r:  r/   r&   r&   r'   r  F  s   
"z(TestTensorsolve.test_non_square_handlingr   ))rf   rg   r)   )rg   rh   rh   rg   )r   rg   rg   r   c                 C   sN   t jj| }t |jd d }t j||}tt j||t	|jd| d S r  )
r"   r`  rr  rQ  r   r   r  r   r  r  )rC   r   r.   r/   r   r&   r&   r'   test_tensorsolve_resultO  s    z'TestTensorsolve.test_tensorsolve_result)
rK   rL   rM   r   r   r	  r"   rQ  r  r  r&   r&   r&   r'   r  D  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 )Nrd   r   rf   ry   float16r3   zunsupported in linalg)r"   r   r   r  r   rt  )r  r&   r&   r'   test_unsupported_commontypeY  s   "r  z,Bad memory reports lead to OOM in ci testing)rX  c                  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        rd   r3   )r   r   )r"   r  r  rQ  r   r   )r  r.   r/   r   r&   r&   r'   test_blas64_dotd  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       rd   r3   r   r   inforz  r  r  l        )
r"   r  r   r  dgeqrfr  r   r  itemr   )
r,   lapack_routinerz  r  ldar.   workr_  resultslworkr&   r&   r'   !test_blas64_geqrf_lwork_smoketestn  s   
&r  )r)   r*   )~__doc__r  r}  r   r   r  r  r   numpyr"   r   r   r   r   r   r   r   r	   
numpy.corer
   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(   r-   r4   r6   r7   rO   r>   rS   r`  ra  r   r   rb  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
  r  r  r  r!  r$  r+  r1  r3  r7  r@  rA  rJ  rf  rk  rl  rm  rn  r{  r  r  r   r	  r  r  r  r  r  r  r  r  r)  r*  r6  r8  r9  r;  r<  r=  r>  rM  rN  rl  r  r  r  r   r  r  r  r  r  r  r  re  r  r&   r&   r&   r'   <module>   s
   (,
	

#




9 
0

:	
$.C
*4U6; x$ !.1
" )

	