Skip to content

Commit 2d2d738

Browse files
committed
Rework OpenFst related preprocessor conditionals.
1 parent 43993b6 commit 2d2d738

24 files changed

+127
-117
lines changed

src/bin/phones-to-prons.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ int main(int argc, char *argv[]) {
170170
<< "not reach end-state, or mismatched lexicon.)";
171171
if (g_kaldi_verbose_level >= 2) {
172172
KALDI_LOG << "phn2word FST is below:";
173-
#ifdef HAVE_OPENFST_GE_10400
173+
#if OPENFST_VER >= 10400
174174
fst::FstPrinter<StdArc> fstprinter(phn2word, NULL, NULL, NULL, false, true, "\t");
175175
#else
176176
fst::FstPrinter<StdArc> fstprinter(phn2word, NULL, NULL, NULL, false, true);

src/fstext/context-fst-inl.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ typename ContextFstImpl<Arc, LabelT>::StateId
4242
if (iter == state_map_.end()) { // Not already in map.
4343
StateId this_state_id = (StateId)state_seqs_.size();
4444
//This check is not needed with OpenFst >= 1.4
45-
#ifndef HAVE_OPENFST_GE_10400
45+
#if OPENFST_VER >= 10400
46+
#else
4647
StateId this_state_id_check = CacheImpl<Arc>::AddState();
4748
// goes back to VectorFstBaseImpl<Arc>, inherited via CacheFst<Arc>
4849
assert(this_state_id == this_state_id_check);
@@ -325,7 +326,7 @@ void ContextFstImpl<Arc, LabelT>::Expand(StateId s) { // expands arcs only [not
325326
// We just try adding all possible symbols on the output side.
326327
Arc arc;
327328
if (this->CreateArc(s, subsequential_symbol_, &arc)) {
328-
#ifdef HAVE_OPENFST_GE_10400
329+
#if OPENFST_VER >= 10400
329330
this->PushArc(s, arc);
330331
#else
331332
this->AddArc(s, arc);
@@ -335,7 +336,7 @@ void ContextFstImpl<Arc, LabelT>::Expand(StateId s) { // expands arcs only [not
335336
iter != phone_syms_.end(); ++iter) {
336337
Label phone = *iter;
337338
if (this->CreateArc(s, phone, &arc)) {
338-
#ifdef HAVE_OPENFST_GE_10400
339+
#if OPENFST_VER >= 10400
339340
this->PushArc(s, arc);
340341
#else
341342
this->AddArc(s, arc);
@@ -346,7 +347,7 @@ void ContextFstImpl<Arc, LabelT>::Expand(StateId s) { // expands arcs only [not
346347
iter != disambig_syms_.end(); ++iter) {
347348
Label disambig_sym = *iter;
348349
if (this->CreateArc(s, disambig_sym, &arc)) {
349-
#ifdef HAVE_OPENFST_GE_10400
350+
#if OPENFST_VER >= 10400
350351
this->PushArc(s, arc);
351352
#else
352353
this->AddArc(s, arc);
@@ -359,22 +360,24 @@ void ContextFstImpl<Arc, LabelT>::Expand(StateId s) { // expands arcs only [not
359360

360361
template<class Arc, class LabelT>
361362
ContextFst<Arc, LabelT>::ContextFst(const ContextFst<Arc, LabelT> &fst, bool reset) {
363+
#if OPENFST_VER >= 10500
362364
if (reset) {
363-
#ifdef HAVE_OPENFST_GE_10500
364365
impl_ = std::make_shared<ContextFstImpl<Arc, LabelT> >(*(fst.impl_));
366+
} else {
367+
impl_ = fst.impl_;
368+
}
365369
#else
370+
if (reset) {
366371
impl_ = new ContextFstImpl<Arc, LabelT>(*(fst.impl_));
367372
// Copy constructor of ContextFstImpl.
368373
// Main use of calling with reset = true is to free up memory
369374
// (e.g. then you could delete original one). Might be useful in transcription
370375
// expansion during training.
371-
#endif
372376
} else {
373377
impl_ = fst.impl_;
374-
#ifndef HAVE_OPENFST_GE_10500
375378
impl_->IncrRefCount();
376-
#endif
377379
}
380+
#endif
378381
}
379382

380383

src/fstext/context-fst-test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ template<class Arc> static void TestContextFst(bool verbose, bool use_matcher) {
192192
}
193193

194194
if (verbose) { // Try to print the fst.
195-
#ifdef HAVE_OPENFST_GE_10400
195+
#if OPENFST_VER >= 10400
196196
FstPrinter<Arc> fstprinter(cfst, cfst.InputSymbols(), cfst.OutputSymbols(), NULL, false, true, "\t");
197197
#else
198198
FstPrinter<Arc> fstprinter(cfst, cfst.InputSymbols(), cfst.OutputSymbols(), NULL, false, true);
@@ -211,7 +211,7 @@ template<class Arc> static void TestContextFst(bool verbose, bool use_matcher) {
211211
if (verbose) {
212212
std::cout << "Sequence FST is:\n";
213213
{ // Try to print the fst.
214-
#ifdef HAVE_OPENFST_GE_10400
214+
#if OPENFST_VER >= 10400
215215
FstPrinter<Arc> fstprinter(*f, f->InputSymbols(), f->OutputSymbols(), NULL, false, true, "\t");
216216
#else
217217
FstPrinter<Arc> fstprinter(*f, f->InputSymbols(), f->OutputSymbols(), NULL, false, true);
@@ -257,7 +257,7 @@ template<class Arc> static void TestContextFst(bool verbose, bool use_matcher) {
257257
if (verbose) {
258258
std::cout << "Composed FST is:\n";
259259
{ // Try to print the fst.
260-
#ifdef HAVE_OPENFST_GE_10400
260+
#if OPENFST_VER >= 10400
261261
FstPrinter<Arc> fstprinter(fst_composed, fst_composed.InputSymbols(),
262262
fst_composed.OutputSymbols(), NULL, false, true, "\t");
263263
#else

src/fstext/context-fst.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class ContextFstImpl : public CacheImpl<Arc> {
9494
typedef typename Arc::Weight Weight;
9595
typedef typename Arc::StateId StateId;
9696
typedef typename Arc::Label Label;
97-
#ifdef HAVE_OPENFST_GE_10400
97+
#if OPENFST_VER >= 10400
9898
typedef DefaultCacheStore<Arc> Store;
9999
typedef typename Store::State State;
100100
#endif
@@ -216,7 +216,8 @@ class ContextFst : public Fst<Arc> {
216216
public:
217217
friend class ArcIterator< ContextFst<Arc> >;
218218
friend class StateIterator< ContextFst<Arc> >;
219-
#ifndef HAVE_OPENFST_GE_10400
219+
#if OPENFST_VER >= 10400
220+
#else
220221
// We have to supply the default template argument below to work around a
221222
// Visual Studio bug.
222223
friend class CacheArcIterator< ContextFst<Arc>,
@@ -226,7 +227,7 @@ class ContextFst : public Fst<Arc> {
226227
typedef typename Arc::Weight Weight;
227228
typedef typename Arc::Label Label;
228229
typedef typename Arc::StateId StateId;
229-
#ifdef HAVE_OPENFST_GE_10400
230+
#if OPENFST_VER >= 10400
230231
typedef DefaultCacheStore<Arc> Store;
231232
typedef typename Store::State State;
232233
#else
@@ -244,7 +245,8 @@ class ContextFst : public Fst<Arc> {
244245

245246
ContextFst(const ContextFst<Arc, LabelT> &fst, bool reset = false);
246247

247-
#ifndef HAVE_OPENFST_GE_10500
248+
#if OPENFST_VER >= 10500
249+
#else
248250
virtual ~ContextFst() { if (!impl_->DecrRefCount()) delete impl_; }
249251
#endif
250252

@@ -309,7 +311,7 @@ class ContextFst : public Fst<Arc> {
309311

310312
friend class CacheStateIterator<ContextFst<Arc> >; // so it can see impl_.
311313
private:
312-
#ifdef HAVE_OPENFST_GE_10500
314+
#if OPENFST_VER >= 10500
313315
std::shared_ptr<ContextFstImpl<Arc, LabelT> > impl_; // protected so CacheStateIterator
314316
ContextFstImpl<Arc, LabelT> *GetImpl() const { return impl_.get(); }
315317
#else

src/fstext/determinize-lattice-test.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ template<class Arc> void TestDeterminizeLattice() {
9191
VectorFst<Arc> *fst = RandFst<Arc>();
9292
std::cout << "FST before lattice-determinizing is:\n";
9393
{
94-
#ifdef HAVE_OPENFST_GE_10400
94+
#if OPENFST_VER >= 10400
9595
FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true, "\t");
9696
#else
9797
FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true);
@@ -107,7 +107,7 @@ template<class Arc> void TestDeterminizeLattice() {
107107
throw std::runtime_error("could not determinize");
108108
std::cout << "FST after lattice-determinizing is:\n";
109109
{
110-
#ifdef HAVE_OPENFST_GE_10400
110+
#if OPENFST_VER >= 10400
111111
FstPrinter<Arc> fstprinter(det_fst, NULL, NULL, NULL, false, true, "\t");
112112
#else
113113
FstPrinter<Arc> fstprinter(det_fst, NULL, NULL, NULL, false, true);
@@ -122,7 +122,7 @@ template<class Arc> void TestDeterminizeLattice() {
122122
ConvertLattice<Weight, Int>(*fst, &compact_fst, false);
123123
std::cout << "Compact FST is:\n";
124124
{
125-
#ifdef HAVE_OPENFST_GE_10400
125+
#if OPENFST_VER >= 10400
126126
FstPrinter<CompactArc> fstprinter(compact_fst, NULL, NULL, NULL, false, true, "\t");
127127
#else
128128
FstPrinter<CompactArc> fstprinter(compact_fst, NULL, NULL, NULL, false, true);
@@ -137,7 +137,7 @@ template<class Arc> void TestDeterminizeLattice() {
137137

138138
std::cout << "Compact version of determinized FST is:\n";
139139
{
140-
#ifdef HAVE_OPENFST_GE_10400
140+
#if OPENFST_VER >= 10400
141141
FstPrinter<CompactArc> fstprinter(compact_det_fst, NULL, NULL, NULL, false, true, "\t");
142142
#else
143143
FstPrinter<CompactArc> fstprinter(compact_det_fst, NULL, NULL, NULL, false, true);
@@ -162,7 +162,7 @@ template<class Arc> void TestDeterminizeLattice2() {
162162
VectorFst<Arc> *fst = RandFst<Arc>(opts);
163163
std::cout << "FST before lattice-determinizing is:\n";
164164
{
165-
#ifdef HAVE_OPENFST_GE_10400
165+
#if OPENFST_VER >= 10400
166166
FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true, "\t");
167167
#else
168168
FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true);
@@ -173,7 +173,7 @@ template<class Arc> void TestDeterminizeLattice2() {
173173
DeterminizeLattice<TropicalWeight, int32>(*fst, &ofst);
174174
std::cout << "FST after lattice-determinizing is:\n";
175175
{
176-
#ifdef HAVE_OPENFST_GE_10400
176+
#if OPENFST_VER >= 10400
177177
FstPrinter<Arc> fstprinter(ofst, NULL, NULL, NULL, false, true, "\t");
178178
#else
179179
FstPrinter<Arc> fstprinter(ofst, NULL, NULL, NULL, false, true);

0 commit comments

Comments
 (0)