HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/numpy/linalg/tests/__pycache__/test_linalg.cpython-310.pyc
o

���g1�@s�
dZddlZddlZddlZddlZddlZddlZddlZddlZ	ddlm
Z
mZmZm
Z
mZmZmZmZddlmZddlmZmZmZmZddlmZddlmZmZmZmZmZddlm Z dd	l!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+zddl,ZWn	e-y�Ynwd
d�Z.e&Z/d�dd�Z&dd�Z0dd�Z1dd�Z2hd�Z3Gdd�d�Z4dd�Z5e	j6�7d�gZ8e8e5de4de
ddgd d!gged"�e
ddged"��e4d#e
ddgd d!gged"�e
ddged"��e4d$e
ddgd d!gged"�e
gd%�gd&�ged"��e4d'e
d(d)gd*d+gge
d"�e
d,d(ge
d"��e4d-e
d(d)gd*d+gged"�e
d,d(ged"��e4d.e
d(d)gd*d+gged"�e
gd/�gd0�ged"��e4d1e	j9d2ed"�e	j9d3ed"�d4hd5�e4d6e	j6�:d7d7�e	j6�:d7��e4d8e	j6�:d9d9�e	j6�:d9��e4d:d9d;gd<d=ggd;d9g�g
�7Z8e8e5d>e4d?e
gd@�gd&�ged"�e
ddged"��e4dAe
ddgd d!gdBdCgged"�e
gdD�ed"��e4dEe
gd@�gd&�ged"�e
ddged"��e4dFe
ddgd d!gdBdCgged"�e
gdD�ed"��e4dGe
gdH�gdI�ge
d"�e
d,d(ge
d"��e4dJe
dKdLgdMdNgdOdPgge
d"�e
gdQ�e
d"��e4dRe
gdH�gdI�ged"�e
d,d(ged"��e4dSe
dKdLgdMdNgdOdPgged"�e
gdQ�ed"��e4dTe
gdH�gdI�ged"�e
d,d(gdUdVgged"��e4dWe
dKdLgdMdNgdOdPgged"�e
d,d(gdUdVgdUdVgged"��e4dXe	j6�:d7dY�e	j6�:d7��e4dZe	j6�:d9d[�e	j6�:d9��e4d\e	j6�:d[d9�e	j6�:d[��e4d]e	j6�:dd=�e	j6�:d�d4hd5�e4d^e	j6�:d=d�e	j6�:d=�d4hd5�g�7Z8e8e5d_e4d`e
ddgddgged"�d�e4dae
ddgddgged"�d�e4dbe
dd)gdcd9gge
d"�d�e4dde
dd)gdcd9gged"�d�e4dee	j9d2ed"�dd4hd5�e4dfd9d;gd;d9ggd�e4dge
ddgddgg�d�e4dhe	j6�:d9d9�d�g�7Z8didj�Z;e8e;�7Z8dkdl�Z<dmdn�Z=e8e=�7Z8Gdodp�dp�Z>Gdqdr�dre>�Z?Gdsdt�dte>�Z@Gdudv�dve>�ZAGdwdx�dxe>�ZBGdydz�dze>�ZCGd{d|�d|e>�ZDd}d~�ZEdd��ZFGd�d��d�e?eB�ZGGd�d��d�eG�ZHGd�d��d�e?eB�ZIGd�d��d�eI�ZJGd�d��d�e?eB�ZKGd�d��d�eK�ZLGd�d��d�e?eB�ZMGd�d��d�eM�ZNGd�d��d��ZOGd�d��d�e?eB�ZPGd�d��d�ePeO�ZQGd�d��d�eAeD�ZRGd�d��d�eReO�ZSGd�d��d�e?eB�ZTGd�d��d�eT�ZUGd�d��d�e?e@eBeC�ZVGd�d��d�eV�ZWGd�d��d�eAeD�ZXGd�d��d�eX�ZYGd�d��d�e?eB�ZZGd�d��d�eZ�Z[Gd�d��d�e?e@�Z\Gd�d��d�e\�Z]ej^�_d�d�d��d�D��Gd�d��d���Z`Gd�d��d�eAeD�ZaGd�d��d��ZbGd�d��d�eAeD�ZcGd�d��d��ZdGd�d��d��ZeGd�d��d�ee�ZfGd�d„d�ee�ZgGd�dĄd�egef�ZhGd�dƄdƃZiGd�dȄd�ee�ZjGd�dʄd�ee�ZkGd�d̄d�ee�ZlGd�d΄d�ehej�ZmGd�dЄd�ehek�ZnGd�d҄d�ehel�ZoGd�dԄdԃZpd�dքZqGd�d؄d؃ZrGd�dڄdڃZsd�d܄Ztej^jue+d�dލd�d��Zvd�d�Zwej^jue+d�dލej^jxd�d���ZyGd�d�d�ZzGd�d�d�Z{Gd�d�d�Z|d�d�Z}ej^j~d�dލd�d��Zej^j�e*d�dލd�d��Z�dS)�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_WASMcCs$t|�t|tj�rt|�uStjuS�N)�type�
isinstance�np�ndarray)�out�in_�r'�I/usr/local/lib/python3.10/dist-packages/numpy/linalg/tests/test_linalg.py�consistent_subclass!s�r)��cKs8t|�jjttfvr
|}n|}t||fd|i|��dS)N�decimal)r�dtyper!rr�old_assert_almost_equal)�a�b�single_decimal�double_decimal�kwr,r'r'r(r+srcCstttttttti|Sr )rrrr�r-r'r'r(�get_real_dtype3�
��r5cCstttttttti|Sr )rrrrr4r'r'r(�get_complex_dtype8r6r7cCs|ttfvrdSdS)Ng�h㈵��>g�dy���=)rrr4r'r'r(�get_rtol=sr8>�square�strided�	hermitian�	nonsquare�generalized�size-0c@s*eZdZe�fdd�Zdd�Zdd�ZdS)�
LinalgCasecCs.tt|t��||_||_||_t|�|_dS)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)rr"�str�namer/r0�	frozenset�tags)�selfrAr/r0rCr'r'r(�__init__Ms
zLinalgCase.__init__cCs||j|j|jd�dS)zN
        Run the function `do` on this test case, expanding arguments
        �rCN)r/r0rC)rD�dor'r'r(�checkXszLinalgCase.checkcCsd|j�d�S)Nz
<LinalgCase: �>)rA�rDr'r'r(�__repr__^szLinalgCase.__repr__N)�__name__�
__module__�__qualname__�setrErHrKr'r'r'r(r?Lsr?cCs,|tvsJd��|D]	}|j|hB|_q
|S)z^
    Add the given tag (a string) to each of the cases (a list of LinalgCase
    objects)
    zInvalid tag)�all_tagsrC)�tag�cases�caser'r'r(�	apply_tagbsrT��r9r��?�@�@�@r4r�double_2)rWrVrY)rXrY�@r��?@y@@y@@y@@�@�?r�	cdouble_2)r]r\y�?@)y�?�y�?�y�?��0x0�rr�rr>rF�8x8��1x1��nonarray���r<�single_nsq_1)rVrWrX�single_nsq_2g@r[)rWrVrX�double_nsq_1�double_nsq_2�
csingle_nsq_1)��?�?�@@�@�)y@�y@"@y@@�
csingle_nsq_2rorprqy@"�y@�y@ @)r]r\rq�
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_1x1cCsg}tD]�}t|jtj�sqt�|jd|jd|jg�}|jdur%d}nt�|jd|jd|jg�}t|jd|||j	dhBd�}|�
|�t�|jgdd��d|jj�}|jdurbd}nt�|jgdd��d|jj�}t|jd	|||j	dhBd�}|�
|�q|S)
Nrgrh�r*�_tile3r=rF�rhrg�_tile213)
�CASESr"r/r#r$rr0r?rArC�append�reshape�shape)�	new_casesrSr/r0�new_caser'r'r(�_make_generalized_cases�s*

�
$
$
�r�ccs��t|tj�s|dfVdSdg|j}d|d<|jdkr!d|d<|jdkr*d	|d
<tjt|��D]�}dd�t|j|�D�}td
d�|D��}tj	||j
d�}|�tj��
d�||}||d<|�|j�}tt�||k��|dd�dd�|D��fV|jdkr�|jddkr�t|j�}d|d<tjjj||d�}|dfV|jdkr�|jddkr�t|j�}d|d<tjjj||d�}|dfV|jdkr�|jdd�dkr�t|j�}d|d<d|d<tjjj||d�}|dfVq1dS)z<
    Generate cartesian product of strides for all axes
    �nopN�re)rerh������re���rg)rer����cSsg|]
\}}t||��qSr')�abs)�.0r/r0r'r'r(�
<listcomp>%sz%_stride_comb_iter.<locals>.<listcomp>cSsg|]}tdd|��qSr )�slice)r��repeatr'r'r(r�&sr4l�>[=.�stride_�_cSsg|]}d|�qS)z%+dr')r��jr'r'r(r�/sr)�strides�stride_xxx_0�stride_xxx_0_x�rere�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_itersL�








��r�c	Csng}tD]0}t|j�D](\}}t|j�D]\}}t|jd|d||||jdhBd�}|�|�qqq|S)Nr�r:rF)r�r�r/r0r?rArCr�)r�rSr/�a_labelr0�b_labelr�r'r'r(�_make_strided_casesDs
���r�c@s"eZdZeZe�e�fdd�ZdS)�LinalgTestCasecCsv|jD]5}|j|@|kr
q|j|@rqz|�|j�Wqty8}zd|�d�}|t��7}t|�|�d}~wwdS)zx
        Run func on each of the cases with all of the tags in require, and none
        of the tags in exclude
        zIn test case: z

N)�
TEST_CASESrCrHrG�	Exception�	traceback�
format_exc�AssertionError)rD�require�excluderS�e�msgr'r'r(�check_casesXs


���zLinalgTestCase.check_casesN)rLrMrNr�r�rOr�r'r'r'r(r�Usr�c@�eZdZdd�Zdd�ZdS)�LinalgSquareTestCasecC�|jdhddhd�dS)Nr9r=r>�r�r��r�rJr'r'r(�
test_sq_casesn�
�z"LinalgSquareTestCase.test_sq_casescC�|jddhdhd�dS)Nr9r>r=r�r�rJr'r'r(�test_empty_sq_casesr�

�z(LinalgSquareTestCase.test_empty_sq_casesN)rLrMrNr�r�r'r'r'r(r�l�r�c@r�)�LinalgNonsquareTestCasecCr�)Nr<r=r>r�r�rJr'r'r(�test_nonsq_casesyr�z(LinalgNonsquareTestCase.test_nonsq_casescCr�)Nr<r>r=r�r�rJr'r'r(�test_empty_nonsq_cases}r�z.LinalgNonsquareTestCase.test_empty_nonsq_casesN)rLrMrNr�r�r'r'r'r(r�wr�r�c@r�)�HermitianTestCasecCr�)Nr;r=r>r�r�rJr'r'r(�test_herm_cases�r�z!HermitianTestCase.test_herm_casescCr�)Nr;r>r=r�r�rJr'r'r(�test_empty_herm_cases�r�z'HermitianTestCase.test_empty_herm_casesN)rLrMrNr�r�r'r'r'r(r��r�r�c@�,eZdZejjdd��Zejjdd��ZdS)�LinalgGeneralizedSquareTestCasecCr�)Nr=r9r>r�r�rJr'r'r(�test_generalized_sq_cases��

�z9LinalgGeneralizedSquareTestCase.test_generalized_sq_casescC�|jhd�d�dS)N>r9r=r>�r�r�rJr'r'r(�test_generalized_empty_sq_cases��z?LinalgGeneralizedSquareTestCase.test_generalized_empty_sq_casesN)rLrMrN�pytest�mark�slowr�r�r'r'r'r(r���

r�c@r�)�"LinalgGeneralizedNonsquareTestCasecCr�)Nr=r<r>r�r�rJr'r'r(�test_generalized_nonsq_cases�r�z?LinalgGeneralizedNonsquareTestCase.test_generalized_nonsq_casescCr�)N>r<r=r>r�r�rJr'r'r(�"test_generalized_empty_nonsq_cases�r�zELinalgGeneralizedNonsquareTestCase.test_generalized_empty_nonsq_casesN)rLrMrNr�r�r�r�r�r'r'r'r(r��r�r�c@r�)�HermitianGeneralizedTestCasecCr�)Nr=r;r>r�r�rJr'r'r(�test_generalized_herm_cases�r�z8HermitianGeneralizedTestCase.test_generalized_herm_casescCs|jhd�dhd�dS)N>r;r=r>�noner�r�rJr'r'r(�!test_generalized_empty_herm_cases�r�z>HermitianGeneralizedTestCase.test_generalized_empty_herm_casesN)rLrMrNr�r�r�r�r�r'r'r'r(r��r�r�cCs�t|�}|jdkrZ|j|jkr|jdd�|jdd�}n|j|jdkr.|jdd�}ntd��tj|t�||�d�}tjt	t
|jdd���D]
}t||||�||<qJ|St||�S)Nrhr�rezNot implemented...r4r�)rr�r��
ValueErrorr#r��common_typer�r��map�ranger)r/r0r��r�cr'r'r(�dot_generalized�s

r�cCsHt|�}|jdkrtj|j|jd�}t|jd�|d<|St|jd�S)Nrhr4r�.r)rr�r#r�r�r-r)r/r�r'r'r(�identity_like_generalized�s
r�c@�eZdZdd�ZdS)�
SolveCasescCs.t�||�}t|t||��tt||��dSr )r�solverr�rr))rDr/r0rCr�r'r'r(rG�sz
SolveCases.doN�rLrMrNrGr'r'r'r(r���r�c@s:eZdZej�deeee	g�dd��Z
dd�Zdd�ZdS)	�	TestSolver-cCs2tjddgddgg|d�}tt�||�j|�dS�Nre��?r4)r#rrrr�r-�rDr-r�r'r'r(�
test_types�szTestSolve.test_typesc	Cs.Gdd�dtj�}t�d��ddd�}t�d��ddd��|�}t�||�dd�dd�dd�f}t�|dd�dd�dd�f|dd�dd�dd�f�}t||�tt	||��t
tjtj|dd�dd�dd�f|�t
ttj||dd�dd�dd�f�t�d��ddd�}t
ttj||�t
ttj|dd�|dd��t�d��dd��|�}t�||�dd�dd�f}t�|dd�dd�dd�f|dd�dd�f�}t||�tt	||��t�d��dd�}t
ttj||�t
ttj|dd�|dd��t
ttj|dd�dd�dd�f|�dS)	Nc@�eZdZdS)z,TestSolve.test_0_size.<locals>.ArraySubclassN�rLrMrNr'r'r'r(�
ArraySubclass��rrcrgr*rerhr)
r#r$�aranger�r�rr�rrr"rrr��rDrr/r0�expected�resultr'r'r(�test_0_size�s*"8
(& 2
 *zTestSolve.test_0_sizecCsGdd�dtj�}t�d��ddd�}t�d��ddd��|�}t�||�dd�dd�dd�f}t�||dd�dd�dd�f�}t||�tt	||��t�||�dd�dd�dd�f}t�|dd�dd�dd�f|dd�dd�dd�f�}t||�tt	||��dS)	Nc@r)z.TestSolve.test_0_size_k.<locals>.ArraySubclassNrr'r'r'r(rrrrirergr*rhr)
r#r$rr�r�rr�rrr"rr'r'r(�
test_0_size_k�s""
"8
zTestSolve.test_0_size_kN)
rLrMrNr�r��parametrizerrrrr�rr	r'r'r'r(r��s

!r�c@r�)�InvCasescCs0t�|�}tt||�t|��tt||��dSr )r�invrr�r�rr))rDr/r0rC�a_invr'r'r(rGs


�zInvCases.doNr�r'r'r'r(rr�rc@�2eZdZej�deeee	g�dd��Z
dd�ZdS)�TestInvr-cCs0tjddgddgg|d�}tt�|�j|�dSr�)r#rrrrr-r�r'r'r(r�szTestInv.test_typescCs�Gdd�dtj�}tjdtjd��|�}t�|�}t|jj	tj
u�t|j|j�tt
||��tjdtjd��|�}t�|�}t|jj	tju�t|j|j�tt
||��dS)Nc@r)z*TestInv.test_0_size.<locals>.ArraySubclassNrr'r'r'r(r"rr�rrerer4r`)r#r$�zeros�int_r�rrrr-r!�float64rr�r"�	complex64�rDrr/�resr'r'r(r s

zTestInv.test_0_sizeN�rLrMrNr�r�r
rrrrr�rr'r'r'r(rs
rc@r�)�EigvalsCasescCs&t�|�}t�|�\}}t||�dSr )r�eigvals�eigr)rDr/r0rC�ev�evalues�evectorsr'r'r(rG3s
zEigvalsCases.doNr�r'r'r'r(r1r�rc@r)�TestEigvalsr-cCs`tjddgddgg|d�}tt�|�j|�tjddgddgg|d�}tt�|�jt|��dS�Nrer�r4r�)r#rrrrr-r7r�r'r'r(r�:szTestEigvals.test_typescCs�Gdd�dtj�}tjdtjd��|�}t�|�}t|jj	tj
u�td|j�tt
|tj��tjdtjd��|�}t�|�}t|jj	tju�td|j�tt
|tj��dS)Nc@r)z.TestEigvals.test_0_size.<locals>.ArraySubclassNrr'r'r'r(rCrrrr4�rrer`ra)r#r$rrr�rrrr-r!rrr�r"rrr'r'r(rA�

