diff --git a/Orange/statistics/util.py b/Orange/statistics/util.py index a32b59ee81b..c1b82014181 100644 --- a/Orange/statistics/util.py +++ b/Orange/statistics/util.py @@ -12,6 +12,21 @@ import scipy.stats.stats +def sparse_array_equal(x1, x2): + """Check if two sparse arrays are equal.""" + assert sp.issparse(x1) + assert sp.issparse(x2) + + return x1.shape == x2.shape and (x1 != x2).nnz == 0 + + +def array_equal(x1, x2): + """Equivalent of np.array_equal that properly handles sparse matrices.""" + if sp.issparse(x1) and sp.issparse(x2): + return sparse_array_equal(x1, x2) + return np.array_equal(x1, x2) + + def _count_nans_per_row_sparse(X, weights, dtype=None): """ Count the number of nans (undefined) values per row. """ if weights is not None: diff --git a/Orange/widgets/unsupervised/owlouvainclustering.py b/Orange/widgets/unsupervised/owlouvainclustering.py index 3e6f1cecf9c..05c1a48be74 100644 --- a/Orange/widgets/unsupervised/owlouvainclustering.py +++ b/Orange/widgets/unsupervised/owlouvainclustering.py @@ -19,6 +19,7 @@ from Orange.data.util import get_unique_names from Orange import preprocess from Orange.projection import PCA +from Orange.statistics import util as ut from Orange.widgets import widget, gui, report from Orange.widgets.settings import DomainContextHandler, ContextSetting, \ Setting @@ -407,8 +408,7 @@ def set_data(self, data): # Make sure to properly enable/disable slider based on `apply_pca` setting self.controls.pca_components.setEnabled(self.apply_pca) - # If X hasn't changed, there's no reason to recompute clusters - if prev_data and self.data and np.array_equal(self.data.X, prev_data.X): + if prev_data and self.data and ut.array_equal(prev_data, self.data): if self.auto_commit: self._send_data() return