]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/kaldi.git/commitdiff
trunk: Add OpenFst-1.4/C++11 support.
authorDogan Can <dogancanbaz@gmail.com>
Sun, 14 Dec 2014 00:25:55 +0000 (00:25 +0000)
committerDogan Can <dogancanbaz@gmail.com>
Sun, 14 Dec 2014 00:25:55 +0000 (00:25 +0000)
git-svn-id: https://svn.code.sf.net/p/kaldi/code/trunk@4697 5e6a8d80-dfce-4ca6-a32a-6e07a63d50c8

56 files changed:
src/Makefile
src/base/kaldi-error.cc
src/base/kaldi-error.h
src/bin/phones-to-prons.cc
src/configure
src/decoder/faster-decoder.h
src/decoder/lattice-simple-decoder.cc
src/decoder/lattice-simple-decoder.h
src/decoder/lattice-tracking-decoder.cc
src/decoder/nbest-decoder.h
src/feat/wave-reader.cc
src/fstext/context-fst-inl.h
src/fstext/context-fst-test.cc
src/fstext/context-fst.h
src/fstext/deterministic-fst.h
src/fstext/determinize-lattice-inl.h
src/fstext/determinize-lattice-test.cc
src/fstext/determinize-star-inl.h
src/fstext/determinize-star-test.cc
src/fstext/factor-inl.h
src/fstext/factor-test.cc
src/fstext/fstext-utils-test.cc
src/fstext/fstext-utils.h
src/fstext/lattice-utils-test.cc
src/fstext/pre-determinize-test.cc
src/fstext/prune-special-inl.h
src/fstext/prune-special-test.cc
src/fstext/push-special-test.cc
src/fstext/remove-eps-local-test.cc
src/fstext/rescale-test.cc
src/fstext/table-matcher-test.cc
src/fstext/trivial-factor-weight-test.cc
src/fstext/trivial-factor-weight.h
src/kwsbin/kws-search.cc
src/lat/determinize-lattice-pruned-test.cc
src/lat/determinize-lattice-pruned.cc
src/lat/kaldi-lattice.cc
src/lat/kws-functions.cc
src/lat/push-lattice-test.cc
src/lm/kaldi-lmtable.h
src/makefiles/darwin_10_10.mk
src/makefiles/darwin_10_9.mk
src/matrix/kaldi-blas.h
src/nnet2bin/nnet-relabel-egs.cc
src/online/online-faster-decoder.cc
src/online/online-faster-decoder.h
src/online2/online-speex-wrapper.h
src/util/basic-filebuf.h [new file with mode: 0644]
src/util/kaldi-pipebuf.h
src/util/stl-utils.h
tools/INSTALL
tools/Makefile
tools/extras/install_sequitur.sh
tools/extras/openfst.patch [new file with mode: 0644]
tools/extras/sequitur.patch [moved from tools/sequitur.patch with 100% similarity]
tools/openfst.patch [deleted file]

index 77c58cd299756342a1d3fd5b73dddd75bcc9709a..a8fc3396d83c807514309ce065b3485533df59ef 100644 (file)
@@ -1,6 +1,6 @@
 # This is the top-level Makefile for Kaldi.
 # Also see kaldi.mk which supplies options and some rules
-# used by the Makefiles in the subdirectories. 
+# used by the Makefiles in the subdirectories.
 
 SHELL := /bin/bash
 
@@ -39,7 +39,7 @@ mklibdir:
 #I don't want to call rm -rf
 rmlibdir:
 ifneq ($(KALDILIBDIR), )
-       -rm $(KALDILIBDIR)/*{.so,.a,.o} 
+       -rm $(KALDILIBDIR)/*{.so,.a,.o}
        -rmdir $(KALDILIBDIR)
 else
        @true
@@ -53,7 +53,7 @@ else
        $(error The kaldi.mk file was generated using a different version of configure script. Run the configure script again.)
 endif
 
-biglib: $(SUBDIRS_LIB) 
+biglib: $(SUBDIRS_LIB)
 ifeq ($(KALDI_FLAVOR), dynamic)
 ifeq ($(shell uname), Darwin)
        $(CXX) -dynamiclib -o $(KALDILIBDIR)/libkaldi.dylib -install_name @rpath/libkaldi.dylib -framework Accelerate $(LDFLAGS) $(SUBDIRS_LIB:=/*.dylib)
@@ -84,15 +84,16 @@ endif
 kaldi.mk:
        @[ -f kaldi.mk ] || { echo "kaldi.mk does not exist; you have to run ./configure"; exit 1; }
 
-# Compile optional stuff 
+# Compile optional stuff
 ext: test_dependencies ext_depend $(SUBDIRS) $(EXT_SUBDIRS)
        -echo Done
 
-# Note: if you have put the OpenFst installation somewhere else, you can just
-# delete or comment out the lines below.
-OPENFST_VER = $(shell grep 'PACKAGE_VERSION' ../tools/openfst/Makefile | sed -e 's:.*= ::')
+# Note: OPENFST_VER is determined by configure and added to kaldi.mk
+OPENFST_VER_NUM := $(shell echo $(OPENFST_VER) | sed 's/\./ /g' | xargs printf "%d%02d%02d")
 test_dependencies:
-       [ "$(OPENFST_VER)" == '1.3.2' ] || [ "$(OPENFST_VER)" == '1.3.3' ] || [ "$(OPENFST_VER)" == '1.3.4' ] || { echo "You now need openfst-1.3.2 or later. cd ../tools; svn update; ./install.sh; cd ../src; make depend; make"; exit 1; };
+ifeq ("$(shell expr $(OPENFST_VER_NUM) \< 10302)","1")
+       $(error OpenFst $(OPENFST_VER) is not supported. You now need OpenFst >= 1.3.2.)
+endif
 
 check_portaudio:
        @[ -d ../tools/portaudio ] || ( cd ../tools;  ./install_portaudio.sh )
index 3bd341cd40f39c89944dc22db1fa54a6b139dc30..8d8acd6839af03b9a484a8bb724d4c1e39599687 100644 (file)
@@ -165,7 +165,7 @@ KaldiErrorMessage::KaldiErrorMessage(const char *func, const char *file,
                  << GetShortFileName(file) << ':' << line << ") ";
 }
 
-KaldiErrorMessage::~KaldiErrorMessage() {
+KaldiErrorMessage::~KaldiErrorMessage() NOEXCEPT(false) {
   // (1) Print the message to stderr.
   std::cerr << ss.str() << '\n';
   // (2) Throw an exception with the message, plus traceback info if available.
index 915ff573189fd6f4ae7e59b8ec6a2317c929601f..8334e42b97c3281086eb07a732b36dc4d25818b7 100644 (file)
 #include <sstream>
 #include <cstdio>
 
+#ifdef _MSC_VER
+#define NOEXCEPT(Predicate)
+#elif __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
+#define NOEXCEPT(Predicate) noexcept((Predicate))
+#else
+#define NOEXCEPT(Predicate)
+#endif
+
 #include "base/kaldi-types.h"
 #include "base/kaldi-utils.h"
 
@@ -97,7 +105,7 @@ class KaldiErrorMessage {
  public:
   KaldiErrorMessage(const char *func, const char *file, int32 line);
   inline std::ostream &stream() { return ss; }
-  ~KaldiErrorMessage();  // defined in kaldi-error.cc
+  ~KaldiErrorMessage() NOEXCEPT(false);  // defined in kaldi-error.cc
  private:
   std::ostringstream ss;
 };
index 47ad96c8031bfaf7cecd7f3b33cf3568d2b72825..2d3caddf78d716a4ef22570787ac7248f2e1931b 100644 (file)
@@ -170,7 +170,11 @@ int main(int argc, char *argv[]) {
                    << "not reach end-state, or mismatched lexicon.)";
         if (g_kaldi_verbose_level >= 2) {
           KALDI_LOG << "phn2word FST is below:";
+#ifdef HAVE_OPENFST_GE_10400
+          fst::FstPrinter<StdArc> fstprinter(phn2word, NULL, NULL, NULL, false, true, "\t");
+#else
           fst::FstPrinter<StdArc> fstprinter(phn2word, NULL, NULL, NULL, false, true);
+#endif
           fstprinter.Print(&std::cerr, "standard error");
           KALDI_LOG << "phone sequence is: ";
           for (size_t i = 0; i < phones.size(); i++)
index 241745101f091264e14a64b1a17f38139d3bb1f7..49e18e937a20307c7871335b5c72f4da670aaba1 100755 (executable)
@@ -1,17 +1,17 @@
 #!/bin/bash
-# 
+#
 # This configure script is hand-generated, not auto-generated.
 # It creates the file kaldi.mk, which is %included by the Makefiles
 # in the subdirectories.
 # The file kaldi.mk is editable by hand-- for example, you may want to
-# remove the options -g -O0 -DKALDI_PARANOID, or edit the 
+# remove the options -g -O0 -DKALDI_PARANOID, or edit the
 # -DKALDI_DOUBLE_PRECISION option (to be 1 not 0),
 
 
 #  Example command lines:
 # ./configure
 # ./configure --shared  ## shared libraries.
-# ./configure --mkl-root=/opt/intel/mkl 
+# ./configure --mkl-root=/opt/intel/mkl
 # ./configure --mkl-root=/opt/intel/mkl --threaded-math=yes
 # ./configure  --openblas-root=../tools/OpenBLAS/install  # before doing
 #        # this, cd to ../tools and type "make openblas".  Note:
@@ -88,16 +88,16 @@ do
   --version) echo $CONFIGURE_VERSION; exit 0 ;;
   --static)
     # FIXME depends on order of options first--static/--shared then --static-math -> it will override it
-  dynamic_kaldi=false; 
+  dynamic_kaldi=false;
   static_math=true;
   static_fst=true;
   shift ;;  
   --shared)
-  dynamic_kaldi=true; 
+  dynamic_kaldi=true;
   static_math=false;
   static_fst=false;
   shift ;;  
-  --atlas-root=*) 
+  --atlas-root=*)
   ATLASROOT=`read_dirname $1`; shift ;;
   --threaded-atlas=yes)
   threaded_atlas=true; shift ;;
@@ -145,7 +145,7 @@ function failure {
   echo "***configure failed: $* ***" >&2
   if [ -f kaldi.mk ]; then rm kaldi.mk; fi
   exit 1;
-} 
+}
 
 function check_exists {
   if [ ! -f $1 ]; then failure "$1 not found."; fi
@@ -171,10 +171,10 @@ function check_for_slow_expf {
   ./exp-test
   if [ $? -eq 1 ]; then
       echo "*** WARNING: expf() seems to be slower than exp() on your machine. This is a known bug in old versions of glibc. Please consider updating glibc. ***"
-      echo "*** Kaldi will be configured to use exp() instead of expf() in base/kaldi-math.h Exp() routine for single-precision floats. ***" 
+      echo "*** Kaldi will be configured to use exp() instead of expf() in base/kaldi-math.h Exp() routine for single-precision floats. ***"
       echo "CXXFLAGS += -DKALDI_NO_EXPF" >> ../kaldi.mk
   fi
-  cd ..    
+  cd ..
 }
 
 function exit_success {
@@ -202,18 +202,18 @@ function linux_configure_mkl_libraries {
   local threaded=$3
 
   #these lines were generated using the Intel Link Line Advisor 2.2
-  local threaded_libs="mkl_intel_lp64 mkl_intel_thread mkl_core"  
-  local sequential_libs="mkl_intel_lp64 mkl_sequential mkl_core"  
+  local threaded_libs="mkl_intel_lp64 mkl_intel_thread mkl_core"
+  local sequential_libs="mkl_intel_lp64 mkl_sequential mkl_core"
 
   if  ! $static && $threaded ; then
     for file in $threaded_libs; do
-      local libfile=$mkllibdir/lib$file.so 
+      local libfile=$mkllibdir/lib$file.so
       check_exists $libfile
     done 
     echo  "-L$mkllibdir -Wl,-rpath=$mkllibdir -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -liomp5 -lpthread -lm"
   elif  ! $static && ! $threaded ; then
     for file in $sequential_libs; do
-      local libfile=$mkllibdir/lib$file.so 
+      local libfile=$mkllibdir/lib$file.so
       check_exists $libfile
     done  
     echo "-L$mkllibdir  -Wl,-rpath=$mkllibdir -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -liomp5 -lpthread -lm"
@@ -222,7 +222,7 @@ function linux_configure_mkl_libraries {
     test -f "$mkllibdir/libmkl_solver_lp64.a" && linkline="$linkline $mkllibdir/libmkl_solver_lp64.a"
     linkline="$linkline -Wl,--start-group"
     for file in $threaded_libs; do
-      local libfile=$mkllibdir/lib$file.a 
+      local libfile=$mkllibdir/lib$file.a
       check_exists $libfile
       linkline="$linkline $libfile"
     done  
@@ -234,7 +234,7 @@ function linux_configure_mkl_libraries {
     test -f "$mkllibdir/libmkl_solver_lp64_sequential.a" && linkline="$linkline $mkllibdir/libmkl_solver_lp64_sequential.a"
     linkline="$linkline -Wl,--start-group"
     for file in $sequential_libs; do
-      local libfile=$mkllibdir/lib$file.a 
+      local libfile=$mkllibdir/lib$file.a
       check_exists $libfile
       linkline="$linkline $libfile"
     done  
@@ -271,23 +271,23 @@ function linux_configure_omplibdir {
   local libexts=$3
   
   
-  ##First we try to use the library in the same directory 
+  ##First we try to use the library in the same directory
   ##where the mkl libraries reside
-  ##Afterwards, just try some possibilities for different MKL layouts 
+  ##Afterwards, just try some possibilities for different MKL layouts
   for libext in $libexts; do
     echo "Testing $libext from [$libexts] " >&2
 
     check_library $mkllibdir "libiomp5" $libext \
     && echo `readlink -f $mkllibdir` && return
     
-    local testdir=`(cd $mklroot; cd ..; cd lib/intel64;pwd)` 
+    local testdir=`(cd $mklroot; cd ..; cd lib/intel64;pwd)`
     test -d $testdir && check_library $testdir "libiomp5" $libext && echo `readlink -f $testdir` && return;
-    local testdir=`(cd $mklroot; cd ..; cd lib/em64t;pwd)` 
+    local testdir=`(cd $mklroot; cd ..; cd lib/em64t;pwd)`
     test -d $testdir && check_library $testdir "libiomp5" $libext && echo `readlink -f $testdir` && return;
     
-    local testdir=`(cd $mkllibdir; cd ../../..; cd lib/intel64;pwd)` 
+    local testdir=`(cd $mkllibdir; cd ../../..; cd lib/intel64;pwd)`
     test -d $testdir && check_library $testdir "libiomp5" $libext && echo `readlink -f $testdir` && return;
-    local testdir=`(cd $mklroot; cd ../../..; cd lib/em64t;pwd)` 
+    local testdir=`(cd $mklroot; cd ../../..; cd lib/em64t;pwd)`
     test -d $testdir && check_library $testdir "libiomp5" $libext && echo `readlink -f $testdir` && return;
   done
 
@@ -384,7 +384,7 @@ function fix_cxx_flag {
 function linux_atlas_failure { # function we use when we couldn't find
    # ATLAS libs.
    echo ATLASINC = [somewhere]/include >> kaldi.mk
-   echo ATLASLIBS = [somewhere]/liblapack.a [somewhere]/libcblas.a [somewhere]/libatlas.a [somewhere]/libf77blas.a $ATLASLIBDIR >> kaldi.mk  
+   echo ATLASLIBS = [somewhere]/liblapack.a [somewhere]/libcblas.a [somewhere]/libatlas.a [somewhere]/libf77blas.a $ATLASLIBDIR >> kaldi.mk
    cat makefiles/linux_atlas.mk >> kaldi.mk
    fix_cxx_flag
    echo "** $* ***"
@@ -399,7 +399,7 @@ function linux_atlas_failure { # function we use when we couldn't find
    echo "** or try going to ../tools and running install_atlas.sh, and running"
    echo "   this script (configure) again."
    exit 1;
-} 
+}
 
 function linux_check_static {
   # will exit with success if $dir seems to contain ATLAS libraries with
@@ -494,11 +494,11 @@ function linux_configure_static {
   ATLASLIBS=
   # The Lapack part of ATLAS seems to appear under various different names.. but it
   # should always have symbols like ATL_cgetrf defined, so we test for this,
-  # for all the names we have encountered. 
+  # for all the names we have encountered.
   for libname in liblapack liblapack_atlas  libclapack; do
     if [ -f $ATLASLIBDIR/${libname}.a -a "$ATLASLIBS" == "" ]; then
       if nm  $ATLASLIBDIR/${libname}.a  | grep ATL_cgetrf >/dev/null; then
-         ATLASLIBS=$ATLASLIBDIR/${libname}.a          
+         ATLASLIBS=$ATLASLIBDIR/${libname}.a
          echo "Using library $ATLASLIBS as ATLAS's CLAPACK library."
       fi
     fi
@@ -563,7 +563,7 @@ function linux_configure_dynamic {
   ATLASLIBS=
   # The Lapack part of ATLAS seems to appear under various different names.. but it
   # should always have symbols like ATL_cgetrf defined, so we test for this,
-  # for all the names we have encountered. 
+  # for all the names we have encountered.
   for libname in lapack lapack_atlas  clapack; do
     if [ -f $ATLASLIBDIR/lib${libname}.so -a "$ATLASLIBS" == "" ]; then
       if nm  --dynamic $ATLASLIBDIR/lib${libname}.so  | grep ATL_cgetrf >/dev/null; then
@@ -630,12 +630,24 @@ echo "KALDI_FLAVOR := dynamic" >> kaldi.mk
 echo "KALDILIBDIR := $KALDILIBDIR" >> kaldi.mk
 fi
 echo "CONFIGURE_VERSION := $CONFIGURE_VERSION" >> kaldi.mk
+echo "FSTROOT = $FSTROOT" >> kaldi.mk
+
+# Check installed OpenFst version and add C++11 flags if OpenFst >= 1.4
+OPENFST_VER=`grep 'PACKAGE_VERSION' $FSTROOT/Makefile | sed -e 's:.*= ::'`
+echo "OPENFST_VER = $OPENFST_VER" >> kaldi.mk
+OPENFST_VER_NUM=`echo $OPENFST_VER | sed 's/\./ /g' | xargs printf "%d%02d%02d"`
+if [ $OPENFST_VER_NUM -ge 10400 ]; then
+  echo "OPENFST_GE_10400 = 1" >> kaldi.mk
+  echo "EXTRA_CXXFLAGS += -DHAVE_OPENFST_GE_10400 -std=c++0x" >> kaldi.mk
+else
+  echo "OPENFST_GE_10400 = 0" >> kaldi.mk
+fi
 
 # Most of the OS-specific steps below will append to kaldi.mk
 echo "Doing OS specific configurations ..."
 
 # Check for Darwin at first, because we later call uname -o (for Cygwin)
-# which crashes on Darwin. Also the linear algebra libraries on Macs are 
+# which crashes on Darwin. Also the linear algebra libraries on Macs are
 # used differently (through the Accelerate framework) than on Linux.
 if [ "`uname`" == "Darwin"  ]; then
  $use_cuda && linux_configure_cuda
@@ -646,28 +658,27 @@ if [ "`uname`" == "Darwin"  ]; then
   if [ ! -f $FSTROOT/lib/libfst.a ]; then
     failure "Static OpenFST library not found:  See ../tools/INSTALL"
   fi
-  echo FSTROOT = $FSTROOT >> kaldi.mk
   # posix_memalign and gcc -rdynamic options not present on OS X 10.5.*
   osx_ver=`sw_vers | grep ProductVersion | awk '{print $2}' | awk '{split($0,a,"\."); print a[1] "." a[2]; }'`
   echo "Configuring for OS X version $osx_ver ..."
   if [ "$osx_ver" == "10.5" ]; then
     check_exists makefiles/darwin_10_5.mk
-    cat makefiles/darwin_10_5.mk >> kaldi.mk 
+    cat makefiles/darwin_10_5.mk >> kaldi.mk
   elif [ "$osx_ver" == "10.6" ]; then
     check_exists makefiles/darwin_10_6.mk
-    cat makefiles/darwin_10_6.mk >> kaldi.mk 
+    cat makefiles/darwin_10_6.mk >> kaldi.mk
   elif [ "$osx_ver" == "10.7" ]; then
     check_exists makefiles/darwin_10_7.mk
-    cat makefiles/darwin_10_7.mk >> kaldi.mk 
+    cat makefiles/darwin_10_7.mk >> kaldi.mk
   elif [ "$osx_ver" == "10.8" ]; then
     check_exists makefiles/darwin_10_8.mk
-    cat makefiles/darwin_10_8.mk >> kaldi.mk 
+    cat makefiles/darwin_10_8.mk >> kaldi.mk
   elif [ "$osx_ver" == "10.9" ]; then
     check_exists makefiles/darwin_10_9.mk
-    cat makefiles/darwin_10_9.mk >> kaldi.mk 
+    cat makefiles/darwin_10_9.mk >> kaldi.mk
   elif [ "$osx_ver" == "10.10" ]; then
     check_exists makefiles/darwin_10_10.mk
-    cat makefiles/darwin_10_10.mk >> kaldi.mk 
+    cat makefiles/darwin_10_10.mk >> kaldi.mk
   else 
     failure "OS X version '$osx_ver' not supported"
   fi
@@ -683,7 +694,6 @@ if [ "`uname -o`" == "Cygwin"  ]; then
     if [ ! -f /usr/lib/lapack/cygblas-0.dll ]; then
        failure "please first install package liblapack0"
     fi
-    echo FSTROOT = $FSTROOT >> kaldi.mk
     cat makefiles/cygwin.mk >> kaldi.mk
     echo "Configuration succeeded for platform cygwin"
     exit_success;
@@ -703,7 +713,6 @@ if [ "`uname`" == "Linux" ]; then
   fi
   echo OPENFSTLIBS = $OPENFSTLIBS >> kaldi.mk
   echo OPENFSTLDFLAGS = $OPENFSTLDFLAGS >> kaldi.mk
-  echo FSTROOT = $FSTROOT >> kaldi.mk
 
   echo "On Linux: Checking for linear algebra header files ..."
   if [ "$MATHLIB" == "ATLAS" ]; then
@@ -712,7 +721,7 @@ if [ "`uname`" == "Linux" ]; then
     fi
     echo "Using ATLAS as the linear algebra library."
     
-    # Finding out where the libraries are located: 
+    # Finding out where the libraries are located:
     # First we look for the static libraries and then look for dynamic ones.
     # We're looking for four libraries, all in the same directory, named
     # libcblas.a, libatlas.a, libf77blas.a, and a library that's variously
@@ -747,7 +756,7 @@ if [ "`uname`" == "Linux" ]; then
 
   elif [ "$MATHLIB" == "MKL" ]; then
     if [ "`uname -m`" != "x86_64" ]; then
-      failure "MKL on Linux only supported for Intel(R) 64 architecture (x86_64). 
+      failure "MKL on Linux only supported for Intel(R) 64 architecture (x86_64).
       See makefiles/linux_64_mkl.mk to manually configure for other platforms."
     fi
     
@@ -778,8 +787,8 @@ if [ "`uname`" == "Linux" ]; then
       || failure "Could not find the iomp5 library, have your tried the --omp-libdir switch?"
     echo "OMP library directory configured as: $OMPLIBDIR"
     OMP_LINK_LINE=''
-    # TODO(arnab): in the following conditional, the $static_math test is needed since 
-    # the OpenMP library is assumed to be dynamic.
+    # TODO(arnab): in the following conditional, the $static_math test is
+    # needed since the OpenMP library is assumed to be dynamic.
     if [ "$OMPLIBDIR" != "$MKLLIBDIR" ] ; then
       OMP_LINK_LINE="-L${OMPLIBDIR}"
       #if the libiomp5 library is dynamic, we add the rpath attribute
@@ -796,7 +805,6 @@ if [ "`uname`" == "Linux" ]; then
     if [ ! -z $MKLLIBDIR ]; then 
       echo MKLLIB = $MKLLIBDIR >> kaldi.mk
     fi
-    echo FSTROOT = $FSTROOT >> kaldi.mk
     check_exists makefiles/linux_x86_64_mkl.mk
     cat makefiles/linux_x86_64_mkl.mk >> kaldi.mk
     fix_cxx_flag
index 225c7f6f2a594bb16a1467e8cedb0ed58b1b8186..b1b031accd1d346eb88480785ac756600ea84af2 100644 (file)
 #include "itf/decodable-itf.h"
 #include "lat/kaldi-lattice.h" // for CompactLatticeArc
 
-#ifdef _MSC_VER
-#include <unordered_map>
-#else
-#include <tr1/unordered_map>
-#endif
-using std::tr1::unordered_map;
-
 namespace kaldi {
 
 struct FasterDecoderOptions {
index 1cee23f1c7af668dca413a1ce69d96fd9b317550..7e9087e59afbd7016c80436aee37da703e78394e 100644 (file)
@@ -692,7 +692,7 @@ bool DecodeUtteranceLatticeSimple(
   }
 
   double likelihood;
-  LatticeWeight weight;
+  LatticeWeight weight = LatticeWeight::Zero();
   int32 num_frames;
   { // First do some stuff with word-level traceback...
     VectorFst<LatticeArc> decoded;
index 3001cf6fe2f963588b878192189f4ab0b483b91f..bfc8485518bbfe401db3cb63ce8dd0c88d3063c2 100644 (file)
 #include "lat/kaldi-lattice.h"
 
 #include <algorithm>
-#ifdef _MSC_VER
-#include <unordered_map>
-#else
-#include <tr1/unordered_map>
-#endif
-using std::tr1::unordered_map;
 
 namespace kaldi {
 
index aac862ad4812f414b9e45ac1b5b929fa44075b4d..5f9d8c313f9fff2470768824a420041cb25d8340 100644 (file)
@@ -914,7 +914,7 @@ bool DecodeUtteranceLatticeTracking(
   }
 
   double likelihood;
-  LatticeWeight weight;
+  LatticeWeight weight = LatticeWeight::Zero();
   int32 num_frames;
   { // First do some stuff with word-level traceback...
     VectorFst<LatticeArc> decoded;
index 1ce8e7a00ea31ed59e98ee3c32d87c9a1cd3bf54..f35dcf2b8e5050bc9bd6b75f0df5a04bc2ba79c3 100644 (file)
 #ifndef KALDI_DECODER_NBEST_DECODER_H_
 #define KALDI_DECODER_NBEST_DECODER_H_
 
-#ifdef _MSC_VER
-#include <unordered_map>
-#else
-#include <tr1/unordered_map>
-#endif
 #include "util/stl-utils.h"
 #include "itf/options-itf.h"
 #include "util/hash-list.h"
@@ -686,7 +681,7 @@ class NBestDecoder {
   TokenHash toks_;
   const fst::Fst<fst::StdArc> &fst_;
   NBestDecoderOptions opts_;
-  typedef std::tr1::unordered_set<StateId> StateQueue;
+  typedef unordered_set<StateId> StateQueue;
   StateQueue queue_; // used in PropagateEpsilon,
   // std::vector<StateId> queue_;  // temp variable used in PropagateEpsilon,
   std::vector<BaseFloat> tmp_array_;  // used in GetCutoff.
index 6ea2770c6a9043058c46760ad37fc6d4ba21c5d1..6db756bc7321ffff0a32e9f4cf6c41421a4f8bdb 100644 (file)
@@ -111,12 +111,10 @@ void WaveData::Read(std::istream &is) {
   char tmp[5];
   tmp[4] = '\0';
   Read4ByteTag(is, &tmp[0]);
-  bool is_rifx;
-  if (!strcmp(tmp, "RIFF"))
-    is_rifx = false;
-  else if (!strcmp(tmp, "RIFX"))
+  bool is_rifx = false;
+  if (!strcmp(tmp, "RIFX"))
     is_rifx = true;
-  else
+  else if (strcmp(tmp, "RIFF"))
     KALDI_ERR << "WaveData: expected RIFF or RIFX, got " << tmp;
 
 #ifdef __BIG_ENDIAN__  
index 4c6243f42a28cbfe1885b5ef30d415b349688192..f796fbc9e202e2b006a59f57a9f39e4d79404197 100644 (file)
@@ -41,9 +41,12 @@ typename ContextFstImpl<Arc, LabelT>::StateId
   VectorToStateIter iter = state_map_.find(seq);
   if (iter == state_map_.end()) {  // Not already in map.
     StateId this_state_id = (StateId)state_seqs_.size();
+    //This check is not needed with OpenFst >= 1.4
+#ifndef HAVE_OPENFST_GE_10400
     StateId this_state_id_check = CacheImpl<Arc>::AddState();
     // goes back to VectorFstBaseImpl<Arc>, inherited via CacheFst<Arc>
     assert(this_state_id == this_state_id_check);
+#endif
     state_seqs_.push_back(seq);
     state_map_[seq] = this_state_id;
     return this_state_id;
@@ -321,16 +324,34 @@ void ContextFstImpl<Arc, LabelT>::Expand(StateId s) {  // expands arcs only [not
 
   // We just try adding all possible symbols on the output side.
   Arc arc;
-  if (this->CreateArc(s, subsequential_symbol_, &arc)) this->AddArc(s, arc);
+  if (this->CreateArc(s, subsequential_symbol_, &arc)) {
+#ifdef HAVE_OPENFST_GE_10400
+    this->PushArc(s, arc);
+#else
+    this->AddArc(s, arc);
+#endif
+  }
   for (typename kaldi::ConstIntegerSet<Label>::iterator iter = phone_syms_.begin();
        iter != phone_syms_.end(); ++iter) {
     Label phone = *iter;
-    if (this->CreateArc(s, phone, &arc)) this->AddArc(s, arc);
+    if (this->CreateArc(s, phone, &arc)) {
+#ifdef HAVE_OPENFST_GE_10400
+      this->PushArc(s, arc);
+#else
+      this->AddArc(s, arc);
+#endif
+    }
   }
   for (typename kaldi::ConstIntegerSet<Label>::iterator iter = disambig_syms_.begin();
        iter != disambig_syms_.end(); ++iter) {
     Label disambig_sym = *iter;
-    if (this->CreateArc(s, disambig_sym, &arc)) this->AddArc(s, arc);
+    if (this->CreateArc(s, disambig_sym, &arc)) {
+#ifdef HAVE_OPENFST_GE_10400
+      this->PushArc(s, arc);
+#else
+      this->AddArc(s, arc);
+#endif
+    }
   }
   this->SetArcs(s);  // mark the arcs as "done". [so HasArcs returns true].
 }
index 3fd8eff43ebf650ebc31d47caceb7e12e521c0e3..53c774f829a275d46675aa02f778b99393a2e70e 100644 (file)
@@ -192,7 +192,11 @@ template<class Arc> static void TestContextFst(bool verbose, bool use_matcher) {
   }
 
   if (verbose) {  // Try to print the fst.
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(cfst, cfst.InputSymbols(), cfst.OutputSymbols(), NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(cfst, cfst.InputSymbols(), cfst.OutputSymbols(), NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
@@ -207,7 +211,11 @@ template<class Arc> static void TestContextFst(bool verbose, bool use_matcher) {
     if (verbose) {
       std::cout << "Sequence FST is:\n";
       {  // Try to print the fst.
+#ifdef HAVE_OPENFST_GE_10400
+        FstPrinter<Arc> fstprinter(*f, f->InputSymbols(), f->OutputSymbols(), NULL, false, true, "\t");
+#else
         FstPrinter<Arc> fstprinter(*f, f->InputSymbols(), f->OutputSymbols(), NULL, false, true);
+#endif
         fstprinter.Print(&std::cout, "standard output");
       }
     }
@@ -249,8 +257,13 @@ template<class Arc> static void TestContextFst(bool verbose, bool use_matcher) {
     if (verbose) {
       std::cout << "Composed FST is:\n";
       {  // Try to print the fst.
+#ifdef HAVE_OPENFST_GE_10400
+        FstPrinter<Arc> fstprinter(fst_composed, fst_composed.InputSymbols(),
+                                   fst_composed.OutputSymbols(), NULL, false, true, "\t");
+#else
         FstPrinter<Arc> fstprinter(fst_composed, fst_composed.InputSymbols(),
                                    fst_composed.OutputSymbols(), NULL, false, true);
+#endif
         fstprinter.Print(&std::cout, "standard output");
       }
     }
index b1a69a82f93a072d936ff657b054c3b03a1fbd08..2b973be18375d5c1486bf6da0a2e7cfedbcd968a 100644 (file)
    efficient to compose with.
 */
 
