
    Gd&                         d dl Z  e j        d          Z e j        d           d dlZd dlmZ d dlmZ  G d d          Z	d Z
d	 ZdS )
    Nnumpyscipy)havel_hakimi_graph)margulis_gabber_galil_graphc                   0    e Zd Zed             Zd Zd ZdS )TestLaplacianc                    g d}t          |          | _        t          j        d | j                                        D                       | _        | j                            d           t          j        | j                  | _        | j        	                                | _
        | j
                                        D ]}| j
                            ||           d S )N)      r      r   c              3   ,   K   | ]\  }}||d ddfV  dS )      ?333333?)weightotherN ).0uvs      Dlib/python3.11/site-packages/networkx/linalg/tests/test_laplacian.py	<genexpr>z,TestLaplacian.setup_class.<locals>.<genexpr>   sF       
 
6<q!QcC001
 
 
 
 
 
       )r   GnxGraphedgesWGadd_node
MultiGraphMGcopyGslnodesadd_edge)clsdegnodes      r   setup_classzTestLaplacian.setup_class   s    oo"3'' 
 
@C
 
 
 
 
 	su%% %**,,GMMOO 	) 	)DGT4((((	) 	)r   c                 $   t                               g dg dg dg dg dg          }d|z  }d|z  }t           j                            t	          j        | j                                                  |           t           j                            t	          j        | j                                                  |           t           j                            t	          j        | j        dd	g
                                          t                               d	dgdd	gg                     t           j                            t	          j        | j	                                                  |           t           j                            t	          j        | j	        d                                          |           t           j                            t	          j        | j	        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testingassert_equalr   laplacian_matrixr   todenser!   r   )selfNLWLOLs       r   test_laplacianzTestLaplacian.test_laplacian   s    XX+++++++++++++++	- . . 2X2X

 3DF ; ; C C E ErJJJ

 3DG < < D D F FKKK

!Q888@@BBHHq"gAw'((	
 	
 	
 	
 3DG < < D D F FKKK

 3DGD I I I Q Q S SUWXXX

888@@BBB	
 	
 	
 	
 	
r   c                    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                            t	          j        | j        t          d
                                                    |d           t           j                            t	          j        | j                                                  |d           t           j                            t	          j        | j	                                                  |d           t           j                            t	          j        | j
                                                  |d           t           j                            t	          j        | j
        d                                          |d           t           j                            t	          j        | j                                                  |d           dS )zGeneralized Graph Laplacian)      ?&1ڿr<   X9v        )r<   r;         r>   r>   )r<   r?   r;   r>   r>   )r=   r>   r>   r;   r>   )r>   r>   r>   r>   r>   )g      ?登zҿr@   eaֿr>   )r@   K=U?ioTտr>   r>   )r@   rC   rB   r>   r>   )rA   r>   r>   r   r>      r,   r
   decimalr   r.   N)r/   r0   r1   assert_almost_equalr   normalized_laplacian_matrixr   ranger4   r!   r   r#   )r5   r   GLLsls       r   test_normalized_laplacianz'TestLaplacian.test_normalized_laplacian2   s    HH;;;;;;;;;;;;;;;	= > >
 XX???????????????	A B B
 hhEEEEEEEEEEEEEEE	G H H 	
&&*46E!HHEEEMMOO 	' 	
 	
 	

 	
&&*4622::<<b! 	' 	
 	
 	
 	
&&*4733;;==r1 	' 	
 	
 	
 	
&&*4733;;==r1 	' 	
 	
 	
 	
&&*477CCCKKMM 	' 	
 	
 	

 	
&&*4844<<>>Q 	' 	
 	
 	
 	
 	
r   N)__name__
__module____qualname__classmethodr)   r9   rL   r   r   r   r   r      sK        ) ) [)
 
 
.)
 )
 )
 )
 )
r   r   c            	      X   t          j                    } |                     d           t                              g dg dg dg dg dg dg          }t          j        | dt          |           	          }t          j                            ||d
           |                     d           t                              g dg dg dg dg dg dg          }t          j        | dt          |           d          }t          j                            ||d
           t                              g dg dg dg dg dg dg          }t          j        | dt          |           d          }t          j                            ||d
           t          j                    } |                     d           t                              g dg dg dg d g          }t          j        | dt          |           	          }t          j                            ||d
           d!S )"zDirected Laplacian