zTestEigvals.test_0_sizeNrr'r'r'r(r9s
rc@r�)�EigCasescCsbt�|�}|j|j}}tt||�t�|�t�|�dddd�ft|j	�d�t
t||��dS)N.��rtol)rr�eigenvalues�eigenvectorsrr�r#rr8r-rr))rDr/r0rCrr%r&r'r'r(rGVs

 �zEigCases.doNr�r'r'r'r(r"Tr�r"c@r)�TestEigr-cCs�tjddgddgg|d�}tj�|�\}}t|j|�t|j|�tjddgddgg|d�}tj�|�\}}t|jt|��t|jt|��dSr)r#rrrrr-r7�rDr-r��w�vr'r'r(r�`szTestEig.test_typescCs�Gdd�dtj�}tjdtjd��|�}t�|�\}}t|jj	tj
u�t|jj	tj
u�t|j|j�td|j�tt
|tj��tjdtjd��|�}t�|�\}}t|jj	tju�t|jj	tju�t|j|j�td|j�tt
|tj��dS)Nc@r)z*TestEig.test_0_size.<locals>.ArraySubclassNrr'r'r'r(rnrrrr4r r`ra)r#r$rrr�rrrr-r!rrr�r"r�rDrr/r�res_vr'r'r(rl�zTestEig.test_0_sizeNrr'r'r'r(r'_s
r'c@s.eZdZdZej�deee	e
g�dd��ZdS)�SVDBaseTestsFr-cCs�tjddgddgg|d�}t�|�}|j|j|j}}}t|j|�t|jt	|��t|j|�tj|d|j
d�}t|jt	|��dS)Nrer�r4F��
compute_uvr;)r#rr�svd�U�S�Vhrr-r5r;)rDr-r�rr2r3r4r�r'r'r(r��s
zSVDBaseTests.test_typesN)rLrMrNr;r�r�r
rrrrr�r'r'r'r(r.�sr.c@r�)�SVDCasesc	Cspt�|d�\}}}t|tt�|�t�|�dddd�ft�|��t|j�d�tt	||��tt	||��dS)NF.r#)
rr1rr�r#rr8r-rr))rDr/r0rC�ur��vtr'r'r(rG�s&��zSVDCases.doNr�r'r'r'r(r5�r�r5c@r�)�TestSVDcCs�t�d�}tj|d|jd�\}}}t|jd�t|jd�t|t�d��t�d�}tj|d|jd�\}}}t|jd�t|jd�t|t�d��dS)	z6 Empty input should put an identity matrix in u or vh )rirTr/�ririr`ri)rriN)r#r�rr1r;rr��eye)rDr�r6r��vhr'r'r(�test_empty_identity�s

