text
stringlengths 0
2.2M
|
---|
for (int i = 0; i < L * T; i++) {
|
alpha[i] = -std::numeric_limits<Float>::infinity();
|
}
|
alpha[0] = input[target[0]];
|
for (int i = 0; i < L; ++i) {
|
transBuf1[i] = trans[target[i] * N + target[i]];
|
transBuf2[i] = i > 0 ? trans[target[i] * N + target[i - 1]] : 0;
|
}
|
for (int t = 1; t < T; ++t) {
|
const Float* inputCur = &input[t * N];
|
double* alphaPrev = &alpha[(t - 1) * L];
|
double* alphaCur = &alpha[t * L];
|
int high = t < L ? t : L;
|
int low = T - t < L ? L - (T - t) : 1;
|
// Handle edge cases.
|
// If (T - t >= L), then we can conceivably still be at the initial blank
|
if (T - t >= L) {
|
alphaCur[0] = alphaPrev[0] + transBuf1[0] + inputCur[target[0]];
|
}
|
// If (t < L), then the highest position can only be be computed
|
// by transitioning. (We couldn't have been at position `high`
|
// at the previous timestep).
|
if (t < L) {
|
alphaCur[high] =
|
alphaPrev[high - 1] + transBuf2[high] + inputCur[target[high]];
|
}
|
for (int i = low; i < high; ++i) {
|
double s1 = alphaPrev[i] + transBuf1[i];
|
double s2 = alphaPrev[i - 1] + transBuf2[i];
|
alphaCur[i] = inputCur[target[i]] + fmax(s1, s2);
|
}
|
}
|
auto ltrIdx = L - 1;
|
int* bestPath = bestPaths + b * T;
|
for (auto t = T - 1; t > 0; t--) {
|
bestPath[t] = target[ltrIdx];
|
auto* alphaPrev = &alpha[(t - 1) * L];
|
if (ltrIdx > 0) {
|
double s1 = alphaPrev[ltrIdx] + transBuf1[ltrIdx];
|
double s2 = alphaPrev[ltrIdx - 1] + transBuf2[ltrIdx];
|
if (s2 > s1) {
|
ltrIdx--;
|
}
|
}
|
}
|
bestPath[0] = target[ltrIdx];
|
}
|
}
|
template struct ForceAlignmentCriterion<float>;
|
template struct ForceAlignmentCriterion<double>;
|
} // namespace cpu
|
} // namespace lib
|
} // namespace fl
|
#include <ATen/TensorGeometry.h>
|
#include <limits>
|
#include <cstddef>
|
namespace at {
|
// See TensorGeometry.h on why this is useful now that we cache is_contiguous.
|
bool geometry_is_contiguous(IntArrayRef sizes, IntArrayRef strides) {
|
assert(!overflows<std::int64_t>(sizes.size()));
|
auto dim = static_cast<std::int64_t>(sizes.size());
|
int64_t expected_stride = 1;
|
bool contig_if_nonempty = true;
|
for (int64_t i = dim - 1; i >= 0; i--) {
|
if (sizes[i] == 0) {
|
return true;
|
}
|
if (contig_if_nonempty) {
|
if (sizes[i] != 1 && strides[i] != expected_stride) {
|
contig_if_nonempty = false;
|
}
|
expected_stride *= sizes[i];
|
}
|
}
|
return contig_if_nonempty;
|
}
|
bool TensorGeometry::is_contiguous() const {
|
if (numel_ == 0) {
|
return true;
|
}
|
return at::geometry_is_contiguous(sizes_, strides_);
|
}
|
} // namespace at
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.