Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] statistics: Speed up countnans for sparse matrices #2965

Merged
merged 1 commit into from
Mar 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Orange/statistics/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ def _count_nans_per_row_sparse(X, weights, dtype=None):

w = sp.coo_matrix((data_weights, (nan_rows, nan_cols)), shape=X.shape)
w = w.tocsr()
return np.asarray(w.sum(axis=1), dtype=dtype).ravel()

return np.fromiter((np.sum(row.data) for row in w), dtype=dtype)

return np.fromiter((np.isnan(row.data).sum() for row in X), dtype=dtype)
if isinstance(X, (sp.csr_matrix, sp.csc_matrix)):
X = type(X)((np.isnan(X.data), X.indices, X.indptr), X.shape)
return np.asarray(X.sum(axis=1), dtype=dtype).ravel()
else: # pragma: no cover
raise TypeError("unsupported type '{}'".format(type(X).__name__))


def sparse_count_implicit_zeros(x):
Expand Down