Skip to content

Commit

Permalink
Finalize scipy sparse fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
asistradition committed Jul 8, 2024
1 parent 5fdaa8b commit 23848c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion inferelator/preprocessing/velocity.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,6 @@ def _sparse_safe_add(x, y):
"""

if sparse.issparse(x) or sparse.issparse(y):
return todense(x + y).A
return todense(x + y)
else:
return np.add(x, y)
18 changes: 7 additions & 11 deletions inferelator/tfa/ridge_tfa.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .tfa_base import ActivityOnlyTFA
from sklearn.linear_model import Ridge
from scipy.sparse import issparse
from inferelator.utils.sparse import todense


class _Ridge_TFA_mixin:
"""
Expand All @@ -23,18 +24,13 @@ def _calculate_activity(
positive=True
)

if issparse(expression_data):
ridge_regressor.fit(
prior,
expression_data.A.T
)
else:
ridge_regressor.fit(
prior,
expression_data.T
)
ridge_regressor.fit(
prior,
todense(expression_data).T
)

return ridge_regressor.coef_.copy()


class RidgeTFA(_Ridge_TFA_mixin, ActivityOnlyTFA):
pass

0 comments on commit 23848c9

Please sign in to comment.