8000 MAINT Use memoryviews in _random.pyx (#25780) · scikit-learn/scikit-learn@5ffec32 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5ffec32

Browse files
2357juanJuan Gomez
andauthored
MAINT Use memoryviews in _random.pyx (#25780)
Co-authored-by: Juan Gomez <{789543}+{2357juan}@users.noreply.github.com>
1 parent b0b354c commit 5ffec32

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

sklearn/utils/_random.pyx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ cpdef _sample_without_replacement_with_tracking_selection(
7878
7979
cdef cnp.int_t i
8080
cdef cnp.int_t j
81-
cdef cnp.ndarray[cnp.int_t, ndim=1] out = np.empty((n_samples, ), dtype=int)
81+
cdef cnp.int_t[:] out = np.empty((n_samples, ), dtype=int)
8282
8383
rng = check_random_state(random_state)
8484
rng_randint = rng.randint
@@ -94,7 +94,7 @@ cpdef _sample_without_replacement_with_tracking_selection(
9494
selected.add(j)
9595
out[i] = j
9696
97-
return out
97+
return np.asarray(out)
9898
9999
100100
cpdef _sample_without_replacement_with_pool(cnp.int_t n_population,
@@ -133,9 +133,9 @@ cpdef _sample_without_replacement_with_pool(cnp.int_t n_population,
133133
134134
cdef cnp.int_t i
135135
cdef cnp.int_t j
136-
cdef cnp.ndarray[cnp.int_t, ndim=1] out = np.empty((n_samples, ), dtype=int)
136+
cdef cnp.int_t[:] out = np.empty((n_samples, ), dtype=int)
137137
138-
cdef cnp.ndarray[cnp.int_t, ndim=1] pool = np.empty((n_population, ),
138+
cdef cnp.int_t[:] pool = np.empty((n_population, ),
139139
dtype=int)
140140
141141
rng = check_random_state(random_state)
@@ -153,7 +153,7 @@ cpdef _sample_without_replacement_with_pool(cnp.int_t n_population,
153153
pool[j] = pool[n_population - i - 1] # move non-selected item into
154154
# vacancy
155155
156-
return out
156+
return np.asarray(out)
157157
158158
159159
cpdef _sample_without_replacement_with_reservoir_sampling(
@@ -195,7 +195,7 @@ cpdef _sample_without_replacement_with_reservoir_sampling(
195195
196196
cdef cnp.int_t i
197197
cdef cnp.int_t j
198-
cdef cnp.ndarray[cnp.int_t, ndim=1] out = np.empty((n_samples, ), dtype=int)
198+
cdef cnp.int_t[:] out = np.empty((n_samples, ), dtype=int)
199199
200200
rng = check_random_state(random_state)
201201
rng_randint = rng.randint
@@ -212,7 +212,7 @@ cpdef _sample_without_replacement_with_reservoir_sampling(
212212
if j < n_samples:
213213
out[j] = i
214214
215-
return out
215+
return np.asarray(out)
216216
217217
218218
cpdef sample_without_replacement(cnp.int_t n_population,

0 commit comments

Comments
 (0)
0