Skip to content

Commit

Permalink
Move numba code to it's own method
Browse files Browse the repository at this point in the history
  • Loading branch information
ivirshup committed Apr 8, 2024
1 parent 99cd8a1 commit 35dd438
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions scanpy/preprocessing/_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@
from numpy.typing import NDArray


@numba.njit(cache=True, parallel=True)
def _scale_sparse_numba(indptr, indices, data, *, std, mask_obs, clip):
for i in numba.prange(len(indptr) - 1):
if mask_obs[i]:
for j in range(indptr[i], indptr[i + 1]):
if clip:
data[j] = min(clip, data[j] / std[indices[j]])

Check warning on line 40 in scanpy/preprocessing/_scale.py

View check run for this annotation

Codecov / codecov/patch

scanpy/preprocessing/_scale.py#L36-L40

Added lines #L36 - L40 were not covered by tests
else:
data[j] /= std[indices[j]]

Check warning on line 42 in scanpy/preprocessing/_scale.py

View check run for this annotation

Codecov / codecov/patch

scanpy/preprocessing/_scale.py#L42

Added line #L42 was not covered by tests


@renamed_arg("X", "data", pos_0=True)
@old_positionals("zero_center", "max_value", "copy", "layer", "obsm")
@singledispatch
Expand Down Expand Up @@ -248,19 +259,6 @@ def scale_sparse(
std = np.sqrt(var)
std[std == 0] = 1

@numba.njit(cache=True)
def _scale_sparse_numba(indptr, indices, data, *, std, mask_obs, clip):
def _loop_scale(cell_ix):
for j in numba.prange(indptr[cell_ix], indptr[cell_ix + 1]):
if clip:
data[j] = min(clip, data[j] / std[indices[j]])
else:
data[j] /= std[indices[j]]

for i in numba.prange(len(indptr) - 1):
if mask_obs[i]:
_loop_scale(i)

if max_value is None:
max_value = 0

Expand Down

0 comments on commit 35dd438

Please sign in to comment.