-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[MRG] Make subfunctions of sparsefuncs private #6659
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
Closed
yenchenlin
wants to merge
1
commit into
scikit-learn:master
from
yenchenlin:make-sparse-utils-funtions-private
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -6,6 +6,9 @@ | |
# | ||
# Licence: BSD 3 clause | ||
|
||
#!python | ||
#cython: boundscheck=False, wraparound=False, cdivision=True | ||
|
||
from libc.math cimport fabs, sqrt, pow | ||
cimport numpy as np | ||
import numpy as np | ||
|
@@ -18,9 +21,6 @@ np.import_array() | |
|
||
ctypedef np.float64_t DOUBLE | ||
|
||
@cython.boundscheck(False) | ||
@cython.wraparound(False) | ||
@cython.cdivision(True) | ||
def csr_row_norms(X): | ||
"""L2 norm of each row in CSR matrix X.""" | ||
cdef: | ||
|
@@ -46,9 +46,6 @@ def csr_row_norms(X): | |
return norms | ||
|
||
|
||
@cython.boundscheck(False) | ||
@cython.wraparound(False) | ||
@cython.cdivision(True) | ||
def csr_mean_variance_axis0(X): | ||
"""Compute mean and variance along axis 0 on a CSR matrix | ||
|
||
|
@@ -109,9 +106,6 @@ def csr_mean_variance_axis0(X): | |
return means, variances | ||
|
||
|
||
@cython.boundscheck(False) | ||
@cython.wraparound(False) | ||
@cython.cdivision(True) | ||
def csc_mean_variance_axis0(X): | ||
"""Compute mean and variance along axis 0 on a CSC matrix | ||
|
||
|
@@ -172,9 +166,6 @@ def csc_mean_variance_axis0(X): | |
return means, variances | ||
|
||
|
||
@cython.boundscheck(False) | ||
@cython.wraparound(False) | ||
@cython.cdivision(True) | ||
def incr_mean_variance_axis0(X, last_mean, last_var, unsigned long last_n): | ||
"""Compute mean and variance along axis 0 on a CSR or CSC matrix. | ||
|
||
|
@@ -271,17 +262,15 @@ def incr_mean_variance_axis0(X, last_mean, last_var, unsigned long last_n): | |
return updated_mean, updated_var, updated_n | ||
|
||
|
||
@cython.boundscheck(False) | ||
@cython.wraparound(False) | ||
@cython.cdivision(True) | ||
def inplace_csr_row_normalize_l1(X): | ||
"""Inplace row normalize using the l1 norm""" | ||
_inplace_csr_row_normalize_l1(X.data, X.shape, X.indices, X.indptr) | ||
|
||
|
||
def _inplace_csr_row_normalize_l1(np.ndarray[floating, ndim=1] X_data, shape, | ||
def _inplace_csr_row_normalize_l1(np.ndarray[floating, ndim=1] X_data, | ||
shape, | ||
np.ndarray[int, ndim=1] X_indices, | ||
np.ndarray[int, ndim=1] X_indptr): | ||
"""Inplace row normalize using the l1 norm""" | ||
cdef unsigned int n_samples = shape[0] | ||
cdef unsigned int n_features = shape[1] | ||
|
||
|
@@ -308,18 +297,15 @@ def _inplace_csr_row_normalize_l1(np.ndarray[floating, ndim=1] X_data, shape, | |
X_data[j] /= sum_ | ||
|
||
|
||
@cython.boundscheck(False) | ||
@cython.wraparound(False) | ||
@cython.cdivision(True) | ||
def inplace_csr_row_normalize_l2(X): | ||
"""Inplace row normalize using the l2 norm""" | ||
_inplace_csr_row_normalize_l2(X.data, X.shape, X.indices, X.indptr) | ||
|
||
|
||
def _inplace_csr_row_normalize_l2(np.ndarray[floating, ndim=1] X_data, | ||
shape, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment on PEP8 compliance here too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for pointing out, fixed! |
||
np.ndarray[int, ndim=1] X_indices, | ||
np.ndarray[int, ndim=1] X_indptr): | ||
"""Inplace row normalize using the l2 norm""" | ||
cdef unsigned int n_samples = shape[0] | ||
cdef unsigned int n_features = shape[1] | ||
|
||
|
@@ -344,8 +330,6 @@ def _inplace_csr_row_normalize_l2(np.ndarray[floating, ndim=1] X_data, | |
X_data[j] /= sum_ | ||
|
||
|
||
@cython.boundscheck(False) | ||
@cython.wraparound(False) | ||
cdef void add_row_csr(np.ndarray[np.float64_t, ndim=1] data, | ||
np.ndarray[int, ndim=1] indices, | ||
np.ndarray[int, ndim=1] indptr, | ||
|
@@ -361,8 +345,6 @@ cdef void add_row_csr(np.ndarray[np.float64_t, ndim=1] data, | |
out[j] += data[ind] | ||
|
||
|
||
@cython.boundscheck(False) | ||
@cython.wraparound(False) | ||
def assign_rows_csr(X, | ||
np.ndarray[np.npy_intp, ndim=1] X_rows, | ||
np.ndarray[np.npy_intp, ndim=1] out_rows, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've one character above but not a space here to match the indentation. Is this still PEP8 compliant?