
    çg7                         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
                            ||           t          j                    | _        | j                            d           t          j        | j                  | _        t          j        d | j                                        D                       | _        | 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      `/var/www/html/ai-engine/env/lib/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   r   r   r
   )r
   r   )r
   r   )r
      )r   r   )r      )r   r   )r   r    )r    r   c              3   ,   K   | ]\  }}||d ddfV  dS r   r   r   s      r   r   z,TestLaplacian.setup_class.<locals>.<genexpr>-   sF       
 
6<q!QcC001
 
 
 
 
 
r   )r   GnxGraphedgesWGadd_node
MultiGraphMGcopyGslnodesadd_edgeDiGraphDiGadd_edges_fromMultiDiGraphDiMGDiWGDiGsl)clsdegnodes      r   setup_classzTestLaplacian.setup_class   s   oo"3'' 
 
@C
 
 
 
 
 	su%% %**,,GMMOO 	) 	)DGT4(((( *,,	
 	
 	
 ?37++: 
 
@C
 
 
 
 
 GLLNN	IOO%% 	+ 	+DItT****	+ 	+r   c           	      H   t                               g dg dg dg dg dg          }d|z  }d|z  }t                               g d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                                          |           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:   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:   )r   r   r   r   r:   r   r   r   nodelistr:   Nr   r   r   )nparraytestingassert_equalr#   laplacian_matrixr"   todenser)   r&   r/   r2   r3   )selfNLWLOLDiNLDiWLDiOLs          r   test_laplacianzTestLaplacian.test_laplacian4   s    XX+++++++++++++++	- . . 2X2Xxx1111111111111111113 4 4 TzTz

 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	
 	
 	
 	
 3DH = = E E G GNNN

 3DI > > F F H H$OOO

Aq6:::BBDDHHq"g1v&''	
 	
 	
 	
 3DI > > F F H H$OOO

	$777??AA4	
 	
 	
 	
	':::BBDDd	
 	
 	
 	
 	
r   c           	      R	   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                               g d
g dg dg dg dg dg          }t                               g d
g dg dg dg dg dg          }t                               g d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           t           j                            t	          j        | j        t          d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ڿrN   X9v        )rN   rM         rP   rP   )rN   rQ   rM   rP   rP   )rO   rP   rP   rM   rP   )rP   rP   rP   rP   rP   )      ?登zҿrS   eaֿrP   )rS   K=U?ioTտrP   rP   )rS   rV   rU   rP   rP   )rT   rP   rP   r   rP   )rM   rP   rڿrP   rP   rP   )rP   rP   rP   rP   rP   rP   )rW   rP   rM   rP   rW   rP   )rP   rP   rP   rM   rQ   -)rP   rP   rP   rQ   rM   rX   )rP   rP   rP   rX   rP   rM   )rW   rP   rM   rW   rP   rP   )rP   rP   rP   rP   rX   rM   )rU   gzrS   rP   rP   rP   )rS   rQ   rR   rS   rP   rP   )rP   rP   rP   rU   rV   rW   )rP   rP   rP   rV   rU   rW   )rP   rP   rP   rP   rW   r   r   r;   r
   decimalr   r=   r      N)r>   r?   r@   assert_almost_equalr#   normalized_laplacian_matrixr"   rangerC   r)   r&   r+   r/   r2   r3   r4   )rD   r"   GLLslr/   DiGLDiLsls          r   test_normalized_laplacianz'TestLaplacian.test_normalized_laplacianc   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 hhNNNNNNNNNNNNNNNNNNP Q Q xxOOOOOOOOOOOOOOOOOOQ R R PPPPPPPPPPPPPPPPPPR S S 	
&&*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 	' 	
 	
 	
 	
&&*q%   gii 	' 	
 	
 	
 	
&&*4844<<>>a 	' 	
 	
 	
 	
&&*4955==??q 	' 	
 	
 	
 	
&&*4955==??q 	' 	
 	
 	
 	
&&*49WEEEMMOO 	' 	
 	
 	

 	
&&*4:66>>@@%QR 	' 	
 	
 	
 	
 	
r   N)__name__
__module____qualname__classmethodr8   rK   rc   r   r   r   r   r      sR        %+ %+ [%+N-
 -
 -
^V
 V
 V
 V
 V
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 Laplacianr   )ŏ1w?:pΈҿ*Dؿ\ Ac̝着&}гY)rj   g7d?8gDioͿS!uqGx$(篔ec])rk   ro   ri   PkwǺݵ|г)rl   rp   rs   ri   H}8߿\(\)rm   rq   rt   rv   ri   )0ʿ)rn   rr   ru   rw   rx   ri   ?alphar<   r
   rY   )r   r   )r    r   )rM   @ǘӿfj+޿rP   rP   ,ԚԿ)r}   rM   	h"lx¿rP   [<ԿrP   )r~   r   rM   rP   o_rP   )rP   rP   rP   rM   rQ   rQ   )rP   r   r   rQ   rM         п)r   rP   rP   rQ   r   rM   randomr{   r<   	walk_type)r   @ǘÿfj+οrP   rP   TĿ)r   r   ]m{rP   [<ĿrP   )r   r   r   rP   +eXrP   )rP   rP   rP   r   r   r   )rP   r   r   r   r         )r   rP   rP   r   r   r   lazy)r   )r   r   )r   r   r   )r
   r   )r   I+ƿr   r   )r   r   rP   r   )r   rP   r   r   )r   r   r   r   N)	r#   r.   r0   r>   r?   directed_laplacian_matrixsortedr@   r\   )r"   r_   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 Laplacianr   )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?ry   rz   r
   rY   r|   )gB`"?Biޡ+ΧrP   rP   :H)r   g+η?rP   r   rP   )r   r   Biޱ?rP   r   rP   )rP   rP   rP   KY8?KY8Žr   )rP   r   r   r   r   r   )r   rP   rP   r   r   r   r   r   )r   5;Nё$ۗrP   rP   rl   )r   g+Χ?wrP   r   rP   )r   r   gBiޡ?rP   r   rP   )rP   rP   rP   KY8Ž?r   r   )rP   r   r   r   r   rl   )rl   rP   rP   r   rl   r   r   r   )K}\UU?iKGUUr   rP   )r   r   rP   r   )r   rP   r   r   )rP   r   r   r   r    pagerankd   )r   r{   Nsilly)r   )r#   r.   r0   r>   r?   'directed_combinatorial_laplacian_matrixr   r@   r\   r   pytestraisesNetworkXError)r"   r_   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n
 n
 n
 n
 n
 n
 n
 n
bC5 C5 C5LNI NI NI NI NIr   