forked from scikit-learn/scikit-learn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved sparsefuncs to sparsefuncs_fast
- Loading branch information
Showing
12 changed files
with
682 additions
and
1,155 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Authors: Manoj Kumar | ||
|
||
# License: BSD 3 clause | ||
import scipy.sparse as sp | ||
|
||
from .sparsefuncs_fast import (csr_mean_variance_axis0, | ||
csc_mean_variance_axis0, | ||
inplace_csr_column_scale, | ||
inplace_csc_column_scale) | ||
|
||
def mean_variance_axis0(X): | ||
"""Compute mean and variance along axis 0 on a CSR or CSC matrix | ||
Parameters | ||
---------- | ||
X: CSR or CSC sparse matrix, shape (n_samples, n_features) | ||
Input data. | ||
Returns | ||
------- | ||
means: float array with shape (n_features,) | ||
Feature-wise means | ||
variances: float array with shape (n_features,) | ||
Feature-wise variances | ||
""" | ||
if isinstance(X, sp.csr_matrix): | ||
return csr_mean_variance_axis0(X) | ||
elif isinstance(X, sp.csc_matrix): | ||
return csc_mean_variance_axis0(X) | ||
else: | ||
raise TypeError( | ||
"Unsupported type; expected a CSR or CSC sparse matrix.") | ||
|
||
|
||
def inplace_column_scale(X, scale): | ||
"""Inplace column scaling of a CSC/CSR matrix. | ||
Scale each feature of the data matrix by multiplying with specific scale | ||
provided by the caller assuming a (n_samples, n_features) shape. | ||
Parameters | ||
---------- | ||
X: CSC or CSR matrix with shape (n_samples, n_features) | ||
Matrix to normalize using the variance of the features. | ||
scale: float array with shape (n_features,) | ||
Array of precomputed feature-wise values to use for scaling. | ||
""" | ||
if isinstance(X, sp.csr_matrix): | ||
return inplace_csr_column_scale(X, scale) | ||
elif isinstance(X, sp.csc_matrix): | ||
return inplace_csc_column_scale(X, scale) | ||
else: | ||
raise TypeError( | ||
"Unsupported type; expected a CSR or CSC sparse matrix.") |
1,329 changes: 423 additions & 906 deletions
1,329
sklearn/utils/sparsefuncs.c → sklearn/utils/sparsefuncs_fast.c
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters