Blockwise-IO argument This is the base class for indexable Blockwise-IO arguments. When constructing a ``Blockwise`` Layer, one or more of the collection tuples passed in with ``indices`` may contain a ``BlockwiseDep`` instance (in place of a "real" collection name). This allows
| 20 | |
| 21 | |
| 22 | class BlockwiseDep: |
| 23 | """Blockwise-IO argument |
| 24 | |
| 25 | This is the base class for indexable Blockwise-IO arguments. |
| 26 | When constructing a ``Blockwise`` Layer, one or more of the |
| 27 | collection tuples passed in with ``indices`` may contain a |
| 28 | ``BlockwiseDep`` instance (in place of a "real" collection name). |
| 29 | This allows a new collection to be created (via IO) within a |
| 30 | ``Blockwise`` layer. |
| 31 | |
| 32 | Parameters |
| 33 | ---------- |
| 34 | numblocks: tuple[int, ...] |
| 35 | The number of blocks/partitions the object can support |
| 36 | along each dimension. |
| 37 | produces_tasks: bool |
| 38 | Whether any nested tasks will be passed to the Blockwise |
| 39 | function. |
| 40 | |
| 41 | See Also |
| 42 | -------- |
| 43 | dask.blockwise.Blockwise |
| 44 | dask.blockwise.BlockwiseDepDict |
| 45 | """ |
| 46 | |
| 47 | numblocks: tuple[int, ...] |
| 48 | produces_tasks: bool |
| 49 | |
| 50 | def __getitem__(self, idx: tuple[int, ...]) -> Any: |
| 51 | """Return Blockwise-function arguments for a specific index""" |
| 52 | raise NotImplementedError( |
| 53 | "Must define `__getitem__` for `BlockwiseDep` subclass." |
| 54 | ) |
| 55 | |
| 56 | def get(self, idx: tuple[int, ...], default) -> Any: |
| 57 | """BlockwiseDep ``__getitem__`` Wrapper""" |
| 58 | try: |
| 59 | return self.__getitem__(idx) |
| 60 | except KeyError: |
| 61 | return default |
| 62 | |
| 63 | @property |
| 64 | def produces_keys(self) -> bool: |
| 65 | """Whether this object will produce external key dependencies. |
| 66 | |
| 67 | An external key corresponds to a task key or ``Delayed``-object |
| 68 | key that does not originate from within the ``Blockwise`` layer |
| 69 | that is including this ``BlockwiseDep`` object in its ``indices``. |
| 70 | A ``BlockwiseDep`` object should only return external-key |
| 71 | dependencies when those dependencies do not correspond to a |
| 72 | blockwise-compatible Dask collection (otherwise the collection |
| 73 | name should just be included in ``indices`` list instead). |
| 74 | """ |
| 75 | return False |
| 76 | |
| 77 | def __repr__(self) -> str: |
| 78 | return f"<{type(self).__name__} {self.numblocks}>" |
| 79 |