Skip to content

Commit f989add

Browse files
committed
add FinalState Getter
1 parent b7b6a7e commit f989add

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

k2/csrc/fsa.h

+6
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ struct Fsa {
112112
return !arc_indexes.empty() ? (static_cast<int32_t>(arc_indexes.size()) - 1)
113113
: 0;
114114
}
115+
116+
int32_t FinalState() const {
117+
// It's not valid to call this if the FSA is empty.
118+
CHECK(!arc_indexes.empty());
119+
return arc_indexes.size() - 2;
120+
}
115121
};
116122

117123
/*

k2/csrc/util.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct PairHash {
3434
};
3535

3636
static const double kMinLogDiffDouble = log(DBL_EPSILON); // negative!
37-
static const float kMinLogDiffFloat = log(FLT_EPSILON); // negative!
37+
static const float kMinLogDiffFloat = logf(FLT_EPSILON); // negative!
3838

3939
// returns log(exp(x) + exp(y)).
4040
inline double LogAdd(double x, double y) {
@@ -71,7 +71,7 @@ inline float LogAdd(float x, float y) {
7171

7272
if (diff >= kMinLogDiffFloat) {
7373
float res;
74-
res = x + log1p(exp(diff));
74+
res = x + log1pf(expf(diff));
7575
return res;
7676
} else {
7777
return x; // return the larger one.

0 commit comments

Comments
 (0)