def window

stelliferous@0.0.2.0 · tensor_band_window.bend:41

import stelliferous@0.0.2.0/tensor_band_window.bend as TensorBandWindow
import Base
import stelliferous@0.0.2.0/tensor_band.bend as Bands

41# Output partition boundaries follow the input cores, with the first and last
42# cores also owning any output rows introduced by padding. The halos hold
43# every window row outside the core, so a window is its image rows exactly.
44# Caller geometry checks establish positive stride/height and bounded products.
45def window(geometry: Geometry,+first: U32,+count: U32) -> RowWindow:
46  Geometry{Bands.Geometry{batch,channels,+height,width},+kernel,+stride,+padding,+output_height,output_width} = geometry
47  +image = (first / height : U32)
48  +core_first = (first % height : U32)
49  +core_end = (core_first + count : U32)
50  +out_first = U32.min(output_height,ceiling(core_first,stride))
51  +out_end = Bool.pick(U32,U32.is_eq(core_end,height),output_height,U32.min(output_height,ceiling(core_end,stride)))
52  +needed_first = start(height,out_first,stride,padding)
53  +needed_end = U32.min(height,subtract_clipped((subtract_clipped(out_end,1) * stride + kernel : U32),padding))
54  +above_first = (image * height + needed_first : U32)
55  +above_end = (image * height + U32.min(core_first,needed_end) : U32)
56  +below_first = (image * height + U32.max(core_end,needed_first) : U32)
57  +below_end = (image * height + needed_end : U32)
58  nonempty(U32.is_lt(out_first,out_end),RowWindow{Rows{(image * output_height + out_first : U32),subtract_clipped(out_end,out_first)},
59    clipped(above_first,above_end),clipped(below_first,below_end),clipped(above_first,below_end)})

Uses (19)

Used by (3)