The H-Net downsampler keeps only the vector at each boundary. The paper's Appendix E compares this with channel-wise mean and max pooling within boundaries. Implement all three for one sequence.
To stay causal, this problem defines a chunk so that its vector is computed when its boundary arrives: chunk j covers the positions after the previous boundary, up to and including boundary j. So with boundaries at positions 0, 3 and 4 in a sequence of length 6, the chunks cover [0], [1, 2, 3] and [4], and positions 5 onward belong to no finished chunk and are ignored. (This segment convention is a choice made for this problem; the paper's figure shows pooling within boundaries, and it must be causal to work.)
chunk_pool(x, b, mode)
x float (L, D), b bool (L,) with b[0] always True. mode is "select", "mean" or "max".(M, D), with M the number of True values in b:
"select": the vector at each boundary."mean": the channel-wise mean over the chunk's positions."max": the channel-wise maximum over the chunk's positions.ValueError for any other mode.L or M. Gradients must flow to the entries each mode actually uses.