@@ -568,20 +568,17 @@ def create_incidence_matrix(self):
568568 For convenience, the heads and tails of each edge are saved in two
569569 additional attributes start_nodes and end_nodes.
570570 """
571- if not hasattr (self , 'directed' ):
572- self .is_directed ()
573-
574- if self .directed or not self .connected :
571+ if self .is_directed () or not self .is_connected ():
575572 raise NotImplementedError ('Focusing on connected non directed graphs first.' )
576573
577574 start_nodes , end_nodes , weights = sparse .find (sparse .tril (self .W ))
578575
579- data = np .concatenate ([np .ones ( self . Ne / 2 ), - np .ones ( self . Ne / 2 )])
580- row = np .concatenate ([np .arange (self . Ne / 2 ) , np .arange (self . Ne / 2 )])
576+ data = np .concatenate ([np .ones_like ( start_nodes ), - np .ones_like ( end_nodes )])
577+ row = np .concatenate ([np .arange (len ( start_nodes )) , np .arange (len ( end_nodes ) )])
581578 col = np .concatenate ([start_nodes , end_nodes ])
582579
583580 self .B = sparse .coo_matrix ((data , (row , col )),
584- shape = (self . Ne / 2 , self .N ) ).tocsc ()
581+ shape = (len ( start_nodes ) , self .N ) ).tocsc ()
585582 self .Wb = sparse .diags (weights ,0 )
586583 self .start_nodes = start_nodes
587584 self .end_nodes = end_nodes
0 commit comments