-#include <algorithm>
-#include <string>
-#include <vector>
 #ifdef _MSC_VER
 #include <unordered_map>
+using std::unordered_map;
+#elif __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
+#include <unordered_map>
+using std::unordered_map;
 #else
 #include <tr1/unordered_map>
-#endif
 using std::tr1::unordered_map;
+#endif
+
+#include <algorithm>
+#include <string>
+#include <vector>
 #include <fst/fstlib.h>
 #include <fst/fst-decl.h>
-#include <fst/slist.h>
 
 #include "util/const-integer-set.h"
 
@@ -90,7 +94,10 @@ class ContextFstImpl : public CacheImpl<Arc> {
   typedef typename Arc::Weight Weight;
   typedef typename Arc::StateId StateId;
   typedef typename Arc::Label Label;
-
+#ifdef HAVE_OPENFST_GE_10400
+  typedef DefaultCacheStore<Arc> Store;
+  typedef typename Store::State State;
+#endif
   typedef unordered_map<vector<LabelT>,
                         StateId, kaldi::VectorHasher<LabelT> > VectorToStateType;
   typedef unordered_map<vector<LabelT>,
@@ -206,16 +213,22 @@ class ContextFst : public Fst<Arc> {
  public:
   friend class ArcIterator< ContextFst<Arc> >;
   friend class StateIterator< ContextFst<Arc> >;
+#ifndef HAVE_OPENFST_GE_10400
   // We have to supply the default template argument below to work around a
   // Visual Studio bug.
   friend class CacheArcIterator< ContextFst<Arc>,
-                                 DefaultCacheStateAllocator<CacheState<Arc> >  >;
+                                 DefaultCacheStateAllocator<CacheState<Arc> > >;
+#endif
 
   typedef typename Arc::Weight Weight;
   typedef typename Arc::Label Label;
   typedef typename Arc::StateId StateId;
+#ifdef HAVE_OPENFST_GE_10400
+  typedef DefaultCacheStore<Arc> Store;
+  typedef typename Store::State State;
+#else
   typedef CacheState<Arc> State;
-
+#endif
 
   /// See \ref graph_context for more details.
   ContextFst(Label subsequential_symbol,  // epsilon not allowed.
index 9a45fd5848d97a34b9c5e4af049fb695b01b2d29..935ac5b48ea39833e89fdbf8301a2d660feba311 100644 (file)
 */
 
 #include <algorithm>
-#ifdef _MSC_VER
-#include <unordered_map>
-#else
-#include <tr1/unordered_map>
-#endif
-using std::tr1::unordered_map;
-
 #include <string>
 #include <utility>
 #include <vector>
 
 #include <fst/fstlib.h>
 #include <fst/fst-decl.h>
-#include <fst/slist.h>
 
 #include "util/stl-utils.h"
 
index e76f27baeee7320bc2f8ab1439991d9aba044fce..9a3f8169dabe22c8efcfffa5b0e4dfbce66acd26 100644 (file)
 #define KALDI_FSTEXT_DETERMINIZE_LATTICE_INL_H_
 // Do not include this file directly.  It is included by determinize-lattice.h
 
-#ifdef _MSC_VER
-#include <unordered_map>
-#else
-#include <tr1/unordered_map>
-#endif
 #include <vector>
-using std::tr1::unordered_map;
 #include <climits>
 
 namespace fst {
index 657dc5ec25c25f937d1dbfd41ce32b35cfa88065..a12e368ea8626643754990c408a4caa447024a96 100644 (file)
@@ -91,7 +91,11 @@ template<class Arc> void TestDeterminizeLattice() {
     VectorFst<Arc> *fst = RandFst<Arc>();
     std::cout << "FST before lattice-determinizing is:\n";
     {
+#ifdef HAVE_OPENFST_GE_10400
+      FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true, "\t");
+#else
       FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true);
+#endif
       fstprinter.Print(&std::cout, "standard output");
     }
     VectorFst<Arc> det_fst;
@@ -103,7 +107,11 @@ template<class Arc> void TestDeterminizeLattice() {
         throw std::runtime_error("could not determinize");
       std::cout << "FST after lattice-determinizing is:\n";
       {
+#ifdef HAVE_OPENFST_GE_10400
+        FstPrinter<Arc> fstprinter(det_fst, NULL, NULL, NULL, false, true, "\t");
+#else
         FstPrinter<Arc> fstprinter(det_fst, NULL, NULL, NULL, false, true);
+#endif
         fstprinter.Print(&std::cout, "standard output");
       }
       assert(det_fst.Properties(kIDeterministic, true) & kIDeterministic);
@@ -114,7 +122,11 @@ template<class Arc> void TestDeterminizeLattice() {
       ConvertLattice<Weight, Int>(*fst, &compact_fst, false);
       std::cout << "Compact FST is:\n";
       {
+#ifdef HAVE_OPENFST_GE_10400
+        FstPrinter<CompactArc> fstprinter(compact_fst, NULL, NULL, NULL, false, true, "\t");
+#else
         FstPrinter<CompactArc> fstprinter(compact_fst, NULL, NULL, NULL, false, true);
+#endif
         fstprinter.Print(&std::cout, "standard output");
       }
       if (kaldi::Rand() % 2 == 1)
@@ -125,7 +137,11 @@ template<class Arc> void TestDeterminizeLattice() {
       
       std::cout << "Compact version of determinized FST is:\n";
       {
+#ifdef HAVE_OPENFST_GE_10400
+        FstPrinter<CompactArc> fstprinter(compact_det_fst, NULL, NULL, NULL, false, true, "\t");
+#else
         FstPrinter<CompactArc> fstprinter(compact_det_fst, NULL, NULL, NULL, false, true);
+#endif
         fstprinter.Print(&std::cout, "standard output");
       }
       
@@ -146,14 +162,22 @@ template<class Arc> void TestDeterminizeLattice2() {
     VectorFst<Arc> *fst = RandFst<Arc>(opts);
     std::cout << "FST before lattice-determinizing is:\n";
     {
+#ifdef HAVE_OPENFST_GE_10400
+      FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true, "\t");
+#else
       FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true);
+#endif
       fstprinter.Print(&std::cout, "standard output");
     }
     VectorFst<Arc> ofst;
     DeterminizeLattice<TropicalWeight, int32>(*fst, &ofst);
     std::cout << "FST after lattice-determinizing is:\n";
     {
+#ifdef HAVE_OPENFST_GE_10400
+      FstPrinter<Arc> fstprinter(ofst, NULL, NULL, NULL, false, true, "\t");
+#else
       FstPrinter<Arc> fstprinter(ofst, NULL, NULL, NULL, false, true);
+#endif
       fstprinter.Print(&std::cout, "standard output");
     }
     delete fst;
index 2b668ccdb19a8243151b2cb66f8a9b43a3f26f77..c7d9194e6bb4b17e81d056644ef58b0314b09ed0 100644 (file)
 
 #ifdef _MSC_VER
 #include <unordered_map>
+using std::unordered_map;
+#elif __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
+#include <unordered_map>
+using std::unordered_map;
 #else
 #include <tr1/unordered_map>
-#endif
 using std::tr1::unordered_map;
+#endif
+
 #include <vector>
 #include <climits>
 
index 7a45c5d90631cda1775499d080963d68ec688624..d83d4f5eaefd74d9ab28a68f8ff0143a91d042b2 100644 (file)
@@ -36,7 +36,11 @@ template<class Arc> void TestDeterminizeGeneral() {
     VectorFst<Arc> *fst = RandFst<Arc>();
     std::cout << "FST before determinizing is:\n";
     {
+#ifdef HAVE_OPENFST_GE_10400
+      FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true, "\t");
+#else
       FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true);
+#endif
       fstprinter.Print(&std::cout, "standard output");
     }
     VectorFst<Arc> ofst;
@@ -44,7 +48,11 @@ template<class Arc> void TestDeterminizeGeneral() {
       DeterminizeStar<Arc>(*fst, &ofst, kDelta, NULL, max_states);
       std::cout << "FST after determinizing is:\n";
       {
+#ifdef HAVE_OPENFST_GE_10400
+        FstPrinter<Arc> fstprinter(ofst, NULL, NULL, NULL, false, true, "\t");
+#else
         FstPrinter<Arc> fstprinter(ofst, NULL, NULL, NULL, false, true);
+#endif
         fstprinter.Print(&std::cout, "standard output");
       }
       assert(RandEquivalent(*fst, ofst, 5/*paths*/, 0.01/*delta*/, kaldi::Rand()/*seed*/, 100/*path length, max*/));      
@@ -99,7 +107,11 @@ template<class Arc>  void TestDeterminize() {
 
   std::cout <<" printing before trimming\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
   // Trim resulting FST.
@@ -107,7 +119,11 @@ template<class Arc>  void TestDeterminize() {
 
   std::cout <<" printing after trimming\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
@@ -120,7 +136,11 @@ template<class Arc>  void TestDeterminize() {
 
   std::cout <<" printing after predeterminization\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
@@ -136,7 +156,11 @@ template<class Arc>  void TestDeterminize() {
 
   std::cout <<" printing after epsilon removal\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
   VectorFst<Arc> ofst_orig;
@@ -155,14 +179,22 @@ template<class Arc>  void TestDeterminize() {
 
   {
     std::cout <<" printing after determinization [baseline]\n";
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(ofst_orig, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(ofst_orig, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
     assert(ofst_orig.Properties(kIDeterministic, true) == kIDeterministic);
   }
 
   {
     std::cout <<" printing after determinization [star]\n";
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(ofst_star, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(ofst_star, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
     assert(ofst_star.Properties(kIDeterministic, true) == kIDeterministic);
   }
@@ -172,7 +204,11 @@ template<class Arc>  void TestDeterminize() {
   int64 num_removed = DeleteISymbols(&ofst_star, extra_syms);
   std::cout <<" printing after removing "<<num_removed<<" instances of extra symbols\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(ofst_star, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(ofst_star, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
@@ -240,7 +276,11 @@ template<class Arc>  void TestPush() {
 
   std::cout <<" printing before trimming\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
   // Trim resulting FST.
@@ -248,7 +288,11 @@ template<class Arc>  void TestPush() {
 
   std::cout <<" printing after trimming\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
@@ -265,7 +309,11 @@ template<class Arc>  void TestPush() {
 
   std::cout <<" printing after pushing\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(fst_pushed, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(fst_pushed, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
@@ -318,7 +366,11 @@ template<class Arc>  void TestMinimize() {
 
   std::cout <<" printing before trimming\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
   // Trim resulting FST.
@@ -326,7 +378,11 @@ template<class Arc>  void TestMinimize() {
 
   std::cout <<" printing after trimming\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
@@ -339,7 +395,11 @@ template<class Arc>  void TestMinimize() {
 
   std::cout <<" printing after predeterminization\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
@@ -355,7 +415,11 @@ template<class Arc>  void TestMinimize() {
 
   std::cout <<" printing after epsilon removal\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
   VectorFst<Arc> ofst_orig;
@@ -368,7 +432,11 @@ template<class Arc>  void TestMinimize() {
   }
   {
     std::cout <<" printing after determinization [baseline]\n";
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(ofst_orig, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(ofst_orig, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
@@ -380,7 +448,11 @@ template<class Arc>  void TestMinimize() {
     DeterminizeStar(*fst, &gallic_fst);
     {
       std::cout <<" printing after determinization by DeterminizeStar [in gallic]\n";
+#ifdef HAVE_OPENFST_GE_10400
+      FstPrinter<GallicArc< Arc> > fstprinter(gallic_fst, sptr, sptr, NULL, false, true, "\t");
+#else
       FstPrinter<GallicArc< Arc> > fstprinter(gallic_fst, sptr, sptr, NULL, false, true);
+#endif
       fstprinter.Print(&std::cout, "standard output");
     }
 
@@ -390,7 +462,11 @@ template<class Arc>  void TestMinimize() {
 
     {
       std::cout <<" printing after pushing weights [in gallic]\n";
+#ifdef HAVE_OPENFST_GE_10400
+      FstPrinter<GallicArc< Arc> > fstprinter(gallic_fst, sptr, sptr, NULL, false, true, "\t");
+#else
       FstPrinter<GallicArc< Arc> > fstprinter(gallic_fst, sptr, sptr, NULL, false, true);
+#endif
       fstprinter.Print(&std::cout, "standard output");
     }
 
@@ -399,24 +475,45 @@ template<class Arc>  void TestMinimize() {
     Minimize(&gallic_fst);
     {
       std::cout <<" printing after  minimization [in gallic]\n";
+#ifdef HAVE_OPENFST_GE_10400
+      FstPrinter<GallicArc< Arc> > fstprinter(gallic_fst, sptr, sptr, NULL, false, true, "\t");
+#else
       FstPrinter<GallicArc< Arc> > fstprinter(gallic_fst, sptr, sptr, NULL, false, true);
+#endif
       fstprinter.Print(&std::cout, "standard output");
     }
 
     printf("Converting gallic back to regular [my approach]\n");
+#ifdef HAVE_OPENFST_GE_10400
+    TrivialFactorWeightFst< GallicArc<Arc, GALLIC_LEFT>, GallicFactor<typename Arc::Label,
+        typename Arc::Weight, GALLIC_LEFT> > fwfst(gallic_fst);
+#else
     TrivialFactorWeightFst< GallicArc<Arc, STRING_LEFT>, GallicFactor<typename Arc::Label,
         typename Arc::Weight, STRING_LEFT> > fwfst(gallic_fst);
+#endif
     {
       std::cout <<" printing factor-weight FST\n";
-      FstPrinter<GallicArc<Arc> >  fstprinter(fwfst, sptr, sptr, NULL, false, true);
+#ifdef HAVE_OPENFST_GE_10400
+      FstPrinter<GallicArc< Arc> > fstprinter(fwfst, sptr, sptr, NULL, false, true, "\t");
+#else
+      FstPrinter<GallicArc< Arc> > fstprinter(fwfst, sptr, sptr, NULL, false, true);
+#endif
       fstprinter.Print(&std::cout, "standard output");
     }
 
+#ifdef HAVE_OPENFST_GE_10400
+    Map(fwfst, &ofst_star, FromGallicMapper<Arc, GALLIC_LEFT>());
+#else
     Map(fwfst, &ofst_star, FromGallicMapper<Arc, STRING_LEFT>());
+#endif
 
     {
       std::cout <<" printing after converting back to regular FST\n";
+#ifdef HAVE_OPENFST_GE_10400
+      FstPrinter<Arc> fstprinter(ofst_star, sptr, sptr, NULL, false, true, "\t");
+#else
       FstPrinter<Arc> fstprinter(ofst_star, sptr, sptr, NULL, false, true);
+#endif
       fstprinter.Print(&std::cout, "standard output");
     }
 
@@ -429,7 +526,11 @@ template<class Arc>  void TestMinimize() {
   int64 num_removed = DeleteISymbols(&ofst_star, extra_syms);
   std::cout <<" printing after removing "<<num_removed<<" instances of extra symbols\n";
   {
-     FstPrinter<Arc> fstprinter(ofst_star, sptr, sptr, NULL, false, true);
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(ofst_star, sptr, sptr, NULL, false, true, "\t");
+#else
+    FstPrinter<Arc> fstprinter(ofst_star, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
index 80d944b1b8716b9d265b0b374843b9e952c8fa28..6913d96013269680bb741816baf7972f82cc1639 100644 (file)
@@ -98,7 +98,7 @@ void Factor(const Fst<Arc> &fst, MutableFst<Arc> *ofst,
                  || state_properties[i] == (kStateArcsIn|kStateArcsOut|kStateIlabelsOut));
   vector<StateId> state_mapping(max_state+1, kNoStateId);
 
-  typedef std::tr1::unordered_map<vector<I>, Label, kaldi::VectorHasher<I> > SymbolMapType;
+  typedef unordered_map<vector<I>, Label, kaldi::VectorHasher<I> > SymbolMapType;
   SymbolMapType symbol_mapping;
   Label symbol_counter = 0;
   {
index 18d73b3f3cbf3b9b4eabc3cb599b745e862b9cd9..9416f6fa4a4cd4dda0976001fb781562cb81e2f6 100644 (file)
@@ -78,7 +78,11 @@ template<class Arc> static void TestFactor() {
 
   std::cout <<" printing before trimming\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
   // Trim resulting FST.
@@ -86,7 +90,11 @@ template<class Arc> static void TestFactor() {
 
   std::cout <<" printing after trimming\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
index bb5547d43e073b8520615c2394f71b8f32621477..b697e20a913d4f0c7bb8c01d5d03a80114ea9ca4 100644 (file)
@@ -143,7 +143,11 @@ template<class Arc>  void TestSafeDeterminizeWrapper() {  // also tests SafeDete
 
   std::cout <<" printing before trimming\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
   // Trim resulting FST.
@@ -151,7 +155,11 @@ template<class Arc>  void TestSafeDeterminizeWrapper() {  // also tests SafeDete
 
   std::cout <<" printing after trimming\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
@@ -366,7 +374,11 @@ void TestEqualAlign() {
 
 template<class Arc> void Print(const Fst<Arc> &fst, std::string message) {
   std::cout << message << "\n";
+#ifdef HAVE_OPENFST_GE_10400
+  FstPrinter<Arc> fstprinter(fst, NULL, NULL, NULL, false, true, "\t");
+#else
   FstPrinter<Arc> fstprinter(fst, NULL, NULL, NULL, false, true);
+#endif
   fstprinter.Print(&std::cout, "standard output");
 }
 
index cfcf6bfb721b70d75974ac9bed236297784f5470..bb27f0421b1b7df7ec7b09ec6a8365800d6b24b2 100644 (file)
@@ -385,8 +385,13 @@ class VectorFstTplHolder {
       // on its own line.
       os << '\n';
       bool acceptor = false, write_one = false;
+#ifdef HAVE_OPENFST_GE_10400
+      FstPrinter<Arc> printer(t, t.InputSymbols(), t.OutputSymbols(),
+                              NULL, acceptor, write_one, "\t");
+#else
       FstPrinter<Arc> printer(t, t.InputSymbols(), t.OutputSymbols(),
                               NULL, acceptor, write_one);
+#endif
       printer.Print(&os, "<unknown>");
       if (os.fail())
         KALDI_WARN << "Stream failure detected.\n";
@@ -473,7 +478,7 @@ class VectorFstTplHolder {
             else t_->SetFinal(s, w);
             break;
           case 3: // 3 columns not ok for Lattice format; it's not an acceptor.
-            ok = false; 
+            ok = false;
             break;
           case 4:
             ok = ConvertStringToInteger(col[1], &arc.nextstate) &&
@@ -501,7 +506,7 @@ class VectorFstTplHolder {
         while (d >= t_->NumStates())
           t_->AddState();
         if (!ok) {
-          KALDI_WARN << "Bad line in FST: " << line;          
+          KALDI_WARN << "Bad line in FST: " << line;
           delete t_;
           t_ = NULL;
           return false;
index af72dde0088e72aef5ab15cb104935659130a30d..a3508d5d241ff3739bc68eeae1d3c22082ccaa6b 100644 (file)
@@ -30,7 +30,11 @@ template<class Weight, class Int> void TestConvert(bool invert) {
     VectorFst<Arc> *fst = RandFst<Arc>();
     std::cout << "FST before converting to compact-arc is:\n";
     {
+#ifdef HAVE_OPENFST_GE_10400
+      FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true, "\t");
+#else
       FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true);
+#endif
       fstprinter.Print(&std::cout, "standard output");
     }
     VectorFst<CompactArc> ofst;
@@ -38,14 +42,22 @@ template<class Weight, class Int> void TestConvert(bool invert) {
 
     std::cout << "FST after converting is:\n";
     {
+#ifdef HAVE_OPENFST_GE_10400
+      FstPrinter<CompactArc> fstprinter(ofst, NULL, NULL, NULL, false, true, "\t");
+#else
       FstPrinter<CompactArc> fstprinter(ofst, NULL, NULL, NULL, false, true);
+#endif
       fstprinter.Print(&std::cout, "standard output");
     }
     VectorFst<Arc> origfst;
     ConvertLattice<Weight, Int>(ofst, &origfst, invert);
     std::cout << "FST after back conversion is:\n";
     {
+#ifdef HAVE_OPENFST_GE_10400
+      FstPrinter<Arc> fstprinter(origfst, NULL, NULL, NULL, false, true, "\t");
+#else
       FstPrinter<Arc> fstprinter(origfst, NULL, NULL, NULL, false, true);
+#endif
       fstprinter.Print(&std::cout, "standard output");
     }
     
@@ -66,7 +78,11 @@ template<class Weight, class Int> void TestShortestPath() {
       std::cout << "Testing shortest path\n";
       std::cout << "FST before converting to compact-arc is:\n";
       {
+#ifdef HAVE_OPENFST_GE_10400
+        FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true, "\t");
+#else
         FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true);
+#endif
         fstprinter.Print(&std::cout, "standard output");
       }
       VectorFst<CompactArc> cfst;
@@ -125,7 +141,7 @@ template<class Int> void TestConvert2() {
       ConvertLattice(*fst1, &fst2);
       ConvertLattice(fst2, &fst3);
 
-      assert(RandEquivalent(*fst1, fst3, 5/*paths*/, 0.01/*delta*/, kaldi::Rand()/*seed*/, 100/*path length-- max?*/));      
+      assert(RandEquivalent(*fst1, fst3, 5/*paths*/, 0.01/*delta*/, kaldi::Rand()/*seed*/, 100/*path length-- max?*/));
       delete fst1;
     }
 
@@ -136,7 +152,7 @@ template<class Int> void TestConvert2() {
       VectorFst<CArcD> cfst2;
       ConvertLattice(cfst1, &cfst2);
       ConvertLattice(cfst2, &cfst3);
-      assert(RandEquivalent(cfst1, cfst3, 5/*paths*/, 0.01/*delta*/, kaldi::Rand()/*seed*/, 100/*path length-- max?*/));            
+      assert(RandEquivalent(cfst1, cfst3, 5/*paths*/, 0.01/*delta*/, kaldi::Rand()/*seed*/, 100/*path length-- max?*/));
       delete fst1;
     }
 
@@ -188,7 +204,7 @@ template<class Int> void TestConvert2() {
       ConvertLattice(*fst1, &cfst1);
       VectorFst<ArcD> fst2;
       ConvertLattice(cfst1, &fst2);
-      assert(RandEquivalent(*fst1, fst2, 5/*paths*/, 0.01/*delta*/, kaldi::Rand()/*seed*/, 100/*path length-- max?*/));      
+      assert(RandEquivalent(*fst1, fst2, 5/*paths*/, 0.01/*delta*/, kaldi::Rand()/*seed*/, 100/*path length-- max?*/));
       delete fst1;
     }
   }
index 7bc36bba973fa8c17fccdc3f84afb4bfb5c9478b..8694267407b745e76eda5e19a2ce4146d0f1d6e2 100644 (file)
 #include "fstext/fst-test-utils.h"
 #include "fstext/fstext-utils.h"
 
-#ifdef _MSC_VER
-#include <unordered_map>
-#else
-#include <tr1/unordered_map>
-#endif
 // Just check that it compiles, for now.
 
 namespace fst
@@ -74,7 +69,11 @@ template<class Arc>  void TestPreDeterminize() {
 
   std::cout <<" printing before trimming\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
   // Trim resulting FST.
@@ -82,7 +81,11 @@ template<class Arc>  void TestPreDeterminize() {
 
   std::cout <<" printing after trimming\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
@@ -96,7 +99,11 @@ template<class Arc>  void TestPreDeterminize() {
 
   std::cout <<" printing after predeterminization\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
@@ -112,7 +119,11 @@ template<class Arc>  void TestPreDeterminize() {
 
   std::cout <<" printing after epsilon removal\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
@@ -122,14 +133,22 @@ template<class Arc>  void TestPreDeterminize() {
   Determinize(*fst, &ofst, opts);
   std::cout <<" printing after determinization\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(ofst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(ofst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
   int64 num_removed = DeleteISymbols(&ofst, extra_syms);
   std::cout <<" printing after removing "<<num_removed<<" instances of extra symbols\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(ofst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(ofst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
@@ -181,7 +200,11 @@ template<class Arc>  void TestAddSelfLoops() {
   }
   std::cout <<" printing before adding self-loops\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, ilabels, olabels, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, ilabels, olabels, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
@@ -200,7 +223,11 @@ template<class Arc>  void TestAddSelfLoops() {
 
   std::cout <<" printing after adding self-loops\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, ilabels, olabels, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, ilabels, olabels, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
index 0af82877006a6f68b440e5c28082167a0675e446..61aa732f3a78070a8eeb4c59306021073a7352c2 100644 (file)
@@ -118,7 +118,7 @@ template<class Arc> class PruneSpecialClass {
   // priority costs in ProcessState().
   inline OutputStateId GetOutputStateId(InputStateId istate,
                                         const Weight &weight) {
-    typedef typename std::tr1::unordered_map<InputStateId, OutputStateId>::iterator IterType;
+    typedef typename unordered_map<InputStateId, OutputStateId>::iterator IterType;
     IterType iter = state_map_.find(istate);
     if (iter == state_map_.end())
       return ProcessState(istate, weight);
@@ -150,7 +150,7 @@ template<class Arc> class PruneSpecialClass {
   Weight beam_;
   size_t max_states_;
 
-  std::tr1::unordered_map<InputStateId, OutputStateId> state_map_;
+  unordered_map<InputStateId, OutputStateId> state_map_;
   std::priority_queue<Task> queue_;
   Weight best_weight_; // if not Zero(), then we have now processed a successful path
                        // through ifst_, and this is the weight.
index 91627914d8d0dc682ea3408f80616016a922602b..e879a7593acdc443158392ad2b08bad1c98f4c7a 100644 (file)
@@ -37,7 +37,11 @@ static void TestPruneSpecial() {
   float beam = 0.55;
 
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*ifst, NULL, NULL, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*ifst, NULL, NULL, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
     std::cout << endl;
   }
@@ -46,7 +50,11 @@ static void TestPruneSpecial() {
   VectorFst<Arc> ofst1;
   PruneSpecial<StdArc>(*ifst, &ofst1, beam);
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(ofst1, NULL, NULL, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(ofst1, NULL, NULL, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
     std::cout << endl;
   }
@@ -55,7 +63,11 @@ static void TestPruneSpecial() {
   VectorFst<Arc> ofst2;
   Prune(*ifst, &ofst2, beam);
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(ofst2, NULL, NULL, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(ofst2, NULL, NULL, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
     std::cout << endl;
   }
index 7e2394e27355c5e5ce5c617f0de57694473c8ba7..7f8ccbe92db81937000c3d9de385ab45c709d999 100644 (file)
@@ -37,7 +37,11 @@ static void TestPushSpecial() {
   VectorFst<Arc> *fst = RandFst<StdArc>();
 
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
   
@@ -55,7 +59,11 @@ static void TestPushSpecial() {
 
 
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(fst_copy, NULL, NULL, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(fst_copy, NULL, NULL, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
   KALDI_LOG << "Min value is " << min.Value() << ", max value is " << max.Value();
index 933ac27be2034bffb5ee112246d135a1782c8254..676ba82025cac40c9f58c878621a0993794155ac 100644 (file)
@@ -82,7 +82,11 @@ template<class Arc> static void TestRemoveEpsLocal() {
 
   std::cout <<" printing after trimming\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
@@ -95,7 +99,11 @@ template<class Arc> static void TestRemoveEpsLocal() {
 
   {
     std::cout << "copy1 = \n";
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(fst_copy1, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(fst_copy1, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
@@ -134,13 +142,17 @@ static void TestRemoveEpsLocalSpecial() {
         }
       }
     }
-  }        
+  }
 #ifndef _MSC_VER
   assert(IsStochasticFst(*logfst, kDelta*10));
 #endif
   {
     std::cout << "logfst = \n";
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<LogArc> fstprinter(*logfst, NULL, NULL, NULL, false, true, "\t");
+#else
     FstPrinter<LogArc> fstprinter(*logfst, NULL, NULL, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
@@ -155,7 +167,11 @@ static void TestRemoveEpsLocalSpecial() {
 
   {
     std::cout << "logfst2 = \n";
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<LogArc> fstprinter(logfst2, NULL, NULL, NULL, false, true, "\t");
+#else
     FstPrinter<LogArc> fstprinter(logfst2, NULL, NULL, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
   if (ApproxEqual(ShortestDistance(*logfst), ShortestDistance(logfst2))) {
index 4f131a1f9db3e9cf840547e5532b283378421307..70d3439b07b1366f1bc7f6460e4ac6f34cae81f2 100644 (file)
@@ -32,7 +32,11 @@ template<class Arc> void TestComputeTotalWeight() {
 
   std::cout <<" printing FST at start\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
@@ -64,7 +68,11 @@ void TestRescaleToStochastic() {
 
   std::cout <<" printing FST at start\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
 
   }
index db793bbb8a53b74916bbb4e8b14a9ddf21b165e4..b9e8a8644545eabe2551a13f2ff1f0ade999c5b4 100644 (file)
@@ -63,13 +63,21 @@ template<class Arc>  void TestTableMatcher(bool connect, bool left) {
 
   std::cout <<"Table-Composed FST\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(composed, NULL, NULL, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(composed, NULL, NULL, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
   std::cout <<" Baseline-Composed FST\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(composed_baseline, NULL, NULL, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(composed_baseline, NULL, NULL, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
@@ -78,7 +86,11 @@ template<class Arc>  void TestTableMatcher(bool connect, bool left) {
     Difference(composed, composed_baseline, &diff1);
     std::cout <<" Diff1 (composed - baseline) \n";
     {
-      FstPrinter<Arc> fstprinter(diff1, NULL, NULL, NULL, false, true);
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(diff1, NULL, NULL, NULL, false, true, "\t");
+#else
+    FstPrinter<Arc> fstprinter(diff1, NULL, NULL, NULL, false, true);
+#endif
       fstprinter.Print(&std::cout, "standard output");
     }
 
@@ -87,7 +99,11 @@ template<class Arc>  void TestTableMatcher(bool connect, bool left) {
     Difference(composed_baseline, composed, &diff2);
     std::cout <<" Diff2 (baseline - composed) \n";
     {
-      FstPrinter<Arc> fstprinter(diff2, NULL, NULL, NULL, false, true);
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(diff2, NULL, NULL, NULL, false, true, "\t");
+#else
+    FstPrinter<Arc> fstprinter(diff2, NULL, NULL, NULL, false, true);
+#endif
       fstprinter.Print(&std::cout, "standard output");
     }
 
@@ -148,7 +164,11 @@ template<class Arc>  void TestTableMatcherCacheLeft(bool connect) {
       Difference(composed, composed_baseline, &diff1);
       std::cout <<" Diff1 (composed - baseline) \n";
       {
+#ifdef HAVE_OPENFST_GE_10400
+        FstPrinter<Arc> fstprinter(diff1, NULL, NULL, NULL, false, true, "\t");
+#else
         FstPrinter<Arc> fstprinter(diff1, NULL, NULL, NULL, false, true);
+#endif
         fstprinter.Print(&std::cout, "standard output");
       }
 
@@ -157,7 +177,11 @@ template<class Arc>  void TestTableMatcherCacheLeft(bool connect) {
       Difference(composed_baseline, composed, &diff2);
       std::cout <<" Diff2 (baseline - composed) \n";
       {
+#ifdef HAVE_OPENFST_GE_10400
+        FstPrinter<Arc> fstprinter(diff2, NULL, NULL, NULL, false, true, "\t");
+#else
         FstPrinter<Arc> fstprinter(diff2, NULL, NULL, NULL, false, true);
+#endif
         fstprinter.Print(&std::cout, "standard output");
       }
 
@@ -218,7 +242,11 @@ template<class Arc>  void TestTableMatcherCacheRight(bool connect) {
       Difference(composed, composed_baseline, &diff1);
       std::cout <<" Diff1 (composed - baseline) \n";
       {
+#ifdef HAVE_OPENFST_GE_10400
+        FstPrinter<Arc> fstprinter(diff1, NULL, NULL, NULL, false, true, "\t");
+#else
         FstPrinter<Arc> fstprinter(diff1, NULL, NULL, NULL, false, true);
+#endif
         fstprinter.Print(&std::cout, "standard output");
       }
 
@@ -227,7 +255,11 @@ template<class Arc>  void TestTableMatcherCacheRight(bool connect) {
       Difference(composed_baseline, composed, &diff2);
       std::cout <<" Diff2 (baseline - composed) \n";
       {
+#ifdef HAVE_OPENFST_GE_10400
+        FstPrinter<Arc> fstprinter(diff2, NULL, NULL, NULL, false, true, "\t");
+#else
         FstPrinter<Arc> fstprinter(diff2, NULL, NULL, NULL, false, true);
+#endif
         fstprinter.Print(&std::cout, "standard output");
       }
 
index 32678244fb4621a40b373b08edd94bfa82f06053..af3f4a3de89cf6c7206a045d64b32d91d552d719 100644 (file)
@@ -70,7 +70,11 @@ template<class Arc>  void TestFactor() {
 
   std::cout <<" printing before trimming\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
   // Trim resulting FST.
@@ -78,7 +82,11 @@ template<class Arc>  void TestFactor() {
 
   std::cout <<" printing after trimming\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
@@ -89,7 +97,11 @@ template<class Arc>  void TestFactor() {
 
   std::cout <<" printing after predeterminization\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
 
@@ -105,7 +117,11 @@ template<class Arc>  void TestFactor() {
 
   std::cout <<" printing after double-epsilon removal\n";
   {
+#ifdef HAVE_OPENFST_GE_10400
+    FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true, "\t");
+#else
     FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL, false, true);
+#endif
     fstprinter.Print(&std::cout, "standard output");
   }
   VectorFst<Arc> ofst_star;
@@ -124,7 +140,11 @@ template<class Arc>  void TestFactor() {
 
     {
       std::cout <<" printing gallic FST\n";
+#ifdef HAVE_OPENFST_GE_10400
+      FstPrinter<GallicArc<Arc> >  fstprinter(gallic_fst, sptr, sptr, NULL, false, true, "\t");
+#else
       FstPrinter<GallicArc<Arc> >  fstprinter(gallic_fst, sptr, sptr, NULL, false, true);
+#endif
       fstprinter.Print(&std::cout, "standard output");
     }
 
@@ -132,25 +152,46 @@ template<class Arc>  void TestFactor() {
     // Map(ofst_star, &gallic_fst, ToGallicMapper<Arc, STRING_LEFT>());
     
     printf("Converting gallic back to regular\n");
+#ifdef HAVE_OPENFST_GE_10400
+    TrivialFactorWeightFst< GallicArc<Arc, GALLIC_LEFT>, GallicFactor<typename Arc::Label,
+        typename Arc::Weight, GALLIC_LEFT> > fwfst(gallic_fst);
+#else
     TrivialFactorWeightFst< GallicArc<Arc, STRING_LEFT>, GallicFactor<typename Arc::Label,
         typename Arc::Weight, STRING_LEFT> > fwfst(gallic_fst);
+#endif
     {
       std::cout <<" printing factor-weight FST\n";
+#ifdef HAVE_OPENFST_GE_10400
+      FstPrinter<GallicArc<Arc> >  fstprinter(fwfst, sptr, sptr, NULL, false, true, "\t");
+#else
       FstPrinter<GallicArc<Arc> >  fstprinter(fwfst, sptr, sptr, NULL, false, true);
+#endif
       fstprinter.Print(&std::cout, "standard output");
     }
 
+#ifdef HAVE_OPENFST_GE_10400
+    Map(fwfst, &ofst_star, FromGallicMapper<Arc, GALLIC_LEFT>());
+#else
     Map(fwfst, &ofst_star, FromGallicMapper<Arc, STRING_LEFT>());
-    
+#endif
+
     {
       std::cout <<" printing after converting back to regular FST\n";
+#ifdef HAVE_OPENFST_GE_10400
+      FstPrinter<Arc> fstprinter(ofst_star, sptr, sptr, NULL, false, true, "\t");
+#else
       FstPrinter<Arc> fstprinter(ofst_star, sptr, sptr, NULL, false, true);
+#endif
       fstprinter.Print(&std::cout, "standard output");
     }
 
 
     VectorFst<GallicArc<Arc> > new_gallic_fst;
+#ifdef HAVE_OPENFST_GE_10400
+    Map(ofst_star, &new_gallic_fst, ToGallicMapper<Arc, GALLIC_LEFT>());
+#else
     Map(ofst_star, &new_gallic_fst, ToGallicMapper<Arc, STRING_LEFT>());
+#endif
 
     assert(RandEquivalent(gallic_fst, new_gallic_fst, 5/*paths*/, 0.01/*delta*/, kaldi::Rand()/*seed*/, 100/*path length-- max?*/));
 
index c92bc313d3dfe8ed43eedfe3a3594b792ca0cec5..109ba75ce1004e5a73914e77b48090b332e6a966 100644 (file)
 // This has the advantage that it always works, for any input (also I just
 // prefer this approach).
 
-
-
-#include <algorithm>
 #ifdef _MSC_VER
 #include <unordered_map>
+using std::unordered_map;
+#elif __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
+#include <unordered_map>
+using std::unordered_map;
 #else
 #include <tr1/unordered_map>
-#endif
 using std::tr1::unordered_map;
-#include <fst/slist.h>
+#endif
+
+
+#include <algorithm>
 #include <string>
 #include <utility>
 #include <vector>
@@ -114,6 +117,11 @@ class TrivialFactorWeightFstImpl
   typedef typename A::StateId StateId;
   typedef F FactorIterator;
 
+#ifdef HAVE_OPENFST_GE_10400
+  typedef DefaultCacheStore<A> Store;
+  typedef typename Store::State State;
+#endif
+
   struct Element {
     Element() {}
 
@@ -336,7 +344,12 @@ class TrivialFactorWeightFst : public ImplToFst< TrivialFactorWeightFstImpl<A, F
   typedef A Arc;
   typedef typename A::Weight Weight;
   typedef typename A::StateId StateId;
+#ifdef HAVE_OPENFST_GE_10400
+  typedef DefaultCacheStore<Arc> Store;
+  typedef typename Store::State State;
+#else
   typedef CacheState<A> State;
+#endif
   typedef TrivialFactorWeightFstImpl<A, F> Impl;
 
   TrivialFactorWeightFst(const Fst<A> &fst)
index 8ae7a5aeff8b8aa0b3d1184aa814c6750e77601c..eafdade0818a291a1a8b6eae9cdd6750ba0d1c2c 100644 (file)
@@ -150,8 +150,8 @@ int main(int argc, char *argv[]) {
     // to do epsilon removal after composition with the keyword FST. They have
     // to traverse the resulting FST.
     int32 label_count = 1;
-    std::tr1::unordered_map<uint64, uint32> label_encoder;
-    std::tr1::unordered_map<uint32, uint64> label_decoder;
+    unordered_map<uint64, uint32> label_encoder;
+    unordered_map<uint32, uint64> label_decoder;
     for (StateIterator<KwsLexicographicFst> siter(index); !siter.Done(); siter.Next()) {
       StateId state_id = siter.Value();
       for (MutableArcIterator<KwsLexicographicFst> 
index 12317af212f9ae5d27dc9db7d8cea34f3c1f3db6..d5f22454017e7e624a6fac454d387b62295fe525 100644 (file)
@@ -62,7 +62,11 @@ template<class Arc> void TestDeterminizeLatticePruned() {
     
     std::cout << "FST before lattice-determinizing is:\n";
     {
+#ifdef HAVE_OPENFST_GE_10400
+      FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true, "\t");
+#else
       FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true);
+#endif
       fstprinter.Print(&std::cout, "standard output");
     }
     VectorFst<Arc> det_fst;
@@ -75,7 +79,11 @@ template<class Arc> void TestDeterminizeLatticePruned() {
 
       std::cout << "FST after lattice-determinizing is:\n";
       {
+#ifdef HAVE_OPENFST_GE_10400
+        FstPrinter<Arc> fstprinter(det_fst, NULL, NULL, NULL, false, true, "\t");
+#else
         FstPrinter<Arc> fstprinter(det_fst, NULL, NULL, NULL, false, true);
+#endif
         fstprinter.Print(&std::cout, "standard output");
       }
       KALDI_ASSERT(det_fst.Properties(kIDeterministic, true) & kIDeterministic);
@@ -92,14 +100,22 @@ template<class Arc> void TestDeterminizeLatticePruned() {
       ConvertLattice<Weight, Int>(pruned_fst, &compact_pruned_fst, false);
       std::cout << "Compact pruned FST is:\n";
       {
+#ifdef HAVE_OPENFST_GE_10400
+        FstPrinter<CompactArc> fstprinter(compact_pruned_fst, NULL, NULL, NULL, false, true, "\t");
+#else
         FstPrinter<CompactArc> fstprinter(compact_pruned_fst, NULL, NULL, NULL, false, true);
+#endif
         fstprinter.Print(&std::cout, "standard output");
       }
       ConvertLattice<Weight, Int>(det_fst, &compact_pruned_det_fst, false);
       
       std::cout << "Compact version of determinized FST is:\n";
       {
+#ifdef HAVE_OPENFST_GE_10400
+        FstPrinter<CompactArc> fstprinter(compact_pruned_det_fst, NULL, NULL, NULL, false, true, "\t");
+#else
         FstPrinter<CompactArc> fstprinter(compact_pruned_det_fst, NULL, NULL, NULL, false, true);
+#endif
         fstprinter.Print(&std::cout, "standard output");
       }
 
@@ -122,14 +138,22 @@ template<class Arc> void TestDeterminizeLatticePruned2() {
     VectorFst<Arc> *fst = RandPairFst<Arc>(opts);
     std::cout << "FST before lattice-determinizing is:\n";
     {
+#ifdef HAVE_OPENFST_GE_10400
+      FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true, "\t");
+#else
       FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true);
+#endif
       fstprinter.Print(&std::cout, "standard output");
     }
     VectorFst<Arc> ofst;
     DeterminizeLatticePruned<Weight>(*fst, 10.0, &ofst);
     std::cout << "FST after lattice-determinizing is:\n";
     {
+#ifdef HAVE_OPENFST_GE_10400
+      FstPrinter<Arc> fstprinter(ofst, NULL, NULL, NULL, false, true, "\t");
+#else
       FstPrinter<Arc> fstprinter(ofst, NULL, NULL, NULL, false, true);
+#endif
       fstprinter.Print(&std::cout, "standard output");
     }
     delete fst;
index 3c9624f8c05ef447d6620fcddb7f99f5bb52c827..e77afc79f49d15bde00de43a104f13aa0c121469 100644 (file)
 
 #ifdef _MSC_VER
 #include <unordered_map>
+using std::unordered_map;
+#elif __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
+#include <unordered_map>
+using std::unordered_map;
 #else
 #include <tr1/unordered_map>
+using std::tr1::unordered_map;
 #endif
+
 #include <vector>
-using std::tr1::unordered_map;
 #include <climits>
 #include "fstext/determinize-lattice.h" // for LatticeStringRepository
 #include "fstext/fstext-utils.h"
index 6dfbcc5f842083931f17005af43e176a8804f7e7..273e4eeb10f9a48e8b9af2454efcc14da7d07b7d 100644 (file)
@@ -62,7 +62,7 @@ Lattice* ConvertToLattice(Lattice *ifst) {
 bool WriteCompactLattice(std::ostream &os, bool binary,
                          const CompactLattice &t) {
   if (binary) {
-    fst::FstWriteOptions opts;    
+    fst::FstWriteOptions opts;
     // Leave all the options default.  Normally these lattices wouldn't have any
     // osymbols/isymbols so no point directing it not to write them (who knows what
     // we'd want to if we had them).
@@ -75,9 +75,15 @@ bool WriteCompactLattice(std::ostream &os, bool binary,
     // on its own line.
     os << '\n';
     bool acceptor = true, write_one = false;
+#ifdef HAVE_OPENFST_GE_10400
+    fst::FstPrinter<CompactLatticeArc> printer(t, t.InputSymbols(),
+                                               t.OutputSymbols(),
+                                               NULL, acceptor, write_one, "\t");
+#else
     fst::FstPrinter<CompactLatticeArc> printer(t, t.InputSymbols(),
                                                t.OutputSymbols(),
                                                NULL, acceptor, write_one);
+#endif
     printer.Print(&os, "<unknown>");
     if (os.fail())
       KALDI_WARN << "Stream failure detected.";
@@ -383,11 +389,11 @@ bool CompactLatticeHolder::Read(std::istream &is) {
   } else {
     return ReadCompactLattice(is, true, &t_);
   }
-}     
+}
 
 bool WriteLattice(std::ostream &os, bool binary, const Lattice &t) {
   if (binary) {
-    fst::FstWriteOptions opts;    
+    fst::FstWriteOptions opts;
     // Leave all the options default.  Normally these lattices wouldn't have any
     // osymbols/isymbols so no point directing it not to write them (who knows what
     // we'd want to if we had them).
@@ -400,9 +406,15 @@ bool WriteLattice(std::ostream &os, bool binary, const Lattice &t) {
     // on its own line.
     os << '\n';
     bool acceptor = false, write_one = false;
+#ifdef HAVE_OPENFST_GE_10400
+    fst::FstPrinter<LatticeArc> printer(t, t.InputSymbols(),
+                                        t.OutputSymbols(),
+                                        NULL, acceptor, write_one, "\t");
+#else
     fst::FstPrinter<LatticeArc> printer(t, t.InputSymbols(),
                                         t.OutputSymbols(),
                                         NULL, acceptor, write_one);
+#endif
     printer.Print(&os, "<unknown>");
     if (os.fail())
       KALDI_WARN << "Stream failure detected.";
index 9251b63430e6f563c52247fcf9264bc1ee9045df..683ee0a980e4aece7d31fa3b2a3e68a3909ed4fe 100644 (file)
@@ -32,10 +32,9 @@ bool CompareInterval(const Interval &i1,
 
 }
 
-bool ClusterLattice(CompactLattice *clat, 
+bool ClusterLattice(CompactLattice *clat,
                     const vector<int32> &state_times) {
   using namespace fst;
-  using std::tr1::unordered_map;
   typedef CompactLattice::StateId StateId;
 
   // Hashmap to store the cluster heads.
index 0eb634f43c4355cd3f82073d2242119a510f346e..e1f99bcb31fcadb731f80347e36d2ee402380369 100644 (file)
@@ -90,13 +90,23 @@ void TestPushCompactLatticeWeights() {
     }
     if (!ApproxEqual(sum, LatticeWeight::One())) {
       {
+#ifdef HAVE_OPENFST_GE_10400
+        fst::FstPrinter<CompactLatticeArc> printer(clat2, NULL, NULL,
+                                                   NULL, true, true, "\t");
+#else
         fst::FstPrinter<CompactLatticeArc> printer(clat2, NULL, NULL,
                                                    NULL, true, true);
+#endif
         printer.Print(&std::cerr, "<unknown>");
       }
       {
-        fst::FstPrinter<CompactLatticeArc> printer(*clat, NULL, NULL, 
+#ifdef HAVE_OPENFST_GE_10400
+        fst::FstPrinter<CompactLatticeArc> printer(*clat, NULL, NULL,
+                                                   NULL, true, true, "\t");
+#else
+        fst::FstPrinter<CompactLatticeArc> printer(*clat, NULL, NULL,
                                                    NULL, true, true);
+#endif
         printer.Print(&std::cerr, "<unknown>");
       }
       KALDI_ERR << "Bad lattice being pushed.";
index 5205537d9888d78b878a903c805f792db0efeb80..132cd87bad0fc1d641043bae5975111cb22bcdc0 100644 (file)
 
 #ifdef _MSC_VER
 #include <unordered_map>
+using std::unordered_map;
+#elif __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
+#include <unordered_map>
+using std::unordered_map;
 #else
 #include <tr1/unordered_map>
-#endif
 using std::tr1::unordered_map;
+#endif
 
 #ifndef HAVE_IRSTLM
 #else
index 66eb529012b31e35a9392c5843431244aa2bd397..4d5a031d0c91cfcd82bc5595254813e557b88bf2 100644 (file)
@@ -26,15 +26,16 @@ CC = $(CXX)
 RANLIB = ranlib
 AR = ar
 
-# On Mac OS 10.10, g++ is actually clang in disguise which by default uses the
-# new c++ standard library libc++. Since openfst-1.3 uses stuff from the tr1
-# namespace, we need to tell clang to use libstdc++ instead. We are also adding
-# the no-mismatched-tags flag to suppress the rather pointless warnings,
-# reported by clang by default, that are perfectly valid per spec.
+# Add no-mismatched-tags flag to suppress the annoying clang warnings
+# that are perfectly valid per spec.
 COMPILER = $(shell $(CXX) -v 2>&1 )
 ifeq ($(findstring clang,$(COMPILER)),clang)
-       CXXFLAGS += -stdlib=libstdc++ -Wno-mismatched-tags
-       LDFLAGS += -stdlib=libstdc++
+  CXXFLAGS += -Wno-mismatched-tags
+  # Link with libstdc++ if we are building against OpenFst < 1.4
+  ifneq ("$(OPENFST_GE_10400)","1")
+    CXXFLAGS += -stdlib=libstdc++
+    LDFLAGS += -stdlib=libstdc++
+  endif
 endif
 
 # We need to tell recent versions of g++ to allow vector conversions without
index 71229063801aa2464c83730051a3a1c584ec9ce9..938c38eb9ef230758c98aa9e65132e469b254cc3 100644 (file)
@@ -5,7 +5,7 @@ $(error FSTROOT not defined.)
 endif
 
 CXXFLAGS += -msse -msse2 -Wall -I.. \
-         -pthread \
+      -pthread \
       -DKALDI_DOUBLEPRECISION=0 -DHAVE_POSIX_MEMALIGN \
       -Wno-sign-compare -Winit-self \
       -DHAVE_EXECINFO_H=1 -DHAVE_CXXABI_H \
@@ -26,16 +26,19 @@ CC = $(CXX)
 RANLIB = ranlib
 AR = ar
 
-# On Mac OS 10.9, g++ is actually clang in disguise which by default uses the
-# new c++ standard library libc++. Since openfst uses stuff from the tr1
-# namespace, we need to tell clang to use libstdc++ instead.
+# Add no-mismatched-tags flag to suppress the annoying clang warnings
+# that are perfectly valid per spec.
 COMPILER = $(shell $(CXX) -v 2>&1 )
 ifeq ($(findstring clang,$(COMPILER)),clang)
-       CXXFLAGS += -stdlib=libstdc++
-       LDFLAGS += -stdlib=libstdc++
+  CXXFLAGS += -Wno-mismatched-tags
+  # Link with libstdc++ if we are building against OpenFst < 1.4
+  ifneq ("$(OPENFST_GE_10400)","1")
+    CXXFLAGS += -stdlib=libstdc++
+    LDFLAGS += -stdlib=libstdc++
+  endif
 endif
 
-# We need to tell recent versions of g++ to allow vector conversions without 
+# We need to tell recent versions of g++ to allow vector conversions without
 # an explicit cast provided the vectors are of the same size.
 ifeq ($(findstring GCC,$(COMPILER)),GCC)
        CXXFLAGS += -flax-vector-conversions -Wno-unused-local-typedefs
index 3a10d2c3d7b1786d925edffaa42c4afd607a335d..35b695d690f26a7fea37db571ea09d5658174845 100644 (file)
   }
 #elif defined(HAVE_CLAPACK)
   #ifdef __APPLE__
+    #ifndef __has_extension
+    #define __has_extension(x) 0
+    #endif
+    #define vImage_Utilities_h
+    #define vImage_CVUtilities_h
     #include <Accelerate/Accelerate.h>
     typedef __CLPK_integer          integer;
     typedef __CLPK_logical          logical;
index 2da97c4986cd13b7ec6be1c1c592698212c9aae9..bae6573d7b2f5094d53a8eed623b1fa958b9a873 100644 (file)
 
 /** @brief Relabels neural network egs with the read pdf-id alignments
 */
-#include<sstream>
+
+#include <sstream>
+
 #ifdef _MSC_VER
 #include <unordered_map>
+using std::unordered_map;
+#elif __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
+#include <unordered_map>
+using std::unordered_map;
 #else
 #include <tr1/unordered_map>
-#endif
 using std::tr1::unordered_map;
+#endif
 
 #include "base/kaldi-common.h"
 #include "util/common-utils.h"
index ccdc7c3eddf3bdcd6e44f13ead2098dfdef426ed..c403a3eeff5a01b92265a9871b317ca39a0728ca 100644 (file)
@@ -85,7 +85,7 @@ OnlineFasterDecoder::MakeLattice(const Token *start,
 
 
 void OnlineFasterDecoder::UpdateImmortalToken() {
-  std::tr1::unordered_set<Token*> emitting;
+  unordered_set<Token*> emitting;
   for (const Elem *e = toks_.GetList(); e != NULL; e = e->tail) {
     Token* tok = e->val;
     while (tok->arc_.ilabel == 0) //deal with non-emitting ones ...
@@ -101,8 +101,8 @@ void OnlineFasterDecoder::UpdateImmortalToken() {
     }
     if (emitting.size() == 0)
       break;
-    std::tr1::unordered_set<Token*> prev_emitting;
-    std::tr1::unordered_set<Token*>::iterator it;
+    unordered_set<Token*> prev_emitting;
+    unordered_set<Token*>::iterator it;
     for (it = emitting.begin(); it != emitting.end(); ++it) {
       Token* tok = *it;
       Token* prev_token = tok->prev_;
index 2e7e5751874285195af5f7a2cc404ab9b6dfe697..adfd836202018b9990edb14b75c64efc57009602 100644 (file)
 #ifndef KALDI_ONLINE_ONLINE_FASTER_DECODER_H_
 #define KALDI_ONLINE_ONLINE_FASTER_DECODER_H_
 
-#ifdef _MSC_VER
-#include <unordered_set>
-#else
-#include <tr1/unordered_set>
-#endif
-using std::tr1::unordered_set;
-
+#include "util/stl-utils.h"
 #include "decoder/faster-decoder.h"
 #include "hmm/transition-model.h"
 
index 7911782b6b5630c16f2c8f7509ade54782abc929..098f29400bd2fb01003267c945f9f71b48aa18f3 100644 (file)
@@ -88,8 +88,9 @@ class OnlineSpeexEncoder {
   private:
     int32 speex_frame_size_;  // in bytes, will be different according to the quality
     int32 speex_encoded_frame_size_;  // in samples, typically 320 in wideband mode, 16kHz
-
+#ifdef HAVE_SPEEX
     void *speex_state_;  // Holds the state of the speex encoder
+#endif
     SPEEXBITS speex_bits_;
 
     Vector<BaseFloat> waveform_remainder_;      // Holds the waveform that have not been processed
@@ -121,7 +122,9 @@ class OnlineSpeexDecoder {
     int32 speex_frame_size_;  // in bytes, will be different according to the quality
     int32 speex_decoded_frame_size_;  // in samples, typically 320 in wideband mode, 16kHz
 
+#ifdef HAVE_SPEEX
     void *speex_state_;  // Holds the state of the speex decoder
+#endif
     SPEEXBITS speex_bits_;
 
 
diff --git a/src/util/basic-filebuf.h b/src/util/basic-filebuf.h
new file mode 100644 (file)
index 0000000..35a0833
--- /dev/null
@@ -0,0 +1,1065 @@
+///////////////////////////////////////////////////////////////////////////////
+// This is a modified version of the std::basic_filebuf from libc++
+// (http://libcxx.llvm.org/).
+// It allows one to create basic_filebuf from an existing FILE* handle or file
+// descriptor.
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source License licenses. See LICENSE.TXT for details (included at the
+// bottom).
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BASIC_FILEBUF_H
+#define BASIC_FILEBUF_H
+
+///////////////////////////////////////////////////////////////////////////////
+#include <fstream>
+#include <cstdio>
+#include <cstring>
+
+///////////////////////////////////////////////////////////////////////////////
+namespace kaldi
+{
+
+///////////////////////////////////////////////////////////////////////////////
+template <typename CharT, typename Traits = std::char_traits<CharT> >
+class basic_filebuf : public std::basic_streambuf<CharT, Traits>
+{
+public:
+    typedef CharT                            char_type;
+    typedef Traits                           traits_type;
+    typedef typename traits_type::int_type   int_type;
+    typedef typename traits_type::pos_type   pos_type;
+    typedef typename traits_type::off_type   off_type;
+    typedef typename traits_type::state_type state_type;
+
+    basic_filebuf();
+    basic_filebuf(basic_filebuf&& rhs);
+    virtual ~basic_filebuf();
+
+    basic_filebuf& operator=(basic_filebuf&& rhs);
+    void swap(basic_filebuf& rhs);
+
+    bool is_open() const;
+    basic_filebuf* open(const char* s, std::ios_base::openmode mode);
+    basic_filebuf* open(const std::string& s, std::ios_base::openmode mode);
+    basic_filebuf* open(int fd, std::ios_base::openmode mode);
+    basic_filebuf* open(FILE* f, std::ios_base::openmode mode);
+    basic_filebuf* close();
+
+    FILE* file() { return this->_M_file; }
+    int fd() { return fileno(this->_M_file); }
+
+protected:
+    int_type underflow() override;
+    int_type pbackfail(int_type c = traits_type::eof()) override;
+    int_type overflow (int_type c = traits_type::eof()) override;
+    std::basic_streambuf<char_type, traits_type>* setbuf(char_type* s, std::streamsize n) override;
+    pos_type seekoff(off_type off, std::ios_base::seekdir way,
+                     std::ios_base::openmode wch = std::ios_base::in | std::ios_base::out) override;
+    pos_type seekpos(pos_type sp,
+                     std::ios_base::openmode wch = std::ios_base::in | std::ios_base::out) override;
+    int sync() override;
+    void imbue(const std::locale& loc) override;
+
+protected:
+    char*       _M_extbuf;
+    const char* _M_extbufnext;
+    const char* _M_extbufend;
+    char _M_extbuf_min[8];
+    size_t _M_ebs;
+    char_type* _M_intbuf;
+    size_t _M_ibs;
+    FILE* _M_file;
+    const std::codecvt<char_type, char, state_type>* _M_cv;
+    state_type _M_st;
+    state_type _M_st_last;
+    std::ios_base::openmode _M_om;
+    std::ios_base::openmode _M_cm;
+    bool _M_owns_eb;
+    bool _M_owns_ib;
+    bool _M_always_noconv;
+
+    const char* _M_get_mode(std::ios_base::openmode mode);
+    bool _M_read_mode();
+    void _M_write_mode();
+};
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+basic_filebuf<CharT, Traits>::basic_filebuf()
+    : _M_extbuf(nullptr),
+      _M_extbufnext(nullptr),
+      _M_extbufend(nullptr),
+      _M_ebs(0),
+      _M_intbuf(nullptr),
+      _M_ibs(0),
+      _M_file(nullptr),
+      _M_cv(nullptr),
+      _M_st(),
+      _M_st_last(),
+      _M_om(std::ios_base::openmode(0)),
+      _M_cm(std::ios_base::openmode(0)),
+      _M_owns_eb(false),
+      _M_owns_ib(false),
+      _M_always_noconv(false)
+{
+    if (std::has_facet<std::codecvt<char_type, char, state_type> >(this->getloc()))
+    {
+        _M_cv = &std::use_facet<std::codecvt<char_type, char, state_type> >(this->getloc());
+        _M_always_noconv = _M_cv->always_noconv();
+    }
+    setbuf(0, 4096);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+basic_filebuf<CharT, Traits>::basic_filebuf(basic_filebuf&& rhs)
+    : std::basic_streambuf<CharT, Traits>(rhs)
+{
+    if (rhs._M_extbuf == rhs._M_extbuf_min)
+    {
+        _M_extbuf = _M_extbuf_min;
+        _M_extbufnext = _M_extbuf + (rhs._M_extbufnext - rhs._M_extbuf);
+        _M_extbufend = _M_extbuf + (rhs._M_extbufend - rhs._M_extbuf);
+    }
+    else
+    {
+        _M_extbuf = rhs._M_extbuf;
+        _M_extbufnext = rhs._M_extbufnext;
+        _M_extbufend = rhs._M_extbufend;
+    }
+    _M_ebs = rhs._M_ebs;
+    _M_intbuf = rhs._M_intbuf;
+    _M_ibs = rhs._M_ibs;
+    _M_file = rhs._M_file;
+    _M_cv = rhs._M_cv;
+    _M_st = rhs._M_st;
+    _M_st_last = rhs._M_st_last;
+    _M_om = rhs._M_om;
+    _M_cm = rhs._M_cm;
+    _M_owns_eb = rhs._M_owns_eb;
+    _M_owns_ib = rhs._M_owns_ib;
+    _M_always_noconv = rhs._M_always_noconv;
+    if (rhs.pbase())
+    {
+        if (rhs.pbase() == rhs._M_intbuf)
+            this->setp(_M_intbuf, _M_intbuf + (rhs. epptr() - rhs.pbase()));
+        else
+            this->setp((char_type*)_M_extbuf,
+                       (char_type*)_M_extbuf + (rhs. epptr() - rhs.pbase()));
+        this->pbump(rhs. pptr() - rhs.pbase());
+    }
+    else if (rhs.eback())
+    {
+        if (rhs.eback() == rhs._M_intbuf)
+            this->setg(_M_intbuf, _M_intbuf + (rhs.gptr() - rhs.eback()),
+                                  _M_intbuf + (rhs.egptr() - rhs.eback()));
+        else
+            this->setg((char_type*)_M_extbuf,
+                       (char_type*)_M_extbuf + (rhs.gptr() - rhs.eback()),
+                       (char_type*)_M_extbuf + (rhs.egptr() - rhs.eback()));
+    }
+    rhs._M_extbuf = nullptr;
+    rhs._M_extbufnext = nullptr;
+    rhs._M_extbufend = nullptr;
+    rhs._M_ebs = 0;
+    rhs._M_intbuf = nullptr;
+    rhs._M_ibs = 0;
+    rhs._M_file = nullptr;
+    rhs._M_st = state_type();
+    rhs._M_st_last = state_type();
+    rhs._M_om = std::ios_base::openmode(0);
+    rhs._M_cm = std::ios_base::openmode(0);
+    rhs._M_owns_eb = false;
+    rhs._M_owns_ib = false;
+    rhs.setg(0, 0, 0);
+    rhs.setp(0, 0);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+inline
+basic_filebuf<CharT, Traits>&
+basic_filebuf<CharT, Traits>::operator=(basic_filebuf&& rhs)
+{
+    close();
+    swap(rhs);
+    return *this;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+basic_filebuf<CharT, Traits>::~basic_filebuf()
+{
+    // try
+    // {
+    //     close();
+    // }
+    // catch (...)
+    // {
+    // }
+    if (_M_owns_eb)
+        delete [] _M_extbuf;
+    if (_M_owns_ib)
+        delete [] _M_intbuf;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+void
+basic_filebuf<CharT, Traits>::swap(basic_filebuf& rhs)
+{
+    std::basic_streambuf<char_type, traits_type>::swap(rhs);
+    if (_M_extbuf != _M_extbuf_min && rhs._M_extbuf != rhs._M_extbuf_min)
+    {
+        std::swap(_M_extbuf, rhs._M_extbuf);
+        std::swap(_M_extbufnext, rhs._M_extbufnext);
+        std::swap(_M_extbufend, rhs._M_extbufend);
+    }
+    else
+    {
+        ptrdiff_t ln = _M_extbufnext - _M_extbuf;
+        ptrdiff_t le = _M_extbufend - _M_extbuf;
+        ptrdiff_t rn = rhs._M_extbufnext - rhs._M_extbuf;
+        ptrdiff_t re = rhs._M_extbufend - rhs._M_extbuf;
+        if (_M_extbuf == _M_extbuf_min && rhs._M_extbuf != rhs._M_extbuf_min)
+        {
+            _M_extbuf = rhs._M_extbuf;
+            rhs._M_extbuf = rhs._M_extbuf_min;
+        }
+        else if (_M_extbuf != _M_extbuf_min && rhs._M_extbuf == rhs._M_extbuf_min)
+        {
+            rhs._M_extbuf = _M_extbuf;
+            _M_extbuf = _M_extbuf_min;
+        }
+        _M_extbufnext = _M_extbuf + rn;
+        _M_extbufend = _M_extbuf + re;
+        rhs._M_extbufnext = rhs._M_extbuf + ln;
+        rhs._M_extbufend = rhs._M_extbuf + le;
+    }
+    std::swap(_M_ebs, rhs._M_ebs);
+    std::swap(_M_intbuf, rhs._M_intbuf);
+    std::swap(_M_ibs, rhs._M_ibs);
+    std::swap(_M_file, rhs._M_file);
+    std::swap(_M_cv, rhs._M_cv);
+    std::swap(_M_st, rhs._M_st);
+    std::swap(_M_st_last, rhs._M_st_last);
+    std::swap(_M_om, rhs._M_om);
+    std::swap(_M_cm, rhs._M_cm);
+    std::swap(_M_owns_eb, rhs._M_owns_eb);
+    std::swap(_M_owns_ib, rhs._M_owns_ib);
+    std::swap(_M_always_noconv, rhs._M_always_noconv);
+    if (this->eback() == (char_type*)rhs._M_extbuf_min)
+    {
+        ptrdiff_t n = this->gptr() - this->eback();
+        ptrdiff_t e = this->egptr() - this->eback();
+        this->setg((char_type*)_M_extbuf_min,
+                   (char_type*)_M_extbuf_min + n,
+                   (char_type*)_M_extbuf_min + e);
+    }
+    else if (this->pbase() == (char_type*)rhs._M_extbuf_min)
+    {
+        ptrdiff_t n = this->pptr() - this->pbase();
+        ptrdiff_t e = this->epptr() - this->pbase();
+        this->setp((char_type*)_M_extbuf_min,
+                   (char_type*)_M_extbuf_min + e);
+        this->pbump(n);
+    }
+    if (rhs.eback() == (char_type*)_M_extbuf_min)
+    {
+        ptrdiff_t n = rhs.gptr() - rhs.eback();
+        ptrdiff_t e = rhs.egptr() - rhs.eback();
+        rhs.setg((char_type*)rhs._M_extbuf_min,
+                 (char_type*)rhs._M_extbuf_min + n,
+                 (char_type*)rhs._M_extbuf_min + e);
+    }
+    else if (rhs.pbase() == (char_type*)_M_extbuf_min)
+    {
+        ptrdiff_t n = rhs.pptr() - rhs.pbase();
+        ptrdiff_t e = rhs.epptr() - rhs.pbase();
+        rhs.setp((char_type*)rhs._M_extbuf_min,
+                 (char_type*)rhs._M_extbuf_min + e);
+        rhs.pbump(n);
+    }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+inline
+void
+swap(basic_filebuf<CharT, Traits>& x, basic_filebuf<CharT, Traits>& y)
+{
+    x.swap(y);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+inline
+bool
+basic_filebuf<CharT, Traits>::is_open() const
+{
+    return _M_file != nullptr;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+const char* basic_filebuf<CharT, Traits>::_M_get_mode(std::ios_base::openmode mode)
+{
+    switch ((mode & ~std::ios_base::ate) | 0)
+    {
+    case std::ios_base::out:
+    case std::ios_base::out | std::ios_base::trunc:
+        return "w";
+    case std::ios_base::out | std::ios_base::app:
+    case std::ios_base::app:
+        return "a";
+        break;
+    case std::ios_base::in:
+        return "r";
+    case std::ios_base::in  | std::ios_base::out:
+        return "r+";
+    case std::ios_base::in  | std::ios_base::out | std::ios_base::trunc:
+        return "w+";
+    case std::ios_base::in  | std::ios_base::out | std::ios_base::app:
+    case std::ios_base::in  | std::ios_base::app:
+        return "a+";
+    case std::ios_base::out | std::ios_base::binary:
+    case std::ios_base::out | std::ios_base::trunc | std::ios_base::binary:
+        return "wb";
+    case std::ios_base::out | std::ios_base::app | std::ios_base::binary:
+    case std::ios_base::app | std::ios_base::binary:
+        return "ab";
+    case std::ios_base::in  | std::ios_base::binary:
+        return "rb";
+    case std::ios_base::in  | std::ios_base::out | std::ios_base::binary:
+        return "r+b";
+    case std::ios_base::in  | std::ios_base::out | std::ios_base::trunc | std::ios_base::binary:
+        return "w+b";
+    case std::ios_base::in  | std::ios_base::out | std::ios_base::app | std::ios_base::binary:
+    case std::ios_base::in  | std::ios_base::app | std::ios_base::binary:
+        return "a+b";
+    default:
+        return nullptr;
+    }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+basic_filebuf<CharT, Traits>*
+basic_filebuf<CharT, Traits>::open(const char* s, std::ios_base::openmode mode)
+{
+    basic_filebuf<CharT, Traits>* rt = nullptr;
+    if (_M_file == nullptr)
+    {
+        const char* md= _M_get_mode(mode);
+        if (md)
+        {
+            _M_file = fopen(s, md);
+            if (_M_file)
+            {
+                rt = this;
+                _M_om = mode;
+                if (mode & std::ios_base::ate)
+                {
+                    if (fseek(_M_file, 0, SEEK_END))
+                    {
+                        fclose(_M_file);
+                        _M_file = nullptr;
+                        rt = nullptr;
+                    }
+                }
+            }
+        }
+    }
+    return rt;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+inline
+basic_filebuf<CharT, Traits>*
+basic_filebuf<CharT, Traits>::open(const std::string& s, std::ios_base::openmode mode)
+{
+    return open(s.c_str(), mode);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+basic_filebuf<CharT, Traits>*
+basic_filebuf<CharT, Traits>::open(int fd, std::ios_base::openmode mode)
+{
+    const char* md= this->_M_get_mode(mode);
+    if (md)
+    {
+        this->_M_file= fdopen(fd, md);
+        this->_M_om = mode;
+        return this;
+    }
+    else return nullptr;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+basic_filebuf<CharT, Traits>*
+basic_filebuf<CharT, Traits>::open(FILE* f, std::ios_base::openmode mode)
+{
+    this->_M_file = f;
+    this->_M_om = mode;
+    return this;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+basic_filebuf<CharT, Traits>*
+basic_filebuf<CharT, Traits>::close()
+{
+    basic_filebuf<CharT, Traits>* rt = nullptr;
+    if (_M_file)
+    {
+        rt = this;
+        std::unique_ptr<FILE, int(*)(FILE*)> h(_M_file, fclose);
+        if (sync())
+            rt = nullptr;
+        if (fclose(h.release()) == 0)
+            _M_file = nullptr;
+        else
+            rt = nullptr;
+    }
+    return rt;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+typename basic_filebuf<CharT, Traits>::int_type
+basic_filebuf<CharT, Traits>::underflow()
+{
+    if (_M_file == nullptr)
+        return traits_type::eof();
+    bool initial = _M_read_mode();
+    char_type buf;
+    if (this->gptr() == nullptr)
+        this->setg(&buf, &buf+1, &buf+1);
+    const size_t unget_sz = initial ? 0 : std::min<size_t>((this->egptr() - this->eback()) / 2, 4);
+    int_type c = traits_type::eof();
+    if (this->gptr() == this->egptr())
+    {
+        memmove(this->eback(), this->egptr() - unget_sz, unget_sz * sizeof(char_type));
+        if (_M_always_noconv)
+        {
+            size_t nmemb = static_cast<size_t>(this->egptr() - this->eback() - unget_sz);
+            nmemb = fread(this->eback() + unget_sz, 1, nmemb, _M_file);
+            if (nmemb != 0)
+            {
+                this->setg(this->eback(),
+                           this->eback() + unget_sz,
+                           this->eback() + unget_sz + nmemb);
+                c = traits_type::to_int_type(*this->gptr());
+            }
+        }
+        else
+        {
+            memmove(_M_extbuf, _M_extbufnext, _M_extbufend - _M_extbufnext);
+            _M_extbufnext = _M_extbuf + (_M_extbufend - _M_extbufnext);
+            _M_extbufend = _M_extbuf + (_M_extbuf == _M_extbuf_min ? sizeof(_M_extbuf_min) : _M_ebs);
+            size_t nmemb = std::min(static_cast<size_t>(_M_ibs - unget_sz),
+                                    static_cast<size_t>(_M_extbufend - _M_extbufnext));
+            std::codecvt_base::result r;
+            _M_st_last = _M_st;
+            size_t nr = fread((void*)_M_extbufnext, 1, nmemb, _M_file);
+            if (nr != 0)
+            {
+                if (!_M_cv)
+                    throw std::bad_cast();
+                _M_extbufend = _M_extbufnext + nr;
+                char_type*  inext;
+                r = _M_cv->in(_M_st, _M_extbuf, _M_extbufend, _M_extbufnext,
+                              this->eback() + unget_sz,
+                              this->eback() + _M_ibs, inext);
+                if (r == std::codecvt_base::noconv)
+                {
+                    this->setg((char_type*)_M_extbuf, (char_type*)_M_extbuf, (char_type*)_M_extbufend);
+                    c = traits_type::to_int_type(*this->gptr());
+                }
+                else if (inext != this->eback() + unget_sz)
+                {
+                    this->setg(this->eback(), this->eback() + unget_sz, inext);
+                    c = traits_type::to_int_type(*this->gptr());
+                }
+            }
+        }
+    }
+    else
+        c = traits_type::to_int_type(*this->gptr());
+    if (this->eback() == &buf)
+        this->setg(0, 0, 0);
+    return c;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+typename basic_filebuf<CharT, Traits>::int_type
+basic_filebuf<CharT, Traits>::pbackfail(int_type c)
+{
+    if (_M_file && this->eback() < this->gptr())
+    {
+        if (traits_type::eq_int_type(c, traits_type::eof()))
+        {
+            this->gbump(-1);
+            return traits_type::not_eof(c);
+        }
+        if ((_M_om & std::ios_base::out) ||
+            traits_type::eq(traits_type::to_char_type(c), this->gptr()[-1]))
+        {
+            this->gbump(-1);
+            *this->gptr() = traits_type::to_char_type(c);
+            return c;
+        }
+    }
+    return traits_type::eof();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+typename basic_filebuf<CharT, Traits>::int_type
+basic_filebuf<CharT, Traits>::overflow(int_type c)
+{
+    if (_M_file == nullptr)
+        return traits_type::eof();
+    _M_write_mode();
+    char_type buf;
+    char_type* pb_save = this->pbase();
+    char_type* epb_save = this->epptr();
+    if (!traits_type::eq_int_type(c, traits_type::eof()))
+    {
+        if (this->pptr() == nullptr)
+            this->setp(&buf, &buf+1);
+        *this->pptr() = traits_type::to_char_type(c);
+        this->pbump(1);
+    }
+    if (this->pptr() != this->pbase())
+    {
+        if (_M_always_noconv)
+        {
+            size_t nmemb = static_cast<size_t>(this->pptr() - this->pbase());
+            if (fwrite(this->pbase(), sizeof(char_type), nmemb, _M_file) != nmemb)
+                return traits_type::eof();
+        }
+        else
+        {
+            char* extbe = _M_extbuf;
+            std::codecvt_base::result r;
+            do
+            {
+                if (!_M_cv)
+                    throw std::bad_cast();
+                const char_type* e;
+                r = _M_cv->out(_M_st, this->pbase(), this->pptr(), e,
+                               _M_extbuf, _M_extbuf + _M_ebs, extbe);
+                if (e == this->pbase())
+                    return traits_type::eof();
+                if (r == std::codecvt_base::noconv)
+                {
+                    size_t nmemb = static_cast<size_t>(this->pptr() - this->pbase());
+                    if (fwrite(this->pbase(), 1, nmemb, _M_file) != nmemb)
+                        return traits_type::eof();
+                }
+                else if (r == std::codecvt_base::ok || r == std::codecvt_base::partial)
+                {
+                    size_t nmemb = static_cast<size_t>(extbe - _M_extbuf);
+                    if (fwrite(_M_extbuf, 1, nmemb, _M_file) != nmemb)
+                        return traits_type::eof();
+                    if (r == std::codecvt_base::partial)
+                    {
+                        this->setp((char_type*)e, this->pptr());
+                        this->pbump(this->epptr() - this->pbase());
+                    }
+                }
+                else
+                    return traits_type::eof();
+            } while (r == std::codecvt_base::partial);
+        }
+        this->setp(pb_save, epb_save);
+    }
+    return traits_type::not_eof(c);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+std::basic_streambuf<CharT, Traits>*
+basic_filebuf<CharT, Traits>::setbuf(char_type* s, std::streamsize n)
+{
+    this->setg(0, 0, 0);
+    this->setp(0, 0);
+    if (_M_owns_eb)
+        delete [] _M_extbuf;
+    if (_M_owns_ib)
+        delete [] _M_intbuf;
+    _M_ebs = n;
+    if (_M_ebs > sizeof(_M_extbuf_min))
+    {
+        if (_M_always_noconv && s)
+        {
+            _M_extbuf = (char*)s;
+            _M_owns_eb = false;
+        }
+        else
+        {
+            _M_extbuf = new char[_M_ebs];
+            _M_owns_eb = true;
+        }
+    }
+    else
+    {
+        _M_extbuf = _M_extbuf_min;
+        _M_ebs = sizeof(_M_extbuf_min);
+        _M_owns_eb = false;
+    }
+    if (!_M_always_noconv)
+    {
+        _M_ibs = std::max<std::streamsize>(n, sizeof(_M_extbuf_min));
+        if (s && _M_ibs >= sizeof(_M_extbuf_min))
+        {
+            _M_intbuf = s;
+            _M_owns_ib = false;
+        }
+        else
+        {
+            _M_intbuf = new char_type[_M_ibs];
+            _M_owns_ib = true;
+        }
+    }
+    else
+    {
+        _M_ibs = 0;
+        _M_intbuf = 0;
+        _M_owns_ib = false;
+    }
+    return this;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+typename basic_filebuf<CharT, Traits>::pos_type
+basic_filebuf<CharT, Traits>::seekoff(off_type off, std::ios_base::seekdir way,
+                                      std::ios_base::openmode)
+{
+    if (!_M_cv)
+        throw std::bad_cast();
+    int width = _M_cv->encoding();
+    if (_M_file == nullptr || (width <= 0 && off != 0) || sync())
+        return pos_type(off_type(-1));
+    // width > 0 || off == 0
+    int whence;
+    switch (way)
+    {
+    case std::ios_base::beg:
+        whence = SEEK_SET;
+        break;
+    case std::ios_base::cur:
+        whence = SEEK_CUR;
+        break;
+    case std::ios_base::end:
+        whence = SEEK_END;
+        break;
+    default:
+        return pos_type(off_type(-1));
+    }
+#if _WIN32
+    if (fseek(_M_file, width > 0 ? width * off : 0, whence))
+        return pos_type(off_type(-1));
+    pos_type r = ftell(_M_file);
+#else
+    if (fseeko(_M_file, width > 0 ? width * off : 0, whence))
+        return pos_type(off_type(-1));
+    pos_type r = ftello(_M_file);
+#endif
+    r.state(_M_st);
+    return r;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+typename basic_filebuf<CharT, Traits>::pos_type
+basic_filebuf<CharT, Traits>::seekpos(pos_type sp, std::ios_base::openmode)
+{
+    if (_M_file == nullptr || sync())
+        return pos_type(off_type(-1));
+#if _WIN32
+    if (fseek(_M_file, sp, SEEK_SET))
+        return pos_type(off_type(-1));
+#else
+    if (fseeko(_M_file, sp, SEEK_SET))
+        return pos_type(off_type(-1));
+#endif
+    _M_st = sp.state();
+    return sp;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+int
+basic_filebuf<CharT, Traits>::sync()
+{
+    if (_M_file == nullptr)
+        return 0;
+    if (!_M_cv)
+        throw std::bad_cast();
+    if (_M_cm & std::ios_base::out)
+    {
+        if (this->pptr() != this->pbase())
+            if (overflow() == traits_type::eof())
+                return -1;
+        std::codecvt_base::result r;
+        do
+        {
+            char* extbe;
+            r = _M_cv->unshift(_M_st, _M_extbuf, _M_extbuf + _M_ebs, extbe);
+            size_t nmemb = static_cast<size_t>(extbe - _M_extbuf);
+            if (fwrite(_M_extbuf, 1, nmemb, _M_file) != nmemb)
+                return -1;
+        } while (r == std::codecvt_base::partial);
+        if (r == std::codecvt_base::error)
+            return -1;
+        if (fflush(_M_file))
+            return -1;
+    }
+    else if (_M_cm & std::ios_base::in)
+    {
+        off_type c;
+        state_type state = _M_st_last;
+        bool update_st = false;
+        if (_M_always_noconv)
+            c = this->egptr() - this->gptr();
+        else
+        {
+            int width = _M_cv->encoding();
+            c = _M_extbufend - _M_extbufnext;
+            if (width > 0)
+                c += width * (this->egptr() - this->gptr());
+            else
+            {
+                if (this->gptr() != this->egptr())
+                {
+                    const int off =  _M_cv->length(state, _M_extbuf,
+                                                   _M_extbufnext,
+                                                   this->gptr() - this->eback());
+                    c += _M_extbufnext - _M_extbuf - off;
+                    update_st = true;
+                }
+            }
+        }
+#if _WIN32
+        if (fseek(_M_file_, -c, SEEK_CUR))
+            return -1;
+#else
+        if (fseeko(_M_file, -c, SEEK_CUR))
+            return -1;
+#endif
+        if (update_st)
+            _M_st = state;
+        _M_extbufnext = _M_extbufend = _M_extbuf;
+        this->setg(0, 0, 0);
+        _M_cm = std::ios_base::openmode(0);
+    }
+    return 0;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+void
+basic_filebuf<CharT, Traits>::imbue(const std::locale& loc)
+{
+    sync();
+    _M_cv = &std::use_facet<std::codecvt<char_type, char, state_type> >(loc);
+    bool old_anc = _M_always_noconv;
+    _M_always_noconv = _M_cv->always_noconv();
+    if (old_anc != _M_always_noconv)
+    {
+        this->setg(0, 0, 0);
+        this->setp(0, 0);
+        // invariant, char_type is char, else we couldn't get here
+        if (_M_always_noconv)  // need to dump _M_intbuf
+        {
+            if (_M_owns_eb)
+                delete [] _M_extbuf;
+            _M_owns_eb = _M_owns_ib;
+            _M_ebs = _M_ibs;
+            _M_extbuf = (char*)_M_intbuf;
+            _M_ibs = 0;
+            _M_intbuf = nullptr;
+            _M_owns_ib = false;
+        }
+        else  // need to obtain an _M_intbuf.
+        {     // If _M_extbuf is user-supplied, use it, else new _M_intbuf
+            if (!_M_owns_eb && _M_extbuf != _M_extbuf_min)
+            {
+                _M_ibs = _M_ebs;
+                _M_intbuf = (char_type*)_M_extbuf;
+                _M_owns_ib = false;
+                _M_extbuf = new char[_M_ebs];
+                _M_owns_eb = true;
+            }
+            else
+            {
+                _M_ibs = _M_ebs;
+                _M_intbuf = new char_type[_M_ibs];
+                _M_owns_ib = true;
+            }
+        }
+    }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+bool
+basic_filebuf<CharT, Traits>::_M_read_mode()
+{
+    if (!(_M_cm & std::ios_base::in))
+    {
+        this->setp(0, 0);
+        if (_M_always_noconv)
+            this->setg((char_type*)_M_extbuf,
+                       (char_type*)_M_extbuf + _M_ebs,
+                       (char_type*)_M_extbuf + _M_ebs);
+        else
+            this->setg(_M_intbuf, _M_intbuf + _M_ibs, _M_intbuf + _M_ibs);
+        _M_cm = std::ios_base::in;
+        return true;
+    }
+    return false;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+template <class CharT, class Traits>
+void
+basic_filebuf<CharT, Traits>::_M_write_mode()
+{
+    if (!(_M_cm & std::ios_base::out))
+    {
+        this->setg(0, 0, 0);
+        if (_M_ebs > sizeof(_M_extbuf_min))
+        {
+            if (_M_always_noconv)
+                this->setp((char_type*)_M_extbuf,
+                           (char_type*)_M_extbuf + (_M_ebs - 1));
+            else
+                this->setp(_M_intbuf, _M_intbuf + (_M_ibs - 1));
+        }
+        else
+            this->setp(0, 0);
+        _M_cm = std::ios_base::out;
+    }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+}
+
+///////////////////////////////////////////////////////////////////////////////
+#endif // BASIC_FILEBUF_H
+
+///////////////////////////////////////////////////////////////////////////////
+
+/*
+ * ============================================================================
+ * libc++ License
+ * ============================================================================
+ *
+ * The libc++ library is dual licensed under both the University of Illinois
+ * "BSD-Like" license and the MIT license.  As a user of this code you may
+ * choose to use it under either license.  As a contributor, you agree to allow
+ * your code to be used under both.
+ *
+ * Full text of the relevant licenses is included below.
+ *
+ * ============================================================================
+ *
+ * University of Illinois/NCSA
+ * Open Source License
+ *
+ * Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT (included below)
+ *
+ * All rights reserved.
+ *
+ * Developed by:
+ *
+ *     LLVM Team
+ *
+ *     University of Illinois at Urbana-Champaign
+ *
+ *     http://llvm.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal with
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ *     * Redistributions of source code must retain the above copyright notice,
+ *       this list of conditions and the following disclaimers.
+ *
+ *     * Redistributions in binary form must reproduce the above copyright notice,
+ *       this list of conditions and the following disclaimers in the
+ *       documentation and/or other materials provided with the distribution.
+ *
+ *     * Neither the names of the LLVM Team, University of Illinois at
+ *       Urbana-Champaign, nor the names of its contributors may be used to
+ *       endorse or promote products derived from this Software without specific
+ *       prior written permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+ * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
+ * SOFTWARE.
+ *
+ * ==============================================================================
+ *
+ * Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT (included below)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * ==============================================================================
+ *
+ * This file is a partial list of people who have contributed to the LLVM/libc++
+ * project.  If you have contributed a patch or made some other contribution to
+ * LLVM/libc++, please submit a patch to this file to add yourself, and it will be
+ * done!
+ *
+ * The list is sorted by surname and formatted to allow easy grepping and
+ * beautification by scripts.  The fields are: name (N), email (E), web-address
+ * (W), PGP key ID and fingerprint (P), description (D), and snail-mail address
+ * (S).
+ *
+ * N: Saleem Abdulrasool
+ * E: compnerd@compnerd.org
+ * D: Minor patches and Linux fixes.
+ *
+ * N: Dimitry Andric
+ * E: dimitry@andric.com
+ * D: Visibility fixes, minor FreeBSD portability patches.
+ *
+ * N: Holger Arnold
+ * E: holgerar@gmail.com
+ * D: Minor fix.
+ *
+ * N: Ruben Van Boxem
+ * E: vanboxem dot ruben at gmail dot com
+ * D: Initial Windows patches.
+ *
+ * N: David Chisnall
+ * E: theraven at theravensnest dot org
+ * D: FreeBSD and Solaris ports, libcxxrt support, some atomics work.
+ *
+ * N: Marshall Clow
+ * E: mclow.lists@gmail.com
+ * E: marshall@idio.com
+ * D: C++14 support, patches and bug fixes.
+ *
+ * N: Bill Fisher
+ * E: william.w.fisher@gmail.com
+ * D: Regex bug fixes.
+ *
+ * N: Matthew Dempsky
+ * E: matthew@dempsky.org
+ * D: Minor patches and bug fixes.
+ *
+ * N: Google Inc.
+ * D: Copyright owner and contributor of the CityHash algorithm
+ *
+ * N: Howard Hinnant
+ * E: hhinnant@apple.com
+ * D: Architect and primary author of libc++
+ *
+ * N: Hyeon-bin Jeong
+ * E: tuhertz@gmail.com
+ * D: Minor patches and bug fixes.
+ *
+ * N: Argyrios Kyrtzidis
+ * E: kyrtzidis@apple.com
+ * D: Bug fixes.
+ *
+ * N: Bruce Mitchener, Jr.
+ * E: bruce.mitchener@gmail.com
+ * D: Emscripten-related changes.
+ *
+ * N: Michel Morin
+ * E: mimomorin@gmail.com
+ * D: Minor patches to is_convertible.
+ *
+ * N: Andrew Morrow
+ * E: andrew.c.morrow@gmail.com
+ * D: Minor patches and Linux fixes.
+ *
+ * N: Arvid Picciani
+ * E: aep at exys dot org
+ * D: Minor patches and musl port.
+ *
+ * N: Bjorn Reese
+ * E: breese@users.sourceforge.net
+ * D: Initial regex prototype
+ *
+ * N: Nico Rieck
+ * E: nico.rieck@gmail.com
+ * D: Windows fixes
+ *
+ * N: Jonathan Sauer
+ * D: Minor patches, mostly related to constexpr
+ *
+ * N: Craig Silverstein
+ * E: csilvers@google.com
+ * D: Implemented Cityhash as the string hash function on 64-bit machines
+ *
+ * N: Richard Smith
+ * D: Minor patches.
+ *
+ * N: Joerg Sonnenberger
+ * E: joerg@NetBSD.org
+ * D: NetBSD port.
+ *
+ * N: Stephan Tolksdorf
+ * E: st@quanttec.com
+ * D: Minor <atomic> fix
+ *
+ * N: Michael van der Westhuizen
+ * E: r1mikey at gmail dot com
+ *
+ * N: Klaas de Vries
+ * E: klaas at klaasgaaf dot nl
+ * D: Minor bug fix.
+ *
+ * N: Zhang Xiongpang
+ * E: zhangxiongpang@gmail.com
+ * D: Minor patches and bug fixes.
+ *
+ * N: Xing Xue
+ * E: xingxue@ca.ibm.com
+ * D: AIX port
+ *
+ * N: Zhihao Yuan
+ * E: lichray@gmail.com
+ * D: Standard compatibility fixes.
+ *
+ * N: Jeffrey Yasskin
+ * E: jyasskin@gmail.com
+ * E: jyasskin@google.com
+ * D: Linux fixes.
+ */
index de97db928420b6f925792b4abbc56affa3fc4d64..43e5a2e8851f6dc4eade392e33eadffce4558c04 100644 (file)
 #ifndef KALDI_UTIL_KALDI_PIPEBUF_H_
 #define KALDI_UTIL_KALDI_PIPEBUF_H_
 
+#if defined(_LIBCPP_VERSION)  // libc++
+#include "basic-filebuf.h"
+#else
 #include <fstream>
+#endif
 
 namespace kaldi
 {
-
-#ifndef _MSC_VER
 // This class provides a way to initialize a filebuf with a FILE* pointer
 // directly; it will not close the file pointer when it is deleted.
 // The C++ standard does not allow implementations of C++ to provide
 // this constructor within basic_filebuf, which makes it hard to deal
 // with pipes using completely native C++.  This is a workaround
 
+#ifdef _MSC_VER
+#elif defined(_LIBCPP_VERSION)  // libc++
+template<class CharType, class Traits = std::char_traits<CharType> >
+class basic_pipebuf : public basic_filebuf<CharType, Traits>
+{
+ public:
+  typedef basic_pipebuf<CharType, Traits>   ThisType;
+
+ public:
+  basic_pipebuf(FILE *fptr, std::ios_base::openmode mode)
+      : basic_filebuf<CharType, Traits>() {
+    this->open(fptr, mode);
+    if (!this->is_open()) {
+      KALDI_WARN << "Error initializing pipebuf";  // probably indicates
+      // code error, if the fptr was good.
+      return;
+    }
+  }
+};  // class basic_pipebuf
+#else
 template<class CharType, class Traits = std::char_traits<CharType> >
 class basic_pipebuf : public std::basic_filebuf<CharType, Traits>
 {
@@ -60,8 +82,6 @@ class basic_pipebuf : public std::basic_filebuf<CharType, Traits>
     this->_M_set_buffer(-1);
   }
 };  // class basic_pipebuf
-
-
 #endif // _MSC_VER
 
 };  // namespace kaldi
index 469cada4c0343cdb508ec7571648ee9da4de2766..12526ff9bcd09eb8854cb01153866cc382f0a50b 100644 (file)
 #ifdef _MSC_VER
 #include <unordered_map>
 #include <unordered_set>
+using std::unordered_map;
+using std::unordered_set;
+#elif __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
+#include <unordered_map>
+#include <unordered_set>
+using std::unordered_map;
+using std::unordered_set;
 #else
 #include <tr1/unordered_map>
 #include <tr1/unordered_set>
-#endif
 using std::tr1::unordered_map;
 using std::tr1::unordered_set;
+#endif
+
 
 namespace kaldi {
 
index d55aa04b43495e763f822f62306aebede9934e2e..fe7e0102a6bf54583311c06c4ce20ec4cb7d1395 100644 (file)
@@ -1,14 +1,19 @@
-To install the prerequisites for Kaldi, type
+To install the prerequisites for Kaldi:
+
   make
-or if you have multiple CPUs and want to use them, type something like:
+
+If you have multiple CPUs and want to speed things up, you can do a parallel
+build by supplying the "-j" option to make, e.g. to use 4 CPUs:
+
   make -j 4
 
-and note that if you have multiple CPUs, you might want to supply 
-an option like "-j 4" to "make"; this will speed things up.
+By default, Kaldi builds against OpenFst-1.3.4. If you want to build against
+OpenFst-1.4, edit the Makefile in this folder. Note that this change requires
+a relatively new compiler with C++11 support, e.g. gcc >= 4.6, clang >= 3.0.
 
-[note: ./install_atlas.sh is a backup plan in case you don't have ATLAS
- installed on your system; ignore it unless you get errors from
- ../src/configure.]
+Note:
+./install_atlas.sh is a backup plan in case you don't have ATLAS installed
+on your system. Ignore it unless you get errors from ../src/configure.
 
 **** IGNORE THE REST OF THIS FILE!  ****
 
index 6a558c791e862f4a2fc10257c7dc0b32c3373de2..6c45b107e410078081a53886a0d9a5e6b8ebfb68 100644 (file)
@@ -1,26 +1,38 @@
 # SHELL += -x
 
 CXX = g++
-
-# On Mac OS 10.9, g++ is actually clang in disguise which by default uses the
-# new c++ standard library libc++. Since openfst uses stuff from the tr1
-# namespace, we need to tell clang to use libstdc++ instead.
-COMPILER = $(shell $(CXX) -v 2>&1 )
-ifeq ($(findstring clang,$(COMPILER)),clang)
-       CXXFLAGS += -stdlib=libstdc++
-       LDFLAGS += -stdlib=libstdc++
+# CXX = clang++  # Uncomment this line to build with Clang.
+
+OPENFST_VERSION = 1.3.4
+# OPENFST_VERSION = 1.4.1  # Uncomment this line to build with OpenFst-1.4.1.
+# Note: OpenFst >= 1.4 requires C++11 support, hence you will need to use a
+# relatively recent C++ compiler, e.g. gcc >= 4.6, clang >= 3.0.
+
+# On Mac OS 10.9+, clang defaults to the new c++ standard library libc++.
+# Since OpenFst-1.3 uses stuff from the tr1 namespace, we need to tell clang
+# to use libstdc++ instead.
+ifeq ($(OPENFST_VERSION), 1.3.4)
+  COMPILER = $(shell $(CXX) -v 2>&1 )
+  ifeq ($(findstring clang,$(COMPILER)),clang)
+    CXXFLAGS += -stdlib=libstdc++
+    LDFLAGS += -stdlib=libstdc++
+  endif
+else
+  ifneq ($(OPENFST_VERSION), 1.4.1)
+    $(error OpenFst version $(OPENFST_VERSION) is not supported. \
+            Supported versions: 1.3.4, 1.4.1)
+  endif
 endif
 
 all: check_required_programs sph2pipe atlas irstlm_tgt sclite openfst
 
-
 check_required_programs:
        extras/check_dependencies.sh
 
 clean: openfst_cleaned sclite_cleaned  irstlm_cleaned
 
 openfst_cleaned:
-       $(MAKE) -C openfst-1.3.4 clean
+       $(MAKE) -C openfst-$(OPENFST_VERSION) clean
 
 irstlm_cleaned:
        $(MAKE) -C irstlm clean 
@@ -29,7 +41,7 @@ sclite_cleaned:
        $(MAKE) -C sctk clean
 
 distclean:
-       rm -rf openfst-1.3.4/
+       rm -rf openfst-$(OPENFST_VERSION)/
        rm -rf sctk-2.4.9/
        rm -rf sctk
        rm -rf ATLAS/
@@ -38,47 +50,46 @@ distclean:
        rm -rf sph2pipe_v2.5.tar.gz
        rm -rf atlas3.8.3.tar.gz
        rm -rf sctk-2.4.9-20141015-1634Z.tar.bz2
-       rm -rf openfst-1.3.4.tar.gz
+       rm -rf openfst-$(OPENFST_VERSION).tar.gz
        rm -f openfst
 
 
 .PHONY: openfst # so target will be made even though "openfst" exists.
-
-openfst: openfst_compiled openfst-1.3.4/lib
+openfst: openfst_compiled openfst-$(OPENFST_VERSION)/lib
+       -rm openfst
+       -ln -s openfst-$(OPENFST_VERSION) openfst
 
 .PHONY: openfst_compiled
-openfst_compiled: openfst-1.3.4/Makefile
-       cd openfst-1.3.4/ && \
+openfst_compiled: openfst-$(OPENFST_VERSION)/Makefile
+       cd openfst-$(OPENFST_VERSION)/ && \
        $(MAKE) install
 
-openfst-1.3.4/lib: | openfst-1.3.4/Makefile
-       -cd openfst-1.3.4 && [ -d lib64 ] && [ ! -d lib ] && ln -s lib64 lib
+openfst-$(OPENFST_VERSION)/lib: | openfst-$(OPENFST_VERSION)/Makefile
+       -cd openfst-$(OPENFST_VERSION) && [ -d lib64 ] && [ ! -d lib ] && ln -s lib64 lib
 
-# Disable shared-library creation on cygwin as it leads to compilation error "file too big"
-# with openfst-1.3.4.
-openfst-1.3.4/Makefile: openfst-1.3.4/.patched
+# Disable shared-library creation on cygwin as it leads to compilation error
+# "file too big".
+openfst-$(OPENFST_VERSION)/Makefile: openfst-$(OPENFST_VERSION)/.patched
 ifeq ($(OSTYPE),cygwin)
-       cd openfst-1.3.4/; ./configure --prefix=`pwd` --enable-static --disable-shared --enable-far --enable-ngram-fsts CXX=$(CXX) CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" LIBS="-ldl"
+       cd openfst-$(OPENFST_VERSION)/; ./configure --prefix=`pwd` --enable-static --disable-shared --enable-far --enable-ngram-fsts CXX=$(CXX) CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" LIBS="-ldl"
 else
-       cd openfst-1.3.4/; ./configure --prefix=`pwd` --enable-static --enable-shared --enable-far --enable-ngram-fsts CXX=$(CXX) CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" LIBS="-ldl"
+       cd openfst-$(OPENFST_VERSION)/; ./configure --prefix=`pwd` --enable-static --enable-shared --enable-far --enable-ngram-fsts CXX=$(CXX) CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" LIBS="-ldl"
 endif
 
 # patches for openfst. openfst_gcc41up.patch is a patch for openfst to \
 # support multi-threads when compile with g++ (gcc) version above 4.1
-openfst-1.3.4/.patched: | openfst-1.3.4
-       -cd openfst-1.3.4/src/include/fst; \
-       patch -p0 -N < ../../../../openfst.patch;
-       $(CXX) -dumpversion | awk '{if(NR==1 && $$1>"4.1") print "cd openfst-1.3.4/src/include/fst; patch -p0 -N < ../../../../extras/openfst_gcc41up.patch"}' | sh -
-       touch $@        
-
-openfst-1.3.4: openfst-1.3.4.tar.gz
-       tar xozf openfst-1.3.4.tar.gz
-       -rm openfst
-       -ln -s openfst-1.3.4 openfst 
-
-openfst-1.3.4.tar.gz: 
-       wget http://openfst.cs.nyu.edu/twiki/pub/FST/FstDownload/openfst-1.3.4.tar.gz || \
-       wget -T 10 -t 3 http://www.openslr.org/resources/2/openfst-1.3.4.tar.gz
+openfst-$(OPENFST_VERSION)/.patched: | openfst-$(OPENFST_VERSION)
+       -cd openfst-$(OPENFST_VERSION)/src/include/fst; \
+       patch -p0 -N < ../../../../extras/openfst.patch;
+       $(CXX) -dumpversion | awk '{if(NR==1 && $$1>"4.1") print "cd openfst-$(OPENFST_VERSION)/src/include/fst; patch -p0 -N < ../../../../extras/openfst_gcc41up.patch"}' | sh -
+       touch $@
+
+openfst-$(OPENFST_VERSION): openfst-$(OPENFST_VERSION).tar.gz
+       tar xozf openfst-$(OPENFST_VERSION).tar.gz
+
+openfst-$(OPENFST_VERSION).tar.gz: 
+       wget http://openfst.cs.nyu.edu/twiki/pub/FST/FstDownload/openfst-$(OPENFST_VERSION).tar.gz || \
+       wget -T 10 -t 3 http://www.openslr.org/resources/2/openfst-$(OPENFST_VERSION).tar.gz
 
 sclite: sclite_compiled
 
index dfdf07ca2b0fcb1ebc67185bce54c8c91f177ea0..11408014c0520eebd97bc4ad92156ae2faea78df 100755 (executable)
@@ -19,7 +19,7 @@ mv g2p sequitur
 
 
 cd sequitur
-patch  < ../sequitur.patch 
+patch  < ../extras/sequitur.patch
 make
 python setup.py install --prefix `pwd`
 
diff --git a/tools/extras/openfst.patch b/tools/extras/openfst.patch
new file mode 100644 (file)
index 0000000..1307513
--- /dev/null
@@ -0,0 +1,227 @@
+*** minimize.h
+***************
+*** 134,140 ****
+    typedef typename A::Weight Weight;
+    typedef ReverseArc<A> RevA;
+  
+!   CyclicMinimizer(const ExpandedFst<A>& fst) {
+      Initialize(fst);
+      Compute(fst);
+    }
+--- 134,147 ----
+    typedef typename A::Weight Weight;
+    typedef ReverseArc<A> RevA;
+  
+!   CyclicMinimizer(const ExpandedFst<A>& fst):
+!       // tell the Partition data-member to expect multiple repeated
+!       // calls to SplitOn with the same element if we are non-deterministic.
+!       P_(fst.Properties(kIDeterministic, true) == 0) {
+!     if(fst.Properties(kIDeterministic, true) == 0)
+!       CHECK(Weight::Properties() & kIdempotent); // this minimization
+!     // algorithm for non-deterministic FSTs can only work with idempotent
+!     // semirings.
+      Initialize(fst);
+      Compute(fst);
+    }
+***************
+*** 315,321 ****
+    typedef typename A::StateId ClassId;
+    typedef typename A::Weight Weight;
+  
+!   AcyclicMinimizer(const ExpandedFst<A>& fst) {
+      Initialize(fst);
+      Refine(fst);
+    }
+--- 322,334 ----
+    typedef typename A::StateId ClassId;
+    typedef typename A::Weight Weight;
+  
+!   AcyclicMinimizer(const ExpandedFst<A>& fst):
+!       // tell the Partition data-member to expect multiple repeated
+!       // calls to SplitOn with the same element if we are non-deterministic.
+!       partition_(fst.Properties(kIDeterministic, true) == 0) {
+!     if(fst.Properties(kIDeterministic, true) == 0)
+!       CHECK(Weight::Properties() & kIdempotent); // minimization for
+!     // non-deterministic FSTs can only work with idempotent semirings.
+      Initialize(fst);
+      Refine(fst);
+    }
+***************
+*** 531,543 ****
+  void Minimize(MutableFst<A>* fst,
+                MutableFst<A>* sfst = 0,
+                float delta = kDelta) {
+!   uint64 props = fst->Properties(kAcceptor | kIDeterministic|
+!                                  kWeighted | kUnweighted, true);
+!   if (!(props & kIDeterministic)) {
+!     FSTERROR() << "FST is not deterministic";
+!     fst->SetProperties(kError, kError);
+!     return;
+!   }
+  
+    if (!(props & kAcceptor)) {  // weighted transducer
+      VectorFst< GallicArc<A, STRING_LEFT> > gfst;
+--- 544,550 ----
+  void Minimize(MutableFst<A>* fst,
+                MutableFst<A>* sfst = 0,
+                float delta = kDelta) {
+!   uint64 props = fst->Properties(kAcceptor | kWeighted | kUnweighted, true);
+  
+    if (!(props & kAcceptor)) {  // weighted transducer
+      VectorFst< GallicArc<A, STRING_LEFT> > gfst;
+*** partition.h
+***************
+*** 43,50 ****
+    friend class PartitionIterator<T>;
+  
+    struct Element {
+!    Element() : value(0), next(0), prev(0) {}
+!    Element(T v) : value(v), next(0), prev(0) {}
+  
+     T        value;
+     Element* next;
+--- 43,50 ----
+    friend class PartitionIterator<T>;
+  
+    struct Element {
+!     Element() : value(0), next(0), prev(0) {}
+!     Element(T v) : value(v), next(0), prev(0) {}
+  
+     T        value;
+     Element* next;
+***************
+*** 52,60 ****
+    };
+  
+   public:
+!   Partition() {}
+  
+!   Partition(T num_states) {
+      Initialize(num_states);
+    }
+  
+--- 52,62 ----
+    };
+  
+   public:
+!   Partition(bool allow_repeated_split):
+!       allow_repeated_split_(allow_repeated_split) {}
+  
+!   Partition(bool allow_repeated_split, T num_states):
+!       allow_repeated_split_(allow_repeated_split) {
+      Initialize(num_states);
+    }
+  
+***************
+*** 137,152 ****
+      if (class_size_[class_id] == 1) return;
+  
+      // first time class is split
+!     if (split_size_[class_id] == 0)
+        visited_classes_.push_back(class_id);
+! 
+      // increment size of split (set of element at head of chain)
+      split_size_[class_id]++;
+! 
+      // update split point
+!     if (class_split_[class_id] == 0)
+!       class_split_[class_id] = classes_[class_id];
+!     if (class_split_[class_id] == elements_[element_id])
+        class_split_[class_id] = elements_[element_id]->next;
+  
+      // move to head of chain in same class
+--- 139,154 ----
+      if (class_size_[class_id] == 1) return;
+  
+      // first time class is split
+!     if (split_size_[class_id] == 0) { 
+        visited_classes_.push_back(class_id);
+!       class_split_[class_id] = classes_[class_id];
+!     }
+      // increment size of split (set of element at head of chain)
+      split_size_[class_id]++;
+!     
+      // update split point
+!     if (class_split_[class_id] != 0
+!         && class_split_[class_id] == elements_[element_id])
+        class_split_[class_id] = elements_[element_id]->next;
+  
+      // move to head of chain in same class
+***************
+*** 157,180 ****
+    // class indices of the newly created class. Returns the new_class id
+    // or -1 if no new class was created.
+    T SplitRefine(T class_id) {
+      // only split if necessary
+!     if (class_size_[class_id] == split_size_[class_id]) {
+!       class_split_[class_id] = 0;
+        split_size_[class_id] = 0;
+        return -1;
+      } else {
+- 
+        T new_class = AddClass();
+        size_t remainder = class_size_[class_id] - split_size_[class_id];
+        if (remainder < split_size_[class_id]) {  // add smaller
+-         Element* split_el   = class_split_[class_id];
+          classes_[new_class] = split_el;
+-         class_size_[class_id] = split_size_[class_id];
+-         class_size_[new_class] = remainder;
+          split_el->prev->next = 0;
+          split_el->prev = 0;
+        } else {
+-         Element* split_el   = class_split_[class_id];
+          classes_[new_class] = classes_[class_id];
+          class_size_[class_id] = remainder;
+          class_size_[new_class] = split_size_[class_id];
+--- 159,189 ----
+    // class indices of the newly created class. Returns the new_class id
+    // or -1 if no new class was created.
+    T SplitRefine(T class_id) {
++ 
++     Element* split_el = class_split_[class_id];
+      // only split if necessary
+!     //if (class_size_[class_id] == split_size_[class_id]) {
+!     if(split_el == NULL) { // we split on everything...
+        split_size_[class_id] = 0;
+        return -1;
+      } else {
+        T new_class = AddClass();
++ 
++       if(allow_repeated_split_) { // split_size_ is possibly
++         // inaccurate, so work it out exactly.
++         size_t split_count;  Element *e;
++         for(split_count=0,e=classes_[class_id];
++             e != split_el; split_count++, e=e->next);
++         split_size_[class_id] = split_count;
++       }
+        size_t remainder = class_size_[class_id] - split_size_[class_id];
+        if (remainder < split_size_[class_id]) {  // add smaller
+          classes_[new_class] = split_el;
+          split_el->prev->next = 0;
+          split_el->prev = 0;
++         class_size_[class_id] = split_size_[class_id];
++         class_size_[new_class] = remainder;
+        } else {
+          classes_[new_class] = classes_[class_id];
+          class_size_[class_id] = remainder;
+          class_size_[new_class] = split_size_[class_id];
+***************
+*** 245,254 ****
+--- 254,269 ----
+    vector<T> class_size_;
+  
+    // size of split for each class
++   // in the nondeterministic case, split_size_ is actually an upper
++   // bound on the size of split for each class.
+    vector<T> split_size_;
+  
+    // set of visited classes to be used in split refine
+    vector<T> visited_classes_;
++ 
++   // true if input fst was deterministic: we can make
++   // certain assumptions in this case that speed up the algorithm.
++   bool allow_repeated_split_;
+  };
+  
+  
+
diff --git a/tools/openfst.patch b/tools/openfst.patch
deleted file mode 100644 (file)
index ebc6b7b..0000000
+++ /dev/null
@@ -1,584 +0,0 @@
-*** minimize.h
-***************
-*** 134,140 ****
-    typedef typename A::Weight Weight;
-    typedef ReverseArc<A> RevA;
-  
-!   CyclicMinimizer(const ExpandedFst<A>& fst) {
-      Initialize(fst);
-      Compute(fst);
-    }
---- 134,147 ----
-    typedef typename A::Weight Weight;
-    typedef ReverseArc<A> RevA;
-  
-!   CyclicMinimizer(const ExpandedFst<A>& fst):
-!       // tell the Partition data-member to expect multiple repeated
-!       // calls to SplitOn with the same element if we are non-deterministic.
-!       P_(fst.Properties(kIDeterministic, true) == 0) {
-!     if(fst.Properties(kIDeterministic, true) == 0)
-!       CHECK(Weight::Properties() & kIdempotent); // this minimization
-!     // algorithm for non-deterministic FSTs can only work with idempotent
-!     // semirings.
-      Initialize(fst);
-      Compute(fst);
-    }
-***************
-*** 315,321 ****
-    typedef typename A::StateId ClassId;
-    typedef typename A::Weight Weight;
-  
-!   AcyclicMinimizer(const ExpandedFst<A>& fst) {
-      Initialize(fst);
-      Refine(fst);
-    }
---- 322,334 ----
-    typedef typename A::StateId ClassId;
-    typedef typename A::Weight Weight;
-  
-!   AcyclicMinimizer(const ExpandedFst<A>& fst):
-!       // tell the Partition data-member to expect multiple repeated
-!       // calls to SplitOn with the same element if we are non-deterministic.
-!       partition_(fst.Properties(kIDeterministic, true) == 0) {
-!     if(fst.Properties(kIDeterministic, true) == 0)
-!       CHECK(Weight::Properties() & kIdempotent); // minimization for
-!     // non-deterministic FSTs can only work with idempotent semirings.
-      Initialize(fst);
-      Refine(fst);
-    }
-***************
-*** 531,543 ****
-  void Minimize(MutableFst<A>* fst,
-                MutableFst<A>* sfst = 0,
-                float delta = kDelta) {
-!   uint64 props = fst->Properties(kAcceptor | kIDeterministic|
-!                                  kWeighted | kUnweighted, true);
-!   if (!(props & kIDeterministic)) {
-!     FSTERROR() << "FST is not deterministic";
-!     fst->SetProperties(kError, kError);
-!     return;
-!   }
-  
-    if (!(props & kAcceptor)) {  // weighted transducer
-      VectorFst< GallicArc<A, STRING_LEFT> > gfst;
---- 544,550 ----
-  void Minimize(MutableFst<A>* fst,
-                MutableFst<A>* sfst = 0,
-                float delta = kDelta) {
-!   uint64 props = fst->Properties(kAcceptor | kWeighted | kUnweighted, true);
-  
-    if (!(props & kAcceptor)) {  // weighted transducer
-      VectorFst< GallicArc<A, STRING_LEFT> > gfst;
-*** partition.h
-***************
-*** 43,50 ****
-    friend class PartitionIterator<T>;
-  
-    struct Element {
-!    Element() : value(0), next(0), prev(0) {}
-!    Element(T v) : value(v), next(0), prev(0) {}
-  
-     T        value;
-     Element* next;
---- 43,50 ----
-    friend class PartitionIterator<T>;
-  
-    struct Element {
-!     Element() : value(0), next(0), prev(0) {}
-!     Element(T v) : value(v), next(0), prev(0) {}
-  
-     T        value;
-     Element* next;
-***************
-*** 52,60 ****
-    };
-  
-   public:
-!   Partition() {}
-  
-!   Partition(T num_states) {
-      Initialize(num_states);
-    }
-  
---- 52,62 ----
-    };
-  
-   public:
-!   Partition(bool allow_repeated_split):
-!       allow_repeated_split_(allow_repeated_split) {}
-  
-!   Partition(bool allow_repeated_split, T num_states):
-!       allow_repeated_split_(allow_repeated_split) {
-      Initialize(num_states);
-    }
-  
-***************
-*** 137,152 ****
-      if (class_size_[class_id] == 1) return;
-  
-      // first time class is split
-!     if (split_size_[class_id] == 0)
-        visited_classes_.push_back(class_id);
-! 
-      // increment size of split (set of element at head of chain)
-      split_size_[class_id]++;
-! 
-      // update split point
-!     if (class_split_[class_id] == 0)
-!       class_split_[class_id] = classes_[class_id];
-!     if (class_split_[class_id] == elements_[element_id])
-        class_split_[class_id] = elements_[element_id]->next;
-  
-      // move to head of chain in same class
---- 139,154 ----
-      if (class_size_[class_id] == 1) return;
-  
-      // first time class is split
-!     if (split_size_[class_id] == 0) { 
-        visited_classes_.push_back(class_id);
-!       class_split_[class_id] = classes_[class_id];
-!     }
-      // increment size of split (set of element at head of chain)
-      split_size_[class_id]++;
-!     
-      // update split point
-!     if (class_split_[class_id] != 0
-!         && class_split_[class_id] == elements_[element_id])
-        class_split_[class_id] = elements_[element_id]->next;
-  
-      // move to head of chain in same class
-***************
-*** 157,180 ****
-    // class indices of the newly created class. Returns the new_class id
-    // or -1 if no new class was created.
-    T SplitRefine(T class_id) {
-      // only split if necessary
-!     if (class_size_[class_id] == split_size_[class_id]) {
-!       class_split_[class_id] = 0;
-        split_size_[class_id] = 0;
-        return -1;
-      } else {
-- 
-        T new_class = AddClass();
-        size_t remainder = class_size_[class_id] - split_size_[class_id];
-        if (remainder < split_size_[class_id]) {  // add smaller
--         Element* split_el   = class_split_[class_id];
-          classes_[new_class] = split_el;
--         class_size_[class_id] = split_size_[class_id];
--         class_size_[new_class] = remainder;
-          split_el->prev->next = 0;
-          split_el->prev = 0;
-        } else {
--         Element* split_el   = class_split_[class_id];
-          classes_[new_class] = classes_[class_id];
-          class_size_[class_id] = remainder;
-          class_size_[new_class] = split_size_[class_id];
---- 159,189 ----
-    // class indices of the newly created class. Returns the new_class id
-    // or -1 if no new class was created.
-    T SplitRefine(T class_id) {
-+ 
-+     Element* split_el = class_split_[class_id];
-      // only split if necessary
-!     //if (class_size_[class_id] == split_size_[class_id]) {
-!     if(split_el == NULL) { // we split on everything...
-        split_size_[class_id] = 0;
-        return -1;
-      } else {
-        T new_class = AddClass();
-+ 
-+       if(allow_repeated_split_) { // split_size_ is possibly
-+         // inaccurate, so work it out exactly.
-+         size_t split_count;  Element *e;
-+         for(split_count=0,e=classes_[class_id];
-+             e != split_el; split_count++, e=e->next);
-+         split_size_[class_id] = split_count;
-+       }
-        size_t remainder = class_size_[class_id] - split_size_[class_id];
-        if (remainder < split_size_[class_id]) {  // add smaller
-          classes_[new_class] = split_el;
-          split_el->prev->next = 0;
-          split_el->prev = 0;
-+         class_size_[class_id] = split_size_[class_id];
-+         class_size_[new_class] = remainder;
-        } else {
-          classes_[new_class] = classes_[class_id];
-          class_size_[class_id] = remainder;
-          class_size_[new_class] = split_size_[class_id];
-***************
-*** 245,254 ****
---- 254,269 ----
-    vector<T> class_size_;
-  
-    // size of split for each class
-+   // in the nondeterministic case, split_size_ is actually an upper
-+   // bound on the size of split for each class.
-    vector<T> split_size_;
-  
-    // set of visited classes to be used in split refine
-    vector<T> visited_classes_;
-+ 
-+   // true if input fst was deterministic: we can make
-+   // certain assumptions in this case that speed up the algorithm.
-+   bool allow_repeated_split_;
-  };
-  
-  
-*** interval-set.h
-***************
-*** 37,74 ****
-  class IntervalSet {
-   public:
-    struct Interval {
-!     T begin;
-!     T end;
-  
-!     Interval() : begin(-1), end(-1) {}
-  
-!     Interval(T b, T e) : begin(b), end(e) {}
-  
-      bool operator<(const Interval &i) const {
-!       return begin < i.begin || (begin == i.begin && end > i.end);
-      }
-  
-      bool operator==(const Interval &i) const {
-!       return begin == i.begin && end == i.end;
-      }
-  
-      bool operator!=(const Interval &i) const {
-!       return begin != i.begin || end != i.end;
-      }
-  
-      istream &Read(istream &strm) {
-        T n;
-        ReadType(strm, &n);
-!       begin = n;
-        ReadType(strm, &n);
-!       end = n;
-        return strm;
-      }
-  
-      ostream &Write(ostream &strm) const {
-!       T n = begin;
-        WriteType(strm, n);
-!       n = end;
-        WriteType(strm, n);
-        return strm;
-      }
---- 37,74 ----
-  class IntervalSet {
-   public:
-    struct Interval {
-!     T begin_;
-!     T end_;
-  
-!     Interval() : begin_(-1), end_(-1) {}
-  
-!     Interval(T b, T e) : begin_(b), end_(e) {}
-  
-      bool operator<(const Interval &i) const {
-!       return begin_ < i.begin_ || (begin_ == i.begin_ && end_ > i.end_);
-      }
-  
-      bool operator==(const Interval &i) const {
-!       return begin_ == i.begin_ && end_ == i.end_;
-      }
-  
-      bool operator!=(const Interval &i) const {
-!       return begin_ != i.begin_ || end_ != i.end_;
-      }
-  
-      istream &Read(istream &strm) {
-        T n;
-        ReadType(strm, &n);
-!       begin_ = n;
-        ReadType(strm, &n);
-!       end_ = n;
-        return strm;
-      }
-  
-      ostream &Write(ostream &strm) const {
-!       T n = begin_;
-        WriteType(strm, n);
-!       n = end_;
-        WriteType(strm, n);
-        return strm;
-      }
-***************
-*** 108,114 ****
-          lower_bound(intervals_.begin(), intervals_.end(), interval);
-      if (lb == intervals_.begin())
-        return false;
-!     return (--lb)->end > value;
-    }
-  
-    // Requires intervals be normalized.
---- 108,114 ----
-          lower_bound(intervals_.begin(), intervals_.end(), interval);
-      if (lb == intervals_.begin())
-        return false;
-!     return (--lb)->end_ > value;
-    }
-  
-    // Requires intervals be normalized.
-***************
-*** 123,129 ****
-  
-    bool Singleton() const {
-      return intervals_.size() == 1 &&
-!         intervals_[0].begin + 1 == intervals_[0].end;
-    }
-  
-  
---- 123,129 ----
-  
-    bool Singleton() const {
-      return intervals_.size() == 1 &&
-!         intervals_[0].begin_ + 1 == intervals_[0].end_;
-    }
-  
-  
-***************
-*** 178,194 ****
-    T size = 0;
-    for (T i = 0; i < intervals_.size(); ++i) {
-      Interval &inti = intervals_[i];
-!     if (inti.begin == inti.end)
-        continue;
-      for (T j = i + 1; j < intervals_.size(); ++j) {
-        Interval &intj = intervals_[j];
-!       if (intj.begin > inti.end)
-          break;
-!       if (intj.end > inti.end)
-!         inti.end = intj.end;
-        ++i;
-      }
-!     count_ += inti.end - inti.begin;
-      intervals_[size++] = inti;
-    }
-    intervals_.resize(size);
---- 178,194 ----
-    T size = 0;
-    for (T i = 0; i < intervals_.size(); ++i) {
-      Interval &inti = intervals_[i];
-!     if (inti.begin_ == inti.end_)
-        continue;
-      for (T j = i + 1; j < intervals_.size(); ++j) {
-        Interval &intj = intervals_[j];
-!       if (intj.begin_ > inti.end_)
-          break;
-!       if (intj.end_ > inti.end_)
-!         inti.end_ = intj.end_;
-        ++i;
-      }
-!     count_ += inti.end_ - inti.begin_;
-      intervals_[size++] = inti;
-    }
-    intervals_.resize(size);
-***************
-*** 208,224 ****
-    oset->count_ = 0;
-  
-    while (it1 != intervals_.end() && it2 != iintervals->end()) {
-!     if (it1->end <= it2->begin) {
-        ++it1;
-!     } else if (it2->end <= it1->begin) {
-        ++it2;
-      } else {
-        Interval interval;
-!       interval.begin = max(it1->begin, it2->begin);
-!       interval.end = min(it1->end, it2->end);
-        ointervals->push_back(interval);
-!       oset->count_ += interval.end - interval.begin;
-!       if (it1->end < it2->end)
-          ++it1;
-        else
-          ++it2;
---- 208,224 ----
-    oset->count_ = 0;
-  
-    while (it1 != intervals_.end() && it2 != iintervals->end()) {
-!     if (it1->end_ <= it2->begin_) {
-        ++it1;
-!     } else if (it2->end_ <= it1->begin_) {
-        ++it2;
-      } else {
-        Interval interval;
-!       interval.begin_ = max(it1->begin_, it2->begin_);
-!       interval.end_ = min(it1->end_, it2->end_);
-        ointervals->push_back(interval);
-!       oset->count_ += interval.end_ - interval.begin_;
-!       if (it1->end_ < it2->end_)
-          ++it1;
-        else
-          ++it2;
-***************
-*** 235,255 ****
-    oset->count_ = 0;
-  
-    Interval interval;
-!   interval.begin = 0;
-    for (typename vector<Interval>::const_iterator it = intervals_.begin();
-         it != intervals_.end();
-         ++it) {
-!     interval.end = min(it->begin, maxval);
-!     if (interval.begin < interval.end) {
-        ointervals->push_back(interval);
-!       oset->count_ += interval.end - interval.begin;
-      }
-!     interval.begin = it->end;
-    }
-!   interval.end = maxval;
-!   if (interval.begin < interval.end) {
-      ointervals->push_back(interval);
-!     oset->count_ += interval.end - interval.begin;
-    }
-  }
-  
---- 235,255 ----
-    oset->count_ = 0;
-  
-    Interval interval;
-!   interval.begin_ = 0;
-    for (typename vector<Interval>::const_iterator it = intervals_.begin();
-         it != intervals_.end();
-         ++it) {
-!     interval.end_ = min(it->begin_, maxval);
-!     if (interval.begin_ < interval.end_) {
-        ointervals->push_back(interval);
-!       oset->count_ += interval.end_ - interval.begin_;
-      }
-!     interval.begin_ = it->end_;
-    }
-!   interval.end_ = maxval;
-!   if (interval.begin_ < interval.end_) {
-      ointervals->push_back(interval);
-!     oset->count_ += interval.end_ - interval.begin_;
-    }
-  }
-  
-***************
-*** 263,269 ****
-      oset->count_ = 0;
-    } else {
-      IntervalSet<T> cset;
-!     iset.Complement(intervals_.back().end, &cset);
-      Intersect(cset, oset);
-    }
-  }
---- 263,269 ----
-      oset->count_ = 0;
-    } else {
-      IntervalSet<T> cset;
-!     iset.Complement(intervals_.back().end_, &cset);
-      Intersect(cset, oset);
-    }
-  }
-***************
-*** 277,285 ****
-    typename vector<Interval>::const_iterator it2 = intervals->begin();
-  
-    while (it1 != intervals_.end() && it2 != intervals->end()) {
-!     if (it1->end <= it2->begin) {
-        ++it1;
-!     } else if (it2->end <= it1->begin) {
-        ++it2;
-      } else {
-        return true;
---- 277,285 ----
-    typename vector<Interval>::const_iterator it2 = intervals->begin();
-  
-    while (it1 != intervals_.end() && it2 != intervals->end()) {
-!     if (it1->end_ <= it2->begin_) {
-        ++it1;
-!     } else if (it2->end_ <= it1->begin_) {
-        ++it2;
-      } else {
-        return true;
-***************
-*** 300,320 ****
-    bool overlap = false; // point in both intervals_ and intervals
-  
-    while (it1 != intervals_.end() && it2 != intervals->end()) {
-!     if (it1->end <= it2->begin) {  // no overlap - it1 first
-        only1 = true;
-        ++it1;
-!     } else if (it2->end <= it1->begin) {  // no overlap - it2 first
-        only2 = true;
-        ++it2;
-!     } else if (it2->begin == it1->begin && it2->end == it1->end) {  // equals
-        overlap = true;
-        ++it1;
-        ++it2;
-!     } else if (it2->begin <= it1->begin && it2->end >= it1->end) {  // 1 c 2
-        only2 = true;
-        overlap = true;
-        ++it1;
-!     } else if (it1->begin <= it2->begin && it1->end >= it2->end) {  // 2 c 1
-        only1 = true;
-        overlap = true;
-        ++it2;
---- 300,320 ----
-    bool overlap = false; // point in both intervals_ and intervals
-  
-    while (it1 != intervals_.end() && it2 != intervals->end()) {
-!     if (it1->end_ <= it2->begin_) {  // no overlap - it1 first
-        only1 = true;
-        ++it1;
-!     } else if (it2->end_ <= it1->begin_) {  // no overlap - it2 first
-        only2 = true;
-        ++it2;
-!     } else if (it2->begin_ == it1->begin_ && it2->end_ == it1->end_) {  // equals
-        overlap = true;
-        ++it1;
-        ++it2;
-!     } else if (it2->begin_ <= it1->begin_ && it2->end_ >= it1->end_) {  // 1 c 2
-        only2 = true;
-        overlap = true;
-        ++it1;
-!     } else if (it1->begin_ <= it2->begin_ && it1->end_ >= it2->end_) {  // 2 c 1
-        only1 = true;
-        overlap = true;
-        ++it2;
-***************
-*** 346,356 ****
-    typename vector<Interval>::const_iterator it2 = intervals->begin();
-  
-    while (it1 != intervals_.end() && it2 != intervals->end()) {
-!     if (it1->end <= it2->begin) {  // no overlap - it1 first
-        ++it1;
-!     } else if (it2->begin < it1->begin || it2->end > it1->end) {  // no C
-        return false;
-!     } else if (it2->end == it1->end) {
-        ++it1;
-        ++it2;
-      } else {
---- 346,356 ----
-    typename vector<Interval>::const_iterator it2 = intervals->begin();
-  
-    while (it1 != intervals_.end() && it2 != intervals->end()) {
-!     if (it1->end_ <= it2->begin_) {  // no overlap - it1 first
-        ++it1;
-!     } else if (it2->begin_ < it1->begin_ || it2->end_ > it1->end_) {  // no C
-        return false;
-!     } else if (it2->end_ == it1->end_) {
-        ++it1;
-        ++it2;
-      } else {
-***************
-*** 370,376 ****
-         ++it) {
-      if (it != intervals->begin())
-        strm << ",";
-!     strm << "[" << it->begin << "," << it->end << ")";
-    }
-    strm << "}";
-    return strm;
---- 370,376 ----
-         ++it) {
-      if (it != intervals->begin())
-        strm << ",";
-!     strm << "[" << it->begin_ << "," << it->end_ << ")";
-    }
-    strm << "}";
-    return strm;