o
    h+                     @   sv   d dl Z d dl mZ d dlZd dlmZmZmZm	Z	m
Z
 d dlmZmZ G dd dZG dd dZG d	d
 d
ZdS )    N)raises)lu	lu_factorlu_solveget_lapack_funcssolve)assert_allcloseassert_array_equalc                   @   s   e Zd Zdd Zdd Zejdddgddgddgddgddgddgg d	g d
g dg	dd Zejdddgddgddgddgddgddggdd Z	dd Z
dd ZdS )TestLUc                 C      t jd| _d S N   n
@h/ nprandomdefault_rngrngself r   \/var/www/html/scripts/venv/lib/python3.10/site-packages/scipy/linalg/tests/test_decomp_lu.pysetup_method
      zTestLU.setup_methodc              	   C   s  t g dg dg dg}t|\}}}t g dg dg dg}t|t t d t|t j|ddt d  t|t | t g dg dg d	g}t|\}}}t g d
g dg dg}t|t t d t|t j|ddt d  t|t | t g dg dg dg}t|\}}}t|t g dg dg dg t|t g dg dg dg t|t g dg dg dgddd t g dg dg dg}t|\}}}t|t g dg dg dg t|t g dg dg dg t|t g dg dg dgd ddd t g dg dg dg}t|\}}}t|t g dg dg dg t|t g dg dg d g t|t g dg d!g d"gddd t g dg dg dgd }	t|	\}}}t|t g dg dg dg t|t g dg dg d g t|t g dg d!g d"gd ddd t g dg dg dg d#g}
t|
\}}}t|t d$g d%d&d&f  t|t g d'g d(g d)g d*g t|t g d#g d+g d,g t g dg dg dg d#gd }t|\}}}t|t d$g d%d&d&f  t|t g d'g d(g d)g d*g t|t g d#g d+g d,gd  d&S )-z*Tests from old fortran based lu test suite         r         )       @g      @      @)      ?              )r"         ?r$   r   )kr                 @r   )r    r)   r!   )r"   y       @      r$      r   r         	   )r   r   r   )r   r   r   r   r   r   )g$I$I?r   r   )g$I$I?r"   r   )r   g۶m۶m?g۶m۶m?r   r   r   r$   g+=)rtolatol              ?y               @y              @y              @r)   y              @y              @y               @y              "@r5   r   r   r   r+   r   r   r-   r.   r/   
      r<   )gqq?r   r   )grq?r"   r   )r   gqq?g?gUUUUUU@)r   r   r#   r   r;   r<   r<   r+   )r   r   r   r   N)r%   r   r   )g?r   r   )gffffff?r#   r   )g?g      ?r"   )r   g?g?)r   r   g      ?)r   arrayr   r   rot90eyetriltriu)r   aplu	result_lubcbhrectchrectvrectcvrectr   r   r   test_old_lu_smoke_tests   s   """"""" """ & 
zTestLU.test_old_lu_smoke_testsshaper   r+      )r   r   r/   r/   )r   r      r   )r   r      r-   c                 C   s   | j jdd|d}t|\}}}t||| |  t|dd\}}t|||  | j jdd|dd }|| j jdd|d7 }t|dd\}}t|||  d S )	N      $      $@sizeT	permute_lr5   ir;   r   uniformr   r   )r   rO   rC   rD   rE   rF   plrH   r   r   r   "test_simple_lu_shapes_real_complexN   s   z)TestLU.test_simple_lu_shapes_real_complexc                 C   sB   | j jdd|d}t|dd\}}}t|||d d f |  d S )NrS   rT   rU   T	p_indicesrY   )r   rO   rC   rD   rE   rF   r   r   r   -test_simple_lu_shapes_real_complex_2d_indices]   s   z4TestLU.test_simple_lu_shapes_real_complex_2d_indicesc                 C   sN  | j jg dtjd}t|dd\}}}t|tjdtd t|tjdtjd t|| | j jg dtjd}t|\}}}t|tjdtjd t|tjdtjd t|| t|dd\}}t|tjdtjd t|| | j jg dtjdt	d }t|\}}}t|tjdtj	d t|tjdtj	d t|| d S )	N)r+   r   r   r   dtypeTr]   )r+   r   r   rO   ra   rW   r5   )
r   r   r   float32r   r   zerosintones	complex64r   rC   rD   rE   rF   r[   r   r   r   test_1by1_input_outputd   s$   


 zTestLU.test_1by1_input_outputc                 C   sL  t ddg}t|\}}}t|t jdt jd t|t jdt jd t|t jdt jd t jddgt jd}t|\}}}t|t jdt jd t|t jdt jd t|t jdt jd t jddgt jd}t|\}}}t|t jdt jd t|t jdt jd t|t jdt jd t|dd	\}}}t|t jd
