Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython_plus_experiments
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Julien Jerphanion
cython_plus_experiments
Commits
3108946b
Commit
3108946b
authored
Apr 08, 2021
by
Julien Jerphanion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unused support for sparse matrices
parent
362ffb35
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
35 deletions
+3
-35
kmeans/_kmeans.pyx
kmeans/_kmeans.pyx
+3
-35
No files found.
kmeans/_kmeans.pyx
View file @
3108946b
...
...
@@ -19,7 +19,6 @@ from libc.stdlib cimport malloc, calloc, free
from
libc.string
cimport
memset
from
libc.math
cimport
sqrt
from
scipy.linalg.cython_blas
cimport
sgemm
,
dgemm
from
scipy
import
sparse
np
.
import_array
()
...
...
@@ -244,38 +243,12 @@ cpdef void _relocate_empty_clusters_dense(
weight_in_clusters
[
new_cluster_id
]
=
weight
weight_in_clusters
[
old_cluster_id
]
-=
weight
def
_csr_row_norms
(
X
):
"""L2 norm of each row in CSR matrix X."""
if
X
.
dtype
not
in
[
np
.
float32
,
np
.
float64
]:
X
=
X
.
astype
(
np
.
float64
)
return
_csr_row_norms
(
X
.
data
,
X
.
shape
,
X
.
indices
,
X
.
indptr
)
def
_csr_row_norms
(
np
.
ndarray
[
floating
,
ndim
=
1
,
mode
=
"c"
]
X_data
,
shape
,
np
.
ndarray
[
integral
,
ndim
=
1
,
mode
=
"c"
]
X_indices
,
np
.
ndarray
[
integral
,
ndim
=
1
,
mode
=
"c"
]
X_indptr
):
cdef
:
unsigned
long
long
n_samples
=
shape
[
0
]
unsigned
long
long
i
integral
j
double
sum_
norms
=
np
.
empty
(
n_samples
,
dtype
=
X_data
.
dtype
)
cdef
floating
[::
1
]
norms_view
=
norms
for
i
in
range
(
n_samples
):
sum_
=
0.0
for
j
in
range
(
X_indptr
[
i
],
X_indptr
[
i
+
1
]):
sum_
+=
X_data
[
j
]
*
X_data
[
j
]
norms_view
[
i
]
=
sum_
return
norms
def
row_norms
(
X
,
squared
=
False
):
"""Row-wise (squared) Euclidean norm of X.
Equivalent to np.sqrt((X * X).sum(axis=1)), but
also supports spars
e
matrices and does not create
an X.shape-sized temporary.
Equivalent to np.sqrt((X * X).sum(axis=1)), but
does not creat
e
an X.shape-sized temporary.
Performs no input validation.
...
...
@@ -291,12 +264,7 @@ def row_norms(X, squared=False):
array-like
The row-wise (squared) Euclidean norm of X.
"""
if
sparse
.
issparse
(
X
):
if
not
isinstance
(
X
,
sparse
.
csr_matrix
):
X
=
sparse
.
csr_matrix
(
X
)
norms
=
_csr_row_norms
(
X
)
else
:
norms
=
np
.
einsum
(
'ij,ij->i'
,
X
,
X
)
norms
=
np
.
einsum
(
'ij,ij->i'
,
X
,
X
)
if
not
squared
:
np
.
sqrt
(
norms
,
norms
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment