a
    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   s   t jd| _d S N   n
@h/ nprandomdefault_rngrngself r   ]/var/www/html/assistant/venv/lib/python3.9/site-packages/scipy/linalg/tests/test_decomp_lu.pysetup_method
   s    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+=)ZrtolZatol              ?y               @y              @y              @r'   y              @y              @y               @y              "@r1   r   r   r   r)   r   r   r+   r,   r-   
      r8   )gqq?r   r   )grq?r    r   )r   gqq?g?gUUUUUU@)r   r   r!   r   r7   r8   r8   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   Zrot90eyeZtrilZtriu)r   apluZ	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Z	permute_lr1   ir7   r   uniformr   r   )r   rG   r<   r=   r>   r?   plr@   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 )NrK   rL   rM   TZ	p_indicesrP   )r   rG   r<   r=   r>   r?   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   dtypeTrT   )r)   r   r   rG   rW   rO   r1   )
r   r   r   float32r   r   ZzerosintZones	complex64r   r<   r=   r>   r?   rR   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 s0    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   rX   r   rV   )r   r   )r   r   TrT   )r   rO   )r   r   r   )r   r   r   r/   )rG   zat least two-dimensional)match)r   r   r.   )r   r   r   )r   emptyr   r   Zfloat64Zfloat16rY   r[   rZ   assert_raises
ValueErrorr:   r\   r   r   r   test_empty_edge_cases{   sX    .zTestLU.test_empty_edge_casesN)__name__
__module____qualname__r   rF   pytestmarkZparametrizerS   rU   r]   rb   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*   r0   r2   r3   r4   r5   r6   r1   r9   )   (   )r   r   r   r   r:   r<   car@   rA   rB   rC   rD   rE   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)Zoverwrite_a)r   r   r   )r   dataZl_and_u1Zpiv1rn   Zl_and_u2Zpiv2_r   r   r   _test_common_lu_factor   s
    
z#TestLUFactor._test_common_lu_factorc                 C   s   |  | j d S N)rq   rB   r   r   r   r   test_hrectangular   s    zTestLUFactor.test_hrectangularc                 C   s   |  | j d S rr   )rq   rD   r   r   r   r   test_vrectangular   s    zTestLUFactor.test_vrectangularc                 C   s   |  | j d S rr   )rq   rC   r   r   r   r   test_hrectangular_complex   s    z&TestLUFactor.test_hrectangular_complexc                 C   s   |  | j d S rr   )rq   rE   r   r   r   r   test_vrectangular_complex   s    z&TestLUFactor.test_vrectangular_complexc                 C   s   |  | j dS z:Check lu decomposition on medium size, rectangular matrix.N)rq   rl   r   r   r   r   test_medium1   s    zTestLUFactor.test_medium1c                 C   s   |  | j dS rw   )rq   rm   r   r   r   r   test_medium1_complex   s    z!TestLUFactor.test_medium1_complexc                 C   s,   t | jdd\}}}t|| | | j d S )NFZcheck_finite)r   r<   r   )r   r=   r>   r?   r   r   r   test_check_finite   s    zTestLUFactor.test_check_finitec                 C   sd   dD ]Z}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   AZLUPr   r   r   test_simple_known   s
    zTestLUFactor.test_simple_knownN)rc   rd   re   r   rq   rs   rt   ru   rv   rx   ry   r{   r   r   r   r   r   rh      s   	rh   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestLUSolvec                 C   s   t jd| _d S r   r   r   r   r   r   r      s    zTestLUSolve.setup_methodc                 C   sZ   | j d}| j d}dD ]8}tj||d}t||}t|}t||}t|| qd S )Nr7   r7   r7   r|   r   )r   r   r   r:   r   r   r   r   )r   Za0r@   r   r<   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   Frz   )r   r   r   r   r   r   )r   r<   r@   r   r   r   r   r   r   r{     s    
zTestLUSolve.test_check_finiteN)rc   rd   re   r   r   r{   r   r   r   r   r      s   r   )rf   r   r`   numpyr   Zscipy.linalgr   r   r   r   r   Znumpy.testingr   r	   r
   rh   r   r   r   r   r   <module>   s    )E