Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c58ca7d

Browse filesBrowse files
MAINT Remove -Wcpp warnings when compiling sklearn.decomposition._online_lda_fast (#25020)
Co-authored-by: Julien Jerphanion <git@jjerphan.xyz>
1 parent e2e7050 commit c58ca7d
Copy full SHA for c58ca7d

File tree

2 files changed

+11
-9
lines changed
Filter options

2 files changed

+11
-9
lines changed

‎setup.py

Copy file name to clipboardExpand all lines: setup.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"sklearn.cluster._k_means_minibatch",
7979
"sklearn.datasets._svmlight_format_fast",
8080
"sklearn.decomposition._cdnmf_fast",
81+
"sklearn.decomposition._online_lda_fast",
8182
"sklearn.ensemble._gradient_boosting",
8283
"sklearn.ensemble._hist_gradient_boosting._gradient_boosting",
8384
"sklearn.ensemble._hist_gradient_boosting.histogram",

‎sklearn/decomposition/_online_lda_fast.pyx

Copy file name to clipboardExpand all lines: sklearn/decomposition/_online_lda_fast.pyx
+10-9Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ from libc.math cimport exp, fabs, log
99
from numpy.math cimport EULER
1010

1111

12-
def mean_change(cnp.ndarray[ndim=1, dtype=floating] arr_1,
13-
cnp.ndarray[ndim=1, dtype=floating] arr_2):
12+
def mean_change(const floating[:] arr_1, const floating[:] arr_2):
1413
"""Calculate the mean difference between two arrays.
1514
1615
Equivalent to np.abs(arr_1 - arr2).mean().
@@ -28,9 +27,11 @@ def mean_change(cnp.ndarray[ndim=1, dtype=floating] arr_1,
2827
return total / size
2928

3029

31-
def _dirichlet_expectation_1d(cnp.ndarray[ndim=1, dtype=floating] doc_topic,
32-
floating doc_topic_prior,
33-
cnp.ndarray[ndim=1, dtype=floating] out):
30+
def _dirichlet_expectation_1d(
31+
floating[:] doc_topic,
32+
floating doc_topic_prior,
33+
floating[:] out
34+
):
3435
"""Dirichlet expectation for a single sample:
3536
exp(E[log(theta)]) for theta ~ Dir(doc_topic)
3637
after adding doc_topic_prior to doc_topic, in-place.
@@ -56,7 +57,7 @@ def _dirichlet_expectation_1d(cnp.ndarray[ndim=1, dtype=floating] doc_topic,
5657
out[i] = exp(psi(doc_topic[i]) - psi_total)
5758

5859

59-
def _dirichlet_expectation_2d(cnp.ndarray[ndim=2, dtype=floating] arr):
60+
def _dirichlet_expectation_2d(const floating[:, :] arr):
6061
"""Dirichlet expectation for multiple samples:
6162
E[log(theta)] for theta ~ Dir(arr).
6263
@@ -66,7 +67,7 @@ def _dirichlet_expectation_2d(cnp.ndarray[ndim=2, dtype=floating] arr):
6667
the exp and doesn't add in the prior.
6768
"""
6869
cdef floating row_total, psi_row_total
69-
cdef cnp.ndarray[ndim=2, dtype=floating] d_exp
70+
cdef floating[:, :] d_exp
7071
cdef cnp.npy_intp i, j, n_rows, n_cols
7172

7273
n_rows = arr.shape[0]
@@ -82,7 +83,7 @@ def _dirichlet_expectation_2d(cnp.ndarray[ndim=2, dtype=floating] arr):
8283
for j in range(n_cols):
8384
d_exp[i, j] = psi(arr[i, j]) - psi_row_total
8485

85-
return d_exp
86+
return d_exp.base
8687

8788

8889
# Psi function for positive arguments. Optimized for speed, not accuracy.
@@ -107,4 +108,4 @@ cdef floating psi(floating x) nogil:
107108
result += log(x) - .5 * r
108109
r = r * r
109110
result -= r * ((1./12.) - r * ((1./120.) - r * (1./252.)))
110-
return result;
111+
return result

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.