@@ -32,7 +32,7 @@ void forced_align_impl(
32
32
const auto L = targets.size (1 );
33
33
const auto S = 2 * L + 1 ;
34
34
35
- auto alphas_a = new scalar_t [S][2 ];
35
+ auto alphas_a = new scalar_t [S][2 ]; // scalar_t is just logProbs.dtype()
36
36
for (int i = 0 ; i < S; i++) {
37
37
alphas_a[i][0 ] = kNegInfinity ;
38
38
alphas_a[i][1 ] = kNegInfinity ;
@@ -91,8 +91,13 @@ void forced_align_impl(
91
91
}
92
92
if (start == 0 ) {
93
93
alphas_a[0 ][curIdxOffset] =
94
+ <<<<<<< HEAD
94
95
alphas_a[0 ][prevIdxOffset] + logProbs_a.index (batchIndex, t, blank);
95
96
backPtr_a[S * t] = 0 ;
97
+ =======
98
+ alphas_a[0 ][prevIdxOffset] + logProbs_a[batchIndex][t][blank];
99
+ backPtr_a[S * t] = 0 ; // backPtr_a[t][0] = 0
100
+ >>>>>>> forced_align_backptr
96
101
startloop += 1 ;
97
102
}
98
103
@@ -114,25 +119,27 @@ void forced_align_impl(
114
119
scalar_t result = 0.0 ;
115
120
if (x2 > x1 && x2 > x0) {
116
121
result = x2;
117
- backPtr_a[t * S + i] = 2 ;
122
+ backPtr_a[t * S + i] = 2 ; // backPtr_a[t][i] = 2
118
123
} else if (x1 > x0 && x1 > x2) {
119
124
result = x1;
120
- backPtr_a[t * S + i] = 1 ;
125
+ backPtr_a[t * S + i] = 1 ; // backPtr_a[t][i] = 1
121
126
} else {
122
127
result = x0;
123
- backPtr_a[t * S + i] = 0 ;
128
+ backPtr_a[t * S + i] = 0 ; // backPtr_a[t][i] = 0
124
129
}
125
130
alphas_a[i][curIdxOffset] = result + logProbs_a.index (batchIndex, t, labelIdx);
126
131
}
127
132
}
128
133
auto idx1 = (T - 1 ) % 2 ;
129
134
auto ltrIdx = alphas_a[S - 1 ][idx1] > alphas_a[S - 2 ][idx1] ? S - 1 : S - 2 ;
135
+ delete[] alphas_a;
130
136
// path stores the token index for each time step after force alignment.
131
137
for (auto t = T - 1 ; t > -1 ; t--) {
132
138
auto lbl_idx = ltrIdx % 2 == 0 ? blank : targets_a.index (batchIndex, ltrIdx / 2 );
133
139
paths_a.set_index (lbl_idx, batchIndex, t);
134
- ltrIdx -= backPtr_a[t * S + ltrIdx];
140
+ ltrIdx -= backPtr_a[t * S + ltrIdx]; // backPtr_a[t][ltrIdx]
135
141
}
142
+ delete[] backPtr_a;
136
143
}
137
144
138
145
std::tuple<Tensor, Tensor> compute (
0 commit comments