From d398b7fd9648b9d21cae3adc860d6d68650a35e1 Mon Sep 17 00:00:00 2001 From: Vighnesh Birodkar Date: Wed, 23 Jul 2014 23:35:31 +0530 Subject: [PATCH] used standard eignen solver --- skimage/graph/graph_cut.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/skimage/graph/graph_cut.py b/skimage/graph/graph_cut.py index acb7d481..c15eb7c0 100644 --- a/skimage/graph/graph_cut.py +++ b/skimage/graph/graph_cut.py @@ -138,10 +138,17 @@ def _ncut_relabel(rag, thresh, num_cuts): """ d, w = _ncut.DW_matrix(rag) error = False + try: m = w.shape[0] - vals, vectors = linalg.eigsh(d - w, M=d, which='SM', + d2 = d.copy() + # Since d is diagonal, we can directly operate on it's data + # the inverse + d2.data = 1.0/d2.data + # the square root + d2.data = np.sqrt(d2.data) + vals, vectors = linalg.eigsh(d2*(d - w)*d2, which='SM', k=min(100, m - 2)) except ArpackNoConvergence as e: # Not all eigenvectors converged, salvage the remaining.