a
    h&                     @   s^   d dl Z e dZe d d dlZd dlmZ d dlmZ G dd dZ	dd	 Z
d
d ZdS )    NnumpyZscipy)havel_hakimi_graph)margulis_gabber_galil_graphc                   @   s(   e Zd Zedd Zdd Zdd ZdS )TestLaplacianc                 C   sv   g d}t || _tdd | j D | _| jd t| j| _| j	 | _
| j
 D ]}| j
|| q^d S )N)      r      r   c                 s   s"   | ]\}}||d ddfV  qdS )      ?333333?)weightotherN ).0uvr   r   R/var/www/auris/lib/python3.9/site-packages/networkx/linalg/tests/test_laplacian.py	<genexpr>   s   z,TestLaplacian.setup_class.<locals>.<genexpr>   )r   GnxZGraphedgesWGadd_nodeZ
MultiGraphMGcopyGslnodesZadd_edge)clsdegnoder   r   r   setup_class   s    


zTestLaplacian.setup_classc                 C   s   t g dg dg dg dg dg}d| }d| }t jt| j | t jt| j | t jtj| jdd	gd
 t d	dgdd	gg t jt| j	 | t jtj| j	dd | t jtj| j	dd | dS )zGraph Laplacian)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   nodelistr!   Nr   r   )
nparraytestingZassert_equalr   Zlaplacian_matrixr   todenser   r   )selfNLZWLZOLr   r   r   test_laplacian   s&    
zTestLaplacian.test_laplacianc                 C   s<  t g dg dg dg dg dg}t g dg dg dg dg dg}t g dg dg dg d	g dg}t jjtj| jtd
d |dd t jjt| j |dd t jjt| j	 |dd t jjt| j
 |dd t jjtj| j
dd |dd t jjt| j |dd dS )zGeneralized Graph Laplacian)      ?&1ڿr-   X9v        )r-   r,         r/   r/   )r-   r0   r,   r/   r/   )r.   r/   r/   r,   r/   )r/   r/   r/   r/   r/   )g      ?登zҿr1   eaֿr/   )r1   K=U?ioTտr/   r/   )r1   r4   r3   r/   r/   )r2   r/   r/   r	   r/      r"   r   decimalr   r$   N)r%   r&   r'   assert_almost_equalr   Znormalized_laplacian_matrixr   ranger(   r   r   r   )r)   r   GLZLslr   r   r   test_normalized_laplacian2   sP    


z'TestLaplacian.test_normalized_laplacianN)__name__
__module____qualname__classmethodr    r+   r;   r   r   r   r   r      s   
r   c               	   C   sz  t  } | d tg dg dg dg dg dg dg}t j| dt| d	}tjj||d
d | d tg dg dg dg dg dg dg}t j| dt| dd}tjj||d
d tg dg dg dg dg dg dg}t j| dt| dd}tjj||d
d t  } | d tg dg dg dg d g}t j| dt| d	}tjj||d
d d!S )"zDirected Laplacian
r   r   r   r   )r   r   )r   r   )r   r5   )r   r5   )r      )r5   r   )r5   rC   )rC   r   )ŏ1w?:pΈҿ*Dؿ\ Ac̝着&}гY)rE   g7d?8gDioͿS!uqGx$(篔ec])rF   rJ   rD   PkwǺݵ|г)rG   rK   rN   rD   H}8߿\(\)rH   rL   rO   rQ   rD   )0ʿ)rI   rM   rP   rR   rS   rD   ?alphar#   r   r6   )r   r5   )rC   r   )r,   @ǘӿfj+޿r/   r/   ,ԚԿ)rX   r,   	h"lx¿r/   [<Կr/   )rY   r[   r,   r/   o_r/   )r/   r/   r/   r,   r0   r0   )r/   r\   r]   r0   r,         п)rZ   r/   r/   r0   r^   r,   randomrV   r#   	walk_type)r	   @ǘÿfj+οr/   r/   TĿ)rb   r	   ]m{r/   [<Ŀr/   )rc   re   r	   r/   +eXr/   )r/   r/   r/   r	   r^   r^   )r/   rf   rg   r^   r	         )rd   r/   r/   r^   rh   r	   lazy)rA   )r   r   )r   r   rB   )r   r   )r	   I+ƿrj   r^   )rj   r	   r/   rj   )rj   r/   r	   rj   )r^   rj   rj   r	   N)	r   DiGraphadd_edges_fromr%   r&   Zdirected_laplacian_matrixsortedr'   r8   )r   r:   Lr   r   r   test_directed_laplacian^   sV    





ro   c               	   C   s  t  } | d tg dg dg dg dg dg dg}t j| dt| d	}tjj||d
d | d tg dg dg dg dg dg dg}t j| dt| dd}tjj||d
d tg dg dg dg dg dg dg}t j| dt| dd}tjj||d
d t t	d}t |}tg dg dg dg d g}tjj||d!d t
t j  t j| d"d#d$ W d%   n1 s0    Y  t
t j t j| d&d' W d%   n1 s0    Y  d%S )(z Directed combinatorial Laplacianr@   )g46<?F%uK=U_QkMb`_vOf)rp   g
ףp=
?Aǘŏ1w-!a+eylxz,C|)rq   ru   gZӼ?y&1lSt$rt   )rr   rv   ry   g|Pk?z6>W[<Nё\˿)rs   rw   rz   r{   gt?B`"۩)rt   rx   rt   r|   r}   gjt?rT   rU   r   r6   rW   )gB`"?Biޡ+Χr/   r/   :H)r~   g+η?r/   r   r/   )r   r   Biޱ?r/   r   r/   )r/   r/   r/   KY8?KY8Žr   )r/   r   r   r   r   r   )r   r/   r/   r   r   r   r_   r`   )r   5;Nё$ۗr/   r/   rG   )r   g+Χ?wr/   r   r/   )r   r   gBiޡ?r/   r   r/   )r/   r/   r/   KY8Ž?r   r   )r/   r   r   r   r   rG   )rG   r/   r/   r   rG   r   ri   r   )K}\UU?iKGUUr   r/   )r   r   r/   r   )r   r/   r   r   )r/   r   r   r   rC   Zpagerankd   )ra   rV   NZsilly)ra   )r   rk   rl   r%   r&   Z'directed_combinatorial_laplacian_matrixrm   r'   r8   r   pytestZraisesZNetworkXError)r   r:   rn   Eexpectedr   r   r   %test_directed_combinatorial_laplacian   sd    




0r   )r   Zimportorskipr%   Znetworkxr   Znetworkx.generators.degree_seqr   Znetworkx.generators.expandersr   r   ro   r   r   r   r   r   <module>   s   

SF