zTestSVD.test_empty_identityN)rLrMrNr<r'r'r'r(r8�sr8c@r�)�SVDHermitianCasesc	Cs�tj|ddd�\}}}t|tt�|�t�|�dddd�ft�|��t|j�d�dd�}tt�	|||��t�
t�|jd�|j��tt�	|||��t�
t�|jd�|j��t
t�|�dddd�f|�tt||��tt||��dS)	NFT�r;.r#cSs<tt|j��}|d|d|d<|d<t�tj||d��S)Nr�r���axes)r�r�r�r#�conj�	transpose)�matr@r'r'r(r;�sz'SVDHermitianCases.do.<locals>.hermitianr�)rr1rr�r#rr8r-rr	�broadcast_tor:r�r�sortrr))rDr/r0rCr6r�r7r;r'r'r(rG�s&��,,zSVDHermitianCases.doNr�r'r'r'r(r=�r�r=c@seZdZdZdS)�TestSVDHermitianTN)rLrMrNr;r'r'r'r(rF�srFc@r�)�	CondCasescCs�t|�}d|vrtttj|�dStj|dd�}tt�|�|d|dddd�tt�|d	�|d|dddd�tt�|d
�|d|dddd�tj�|�}tt�|d�t	|��
d
��d�t	|��
d
��d�ddd�tt�|d�t	|��
d
��d�t	|��
d
��d�ddd�tt�|tj
�t	|��
d��d�t	|��
d��d�ddd�tt�|tj
�t	|��
d��d�t	|��
d��d�ddd�tt�|d
�t�t	|�d	�
d��
d�t	|�d	�
d��
d��ddd�dS)Nr>F)r0).r).r�rzrx�r1r2rgr�rer��fro)rrrr�condr1rr#rr��sum�max�minr
�sqrt)rDr/r0rCr�r��cinvr'r'r(rG�sZ���
&�
&�&�&�
�
�zCondCases.doNr�r'r'r'r(rG�srGc@s>eZdZdd�Zdd�Zejjdddd�d	d
��Zdd�Z	d
S)�TestCondcCs�tgd�gd�gd�g�}tt�|t�d�tt�|t�d�tt�|d�d�tt�|d�d�tt�|d	�t�d
��dS)N)rVrre)rg�r)rrrXrigUUUUUU�?rer�r�rIgUUUUU6@)rrrrJr
r#rN�rD�Ar'r'r(�test_basic_nonsvd�szTestCond.test_basic_nonsvdcCstt�d�t�d�g}gd�}ddg}t�||�D]\}}tt�||�dk�qt�||�D]
\}}t�||�q-dS)N�rgrg�NrergrIr�r��4&�kC)r#r�onesr�r�rrrJ)rD�As�p_pos�p_negrR�pr'r'r(�
test_singular�s�zTestCond.test_singularTFz/Platform/LAPACK-dependent failure, see gh-18914)�run�reasoncCs�gd�}gd�}t�d�}tj|d<|D]}t�||�}tt|tj��tt�|��qt�d�}tj|d<|D]:}t�||�}tt�|d��||vr^t|dd	k�t|d
d	k�q8tt�|d��tt�|d
��q8dS)N)Nrer�rgr�rIrUrTr )rhrgrg�rerrererrVrg)	r#rW�nanrrJrr"�float_�isnan)rD�psrYrRr[r�r'r'r(�test_nan
s&