r   r   r   r
   )r
   r   )r
   r   )r
   rD   )r   rD   )r      )rD   r   )rD   rU   )rU   r   )ŏ1w?:pΈҿ*Dؿ\ Ac̝着&}гY)rW   g7d?8gDioͿS!uqGx$(篔ec])rX   r\   rV   PkwǺݵ|г)rY   r]   r`   rV   H}8߿\(\)rZ   r^   ra   rc   rV   )0ʿ)r[   r_   rb   rd   re   rV   ?alphar-   r
   rE   )r   rD   )rU   r   )r;   @ǘӿfj+޿r>   r>   ,ԚԿ)rj   r;   	h"lx¿r>   [<Կr>   )rk   rm   r;   r>   o_r>   )r>   r>   r>   r;   r?   r?   )r>   rn   ro   r?   r;         п)rl   r>   r>   r?   rp   r;   randomrh   r-   	walk_type)r   @ǘÿfj+οr>   r>   TĿ)rt   r   ]m{r>   [<Ŀr>   )ru   rw   r   r>   +eXr>   )r>   r>   r>   r   rp   rp   )r>   rx   ry   rp   r         )rv   r>   r>   rp   rz   r   lazy)rS   )r   r   )r   r   rT   )r
   r   )r   I+ƿr|   rp   )r|   r   r>   r|   )r|   r>   r   r|   )rp   r|   r|   r   N)	r   DiGraphadd_edges_fromr/   r0   directed_laplacian_matrixsortedr1   rG   )r   rJ   Ls      r   test_directed_laplacianr   ^   s   
 	
A	
   
IIIIIIIIIIIIIIIIIIK 
L 
LB 	$QcF1IIFFFAJ""1b!"444 %&&&	IIIIIIIIIIIIIIIIIIK 
L 
LB 	$	vayyH	 	 	A J""1b!"444 
IIIIIIIIIIIIIIIIIIK 
L 
LB 	$QcF1IIQWXXXAJ""1b!"444 	
A=>>>	3333333333335 
6 
6B
 	$QcF1IIFFFAJ""1b!"44444r   c            	      ^   t          j                    } |                     d           t                              g dg dg dg dg dg dg          }t          j        | dt          |           	          }t          j                            ||d
           |                     d           t                              g dg dg dg dg dg dg          }t          j        | dt          |           d          }t          j                            ||d
           t                              g dg dg dg dg dg dg          }t          j        | dt          |           d          }t          j                            ||d
           t          j        t          d                    }t          j        |          }t                              g dg dg dg d g          }t          j                            ||d!           t          j        t           j                  5  t          j        | d"d#$           d%d%d%           n# 1 swxY w Y   t          j        t           j                  5  t          j        | d&'           d%d%d%           d%S # 1 swxY w Y   d%S )(z Directed combinatorial LaplacianrR   )g46<?F%uK=U_QkMb`_vOf)r   g
ףp=
?Aǘŏ1w-!a+eylxz,C|)r   r   gZӼ?y&1lSt$r   )r   r   r   g|Pk?z6>W[<Nё\˿)r   r   r   r   gt?B`"۩)r   r   r   r   r   gjt?rf   rg   r
   rE   ri   )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   rq   rr   )r   5;Nё$ۗr>   r>   rY   )r   g+Χ?wr>   r   r>   )r   r   gBiޡ?r>   r   r>   )r>   r>   r>   KY8Ž?r   r   )r>   r   r   r   r   rY   )rY   r>   r>   r   rY   r   r{   r   )K}\UU?iKGUUr   r>   )r   r   r>   r   )r   r>   r   r   )r>   r   r   r   rU   pagerankd   )rs   rh   Nsilly)rs   )r   r}   r~   r/   r0   'directed_combinatorial_laplacian_matrixr   r1   rG   r   pytestraisesNetworkXError)r   rJ   r   Eexpecteds        r   %test_directed_combinatorial_laplacianr      s   
 	
A	
   
IIIIIIIIIIIIIIIIIIK 
L 
LB 	21C&QR))TTTAJ""1b!"444 %&&& 
IIIIIIIIIIIIIIIIIIK 
L 
LB 	2	vayyH	 	 	A J""1b!"444 
IIIIIIIIIIIIIIIIIIK 
L 
LB 	2	vayyF	 	 	A J""1b!"444

.q1122A
2155Axx	=	=	=	=	=	=	=	=	=	=	=	=	? H J""1h":::	r'	(	( W W
21
RUVVVVW W W W W W W W W W W W W W W	r'	(	( I I
21HHHHI I I I I I I I I I I I I I I I I Is$   1III>J""J&)J&)r   importorskipr/   networkxr   networkx.generators.degree_seqr   networkx.generators.expandersr   r   r   r   r   r   r   <module>r      s    V!!  G        = = = = = = E E E E E EP
 P
 P
 P
 P
 P
 P
 P
fC5 C5 C5LNI NI NI NI NIr   