kernels

module of dascore.lazy source

The kernel every operation runs on a lazy array, unless it registers its own.

It computes nothing. It asks the processor for its chunk contract for the input’s dtype and the plan – a contract written above the class which owns the kernel describes some other kernel, so it does not count – then:

PatchProcessor.kernel_for answers with it for the lazy backend.

Examples

import dascore as dc
from dascore.core.source import ArraySource
from dascore.lazy.contract import Pointwise
from dascore.lazy.recipe import Recipe

class Negate(dc.PatchProcessor):
    '''Negate 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

recipe = Recipe.from_source(ArraySource.full((3, 2), -1.0))
patch = dc.Patch(data=recipe, coords={"x": range(3), "y": range(2)},
                 dims=("x", "y"))
out = Negate()(patch)
assert out.backend == "lazy" and len(out.data.chain) == 1
assert out.data.chain.last.data_id == out.attrs.data_id
assert (out.load().data == 1).all()

Functions

Name Description
lazy_kernel Answer for an operation on a lazy array by its chunk contract.