�zTestCond.test_nancCs�tj�d�tj�dddd�}d|d<d|d<dD]*}t�||�}t|dtj�t|dtj�tt�	|d��tt�	|d��qdS)	NrUrgrr`r�)NrergrIr�r�r �rer)
r#�random�seed�randrrJrr
r�isfinite)rDrRr[r�r'r'r(�test_stacked_singular%s�zTestCond.test_stacked_singularN)
rLrMrNrSr\r�r��xfailrdrjr'r'r'r(rP�s	
�
rPc@r�)�	PinvCasescCs<t�|�}t}t||||�|�|ddd�tt||��dS)NrzrxrH�r�pinvr�rrr)�rDr/r0rC�a_ginvrr'r'r(rG:s
zPinvCases.doNr�r'r'r'r(rl5srlc@r)�TestPinvNrr'r'r'r(rqBrrqc@r�)�PinvHermitianCasescCs@tj|dd�}t}t||||�|�|ddd�tt||��dS)NTr>rzrxrHrmror'r'r(rGHszPinvHermitianCases.doNr�r'r'r'r(rrFr�rrc@r)�TestPinvHermitianNrr'r'r'r(rsPrrsc@r�)�DetCasescCs�t�|�}t�|�}|j|j}}t|�jjtt	fvr#t|��
t	�}nt|��
t�}t�|�}	t
|tj|	dd��t
|t�|�tj|	dd��t�|�}t�|�}|dk}
t
t�||
�d�t||
t�dS)Nr���axisrre)r�det�slogdet�sign�	logabsdetrr-r!rr�astyperrrr�reducer#�exp�
atleast_1dr�rr
)rDr/r0rC�drr��ld�adr�mr'r'r(rGVs




zDetCases.doNr�r'r'r'r(rtTr�rtc@s:eZdZdd�Zej�deee	e
g�dd��Zdd�ZdS)	�TestDetcCstt�dgg�d�ttt�dgg��t�tt�dgg�d�ttt�dgg��t�tt�dgg�dtf�ttt�dgg�d�t�ttt�dgg�d�t�tt�dgg�dtf�ttt�dgg�d�t�ttt�dgg�d�t�dS)N�yrre)rrrwr!rrrxr
rJr'r'r(�	test_zerojs zTestDet.test_zeror-cCs^tjddgddgg|d�}ttj�|�j|�tj�|�\}}t|jt|��t|j|�dSr�)r#rrrrwr-rxr5)rDr-r��phr�r'r'r(r�ws
zTestDet.test_typescCs�tjdtjd�}t�|�}t|d�t|jjtju�t�	|�}t|d�t|djjtju�t|djjtj
u�tjdtjd�}t�|�}t|d�t|jjtju�t�	|�}t|d�t|djjtju�t|djjtju�dS)Nr`r4rVrerre)r#rrrrwrrr-r!rx�float32r)rDr/rr'r'r(rs 







zTestDet.test_0_sizeN)
rLrMrNr�r�r�r
rrrrr�rr'r'r'r(r�is

r�c@r�)�
LstsqCasescCsLt�|�}|j\}}t�|d�\}}}	tj||dd�\}
}}}
|dkr+t|
dk���||kr=t|t	||
��t
||�nt
||�t|
|
�|��||kr}||kr}t�tt�	||
�|��dj
dd�}t�|�}t�|�jdkr|d|_t
|j|j�n
t�g��t|
��}t||�tt�|jtj��tt|
|��tt||��dS)	NFr���rcondrrgrurer�)r#rr�rr1�lstsqrr�rrr�__array_wrap__r�rKr�rr�r!�
issubdtyper-�floatingr))rDr/r0rC�arrr��nr6r�r7r��	residuals�rank�sv�
expect_residsr'r'r(rG�s0


 �
�
z
LstsqCases.doNr�r'r'r'r(r��r�r�c@s:eZdZdd�Zej�gd�gd��dd��Zdd�Zd	S)
�	TestLstsqc	Cs�t�gd�gd�gd�gd�g�j}t�gd��}t��K}|�td�}t�||�\}}}}t|dk�tj||dd	�\}}}}t|dk�tj||dd	�\}}}}t|d
k�tt	|�dk�Wd�dS1sjwYdS)N)r�rVr�rVrWr�)r�rWr�r�rVr�)rVr�rVr�r�rY)r�r�r�rWrXr�)rerrrrrz`rcond` parameter will changerir�r�rhre)
r#r�Tr�record�
FutureWarningrr�r�len)	rDr/r0�supr)r�r�r�r�r'r'r(�test_future_rcond�s$
��"�zTestLstsq.test_future_rcond)r�r��n_rhs))rirgrg)rrire)rrirg)rirre)rirrg)rirgr)rrrcCs�t�||��||�}t�||f�}tj||dd�\}}}}	|dkr*t|dk���t|j	||f�t|j	||kr<|fnd�||krZ|dkrZ|t�
||�}
t||
|
jdd��t|t
||��t|	j	t
||�f�dS)Nr�rrar�ru)r#rr�rWrr�rr�rr�rrrKrM)rDr�r�r�r/r0r�r�r�r�r�r'r'r(�test_empty_a_b�s
zTestLstsq.test_empty_a_bcCsvt�gd��}t�gd��}t�|t�t|��g�j}ttd��tj	||dd�Wd�dS1s4wYdS)N)rrergrh)r�g�������?g�������?g������@gffffff
@zIncompatible dimensionsr�)
r#r�vstackrWr�r�rrrr�)rDr��yrRr'r'r(�test_incompatible_dims�s"�z TestLstsq.test_incompatible_dimsN)	rLrMrNr�r�r�r
r�r�r'r'r'r(r��s

	r��dtcCsg|]}t�|��qSr')r#r-)r�r�r'r'r(r��sr�z?bBhHiIqQefdgFDGOc@s�eZdZe�d�Zegd�Zegd�Zegd�ZeeeegZ	e
ddgddgg�Ze�egggd�Z
ee�d�e�d	�e�d
�gZdd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zejjedd�dd��ZdS)�TestMatrixPowerri)rhrrerg)rgrhrre)rergrhrrerrgr��g�GcCs�|j�|�}tt|ddddd�|j�tt|ddddd�|j�tt|ddddd�|j�tt|ddddd�|j�dS)Nrg�di� rrerh)�rshft_1r{rr�rshft_0�rshft_2�rshft_3)rDr��rshftr'r'r(�test_large_power�s����z TestMatrixPower.test_large_powercC�>dd�}|jD]}||�|��|tkr||j�|��qdS)NcSs*t|d�}t|t|��t|j|j�dS)Nr)rrr�r-)�M�mzr'r'r(�tz�s
z.TestMatrixPower.test_power_is_zero.<locals>.tz��	rshft_allr{�object�stacked�rDr�r�rCr'r'r(�test_power_is_zero��
��z"TestMatrixPower.test_power_is_zerocCr�)NcSs&t|d�}t||�t|j|j�dS)Nre)rrr-)rCr�r'r'r(r�	s

z-TestMatrixPower.test_power_is_one.<locals>.tzr�r�r'r'r(�test_power_is_oner�z!TestMatrixPower.test_power_is_onecCr�)NcSs>t|d�}|jtkrtnt}t||||��t|j|j�dS)Nrg)rr-r�r	rr)rCr��mmulr'r'r(r�s
z-TestMatrixPower.test_power_is_two.<locals>.tzr�r�r'r'r(�test_power_is_twos
��z!TestMatrixPower.test_power_is_twocCs0dd�}|jD]}||jvr||�|��qdS)NcSs4t|d�}|jtkrtnt}t|||�t|��dS�Nr�)rr-r�r	rrr�)rC�invmatr�r'r'r(r� s

�z3TestMatrixPower.test_power_is_minus_one.<locals>.tz)r��dtnoinvr{r�r'r'r(�test_power_is_minus_ones

��z'TestMatrixPower.test_power_is_minus_onecCs.|j�|�}ttt|d�ttt|dg�dS)Ng�?re)r�r{r�	TypeErrorr�rDr�rCr'r'r(�test_exceptions_bad_power*sz)TestMatrixPower.test_exceptions_bad_powercCsPtttt�dg|�d�tttt�dgdgg|�d�tttt�d|�d�dS)Nrerg)rirhrg)rrrr#rrW)rDr�r'r'r(�test_exceptions_non_square/sz*TestMatrixPower.test_exceptions_non_square�fp errors don't work in wasm�r^cCs,||jvrdS|j�|�}ttt|d�dSr�)r��noninvr{rrrr�r'r'r(�test_exceptions_not_invertible4s
z.TestMatrixPower.test_exceptions_not_invertibleN)rLrMrNr#r:r�r�r�r�r�rr��blockr�r�r-r�r�r�r�r�r�r�r�r�r��skipifrr�r'r'r'r(r��s$
r�c@r�)�TestEigvalshCasescCs^t�|d�}t�|�\}}|jdd�t||t|j�d�t�|d�}t||t|j�d�dS)N�Lr�rur#r2)r�eigvalshrrErr8r-)rDr/r0rCrrr�ev2r'r'r(rG>szTestEigvalshCases.doNr�r'r'r'r(r�<r�r�c@�BeZdZej�deeee	g�dd��Z
dd�Zdd�Zdd	�Z
d
S)�TestEigvalshr-cCs:tjddgddgg|d�}tj�|�}t|jt|��dSr�)r#rrr�rr-r5)rDr-r�r)r'r'r(r�KszTestEigvalsh.test_typescC�Xtjddgddggtjd�}tttjj|dd�tttjj|d�tttjj|d�dS�Nrer�r4�lrong��UPLO�lower�upper)r#rr�rr�rr��rDr�r'r'r(�test_invalidQ�zTestEigvalsh.test_invalidcCs�tjddgddggtjd�}tjddgddggtjd�}tjddgtjd�}ttj�}tj�|�}t|||d�tjj|dd�}t|||d�tjj|dd�}t|||d�tjj|d	d�}t|||d�tjj|d
d�}t|||d�dS�Nrrer4r�r#r�r��lr2r6)r#rrr8rr�r)rD�Klo�Kup�tgtr$r)r'r'r(�	test_UPLOWs
zTestEigvalsh.test_UPLOcCs�Gdd�dtj�}tjdtjd��|�}t�|�}t|jj	tj
u�td|j�tt
|tj��tjdtjd��|�}t�|�}t|jj	tju�td|j�tt
|tj��dS)Nc@r)z/TestEigvalsh.test_0_size.<locals>.ArraySubclassNrr'r'r'r(rorrrr4r r`ra)r#r$rrr�rr�rr-r!rrr�r"rr�rr'r'r(rmr!zTestEigvalsh.test_0_sizeN�rLrMrNr�r�r
rrrrr�r�r�rr'r'r'r(r�Js
r�c@r�)�
TestEighCasescCs�t�|�}|j|j}}t�|�\}}|jdd�t||�tt||�t	�
|�dddd�ft	�
|�t|j�d�t�|d�\}	}
t|	|�tt||
�t	�
|	�dddd�ft	�
|
�t|j�t
|�d�dS)Nr�ru.r#r2)r$�err_msg)r�eighr%r&rrErrr�r#rr8r-�repr)rDr/r0rCrr�evcrrr��evc2r'r'r(rG�s


 �

 
�zTestEighCases.doNr�r'r'r'r(r��r�r�c@r�)�TestEighr-cCsJtjddgddgg|d�}tj�|�\}}t|jt|��t|j|�dSr�)r#rrr�rr-r5r(r'r'r(r��szTestEigh.test_typescCr�r�)r#rr�rr�rr�r�r'r'r(r��r�zTestEigh.test_invalidcCstjddgddggtjd�}tjddgddggtjd�}tjddgtjd�}ttj�}tj�|�\}}t|||d�tjj|dd�\}}t|||d�tjj|dd�\}}t|||d�tjj|d	d�\}}t|||d�tjj|d
d�\}}t|||d�dSr�)r#rrr8rr�r)rDr�r�r�r$r)r*r'r'r(r��s
zTestEigh.test_UPLOcCs�Gdd�dtj�}tjdtjd��|�}t�|�\}}t|jj	tj
u�t|jj	tj
u�t|j|j�td|j�tt
|tj��tjdtjd��|�}t�|�\}}t|jj	tju�t|jj	tju�t|j|j�td|j�tt
|tj��dS)Nc@r)z+TestEigh.test_0_size.<locals>.ArraySubclassNrr'r'r'r(r�rrrr4r r`ra)r#r$rrr�rr�rr-r!rrr�r"rr�r+r'r'r(r�r-zTestEigh.test_0_sizeNr�r'r'r'r(r��s
r�c@s eZdZdZdZedd��ZdS)�
_TestNormBaseNcCs<t|jjtj�rt|j|jj�dStt|jjtj��dSr )	�
issubclassr-r!r#�inexactr�realrr�)r�rr'r'r(�check_dtype�sz_TestNormBase.check_dtype)rLrMrNr��dec�staticmethodr�r'r'r'r(r��s
r�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�_TestNormGeneralcCsFttg�d�tttg|jd��d�ttttg|jd���d�dS)Nr�r4)rrrr�rrJr'r'r(�
test_empty�s z_TestNormGeneral.test_emptyc		Cs�t�gd��}tjd}tjd}||}|D]�}|�|�}t|tj�}|�||�t|d�t��}|�	t
d�t|d�}|�||�t|d�Wd�n1sTwYt|d�}|�||�t|d�t|d	�}|�||�t|d
�t|d�}|�||�t||j�d
�|j�d��t|d�}|�||�t||j�d
�|j�d
��t|tj�}|�||�t|d�qdS)Nr_�
AllInteger�AllFloatr��divide by zero encounteredr�rrgrerWr�rig�?rV)
r#r�	typecodesr{rr
r�rr�filter�RuntimeWarningr-r!�	rDr/�exact_types�
inexact_types�	all_types�	each_type�at�anr�r'r'r(�test_vector_return_type�s>




�





�z(_TestNormGeneral.test_vector_return_typecsvgd�}gd�}gd�}�fdd�}|||fD]}||�qt|�jd�t|�jd�t|�jd�fD]}||�q2dS)N)rergrhri)r�r�r�r�)r�rgr�rics�tjjt|�d�jd�tjjt|t�d�jd�tjjt|t�d�jd�tjjt|d�d�jd�tjjt|d�d�jd�tjjt|d	�d�jd�tjjt|d
�d�jd�tjjt|d�d
�jd�dS)Ng��6ҭ�@�r,rYrVre�$@r�g���Q��?rgr�g�s�c���?rri)r#�testingrrr�r
)r*rJr'r(�_tests0�������
�z+_TestNormGeneral.test_vector.<locals>._testr4)rr�)rDr/r0r�rr*r'rJr(�test_vectors
�
�z_TestNormGeneral.test_vectorc		s�tgd�gd�g|jd��ddddddtjtjfD]4���fd	d
�t�jd�D�}tt��dd�|���fdd
�t�jd�D�}tt��dd�|�qtjdd
|jd��	ddd���j
}dddddtjtjdfD]h�t�t||�d�D][}|\}}|dkr�||7}|dkr�||7}||kr�t
tt��|d�qyt��|d�}|||�||kr����fdd
�t�j��D�}n���fdd
�t�j��D�}t||�qyqmdS)N�rergrh�rirzr*r4r�rrergrhcs$g|]}t�dd�|f�d��qS�N��ord�r�r��k�rR�orderr'r(r�3�$z._TestNormGeneral.test_axis.<locals>.<listcomp>�rrvcs$g|]}t�|dd�f�d��qSrrr	rr'r(r�5r
�rir�rIcs*g|]}t�dd�j|�d��d��qS�Nrur)r�taker	��B�k_indexrr'r(r�Ks"�cs,g|]}t�dd�j|�d�j�d��qSr)rrr�r	rr'r(r�Ns$�)rr�r#�Infr�r�rrrr�r�r��combinationsrr�)	rD�	expected0�	expected1�ndrv�row_axis�col_axisr�rr')rRrrrr(�	test_axis-s:����z_TestNormGeneral.test_axisc	
Cs�tjdd|jd��ddd�}d}d}t|ddd	�}t|ddd
d�}tt�|�||�dd�d�d
}t|j	|k|�|j	|dd��ddddddtj
tj
fD]C}t|j�D];}t|||d	�}t|||d
d�}tt�|�||�||�d�t
|j	�}d||<t|�}t|j	|k|�|j	|||��qTqMdddddtj
tj
ddf	D]O}t�t|j�d�D]C}t|||d	�}t|||d
d�}tt�|�||�||�d�t
|j	�}d||d<d||d<t|�}t|j	|k|�|j	|||��q�q�dS)Nrerr4rgrhrizorder {0}, axis = {1}z;Shape mismatch found {0}, expected {1}, order={2}, axis={3}rT)rrv�keepdims)r�)rererer�rr�rI�nuc)r#rr�r�rr�squeeze�formatrr�rr�r�r�r�r��permutations)	rDrR�allclose_err�	shape_errr�found�expected_shaperr
r'r'r(�
test_keepdimsRsT
�
�
�

�� 
�

���z_TestNormGeneral.test_keepdimsN)rLrMrNr�r�rrr&r'r'r'r(r��s)%r�c@s:eZdZejZdd�Zdd�Zdd�Zdd�Zd	d
�Z	dS)�_TestNorm2DcCs tt|jgg|jd��d�dS)Nr4r�)rrrr�rJr'r'r(�test_matrix_empty�s z_TestNorm2D.test_matrix_emptyc		Cs�|�gd�gd�g�}tjd}d}||}|D]�}|�|�}t|tj�}|�||�t|d�t��}|�	t
d�t|d�}|�||�t|d�Wd�n1sUwYt|d	�}|�||�t|d�t|d
�}|�||�t|d�t|d�}|�||�t|d�t|tj�}|�||�t|d�t|d
�}|�||�t|d�t|d�}|�||�tjj|ddd�qdS)Nr_rr��fdFDrWr�r�rVrergg�LX�z��?r�rIrgU&,t=�@r*r�)rr#r�r{rr
r�rrr�r�rr�r'r'r(�test_matrix_return_type�sD



�









�z#_TestNorm2D.test_matrix_return_typecCs�|jddgddgg|jd�}tt|�d�tt|d�d�tt|d�d	�tt|t�d
�tt|t�d�tt|d�d	�tt|d�d
�tt|d�d�tt|d�d�ttt|d�ttt|d�ttt|d�dS)Nrerhrzr�r4g���T"@rIrr�g(@rYr�r[rgg��W�?"@r�gї�ʄ�?�nofror�r)rr�rrr
rr�rQr'r'r(�test_matrix_2x2�sz_TestNorm2D.test_matrix_2x2cCs�d|jgd�gd�gd�g|jd�}tt|�d�tt|d�d�tt|d�d	�tt|t�d
�tt|t�d�tt|d�d
�tt|d�d�tt|d�d�tt|d�d�dS)Ng�������?r)r*rrz)rhrgrer4grj=Q0�?rIrg�B+pc�?g�������?g333333�?rerVr�g�������?rgg�&��.d�?r�gܸՠ���?)rr�rrr
rQr'r'r(�test_matrix_3x3�s �z_TestNorm2D.test_matrix_3x3cCs|jgd�gd�g|jd�}tjdd|jd��ddd�}ttt|d	d
�ttt|dd
�tttddgd	d�tttddgdd�tttddgdd�d
D]}ttt||d�ttt||d�ttt||d�qLttjt|dd�ttjt|dd�ttt|dd�dS)Nrrr4rerrgrhrirIrr�test�rrhr )rerg�rgrh)rrerg)	rr�r#rr�rr�r�	AxisError)rDrRrrr'r'r(�
test_bad_args�sz_TestNorm2D.test_bad_argsN)
rLrMrNr#rr(r*r,r-r2r'r'r'r(r'}s3r'c@r)�	_TestNormNrr'r'r'r(r3�rr3c@s$eZdZdd�Zdd�Zdd�ZdS)�TestNorm_NonSystematiccCs*tjdtjd�}tt|dd�ddd�dS)N�
r4rhrg�����L)@rgr�)r#r�
longdoubler.rr�r'r'r(�test_longdouble_norm�sz+TestNorm_NonSystematic.test_longdouble_normcCs,tjdgtjd�}tt|dd�ddd�dS)Ni�r4rhrlrzr�)r#r�int32r.rr�r'r'r(�test_intminsz"TestNorm_NonSystematic.test_intmincCs�tjdtjd�}d|d<d|d<d}ttjj|dd	�|d
d�|�tj�}ttjj|dd	�|dd�|�tj�}ttjj|dd	�|d
d�dS)N�rgr4y@@ry�@reg���V;'@rhrr5r��	rz)	r#r��clongdoubler.rrr{�
complex128r)rDrrr'r'r(�test_complex_high_ordsz,TestNorm_NonSystematic.test_complex_high_ordN)rLrMrNr7r9r>r'r'r'r(r4�sr4c@�eZdZejZdZdS)�_TestNormDoubleBaser+N)rLrMrNr#rr�r�r'r'r'r(r@�r@c@r?)�_TestNormSingleBaser*N)rLrMrNr#r�r�r�r'r'r'r(rBrArBc@r?)�_TestNormInt64Baser+N)rLrMrNr#�int64r�r�r'r'r'r(rCrArCc@r)�TestNormDoubleNrr'r'r'r(rE$rrEc@r)�TestNormSingleNrr'r'r'r(rF(rrFc@r)�
TestNormInt64Nrr'r'r'r(rG,rrGc@r�)�TestMatrixRankcCs�tdtt�d���t�d�}d|d<tt|�d�ttt�d��d�ttgd��d�ttt�d	��d�ttdg�d�t�|t�d�t�d�g�}tt|�t�gd
���ttd�d�dS)Nrir��r�r�rhr9r)rerrrre)ri)rhrir)rrr#r:rr)rD�I�msr'r'r(�test_matrix_rank2s
zTestMatrixRank.test_matrix_rankcCs�tdtt�d�dd��tdtt�d�dd��tdtt�d�dd��t�d�}d|d<td	t|dd��d
|d<tdt|ddd��td	t|dd
d��dS)NriTr>rer9rr�rIrhg:�0�yE>g��|"�BE>)r;�tolg�;䡈�E>)rrr#r:rWr)rDrJr'r'r(�test_symmetric_rankFs
z"TestMatrixRank.test_symmetric_rankN)rLrMrNrLrNr'r'r'r(rH0srHcCs�tj�d�}td�D]B}|jdd�}|dd�df|dd�df|dd�df<tt|�d�|dd�d	f|dd�d
f|dd�df<tt|�d�q
dS)
Ni�3r�)�(r5��sizerergrr;rirzrhrc)r#rf�RandomStater��normalrr)�rng�i�Xr'r'r(�test_reduced_rankTs,,�rWc	@s�eZdZejZdd�Zej�ddggd��dd��Z	dd	�Z
d
d�Zdd
�Zej�dgd��ej�dgd��ej�dej
ejejejg�dd����ZdS)�TestQRc
Cs�t|�}|j}|j\}}t||�}tj|dd�}|j|j}}	t|j|k�t|	j|k�tt	||��tt	|	|��t|j||fk�t|	j||fk�t
t||	�|�t
t|j�
�|�t�|��t
t�|	�|	�tj|dd�\}
}t|
j|k�t|j|k�tt	|
|��tt	||��t|
j||fk�t|j||fk�t
t|
|�|�t
t|
j�
�|
�t�|��t
t�|�|�tj|dd�}t|j|k�tt	||��t
||�dS)N�complete��mode�reducedr�)r!r-r�rMr�qr�Q�Rrr"rrr�rAr#r:�triu)
rDr/�a_type�a_dtyper�r�r
rr^r_�q1�r1�r2r'r'r(�check_qres:

zTestQR.check_qrr�r�)�rhrr/r`cCstt||�}t�||f�}|�|�tjj|dd�\}}t|jtj�t|jtj�t|j	||f�t|j	|f�dS)N�rawrZ)
rMr#r�rfrr]rr-rr�)rDr�r�r
r/�h�taur'r'r(�
test_qr_empty�s

zTestQR.test_qr_emptycCs�|jddgddgddggtjd�}tj|dd	�\}}t|jtjk�t|jtjk�t|jd
k�t|jdk�tj|jdd	�\}}t|jtjk�t|jtjk�t|jdk�t|jdk�dS)
Nrergrhrirzr*r4rhrZr0r:r�)	rr#rrr]rr-r�r�)rDr/rirjr'r'r(�
test_mode_raw�s"zTestQR.test_mode_rawcCs�|�ddgddgg�}|�ddgddgddgg�}dD]}|�|�}|�|�}|�|�|�|�|�|j�qdD]$}dd|�|�}dd|�|�}|�|�|�|�|�|j�q:dS)	Nrergrhrirzr*�fd��?)rr{rfr�)rDr/r0r��m1�m2r'r'r(�test_mode_all_but_economic�s





�z!TestQR.test_mode_all_but_economiccCsft|�}|j}|jdd�\}}t||�}tj|dd�\}}t|j|k�t|j|k�tt||��tt||��t|jdd�||fk�t|jdd�||fk�tt	||�|�t
�|jd�}	t
�|	|jdd�|jdfd�}
tt	t
|dd���|�|
�tt
�|ddd�dd�f�|�tj|dd�\}}t|j|k�t|j|k�tt||��tt||��t|jdd�||fk�t|jdd�||fk�tt	||�|�t
�|jd�}	t
�|	|jdd�|jdfd�}
tt	t
|dd���|�|
�tt
�|ddd�dd�f�|�tj|dd�}
t|
j|k�tt|
|��t|
|�dS)	Nr�rYrZr�rg.r\r�)r!r-r�rMrr]rr"rr	r#rrDr
rAr`)rDr/rarbr�r�r
�qr��I_mat�stack_I_matrcrdrer'r'r(�check_qr_stacked�sL
�"��"zTestQR.check_qr_stackedrQ))rhri)rirhr9rgr/�
outer_size)rTr:)rgrhrir�cCsPtjj||d��|�}tjj||d��|�}|�|�|�|d|�dS)NrPrn)r#rfrSr{ru)rDrvrQr�rRrr'r'r(�test_stacked_inputs�s

