
    J/Phbw                       d dl Z d dlZd dlmZmZ d dlZd dlZd dlmZm	Z	 d dl
Z
d dlZd dl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 ddlmZ d dlZd	 Zd
 Zd Z G d dee          Zd Z d Z!d Z"d Z#d Z$d Z%dLdZ&d Z'dMdZ(d Z)dNdZ*d Z+d Z,dOdZ-dOdZ.dOdZ/d  Z0dPd!Z1d" Z2dOd#Z3d$ Z4 G d% d&ee          Z5 G d' d(e          Z6 G d) d*e5          Z7 G d+ d,e5          Z8 G d- d.e5          Z9 G d/ d0e5          Z: G d1 d2e5          Z; G d3 d4e5          Z< G d5 d6e<          Z= G d7 d8e<          Z> G d9 d:e5          Z? G d; d<e5          Z@ G d= d>e<          ZA G d? d@e5          ZB G dA dBe<          ZC G dC dDe5          ZD G dE dFe5          ZE G dG dHe<          ZF G dI dJe          ZGeHdKk    r ejI                     dS dS )Q    N)productcycle)NumberIntegral)jitnjittypeof)errors)TestCasetagneeds_lapack
needs_blas
_is_armv7lEnableNRTStatsMixin   )matmul_usecasec                 ,    t          j        | |          S Nnpdotabs     W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/tests/test_linalg.pydot2r      s    6!Q<<    c                 0    t          j        | ||          S Noutr   r   r   r!   s      r   dot3r#      s    6!QC    r   c                 ,    t          j        | |          S r   )r   vdotr   s     r   r%   r%          71a==r   c                   f    e Zd ZdZej        ej        ej        ej        fZ	 fdZ
d Zd Zej        d             Zd Zd Zd Zdd
ZddZd Zed             Zed             Zd Zed             Zd Zed             Zed             Zed             Zed             Zed             Z  xZ!S )TestProductz!
    Tests for dot products.
    c                 |    t          j                     t          t          |                                            d S r   )gccollectsuperr(   setUpself	__class__s    r   r-   zTestProduct.setUp&   s0    

k4  &&(((((r   c                     t          j        |          }t          |t           j                  r|dz  dz                       |          S |dz  dz
                      |          S Ny      ?      y               @g      ?r   r   arange
issubclasscomplexfloatingastyper/   ndtypebases       r   sample_vectorzTestProduct.sample_vector+   `     y||eR/00 	2H%*2259993JN**5111r   c                 ^    |                      ||z  |                              ||f          S r   )r<   reshape)r/   mr9   r:   s       r   sample_matrixzTestProduct.sample_matrix4   s.    !!!a%//77A???r   c              #   T  K   t          j        d          5 }t          j        dt          j                   dV  ddd           n# 1 swxY w Y   |                     t          |          d           |                     |d         j        t          j                   | 	                    dt          |d         j                             |                     |d         j        |j        j                   |                     |d         j        |j        j        dz              dS )zB
        Check performance warning(s) for non-contiguity.
        T)recordalwaysNr   r   zfaster on contiguous arrays)warningscatch_warningssimplefilterr
   NumbaPerformanceWarningassertGreaterEquallenassertIscategoryassertInstrmessageassertEqualfilename__code__co_filenamelinenoco_firstlineno)r/   pyfuncws      r   check_contiguity_warningz$TestProduct.check_contiguity_warning7   s8     
 $D111 	Q!(F,JKKKEEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	A***admV%CDDD3S15F5FGGG1(CDDD1fo&Dq&HIIIIIs   $AAAc                     |                                  5   || } || }|                     ||d           ~~d d d            d S # 1 swxY w Y   d S )NTignore_sign_on_zero)assertNoNRTLeakassertPreciseEqual)r/   rV   cfuncargsexpectedgots         r   
check_funczTestProduct.check_funcF   s    !!## 	 	vt}H%,C##Ct#LLLX		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   %AAAc                    |j         dz   |j        z  dz   }|j         |j        z  }t          j        |t          j                  }t          |j        dz             D ]6}||||z                                |j                  }|j        j	        r n7t          d          |j        j        rt          j        ||j        d          }nt          j        ||j        d          }|d d          |d d <   |j        j	        sJ |S )Nr   r:   zCould not obtain aligned arrayCorderF)sizeitemsizer   emptyuint8rangeviewr:   flagsaligned	Exceptionc_contiguousr?   shape)r/   arrri   datasizetmpinews          r   _aligned_copyzTestProduct._aligned_copyN   s    1,q08cl*ht28,,,s|a'(( 	> 	>Aa!h,&',,39,==Cy   <===9! 	8*S#)3777CC*S#)3777CQQQAAAy    
r   c                 d   t           r| j        nt          j        }|                                 5   ||          } ||          }|                      ||d|i|           |                      ||d|i|           |                     ||d           ~~d d d            d S # 1 swxY w Y   d S )Nr!   TrZ   )r   ry   r   copyr\   rK   r]   )r/   rV   r^   r_   r!   copierr`   ra   s           r   check_func_outzTestProduct.check_func_outc   s   '1>##rw!!## 	 	vc{{H&++CMM&&$5H55x@@@MM%%/3//555##Ct#LLLX	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A)B%%B),B)Fc                     |                      t                    5 } ||  d d d            n# 1 swxY w Y   |rdnd}|                     |t          |j                             d S )Nzincompatible output array sizezincompatible array sizes)assertRaises
ValueErrorrM   rN   	exception)r/   r^   r_   is_outraisesmsgs         r   assert_mismatching_sizesz$TestProduct.assert_mismatching_sizesm   s    z** 	fE4LL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	39 *//) 	c3v/0011111s   -11np.dot()c                     |                      t          j                  5 } ||  d d d            n# 1 swxY w Y   |                     |dt	          |j                             d S )Nz' arguments must all have the same dtype)r   r
   TypingErrorrM   rN   r   )r/   r^   r_   	func_namer   s        r   assert_mismatching_dtypesz%TestProduct.assert_mismatching_dtypest   s    v122 	fE4LL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	"%&*++	- 	- 	- 	- 	-s   266c           
         d} t          d          |          }| j        D ]r}|                     ||          }|                     ||          }|                     ||||f           |                     |||d d d         |d d d         f           s|                     |dz
  t          j                  }|                     |t          j                  }|                     |||f           |                     |t          j                  }|                     |t          j                  }|                     |||f|           d S )N   Tnopythonr   )r   )	r   dtypesr<   rb   r   float64r   float32r   )r/   rV   r   r9   r^   r:   r   r   s           r   check_dot_vvzTestProduct.check_dot_vv{   sI   "T"""6**[ 	? 	?E""1e,,A""1e,,AOOFEAq6222OOFEAdddGQtttW+=>>>> q1ubj11q"*--%%eaV444q"*--q"*--&&uq!f	&JJJJJr   c                 <    |                      t          d           dS )z/
        Test vector * vector np.dot()
        r   N)r   r   r/   s    r   test_dot_vvzTestProduct.test_dot_vv   s     
 	$
+++++r   c                 <    |                      t          d           dS )z 
        Test np.vdot()
        z	np.vdot()N)r   r%   r   s    r   	test_vdotzTestProduct.test_vdot   s     
 	$,,,,,r   c                      fd} t          d          |          }| t          d          |          }dD ]\  }} |||          D ]<\  }	}
                     |||	|
f                                |||
|	j        f           =|f |||          D ]Y\  }	}
t          j        ||	j                  }                     |||	|
f|                                |||
|	j        f|           Zd\  }}                     ||dz
  t          j                  }	 	                    |t          j                  }
 
                    ||	|
f            
                    ||
|	j        f           |t          j        |t          j                  } 
                    ||	|
|f            
                    ||
|	j        |f                                ||t          j                  }	 	                    |t          j                  }
t          j        |dz
  t          j                  } 
                    ||	|
|fd            
                    ||
|	j        |fd                                ||t          j                  }	 	                    |t          j                  }
                     ||	|
f|           ||                     ||t          j                  }	 	                    |t          j                  }
t          j        |t          j                  }                     ||	|
|f|           d S d S )	Nc              3   v  K   dD ]]}                     | |t          j                                      |          }                    |t          j                  }||fV  ^j        D ]5}                     | ||          }                    ||          }||fV  6|d d d         |d d d         fV  d S NCFrf   r   )rA   r   r   r{   r<   r   )r@   r9   rg   r   r   r:   r/   s         r   samplesz)TestProduct.check_dot_vm.<locals>.samples   s        &&q!RZ88==E=JJ&&q"*55d



  &&q!U33&&q%00d



DDbD'1TTrT7""""""r   Tr   )   r   )r   r   )r   r   rd   r   r   r   )r   rb   Tr   rk   r:   r}   rA   r   r<   r   r   r   )r/   pyfunc2pyfunc3r   r   cfunc2cfunc3r@   r9   r   r   r!   s   `           r   check_dot_vmzTestProduct.check_dot_vm   sX   
	# 
	# 
	# 
	# 
	# $d###G,,'S$'''00F 	H 	HDAq  1 ; ;1!Q888!QS::::"#GAqMM H HDAq(1AG444C''!QEEE''!QS3GGGG 1q!a%44q"*--%%fq!f555%%fq!#h777(1bj))C))&1a+>>>))&1ac3-@@@""1a44A""1bj11A(1q5"*--C))&1a+d)KKK))&1ac3-)MMMq!RZ00q"*--&&v1vyAAA""1a44A""1bj11A(1bj))C**6Aq#;	JJJJJ	 r   c                 H    |                      t          t          d           dS )zC
        Test vector * matrix and matrix * vector np.dot()
        r   N)r   r   r#   r   s    r   test_dot_vmzTestProduct.test_dot_vm   "    
 	$j11111r   c                 <     fd} t          d          |          }| t          d          |          }dD ]\  }}}	 ||||	          D ]A\  }
}                     |||
|f                                |||j        |
j        f           B| ||||	          D ]}\  }
}t          j        ||f|
j                  }                     |||
|f|           t          j        ||f|
j                  }                     |||j        |
j        f|           ~d\  }}}	                     ||	dz
  t          j                  }
                     |	|t          j                  } 	                    ||
|f           |t          j        ||ft          j                  } 	                    ||
||f                                ||	t          j                  }
                     |	|t          j                  }t          j        ||dz
  ft          j                  } 	                    ||
||fd                                ||	t          j
                  }
                     |	|t          j                  }                     ||
|f|           |                     ||	t          j                  }
                     |	|t          j                  }t          j        ||ft          j
                  }                     ||
||f|           d S d S )	Nc              3     K   t          dd          D ]u\  }}                    | |t          j                                      |          }                    ||t          j                                      |          }||fV  vj        D ]6}                    | ||          }                    |||          }||fV  7|d d d         |d d d         fV  d S r   )r   rA   r   r   r{   r   )	r@   r9   korder_aorder_br   r   r:   r/   s	           r   r   z)TestProduct.check_dot_mm.<locals>.samples   s     $+D$$7$7   &&q!RZ88==G=LL&&q!RZ88==G=LLd



  &&q!U33&&q!U33d



DDbD'1TTrT7""""""r   Tr   )r   r      )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   rd   r   r   r   )r   rb   r   r   rk   r:   r}   rA   r   r   r   r   )r/   r   r   r   r   r   r   r@   r9   r   r   r   r!   s   `            r   check_dot_mmzTestProduct.check_dot_mm   s=   
	# 
	# 
	# 
	# 
	# $d###G,,'S$'''00F 	J 	JGAq!  1a(( = =1!Q888!#qs<<<<"#GAq!,, J JDAq(Aq6999C''!QEEE(Aq6999C''!#qsSIIII 1aq!a%44q!RZ00%%fq!f555(Aq62:..C))&1a+>>>""1a44A""1a44A(Aq1u:rz22C))&1a+d)KKKq!RZ00q!RZ00&&v1vyAAA""1a44A""1a44A(Aq62:..C**6Aq#;	JJJJJ	 r   c                 H    |                      t          t          d           dS )z/
        Test matrix * matrix np.dot()
        r   N)r   r   r#   r   s    r   test_dot_mmzTestProduct.test_dot_mm  r   r   c                 <    |                      t          d           dS )z&
        Test vector @ vector
        '@'N)r   r   r   s    r   test_matmul_vvzTestProduct.test_matmul_vv   s     
 	.%00000r   c                 >    |                      t          dd           dS )z:
        Test vector @ matrix and matrix @ vector
        Nr   )r   r   r   s    r   test_matmul_vmzTestProduct.test_matmul_vm'  "    
 	.$66666r   c                 >    |                      t          dd           dS )z&
        Test matrix @ matrix
        Nr   )r   r   r   s    r   test_matmul_mmzTestProduct.test_matmul_mm.  r   r   c                    d\  }}}t           j        }|                     |||          d d d         }|                     |||          d d d         }t          j        ||f|          } t	          d          t
                    }|                     |j                  5   |||           d d d            n# 1 swxY w Y    t	          d          t                    }|                     |j                  5   ||||           d d d            n# 1 swxY w Y   | 	                    ||          d d d         }| 	                    ||          d d d         } t	          d          t                    }|                     |j                  5   |||           d d d            d S # 1 swxY w Y   d S )Nr   r   Tr   )r   r   rA   rk   r   r   rX   py_funcr#   r<   r%   )	r/   r@   r   r9   r:   r   r   r!   r^   s	            r   test_contiguity_warningsz$TestProduct.test_contiguity_warnings5  s   1a
q!U++DDbD1q!U++DDbD1h1vu%%"T"""4((**5=99 	 	E!QKKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	"T"""4((**5=99 	 	E!Q	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 q%((2.q%((2."T"""4((**5=99 	 	E!QKKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s6   "B;;B?B?>DDDF33F7:F7)F)r   )"__name__
__module____qualname____doc__r   r   r   
complex128	complex64r   r-   r<   rA   
contextlibcontextmanagerrX   rb   ry   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r0   s   @r   r(   r(      s         j"*bmR\BF) ) ) ) )
2 2 2@ @ @ J J J    *  2 2 2 2- - - -K K K& , , Z, - - Z-6K 6K 6Kp 2 2 Z2<K <K <K| 2 2 Z2 1 1 Z1 7 7 Z7 7 7 Z7   Z    r   r(   c                 @    t           j                            |           S r   r   linalginvr   s    r   invert_matrixr   N      9==r   c                 @    t           j                            |           S r   )r   r   choleskyr   s    r   cholesky_matrixr   R      9a   r   c                 @    t           j                            |           S r   )r   r   eigr   s    r   
eig_matrixr   V  r   r   c                 @    t           j                            |           S r   )r   r   eigvalsr   s    r   eigvals_matrixr   Z      9Qr   c                 @    t           j                            |           S r   )r   r   eighr   s    r   eigh_matrixr   ^      9>>!r   c                 @    t           j                            |           S r   )r   r   eigvalshr   s    r   eigvalsh_matrixr   b  r   r   c                 B    t           j                            | |          S r   r   r   svd)r   full_matricess     r   
svd_matrixr   f  s    9==M***r   c                 @    t           j                            |           S r   r   r   qrr   s    r   	qr_matrixr   j  s    9<<??r   r   c                 D    t           j                            | ||          S r   r   r   lstsq)ABrconds      r   lstsq_systemr   n  s    9??1a'''r   c                 B    t           j                            | |          S r   r   r   solve)r   r   s     r   solve_systemr   r  s    9??1a   r   V瞯<c                 @    t           j                            |           S r   r   r   pinv)r   r   s     r   pinv_matrixr   v  r   r   c                 @    t           j                            |           S r   r   r   slogdetr   s    r   slogdet_matrixr   z  r   r   c                 @    t           j                            |           S r   )r   r   detr   s    r   
det_matrixr  ~  r   r   c                 B    t           j                            | |          S r   )r   r   norm)r   ords     r   norm_matrixr    s    9>>!S!!!r   c                 B    t           j                            | |          S r   )r   r   cond)r   ps     r   cond_matrixr	    s    9>>!Qr   c                 B    t           j                            | |          S r   r   r   matrix_rank)r   tols     r   matrix_rank_matrixr    s    9  C(((r   c                 B    t           j                            | |          S r   )r   r   matrix_power)r   r9   s     r   matrix_power_matrixr    s    9!!!Q'''r   c                 ,    t          j        | |          S r   r   trace)r   offsets     r   trace_matrixr    s    8Avr   c                 *    t          j        |           S r   r  r   s    r   trace_matrix_no_offsetr    s    8A;;r   c                 0    t          j        | ||          S r   )r   outerr"   s      r   outer_matrixr    s    8Aqc""""r   c                 ,    t          j        | |          S r   )r   kronr   s     r   kron_matrixr    r&   r   c                        e Zd ZdZej        ej        ej        ej        fZ	 fdZ
d Z	 ddZefdZd Zd Zdd
Zd Zd Zd ZddZd Zd Z xZS )TestLinalgBasezU
    Provides setUp and common data/error modes for testing np.linalg functions.
    c                 |    t          j                     t          t          |                                            d S r   )r*   r+   r,   r   r-   r.   s    r   r-   zTestLinalgBase.setUp  s0    

nd##))+++++r   c                     t          j        |          }t          |t           j                  r|dz  dz                       |          S |dz  dz                       |          S r2   r3   r8   s       r   r<   zTestLinalgBase.sample_vector  r=   r   Nc                    d}t          |          dk    rt          d          |dvrt          d          |t          j        t          j        t          j        t          j        fvrt          d          ||t          d          ||}|d	k     rt          d
          t          j                            d           |\  }}|dk     s|dk     rt          d          t          ||          }	||	}
nP|dk    rt          d          t          |t                    st          d          |}
||	k    rt          d          |d	k    s|d	k    rQ||k    rt          d          t          ||          }|                     ||                              ||          }na|                     ||z  |                              ||          }t          j                            |          \  }}|                     ||z  |          ddd                             ||          }t          j                            |          \  }}t          j        |||
          }t          j        ||f          }t          j        t          j        ||                    }|||d         d|
         |d	         d|
         f<   t          j        t          j        ||          |j                  }t          j        |||          }|S )a  
        Provides a sample matrix with an optionally specified rank or condition
        number.

        size: (rows, columns), the dimensions of the returned matrix.
        dtype: the dtype for the returned matrix.
        order: the memory layout for the returned matrix, 'F' or 'C'.
        rank: the rank of the matrix, an integer value, defaults to full rank.
        condition: the condition number of the matrix (defaults to 1.)

        NOTE: Only one of rank or condition may be set.
              ?r   size must be a length 2 tuple.)rh   re    order must be one of 'F' or 'C'.*dtype must be a numpy floating point type.N/Only one of rank or condition can be specified.r   Condition number must be >=1.r   +Negative dimensions given for matrix shape.Rank must be greater than zero.Rank must an integer."Rank given greater than full rank.8Condition number was specified for a vector (always 1.).r   r:   rg   )rJ   r   r   r   r   r   r   randomseedmin
isinstancer   maxr<   r?   r   r   linspacezerosnonzeroeyer   r   array)r/   ri   r:   rg   rank	conditiond_condr@   r9   minmnrvmaxmnQrv   U_VsvSidxs                       r   specific_sample_matrixz%TestLinalgBase.specific_sample_matrix  s     t99>>=>>>
""?@@@RZr}MMMIJJJ	 5NOOOIq==<===
	q1q55AEEJKKKAq		<BBqyy !BCCCdH-- : !8999Be|| !EFFF66Q!VV F"" NP P P1IIE""5%0088A>>AA $$QUE22::1a@@C9<<$$DAq$$QUE2244R48@@AFFC9<<$$DAqVY33B!Q  A*RVAq\\**C*,Ac!fSbSk3q6#2#;&'rva||QS))A%u555Ar   c                     |                      |          5 } ||  d d d            n# 1 swxY w Y   |                     |t          |j                             d S r   )r   rM   rN   r   )r/   r^   r_   r   errr   s         r   assert_errorzTestLinalgBase.assert_error  s    s## 	vE4LL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	c3v/0011111s   (,,c                 X    d}|                      |||t          j        j                   d S )Nz.Last 2 dimensions of the array must be square.rJ  r   r   LinAlgErrorr/   r^   r_   r   s       r   assert_non_squarez TestLinalgBase.assert_non_square  s,    >%sBI,ABBBBBr   c                 T    d|z  }|                      |||t          j                   d S )Nz9np.linalg.%s() only supported on float and complex arraysrJ  r
   r   r/   namer^   r_   r   s        r   assert_wrong_dtypez!TestLinalgBase.assert_wrong_dtype  s/    IDP%sF,>?????r   Tc                 f    |rdnd}|d|d}|                      |||t          j                   d S )N	np.linalgr   .z() only supported on 2-D arraysrQ  r/   rS  r^   r_   	la_prefixprefixr   s          r   assert_wrong_dimensionsz&TestLinalgBase.assert_wrong_dimensions  sE     )3t8>E%sF,>?????r   c                 X    d}|                      |||t          j        j                   d S )Nz$Array must not contain infs or NaNs.rL  rN  s       r   assert_no_nan_or_infz#TestLinalgBase.assert_no_nan_or_inf  s,    4%sBI,ABBBBBr   c                    t          |t                    r|D ]}|                     ||           dS t          |t                    s|j        j        }|j        j        }d}|                     ||z  |           d}|dk    r|                     ||           dS |dk    r|                     ||           dS t          d          dS )a6  
        This checks that in a computed result from numba (array, possibly tuple
        of arrays) all the arrays are contiguous in memory and that they are
        all at least one of "C_CONTIGUOUS" or "F_CONTIGUOUS". The computed
        result of the contiguousness is then compared against a hardcoded
        expected result.

        got: is the computed results from numba
        expected_contig: is "C" or "F" and is the expected type of
                        contiguousness across all input values
                        (and therefore tests).
        z6Results are not at least one of all C or F contiguous.z0Computed contiguousness does not match expected.re   rh   zUnknown contigN)	r3  tupleassert_contig_sanityr   ro   rr   f_contiguous
assertTruer   )r/   ra   expected_contigr   c_contigf_contigr   s          r   r`  z#TestLinalgBase.assert_contig_sanity"  s     c5!! 	7 > >))!_====> > c6** 79191 O8 3S999H"c))OOHc22222$++OOHc22222$%5666!7 7r   c                 Z    d}|                      |||t          j        j                   d S )Nz(Matrix is singular to machine precision.rI  rL  rN  s       r   assert_raise_on_singularz'TestLinalgBase.assert_raise_on_singularG  s/    8%s	0EFFFFFr   c                 L   |                      |j        d         |j        d                    t          j        |j        d         |j                  }dt          j        |j                  j        z  }|d|z  }|d|z  }t          j                            ||||           dS )zE
        Checks if a matrix is equal to the identity matrix.
        r   rd      N
   d   )	rP   rs   r   r8  r:   finfo
resolutiontestingassert_allclose)r/   ra   rtolatolr8  ro  s         r   assert_is_identity_matrixz(TestLinalgBase.assert_is_identity_matrixK  s    
 	2	"666fSYr]#)444#),,77
<
?D<#D

""3T488888r   c                 D    d}|                      |||t                     dS )z5
        For use in norm() and cond() tests.
        z Invalid norm order for matrices.N)rJ  r   rN  s       r   assert_invalid_norm_kindz'TestLinalgBase.assert_invalid_norm_kind[  s)     1%sJ77777r   c                 X    d}|                      |||t          j        j                   d S )NzArrays cannot be emptyrL  rN  s       r   assert_raise_on_emptyz$TestLinalgBase.assert_raise_on_emptyb  s,    &%sBI,ABBBBBr   )NNT)r   r   r   r   r   r   r   r   r   r   r-   r<   rG  r   rJ  rO  rT  r[  r]  r`  rh  rt  rv  rx  r   r   s   @r   r   r     sJ        
 j"*bmR\BF, , , , ,
2 2 2 <@R R R Rh 2< 2 2 2 2
C C C@ @ @@ @ @ @
C C C#7 #7 #7JG G G9 9 9 9 8 8 8C C C C C C Cr   r   c                       e Zd ZdZd ZdS )TestTestLinalgBasez
    The sample matrix code TestLinalgBase.specific_sample_matrix()
    is a bit involved, this class tests it works as intended.
    c                     t          d          g d}t          |j        d          D ]\  }}}|\  }}t          ||          }                    |||          }                     |j        |                                t          j        	                    |          |           |dk    rl|dz
  }	                    ||||	          }                     |j        |                                t          j        	                    |          |	           dt          j
        |          j        z  }
                    |||          }                     |j        |           t          j                            t          j                            |          d|
|
           |dk    rvd	}                    ||||
          }                     |j        |           t          j                            t          j                            |          d	|
|
           t          f fd	}                     t"                    5 }d} |dt          j        df|t                     d d d            n# 1 swxY w Y   d} |dt          j        df|t                     d} |dt          j        df|t                     d} |dt          j        df|t                     d} |dt          j        dddf|t                     d} |dt          j        dd df|t                     d} |dt          j        df|t                     d} |dt          j        ddf|t                     d} |dt          j        ddf|t                     d} |dt          j        dd df|t                     d } |dt          j        dd!f|t                     d S )"NrG     r      rk  rk  r  r   r   r   r  FCr   r:  rk  r$  rr  rs        $@r;  c                                          |          5 } j        |   d d d            n# 1 swxY w Y                       |t          |j                             d S r   )r   rG  rM   rN   r   )r_   r   rI  r   instr/   s       r   check_errorzCTestTestLinalgBase.test_specific_sample_matrix.<locals>.check_error  s    ""3'' 36++T223 3 3 3 3 3 3 3 3 3 3 3 3 3 3MM#s6#34455555s   .22blankr   rh   rg  r%  r   r&  zr'  r(  r)  r   r*  )r   r+  r-  r   r.  )r   r   rl  r,  g      ?)r   r   r   r2  rG  rP   rs   r   r   r  rn  ro  rp  rq  r  r   r   AssertionErrorr   int32)r/   sizesri   r:   rg   r@   r9   r=  r   r:  ro  r;  r  r   r   r  s   `              @r   test_specific_sample_matrixz.TestTestLinalgBase.test_specific_sample_matrixm  s    677::: #*%d"C"C $	< $	<D%DAq1IIE ++D%??AQWd+++RY22155u=== qyyqy//eU/NN  $///  !6!6q!9!94@@@RXe__77J ++D%??AQWd+++J&&ry~~a'8'8'),6,6 ' 8 8 8 qyy	//%) 0 = =  $///
**29>>!+<+<+.0:0: + < < < (2 	6 	6 	6 	6 	6 	6 	6 ~.. 	H&CKS13JGGGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H /T2:s+SjAAAA 1VRZ-s
CCCC ;VRXs+SjAAAA @VRZa3SjIIII .VRZdB7*MMMM <Wbj#.DDDD 0VRZb13JGGGG 3VRZa0#:FFFF IVRZdB7*MMMM &VRZc2CZHHHHHHs   #JJJN)r   r   r   r   r   r   r   r{  r{  g  s7         
aI aI aI aI aIr   r{  c                   >    e Zd ZdZed             Zed             ZdS )TestLinalgInvz"
    Tests for np.linalg.inv.
    c                 r    d} t          d          t                     fd}t           j        d          D ])\  }}                     ||f||          } ||           * |t          j        d                                          t          j        d          f            	                    dt          j        d	t
          j
        
          f                                dt          j        d          f                                t          j        d	          f           dS )z$
        Test np.linalg.inv
        rl  Tr   c                    t          |           } |           }                    |d           d}	 t          j                            ||d           n# t
          $ r d}Y nw xY w|r*t          j        ||           }                    |                                           5   |            d d d            d S # 1 swxY w Y   d S )Nrh   Frl  nulpT)	r   r`  r   rp  assert_array_almost_equal_nulpr  r   rt  r\   )r   kwargsr`   ra   use_reconstructionrecr^   r/   s         r   checkz,TestLinalgInv.test_linalg_inv.<locals>.check  sF   $Q''H%((C%%c3///!&*
99#x?A : C C C C! * * *%)"""* " 4fS!nn..s333 %%''  a                 s#   "A A'&A'*CC
Cr   r   r   r   r   r   r   rd   N)r   r   r   r   rG  r   rk   rO  onesrT  r  r[  rh  r6  )r/   r9   r  r:   rg   r   r^   s   `     @r   test_linalg_invzTestLinalgInv.test_linalg_inv  sT   
 "T"""=11	 	 	 	 	 	. $DK66 	 	LE5++QFE5AAAE!HHHH 	bhv 	urwv&8999 	u!#rx!@!@!@ B	D 	D 	D 	$$UEBGBKK>BBB 	%%ebhv.>.>-@AAAAAr   c                    t          j        g dg dg dg dgd          }t          j        |          }t          d          d	             }|                    |d
          }t           j                            ||            ||d
          }t           j                            ||           t           j                            ||           d S )Nr$  r   r   r  r   r   r   	   r  r   r   r   rj  r      rh   rf   Tr   c                 `    |r| ddd d f         } t           j                            |           S Nr   r   r   Xtests     r   ainvz2TestLinalgInv.test_no_input_mutation.<locals>.ainv  3     ac111fI9==###r   Fr   r9  r{   r   r   rp  rq  )r/   r  X_origr  r`   ra   s         r   test_no_input_mutationz$TestLinalgInv.test_no_input_mutation	  s    Hnnn$nn$nn$nn& .12 2 2
 	d				$ 	$ 
		$ <<5))

""1f---d1enn

""1f---

""8S11111r   N)r   r   r   r   r   r  r  r  r   r   r  r    sX          0B 0B \0Bd 2 2 \2 2 2r   r  c                   4    e Zd ZdZd Zd Zed             ZdS )TestLinalgCholeskyz'
    Tests for np.linalg.cholesky.
    c                    t           j                            d           t           j                            ||          }t           j                            |          \  }}t          j        d|dz             }t          j        t          j        |j        t          j	        |                    |          }t          j
        |||          }|S )Nr   r   r/  )r   r0  r1  randr   r   r4   r   r   diagr9  )	r/   r@   r:   rg   r   qrB  Lr@  s	            r   rA   z TestLinalgCholesky.sample_matrix'  s    
	qINN1a   y||A1IaQF26!#rwqzz**A..HQe5111r   c                 X    d}|                      |||t          j        j                   d S )Nz Matrix is not positive definite.rL  rN  s       r   assert_not_pdz TestLinalgCholesky.assert_not_pd3  s,    0%sBI,ABBBBBr   c                     d} t          d          t                     fd}t           j        d          D ]'\  }}                     |||          } ||           ( |t          j        d                     d}                     t          j        dt
          j	        	          f            
                    |t          j        d
t
          j        	          f                                |t          j        dt
          j	        	          f                                t          j        dt
          j	        	                              dd          f           dS )z)
        Test np.linalg.cholesky
        rl  Tr   c                 ,   t          |           } |           }d}                    |d           	 t          j                            ||d           n# t
          $ r d}Y nw xY w|rpt          j        |t          j        |j                            }dt          j	        | j
                  j        z  }t          j                            | |||                                           5   |            d d d            d S # 1 swxY w Y   d S )NFre   rl  r  Trk  r  )r   r`  r   rp  r  r  r   conjr   rn  r:   ro  rq  r\   )r   r`   ra   r  r  ro  r^   r/   s         r   r  z6TestLinalgCholesky.test_linalg_cholesky.<locals>.check?  s   &q))H%((C!&%%c3///*
99#x?A : C C C C! * * *%)"""*
 " fS"'#%..11!'!2!2!==

**##	 +    %%''  a                 s#   "A A'&A'0D		DDr  r  r   r   rd   r  r   r   N)r   r   r   r   rA   r   rk   rO  r  r   rT  r  r[  r  r?   )r/   r9   r  r:   rg   r   rnr^   s   `      @r   test_linalg_choleskyz'TestLinalgCholesky.test_linalg_cholesky7  s   
 "T"""?33	 	 	 	 	 	< $DK66 	 	LE5""1eU33AE!HHHH 	bhvurwvRZ'H'H'H&JKKK 	E!#rx!@!@!@ B	D 	D 	D 	$$R&(gb
&C&C&C%E	G 	G 	G 	5GARZ888@@AFFH	J 	J 	J 	J 	Jr   N)r   r   r   r   rA   r  r   r  r  r   r   r  r  "  s_         
 
 
C C C :J :J \:J :J :Jr   r  c                       e Zd ZdZd Zd Zd Z	 ddZed             Z	ed             Z
ed	             Zed
             Zed             ZdS )TestLinalgEigenSystemsz*
    Tests for np.linalg.eig/eigvals.
    c                    |                      ||          }t          j        |          }t          j        t          j        |j        d         |j        d         d                    }|dd          ||<   t          j        t          j        |j        d         |j        d         d                    }|d d         ||<   t          j        |||          }|S )Nr   r   r   r/  )r<   r   r  r7  r8  rs   r9  )r/   r@   r:   rg   vr@  rF  s          r   rA   z$TestLinalgEigenSystems.sample_matrixz  s    q%((GAJJj
AGAJ::;;122#j
AGAJ;;<<3B3#HQe5111r   c                 >    |dz   }|                      |||           d S )Nz+() argument must not cause a domain change.)rJ  rR  s        r   assert_no_domain_changez.TestLinalgEigenSystems.assert_no_domain_change  s+    BB%s+++++r   c                       fd}|S )Nc                      j         |  } |  }| d         }                    t          |          t          |                     d}t          |t                    r&d}                    t          |                     n                    |j                                       |d           d}t          t          |                    D ]C}	 t          j	        
                    ||         ||         d           2# t          $ r d}Y @w xY wdt          j        |j                  j        z  }|r|r|\  }}	d         d	k    rt          j        t          j        |j        d         |j        d
         d                    }
t          j        t          j        |j        d         |j        d
         d
                    } |   t          j        ||
                   ||<   t          j        t          j        |                    |t          j        |j        d                   <   t          j        ||	          }t          j        |	t          j        |                    }t          j	                            |j        |j        ||           t          j        |	          r-t          j	                            |j        |j        ||           nGt          j	                            t          j        |          t          j        |          ||                                           5   |   d d d            d S # 1 swxY w Y   d S )Nr   FTrh   rl  r  rk  r   hr   r  )r   rP   rJ   r3  r_  ndimr`  rm   r   rp  r  r  rn  r:   ro  r7  r8  rs   r  realr  diag_indicesr   rq  iscomplexobjimagsortr\   )r_   r`   ra   r   res_is_tupler  r   ro  rW   r  idxlidxulhsrhsr^   expected_res_lenrS  r/   s                 r   r  z3TestLinalgEigenSystems._check_worker.<locals>.check  sz   $u}d+H%,CQAS]]CHH555 L#u%% =#  S+;<<<<  +;<<< %%c3///!&3x==)) . ..J==A" > 6 6 6 6% . . .)-&&&. RXag..99J! 1 0DAq Bx3!z"&QWQZ*L*LMM!z"&QWQZ*K*KLLt #%'!D'"2"2$ :<9L9L"/!'!*556&A,,C&BGAJJ//CJ..''	 /    q)) 
