Lazily computed array holding values of elemwise-function. Do not construct this object directly: call lazy_elemwise_func instead. Values are computed upon indexing or coercion to a NumPy array.
| 46 | |
| 47 | |
| 48 | class _ElementwiseFunctionArray(indexing.ExplicitlyIndexedNDArrayMixin): |
| 49 | """Lazily computed array holding values of elemwise-function. |
| 50 | |
| 51 | Do not construct this object directly: call lazy_elemwise_func instead. |
| 52 | |
| 53 | Values are computed upon indexing or coercion to a NumPy array. |
| 54 | """ |
| 55 | |
| 56 | def __init__(self, array, func: Callable, dtype: np.typing.DTypeLike | None): |
| 57 | assert not is_chunked_array(array) |
| 58 | self.array = indexing.as_indexable(array) |
| 59 | self.func = func |
| 60 | self._dtype = dtype |
| 61 | |
| 62 | @property |
| 63 | def dtype(self) -> np.dtype: |
| 64 | return np.dtype(self._dtype) |
| 65 | |
| 66 | def transpose(self, order): |
| 67 | # For elementwise functions, we can compose transpose and function application |
| 68 | return type(self)(self.array.transpose(order), self.func, self.dtype) |
| 69 | |
| 70 | def _oindex_get(self, key): |
| 71 | return type(self)(self.array.oindex[key], self.func, self.dtype) |
| 72 | |
| 73 | def _vindex_get(self, key): |
| 74 | return type(self)(self.array.vindex[key], self.func, self.dtype) |
| 75 | |
| 76 | def __getitem__(self, key): |
| 77 | return type(self)(self.array[key], self.func, self.dtype) |
| 78 | |
| 79 | def get_duck_array(self): |
| 80 | return self.func(self.array.get_duck_array()) |
| 81 | |
| 82 | async def async_get_duck_array(self): |
| 83 | return self.func(await self.array.async_get_duck_array()) |
| 84 | |
| 85 | def __repr__(self) -> str: |
| 86 | return f"{type(self).__name__}({self.array!r}, func={self.func!r}, dtype={self.dtype!r})" |
| 87 | |
| 88 | |
| 89 | def lazy_elemwise_func(array, func: Callable, dtype: np.typing.DTypeLike | None): |
no outgoing calls
no test coverage detected
searching dependent graphs…