Tiles

class of dascore.lazy.contract
inherits from: ChunkContract
source

Tiles(
    spans: collections.abc.Mapping[int, tuple[int, int, int]] ,
    widths: collections.abc.Mapping[int, tuple[int, int]] = ,
    whole: tuple[int, …] = (),
    factors: collections.abc.Mapping[int, int] = ,
)-> None

An output chunk needs the tiles which overlap it.

The operation cuts some axes into overlapping tiles, computes each tile from itself alone, and blends them. The tiles are placed by the array, not by the chunk: tile k of an axis starts at k * stride - margin, where margin is the largest multiple of the stride less than the tile’s size, so tile 0 is the earliest which holds the first sample. A chunk is grown out to the edges of the tiles which overlap it, so each of those tiles is computed whole and the chunk is the same however the work is cut.

Along an axis which is not tiled a tile is computed from the chunk alone, unless widths or whole say what else it reads.

The kernel is told which tiles it was given: it takes a tiles keyword holding, for each tiled axis in the order of spans, the first tile and one past the last.

Parameters

Parameter Description
spans For each tiled axis, the tile’s size, its stride, and the length
of the whole axis.
widths For an axis which is not tiled, how many samples before and after
an output sample are read, as for
Halo.
whole The axes which are not tiled and are needed whole.
factors For a tiled axis along which the operation keeps every n-th sample
of a tile, that n, which the stride is a multiple of. The output is
then shorter than the input along the axis: a box counts samples of
the output, and what it needs counts samples of the input.

Examples

from dascore.lazy.contract import Tiles
# Tiles of 8 samples every 4, so one starts 4 before the array.
tiles = Tiles({0: (8, 4, 100)})
box = (slice(10, 20), slice(0, 5))
assert tiles.tiles(box) == ((2, 6),)
assert tiles.needs(box, (100, 5)) == (slice(4, 24), slice(0, 5))
# Every second sample kept: output samples 10 to 19 are input
# samples 20 to 38, read with the tiles which hold them.
halved = Tiles({0: (8, 4, 100)}, factors={0: 2})
assert halved.needs(box, (100, 5)) == (slice(16, 44), slice(0, 5))

Methods

Name Description
apply Return the output box, blended from the tiles which overlap it.
needs Return the box grown to whole tiles, and by what else is read.
tiles Return the first tile overlapping a box, and one past the last.