22HH!+!+	 3    J..))''	 /    %%''  t                 s$   .DDD;MMMr  )r/   r^   rS  r  check_for_domain_changer  s   ````  r   _check_workerz$TestLinalgEigenSystems._check_worker  s>    [	 [	 [	 [	 [	 [	 [	 [	x r   Nc           	         d} t          d          |          }|                     ||||          }t          | j        d          D ]'\  }}	|                     |||	          }
 ||
           (t
          j        t
          j        fD ]} |t          j        d|                     | 	                    |t          j
        d|          f           |                     ||t          j
        dt
          j                  f           |                     ||t          j
        d|          f           |                     |t          j        d	d
gt
          j        t
          j        gg|          f           |rt          j        ddgddgg          } ||                    t
          j                              ||          \  }}|                     t          j        |j                             t
          j        t
          j        fD ]/}|                     |||                    |          f           .dS dS )z$
        Test np.linalg.eig
        rl  Tr   r  r  rd   r   r  r$         @r   rj  r   N)r   r  r   r   rA   r   r   r   rk   rO  r  rT  r  r[  r]  r9  infnanr7   r   rb  anyr  r   r  )r/   rS  funcr  r  r9   r^   r  r:   rg   r   tyr   lrB  s                  r   checker_for_linalg_eigz-TestLinalgEigenSystems.checker_for_linalg_eig  sr   
 "T"""4((""5$0@#:< <
 $DK66 	 	LE5""1eU33AE!HHHH :r|, 	= 	=B E"(6,,,--- ""5276+D+D+D*FGGG ##D%%'WV28%D%D%D$FH H H ((urwr7L7L7L6NOOO %%e')x"bbfbf=M0N68(: (: (: '<= = = = # 	K 1b'Aq6*++AE!((2=))***477DAqOOBF16NN+++ z2:. K K,,T5188B<</JJJJ/	K 	K,K Kr   c                 @    |                      dt          dd           d S )Nr   r   T)r  r   r   s    r   test_linalg_eigz&TestLinalgEigenSystems.test_linalg_eig'  s"    ##E:q$?????r   c                 @    |                      dt          dd           d S )Nr   r   T)r  r   r   s    r   test_linalg_eigvalsz*TestLinalgEigenSystems.test_linalg_eigvals+  s"    ##I~q$GGGGGr   c                 @    |                      dt          dd           d S )Nr   r   F)r  r   r   s    r   test_linalg_eighz'TestLinalgEigenSystems.test_linalg_eigh/  s"    ##FKEBBBBBr   c                 @    |                      dt          dd           d S )Nr   r   F)r  r   r   s    r   test_linalg_eigvalshz+TestLinalgEigenSystems.test_linalg_eigvalsh3  s"    ##JEJJJJJr   c           
         dD ]E}|\  }}}t          t          j        |          t          d          fd            }|                     ||||          }t          j        t          j        fD ]}|                     |          5  t          j        g dg dg dg d	gd
|          }t          j	        |          }	|
                    |d          }
t          j                            ||	            ||d          }t          j                            ||	            ||d           d d d            n# 1 swxY w Y   אGd S )N))r   r   T)r   r   T)r   r   F)r   r   FTr   c                 :    |r| ddd d f         }  |           S r  r  )r  r  meths     r   r  z;TestLinalgEigenSystems.test_no_input_mutation.<locals>.funcD  s-     "!A#qqq&	AtAwwr   )r  r:   )r  r   r   r   )r   r  r   r   )r   r   r  r   )r   r   r   r  rh   )rg   r:   F)getattrr   r   r   r  r   r   subTestr9  r{   r   rp  rq  )r/   cr@   noutdomain_changer  r  r:   r  r  r`   ra   r  s               @r   r  z-TestLinalgEigenSystems.test_no_input_mutation7  s   * $	$ $	$A
 &'"At]29a((D$      &&tQmDDE*bm4 $ $\\t5\99 $ $ ... , , ,"" *-E	; ; ;A  WQZZF#||Au55HJ..q&999$q%..CJ..q&999E!UOOO#$ $ $ $ $ $ $ $ $ $ $ $ $ $ $$%$	$ $	$s   B&D==EEr   )r   r   r   r   rA   r  r  r  r   r  r  r  r  r  r  r   r   r  r  u  s        	 	 	, , ,^ ^ ^B IM<K <K <K <K| @ @ \@ H H \H C C \C K K \K '$ '$ \'$ '$ '$r   r  c                   D    e Zd ZdZd Zed             Zed             ZdS )TestLinalgSvdz"
    Tests for np.linalg.svd.
    c                    |\  }}}t          t          |                    D ].}|                     ||         j        ||         j                   /t	          j        |j        d         |j        d         f          }t	          j        ||           t	          j        t	          j        ||          |          }	t	          j        |j	                  j
        }
t          j                            ||	d|
z  d|
z             d S )Nr   r   rl  rm  r  )rm   rJ   rP   rs   r   r6  fill_diagonalr   rn  r:   ro  rp  rq  )r/   r   ra   r`   urD  vtr   sr  ro  s              r   check_reconstructionz"TestLinalgSvd.check_reconstructionm  s    	2r s8}}%% 	> 	>ASV\8A;+<==== Hagaj"(1+.//
BfRVAq\\2&&Xag&&1


""jz!	 	# 	
 	
 	
 	
 	
r   c                      t          d          t                     fd}g d}d}t          | j        |d          D ]+\  }}}}                     |||          } |||           ,d}	                     |	t          j        d	t          j        
          f            	                    |	t          j        dt          j
        
          f                                t          j        ddgt          j        t          j        ggt          j
        
          f           dD ].}
t          j        |
          df}                     |           /dS )z$
        Test np.linalg.svd
        Tr   c                 h   t          | fi |} | fi |}                    t          |          t          |                                         t          |          d                               |d           d}t	          t          |                    D ]C}	 t
          j                            ||         ||         d           2# t          $ r d}Y @w xY w|r	                    | ||           
                                5   | fi | d d d            d S # 1 swxY w Y   d S )Nr   rh   Frl  r  T)r   rP   rJ   r`  rm   r   rp  r  r  r  r\   )r   r  r`   ra   r  r   r^   r/   s         r   r  z,TestLinalgSvd.test_linalg_svd.<locals>.check  s   !!..v..H%$$V$$CS]]CHH555SXXq)))%%c3///!&3x==)) . ..J==A" > 6 6 6 6% . . .)-&&&. " <))!S(;;; %%'' # #a""6"""# # # # # # # # # # # # # # # # # #s$   ".CC C 
D''D+.D+)r~  )r  rk  )rk  r  r  r  )TFr  )r   r   r  rd   rl  r$  r  r   r   r   r   r  N)r   r   r   r   rG  rT  r   r  r  r[  r   r]  r9  r  r  rk   rx  )r/   r  r  r   ri   r:   fmatrg   r   r  szr_   r^   s   `           @r   test_linalg_svdzTestLinalgSvd.test_linalg_svd  s   
 #T""":..	# 	# 	# 	# 	# 	#< 988 & t{M4@@	) 	)$D%u ++D%??AE!4((((( 	E!#rx!@!@!@ B	D 	D 	D 	$$R&(gb
&C&C&C%E	G 	G 	G 	!!%#%8b"Z"&"&9I,J24*$> $> $> #@	A 	A 	A + 	4 	4BHRLL$'D&&ud3333	4 	4r   c                 &   t          j        g dg dg dg dgd          }t          j        |          }t          d          d	             }|                    |d
          }t           j                            ||            ||d
          }t           j                            ||           	 t          ||          D ]%\  }}t           j                            ||           &d S # t          $ r | 	                    |||           Y d S w xY w)Nr  r  r  r  rh   rf   Tr   c                 `    |r| ddd d f         } t           j                            |           S r  r   r  s     r   r  z2TestLinalgSvd.test_no_input_mutation.<locals>.func  r  r   F)
r   r9  r{   r   r   rp  rq  zipr  r  r/   r  r  r  r`   ra   e_ag_as           r   r  z$TestLinalgSvd.test_no_input_mutation  sH   Hnnn$nn$nn$nn& .12 2 2
 	d				$ 	$ 
		$ <<5))

""1f---d1enn

""1f---	8#.. 5 5S
**344445 5 	8 	8 	8%%ah777777	8s   36C+ +!DDN)r   r   r   r   r  r   r  r  r  r   r   r  r  b  sg         
 
 
( A4 A4 \A4F 8 8 \8 8 8r   r  c                   >    e Zd ZdZed             Zed             ZdS )TestLinalgQrz!
    Tests for np.linalg.qr.
    c                    	  t          d          t                    		 fd}g d}t          | j        d          D ](\  }}}                     |||          } ||           )d}                     |	t          j        dt          j                  f            	                    |	t          j        d	t          j
                  f                                	t          j        d
dgt          j        t          j        ggt          j
                  f           dD ]+}                     	t          j        |          f           ,dS )z#
        Test np.linalg.qr
        Tr   c                    t          | fi |} 
| fi |}                    t          |          t          |                                         t          |          d                               |d           d}t	          t          |                    D ]C}	 t
          j                            ||         ||         d           2# t          $ r d}Y @w xY w|r|\  }}t	          t          |                    D ].}                    ||         j	        ||         j	                   /t          j
        ||          }t          j        | j                  j        }	t
          j                            | |d|	z  d|	z                                 t          j
        t          j        |j                  |                                                     5   
| fi | d d d            d S # 1 swxY w Y   d S )	Nr   rh   Frl  r  Trm  r  )r   rP   rJ   r`  rm   r   rp  r  r  rs   r   rn  r:   ro  rq  rt  	conjugater   r\   )r   r  r`   ra   r  r   r  rr  ro  r^   r/   s             r   r  z*TestLinalgQr.test_linalg_qr.<locals>.check  sy    --f--H%$$V$$C S]]CHH555SXXq)))%%c3///!&3x==)) . ..J==A" > 6 6 6 6% . . .)-&&&. " M1 s8}}-- F FA$$SV\8A;3DEEEE fQllXag..9

**jz)	 +    ..rvbl136G6G/K/KLLL %%'' # #a""6"""# # # # # # # # # # # # # # # # # #s$   ".CC C $
G;;G?G?r}  r  r   r  rd   rl  r$  r  r  N)r   r   r   r   rG  rT  r   r  r  r[  r   r]  r9  r  r  rx  rk   )
r/   r  r  ri   r:   rg   r   r  r  r^   s
   `        @r   test_linalg_qrzTestLinalgQr.test_linalg_qr  s   
 #T"""9--3	# 3	# 3	# 3	# 3	# 3	#n ;:: t{D11	 	D%++D%??AE!HHHH 	E!#rx!@!@!@ B	D 	D 	D 	$$R&(gb
