Permalink
Browse files

BUG: fix csgraph.laplacian bug. See PR-266 for details.

  • Loading branch information...
rgommers committed Jul 16, 2012
1 parent 73b61f5 commit c818914c8dba6d89ffe813f20b32dbf0cb952de0
Showing with 4 additions and 2 deletions.
  1. +3 −1 scipy/sparse/csgraph/_laplacian.py
  2. +1 −1 scipy/sparse/csgraph/tests/test_graph_laplacian.py
@@ -106,9 +106,10 @@ def _laplacian_sparse(graph, normed=False, return_diag=False):
w[w_zeros] = 1
lap.data /= w[lap.row]
lap.data /= w[lap.col]
- lap.data[diag_mask] = (1 - w_zeros).astype(lap.data.dtype)
+ lap.data[diag_mask] = (1 - w_zeros[lap.row[diag_mask]]).astype(lap.data.dtype)
else:
lap.data[diag_mask] = w[lap.row[diag_mask]]
+
if return_diag:
return lap, w
return lap
@@ -130,6 +131,7 @@ def _laplacian_dense(graph, normed=False, return_diag=False):
lap.flat[::n_nodes + 1] = 1 - w_zeros
else:
lap.flat[::n_nodes + 1] = w
+
if return_diag:
return lap, w
return lap
@@ -15,7 +15,7 @@ def _explicit_laplacian(x, normed=False):
for j in range(y.shape[0]):
y[j,j] = x[j,j+1:].sum() + x[j,:j].sum()
if normed:
- d = np.diag(y)
+ d = np.diag(y).copy()
d[d == 0] = 1.0
y /= d[:,None]**.5
y /= d[None,:]**.5

0 comments on commit c818914

Please sign in to comment.