o
    &?e                     @   s  d dl Z d dlZd dlmZ d dlm  mZ d dl	m
Z
mZ zd dlZW n ey0   dZY nw e jjedu ddZdZe de jde jjedgdfZejejejejejejgZe jed	d
d Ze jed	dd Ze jdd Ze jdd Zdd Z dd Z!dd Z"dd Z#dd Z$dd Z%dd Z&d d! Z'd"d# Z(d$d% Z)d&d' Z*d(d) Z+d*d+ Z,d,d- Z-d.d/ Z.d0d1 Z/d2d3 Z0dS )4    N)assert_allcloseassert_equalzpydata/sparse not installed)reasonz;pydata/sparse (0.8) does not implement necessary operationsZCOOZDOK)Zmarks)paramsc                 C   s   t t| jS N)getattrsparseparamrequest r   m/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/scipy/sparse/linalg/tests/test_pydata_sparse.py
sparse_cls"   s   r   c                 C   s   | j S r   )r	   r
   r   r   r   sp_sparse_cls'   s   r   c                 C   s*   t jd t jdd}||| |fS Ni  	   )nprandomseedrand)r   r   A_denser   r   r   same_matrix,   s   r   c                 C   sB   t jd t jdd}||j }| |}t jd}|||fS r   )r   r   r   r   T)r   r   A_sparsebr   r   r   matrices3   s   

r   c                 C   sL   | \}}}t j||dd\}}|dksJ t|tjsJ t|| | d S )NgV瞯<Zatolr   )splinZgmres
isinstancer   ndarrayr   )r   r   r   r   xinfor   r   r   test_isolve_gmres=   s
   
r"   c                 C   <   | \}}}t ||}t ||}t|d |d dd d S )Nr   g?̔>r   )r   lsmrr   r   r   r   r   Zres0resr   r   r   	test_lsmrG      
r'   c                  C   s6   t jtdtdtddd } t| jd d S )N)
      r)   r*   )Ar   x0r   )r*   )r   r$   r   onesZzerosr   shape)r    r   r   r   test_lsmr_output_shapeO   s   &r/   c                 C   r#   )Nr   gh㈵>r   )r   Zlsqrr   r%   r   r   r   	test_lsqrT   r(   r0   c                 C   s   | \}}}t |d }||}tj|d|d\}}tj|d|d\}}	t|| t|	| ||fD ]B}
tj||d|d\}}tj||
d|d\}}	t|| t|	| tj||d|d\}}tj||
d|d\}}	t|| t|	| q3d S )N      kv0)Mr4   r5   )r   Zdiag	__class__r   Zeigsr   Zeigsh)r   r   r   r5   ZM_denseZM_sparsew_densev_densewvr6   r   r   r   	test_eigs[   s"   






r<   c           
      C   sX   | \}}}t j|d|d\}}}t j|d|d\}}}	t|| t|| t|	| d S )Nr1   r3   )r   Zsvdsr   )
r   r   r   r5   Zu0s0Zvt0usvtr   r   r   	test_svdsu   s   


rA   c           	      C   sR   | \}}}|d d d f }t ||\}}t ||\}}t|| t|| d S r   )r   Zlobpcgr   )	r   r   r   r    Xr8   r9   r:   r;   r   r   r   test_lobpcg   s   

rC   c                 C   s  | \}}}t jt|d}tt||}t||}t|t j	s%J t
|| tt||}tj||dd}t|t j	sCJ t
|| tt||}t||}t|t j	s_J t
|| tt|t|}t||}t|t|sJ t
| |  d S )Nr2   T)Zuse_umfpack)r   r   r   lenr   Zspsolvesp
csc_matrixr   r   r   typetoarray)r   r   r   r   b2r,   r    r   r   r   test_spsolve   s(   



rJ   c                 C   s   | \}}}t |}t|}t|}t|j|sJ t|j|s"J |tt	
||jt	|ff}|tt	
|t	||jff}|j|j |j |j }	t|	 |  || }
t|
t	|dd d S )Ng|=r   )rD   rG   r   Zsplur   LUrE   rF   r   r-   Zperm_rZarangeZperm_cr   r   rH   solveeye)r   r   r   r   nr   luZPrZPcA2zr   r   r   	test_splu   s   

$$rS   c                 C   sf   | \}}}t |}t|}t|j|sJ t|j|sJ || }t|t	
t|dd d S )NgMbP?r   )rG   r   Zspilur   rK   rL   rM   rH   r   r   rN   rD   )r   r   r   r   r   rP   rR   r   r   r   
test_spilu   s   

rT   c                 C   s2   | \}}}t |}t||}t|| | d S r   )r   Ztrilr   Zspsolve_triangularr   )r   r   r   r   r    r   r   r   test_spsolve_triangular   s   

rU   c                 C   s,   | \}}}t |}t |}t|| d S r   )r   Z
onenormestr   )r   r   r   r   Zest0Zestr   r   r   test_onenormest   s   


rV   c                 C   :   | \}}}t t|}t |}t| |  d S r   )r   invrE   rF   r   rH   r   r   r   r   r,   r    r   r   r   test_inv      

rZ   c                 C   rW   r   )r   ZexpmrE   rF   r   rH   rY   r   r   r   	test_expm   r[   r\   c                 C   s0   | \}}}t ||}t ||}t|| d S r   )r   Zexpm_multiplyr   rY   r   r   r   test_expm_multiply   s   
r]   c                 C   s   | \}}||k  sJ d S r   )allr   Z	sp_sparseZ	pd_sparser   r   r   test_eq      r`   c                 C   s   | \}}||k  rJ d S r   )anyr_   r   r   r   test_ne   ra   rc   )1Zpytestnumpyr   Zscipy.sparser   rE   Zscipy.sparse.linalgZlinalgr   Znumpy.testingr   r   	ExceptionmarkZskipifZ
pytestmarkmsgr	   ZxfailZsparse_paramsZ
bsr_matrixZ
csr_matrixZ
coo_matrixrF   Z
dia_matrixZ
dok_matrixZscipy_sparse_classesZfixturer   r   r   r   r"   r'   r/   r0   r<   rA   rC   rJ   rS   rT   rU   rV   rZ   r\   r]   r`   rc   r   r   r   r   <module>   sb    






	
