import dascore as dc
class ScaleExample(dc.PatchProcessor):
'''Multiply the data by a factor.'''
factor: float = 2.0
def kernel(self, data):
return data * self.factor
patch = dc.get_example_patch()
out = ScaleExample(3)(patch)
assert out.equals(ScaleExample.patch_function(patch, factor=3))
assert ScaleExample(3).fingerprint == ScaleExample(3.0).fingerprintprocessor
Patch operations written as classes.
A PatchProcessor subclass is a whole operation: its fields are the parameters, derive and plan work out the result’s metadata and the numbers the kernel needs without touching data, and kernel computes the array. Subclassing registers the operation and generates its patch function (cls.patch_function), so the class is written once and the function is never hand-written.
Examples
Functions
| Name | Description |
|---|---|
| register_kernel | Say that a function is how an operation runs on one array backend. |
Classes
| Name | Description |
|---|---|
| PatchMeta | Everything a patch carries except its data. |
| PatchProcessor | An operation on a patch, written as a class. |