77from typing import Optional , Callable , Tuple , Any
88
99import numpy as np
10+ import scipy .sparse as sp
1011import networkx as nx
1112
1213from AnyQt .QtCore import (
3031from Orange .widgets .widget import Msg
3132
3233try :
33- from orangecontrib .network .network import Graph
34+ from orangecontrib .network .network import Network
3435except ImportError :
35- Graph = None
36+ Network = None
3637
3738
3839_MAX_PCA_COMPONENTS = 50
@@ -57,13 +58,10 @@ class OWLouvainClustering(widget.OWWidget):
5758 class Inputs :
5859 data = Input ("Data" , Table , default = True )
5960
60- if Graph is not None :
61- class Outputs :
62- annotated_data = Output (ANNOTATED_DATA_SIGNAL_NAME , Table , default = True )
63- graph = Output ("Network" , Graph )
64- else :
65- class Outputs :
66- annotated_data = Output (ANNOTATED_DATA_SIGNAL_NAME , Table , default = True )
61+ class Outputs :
62+ annotated_data = Output (ANNOTATED_DATA_SIGNAL_NAME , Table , default = True )
63+ if Network is not None :
64+ graph = Output ("Network" , Network )
6765
6866 apply_pca = ContextSetting (True )
6967 pca_components = ContextSetting (_DEFAULT_PCA_COMPONENTS )
@@ -391,9 +389,12 @@ def _send_data(self):
391389 new_table .get_column_view (cluster_var )[0 ][:] = new_partition
392390 self .Outputs .annotated_data .send (new_table )
393391
394- if Graph is not None :
395- graph = Graph (self .graph )
396- graph .set_items (new_table )
392+ if Network is not None :
393+ n_edges = self .graph .number_of_edges ()
394+ edges = sp .coo_matrix (
395+ (np .ones (n_edges ), np .array (self .graph .edges ()).T ),
396+ shape = (n_edges , n_edges ))
397+ graph = Network (new_table , edges )
397398 self .Outputs .graph .send (graph )
398399
399400 @Inputs .data
@@ -414,7 +415,7 @@ def set_data(self, data):
414415 self .cancel ()
415416 # Clear the outputs
416417 self .Outputs .annotated_data .send (None )
417- if Graph is not None :
418+ if Network is not None :
418419 self .Outputs .graph .send (None )
419420
420421 # Clear internal state
0 commit comments