Skip to content

Commit 13441d0

Browse files
authored
Merge pull request #4927 from jtrmal/openfst-1.8.2
Support for both OpenFST 1.7.3 and 1.8.2
2 parents 122a3f2 + a7fcc2d commit 13441d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+287
-172
lines changed

src/base/kaldi-error-test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ int main() {
7676
kaldi::UnitTestError();
7777
KALDI_ASSERT(0); // should not happen.
7878
exit(1);
79-
} catch (kaldi::KaldiFatalError &e) {
79+
} catch (const kaldi::KaldiFatalError &e) {
8080
std::cout << "The error we generated was: '" << e.KaldiMessage() << "'\n";
8181
}
8282
}

src/base/kaldi-types.h

+14-21
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,21 @@ typedef float BaseFloat;
3939
// we find in the future lacks stdint.h
4040
#include <stdint.h>
4141

42-
// for discussion on what to do if you need compile kaldi
43-
// without OpenFST, see the bottom of this this file
42+
#if OPENFST_VER >= 10800
43+
typedef int8_t int8;
44+
typedef int16_t int16;
45+
typedef int32_t int32;
46+
typedef int64_t int64;
47+
48+
typedef uint8_t uint8;
49+
typedef uint16_t uint16;
50+
typedef uint32_t uint32;
51+
typedef uint64_t uint64;
52+
typedef float float32;
53+
typedef double double64;
54+
#else
4455
#include <fst/types.h>
56+
#endif
4557