&C&C&C%E	G 	G 	G 	!!%#%8b"Z"&"&9I,J24*$> $> $> #@	A 	A 	A
 + 	? 	?B&&urx||o>>>>	? 	?r   c                    t          j        g dg dg dg dgd          }t          j        |          }t          d          d	             }|                    |d
          }t           j                            ||            ||d
          }t           j                            ||           t          ||          D ]%\  }}t           j                            ||           &d S )Nr  r  r  r  rh   rf   Tr   c                 `    |r| ddd d f         } t           j                            |           S r  r   r  s     r   r  z1TestLinalgQr.test_no_input_mutation.<locals>.funcI  s1     ac111fI9<<??"r   F)r   r9  r{   r   r   rp  rq  r  r  s           r   r  z#TestLinalgQr.test_no_input_mutation@  s   Hnnn$nn$nn$nn& .12 2 2
 	d				# 	# 
		# <<5))

""1f---d1enn

""1f---Hc** 	1 	1HCJ&&sC0000	1 	1r   N)r   r   r   r   r   r  r  r  r   r   r  r    sX          V? V? \V?p 1 1 \1 1 1r   r  c                   &    e Zd ZdZddZd Zd ZdS )TestLinalgSystemszu
    Base class for testing "system" solvers from np.linalg.
    Namely np.linalg.solve() and np.linalg.lstsq().
    Tc                 f    |rdnd}|d|d}|                      |||t          j                   d S )NrV  r   rW  z%() only supported on 1 and 2-D arraysrQ  rX  s          r   assert_wrong_dimensions_1Dz,TestLinalgSystems.assert_wrong_dimensions_1Da  sE     )3t>DffdddK%sF,>?????r   c                 X    d}|                      |||t          j        j                   d S )Nz<Incompatible array sizes, system is not dimensionally valid.rL  rN  s       r   assert_dimensionally_invalidz.TestLinalgSystems.assert_dimensionally_invalidg  s,    L%sBI,ABBBBBr   c                 T    d|z  }|                      |||t          j                   d S )NzAnp.linalg.%s() only supports inputs that have homogeneous dtypes.rQ  rR  s        r   assert_homogeneous_dtypesz+TestLinalgSystems.assert_homogeneous_dtypesl  s0    QTXX%sF,>?????r   Nry  )r   r   r   r   r  r  r  r  r   r   r  r  Z  s\         @ @ @ @C C C
@ @ @ @ @r   r  c                   >    e Zd ZdZed             Zed             ZdS )TestLinalgLstsqz$
    Tests for np.linalg.lstsq.
    c                      t          d          t                     fdg d}t           j                  }ddg}t          |          d} fd}|D ]}t	          |          }t	                    }                     |||          }	 ||	|           |\  }
}t          |
|          }|
d	k    ra|d	k    r[|d	z
  }                     ||||
          }	 ||	|                                ||||          }	d|z  }||z  } ||	||           ddgddgddgddgg}|D ]C\  }	}t          j        |	          t          j        |          f} 	                    |           Dt          j
        ddgddggt          j                  }||ff d}t          j
        d	dgddggt          j                  }                     |||f                                |||f           t          j
        d	dgddggt          j                  }                     |||f                                |||f           t          j
        d	dgt          j                  }                     |||f           t          j
        ddgt          j        t          j        ggt          j                  }                     ||f                                ||f           t          j
        ddgt          j                  }||ff t          j
        d	dgddggddgddgggt          j                  }                     |||f           t          j
        dgt          j                  }t          j
        dgdgdggt          j                  }                     ||f                                ||f           dS ) z&
        Test np.linalg.lstsq
        Tr   c           
      6   t          | |fi |} | |fi |}                    t          |          t          |                                         t          |          d                               |d           d}	                     |d         |d                    t	          t          |                    D ]C}	 t
          j                            ||         ||         d           2# t          $ r d}Y @w xY wn# t          $ r d}Y nw xY w|rD|\  }}}	}
g d}	                     |	|d                    |D ]N}t          ||         t
          j
                  r,                    ||         j        ||         j                   On?# t          $ r2                     t          |	|d         z
            dk                Y nw xY wt          j        | j                  j        }	 t          j        | |          }t
          j                            ||d|z  d|z  	           n,# t          $ r |D ]}	 t
          j                            ||         ||         d
|z  d
|z  	           nK# t          $ r> t
          j                            |           }                    d|z  d|z             Y nw xY wt
          j                            |t          j        | |d                   z
            }t
          j                            |t          j        | |          z
            }t
          j                            ||d           Y nw xY w                                5   | |fi | d d d            d S # 1 swxY w Y   d S )Nr   re   Fr   rl  r  T)r   r   r   r  rm  r$  r   r  rr  )r   rP   rJ   r`  rm   r   rp  r  r  r3  ndarrayrs   rb  absrn  r:   ro  r   rq  r   r  assertGreaterr  r\   )r   r   r  r`   ra   r  r   xresr:  r  out_array_idxro  r  r  res_expectedres_gotr^   r/   s                    r   r  z0TestLinalgLstsq.test_linalg_lstsq.<locals>.check  s   #Aq33F33H%1''''C S]]CHH555SXXq)))%%c3///!&
*  Q!555s8}}-- 2 2A2
AAFHQKb B : : : :) 2 2 2-1***2	2 " * * *%)"""* " 7="%3a !*			A$$T8A;777* N N%hqk2:>> N ,,SV\8A;;LMMMN & A A AOOCx{(:$;$;a$?@@@@@A
  Xag..9
$= &A,,CJ..*_*_	 /     & = = = + = =
JJ66 ( #A%(:%5%(:%5	 7      . J J J "	q 1 1A ..rAvZIIIIIJ (*y~~q(1+ 6 66(8 (8"$)..RVAq\\1A"B"B 
22(' 3 = = = =+= =	=: %%'' & &a%%f%%%& & & & & & & & & & & & & & & & & &s   A D	 .C65D	 6DD	 DD	 	DD*A-F 9GG6>H6 6M5I=<M=AKMKBMM6NNNr}  rh   re   r  c                    d}|D ]x}t          	          }
                    | j        d         |f||          } | |fi | t          	          }|d d df                             |          } | |fi | yd S )Nr      r   rf   )nextrG  rs   r{   )r   dtr  b_sizesb_sizeb_orderr   rv   r  cycle_orderr/   s           r   inner_test_loop_fnz=TestLinalgLstsq.test_linalg_lstsq.<locals>.inner_test_loop_fn  s    G! ( ( {++//WQZ("g7 7a%%f%%% {++1glll11a''''''( (r   r   r  r  r$  r   r   r  r  r   r   r   r        @      @rd   r   r   r   r   rk     r  r  N)r   r   r   r   r,  rG  r2  r   rk   rx  r9  r   r  rT  r   r  r[  r  r  r]  r  r  )r/   r  cycle_dtordersspecific_condr2  a_sizer-  a_orderr   r@   r9   r=  r  r   approx_half_rank_rcondemptiesr   r_   okr  badoneDbad1Dbad2Dr^   r  r1  s   `                        @@@r   test_linalg_lstsqz!TestLinalgLstsq.test_linalg_lstsq  s   
 #T"""<00X	& X	& X	& X	& X	& X	&x ;:: %%sFmm 	( 	( 	( 	( 	( 	( 	($  #	A #	AFhB;''G ++FB@@A q"%%%DAq1IIE Avv!q&& AI//Ba 0 1 1 #"1b))) //B= 0 B B ]*).&""1b)?A A A A
 
				
  	4 	4DAqHQKK!-D&&ud3333 XBx"b*"*=== 	Bx  hAA'rx888EB9555EC9555 hAA'rz:::&&r52s)<<<&&r53)<<< h1vRZ000$$Rb	::: hR
RVRV$45RZHHH!!%"c333!!%#r333 xR
333Dzh!Q!Q(Aq6Aq6*:;2:NNN''EB9=== "RZ0002$rd+2:>>>))%"e===))%"e=====r   c           	      6   t          j        g dg dg dg dg dg dgd          }t          j        |          }t          j        g d	          }t          d
          d             } |||d           t           j                            ||           d S )N)r$  g)\(@gGz@)r$  g@r7  )r$  g      @gffffff@)r$  gffffff?g(\@)r$  gzG@g)\(
@)r$  g(\?g@rh   rf   )r$  r  r6  r7        @g      @Tr   c                 b    |r| ddd d f         } t           j                            | |          S r  r   r  yr  s      r   f2z*TestLinalgLstsq.test_issue3368.<locals>.f2n  5     ac111fI9??1a(((r   F)r   r9  r{   r   rp  rq  )r/   r  r  rJ  rK  s        r   test_issue3368zTestLinalgLstsq.test_issue3368b  s    H&&&&&&&&&&&&&&&&&&)
 145 5 5 H---..	d				) 	) 
		) 	1a

""1f-----r   N)r   r   r   r   r   rE  rM  r  r   r   r  r  q  sX          `> `> \`>D . . \. . .r   r  c                   >    e Zd ZdZed             Zed             ZdS )TestLinalgSolvez$
    Tests for np.linalg.solve.
    c                 j     t          d          t                     fd}g d}t          | j        d          D ]\  }}}                     |||          }d}t          |d          D ]a\  }}	                     |j        d         |f||	          }
 |||
           |
dddf                             |		          } |||           b t          j        d
          t          j        d                     t          j	        ddgddggt          j
                  } ||           d}t          j	        ddgddggt          j                  }                     |||f                                |||f           t          j	        ddgddggt          j                  }                     |||f                                |||f           t          j	        ddgt          j
                  }                     |||f           t          j	        ddgt          j        t          j        ggt          j
                  }                     ||f                                ||f           t          j	        ddgt          j
                  } ||           t          j	        ddgddggddgddgggt          j
                  }                     |||f           t          j	        dgt          j
                  }t          j	        dgdgdggt          j
                  }                     ||f                                ||f                                dt          j
        dd          }                     ||f           dS )z&
        Test np.linalg.solve
        Tr   c                 >   t          | |fi |} | |fi |}	                    |d           d}	 t          j                            ||d           n# t
          $ r d}Y nw xY w|r|	                    |j        |j                   t          j        | |          }t          j	        | j
                  j        }t          j                            ||d|z  d|z             	                                5   | |fi | d d d            d S # 1 swxY w Y   d S )Nrh   Frl  r  Trm  r  )r   r`  r   rp  r  r  rP   rs   r   rn  r:   ro  rq  r\   )
