-
Notifications
You must be signed in to change notification settings - Fork 612
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test full Dask support for
log1p
, normalize_per_cell
, `filter_cel…
…ls`/`filter_genes` (#2814)
- Loading branch information
1 parent
4f4b1c3
commit e00932b
Showing
4 changed files
with
120 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,49 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, overload | ||
|
||
import numpy as np | ||
|
||
# install dask if available | ||
try: | ||
import dask.array as da | ||
except ImportError: | ||
da = None | ||
from scanpy._compat import DaskArray, ZappyArray | ||
|
||
if TYPE_CHECKING: | ||
from numpy.typing import ArrayLike | ||
|
||
|
||
@overload | ||
def materialize_as_ndarray(a: ArrayLike) -> np.ndarray: | ||
... | ||
|
||
|
||
@overload | ||
def materialize_as_ndarray(a: tuple[ArrayLike]) -> tuple[np.ndarray]: | ||
... | ||
|
||
|
||
@overload | ||
def materialize_as_ndarray( | ||
a: tuple[ArrayLike, ArrayLike], | ||
) -> tuple[np.ndarray, np.ndarray]: | ||
... | ||
|
||
def materialize_as_ndarray(a): | ||
|
||
@overload | ||
def materialize_as_ndarray( | ||
a: tuple[ArrayLike, ArrayLike, ArrayLike], | ||
) -> tuple[np.ndarray, np.ndarray, np.ndarray]: | ||
... | ||
|
||
|
||
def materialize_as_ndarray( | ||
a: ArrayLike | tuple[ArrayLike | ZappyArray | DaskArray, ...], | ||
) -> tuple[np.ndarray] | np.ndarray: | ||
"""Convert distributed arrays to ndarrays.""" | ||
if type(a) in (list, tuple): | ||
if da is not None and any(isinstance(arr, da.Array) for arr in a): | ||
return da.compute(*a, sync=True) | ||
if not isinstance(a, tuple): | ||
return np.asarray(a) | ||
|
||
if not any(isinstance(arr, DaskArray) for arr in a): | ||
return tuple(np.asarray(arr) for arr in a) | ||
return np.asarray(a) | ||
|
||
import dask.array as da | ||
|
||
return da.compute(*a, sync=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters