Skip to content

Commit

Permalink
OwLouvain: Properly compare new data with old without warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlin-policar committed Feb 15, 2019
1 parent ee5d4f3 commit 8fc6215
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions Orange/statistics/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions Orange/widgets/unsupervised/owlouvainclustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8fc6215

Please sign in to comment.