Expose an eager array interface over a lazy view.
Constructing the adapter does not read source values. Indexing materializes
the selected view in fresh memory, using its existing reader and partitioning.
Tokenization delegates to the view's source-token contract and may read data.
Examples:
>>> import numpy as np
>>> from zarr_indexing import LazyArray
>>> view = LazyArray(np.arange(8))[1::2]
>>> EagerArrayAdapter(view)[1:3]
array([3, 5])
Source code in src/zarr_indexing/eager.py
| class EagerArrayAdapter:
"""Expose an eager array interface over a lazy view.
Constructing the adapter does not read source values. Indexing materializes
the selected view in fresh memory, using its existing reader and partitioning.
Tokenization delegates to the view's source-token contract and may read data.
Examples
--------
>>> import numpy as np
>>> from zarr_indexing import LazyArray
>>> view = LazyArray(np.arange(8))[1::2]
>>> EagerArrayAdapter(view)[1:3]
array([3, 5])
"""
__slots__ = ("_view",)
def __init__(self, view: LazyArray) -> None:
self._view = view
@property
def shape(self) -> tuple[int, ...]:
"""Shape of the selected view."""
return self._view.shape
@property
def ndim(self) -> int:
"""Number of dimensions of the selected view."""
return self._view.ndim
@property
def dtype(self) -> Any:
"""Data type reported by the source."""
return self._view.dtype
def __getitem__(self, selection: Any) -> Any:
"""Read a basic selection into fresh memory."""
return self._view[selection].result()
def __array__(self, dtype: Any = None, copy: bool | None = None) -> Any:
"""Materialize using the view's NumPy conversion contract."""
return self._view.__array__(dtype=dtype, copy=copy)
def __dask_tokenize__(self) -> tuple[Any, ...]:
"""Distinguish eager tasks while preserving the source identity contract."""
return (type(self).__qualname__, self._view.__dask_tokenize__())
|
__slots__
class-attribute
instance-attribute
dtype
property
Data type reported by the source.
ndim
property
Number of dimensions of the selected view.
shape
property
Shape of the selected view.
__array__
__array__(
dtype: Any = None, copy: bool | None = None
) -> Any
Materialize using the view's NumPy conversion contract.
Source code in src/zarr_indexing/eager.py
| def __array__(self, dtype: Any = None, copy: bool | None = None) -> Any:
"""Materialize using the view's NumPy conversion contract."""
return self._view.__array__(dtype=dtype, copy=copy)
|
__dask_tokenize__
Distinguish eager tasks while preserving the source identity contract.
Source code in src/zarr_indexing/eager.py
| def __dask_tokenize__(self) -> tuple[Any, ...]:
"""Distinguish eager tasks while preserving the source identity contract."""
return (type(self).__qualname__, self._view.__dask_tokenize__())
|
__getitem__
__getitem__(selection: Any) -> Any
Read a basic selection into fresh memory.
Source code in src/zarr_indexing/eager.py
| def __getitem__(self, selection: Any) -> Any:
"""Read a basic selection into fresh memory."""
return self._view[selection].result()
|
__init__
Source code in src/zarr_indexing/eager.py
| def __init__(self, view: LazyArray) -> None:
self._view = view
|