@@ -561,11 +561,13 @@ void Argument::degradeSequence(const Argument& input) {
561
561
562
562
void Argument::poolSequenceWithStride (const Argument& input,
563
563
size_t stride,
564
- IVectorPtr* stridePostions) {
564
+ IVectorPtr* stridePostions,
565
+ bool reversed) {
565
566
/*
566
567
* If input.sequenceStartPositions = [0, 9, 14, 17, 30] and stride = 5,
567
- * then sequenceStartPositions = [0, 2, 3, 4, 7],
568
- * and stridePostions = [0, 5, 9, 14, 17, 22, 27, 30]
568
+ * then sequenceStartPositions = [0, 2, 3, 4, 7].
569
+ * If reversed = false, stridePostions = [0, 5, 9, 14, 17, 22, 27, 30];
570
+ * else reversed = true, stridePostions = [0, 4, 9, 14, 17, 20, 25, 30]
569
571
*/
570
572
CHECK (input.sequenceStartPositions );
571
573
CHECK_EQ (input.hasSubseq (), 0UL );
@@ -584,14 +586,13 @@ void Argument::poolSequenceWithStride(const Argument& input,
584
586
if (seqLength == 0 ) {
585
587
// empty sequence
586
588
tgtBuf[seqId + 1 ] = tgtBuf[seqId];
587
- } else if (seqLength < stride) {
588
- tgtBuf[seqId + 1 ] = tgtBuf[seqId] + 1 ;
589
589
} else {
590
- tgtBuf[seqId + 1 ] = tgtBuf[seqId] + ceil ((float )seqLength / stride);
591
- int size =
592
- (seqLength % stride) ? seqLength / stride : seqLength / stride - 1 ;
593
- for (int i = 0 ; i < size; i++) {
594
- stridePos.emplace_back (stridePos.back () + stride);
590
+ int size = ceil ((float )seqLength / stride);
591
+ tgtBuf[seqId + 1 ] = tgtBuf[seqId] + size;
592
+ for (int i = 0 ; i < size - 1 ; i++) {
593
+ int cur = reversed ? starts[seqId + 1 ] - (size - 1 - i) * stride
594
+ : stridePos.back () + stride;
595
+ stridePos.emplace_back (cur);
595
596
}
596
597
}
597
598
}
0 commit comments