import dascore as dc
from dascore.utils.downloader import fetch
patch = dc.read(fetch("example_dasdae_event_1.h5"))[0]
lazy = patch.set_backend("lazy")
assert lazy.backend == "lazy" and lazy.shape == patch.shape
# An operation on it computes nothing until the data are asked for.
out = lazy.abs().set_backend("numpy")
assert out.backend == "numpy" and out.equals(patch.abs())set_backend
set_backend(
self ,
backend: str ,
)-> ‘Self’
Return the patch with its data on another array backend.
The values, attrs and data_id are the patch’s own: only where the array lives, and when it is read, changes.
Parameters
| Parameter | Description |
|---|---|
| backend |
An array library by name, such as "numpy", "jax" or"cupy", which reads lazy data into memory on it. Or a lazybackend, under which nothing is read until load: "LazyArray", or its alias"lazy", computes each chunk on NumPy, and"LazyArray[jax]" names another library to compute on.
|
Raises
ParameterError If the name is no backend, the array library cannot be imported, or the patch is asked to be lazy and its data are not what a stored array holds: a lazy patch is a promise to read, and a patch made or changed in memory has nothing to read.
Examples
Note
set_backend("numpy")is whatloaddoes to a lazy patch computed on NumPy.loadleaves a"LazyArray[jax]"patch on JAX, where this computes it on NumPy.- Data in memory on one array library are moved to another through NumPy, since that is what every library takes an array from.
- A step already pending on a lazy patch is asked for its kernel on the library named, and one with none is the
numpy_fallbacksetting’s to allow, as it is when a step is chained. What was allowed when a step was chained is not asked again atload.