diff --git a/pygsp/graphs/graph.py b/pygsp/graphs/graph.py index c6fd5397..d63feca3 100644 --- a/pygsp/graphs/graph.py +++ b/pygsp/graphs/graph.py @@ -568,20 +568,17 @@ def create_incidence_matrix(self): For convenience, the heads and tails of each edge are saved in two additional attributes start_nodes and end_nodes. """ - if not hasattr(self, 'directed'): - self.is_directed() - - if self.directed or not self.connected: + if self.is_directed() or not self.is_connected(): raise NotImplementedError('Focusing on connected non directed graphs first.') start_nodes, end_nodes, weights = sparse.find(sparse.tril(self.W)) - data = np.concatenate([np.ones(self.Ne/2), -np.ones(self.Ne/2)]) - row = np.concatenate([np.arange(self.Ne/2), np.arange(self.Ne/2)]) + data = np.concatenate([np.ones_like(start_nodes), -np.ones_like(end_nodes)]) + row = np.concatenate([np.arange(len(start_nodes)), np.arange(len(end_nodes))]) col = np.concatenate([start_nodes, end_nodes]) self.B = sparse.coo_matrix((data, (row, col)), - shape=(self.Ne/2, self.N) ).tocsc() + shape=(len(start_nodes), self.N) ).tocsc() self.Wb = sparse.diags(weights,0) self.start_nodes = start_nodes self.end_nodes = end_nodes diff --git a/pygsp/reduction.py b/pygsp/reduction.py index 294d1730..45c4421d 100644 --- a/pygsp/reduction.py +++ b/pygsp/reduction.py @@ -339,7 +339,6 @@ def kron_reduction(G, ind, threshold=np.spacing(1)): """ if isinstance(G, graphs.Graph): - if G.lap_type != 'combinatorial': msg = 'Unknown reduction for {} Laplacian.'.format(G.lap_type) raise NotImplementedError(msg) @@ -353,14 +352,13 @@ def kron_reduction(G, ind, threshold=np.spacing(1)): else: L = G - N = np.shape(L)[0] ind_comp = np.setdiff1d(np.arange(N, dtype=int), ind) - L_red = extract_submatrix(L,ind, ind) - L_in_out = extract_submatrix(L, ind, ind_comp) + L_red = utils.extract_submatrix(L,ind, ind) + L_in_out = utils.extract_submatrix(L, ind, ind_comp) L_out_in = L_in_out.transpose().tocsc() - L_comp = extract_submatrix(L,ind_comp, ind_comp).tocsc() + L_comp = utils.extract_submatrix(L,ind_comp, ind_comp).tocsc() Lnew = L_red - L_in_out.dot(utils.splu_inv_dot(L_comp, L_out_in))