@@ -244,12 +244,11 @@ def _compute_label_chunk_bitmask(labels, chunks, nlabels):
244
244
245
245
labels = np .broadcast_to (labels , shape [- labels .ndim :])
246
246
247
- rows = []
248
247
cols = []
249
248
# Add one to handle the -1 sentinel value
250
249
label_is_present = np .zeros ((nlabels + 1 ,), dtype = bool )
251
250
ilabels = np .arange (nlabels )
252
- for idx , region in enumerate ( slices_from_chunks (chunks ) ):
251
+ for region in slices_from_chunks (chunks ):
253
252
# This is a quite fast way to find unique integers, when we know how many there are
254
253
# inspired by a similar idea in numpy_groupies for first, last
255
254
# instead of explicitly finding uniques, repeatedly write True to the same location
@@ -259,10 +258,9 @@ def _compute_label_chunk_bitmask(labels, chunks, nlabels):
259
258
# skip the -1 sentinel by slicing
260
259
# Faster than np.argwhere by a lot
261
260
uniques = ilabels [label_is_present [:- 1 ]]
262
- rows .append (np .full_like (uniques , idx ))
263
261
cols .append (uniques )
264
262
label_is_present [:] = False
265
- rows_array = np .concatenate ( rows )
263
+ rows_array = np .repeat ( np . arange ( nchunks ), tuple ( len ( col ) for col in cols ) )
266
264
cols_array = np .concatenate (cols )
267
265
data = np .broadcast_to (np .array (1 , dtype = np .uint8 ), rows_array .shape )
268
266
bitmask = csc_array ((data , (rows_array , cols_array )), dtype = bool , shape = (nchunks , nlabels ))
0 commit comments