zTestQR.test_stacked_inputsN)rLrMrNr#rrfr�r�r
rkrlrqrurrrrrwr'r'r'r(rXas(
-�rXc@sLeZdZej�dgd��ej�dejejej	ej
f�dd���Zdd�ZdS)	�TestCholeskyr�)r�rT�rhrh)�2rz)rhr5r5r-cCstj�d�tjj|�}t�|tj�r|dtjj|�}ttt|���}d|dd�<t�	|�
|���|�}tj||d�}tj
�|�}t�	||�
|����}t���d|jdt�|�j}Wd�n1sjwYt||||�d|�d	|�d	|��d
�dS)Nrern)r�r�r�r4i�r� �
)�atolr�)r#rfrg�randnr��complexfloatingr�r�r�r	rBrArr�cholesky�_no_nep50_warningr��finfo�epsr)rDr�r-r/�tr�r0r}r'r'r(�test_basic_propertys
�*z TestCholesky.test_basic_propertycCs�Gdd�dtj�}tjdtjd��|�}t�|�}t|j|j�t	|j
jtju�t	t
|tj��tjdtjd��|�}t�|�}t|j|j�t	|j
jtju�t	t
|tj��dS)Nc@r)z/TestCholesky.test_0_size.<locals>.ArraySubclassNrr'r'r'r(r rrrr4)rerr)r#r$rrr�rr�rr�rr-r!rr"rrr'r'r(rs

zTestCholesky.test_0_sizeN)
rLrMrNr�r�r
r#r�rrr=r�rr'r'r'r(rxs��rxcCs�tjdkrd}nd}tjtjfD]9}tjd|d�}|�|�}|�d���}t|j	jd�t
jt
jt
j
fD]}||�}t|||��t|||��q4qdS)N�little�<rIrir4r3�=)�sys�	byteorderr#r�rr:�newbyteorder�byteswaprr-rrrwrnr)�native�dttr��n_arr�sw_arr�routinerr'r'r(�test_byteorder_check0s

��r�r�r�cCslt�ddgddgg�}t�ddgddgg�}t�gd��ddd�}||d<||d<ttjjtjj|�dS)Nrergrhri)ririrgrg.r`)r#rrrrrr)�
invertible�non_invertibler�r'r'r(� test_generalized_raise_multiloopEsr�cCsLd}zt��}Wnttfyt�d�Ynw|dkr�t�d�t�d�ddl}|�|j	d�zt
jj�
�WntyCYntyQt�tj�Ynwzt
�dgg�}t
jj�ddd|d||dd�	Wnty�}zdt|�vr}t�|�WYd}~nd}~wwt�tj�dSt��\}}t�|�|kr�t�d�dSdS)	N�zNot POSIX or fork failed.rrer`rVzDORGQR parameter number 5zNumpy 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_overrideTsF�

��
���r�zCannot start subprocesscCsdddg}t�d�}|D]$}|jdd|d�}t�tjd|g�|jdd|d�}t�tjd|g�qdS)	NzPyQt5.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)
    zimport numpy as np�)�before�after�bad_libz-c)r�r�r�)�textwrap�dedentr �
subprocess�
check_callr��
executable)�bad_libs�templater��coder'r'r(�test_sdot_bug_8577�s
���r�c@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�TestMultiDotc	Csltj�d�}tj�d�}tj�d�}tt|||g�|�|��|��tt|||g�t�|t�||���dS�N�r*rg�rgr*�r#rfrrr)rDrRr�Cr'r'r(�(test_basic_function_with_three_arguments�s
 (z5TestMultiDot.test_basic_function_with_three_argumentscCsNtj�d�}tj�d�}tt||g�|�|��tt||g�t�||��dSr�r�)rDrRrr'r'r(�&test_basic_function_with_two_arguments�sz3TestMultiDot.test_basic_function_with_two_argumentscCs\tj�d�}tj�d�}tj�d�}tj�d�}tt||||g�|�|��|��|��dS)Nr�r��rgrer�)rDrRrr��Dr'r'r(�9test_basic_function_with_dynamic_programming_optimization�s
,zFTestMultiDot.test_basic_function_with_dynamic_programming_optimizationcCsLtj�d�}tj�d�}tj�d�}tj�d�}tt||||g�jd�dS)Nrgr�r�rTr:�r#rfrrr�)rD�A1drr�r�r'r'r(�test_vector_as_first_argument��
z*TestMultiDot.test_vector_as_first_argumentcCsLtj�d�}tj�d�}tj�d�}tj�d�}tt||||g�jd�dS)Nr�r�rg)r*r�)rDrRrr��D1dr'r'r(�test_vector_as_last_argument�r�z)TestMultiDot.test_vector_as_last_argumentcCsLtj�d�}tj�d�}tj�d�}tj�d�}tt||||g�jd�dS)Nrgr�r�r'r�)rDr�rr�r�r'r'r(�&test_vector_as_first_and_last_argument�r�z3TestMultiDot.test_vector_as_first_and_last_argumentc	Cs�tj�d�}tj�d�}tj�d�}t�d�}t|||g|d�}||us&J�t||�|��|��t|t�|t�||���dS)Nr�r��r%�r#rfrrrr)rDrRrr�r%�retr'r'r(�test_three_arguments_and_out�s
z)TestMultiDot.test_three_arguments_and_outcCsdtj�d�}tj�d�}t�d�}t||g|d�}||usJ�t||�|��t|t�||��dS)Nr�r�)r*r*r�r�)rDrRrr%r�r'r'r(�test_two_arguments_and_out�s
z'TestMultiDot.test_two_arguments_and_outcCsztj�d�}tj�d�}tj�d�}tj�d�}t�d�}t||||g|d�}||us-J�t||�|��|��|��dS)Nr�r�r�)r*rer�r�)rDrRrr�r�r%r�r'r'r(�-test_dynamic_programming_optimization_and_out�s
 z:TestMultiDot.test_dynamic_programming_optimization_and_outc	Cstj�d�tj�d�tj�d�tj�d�tj�d�tj�d�g}t�gd�gd�gd	�gd
�gd�gd�g�}tjgd
�gd�gd�gd�gd�gd�gtd�}|d8}t|dd�\}}tt�|dd�dd�f�t�|dd�dd�f��tt�|�t�|��dS)N)��#)r��)r�rz)rzr5)r5�)r�r)r�g��@gþ@g�O�@g�1�@g���@)r�r�g��@g�@gջ@g��@)r�r�r�gp�@g��@g��@)r�r�r�r�g@�@gX�@)r�r�r�r�r�g��@)r�r�r�r�r�r�)rrererhrhrh)rrrgrhrhrh)rrrrhrhrh)rrrrrirz)rrrrrrz)rrrrrrr4reT)�return_costsr�)r#rfr�intrrr`)rD�arrays�
m_expected�
s_expectedr�r�r'r'r(�test_dynamic_programming_logics:





�
�
���z+TestMultiDot.test_dynamic_programming_logiccCs&tttg�ttttj�d�g�dS)Nry)rr�rr#rfrJr'r'r(�test_too_few_input_arrays%sz&TestMultiDot.test_too_few_input_arraysN)rLrMrNr�r�r�r�r�r�r�r�r�r�r�r'r'r'r(r��s
	




r�c@sveZdZej�de�d�dfe�d�dfg�dd��Zej�dd	d
g�dd��Z	ej�d
ddg�dd��Z
dd�ZdS)�
TestTensorinvzarr, ind�rir*rcrgrg�rhrhrgrecCs<tt��tj||d�Wd�dS1swYdS)N��ind)rrr�	tensorinv)rDr�r�r'r'r(�test_non_square_handling,s
"�z&TestTensorinv.test_non_square_handlingz
shape, ind)�rir*rcrhrg)��rcrhrecCsNt�d�}||_tj||d�}|j|d�|jd|�}|j}t||�dS)Nr��r/r�)r#r:r�rr�r)rDr�r�r/�ainvr�actualr'r'r(�test_tensorinv_shape4s
z"TestTensorinv.test_tensorinv_shaper�rr�cCsLt�d�}d|_tt��tj||d�Wd�dS1swYdS)Nr�r�r�)r#r:r�rr�rr�)rDr�r/r'r'r(�test_tensorinv_ind_limitAs


"�z&TestTensorinv.test_tensorinv_ind_limitcCsJt�d�}d|_tj|dd�}t�d�}tt�||d�tj�||��dS)Nr�r�rer�)	r#r:r�rr�rWr�	tensordot�tensorsolve)rDr/r�r0r'r'r(�test_tensorinv_resultJs


"z#TestTensorinv.test_tensorinv_resultN)rLrMrNr�r�r
r#rWr�r�r�r�r'r'r'r(r�*s �
�
�
r�c@sTeZdZej�de�d�dfe�d�dfg�dd��Zej�dgd	��d
d��Z	dS)�TestTensorsolveza, axesr�Nr�)rrgcCsRtt��t�|jdd��}tj|||d�Wd�dS1s"wYdS�Nrgr?)rrr#rWr�rr�)rDr/r@r0r'r'r(r�Us
"�z(TestTensorsolve.test_non_square_handlingr�))rgrhr*)rhririrh)rrhrhrcCsNtjj|�}t�|jdd��}tj�||�}ttj||t	|j�d�|�dSr�)
r#rfr~rWr�rr�rr�r�)rDr�r/r0r�r'r'r(�test_tensorsolve_result^s z'TestTensorsolve.test_tensorsolve_result)
rLrMrNr�r�r
r#rWr�r�r'r'r'r(r�Ss�
�r�cCsTtjddgddggdd�}ttd��t�|�Wd�dS1s#wYdS)Nrer�rgrz�float16r4zunsupported in linalg)r#rrr�rr�)r�r'r'r(�test_unsupported_commontypehs"�r�z,Bad memory reports lead to OOM in ci testingcCsRd}tjd|gtjd�}tjddgtjd�}d|d<t�||�}t|dd�dS)N�rer4)rr�)r#rr�rWrr)r�r/r0r�r'r'r(�test_blas64_dotssr�z*Numpy not compiled with 64-bit BLAS/LAPACKc
	Cs�tj}tjjj}d}d}|}tjddg|d�}tjdg|d�}tjdg|d�}|||||||dd�}t|dd�t|d|�t|d|�t|���}	t	d	|	koZd
k�dS�dS)Nlrer4r�r�infor�r�r�l)
r#rrr��dgeqrfrrr��itemr)
r-�lapack_routiner�r��ldar/�workrj�results�lworkr'r'r(�!test_blas64_geqrf_lwork_smoketest}s
&r�)r*r+)��__doc__r�r�r�r�r�r�r��numpyr#rrrrrrrr	�
numpy.corer
rrr
rr�numpy.linalgrrrrr�numpy.linalg.linalgr�
numpy.testingrrrrrrrrrr�numpy.linalg.lapack_lite�ImportErrorr)r.r5r7r8rPr?rTrfrgr�r�rhr�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr"r'r.r5r8r=rFrGrPrlrqrrrsrtr�r�r�r�r
r�r�r�r�r�r�r�r'r3r4r@rBrCrErFrGrHrWrXrxr�r�r�r�r�r�r�r�r�r�r�r�rkr�r'r'r'r(�<module>s(0�
	�������
�
���#����������������
�
�
�
�
��9��������� 
0


:	$.C�

*4V6;
x$
".
1")

	