r   r   r  r`   ra   r  r  ro  r^   r/   s
           r   r  z0TestLinalgSolve.test_linalg_solve.<locals>.check  s   #Aq33F33H%1''''C %%c3///!&*
99 : , , , ,! * * *%)"""* "   HN;;; fQnnXag..9

**jz)	 +    %%'' & &a%%f%%%& & & & & & & & & & & & & & & & & &s#   "A A%$A%:DDD)r4  r  r  r  r  r*  r   Nrf   r  r5  r$          rd   r   r   r   r   r   r  rk  r8  r  r  r6  r  re   r  )r   r   r   r   rG  rs   r{   r   rk   r9  r   r  rT  r   r  r[  r  r  r]  r  r  rh  )r/   r  r  ri   r:   rg   r   r.  r/  r0  r   rv   r@  r  rA  ok_oneDrC  rD  r^   s   `                 @r   test_linalg_solvez!TestLinalgSolve.test_linalg_solve~  s   
 #T"""<00(	& (	& (	& (	& (	& (	&V )(( t{D11	 	D%++D%??AG#*7D#9#9  //WQZ(%: :a 1glll11a 	bhv/// XBx"b*"*=== 	b"  hAA'rx888EB9555EC9555 hAA'rz:::&&r52s)<<<&&r53)<<< h1vRZ000$$Rb	::: hR
RVRV$45RZHHH!!%"c333!!%#r333 (B82:666b'h!Q!Q(Aq6Aq6*:;2:NNN''EB9=== "RZ0002$rd+2:>>>))%"e===))%"e=== ++FBJ!+LL%%eeR[99999r   c                    t          j        g dg dg dg dgd          }t          j        |          }t          j        g d          }t          j        |          }t          d	          d
             }|                    ||d          }t           j                            ||           t           j                            ||            |||d          }t           j                            ||           t           j                            ||           t           j                            ||           d S )N)r$  r   r   r   )rS  r   r   r   )rS  r   r   r   )r$  r   r   r   rh   rf   )r$  r  r6  r   Tr   c                 b    |r| ddd d f         } t           j                            | |          S r  r   rI  s      r   r  z4TestLinalgSolve.test_no_input_mutation.<locals>.func  rL  r   Fr  )r/   r  r  rJ  y_origr  r`   ra   s           r   r  z&TestLinalgSolve.test_no_input_mutation  s9   Hmmm#mm#mm#mm& .12 2 2
 H___%%	d				) 	) 
		) <<1e,,

""1f---

""1f---d1a

""1f---

""1f---

""8S11111r   N)r   r   r   r   r   rU  r  r  r   r   rO  rO  y  sX          r: r: \r:h 2 2 \2 2 2r   rO  c                   >    e Zd ZdZed             Zed             ZdS )TestLinalgPinvz#
    Tests for np.linalg.pinv.
    c                 <     t          d          t                     fd}g d}d}t          | j        d          D ]y\  }}}                     |||          } ||           |\  }}	|dk    rF|	dk    r@t          ||	          }
                     ||||          }d	|z  }|
|z  } |||
           zdD ]} |t          j        |                      d}                     |t          j	        dt          j
                  f                                |t          j	        dt          j                  f                                t          j        d	dgt          j        t          j        ggt          j                  f           dS )z%
        Test np.linalg.pinv
        Tr   c                 d   t          | fi |} 	| fi |}
                    |d           d}	 t          j                            ||d           n# t
          $ r d}Y nw xY w|r
                    |j        |j                   t          j        ||           }	 
	                    |           nD# t
          $ r6 dt          j
        | j                  j        z  } 	|          }t          j                            || d|z  d|z             | j        d	         | j        d
         k    r t          d          t                    } || t          j        | j        d	                                       | j                  fi |d	         }t          j                            ||d|z  d|z             
                    t          j                            ||z
            |           Y nw xY w
                                5   	| fi | d d d            d S # 1 swxY w Y   d S )Nrh   Frl  r  Trk  rm  r  r   r   r   )r   r`  r   rp  r  r  rP   rs   r   rt  rn  r:   ro  rq  r   r   r8  r7   
assertLessr   r  r\   )r   r  r`   ra   r  r  ro  r   
lstsq_pinvr^   r/   s            r   r  z.TestLinalgPinv.test_linalg_pinv.<locals>.check  s   "1////H%$$V$$C %%c3///!&*
99 : , , , ,! * * *%)"""* " %P   HN;;;
 fS!nnP2237777% P P P!"RXag%6%6%A!AJ%**CJ..*_ :-	 /    wqzQWQZ// !3T 2 2 2< @ @%*Urv !
 ,  ,,2F !-) -)&4 &4 -3&4 &4 56&7
 
22&!#j!$z!1	 3    OOBINN3>$B$BJOOOOO5P: %%'' # #a""6"""# # # # # # # # # # # # # # # # # #s6   "A A#"A#B6 6D>G76G7
H%%H),H)r}  r  r  r   r  r$  r3  )r   r  r   r  rd   rl  r  N)r   r   r   r   rG  r2  r   rk   rT  r  r  r[  r   r]  r9  r  r  )r/   r  r  r;  ri   r:   rg   r   r@   r9   r=  r   r>  r  r  r^   s   `              @r   test_linalg_pinvzTestLinalgPinv.test_linalg_pinv  s   
 #T""";//@	# @	# @	# @	# @	# @	#H ;::  t{D11	7 	7D% ++D%??AE!HHHDAqAvv!q&&Aq		//eU:G 0 I I]*).&a56666 # 	  	 BE"(2,, 	E!#rx!@!@!@ B	D 	D 	D 	$$R&(gb
&C&C&C%E	G 	G 	G 	!!%#%8b"Z"&"&9I,J24*$> $> $> #@	A 	A 	A 	A 	Ar   c                    t          d          d             }t          j        g dg dg dg dgd	          }t          j        |          }|                    d
          }|                    |          }t          j                            ||            ||          }t          j                            ||           t          j                            ||           d S )NTr   c                 L    t           j                            | d                   S )Nr   r   )r  s    r   some_fnz.TestLinalgPinv.test_issue5870.<locals>.some_fn  s    9>>!A$'''r   r  r  r  r  rh   rf   )r   r   r   )r   r   r9  r{   r?   r   rp  rq  )r/   rb  v_datav_orig
reshaped_vr`   ra   s          r   test_issue5870zTestLinalgPinv.test_issue5870  s     
d				( 	( 
		( >>>)>>)>>)>>+ 367 7 7
 ^^I..
??:..

""66222gj!!

""66222

""8S11111r   N)r   r   r   r   r   r_  rf  r  r   r   rZ  rZ    s[          qA qA \qAf 2 2 \2 2 2r   rZ  c                   f    e Zd ZdZd Zd Zd Zed             Zed             Z	ed             Z
dS )	TestLinalgDetAndSlogdetz
    Tests for np.linalg.det. and np.linalg.slogdet.
    Exactly the same inputs are used for both tests as
    det() is a trivial function of slogdet(), the tests
    are therefore combined.
    c                 $   t          |fi |} ||fi |}dt          j        |j                  j        z  }t          j                            |||           |                                 5   ||fi | d d d            d S # 1 swxY w Y   d S Nrk  r   )r  r   rn  r:   ro  rp  rq  r\   )r/   r^   r   r  r`   ra   ro  s          r   	check_detz!TestLinalgDetAndSlogdet.check_det  s    a**6**eA    !'**55
 	
""3z"BBB !!## 	 	E!v	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   .
BB	B	c                 $   t          |fi |} ||fi |}|                     t          |          t          |                     |                     t          |          d           t          d          D ]H}|                     t	          j        ||                   t	          j        ||                              I|j                            |d                   }t          j        	                    ||d         d           dt	          j
        |j                  j        z  }t          j                            |d         |d         ||           |                                 5   ||fi | d d d            d S # 1 swxY w Y   d S )Nr   r   rl  r  rk  r   r  )r   rP   rJ   rm   r   r  r:   typerp  r  rn  ro  rq  r\   )	r/   r^   r   r  r`   ra   r   got_convro  s	            r   check_slogdetz%TestLinalgDetAndSlogdet.check_slogdet  s   !!..v..eA     	XC111S1%%% q 	. 	.AA'',,. . . . 7<<A''

11hqk 	2 	, 	, 	, !'**55


""FHQKjz 	# 	C 	C 	C !!## 	 	E!v	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   .
FF	F	c                    g d}t          || j        d          D ])\  }}}|                     |||          } |||           *t          | j        d          D ]'\  }}t          j        d|          } |||           ( ||t          j        d                     |                     ||t          j        dt          j                  f           | 	                    ||t          j        dt          j
                  f           |                     |t          j        dd	gt          j        t          j        ggt          j
                  f           d S )
N)r4  )r   r   rR  r  r  rd   r  r  rl  r$  r  )r   r   rG  r   r6  rk   rT  r  r  r[  r   r]  r9  r  r  )	r/   r  r  r^   r  ri   r:   rg   r   s	            r   do_testzTestLinalgDetAndSlogdet.do_test  s    )(( t{D11	 	D% ++D%??AE%OOOO $DK66 	 	LE5u---AE%OOOO 	eRXf%%&&& 	E!#rx!@!@!@ B	D 	D 	D 	$$R&(gb
&C&C&C%E	G 	G 	G 	!!%#%8b"Z"&"&9I,J24*$> $> $> #@	A 	A 	A 	A 	Ar   c                 z     t          d          t                    }|                     d| j        |           d S )NTr   r   )r   r  rq  rk  r/   r^   s     r   test_linalg_detz'TestLinalgDetAndSlogdet.test_linalg_det  s:    "T""":..UDNE22222r   c                 z     t          d          t                    }|                     d| j        |           d S )NTr   r   )r   r   rq  ro  rs  s     r   test_linalg_slogdetz+TestLinalgDetAndSlogdet.test_linalg_slogdet  s;    "T""">22Y 2E:::::r   c                    t          j        g dg dg dg dgd          }t          j        |          }t          d          d	             }|                    |d
          }t           j                            ||            ||d
          }t           j                            ||           t           j                            ||           d S )Nr  r  r  r  rh   rf   Tr   c                 `    |r| ddd d f         } t           j                            |           S r  r   r  s     r   r  z<TestLinalgDetAndSlogdet.test_no_input_mutation.<locals>.func  s5     ac111fI9$$Q'''r   Fr  r/   r  r  r  r`   ra   s         r   r  z.TestLinalgDetAndSlogdet.test_no_input_mutation  s    Hnnn$nn$nn$nn& .12 2 2
 	d				( 	( 
		( <<5))

""1f---d1enn

""1f---

""8S11111r   N)r   r   r   r   rk  ro  rq  r   rt  rv  r  r  r   r   rh  rh    s           ! ! !FA A AB 3 3 \3 ; ; \; 2 2 \2 2 2r   rh  c                   (    e Zd ZdZed             ZdS )TestLinalgNormz#
    Tests for np.linalg.norm.
    c                    
  t          d          t                    

 fd}g d}dt          j        t          j         dddd	d
dddg}t	          | j        |          D ])\  }}}                     ||          } |||           *t	           j        |          D ]1\  }}                     d|          ddd         } |||           2g d}dt          j        t          j         ddd	d
g}t	          | j        d|          D ]+\  }}}}                     |||          } |||           ,dg}t	           j        |d          D ]c\  }}}                     d||          } ||dd         |            ||ddddf         |            ||ddddf         |           dt	           j        |d          D ]t\  }}}t          j        d||          } 	                     
||          d           t          j        d||          } 	                     
||          d           ud}	 
                    |	
t          j        dt          j                  f                                |	
t          j        dt          j                                      d	d	d          f                                
t          j        ddgt          j        t          j        ggt          j                  d	f                                
t          j        ddgdd ggt          j                  d!f           dS )"z%
        Test np.linalg.norm
        Tr   c                 v   t          | fi |} | fi |}                    t          j        |                      dt          j        | j                  j        z  }t          j                            |||           	                                5   | fi | d d d            d S # 1 swxY w Y   d S rj  )
r  rb  r   r  rn  r:   ro  rp  rq  r\   r   r  r`   ra   ro  r^   r/   s        r   r  z.TestLinalgNorm.test_linalg_norm.<locals>.check,     "1////H%$$V$$C OO 4 44555RXag..99J J&&sH:&FFF %%'' # #a""6"""# # # # # # # # # # # # # # # # # #   
B..B25B2)r   r   r  Nr   r   r   r   rj  rk  g@g333333)r  rl  r   r}  r  )   r+  r   r5  r/  rS  r  r  r  rd      r$  r  r6  r7  r8  )r   r  r   r  r   r   r<   rG  rk   rP   rT  r  r  r  r   r?   r]  r9  r  rv  )r/   r  r  	nrm_typesri   r:   nrm_typer   rg   r  r^   s   `         @r   test_linalg_normzTestLinalgNorm.test_linalg_norm%  s&   
 #T""";//	# 	# 	# 	# 	# 	#" 		26BF7Aq"aQTJ	 t{I66	# 	#!D%""4//AE!""""" Y//	# 	#OE8""2u--ccc2AE!"""""
 ;::26BF7Ar1b9	 t{D)<<	# 	#(D% ++D%??AE!""""" F	Y55
	, 
	,"E8U++HeUCCAE!BQB%X&&&& E!AAAqrrE()))) E!Aqt!tG*(+++++ Y55	6 	6"E8UU%888AUU1h//555uE:::AUU1h//5555 	E!#rx!@!@!@ B	D 	D 	D 	''"*& & &&-g1a' '	 	 	 	!!%#%8b"X7G,H24*$> $> $>?@#B	C 	C 	C
 	%%ebhR2r(7K=?Z/I /I /IJK.M 	N 	N 	N 	N 	Nr   N)r   r   r   r   r   r  r  r   r   r{  r{     sC          `N `N \`N `N `Nr   r{  c                   (    e Zd ZdZed             ZdS )TestLinalgCondz#
    Tests for np.linalg.cond.
    c                      t          d          t                     fd}dt          j        t          j         ddddg}d	d
g}t	          | j        d|          D ]+\  }}}}                     |||          } |||           ,g d}t	          | j        d          D ](\  }}}                     |||          } ||           )dD ]+}	                     t          j        |	          f           ,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                    5  t          j	        ddgddggt          j
                  }t          j        dt                      ||           ddd           n# 1 swxY w Y   d}                     |t          j        dt          j                  f                                |t          j        dt          j
                  f                                t          j	        ddgt          j        t          j        ggt          j
                  f                                t          j	        ddgddggt          j
                  df           dS )z%
        Test np.linalg.cond
        Tr   c                 v   t          | fi |} | fi |}                    t          j        |                      dt          j        | j                  j        z  }t          j                            |||           	                                5   | fi | d d d            d S # 1 swxY w Y   d S rj  )
r	  rb  r   r  rn  r:   ro  rp  rq  r\   r~  s        r   r  z.TestLinalgCond.test_linalg_cond.<locals>.check  r  r  Nr   r   r   rj  r  rR  r  )r  )r~  r  r  r  r  r   rd   gg?ignorer  r  rl  r$  r  r6  r7  r8  )r   r	  r   r  r   r   rG  rx  rk   r9  r   rE   rF   rG   RuntimeWarningrT  r  r  r[  r]  r  rv  )r/   r  psr  ri   r:   rg   r  r   r  r$  r  r^   s   `           @r   test_linalg_condzTestLinalgCond.test_linalg_cond  s    #T""";//	# 	# 	# 	# 	# 	#" BFRVGQAr2  t{D"55	 	!D%++D%??AE!qMMMMM 322t{D11	 	D%++D%??AE!HHHH + 	? 	?B&&urx||o>>>> Hq!fq!f%RZ888aa1Hq!fq!f%RZ888a2
 $&& 	 	61+3x0
