import numpy as np
import dascore as dc
from dascore.lazy.contract import Pointwise, Unchanged
class Double(dc.PatchProcessor):
'''Double every sample.'''
name = None # so this example claims no name of its own
def chunk_contract(self, dtype, plan):
return Pointwise()
def kernel(self, data):
return data * 2
assert isinstance(Double().chunk_contract(np.dtype("f8"), {}), Pointwise)
assert dc.PatchProcessor().chunk_contract(np.dtype("f8"), {}) is Nonecontract
Chunk contracts: what one chunk of an operation’s output needs of its input.
An operation which can run on a lazy array says so by returning a contract from PatchProcessor.chunk_contract, for the input’s dtype and the plan get_metadata worked out. The contract is what lets the work be split into chunks without changing the result: each output chunk is computed from the input it names, and nothing else. Returning None says the operation cannot run on a lazy array.
A chunk is a box: one slice for each axis, with a start and a stop and a step of one. A contract answers two questions about one. needs says which box of the input an output box is computed from, and apply computes the output box from that input. Neither chooses a chunk size or loops over chunks: dascore.lazy.execute does both.
This module imports nothing from the rest of DASCore, because the processors in dascore.proc and dascore.transform import it.
Examples
Classes
| Name | Description |
|---|---|
| ChunkContract | What one chunk of an operation’s output needs of its input. |
| Halo | An output chunk needs the input chunk and some samples around it. |
| Pointwise | An output chunk needs only the input chunk at the same place. |
| Tiles | An output chunk needs the tiles which overlap it. |
| Unchanged | The kernel hands its input back, for this dtype and plan. |
| WholeAxis | An output chunk needs the whole of the input along some axes. |
| Window | The output is a window of the input: a slice with a step of one per axis. |