forked from scverse/scanpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request scverse#439 from tomwhite/generalize-distributed
Use np.asarray() rather than Zappy-specific code.
- Loading branch information
Showing
2 changed files
with
9 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,15 @@ | ||
import numpy as np | ||
|
||
# install dask if available | ||
try: | ||
import dask.array as da | ||
except ImportError: | ||
da = None | ||
|
||
# install zappy (which wraps numpy), or fall back to plain numpy | ||
try: | ||
import zappy.base as np | ||
except ImportError: | ||
import numpy as np | ||
|
||
|
||
def materialize_as_ndarray(a): | ||
"""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) | ||
elif hasattr(np, 'asarray'): # zappy case | ||
return tuple(np.asarray(arr) for arr in a) | ||
else: | ||
if da is not None and isinstance(a, da.Array): | ||
return a.compute() | ||
elif hasattr(np, 'asarray'): # zappy case | ||
return np.asarray(a) | ||
return a | ||
return tuple(np.asarray(arr) for arr in a) | ||
return np.asarray(a) |
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