CCCA!(N;;;E!HHH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
  	E!#rx!@!@!@ B	D 	D 	D 	$$R&(gb
&C&C&C%E	G 	G 	G 	!!%#%8b"Z"&"&9I,J24*$> $> $> #@	A 	A 	A
 	%%ebhR2r(7K=?Z/I /I /IJK.M 	N 	N 	N 	N 	Ns   AGG GN)r   r   r   r   r   r  r  r   r   r  r    sC          KN KN \KN KN KNr   r  c                   >    e Zd ZdZed             Zed             ZdS )TestLinalgMatrixRankz*
    Tests for np.linalg.matrix_rank.
    c           	           t          d          t                     fd}g d}t          | j        d          D ]?\  }}}                     |||          } ||           d}t          dt          |          dz
            D ]q}                     ||||          }                      |          |            ||           |j        \  }	}
d	|d
d
d
d
f<   t          j
        t          j        |	|
                    }t          j        |          rNdt          j                            |          z   dz   dt          j                            |          z  z   }d|d<   n'dt          j                            |          z   }d|d<   |                    |          ||d         d
|         |d         d
|         f<                         ||          |dz
              |||           sd	|d
d
d
d
f<                         |          d            ||           t          j        |          rd|d<   nd|d<                         ||          d            |||           A j        D ]q}t          j        d|          }                      |          d            ||           d|d<                         |          d            ||           rdD ]1}dD ],}                     t          j        |          |f           -2d}                     |t          j        dt          j                  f                                |t          j        dt          j                                      ddd          f                                t          j        ddgt          j        t          j        ggt          j                  f           d
S )z,
        Test np.linalg.matrix_rank
        Tr   c                     t          | fi |} | fi |}t          j                            ||                                           5   | fi | d d d            d S # 1 swxY w Y   d S r   )r  r   rp  rq  r\   )r   r  r`   ra   r^   r/   s       r   r  z;TestLinalgMatrixRank.test_linalg_matrix_rank.<locals>.check  s    )!66v66H%$$V$$C J&&sH555 %%'' # #a""6"""# # # # # # # # # # # # # # # # # #s   
A##A'*A'r}  r  vIh%<=r   r  rS  Nr$                ?y+=+=r   g+=)r  )r   r   rk  rd   r  )Nr  r  r  r  r   r   r  )r   r  r   r   rG  rm   r2  rP   rs   r   r7  r8  r  r0  r  r7   r6  rx  rk   rT  r  r  r  r   r?   r]  r9  r  r  )r/   r  r  ri   r:   rg   r   r  r   r@   r9   rF  r   r-  r  r  r^   s   `               @r   test_linalg_matrix_rankz,TestLinalgMatrixRank.test_linalg_matrix_rank  s    #T"""#566
	# 
	# 
	# 
	# 
	# 
	# ;:: t{D11,	 ,	D% ++D%??AE!HHH C1c$ii!m,, " "//eU/KK  q1---a w1!!!QQQ$j1..?1%% !RY^^A...4binnQ///0A *AaDDRY^^A...A AaD,-HHUOO#a&!*c!fRaRj()  q#A666aS!!!!!AaaadGUU1XXq)))E!HHHq!! "*&		!&	UU1c]]A...E! + 	 	B!B'''AUU1XXq)))E!HHHAaDUU1XXq)))E!HHHH + 	G 	GB$ G G**528B<<2EFFFFG  	E!#rx!@!@!@ B	D 	D 	D 	''"*& & &&-g1a' '	 	 	 	!!%#%8b"Z"&"&9I,J24*$> $> $> #@	A 	A 	A 	A 	Ar   c                    t          j        g dg dg dg dgd          }t          j        |          }t          d          d	             }|                    |d
          }t           j                            ||            ||d
          }t           j                            ||           t           j                            ||           d S )Nr  r  r  r  rh   rf   Tr   c                 `    |r| ddd d f         } t           j                            |           S r  r  r  s     r   r  z9TestLinalgMatrixRank.test_no_input_mutation.<locals>.funcT	  s5     ac111fI9((+++r   Fr  ry  s         r   r  z+TestLinalgMatrixRank.test_no_input_mutationG	  s     Hnnn$nn$nn$nn& .12 2 2
 	d				, 	, 
		, <<5))

""1f---d1enn

""1f---

""8S11111r   N)r   r   r   r   r   r  r  r  r   r   r  r    s[          bA bA \bAH 2 2 \2 2 2r   r  c                   .    e Zd ZdZd Zed             ZdS )TestLinalgMatrixPowerz+
    Tests for np.linalg.matrix_power.
    c                      ||d         d           |                      t          j                  5   ||  d d d            d S # 1 swxY w Y   d S )Nr   r   r   r
   r   )r/   r^   r_   s      r   assert_int_exponenentz+TestLinalgMatrixPower.assert_int_exponenenti	  s    d1gqv122 	 	E4LL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AA	A	c                      t          d          t                     fd}g d}ddgt          t          dd                    z   d	d
gz   }t	          || j        d          D ]M\  }}}}                     |||          } |||           t          j        d||          } |||           Nd}	 	                    |	t          j
        dt          j                  df            	                    |	t          j
        dt          j                  df           t          j
        d          df}
d}                     |
|                                |	t          j
        dt          j                  df                                t          j
        d          df                                t          j        ddgddgg          df           d S )NTr   c                 f   t          | |          } | |          }                    |d           dt          j        | j                  j        z  }t          j                            ||||                                           5   | |           d d d            d S # 1 swxY w Y   d S )Nre   r  r  )	r  r`  r   rn  r:   ro  rp  rq  r\   )r   pwrr`   ra   r%  r^   r/   s        r   r  z=TestLinalgMatrixPower.test_linalg_matrix_power.<locals>.checkt	  s    *1c22H%3--C %%c3///bhqw''22CJ&&sH3S&III %%''  a                 s   B&&B*-B*)r4  rk  rk  rR  iirl  r  !   r  r  r/  r  r  rd   r   )r   rk  zinput must be a square array333333?rS  r   r   )r   r  listrm   r   r   rG  r   rk   rT  r  r  rJ  r[  r   r  rh  r9  )r/   r  r  powersri   r  r:   rg   r   r  r_   r   r^   s   `           @r   test_linalg_matrix_powerz.TestLinalgMatrixPower.test_linalg_matrix_powerp	  s+   "T"""#677	 	 	 	 	 	 )((sd5b>>222b"X= vt{D99	 	#D#ue++D%??AE!SMMMuE:::AE!SMMMM 	E!#rx!@!@!@! D	F 	F 	F 	E!#rx!@!@!@! D	F 	F 	F #,%s+++ 	$$R&(gb
&C&C&CQ%G	I 	I 	I 	""5276??C*@AAA 	%%ebhQ!Q7H.I.I2-NOOOOOr   N)r   r   r   r   r  r   r  r  r   r   r  r  d	  sM            2P 2P \2P 2P 2Pr   r  c                   4     e Zd ZdZ fdZd Zd Zd Z xZS )	TestTracez
    Tests for np.trace.
    c                     t          t          |                                             t          d          t                    | _         t          d          t                    | _        d S )NTr   )r,   r  r-   r   r  cfunc_w_offsetr  cfunc_no_offsetr.   s    r   r-   zTestTrace.setUp	  s`    i$$&&&0c4000>>1sD1112HIIr   c                      ||           |                      t          j                  5   ||fi | d d d            d S # 1 swxY w Y   d S r   r  )r/   r^   r   r  s       r   assert_int_offsetzTestTrace.assert_int_offset	  s    av122 	 	E!v	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   
AA	Ac                      fd}g d}g dt          t          dd                    z   g dz   }t          || j        d          D ]q\  }}}}                     |||          } |||           |d	k    r ||           t          j        d
||          } |||           |d	k    r ||           rd}	                     |	 j        t          j	        dt
          j
                  dfd                                |	 j        t          j	        dt
          j
                  fd                                 j        t          j	        d          d           d S )Nc                 h   d|v rt          | fi |}j        }nt          | fi |}j        } || fi |}dt	          j        | j                  j        z  }t          j        	                    ||||           
                                5   || fi | d d d            d S # 1 swxY w Y   d S )Nr  rk  r  )r  r  r  r  r   rn  r:   ro  rp  rq  r\   )r   r  r`   r^   ra   r%  r/   s         r   r  z#TestTrace.test_trace.<locals>.check	  s)   6!!'44V44+1!>>v>>,%$$V$$Cbhqw''22CJ&&sH3S&III %%'' # #a""6"""# # # # # # # # # # # # # # # # # #s   
B''B+.B+r}  )iiir  rl  )r  r  r+  r  )r  r   r  r/  r  rd   r   Fr  r  )r  rm   r   r   rG  r   rk   r[  r  r  r   r  r  )
r/   r  r  offsetsri   r  r:   rg   r   r  s
   `         r   
test_tracezTestTrace.test_trace	  s   	# 	# 	# 	# 	#& ;:: "//DsB$8$88<<<G wT::		 		&D&%++D%??AE!F####{{auE:::AE!F####{{a 	$$R)<&(gb
&C&C&CQ%G	P 	P 	P$$R)=&(gb
&C&C&C%Eu	N 	N 	N 	" " # 	 	% 	% 	% 	% 	%r   c                 ^   t          dd          d             }t          j        dt          j                  } ||           |                     t
                    5 } |d           ddd           n# 1 swxY w Y   t          |j                  }|                     d|           dS )	z
Issue 2314z(optional(float64[:,:]),)Tr   c                 *    t          j        |           S r   r  r   s    r   testedz5TestTrace.test_trace_w_optional_input.<locals>.tested	  s    8A;;r   r  rd   Nz(expected array(float64, 2d, A), got None)	r   r   r  r   r   	TypeErrorrN   r   rP   )r/   r  r   r   errmsgs        r   test_trace_w_optional_inputz%TestTrace.test_trace_w_optional_input	  s    	(4	8	8	8	 	 
9	8	 GF"*---q			y)) 	VF4LLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 V%&&CVLLLLLs    A88A<?A<)	r   r   r   r   r-   r  r  r  r   r   s   @r   r  r  	  s|         J J J J J  0% 0% 0%dM M M M M M Mr   r  c                   h    e Zd Z eg d          Z eg d          Zg dZd Zd Zd Z	d Z
d Zd	S )

TestBasics)rh   re   re   rh   )re   rh   re   rh   )r~  r  r  )r  r  )r   r6  rG  c           	      :   |                      ||t          j        dgggt          j                  t          j        d          fd           |                      ||t          j        d          t          j        dgggt          j                  fd           d S )Nr   rd   F)r  r   r9  r   r  )r/   r  r^   s      r   _assert_wrong_dimzTestBasics._assert_wrong_dim
  s    ''A3%
;;;RWQZZH%	Q 	Q 	Q''

BHseWBJ$G$G$GH%	Q 	Q 	Q 	Q 	Qr   c                    t          |t                    s|S t          |          dk    r|                     |d         |          S |                     |d         |d         z  |                              ||          S )Nr   r   rf   )r3  r_  rJ   r<   r?   )r/   ri   r:   rg   s       r   
_gen_inputzTestBasics._gen_input

  s    $&& 		'K4yyA~~))$q'5999))Gd1g% "7 # ' ''r   c                    |                      ||t          | j                            }|                      ||t          | j                            }t	          j        |          r|dz   }t	          j        |          r|dz   }||fS )Nr  )r  r,  order1order2r   r  )r/   size1size2r:   r   r   s         r   
_get_inputzTestBasics._get_input
  s    OOE5$t{*;*;<<OOE5$t{*;*;<<?1 	BA?1 	BA1vr   c                 &   	  t          d          t                    		 fd}t           j                  }t	           j         j                  D ]\  }}t          |          }                     |||          \  }} |||           t          j	        t          j
        |          j        t          j
        |          j        ft          j
        |          j                  } ||||                                d	           d S )NTr   c                    t          | |          } | |          }dt          j        t          j        |           j                  j        z  }t          j                            ||||           d|v rV | |fi |}t          j                            ||||           t          j                            |d         |||                                           5   | |fi | d d d            d S # 1 swxY w Y   d S )Nrk  r  r!   )	r  r   rn  asarrayr:   ro  rp  rq  r\   r   r   r  r`   ra   r%  r^   r/   s         r   r  z$TestBasics.test_outer.<locals>.check#
  sn    $Aq))H%1++Cbhrz!}}233>>CJ&&sH3S&III eAq++F++
**3s03 + 5 5 5
**6%=(03# + ? ? ? %%'' & &a%%f%%%& & & & & & & & & & & & & & & & & &s   "C::C>C>rd   r    r  )r   r  r   r   r   r  r,  r  r   rk   r  ri   r:   r  )
r/   r  dtsr  r  r:   r   r   r  r^   s
   `        @r   
test_outerzTestBasics.test_outer 
  s   "T"""<00	& 	& 	& 	& 	& 	&* DK  #DJ
;; 	 	LE5IIE__UE599FQE!QKKK"*Q--,bjmm.@A"$*Q--"57 7 7AE!QAw.....r   c                    	  t          d          t                    		 fd}t           j         j         j                  D ],\  }}}                     |||          \  }} |||           -                     d	           t          j        d          d d d         t          j        d          d d d         f}d} 	                    	||t          j                   d S )	NTr   c                 ^   t          | |          } | |          }dt          j        t          j        |           j                  j        z  }t          j                            ||||                                           5   | |           d d d            d S # 1 swxY w Y   d S )Nrk  r  )	r  r   rn  r  r:   ro  rp  rq  r\   r  s         r   r  z#TestBasics.test_kron.<locals>.checkF
  s    "1a((H%1++Cbhrz!}}233>>CJ&&sH3S&III %%''  a                 s   B""B&)B&r  rl  r   zonly supports 'C' or 'F' layoutrg  )r   r  r   r  r   r  r  r   rk   rJ  r
   r   )
r/   r  r  r  r:   r   r   r_   r   r^   s
   `        @r   	test_kronzTestBasics.test_kronC
  s   "T""";//
	 
	 
	 
	 
	 
	 
DJ<<	 	E5%__UE599FQE!QKKKKvu---SSqS!28B<<!#45/%s0BCCCCCr   N)r   r   r   r   r  r  r  r  r  r  r  r  r  r   r   r  r  	  s        U'''((FU'''((F ?>>EQ Q Q
' 
' 
'  !/ !/ !/FD D D D Dr   r  c                       e Zd Zd ZdS )TestHelpersc                     ddl m  fd}t          fd            }ddg}t          j        g}ddg} ||t          j        |||           t          fd	            }d
dg}t          j        g}ddg}d } ||||||           d S )Nr   )_copy_to_fortran_orderc                 V   t          |||          D ]\  }}}t          j        t          j        |                                        ||          } | |          }	
                     ||          |	           
                    |j        j        |	j        j                   d S )Nrf   )	r   r   r4   prodr?   r]   assertNotEqualctypesdata)udtexpectfnshapesr   r:  rs   r:   rg   r   r  r/   s             r   r  z5TestHelpers.test_copy_to_fortran_order.<locals>.checkb
  s    '.vvv'F'F B B#ueIbgenn--55e55IICFF''Q777##AHM18=AAAAB Br   c                      |           S r   r  )r   r  s    r   direct_callz;TestHelpers.test_copy_to_fortran_order.<locals>.direct_calll
  s    ))!,,,r   )r   r   )r   r   rk  re   rh   c                 <    | d d d         d         } |          S Nr   r   r  )r   slicedr  s     r   slice_to_anyz<TestHelpers.test_copy_to_fortran_order.<locals>.slice_to_anyv
  s)     sssVAYF))&111r   )r   r   r   )r   r   r   rk  c                 L    | d d d         d         }t          j        |          S r  )r   asfortranarray)r   r  s     r   expected_slice_to_anyzETestHelpers.test_copy_to_fortran_order.<locals>.expected_slice_to_any
  s&    sssVAYF$V,,,r   )numba.np.linalgr  r   r   intpr  )	r/   r  r  r  r   r:  r  r  r  s	   `       @r   test_copy_to_fortran_orderz&TestHelpers.test_copy_to_fortran_order_
  s   ::::::	B 	B 	B 	B 	B 
	- 	- 	- 	- 
	- )$'sk2,fffEEE 
	2 	2 	2 	2 
	2
 \*'s	- 	- 	-
 	l1666JJJJJr   N)r   r   r   r  r  r   r   r  r  ^
  s(        &K &K &K &K &Kr   r  __main__r  )r   )r   r   r5  )Jr   r*   	itertoolsr   r   sysrE   numbersr   r   platformnumpyr   numbar   r   r	   
numba.corer
   numba.tests.supportr   r   r   r   r   r   r   unittestr   r#   r%   r(   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r	  r  r  r  r  r  r  r   r{  r  r  r  r  r  r  r  rO  rZ  rh  r{  r  r  r  r  r  r  r   mainr  r   r   <module>r     s       				 $ $ $ $ $ $ $ $ 



  $ $ $ $ $ $ $ $      # # # # # # # # # #      B B B B B B B B B B B B B B B B * * * * * *   ! ! !  j j j j j%x j j j^	  ! ! !         ! ! !+ + + +  ( ( ( (! ! !          " " " "       ) ) ) )( ( (     # # # #  BC BC BC BC BC(( BC BC BCJgI gI gI gI gI gI gI gITN2 N2 N2 N2 N2N N2 N2 N2bPJ PJ PJ PJ PJ PJ PJ PJfj$ j$ j$ j$ j$^ j$ j$ j$Z}8 }8 }8 }8 }8N }8 }8 }8@u1 u1 u1 u1 u1> u1 u1 u1p@ @ @ @ @ @ @ @.E. E. E. E. E.' E. E. E.PT2 T2 T2 T2 T2' T2 T2 T2nN2 N2 N2 N2 N2^ N2 N2 N2by2 y2 y2 y2 y2n y2 y2 y2~fN fN fN fN fN& fN fN fNRQN QN QN QN QN^ QN QN QNhD2 D2 D2 D2 D2, D2 D2 D2N?P ?P ?P ?P ?PN ?P ?P ?PDQM QM QM QM QM QM QM QMhaD aD aD aD aD" aD aD aDH'K 'K 'K 'K 'K( 'K 'K 'KR zHMOOOOO r   