td t|t jdt jd t|t jdt jd t|dd\}}t|t jdt jd t|t jdt jd t jg dt jd}t|\}}}t|t jdt jd t|t jdt jd t|t jdt jd t g d}t|\}}}t|t jdd t|t jdd t|t jdd t	t
dd tt g  W d    n	1 sNw   Y  t g g}t|\}}}t|t jdd t|t jdd t|t jdd t g gg}t|\}}}t|t jdd t|t jdd t|t jdd d S )Nr   )r   r   rb   r   r`   )r   r   )r   r   Tr]   )r   rW   )r   r   r   )r   r   r   r1   )rO   zat least two-dimensional)match)r   r   r0   )r   r   r   )r   emptyr   r   float64float16rc   rg   re   assert_raises
ValueErrorr>   rh   r   r   r   test_empty_edge_cases{   sZ   zTestLU.test_empty_edge_casesN)__name__
__module____qualname__r   rN   pytestmarkparametrizer\   r_   ri   rp   r   r   r   r   r
   	   s     A
 
r
   c                   @   s\   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd ZdS )TestLUFactorc                 C   sB  t jd| _t g dg dg dg| _t g dg dg dg| _t g dg dg dg| _t g dg dg d	g| _t g d
g dg dg| _	t g d
g dg dgd | _
t g dg dg dg dg| _dt g dg dg dg dg | _| jd| _| jdd| jd  | _d S )Nr   r   r   r(   r*   r,   r4   r6   r7   r8   r9   r:   r5   r=   )   (   )r   r   r   r   r>   rC   carH   rI   rJ   rK   rL   rM   medcmedr   r   r   r   r      s&   $
"zTestLUFactor.setup_methodc                 C   sD   t |\}}td|f\}||dd\}}}t|| t|| d S )N)getrfF)overwrite_a)r   r   r   )r   datal_and_u1piv1r}   l_and_u2piv2_r   r   r   _test_common_lu_factor   s
   
z#TestLUFactor._test_common_lu_factorc                 C      |  | j d S N)r   rJ   r   r   r   r   test_hrectangular      zTestLUFactor.test_hrectangularc                 C   r   r   )r   rL   r   r   r   r   test_vrectangular   r   zTestLUFactor.test_vrectangularc                 C   r   r   )r   rK   r   r   r   r   test_hrectangular_complex   r   z&TestLUFactor.test_hrectangular_complexc                 C   r   r   )r   rM   r   r   r   r   test_vrectangular_complex   r   z&TestLUFactor.test_vrectangular_complexc                 C      |  | j dS z:Check lu decomposition on medium size, rectangular matrix.N)r   r{   r   r   r   r   test_medium1      zTestLUFactor.test_medium1c                 C   r   r   )r   r|   r   r   r   r   test_medium1_complex   r   z!TestLUFactor.test_medium1_complexc                 C   s,   t | jdd\}}}t|| | | j d S )NFcheck_finite)r   rC   r   )r   rD   rE   rF   r   r   r   test_check_finite   s   zTestLUFactor.test_check_finitec                 C   sd   dD ]-}t jddgddgg|d}t|\}}t|t ddgddgg t|t ddg qd S )NCFr   r   r   r%   order)r   r>   r   r   r	   )r   r   ALUPr   r   r   test_simple_known   s   zTestLUFactor.test_simple_knownN)rq   rr   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rw      s    	rw   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestLUSolvec                 C   r   r   r   r   r   r   r   r      r   zTestLUSolve.setup_methodc                 C   sZ   | j d}| j d}dD ]}tj||d}t||}t|}t||}t|| qd S )Nr;   r;   r;   r   r   )r   r   r   r>   r   r   r   r   )r   a0rH   r   rC   x1lu_ax2r   r   r   test_lu   s   

zTestLUSolve.test_luc                 C   sJ   | j d}| j d}t||}t|dd}t||dd}t|| d S )Nr   r   Fr   )r   r   r   r   r   r   )r   rC   rH   r   r   r   r   r   r   r     s   
zTestLUSolve.test_check_finiteN)rq   rr   rs   r   r   r   r   r   r   r   r      s    r   )rt   r   rn   numpyr   scipy.linalgr   r   r   r   r   numpy.testingr   r	   r
   rw   r   r   r   r   r   <module>   s     )E