Skip to content

Commit

Permalink
update trimming
Browse files Browse the repository at this point in the history
  • Loading branch information
Intron7 committed Nov 6, 2024
1 parent 7b98cb9 commit 3cc7aed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/rapids_singlecell/preprocessing/_kernels/_bbknn.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
extern "C" __global__
void cut_smaller(
const int *indptr,
const int * index,
float *data,
float* vals,
int n_rows) {
Expand All @@ -74,13 +75,15 @@
int start_idx = indptr[row_id];
int stop_idx = indptr[row_id+1];
float cut = vals[row_id];
float cut_row = vals[row_id];
for(int i = start_idx+threadIdx.x; i < stop_idx; i+= blockDim.x){
float cut = max(vals[index[i]], cut_row);
if(data[i]<cut){
data[i] = 0;
}
}
}
"""
cut_smaller_func = cp.RawKernel(_cut_smaller_kernel, "cut_smaller")
15 changes: 6 additions & 9 deletions src/rapids_singlecell/preprocessing/_neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,12 @@ def _trimming(cnts: cp_sparse.csr_matrix, trim: int) -> cp_sparse.csr_matrix:
(cnts.data, cnts.indptr, cnts.shape[0], trim, vals_gpu),
shared_mem=shared_mem_size,
)

for _ in range(2):
cut_smaller_func(
(cnts.shape[0],),
(64,),
(cnts.indptr, cnts.data, vals_gpu, cnts.shape[0]),
)
cnts.eliminate_zeros()
cnts = cnts.T.tocsr()
cut_smaller_func(
(cnts.shape[0],),
(64,),
(cnts.indptr, cnts.indices, cnts.data, vals_gpu, cnts.shape[0]),
)
cnts.eliminate_zeros()
return cnts


Expand Down

0 comments on commit 3cc7aed

Please sign in to comment.