4658
namespace kaldi {
4759
using ::int16;
@@ -53,23 +65,4 @@ namespace kaldi {
5365
typedef float float32;
5466
typedef double double64;
5567
} // end namespace kaldi
56-
57-
// In a theoretical case you decide compile Kaldi without the OpenFST
58-
// comment the previous namespace statement and uncomment the following
59-
/*
60-
namespace kaldi {
61-
typedef int8_t int8;
62-
typedef int16_t int16;
63-
typedef int32_t int32;
64-
typedef int64_t int64;
65-
66-
typedef uint8_t uint8;
67-
typedef uint16_t uint16;
68-
typedef uint32_t uint32;
69-
typedef uint64_t uint64;
70-
typedef float float32;
71-
typedef double double64;
72-
} // end namespace kaldi
73-
*/
74-
7568
#endif // KALDI_BASE_KALDI_TYPES_H_

src/bin/phones-to-prons.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ int main(int argc, char *argv[]) {
172172
if (g_kaldi_verbose_level >= 2) {
173173
KALDI_LOG << "phn2word FST is below:";
174174
fst::FstPrinter<StdArc> fstprinter(phn2word, NULL, NULL, NULL, false, true, "\t");
175-
fstprinter.Print(&std::cerr, "standard error");
175+
printer_print(std::cerr, fstprinter, "standard error");
176+
//fstprinter.Print(&std::cerr, "standard error");
176177
KALDI_LOG << "phone sequence is: ";
177178
for (size_t i = 0; i < phones.size(); i++)
178179
std::cerr << phones[i] << ' ';

src/chain/chain-supervision.cc

+4-6
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,8 @@ void Supervision::Write(std::ostream &os, bool binary) const {
571571
// Write using StdAcceptorCompactFst, making use of the fact that it's an
572572
// acceptor.
573573
fst::FstWriteOptions write_options("<unknown>");
574-
fst::StdCompactAcceptorFst::WriteFst(
575-
fst, fst::AcceptorCompactor<fst::StdArc>(), os,
576-
write_options);
574+
fst::StdCompactAcceptorFst cfst(fst);
575+
cfst.Write(os, write_options);
577576
}
578577
} else {
579578
KALDI_ASSERT(e2e_fsts.size() == num_sequences);
@@ -586,9 +585,8 @@ void Supervision::Write(std::ostream &os, bool binary) const {
586585
// Write using StdAcceptorCompactFst, making use of the fact that it's an
587586
// acceptor.
588587
fst::FstWriteOptions write_options("<unknown>");
589-
fst::StdCompactAcceptorFst::WriteFst(
590-
e2e_fsts[i], fst::AcceptorCompactor<fst::StdArc>(), os,
591-
write_options);
588+
fst::StdCompactAcceptorFst cfst(e2e_fsts[i]);
589+
cfst.Write(os, write_options);
592590
}
593591
}
594592
WriteToken(os, binary, "</Fsts>");

src/configure

+9-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
# This should be incremented after any significant change to the configure
4141
# script, i.e. any change affecting kaldi.mk or the build system as a whole.
42-
CONFIGURE_VERSION=14
42+
CONFIGURE_VERSION=15
4343

4444
# We support bash version 3.2 (Macs still ship with this version as of 2019)
4545
# and above.
@@ -1024,6 +1024,14 @@ OPENFST_VER_NUM=$(echo $OPENFST_VER | sed 's/\./ /g' | xargs printf "%d%02d%02d"
10241024
if [ $OPENFST_VER_NUM -lt 10600 ]; then
10251025
failure "OpenFst-$OPENFST_VER is not supported. You need OpenFst >= 1.6.0.)"
10261026
fi
1027+
1028+
if [ $OPENFST_VER_NUM -lt 10800 ]; then
1029+
echo "CXXLANGVERSION = c++14"
1030+
else
1031+
echo "CXXLANGVERSION = c++17"
1032+
fi >> kaldi.mk
1033+
1034+
echo "OPENFSTVER = $OPENFST_VER_NUM" >> kaldi.mk
10271035
echo "OPENFSTINC = $FSTROOT/include" >> kaldi.mk
10281036
if $static_fst ; then
10291037
OPENFSTLIBS="$FSTROOT/lib/libfst.a"

src/fstext/context-fst-test.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "util/kaldi-io.h"
2424
#include "base/kaldi-math.h"
2525

26+
#include "fstext/openfst_compat.h"
27+
2628
namespace fst
2729
{
2830
using std::vector;
@@ -196,7 +198,7 @@ static void TestContextFst(bool verbose, bool use_matcher) {
196198
std::cout << "Sequence FST is:\n";
197199
{ // Try to print the fst.
198200
FstPrinter<Arc> fstprinter(*f, NULL, NULL, NULL, false, true, "\t");
199-
fstprinter.Print(&std::cout, "standard output");
201+
printer_print(std::cout, fstprinter, "standard output");
200202
}
201203
}
202204

@@ -224,7 +226,7 @@ static void TestContextFst(bool verbose, bool use_matcher) {
224226
std::cout << "Composed FST is:\n";
225227
{ // Try to print the fst.
226228
FstPrinter<Arc> fstprinter(fst_composed, NULL, NULL, NULL, false, true, "\t");
227-
fstprinter.Print(&std::cout, "standard output");
229+
printer_print(std::cout, fstprinter, "standard output");
228230
}
229231
}
230232

src/fstext/determinize-lattice-test.cc

+8-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "fstext/fst-test-utils.h"
2323
#include "base/kaldi-math.h"
2424

25+
#include "fstext/openfst_compat.h"
26+
2527
namespace fst {
2628
using std::vector;
2729
using std::cout;
@@ -94,7 +96,7 @@ template<class Arc> void TestDeterminizeLattice() {
9496
std::cout << "FST before lattice-determinizing is:\n";
9597
{
9698
FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true, "\t");
97-
fstprinter.Print(&std::cout, "standard output");
99+
printer_print(std::cout, fstprinter, "standard output");
98100
}
99101
VectorFst<Arc> det_fst;
100102
try {
@@ -106,7 +108,7 @@ template<class Arc> void TestDeterminizeLattice() {
106108
std::cout << "FST after lattice-determinizing is:\n";
107109
{
108110
FstPrinter<Arc> fstprinter(det_fst, NULL, NULL, NULL, false, true, "\t");
109-
fstprinter.Print(&std::cout, "standard output");
111+
printer_print(std::cout, fstprinter, "standard output");
110112
}
111113
assert(det_fst.Properties(kIDeterministic, true) & kIDeterministic);
112114
// OK, now determinize it a different way and check equivalence.
@@ -117,7 +119,7 @@ template<class Arc> void TestDeterminizeLattice() {
117119
std::cout << "Compact FST is:\n";
118120
{
119121
FstPrinter<CompactArc> fstprinter(compact_fst, NULL, NULL, NULL, false, true, "\t");
120-
fstprinter.Print(&std::cout, "standard output");
122+
printer_print(std::cout, fstprinter, "standard output");
121123
}
122124
if (kaldi::Rand() % 2 == 1)
123125
ConvertLattice<Weight, Int>(det_fst, &compact_det_fst, false);
@@ -128,7 +130,7 @@ template<class Arc> void TestDeterminizeLattice() {
128130
std::cout << "Compact version of determinized FST is:\n";
129131
{
130132
FstPrinter<CompactArc> fstprinter(compact_det_fst, NULL, NULL, NULL, false, true, "\t");
131-
fstprinter.Print(&std::cout, "standard output");
133+
printer_print(std::cout, fstprinter, "standard output");
132134
}
133135

134136
assert(RandEquivalent(compact_det_fst, compact_fst, 5/*paths*/, 0.01/*delta*/, kaldi::Rand()/*seed*/, 100/*path length, max*/));
@@ -149,14 +151,14 @@ template<class Arc> void TestDeterminizeLattice2() {
149151
std::cout << "FST before lattice-determinizing is:\n";
150152
{
151153
FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true, "\t");
152-
fstprinter.Print(&std::cout, "standard output");
154+
printer_print(std::cout, fstprinter, "standard output");
153155
}
154156
VectorFst<Arc> ofst;
155157
DeterminizeLattice<TropicalWeight, int32>(*fst, &ofst);
156158
std::cout << "FST after lattice-determinizing is:\n";
157159
{
158160
FstPrinter<Arc> fstprinter(ofst, NULL, NULL, NULL, false, true, "\t");
159-
fstprinter.Print(&std::cout, "standard output");
161+
printer_print(std::cout, fstprinter, "standard output");
160162
}
161163
delete fst;
162164
}

0 commit comments

Comments
 (0)