From 96a32415ab43377cf1575bd3f4f2980f58028209 Mon Sep 17 00:00:00 2001 From: Determinant Date: Fri, 14 Aug 2015 11:51:42 +0800 Subject: add implementation for kaldi io (by ymz) --- kaldi_io/src/tools/ATLAS/include/atlas_altivec.h | 27 + kaldi_io/src/tools/ATLAS/include/atlas_asm.h | 411 ++ kaldi_io/src/tools/ATLAS/include/atlas_aux.h | 785 +++ .../src/tools/ATLAS/include/atlas_cblascalias.h | 40 + .../src/tools/ATLAS/include/atlas_cblasdalias.h | 39 + .../src/tools/ATLAS/include/atlas_cblassalias.h | 39 + .../src/tools/ATLAS/include/atlas_cblastypealias.h | 9 + .../src/tools/ATLAS/include/atlas_cblaszalias.h | 40 + kaldi_io/src/tools/ATLAS/include/atlas_enum.h | 55 + kaldi_io/src/tools/ATLAS/include/atlas_f77.h | 83 + kaldi_io/src/tools/ATLAS/include/atlas_f77blas.h | 849 +++ kaldi_io/src/tools/ATLAS/include/atlas_f77wrap.h | 1088 ++++ kaldi_io/src/tools/ATLAS/include/atlas_fopen.h | 40 + kaldi_io/src/tools/ATLAS/include/atlas_kern3.h | 110 + kaldi_io/src/tools/ATLAS/include/atlas_kernel2.h | 5408 ++++++++++++++++++++ kaldi_io/src/tools/ATLAS/include/atlas_kernel3.h | 1393 +++++ kaldi_io/src/tools/ATLAS/include/atlas_lapack.h | 239 + kaldi_io/src/tools/ATLAS/include/atlas_level1.h | 127 + kaldi_io/src/tools/ATLAS/include/atlas_level2.h | 267 + kaldi_io/src/tools/ATLAS/include/atlas_level3.h | 181 + kaldi_io/src/tools/ATLAS/include/atlas_lvl2.h | 294 ++ kaldi_io/src/tools/ATLAS/include/atlas_lvl3.h | 512 ++ kaldi_io/src/tools/ATLAS/include/atlas_misc.h | 416 ++ kaldi_io/src/tools/ATLAS/include/atlas_mv.h | 45 + kaldi_io/src/tools/ATLAS/include/atlas_pkblas.h | 569 ++ kaldi_io/src/tools/ATLAS/include/atlas_prefetch.h | 197 + kaldi_io/src/tools/ATLAS/include/atlas_ptalias1.h | 60 + kaldi_io/src/tools/ATLAS/include/atlas_ptalias2.h | 80 + kaldi_io/src/tools/ATLAS/include/atlas_ptalias3.h | 43 + kaldi_io/src/tools/ATLAS/include/atlas_ptlevel3.h | 284 + kaldi_io/src/tools/ATLAS/include/atlas_ptlvl3.h | 389 ++ kaldi_io/src/tools/ATLAS/include/atlas_ptmisc.h | 410 ++ kaldi_io/src/tools/ATLAS/include/atlas_r1.h | 39 + kaldi_io/src/tools/ATLAS/include/atlas_rblas3.h | 474 ++ kaldi_io/src/tools/ATLAS/include/atlas_refalias1.h | 59 + kaldi_io/src/tools/ATLAS/include/atlas_refalias2.h | 79 + kaldi_io/src/tools/ATLAS/include/atlas_refalias3.h | 43 + kaldi_io/src/tools/ATLAS/include/atlas_reflevel1.h | 421 ++ kaldi_io/src/tools/ATLAS/include/atlas_reflevel2.h | 788 +++ kaldi_io/src/tools/ATLAS/include/atlas_reflevel3.h | 374 ++ kaldi_io/src/tools/ATLAS/include/atlas_reflvl2.h | 3184 ++++++++++++ kaldi_io/src/tools/ATLAS/include/atlas_reflvl3.h | 2292 +++++++++ kaldi_io/src/tools/ATLAS/include/atlas_refmisc.h | 367 ++ kaldi_io/src/tools/ATLAS/include/atlas_tst.h | 909 ++++ kaldi_io/src/tools/ATLAS/include/cblas.h | 596 +++ kaldi_io/src/tools/ATLAS/include/cblas_test.h | 542 ++ kaldi_io/src/tools/ATLAS/include/clapack.h | 149 + .../tools/ATLAS/include/contrib/ATL_gemv_ger_SSE.h | 188 + kaldi_io/src/tools/ATLAS/include/contrib/Make.ext | 39 + .../src/tools/ATLAS/include/contrib/SSE3Dnow.h | 709 +++ .../src/tools/ATLAS/include/contrib/camm_dpa.h | 1626 ++++++ .../src/tools/ATLAS/include/contrib/camm_pipe3.h | 295 ++ .../src/tools/ATLAS/include/contrib/camm_scale.h | 215 + .../src/tools/ATLAS/include/contrib/camm_strat1.h | 2982 +++++++++++ .../src/tools/ATLAS/include/contrib/camm_tpipe.h | 331 ++ .../src/tools/ATLAS/include/contrib/camm_util.h | 508 ++ kaldi_io/src/tools/ATLAS/include/f77wrap_lapack.h | 91 + .../src/tools/openfst/include/fst/accumulator.h | 745 +++ kaldi_io/src/tools/openfst/include/fst/add-on.h | 306 ++ kaldi_io/src/tools/openfst/include/fst/arc-map.h | 1146 +++++ kaldi_io/src/tools/openfst/include/fst/arc.h | 307 ++ kaldi_io/src/tools/openfst/include/fst/arcfilter.h | 99 + kaldi_io/src/tools/openfst/include/fst/arcsort.h | 217 + kaldi_io/src/tools/openfst/include/fst/bi-table.h | 532 ++ kaldi_io/src/tools/openfst/include/fst/cache.h | 861 ++++ kaldi_io/src/tools/openfst/include/fst/closure.h | 155 + .../src/tools/openfst/include/fst/compact-fst.h | 1438 ++++++ kaldi_io/src/tools/openfst/include/fst/compat.h | 131 + .../src/tools/openfst/include/fst/complement.h | 338 ++ .../src/tools/openfst/include/fst/compose-filter.h | 542 ++ kaldi_io/src/tools/openfst/include/fst/compose.h | 728 +++ kaldi_io/src/tools/openfst/include/fst/concat.h | 246 + kaldi_io/src/tools/openfst/include/fst/config.h | 12 + kaldi_io/src/tools/openfst/include/fst/connect.h | 319 ++ kaldi_io/src/tools/openfst/include/fst/const-fst.h | 497 ++ .../src/tools/openfst/include/fst/determinize.h | 1015 ++++ kaldi_io/src/tools/openfst/include/fst/dfs-visit.h | 205 + .../src/tools/openfst/include/fst/difference.h | 189 + kaldi_io/src/tools/openfst/include/fst/edit-fst.h | 779 +++ kaldi_io/src/tools/openfst/include/fst/encode.h | 599 +++ .../src/tools/openfst/include/fst/epsnormalize.h | 73 + kaldi_io/src/tools/openfst/include/fst/equal.h | 124 + .../src/tools/openfst/include/fst/equivalent.h | 275 + .../src/tools/openfst/include/fst/expanded-fst.h | 189 + .../tools/openfst/include/fst/expectation-weight.h | 142 + .../include/fst/extensions/far/compile-strings.h | 304 ++ .../openfst/include/fst/extensions/far/create.h | 87 + .../openfst/include/fst/extensions/far/equal.h | 99 + .../openfst/include/fst/extensions/far/extract.h | 140 + .../tools/openfst/include/fst/extensions/far/far.h | 532 ++ .../openfst/include/fst/extensions/far/farlib.h | 31 + .../openfst/include/fst/extensions/far/farscript.h | 273 + .../openfst/include/fst/extensions/far/info.h | 128 + .../openfst/include/fst/extensions/far/main.h | 43 + .../include/fst/extensions/far/print-strings.h | 138 + .../openfst/include/fst/extensions/far/stlist.h | 305 ++ .../openfst/include/fst/extensions/far/sttable.h | 371 ++ .../include/fst/extensions/ngram/bitmap-index.h | 183 + .../include/fst/extensions/ngram/ngram-fst.h | 934 ++++ .../openfst/include/fst/extensions/ngram/nthbit.h | 46 + .../src/tools/openfst/include/fst/factor-weight.h | 475 ++ kaldi_io/src/tools/openfst/include/fst/flags.h | 242 + .../src/tools/openfst/include/fst/float-weight.h | 601 +++ kaldi_io/src/tools/openfst/include/fst/fst-decl.h | 124 + kaldi_io/src/tools/openfst/include/fst/fst.h | 949 ++++ kaldi_io/src/tools/openfst/include/fst/fstlib.h | 153 + .../tools/openfst/include/fst/generic-register.h | 159 + kaldi_io/src/tools/openfst/include/fst/heap.h | 206 + kaldi_io/src/tools/openfst/include/fst/icu.h | 116 + kaldi_io/src/tools/openfst/include/fst/intersect.h | 172 + .../src/tools/openfst/include/fst/interval-set.h | 381 ++ kaldi_io/src/tools/openfst/include/fst/invert.h | 125 + .../tools/openfst/include/fst/label-reachable.h | 565 ++ .../openfst/include/fst/lexicographic-weight.h | 151 + kaldi_io/src/tools/openfst/include/fst/lock.h | 100 + kaldi_io/src/tools/openfst/include/fst/log.h | 66 + .../tools/openfst/include/fst/lookahead-filter.h | 698 +++ .../tools/openfst/include/fst/lookahead-matcher.h | 812 +++ kaldi_io/src/tools/openfst/include/fst/map.h | 121 + .../src/tools/openfst/include/fst/mapped-file.h | 83 + .../src/tools/openfst/include/fst/matcher-fst.h | 359 ++ kaldi_io/src/tools/openfst/include/fst/matcher.h | 1205 +++++ kaldi_io/src/tools/openfst/include/fst/minimize.h | 591 +++ .../src/tools/openfst/include/fst/mutable-fst.h | 378 ++ .../src/tools/openfst/include/fst/pair-weight.h | 280 + kaldi_io/src/tools/openfst/include/fst/partition.h | 305 ++ .../src/tools/openfst/include/fst/power-weight.h | 159 + .../src/tools/openfst/include/fst/product-weight.h | 115 + kaldi_io/src/tools/openfst/include/fst/project.h | 148 + .../src/tools/openfst/include/fst/properties.h | 460 ++ kaldi_io/src/tools/openfst/include/fst/prune.h | 339 ++ kaldi_io/src/tools/openfst/include/fst/push.h | 175 + kaldi_io/src/tools/openfst/include/fst/queue.h | 938 ++++ .../src/tools/openfst/include/fst/randequivalent.h | 135 + kaldi_io/src/tools/openfst/include/fst/randgen.h | 712 +++ .../src/tools/openfst/include/fst/random-weight.h | 348 ++ kaldi_io/src/tools/openfst/include/fst/rational.h | 330 ++ kaldi_io/src/tools/openfst/include/fst/register.h | 133 + kaldi_io/src/tools/openfst/include/fst/relabel.h | 528 ++ .../src/tools/openfst/include/fst/replace-util.h | 550 ++ kaldi_io/src/tools/openfst/include/fst/replace.h | 1453 ++++++ kaldi_io/src/tools/openfst/include/fst/reverse.h | 91 + kaldi_io/src/tools/openfst/include/fst/reweight.h | 146 + kaldi_io/src/tools/openfst/include/fst/rmepsilon.h | 600 +++ .../src/tools/openfst/include/fst/rmfinalepsilon.h | 107 + .../src/tools/openfst/include/fst/script/arcsort.h | 49 + .../tools/openfst/include/fst/script/arg-packs.h | 240 + .../src/tools/openfst/include/fst/script/closure.h | 41 + .../openfst/include/fst/script/compile-impl.h | 216 + .../src/tools/openfst/include/fst/script/compile.h | 92 + .../src/tools/openfst/include/fst/script/compose.h | 63 + .../src/tools/openfst/include/fst/script/concat.h | 54 + .../src/tools/openfst/include/fst/script/connect.h | 45 + .../src/tools/openfst/include/fst/script/convert.h | 49 + .../src/tools/openfst/include/fst/script/decode.h | 46 + .../tools/openfst/include/fst/script/determinize.h | 68 + .../tools/openfst/include/fst/script/difference.h | 67 + .../openfst/include/fst/script/disambiguate.h | 68 + .../tools/openfst/include/fst/script/draw-impl.h | 234 + .../src/tools/openfst/include/fst/script/draw.h | 114 + .../src/tools/openfst/include/fst/script/encode.h | 58 + .../openfst/include/fst/script/epsnormalize.h | 44 + .../src/tools/openfst/include/fst/script/equal.h | 45 + .../tools/openfst/include/fst/script/equivalent.h | 47 + .../tools/openfst/include/fst/script/fst-class.h | 382 ++ .../openfst/include/fst/script/fstscript-decl.h | 35 + .../tools/openfst/include/fst/script/fstscript.h | 154 + .../tools/openfst/include/fst/script/info-impl.h | 325 ++ .../src/tools/openfst/include/fst/script/info.h | 48 + .../tools/openfst/include/fst/script/intersect.h | 65 + .../src/tools/openfst/include/fst/script/invert.h | 43 + .../src/tools/openfst/include/fst/script/map.h | 123 + .../tools/openfst/include/fst/script/minimize.h | 45 + .../tools/openfst/include/fst/script/print-impl.h | 149 + .../src/tools/openfst/include/fst/script/print.h | 86 + .../src/tools/openfst/include/fst/script/project.h | 43 + .../src/tools/openfst/include/fst/script/prune.h | 153 + .../src/tools/openfst/include/fst/script/push.h | 70 + .../openfst/include/fst/script/randequivalent.h | 105 + .../src/tools/openfst/include/fst/script/randgen.h | 76 + .../tools/openfst/include/fst/script/register.h | 120 + .../src/tools/openfst/include/fst/script/relabel.h | 102 + .../src/tools/openfst/include/fst/script/replace.h | 62 + .../src/tools/openfst/include/fst/script/reverse.h | 42 + .../tools/openfst/include/fst/script/reweight.h | 53 + .../tools/openfst/include/fst/script/rmepsilon.h | 211 + .../tools/openfst/include/fst/script/script-impl.h | 206 + .../openfst/include/fst/script/shortest-distance.h | 250 + .../openfst/include/fst/script/shortest-path.h | 190 + .../src/tools/openfst/include/fst/script/symbols.h | 20 + .../tools/openfst/include/fst/script/synchronize.h | 42 + .../src/tools/openfst/include/fst/script/text-io.h | 51 + .../src/tools/openfst/include/fst/script/topsort.h | 40 + .../src/tools/openfst/include/fst/script/union.h | 42 + .../src/tools/openfst/include/fst/script/verify.h | 40 + .../openfst/include/fst/script/weight-class.h | 223 + .../tools/openfst/include/fst/shortest-distance.h | 348 ++ .../src/tools/openfst/include/fst/shortest-path.h | 501 ++ .../tools/openfst/include/fst/signed-log-weight.h | 367 ++ kaldi_io/src/tools/openfst/include/fst/slist.h | 61 + .../openfst/include/fst/sparse-power-weight.h | 225 + .../openfst/include/fst/sparse-tuple-weight.h | 640 +++ kaldi_io/src/tools/openfst/include/fst/state-map.h | 605 +++ .../tools/openfst/include/fst/state-reachable.h | 198 + .../src/tools/openfst/include/fst/state-table.h | 481 ++ kaldi_io/src/tools/openfst/include/fst/statesort.h | 97 + .../src/tools/openfst/include/fst/string-weight.h | 560 ++ kaldi_io/src/tools/openfst/include/fst/string.h | 271 + .../tools/openfst/include/fst/symbol-table-ops.h | 91 + .../src/tools/openfst/include/fst/symbol-table.h | 537 ++ .../src/tools/openfst/include/fst/synchronize.h | 457 ++ .../tools/openfst/include/fst/test-properties.h | 250 + kaldi_io/src/tools/openfst/include/fst/topsort.h | 112 + .../src/tools/openfst/include/fst/tuple-weight.h | 332 ++ kaldi_io/src/tools/openfst/include/fst/types.h | 38 + .../src/tools/openfst/include/fst/union-find.h | 110 + kaldi_io/src/tools/openfst/include/fst/union.h | 185 + kaldi_io/src/tools/openfst/include/fst/util.h | 437 ++ .../src/tools/openfst/include/fst/vector-fst.h | 731 +++ kaldi_io/src/tools/openfst/include/fst/verify.h | 126 + kaldi_io/src/tools/openfst/include/fst/visit.h | 284 + kaldi_io/src/tools/openfst/include/fst/weight.h | 179 + 222 files changed, 77995 insertions(+) create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_altivec.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_asm.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_aux.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_cblascalias.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_cblasdalias.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_cblassalias.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_cblastypealias.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_cblaszalias.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_enum.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_f77.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_f77blas.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_f77wrap.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_fopen.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_kern3.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_kernel2.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_kernel3.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_lapack.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_level1.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_level2.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_level3.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_lvl2.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_lvl3.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_misc.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_mv.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_pkblas.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_prefetch.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_ptalias1.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_ptalias2.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_ptalias3.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_ptlevel3.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_ptlvl3.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_ptmisc.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_r1.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_rblas3.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_refalias1.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_refalias2.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_refalias3.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_reflevel1.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_reflevel2.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_reflevel3.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_reflvl2.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_reflvl3.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_refmisc.h create mode 100644 kaldi_io/src/tools/ATLAS/include/atlas_tst.h create mode 100644 kaldi_io/src/tools/ATLAS/include/cblas.h create mode 100644 kaldi_io/src/tools/ATLAS/include/cblas_test.h create mode 100644 kaldi_io/src/tools/ATLAS/include/clapack.h create mode 100644 kaldi_io/src/tools/ATLAS/include/contrib/ATL_gemv_ger_SSE.h create mode 100644 kaldi_io/src/tools/ATLAS/include/contrib/Make.ext create mode 100644 kaldi_io/src/tools/ATLAS/include/contrib/SSE3Dnow.h create mode 100644 kaldi_io/src/tools/ATLAS/include/contrib/camm_dpa.h create mode 100644 kaldi_io/src/tools/ATLAS/include/contrib/camm_pipe3.h create mode 100644 kaldi_io/src/tools/ATLAS/include/contrib/camm_scale.h create mode 100644 kaldi_io/src/tools/ATLAS/include/contrib/camm_strat1.h create mode 100644 kaldi_io/src/tools/ATLAS/include/contrib/camm_tpipe.h create mode 100644 kaldi_io/src/tools/ATLAS/include/contrib/camm_util.h create mode 100644 kaldi_io/src/tools/ATLAS/include/f77wrap_lapack.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/accumulator.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/add-on.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/arc-map.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/arc.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/arcfilter.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/arcsort.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/bi-table.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/cache.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/closure.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/compact-fst.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/compat.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/complement.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/compose-filter.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/compose.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/concat.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/config.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/connect.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/const-fst.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/determinize.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/dfs-visit.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/difference.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/edit-fst.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/encode.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/epsnormalize.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/equal.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/equivalent.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/expanded-fst.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/expectation-weight.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/extensions/far/compile-strings.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/extensions/far/create.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/extensions/far/equal.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/extensions/far/extract.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/extensions/far/far.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/extensions/far/farlib.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/extensions/far/farscript.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/extensions/far/info.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/extensions/far/main.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/extensions/far/print-strings.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/extensions/far/stlist.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/extensions/far/sttable.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/extensions/ngram/bitmap-index.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/extensions/ngram/ngram-fst.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/extensions/ngram/nthbit.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/factor-weight.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/flags.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/float-weight.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/fst-decl.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/fst.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/fstlib.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/generic-register.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/heap.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/icu.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/intersect.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/interval-set.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/invert.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/label-reachable.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/lexicographic-weight.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/lock.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/log.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/lookahead-filter.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/lookahead-matcher.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/map.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/mapped-file.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/matcher-fst.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/matcher.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/minimize.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/mutable-fst.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/pair-weight.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/partition.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/power-weight.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/product-weight.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/project.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/properties.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/prune.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/push.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/queue.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/randequivalent.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/randgen.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/random-weight.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/rational.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/register.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/relabel.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/replace-util.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/replace.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/reverse.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/reweight.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/rmepsilon.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/rmfinalepsilon.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/arcsort.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/arg-packs.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/closure.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/compile-impl.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/compile.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/compose.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/concat.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/connect.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/convert.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/decode.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/determinize.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/difference.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/disambiguate.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/draw-impl.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/draw.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/encode.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/epsnormalize.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/equal.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/equivalent.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/fst-class.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/fstscript-decl.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/fstscript.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/info-impl.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/info.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/intersect.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/invert.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/map.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/minimize.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/print-impl.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/print.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/project.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/prune.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/push.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/randequivalent.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/randgen.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/register.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/relabel.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/replace.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/reverse.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/reweight.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/rmepsilon.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/script-impl.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/shortest-distance.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/shortest-path.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/symbols.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/synchronize.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/text-io.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/topsort.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/union.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/verify.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/script/weight-class.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/shortest-distance.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/shortest-path.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/signed-log-weight.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/slist.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/sparse-power-weight.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/sparse-tuple-weight.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/state-map.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/state-reachable.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/state-table.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/statesort.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/string-weight.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/string.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/symbol-table-ops.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/symbol-table.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/synchronize.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/test-properties.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/topsort.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/tuple-weight.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/types.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/union-find.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/union.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/util.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/vector-fst.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/verify.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/visit.h create mode 100644 kaldi_io/src/tools/openfst/include/fst/weight.h (limited to 'kaldi_io/src/tools') diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_altivec.h b/kaldi_io/src/tools/ATLAS/include/atlas_altivec.h new file mode 100644 index 0000000..a772448 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_altivec.h @@ -0,0 +1,27 @@ +#ifndef ATLAS_ALTIVEC_H + #define ATLAS_ALTIVEC_H + +#ifdef ATL_AltiVec + #ifdef ATL_AVgcc + #include + + #define VECTOR_INIT(v0_,v1_,v2_,v3_) (vector float) {v0_,v1_,v2_,v3_} + #define VECTOR_INITI(v0_,v1_,v2_,v3_) (vector int) {v0_,v1_,v2_,v3_} + #else + #define VECTOR_INIT(v0_,v1_,v2_,v3_) (vector float)(v0_,v1_,v2_,v3_) + #define VECTOR_INITI(v0_,v1_,v2_,v3_) (vector int)(v0_,v1_,v2_,v3_) + #define VECTOR_INITL(v0_,v1_,v2_,v3_) (vector long)(v0_,v1_,v2_,v3_) + #endif + #define ATL_GetCtrl(stride, count, size) \ + (int)((stride) | ((count)<<16) | ((size)<<24)) + #define ATL_pfavR(ptr, cwrd, stream) \ + vec_dst((vector float *)(ptr), (cwrd), (stream)) + #define ATL_pfavW(ptr, cwrd, stream) \ + vec_dstst((vector float *)(ptr), (cwrd), (stream)) +#else + #define ATL_GetCtrl(stride, count, size) + #define ATL_pfavR(ptr, cwrd, stream) + #define ATL_pfavW(ptr, cwrd, stream) +#endif + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_asm.h b/kaldi_io/src/tools/ATLAS/include/atlas_asm.h new file mode 100644 index 0000000..4c4fa86 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_asm.h @@ -0,0 +1,411 @@ +#ifndef ATLAS_ASM_H + #define ATLAS_ASM_H + +#ifndef Mjoin + #define Mjoin(pre, nam) my_join(pre, nam) + #define my_join(pre, nam) pre ## nam +#endif + +#if defined(ATL_OS_WinNT) || defined(ATL_OS_Win9x) || defined(ATL_OS_OSX) + #define ATL_asmdecor(nam) Mjoin(_,nam) +#elif defined(ATL_OS_AIX) && defined(ATL_GAS_PPC) + #define ATL_asmdecor(nam) Mjoin(.,nam) +#elif !defined(ATL_OS_OSX) && defined(ATL_GAS_PPC) && defined(ATL_USE64BITS) + #define ATL_asmdecor(nam) Mjoin(.,nam) +#else + #define ATL_asmdecor(nam) nam +#endif + +#ifdef ATL_GAS_PARISC + #ifdef ATL_OS_HPUX + #define ATL_HPUX_PARISC + #else + #define ATL_LINUX_PARISC + #endif +#endif + +#ifdef ATL_GAS_PPC + #ifdef ATL_OS_OSX + #define ATL_AS_OSX_PPC + #elif defined(ATL_OS_AIX) + #define ATL_AS_AIX_PPC + #else + #define ATL_GAS_LINUX_PPC + #endif +#endif + +#if defined(ATL_GAS_LINUX_PPC) || defined(ATL_AS_AIX_PPC) + + #define r0 0 + #define f0 0 + #define r1 1 + #define f1 1 + #define r2 2 + #define f2 2 + #define r3 3 + #define f3 3 + #define r4 4 + #define f4 4 + #define r5 5 + #define f5 5 + #define r6 6 + #define f6 6 + #define r7 7 + #define f7 7 + #define r8 8 + #define f8 8 + #define r9 9 + #define f9 9 + #define r10 10 + #define f10 10 + #define r11 11 + #define f11 11 + #define r12 12 + #define f12 12 + #define r13 13 + #define f13 13 + #define r14 14 + #define f14 14 + #define r15 15 + #define f15 15 + #define r16 16 + #define f16 16 + #define r17 17 + #define f17 17 + #define r18 18 + #define f18 18 + #define r19 19 + #define f19 19 + #define r20 20 + #define f20 20 + #define r21 21 + #define f21 21 + #define r22 22 + #define f22 22 + #define r23 23 + #define f23 23 + #define r24 24 + #define f24 24 + #define r25 25 + #define f25 25 + #define r26 26 + #define f26 26 + #define r27 27 + #define f27 27 + #define r28 28 + #define f28 28 + #define r29 29 + #define f29 29 + #define r30 30 + #define f30 30 + #define r31 31 + #define f31 31 + #define cr0 0 + #define cr1 1 + #define cr2 2 + #define cr3 3 + #define cr4 4 + #define cr5 5 + #define cr6 6 + #define cr7 7 + +#endif + +#ifdef ATL_OS_OSX + #define ALIGN2 .align 1 + #define ALIGN4 .align 2 + #define ALIGN8 .align 3 + #define ALIGN16 .align 4 + #define ALIGN32 .align 5 + #define ALIGN64 .align 6 + #define ALIGN128 .align 7 + #define global globl +#else + #define ALIGN2 .align 2 + #define ALIGN4 .align 4 + #define ALIGN8 .align 8 + #define ALIGN16 .align 16 + #define ALIGN32 .align 32 + #define ALIGN64 .align 64 + #define ALIGN128 .align 128 +#endif + +#if defined(ATL_SSE1) && !defined(ATL_3DNow) + #define prefetchw prefetchnta +#endif +/* + * Solaris doesn't allow division in integer expressions in assembly, but + * many x86 kernels need to do $MB/mu; we work around this insanity with + * this kludge + */ +#if defined(ATL_DIV_NUM) && defined(ATL_DIV_DEN) + #if (ATL_DIV_NUM/ATL_DIV_DEN) == 0 + #define ATL_DivAns 0 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 1 + #define ATL_DivAns 1 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 2 + #define ATL_DivAns 2 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 3 + #define ATL_DivAns 3 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 4 + #define ATL_DivAns 4 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 5 + #define ATL_DivAns 5 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 6 + #define ATL_DivAns 6 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 7 + #define ATL_DivAns 7 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 8 + #define ATL_DivAns 8 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 9 + #define ATL_DivAns 9 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 10 + #define ATL_DivAns 10 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 11 + #define ATL_DivAns 11 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 12 + #define ATL_DivAns 12 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 13 + #define ATL_DivAns 13 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 14 + #define ATL_DivAns 14 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 15 + #define ATL_DivAns 15 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 16 + #define ATL_DivAns 16 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 17 + #define ATL_DivAns 17 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 18 + #define ATL_DivAns 18 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 19 + #define ATL_DivAns 19 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 20 + #define ATL_DivAns 20 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 21 + #define ATL_DivAns 21 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 22 + #define ATL_DivAns 22 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 23 + #define ATL_DivAns 23 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 24 + #define ATL_DivAns 24 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 25 + #define ATL_DivAns 25 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 26 + #define ATL_DivAns 26 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 27 + #define ATL_DivAns 27 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 28 + #define ATL_DivAns 28 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 29 + #define ATL_DivAns 29 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 30 + #define ATL_DivAns 30 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 31 + #define ATL_DivAns 31 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 32 + #define ATL_DivAns 32 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 33 + #define ATL_DivAns 33 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 34 + #define ATL_DivAns 34 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 35 + #define ATL_DivAns 35 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 36 + #define ATL_DivAns 36 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 37 + #define ATL_DivAns 37 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 38 + #define ATL_DivAns 38 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 39 + #define ATL_DivAns 39 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 40 + #define ATL_DivAns 40 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 41 + #define ATL_DivAns 41 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 42 + #define ATL_DivAns 42 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 43 + #define ATL_DivAns 43 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 44 + #define ATL_DivAns 44 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 45 + #define ATL_DivAns 45 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 46 + #define ATL_DivAns 46 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 47 + #define ATL_DivAns 47 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 48 + #define ATL_DivAns 48 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 49 + #define ATL_DivAns 49 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 50 + #define ATL_DivAns 50 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 51 + #define ATL_DivAns 51 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 52 + #define ATL_DivAns 52 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 53 + #define ATL_DivAns 53 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 54 + #define ATL_DivAns 54 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 55 + #define ATL_DivAns 55 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 56 + #define ATL_DivAns 56 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 57 + #define ATL_DivAns 57 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 58 + #define ATL_DivAns 58 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 59 + #define ATL_DivAns 59 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 60 + #define ATL_DivAns 60 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 61 + #define ATL_DivAns 61 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 62 + #define ATL_DivAns 62 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 63 + #define ATL_DivAns 63 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 64 + #define ATL_DivAns 64 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 65 + #define ATL_DivAns 65 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 66 + #define ATL_DivAns 66 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 67 + #define ATL_DivAns 67 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 68 + #define ATL_DivAns 68 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 69 + #define ATL_DivAns 69 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 70 + #define ATL_DivAns 70 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 71 + #define ATL_DivAns 71 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 72 + #define ATL_DivAns 72 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 73 + #define ATL_DivAns 73 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 74 + #define ATL_DivAns 74 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 75 + #define ATL_DivAns 75 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 76 + #define ATL_DivAns 76 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 77 + #define ATL_DivAns 77 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 78 + #define ATL_DivAns 78 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 79 + #define ATL_DivAns 79 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 80 + #define ATL_DivAns 80 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 81 + #define ATL_DivAns 81 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 82 + #define ATL_DivAns 82 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 83 + #define ATL_DivAns 83 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 84 + #define ATL_DivAns 84 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 85 + #define ATL_DivAns 85 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 86 + #define ATL_DivAns 86 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 87 + #define ATL_DivAns 87 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 88 + #define ATL_DivAns 88 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 89 + #define ATL_DivAns 89 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 90 + #define ATL_DivAns 90 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 91 + #define ATL_DivAns 91 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 92 + #define ATL_DivAns 92 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 93 + #define ATL_DivAns 93 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 94 + #define ATL_DivAns 94 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 95 + #define ATL_DivAns 95 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 96 + #define ATL_DivAns 96 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 97 + #define ATL_DivAns 97 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 98 + #define ATL_DivAns 98 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 99 + #define ATL_DivAns 99 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 100 + #define ATL_DivAns 100 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 101 + #define ATL_DivAns 101 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 102 + #define ATL_DivAns 102 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 103 + #define ATL_DivAns 103 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 104 + #define ATL_DivAns 104 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 105 + #define ATL_DivAns 105 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 106 + #define ATL_DivAns 106 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 107 + #define ATL_DivAns 107 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 108 + #define ATL_DivAns 108 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 109 + #define ATL_DivAns 109 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 110 + #define ATL_DivAns 110 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 111 + #define ATL_DivAns 111 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 112 + #define ATL_DivAns 112 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 113 + #define ATL_DivAns 113 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 114 + #define ATL_DivAns 114 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 115 + #define ATL_DivAns 115 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 116 + #define ATL_DivAns 116 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 117 + #define ATL_DivAns 117 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 118 + #define ATL_DivAns 118 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 119 + #define ATL_DivAns 119 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 120 + #define ATL_DivAns 120 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 121 + #define ATL_DivAns 121 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 122 + #define ATL_DivAns 122 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 123 + #define ATL_DivAns 123 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 124 + #define ATL_DivAns 124 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 125 + #define ATL_DivAns 125 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 126 + #define ATL_DivAns 126 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 127 + #define ATL_DivAns 127 + #elif (ATL_DIV_NUM/ATL_DIV_DEN) == 128 + #define ATL_DivAns 128 + #endif +#endif + +/* + * For GNU/Linux, set no-execute bit for all ATLAS assembly + */ +#if defined(ATL_OS_Linux) && defined(__ELF__) && defined(__GNUC__) && \ + defined(ATL_SSE1) +.section .note.GNU-stack,"",%progbits +#endif + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_aux.h b/kaldi_io/src/tools/ATLAS/include/atlas_aux.h new file mode 100644 index 0000000..ce31eee --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_aux.h @@ -0,0 +1,785 @@ +/* + * Automatically Tuned Linear Algebra Software v3.8.3 + * (C) Copyright 1999 R. Clint Whaley + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the ATLAS group or the names of its contributers may + * not be used to endorse or promote products derived from this + * software without specific written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +/* + * Header file for ATLAS's auxiliary routines + */ +#ifndef ATLAS_AUX_H +#define ATLAS_AUX_H +#include "atlas_misc.h" + +void ATL_xerbla(int p, char *rout, char *form, ...); +int ATL_lcm(const int M, const int N); +double ATL_walltime(); +double ATL_cputime(); + +/* + * Auxiliary routines that come in all four types + */ +void ATL_sgeadd(const int M, const int N, const float alpha, + const float *A, const int lda, const float beta, + float *C, const int ldc); +void ATL_sgemove(const int M, const int N, const float alpha, + const float *A, const int lda, float *C, const int ldc); +void ATL_sgemoveT(const int N, const int M, const float alpha, + const float *A, const int lda, float *C, const int ldc); +void ATL_ssyreflect(const enum ATLAS_UPLO Uplo, const int N, + float *C, const int ldc); +void ATL_sgecopy(const int M, const int N, const float *A, const int lda, + float *C, const int ldc); + +void ATL_sgescal(const int M, const int N, const float beta, + float *C, const int ldc); +void ATL_strscal + (const enum ATLAS_UPLO Uplo, const int M, const int N, const float alpha, + float *A, const int lda); +void ATL_shescal + (const enum ATLAS_UPLO Uplo, const int M, const int N, const float alpha, + float *A, const int lda); + +void ATL_sgezero(const int M, const int N, float *C, const int ldc); + +void ATL_szero(const int N, float *X, const int incX); +void ATL_sset(const int N, const float alpha, float *X, const int incX); +void ATL_sscal(const int N, const float alpha, float *X, const int incX); +void ATL_scopy(const int N, const float *X, const int incX, + float *Y, const int incY); +void ATL_scpsc(const int N, const float alpha, const float *X, + const int incX, float *Y, const int incY); +void ATL_saxpy(const int N, const float alpha, const float *X, + const int incX, float *Y, const int incY); +void ATL_saxpy_x1_y1(const int N, const float alpha, const float *X, + const int incX, float *Y, const int incY); +void ATL_saxpby(const int N, const float alpha, const float *X, + const int incX, const float beta, float *Y, const int incY); + +void ATL_sgeadd_a1_b1 + (const int M, const int N, const float alpha, const float *A, + const int lda, const float beta, float *C, const int ldc); +void ATL_saxpby_a1_b1 + (const int N, const float alpha, const float *X, const int incX, + const float beta, float *Y, const int incY); +void ATL_sgeadd_a0_b1 + (const int M, const int N, const float alpha, const float *A, + const int lda, const float beta, float *C, const int ldc); +void ATL_saxpby_a0_b1 + (const int N, const float alpha, const float *X, const int incX, + const float beta, float *Y, const int incY); +void ATL_sgeadd_aX_b1 + (const int M, const int N, const float alpha, const float *A, + const int lda, const float beta, float *C, const int ldc); +void ATL_saxpby_aX_b1 + (const int N, const float alpha, const float *X, const int incX, + const float beta, float *Y, const int incY); +void ATL_sgeadd_a1_b0 + (const int M, const int N, const float alpha, const float *A, + const int lda, const float beta, float *C, const int ldc); +void ATL_saxpby_a1_b0 + (const int N, const float alpha, const float *X, const int incX, + const float beta, float *Y, const int incY); +void ATL_sgeadd_a0_b0 + (const int M, const int N, const float alpha, const float *A, + const int lda, const float beta, float *C, const int ldc); +void ATL_saxpby_a0_b0 + (const int N, const float alpha, const float *X, const int incX, + const float beta, float *Y, const int incY); +void ATL_sgeadd_aX_b0 + (const int M, const int N, const float alpha, const float *A, + const int lda, const float beta, float *C, const int ldc); +void ATL_saxpby_aX_b0 + (const int N, const float alpha, const float *X, const int incX, + const float beta, float *Y, const int incY); +void ATL_sgeadd_a1_bX + (const int M, const int N, const float alpha, const float *A, + const int lda, const float beta, float *C, const int ldc); +void ATL_saxpby_a1_bX + (const int N, const float alpha, const float *X, const int incX, + const float beta, float *Y, const int incY); +void ATL_sgeadd_a0_bX + (const int M, const int N, const float alpha, const float *A, + const int lda, const float beta, float *C, const int ldc); +void ATL_saxpby_a0_bX + (const int N, const float alpha, const float *X, const int incX, + const float beta, float *Y, const int incY); +void ATL_sgeadd_aX_bX + (const int M, const int N, const float alpha, const float *A, + const int lda, const float beta, float *C, const int ldc); +void ATL_saxpby_aX_bX + (const int N, const float alpha, const float *X, const int incX, + const float beta, float *Y, const int incY); + +void ATL_sgemove_a1 + (const int M, const int N, const float alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_sgemove_a0 + (const int M, const int N, const float alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_sgemove_aX + (const int M, const int N, const float alpha, const float *A, + const int lda, float *C, const int ldc); + +void ATL_sgescal_b1 + (const int M, const int N, const float beta, float *C, const int ldc); +void ATL_sgescal_b0 + (const int M, const int N, const float beta, float *C, const int ldc); +void ATL_sgescal_bX + (const int M, const int N, const float beta, float *C, const int ldc); + +void ATL_dgeadd(const int M, const int N, const double alpha, + const double *A, const int lda, const double beta, + double *C, const int ldc); +void ATL_dgemove(const int M, const int N, const double alpha, + const double *A, const int lda, double *C, const int ldc); +void ATL_dgemoveT(const int N, const int M, const double alpha, + const double *A, const int lda, double *C, const int ldc); +void ATL_dsyreflect(const enum ATLAS_UPLO Uplo, const int N, + double *C, const int ldc); +void ATL_dgecopy(const int M, const int N, const double *A, const int lda, + double *C, const int ldc); + +void ATL_dgescal(const int M, const int N, const double beta, + double *C, const int ldc); +void ATL_dtrscal + (const enum ATLAS_UPLO Uplo, const int M, const int N, const double alpha, + double *A, const int lda); +void ATL_dhescal + (const enum ATLAS_UPLO Uplo, const int M, const int N, const double alpha, + double *A, const int lda); + +void ATL_dgezero(const int M, const int N, double *C, const int ldc); + +void ATL_dzero(const int N, double *X, const int incX); +void ATL_dset(const int N, const double alpha, double *X, const int incX); +void ATL_dscal(const int N, const double alpha, double *X, const int incX); +void ATL_dcopy(const int N, const double *X, const int incX, + double *Y, const int incY); +void ATL_dcpsc(const int N, const double alpha, const double *X, + const int incX, double *Y, const int incY); +void ATL_daxpy(const int N, const double alpha, const double *X, + const int incX, double *Y, const int incY); +void ATL_daxpy_x1_y1(const int N, const double alpha, const double *X, + const int incX, double *Y, const int incY); +void ATL_daxpby(const int N, const double alpha, const double *X, + const int incX, const double beta, double *Y, const int incY); + +void ATL_dgeadd_a1_b1 + (const int M, const int N, const double alpha, const double *A, + const int lda, const double beta, double *C, const int ldc); +void ATL_daxpby_a1_b1 + (const int N, const double alpha, const double *X, const int incX, + const double beta, double *Y, const int incY); +void ATL_dgeadd_a0_b1 + (const int M, const int N, const double alpha, const double *A, + const int lda, const double beta, double *C, const int ldc); +void ATL_daxpby_a0_b1 + (const int N, const double alpha, const double *X, const int incX, + const double beta, double *Y, const int incY); +void ATL_dgeadd_aX_b1 + (const int M, const int N, const double alpha, const double *A, + const int lda, const double beta, double *C, const int ldc); +void ATL_daxpby_aX_b1 + (const int N, const double alpha, const double *X, const int incX, + const double beta, double *Y, const int incY); +void ATL_dgeadd_a1_b0 + (const int M, const int N, const double alpha, const double *A, + const int lda, const double beta, double *C, const int ldc); +void ATL_daxpby_a1_b0 + (const int N, const double alpha, const double *X, const int incX, + const double beta, double *Y, const int incY); +void ATL_dgeadd_a0_b0 + (const int M, const int N, const double alpha, const double *A, + const int lda, const double beta, double *C, const int ldc); +void ATL_daxpby_a0_b0 + (const int N, const double alpha, const double *X, const int incX, + const double beta, double *Y, const int incY); +void ATL_dgeadd_aX_b0 + (const int M, const int N, const double alpha, const double *A, + const int lda, const double beta, double *C, const int ldc); +void ATL_daxpby_aX_b0 + (const int N, const double alpha, const double *X, const int incX, + const double beta, double *Y, const int incY); +void ATL_dgeadd_a1_bX + (const int M, const int N, const double alpha, const double *A, + const int lda, const double beta, double *C, const int ldc); +void ATL_daxpby_a1_bX + (const int N, const double alpha, const double *X, const int incX, + const double beta, double *Y, const int incY); +void ATL_dgeadd_a0_bX + (const int M, const int N, const double alpha, const double *A, + const int lda, const double beta, double *C, const int ldc); +void ATL_daxpby_a0_bX + (const int N, const double alpha, const double *X, const int incX, + const double beta, double *Y, const int incY); +void ATL_dgeadd_aX_bX + (const int M, const int N, const double alpha, const double *A, + const int lda, const double beta, double *C, const int ldc); +void ATL_daxpby_aX_bX + (const int N, const double alpha, const double *X, const int incX, + const double beta, double *Y, const int incY); + +void ATL_dgemove_a1 + (const int M, const int N, const double alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_dgemove_a0 + (const int M, const int N, const double alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_dgemove_aX + (const int M, const int N, const double alpha, const double *A, + const int lda, double *C, const int ldc); + +void ATL_dgescal_b1 + (const int M, const int N, const double beta, double *C, const int ldc); +void ATL_dgescal_b0 + (const int M, const int N, const double beta, double *C, const int ldc); +void ATL_dgescal_bX + (const int M, const int N, const double beta, double *C, const int ldc); + +void ATL_cgeadd(const int M, const int N, const float *alpha, + const float *A, const int lda, const float *beta, + float *C, const int ldc); +void ATL_cgemove(const int M, const int N, const float *alpha, + const float *A, const int lda, float *C, const int ldc); +void ATL_cgemoveT(const int N, const int M, const float *alpha, + const float *A, const int lda, float *C, const int ldc); +void ATL_csyreflect(const enum ATLAS_UPLO Uplo, const int N, + float *C, const int ldc); +void ATL_cgecopy(const int M, const int N, const float *A, const int lda, + float *C, const int ldc); + +void ATL_cgescal(const int M, const int N, const float *beta, + float *C, const int ldc); +void ATL_ctrscal + (const enum ATLAS_UPLO Uplo, const int M, const int N, const float *alpha, + float *A, const int lda); +void ATL_chescal + (const enum ATLAS_UPLO Uplo, const int M, const int N, const float alpha, + float *A, const int lda); + +void ATL_cgezero(const int M, const int N, float *C, const int ldc); + +void ATL_czero(const int N, float *X, const int incX); +void ATL_cset(const int N, const float *alpha, float *X, const int incX); +void ATL_cscal(const int N, const float *alpha, float *X, const int incX); +void ATL_ccopy(const int N, const float *X, const int incX, + float *Y, const int incY); +void ATL_ccpsc(const int N, const float *alpha, const float *X, + const int incX, float *Y, const int incY); +void ATL_caxpy(const int N, const float *alpha, const float *X, + const int incX, float *Y, const int incY); +void ATL_caxpy_x1_y1(const int N, const float *alpha, const float *X, + const int incX, float *Y, const int incY); +void ATL_caxpby(const int N, const float *alpha, const float *X, + const int incX, const float *beta, float *Y, const int incY); + +void ATL_cgeadd_a1_b1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_caxpby_a1_b1 + (const int N, const float *alpha, const float *X, const int incX, + const float *beta, float *Y, const int incY); +void ATL_cgeadd_a0_b1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_caxpby_a0_b1 + (const int N, const float *alpha, const float *X, const int incX, + const float *beta, float *Y, const int incY); +void ATL_cgeadd_aX_b1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_caxpby_aX_b1 + (const int N, const float *alpha, const float *X, const int incX, + const float *beta, float *Y, const int incY); +void ATL_cgeadd_a1_b0 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_caxpby_a1_b0 + (const int N, const float *alpha, const float *X, const int incX, + const float *beta, float *Y, const int incY); +void ATL_cgeadd_a0_b0 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_caxpby_a0_b0 + (const int N, const float *alpha, const float *X, const int incX, + const float *beta, float *Y, const int incY); +void ATL_cgeadd_aX_b0 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_caxpby_aX_b0 + (const int N, const float *alpha, const float *X, const int incX, + const float *beta, float *Y, const int incY); +void ATL_cgeadd_a1_bX + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_caxpby_a1_bX + (const int N, const float *alpha, const float *X, const int incX, + const float *beta, float *Y, const int incY); +void ATL_cgeadd_a0_bX + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_caxpby_a0_bX + (const int N, const float *alpha, const float *X, const int incX, + const float *beta, float *Y, const int incY); +void ATL_cgeadd_aX_bX + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_caxpby_aX_bX + (const int N, const float *alpha, const float *X, const int incX, + const float *beta, float *Y, const int incY); + +void ATL_cgemove_a1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_cgemove_a0 + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_cgemove_aX + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); + +void ATL_cgescal_b1 + (const int M, const int N, const float *beta, float *C, const int ldc); +void ATL_cgescal_b0 + (const int M, const int N, const float *beta, float *C, const int ldc); +void ATL_cgescal_bX + (const int M, const int N, const float *beta, float *C, const int ldc); + +void ATL_zgeadd(const int M, const int N, const double *alpha, + const double *A, const int lda, const double *beta, + double *C, const int ldc); +void ATL_zgemove(const int M, const int N, const double *alpha, + const double *A, const int lda, double *C, const int ldc); +void ATL_zgemoveT(const int N, const int M, const double *alpha, + const double *A, const int lda, double *C, const int ldc); +void ATL_zsyreflect(const enum ATLAS_UPLO Uplo, const int N, + double *C, const int ldc); +void ATL_zgecopy(const int M, const int N, const double *A, const int lda, + double *C, const int ldc); + +void ATL_zgescal(const int M, const int N, const double *beta, + double *C, const int ldc); +void ATL_ztrscal + (const enum ATLAS_UPLO Uplo, const int M, const int N, const double *alpha, + double *A, const int lda); +void ATL_zhescal + (const enum ATLAS_UPLO Uplo, const int M, const int N, const double alpha, + double *A, const int lda); + +void ATL_zgezero(const int M, const int N, double *C, const int ldc); + +void ATL_zzero(const int N, double *X, const int incX); +void ATL_zset(const int N, const double *alpha, double *X, const int incX); +void ATL_zscal(const int N, const double *alpha, double *X, const int incX); +void ATL_zcopy(const int N, const double *X, const int incX, + double *Y, const int incY); +void ATL_zcpsc(const int N, const double *alpha, const double *X, + const int incX, double *Y, const int incY); +void ATL_zaxpy(const int N, const double *alpha, const double *X, + const int incX, double *Y, const int incY); +void ATL_zaxpy_x1_y1(const int N, const double *alpha, const double *X, + const int incX, double *Y, const int incY); +void ATL_zaxpby(const int N, const double *alpha, const double *X, + const int incX, const double *beta, double *Y, const int incY); + +void ATL_zgeadd_a1_b1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zaxpby_a1_b1 + (const int N, const double *alpha, const double *X, const int incX, + const double *beta, double *Y, const int incY); +void ATL_zgeadd_a0_b1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zaxpby_a0_b1 + (const int N, const double *alpha, const double *X, const int incX, + const double *beta, double *Y, const int incY); +void ATL_zgeadd_aX_b1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zaxpby_aX_b1 + (const int N, const double *alpha, const double *X, const int incX, + const double *beta, double *Y, const int incY); +void ATL_zgeadd_a1_b0 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zaxpby_a1_b0 + (const int N, const double *alpha, const double *X, const int incX, + const double *beta, double *Y, const int incY); +void ATL_zgeadd_a0_b0 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zaxpby_a0_b0 + (const int N, const double *alpha, const double *X, const int incX, + const double *beta, double *Y, const int incY); +void ATL_zgeadd_aX_b0 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zaxpby_aX_b0 + (const int N, const double *alpha, const double *X, const int incX, + const double *beta, double *Y, const int incY); +void ATL_zgeadd_a1_bX + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zaxpby_a1_bX + (const int N, const double *alpha, const double *X, const int incX, + const double *beta, double *Y, const int incY); +void ATL_zgeadd_a0_bX + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zaxpby_a0_bX + (const int N, const double *alpha, const double *X, const int incX, + const double *beta, double *Y, const int incY); +void ATL_zgeadd_aX_bX + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zaxpby_aX_bX + (const int N, const double *alpha, const double *X, const int incX, + const double *beta, double *Y, const int incY); + +void ATL_zgemove_a1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_zgemove_a0 + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_zgemove_aX + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); + +void ATL_zgescal_b1 + (const int M, const int N, const double *beta, double *C, const int ldc); +void ATL_zgescal_b0 + (const int M, const int N, const double *beta, double *C, const int ldc); +void ATL_zgescal_bX + (const int M, const int N, const double *beta, double *C, const int ldc); + +/* + * Specialized complex auxiliary routines + */ + +void ATL_ccplxinvert + (const int N, float *X, const int incX, float *Y, const int incY); + +void ATL_chereflect(const enum ATLAS_UPLO Uplo, const int N, + float *C, const int ldc); +void ATL_cscalConj + (const int N, const float *alpha, float *X, const int incX); +void ATL_ccopyConj + (const int N, const float *X, const int incX, float *Y, const int incY); +void ATL_cmoveConj + (const int N, const float *alpha, const float *X, const int incX, + float *Y, const int incY); +void ATL_caxpyConj + (const int N, const float *alpha, const float *X, const int incX, + float *Y, const int incY); +void ATL_caxpyConj_x1_y1(const int N, const float *alpha, const float *X, + const int incX, float *Y, const int incY); +void ATL_caxpbyConj + (const int N, const float *alpha, const float *X, const int incX, + const float *beta, float *Y, const int incY); +void ATL_cgemoveC(const int N, const int M, const float *alpha, + const float *A, const int lda, float *C, const int ldc); + +void ATL_cgeaddConj_aXi0_b1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_cgeaddConj_a1_b1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_cgeaddConj_a0_b1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_cgeaddConj_aXi0_b1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_cgeaddConj_aX_b1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_cgeaddConj_aXi0_b0 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_cgeaddConj_a1_b0 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_cgeaddConj_a0_b0 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_cgeaddConj_aXi0_b0 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_cgeaddConj_aX_b0 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_cgeaddConj_aXi0_bXi0 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_cgeaddConj_a1_bXi0 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_cgeaddConj_a0_bXi0 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_cgeaddConj_aXi0_bXi0 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_cgeaddConj_aX_bXi0 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_cgeaddConj_aXi0_bX + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_cgeaddConj_a1_bX + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_cgeaddConj_a0_bX + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_cgeaddConj_aXi0_bX + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_cgeaddConj_aX_bX + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_caxpby_aXi0_b1 + (const int N, const float *alpha, const float *X, const int incX, + const float *beta, float *Y, const int incY); +void ATL_caxpby_aXi0_b1 + (const int N, const float *alpha, const float *X, const int incX, + const float *beta, float *Y, const int incY); +void ATL_cgeadd_aXi0_b1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_caxpby_aXi0_b0 + (const int N, const float *alpha, const float *X, const int incX, + const float *beta, float *Y, const int incY); +void ATL_caxpby_aXi0_b0 + (const int N, const float *alpha, const float *X, const int incX, + const float *beta, float *Y, const int incY); +void ATL_cgeadd_aXi0_b0 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_caxpby_aXi0_bXi0 + (const int N, const float *alpha, const float *X, const int incX, + const float *beta, float *Y, const int incY); +void ATL_caxpby_aXi0_bXi0 + (const int N, const float *alpha, const float *X, const int incX, + const float *beta, float *Y, const int incY); +void ATL_cgeadd_aXi0_bXi0 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_caxpby_aXi0_bX + (const int N, const float *alpha, const float *X, const int incX, + const float *beta, float *Y, const int incY); +void ATL_caxpby_aXi0_bX + (const int N, const float *alpha, const float *X, const int incX, + const float *beta, float *Y, const int incY); +void ATL_cgeadd_aXi0_bX + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_caxpby_a1_bXi0 + (const int N, const float *alpha, const float *X, const int incX, + const float *beta, float *Y, const int incY); +void ATL_cgeadd_a1_bXi0 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_caxpby_a0_bXi0 + (const int N, const float *alpha, const float *X, const int incX, + const float *beta, float *Y, const int incY); +void ATL_cgeadd_a0_bXi0 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); +void ATL_caxpby_aX_bXi0 + (const int N, const float *alpha, const float *X, const int incX, + const float *beta, float *Y, const int incY); +void ATL_cgeadd_aX_bXi0 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *beta, float *C, const int ldc); + +void ATL_cgemove_aXi0 + (const int M, const int N, const float *alpha0, const float *A, + const int lda, float *C, const int ldc); + +void ATL_cgescal_bXi0 + (const int M, const int N, const float *beta, float *C, const int ldc); + +void ATL_zcplxinvert + (const int N, double *X, const int incX, double *Y, const int incY); + +void ATL_zhereflect(const enum ATLAS_UPLO Uplo, const int N, + double *C, const int ldc); +void ATL_zscalConj + (const int N, const double *alpha, double *X, const int incX); +void ATL_zcopyConj + (const int N, const double *X, const int incX, double *Y, const int incY); +void ATL_zmoveConj + (const int N, const double *alpha, const double *X, const int incX, + double *Y, const int incY); +void ATL_zaxpyConj + (const int N, const double *alpha, const double *X, const int incX, + double *Y, const int incY); +void ATL_zaxpyConj_x1_y1(const int N, const double *alpha, const double *X, + const int incX, double *Y, const int incY); +void ATL_zaxpbyConj + (const int N, const double *alpha, const double *X, const int incX, + const double *beta, double *Y, const int incY); +void ATL_zgemoveC(const int N, const int M, const double *alpha, + const double *A, const int lda, double *C, const int ldc); + +void ATL_zgeaddConj_aXi0_b1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zgeaddConj_a1_b1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zgeaddConj_a0_b1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zgeaddConj_aXi0_b1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zgeaddConj_aX_b1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zgeaddConj_aXi0_b0 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zgeaddConj_a1_b0 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zgeaddConj_a0_b0 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zgeaddConj_aXi0_b0 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zgeaddConj_aX_b0 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zgeaddConj_aXi0_bXi0 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zgeaddConj_a1_bXi0 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zgeaddConj_a0_bXi0 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zgeaddConj_aXi0_bXi0 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zgeaddConj_aX_bXi0 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zgeaddConj_aXi0_bX + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zgeaddConj_a1_bX + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zgeaddConj_a0_bX + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zgeaddConj_aXi0_bX + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zgeaddConj_aX_bX + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zaxpby_aXi0_b1 + (const int N, const double *alpha, const double *X, const int incX, + const double *beta, double *Y, const int incY); +void ATL_zaxpby_aXi0_b1 + (const int N, const double *alpha, const double *X, const int incX, + const double *beta, double *Y, const int incY); +void ATL_zgeadd_aXi0_b1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zaxpby_aXi0_b0 + (const int N, const double *alpha, const double *X, const int incX, + const double *beta, double *Y, const int incY); +void ATL_zaxpby_aXi0_b0 + (const int N, const double *alpha, const double *X, const int incX, + const double *beta, double *Y, const int incY); +void ATL_zgeadd_aXi0_b0 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zaxpby_aXi0_bXi0 + (const int N, const double *alpha, const double *X, const int incX, + const double *beta, double *Y, const int incY); +void ATL_zaxpby_aXi0_bXi0 + (const int N, const double *alpha, const double *X, const int incX, + const double *beta, double *Y, const int incY); +void ATL_zgeadd_aXi0_bXi0 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zaxpby_aXi0_bX + (const int N, const double *alpha, const double *X, const int incX, + const double *beta, double *Y, const int incY); +void ATL_zaxpby_aXi0_bX + (const int N, const double *alpha, const double *X, const int incX, + const double *beta, double *Y, const int incY); +void ATL_zgeadd_aXi0_bX + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zaxpby_a1_bXi0 + (const int N, const double *alpha, const double *X, const int incX, + const double *beta, double *Y, const int incY); +void ATL_zgeadd_a1_bXi0 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zaxpby_a0_bXi0 + (const int N, const double *alpha, const double *X, const int incX, + const double *beta, double *Y, const int incY); +void ATL_zgeadd_a0_bXi0 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); +void ATL_zaxpby_aX_bXi0 + (const int N, const double *alpha, const double *X, const int incX, + const double *beta, double *Y, const int incY); +void ATL_zgeadd_aX_bXi0 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *beta, double *C, const int ldc); + +void ATL_zgemove_aXi0 + (const int M, const int N, const double *alpha0, const double *A, + const int lda, double *C, const int ldc); + +void ATL_zgescal_bXi0 + (const int M, const int N, const double *beta, double *C, const int ldc); + + +#if defined(ATL_USEPTHREADS) && !defined(ATL_flushcache) + #include "atlas_pthreads.h" + #define ATL_flushcache ATL_ptflushcache + #define ATL_PTCACHEMUL * ATL_NTHREADS +#else + #define ATL_PTCACHEMUL +#endif +double ATL_flushcache(int size); + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_cblascalias.h b/kaldi_io/src/tools/ATLAS/include/atlas_cblascalias.h new file mode 100644 index 0000000..267b176 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_cblascalias.h @@ -0,0 +1,40 @@ +#ifndef ATLAS_CBLASCALIAS_H + #define ATLAS_CBLASCALIAS_H + +#define cblas_dotc_sub cblas_cdotc_sub +#define cblas_dotu_sub cblas_cdotu_sub +#define cblas_axpy cblas_caxpy +#define cblas_copy cblas_ccopy +#define cblas_scal cblas_cscal +#define cblas_swap cblas_cswap +#define cblas_hpr2 cblas_chpr2 +#define cblas_her2 cblas_cher2 +#define cblas_hpr cblas_chpr +#define cblas_her cblas_cher +#define cblas_gerc cblas_cgerc +#define cblas_geru cblas_cgeru +#define cblas_tpsv cblas_ctpsv +#define cblas_tbsv cblas_ctbsv +#define cblas_trsv cblas_ctrsv +#define cblas_tpmv cblas_ctpmv +#define cblas_tbmv cblas_ctbmv +#define cblas_trmv cblas_ctrmv +#define cblas_hpmv cblas_chpmv +#define cblas_hbmv cblas_chbmv +#define cblas_hemv cblas_chemv +#define cblas_gbmv cblas_cgbmv +#define cblas_gemv cblas_cgemv +#define cblas_trsm cblas_ctrsm +#define cblas_trmm cblas_ctrmm +#define cblas_her2k cblas_cher2k +#define cblas_syr2k cblas_csyr2k +#define cblas_herk cblas_cherk +#define cblas_syrk cblas_csyrk +#define cblas_hemm cblas_chemm +#define cblas_symm cblas_csymm +#define cblas_gemm cblas_cgemm +#define cblas_iamax cblas_icamax +#define cblas_nrm2 cblas_scnrm2 +#define cblas_asum cblas_scasum + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_cblasdalias.h b/kaldi_io/src/tools/ATLAS/include/atlas_cblasdalias.h new file mode 100644 index 0000000..cfc6d10 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_cblasdalias.h @@ -0,0 +1,39 @@ +#ifndef ATLAS_CBLASDALIAS_H + #define ATLAS_CBLASDALIAS_H + +#define cblas_asum cblas_dasum +#define cblas_nrm2 cblas_dnrm2 +#define cblas_dot cblas_ddot +#define cblas_axpy cblas_daxpy +#define cblas_copy cblas_dcopy +#define cblas_scal cblas_dscal +#define cblas_swap cblas_dswap +#define cblas_rotm cblas_drotm +#define cblas_rot cblas_drot +#define cblas_rotmg cblas_drotmg +#define cblas_rotg cblas_drotg +#define cblas_spr2 cblas_dspr2 +#define cblas_syr2 cblas_dsyr2 +#define cblas_spr cblas_dspr +#define cblas_syr cblas_dsyr +#define cblas_ger cblas_dger +#define cblas_tpsv cblas_dtpsv +#define cblas_tbsv cblas_dtbsv +#define cblas_trsv cblas_dtrsv +#define cblas_tpmv cblas_dtpmv +#define cblas_tbmv cblas_dtbmv +#define cblas_trmv cblas_dtrmv +#define cblas_spmv cblas_dspmv +#define cblas_sbmv cblas_dsbmv +#define cblas_symv cblas_dsymv +#define cblas_gbmv cblas_dgbmv +#define cblas_gemv cblas_dgemv +#define cblas_trsm cblas_dtrsm +#define cblas_trmm cblas_dtrmm +#define cblas_syr2k cblas_dsyr2k +#define cblas_syrk cblas_dsyrk +#define cblas_symm cblas_dsymm +#define cblas_gemm cblas_dgemm +#define cblas_iamax cblas_idamax + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_cblassalias.h b/kaldi_io/src/tools/ATLAS/include/atlas_cblassalias.h new file mode 100644 index 0000000..090f9de --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_cblassalias.h @@ -0,0 +1,39 @@ +#ifndef ATLAS_CBLASSALIAS_H + #define ATLAS_CBLASSALIAS_H + +#define cblas_asum cblas_sasum +#define cblas_nrm2 cblas_snrm2 +#define cblas_dot cblas_sdot +#define cblas_axpy cblas_saxpy +#define cblas_copy cblas_scopy +#define cblas_scal cblas_sscal +#define cblas_swap cblas_sswap +#define cblas_rotm cblas_srotm +#define cblas_rot cblas_srot +#define cblas_rotmg cblas_srotmg +#define cblas_rotg cblas_srotg +#define cblas_spr2 cblas_sspr2 +#define cblas_syr2 cblas_ssyr2 +#define cblas_spr cblas_sspr +#define cblas_syr cblas_ssyr +#define cblas_ger cblas_sger +#define cblas_tpsv cblas_stpsv +#define cblas_tbsv cblas_stbsv +#define cblas_trsv cblas_strsv +#define cblas_tpmv cblas_stpmv +#define cblas_tbmv cblas_stbmv +#define cblas_trmv cblas_strmv +#define cblas_spmv cblas_sspmv +#define cblas_sbmv cblas_ssbmv +#define cblas_symv cblas_ssymv +#define cblas_gbmv cblas_sgbmv +#define cblas_gemv cblas_sgemv +#define cblas_trsm cblas_strsm +#define cblas_trmm cblas_strmm +#define cblas_syr2k cblas_ssyr2k +#define cblas_syrk cblas_ssyrk +#define cblas_symm cblas_ssymm +#define cblas_gemm cblas_sgemm +#define cblas_iamax cblas_isamax + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_cblastypealias.h b/kaldi_io/src/tools/ATLAS/include/atlas_cblastypealias.h new file mode 100644 index 0000000..0c3e82f --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_cblastypealias.h @@ -0,0 +1,9 @@ +#ifdef SREAL + #include "atlas_cblassalias.h" +#elif defined(DREAL) + #include "atlas_cblasdalias.h" +#elif defined(SCPLX) + #include "atlas_cblascalias.h" +#elif defined(DCPLX) + #include "atlas_cblaszalias.h" +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_cblaszalias.h b/kaldi_io/src/tools/ATLAS/include/atlas_cblaszalias.h new file mode 100644 index 0000000..ac01436 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_cblaszalias.h @@ -0,0 +1,40 @@ +#ifndef ATLAS_CBLASZALIAS_H + #define ATLAS_CBLASZALIAS_H + +#define cblas_dotc_sub cblas_zdotc_sub +#define cblas_dotu_sub cblas_zdotu_sub +#define cblas_axpy cblas_zaxpy +#define cblas_copy cblas_zcopy +#define cblas_scal cblas_zscal +#define cblas_swap cblas_zswap +#define cblas_hpr2 cblas_zhpr2 +#define cblas_her2 cblas_zher2 +#define cblas_hpr cblas_zhpr +#define cblas_her cblas_zher +#define cblas_gerc cblas_zgerc +#define cblas_geru cblas_zgeru +#define cblas_tpsv cblas_ztpsv +#define cblas_tbsv cblas_ztbsv +#define cblas_trsv cblas_ztrsv +#define cblas_tpmv cblas_ztpmv +#define cblas_tbmv cblas_ztbmv +#define cblas_trmv cblas_ztrmv +#define cblas_hpmv cblas_zhpmv +#define cblas_hbmv cblas_zhbmv +#define cblas_hemv cblas_zhemv +#define cblas_gbmv cblas_zgbmv +#define cblas_gemv cblas_zgemv +#define cblas_trsm cblas_ztrsm +#define cblas_trmm cblas_ztrmm +#define cblas_her2k cblas_zher2k +#define cblas_syr2k cblas_zsyr2k +#define cblas_herk cblas_zherk +#define cblas_syrk cblas_zsyrk +#define cblas_hemm cblas_zhemm +#define cblas_symm cblas_zsymm +#define cblas_gemm cblas_zgemm +#define cblas_iamax cblas_izamax +#define cblas_nrm2 cblas_dznrm2 +#define cblas_asum cblas_dzasum + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_enum.h b/kaldi_io/src/tools/ATLAS/include/atlas_enum.h new file mode 100644 index 0000000..3d638be --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_enum.h @@ -0,0 +1,55 @@ +/* + * Automatically Tuned Linear Algebra Software v3.8.3 + * (C) Copyright 1997 R. Clint Whaley + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the ATLAS group or the names of its contributers may + * not be used to endorse or promote products derived from this + * software without specific written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef ATLAS_ENUM_H + #define ATLAS_ENUM_H + + #define CBLAS_ENUM_ONLY + #include "cblas.h" + #undef CBLAS_ENUM_ONLY + + #define ATLAS_ORDER CBLAS_ORDER + #define AtlasRowMajor CblasRowMajor + #define AtlasColMajor CblasColMajor + #define ATLAS_TRANS CBLAS_TRANSPOSE + #define AtlasNoTrans CblasNoTrans + #define AtlasTrans CblasTrans + #define AtlasConjTrans CblasConjTrans + #define ATLAS_UPLO CBLAS_UPLO + #define AtlasUpper CblasUpper + #define AtlasLower CblasLower + #define ATLAS_DIAG CBLAS_DIAG + #define AtlasNonUnit CblasNonUnit + #define AtlasUnit CblasUnit + #define ATLAS_SIDE CBLAS_SIDE + #define AtlasLeft CblasLeft + #define AtlasRight CblasRight + +#endif + diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_f77.h b/kaldi_io/src/tools/ATLAS/include/atlas_f77.h new file mode 100644 index 0000000..1586fba --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_f77.h @@ -0,0 +1,83 @@ +/* + * Automatically Tuned Linear Algebra Software v3.8.3 + * (C) Copyright 1997 R. Clint Whaley + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the ATLAS group or the names of its contributers may + * not be used to endorse or promote products derived from this + * software without specific written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef ATLAS_F77_H +#define ATLAS_F77_H + + #ifndef ATL_F77_SUBROUTINE + #define ATL_F77_SUBROUTINE void + #endif + #ifndef F77_INTEGER + #define F77_INTEGER int + #else + #define ATL_FunkyInts + #endif + #if defined(CRAY) + #define UseTransChar 1 + #include + #define F77_CHAR _fcd + #define ATL_F2C_TransChar(c) (*(_fcdtocp(c) )) + #define ATL_C2F_TransChar(c) (_cptofcd(&(c), 1)) + #elif defined(StringStructVal) + typedef struct {char *cp; F77_INTEGER len;} F77_CHAR; + #define ATL_F2C_TransChar(c) (*(c.cp)) + #define UseTransChar 2 + #elif defined(StringStructPtr) + typedef struct {char *cp; F77_INTEGER len;} F77_CHAR; + #define ATL_F2C_TransChar(c) (*(c->cp)) + #define UseTransChar 3 + #else + #define ATL_DeclareSlens + #define F77_CHAR char * + #define ATL_F2C_TransChar(c) (*(c)) + #define ATL_C2F_TransChar(c) (&(c)) + #define ATL_STRLEN_1 ,F77_INTEGER ATL_Slen1 + #define ATL_STRLEN_2 ,F77_INTEGER ATL_Slen1, F77_INTEGER ATL_Slen2 + #define ATL_STRLEN_3 ,F77_INTEGER ATL_Slen1, F77_INTEGER ATL_Slen2, \ + F77_INTEGER ATL_Slen3 + #define ATL_STRLEN_4 ,F77_INTEGER ATL_Slen1, F77_INTEGER ATL_Slen2, \ + F77_INTEGER ATL_Slen3, F77_INTEGER ATL_Slen4 + #define ATL_STRLEN_1_para ,ATL_Slen1 + #define ATL_STRLEN_2_para ,ATL_Slen1, ATL_Slen2 + #define ATL_STRLEN_3_para ,ATL_Slen1, ATL_Slen2, ATL_Slen3 + #define ATL_STRLEN_4_para ,ATL_Slen1, ATL_Slen2, ATL_Slen3, ATL_Slen4 + #endif + + #ifndef ATL_STRLEN_1 + #define ATL_STRLEN_1 + #define ATL_STRLEN_2 + #define ATL_STRLEN_3 + #define ATL_STRLEN_4 + #define ATL_STRLEN_1_para + #define ATL_STRLEN_2_para + #define ATL_STRLEN_3_para + #define ATL_STRLEN_4_para + #endif + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_f77blas.h b/kaldi_io/src/tools/ATLAS/include/atlas_f77blas.h new file mode 100644 index 0000000..a7c109d --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_f77blas.h @@ -0,0 +1,849 @@ +#ifndef ATLAS_F77_LVLS +#define ATLAS_F77_LVLS + +#include "atlas_f77.h" + +#if defined( StringSunStyle ) +#define F77_CHAR_DECL F77_CHAR /* input character*1 */ +#define F77_1_CHAR , F77_INTEGER +#define F77_2_CHAR F77_1_CHAR F77_1_CHAR +#define F77_3_CHAR F77_2_CHAR F77_1_CHAR +#define F77_4_CHAR F77_3_CHAR F77_1_CHAR +#elif defined( StringCrayStyle ) +#define F77_CHAR_DECL F77_CHAR /* input character*1 */ +#elif defined( StringStructVal ) +#define F77_CHAR_DECL F77_CHAR /* input character*1 */ +#elif defined( StringStructPtr ) +#define F77_CHAR_DECL F77_CHAR * /* input character*1 */ +#endif + +#ifndef F77_1_CHAR +#define F77_1_CHAR +#define F77_2_CHAR +#define F77_3_CHAR +#define F77_4_CHAR +#endif + +#ifndef F77_CHAR_DECL + #define F77_CHAR_DECL F77_CHAR * /* input character*1 */ +#endif + +#define F77_INT_DECL const F77_INTEGER * /* input integer */ + +#ifdef TREAL +#define F77_SIN_DECL const TYPE * /* input scalar */ +#define F77_SINOUT_DECL TYPE * /* input/output scalar */ +#define F77_RIN_DECL const TYPE * /* input real scalar */ +#define F77_RINOUT_DECL TYPE * /* input/output real scalar */ +#else +#define F77_SIN_DECL const TYPE * /* input scalar */ +#define F77_SINOUT_DECL TYPE * /* input/output scalar */ +#define F77_RIN_DECL const TYPE * /* input real scalar */ +#define F77_RINOUT_DECL TYPE * /* input/output real scalar */ +#endif + +#define F77_VIN_DECL const TYPE * /* input vector */ +#define F77_VINOUT_DECL TYPE * /* input/output matrix */ + +#define F77_MIN_DECL const TYPE * /* input matrix */ +#define F77_MINOUT_DECL TYPE * /* input/output matrix */ + +#if defined( CRAY ) +#define F77_VOID_FUN extern fortran void /* subroutine */ +#define F77_INT_FUN extern fortran int /* integer function */ +#define F77_TYPE_FUN extern fortran TYPE /* real function */ +#define F77_DBLE_FUN extern fortran double /* dble function */ +#else +#define F77_VOID_FUN extern void /* subroutine */ +#define F77_INT_FUN extern int /* integer function */ +#define F77_TYPE_FUN extern TYPE /* real function */ +#define F77_DBLE_FUN extern double /* dble function */ +#endif + +#if defined( NoChange ) +/* + * These defines set up the naming scheme required to have a FORTRAN + * routine called by a C routine with the following FORTRAN to C inter- + * face: + * + * FORTRAN DECLARATION C CALL + * SUBROUTINE DGEMM(...) dgemm(...) + */ +#if defined( SREAL ) + +#define F77rotg srotg +#define F77rotmg srotmg +#define F77nrm2 swrapnrm2 +#define F77asum swrapasum +#define F77amax isamax +#define F77scal sscal +#define F77axpy saxpy +#define F77axpby fatlas_saxpby +#define F77set fatlas_sset +#define F77copy scopy +#define F77swap sswap +#define F77rot srot +#define F77rotm srotm +#define F77dot swrapdot +#define F77dsdot dswrapdot +#define F77sdsdot sdswrapdot + +#define F77gemv sgemv +#define F77gbmv sgbmv +#define F77sbmv ssbmv +#define F77spmv sspmv +#define F77symv ssymv +#define F77tbmv stbmv +#define F77tpmv stpmv +#define F77trmv strmv +#define F77tbsv stbsv +#define F77tpsv stpsv +#define F77trsv strsv +#define F77ger sger +#define F77spr sspr +#define F77syr ssyr +#define F77spr2 sspr2 +#define F77syr2 ssyr2 + +#define F77gemm sgemm +#define F77symm ssymm +#define F77syrk ssyrk +#define F77syr2k ssyr2k +#define F77trmm strmm +#define F77trsm strsm + +#elif defined( DREAL ) + +#define F77rotg drotg +#define F77rotmg drotmg +#define F77nrm2 dwrapnrm2 +#define F77asum dwrapasum +#define F77amax idamax +#define F77scal dscal +#define F77axpy daxpy +#define F77axpby fatlas_daxpby +#define F77set fatlas_dset +#define F77copy dcopy +#define F77swap dswap +#define F77rot drot +#define F77rotm drotm +#define F77dot dwrapdot + +#define F77gemv dgemv +#define F77gbmv dgbmv +#define F77sbmv dsbmv +#define F77spmv dspmv +#define F77symv dsymv +#define F77tbmv dtbmv +#define F77tpmv dtpmv +#define F77trmv dtrmv +#define F77tbsv dtbsv +#define F77tpsv dtpsv +#define F77trsv dtrsv +#define F77ger dger +#define F77spr dspr +#define F77syr dsyr +#define F77spr2 dspr2 +#define F77syr2 dsyr2 + +#define F77gemm dgemm +#define F77symm dsymm +#define F77syrk dsyrk +#define F77syr2k dsyr2k +#define F77trmm dtrmm +#define F77trsm dtrsm + +#elif defined( SCPLX ) + +#define F77rotg crotg +#define F77nrm2 scwrapnrm2 +#define F77asum scwrapasum +#define F77amax icamax +#define F77scal cscal +#define F77rscal csscal +#define F77axpy caxpy +#define F77axpby fatlas_caxpby +#define F77set fatlas_cset +#define F77copy ccopy +#define F77swap cswap +#define F77rot csrot +#define F77dotc cwrapdotc +#define F77dotu cwrapdotu + +#define F77gbmv cgbmv +#define F77gemv cgemv +#define F77hbmv chbmv +#define F77hpmv chpmv +#define F77hemv chemv +#define F77tbmv ctbmv +#define F77tpmv ctpmv +#define F77trmv ctrmv +#define F77tbsv ctbsv +#define F77tpsv ctpsv +#define F77trsv ctrsv +#define F77gerc cgerc +#define F77geru cgeru +#define F77hpr chpr +#define F77her cher +#define F77hpr2 chpr2 +#define F77her2 cher2 + +#define F77gemm cgemm +#define F77hemm chemm +#define F77herk cherk +#define F77her2k cher2k +#define F77symm csymm +#define F77syrk csyrk +#define F77syr2k csyr2k +#define F77trmm ctrmm +#define F77trsm ctrsm + +#elif defined( DCPLX ) + +#define F77rotg zrotg +#define F77nrm2 dzwrapnrm2 +#define F77asum dzwrapasum +#define F77amax izamax +#define F77scal zscal +#define F77rscal zdscal +#define F77axpy zaxpy +#define F77axpby fatlas_zaxpby +#define F77set fatlas_zset +#define F77copy zcopy +#define F77swap zswap +#define F77rot zdrot +#define F77dotc zwrapdotc +#define F77dotu zwrapdotu + +#define F77gbmv zgbmv +#define F77gemv zgemv +#define F77hbmv zhbmv +#define F77hpmv zhpmv +#define F77hemv zhemv +#define F77tbmv ztbmv +#define F77tpmv ztpmv +#define F77trmv ztrmv +#define F77tbsv ztbsv +#define F77tpsv ztpsv +#define F77trsv ztrsv +#define F77gerc zgerc +#define F77geru zgeru +#define F77hpr zhpr +#define F77her zher +#define F77hpr2 zhpr2 +#define F77her2 zher2 + +#define F77gemm zgemm +#define F77hemm zhemm +#define F77herk zherk +#define F77her2k zher2k +#define F77symm zsymm +#define F77syrk zsyrk +#define F77syr2k zsyr2k +#define F77trmm ztrmm +#define F77trsm ztrsm + +#endif + +#elif defined( UpCase ) +/* + * These defines set up the naming scheme required to have a FORTRAN + * routine called by a C routine with the following FORTRAN to C inter- + * face: + * + * FORTRAN DECLARATION C CALL + * SUBROUTINE DGEMM(...) DGEMM(...) + */ +#if defined( SREAL ) + +#define F77rotg SROTG +#define F77rotmg SROTMG +#define F77nrm2 SWRAPNRM2 +#define F77asum SWRAPASUM +#define F77amax ISAMAX +#define F77scal SSCAL +#define F77axpy SAXPY +#define F77axpby FATLAS_SAXPBY +#define F77set FATLAS_SSET +#define F77copy SCOPY +#define F77swap SSWAP +#define F77rot SROT +#define F77rotm SROTM +#define F77dot SWRAPDOT +#define F77dsdot DSWRAPDOT +#define F77sdsdot SDSWRAPDOT + +#define F77gemv SGEMV +#define F77gbmv SGBMV +#define F77sbmv SSBMV +#define F77spmv SSPMV +#define F77symv SSYMV +#define F77tbmv STBMV +#define F77tpmv STPMV +#define F77trmv STRMV +#define F77tbsv STBSV +#define F77tpsv STPSV +#define F77trsv STRSV +#define F77ger SGER +#define F77spr SSPR +#define F77syr SSYR +#define F77spr2 SSPR2 +#define F77syr2 SSYR2 + +#define F77gemm SGEMM +#define F77symm SSYMM +#define F77syrk SSYRK +#define F77syr2k SSYR2K +#define F77trmm STRMM +#define F77trsm STRSM + +#elif defined( DREAL ) + +#define F77rotg DROTG +#define F77rotmg DROTMG +#define F77nrm2 DWRAPNRM2 +#define F77asum DWRAPASUM +#define F77amax IDAMAX +#define F77scal DSCAL +#define F77axpy DAXPY +#define F77axpby FATLAS_DAXPBY +#define F77set FATLAS_DSET +#define F77copy DCOPY +#define F77swap DSWAP +#define F77rot DROT +#define F77rotm DROTM +#define F77dot DWRAPDOT + +#define F77gemv DGEMV +#define F77gbmv DGBMV +#define F77sbmv DSBMV +#define F77spmv DSPMV +#define F77symv DSYMV +#define F77tbmv DTBMV +#define F77tpmv DTPMV +#define F77trmv DTRMV +#define F77tbsv DTBSV +#define F77tpsv DTPSV +#define F77trsv DTRSV +#define F77ger DGER +#define F77spr DSPR +#define F77syr DSYR +#define F77spr2 DSPR2 +#define F77syr2 DSYR2 + +#define F77gemm DGEMM +#define F77symm DSYMM +#define F77syrk DSYRK +#define F77syr2k DSYR2K +#define F77trmm DTRMM +#define F77trsm DTRSM + +#elif defined( SCPLX ) + +#define F77rotg CROTG +#define F77nrm2 SCWRAPNRM2 +#define F77asum SCWRAPASUM +#define F77amax ICAMAX +#define F77scal CSCAL +#define F77rscal CSSCAL +#define F77axpy CAXPY +#define F77axpby FATLAS_CAXPBY +#define F77set FATLAS_CSET +#define F77copy CCOPY +#define F77swap CSWAP +#define F77rot CSROT +#define F77dotc CWRAPDOTC +#define F77dotu CWRAPDOTU + +#define F77gbmv CGBMV +#define F77gemv CGEMV +#define F77hbmv CHBMV +#define F77hpmv CHPMV +#define F77hemv CHEMV +#define F77tbmv CTBMV +#define F77tpmv CTPMV +#define F77trmv CTRMV +#define F77tbsv CTBSV +#define F77tpsv CTPSV +#define F77trsv CTRSV +#define F77gerc CGERC +#define F77geru CGERU +#define F77hpr CHPR +#define F77her CHER +#define F77hpr2 CHPR2 +#define F77her2 CHER2 + +#define F77gemm CGEMM +#define F77hemm CHEMM +#define F77herk CHERK +#define F77her2k CHER2K +#define F77symm CSYMM +#define F77syrk CSYRK +#define F77syr2k CSYR2K +#define F77trmm CTRMM +#define F77trsm CTRSM + +#elif defined( DCPLX ) + +#define F77rotg ZROTG +#define F77nrm2 DZWRAPNRM2 +#define F77asum DZWRAPASUM +#define F77amax IZAMAX +#define F77scal ZSCAL +#define F77rscal ZDSCAL +#define F77axpy ZAXPY +#define F77axpby FATLAS_ZAXPBY +#define F77set FATLAS_ZSET +#define F77copy ZCOPY +#define F77swap ZSWAP +#define F77rot ZDROT +#define F77dotc ZWRAPDOTC +#define F77dotu ZWRAPDOTU + +#define F77gbmv ZGBMV +#define F77gemv ZGEMV +#define F77hbmv ZHBMV +#define F77hpmv ZHPMV +#define F77hemv ZHEMV +#define F77tbmv ZTBMV +#define F77tpmv ZTPMV +#define F77trmv ZTRMV +#define F77tbsv ZTBSV +#define F77tpsv ZTPSV +#define F77trsv ZTRSV +#define F77gerc ZGERC +#define F77geru ZGERU +#define F77hpr ZHPR +#define F77her ZHER +#define F77hpr2 ZHPR2 +#define F77her2 ZHER2 + +#define F77gemm ZGEMM +#define F77hemm ZHEMM +#define F77herk ZHERK +#define F77her2k ZHER2K +#define F77symm ZSYMM +#define F77syrk ZSYRK +#define F77syr2k ZSYR2K +#define F77trmm ZTRMM +#define F77trsm ZTRSM + +#endif + +#elif defined( Add_ ) || defined( Add__ ) +/* + * These defines set up the naming scheme required to have a FORTRAN + * routine called by a C routine with the following FORTRAN to C inter- + * face: + * + * FORTRAN DECLARATION C CALL + * SUBROUTINE DGEMM(...) dgemm_(...) + */ +#if defined( SREAL ) + +#define F77rotg srotg_ +#define F77rotmg srotmg_ +#define F77nrm2 swrapnrm2_ +#define F77asum swrapasum_ +#define F77amax isamax_ +#define F77scal sscal_ +#define F77axpy saxpy_ +#ifdef Add_ + #define F77axpby fatlas_saxpby_ + #define F77set fatlas_sset_ +#else + #define F77axpby fatlas_saxpby__ + #define F77set fatlas_sset__ +#endif +#define F77copy scopy_ +#define F77swap sswap_ +#define F77rot srot_ +#define F77rotm srotm_ +#define F77dot swrapdot_ +#define F77dsdot dswrapdot_ +#define F77sdsdot sdswrapdot_ + +#define F77gemv sgemv_ +#define F77gbmv sgbmv_ +#define F77sbmv ssbmv_ +#define F77spmv sspmv_ +#define F77symv ssymv_ +#define F77tbmv stbmv_ +#define F77tpmv stpmv_ +#define F77trmv strmv_ +#define F77tbsv stbsv_ +#define F77tpsv stpsv_ +#define F77trsv strsv_ +#define F77ger sger_ +#define F77spr sspr_ +#define F77syr ssyr_ +#define F77spr2 sspr2_ +#define F77syr2 ssyr2_ + +#define F77gemm sgemm_ +#define F77symm ssymm_ +#define F77syrk ssyrk_ +#define F77syr2k ssyr2k_ +#define F77trmm strmm_ +#define F77trsm strsm_ + +#elif defined( DREAL ) + +#define F77rotg drotg_ +#define F77rotmg drotmg_ +#define F77nrm2 dwrapnrm2_ +#define F77asum dwrapasum_ +#define F77amax idamax_ +#define F77scal dscal_ +#define F77axpy daxpy_ +#ifdef Add_ + #define F77axpby fatlas_daxpby_ + #define F77set fatlas_dset_ +#else + #define F77axpby fatlas_daxpby__ + #define F77set fatlas_dset__ +#endif +#define F77copy dcopy_ +#define F77swap dswap_ +#define F77rot drot_ +#define F77rotm drotm_ +#define F77dot dwrapdot_ + +#define F77gemv dgemv_ +#define F77gbmv dgbmv_ +#define F77sbmv dsbmv_ +#define F77spmv dspmv_ +#define F77symv dsymv_ +#define F77tbmv dtbmv_ +#define F77tpmv dtpmv_ +#define F77trmv dtrmv_ +#define F77tbsv dtbsv_ +#define F77tpsv dtpsv_ +#define F77trsv dtrsv_ +#define F77ger dger_ +#define F77spr dspr_ +#define F77syr dsyr_ +#define F77spr2 dspr2_ +#define F77syr2 dsyr2_ + +#define F77gemm dgemm_ +#define F77symm dsymm_ +#define F77syrk dsyrk_ +#define F77syr2k dsyr2k_ +#define F77trmm dtrmm_ +#define F77trsm dtrsm_ + +#elif defined( SCPLX ) + +#define F77rotg crotg_ +#define F77nrm2 scwrapnrm2_ +#define F77asum scwrapasum_ +#define F77amax icamax_ +#define F77scal cscal_ +#define F77rscal csscal_ +#define F77axpy caxpy_ +#ifdef Add_ + #define F77axpby fatlas_caxpby_ + #define F77set fatlas_cset_ +#else + #define F77axpby fatlas_caxpby__ + #define F77set fatlas_cset__ +#endif +#define F77copy ccopy_ +#define F77swap cswap_ +#define F77rot csrot_ +#define F77dotc cwrapdotc_ +#define F77dotu cwrapdotu_ + +#define F77gbmv cgbmv_ +#define F77gemv cgemv_ +#define F77hbmv chbmv_ +#define F77hpmv chpmv_ +#define F77hemv chemv_ +#define F77tbmv ctbmv_ +#define F77tpmv ctpmv_ +#define F77trmv ctrmv_ +#define F77tbsv ctbsv_ +#define F77tpsv ctpsv_ +#define F77trsv ctrsv_ +#define F77gerc cgerc_ +#define F77geru cgeru_ +#define F77hpr chpr_ +#define F77her cher_ +#define F77hpr2 chpr2_ +#define F77her2 cher2_ + +#define F77gemm cgemm_ +#define F77hemm chemm_ +#define F77herk cherk_ +#define F77her2k cher2k_ +#define F77symm csymm_ +#define F77syrk csyrk_ +#define F77syr2k csyr2k_ +#define F77trmm ctrmm_ +#define F77trsm ctrsm_ + +#elif defined( DCPLX ) + +#define F77rotg zrotg_ +#define F77nrm2 dzwrapnrm2_ +#define F77asum dzwrapasum_ +#define F77amax izamax_ +#define F77scal zscal_ +#define F77rscal zdscal_ +#define F77axpy zaxpy_ +#ifdef Add_ + #define F77axpby fatlas_zaxpby_ + #define F77set fatlas_zset_ +#else + #define F77axpby fatlas_zaxpby__ + #define F77set fatlas_zset__ +#endif +#define F77copy zcopy_ +#define F77swap zswap_ +#define F77rot zdrot_ +#define F77dotc zwrapdotc_ +#define F77dotu zwrapdotu_ + +#define F77gbmv zgbmv_ +#define F77gemv zgemv_ +#define F77hbmv zhbmv_ +#define F77hpmv zhpmv_ +#define F77hemv zhemv_ +#define F77tbmv ztbmv_ +#define F77tpmv ztpmv_ +#define F77trmv ztrmv_ +#define F77tbsv ztbsv_ +#define F77tpsv ztpsv_ +#define F77trsv ztrsv_ +#define F77gerc zgerc_ +#define F77geru zgeru_ +#define F77hpr zhpr_ +#define F77her zher_ +#define F77hpr2 zhpr2_ +#define F77her2 zher2_ + +#define F77gemm zgemm_ +#define F77hemm zhemm_ +#define F77herk zherk_ +#define F77her2k zher2k_ +#define F77symm zsymm_ +#define F77syrk zsyrk_ +#define F77syr2k zsyr2k_ +#define F77trmm ztrmm_ +#define F77trsm ztrsm_ + +#endif + +#endif + +#ifdef TREAL +F77_VOID_FUN F77rotg +( F77_SINOUT_DECL, F77_SINOUT_DECL, F77_SINOUT_DECL, F77_SINOUT_DECL ); +F77_VOID_FUN F77rotmg +( F77_SINOUT_DECL, F77_SINOUT_DECL, F77_SINOUT_DECL, F77_SIN_DECL, + F77_VINOUT_DECL ); +#else +F77_VOID_FUN F77rotg +( F77_SINOUT_DECL, F77_SIN_DECL, F77_SINOUT_DECL, F77_SINOUT_DECL ); +#endif +F77_VOID_FUN F77nrm2 +( F77_INT_DECL, F77_VIN_DECL, F77_INT_DECL, F77_RINOUT_DECL ); +F77_VOID_FUN F77asum +( F77_INT_DECL, F77_VIN_DECL, F77_INT_DECL, F77_RINOUT_DECL ); +F77_INT_FUN F77amax +( F77_INT_DECL, F77_VIN_DECL, F77_INT_DECL ); +F77_VOID_FUN F77scal +( F77_INT_DECL, F77_SIN_DECL, F77_VINOUT_DECL, F77_INT_DECL ); +#ifdef TCPLX +F77_VOID_FUN F77rscal +( F77_INT_DECL, F77_RIN_DECL, F77_VINOUT_DECL, F77_INT_DECL ); +#endif +void F77set +( F77_INT_DECL, F77_SIN_DECL, F77_VINOUT_DECL, F77_INT_DECL ); +void F77axpby +( F77_INT_DECL, F77_SIN_DECL, F77_VIN_DECL, F77_INT_DECL, + F77_SIN_DECL, F77_VINOUT_DECL, F77_INT_DECL ); +F77_VOID_FUN F77axpy +( F77_INT_DECL, F77_SIN_DECL, F77_VIN_DECL, F77_INT_DECL, + F77_VINOUT_DECL, F77_INT_DECL ); +F77_VOID_FUN F77copy +( F77_INT_DECL, F77_VIN_DECL, F77_INT_DECL, F77_VINOUT_DECL, + F77_INT_DECL ); +F77_VOID_FUN F77swap +( F77_INT_DECL, F77_VINOUT_DECL, F77_INT_DECL, F77_VINOUT_DECL, + F77_INT_DECL ); +F77_VOID_FUN F77rot +( F77_INT_DECL, F77_VINOUT_DECL, F77_INT_DECL, F77_VINOUT_DECL, + F77_INT_DECL, F77_SIN_DECL, F77_SIN_DECL ); +#ifdef TREAL +F77_VOID_FUN F77rotm +( F77_INT_DECL, F77_VINOUT_DECL, F77_INT_DECL, F77_VINOUT_DECL, + F77_INT_DECL, F77_VIN_DECL ); +#endif +#ifdef TREAL +F77_VOID_FUN F77dot +( F77_INT_DECL, F77_VIN_DECL, F77_INT_DECL, F77_VIN_DECL, + F77_INT_DECL, F77_SINOUT_DECL ); +#ifdef SREAL +F77_VOID_FUN F77dsdot +( F77_INT_DECL, F77_VIN_DECL, F77_INT_DECL, F77_VIN_DECL, + F77_INT_DECL, double * ); +F77_VOID_FUN F77sdsdot +( F77_INT_DECL, F77_SIN_DECL, F77_VIN_DECL, F77_INT_DECL, + F77_VIN_DECL, F77_INT_DECL, F77_SINOUT_DECL ); +#endif +#else +F77_VOID_FUN F77dotc +( F77_INT_DECL, F77_VIN_DECL, F77_INT_DECL, F77_VIN_DECL, + F77_INT_DECL, F77_SINOUT_DECL ); +F77_VOID_FUN F77dotu +( F77_INT_DECL, F77_VIN_DECL, F77_INT_DECL, F77_VIN_DECL, + F77_INT_DECL, F77_SINOUT_DECL ); +#endif + +F77_VOID_FUN F77gbmv +( F77_CHAR_DECL, F77_INT_DECL, F77_INT_DECL, F77_INT_DECL, + F77_INT_DECL, F77_SIN_DECL, F77_MIN_DECL, F77_INT_DECL, + F77_VIN_DECL, F77_INT_DECL, F77_SIN_DECL, F77_VINOUT_DECL, + F77_INT_DECL F77_1_CHAR ); +F77_VOID_FUN F77gemv +( F77_CHAR_DECL, F77_INT_DECL, F77_INT_DECL, + F77_SIN_DECL, F77_MIN_DECL, F77_INT_DECL, + F77_VIN_DECL, F77_INT_DECL, F77_SIN_DECL, F77_VINOUT_DECL, + F77_INT_DECL F77_1_CHAR ); +#ifdef TREAL +F77_VOID_FUN F77ger +( F77_INT_DECL, F77_INT_DECL, F77_SIN_DECL, F77_VIN_DECL, + F77_INT_DECL, F77_VIN_DECL, F77_INT_DECL, F77_MINOUT_DECL, + F77_INT_DECL ); +F77_VOID_FUN F77sbmv +( F77_CHAR_DECL, F77_INT_DECL, F77_INT_DECL, F77_SIN_DECL, + F77_MIN_DECL, F77_INT_DECL, F77_VIN_DECL, F77_INT_DECL, + F77_SIN_DECL, F77_VINOUT_DECL, F77_INT_DECL F77_1_CHAR ); +F77_VOID_FUN F77spmv +( F77_CHAR_DECL, F77_INT_DECL, F77_SIN_DECL, + F77_MIN_DECL, F77_VIN_DECL, F77_INT_DECL, + F77_SIN_DECL, F77_VINOUT_DECL, F77_INT_DECL F77_1_CHAR ); +F77_VOID_FUN F77symv +( F77_CHAR_DECL, F77_INT_DECL, F77_SIN_DECL, + F77_MIN_DECL, F77_INT_DECL, F77_VIN_DECL, F77_INT_DECL, + F77_SIN_DECL, F77_VINOUT_DECL, F77_INT_DECL F77_1_CHAR ); +F77_VOID_FUN F77spr +( F77_CHAR_DECL, F77_INT_DECL, F77_SIN_DECL, F77_VIN_DECL, + F77_INT_DECL, F77_MINOUT_DECL F77_1_CHAR ); +F77_VOID_FUN F77syr +( F77_CHAR_DECL, F77_INT_DECL, F77_SIN_DECL, F77_VIN_DECL, + F77_INT_DECL, F77_MINOUT_DECL, F77_INT_DECL F77_1_CHAR ); +F77_VOID_FUN F77spr2 +( F77_CHAR_DECL, F77_INT_DECL, F77_SIN_DECL, F77_VIN_DECL, + F77_INT_DECL, F77_VIN_DECL, F77_INT_DECL, F77_MINOUT_DECL + F77_1_CHAR ); +F77_VOID_FUN F77syr2 +( F77_CHAR_DECL, F77_INT_DECL, F77_SIN_DECL, F77_VIN_DECL, + F77_INT_DECL, F77_VIN_DECL, F77_INT_DECL, F77_MINOUT_DECL, + F77_INT_DECL F77_1_CHAR ); +#else +F77_VOID_FUN F77gerc +( F77_INT_DECL, F77_INT_DECL, F77_SIN_DECL, F77_VIN_DECL, + F77_INT_DECL, F77_VIN_DECL, F77_INT_DECL, F77_MINOUT_DECL, + F77_INT_DECL ); +F77_VOID_FUN F77geru +( F77_INT_DECL, F77_INT_DECL, F77_SIN_DECL, F77_VIN_DECL, + F77_INT_DECL, F77_VIN_DECL, F77_INT_DECL, F77_MINOUT_DECL, + F77_INT_DECL ); +F77_VOID_FUN F77hbmv +( F77_CHAR_DECL, F77_INT_DECL, F77_INT_DECL, F77_SIN_DECL, + F77_MIN_DECL, F77_INT_DECL, F77_VIN_DECL, F77_INT_DECL, + F77_SIN_DECL, F77_VINOUT_DECL, F77_INT_DECL F77_1_CHAR ); +F77_VOID_FUN F77hpmv +( F77_CHAR_DECL, F77_INT_DECL, F77_SIN_DECL, + F77_MIN_DECL, F77_VIN_DECL, F77_INT_DECL, + F77_SIN_DECL, F77_VINOUT_DECL, F77_INT_DECL F77_1_CHAR ); +F77_VOID_FUN F77hemv +( F77_CHAR_DECL, F77_INT_DECL, F77_SIN_DECL, + F77_MIN_DECL, F77_INT_DECL, F77_VIN_DECL, F77_INT_DECL, + F77_SIN_DECL, F77_VINOUT_DECL, F77_INT_DECL F77_1_CHAR ); +F77_VOID_FUN F77hpr +( F77_CHAR_DECL, F77_INT_DECL, F77_RIN_DECL, F77_VIN_DECL, + F77_INT_DECL, F77_MINOUT_DECL F77_1_CHAR ); +F77_VOID_FUN F77her +( F77_CHAR_DECL, F77_INT_DECL, F77_RIN_DECL, F77_VIN_DECL, + F77_INT_DECL, F77_MINOUT_DECL, F77_INT_DECL F77_1_CHAR ); +F77_VOID_FUN F77hpr2 +( F77_CHAR_DECL, F77_INT_DECL, F77_SIN_DECL, F77_VIN_DECL, + F77_INT_DECL, F77_VIN_DECL, F77_INT_DECL, F77_MINOUT_DECL + F77_1_CHAR ); +F77_VOID_FUN F77her2 +( F77_CHAR_DECL, F77_INT_DECL, F77_SIN_DECL, F77_VIN_DECL, + F77_INT_DECL, F77_VIN_DECL, F77_INT_DECL, F77_MINOUT_DECL, + F77_INT_DECL F77_1_CHAR ); +#endif +F77_VOID_FUN F77tbmv +( F77_CHAR_DECL, F77_CHAR_DECL, F77_CHAR_DECL, F77_INT_DECL, + F77_INT_DECL, F77_MIN_DECL, F77_INT_DECL, F77_VINOUT_DECL, + F77_INT_DECL F77_3_CHAR ); +F77_VOID_FUN F77tpmv +( F77_CHAR_DECL, F77_CHAR_DECL, F77_CHAR_DECL, F77_INT_DECL, + F77_MIN_DECL, F77_VINOUT_DECL, + F77_INT_DECL F77_3_CHAR ); +F77_VOID_FUN F77trmv +( F77_CHAR_DECL, F77_CHAR_DECL, F77_CHAR_DECL, F77_INT_DECL, + F77_MIN_DECL, F77_INT_DECL, F77_VINOUT_DECL, + F77_INT_DECL F77_3_CHAR ); +F77_VOID_FUN F77tbsv +( F77_CHAR_DECL, F77_CHAR_DECL, F77_CHAR_DECL, F77_INT_DECL, + F77_INT_DECL, F77_MIN_DECL, F77_INT_DECL, F77_VINOUT_DECL, + F77_INT_DECL F77_3_CHAR ); +F77_VOID_FUN F77tpsv +( F77_CHAR_DECL, F77_CHAR_DECL, F77_CHAR_DECL, F77_INT_DECL, + F77_MIN_DECL, F77_VINOUT_DECL, + F77_INT_DECL F77_3_CHAR ); +F77_VOID_FUN F77trsv +( F77_CHAR_DECL, F77_CHAR_DECL, F77_CHAR_DECL, F77_INT_DECL, + F77_MIN_DECL, F77_INT_DECL, F77_VINOUT_DECL, + F77_INT_DECL F77_3_CHAR ); + +F77_VOID_FUN F77gemm +( F77_CHAR_DECL, F77_CHAR_DECL, F77_INT_DECL, F77_INT_DECL, + F77_INT_DECL, F77_SIN_DECL, F77_MIN_DECL, F77_INT_DECL, + F77_MIN_DECL, F77_INT_DECL, F77_SIN_DECL, F77_MINOUT_DECL, + F77_INT_DECL F77_2_CHAR ); +F77_VOID_FUN F77hemm +( F77_CHAR_DECL, F77_CHAR_DECL, F77_INT_DECL, F77_INT_DECL, + F77_SIN_DECL, F77_MIN_DECL, F77_INT_DECL, F77_MIN_DECL, + F77_INT_DECL, F77_SIN_DECL, F77_MINOUT_DECL, F77_INT_DECL + F77_2_CHAR ); +F77_VOID_FUN F77her2k +( F77_CHAR_DECL, F77_CHAR_DECL, F77_INT_DECL, F77_INT_DECL, + F77_SIN_DECL, F77_MIN_DECL, F77_INT_DECL, F77_MIN_DECL, + F77_INT_DECL, F77_RIN_DECL, F77_MINOUT_DECL, F77_INT_DECL + F77_2_CHAR ); +F77_VOID_FUN F77herk +( F77_CHAR_DECL, F77_CHAR_DECL, F77_INT_DECL, F77_INT_DECL, + F77_RIN_DECL, F77_MIN_DECL, F77_INT_DECL, F77_RIN_DECL, + F77_MINOUT_DECL, F77_INT_DECL F77_2_CHAR ); +F77_VOID_FUN F77symm +( F77_CHAR_DECL, F77_CHAR_DECL, F77_INT_DECL, F77_INT_DECL, + F77_SIN_DECL, F77_MIN_DECL, F77_INT_DECL, F77_MIN_DECL, + F77_INT_DECL, F77_SIN_DECL, F77_MINOUT_DECL, F77_INT_DECL + F77_2_CHAR ); +F77_VOID_FUN F77syr2k +( F77_CHAR_DECL, F77_CHAR_DECL, F77_INT_DECL, F77_INT_DECL, + F77_SIN_DECL, F77_MIN_DECL, F77_INT_DECL, F77_MIN_DECL, + F77_INT_DECL, F77_SIN_DECL, F77_MINOUT_DECL, F77_INT_DECL + F77_2_CHAR ); +F77_VOID_FUN F77syrk +( F77_CHAR_DECL, F77_CHAR_DECL, F77_INT_DECL, F77_INT_DECL, + F77_SIN_DECL, F77_MIN_DECL, F77_INT_DECL, F77_SIN_DECL, + F77_MINOUT_DECL, F77_INT_DECL F77_2_CHAR ); +F77_VOID_FUN F77trmm +( F77_CHAR_DECL, F77_CHAR_DECL, F77_CHAR_DECL, F77_CHAR_DECL, + F77_INT_DECL, F77_INT_DECL, F77_SIN_DECL, F77_MIN_DECL, + F77_INT_DECL, F77_MINOUT_DECL, F77_INT_DECL F77_4_CHAR ); +F77_VOID_FUN F77trsm +( F77_CHAR_DECL, F77_CHAR_DECL, F77_CHAR_DECL, F77_CHAR_DECL, + F77_INT_DECL, F77_INT_DECL, F77_SIN_DECL, F77_MIN_DECL, + F77_INT_DECL, F77_MINOUT_DECL, F77_INT_DECL F77_4_CHAR ); + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_f77wrap.h b/kaldi_io/src/tools/ATLAS/include/atlas_f77wrap.h new file mode 100644 index 0000000..db6099c --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_f77wrap.h @@ -0,0 +1,1088 @@ +/* --------------------------------------------------------------------- + * + * -- Automatically Tuned Linear Algebra Software (ATLAS) + * (C) Copyright 2000 All Rights Reserved + * + * -- ATLAS routine -- Version 3.2 -- December 25, 2000 + * + * Author : Antoine P. Petitet + * Originally developed at the University of Tennessee, + * Innovative Computing Laboratory, Knoxville TN, 37996-1301, USA. + * + * --------------------------------------------------------------------- + * + * -- Copyright notice and Licensing terms: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in + * the documentation and/or other materials provided with the distri- + * bution. + * 3. The name of the University, the ATLAS group, or the names of its + * contributors may not be used to endorse or promote products deri- + * ved from this software without specific written permission. + * + * -- Disclaimer: + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEO- + * RY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (IN- + * CLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * --------------------------------------------------------------------- + */ +#ifndef ATLAS_F77WRAP_H +#define ATLAS_F77WRAP_H +/* + * ===================================================================== + * Include Files + * ===================================================================== + */ +#include "atlas_misc.h" +#include "atlas_f77.h" +/* + * ===================================================================== + * Multi-threaded/reference implementation function names re-definition + * ===================================================================== + * + * Uncomment the following definition macros to call the multi-threaded + * implementation or define those macros at compile time. + * + * #define USE_L1_PTHREADS + * #define USE_L2_PTHREADS + * #define USE_L3_PTHREADS + * + * Uncomment the following definition macros to call the reference im- + * plementation or define those macros at compile time. + * + * #define USE_L1_REFERENCE + * #define USE_L2_REFERENCE + * #define USE_L3_REFERENCE + * + * ===================================================================== + */ + +#ifdef ATL_USEPTHREADS +#define USE_L3_PTHREADS +#endif + +/* + * ===================================================================== + * ATLAS Levels 1, 2 and 3 Prototypes + * ===================================================================== + */ +#if defined( USE_L1_PTHREADS ) +#include "atlas_ptalias1.h" +#include "atlas_ptlevel1.h" +#elif defined( USE_L1_REFERENCE ) +#include "atlas_refalias1.h" +#include "atlas_reflevel1.h" +#else +#include "atlas_level1.h" +#endif + +#if defined( USE_L2_PTHREADS ) +#include "atlas_ptalias2.h" +#include "atlas_ptlevel2.h" +#elif defined( USE_L2_REFERENCE ) +#include "atlas_refalias2.h" +#include "atlas_reflevel2.h" +#else +#include "atlas_level2.h" +#endif + +#if defined( USE_L3_PTHREADS ) +#include "atlas_ptalias3.h" +#include "atlas_ptlevel3.h" +#elif defined( USE_L3_REFERENCE ) +#include "atlas_refalias3.h" +#include "atlas_reflevel3.h" +#else +#include "atlas_level3.h" +#endif +/* + * ===================================================================== + * #define macro constants + * ===================================================================== + */ +#define PATLF77WRAP Mjoin( ATL_F77wrap_, PRE ) + +#ifdef TREAL +#define ATLPUF77WRAP Mjoin( ATL_F77wrap_, PRE ) +#define ATLUPF77WRAP Mjoin( ATL_F77wrap_, PRE ) +#else +#define ATLPUF77WRAP Mjoin( Mjoin( ATL_F77wrap_, PRE ), UPR ) +#define ATLUPF77WRAP Mjoin( Mjoin( ATL_F77wrap_, UPR ), PRE ) +#endif + +#define F77_INOTRAN 111 +#define F77_ITRAN 112 +#define F77_ICOTRAN 113 + +#define F77_IUPPER 121 +#define F77_ILOWER 122 + +#define F77_INONUNIT 131 +#define F77_IUNIT 132 + +#define F77_ILEFT 141 +#define F77_IRIGHT 142 +/* + * ===================================================================== + * #define macro functions + * ===================================================================== + */ +#ifdef TREAL +#define V1N( n_, x_, incx_ ) \ + ( (*n_) > 0 ? (x_)+(1-(*n_))*(*incx_) : (x_) ) +#define VN1( n_, x_, incx_ ) \ + ( (*n_) > 0 ? (x_)+((*n_)-1)*(*incx_) : (x_) ) +#define W1N( n_, x_, incx_ ) \ + ( (*incx_) < 0 ? V1N( n_, x_, incx_ ) : (x_) ) +#else +#define V1N( n_, x_, incx_ ) \ + ( (*n_) > 0 ? (x_)+( ( (1-(*n_))*(*incx_) ) << 1 ) : (x_) ) +#define VN1( n_, x_, incx_ ) \ + ( (*n_) > 0 ? (x_)+( ( ((*n_)-1)*(*incx_) ) << 1 ) : (x_) ) +#define W1N( n_, x_, incx_ ) \ + ( (*incx_) < 0 ? V1N( n_, x_, incx_ ) : (x_) ) +#endif +/* + * ===================================================================== + * FORTRAN <-> C interface + * ===================================================================== + * + * These macros identifies how these wrappers will be called as follows: + * + * Add_: the FORTRAN compiler expects the name of C functions to be + * in all lower case and to have an underscore postfixed it (Suns, Intel + * compilers expect this). + * + * NoChange: the FORTRAN compiler expects the name of C functions to be + * in all lower case (IBM RS6K compilers do this). + * + * UpCase: the FORTRAN compiler expects the name of C functions to be + * in all upcase. (Cray compilers expect this). + * + * Add__: the FORTRAN compiler in use is f2c, a FORTRAN to C conver- + * ter. + */ +#if defined( Add_ ) +/* + * These defines set up the naming scheme required to have a FORTRAN + * routine calling a C routine. + * + * FORTRAN CALL C declaration + * CALL ATL_F77WRAP_SGEMM(...) void atl_f77wrap_sgemm_(...) + * + * This is the default. + */ +#if defined( SREAL ) + +#define ATL_F77wrap_srotg atl_f77wrap_srotg_ +#define ATL_F77wrap_srotmg atl_f77wrap_srotmg_ +#define ATL_F77wrap_snrm2 atl_f77wrap_snrm2_ +#define ATL_F77wrap_sasum atl_f77wrap_sasum_ +#define ATL_F77wrap_sscal atl_f77wrap_sscal_ +#define ATL_F77wrap_isamax atl_f77wrap_isamax_ +#define ATL_F77wrap_saxpy atl_f77wrap_saxpy_ +#define ATL_F77wrap_scopy atl_f77wrap_scopy_ +#define ATL_F77wrap_sswap atl_f77wrap_sswap_ +#define ATL_F77wrap_srot atl_f77wrap_srot_ +#define ATL_F77wrap_srotm atl_f77wrap_srotm_ +#define ATL_F77wrap_sdot atl_f77wrap_sdot_ +#define ATL_F77wrap_dsdot atl_f77wrap_dsdot_ +#define ATL_F77wrap_sdsdot atl_f77wrap_sdsdot_ + +#define ATL_F77wrap_sgbmv atl_f77wrap_sgbmv_ +#define ATL_F77wrap_sgemv atl_f77wrap_sgemv_ +#define ATL_F77wrap_sger atl_f77wrap_sger_ +#define ATL_F77wrap_ssbmv atl_f77wrap_ssbmv_ +#define ATL_F77wrap_sspmv atl_f77wrap_sspmv_ +#define ATL_F77wrap_ssymv atl_f77wrap_ssymv_ +#define ATL_F77wrap_sspr atl_f77wrap_sspr_ +#define ATL_F77wrap_ssyr atl_f77wrap_ssyr_ +#define ATL_F77wrap_sspr2 atl_f77wrap_sspr2_ +#define ATL_F77wrap_ssyr2 atl_f77wrap_ssyr2_ +#define ATL_F77wrap_stbmv atl_f77wrap_stbmv_ +#define ATL_F77wrap_stpmv atl_f77wrap_stpmv_ +#define ATL_F77wrap_strmv atl_f77wrap_strmv_ +#define ATL_F77wrap_stbsv atl_f77wrap_stbsv_ +#define ATL_F77wrap_stpsv atl_f77wrap_stpsv_ +#define ATL_F77wrap_strsv atl_f77wrap_strsv_ + +#define ATL_F77wrap_sgemm atl_f77wrap_sgemm_ +#define ATL_F77wrap_ssymm atl_f77wrap_ssymm_ +#define ATL_F77wrap_ssyrk atl_f77wrap_ssyrk_ +#define ATL_F77wrap_ssyr2k atl_f77wrap_ssyr2k_ +#define ATL_F77wrap_strmm atl_f77wrap_strmm_ +#define ATL_F77wrap_strsm atl_f77wrap_strsm_ + +#elif defined( DREAL ) + +#define ATL_F77wrap_drotg atl_f77wrap_drotg_ +#define ATL_F77wrap_drotmg atl_f77wrap_drotmg_ +#define ATL_F77wrap_dnrm2 atl_f77wrap_dnrm2_ +#define ATL_F77wrap_dasum atl_f77wrap_dasum_ +#define ATL_F77wrap_dscal atl_f77wrap_dscal_ +#define ATL_F77wrap_idamax atl_f77wrap_idamax_ +#define ATL_F77wrap_daxpy atl_f77wrap_daxpy_ +#define ATL_F77wrap_dcopy atl_f77wrap_dcopy_ +#define ATL_F77wrap_dswap atl_f77wrap_dswap_ +#define ATL_F77wrap_drot atl_f77wrap_drot_ +#define ATL_F77wrap_drotm atl_f77wrap_drotm_ +#define ATL_F77wrap_ddot atl_f77wrap_ddot_ + +#define ATL_F77wrap_dgbmv atl_f77wrap_dgbmv_ +#define ATL_F77wrap_dgemv atl_f77wrap_dgemv_ +#define ATL_F77wrap_dger atl_f77wrap_dger_ +#define ATL_F77wrap_dsbmv atl_f77wrap_dsbmv_ +#define ATL_F77wrap_dspmv atl_f77wrap_dspmv_ +#define ATL_F77wrap_dsymv atl_f77wrap_dsymv_ +#define ATL_F77wrap_dspr atl_f77wrap_dspr_ +#define ATL_F77wrap_dsyr atl_f77wrap_dsyr_ +#define ATL_F77wrap_dspr2 atl_f77wrap_dspr2_ +#define ATL_F77wrap_dsyr2 atl_f77wrap_dsyr2_ +#define ATL_F77wrap_dtbmv atl_f77wrap_dtbmv_ +#define ATL_F77wrap_dtpmv atl_f77wrap_dtpmv_ +#define ATL_F77wrap_dtrmv atl_f77wrap_dtrmv_ +#define ATL_F77wrap_dtbsv atl_f77wrap_dtbsv_ +#define ATL_F77wrap_dtpsv atl_f77wrap_dtpsv_ +#define ATL_F77wrap_dtrsv atl_f77wrap_dtrsv_ + +#define ATL_F77wrap_dgemm atl_f77wrap_dgemm_ +#define ATL_F77wrap_dsymm atl_f77wrap_dsymm_ +#define ATL_F77wrap_dsyrk atl_f77wrap_dsyrk_ +#define ATL_F77wrap_dsyr2k atl_f77wrap_dsyr2k_ +#define ATL_F77wrap_dtrmm atl_f77wrap_dtrmm_ +#define ATL_F77wrap_dtrsm atl_f77wrap_dtrsm_ + +#elif defined( SCPLX ) + +#define ATL_F77wrap_crotg atl_f77wrap_crotg_ +#define ATL_F77wrap_scnrm2 atl_f77wrap_scnrm2_ +#define ATL_F77wrap_scasum atl_f77wrap_scasum_ +#define ATL_F77wrap_cscal atl_f77wrap_cscal_ +#define ATL_F77wrap_csscal atl_f77wrap_csscal_ +#define ATL_F77wrap_icamax atl_f77wrap_icamax_ +#define ATL_F77wrap_caxpy atl_f77wrap_caxpy_ +#define ATL_F77wrap_ccopy atl_f77wrap_ccopy_ +#define ATL_F77wrap_cswap atl_f77wrap_cswap_ +#define ATL_F77wrap_csrot atl_f77wrap_csrot_ +#define ATL_F77wrap_cdotc atl_f77wrap_cdotc_ +#define ATL_F77wrap_cdotu atl_f77wrap_cdotu_ + +#define ATL_F77wrap_cgbmv atl_f77wrap_cgbmv_ +#define ATL_F77wrap_cgemv atl_f77wrap_cgemv_ +#define ATL_F77wrap_cgerc atl_f77wrap_cgerc_ +#define ATL_F77wrap_cgeru atl_f77wrap_cgeru_ +#define ATL_F77wrap_chbmv atl_f77wrap_chbmv_ +#define ATL_F77wrap_chpmv atl_f77wrap_chpmv_ +#define ATL_F77wrap_chemv atl_f77wrap_chemv_ +#define ATL_F77wrap_chpr atl_f77wrap_chpr_ +#define ATL_F77wrap_cher atl_f77wrap_cher_ +#define ATL_F77wrap_chpr2 atl_f77wrap_chpr2_ +#define ATL_F77wrap_cher2 atl_f77wrap_cher2_ +#define ATL_F77wrap_ctbmv atl_f77wrap_ctbmv_ +#define ATL_F77wrap_ctpmv atl_f77wrap_ctpmv_ +#define ATL_F77wrap_ctrmv atl_f77wrap_ctrmv_ +#define ATL_F77wrap_ctbsv atl_f77wrap_ctbsv_ +#define ATL_F77wrap_ctpsv atl_f77wrap_ctpsv_ +#define ATL_F77wrap_ctrsv atl_f77wrap_ctrsv_ + +#define ATL_F77wrap_cgemm atl_f77wrap_cgemm_ +#define ATL_F77wrap_chemm atl_f77wrap_chemm_ +#define ATL_F77wrap_cherk atl_f77wrap_cherk_ +#define ATL_F77wrap_cher2k atl_f77wrap_cher2k_ +#define ATL_F77wrap_csymm atl_f77wrap_csymm_ +#define ATL_F77wrap_csyrk atl_f77wrap_csyrk_ +#define ATL_F77wrap_csyr2k atl_f77wrap_csyr2k_ +#define ATL_F77wrap_ctrmm atl_f77wrap_ctrmm_ +#define ATL_F77wrap_ctrsm atl_f77wrap_ctrsm_ + +#elif defined( DCPLX ) + +#define ATL_F77wrap_zrotg atl_f77wrap_zrotg_ +#define ATL_F77wrap_dznrm2 atl_f77wrap_dznrm2_ +#define ATL_F77wrap_dzasum atl_f77wrap_dzasum_ +#define ATL_F77wrap_zscal atl_f77wrap_zscal_ +#define ATL_F77wrap_zdscal atl_f77wrap_zdscal_ +#define ATL_F77wrap_izamax atl_f77wrap_izamax_ +#define ATL_F77wrap_zaxpy atl_f77wrap_zaxpy_ +#define ATL_F77wrap_zcopy atl_f77wrap_zcopy_ +#define ATL_F77wrap_zswap atl_f77wrap_zswap_ +#define ATL_F77wrap_zdrot atl_f77wrap_zdrot_ +#define ATL_F77wrap_zdotc atl_f77wrap_zdotc_ +#define ATL_F77wrap_zdotu atl_f77wrap_zdotu_ + +#define ATL_F77wrap_zgbmv atl_f77wrap_zgbmv_ +#define ATL_F77wrap_zgemv atl_f77wrap_zgemv_ +#define ATL_F77wrap_zgerc atl_f77wrap_zgerc_ +#define ATL_F77wrap_zgeru atl_f77wrap_zgeru_ +#define ATL_F77wrap_zhbmv atl_f77wrap_zhbmv_ +#define ATL_F77wrap_zhpmv atl_f77wrap_zhpmv_ +#define ATL_F77wrap_zhemv atl_f77wrap_zhemv_ +#define ATL_F77wrap_zhpr atl_f77wrap_zhpr_ +#define ATL_F77wrap_zher atl_f77wrap_zher_ +#define ATL_F77wrap_zhpr2 atl_f77wrap_zhpr2_ +#define ATL_F77wrap_zher2 atl_f77wrap_zher2_ +#define ATL_F77wrap_ztbmv atl_f77wrap_ztbmv_ +#define ATL_F77wrap_ztpmv atl_f77wrap_ztpmv_ +#define ATL_F77wrap_ztrmv atl_f77wrap_ztrmv_ +#define ATL_F77wrap_ztbsv atl_f77wrap_ztbsv_ +#define ATL_F77wrap_ztpsv atl_f77wrap_ztpsv_ +#define ATL_F77wrap_ztrsv atl_f77wrap_ztrsv_ + +#define ATL_F77wrap_zgemm atl_f77wrap_zgemm_ +#define ATL_F77wrap_zhemm atl_f77wrap_zhemm_ +#define ATL_F77wrap_zherk atl_f77wrap_zherk_ +#define ATL_F77wrap_zher2k atl_f77wrap_zher2k_ +#define ATL_F77wrap_zsymm atl_f77wrap_zsymm_ +#define ATL_F77wrap_zsyrk atl_f77wrap_zsyrk_ +#define ATL_F77wrap_zsyr2k atl_f77wrap_zsyr2k_ +#define ATL_F77wrap_ztrmm atl_f77wrap_ztrmm_ +#define ATL_F77wrap_ztrsm atl_f77wrap_ztrsm_ + +#endif + +#elif defined( UpCase ) +/* + * These defines set up the naming scheme required to have a FORTRAN + * routine calling a C routine with the following interface: + * + * FORTRAN CALL C declaration + * CALL ATL_F77WRAP_SGEMM(...) void ATL_F77WRAP_SGEMM(...) + * + */ +#if defined( SREAL ) + +#define ATL_F77wrap_srotg ATL_F77WRAP_SROTG +#define ATL_F77wrap_srotmg ATL_F77WRAP_SROTMG +#define ATL_F77wrap_snrm2 ATL_F77WRAP_SNRM2 +#define ATL_F77wrap_sasum ATL_F77WRAP_SASUM +#define ATL_F77wrap_sscal ATL_F77WRAP_SSCAL +#define ATL_F77wrap_isamax ATL_F77WRAP_ISAMAX +#define ATL_F77wrap_saxpy ATL_F77WRAP_SAXPY +#define ATL_F77wrap_scopy ATL_F77WRAP_SCOPY +#define ATL_F77wrap_sswap ATL_F77WRAP_SSWAP +#define ATL_F77wrap_srot ATL_F77WRAP_SROT +#define ATL_F77wrap_srotm ATL_F77WRAP_SROTM +#define ATL_F77wrap_sdot ATL_F77WRAP_SDOT +#define ATL_F77wrap_dsdot ATL_F77WRAP_DSDOT +#define ATL_F77wrap_sdsdot ATL_F77WRAP_SDSDOT + +#define ATL_F77wrap_sgbmv ATL_F77WRAP_SGBMV +#define ATL_F77wrap_sgemv ATL_F77WRAP_SGEMV +#define ATL_F77wrap_sger ATL_F77WRAP_SGER +#define ATL_F77wrap_ssbmv ATL_F77WRAP_SSBMV +#define ATL_F77wrap_sspmv ATL_F77WRAP_SSPMV +#define ATL_F77wrap_ssymv ATL_F77WRAP_SSYMV +#define ATL_F77wrap_sspr ATL_F77WRAP_SSPR +#define ATL_F77wrap_ssyr ATL_F77WRAP_SSYR +#define ATL_F77wrap_sspr2 ATL_F77WRAP_SSPR2 +#define ATL_F77wrap_ssyr2 ATL_F77WRAP_SSYR2 +#define ATL_F77wrap_stbmv ATL_F77WRAP_STBMV +#define ATL_F77wrap_stpmv ATL_F77WRAP_STPMV +#define ATL_F77wrap_strmv ATL_F77WRAP_STRMV +#define ATL_F77wrap_stbsv ATL_F77WRAP_STBSV +#define ATL_F77wrap_stpsv ATL_F77WRAP_STPSV +#define ATL_F77wrap_strsv ATL_F77WRAP_STRSV + +#define ATL_F77wrap_sgemm ATL_F77WRAP_SGEMM +#define ATL_F77wrap_ssymm ATL_F77WRAP_SSYMM +#define ATL_F77wrap_ssyrk ATL_F77WRAP_SSYRK +#define ATL_F77wrap_ssyr2k ATL_F77WRAP_SSYR2K +#define ATL_F77wrap_strmm ATL_F77WRAP_STRMM +#define ATL_F77wrap_strsm ATL_F77WRAP_STRSM + +#elif defined( DREAL ) + +#define ATL_F77wrap_drotg ATL_F77WRAP_DROTG +#define ATL_F77wrap_drotmg ATL_F77WRAP_DROTMG +#define ATL_F77wrap_dnrm2 ATL_F77WRAP_DNRM2 +#define ATL_F77wrap_dasum ATL_F77WRAP_DASUM +#define ATL_F77wrap_dscal ATL_F77WRAP_DSCAL +#define ATL_F77wrap_idamax ATL_F77WRAP_IDAMAX +#define ATL_F77wrap_daxpy ATL_F77WRAP_DAXPY +#define ATL_F77wrap_dcopy ATL_F77WRAP_DCOPY +#define ATL_F77wrap_dswap ATL_F77WRAP_DSWAP +#define ATL_F77wrap_drot ATL_F77WRAP_DROT +#define ATL_F77wrap_drotm ATL_F77WRAP_DROTM +#define ATL_F77wrap_ddot ATL_F77WRAP_DDOT + +#define ATL_F77wrap_dgbmv ATL_F77WRAP_DGBMV +#define ATL_F77wrap_dgemv ATL_F77WRAP_DGEMV +#define ATL_F77wrap_dger ATL_F77WRAP_DGER +#define ATL_F77wrap_dsbmv ATL_F77WRAP_DSBMV +#define ATL_F77wrap_dspmv ATL_F77WRAP_DSPMV +#define ATL_F77wrap_dsymv ATL_F77WRAP_DSYMV +#define ATL_F77wrap_dspr ATL_F77WRAP_DSPR +#define ATL_F77wrap_dsyr ATL_F77WRAP_DSYR +#define ATL_F77wrap_dspr2 ATL_F77WRAP_DSPR2 +#define ATL_F77wrap_dsyr2 ATL_F77WRAP_DSYR2 +#define ATL_F77wrap_dtbmv ATL_F77WRAP_DTBMV +#define ATL_F77wrap_dtpmv ATL_F77WRAP_DTPMV +#define ATL_F77wrap_dtrmv ATL_F77WRAP_DTRMV +#define ATL_F77wrap_dtbsv ATL_F77WRAP_DTBSV +#define ATL_F77wrap_dtpsv ATL_F77WRAP_DTPSV +#define ATL_F77wrap_dtrsv ATL_F77WRAP_DTRSV + +#define ATL_F77wrap_dgemm ATL_F77WRAP_DGEMM +#define ATL_F77wrap_dsymm ATL_F77WRAP_DSYMM +#define ATL_F77wrap_dsyrk ATL_F77WRAP_DSYRK +#define ATL_F77wrap_dsyr2k ATL_F77WRAP_DSYR2K +#define ATL_F77wrap_dtrmm ATL_F77WRAP_DTRMM +#define ATL_F77wrap_dtrsm ATL_F77WRAP_DTRSM + +#elif defined( SCPLX ) + +#define ATL_F77wrap_crotg ATL_F77WRAP_CROTG +#define ATL_F77wrap_scnrm2 ATL_F77WRAP_SCNRM2 +#define ATL_F77wrap_scasum ATL_F77WRAP_SCASUM +#define ATL_F77wrap_cscal ATL_F77WRAP_CSCAL +#define ATL_F77wrap_csscal ATL_F77WRAP_CSSCAL +#define ATL_F77wrap_icamax ATL_F77WRAP_ICAMAX +#define ATL_F77wrap_caxpy ATL_F77WRAP_CAXPY +#define ATL_F77wrap_ccopy ATL_F77WRAP_CCOPY +#define ATL_F77wrap_cswap ATL_F77WRAP_CSWAP +#define ATL_F77wrap_csrot ATL_F77WRAP_CSROT +#define ATL_F77wrap_cdotc ATL_F77WRAP_CDOTC +#define ATL_F77wrap_cdotu ATL_F77WRAP_CDOTU + +#define ATL_F77wrap_cgbmv ATL_F77WRAP_CGBMV +#define ATL_F77wrap_cgemv ATL_F77WRAP_CGEMV +#define ATL_F77wrap_cgerc ATL_F77WRAP_CGERC +#define ATL_F77wrap_cgeru ATL_F77WRAP_CGERU +#define ATL_F77wrap_chbmv ATL_F77WRAP_CHBMV +#define ATL_F77wrap_chpmv ATL_F77WRAP_CHPMV +#define ATL_F77wrap_chemv ATL_F77WRAP_CHEMV +#define ATL_F77wrap_chpr ATL_F77WRAP_CHPR +#define ATL_F77wrap_cher ATL_F77WRAP_CHER +#define ATL_F77wrap_chpr2 ATL_F77WRAP_CHPR2 +#define ATL_F77wrap_cher2 ATL_F77WRAP_CHER2 +#define ATL_F77wrap_ctbmv ATL_F77WRAP_CTBMV +#define ATL_F77wrap_ctpmv ATL_F77WRAP_CTPMV +#define ATL_F77wrap_ctrmv ATL_F77WRAP_CTRMV +#define ATL_F77wrap_ctbsv ATL_F77WRAP_CTBSV +#define ATL_F77wrap_ctpsv ATL_F77WRAP_CTPSV +#define ATL_F77wrap_ctrsv ATL_F77WRAP_CTRSV + +#define ATL_F77wrap_cgemm ATL_F77WRAP_CGEMM +#define ATL_F77wrap_chemm ATL_F77WRAP_CHEMM +#define ATL_F77wrap_cherk ATL_F77WRAP_CHERK +#define ATL_F77wrap_cher2k ATL_F77WRAP_CHER2K +#define ATL_F77wrap_csymm ATL_F77WRAP_CSYMM +#define ATL_F77wrap_csyrk ATL_F77WRAP_CSYRK +#define ATL_F77wrap_csyr2k ATL_F77WRAP_CSYR2K +#define ATL_F77wrap_ctrmm ATL_F77WRAP_CTRMM +#define ATL_F77wrap_ctrsm ATL_F77WRAP_CTRSM + +#elif defined( DCPLX ) + +#define ATL_F77wrap_zrotg ATL_F77WRAP_ZROTG +#define ATL_F77wrap_dznrm2 ATL_F77WRAP_DZNRM2 +#define ATL_F77wrap_dzasum ATL_F77WRAP_DZASUM +#define ATL_F77wrap_zscal ATL_F77WRAP_ZSCAL +#define ATL_F77wrap_zdscal ATL_F77WRAP_ZDSCAL +#define ATL_F77wrap_izamax ATL_F77WRAP_IZAMAX +#define ATL_F77wrap_zaxpy ATL_F77WRAP_ZAXPY +#define ATL_F77wrap_zcopy ATL_F77WRAP_ZCOPY +#define ATL_F77wrap_zswap ATL_F77WRAP_ZSWAP +#define ATL_F77wrap_zdrot ATL_F77WRAP_ZDROT +#define ATL_F77wrap_zdotc ATL_F77WRAP_ZDOTC +#define ATL_F77wrap_zdotu ATL_F77WRAP_ZDOTU + +#define ATL_F77wrap_zgbmv ATL_F77WRAP_ZGBMV +#define ATL_F77wrap_zgemv ATL_F77WRAP_ZGEMV +#define ATL_F77wrap_zgerc ATL_F77WRAP_ZGERC +#define ATL_F77wrap_zgeru ATL_F77WRAP_ZGERU +#define ATL_F77wrap_zhbmv ATL_F77WRAP_ZHBMV +#define ATL_F77wrap_zhpmv ATL_F77WRAP_ZHPMV +#define ATL_F77wrap_zhemv ATL_F77WRAP_ZHEMV +#define ATL_F77wrap_zhpr ATL_F77WRAP_ZHPR +#define ATL_F77wrap_zher ATL_F77WRAP_ZHER +#define ATL_F77wrap_zhpr2 ATL_F77WRAP_ZHPR2 +#define ATL_F77wrap_zher2 ATL_F77WRAP_ZHER2 +#define ATL_F77wrap_ztbmv ATL_F77WRAP_ZTBMV +#define ATL_F77wrap_ztpmv ATL_F77WRAP_ZTPMV +#define ATL_F77wrap_ztrmv ATL_F77WRAP_ZTRMV +#define ATL_F77wrap_ztbsv ATL_F77WRAP_ZTBSV +#define ATL_F77wrap_ztpsv ATL_F77WRAP_ZTPSV +#define ATL_F77wrap_ztrsv ATL_F77WRAP_ZTRSV + +#define ATL_F77wrap_zgemm ATL_F77WRAP_ZGEMM +#define ATL_F77wrap_zhemm ATL_F77WRAP_ZHEMM +#define ATL_F77wrap_zherk ATL_F77WRAP_ZHERK +#define ATL_F77wrap_zher2k ATL_F77WRAP_ZHER2K +#define ATL_F77wrap_zsymm ATL_F77WRAP_ZSYMM +#define ATL_F77wrap_zsyrk ATL_F77WRAP_ZSYRK +#define ATL_F77wrap_zsyr2k ATL_F77WRAP_ZSYR2K +#define ATL_F77wrap_ztrmm ATL_F77WRAP_ZTRMM +#define ATL_F77wrap_ztrsm ATL_F77WRAP_ZTRSM + +#endif + +#elif defined( NoChange ) +/* + * These defines set up the naming scheme required to have a FORTRAN + * routine calling a C routine with the following interface: + * + * FORTRAN CALL C declaration + * CALL ATL_F77WRAP_SGEMM(...) void atl_f77wrap_sgemm(...) + */ +#if defined( SREAL ) + +#define ATL_F77wrap_srotg atl_f77wrap_srotg +#define ATL_F77wrap_srotmg atl_f77wrap_srotmg +#define ATL_F77wrap_snrm2 atl_f77wrap_snrm2 +#define ATL_F77wrap_sasum atl_f77wrap_sasum +#define ATL_F77wrap_sscal atl_f77wrap_sscal +#define ATL_F77wrap_isamax atl_f77wrap_isamax +#define ATL_F77wrap_saxpy atl_f77wrap_saxpy +#define ATL_F77wrap_scopy atl_f77wrap_scopy +#define ATL_F77wrap_sswap atl_f77wrap_sswap +#define ATL_F77wrap_srot atl_f77wrap_srot +#define ATL_F77wrap_srotm atl_f77wrap_srotm +#define ATL_F77wrap_sdot atl_f77wrap_sdot +#define ATL_F77wrap_dsdot atl_f77wrap_dsdot +#define ATL_F77wrap_sdsdot atl_f77wrap_sdsdot + +#define ATL_F77wrap_sgbmv atl_f77wrap_sgbmv +#define ATL_F77wrap_sgemv atl_f77wrap_sgemv +#define ATL_F77wrap_sger atl_f77wrap_sger +#define ATL_F77wrap_ssbmv atl_f77wrap_ssbmv +#define ATL_F77wrap_sspmv atl_f77wrap_sspmv +#define ATL_F77wrap_ssymv atl_f77wrap_ssymv +#define ATL_F77wrap_sspr atl_f77wrap_sspr +#define ATL_F77wrap_ssyr atl_f77wrap_ssyr +#define ATL_F77wrap_sspr2 atl_f77wrap_sspr2 +#define ATL_F77wrap_ssyr2 atl_f77wrap_ssyr2 +#define ATL_F77wrap_stbmv atl_f77wrap_stbmv +#define ATL_F77wrap_stpmv atl_f77wrap_stpmv +#define ATL_F77wrap_strmv atl_f77wrap_strmv +#define ATL_F77wrap_stbsv atl_f77wrap_stbsv +#define ATL_F77wrap_stpsv atl_f77wrap_stpsv +#define ATL_F77wrap_strsv atl_f77wrap_strsv + +#define ATL_F77wrap_sgemm atl_f77wrap_sgemm +#define ATL_F77wrap_ssymm atl_f77wrap_ssymm +#define ATL_F77wrap_ssyrk atl_f77wrap_ssyrk +#define ATL_F77wrap_ssyr2k atl_f77wrap_ssyr2k +#define ATL_F77wrap_strmm atl_f77wrap_strmm +#define ATL_F77wrap_strsm atl_f77wrap_strsm + +#elif defined( DREAL ) + +#define ATL_F77wrap_drotg atl_f77wrap_drotg +#define ATL_F77wrap_drotmg atl_f77wrap_drotmg +#define ATL_F77wrap_dnrm2 atl_f77wrap_dnrm2 +#define ATL_F77wrap_dasum atl_f77wrap_dasum +#define ATL_F77wrap_dscal atl_f77wrap_dscal +#define ATL_F77wrap_idamax atl_f77wrap_idamax +#define ATL_F77wrap_daxpy atl_f77wrap_daxpy +#define ATL_F77wrap_dcopy atl_f77wrap_dcopy +#define ATL_F77wrap_dswap atl_f77wrap_dswap +#define ATL_F77wrap_drot atl_f77wrap_drot +#define ATL_F77wrap_drotm atl_f77wrap_drotm +#define ATL_F77wrap_ddot atl_f77wrap_ddot + +#define ATL_F77wrap_dgbmv atl_f77wrap_dgbmv +#define ATL_F77wrap_dgemv atl_f77wrap_dgemv +#define ATL_F77wrap_dger atl_f77wrap_dger +#define ATL_F77wrap_dsbmv atl_f77wrap_dsbmv +#define ATL_F77wrap_dspmv atl_f77wrap_dspmv +#define ATL_F77wrap_dsymv atl_f77wrap_dsymv +#define ATL_F77wrap_dspr atl_f77wrap_dspr +#define ATL_F77wrap_dsyr atl_f77wrap_dsyr +#define ATL_F77wrap_dspr2 atl_f77wrap_dspr2 +#define ATL_F77wrap_dsyr2 atl_f77wrap_dsyr2 +#define ATL_F77wrap_dtbmv atl_f77wrap_dtbmv +#define ATL_F77wrap_dtpmv atl_f77wrap_dtpmv +#define ATL_F77wrap_dtrmv atl_f77wrap_dtrmv +#define ATL_F77wrap_dtbsv atl_f77wrap_dtbsv +#define ATL_F77wrap_dtpsv atl_f77wrap_dtpsv +#define ATL_F77wrap_dtrsv atl_f77wrap_dtrsv + +#define ATL_F77wrap_dgemm atl_f77wrap_dgemm +#define ATL_F77wrap_dsymm atl_f77wrap_dsymm +#define ATL_F77wrap_dsyrk atl_f77wrap_dsyrk +#define ATL_F77wrap_dsyr2k atl_f77wrap_dsyr2k +#define ATL_F77wrap_dtrmm atl_f77wrap_dtrmm +#define ATL_F77wrap_dtrsm atl_f77wrap_dtrsm + +#elif defined( SCPLX ) + +#define ATL_F77wrap_crotg atl_f77wrap_crotg +#define ATL_F77wrap_scnrm2 atl_f77wrap_scnrm2 +#define ATL_F77wrap_scasum atl_f77wrap_scasum +#define ATL_F77wrap_cscal atl_f77wrap_cscal +#define ATL_F77wrap_csscal atl_f77wrap_csscal +#define ATL_F77wrap_icamax atl_f77wrap_icamax +#define ATL_F77wrap_caxpy atl_f77wrap_caxpy +#define ATL_F77wrap_ccopy atl_f77wrap_ccopy +#define ATL_F77wrap_cswap atl_f77wrap_cswap +#define ATL_F77wrap_csrot atl_f77wrap_csrot +#define ATL_F77wrap_cdotc atl_f77wrap_cdotc +#define ATL_F77wrap_cdotu atl_f77wrap_cdotu + +#define ATL_F77wrap_cgbmv atl_f77wrap_cgbmv +#define ATL_F77wrap_cgemv atl_f77wrap_cgemv +#define ATL_F77wrap_cgerc atl_f77wrap_cgerc +#define ATL_F77wrap_cgeru atl_f77wrap_cgeru +#define ATL_F77wrap_chbmv atl_f77wrap_chbmv +#define ATL_F77wrap_chpmv atl_f77wrap_chpmv +#define ATL_F77wrap_chemv atl_f77wrap_chemv +#define ATL_F77wrap_chpr atl_f77wrap_chpr +#define ATL_F77wrap_cher atl_f77wrap_cher +#define ATL_F77wrap_chpr2 atl_f77wrap_chpr2 +#define ATL_F77wrap_cher2 atl_f77wrap_cher2 +#define ATL_F77wrap_ctbmv atl_f77wrap_ctbmv +#define ATL_F77wrap_ctpmv atl_f77wrap_ctpmv +#define ATL_F77wrap_ctrmv atl_f77wrap_ctrmv +#define ATL_F77wrap_ctbsv atl_f77wrap_ctbsv +#define ATL_F77wrap_ctpsv atl_f77wrap_ctpsv +#define ATL_F77wrap_ctrsv atl_f77wrap_ctrsv + +#define ATL_F77wrap_cgemm atl_f77wrap_cgemm +#define ATL_F77wrap_chemm atl_f77wrap_chemm +#define ATL_F77wrap_cherk atl_f77wrap_cherk +#define ATL_F77wrap_cher2k atl_f77wrap_cher2k +#define ATL_F77wrap_csymm atl_f77wrap_csymm +#define ATL_F77wrap_csyrk atl_f77wrap_csyrk +#define ATL_F77wrap_csyr2k atl_f77wrap_csyr2k +#define ATL_F77wrap_ctrmm atl_f77wrap_ctrmm +#define ATL_F77wrap_ctrsm atl_f77wrap_ctrsm + +#elif defined( DCPLX ) + +#define ATL_F77wrap_zrotg atl_f77wrap_zrotg +#define ATL_F77wrap_dznrm2 atl_f77wrap_dznrm2 +#define ATL_F77wrap_dzasum atl_f77wrap_dzasum +#define ATL_F77wrap_zscal atl_f77wrap_zscal +#define ATL_F77wrap_zdscal atl_f77wrap_zdscal +#define ATL_F77wrap_izamax atl_f77wrap_izamax +#define ATL_F77wrap_zaxpy atl_f77wrap_zaxpy +#define ATL_F77wrap_zcopy atl_f77wrap_zcopy +#define ATL_F77wrap_zswap atl_f77wrap_zswap +#define ATL_F77wrap_zdrot atl_f77wrap_zdrot +#define ATL_F77wrap_zdotc atl_f77wrap_zdotc +#define ATL_F77wrap_zdotu atl_f77wrap_zdotu + +#define ATL_F77wrap_zgbmv atl_f77wrap_zgbmv +#define ATL_F77wrap_zgemv atl_f77wrap_zgemv +#define ATL_F77wrap_zgerc atl_f77wrap_zgerc +#define ATL_F77wrap_zgeru atl_f77wrap_zgeru +#define ATL_F77wrap_zhbmv atl_f77wrap_zhbmv +#define ATL_F77wrap_zhpmv atl_f77wrap_zhpmv +#define ATL_F77wrap_zhemv atl_f77wrap_zhemv +#define ATL_F77wrap_zhpr atl_f77wrap_zhpr +#define ATL_F77wrap_zher atl_f77wrap_zher +#define ATL_F77wrap_zhpr2 atl_f77wrap_zhpr2 +#define ATL_F77wrap_zher2 atl_f77wrap_zher2 +#define ATL_F77wrap_ztbmv atl_f77wrap_ztbmv +#define ATL_F77wrap_ztpmv atl_f77wrap_ztpmv +#define ATL_F77wrap_ztrmv atl_f77wrap_ztrmv +#define ATL_F77wrap_ztbsv atl_f77wrap_ztbsv +#define ATL_F77wrap_ztpsv atl_f77wrap_ztpsv +#define ATL_F77wrap_ztrsv atl_f77wrap_ztrsv + +#define ATL_F77wrap_zgemm atl_f77wrap_zgemm +#define ATL_F77wrap_zhemm atl_f77wrap_zhemm +#define ATL_F77wrap_zherk atl_f77wrap_zherk +#define ATL_F77wrap_zher2k atl_f77wrap_zher2k +#define ATL_F77wrap_zsymm atl_f77wrap_zsymm +#define ATL_F77wrap_zsyrk atl_f77wrap_zsyrk +#define ATL_F77wrap_zsyr2k atl_f77wrap_zsyr2k +#define ATL_F77wrap_ztrmm atl_f77wrap_ztrmm +#define ATL_F77wrap_ztrsm atl_f77wrap_ztrsm + +#endif + +#elif defined( Add__ ) +/* + * These defines set up the naming scheme required to have a FORTRAN + * routine calling a C routine with the following interface: + * + * FORTRAN CALL C declaration + * CALL ATL_F77WRAP_SGEMM(...) void atl_f77wrap_sgemm__(...) + */ +#if defined( SREAL ) + +#define ATL_F77wrap_srotg atl_f77wrap_srotg__ +#define ATL_F77wrap_srotmg atl_f77wrap_srotmg__ +#define ATL_F77wrap_snrm2 atl_f77wrap_snrm2__ +#define ATL_F77wrap_sasum atl_f77wrap_sasum__ +#define ATL_F77wrap_sscal atl_f77wrap_sscal__ +#define ATL_F77wrap_isamax atl_f77wrap_isamax__ +#define ATL_F77wrap_saxpy atl_f77wrap_saxpy__ +#define ATL_F77wrap_scopy atl_f77wrap_scopy__ +#define ATL_F77wrap_sswap atl_f77wrap_sswap__ +#define ATL_F77wrap_srot atl_f77wrap_srot__ +#define ATL_F77wrap_srotm atl_f77wrap_srotm__ +#define ATL_F77wrap_sdot atl_f77wrap_sdot__ +#define ATL_F77wrap_dsdot atl_f77wrap_dsdot__ +#define ATL_F77wrap_sdsdot atl_f77wrap_sdsdot__ + +#define ATL_F77wrap_sgbmv atl_f77wrap_sgbmv__ +#define ATL_F77wrap_sgemv atl_f77wrap_sgemv__ +#define ATL_F77wrap_sger atl_f77wrap_sger__ +#define ATL_F77wrap_ssbmv atl_f77wrap_ssbmv__ +#define ATL_F77wrap_sspmv atl_f77wrap_sspmv__ +#define ATL_F77wrap_ssymv atl_f77wrap_ssymv__ +#define ATL_F77wrap_sspr atl_f77wrap_sspr__ +#define ATL_F77wrap_ssyr atl_f77wrap_ssyr__ +#define ATL_F77wrap_sspr2 atl_f77wrap_sspr2__ +#define ATL_F77wrap_ssyr2 atl_f77wrap_ssyr2__ +#define ATL_F77wrap_stbmv atl_f77wrap_stbmv__ +#define ATL_F77wrap_stpmv atl_f77wrap_stpmv__ +#define ATL_F77wrap_strmv atl_f77wrap_strmv__ +#define ATL_F77wrap_stbsv atl_f77wrap_stbsv__ +#define ATL_F77wrap_stpsv atl_f77wrap_stpsv__ +#define ATL_F77wrap_strsv atl_f77wrap_strsv__ + +#define ATL_F77wrap_sgemm atl_f77wrap_sgemm__ +#define ATL_F77wrap_ssymm atl_f77wrap_ssymm__ +#define ATL_F77wrap_ssyrk atl_f77wrap_ssyrk__ +#define ATL_F77wrap_ssyr2k atl_f77wrap_ssyr2k__ +#define ATL_F77wrap_strmm atl_f77wrap_strmm__ +#define ATL_F77wrap_strsm atl_f77wrap_strsm__ + +#elif defined( DREAL ) + +#define ATL_F77wrap_drotg atl_f77wrap_drotg__ +#define ATL_F77wrap_drotmg atl_f77wrap_drotmg__ +#define ATL_F77wrap_dnrm2 atl_f77wrap_dnrm2__ +#define ATL_F77wrap_dasum atl_f77wrap_dasum__ +#define ATL_F77wrap_dscal atl_f77wrap_dscal__ +#define ATL_F77wrap_idamax atl_f77wrap_idamax__ +#define ATL_F77wrap_daxpy atl_f77wrap_daxpy__ +#define ATL_F77wrap_dcopy atl_f77wrap_dcopy__ +#define ATL_F77wrap_dswap atl_f77wrap_dswap__ +#define ATL_F77wrap_drot atl_f77wrap_drot__ +#define ATL_F77wrap_drotm atl_f77wrap_drotm__ +#define ATL_F77wrap_ddot atl_f77wrap_ddot__ + +#define ATL_F77wrap_dgbmv atl_f77wrap_dgbmv__ +#define ATL_F77wrap_dgemv atl_f77wrap_dgemv__ +#define ATL_F77wrap_dger atl_f77wrap_dger__ +#define ATL_F77wrap_dsbmv atl_f77wrap_dsbmv__ +#define ATL_F77wrap_dspmv atl_f77wrap_dspmv__ +#define ATL_F77wrap_dsymv atl_f77wrap_dsymv__ +#define ATL_F77wrap_dspr atl_f77wrap_dspr__ +#define ATL_F77wrap_dsyr atl_f77wrap_dsyr__ +#define ATL_F77wrap_dspr2 atl_f77wrap_dspr2__ +#define ATL_F77wrap_dsyr2 atl_f77wrap_dsyr2__ +#define ATL_F77wrap_dtbmv atl_f77wrap_dtbmv__ +#define ATL_F77wrap_dtpmv atl_f77wrap_dtpmv__ +#define ATL_F77wrap_dtrmv atl_f77wrap_dtrmv__ +#define ATL_F77wrap_dtbsv atl_f77wrap_dtbsv__ +#define ATL_F77wrap_dtpsv atl_f77wrap_dtpsv__ +#define ATL_F77wrap_dtrsv atl_f77wrap_dtrsv__ + +#define ATL_F77wrap_dgemm atl_f77wrap_dgemm__ +#define ATL_F77wrap_dsymm atl_f77wrap_dsymm__ +#define ATL_F77wrap_dsyrk atl_f77wrap_dsyrk__ +#define ATL_F77wrap_dsyr2k atl_f77wrap_dsyr2k__ +#define ATL_F77wrap_dtrmm atl_f77wrap_dtrmm__ +#define ATL_F77wrap_dtrsm atl_f77wrap_dtrsm__ + +#elif defined( SCPLX ) + +#define ATL_F77wrap_crotg atl_f77wrap_crotg__ +#define ATL_F77wrap_scnrm2 atl_f77wrap_scnrm2__ +#define ATL_F77wrap_scasum atl_f77wrap_scasum__ +#define ATL_F77wrap_cscal atl_f77wrap_cscal__ +#define ATL_F77wrap_csscal atl_f77wrap_csscal__ +#define ATL_F77wrap_icamax atl_f77wrap_icamax__ +#define ATL_F77wrap_caxpy atl_f77wrap_caxpy__ +#define ATL_F77wrap_ccopy atl_f77wrap_ccopy__ +#define ATL_F77wrap_cswap atl_f77wrap_cswap__ +#define ATL_F77wrap_csrot atl_f77wrap_csrot__ +#define ATL_F77wrap_cdotc atl_f77wrap_cdotc__ +#define ATL_F77wrap_cdotu atl_f77wrap_cdotu__ + +#define ATL_F77wrap_cgbmv atl_f77wrap_cgbmv__ +#define ATL_F77wrap_cgemv atl_f77wrap_cgemv__ +#define ATL_F77wrap_cgerc atl_f77wrap_cgerc__ +#define ATL_F77wrap_cgeru atl_f77wrap_cgeru__ +#define ATL_F77wrap_chbmv atl_f77wrap_chbmv__ +#define ATL_F77wrap_chpmv atl_f77wrap_chpmv__ +#define ATL_F77wrap_chemv atl_f77wrap_chemv__ +#define ATL_F77wrap_chpr atl_f77wrap_chpr__ +#define ATL_F77wrap_cher atl_f77wrap_cher__ +#define ATL_F77wrap_chpr2 atl_f77wrap_chpr2__ +#define ATL_F77wrap_cher2 atl_f77wrap_cher2__ +#define ATL_F77wrap_ctbmv atl_f77wrap_ctbmv__ +#define ATL_F77wrap_ctpmv atl_f77wrap_ctpmv__ +#define ATL_F77wrap_ctrmv atl_f77wrap_ctrmv__ +#define ATL_F77wrap_ctbsv atl_f77wrap_ctbsv__ +#define ATL_F77wrap_ctpsv atl_f77wrap_ctpsv__ +#define ATL_F77wrap_ctrsv atl_f77wrap_ctrsv__ + +#define ATL_F77wrap_cgemm atl_f77wrap_cgemm__ +#define ATL_F77wrap_chemm atl_f77wrap_chemm__ +#define ATL_F77wrap_cherk atl_f77wrap_cherk__ +#define ATL_F77wrap_cher2k atl_f77wrap_cher2k__ +#define ATL_F77wrap_csymm atl_f77wrap_csymm__ +#define ATL_F77wrap_csyrk atl_f77wrap_csyrk__ +#define ATL_F77wrap_csyr2k atl_f77wrap_csyr2k__ +#define ATL_F77wrap_ctrmm atl_f77wrap_ctrmm__ +#define ATL_F77wrap_ctrsm atl_f77wrap_ctrsm__ + +#elif defined( DCPLX ) + +#define ATL_F77wrap_zrotg atl_f77wrap_zrotg__ +#define ATL_F77wrap_dznrm2 atl_f77wrap_dznrm2__ +#define ATL_F77wrap_dzasum atl_f77wrap_dzasum__ +#define ATL_F77wrap_zscal atl_f77wrap_zscal__ +#define ATL_F77wrap_zdscal atl_f77wrap_zdscal__ +#define ATL_F77wrap_izamax atl_f77wrap_izamax__ +#define ATL_F77wrap_zaxpy atl_f77wrap_zaxpy__ +#define ATL_F77wrap_zcopy atl_f77wrap_zcopy__ +#define ATL_F77wrap_zswap atl_f77wrap_zswap__ +#define ATL_F77wrap_zdrot atl_f77wrap_zdrot__ +#define ATL_F77wrap_zdotc atl_f77wrap_zdotc__ +#define ATL_F77wrap_zdotu atl_f77wrap_zdotu__ + +#define ATL_F77wrap_zgbmv atl_f77wrap_zgbmv__ +#define ATL_F77wrap_zgemv atl_f77wrap_zgemv__ +#define ATL_F77wrap_zgerc atl_f77wrap_zgerc__ +#define ATL_F77wrap_zgeru atl_f77wrap_zgeru__ +#define ATL_F77wrap_zhbmv atl_f77wrap_zhbmv__ +#define ATL_F77wrap_zhpmv atl_f77wrap_zhpmv__ +#define ATL_F77wrap_zhemv atl_f77wrap_zhemv__ +#define ATL_F77wrap_zhpr atl_f77wrap_zhpr__ +#define ATL_F77wrap_zher atl_f77wrap_zher__ +#define ATL_F77wrap_zhpr2 atl_f77wrap_zhpr2__ +#define ATL_F77wrap_zher2 atl_f77wrap_zher2__ +#define ATL_F77wrap_ztbmv atl_f77wrap_ztbmv__ +#define ATL_F77wrap_ztpmv atl_f77wrap_ztpmv__ +#define ATL_F77wrap_ztrmv atl_f77wrap_ztrmv__ +#define ATL_F77wrap_ztbsv atl_f77wrap_ztbsv__ +#define ATL_F77wrap_ztpsv atl_f77wrap_ztpsv__ +#define ATL_F77wrap_ztrsv atl_f77wrap_ztrsv__ + +#define ATL_F77wrap_zgemm atl_f77wrap_zgemm__ +#define ATL_F77wrap_zhemm atl_f77wrap_zhemm__ +#define ATL_F77wrap_zherk atl_f77wrap_zherk__ +#define ATL_F77wrap_zher2k atl_f77wrap_zher2k__ +#define ATL_F77wrap_zsymm atl_f77wrap_zsymm__ +#define ATL_F77wrap_zsyrk atl_f77wrap_zsyrk__ +#define ATL_F77wrap_zsyr2k atl_f77wrap_zsyr2k__ +#define ATL_F77wrap_ztrmm atl_f77wrap_ztrmm__ +#define ATL_F77wrap_ztrsm atl_f77wrap_ztrsm__ + +#endif + +#endif +/* + * ===================================================================== + * Prototypes for F77 interface wrappers ATLAS BLAS routines + * ===================================================================== + */ +void Mjoin( PATLF77WRAP, rotg ) +( TYPE *, TYPE *, TYPE *, TYPE * ); +#ifdef TREAL +void Mjoin( PATLF77WRAP, rotmg ) +( TYPE *, TYPE *, TYPE *, TYPE *, + TYPE * ); +#endif +void Mjoin( ATLUPF77WRAP, nrm2 ) +( F77_INTEGER *, TYPE *, F77_INTEGER *, TYPE * ); +void Mjoin( ATLUPF77WRAP, asum ) +( F77_INTEGER *, TYPE *, F77_INTEGER *, TYPE * ); +void Mjoin( PATLF77WRAP, scal ) +( F77_INTEGER *, TYPE *, TYPE *, F77_INTEGER * ); +#ifdef TCPLX +void Mjoin( ATLPUF77WRAP, scal ) +( F77_INTEGER *, TYPE *, TYPE *, F77_INTEGER * ); +#endif +void Mjoin( Mjoin( ATL_F77wrap_i, PRE ), amax ) +( F77_INTEGER *, TYPE *, F77_INTEGER *, F77_INTEGER * ); +void Mjoin( PATLF77WRAP, axpy ) +( F77_INTEGER *, TYPE *, TYPE *, F77_INTEGER *, + TYPE *, F77_INTEGER * ); +void Mjoin( PATLF77WRAP, copy ) +( F77_INTEGER *, TYPE *, F77_INTEGER *, TYPE *, + F77_INTEGER * ); +void Mjoin( PATLF77WRAP, swap ) +( F77_INTEGER *, TYPE *, F77_INTEGER *, TYPE *, + F77_INTEGER * ); +void Mjoin( ATLPUF77WRAP, rot ) +( F77_INTEGER *, TYPE *, F77_INTEGER *, TYPE *, + F77_INTEGER *, TYPE *, TYPE * ); +#ifdef TREAL +void Mjoin( PATLF77WRAP, rotm ) +( F77_INTEGER *, TYPE *, F77_INTEGER *, TYPE *, + F77_INTEGER *, TYPE * ); +#endif +#ifdef TREAL +void Mjoin( PATLF77WRAP, dot ) +( F77_INTEGER *, TYPE *, F77_INTEGER *, TYPE *, + F77_INTEGER *, TYPE * ); +#else +void Mjoin( PATLF77WRAP, dotc ) +( F77_INTEGER *, TYPE *, F77_INTEGER *, TYPE *, + F77_INTEGER *, TYPE * ); +void Mjoin( PATLF77WRAP, dotu ) +( F77_INTEGER *, TYPE *, F77_INTEGER *, TYPE *, + F77_INTEGER *, TYPE * ); +#endif +void ATL_F77wrap_dsdot +( F77_INTEGER *, float *, F77_INTEGER *, float *, + F77_INTEGER *, double * ); +void ATL_F77wrap_sdsdot +( F77_INTEGER *, float *, float *, F77_INTEGER *, + float *, F77_INTEGER *, float * ); + +void Mjoin( PATLF77WRAP, gbmv ) +( F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, + F77_INTEGER *, TYPE *, TYPE *, F77_INTEGER *, + TYPE *, F77_INTEGER *, TYPE *, TYPE *, + F77_INTEGER * ); +void Mjoin( PATLF77WRAP, gemv ) +( F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, TYPE *, + TYPE *, F77_INTEGER *, TYPE *, F77_INTEGER *, + TYPE *, TYPE *, F77_INTEGER * ); +#ifdef TREAL +void Mjoin( PATLF77WRAP, ger ) +( F77_INTEGER *, F77_INTEGER *, TYPE *, TYPE *, + F77_INTEGER *, TYPE *, F77_INTEGER *, TYPE *, + F77_INTEGER * ); +void Mjoin( PATLF77WRAP, sbmv ) +( F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, TYPE *, + TYPE *, F77_INTEGER *, TYPE *, F77_INTEGER *, + TYPE *, TYPE *, F77_INTEGER * ); +void Mjoin( PATLF77WRAP, spmv ) +( F77_INTEGER *, F77_INTEGER *, TYPE *, TYPE *, + TYPE *, F77_INTEGER *, TYPE *, TYPE *, + F77_INTEGER * ); +void Mjoin( PATLF77WRAP, symv ) +( F77_INTEGER *, F77_INTEGER *, TYPE *, TYPE *, + F77_INTEGER *, TYPE *, F77_INTEGER *, TYPE *, + TYPE *, F77_INTEGER * ); +void Mjoin( PATLF77WRAP, spr ) +( F77_INTEGER *, F77_INTEGER *, TYPE *, TYPE *, + F77_INTEGER *, TYPE * ); +void Mjoin( PATLF77WRAP, syr ) +( F77_INTEGER *, F77_INTEGER *, TYPE *, TYPE *, + F77_INTEGER *, TYPE *, F77_INTEGER * ); +void Mjoin( PATLF77WRAP, spr2 ) +( F77_INTEGER *, F77_INTEGER *, TYPE *, TYPE *, + F77_INTEGER *, TYPE *, F77_INTEGER *, TYPE * ); +void Mjoin( PATLF77WRAP, syr2 ) +( F77_INTEGER *, F77_INTEGER *, TYPE *, TYPE *, + F77_INTEGER *, TYPE *, F77_INTEGER *, TYPE *, + F77_INTEGER * ); +#else +void Mjoin( PATLF77WRAP, gerc ) +( F77_INTEGER *, F77_INTEGER *, TYPE *, TYPE *, + F77_INTEGER *, TYPE *, F77_INTEGER *, TYPE *, + F77_INTEGER * ); +void Mjoin( PATLF77WRAP, geru ) +( F77_INTEGER *, F77_INTEGER *, TYPE *, TYPE *, + F77_INTEGER *, TYPE *, F77_INTEGER *, TYPE *, + F77_INTEGER * ); +void Mjoin( PATLF77WRAP, hbmv ) +( F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, TYPE *, + TYPE *, F77_INTEGER *, TYPE *, F77_INTEGER *, + TYPE *, TYPE *, F77_INTEGER * ); +void Mjoin( PATLF77WRAP, hpmv ) +( F77_INTEGER *, F77_INTEGER *, TYPE *, TYPE *, + TYPE *, F77_INTEGER *, TYPE *, TYPE *, + F77_INTEGER * ); +void Mjoin( PATLF77WRAP, hemv ) +( F77_INTEGER *, F77_INTEGER *, TYPE *, TYPE *, + F77_INTEGER *, TYPE *, F77_INTEGER *, TYPE *, + TYPE *, F77_INTEGER * ); +void Mjoin( PATLF77WRAP, hpr ) +( F77_INTEGER *, F77_INTEGER *, TYPE *, TYPE *, + F77_INTEGER *, TYPE * ); +void Mjoin( PATLF77WRAP, her ) +( F77_INTEGER *, F77_INTEGER *, TYPE *, TYPE *, + F77_INTEGER *, TYPE *, F77_INTEGER * ); +void Mjoin( PATLF77WRAP, hpr2 ) +( F77_INTEGER *, F77_INTEGER *, TYPE *, TYPE *, + F77_INTEGER *, TYPE *, F77_INTEGER *, TYPE * ); +void Mjoin( PATLF77WRAP, her2 ) +( F77_INTEGER *, F77_INTEGER *, TYPE *, TYPE *, + F77_INTEGER *, TYPE *, F77_INTEGER *, TYPE *, + F77_INTEGER * ); +#endif +void Mjoin( PATLF77WRAP, tbmv ) +( F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, + F77_INTEGER *, TYPE *, F77_INTEGER *, TYPE *, + F77_INTEGER * ); +void Mjoin( PATLF77WRAP, tpmv ) +( F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, + TYPE *, TYPE *, F77_INTEGER * ); +void Mjoin( PATLF77WRAP, trmv ) +( F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, + TYPE *, F77_INTEGER *, TYPE *, F77_INTEGER * ); +void Mjoin( PATLF77WRAP, tbsv ) +( F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, + F77_INTEGER *, TYPE *, F77_INTEGER *, TYPE *, + F77_INTEGER * ); +void Mjoin( PATLF77WRAP, tpsv ) +( F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, + TYPE *, TYPE *, F77_INTEGER * ); +void Mjoin( PATLF77WRAP, trsv ) +( F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, + TYPE *, F77_INTEGER *, TYPE *, F77_INTEGER * ); + +void Mjoin( PATLF77WRAP, gemm ) +( F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, + F77_INTEGER *, TYPE *, TYPE *, F77_INTEGER *, + TYPE *, F77_INTEGER *, TYPE *, TYPE *, + F77_INTEGER * ); +#ifdef TCPLX +void Mjoin( PATLF77WRAP, hemm ) +( F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, + TYPE *, TYPE *, F77_INTEGER *, TYPE *, + F77_INTEGER *, TYPE *, TYPE *, F77_INTEGER * ); +void Mjoin( PATLF77WRAP, herk ) +( F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, + TYPE *, TYPE *, F77_INTEGER *, TYPE *, + TYPE *, F77_INTEGER * ); +void Mjoin( PATLF77WRAP, her2k ) +( F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, + TYPE *, TYPE *, F77_INTEGER *, TYPE *, + F77_INTEGER *, TYPE *, TYPE *, F77_INTEGER * ); +#endif +void Mjoin( PATLF77WRAP, symm ) +( F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, + TYPE *, TYPE *, F77_INTEGER *, TYPE *, + F77_INTEGER *, TYPE *, TYPE *, F77_INTEGER * ); +void Mjoin( PATLF77WRAP, syrk ) +( F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, + TYPE *, TYPE *, F77_INTEGER *, TYPE *, + TYPE *, F77_INTEGER * ); +void Mjoin( PATLF77WRAP, syr2k ) +( F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, + TYPE *, TYPE *, F77_INTEGER *, TYPE *, + F77_INTEGER *, TYPE *, TYPE *, F77_INTEGER * ); +void Mjoin( PATLF77WRAP, trmm ) +( F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, + F77_INTEGER *, F77_INTEGER *, TYPE *, TYPE *, + F77_INTEGER *, TYPE *, F77_INTEGER * ); +void Mjoin( PATLF77WRAP, trsm ) +( F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, F77_INTEGER *, + F77_INTEGER *, F77_INTEGER *, TYPE *, TYPE *, + F77_INTEGER *, TYPE *, F77_INTEGER * ); + +#endif +/* + * End of atlas_f77wrap.h + */ diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_fopen.h b/kaldi_io/src/tools/ATLAS/include/atlas_fopen.h new file mode 100644 index 0000000..aaed713 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_fopen.h @@ -0,0 +1,40 @@ +#ifndef ATLAS_FOPEN_H +#define ATLAS_FOPEN_H + +static int FileExists(const char *path) +{ + FILE *fp; + int iret=0; + fp = fopen(path, "r"); + if (fp) + { + fclose(fp); + iret = 1; + } + return(iret); +} + +#ifdef ATL_FOPENDELAY +static FILE *ATL_fopen(const char *path, const char *mode) +/* + * Overload fopen so it waits for NFS propogation upon first read failure + */ +{ + FILE *fp; + char ln[256]; + + fp = fopen(path, mode); + if (fp == NULL) + { + if (*mode == 'r') /* give NFS time to produce file */ + { + sprintf(ln, "make waitfile waitfile=%s\n", path); + if (system(ln) == 0) fp = fopen(path, mode); + } + } + return(fp); +} +#define fopen ATL_fopen +#endif + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_kern3.h b/kaldi_io/src/tools/ATLAS/include/atlas_kern3.h new file mode 100644 index 0000000..97e8bcc --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_kern3.h @@ -0,0 +1,110 @@ +/* + * Automatically Tuned Linear Algebra Software v3.8.3 + * (C) Copyright 1999 R. Clint Whaley + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the ATLAS group or the names of its contributers may + * not be used to endorse or promote products derived from this + * software without specific written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef ATLAS_KERN3_H +#define ATLAS_KERN3_H + +#include "atlas_misc.h" +#include Mstr(Mjoin(Mjoin(atlas_,PRE),NCmm.h)) +#include "atlas_lvl3.h" +#include "atlas_kernel3.h" +#include "atlas_reflevel3.h" +/* + * Gemm entry points + */ +#define CgemmNN Mjoin(PATL,gemmNN) +#define CgemmNT Mjoin(PATL,gemmNT) +#define CgemmTN Mjoin(PATL,gemmTN) +#define CgemmNC Mjoin(PATL,gemmNC) +#define CgemmCN Mjoin(PATL,gemmCN) + +#define CAgemmNN Mjoin(PATL,aliased_gemmNN) +#define CAgemmTN Mjoin(PATL,aliased_gemmTN) + +#ifdef Left_ + #define Side_ AtlasLeft + #define SideNM L +#elif defined(Right_) + #define Side_ AtlasRight + #define SideNM R +#endif + +#ifdef Upper_ + #define Uplo_ AtlasUpper + #define UploNM U +#elif defined(Lower_) + #define Uplo_ AtlasLower + #define UploNM L +#endif + +#ifdef UnitDiag_ + #define Unit_ AtlasUnit + #define UnitNM U +#elif defined(NonUnitDiag_) + #define Unit_ AtlasNonUnit + #define UnitNM N +#endif + +#ifdef Transpose_ + #define Trans_ AtlasTrans + #define TransNM T +#elif defined(Notranspose_) + #define Trans_ AtlasNoTrans + #define TransNM N +#elif defined(ConjTrans_) + #define Trans_ AtlasConjTrans + #define TransNM C +#endif + +#ifndef TRSM_Xover + #define TRSM_Xover NB +#endif +#ifndef TRMM_Xover + #define TRMM_Xover NB +#endif +#ifndef HER2K_Xover + #define HER2K_Xover NB +#endif +#ifndef SYR2K_Xover + #define SYR2K_Xover NB +#endif +#ifndef HERK_Xover + #define HERK_Xover NB +#endif +#ifndef SYRK_Xover + #define SYRK_Xover NB +#endif +#ifndef HEMM_Xover + #define HEMM_Xover NB +#endif +#ifndef SYMM_Xover + #define SYMM_Xover NB +#endif + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_kernel2.h b/kaldi_io/src/tools/ATLAS/include/atlas_kernel2.h new file mode 100644 index 0000000..4663def --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_kernel2.h @@ -0,0 +1,5408 @@ +/* --------------------------------------------------------------------- + * + * -- Automatically Tuned Linear Algebra Software (ATLAS) + * (C) Copyright 2000 All Rights Reserved + * + * -- ATLAS routine -- Version 3.2 -- December 25, 2000 + * + * Author : Antoine P. Petitet + * Contributor(s) : R. Clint Whaley + * Originally developed at the University of Tennessee, + * Innovative Computing Laboratory, Knoxville TN, 37996-1301, USA. + * + * --------------------------------------------------------------------- + * + * -- Copyright notice and Licensing terms: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in + * the documentation and/or other materials provided with the distri- + * bution. + * 3. The name of the University, the ATLAS group, or the names of its + * contributors may not be used to endorse or promote products deri- + * ved from this software without specific written permission. + * + * -- Disclaimer: + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEO- + * RY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (IN- + * CLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * --------------------------------------------------------------------- + */ +#ifndef ATLAS_KERNEL2_H +#define ATLAS_KERNEL2_H +/* + * ===================================================================== + * Macro function definitions + * ===================================================================== + */ +#define ATL_GetPartSBMV ATL_GetPartSYMV +#define ATL_GetPartSPMV ATL_GetPartSYMV +#define ATL_GetPartP1 ATL_GetPartR1 + +#define MLpprev( n_, a_, lda_ ) \ + { a_ -= ( (((n_) * (lda_)) + (((n_)*((n_)+1)) >> 1)) SHIFT ); lda_ += (n_); } +#define MUpprev( n_, a_, lda_ ) \ + { a_ -= ( (((n_) * (lda_)) - (((n_)*((n_)-1)) >> 1)) SHIFT ); lda_ -= (n_); } +#define MLpnext( n_, a_, lda_ ) \ + { a_ += ( (((n_) * (lda_)) - (((n_)*((n_)-1)) >> 1)) SHIFT ); lda_ -= (n_); } +#define MUpnext( n_, a_, lda_ ) \ + { a_ += ( (((n_) * (lda_)) + (((n_)*((n_)+1)) >> 1)) SHIFT ); lda_ += (n_); } + +#define MLrprev( n_, a_, lda_ ) \ + { a_ -= ( ((n_) * ((lda_)+1)) SHIFT ); } +#define MUrprev( n_, a_, lda_ ) \ + { a_ -= ( ((n_) * ((lda_)+1)) SHIFT ); } +#define MLrnext( n_, a_, lda_ ) \ + { a_ += ( ((n_) * ((lda_)+1)) SHIFT ); } +#define MUrnext( n_, a_, lda_ ) \ + { a_ += ( ((n_) * ((lda_)+1)) SHIFT ); } +/* + * ===================================================================== + * Recursive Level 2 BLAS function prototypes + * ===================================================================== + */ +void ATL_strsvLTU +( + const int, + const float *, const int, + float * +); + +void ATL_strsvLNU +( + const int, + const float *, const int, + float * +); + +void ATL_strsvLTN +( + const int, + const float *, const int, + float * +); + +void ATL_strsvLNN +( + const int, + const float *, const int, + float * +); + +void ATL_strsvUTU +( + const int, + const float *, const int, + float * +); + +void ATL_strsvUNU +( + const int, + const float *, const int, + float * +); + +void ATL_strsvUTN +( + const int, + const float *, const int, + float * +); + +void ATL_strsvUNN +( + const int, + const float *, const int, + float * +); + +void ATL_strsvLT +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_strsvLN +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_strsvUT +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_strsvUN +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_stpsvLTU +( + const int, + const float *, const int, + float * +); + +void ATL_stpsvLNU +( + const int, + const float *, const int, + float * +); + +void ATL_stpsvLTN +( + const int, + const float *, const int, + float * +); + +void ATL_stpsvLNN +( + const int, + const float *, const int, + float * +); + +void ATL_stpsvUTU +( + const int, + const float *, const int, + float * +); + +void ATL_stpsvUNU +( + const int, + const float *, const int, + float * +); + +void ATL_stpsvUTN +( + const int, + const float *, const int, + float * +); + +void ATL_stpsvUNN +( + const int, + const float *, const int, + float * +); + +void ATL_stpsvLT +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_stpsvLN +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_stpsvUT +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_stpsvUN +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_stbsvLTU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_stbsvLNU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_stbsvLTN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_stbsvLNN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_stbsvUTU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_stbsvUNU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_stbsvUTN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_stbsvUNN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_stbsvLT +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_stbsvLN +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_stbsvUT +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_stbsvUN +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_strmvLTU +( + const int, + const float *, const int, + float * +); + +void ATL_strmvLNU +( + const int, + const float *, const int, + float * +); + +void ATL_strmvLTN +( + const int, + const float *, const int, + float * +); + +void ATL_strmvLNN +( + const int, + const float *, const int, + float * +); + +void ATL_strmvUTU +( + const int, + const float *, const int, + float * +); + +void ATL_strmvUNU +( + const int, + const float *, const int, + float * +); + +void ATL_strmvUTN +( + const int, + const float *, const int, + float * +); + +void ATL_strmvUNN +( + const int, + const float *, const int, + float * +); + +void ATL_strmvLT +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_strmvLN +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_strmvUT +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_strmvUN +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_stpmvLTU +( + const int, + const float *, const int, + float * +); + +void ATL_stpmvLNU +( + const int, + const float *, const int, + float * +); + +void ATL_stpmvLTN +( + const int, + const float *, const int, + float * +); + +void ATL_stpmvLNN +( + const int, + const float *, const int, + float * +); + +void ATL_stpmvUTU +( + const int, + const float *, const int, + float * +); + +void ATL_stpmvUNU +( + const int, + const float *, const int, + float * +); + +void ATL_stpmvUTN +( + const int, + const float *, const int, + float * +); + +void ATL_stpmvUNN +( + const int, + const float *, const int, + float * +); + +void ATL_stpmvLT +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_stpmvLN +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_stpmvUT +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_stpmvUN +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_stbmvLTU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_stbmvLNU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_stbmvLTN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_stbmvLNN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_stbmvUTU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_stbmvUNU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_stbmvUTN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_stbmvUNN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_stbmvLT +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_stbmvLN +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_stbmvUT +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_stbmvUN +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_ssyr2U +( + const int, + const float *, + const float *, + float *, const int +); + +void ATL_ssyr2L +( + const int, + const float *, + const float *, + float *, const int +); + +void ATL_sspr2U +( + const int, + const float *, + const float *, + float *, const int +); + +void ATL_sspr2L +( + const int, + const float *, + const float *, + float *, const int +); + +void ATL_ssyrU +( + const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_ssyrL +( + const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_ssprU +( + const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_ssprL +( + const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_ssymvU +( + const int, + const float *, const int, + const float *, + const float, + float * +); + +void ATL_ssymvL +( + const int, + const float *, const int, + const float *, + const float, + float * +); + +void ATL_sspmvU +( + const int, + const float *, const int, + const float *, + const float, + float * +); + +void ATL_sspmvL +( + const int, + const float *, const int, + const float *, + const float, + float * +); + +void ATL_ssbmvU +( + const int, const int, + const float *, const int, + const float *, + const float, + float * +); + +void ATL_ssbmvL +( + const int, const int, + const float *, const int, + const float *, + const float, + float * +); + +void ATL_sgpmv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_sgprU +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_sgprL +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_sgpr +( + const enum ATLAS_UPLO, + const int, const int, + const float, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_sgpr1U_a1_x1_yX +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_sgpr1L_a1_x1_yX +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_sgpmvUT_a1_x1_bX_y1 +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_sgpmvUN_a1_x1_bX_y1 +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_sgpmvUT_a1_x1_b1_y1 +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_sgpmvUN_a1_x1_b1_y1 +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_sgpmvUT_a1_x1_b0_y1 +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_sgpmvUN_a1_x1_b0_y1 +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_sgpmvLT_a1_x1_bX_y1 +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_sgpmvLN_a1_x1_bX_y1 +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_sgpmvLT_a1_x1_b1_y1 +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_sgpmvLN_a1_x1_b1_y1 +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_sgpmvLT_a1_x1_b0_y1 +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_sgpmvLN_a1_x1_b0_y1 +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_sgbmvT_a1_x1_bX_y1 +( + const int, const int, + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_sgbmvN_a1_x1_bX_y1 +( + const int, const int, + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_sgbmvT_a1_x1_b1_y1 +( + const int, const int, + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_sgbmvN_a1_x1_b1_y1 +( + const int, const int, + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_sgbmvT_a1_x1_b0_y1 +( + const int, const int, + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_sgbmvN_a1_x1_b0_y1 +( + const int, const int, + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_dtrsvLTU +( + const int, + const double *, const int, + double * +); + +void ATL_dtrsvLNU +( + const int, + const double *, const int, + double * +); + +void ATL_dtrsvLTN +( + const int, + const double *, const int, + double * +); + +void ATL_dtrsvLNN +( + const int, + const double *, const int, + double * +); + +void ATL_dtrsvUTU +( + const int, + const double *, const int, + double * +); + +void ATL_dtrsvUNU +( + const int, + const double *, const int, + double * +); + +void ATL_dtrsvUTN +( + const int, + const double *, const int, + double * +); + +void ATL_dtrsvUNN +( + const int, + const double *, const int, + double * +); + +void ATL_dtrsvLT +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_dtrsvLN +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_dtrsvUT +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_dtrsvUN +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_dtpsvLTU +( + const int, + const double *, const int, + double * +); + +void ATL_dtpsvLNU +( + const int, + const double *, const int, + double * +); + +void ATL_dtpsvLTN +( + const int, + const double *, const int, + double * +); + +void ATL_dtpsvLNN +( + const int, + const double *, const int, + double * +); + +void ATL_dtpsvUTU +( + const int, + const double *, const int, + double * +); + +void ATL_dtpsvUNU +( + const int, + const double *, const int, + double * +); + +void ATL_dtpsvUTN +( + const int, + const double *, const int, + double * +); + +void ATL_dtpsvUNN +( + const int, + const double *, const int, + double * +); + +void ATL_dtpsvLT +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_dtpsvLN +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_dtpsvUT +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_dtpsvUN +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_dtbsvLTU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_dtbsvLNU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_dtbsvLTN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_dtbsvLNN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_dtbsvUTU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_dtbsvUNU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_dtbsvUTN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_dtbsvUNN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_dtbsvLT +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_dtbsvLN +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_dtbsvUT +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_dtbsvUN +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_dtrmvLTU +( + const int, + const double *, const int, + double * +); + +void ATL_dtrmvLNU +( + const int, + const double *, const int, + double * +); + +void ATL_dtrmvLTN +( + const int, + const double *, const int, + double * +); + +void ATL_dtrmvLNN +( + const int, + const double *, const int, + double * +); + +void ATL_dtrmvUTU +( + const int, + const double *, const int, + double * +); + +void ATL_dtrmvUNU +( + const int, + const double *, const int, + double * +); + +void ATL_dtrmvUTN +( + const int, + const double *, const int, + double * +); + +void ATL_dtrmvUNN +( + const int, + const double *, const int, + double * +); + +void ATL_dtrmvLT +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_dtrmvLN +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_dtrmvUT +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_dtrmvUN +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_dtpmvLTU +( + const int, + const double *, const int, + double * +); + +void ATL_dtpmvLNU +( + const int, + const double *, const int, + double * +); + +void ATL_dtpmvLTN +( + const int, + const double *, const int, + double * +); + +void ATL_dtpmvLNN +( + const int, + const double *, const int, + double * +); + +void ATL_dtpmvUTU +( + const int, + const double *, const int, + double * +); + +void ATL_dtpmvUNU +( + const int, + const double *, const int, + double * +); + +void ATL_dtpmvUTN +( + const int, + const double *, const int, + double * +); + +void ATL_dtpmvUNN +( + const int, + const double *, const int, + double * +); + +void ATL_dtpmvLT +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_dtpmvLN +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_dtpmvUT +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_dtpmvUN +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_dtbmvLTU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_dtbmvLNU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_dtbmvLTN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_dtbmvLNN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_dtbmvUTU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_dtbmvUNU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_dtbmvUTN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_dtbmvUNN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_dtbmvLT +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_dtbmvLN +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_dtbmvUT +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_dtbmvUN +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_dsyr2U +( + const int, + const double *, + const double *, + double *, const int +); + +void ATL_dsyr2L +( + const int, + const double *, + const double *, + double *, const int +); + +void ATL_dspr2U +( + const int, + const double *, + const double *, + double *, const int +); + +void ATL_dspr2L +( + const int, + const double *, + const double *, + double *, const int +); + +void ATL_dsyrU +( + const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_dsyrL +( + const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_dsprU +( + const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_dsprL +( + const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_dsymvU +( + const int, + const double *, const int, + const double *, + const double, + double * +); + +void ATL_dsymvL +( + const int, + const double *, const int, + const double *, + const double, + double * +); + +void ATL_dspmvU +( + const int, + const double *, const int, + const double *, + const double, + double * +); + +void ATL_dspmvL +( + const int, + const double *, const int, + const double *, + const double, + double * +); + +void ATL_dsbmvU +( + const int, const int, + const double *, const int, + const double *, + const double, + double * +); + +void ATL_dsbmvL +( + const int, const int, + const double *, const int, + const double *, + const double, + double * +); + +void ATL_dgpmv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_dgprU +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_dgprL +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_dgpr +( + const enum ATLAS_UPLO, + const int, const int, + const double, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_dgpr1U_a1_x1_yX +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_dgpr1L_a1_x1_yX +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_dgpmvUT_a1_x1_bX_y1 +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_dgpmvUN_a1_x1_bX_y1 +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_dgpmvUT_a1_x1_b1_y1 +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_dgpmvUN_a1_x1_b1_y1 +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_dgpmvUT_a1_x1_b0_y1 +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_dgpmvUN_a1_x1_b0_y1 +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_dgpmvLT_a1_x1_bX_y1 +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_dgpmvLN_a1_x1_bX_y1 +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_dgpmvLT_a1_x1_b1_y1 +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_dgpmvLN_a1_x1_b1_y1 +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_dgpmvLT_a1_x1_b0_y1 +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_dgpmvLN_a1_x1_b0_y1 +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_dgbmvT_a1_x1_bX_y1 +( + const int, const int, + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_dgbmvN_a1_x1_bX_y1 +( + const int, const int, + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_dgbmvT_a1_x1_b1_y1 +( + const int, const int, + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_dgbmvN_a1_x1_b1_y1 +( + const int, const int, + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_dgbmvT_a1_x1_b0_y1 +( + const int, const int, + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_dgbmvN_a1_x1_b0_y1 +( + const int, const int, + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_ctrsvLHU +( + const int, + const float *, const int, + float * +); + +void ATL_ctrsvLCU +( + const int, + const float *, const int, + float * +); + +void ATL_ctrsvLTU +( + const int, + const float *, const int, + float * +); + +void ATL_ctrsvLNU +( + const int, + const float *, const int, + float * +); + +void ATL_ctrsvLHN +( + const int, + const float *, const int, + float * +); + +void ATL_ctrsvLCN +( + const int, + const float *, const int, + float * +); + +void ATL_ctrsvLTN +( + const int, + const float *, const int, + float * +); + +void ATL_ctrsvLNN +( + const int, + const float *, const int, + float * +); + +void ATL_ctrsvUHU +( + const int, + const float *, const int, + float * +); + +void ATL_ctrsvUCU +( + const int, + const float *, const int, + float * +); + +void ATL_ctrsvUTU +( + const int, + const float *, const int, + float * +); + +void ATL_ctrsvUNU +( + const int, + const float *, const int, + float * +); + +void ATL_ctrsvUHN +( + const int, + const float *, const int, + float * +); + +void ATL_ctrsvUCN +( + const int, + const float *, const int, + float * +); + +void ATL_ctrsvUTN +( + const int, + const float *, const int, + float * +); + +void ATL_ctrsvUNN +( + const int, + const float *, const int, + float * +); + +void ATL_ctrsvLH +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctrsvLC +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctrsvLT +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctrsvLN +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctrsvUH +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctrsvUC +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctrsvUT +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctrsvUN +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctpsvLHU +( + const int, + const float *, const int, + float * +); + +void ATL_ctpsvLCU +( + const int, + const float *, const int, + float * +); + +void ATL_ctpsvLTU +( + const int, + const float *, const int, + float * +); + +void ATL_ctpsvLNU +( + const int, + const float *, const int, + float * +); + +void ATL_ctpsvLHN +( + const int, + const float *, const int, + float * +); + +void ATL_ctpsvLCN +( + const int, + const float *, const int, + float * +); + +void ATL_ctpsvLTN +( + const int, + const float *, const int, + float * +); + +void ATL_ctpsvLNN +( + const int, + const float *, const int, + float * +); + +void ATL_ctpsvUHU +( + const int, + const float *, const int, + float * +); + +void ATL_ctpsvUCU +( + const int, + const float *, const int, + float * +); + +void ATL_ctpsvUTU +( + const int, + const float *, const int, + float * +); + +void ATL_ctpsvUNU +( + const int, + const float *, const int, + float * +); + +void ATL_ctpsvUHN +( + const int, + const float *, const int, + float * +); + +void ATL_ctpsvUCN +( + const int, + const float *, const int, + float * +); + +void ATL_ctpsvUTN +( + const int, + const float *, const int, + float * +); + +void ATL_ctpsvUNN +( + const int, + const float *, const int, + float * +); + +void ATL_ctpsvLH +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctpsvLC +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctpsvLT +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctpsvLN +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctpsvUH +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctpsvUC +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctpsvUT +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctpsvUN +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctbsvLHU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvLCU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvLTU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvLNU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvLHN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvLCN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvLTN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvLNN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvUHU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvUCU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvUTU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvUNU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvUHN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvUCN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvUTN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvUNN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvLH +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvLC +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvLT +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvLN +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvUH +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvUC +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvUT +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbsvUN +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_ctrmvLHU +( + const int, + const float *, const int, + float * +); + +void ATL_ctrmvLCU +( + const int, + const float *, const int, + float * +); + +void ATL_ctrmvLTU +( + const int, + const float *, const int, + float * +); + +void ATL_ctrmvLNU +( + const int, + const float *, const int, + float * +); + +void ATL_ctrmvLHN +( + const int, + const float *, const int, + float * +); + +void ATL_ctrmvLCN +( + const int, + const float *, const int, + float * +); + +void ATL_ctrmvLTN +( + const int, + const float *, const int, + float * +); + +void ATL_ctrmvLNN +( + const int, + const float *, const int, + float * +); + +void ATL_ctrmvUHU +( + const int, + const float *, const int, + float * +); + +void ATL_ctrmvUCU +( + const int, + const float *, const int, + float * +); + +void ATL_ctrmvUTU +( + const int, + const float *, const int, + float * +); + +void ATL_ctrmvUNU +( + const int, + const float *, const int, + float * +); + +void ATL_ctrmvUHN +( + const int, + const float *, const int, + float * +); + +void ATL_ctrmvUCN +( + const int, + const float *, const int, + float * +); + +void ATL_ctrmvUTN +( + const int, + const float *, const int, + float * +); + +void ATL_ctrmvUNN +( + const int, + const float *, const int, + float * +); + +void ATL_ctrmvLH +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctrmvLC +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctrmvLT +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctrmvLN +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctrmvUH +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctrmvUC +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctrmvUT +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctrmvUN +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctpmvLHU +( + const int, + const float *, const int, + float * +); + +void ATL_ctpmvLCU +( + const int, + const float *, const int, + float * +); + +void ATL_ctpmvLTU +( + const int, + const float *, const int, + float * +); + +void ATL_ctpmvLNU +( + const int, + const float *, const int, + float * +); + +void ATL_ctpmvLHN +( + const int, + const float *, const int, + float * +); + +void ATL_ctpmvLCN +( + const int, + const float *, const int, + float * +); + +void ATL_ctpmvLTN +( + const int, + const float *, const int, + float * +); + +void ATL_ctpmvLNN +( + const int, + const float *, const int, + float * +); + +void ATL_ctpmvUHU +( + const int, + const float *, const int, + float * +); + +void ATL_ctpmvUCU +( + const int, + const float *, const int, + float * +); + +void ATL_ctpmvUTU +( + const int, + const float *, const int, + float * +); + +void ATL_ctpmvUNU +( + const int, + const float *, const int, + float * +); + +void ATL_ctpmvUHN +( + const int, + const float *, const int, + float * +); + +void ATL_ctpmvUCN +( + const int, + const float *, const int, + float * +); + +void ATL_ctpmvUTN +( + const int, + const float *, const int, + float * +); + +void ATL_ctpmvUNN +( + const int, + const float *, const int, + float * +); + +void ATL_ctpmvLH +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctpmvLC +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctpmvLT +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctpmvLN +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctpmvUH +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctpmvUC +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctpmvUT +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctpmvUN +( + const enum ATLAS_DIAG, + const int, + const float *, const int, + float * +); + +void ATL_ctbmvLHU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvLCU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvLTU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvLNU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvLHN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvLCN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvLTN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvLNN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvUHU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvUCU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvUTU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvUNU +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvUHN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvUCN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvUTN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvUNN +( + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvLH +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvLC +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvLT +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvLN +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvUH +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvUC +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvUT +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_ctbmvUN +( + const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float * +); + +void ATL_cher2U +( + const int, + const float *, + const float *, + float *, const int +); + +void ATL_cher2L +( + const int, + const float *, + const float *, + float *, const int +); + +void ATL_chpr2U +( + const int, + const float *, + const float *, + float *, const int +); + +void ATL_chpr2L +( + const int, + const float *, + const float *, + float *, const int +); + +void ATL_cherU +( + const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_cherL +( + const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_chprU +( + const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_chprL +( + const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_chemvU +( + const int, + const float *, const int, + const float *, + const float *, + float * +); + +void ATL_chemvL +( + const int, + const float *, const int, + const float *, + const float *, + float * +); + +void ATL_chpmvU +( + const int, + const float *, const int, + const float *, + const float *, + float * +); + +void ATL_chpmvL +( + const int, + const float *, const int, + const float *, + const float *, + float * +); + +void ATL_chbmvU +( + const int, const int, + const float *, const int, + const float *, + const float *, + float * +); + +void ATL_chbmvL +( + const int, const int, + const float *, const int, + const float *, + const float *, + float * +); + +void ATL_cgpmv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpruU +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_cgpruL +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_cgpru +( + const enum ATLAS_UPLO, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_cgprcU +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_cgprcL +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_cgprc +( + const enum ATLAS_UPLO, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_cgpr1uU_a1_x1_yX +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_cgpr1uL_a1_x1_yX +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_cgpr1cU_a1_x1_yX +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_cgpr1cL_a1_x1_yX +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_cgpmvUNc_a1_x1_bX_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvUC_a1_x1_bX_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvUT_a1_x1_bX_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvUN_a1_x1_bX_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvUNc_a1_x1_b1_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvUC_a1_x1_b1_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvUT_a1_x1_b1_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvUN_a1_x1_b1_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvUNc_a1_x1_bXi0_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvUC_a1_x1_bXi0_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvUT_a1_x1_bXi0_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvUN_a1_x1_bXi0_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvUNc_a1_x1_b0_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvUC_a1_x1_b0_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvUT_a1_x1_b0_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvUN_a1_x1_b0_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvLNc_a1_x1_bX_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvLC_a1_x1_bX_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvLT_a1_x1_bX_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvLN_a1_x1_bX_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvLNc_a1_x1_b1_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvLC_a1_x1_b1_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvLT_a1_x1_b1_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvLN_a1_x1_b1_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvLNc_a1_x1_bXi0_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvLC_a1_x1_bXi0_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvLT_a1_x1_bXi0_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvLN_a1_x1_bXi0_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvLNc_a1_x1_b0_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvLC_a1_x1_b0_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvLT_a1_x1_b0_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgpmvLN_a1_x1_b0_y1 +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgbmvNc_a1_x1_bX_y1 +( + const int, const int, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgbmvC_a1_x1_bX_y1 +( + const int, const int, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgbmvT_a1_x1_bX_y1 +( + const int, const int, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgbmvN_a1_x1_bX_y1 +( + const int, const int, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgbmvNc_a1_x1_b1_y1 +( + const int, const int, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgbmvC_a1_x1_b1_y1 +( + const int, const int, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgbmvT_a1_x1_b1_y1 +( + const int, const int, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgbmvN_a1_x1_b1_y1 +( + const int, const int, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgbmvNc_a1_x1_bXi0_y1 +( + const int, const int, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgbmvC_a1_x1_bXi0_y1 +( + const int, const int, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgbmvT_a1_x1_bXi0_y1 +( + const int, const int, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgbmvN_a1_x1_bXi0_y1 +( + const int, const int, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgbmvNc_a1_x1_b0_y1 +( + const int, const int, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgbmvC_a1_x1_b0_y1 +( + const int, const int, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgbmvT_a1_x1_b0_y1 +( + const int, const int, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_cgbmvN_a1_x1_b0_y1 +( + const int, const int, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_ztrsvLHU +( + const int, + const double *, const int, + double * +); + +void ATL_ztrsvLCU +( + const int, + const double *, const int, + double * +); + +void ATL_ztrsvLTU +( + const int, + const double *, const int, + double * +); + +void ATL_ztrsvLNU +( + const int, + const double *, const int, + double * +); + +void ATL_ztrsvLHN +( + const int, + const double *, const int, + double * +); + +void ATL_ztrsvLCN +( + const int, + const double *, const int, + double * +); + +void ATL_ztrsvLTN +( + const int, + const double *, const int, + double * +); + +void ATL_ztrsvLNN +( + const int, + const double *, const int, + double * +); + +void ATL_ztrsvUHU +( + const int, + const double *, const int, + double * +); + +void ATL_ztrsvUCU +( + const int, + const double *, const int, + double * +); + +void ATL_ztrsvUTU +( + const int, + const double *, const int, + double * +); + +void ATL_ztrsvUNU +( + const int, + const double *, const int, + double * +); + +void ATL_ztrsvUHN +( + const int, + const double *, const int, + double * +); + +void ATL_ztrsvUCN +( + const int, + const double *, const int, + double * +); + +void ATL_ztrsvUTN +( + const int, + const double *, const int, + double * +); + +void ATL_ztrsvUNN +( + const int, + const double *, const int, + double * +); + +void ATL_ztrsvLH +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztrsvLC +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztrsvLT +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztrsvLN +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztrsvUH +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztrsvUC +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztrsvUT +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztrsvUN +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztpsvLHU +( + const int, + const double *, const int, + double * +); + +void ATL_ztpsvLCU +( + const int, + const double *, const int, + double * +); + +void ATL_ztpsvLTU +( + const int, + const double *, const int, + double * +); + +void ATL_ztpsvLNU +( + const int, + const double *, const int, + double * +); + +void ATL_ztpsvLHN +( + const int, + const double *, const int, + double * +); + +void ATL_ztpsvLCN +( + const int, + const double *, const int, + double * +); + +void ATL_ztpsvLTN +( + const int, + const double *, const int, + double * +); + +void ATL_ztpsvLNN +( + const int, + const double *, const int, + double * +); + +void ATL_ztpsvUHU +( + const int, + const double *, const int, + double * +); + +void ATL_ztpsvUCU +( + const int, + const double *, const int, + double * +); + +void ATL_ztpsvUTU +( + const int, + const double *, const int, + double * +); + +void ATL_ztpsvUNU +( + const int, + const double *, const int, + double * +); + +void ATL_ztpsvUHN +( + const int, + const double *, const int, + double * +); + +void ATL_ztpsvUCN +( + const int, + const double *, const int, + double * +); + +void ATL_ztpsvUTN +( + const int, + const double *, const int, + double * +); + +void ATL_ztpsvUNN +( + const int, + const double *, const int, + double * +); + +void ATL_ztpsvLH +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztpsvLC +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztpsvLT +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztpsvLN +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztpsvUH +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztpsvUC +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztpsvUT +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztpsvUN +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztbsvLHU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvLCU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvLTU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvLNU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvLHN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvLCN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvLTN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvLNN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvUHU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvUCU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvUTU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvUNU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvUHN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvUCN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvUTN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvUNN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvLH +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvLC +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvLT +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvLN +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvUH +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvUC +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvUT +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbsvUN +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_ztrmvLHU +( + const int, + const double *, const int, + double * +); + +void ATL_ztrmvLCU +( + const int, + const double *, const int, + double * +); + +void ATL_ztrmvLTU +( + const int, + const double *, const int, + double * +); + +void ATL_ztrmvLNU +( + const int, + const double *, const int, + double * +); + +void ATL_ztrmvLHN +( + const int, + const double *, const int, + double * +); + +void ATL_ztrmvLCN +( + const int, + const double *, const int, + double * +); + +void ATL_ztrmvLTN +( + const int, + const double *, const int, + double * +); + +void ATL_ztrmvLNN +( + const int, + const double *, const int, + double * +); + +void ATL_ztrmvUHU +( + const int, + const double *, const int, + double * +); + +void ATL_ztrmvUCU +( + const int, + const double *, const int, + double * +); + +void ATL_ztrmvUTU +( + const int, + const double *, const int, + double * +); + +void ATL_ztrmvUNU +( + const int, + const double *, const int, + double * +); + +void ATL_ztrmvUHN +( + const int, + const double *, const int, + double * +); + +void ATL_ztrmvUCN +( + const int, + const double *, const int, + double * +); + +void ATL_ztrmvUTN +( + const int, + const double *, const int, + double * +); + +void ATL_ztrmvUNN +( + const int, + const double *, const int, + double * +); + +void ATL_ztrmvLH +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztrmvLC +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztrmvLT +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztrmvLN +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztrmvUH +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztrmvUC +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztrmvUT +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztrmvUN +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztpmvLHU +( + const int, + const double *, const int, + double * +); + +void ATL_ztpmvLCU +( + const int, + const double *, const int, + double * +); + +void ATL_ztpmvLTU +( + const int, + const double *, const int, + double * +); + +void ATL_ztpmvLNU +( + const int, + const double *, const int, + double * +); + +void ATL_ztpmvLHN +( + const int, + const double *, const int, + double * +); + +void ATL_ztpmvLCN +( + const int, + const double *, const int, + double * +); + +void ATL_ztpmvLTN +( + const int, + const double *, const int, + double * +); + +void ATL_ztpmvLNN +( + const int, + const double *, const int, + double * +); + +void ATL_ztpmvUHU +( + const int, + const double *, const int, + double * +); + +void ATL_ztpmvUCU +( + const int, + const double *, const int, + double * +); + +void ATL_ztpmvUTU +( + const int, + const double *, const int, + double * +); + +void ATL_ztpmvUNU +( + const int, + const double *, const int, + double * +); + +void ATL_ztpmvUHN +( + const int, + const double *, const int, + double * +); + +void ATL_ztpmvUCN +( + const int, + const double *, const int, + double * +); + +void ATL_ztpmvUTN +( + const int, + const double *, const int, + double * +); + +void ATL_ztpmvUNN +( + const int, + const double *, const int, + double * +); + +void ATL_ztpmvLH +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztpmvLC +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztpmvLT +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztpmvLN +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztpmvUH +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztpmvUC +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztpmvUT +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztpmvUN +( + const enum ATLAS_DIAG, + const int, + const double *, const int, + double * +); + +void ATL_ztbmvLHU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvLCU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvLTU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvLNU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvLHN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvLCN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvLTN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvLNN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvUHU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvUCU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvUTU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvUNU +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvUHN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvUCN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvUTN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvUNN +( + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvLH +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvLC +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvLT +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvLN +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvUH +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvUC +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvUT +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_ztbmvUN +( + const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double * +); + +void ATL_zher2U +( + const int, + const double *, + const double *, + double *, const int +); + +void ATL_zher2L +( + const int, + const double *, + const double *, + double *, const int +); + +void ATL_zhpr2U +( + const int, + const double *, + const double *, + double *, const int +); + +void ATL_zhpr2L +( + const int, + const double *, + const double *, + double *, const int +); + +void ATL_zherU +( + const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zherL +( + const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zhprU +( + const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zhprL +( + const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zhemvU +( + const int, + const double *, const int, + const double *, + const double *, + double * +); + +void ATL_zhemvL +( + const int, + const double *, const int, + const double *, + const double *, + double * +); + +void ATL_zhpmvU +( + const int, + const double *, const int, + const double *, + const double *, + double * +); + +void ATL_zhpmvL +( + const int, + const double *, const int, + const double *, + const double *, + double * +); + +void ATL_zhbmvU +( + const int, const int, + const double *, const int, + const double *, + const double *, + double * +); + +void ATL_zhbmvL +( + const int, const int, + const double *, const int, + const double *, + const double *, + double * +); + +void ATL_zgpmv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpruU +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zgpruL +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zgpru +( + const enum ATLAS_UPLO, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zgprcU +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zgprcL +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zgprc +( + const enum ATLAS_UPLO, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zgpr1uU_a1_x1_yX +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zgpr1uL_a1_x1_yX +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zgpr1cU_a1_x1_yX +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zgpr1cL_a1_x1_yX +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zgpmvUNc_a1_x1_bX_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvUC_a1_x1_bX_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvUT_a1_x1_bX_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvUN_a1_x1_bX_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvUNc_a1_x1_b1_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvUC_a1_x1_b1_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvUT_a1_x1_b1_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvUN_a1_x1_b1_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvUNc_a1_x1_bXi0_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvUC_a1_x1_bXi0_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvUT_a1_x1_bXi0_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvUN_a1_x1_bXi0_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvUNc_a1_x1_b0_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvUC_a1_x1_b0_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvUT_a1_x1_b0_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvUN_a1_x1_b0_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvLNc_a1_x1_bX_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvLC_a1_x1_bX_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvLT_a1_x1_bX_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvLN_a1_x1_bX_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvLNc_a1_x1_b1_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvLC_a1_x1_b1_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvLT_a1_x1_b1_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvLN_a1_x1_b1_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvLNc_a1_x1_bXi0_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvLC_a1_x1_bXi0_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvLT_a1_x1_bXi0_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvLN_a1_x1_bXi0_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvLNc_a1_x1_b0_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvLC_a1_x1_b0_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvLT_a1_x1_b0_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgpmvLN_a1_x1_b0_y1 +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgbmvNc_a1_x1_bX_y1 +( + const int, const int, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgbmvC_a1_x1_bX_y1 +( + const int, const int, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgbmvT_a1_x1_bX_y1 +( + const int, const int, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgbmvN_a1_x1_bX_y1 +( + const int, const int, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgbmvNc_a1_x1_b1_y1 +( + const int, const int, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgbmvC_a1_x1_b1_y1 +( + const int, const int, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgbmvT_a1_x1_b1_y1 +( + const int, const int, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgbmvN_a1_x1_b1_y1 +( + const int, const int, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgbmvNc_a1_x1_bXi0_y1 +( + const int, const int, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgbmvC_a1_x1_bXi0_y1 +( + const int, const int, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgbmvT_a1_x1_bXi0_y1 +( + const int, const int, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgbmvN_a1_x1_bXi0_y1 +( + const int, const int, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgbmvNc_a1_x1_b0_y1 +( + const int, const int, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgbmvC_a1_x1_b0_y1 +( + const int, const int, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgbmvT_a1_x1_b0_y1 +( + const int, const int, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zgbmvN_a1_x1_b0_y1 +( + const int, const int, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + + +#endif +/* + * End of atlas_kernel2.h + */ diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_kernel3.h b/kaldi_io/src/tools/ATLAS/include/atlas_kernel3.h new file mode 100644 index 0000000..a929c2d --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_kernel3.h @@ -0,0 +1,1393 @@ +/* + * Automatically Tuned Linear Algebra Software v3.8.3 + * (C) Copyright 1999 R. Clint Whaley + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the ATLAS group or the names of its contributers may + * not be used to endorse or promote products derived from this + * software without specific written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef ATLAS_KERNEL3_H +#define ATLAS_KERNEL3_H + +/* + * Real level 3 kernels + */ +void ATL_ssymmRU + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_ssymmLU + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_ssymmRL + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_ssymmLL + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_strsmLLTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strmmLLTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strsmLLTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strmmLLTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strsmLLNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strmmLLNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strsmLLNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strmmLLNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strsmLUTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strmmLUTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strsmLUTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strmmLUTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strsmLUNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strmmLUNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strsmLUNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strmmLUNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strsmRLTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strmmRLTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strsmRLTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strmmRLTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strsmRLNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strmmRLNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strsmRLNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strmmRLNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strsmRUTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strmmRUTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strsmRUTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strmmRUTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strsmRUNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strmmRUNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strsmRUNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_strmmRUNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ssyrkLT + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +void ATL_ssyrkUT + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +void ATL_ssyrkLN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +void ATL_ssyrkUN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +int ATL_ssyr2kLT + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); +int ATL_ssyr2kUT + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); +int ATL_ssyr2kLN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); +int ATL_ssyr2kUN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); +void ATL_dsymmRU + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_dsymmLU + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_dsymmRL + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_dsymmLL + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_dtrsmLLTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrmmLLTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrsmLLTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrmmLLTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrsmLLNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrmmLLNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrsmLLNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrmmLLNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrsmLUTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrmmLUTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrsmLUTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrmmLUTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrsmLUNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrmmLUNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrsmLUNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrmmLUNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrsmRLTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrmmRLTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrsmRLTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrmmRLTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrsmRLNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrmmRLNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrsmRLNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrmmRLNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrsmRUTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrmmRUTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrsmRUTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrmmRUTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrsmRUNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrmmRUNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrsmRUNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dtrmmRUNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_dsyrkLT + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +void ATL_dsyrkUT + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +void ATL_dsyrkLN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +void ATL_dsyrkUN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +int ATL_dsyr2kLT + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); +int ATL_dsyr2kUT + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); +int ATL_dsyr2kLN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); +int ATL_dsyr2kUN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); + +/* + * Complex level 3 kernels + */ +void ATL_chemmRU + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_chemmLU + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_chemmRL + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_chemmLL + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_csymmRU + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_csymmLU + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_csymmRL + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_csymmLL + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_ctrsmLLTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmLLTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmLLTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmLLTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmLLNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmLLNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmLLNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmLLNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmLLCN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmLLCN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmLLCU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmLLCU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmLUTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmLUTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmLUTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmLUTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmLUNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmLUNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmLUNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmLUNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmLUCN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmLUCN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmLUCU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmLUCU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmRLTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmRLTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmRLTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmRLTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmRLNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmRLNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmRLNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmRLNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmRLCN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmRLCN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmRLCU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmRLCU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmRUTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmRUTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmRUTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmRUTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmRUNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmRUNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmRUNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmRUNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmRUCN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmRUCN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrsmRUCU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ctrmmRUCU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_cherkLC + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +void ATL_cherkUC + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +void ATL_cherkLN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +void ATL_cherkUN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +void ATL_csyrkLT + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +void ATL_csyrkUT + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +void ATL_csyrkLN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +void ATL_csyrkUN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +int ATL_cher2kLC + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); +int ATL_cher2kUC + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); +int ATL_cher2kLN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); +int ATL_cher2kUN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); +int ATL_csyr2kLT + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); +int ATL_csyr2kUT + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); +int ATL_csyr2kLN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); +int ATL_csyr2kUN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); +void ATL_zhemmRU + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_zhemmLU + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_zhemmRL + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_zhemmLL + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_zsymmRU + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_zsymmLU + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_zsymmRL + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_zsymmLL + (const int M, const int N, const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, void *C, const int ldc); +void ATL_ztrsmLLTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmLLTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmLLTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmLLTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmLLNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmLLNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmLLNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmLLNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmLLCN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmLLCN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmLLCU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmLLCU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmLUTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmLUTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmLUTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmLUTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmLUNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmLUNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmLUNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmLUNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmLUCN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmLUCN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmLUCU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmLUCU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmRLTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmRLTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmRLTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmRLTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmRLNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmRLNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmRLNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmRLNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmRLCN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmRLCN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmRLCU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmRLCU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmRUTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmRUTN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmRUTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmRUTU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmRUNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmRUNN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmRUNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmRUNU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmRUCN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmRUCN + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrsmRUCU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_ztrmmRUCU + (const int M, const int N, const void *valpha, const void *A, const int lda, + void *C, const int ldc); +void ATL_zherkLC + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +void ATL_zherkUC + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +void ATL_zherkLN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +void ATL_zherkUN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +void ATL_zsyrkLT + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +void ATL_zsyrkUT + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +void ATL_zsyrkLN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +void ATL_zsyrkUN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *vbeta, void *C, const int ldc); +int ATL_zher2kLC + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); +int ATL_zher2kUC + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); +int ATL_zher2kLN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); +int ATL_zher2kUN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); +int ATL_zsyr2kLT + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); +int ATL_zsyr2kUT + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); +int ATL_zsyr2kLN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); +int ATL_zsyr2kUN + (const int N, const int K, const void *valpha, const void *A, const int lda, + const void *B, const int ldb, const void *vbeta, void *C, const int ldc); + +/* + * Real level 3 kernel auxiliaries + */ +void ATL_ssycopyU_a0 + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_ssycopyL_a0 + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyU2L_N_a0 + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyU2L_U_a0 + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyU2U_N_a0 + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyU2U_U_a0 + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyL2L_N_a0 + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyL2L_U_a0 + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyL2U_N_a0 + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyL2U_U_a0 + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_ssycopyU_a1 + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_ssycopyL_a1 + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyU2L_N_a1 + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyU2L_U_a1 + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyU2U_N_a1 + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyU2U_U_a1 + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyL2L_N_a1 + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyL2L_U_a1 + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyL2U_N_a1 + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyL2U_U_a1 + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_ssycopyU_aX + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_ssycopyL_aX + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyU2L_N_aX + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyU2L_U_aX + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyU2U_N_aX + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyU2U_U_aX + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyL2L_N_aX + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyL2L_U_aX + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyL2U_N_aX + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strcopyL2U_U_aX + (const int N, const float alpha, const float *A, const int lda, float *C); +void ATL_strinvertUU(const int N, float *A, const int lda); +void ATL_strinvertLU(const int N, float *A, const int lda); +void ATL_strinvertUN(const int N, float *A, const int lda); +void ATL_strinvertLN(const int N, float *A, const int lda); +void ATL_ssyr2k_putU_bX + (const int N, const float *v, const float beta, float *A, const int lda); +void ATL_ssyr2k_putL_bX + (const int N, const float *v, const float beta, float *A, const int lda); +void ATL_strputU_bX + (const int N, const float *v, const float beta, float *A, const int lda); +void ATL_strputL_bX + (const int N, const float *v, const float beta, float *A, const int lda); +void ATL_ssyr2k_putU_b1 + (const int N, const float *v, const float beta, float *A, const int lda); +void ATL_ssyr2k_putL_b1 + (const int N, const float *v, const float beta, float *A, const int lda); +void ATL_strputU_b1 + (const int N, const float *v, const float beta, float *A, const int lda); +void ATL_strputL_b1 + (const int N, const float *v, const float beta, float *A, const int lda); +void ATL_ssyr2k_putU_b0 + (const int N, const float *v, const float beta, float *A, const int lda); +void ATL_ssyr2k_putL_b0 + (const int N, const float *v, const float beta, float *A, const int lda); +void ATL_strputU_b0 + (const int N, const float *v, const float beta, float *A, const int lda); +void ATL_strputL_b0 + (const int N, const float *v, const float beta, float *A, const int lda); +void ATL_strsmKLLTN + (const int M, const int N, const float alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_strsmKLLTU + (const int M, const int N, const float alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_strsmKLLNN + (const int M, const int N, const float alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_strsmKLLNU + (const int M, const int N, const float alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_strsmKLUTN + (const int M, const int N, const float alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_strsmKLUTU + (const int M, const int N, const float alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_strsmKLUNN + (const int M, const int N, const float alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_strsmKLUNU + (const int M, const int N, const float alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_strsmKRLTN + (const int M, const int N, const float alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_strsmKRLTU + (const int M, const int N, const float alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_strsmKRLNN + (const int M, const int N, const float alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_strsmKRLNU + (const int M, const int N, const float alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_strsmKRUTN + (const int M, const int N, const float alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_strsmKRUTU + (const int M, const int N, const float alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_strsmKRUNN + (const int M, const int N, const float alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_strsmKRUNU + (const int M, const int N, const float alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_dsycopyU_a0 + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dsycopyL_a0 + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyU2L_N_a0 + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyU2L_U_a0 + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyU2U_N_a0 + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyU2U_U_a0 + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyL2L_N_a0 + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyL2L_U_a0 + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyL2U_N_a0 + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyL2U_U_a0 + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dsycopyU_a1 + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dsycopyL_a1 + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyU2L_N_a1 + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyU2L_U_a1 + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyU2U_N_a1 + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyU2U_U_a1 + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyL2L_N_a1 + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyL2L_U_a1 + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyL2U_N_a1 + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyL2U_U_a1 + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dsycopyU_aX + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dsycopyL_aX + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyU2L_N_aX + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyU2L_U_aX + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyU2U_N_aX + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyU2U_U_aX + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyL2L_N_aX + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyL2L_U_aX + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyL2U_N_aX + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrcopyL2U_U_aX + (const int N, const double alpha, const double *A, const int lda, double *C); +void ATL_dtrinvertUU(const int N, double *A, const int lda); +void ATL_dtrinvertLU(const int N, double *A, const int lda); +void ATL_dtrinvertUN(const int N, double *A, const int lda); +void ATL_dtrinvertLN(const int N, double *A, const int lda); +void ATL_dsyr2k_putU_bX + (const int N, const double *v, const double beta, double *A, const int lda); +void ATL_dsyr2k_putL_bX + (const int N, const double *v, const double beta, double *A, const int lda); +void ATL_dtrputU_bX + (const int N, const double *v, const double beta, double *A, const int lda); +void ATL_dtrputL_bX + (const int N, const double *v, const double beta, double *A, const int lda); +void ATL_dsyr2k_putU_b1 + (const int N, const double *v, const double beta, double *A, const int lda); +void ATL_dsyr2k_putL_b1 + (const int N, const double *v, const double beta, double *A, const int lda); +void ATL_dtrputU_b1 + (const int N, const double *v, const double beta, double *A, const int lda); +void ATL_dtrputL_b1 + (const int N, const double *v, const double beta, double *A, const int lda); +void ATL_dsyr2k_putU_b0 + (const int N, const double *v, const double beta, double *A, const int lda); +void ATL_dsyr2k_putL_b0 + (const int N, const double *v, const double beta, double *A, const int lda); +void ATL_dtrputU_b0 + (const int N, const double *v, const double beta, double *A, const int lda); +void ATL_dtrputL_b0 + (const int N, const double *v, const double beta, double *A, const int lda); +void ATL_dtrsmKLLTN + (const int M, const int N, const double alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_dtrsmKLLTU + (const int M, const int N, const double alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_dtrsmKLLNN + (const int M, const int N, const double alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_dtrsmKLLNU + (const int M, const int N, const double alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_dtrsmKLUTN + (const int M, const int N, const double alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_dtrsmKLUTU + (const int M, const int N, const double alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_dtrsmKLUNN + (const int M, const int N, const double alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_dtrsmKLUNU + (const int M, const int N, const double alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_dtrsmKRLTN + (const int M, const int N, const double alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_dtrsmKRLTU + (const int M, const int N, const double alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_dtrsmKRLNN + (const int M, const int N, const double alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_dtrsmKRLNU + (const int M, const int N, const double alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_dtrsmKRUTN + (const int M, const int N, const double alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_dtrsmKRUTU + (const int M, const int N, const double alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_dtrsmKRUNN + (const int M, const int N, const double alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_dtrsmKRUNU + (const int M, const int N, const double alpha, const double *A, + const int lda, double *C, const int ldc); + +/* + * Complex level 3 kernel auxiliaries + */ +void ATL_cCtrsmKL + (enum ATLAS_UPLO Uplo, enum ATLAS_TRANS Trans, enum ATLAS_DIAG Diag, + const int M, const int N, const float *alpha, const float *A, + const int lda, float *B, const int ldb); +void ATL_checopy + (const int N, const float *A, const int lda, float *C); +void ATL_csycopy + (const int N, const float *A, const int lda, float *C); +void ATL_ctrcopyU2L_N + (const int N, const float *A, const int lda, float *C); +void ATL_ctrcopyU2Lc_N + (const int N, const float *A, const int lda, float *C); +void ATL_ctrcopyU2L_U + (const int N, const float *A, const int lda, float *C); +void ATL_ctrcopyU2Lc_U + (const int N, const float *A, const int lda, float *C); +void ATL_ctrcopyU2U_N + (const int N, const float *A, const int lda, float *C); +void ATL_ctrcopyU2Uc_N + (const int N, const float *A, const int lda, float *C); +void ATL_ctrcopyU2U_U + (const int N, const float *A, const int lda, float *C); +void ATL_ctrcopyU2Uc_U + (const int N, const float *A, const int lda, float *C); +void ATL_ctrcopyL2L_N + (const int N, const float *A, const int lda, float *C); +void ATL_ctrcopyL2Lc_N + (const int N, const float *A, const int lda, float *C); +void ATL_ctrcopyL2L_U + (const int N, const float *A, const int lda, float *C); +void ATL_ctrcopyL2Lc_U + (const int N, const float *A, const int lda, float *C); +void ATL_ctrcopyL2U_N + (const int N, const float *A, const int lda, float *C); +void ATL_ctrcopyL2Uc_N + (const int N, const float *A, const int lda, float *C); +void ATL_ctrcopyL2U_U + (const int N, const float *A, const int lda, float *C); +void ATL_ctrcopyL2Uc_U + (const int N, const float *A, const int lda, float *C); +void ATL_ctrmv_scalLNU_an1 + (const int N, const float *alpha, const float *A, const int lda, float *X); +void ATL_ctrmv_scalLNN_aX + (const int N, const float *alpha, const float *A, const int lda, float *X); +void ATL_ctrmv_scalUNU_an1 + (const int N, const float *alpha, const float *A, const int lda, float *X); +void ATL_ctrmv_scalUNN_aX + (const int N, const float *alpha, const float *A, const int lda, float *X); +void ATL_ctrinvertUU(const int N, float *A, const int lda); +void ATL_ctrinvertLU(const int N, float *A, const int lda); +void ATL_ctrinvertUN(const int N, float *A, const int lda); +void ATL_ctrinvertLN(const int N, float *A, const int lda); +void ATL_ctrputU_b0 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_ctrputL_b0 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_csyr2k_putU_b0 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_csyr2k_putL_b0 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_ctrputU_b1 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_ctrputL_b1 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_csyr2k_putU_b1 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_csyr2k_putL_b1 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_ctrputU_bX + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_ctrputL_bX + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_csyr2k_putU_bX + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_csyr2k_putL_bX + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_ctrputU_bXi0 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_ctrputL_bXi0 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_csyr2k_putU_bXi0 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_csyr2k_putL_bXi0 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_ctrputU_bn1 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_ctrputL_bn1 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_csyr2k_putU_bn1 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_csyr2k_putL_bn1 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_cher2k_putU_b0 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_cher2k_putL_b0 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_cheputU_b0 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_cheputL_b0 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_cher2k_putU_b1 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_cher2k_putL_b1 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_cheputU_b1 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_cheputL_b1 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_cher2k_putU_bXi0 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_cher2k_putL_bXi0 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_cheputU_bXi0 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_cheputL_bXi0 + (const int N, const float *v, const float *beta, float *A, const int lda); +void ATL_ctrsm0LLTN + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0LLTU + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0LLNN + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0LLNU + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0LLCN + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0LLCU + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0LUTN + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0LUTU + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0LUNN + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0LUNU + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0LUCN + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0LUCU + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0RLTN + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0RLTU + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0RLNN + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0RLNU + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0RLCN + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0RLCU + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0RUTN + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0RUTU + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0RUNN + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0RUNU + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0RUCN + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_ctrsm0RUCU + (const int M, const int N, const float *alpha, const float *A, + const int lda, float *C, const int ldc); +void ATL_zCtrsmKL + (enum ATLAS_UPLO Uplo, enum ATLAS_TRANS Trans, enum ATLAS_DIAG Diag, + const int M, const int N, const double *alpha, const double *A, + const int lda, double *B, const int ldb); +void ATL_zhecopy + (const int N, const double *A, const int lda, double *C); +void ATL_zsycopy + (const int N, const double *A, const int lda, double *C); +void ATL_ztrcopyU2L_N + (const int N, const double *A, const int lda, double *C); +void ATL_ztrcopyU2Lc_N + (const int N, const double *A, const int lda, double *C); +void ATL_ztrcopyU2L_U + (const int N, const double *A, const int lda, double *C); +void ATL_ztrcopyU2Lc_U + (const int N, const double *A, const int lda, double *C); +void ATL_ztrcopyU2U_N + (const int N, const double *A, const int lda, double *C); +void ATL_ztrcopyU2Uc_N + (const int N, const double *A, const int lda, double *C); +void ATL_ztrcopyU2U_U + (const int N, const double *A, const int lda, double *C); +void ATL_ztrcopyU2Uc_U + (const int N, const double *A, const int lda, double *C); +void ATL_ztrcopyL2L_N + (const int N, const double *A, const int lda, double *C); +void ATL_ztrcopyL2Lc_N + (const int N, const double *A, const int lda, double *C); +void ATL_ztrcopyL2L_U + (const int N, const double *A, const int lda, double *C); +void ATL_ztrcopyL2Lc_U + (const int N, const double *A, const int lda, double *C); +void ATL_ztrcopyL2U_N + (const int N, const double *A, const int lda, double *C); +void ATL_ztrcopyL2Uc_N + (const int N, const double *A, const int lda, double *C); +void ATL_ztrcopyL2U_U + (const int N, const double *A, const int lda, double *C); +void ATL_ztrcopyL2Uc_U + (const int N, const double *A, const int lda, double *C); +void ATL_ztrmv_scalLNU_an1 + (const int N, const double *alpha, const double *A, const int lda, double *X); +void ATL_ztrmv_scalLNN_aX + (const int N, const double *alpha, const double *A, const int lda, double *X); +void ATL_ztrmv_scalUNU_an1 + (const int N, const double *alpha, const double *A, const int lda, double *X); +void ATL_ztrmv_scalUNN_aX + (const int N, const double *alpha, const double *A, const int lda, double *X); +void ATL_ztrinvertUU(const int N, double *A, const int lda); +void ATL_ztrinvertLU(const int N, double *A, const int lda); +void ATL_ztrinvertUN(const int N, double *A, const int lda); +void ATL_ztrinvertLN(const int N, double *A, const int lda); +void ATL_ztrputU_b0 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_ztrputL_b0 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_zsyr2k_putU_b0 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_zsyr2k_putL_b0 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_ztrputU_b1 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_ztrputL_b1 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_zsyr2k_putU_b1 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_zsyr2k_putL_b1 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_ztrputU_bX + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_ztrputL_bX + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_zsyr2k_putU_bX + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_zsyr2k_putL_bX + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_ztrputU_bXi0 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_ztrputL_bXi0 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_zsyr2k_putU_bXi0 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_zsyr2k_putL_bXi0 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_ztrputU_bn1 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_ztrputL_bn1 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_zsyr2k_putU_bn1 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_zsyr2k_putL_bn1 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_zher2k_putU_b0 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_zher2k_putL_b0 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_zheputU_b0 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_zheputL_b0 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_zher2k_putU_b1 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_zher2k_putL_b1 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_zheputU_b1 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_zheputL_b1 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_zher2k_putU_bXi0 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_zher2k_putL_bXi0 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_zheputU_bXi0 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_zheputL_bXi0 + (const int N, const double *v, const double *beta, double *A, const int lda); +void ATL_ztrsm0LLTN + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0LLTU + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0LLNN + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0LLNU + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0LLCN + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0LLCU + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0LUTN + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0LUTU + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0LUNN + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0LUNU + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0LUCN + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0LUCU + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0RLTN + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0RLTU + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0RLNN + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0RLNU + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0RLCN + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0RLCU + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0RUTN + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0RUTU + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0RUNN + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0RUNU + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0RUCN + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); +void ATL_ztrsm0RUCU + (const int M, const int N, const double *alpha, const double *A, + const int lda, double *C, const int ldc); + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_lapack.h b/kaldi_io/src/tools/ATLAS/include/atlas_lapack.h new file mode 100644 index 0000000..4b370b8 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_lapack.h @@ -0,0 +1,239 @@ +/* + * Automatically Tuned Linear Algebra Software v3.8.3 + * (C) Copyright 1999 R. Clint Whaley + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the ATLAS group or the names of its contributers may + * not be used to endorse or promote products derived from this + * software without specific written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef ATLAS_LAPACK_H + #define ATLAS_LAPACK_H + +#include "atlas_misc.h" +#include "cblas.h" + +#ifdef PATL + +#include "atlas_cblastypealias.h" +/* + * predefined type macro names + */ +#define ATL_getriR Mjoin(PATL,getriR) +#define ATL_getriC Mjoin(PATL,getriC) +#define ATL_getri Mjoin(PATL,getri) +#define ATL_lauumRL Mjoin(PATL,lauumRL) +#define ATL_lauumRU Mjoin(PATL,lauumRU) +#define ATL_lauumCL Mjoin(PATL,lauumCL) +#define ATL_lauumCU Mjoin(PATL,lauumCU) +#define ATL_lauum Mjoin(PATL,lauum) +#define ATL_trtriRL Mjoin(PATL,trtriRL) +#define ATL_trtriRU Mjoin(PATL,trtriRU) +#define ATL_trtriCL Mjoin(PATL,trtriCL) +#define ATL_trtriCU Mjoin(PATL,trtriCU) +#define ATL_trtri Mjoin(PATL,trtri) +#define ATL_potrfU Mjoin(PATL,potrfU) +#define ATL_potrfL Mjoin(PATL,potrfL) +#define ATL_potrs Mjoin(PATL,potrs) +#define ATL_potrf Mjoin(PATL,potrf) +#define ATL_getrfR Mjoin(PATL,getrfR) +#define ATL_getrfC Mjoin(PATL,getrfC) +#define ATL_getrs Mjoin(PATL,getrs) +#define ATL_getrf Mjoin(PATL,getrf) +#define ATL_laswp Mjoin(PATL,laswp) + +#endif + +int ATL_sgetri(const enum CBLAS_ORDER Order, const int N, TYPE *A, const int lda, + const int *ipiv, TYPE *wrk, int *lwrk); +int ATL_sgetriR(const int N, TYPE *A, const int lda, const int *ipiv, + TYPE *wrk, const int lwrk); +int ATL_sgetriC(const int N, TYPE *A, const int lda, const int *ipiv, + TYPE *wrk, const int lwrk); +void ATL_slauum(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, float *A, const int lda); +int ATL_spotrf(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, float *A, const int lda); +void ATL_spotrs(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const int NRHS, const float *A, const int lda, + float *B, const int ldb); +int ATL_sgetrf(const enum CBLAS_ORDER Order, const int M, const int N, + float *A, const int lda, int *ipiv); +void ATL_sgetrs(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE Trans, + const int N, const int NRHS, const float *A, const int lda, + const int *ipiv, float *B, const int ldb); +void ATL_slaswp(const int N, float *A, const int lda0, const int K1, + const int K2, const int *ipiv, const int inci); +int ATL_sgetrfC(const int M, const int N, float *A, const int lda, + int *ipiv); +int ATL_sgetrfR(const int M, const int N, float *A, const int lda, + int *ipiv); +void ATL_slauumRU(const int N, float *A, const int lda); +void ATL_slauumRL(const int N, float *A, const int lda); +void ATL_slauumCU(const int N, float *A, const int lda); +void ATL_slauumCL(const int N, float *A, const int lda); +int ATL_spotrfU(const int N, float *A, const int lda); +int ATL_spotrfL(const int N, float *A, const int lda); +int ATL_strtri(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_DIAG Diag, const int N, + float *A, const int lda); +int ATL_strtriRU(const enum CBLAS_DIAG Diag, const int N, float *A, + const int lda); +int ATL_strtriRL(const enum CBLAS_DIAG Diag, const int N, float *A, + const int lda); +int ATL_strtriCU(const enum CBLAS_DIAG Diag, const int N, float *A, + const int lda); +int ATL_strtriCL(const enum CBLAS_DIAG Diag, const int N, float *A, + const int lda); + +int ATL_dgetri(const enum CBLAS_ORDER Order, const int N, TYPE *A, const int lda, + const int *ipiv, TYPE *wrk, int *lwrk); +int ATL_dgetriR(const int N, TYPE *A, const int lda, const int *ipiv, + TYPE *wrk, const int lwrk); +int ATL_dgetriC(const int N, TYPE *A, const int lda, const int *ipiv, + TYPE *wrk, const int lwrk); +void ATL_dlauum(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, double *A, const int lda); +int ATL_dpotrf(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, double *A, const int lda); +void ATL_dpotrs(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const int NRHS, const double *A, const int lda, + double *B, const int ldb); +int ATL_dgetrf(const enum CBLAS_ORDER Order, const int M, const int N, + double *A, const int lda, int *ipiv); +void ATL_dgetrs(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE Trans, + const int N, const int NRHS, const double *A, const int lda, + const int *ipiv, double *B, const int ldb); +void ATL_dlaswp(const int N, double *A, const int lda0, const int K1, + const int K2, const int *ipiv, const int inci); +int ATL_dgetrfC(const int M, const int N, double *A, const int lda, + int *ipiv); +int ATL_dgetrfR(const int M, const int N, double *A, const int lda, + int *ipiv); +void ATL_dlauumRU(const int N, double *A, const int lda); +void ATL_dlauumRL(const int N, double *A, const int lda); +void ATL_dlauumCU(const int N, double *A, const int lda); +void ATL_dlauumCL(const int N, double *A, const int lda); +int ATL_dpotrfU(const int N, double *A, const int lda); +int ATL_dpotrfL(const int N, double *A, const int lda); +int ATL_dtrtri(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_DIAG Diag, const int N, + double *A, const int lda); +int ATL_dtrtriRU(const enum CBLAS_DIAG Diag, const int N, double *A, + const int lda); +int ATL_dtrtriRL(const enum CBLAS_DIAG Diag, const int N, double *A, + const int lda); +int ATL_dtrtriCU(const enum CBLAS_DIAG Diag, const int N, double *A, + const int lda); +int ATL_dtrtriCL(const enum CBLAS_DIAG Diag, const int N, double *A, + const int lda); + +int ATL_cgetri(const enum CBLAS_ORDER Order, const int N, TYPE *A, const int lda, + const int *ipiv, TYPE *wrk, int *lwrk); +int ATL_cgetriR(const int N, TYPE *A, const int lda, const int *ipiv, + TYPE *wrk, const int lwrk); +int ATL_cgetriC(const int N, TYPE *A, const int lda, const int *ipiv, + TYPE *wrk, const int lwrk); +void ATL_clauum(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, float *A, const int lda); +int ATL_cpotrf(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, float *A, const int lda); +void ATL_cpotrs(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const int NRHS, const float *A, const int lda, + float *B, const int ldb); +int ATL_cgetrf(const enum CBLAS_ORDER Order, const int M, const int N, + float *A, const int lda, int *ipiv); +void ATL_cgetrs(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE Trans, + const int N, const int NRHS, const float *A, const int lda, + const int *ipiv, float *B, const int ldb); +void ATL_claswp(const int N, float *A, const int lda0, const int K1, + const int K2, const int *ipiv, const int inci); +int ATL_cgetrfC(const int M, const int N, float *A, const int lda, + int *ipiv); +int ATL_cgetrfR(const int M, const int N, float *A, const int lda, + int *ipiv); +void ATL_clauumRU(const int N, float *A, const int lda); +void ATL_clauumRL(const int N, float *A, const int lda); +void ATL_clauumCU(const int N, float *A, const int lda); +void ATL_clauumCL(const int N, float *A, const int lda); +int ATL_cpotrfRU(const int N, float *A, const int lda); +int ATL_cpotrfRL(const int N, float *A, const int lda); +int ATL_cpotrfU(const int N, float *A, const int lda); +int ATL_cpotrfL(const int N, float *A, const int lda); +int ATL_ctrtri(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_DIAG Diag, const int N, + float *A, const int lda); +int ATL_ctrtriRU(const enum CBLAS_DIAG Diag, const int N, float *A, + const int lda); +int ATL_ctrtriRL(const enum CBLAS_DIAG Diag, const int N, float *A, + const int lda); +int ATL_ctrtriCU(const enum CBLAS_DIAG Diag, const int N, float *A, + const int lda); +int ATL_ctrtriCL(const enum CBLAS_DIAG Diag, const int N, float *A, + const int lda); + +int ATL_zgetri(const enum CBLAS_ORDER Order, const int N, TYPE *A, const int lda, + const int *ipiv, TYPE *wrk, int *lwrk); +int ATL_zgetriR(const int N, TYPE *A, const int lda, const int *ipiv, + TYPE *wrk, const int lwrk); +int ATL_zgetriC(const int N, TYPE *A, const int lda, const int *ipiv, + TYPE *wrk, const int lwrk); +void ATL_zlauum(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, double *A, const int lda); +int ATL_zpotrf(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, double *A, const int lda); +void ATL_zpotrs(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const int NRHS, const double *A, const int lda, + double *B, const int ldb); +int ATL_zgetrf(const enum CBLAS_ORDER Order, const int M, const int N, + double *A, const int lda, int *ipiv); +void ATL_zgetrs(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE Trans, + const int N, const int NRHS, const double *A, const int lda, + const int *ipiv, double *B, const int ldb); +void ATL_zlaswp(const int N, double *A, const int lda0, const int K1, + const int K2, const int *ipiv, const int inci); +int ATL_zgetrfC(const int M, const int N, double *A, const int lda, + int *ipiv); +int ATL_zgetrfR(const int M, const int N, double *A, const int lda, + int *ipiv); +void ATL_zlauumRU(const int N, double *A, const int lda); +void ATL_zlauumRL(const int N, double *A, const int lda); +void ATL_zlauumCU(const int N, double *A, const int lda); +void ATL_zlauumCL(const int N, double *A, const int lda); +int ATL_zpotrfRU(const int N, double *A, const int lda); +int ATL_zpotrfRL(const int N, double *A, const int lda); +int ATL_zpotrfU(const int N, double *A, const int lda); +int ATL_zpotrfL(const int N, double *A, const int lda); +int ATL_ztrtri(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_DIAG Diag, const int N, + double *A, const int lda); +int ATL_ztrtriRU(const enum CBLAS_DIAG Diag, const int N, double *A, + const int lda); +int ATL_ztrtriRL(const enum CBLAS_DIAG Diag, const int N, double *A, + const int lda); +int ATL_ztrtriCU(const enum CBLAS_DIAG Diag, const int N, double *A, + const int lda); +int ATL_ztrtriCL(const enum CBLAS_DIAG Diag, const int N, double *A, + const int lda); + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_level1.h b/kaldi_io/src/tools/ATLAS/include/atlas_level1.h new file mode 100644 index 0000000..d4d61d8 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_level1.h @@ -0,0 +1,127 @@ +/* + * Automatically Tuned Linear Algebra Software v3.8.3 + * (C) Copyright 1999 R. Clint Whaley + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the ATLAS group or the names of its contributers may + * not be used to endorse or promote products derived from this + * software without specific written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* + * Prototypes ATLAS Level 1 functions not defined in atlas_aux.h + */ +#ifndef ATLAS_LEVEL1_H +#define ATLAS_LEVEL1_H + +/* + * Many level one blas routines actually taken care of by atlas auxiliary + */ +#include "atlas_aux.h" + +float ATL_sdsdot(const int N, const float alpha, const float *X, + const int incX, const float *Y, const int incY); +double ATL_dsdot(const int N, const float *X, const int incX, + const float *Y, const int incY); +/* + * Routines with all four types + */ +void ATL_sswap(const int N, float *X, const int incX, + float *Y, const int incY); +int ATL_isamax(const int N, const float *X, const int incX); + +void ATL_dswap(const int N, double *X, const int incX, + double *Y, const int incY); +int ATL_idamax(const int N, const double *X, const int incX); + +void ATL_cswap(const int N, float *X, const int incX, + float *Y, const int incY); +int ATL_icamax(const int N, const float *X, const int incX); + +void ATL_zswap(const int N, double *X, const int incX, + double *Y, const int incY); +int ATL_izamax(const int N, const double *X, const int incX); + +/* + * Routines with real types + */ +void ATL_srotg(float *a, float *b, float *c, float *s); +void ATL_srotmg(float *d1, float *d2, float *b1, const float b2, float *P); +void ATL_srot(const int N, float *X, const int incX, + float *Y, const int incY, const float c, const float s); +void ATL_srotm(const int N, float *X, const int incX, + float *Y, const int incY, const float *P); +float ATL_sdot(const int N, const float *X, const int incX, + const float *Y, const int incY); +void ATL_sssq(const int N, const float *X, const int incX, + float *scal0, float *ssq0); +float ATL_snrm2(const int N, const float *X, const int incX); +float ATL_sasum(const int N, const float *X, const int incX); + +void ATL_drotg(double *a, double *b, double *c, double *s); +void ATL_drotmg(double *d1, double *d2, double *b1, const double b2, double *P); +void ATL_drot(const int N, double *X, const int incX, + double *Y, const int incY, const double c, const double s); +void ATL_drotm(const int N, double *X, const int incX, + double *Y, const int incY, const double *P); +double ATL_ddot(const int N, const double *X, const int incX, + const double *Y, const int incY); +void ATL_dssq(const int N, const double *X, const int incX, + double *scal0, double *ssq0); +double ATL_dnrm2(const int N, const double *X, const int incX); +double ATL_dasum(const int N, const double *X, const int incX); + +/* + * Routines with complex types + */ +void ATL_csrot(const int N, float *X, const int incX, + float *Y, const int incY, const float c, const float s); +void ATL_crotg(float *a, const float *b, float *c, float *s); +void ATL_cdotu_sub(const int N, const float *X, const int incX, + const float *Y, const int incY, float *dot); +void ATL_cdotc_sub(const int N, const float *X, const int incX, + const float *Y, const int incY, float *dot); +void ATL_cssq(const int N, const float *X, const int incX, + float *scal0, float *ssq0); +float ATL_scnrm2(const int N, const float *X, const int incX); +float ATL_scasum(const int N, const float *X, const int incX); + +void ATL_zdrot(const int N, double *X, const int incX, + double *Y, const int incY, const double c, const double s); +void ATL_zrotg(double *a, const double *b, double *c, double *s); +void ATL_zdotu_sub(const int N, const double *X, const int incX, + const double *Y, const int incY, double *dot); +void ATL_zdotc_sub(const int N, const double *X, const int incX, + const double *Y, const int incY, double *dot); +void ATL_zssq(const int N, const double *X, const int incX, + double *scal0, double *ssq0); +double ATL_dznrm2(const int N, const double *X, const int incX); +double ATL_dzasum(const int N, const double *X, const int incX); + + +#define ATL_casum ATL_scasum +#define ATL_zasum ATL_dzasum +#define ATL_cnrm2 ATL_scnrm2 +#define ATL_znrm2 ATL_dznrm2 + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_level2.h b/kaldi_io/src/tools/ATLAS/include/atlas_level2.h new file mode 100644 index 0000000..d05f6d5 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_level2.h @@ -0,0 +1,267 @@ +/* + * Automatically Tuned Linear Algebra Software v3.8.3 + * (C) Copyright 1999 R. Clint Whaley + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the ATLAS group or the names of its contributers may + * not be used to endorse or promote products derived from this + * software without specific written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* + * =========================================================================== + * Prototypes for level 2 BLAS + * =========================================================================== + */ +#ifndef ATLAS_LEVEL2_H +#define ATLAS_LEVEL2_H + +/* + * Routines with standard 4 prefixes (S, D, C, Z) + */ +void ATL_sgemv(const enum ATLAS_TRANS TransA, const int M, const int N, + const float alpha, const float *A, const int lda, + const float *X, const int incX, const float beta, + float *Y, const int incY); +void ATL_sgbmv(const enum ATLAS_TRANS TransA, const int M, const int N, + const int KL, const int KU, const float alpha, + const float *A, const int lda, const float *X, + const int incX, const float beta, float *Y, const int incY); +void ATL_strmv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, + const float *A, const int lda, float *X, const int incX); +void ATL_stbmv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, const int K, + const float *A, const int lda, float *X, const int incX); +void ATL_stpmv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, const float *Ap, + float *X, const int incX); +void ATL_strsv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, + const float *A, const int lda, float *X, const int incX); +void ATL_stbsv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, const int K, + const float *A, const int lda, float *X, const int incX); +void ATL_stpsv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, + const float *Ap, float *X, const int incX); + +void ATL_dgemv(const enum ATLAS_TRANS TransA, const int M, const int N, + const double alpha, const double *A, const int lda, + const double *X, const int incX, const double beta, + double *Y, const int incY); +void ATL_dgbmv(const enum ATLAS_TRANS TransA, const int M, const int N, + const int KL, const int KU, const double alpha, + const double *A, const int lda, const double *X, + const int incX, const double beta, double *Y, const int incY); +void ATL_dtrmv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, + const double *A, const int lda, double *X, const int incX); +void ATL_dtbmv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, const int K, + const double *A, const int lda, double *X, const int incX); +void ATL_dtpmv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, const double *Ap, + double *X, const int incX); +void ATL_dtrsv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, + const double *A, const int lda, double *X, const int incX); +void ATL_dtbsv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, const int K, + const double *A, const int lda, double *X, const int incX); +void ATL_dtpsv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, + const double *Ap, double *X, const int incX); + +void ATL_cgemv(const enum ATLAS_TRANS TransA, const int M, const int N, + const float *alpha, const float *A, const int lda, + const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_cgbmv(const enum ATLAS_TRANS TransA, const int M, const int N, + const int KL, const int KU, const float *alpha, + const float *A, const int lda, const float *X, + const int incX, const float *beta, float *Y, const int incY); +void ATL_ctrmv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, + const float *A, const int lda, float *X, const int incX); +void ATL_ctbmv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, const int K, + const float *A, const int lda, float *X, const int incX); +void ATL_ctpmv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, const float *Ap, + float *X, const int incX); +void ATL_ctrsv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, + const float *A, const int lda, float *X, const int incX); +void ATL_ctbsv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, const int K, + const float *A, const int lda, float *X, const int incX); +void ATL_ctpsv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, + const float *Ap, float *X, const int incX); + +void ATL_zgemv(const enum ATLAS_TRANS TransA, const int M, const int N, + const double *alpha, const double *A, const int lda, + const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zgbmv(const enum ATLAS_TRANS TransA, const int M, const int N, + const int KL, const int KU, const double *alpha, + const double *A, const int lda, const double *X, + const int incX, const double *beta, double *Y, const int incY); +void ATL_ztrmv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, + const double *A, const int lda, double *X, const int incX); +void ATL_ztbmv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, const int K, + const double *A, const int lda, double *X, const int incX); +void ATL_ztpmv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, const double *Ap, + double *X, const int incX); +void ATL_ztrsv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, + const double *A, const int lda, double *X, const int incX); +void ATL_ztbsv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, const int K, + const double *A, const int lda, double *X, const int incX); +void ATL_ztpsv(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS TransA, + const enum ATLAS_DIAG Diag, const int N, + const double *Ap, double *X, const int incX); + + +/* + * Routines with S and D prefixes only + */ +void ATL_ssymv(const enum ATLAS_UPLO Uplo, const int N, + const float alpha, const float *A, const int lda, + const float *X, const int incX, const float beta, + float *Y, const int incY); +void ATL_ssbmv(const enum ATLAS_UPLO Uplo, const int N, const int K, + const float alpha, const float *A, const int lda, + const float *X, const int incX, const float beta, + float *Y, const int incY); +void ATL_sspmv(const enum ATLAS_UPLO Uplo, const int N, const float alpha, + const float *Ap, const float *X, const int incX, + const float beta, float *Y, const int incY); +void ATL_sger(const int M, const int N, const float alpha, + const float *X, const int incX, const float *Y, const int incY, + float *A, const int lda); +void ATL_ssyr(const enum ATLAS_UPLO Uplo, const int N, const float alpha, + const float *X, const int incX, float *A, const int lda); +void ATL_sspr(const enum ATLAS_UPLO Uplo, const int N, const float alpha, + const float *X, const int incX, float *Ap); +void ATL_ssyr2(const enum ATLAS_UPLO Uplo, const int N, const float alpha, + const float *X, const int incX, const float *Y, const int incY, + float *A, const int lda); +void ATL_sspr2(const enum ATLAS_UPLO Uplo, const int N, const float alpha, + const float *X, const int incX, const float *Y, const int incY, + float *A); + +void ATL_dsymv(const enum ATLAS_UPLO Uplo, const int N, + const double alpha, const double *A, const int lda, + const double *X, const int incX, const double beta, + double *Y, const int incY); +void ATL_dsbmv(const enum ATLAS_UPLO Uplo, const int N, const int K, + const double alpha, const double *A, const int lda, + const double *X, const int incX, const double beta, + double *Y, const int incY); +void ATL_dspmv(const enum ATLAS_UPLO Uplo, const int N, const double alpha, + const double *Ap, const double *X, const int incX, + const double beta, double *Y, const int incY); +void ATL_dger(const int M, const int N, const double alpha, + const double *X, const int incX, const double *Y, const int incY, + double *A, const int lda); +void ATL_dsyr(const enum ATLAS_UPLO Uplo, const int N, const double alpha, + const double *X, const int incX, double *A, const int lda); +void ATL_dspr(const enum ATLAS_UPLO Uplo, const int N, const double alpha, + const double *X, const int incX, double *Ap); +void ATL_dsyr2(const enum ATLAS_UPLO Uplo, const int N, const double alpha, + const double *X, const int incX, const double *Y, const int incY, + double *A, const int lda); +void ATL_dspr2(const enum ATLAS_UPLO Uplo, const int N, const double alpha, + const double *X, const int incX, const double *Y, const int incY, + double *A); + + +/* + * Routines with C and Z prefixes only + */ +void ATL_chemv(const enum ATLAS_UPLO Uplo, const int N, + const float *alpha, const float *A, const int lda, + const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_chbmv(const enum ATLAS_UPLO Uplo, const int N, const int K, + const float *alpha, const float *A, const int lda, + const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_chpmv(const enum ATLAS_UPLO Uplo, const int N, + const float *alpha, const float *Ap, + const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_cgeru(const int M, const int N, const float *alpha, + const float *X, const int incX, const float *Y, const int incY, + float *A, const int lda); +void ATL_cgerc(const int M, const int N, const float *alpha, + const float *X, const int incX, const float *Y, const int incY, + float *A, const int lda); +void ATL_cher(const enum ATLAS_UPLO Uplo, const int N, const float alpha, + const float *X, const int incX, float *A, const int lda); +void ATL_chpr(const enum ATLAS_UPLO Uplo, const int N, const float alpha, + const float *X, const int incX, float *A); +void ATL_cher2(const enum ATLAS_UPLO Uplo, const int N, + const float *alpha, const float *X, const int incX, + const float *Y, const int incY, float *A, const int lda); +void ATL_chpr2(const enum ATLAS_UPLO Uplo, const int N, + const float *alpha, const float *X, const int incX, + const float *Y, const int incY, float *Ap); + +void ATL_zhemv(const enum ATLAS_UPLO Uplo, const int N, + const double *alpha, const double *A, const int lda, + const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zhbmv(const enum ATLAS_UPLO Uplo, const int N, const int K, + const double *alpha, const double *A, const int lda, + const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zhpmv(const enum ATLAS_UPLO Uplo, const int N, + const double *alpha, const double *Ap, + const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zgeru(const int M, const int N, const double *alpha, + const double *X, const int incX, const double *Y, const int incY, + double *A, const int lda); +void ATL_zgerc(const int M, const int N, const double *alpha, + const double *X, const int incX, const double *Y, const int incY, + double *A, const int lda); +void ATL_zher(const enum ATLAS_UPLO Uplo, const int N, const double alpha, + const double *X, const int incX, double *A, const int lda); +void ATL_zhpr(const enum ATLAS_UPLO Uplo, const int N, const double alpha, + const double *X, const int incX, double *A); +void ATL_zher2(const enum ATLAS_UPLO Uplo, const int N, + const double *alpha, const double *X, const int incX, + const double *Y, const int incY, double *A, const int lda); +void ATL_zhpr2(const enum ATLAS_UPLO Uplo, const int N, + const double *alpha, const double *X, const int incX, + const double *Y, const int incY, double *Ap); + + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_level3.h b/kaldi_io/src/tools/ATLAS/include/atlas_level3.h new file mode 100644 index 0000000..023c63c --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_level3.h @@ -0,0 +1,181 @@ +/* + * Automatically Tuned Linear Algebra Software v3.8.3 + * (C) Copyright 1997 R. Clint Whaley + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the ATLAS group or the names of its contributers may + * not be used to endorse or promote products derived from this + * software without specific written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +/* + * =========================================================================== + * Prototypes for level 3 BLAS + * =========================================================================== + */ +#ifndef ATLAS_LEVEL3_H +#define ATLAS_LEVEL3_H + + +/* + * Routines with standard 4 prefixes (S, D, C, Z) + */ +int ATL_sGetNB(void); +int ATL_sGetNCNB(void); +void ATL_sgemm(const enum ATLAS_TRANS TransA, const enum ATLAS_TRANS TransB, + const int M, const int N, const int K, const float alpha, + const float *A, const int lda, const float *B, const int ldb, + const float beta, float *C, const int ldc); +void ATL_ssymm(const enum ATLAS_SIDE Side, const enum ATLAS_UPLO Uplo, + const int M, const int N, const float alpha, + const float *A, const int lda, const float *B, const int ldb, + const float beta, float *C, const int ldc); +void ATL_ssyrk(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS Trans, + const int N, const int K, const float alpha, + const float *A, const int lda, const float beta, + float *C, const int ldc); +void ATL_ssyr2k(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS Trans, + const int N, const int K, const float alpha, + const float *A, const int lda, const float *B, const int ldb, + const float beta, float *C, const int ldc); +void ATL_strmm(const enum ATLAS_SIDE Side, const enum ATLAS_UPLO Uplo, + const enum ATLAS_TRANS TransA, const enum ATLAS_DIAG Diag, + const int M, const int N, const float alpha, + const float *A, const int lda, float *B, const int ldb); +void ATL_strsm(const enum ATLAS_SIDE Side, const enum ATLAS_UPLO Uplo, + const enum ATLAS_TRANS TransA, const enum ATLAS_DIAG Diag, + const int M, const int N, const float alpha, + const float *A, const int lda, float *B, const int ldb); + +int ATL_dGetNB(void); +int ATL_dGetNCNB(void); +void ATL_dgemm(const enum ATLAS_TRANS TransA, const enum ATLAS_TRANS TransB, + const int M, const int N, const int K, const double alpha, + const double *A, const int lda, const double *B, const int ldb, + const double beta, double *C, const int ldc); +void ATL_dsymm(const enum ATLAS_SIDE Side, const enum ATLAS_UPLO Uplo, + const int M, const int N, const double alpha, + const double *A, const int lda, const double *B, const int ldb, + const double beta, double *C, const int ldc); +void ATL_dsyrk(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS Trans, + const int N, const int K, const double alpha, + const double *A, const int lda, const double beta, + double *C, const int ldc); +void ATL_dsyr2k(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS Trans, + const int N, const int K, const double alpha, + const double *A, const int lda, const double *B, const int ldb, + const double beta, double *C, const int ldc); +void ATL_dtrmm(const enum ATLAS_SIDE Side, const enum ATLAS_UPLO Uplo, + const enum ATLAS_TRANS TransA, const enum ATLAS_DIAG Diag, + const int M, const int N, const double alpha, + const double *A, const int lda, double *B, const int ldb); +void ATL_dtrsm(const enum ATLAS_SIDE Side, const enum ATLAS_UPLO Uplo, + const enum ATLAS_TRANS TransA, const enum ATLAS_DIAG Diag, + const int M, const int N, const double alpha, + const double *A, const int lda, double *B, const int ldb); + +int ATL_cGetNB(void); +int ATL_cGetNCNB(void); +void ATL_cgemm(const enum ATLAS_TRANS TransA, const enum ATLAS_TRANS TransB, + const int M, const int N, const int K, const float *alpha, + const float *A, const int lda, const float *B, const int ldb, + const float *beta, float *C, const int ldc); +void ATL_csymm(const enum ATLAS_SIDE Side, const enum ATLAS_UPLO Uplo, + const int M, const int N, const float *alpha, + const float *A, const int lda, const float *B, const int ldb, + const float *beta, float *C, const int ldc); +void ATL_csyrk(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS Trans, + const int N, const int K, const float *alpha, + const float *A, const int lda, const float *beta, + float *C, const int ldc); +void ATL_csyr2k(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS Trans, + const int N, const int K, const float *alpha, + const float *A, const int lda, const float *B, const int ldb, + const float *beta, float *C, const int ldc); +void ATL_ctrmm(const enum ATLAS_SIDE Side, const enum ATLAS_UPLO Uplo, + const enum ATLAS_TRANS TransA, const enum ATLAS_DIAG Diag, + const int M, const int N, const float *alpha, + const float *A, const int lda, float *B, const int ldb); +void ATL_ctrsm(const enum ATLAS_SIDE Side, const enum ATLAS_UPLO Uplo, + const enum ATLAS_TRANS TransA, const enum ATLAS_DIAG Diag, + const int M, const int N, const float *alpha, + const float *A, const int lda, float *B, const int ldb); + +int ATL_zGetNB(void); +int ATL_zGetNCNB(void); +void ATL_zgemm(const enum ATLAS_TRANS TransA, const enum ATLAS_TRANS TransB, + const int M, const int N, const int K, const double *alpha, + const double *A, const int lda, const double *B, const int ldb, + const double *beta, double *C, const int ldc); +void ATL_zsymm(const enum ATLAS_SIDE Side, const enum ATLAS_UPLO Uplo, + const int M, const int N, const double *alpha, + const double *A, const int lda, const double *B, const int ldb, + const double *beta, double *C, const int ldc); +void ATL_zsyrk(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS Trans, + const int N, const int K, const double *alpha, + const double *A, const int lda, const double *beta, + double *C, const int ldc); +void ATL_zsyr2k(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS Trans, + const int N, const int K, const double *alpha, + const double *A, const int lda, const double *B, const int ldb, + const double *beta, double *C, const int ldc); +void ATL_ztrmm(const enum ATLAS_SIDE Side, const enum ATLAS_UPLO Uplo, + const enum ATLAS_TRANS TransA, const enum ATLAS_DIAG Diag, + const int M, const int N, const double *alpha, + const double *A, const int lda, double *B, const int ldb); +void ATL_ztrsm(const enum ATLAS_SIDE Side, const enum ATLAS_UPLO Uplo, + const enum ATLAS_TRANS TransA, const enum ATLAS_DIAG Diag, + const int M, const int N, const double *alpha, + const double *A, const int lda, double *B, const int ldb); + + +/* + * Routines with prefixes C and Z only + */ +void ATL_chemm(const enum ATLAS_SIDE Side, const enum ATLAS_UPLO Uplo, + const int M, const int N, const float *alpha, + const float *A, const int lda, const float *B, const int ldb, + const float *beta, float *C, const int ldc); +void ATL_cherk(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS Trans, + const int N, const int K, const float alpha, + const float *A, const int lda, const float beta, + float *C, const int ldc); +void ATL_cher2k(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS Trans, + const int N, const int K, const float *alpha, + const float *A, const int lda, const float *B, const int ldb, + const float beta, float *C, const int ldc); + +void ATL_zhemm(const enum ATLAS_SIDE Side, const enum ATLAS_UPLO Uplo, + const int M, const int N, const double *alpha, + const double *A, const int lda, const double *B, const int ldb, + const double *beta, double *C, const int ldc); +void ATL_zherk(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS Trans, + const int N, const int K, const double alpha, + const double *A, const int lda, const double beta, + double *C, const int ldc); +void ATL_zher2k(const enum ATLAS_UPLO Uplo, const enum ATLAS_TRANS Trans, + const int N, const int K, const double *alpha, + const double *A, const int lda, const double *B, const int ldb, + const double beta, double *C, const int ldc); + + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_lvl2.h b/kaldi_io/src/tools/ATLAS/include/atlas_lvl2.h new file mode 100644 index 0000000..b09a021 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_lvl2.h @@ -0,0 +1,294 @@ +/* + * Automatically Tuned Linear Algebra Software v3.8.3 + * (C) Copyright 1999 R. Clint Whaley + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the ATLAS group or the names of its contributers may + * not be used to endorse or promote products derived from this + * software without specific written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "atlas_level2.h" +#include "atlas_kernel2.h" +#ifndef ATLAS_LVL2_H +#define ATLAS_LVL2_H + +/* + * Real kernels + */ +void ATL_sger1_a1_x1_yX + (const int M, const int N, const float alpha, const float *X, + const int incX, const float *Y, const int incY, float *A, const int lda); +void ATL_sgemvS_a1_x1_bX_y1 + (const int M, const int N, const float alpha, const float *A, + const int lda, const float *X, const int incX, const float beta, + float *Y, const int incY); +void ATL_sgemvT_a1_x1_bX_y1 + (const int M, const int N, const float alpha, const float *A, + const int lda, const float *X, const int incX, const float beta, + float *Y, const int incY); +void ATL_sgemvN_a1_x1_bX_y1 + (const int M, const int N, const float alpha, const float *A, + const int lda, const float *X, const int incX, const float beta, + float *Y, const int incY); +void ATL_sgemvS_a1_x1_b1_y1 + (const int M, const int N, const float alpha, const float *A, + const int lda, const float *X, const int incX, const float beta, + float *Y, const int incY); +void ATL_sgemvT_a1_x1_b1_y1 + (const int M, const int N, const float alpha, const float *A, + const int lda, const float *X, const int incX, const float beta, + float *Y, const int incY); +void ATL_sgemvN_a1_x1_b1_y1 + (const int M, const int N, const float alpha, const float *A, + const int lda, const float *X, const int incX, const float beta, + float *Y, const int incY); +void ATL_sgemvS_a1_x1_b0_y1 + (const int M, const int N, const float alpha, const float *A, + const int lda, const float *X, const int incX, const float beta, + float *Y, const int incY); +void ATL_sgemvT_a1_x1_b0_y1 + (const int M, const int N, const float alpha, const float *A, + const int lda, const float *X, const int incX, const float beta, + float *Y, const int incY); +void ATL_sgemvN_a1_x1_b0_y1 + (const int M, const int N, const float alpha, const float *A, + const int lda, const float *X, const int incX, const float beta, + float *Y, const int incY); +void ATL_dger1_a1_x1_yX + (const int M, const int N, const double alpha, const double *X, + const int incX, const double *Y, const int incY, double *A, const int lda); +void ATL_dgemvS_a1_x1_bX_y1 + (const int M, const int N, const double alpha, const double *A, + const int lda, const double *X, const int incX, const double beta, + double *Y, const int incY); +void ATL_dgemvT_a1_x1_bX_y1 + (const int M, const int N, const double alpha, const double *A, + const int lda, const double *X, const int incX, const double beta, + double *Y, const int incY); +void ATL_dgemvN_a1_x1_bX_y1 + (const int M, const int N, const double alpha, const double *A, + const int lda, const double *X, const int incX, const double beta, + double *Y, const int incY); +void ATL_dgemvS_a1_x1_b1_y1 + (const int M, const int N, const double alpha, const double *A, + const int lda, const double *X, const int incX, const double beta, + double *Y, const int incY); +void ATL_dgemvT_a1_x1_b1_y1 + (const int M, const int N, const double alpha, const double *A, + const int lda, const double *X, const int incX, const double beta, + double *Y, const int incY); +void ATL_dgemvN_a1_x1_b1_y1 + (const int M, const int N, const double alpha, const double *A, + const int lda, const double *X, const int incX, const double beta, + double *Y, const int incY); +void ATL_dgemvS_a1_x1_b0_y1 + (const int M, const int N, const double alpha, const double *A, + const int lda, const double *X, const int incX, const double beta, + double *Y, const int incY); +void ATL_dgemvT_a1_x1_b0_y1 + (const int M, const int N, const double alpha, const double *A, + const int lda, const double *X, const int incX, const double beta, + double *Y, const int incY); +void ATL_dgemvN_a1_x1_b0_y1 + (const int M, const int N, const double alpha, const double *A, + const int lda, const double *X, const int incX, const double beta, + double *Y, const int incY); + +/* + * Complex kernels + */ +void ATL_cger1u_a1_x1_yX + (const int M, const int N, const float *alpha, const float *X, + const int incX, const float *Y, const int incY, float *A, const int lda); +void ATL_cger1c_a1_x1_yX + (const int M, const int N, const float *alpha, const float *X, + const int incX, const float *Y, const int incY, float *A, const int lda); +void ATL_cgemvS_a1_x1_bXi0_y1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_cgemvC_a1_x1_bXi0_y1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_cgemvNc_a1_x1_bXi0_y1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_cgemvT_a1_x1_bXi0_y1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_cgemvN_a1_x1_bXi0_y1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_cgemvS_a1_x1_bX_y1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_cgemvC_a1_x1_bX_y1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_cgemvNc_a1_x1_bX_y1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_cgemvT_a1_x1_bX_y1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_cgemvN_a1_x1_bX_y1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_cgemvS_a1_x1_b1_y1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_cgemvC_a1_x1_b1_y1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_cgemvNc_a1_x1_b1_y1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_cgemvT_a1_x1_b1_y1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_cgemvN_a1_x1_b1_y1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_cgemvS_a1_x1_b0_y1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_cgemvC_a1_x1_b0_y1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_cgemvNc_a1_x1_b0_y1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_cgemvT_a1_x1_b0_y1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_cgemvN_a1_x1_b0_y1 + (const int M, const int N, const float *alpha, const float *A, + const int lda, const float *X, const int incX, const float *beta, + float *Y, const int incY); +void ATL_zger1u_a1_x1_yX + (const int M, const int N, const double *alpha, const double *X, + const int incX, const double *Y, const int incY, double *A, const int lda); +void ATL_zger1c_a1_x1_yX + (const int M, const int N, const double *alpha, const double *X, + const int incX, const double *Y, const int incY, double *A, const int lda); +void ATL_zgemvS_a1_x1_bXi0_y1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zgemvC_a1_x1_bXi0_y1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zgemvNc_a1_x1_bXi0_y1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zgemvT_a1_x1_bXi0_y1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zgemvN_a1_x1_bXi0_y1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zgemvS_a1_x1_bX_y1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zgemvC_a1_x1_bX_y1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zgemvNc_a1_x1_bX_y1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zgemvT_a1_x1_bX_y1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zgemvN_a1_x1_bX_y1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zgemvS_a1_x1_b1_y1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zgemvC_a1_x1_b1_y1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zgemvNc_a1_x1_b1_y1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zgemvT_a1_x1_b1_y1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zgemvN_a1_x1_b1_y1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zgemvS_a1_x1_b0_y1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zgemvC_a1_x1_b0_y1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zgemvNc_a1_x1_b0_y1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zgemvT_a1_x1_b0_y1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *X, const int incX, const double *beta, + double *Y, const int incY); +void ATL_zgemvN_a1_x1_b0_y1 + (const int M, const int N, const double *alpha, const double *A, + const int lda, const double *X, const int incX, const double *beta, + double *Y, const int incY); + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_lvl3.h b/kaldi_io/src/tools/ATLAS/include/atlas_lvl3.h new file mode 100644 index 0000000..eab93c0 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_lvl3.h @@ -0,0 +1,512 @@ +/* + * Automatically Tuned Linear Algebra Software v3.8.3 + * (C) Copyright 1997 R. Clint Whaley + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the ATLAS group or the names of its contributers may + * not be used to endorse or promote products derived from this + * software without specific written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef ATLAS_LVL3_H +#define ATLAS_LVL3_H + +#include "atlas_misc.h" +#include "atlas_f77.h" +#include "atlas_level3.h" +#if defined(SREAL) + #include "smm.h" + #include "sXover.h" +#elif defined(DREAL) + #include "dmm.h" + #include "dXover.h" +#elif defined(QREAL) + #include "qmm.h" + #include "qXover.h" +#elif defined(SCPLX) + #ifdef ATL_NCMM + #include "atlas_cNCmm.h" + #else + #include "cmm.h" + #endif + #include "cXover.h" +#elif defined(DCPLX) + #ifdef ATL_NCMM + #include "atlas_zNCmm.h" + #else + #include "zmm.h" + #endif + #include "zmm.h" + #include "zXover.h" +#endif +#ifndef ATL_3NB + #define ATL_3NB 3*NB + + #define NN_MNK_M NBNB*NB + #define NN_MNK_N NBNB*NB + #define NN_MNK_K NBNB*NB + #define NN_MNK_MN NBNB*NB + #define NN_MNK_GE NBNB*NB + + #define NT_MNK_M NBNB*NB + #define NT_MNK_N NBNB*NB + #define NT_MNK_K NBNB*NB + #define NT_MNK_MN NBNB*NB + #define NT_MNK_GE NBNB*NB + + #define TN_MNK_M NBNB*NB + #define TN_MNK_N NBNB*NB + #define TN_MNK_K NBNB*NB + #define TN_MNK_MN NBNB*NB + #define TN_MNK_GE NBNB*NB + + #define TT_MNK_M NBNB*NB + #define TT_MNK_N NBNB*NB + #define TT_MNK_K NBNB*NB + #define TT_MNK_MN NBNB*NB + #define TT_MNK_GE NBNB*NB +#endif + +#ifndef CN_MNK_M + #define CN_MNK_M TN_MNK_M + #define CN_MNK_N TN_MNK_N + #define CN_MNK_K TN_MNK_K + #define CN_MNK_MN TN_MNK_MN + #define CN_MNK_GE TN_MNK_GE +#endif +#ifndef NC_MNK_M + #define NC_MNK_M NT_MNK_M + #define NC_MNK_N NT_MNK_N + #define NC_MNK_K NT_MNK_K + #define NC_MNK_MN NT_MNK_MN + #define NC_MNK_GE NT_MNK_GE +#endif +#ifndef CT_MNK_M + #define CT_MNK_M TT_MNK_M + #define CT_MNK_N TT_MNK_N + #define CT_MNK_K TT_MNK_K + #define CT_MNK_MN TT_MNK_MN + #define CT_MNK_GE TT_MNK_GE +#endif +#ifndef TC_MNK_M + #define TC_MNK_M TT_MNK_M + #define TC_MNK_N TT_MNK_N + #define TC_MNK_K TT_MNK_K + #define TC_MNK_MN TT_MNK_MN + #define TC_MNK_GE TT_MNK_GE +#endif +#ifndef CC_MNK_M + #define CC_MNK_M TT_MNK_M + #define CC_MNK_N TT_MNK_N + #define CC_MNK_K TT_MNK_K + #define CC_MNK_MN TT_MNK_MN + #define CC_MNK_GE TT_MNK_GE +#endif + +#define CPAT Mjoin(C_ATL_, PRE); + +#ifndef ATL_MaxMalloc + #define ATL_MaxMalloc 67108864 +#endif + +typedef void (*MAT2BLK)(int, int, const TYPE*, int, TYPE*, const SCALAR); +typedef void (*MAT2BLK2)(const int, const int, const SCALAR, const TYPE*, + const int, TYPE*, const int); +typedef void (*MATSCAL)(const int, const int, const SCALAR, TYPE*, const int); +typedef void (*PUTBLK)(int, int, TYPE*, TYPE*, int, const SCALAR); +typedef void (*NBCLEANUP)(const TYPE*, const TYPE*, TYPE*, const int); +typedef int (*MMINTR)(const enum ATLAS_TRANS, const enum ATLAS_TRANS, + const int, const int, const int, const SCALAR, + const TYPE *, const int, const TYPE *, const int, + const SCALAR, TYPE *, const int); +typedef void (*NBMM0)(const int, const int, const int, const TYPE, + const TYPE*, const int, const TYPE*, const int, + const TYPE, TYPE*, const int); + +void ATL_xerbla(int p, char *rout, char *form, ...); +int Mjoin(PATL,GetNB)(void); +int Mjoin(PATL,GetNCNB)(void); + +void Mjoin(PATL, gescal_bX)(const int, const int, const SCALAR, TYPE*, + const int); +void Mjoin(PATL, gescal_bn1)(const int, const int, const SCALAR, TYPE*, + const int); +void Mjoin(PATL, gescal_b0)(const int, const int, const SCALAR, TYPE*, + const int); + +void Mjoin(PATL,pKBmm_bX)(const int M, const int N, const int K, + const TYPE alpha, const TYPE *A, const int lda, + const TYPE *B, const int ldb, const TYPE beta, + TYPE *C, const int ldc); +void Mjoin(PATL,pNBmm_bX)(const int M, const int N, const int K, + const TYPE alpha, const TYPE *A, const int lda, + const TYPE *B, const int ldb, const TYPE beta, + TYPE *C, const int ldc); +void Mjoin(PATL,pMBmm_bX)(const int M, const int N, const int K, + const TYPE alpha, const TYPE *A, const int lda, + const TYPE *B, const int ldb, const TYPE beta, + TYPE *C, const int ldc); +void Mjoin(PATL,pKBmm_b1)(const int M, const int N, const int K, + const TYPE alpha, const TYPE *A, const int lda, + const TYPE *B, const int ldb, const TYPE beta, + TYPE *C, const int ldc); +void Mjoin(PATL,pNBmm_b1)(const int M, const int N, const int K, + const TYPE alpha, const TYPE *A, const int lda, + const TYPE *B, const int ldb, const TYPE beta, + TYPE *C, const int ldc); +void Mjoin(PATL,pMBmm_b1)(const int M, const int N, const int K, + const TYPE alpha, const TYPE *A, const int lda, + const TYPE *B, const int ldb, const TYPE beta, + TYPE *C, const int ldc); +void Mjoin(PATL,pKBmm_b0)(const int M, const int N, const int K, + const TYPE alpha, const TYPE *A, const int lda, + const TYPE *B, const int ldb, const TYPE beta, + TYPE *C, const int ldc); +void Mjoin(PATL,pNBmm_b0)(const int M, const int N, const int K, + const TYPE alpha, const TYPE *A, const int lda, + const TYPE *B, const int ldb, const TYPE beta, + TYPE *C, const int ldc); +void Mjoin(PATL,pMBmm_b0)(const int M, const int N, const int K, + const TYPE alpha, const TYPE *A, const int lda, + const TYPE *B, const int ldb, const TYPE beta, + TYPE *C, const int ldc); +void Mjoin(PATL,pKBmm)(const int M, const int N, const int K, + const TYPE alpha, const TYPE *A, const int lda, + const TYPE *B, const int ldb, const TYPE beta, + TYPE *C, const int ldc); + +void Mjoin(PATL,MBJBmm)(const int N, const int K, const TYPE *A, const TYPE *B, + const TYPE beta, TYPE *C, const int ldc); +void Mjoin(PATL,IBJBmm)(int IB, int JB, int K, const TYPE *A, const TYPE *B, + const TYPE beta, TYPE *C, const int ldc); +void Mjoin(PATL,IBNBmm)(const int M, const int K, const TYPE *A, const TYPE *B, + const TYPE beta, TYPE *C, const int ldc); +#ifdef TCPLX + +void Mjoin(PATL,CNBmm_b0)(const int M, const int N, const int K, + const TYPE alpha, const TYPE *A, const int lda, + const TYPE *B, const int ldb, const TYPE beta, + TYPE *C, const int ldc); +void Mjoin(PATL,CNBmm_b1)(const int M, const int N, const int K, + const TYPE alpha, const TYPE *A, const int lda, + const TYPE *B, const int ldb, const TYPE beta, + TYPE *C, const int ldc); +void Mjoin(PATL,CNBmm_bX)(const int M, const int N, const int K, + const TYPE alpha, const TYPE *A, const int lda, + const TYPE *B, const int ldb, const TYPE beta, + TYPE *C, const int ldc); +void Mjoin(PATL, gescal_bXi0)(const int, const int, const SCALAR, TYPE*, + const int); + +void Mjoin(PATL,row2blkT_aXi0) + (const int, const int, const TYPE*, const int, TYPE*, const SCALAR); +void Mjoin(PATL,row2blkT2_aXi0) + (const int, const int, const TYPE*, const int, TYPE*, const SCALAR); +void Mjoin(PATL,col2blk_aXi0) + (const int, const int, const TYPE*, const int, TYPE*, const SCALAR); +void Mjoin(PATL,col2blk2_aXi0) + (const int, const int, const TYPE*, const int, TYPE*, const SCALAR); + +void Mjoin(PATL,row2blkC_aX) + (const int, const int, const TYPE*, const int, TYPE*, const SCALAR); +void Mjoin(PATL,row2blkC2_aX) + (const int, const int, const TYPE*, const int, TYPE*, const SCALAR); +void Mjoin(PATL,col2blkConj_aX) + (const int, const int, const TYPE*, const int, TYPE*, const SCALAR); +void Mjoin(PATL,col2blkConj2_aX) + (const int, const int, const TYPE*, const int, TYPE*, const SCALAR); +void Mjoin(PATL,row2blkC_a1) + (const int, const int, const TYPE*, const int, TYPE*, const SCALAR); +void Mjoin(PATL,row2blkC2_a1) + (const int, const int, const TYPE*, const int, TYPE*, const SCALAR); +void Mjoin(PATL,col2blkConj_a1) + (const int, const int, const TYPE*, const int, TYPE*, const SCALAR); +void Mjoin(PATL,col2blkConj2_a1) + (const int, const int, const TYPE*, const int, TYPE*, const SCALAR); +void Mjoin(PATL,row2blkC_aXi0) + (const int, const int, const TYPE*, const int, TYPE*, const SCALAR); +void Mjoin(PATL,row2blkC2_aXi0) + (const int, const int, const TYPE*, const int, TYPE*, const SCALAR); +void Mjoin(PATL,col2blkConj_aXi0) + (const int, const int, const TYPE*, const int, TYPE*, const SCALAR); +void Mjoin(PATL,col2blkConj2_aXi0) + (const int, const int, const TYPE*, const int, TYPE*, const SCALAR); + +void Mjoin(PATL,mmJIK2) + (int K, int nMb, int nNb, int nKb, int ib, int jb, int kb, + const SCALAR alpha, const TYPE *pA0, const TYPE *B, int ldb, TYPE *pB0, + int incB, MAT2BLK B2blk, const SCALAR beta, TYPE *C, int ldc, + MATSCAL gescal, NBMM0 NBmm0); + +void Mjoin(PATL,mmIJK2) + (int K, int nMb, int nNb, int nKb, int ib, int jb, int kb, + const SCALAR alpha, const TYPE *A, const int lda, TYPE *pA0, const int incA, + MAT2BLK A2blk, TYPE *pB0, const SCALAR beta, TYPE *C, int ldc, + MATSCAL gescal, NBMM0 NBmm0); + +#else /* real */ + +void Mjoin(PATL,putblk_bX)(int M, int N, TYPE *V, TYPE *C, int ldc, const SCALAR beta); +void Mjoin(PATL,putblk_bn1)(int M, int N, TYPE *V, TYPE *C, int ldc, const SCALAR beta); +void Mjoin(PATL,putblk_b1)(int M, int N, TYPE *V, TYPE *C, int ldc, const SCALAR beta); +void Mjoin(PATL,putblk_b0)(int M, int N, TYPE *V, TYPE *C, int ldc, const SCALAR beta); +void ATL_gereal2cplx(const int M, const int N, TYPE *alpha, TYPE *R, int ldr, + TYPE *I, int ldi, TYPE *beta, TYPE *C, int ldc); + +void NBmm_b1(const int M, const int N, const int K, const TYPE alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const TYPE beta, TYPE *C, const int ldc); +void NBmm_b0(const int M, const int N, const int K, const TYPE alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const TYPE beta, TYPE *C, const int ldc); +void NBmm_bX(const int M, const int N, const int K, const TYPE alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const TYPE beta, TYPE *C, const int ldc); +void Mjoin(PATL,mmJIK2)(int K, int nMb, int nNb, int nKb, int ib, int jb, + int kb, const SCALAR alpha, const TYPE *pA0, + const TYPE *B, int ldb, TYPE *pB0, int incB, + MAT2BLK B2blk, const SCALAR beta, TYPE *C, int ldc, + TYPE *pC, PUTBLK putblk, NBMM0 NBmm0); + +void Mjoin(PATL,mmIJK2)(int K, int nMb, int nNb, int nKb, int ib, int jb, + int kb, const SCALAR alpha, const TYPE *A, int lda, + TYPE *pA0, int incA, MAT2BLK A2blk, const TYPE *pB0, + const SCALAR beta, TYPE *C, int ldc, TYPE *pC, + PUTBLK putblk, NBMM0 NBmm0); + + +void Mjoin(PATL,aliased_gemm) + (const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void Mjoin(PATL,f77gemm) + (const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void Mjoin(PATL,gemm) + (const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void Mjoin(PATL,small_mm) + (const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void Mjoin(PATL,big_mm) + (const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +#endif + +#ifdef USERGEMM +int Mjoin(PATU,usergemm)(const enum ATLAS_TRANS, const enum ATLAS_TRANS, + const int, const int, const int, const SCALAR, + const TYPE*, const int, const TYPE*, + const int, const SCALAR, TYPE*, const int); +#endif +int Mjoin(PATL,NCmmJIK)(const enum ATLAS_TRANS, const enum ATLAS_TRANS, + const int, const int, const int, const SCALAR, + const TYPE*, const int, const TYPE*, + const int, const SCALAR, TYPE*, const int); +int Mjoin(PATL,NCmmIJK)(const enum ATLAS_TRANS, const enum ATLAS_TRANS, + const int, const int, const int, const SCALAR, + const TYPE*, const int, const TYPE*, + const int, const SCALAR, TYPE*, const int); +int Mjoin(PATL,NCmmJIK_c)(const enum ATLAS_TRANS, const enum ATLAS_TRANS, + const int, const int, const int, const SCALAR, + const TYPE*, const int, const TYPE*, + const int, const SCALAR, TYPE*, const int); +int Mjoin(PATL,NCmmIJK_c)(const enum ATLAS_TRANS, const enum ATLAS_TRANS, + const int, const int, const int, const SCALAR, + const TYPE*, const int, const TYPE*, + const int, const SCALAR, TYPE*, const int); + +void Mjoin(PATL,row2blkT2_aX)(int, int, const TYPE*, int, TYPE*, const SCALAR); +void Mjoin(PATL,row2blkT_aX)(int, int, const TYPE*, int, TYPE*, const SCALAR); +void Mjoin(PATL,col2blk2_aX)(int, int, const TYPE*, int, TYPE*, const SCALAR); +void Mjoin(PATL,col2blk_aX)(int, int, const TYPE*, int, TYPE*, const SCALAR); +void Mjoin(PATL,row2blkT2_an1)(int, int, const TYPE*, int, TYPE*, + const SCALAR); +void Mjoin(PATL,row2blkT_an1)(int, int, const TYPE*, int, TYPE*, const SCALAR); +void Mjoin(PATL,col2blk2_an1)(int, int, const TYPE*, int, TYPE*, const SCALAR); +void Mjoin(PATL,col2blk_an1)(int, int, const TYPE*, int, TYPE*, const SCALAR); +void Mjoin(PATL,row2blkT2_a1)(int, int, const TYPE*, int, TYPE*, const SCALAR); +void Mjoin(PATL,row2blkT_a1)(int, int, const TYPE*, int, TYPE*, const SCALAR); +void Mjoin(PATL,col2blk2_a1)(int, int, const TYPE*, int, TYPE*, const SCALAR); +void Mjoin(PATL,col2blk_a1)(int, int, const TYPE*, int, TYPE*, const SCALAR); + +int Mjoin(PATL,mmJITcp)(const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, + const SCALAR alpha, const TYPE *A, const int lda, + const TYPE *B, const int ldb, const SCALAR beta, + TYPE *C, const int ldc); +int Mjoin(PATL,mmJIK)(const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, + const SCALAR alpha, const TYPE *A, const int lda, + const TYPE *B, const int ldb, const SCALAR beta, + TYPE *C, const int ldc); +int Mjoin(PATL,mmIJK)(const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, + const SCALAR alpha, const TYPE *A, const int lda, + const TYPE *B, const int ldb, const SCALAR beta, + TYPE *C, const int ldc); +int Mjoin(PATL,mmJKI)(const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, + const SCALAR alpha, const TYPE *A, const int lda, + const TYPE *B, const int ldb, const SCALAR beta, + TYPE *C, const int ldc); + +void Mjoin(PATL,mmK) + (int M, int m, int N, int n, int nblk, int kr, int KR, const SCALAR alphaA, + const SCALAR alphaB, const SCALAR beta, const TYPE *A, const int lda, + const int incA, TYPE *pA, const int incAW, const TYPE *B, const int ldb, + const int incB, TYPE *pB, const int incBW, TYPE *C, const int ldc, + MAT2BLK2 A2blk, MAT2BLK2 B2blk, NBMM0 NBmm0, NBMM0 NBmm1); + +int Mjoin(PATL,mmBPP)(const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, + const SCALAR alpha, const TYPE *A, const int lda, + const TYPE *B, const int ldb, const SCALAR beta, + TYPE *C, const int ldc); + + +void Mjoin(PATL,gemmTT) + (const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void Mjoin(PATL,aliased_gemmTT) + (const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void Mjoin(PATL,gemmTN) + (const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void Mjoin(PATL,aliased_gemmTN) + (const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void Mjoin(PATL,gemmNT) + (const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void Mjoin(PATL,aliased_gemmNT) + (const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void Mjoin(PATL,gemmNN) + (const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void Mjoin(PATL,aliased_gemmNN) + (const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); + + +void NCmmNNIJK_c + (const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void NCmmNTIJK_c + (const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void NCmmTNIJK_c + (const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void NCmmTTIJK_c + (const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void NCmmNNIJK + (const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void NCmmNTIJK + (const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void NCmmTNIJK + (const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void NCmmTTIJK + (const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void NCmmNNJIK_c + (const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void NCmmNTJIK_c + (const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void NCmmTNJIK_c + (const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void NCmmTTJIK_c + (const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void NCmmNNJIK + (const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void NCmmNTJIK + (const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void NCmmTNJIK + (const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); +void NCmmTTJIK + (const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, TYPE *C, const int ldc); + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_misc.h b/kaldi_io/src/tools/ATLAS/include/atlas_misc.h new file mode 100644 index 0000000..88f754d --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_misc.h @@ -0,0 +1,416 @@ +/* + * Automatically Tuned Linear Algebra Software v3.8.3 + * (C) Copyright 1997 R. Clint Whaley + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the ATLAS group or the names of its contributers may + * not be used to endorse or promote products derived from this + * software without specific written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include "atlas_enum.h" + +#ifndef ATLAS_MISC_H +#define ATLAS_MISC_H +#include "atlas_type.h" +#ifdef ATL_PROFILE + extern int ATL_ProfGemmCameFrom; +#endif +/* + * Some useful macro functions + */ +#if (defined(PentiumCPS) || defined(ATL_USEPTHREADS)) && !defined(WALL) + #define WALL +#endif +#ifndef time00 + #if defined(WALL) + #define time00 ATL_walltime + #else + #define time00 ATL_cputime + #endif +#endif +#define Mabs(x) ( (x) >= 0 ? (x) : -(x) ) +#define Mmax(x, y) ( (x) > (y) ? (x) : (y) ) +#define Mmin(x, y) ( (x) > (y) ? (y) : (x) ) +#define Mlowcase(C) ( ((C) > 64 && (C) < 91) ? (C) | 32 : (C) ) +#define Mupcase(C) ( ((C) > 96 && (C) < 123) ? (C) & 0xDF : (C) ) +/* + * packed indexing functions (upper & lower) + */ + +#define Mjoin(pre, nam) my_join(pre, nam) +#define my_join(pre, nam) pre ## nam +#define Mstr2(m) # m +#define Mstr(m) Mstr2(m) + +#define ATL_assert(n_) \ +{ \ + if (!(n_)) \ + { \ + ATL_xerbla(0, __FILE__, "assertion %s failed, line %d of file %s\n", \ + Mstr(n_), __LINE__, __FILE__); \ + } \ +} + +/* + * Define some C99 features that we use when we know the compiler supports them + */ +#if defined(__STDC_VERSION__) && (__STDC_VERSION__/100 >= 1999) + #define INLINE inline + #define RESTRICT restrict +#else + #define INLINE + #define RESTRICT +#endif + +#if defined(SREAL) + #define EPS 5.0e-7 + #define TYPE float + #define PRE s + #define UPR s + #define PREU S + #define PATL ATL_s + #define PATU ATLU_s + #define UATL ATLU_s + #define CBLA cblas_s + #define PATLU ATL_s + #define ATL_rone 1.0f + #define ATL_rnone -1.0f + #define ATL_rzero 0.0f + #define ATL_typify(m_) Mjoin(m_,f) + #include "atlas_ssysinfo.h" +#elif defined(DREAL) + #define EPS 1.0e-15 + #define TYPE double + #define PRE d + #define UPR d + #define PREU D + #define PATL ATL_d + #define PATU ATLU_d + #define UATL ATLU_d + #define CBLA cblas_d + #define PATLU ATL_d + #define ATL_rone 1.0 + #define ATL_rnone -1.0 + #define ATL_rzero 0.0 + #define ATL_typify(m_) m_ + #include "atlas_dsysinfo.h" +#elif defined (QREAL) + #define EPS 1.9259299443872358530559779425849273E-34L + #define TYPE long double + #define PRE q + #define UPR q + #define PREU Q + #define PATL ATL_q + #define PATU ATLU_q + #define CBLA cblas_q +#elif defined(SCPLX) + #define EPS 5.0e-7 + #define TYPE float + #define PRE c + #define UPR s + #define PREU C + #define PATL ATL_c + #define PATLU ATL_s + #define PATU ATLU_c + #define UATL ATLU_s + #define ATL_rone 1.0f + #define ATL_rnone -1.0f + #define ATL_rzero 0.0f + #define ATL_typify(m_) Mjoin(m_,f) + #define CBLA cblas_c + #include "atlas_csysinfo.h" +#elif defined(DCPLX) + #define TYPE double + #define PRE z + #define UPR d + #define PREU Z + #define PATL ATL_z + #define PATLU ATL_d + #define PATU ATLU_z + #define UATL ATLU_d + #define EPS 1.0e-15 + #define ATL_rone 1.0 + #define ATL_rnone -1.0 + #define ATL_rzero 0.0 + #define ATL_typify(m_) m_ + #define CBLA cblas_z + #include "atlas_zsysinfo.h" +#endif + +#if defined (SREAL) || defined (DREAL) || defined (SCPLX) || defined (DCPLX) + #define ATL_sizeof Mjoin(PATL,size) + #define ATL_MulBySize Mjoin(PATL,MulBySize) + #define ATL_DivBySize Mjoin(PATL,DivBySize) +#endif + +#if ( defined(SREAL) || defined(DREAL) || defined(QREAL) ) + #define TREAL + #define SHIFT + #define SCALAR TYPE + #define SADD & + #define SVAL + #define SVVAL * + #define SCALAR_IS_ONE(M_scalar) ((M_scalar) == ATL_rone) + #define SCALAR_IS_NONE(M_scalar) ((M_scalar) == ATL_rnone) + #define SCALAR_IS_ZERO(M_scalar) ((M_scalar) == ATL_rzero) +#elif defined(SCPLX) || defined(DCPLX) + #define TCPLX +/* + * c = b*c + v; + */ + #define CMULT2(v, a, b, tmp) \ + { \ + tmp = *(a) * *(b) - *(a+1) * *(b+1); \ + *(b+1) = *(a) * *(b+1) + *(a+1) * *(b) + *(v+1); \ + *(b) = tmp + *v; \ + } + #define SHIFT << 1 + #define SCALAR TYPE * + #define SADD + #define SVAL * + #define SVVAL + #define SCALAR_IS_ONE(M_scalar) \ + ( (*(M_scalar) == ATL_rone) && ((M_scalar)[1] == ATL_rzero) ) + #define SCALAR_IS_NONE(M_scalar) \ + ( (*(M_scalar) == ATL_rnone) && ((M_scalar)[1] == ATL_rzero) ) + #define SCALAR_IS_ZERO(M_scalar) \ + ( (*(M_scalar) == ATL_rzero) && ((M_scalar)[1] == ATL_rzero) ) +#endif + +#if defined(ALPHA1) + #define ATL_MulByALPHA(x_) (x_) + #define NM _a1 +#elif defined (ALPHA0) + #define ATL_MulByALPHA(x_) ATL_rzero + #define NM _a0 +#elif defined (ALPHAN1) + #define ATL_MulByALPHA(x_) (-(x_)) + #define NM _an1 +#elif defined (ALPHAXI0) + #define ATL_MulByALPHA(x_) (ralpha*(x_)) + #define NM _aXi0 +#elif defined (ALPHA1C) + #define NM _a1c +#elif defined (ALPHAN1C) + #define NM _an1c +#elif defined (ALPHAXI0C) + #define NM _aXi0c +#elif defined (ALPHAXC) + #define NM _aXc +#elif defined (ALPHAX) + #define ATL_MulByALPHA(x_) (alpha*(x_)) + #define NM _aX +#endif + +#if defined(BETA1) + #define ATL_MulByBETA(x_) (x_) + #define MSTAT A[i] += v[i] + #define BNM _b1 +#elif defined(BETA1C) + #define BNM _b1c +#elif defined(BETAN1) + #define ATL_MulByBETA(x_) (-(x_)) + #define MSTAT A[i] = v[i] - A[i] + #define BNM _bn1 +#elif defined(BETAN1C) + #define BNM _bn1c +#elif defined(BETA0) + #define ATL_MulByBETA(x_) ATL_rzero + #define MSTAT A[i] = v[i] + #define BNM _b0 +#elif defined (BETAXI0) + #define BNM _bXi0 + #define ATL_MulByBETA(x_) (rbeta*(x_)) +#elif defined (BETAXI0C) + #define BNM _bXi0c +#elif defined (BETAX) + #define ATL_MulByBETA(x_) (beta*(x_)) + #define MSTAT A[i] = beta*A[i] + v[i] + #define BNM _bX +#elif defined (BETAXC) + #define BNM _bXc +#endif + +/* any alignment below this forces data copy in gemm */ +#ifndef ATL_MinMMAlign + #define ATL_MinMMAlign 16 +#endif +#if (ATL_MinMMAlign == 1 || ATL_MinMMAlign == 0) + #define ATL_DataIsMinAligned(ptr) 1 +#elif (ATL_MinMMAlign == 2) + #define ATL_DataIsMinAligned(ptr) \ + ( (((size_t) (ptr))>>1)<<1 == (size_t) (ptr) ) +#elif (ATL_MinMMAlign == 4) + #define ATL_DataIsMinAligned(ptr) \ + ( (((size_t) (ptr))>>2)<<2 == (size_t) (ptr) ) +#elif (ATL_MinMMAlign == 8) + #define ATL_DataIsMinAligned(ptr) \ + ( (((size_t) (ptr))>>3)<<3 == (size_t) (ptr) ) +#elif (ATL_MinMMAlign == 16) + #define ATL_DataIsMinAligned(ptr) \ + ( (((size_t) (ptr))>>4)<<4 == (size_t) (ptr) ) +#elif (ATL_MinMMAlign == 32) + #define ATL_DataIsMinAligned(ptr) \ + ( (((size_t) (ptr))>>5)<<5 == (size_t) (ptr) ) +#elif (ATL_MinMMAlign == 64) + #define ATL_DataIsMinAligned(ptr) \ + ( (((size_t) (ptr))>>6)<<6 == (size_t) (ptr) ) +#elif (ATL_MinMMAlign == 128) + #define ATL_DataIsMinAligned(ptr) \ + ( (((size_t) (ptr))>>7)<<7 == (size_t) (ptr) ) +#else + #define ATL_DataIsMinAligned(ptr) \ + ( (((size_t) (ptr))/ATL_MinMMAlign)*ATL_MinMMAlign == (size_t) (ptr) ) +#endif + +#define ATL_Cachelen 32 +#if (ATL_Cachelen == 4) + #define ATL_MulByCachelen(N_) ( (N_) << 2 ) + #define ATL_DivByCachelen(N_) ( (N_) >> 2 ) +#elif (ATL_Cachelen == 8) + #define ATL_MulByCachelen(N_) ( (N_) << 3 ) + #define ATL_DivByCachelen(N_) ( (N_) >> 3 ) +#elif (ATL_Cachelen == 16) + #define ATL_MulByCachelen(N_) ( (N_) << 4 ) + #define ATL_DivByCachelen(N_) ( (N_) >> 4 ) +#elif (ATL_Cachelen == 32) + #define ATL_MulByCachelen(N_) ( (N_) << 5 ) + #define ATL_DivByCachelen(N_) ( (N_) >> 5 ) +#elif (ATL_Cachelen == 64) + #define ATL_MulByCachelen(N_) ( (N_) << 6 ) + #define ATL_DivByCachelen(N_) ( (N_) >> 6 ) +#elif (ATL_Cachelen == 128) + #define ATL_MulByCachelen(N_) ( (N_) << 7 ) + #define ATL_DivByCachelen(N_) ( (N_) >> 7 ) +#elif (ATL_Cachelen == 256) + #define ATL_MulByCachelen(N_) ( (N_) << 8 ) + #define ATL_DivByCachelen(N_) ( (N_) >> 8 ) +#else + #define ATL_MulByCachelen(N_) ( (N_) * ATL_Cachelen ) + #define ATL_DivByCachelen(N_) ( (N_) / ATL_Cachelen ) +#endif + +#if (ATL_Cachelen < ATL_MinMMAlign) + Force a compilation error if our required alignment is at least the + minimum!!@^ +#endif + +#define ATL_AlignPtr(vp) \ + (void*) (ATL_Cachelen + ATL_MulByCachelen(ATL_DivByCachelen((size_t) (vp)))) + +#define ATL_FindPtrAdjust(vp, iadj_) \ +{ \ + (iadj_) = ((size_t)(vp))-ATL_MulByCachelen(ATL_DivByCachelen((size_t)(vp)));\ + if (iadj_) \ + { \ + if ( (iadj_) == ATL_MulBySize(ATL_DivBySize(iadj_)) ) \ + (iadj_) = ATL_DivBySize(iadj_); \ + else (iadj_) = 0; \ + }\ +} +#define ATL_FindMatAdjust(vp_, lda_, iadj_) \ +{ \ + if (ATL_MulByCachelen(ATL_DivByCachelen(ATL_MulBySize(lda_))) \ + == ATL_MulBySize(lda_)) \ + { \ + ATL_FindPtrAdjust(vp_, iadj_); \ + } \ + else (iadj_) = 0; \ +} + +#define ATL_sqrtLL(x, res) \ + asm ("fsqrt" : "=t" (res) : "0" (x)); + +/* + * Find N necessary for alignment. Written as function for optimization, + * declared static to encourage inlining + */ +static int ATL_AlignOffset +(const int N, /* max return value */ + const void *vp, /* pointer to be aligned */ + const int inc, /* size of each elt, in bytes */ + const int align) /* required alignment, in bytes */ +{ + const int p = align/inc; + const size_t k=(size_t)vp, j=k/inc; + int iret; + if (k == (j)*inc && p*inc == align) + { + iret = ((j+p-1) / p)*p - j; + if (iret <= N) return(iret); + } + return(N); +} + +/* + * Gcc links in crap that MSVC++ and DVF can't handle if you use stdout + * or stderr, so use this beautiful kludge to avoid this problem -- RCW + */ +#ifdef GCCWIN + +#include +static int WINFPRINTF(FILE *fpout, char *form, ...) +{ + int ierr=0; + va_list argptr; + + va_start(argptr, form); + if (fpout == NULL) ierr = vprintf(form, argptr); + else ierr = vfprintf(fpout, form, argptr); + va_end(argptr); + + return(ierr); +} + +#ifdef stdout + #undef stdout +#endif +#ifdef stderr + #undef stderr +#endif +#ifdef assert + #undef assert +#endif + +#define stdout NULL +#define stderr NULL +#define fprintf WINFPRINTF +#define assert WINASSERT +#define WINASSERT(n_) \ +{ \ + if (!(n_)) \ + { \ + printf("assertion %s failed, line %d of file %s\n", \ + Mstr(n_), __LINE__, __FILE__); \ + exit(1); \ + } \ +} + +#endif + +#include "atlas_aux.h" + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_mv.h b/kaldi_io/src/tools/ATLAS/include/atlas_mv.h new file mode 100644 index 0000000..f26da5f --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_mv.h @@ -0,0 +1,45 @@ +/* + * Automatically Tuned Linear Algebra Software v3.8.3 + * (C) Copyright 1999 R. Clint Whaley + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the ATLAS group or the names of its contributers may + * not be used to endorse or promote products derived from this + * software without specific written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef ATLAS_MV_H + #define ATLAS_MV_H + +#include "atlas_misc.h" +#if defined(SREAL) + #include "atlas_smv.h" +#elif defined(DREAL) + #include "atlas_dmv.h" +#elif defined(SCPLX) + #include "atlas_cmv.h" +#elif defined(DCPLX) + #include "atlas_zmv.h" +#endif + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_pkblas.h b/kaldi_io/src/tools/ATLAS/include/atlas_pkblas.h new file mode 100644 index 0000000..b9c7d82 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_pkblas.h @@ -0,0 +1,569 @@ +/* + * Automatically Tuned Linear Algebra Software v3.8.3 + * (C) Copyright 2003 R. Clint Whaley + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the ATLAS group or the names of its contributers may + * not be used to endorse or promote products derived from this + * software without specific written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef ATLAS_PKBLAS_H +#define ATLAS_PKBLAS_H + +#include "atlas_misc.h" +#ifndef ATL_NOL3 +#include "atlas_lvl3.h" +#endif + +#define CBLAS_ENUM_ONLY +#include "cblas.h" +#undef CBLAS_ENUM_ONLY + +enum PACK_UPLO {PackUpper=121, PackLower=122, PackGen=123}; + +#define PACK_ORDER CBLAS_ORDER + #define PackRowMajor CblasRowMajor + #define PackColMajor CblasColMajor +#define PACK_TRANS CBLAS_TRANSPOSE + #define PackNoTrans CblasNoTrans + #define PackTrans CblasTrans + #define PackConjTrans CblasConjTrans + #define PackConj AtlasConj +#define PACK_DIAG CBLAS_DIAG + #define PackNonUnit CblasNonUnit + #define PackUnit CblasUnit +#define PACK_SIDE CBLAS_SIDE + #define PackLeft CblasLeft + #define PackRight CblasRight + +#ifndef ATL_pkMaxMalloc + #define ATL_pkMaxMalloc ATL_MaxMalloc +#endif + +#ifdef TCPLX + #define MindexPL(I_,J_,lda_) ( (((J_)*((lda_)+(lda_)-(J_)-1))) + (I_)+(I_) ) + #define MindexPU(I_,J_,lda_) ( ((((lda_)+(lda_)+(J_)-1)*(J_))) + (I_)+(I_) ) +#else + #define MindexPL(I_,J_,lda_) ( (((J_)*((lda_)+(lda_)-(J_)-1))>>1) + (I_) ) + #define MindexPU(I_,J_,lda_) ( ((((lda_)+(lda_)+(J_)-1)*(J_))>>1) + (I_) ) +#endif +#define MindexP(uplo_,I_,J_,lda_) \ + ( (uplo_) == PackUpper ? MindexPU(I_,J_,lda_) : \ + ( (uplo_) == PackLower ? MindexPL(I_,J_,lda_) : \ + (((J_)*(lda_)+(I_))SHIFT) ) ) +#define Mpld(uplo_,J_,lda_) (uplo_) == PackUpper ? (lda_)+(J_) : \ + ( (uplo_) == PackLower ? (lda_)-(J_) : (lda_) ) + + +void ATL_sgpmm(const enum PACK_UPLO UA, const enum PACK_TRANS TA, + const enum PACK_UPLO UB, const enum PACK_TRANS TB, + const enum PACK_UPLO UC, + const int M, const int N, const int K, const float alpha, + const float *A, const int IA, const int JA, const int lda, + const float *B, const int IB, const int JB, const int ldb, + const float beta, float *C, const int IC, const int JC, + const int ldc); +void ATL_sprankK(const enum PACK_UPLO UA, const enum ATLAS_TRANS TA, + const enum PACK_UPLO UB, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, int R, + const SCALAR alpha, const TYPE *A, int lda, + const TYPE *B, int ldb, const SCALAR beta, + const enum PACK_UPLO UC, TYPE *C, int ldc); +int ATL_spmmJIKF(const enum PACK_UPLO UA, const enum ATLAS_TRANS TA, + const enum PACK_UPLO UB, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, const enum PACK_UPLO UC, + TYPE *C, const int ldc); +int ATL_spmmJIK(const enum PACK_UPLO UA, const enum ATLAS_TRANS TA, + const enum PACK_UPLO UB, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const float alpha, + const float *A, const int lda, const float *B, const int ldb, + const float beta, const enum PACK_UPLO UC, + float *C, const int ldc); +void ATL_spcol2blkF(const int M, const int N, const float alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_sprow2blkTF(const int M, const int N, const float alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_spcol2blk_a1(const int M, const int N, const float alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_spcol2blk_aX(const int M, const int N, const float alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_sprow2blkT_a1(const int M, const int N, const float alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_sprow2blkT_aX(const int M, const int N, const float alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_spputblk(const int M, const int N, const TYPE *V, TYPE *C, + int ldc, int ldcinc, const SCALAR beta); +void ATL_spputblk_diag + (const int M, const int N, const float *V, const enum ATLAS_UPLO UC, + float *C, int ldc, int ldcinc, const float alpha, const float beta); +void ATL_spputblk_aX + (const int M, const int N, const float *V, float *C, int ldc, int ldcinc, + const float alpha, const float beta); +void ATL_ssprk(const enum PACK_UPLO UA, const enum PACK_TRANS TA, + const enum ATLAS_UPLO UC, const int CP, + const int N, const int K, const float alpha, + const float *A, const int IA, const int JA, const int lda, + const float beta, + float *C, const int IC, const int JC, const int ldc); +void ATL_shprk(const enum PACK_UPLO UA, const enum PACK_TRANS TA, + const enum ATLAS_UPLO UC, const int CP, + const int N, const int K, const float alpha, + const float *A, const int IA, const int JA, const int lda, + const float beta, + float *C, const int IC, const int JC, const int ldc); +void ATL_shprk_rK(const enum PACK_UPLO UA, const enum PACK_TRANS TA, + const enum ATLAS_UPLO UC, const int CP, + const int N, const int K, int R, const float alpha, + const float *A, int lda, const float beta, + float *C, const int ldc); +int ATL_sphk_kmm(const enum ATLAS_UPLO UC, const enum PACK_UPLO UA, + const enum ATLAS_TRANS TA, const int N, const int K, + const float alpha, const float *A, const int lda, + const float beta, const int CP, float *C, const int ldc); +void ATL_ssprk_rK(const enum PACK_UPLO UA, const enum PACK_TRANS TA, + const enum ATLAS_UPLO UC, const int CP, + const int N, const int K, int R, const float alpha, + const float *A, int lda, const float beta, + float *C, const int ldc); +int ATL_sprk_kmm(const enum ATLAS_UPLO UC, const enum PACK_UPLO UA, + const enum ATLAS_TRANS TA, const int N, const int K, + const float alpha, const float *A, const int lda, + const float beta, const int CP, float *C, const int ldc); + +void ATL_dgpmm(const enum PACK_UPLO UA, const enum PACK_TRANS TA, + const enum PACK_UPLO UB, const enum PACK_TRANS TB, + const enum PACK_UPLO UC, + const int M, const int N, const int K, const double alpha, + const double *A, const int IA, const int JA, const int lda, + const double *B, const int IB, const int JB, const int ldb, + const double beta, double *C, const int IC, const int JC, + const int ldc); +void ATL_dprankK(const enum PACK_UPLO UA, const enum ATLAS_TRANS TA, + const enum PACK_UPLO UB, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, int R, + const SCALAR alpha, const TYPE *A, int lda, + const TYPE *B, int ldb, const SCALAR beta, + const enum PACK_UPLO UC, TYPE *C, int ldc); +int ATL_dpmmJIKF(const enum PACK_UPLO UA, const enum ATLAS_TRANS TA, + const enum PACK_UPLO UB, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, const enum PACK_UPLO UC, + TYPE *C, const int ldc); +int ATL_dpmmJIK(const enum PACK_UPLO UA, const enum ATLAS_TRANS TA, + const enum PACK_UPLO UB, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const double alpha, + const double *A, const int lda, const double *B, const int ldb, + const double beta, const enum PACK_UPLO UC, + double *C, const int ldc); +void ATL_dpcol2blkF(const int M, const int N, const double alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_dprow2blkTF(const int M, const int N, const double alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_dpcol2blk_a1(const int M, const int N, const double alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_dpcol2blk_aX(const int M, const int N, const double alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_dprow2blkT_a1(const int M, const int N, const double alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_dprow2blkT_aX(const int M, const int N, const double alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_dpputblk(const int M, const int N, const TYPE *V, TYPE *C, + int ldc, int ldcinc, const SCALAR beta); +void ATL_dpputblk_diag + (const int M, const int N, const double *V, const enum ATLAS_UPLO UC, + double *C, int ldc, int ldcinc, const double alpha, const double beta); +void ATL_dpputblk_aX + (const int M, const int N, const double *V, double *C, int ldc, int ldcinc, + const double alpha, const double beta); +void ATL_dsprk(const enum PACK_UPLO UA, const enum PACK_TRANS TA, + const enum ATLAS_UPLO UC, const int CP, + const int N, const int K, const double alpha, + const double *A, const int IA, const int JA, const int lda, + const double beta, + double *C, const int IC, const int JC, const int ldc); +void ATL_dhprk(const enum PACK_UPLO UA, const enum PACK_TRANS TA, + const enum ATLAS_UPLO UC, const int CP, + const int N, const int K, const double alpha, + const double *A, const int IA, const int JA, const int lda, + const double beta, + double *C, const int IC, const int JC, const int ldc); +void ATL_dhprk_rK(const enum PACK_UPLO UA, const enum PACK_TRANS TA, + const enum ATLAS_UPLO UC, const int CP, + const int N, const int K, int R, const double alpha, + const double *A, int lda, const double beta, + double *C, const int ldc); +int ATL_dphk_kmm(const enum ATLAS_UPLO UC, const enum PACK_UPLO UA, + const enum ATLAS_TRANS TA, const int N, const int K, + const double alpha, const double *A, const int lda, + const double beta, const int CP, double *C, const int ldc); +void ATL_dsprk_rK(const enum PACK_UPLO UA, const enum PACK_TRANS TA, + const enum ATLAS_UPLO UC, const int CP, + const int N, const int K, int R, const double alpha, + const double *A, int lda, const double beta, + double *C, const int ldc); +int ATL_dprk_kmm(const enum ATLAS_UPLO UC, const enum PACK_UPLO UA, + const enum ATLAS_TRANS TA, const int N, const int K, + const double alpha, const double *A, const int lda, + const double beta, const int CP, double *C, const int ldc); + +void ATL_cgpmm(const enum PACK_UPLO UA, const enum PACK_TRANS TA, + const enum PACK_UPLO UB, const enum PACK_TRANS TB, + const enum PACK_UPLO UC, + const int M, const int N, const int K, const float* alpha, + const float *A, const int IA, const int JA, const int lda, + const float *B, const int IB, const int JB, const int ldb, + const float* beta, float *C, const int IC, const int JC, + const int ldc); +void ATL_cprankK(const enum PACK_UPLO UA, const enum ATLAS_TRANS TA, + const enum PACK_UPLO UB, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, int R, + const SCALAR alpha, const TYPE *A, int lda, + const TYPE *B, int ldb, const SCALAR beta, + const enum PACK_UPLO UC, TYPE *C, int ldc); +int ATL_cpmmJIKF(const enum PACK_UPLO UA, const enum ATLAS_TRANS TA, + const enum PACK_UPLO UB, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, const enum PACK_UPLO UC, + TYPE *C, const int ldc); +int ATL_cpmmJIK(const enum PACK_UPLO UA, const enum ATLAS_TRANS TA, + const enum PACK_UPLO UB, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const float* alpha, + const float *A, const int lda, const float *B, const int ldb, + const float* beta, const enum PACK_UPLO UC, + float *C, const int ldc); +void ATL_cpcol2blkF(const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cprow2blkTF(const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cpcol2blk_a1(const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cpcol2blk_aX(const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cprow2blkT_a1(const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cprow2blkT_aX(const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cpputblk(const int M, const int N, const TYPE *V, TYPE *C, + int ldc, int ldcinc, const SCALAR beta); +void ATL_cpputblk_diag + (const int M, const int N, const float *V, const enum ATLAS_UPLO UC, + float *C, int ldc, int ldcinc, const float* alpha, const float* beta); +void ATL_cpputblk_aX + (const int M, const int N, const float *V, float *C, int ldc, int ldcinc, + const float* alpha, const float* beta); +void ATL_csprk(const enum PACK_UPLO UA, const enum PACK_TRANS TA, + const enum ATLAS_UPLO UC, const int CP, + const int N, const int K, const float* alpha, + const float *A, const int IA, const int JA, const int lda, + const float* beta, + float *C, const int IC, const int JC, const int ldc); +void ATL_chprk(const enum PACK_UPLO UA, const enum PACK_TRANS TA, + const enum ATLAS_UPLO UC, const int CP, + const int N, const int K, const float alpha, + const float *A, const int IA, const int JA, const int lda, + const float beta, + float *C, const int IC, const int JC, const int ldc); +void ATL_chprk_rK(const enum PACK_UPLO UA, const enum PACK_TRANS TA, + const enum ATLAS_UPLO UC, const int CP, + const int N, const int K, int R, const float* alpha, + const float *A, int lda, const float* beta, + float *C, const int ldc); +int ATL_cphk_kmm(const enum ATLAS_UPLO UC, const enum PACK_UPLO UA, + const enum ATLAS_TRANS TA, const int N, const int K, + const float* alpha, const float *A, const int lda, + const float* beta, const int CP, float *C, const int ldc); +void ATL_csprk_rK(const enum PACK_UPLO UA, const enum PACK_TRANS TA, + const enum ATLAS_UPLO UC, const int CP, + const int N, const int K, int R, const float* alpha, + const float *A, int lda, const float* beta, + float *C, const int ldc); +int ATL_cprk_kmm(const enum ATLAS_UPLO UC, const enum PACK_UPLO UA, + const enum ATLAS_TRANS TA, const int N, const int K, + const float* alpha, const float *A, const int lda, + const float* beta, const int CP, float *C, const int ldc); + +void ATL_zgpmm(const enum PACK_UPLO UA, const enum PACK_TRANS TA, + const enum PACK_UPLO UB, const enum PACK_TRANS TB, + const enum PACK_UPLO UC, + const int M, const int N, const int K, const double* alpha, + const double *A, const int IA, const int JA, const int lda, + const double *B, const int IB, const int JB, const int ldb, + const double* beta, double *C, const int IC, const int JC, + const int ldc); +void ATL_zprankK(const enum PACK_UPLO UA, const enum ATLAS_TRANS TA, + const enum PACK_UPLO UB, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, int R, + const SCALAR alpha, const TYPE *A, int lda, + const TYPE *B, int ldb, const SCALAR beta, + const enum PACK_UPLO UC, TYPE *C, int ldc); +int ATL_zpmmJIKF(const enum PACK_UPLO UA, const enum ATLAS_TRANS TA, + const enum PACK_UPLO UB, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const SCALAR alpha, + const TYPE *A, const int lda, const TYPE *B, const int ldb, + const SCALAR beta, const enum PACK_UPLO UC, + TYPE *C, const int ldc); +int ATL_zpmmJIK(const enum PACK_UPLO UA, const enum ATLAS_TRANS TA, + const enum PACK_UPLO UB, const enum ATLAS_TRANS TB, + const int M, const int N, const int K, const double* alpha, + const double *A, const int lda, const double *B, const int ldb, + const double* beta, const enum PACK_UPLO UC, + double *C, const int ldc); +void ATL_zpcol2blkF(const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zprow2blkTF(const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zpcol2blk_a1(const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zpcol2blk_aX(const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zprow2blkT_a1(const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zprow2blkT_aX(const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zpputblk(const int M, const int N, const TYPE *V, TYPE *C, + int ldc, int ldcinc, const SCALAR beta); +void ATL_zpputblk_diag + (const int M, const int N, const double *V, const enum ATLAS_UPLO UC, + double *C, int ldc, int ldcinc, const double* alpha, const double* beta); +void ATL_zpputblk_aX + (const int M, const int N, const double *V, double *C, int ldc, int ldcinc, + const double* alpha, const double* beta); +void ATL_zsprk(const enum PACK_UPLO UA, const enum PACK_TRANS TA, + const enum ATLAS_UPLO UC, const int CP, + const int N, const int K, const double* alpha, + const double *A, const int IA, const int JA, const int lda, + const double* beta, + double *C, const int IC, const int JC, const int ldc); +void ATL_zhprk(const enum PACK_UPLO UA, const enum PACK_TRANS TA, + const enum ATLAS_UPLO UC, const int CP, + const int N, const int K, const double alpha, + const double *A, const int IA, const int JA, const int lda, + const double beta, + double *C, const int IC, const int JC, const int ldc); +void ATL_zhprk_rK(const enum PACK_UPLO UA, const enum PACK_TRANS TA, + const enum ATLAS_UPLO UC, const int CP, + const int N, const int K, int R, const double* alpha, + const double *A, int lda, const double* beta, + double *C, const int ldc); +int ATL_zphk_kmm(const enum ATLAS_UPLO UC, const enum PACK_UPLO UA, + const enum ATLAS_TRANS TA, const int N, const int K, + const double* alpha, const double *A, const int lda, + const double* beta, const int CP, double *C, const int ldc); +void ATL_zsprk_rK(const enum PACK_UPLO UA, const enum PACK_TRANS TA, + const enum ATLAS_UPLO UC, const int CP, + const int N, const int K, int R, const double* alpha, + const double *A, int lda, const double* beta, + double *C, const int ldc); +int ATL_zprk_kmm(const enum ATLAS_UPLO UC, const enum PACK_UPLO UA, + const enum ATLAS_TRANS TA, const int N, const int K, + const double* alpha, const double *A, const int lda, + const double* beta, const int CP, double *C, const int ldc); + +void ATL_cpcol2blk_aX_blk + (const int blk, const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cprow2blkT_aX_blk + (const int blk, const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cpcol2blk_a1_blk + (const int blk, const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cprow2blkT_a1_blk + (const int blk, const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cpcol2blkConjF + (const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cpcol2blkConj_a1 + (const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cpcol2blkConj_aX + (const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cpcol2blk_aXi0 + (const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cpcol2blkConj_aXi0 + (const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc,float*V); +void ATL_cprow2blkHF + (const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cprow2blkH_a1 + (const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cprow2blkH_aX + (const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cprow2blkH_aXi0 + (const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cprow2blkT_aXi0 + (const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cpcol2blkConjF_blk + (const int blk, const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cpcol2blkConj_a1_blk + (const int blk, const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cpcol2blkConj_aX_blk + (const int blk, const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cpcol2blk_aXi0_blk + (const int blk, const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cpcol2blkConj_aXi0_blk + (const int blk, const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc,float*V); +void ATL_cprow2blkHF_blk + (const int blk, const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cprow2blkH_a1_blk + (const int blk, const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cprow2blkH_aX_blk + (const int blk, const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cprow2blkH_aXi0_blk + (const int blk, const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); +void ATL_cprow2blkT_aXi0_blk + (const int blk, const int M, const int N, const float* alpha, + const float *A, int lda, const int ldainc, float *V); + +void ATL_cprow2blkT_KB_aXi0 + (const int mb, const int nb, const SCALAR alpha, const TYPE *A, int lda, + const int ldainc, TYPE *V); +void ATL_cprow2blkT_KB_aX + (const int mb, const int nb, const SCALAR alpha, const TYPE *A, int lda, + const int ldainc, TYPE *V); +void ATL_cprow2blkT_KB_a1 + (const int mb, const int nb, const SCALAR alpha, const TYPE *A, int lda, + const int ldainc, TYPE *V); +void ATL_cprow2blkH_KB_aXi0 + (const int mb, const int nb, const SCALAR alpha, const TYPE *A, int lda, + const int ldainc, TYPE *V); +void ATL_cprow2blkH_KB_aX + (const int mb, const int nb, const SCALAR alpha, const TYPE *A, int lda, + const int ldainc, TYPE *V); +void ATL_cprow2blkH_KB_a1 + (const int mb, const int nb, const SCALAR alpha, const TYPE *A, int lda, + const int ldainc, TYPE *V); +void ATL_zpcol2blk_aX_blk + (const int blk, const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zprow2blkT_aX_blk + (const int blk, const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zpcol2blk_a1_blk + (const int blk, const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zprow2blkT_a1_blk + (const int blk, const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zpcol2blkConjF + (const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zpcol2blkConj_a1 + (const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zpcol2blkConj_aX + (const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zpcol2blk_aXi0 + (const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zpcol2blkConj_aXi0 + (const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc,double*V); +void ATL_zprow2blkHF + (const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zprow2blkH_a1 + (const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zprow2blkH_aX + (const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zprow2blkH_aXi0 + (const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zprow2blkT_aXi0 + (const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zpcol2blkConjF_blk + (const int blk, const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zpcol2blkConj_a1_blk + (const int blk, const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zpcol2blkConj_aX_blk + (const int blk, const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zpcol2blk_aXi0_blk + (const int blk, const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zpcol2blkConj_aXi0_blk + (const int blk, const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc,double*V); +void ATL_zprow2blkHF_blk + (const int blk, const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zprow2blkH_a1_blk + (const int blk, const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zprow2blkH_aX_blk + (const int blk, const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zprow2blkH_aXi0_blk + (const int blk, const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); +void ATL_zprow2blkT_aXi0_blk + (const int blk, const int M, const int N, const double* alpha, + const double *A, int lda, const int ldainc, double *V); + +void ATL_zprow2blkT_KB_aXi0 + (const int mb, const int nb, const SCALAR alpha, const TYPE *A, int lda, + const int ldainc, TYPE *V); +void ATL_zprow2blkT_KB_aX + (const int mb, const int nb, const SCALAR alpha, const TYPE *A, int lda, + const int ldainc, TYPE *V); +void ATL_zprow2blkT_KB_a1 + (const int mb, const int nb, const SCALAR alpha, const TYPE *A, int lda, + const int ldainc, TYPE *V); +void ATL_zprow2blkH_KB_aXi0 + (const int mb, const int nb, const SCALAR alpha, const TYPE *A, int lda, + const int ldainc, TYPE *V); +void ATL_zprow2blkH_KB_aX + (const int mb, const int nb, const SCALAR alpha, const TYPE *A, int lda, + const int ldainc, TYPE *V); +void ATL_zprow2blkH_KB_a1 + (const int mb, const int nb, const SCALAR alpha, const TYPE *A, int lda, + const int ldainc, TYPE *V); + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_prefetch.h b/kaldi_io/src/tools/ATLAS/include/atlas_prefetch.h new file mode 100644 index 0000000..83ee2df --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_prefetch.h @@ -0,0 +1,197 @@ +#ifndef ATLAS_PREFETCH_H +#define ATLAS_PREFETCH_H +/* + * Altivec prefetch model not well utilized by SSE-like prefetch, so have + * special commands for it. + */ +#if defined(ATL_AltiVec) + #include "atlas_altivec.h" +#endif +/* + * + * ATL_pfl1R(mem) : fetch location mem to L1, with intent to read *only* + * ATL_pfl1W(mem) : fetch location mem to L1, with intent to read/write + * ATL_pfl1WO(mem) : fetch location mem to L1, with intent to write ONLY + */ + +#if defined(ATL_3DNow) + #ifdef __GNUC__ + #define ATL_pfl1R(mem) \ + __asm__ __volatile__ ("prefetch %0" : : "m" (*((char *)(mem)))) + #define ATL_pfl1W(mem) \ + __asm__ __volatile__ ("prefetchw %0" : : "m" (*((char *)(mem)))) + #define ATL_pfl1WO ATL_pfl1W + #define ATL_GOT_L1PREFETCH + #ifdef ATL_SSE1 + #define ATL_pfl2R(mem) \ + __asm__ __volatile__ ("prefetcht1 %0" : : "m" (*((char *)(mem)))) + #define ATL_pfl2W(mem) \ + __asm__ __volatile__ ("prefetcht1 %0" : : "m" (*((char *)(mem)))) + #define ATL_pfl2WO ATL_pfl2W + #define ATL_GOT_L2PREFETCH + #endif + #endif +#elif defined(ATL_SSE1) || defined (ATL_SSE2) /* SSE prefetch is available */ + #ifdef __GNUC__ + #define ATL_pfl1R(mem) \ + __asm__ __volatile__ ("prefetchnta %0" : : "m" (*((char *)(mem)))) + #define ATL_pfl1W(mem) \ + __asm__ __volatile__ ("prefetchnta %0" : : "m" (*((char *)(mem)))) + #define ATL_pfl1WO ATL_pfl1W + #define ATL_GOT_L1PREFETCH + + #define ATL_pfl2R(mem) \ + __asm__ __volatile__ ("prefetcht1 %0" : : "m" (*((char *)(mem)))) + #define ATL_pfl2W(mem) \ + __asm__ __volatile__ ("prefetcht1 %0" : : "m" (*((char *)(mem)))) + #define ATL_pfl2WO ATL_pfl2W + #define ATL_GOT_L2PREFETCH + #endif +#elif defined(__SUNPRO_C) && defined(__sparc) /* && __SUNPRO_CC > 0x600 */ + #include + #define ATL_pfl1R(mem) sparc_prefetch_read_many((void*)(mem)) + #define ATL_pfl1W(mem) sparc_prefetch_write_many((void*)(mem)) + #define ATL_GOT_L1PREFETCH + #define ATL_pfl2R(mem) sparc_prefetch_read_many((void*)(mem)) + #define ATL_pfl2W(mem) sparc_prefetch_write_many((void*)(mem)) + #define ATL_GOT_L2PREFETCH +#elif defined(ATL_ARCH_21264) + #ifdef __GNUC__ + #define ATL_pfl1R(mem) \ + __asm__ __volatile__ ("ldt $f31, %0" : : "m" (*((char *)(mem)))) + #define ATL_pfl1W(mem) \ + __asm__ __volatile__ ("lds $f31, %0" : : "m" (*((char *)(mem)))) + #define ATL_pfl1WO(mem) \ + __asm__ __volatile__ ("wh64 %0" : : "m" (*((char *)(mem)))) + #define ATL_GOT_L1PREFETCH + #elif defined(__DECC) + #include "c_asm.h" + #define ATL_pfl1R(mem) asm ("ldt %f31,(%a0) ;", mem) + #define ATL_pfl1W(mem) asm ("lds %f31,(%a0) ;", mem) + #define ATL_pfl1WO(mem) asm ("wh64 (%a0) ;", mem) + #define ATL_GOT_L1PREFETCH + #endif +/* + * Note: SunUS5/10 seems to get no benefit from prefetch, so don't enable + */ +#elif defined(ATL_ARCH_USIV) || defined(ATL_ARCH_SunUSIII) || \ + defined(ATL_ARCH_SunUSII) || defined(ATL_ARCH_SunUSI) + #ifdef __GNUC__ + #define ATL_pfl1R(mem) \ + __asm__ __volatile__ ("prefetch %0,0" : : "m" (*((char *)(mem)))) + #define ATL_pfl1W(mem) \ + __asm__ __volatile__ ("prefetch %0,2" : : "m" (*((char *)(mem)))) + #define ATL_GOT_L1PREFETCH + #define ATL_pfl2R(mem) \ + __asm__ __volatile__ ("prefetch %0,3" : : "m" (*((char *)(mem)))) + #define ATL_pfl2W(mem) \ + __asm__ __volatile__ ("prefetch %0,2" : : "m" (*((char *)(mem)))) + #define ATL_GOT_L2PREFETCH + #endif +/* + * Gives gigantic slowdown on POWER4, so don't enable there, just use gcc + * builtin + */ +#elif defined(ATL_ARCH_PPCG5) || defined(ATL_ARCH_PPCG5) || \ + defined(ATL_ARCH_POWER5) + #if defined(__GNUC__) || defined(__IBM_GCC_ASM) + #define ATL_pfl1R(mem) \ + __asm__ __volatile__ ("dcbt 0, %0, 0" : : "r" ((mem))) + #define ATL_pfl1W(mem) \ + __asm__ __volatile__ ("dcbtst 0, %0" : : "r" ((mem))) + #define ATL_pfST(mem) \ + __asm__ __volatile__ ("dcbt 0, %0, 1" : : "r" ((mem))) + #define ATL_pfl1STi(mem, str) \ + __asm__ __volatile__ ("rlwinm %0, %0, 0, 0, 24\n\t" \ + "ori %0, %0, 96+%2\n\t" \ + "dcbt 0, %0, 8" \ + : "=r" (mem) \ + : "0" (mem), "i" (str)) + + #define ATL_GOT_L1PREFETCH + #define ATL_L1LS 128 + #endif +#elif defined(ATL_ARCH_IA64Itan) || defined(ATL_ARCH_IA64Itan2) +/* + * Have to use nt2, 'cause fpu ignored L1. + * NOTE: just let icc to prefetch, keep inst here for reference + */ + #if defined(__ECC) && 0 + #include "ia64intrin.h" + #define ATL_pfl1R(mem) __lfetch(2, (mem)) + #define ATL_pfl1W(mem) __lfetch_excl(2, (mem)) + #define ATL_GOT_L1PREFETCH + #elif defined(__GNUC__) && !defined(__ECC) + #define ATL_pfl1R(mem) \ + __asm__ (" lfetch.nt2 [%0]": : "r"((void *)(mem))) + #define ATL_pfl1W(mem) \ + __asm__ (" lfetch.excl [%0]": : "r"((void *)(mem))) + #define ATL_GOT_L1PREFETCH + #endif +#elif defined(ATL_ARCH_HPPA20) && defined(__GNUC__) + #define ATL_pfl1R(mem) \ + __asm__ __volatile__ ("ldw %0, %%r0" : : "m" (*((char *)(mem)))) + #define ATL_pfl1W(mem) \ + __asm__ __volatile__ ("ldd %0, %%r0" : : "m" (*((char *)(mem)))) + #define ATL_GOT_L1PREFETCH +#elif defined(ATL_AltiVec) && !defined(ATL_pfl1R) + #ifndef ATL_NoFakePF + /* 33619968 is ATL_GetCtrl(0, 1, 2), or fetch 1 32-byte block */ + #define ATL_pfl1R(mem) ATL_pfavR(mem, 33619968, 3) + #define ATL_pfl1W(mem) ATL_pfavW(mem, 33619968, 2) + #define ATL_GOT_L1PREFETCH + #endif +#elif defined(ATL_ARCH_MIPSICE9) && defined(__GNUC__) + #define ATL_pfl1R(mem) \ + __asm__ __volatile__ ("pref 6,%0" : : "m" (*((char *)(mem)))) + #define ATL_pfl1W(mem) \ + __asm__ __volatile__ ("pref 7,%0" : : "m" (*((char *)(mem)))) + #define ATL_GOT_L1PREFETCH + #define ATL_L1LS 32 + #define ATL_L2LS 64 +#elif defined(__GNUC__) /* last ditch, use gcc predefined func */ + #define ATL_pfl1R(mem) __builtin_prefetch(mem, 0, 3) + #define ATL_pfl1W(mem) __builtin_prefetch(mem, 1, 3) + #define ATL_GOT_L1PREFETCH +#endif +#if defined(ATL_pfl1W) && !defined(ATL_pfl1WO) + #define ATL_pfl1WO ATL_pfl1W +#endif + +#ifdef ATL_NOL1PREFETCH + #ifdef ATL_GOT_L1PREFETCH + #undef ATL_pfl1R + #undef ATL_pfl1W + #undef ATL_pfl1WO + #undef ATL_GOT_L1PREFETCH + #endif +#endif +#ifdef ATL_NOL2PREFETCH + #ifdef ATL_GOT_L2PREFETCH + #undef ATL_pfl2R + #undef ATL_pfl2W + #undef ATL_pfl2WO + #undef ATL_GOT_L2PREFETCH + #endif +#endif +#ifndef ATL_GOT_L1PREFETCH /* dummy calls cpp takes out of code */ + #define ATL_pfl1R(mem) + #define ATL_pfl1W(mem) + #define ATL_pfl1WO(mem) +#endif +#ifndef ATL_GOT_L2PREFETCH /* dummy calls cpp takes out of code */ + #define ATL_pfl2R(mem) + #define ATL_pfl2W(mem) +#endif + +/* + * Define Cache line sizes for L1 and L2 + */ +#ifndef ATL_L1LS + #define ATL_L1LS 64 +#endif +#ifndef ATL_L2LS + #define ATL_L2LS ATL_L1LS +#endif + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_ptalias1.h b/kaldi_io/src/tools/ATLAS/include/atlas_ptalias1.h new file mode 100644 index 0000000..2a45eda --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_ptalias1.h @@ -0,0 +1,60 @@ +#define ATLAS_PTALIAS1_H /* no threaded routs for Level 1 and 2 yet */ +#ifndef ATLAS_PTALIAS1_H +#define ATLAS_PTALIAS1_H +/* + * Real BLAS + */ + #define ATL_dsdot ATL_dsptdot + #define ATL_sdsdot ATL_sdsptdot + #define ATL_sasum ATL_sptasum + #define ATL_snrm2 ATL_sptnrm2 + #define ATL_sdot ATL_sptdot + #define ATL_saxpy ATL_sptaxpy + #define ATL_scopy ATL_sptcopy + #define ATL_sscal ATL_sptscal + #define ATL_sswap ATL_sptswap + #define ATL_srotm ATL_sptrotm + #define ATL_srot ATL_sptrot + #define ATL_srotmg ATL_sptrotmg + #define ATL_srotg ATL_sptrotg + #define ATL_isamax ATL_isptamax + + #define ATL_dasum ATL_dptasum + #define ATL_dnrm2 ATL_dptnrm2 + #define ATL_ddot ATL_dptdot + #define ATL_daxpy ATL_dptaxpy + #define ATL_dcopy ATL_dptcopy + #define ATL_dscal ATL_dptscal + #define ATL_dswap ATL_dptswap + #define ATL_drotm ATL_dptrotm + #define ATL_drot ATL_dptrot + #define ATL_drotmg ATL_dptrotmg + #define ATL_drotg ATL_dptrotg + #define ATL_idamax ATL_idptamax + +/* + * Complex BLAS + */ + #define ATL_cdotc_sub ATL_cptdotc_sub + #define ATL_cdotu_sub ATL_cptdotu_sub + #define ATL_caxpy ATL_cptaxpy + #define ATL_ccopy ATL_cptcopy + #define ATL_cscal ATL_cptscal + #define ATL_cswap ATL_cptswap + #define ATL_icamax ATL_icptamax + #define ATL_csscal ATL_csptscal + #define ATL_scnrm2 ATL_scptnrm2 + #define ATL_scasum ATL_scptasum + + #define ATL_zdotc_sub ATL_zptdotc_sub + #define ATL_zdotu_sub ATL_zptdotu_sub + #define ATL_zaxpy ATL_zptaxpy + #define ATL_zcopy ATL_zptcopy + #define ATL_zscal ATL_zptscal + #define ATL_zswap ATL_zptswap + #define ATL_izamax ATL_izptamax + #define ATL_zdscal ATL_zdptscal + #define ATL_dznrm2 ATL_dzptnrm2 + #define ATL_dzasum ATL_dzptasum + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_ptalias2.h b/kaldi_io/src/tools/ATLAS/include/atlas_ptalias2.h new file mode 100644 index 0000000..66b1e0e --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_ptalias2.h @@ -0,0 +1,80 @@ +#define ATLAS_PTALIAS2_H /* no threaded routs for Level 1 and 2 yet */ +#ifndef ATLAS_PTALIAS2_H +#define ATLAS_PTALIAS2_H +/* + * Real BLAS + */ + #define ATL_sspr2 ATL_sptspr2 + #define ATL_ssyr2 ATL_sptsyr2 + #define ATL_sspr ATL_sptspr + #define ATL_ssyr ATL_sptsyr + #define ATL_sger ATL_sptger + #define ATL_stpsv ATL_spttpsv + #define ATL_stbsv ATL_spttbsv + #define ATL_strsv ATL_spttrsv + #define ATL_stpmv ATL_spttpmv + #define ATL_stbmv ATL_spttbmv + #define ATL_strmv ATL_spttrmv + #define ATL_sspmv ATL_sptspmv + #define ATL_ssbmv ATL_sptsbmv + #define ATL_ssymv ATL_sptsymv + #define ATL_sgbmv ATL_sptgbmv + #define ATL_sgemv ATL_sptgemv + + #define ATL_dspr2 ATL_dptspr2 + #define ATL_dsyr2 ATL_dptsyr2 + #define ATL_dspr ATL_dptspr + #define ATL_dsyr ATL_dptsyr + #define ATL_dger ATL_dptger + #define ATL_dtpsv ATL_dpttpsv + #define ATL_dtbsv ATL_dpttbsv + #define ATL_dtrsv ATL_dpttrsv + #define ATL_dtpmv ATL_dpttpmv + #define ATL_dtbmv ATL_dpttbmv + #define ATL_dtrmv ATL_dpttrmv + #define ATL_dspmv ATL_dptspmv + #define ATL_dsbmv ATL_dptsbmv + #define ATL_dsymv ATL_dptsymv + #define ATL_dgbmv ATL_dptgbmv + #define ATL_dgemv ATL_dptgemv + +/* + * Complex BLAS + */ + #define ATL_chpr2 ATL_cpthpr2 + #define ATL_cher2 ATL_cpther2 + #define ATL_chpr ATL_cpthpr + #define ATL_cher ATL_cpther + #define ATL_cgerc ATL_cptgerc + #define ATL_cgeru ATL_cptgeru + #define ATL_ctpsv ATL_cpttpsv + #define ATL_ctbsv ATL_cpttbsv + #define ATL_ctrsv ATL_cpttrsv + #define ATL_ctpmv ATL_cpttpmv + #define ATL_ctbmv ATL_cpttbmv + #define ATL_ctrmv ATL_cpttrmv + #define ATL_chpmv ATL_cpthpmv + #define ATL_chbmv ATL_cpthbmv + #define ATL_chemv ATL_cpthemv + #define ATL_cgbmv ATL_cptgbmv + #define ATL_cgemv ATL_cptgemv + + #define ATL_zhpr2 ATL_zpthpr2 + #define ATL_zher2 ATL_zpther2 + #define ATL_zhpr ATL_zpthpr + #define ATL_zher ATL_zpther + #define ATL_zgerc ATL_zptgerc + #define ATL_zgeru ATL_zptgeru + #define ATL_ztpsv ATL_zpttpsv + #define ATL_ztbsv ATL_zpttbsv + #define ATL_ztrsv ATL_zpttrsv + #define ATL_ztpmv ATL_zpttpmv + #define ATL_ztbmv ATL_zpttbmv + #define ATL_ztrmv ATL_zpttrmv + #define ATL_zhpmv ATL_zpthpmv + #define ATL_zhbmv ATL_zpthbmv + #define ATL_zhemv ATL_zpthemv + #define ATL_zgbmv ATL_zptgbmv + #define ATL_zgemv ATL_zptgemv + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_ptalias3.h b/kaldi_io/src/tools/ATLAS/include/atlas_ptalias3.h new file mode 100644 index 0000000..2a25d23 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_ptalias3.h @@ -0,0 +1,43 @@ +#ifndef ATLAS_PTALIAS3_H +#define ATLAS_PTALIAS3_H +/* + * Real BLAS + */ + #define ATL_strsm ATL_spttrsm + #define ATL_strmm ATL_spttrmm + #define ATL_ssyr2k ATL_sptsyr2k + #define ATL_ssyrk ATL_sptsyrk + #define ATL_ssymm ATL_sptsymm + #define ATL_sgemm ATL_sptgemm + + #define ATL_dtrsm ATL_dpttrsm + #define ATL_dtrmm ATL_dpttrmm + #define ATL_dsyr2k ATL_dptsyr2k + #define ATL_dsyrk ATL_dptsyrk + #define ATL_dsymm ATL_dptsymm + #define ATL_dgemm ATL_dptgemm + +/* + * Complex BLAS + */ + #define ATL_ctrsm ATL_cpttrsm + #define ATL_ctrmm ATL_cpttrmm + #define ATL_cher2k ATL_cpther2k + #define ATL_csyr2k ATL_cptsyr2k + #define ATL_cherk ATL_cptherk + #define ATL_csyrk ATL_cptsyrk + #define ATL_chemm ATL_cpthemm + #define ATL_csymm ATL_cptsymm + #define ATL_cgemm ATL_cptgemm + + #define ATL_ztrsm ATL_zpttrsm + #define ATL_ztrmm ATL_zpttrmm + #define ATL_zher2k ATL_zpther2k + #define ATL_zsyr2k ATL_zptsyr2k + #define ATL_zherk ATL_zptherk + #define ATL_zsyrk ATL_zptsyrk + #define ATL_zhemm ATL_zpthemm + #define ATL_zsymm ATL_zptsymm + #define ATL_zgemm ATL_zptgemm + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_ptlevel3.h b/kaldi_io/src/tools/ATLAS/include/atlas_ptlevel3.h new file mode 100644 index 0000000..d1bded3 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_ptlevel3.h @@ -0,0 +1,284 @@ + +/* --------------------------------------------------------------------- + * + * -- Automatically Tuned Linear Algebra Software (ATLAS) + * (C) Copyright 2000 All Rights Reserved + * + * -- ATLAS routine -- Version 3.2 -- December 25, 2000 + * + * Author : Antoine P. Petitet + * Originally developed at the University of Tennessee, + * Innovative Computing Laboratory, Knoxville TN, 37996-1301, USA. + * + * --------------------------------------------------------------------- + * + * -- Copyright notice and Licensing terms: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in + * the documentation and/or other materials provided with the distri- + * bution. + * 3. The name of the University, the ATLAS group, or the names of its + * contributors may not be used to endorse or promote products deri- + * ved from this software without specific written permission. + * + * -- Disclaimer: + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEO- + * RY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (IN- + * CLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * --------------------------------------------------------------------- + */ +#ifndef ATLAS_PTLEVEL3_H +#define ATLAS_PTLEVEL3_H +/* + * ===================================================================== + * Include files + * ===================================================================== + */ +#include "atlas_enum.h" +#include "atlas_pthreads.h" +/* + * ===================================================================== + * Prototypes for single precision real Level 3 multi-threaded ATLAS + * BLAS routines. + * ===================================================================== + */ +void ATL_sptgeadd +( const int, const int, const float, const float *, + const int, const float, float *, const int ); +void ATL_sptgezero +( const int, const int, float *, const int ); +void ATL_sptgescal +( const int, const int, const float, float *, + const int ); +void ATL_spttrscal +( const enum ATLAS_UPLO, const int, const int, + const float, float *, const int ); + +void ATL_sptgemm +( const enum ATLAS_TRANS, const enum ATLAS_TRANS, + const int, const int, const int, const float, + const float *, const int, const float *, const int, + const float, float *, const int ); +void ATL_sptsymm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const int, const int, const float, const float *, + const int, const float *, const int, const float, + float *, const int ); +void ATL_sptsyrk +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const float, const float *, + const int, const float, float *, const int ); +void ATL_sptsyr2k +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const float, const float *, + const int, const float *, const int, const float, + float *, const int ); +void ATL_spttrmm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const float, const float *, + const int, float *, const int ); +void ATL_spttrsm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const float, const float *, + const int, float *, const int ); +/* + * ===================================================================== + * Prototypes for double precision real Level 3 multi-threaded ATLAS + * BLAS routines. + * ===================================================================== + */ +void ATL_dptgeadd +( const int, const int, const double, const double *, + const int, const double, double *, const int ); +void ATL_dptgezero +( const int, const int, double *, const int ); +void ATL_dptgescal +( const int, const int, const double, double *, + const int ); +void ATL_dpttrscal +( const enum ATLAS_UPLO, const int, const int, + const double, double *, const int ); + +void ATL_dptgemm +( const enum ATLAS_TRANS, const enum ATLAS_TRANS, + const int, const int, const int, const double, + const double *, const int, const double *, const int, + const double, double *, const int ); +void ATL_dptsymm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const int, const int, const double, const double *, + const int, const double *, const int, const double, + double *, const int ); +void ATL_dptsyrk +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const double, const double *, + const int, const double, double *, const int ); +void ATL_dptsyr2k +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const double, const double *, + const int, const double *, const int, const double, + double *, const int ); +void ATL_dpttrmm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const double, const double *, + const int, double *, const int ); +void ATL_dpttrsm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const double, const double *, + const int, double *, const int ); +/* + * ===================================================================== + * Prototypes for single precision complex Level 3 multi-threaded ATLAS + * BLAS routines. + * ===================================================================== + */ +void ATL_cptgeadd +( const int, const int, const float *, const float *, + const int, const float *, float *, const int ); +void ATL_cptgezero +( const int, const int, float *, const int ); +void ATL_cptgescal +( const int, const int, const float *, float *, + const int ); +void ATL_cpttrscal +( const enum ATLAS_UPLO, const int, const int, + const float *, float *, const int ); +void ATL_cpthescal +( const enum ATLAS_UPLO, const int, const int, + const float, float *, const int ); + +void ATL_cptgemm +( const enum ATLAS_TRANS, const enum ATLAS_TRANS, + const int, const int, const int, const float *, + const float *, const int, const float *, const int, + const float *, float *, const int ); +void ATL_cptsymm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const int, const int, const float *, const float *, + const int, const float *, const int, const float *, + float *, const int ); +void ATL_cptsyrk +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const float *, const float *, + const int, const float *, float *, const int ); +void ATL_cptsyr2k +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const float *, const float *, + const int, const float *, const int, const float *, + float *, const int ); +void ATL_cpttrmm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const float *, const float *, + const int, float *, const int ); +void ATL_cpttrsm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const float *, const float *, + const int, float *, const int ); +/* + * ===================================================================== + * Prototypes for double precision complex Level 3 multi-threaded ATLAS + * BLAS routines. + * ===================================================================== + */ +void ATL_zptgeadd +( const int, const int, const double *, const double *, + const int, const double *, double *, const int ); +void ATL_zptgezero +( const int, const int, double *, const int ); +void ATL_zptgescal +( const int, const int, const double *, double *, + const int ); +void ATL_zpttrscal +( const enum ATLAS_UPLO, const int, const int, + const double *, double *, const int ); +void ATL_zpthescal +( const enum ATLAS_UPLO, const int, const int, + const double, double *, const int ); + +void ATL_zptgemm +( const enum ATLAS_TRANS, const enum ATLAS_TRANS, + const int, const int, const int, const double *, + const double *, const int, const double *, const int, + const double *, double *, const int ); +void ATL_zptsymm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const int, const int, const double *, const double *, + const int, const double *, const int, const double *, + double *, const int ); +void ATL_zptsyrk +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const double *, const double *, + const int, const double *, double *, const int ); +void ATL_zptsyr2k +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const double *, const double *, + const int, const double *, const int, const double *, + double *, const int ); +void ATL_zpttrmm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const double *, const double *, + const int, double *, const int ); +void ATL_zpttrsm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const double *, const double *, + const int, double *, const int ); + +void ATL_cpthemm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const int, const int, const float *, const float *, + const int, const float *, const int, const float *, + float *, const int ); +void ATL_cptherk +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const float, const float *, + const int, const float, float *, const int ); +void ATL_cpther2k +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const float *, const float *, + const int, const float *, const int, const float, + float *, const int ); + +void ATL_zpthemm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const int, const int, const double *, const double *, + const int, const double *, const int, const double *, + double *, const int ); +void ATL_zptherk +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const double, const double *, + const int, const double, double *, const int ); +void ATL_zpther2k +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const double *, const double *, + const int, const double *, const int, const double, + double *, const int ); + +#endif +/* + * End of atlas_ptlevel3.h + */ diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_ptlvl3.h b/kaldi_io/src/tools/ATLAS/include/atlas_ptlvl3.h new file mode 100644 index 0000000..916afd0 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_ptlvl3.h @@ -0,0 +1,389 @@ + +/* --------------------------------------------------------------------- + * + * -- Automatically Tuned Linear Algebra Software (ATLAS) + * (C) Copyright 2000 All Rights Reserved + * + * -- ATLAS routine -- Version 3.2 -- December 25, 2000 + * + * Author : Antoine P. Petitet + * Originally developed at the University of Tennessee, + * Innovative Computing Laboratory, Knoxville TN, 37996-1301, USA. + * + * --------------------------------------------------------------------- + * + * -- Copyright notice and Licensing terms: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in + * the documentation and/or other materials provided with the distri- + * bution. + * 3. The name of the University, the ATLAS group, or the names of its + * contributors may not be used to endorse or promote products deri- + * ved from this software without specific written permission. + * + * -- Disclaimer: + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEO- + * RY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (IN- + * CLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * --------------------------------------------------------------------- + */ +#ifndef ATLAS_PTLVL3_H +#define ATLAS_PTLVL3_H +/* + * ===================================================================== + * Include files + * ===================================================================== + */ +#include "atlas_ptmisc.h" +#include "atlas_level3.h" +#include "atlas_rblas3.h" +/* + * ===================================================================== + * macro constants + * ===================================================================== + */ +#ifdef TREAL +#define ATL_XOVER_L3_DEFAULT 8 /* number of NB x NB blocks */ +#else +#define ATL_XOVER_L3_DEFAULT 4 +#endif +/* + * ===================================================================== + * macro functions + * ===================================================================== + */ +#define Mpt3( a_, i_, siz_ ) ( ( (char*)(a_) + ( (i_) * (siz_) ) ) ) +#define Mvpt3( a_, i_, siz_ ) ( (void *)(Mpt3( (a_), (i_), (siz_) ))) +/* + * ===================================================================== + * typedef definitions + * ===================================================================== + */ +typedef PT_TREE_T (*PT_GEMM_FUN_T) +( + const unsigned int, pthread_attr_t *, + const enum ATLAS_TRANS, const enum ATLAS_TRANS, + const int, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int +); + +typedef PT_TREE_T (*PT_TRMM_FUN_T) +( + const unsigned int, pthread_attr_t *, + const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const void *, const void *, + const int, void *, const int +); + +typedef int (*PT_SYR2K_FUN_T) +( + const unsigned int, pthread_attr_t *, + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_TRANS, const int, const int, + const void *, const void *, const int, const void *, + const int, const void *, void *, const int +); + + +typedef struct +{ + size_t size; + void * negone, * one, * zero; + PT_FUN_T geadd0, gemm0, symm0, hemm0, syrk0, syr2k0, + herk0, her2k0, trmm0, trsm0; + PT_GEMM_FUN_T ptgemm; + PT_TRMM_FUN_T pttrmm; + PT_SYR2K_FUN_T ptsyr2k0, pther2k0; +} PT_LVL3_TYPE_T; + +typedef struct +{ + const void * a, * al, * b, * be; + void * c; + enum ATLAS_TRANS ta, tb; + int k, la, lb, lc, m, n; +} PT_GEMM_ARGS_T; + +typedef struct +{ + const void * a, * al, * b, * be; + void * c; + enum ATLAS_SIDE si; + enum ATLAS_UPLO up; + int la, lb, lc, m, n; +} PT_SYMM_ARGS_T; + +typedef struct +{ + const void * a, * al, * be; + void * c; + enum ATLAS_UPLO up; + enum ATLAS_TRANS tr; + int l, la, lc, m, n, k; +} PT_SYRK_ARGS_T; + +typedef struct +{ + const void * a, * al, * ac, * b, * be; + void * c; + enum ATLAS_UPLO up; + enum ATLAS_TRANS tr; + int l, la, lb, lc, m, n, k; +} PT_SYR2K_ARGS_T; + +typedef struct +{ + const void * a, * al; + void * b; + enum ATLAS_SIDE si; + enum ATLAS_UPLO up; + enum ATLAS_TRANS tr; + enum ATLAS_DIAG di; + int la, lb, m, n; +} PT_TRMM_ARGS_T; + +typedef struct +{ + const void * a, * al; + void * b; + enum ATLAS_SIDE si; + enum ATLAS_UPLO up; + enum ATLAS_TRANS tr; + enum ATLAS_DIAG di; + int la, lb, m, n; +} PT_TRSM_ARGS_T; + +/* + * ===================================================================== + * Function prototypes + * ===================================================================== + */ +PT_TREE_T ATL_Sgemm +( const PT_LVL3_TYPE_T *, const unsigned int, + const unsigned int, pthread_attr_t *, const int, + const enum ATLAS_TRANS, const enum ATLAS_TRANS, + const int, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int ); +PT_TREE_T ATL_Ssymm +( const PT_LVL3_TYPE_T *, const unsigned int, + const unsigned int, pthread_attr_t *, const int, + const enum ATLAS_TRANS, const enum ATLAS_SIDE, + const enum ATLAS_UPLO, const int, const int, + const void *, const void *, const int, const void *, + const int, const void *, void *, const int ); +PT_TREE_T ATL_Ssyrk +( const PT_LVL3_TYPE_T *, const unsigned int, + const unsigned int, pthread_attr_t *, const int, + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_TRANS, const int, const int, + const int, const int, const void *, const void *, + const int, const void *, void *, const int ); +PT_TREE_T ATL_Ssyr2k +( const PT_LVL3_TYPE_T *, const unsigned int, + const unsigned int, pthread_attr_t *, const int, + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_TRANS, const int, const int, + const int, const int, const void *, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int ); +PT_TREE_T ATL_Strmm +( const PT_LVL3_TYPE_T *, const unsigned int, + const unsigned int, pthread_attr_t *, const int, + const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const void *, const void *, + const int, void *, const int ); +PT_TREE_T ATL_Strsm +( const PT_LVL3_TYPE_T *, const unsigned int, + const unsigned int, pthread_attr_t *, const int, + const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const void *, const void *, + const int, void *, const int ); + +#if defined( TREAL ) || defined( TCPLX ) + +int Mjoin( PATL, GetNB ) ( void ); + +void Mjoin( PATL, ptl3settype ) ( PT_LVL3_TYPE_T * ); + +void Mjoin( PATL, gemmNN ) +( const int, const int, const int, const SCALAR, + const TYPE *, const int, const TYPE *, const int, + const SCALAR, TYPE *, const int ); +void Mjoin( PATL, gemmNT ) +( const int, const int, const int, const SCALAR, + const TYPE *, const int, const TYPE *, const int, + const SCALAR, TYPE *, const int ); +void Mjoin( PATL, gemmTN ) +( const int, const int, const int, const SCALAR, + const TYPE *, const int, const TYPE *, const int, + const SCALAR, TYPE *, const int ); + +#if defined( TCPLX ) +void Mjoin( PATL, gemmNC ) +( const int, const int, const int, const SCALAR, + const TYPE *, const int, const TYPE *, const int, + const SCALAR, TYPE *, const int ); +void Mjoin( PATL, gemmCN ) +( const int, const int, const int, const SCALAR, + const TYPE *, const int, const TYPE *, const int, + const SCALAR, TYPE *, const int ); +#endif + +PT_FUN_ARG_T Mjoin( PATL, ptgemm0 ) ( PT_FUN_ARG_T ); +PT_FUN_ARG_T Mjoin( PATL, ptsymm0 ) ( PT_FUN_ARG_T ); +PT_FUN_ARG_T Mjoin( PATL, ptsyr2k0 ) ( PT_FUN_ARG_T ); +PT_FUN_ARG_T Mjoin( PATL, ptsyrk0 ) ( PT_FUN_ARG_T ); +PT_FUN_ARG_T Mjoin( PATL, pttrmm0 ) ( PT_FUN_ARG_T ); +PT_FUN_ARG_T Mjoin( PATL, pttrsm0 ) ( PT_FUN_ARG_T ); + +#if defined( TCPLX ) +PT_FUN_ARG_T Mjoin( PATL, pthemm0 ) ( PT_FUN_ARG_T ); +PT_FUN_ARG_T Mjoin( PATL, pther2k0 ) ( PT_FUN_ARG_T ); +PT_FUN_ARG_T Mjoin( PATL, ptherk0 ) ( PT_FUN_ARG_T ); +#endif +/* + * ===================================================================== + * Prototypes for the Level 3 multi-threaded ATLAS BLAS routines + * ===================================================================== + */ +PT_TREE_T Mjoin( PATL, ptgemm_nt ) +( const unsigned int, pthread_attr_t *, + const enum ATLAS_TRANS, const enum ATLAS_TRANS, + const int, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int ); +PT_TREE_T Mjoin( PATL, ptsymm_nt ) +( const unsigned int, pthread_attr_t *, + const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const int, const int, const void *, const void *, + const int, const void *, const int, const void *, + void *, const int ); +PT_TREE_T Mjoin( PATL, ptsyr2k_nt ) +( const unsigned int, pthread_attr_t *, + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const void *, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int ); +int Mjoin( PATL, ptsyr2k0_nt ) +( const unsigned int, pthread_attr_t *, + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_TRANS, const int, const int, + const void *, const void *, const int, const void *, + const int, const void *, void *, const int ); +PT_TREE_T Mjoin( PATL, ptsyrk_nt ) +( const unsigned int, pthread_attr_t *, + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const void *, const void *, + const int, const void *, void *, const int ); +PT_TREE_T Mjoin( PATL, pttrmm_nt ) +( const unsigned int, pthread_attr_t *, + const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const void *, const void *, + const int, void *, const int ); +PT_TREE_T Mjoin( PATL, pttrsm_nt ) +( const unsigned int, pthread_attr_t *, + const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const void *, const void *, + const int, void *, const int ); + +void Mjoin( PATL, ptgemm ) +( const enum ATLAS_TRANS, const enum ATLAS_TRANS, + const int, const int, const int, const SCALAR, + const TYPE *, const int, const TYPE *, const int, + const SCALAR, TYPE *, const int ); +void Mjoin( PATL, ptsymm ) +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const int, const int, const SCALAR, const TYPE *, + const int, const TYPE *, const int, const SCALAR, + TYPE *, const int ); +void Mjoin( PATL, ptsyr2k ) +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const SCALAR, const TYPE *, + const int, const TYPE *, const int, const SCALAR, + TYPE *, const int ); +void Mjoin( PATL, ptsyrk ) +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const SCALAR, const TYPE *, + const int, const SCALAR, TYPE *, const int ); +void Mjoin( PATL, pttrmm ) +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const SCALAR, const TYPE *, + const int, TYPE *, const int ); +void Mjoin( PATL, pttrsm ) +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const SCALAR, const TYPE *, + const int, TYPE *, const int ); + +#if defined( TCPLX ) +PT_TREE_T Mjoin( PATL, pthemm_nt ) +( const unsigned int, pthread_attr_t *, + const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const int, const int, const void *, const void *, + const int, const void *, const int, const void *, + void *, const int ); +PT_TREE_T Mjoin( PATL, pther2k_nt ) +( const unsigned int, pthread_attr_t *, + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const void *, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int ); +int Mjoin( PATL, pther2k0_nt ) +( const unsigned int, pthread_attr_t *, + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_TRANS, const int, const int, + const void *, const void *, const int, const void *, + const int, const void *, void *, const int ); +PT_TREE_T Mjoin( PATL, ptherk_nt ) +( const unsigned int, pthread_attr_t *, + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const void *, const void *, + const int, const void *, void *, const int ); + +void Mjoin( PATL, pthemm ) +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const int, const int, const SCALAR, const TYPE *, + const int, const TYPE *, const int, const SCALAR, + TYPE *, const int ); +void Mjoin( PATL, pther2k ) +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const SCALAR, const TYPE *, + const int, const TYPE *, const int, const TYPE, + TYPE *, const int ); +void Mjoin( PATL, ptherk ) +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const TYPE, const TYPE *, + const int, const TYPE, TYPE *, const int ); +#endif + +#endif + +#endif +/* + * End of atlas_ptlvl3.h + */ diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_ptmisc.h b/kaldi_io/src/tools/ATLAS/include/atlas_ptmisc.h new file mode 100644 index 0000000..4c3db23 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_ptmisc.h @@ -0,0 +1,410 @@ +/* --------------------------------------------------------------------- + * + * -- Automatically Tuned Linear Algebra Software (ATLAS) + * (C) Copyright 2000 All Rights Reserved + * + * -- ATLAS routine -- Version 3.2 -- December 25, 2000 + * + * Author : Antoine P. Petitet + * Originally developed at the University of Tennessee, + * Innovative Computing Laboratory, Knoxville TN, 37996-1301, USA. + * + * --------------------------------------------------------------------- + * + * -- Copyright notice and Licensing terms: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in + * the documentation and/or other materials provided with the distri- + * bution. + * 3. The name of the University, the ATLAS group, or the names of its + * contributors may not be used to endorse or promote products deri- + * ved from this software without specific written permission. + * + * -- Disclaimer: + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEO- + * RY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (IN- + * CLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * --------------------------------------------------------------------- + */ +#ifndef ATLAS_PTMISC_H +#define ATLAS_PTMISC_H +/* + * ===================================================================== + * Include Files + * ===================================================================== + */ +#include +#include + +#include "atlas_misc.h" +#include "atlas_pthreads.h" +/* + * ===================================================================== + * #define macro constants + * ===================================================================== + * + * ATL_XOVER_MI_DEFAULT is the smallest number of NB-by-NB blocks for + * which threading is enabled, where NB is the value returned by the + * ATLAS function Mjoin( PATL, GetNB ). + */ +#ifdef TREAL +#define ATL_XOVER_MI_DEFAULT 8 /* number of NB x NB blocks */ +#else +#define ATL_XOVER_MI_DEFAULT 4 +#endif + +#define NOSPLIT 0 /* For convenience */ +#define SPLIT_M 1 +#define SPLIT_N 2 +#define SPLIT_K 3 + +/* + * ===================================================================== + * macro functions + * ===================================================================== + */ +#define Mptm( a_, i_, siz_ ) ( ( (char*)(a_) + ( (i_) * (siz_) ) ) ) +#define Mvptm( a_, i_, siz_ ) ( (void *)(Mptm( (a_), (i_), (siz_) ))) +/* + * ===================================================================== + * typedef definitions + * ===================================================================== + * + * Definition of the Binary (recursive) task tree: Each node of the tree + * mainly consist a node number, a reference counter to enforce depen- + * dencies, a argument structure and a function to be applied. + */ +typedef void * PT_DATA_T; +typedef void * PT_FUN_VAL_T; +typedef void * PT_FUN_ARG_T; +typedef PT_FUN_VAL_T (*PT_FUN_T) ( PT_FUN_ARG_T ); + +typedef struct PT_node_T +{ + pthread_t pid; + pthread_mutex_t mutex; + pthread_cond_t cond; + struct PT_node_T * left; + struct PT_node_T * right; + PT_DATA_T data; + PT_FUN_VAL_T * val; + PT_FUN_T fun; + PT_FUN_ARG_T arg; + unsigned int node; + unsigned int count; +} PT_NODE_T; + +typedef PT_NODE_T * PT_TREE_T; +typedef void (*PT_APPLY_FUN_T)( PT_TREE_T ); + +enum DIM_1DSPLIT_E +{ + Atlas1dSplit = 100, + Atlas1dNoSplit = 199 +}; + +enum DIM_TZSPLIT_E +{ + AtlasTzSplitMrow = 200, + AtlasTzSplitKrow = 201, + AtlasTzSplitKcol = 202, + AtlasTzSplitNcol = 203, + AtlasTzNoSplit = 299 +}; + +typedef enum DIM_1DSPLIT_E DIM_1DSPLIT_T; +typedef enum DIM_TZSPLIT_E DIM_TZSPLIT_T; + +/* + * Type definitions for some auxiliaries that have been multi-threaded + * as well. + */ +typedef struct +{ + size_t size; + PT_FUN_T fun; +} PT_MISC_TYPE_T; + +typedef struct +{ + const void * al, * be; + const void * a; + void * c; + int la, lc, m, n; +} PT_GEADD_ARGS_T; + +typedef struct +{ + void * a; + int la, m, n; +} PT_GEZERO_ARGS_T; + +typedef struct +{ + const void * al; + void * a; + int la, m, n; +} PT_GESCAL_ARGS_T; + +typedef struct +{ + enum ATLAS_UPLO up; + const void * al; + void * a; + int k, la, m, n; +} PT_TZSCAL_ARGS_T; + +/* + * ===================================================================== + * Function prototypes + * ===================================================================== + */ +int ATL_sGetNB ( void ); +int ATL_dGetNB ( void ); +int ATL_cGetNB ( void ); +int ATL_zGetNB ( void ); + +DIM_1DSPLIT_T ATL_1dsplit +( + const unsigned int, + const int, + const int, + unsigned int *, + unsigned int *, + int *, + int *, + double * +); + +DIM_TZSPLIT_T ATL_tzsplit +( + const enum ATLAS_UPLO, + const unsigned int, + const int, + const int, + const int, + const int, + unsigned int *, + unsigned int *, + int *, + int * +); +/* + * Task tree management + */ +PT_TREE_T ATL_init_node +( unsigned int, PT_TREE_T, PT_TREE_T, PT_DATA_T, + PT_FUN_VAL_T *, PT_FUN_T, PT_FUN_ARG_T ); + +void ATL_traverse_tree ( PT_TREE_T ); +void ATL_apply_tree ( PT_TREE_T, PT_APPLY_FUN_T ); +void ATL_free_tree ( PT_TREE_T ); +void ATL_free_node ( PT_TREE_T ); +void ATL_print_node_id ( PT_TREE_T ); + +void ATL_thread_init ( pthread_attr_t * ); +void ATL_thread_exit ( pthread_attr_t * ); +void ATL_wait_tree ( PT_TREE_T ); +void ATL_signal_tree ( PT_TREE_T ); +void ATL_thread_tree ( PT_TREE_T, pthread_attr_t * ); +void ATL_join_tree ( PT_TREE_T ); + +PT_TREE_T ATL_create_tree +( unsigned int *, const int, const int ); +/* + * Typeless auxiliary functions + */ +PT_TREE_T ATL_Sgeadd +( const PT_MISC_TYPE_T *, const unsigned int, + const unsigned int, pthread_attr_t *, const int, + const int, const int, const void *, const void *, + const int, const void *, void *, const int ); +PT_TREE_T ATL_Sgescal +( const PT_MISC_TYPE_T *, const unsigned int, + const unsigned int, pthread_attr_t *, const int, + const int, const int, const void *, void *, + const int ); +PT_TREE_T ATL_Sgezero +( const PT_MISC_TYPE_T *, const unsigned int, + const unsigned int, pthread_attr_t *, const int, + const int, const int, void *, const int ); +PT_TREE_T ATL_Stzscal +( const PT_MISC_TYPE_T *, const unsigned int, + const unsigned int, pthread_attr_t *, const int, + const enum ATLAS_UPLO, const int, const int, + const int, const void *, void *, const int ); +/* + * Single precision real auxiliary functions + */ +PT_FUN_ARG_T ATL_sptgeadd0 ( PT_FUN_ARG_T ); +PT_FUN_ARG_T ATL_sptgescal0 ( PT_FUN_ARG_T ); +PT_FUN_ARG_T ATL_sptgezero0 ( PT_FUN_ARG_T ); +PT_FUN_ARG_T ATL_spttzscal0 ( PT_FUN_ARG_T ); + +PT_TREE_T ATL_sptgeadd_nt +( const unsigned int, pthread_attr_t *, const int, + const int, const void *, const void *, const int, + const void *, void *, const int ); +PT_TREE_T ATL_sptgescal_nt +( const unsigned int, pthread_attr_t *, const int, + const int, const void *, void *, const int ); +PT_TREE_T ATL_sptgezero_nt +( const unsigned int, pthread_attr_t *, const int, + const int, void *, const int ); +PT_TREE_T ATL_spttrscal_nt +( const unsigned int, pthread_attr_t *, + const enum ATLAS_UPLO, const int, const int, + const void *, void *, const int ); + +void ATL_sptgeadd +( const int, const int, const float, const float *, + const int, const float, float *, const int ); +void ATL_sptgescal +( const int, const int, const float, float *, + const int ); +void ATL_sptgezero +( const int, const int, float *, const int ); +void ATL_spttrscal +( const enum ATLAS_UPLO, const int, const int, + const float, float *, const int ); + +/* + * Double precision real auxiliary functions + */ +PT_FUN_ARG_T ATL_dptgeadd0 ( PT_FUN_ARG_T ); +PT_FUN_ARG_T ATL_dptgescal0 ( PT_FUN_ARG_T ); +PT_FUN_ARG_T ATL_dptgezero0 ( PT_FUN_ARG_T ); +PT_FUN_ARG_T ATL_dpttzscal0 ( PT_FUN_ARG_T ); + +PT_TREE_T ATL_dptgeadd_nt +( const unsigned int, pthread_attr_t *, const int, + const int, const void *, const void *, const int, + const void *, void *, const int ); +PT_TREE_T ATL_dptgescal_nt +( const unsigned int, pthread_attr_t *, const int, + const int, const void *, void *, const int ); +PT_TREE_T ATL_dptgezero_nt +( const unsigned int, pthread_attr_t *, const int, + const int, void *, const int ); +PT_TREE_T ATL_dpttrscal_nt +( const unsigned int, pthread_attr_t *, + const enum ATLAS_UPLO, const int, const int, + const void *, void *, const int ); + +void ATL_dptgeadd +( const int, const int, const double, const double *, + const int, const double, double *, const int ); +void ATL_dptgescal +( const int, const int, const double, double *, + const int ); +void ATL_dptgezero +( const int, const int, double *, const int ); +void ATL_dpttrscal +( const enum ATLAS_UPLO, const int, const int, + const double, double *, const int ); +/* + * Single precision complex auxiliary functions + */ +PT_FUN_ARG_T ATL_cptgeadd0 ( PT_FUN_ARG_T ); +PT_FUN_ARG_T ATL_cptgescal0 ( PT_FUN_ARG_T ); +PT_FUN_ARG_T ATL_cptgezero0 ( PT_FUN_ARG_T ); +PT_FUN_ARG_T ATL_cpthescal0 ( PT_FUN_ARG_T ); +PT_FUN_ARG_T ATL_cpttzscal0 ( PT_FUN_ARG_T ); + +PT_TREE_T ATL_cptgeadd_nt +( const unsigned int, pthread_attr_t *, const int, + const int, const void *, const void *, const int, + const void *, void *, const int ); +PT_TREE_T ATL_cptgescal_nt +( const unsigned int, pthread_attr_t *, const int, + const int, const void *, void *, const int ); +PT_TREE_T ATL_cptgezero_nt +( const unsigned int, pthread_attr_t *, const int, + const int, void *, const int ); +PT_TREE_T ATL_cpttrscal_nt +( const unsigned int, pthread_attr_t *, + const enum ATLAS_UPLO, const int, const int, + const void *, void *, const int ); +PT_TREE_T ATL_cpthescal_nt +( const unsigned int, pthread_attr_t *, + const enum ATLAS_UPLO, const int, const int, + const void *, void *, const int ); + +void ATL_cptgeadd +( const int, const int, const float *, const float *, + const int, const float *, float *, const int ); +void ATL_cptgezero +( const int, const int, float *, const int ); +void ATL_cptgescal +( const int, const int, const float *, float *, + const int ); +void ATL_cpttrscal +( const enum ATLAS_UPLO, const int, const int, + const float *, float *, const int ); +void ATL_cpthescal +( const enum ATLAS_UPLO, const int, const int, + const float, float *, const int ); +/* + * Double precision complex auxiliary functions + */ +PT_FUN_ARG_T ATL_zptgeadd0 ( PT_FUN_ARG_T ); +PT_FUN_ARG_T ATL_zptgescal0 ( PT_FUN_ARG_T ); +PT_FUN_ARG_T ATL_zptgezero0 ( PT_FUN_ARG_T ); +PT_FUN_ARG_T ATL_zpthescal0 ( PT_FUN_ARG_T ); +PT_FUN_ARG_T ATL_zpttzscal0 ( PT_FUN_ARG_T ); + +PT_TREE_T ATL_zptgeadd_nt +( const unsigned int, pthread_attr_t *, const int, + const int, const void *, const void *, const int, + const void *, void *, const int ); +PT_TREE_T ATL_zptgescal_nt +( const unsigned int, pthread_attr_t *, const int, + const int, const void *, void *, const int ); +PT_TREE_T ATL_zptgezero_nt +( const unsigned int, pthread_attr_t *, const int, + const int, void *, const int ); +PT_TREE_T ATL_zpttrscal_nt +( const unsigned int, pthread_attr_t *, + const enum ATLAS_UPLO, const int, const int, + const void *, void *, const int ); +PT_TREE_T ATL_zpthescal_nt +( const unsigned int, pthread_attr_t *, + const enum ATLAS_UPLO, const int, const int, + const void *, void *, const int ); + +void ATL_zptgeadd +( const int, const int, const double *, const double *, + const int, const double *, double *, const int ); +void ATL_zptgezero +( const int, const int, double *, const int ); +void ATL_zptgescal +( const int, const int, const double *, double *, + const int ); +void ATL_zpttrscal +( const enum ATLAS_UPLO, const int, const int, + const double *, double *, const int ); +void ATL_zpthescal +( const enum ATLAS_UPLO, const int, const int, + const double, double *, const int ); + +#endif +/* + * End of atlas_ptmisc.h + */ diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_r1.h b/kaldi_io/src/tools/ATLAS/include/atlas_r1.h new file mode 100644 index 0000000..dc49fe2 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_r1.h @@ -0,0 +1,39 @@ +/* + * Automatically Tuned Linear Algebra Software v3.8.3 + * (C) Copyright 1999 R. Clint Whaley + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the ATLAS group or the names of its contributers may + * not be used to endorse or promote products derived from this + * software without specific written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifdef SREAL + #include "atlas_sr1.h" +#elif defined(DREAL) + #include "atlas_dr1.h" +#elif defined(SCPLX) + #include "atlas_cr1.h" +#elif defined(DCPLX) + #include "atlas_zr1.h" +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_rblas3.h b/kaldi_io/src/tools/ATLAS/include/atlas_rblas3.h new file mode 100644 index 0000000..9ad27e7 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_rblas3.h @@ -0,0 +1,474 @@ +/* --------------------------------------------------------------------- + * + * -- Automatically Tuned Linear Algebra Software (ATLAS) + * (C) Copyright 2000 All Rights Reserved + * + * -- ATLAS routine -- Version 3.2 -- December 25, 2000 + * + * Author : Antoine P. Petitet + * Contributor(s) : R. Clint Whaley + * Originally developed at the University of Tennessee, + * Innovative Computing Laboratory, Knoxville TN, 37996-1301, USA. + * + * --------------------------------------------------------------------- + * + * -- Copyright notice and Licensing terms: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in + * the documentation and/or other materials provided with the distri- + * bution. + * 3. The name of the University, the ATLAS group, or the names of its + * contributors may not be used to endorse or promote products deri- + * ved from this software without specific written permission. + * + * -- Disclaimer: + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEO- + * RY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (IN- + * CLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * --------------------------------------------------------------------- + */ +#ifndef ATLAS_RBLAS3_H +#define ATLAS_RBLAS3_H +/* + * ===================================================================== + * Include files + * ===================================================================== + */ +#include "atlas_misc.h" +/* + * ===================================================================== + * #define macros definitions + * ===================================================================== + */ +#define Mrc3( a_, i_, j_, lda_, siz_ ) \ + ( (void*) ( (char*)(a_) + ( ( (i_)+(j_)*(lda_) )*(siz_) ) ) ) +/* + * ===================================================================== + * #typedef definitions + * ===================================================================== + */ +typedef void (*KR3_FUN_GEMM_T) +( const int, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int ); +typedef void (*KR3_FUN_HEMM_T) +( const int, const int, const void *, const void *, + const int, const void *, const int, const void *, + void *, const int ); +typedef int (*KR3_FUN_HER2K_T) +( const int, const int, const void *, const void *, + const int, const void *, const int, const void *, + void *, const int ); +typedef void (*KR3_FUN_HERK_T) +( const int, const int, const void *, const void *, + const int, const void *, void *, const int ); +typedef void (*KR3_FUN_SYMM_T) +( const int, const int, const void *, const void *, + const int, const void *, const int, const void *, + void *, const int ); +typedef int (*KR3_FUN_SYR2K_T) +( const int, const int, const void *, const void *, + const int, const void *, const int, const void *, + void *, const int ); +typedef void (*KR3_FUN_SYRK_T) +( const int, const int, const void *, const void *, + const int, const void *, void *, const int ); +typedef void (*KR3_FUN_TRMM_T) +( const int, const int, const void *, const void *, + const int, void *, const int ); +typedef void (*KR3_FUN_TRSM_T) +( const int, const int, const void *, const void *, + const int, void *, const int ); + +typedef struct +{ + size_t size; + void * one; + KR3_FUN_GEMM_T TgemmNN; + KR3_FUN_GEMM_T Tgemm; + KR3_FUN_SYMM_T Tsymm; +} RC3_SYMM_T; + +typedef struct +{ + size_t size; + void * one; + KR3_FUN_GEMM_T TgemmNN; + KR3_FUN_GEMM_T Tgemm; + KR3_FUN_HEMM_T Themm; +} RC3_HEMM_T; + +typedef struct +{ + size_t size; + KR3_FUN_GEMM_T Tgemm; + KR3_FUN_SYRK_T Tsyrk; +} RC3_SYRK_T; + +typedef struct +{ + size_t size; + KR3_FUN_GEMM_T Tgemm; + KR3_FUN_HERK_T Therk; +} RC3_HERK_T; + +typedef struct +{ + size_t size; + void * one; + KR3_FUN_GEMM_T Tgemm; + KR3_FUN_SYR2K_T Tsyr2k; +} RC3_SYR2K_T; + +typedef struct +{ + size_t size; + void * one; + KR3_FUN_GEMM_T Tgemm; + KR3_FUN_HER2K_T Ther2k; +} RC3_HER2K_T; + +typedef struct +{ + size_t size; + void * one; + KR3_FUN_GEMM_T Tgemm; + KR3_FUN_TRMM_T Ttrmm; +} RC3_TRMM_T; + +typedef struct +{ + size_t size; + void * one, * negone; + KR3_FUN_GEMM_T Tgemm; + KR3_FUN_TRSM_T Ttrsm; +} RC3_TRSM_T; + +typedef void (*RC3_FUN_HEMM_T) +( RC3_HEMM_T *, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int, const int ); +typedef void (*RC3_FUN_HER2K_T) +( RC3_HER2K_T *, const int, const int, const void *, + const void *, const void *, const int, const void *, + const int, const void *, void *, const int, + const int ); +typedef void (*RC3_FUN_HERK_T) +( RC3_HERK_T *, const int, const int, const void *, + const void *, const int, const void *, void *, + const int, const int ); +typedef void (*RC3_FUN_SYMM_T) +( RC3_SYMM_T *, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int, const int ); +typedef void (*RC3_FUN_SYR2K_T) +( RC3_SYR2K_T *, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int, const int ); +typedef void (*RC3_FUN_SYRK_T) +( RC3_SYRK_T *, const int, const int, const void *, + const void *, const int, const void *, void *, + const int, const int ); +typedef void (*RC3_FUN_TRMM_T) +( RC3_TRMM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +typedef void (*RC3_FUN_TRSM_T) +( RC3_TRSM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +/* + * ===================================================================== + * Level 3 recursive BLAS internal function prototypes + * ===================================================================== + */ +void ATL_sgemmTN_RB +( const int, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int ); +void ATL_sgemmNT_RB +( const int, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int ); +void ATL_sgemmNN_RB +( const int, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int ); +void ATL_dgemmTN_RB +( const int, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int ); +void ATL_dgemmNT_RB +( const int, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int ); +void ATL_dgemmNN_RB +( const int, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int ); +void ATL_cgemmCN_RB +( const int, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int ); +void ATL_cgemmNC_RB +( const int, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int ); +void ATL_cgemmTN_RB +( const int, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int ); +void ATL_cgemmNT_RB +( const int, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int ); +void ATL_cgemmNN_RB +( const int, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int ); +void ATL_zgemmCN_RB +( const int, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int ); +void ATL_zgemmNC_RB +( const int, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int ); +void ATL_zgemmTN_RB +( const int, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int ); +void ATL_zgemmNT_RB +( const int, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int ); +void ATL_zgemmNN_RB +( const int, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int ); +/* + * ===================================================================== + * Recursive BLAS function prototypes + * ===================================================================== + */ +void ATL_rsymmRU +( RC3_SYMM_T *, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int, const int ); +void ATL_rhemmRU +( RC3_HEMM_T *, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int, const int ); +void ATL_rsymmRL +( RC3_SYMM_T *, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int, const int ); +void ATL_rhemmRL +( RC3_HEMM_T *, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int, const int ); +void ATL_rsymmLU +( RC3_SYMM_T *, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int, const int ); +void ATL_rhemmLU +( RC3_HEMM_T *, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int, const int ); +void ATL_rsymmLL +( RC3_SYMM_T *, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int, const int ); +void ATL_rhemmLL +( RC3_HEMM_T *, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int, const int ); + +void ATL_rsyrkUT +( RC3_SYRK_T *, const int, const int, const void *, + const void *, const int, const void *, void *, + const int, const int ); +void ATL_rsyr2kUT +( RC3_SYR2K_T *, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int, const int ); +void ATL_rsyrkUN +( RC3_SYRK_T *, const int, const int, const void *, + const void *, const int, const void *, void *, + const int, const int ); +void ATL_rsyr2kUN +( RC3_SYR2K_T *, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int, const int ); +void ATL_rsyrkLT +( RC3_SYRK_T *, const int, const int, const void *, + const void *, const int, const void *, void *, + const int, const int ); +void ATL_rsyr2kLT +( RC3_SYR2K_T *, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int, const int ); +void ATL_rsyrkLN +( RC3_SYRK_T *, const int, const int, const void *, + const void *, const int, const void *, void *, + const int, const int ); +void ATL_rsyr2kLN +( RC3_SYR2K_T *, const int, const int, const void *, + const void *, const int, const void *, const int, + const void *, void *, const int, const int ); + +void ATL_rherkUC +( RC3_HERK_T *, const int, const int, const void *, + const void *, const int, const void *, void *, + const int, const int ); +void ATL_rher2kUC +( RC3_HER2K_T *, const int, const int, const void *, + const void *, const void *, const int, const void *, + const int, const void *, void *, const int, + const int ); +void ATL_rherkUN +( RC3_HERK_T *, const int, const int, const void *, + const void *, const int, const void *, void *, + const int, const int ); +void ATL_rher2kUN +( RC3_HER2K_T *, const int, const int, const void *, + const void *, const void *, const int, const void *, + const int, const void *, void *, const int, + const int ); +void ATL_rherkLC +( RC3_HERK_T *, const int, const int, const void *, + const void *, const int, const void *, void *, + const int, const int ); +void ATL_rher2kLC +( RC3_HER2K_T *, const int, const int, const void *, + const void *, const void *, const int, const void *, + const int, const void *, void *, const int, + const int ); +void ATL_rherkLN +( RC3_HERK_T *, const int, const int, const void *, + const void *, const int, const void *, void *, + const int, const int ); +void ATL_rher2kLN +( RC3_HER2K_T *, const int, const int, const void *, + const void *, const void *, const int, const void *, + const int, const void *, void *, const int, + const int ); + +void ATL_rtrmmRUC +( RC3_TRMM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrsmRUC +( RC3_TRSM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrmmRLC +( RC3_TRMM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrsmRLC +( RC3_TRSM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrmmRUT +( RC3_TRMM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrsmRUT +( RC3_TRSM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrmmRLT +( RC3_TRMM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrsmRLT +( RC3_TRSM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrmmRUN +( RC3_TRMM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrsmRUN +( RC3_TRSM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrmmRLN +( RC3_TRMM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrsmRLN +( RC3_TRSM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrmmLUC +( RC3_TRMM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrsmLUC +( RC3_TRSM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrmmLLC +( RC3_TRMM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrsmLLC +( RC3_TRSM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrmmLUT +( RC3_TRMM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrsmLUT +( RC3_TRSM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrmmLLT +( RC3_TRMM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrsmLLT +( RC3_TRSM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrmmLUN +( RC3_TRMM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrsmLUN +( RC3_TRSM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrmmLLN +( RC3_TRMM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); +void ATL_rtrsmLLN +( RC3_TRSM_T *, const int, const int, const void *, + const void *, const int, void *, const int, + const int ); + +#endif +/* + * End of atlas_rblas3.h + */ diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_refalias1.h b/kaldi_io/src/tools/ATLAS/include/atlas_refalias1.h new file mode 100644 index 0000000..7dcac8a --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_refalias1.h @@ -0,0 +1,59 @@ +#ifndef ATLAS_REFALIAS1_H +#define ATLAS_REFALIAS1_H +/* + * Real BLAS + */ + #define ATL_dsdot ATL_dsrefdot + #define ATL_sdsdot ATL_sdsrefdot + #define ATL_sasum ATL_srefasum + #define ATL_snrm2 ATL_srefnrm2 + #define ATL_sdot ATL_srefdot + #define ATL_saxpy ATL_srefaxpy + #define ATL_scopy ATL_srefcopy + #define ATL_sscal ATL_srefscal + #define ATL_sswap ATL_srefswap + #define ATL_srotm ATL_srefrotm + #define ATL_srot ATL_srefrot + #define ATL_srotmg ATL_srefrotmg + #define ATL_srotg ATL_srefrotg + #define ATL_isamax ATL_isrefamax + + #define ATL_dasum ATL_drefasum + #define ATL_dnrm2 ATL_drefnrm2 + #define ATL_ddot ATL_drefdot + #define ATL_daxpy ATL_drefaxpy + #define ATL_dcopy ATL_drefcopy + #define ATL_dscal ATL_drefscal + #define ATL_dswap ATL_drefswap + #define ATL_drotm ATL_drefrotm + #define ATL_drot ATL_drefrot + #define ATL_drotmg ATL_drefrotmg + #define ATL_drotg ATL_drefrotg + #define ATL_idamax ATL_idrefamax + +/* + * Complex BLAS + */ + #define ATL_cdotc_sub ATL_crefdotc_sub + #define ATL_cdotu_sub ATL_crefdotu_sub + #define ATL_caxpy ATL_crefaxpy + #define ATL_ccopy ATL_crefcopy + #define ATL_cscal ATL_crefscal + #define ATL_cswap ATL_crefswap + #define ATL_icamax ATL_icrefamax + #define ATL_csscal ATL_csrefscal + #define ATL_scnrm2 ATL_screfnrm2 + #define ATL_scasum ATL_screfasum + + #define ATL_zdotc_sub ATL_zrefdotc_sub + #define ATL_zdotu_sub ATL_zrefdotu_sub + #define ATL_zaxpy ATL_zrefaxpy + #define ATL_zcopy ATL_zrefcopy + #define ATL_zscal ATL_zrefscal + #define ATL_zswap ATL_zrefswap + #define ATL_izamax ATL_izrefamax + #define ATL_zdscal ATL_zdrefscal + #define ATL_dznrm2 ATL_dzrefnrm2 + #define ATL_dzasum ATL_dzrefasum + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_refalias2.h b/kaldi_io/src/tools/ATLAS/include/atlas_refalias2.h new file mode 100644 index 0000000..5871491 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_refalias2.h @@ -0,0 +1,79 @@ +#ifndef ATLAS_REFALIAS2_H +#define ATLAS_REFALIAS2_H +/* + * Real BLAS + */ + #define ATL_sspr2 ATL_srefspr2 + #define ATL_ssyr2 ATL_srefsyr2 + #define ATL_sspr ATL_srefspr + #define ATL_ssyr ATL_srefsyr + #define ATL_sger ATL_srefger + #define ATL_stpsv ATL_sreftpsv + #define ATL_stbsv ATL_sreftbsv + #define ATL_strsv ATL_sreftrsv + #define ATL_stpmv ATL_sreftpmv + #define ATL_stbmv ATL_sreftbmv + #define ATL_strmv ATL_sreftrmv + #define ATL_sspmv ATL_srefspmv + #define ATL_ssbmv ATL_srefsbmv + #define ATL_ssymv ATL_srefsymv + #define ATL_sgbmv ATL_srefgbmv + #define ATL_sgemv ATL_srefgemv + + #define ATL_dspr2 ATL_drefspr2 + #define ATL_dsyr2 ATL_drefsyr2 + #define ATL_dspr ATL_drefspr + #define ATL_dsyr ATL_drefsyr + #define ATL_dger ATL_drefger + #define ATL_dtpsv ATL_dreftpsv + #define ATL_dtbsv ATL_dreftbsv + #define ATL_dtrsv ATL_dreftrsv + #define ATL_dtpmv ATL_dreftpmv + #define ATL_dtbmv ATL_dreftbmv + #define ATL_dtrmv ATL_dreftrmv + #define ATL_dspmv ATL_drefspmv + #define ATL_dsbmv ATL_drefsbmv + #define ATL_dsymv ATL_drefsymv + #define ATL_dgbmv ATL_drefgbmv + #define ATL_dgemv ATL_drefgemv + +/* + * Complex BLAS + */ + #define ATL_chpr2 ATL_crefhpr2 + #define ATL_cher2 ATL_crefher2 + #define ATL_chpr ATL_crefhpr + #define ATL_cher ATL_crefher + #define ATL_cgerc ATL_crefgerc + #define ATL_cgeru ATL_crefgeru + #define ATL_ctpsv ATL_creftpsv + #define ATL_ctbsv ATL_creftbsv + #define ATL_ctrsv ATL_creftrsv + #define ATL_ctpmv ATL_creftpmv + #define ATL_ctbmv ATL_creftbmv + #define ATL_ctrmv ATL_creftrmv + #define ATL_chpmv ATL_crefhpmv + #define ATL_chbmv ATL_crefhbmv + #define ATL_chemv ATL_crefhemv + #define ATL_cgbmv ATL_crefgbmv + #define ATL_cgemv ATL_crefgemv + + #define ATL_zhpr2 ATL_zrefhpr2 + #define ATL_zher2 ATL_zrefher2 + #define ATL_zhpr ATL_zrefhpr + #define ATL_zher ATL_zrefher + #define ATL_zgerc ATL_zrefgerc + #define ATL_zgeru ATL_zrefgeru + #define ATL_ztpsv ATL_zreftpsv + #define ATL_ztbsv ATL_zreftbsv + #define ATL_ztrsv ATL_zreftrsv + #define ATL_ztpmv ATL_zreftpmv + #define ATL_ztbmv ATL_zreftbmv + #define ATL_ztrmv ATL_zreftrmv + #define ATL_zhpmv ATL_zrefhpmv + #define ATL_zhbmv ATL_zrefhbmv + #define ATL_zhemv ATL_zrefhemv + #define ATL_zgbmv ATL_zrefgbmv + #define ATL_zgemv ATL_zrefgemv + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_refalias3.h b/kaldi_io/src/tools/ATLAS/include/atlas_refalias3.h new file mode 100644 index 0000000..f10e65c --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_refalias3.h @@ -0,0 +1,43 @@ +#ifndef ATLAS_REFALIAS3_H +#define ATLAS_REFALIAS3_H +/* + * Real BLAS + */ + #define ATL_strsm ATL_sreftrsm + #define ATL_strmm ATL_sreftrmm + #define ATL_ssyr2k ATL_srefsyr2k + #define ATL_ssyrk ATL_srefsyrk + #define ATL_ssymm ATL_srefsymm + #define ATL_sgemm ATL_srefgemm + + #define ATL_dtrsm ATL_dreftrsm + #define ATL_dtrmm ATL_dreftrmm + #define ATL_dsyr2k ATL_drefsyr2k + #define ATL_dsyrk ATL_drefsyrk + #define ATL_dsymm ATL_drefsymm + #define ATL_dgemm ATL_drefgemm + +/* + * Complex BLAS + */ + #define ATL_ctrsm ATL_creftrsm + #define ATL_ctrmm ATL_creftrmm + #define ATL_cher2k ATL_crefher2k + #define ATL_csyr2k ATL_crefsyr2k + #define ATL_cherk ATL_crefherk + #define ATL_csyrk ATL_crefsyrk + #define ATL_chemm ATL_crefhemm + #define ATL_csymm ATL_crefsymm + #define ATL_cgemm ATL_crefgemm + + #define ATL_ztrsm ATL_zreftrsm + #define ATL_ztrmm ATL_zreftrmm + #define ATL_zher2k ATL_zrefher2k + #define ATL_zsyr2k ATL_zrefsyr2k + #define ATL_zherk ATL_zrefherk + #define ATL_zsyrk ATL_zrefsyrk + #define ATL_zhemm ATL_zrefhemm + #define ATL_zsymm ATL_zrefsymm + #define ATL_zgemm ATL_zrefgemm + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_reflevel1.h b/kaldi_io/src/tools/ATLAS/include/atlas_reflevel1.h new file mode 100644 index 0000000..2f79ac8 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_reflevel1.h @@ -0,0 +1,421 @@ +/* --------------------------------------------------------------------- + * + * -- Automatically Tuned Linear Algebra Software (ATLAS) + * (C) Copyright 2000 All Rights Reserved + * + * -- ATLAS routine -- Version 3.2 -- December 25, 2000 + * + * Author : Antoine P. Petitet + * Originally developed at the University of Tennessee, + * Innovative Computing Laboratory, Knoxville TN, 37996-1301, USA. + * + * --------------------------------------------------------------------- + * + * -- Copyright notice and Licensing terms: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in + * the documentation and/or other materials provided with the distri- + * bution. + * 3. The name of the University, the ATLAS group, or the names of its + * contributors may not be used to endorse or promote products deri- + * ved from this software without specific written permission. + * + * -- Disclaimer: + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEO- + * RY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (IN- + * CLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * --------------------------------------------------------------------- + */ +#ifndef ATLAS_REFLEVEL1_H +#define ATLAS_REFLEVEL1_H +/* + * ===================================================================== + * Prototypes for Level 1 Reference ATLAS BLAS routines + * ===================================================================== + */ +void ATL_srefrotg +( + float *, + float *, + float *, + float * +); + +void ATL_srefrotmg +( + float *, + float *, + float *, + const float, + float * +); + +float ATL_srefnrm2 +( + const int, + const float *, const int +); + +float ATL_srefasum +( + const int, + const float *, const int +); + +int ATL_isrefamax +( + const int, + const float *, const int +); + +void ATL_srefscal +( + const int, + const float, + float *, const int +); + +void ATL_srefswap +( + const int, + float *, const int, + float *, const int +); + +void ATL_srefcopy +( + const int, + const float *, const int, + float *, const int +); + +void ATL_srefaxpy +( + const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_srefrot +( + const int, + float *, const int, + float *, const int, + const float, + const float +); + +void ATL_srefrotm +( + const int, + float *, const int, + float *, const int, + const float * +); + +float ATL_srefdot +( + const int, + const float *, const int, + const float *, const int +); + +float ATL_sdsrefdot +( + const int, + const float, + const float *, const int, + const float *, const int +); + +double ATL_dsrefdot +( + const int, + const float *, const int, + const float *, const int +); + +void ATL_drefrotg +( + double *, + double *, + double *, + double * +); + +void ATL_drefrotmg +( + double *, + double *, + double *, + const double, + double * +); + +double ATL_drefnrm2 +( + const int, + const double *, const int +); + +double ATL_drefasum +( + const int, + const double *, const int +); + +int ATL_idrefamax +( + const int, + const double *, const int +); + +void ATL_drefscal +( + const int, + const double, + double *, const int +); + +void ATL_drefswap +( + const int, + double *, const int, + double *, const int +); + +void ATL_drefcopy +( + const int, + const double *, const int, + double *, const int +); + +void ATL_drefaxpy +( + const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_drefrot +( + const int, + double *, const int, + double *, const int, + const double, + const double +); + +void ATL_drefrotm +( + const int, + double *, const int, + double *, const int, + const double * +); + +double ATL_drefdot +( + const int, + const double *, const int, + const double *, const int +); + +void ATL_crefrotg +( + float *, + const float *, + float *, + float * +); + +float ATL_screfnrm2 +( + const int, + const float *, const int +); + +float ATL_screfasum +( + const int, + const float *, const int +); + +int ATL_icrefamax +( + const int, + const float *, const int +); + +void ATL_crefscal +( + const int, + const float *, + float *, const int +); + +void ATL_csrefscal +( + const int, + const float, + float *, const int +); + +void ATL_crefswap +( + const int, + float *, const int, + float *, const int +); + +void ATL_crefcopy +( + const int, + const float *, const int, + float *, const int +); + +void ATL_crefaxpy +( + const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_csrefrot +( + const int, + float *, const int, + float *, const int, + const float, + const float +); + +void ATL_crefdotc_sub +( + const int, + const float *, const int, + const float *, const int, + float * +); + +void ATL_crefdotu_sub +( + const int, + const float *, const int, + const float *, const int, + float * +); + +void ATL_zrefrotg +( + double *, + const double *, + double *, + double * +); + +double ATL_dzrefnrm2 +( + const int, + const double *, const int +); + +double ATL_dzrefasum +( + const int, + const double *, const int +); + +int ATL_izrefamax +( + const int, + const double *, const int +); + +void ATL_zrefscal +( + const int, + const double *, + double *, const int +); + +void ATL_zdrefscal +( + const int, + const double, + double *, const int +); + +void ATL_zrefswap +( + const int, + double *, const int, + double *, const int +); + +void ATL_zrefcopy +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zrefaxpy +( + const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zdrefrot +( + const int, + double *, const int, + double *, const int, + const double, + const double +); + +void ATL_zrefdotc_sub +( + const int, + const double *, const int, + const double *, const int, + double * +); + +void ATL_zrefdotu_sub +( + const int, + const double *, const int, + const double *, const int, + double * +); + +#endif +/* + * End of atlas_reflevel1.h + */ diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_reflevel2.h b/kaldi_io/src/tools/ATLAS/include/atlas_reflevel2.h new file mode 100644 index 0000000..6158d17 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_reflevel2.h @@ -0,0 +1,788 @@ +/* --------------------------------------------------------------------- + * + * -- Automatically Tuned Linear Algebra Software (ATLAS) + * (C) Copyright 2000 All Rights Reserved + * + * -- ATLAS routine -- Version 3.2 -- December 25, 2000 + * + * Author : Antoine P. Petitet + * Originally developed at the University of Tennessee, + * Innovative Computing Laboratory, Knoxville TN, 37996-1301, USA. + * + * --------------------------------------------------------------------- + * + * -- Copyright notice and Licensing terms: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in + * the documentation and/or other materials provided with the distri- + * bution. + * 3. The name of the University, the ATLAS group, or the names of its + * contributors may not be used to endorse or promote products deri- + * ved from this software without specific written permission. + * + * -- Disclaimer: + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEO- + * RY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (IN- + * CLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * --------------------------------------------------------------------- + */ +#ifndef ATLAS_REFLEVEL2_H +#define ATLAS_REFLEVEL2_H + +#include "atlas_enum.h" +/* + * ===================================================================== + * Prototypes for Level 2 Reference ATLAS BLAS routines + * ===================================================================== + */ +void ATL_srefgbmv +( + const enum ATLAS_TRANS, + const int, const int, + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefgpmv +( + const enum ATLAS_UPLO, + const enum ATLAS_TRANS, + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefgemv +( + const enum ATLAS_TRANS, + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefgpr +( + const enum ATLAS_UPLO, + const int, const int, + const float, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_srefger +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_srefsbmv +( + const enum ATLAS_UPLO, + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefspmv +( + const enum ATLAS_UPLO, + const int, + const float, + const float *, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefspr +( + const enum ATLAS_UPLO, + const int, + const float, + const float *, const int, + float * +); + +void ATL_srefspr2 +( + const enum ATLAS_UPLO, + const int, + const float, + const float *, const int, + const float *, const int, + float * +); + +void ATL_srefsymv +( + const enum ATLAS_UPLO, + const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefsyr +( + const enum ATLAS_UPLO, + const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_srefsyr2 +( + const enum ATLAS_UPLO, + const int, + const float, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_sreftbmv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_sreftbsv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_sreftpmv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, + const float *, + float *, const int +); + +void ATL_sreftpsv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, + const float *, + float *, const int +); + +void ATL_sreftrmv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftrsv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, + const float *, const int, + float *, const int +); + +void ATL_drefgbmv +( + const enum ATLAS_TRANS, + const int, const int, + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefgpmv +( + const enum ATLAS_UPLO, + const enum ATLAS_TRANS, + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefgemv +( + const enum ATLAS_TRANS, + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefgpr +( + const enum ATLAS_UPLO, + const int, const int, + const double, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_drefger +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_drefsbmv +( + const enum ATLAS_UPLO, + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefspmv +( + const enum ATLAS_UPLO, + const int, + const double, + const double *, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefspr +( + const enum ATLAS_UPLO, + const int, + const double, + const double *, const int, + double * +); + +void ATL_drefspr2 +( + const enum ATLAS_UPLO, + const int, + const double, + const double *, const int, + const double *, const int, + double * +); + +void ATL_drefsymv +( + const enum ATLAS_UPLO, + const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefsyr +( + const enum ATLAS_UPLO, + const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_drefsyr2 +( + const enum ATLAS_UPLO, + const int, + const double, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_dreftbmv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_dreftbsv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_dreftpmv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, + const double *, + double *, const int +); + +void ATL_dreftpsv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, + const double *, + double *, const int +); + +void ATL_dreftrmv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftrsv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, + const double *, const int, + double *, const int +); + +void ATL_crefgbmv +( + const enum ATLAS_TRANS, + const int, const int, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgpmv +( + const enum ATLAS_UPLO, + const enum ATLAS_TRANS, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgemv +( + const enum ATLAS_TRANS, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgprc +( + const enum ATLAS_UPLO, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_crefgpru +( + const enum ATLAS_UPLO, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_crefgerc +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_crefgeru +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_crefhbmv +( + const enum ATLAS_UPLO, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefhpmv +( + const enum ATLAS_UPLO, + const int, + const float *, + const float *, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefhpr +( + const enum ATLAS_UPLO, + const int, + const float, + const float *, const int, + float * +); + +void ATL_crefhpr2 +( + const enum ATLAS_UPLO, + const int, + const float *, + const float *, const int, + const float *, const int, + float * +); + +void ATL_crefhemv +( + const enum ATLAS_UPLO, + const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefher +( + const enum ATLAS_UPLO, + const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_crefher2 +( + const enum ATLAS_UPLO, + const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbmv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbsv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftpmv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, + const float *, + float *, const int +); + +void ATL_creftpsv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, + const float *, + float *, const int +); + +void ATL_creftrmv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrsv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, + const float *, const int, + float *, const int +); + +void ATL_zrefgbmv +( + const enum ATLAS_TRANS, + const int, const int, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgpmv +( + const enum ATLAS_UPLO, + const enum ATLAS_TRANS, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgemv +( + const enum ATLAS_TRANS, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgprc +( + const enum ATLAS_UPLO, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zrefgpru +( + const enum ATLAS_UPLO, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zrefgerc +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zrefgeru +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zrefhbmv +( + const enum ATLAS_UPLO, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefhpmv +( + const enum ATLAS_UPLO, + const int, + const double *, + const double *, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefhpr +( + const enum ATLAS_UPLO, + const int, + const double, + const double *, const int, + double * +); + +void ATL_zrefhpr2 +( + const enum ATLAS_UPLO, + const int, + const double *, + const double *, const int, + const double *, const int, + double * +); + +void ATL_zrefhemv +( + const enum ATLAS_UPLO, + const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefher +( + const enum ATLAS_UPLO, + const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_zrefher2 +( + const enum ATLAS_UPLO, + const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbmv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbsv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpmv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, + const double *, + double *, const int +); + +void ATL_zreftpsv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, + const double *, + double *, const int +); + +void ATL_zreftrmv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrsv +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, + const double *, const int, + double *, const int +); + +#endif +/* + * End of atlas_reflevel2.h + */ diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_reflevel3.h b/kaldi_io/src/tools/ATLAS/include/atlas_reflevel3.h new file mode 100644 index 0000000..eba976b --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_reflevel3.h @@ -0,0 +1,374 @@ +/* --------------------------------------------------------------------- + * + * -- Automatically Tuned Linear Algebra Software (ATLAS) + * (C) Copyright 2000 All Rights Reserved + * + * -- ATLAS routine -- Version 3.2 -- December 25, 2000 + * + * Author : Antoine P. Petitet + * Originally developed at the University of Tennessee, + * Innovative Computing Laboratory, Knoxville TN, 37996-1301, USA. + * + * --------------------------------------------------------------------- + * + * -- Copyright notice and Licensing terms: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in + * the documentation and/or other materials provided with the distri- + * bution. + * 3. The name of the University, the ATLAS group, or the names of its + * contributors may not be used to endorse or promote products deri- + * ved from this software without specific written permission. + * + * -- Disclaimer: + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEO- + * RY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (IN- + * CLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * --------------------------------------------------------------------- + */ +#ifndef ATLAS_REFLEVEL3_H +#define ATLAS_REFLEVEL3_H + +#include "atlas_enum.h" +/* + * ===================================================================== + * Prototypes for Level 3 Reference ATLAS BLAS routines + * ===================================================================== + */ +void ATL_srefgemm +( + const enum ATLAS_TRANS, const enum ATLAS_TRANS, + const int, const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefsymm +( + const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefsyrk +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, + const float, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefsyr2k +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_sreftrmm +( + const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrsm +( + const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_drefgemm +( + const enum ATLAS_TRANS, const enum ATLAS_TRANS, + const int, const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefsymm +( + const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefsyrk +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, + const double, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefsyr2k +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_dreftrmm +( + const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrsm +( + const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_crefgemm +( + const enum ATLAS_TRANS, const enum ATLAS_TRANS, + const int, const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefhemm +( + const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefherk +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, + const float, + const float *, const int, + const float, + float *, const int +); + +void ATL_crefher2k +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_crefsymm +( + const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefsyrk +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, + const float *, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefsyr2k +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_creftrmm +( + const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsm +( + const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_zrefgemm +( + const enum ATLAS_TRANS, const enum ATLAS_TRANS, + const int, const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefhemm +( + const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefherk +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, + const double, + const double *, const int, + const double, + double *, const int +); + +void ATL_zrefher2k +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_zrefsymm +( + const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefsyrk +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, + const double *, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefsyr2k +( + const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zreftrmm +( + const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsm +( + const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +#endif +/* + * End of atlas_reflevel3.h + */ diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_reflvl2.h b/kaldi_io/src/tools/ATLAS/include/atlas_reflvl2.h new file mode 100644 index 0000000..c557f04 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_reflvl2.h @@ -0,0 +1,3184 @@ +/* --------------------------------------------------------------------- + * + * -- Automatically Tuned Linear Algebra Software (ATLAS) + * (C) Copyright 2000 All Rights Reserved + * + * -- ATLAS routine -- Version 3.2 -- December 25, 2000 + * + * Author : Antoine P. Petitet + * Originally developed at the University of Tennessee, + * Innovative Computing Laboratory, Knoxville TN, 37996-1301, USA. + * + * --------------------------------------------------------------------- + * + * -- Copyright notice and Licensing terms: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in + * the documentation and/or other materials provided with the distri- + * bution. + * 3. The name of the University, the ATLAS group, or the names of its + * contributors may not be used to endorse or promote products deri- + * ved from this software without specific written permission. + * + * -- Disclaimer: + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEO- + * RY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (IN- + * CLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * --------------------------------------------------------------------- + */ +#ifndef ATLAS_REFLVL2_H +#define ATLAS_REFLVL2_H +/* + * ===================================================================== + * Prototypes for Level 2 Reference Internal ATLAS BLAS routines + * ===================================================================== + */ +void ATL_srefgbmvN +( + const int, const int, + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefgbmvT +( + const int, const int, + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefgpmvUN +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefgpmvUT +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefgpmvLN +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefgpmvLT +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefgemvN +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefgemvT +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefgprL +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_srefgprU +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_srefsbmvL +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefsbmvU +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefspmvL +( + const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefspmvU +( + const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefsprL +( + const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_srefsprU +( + const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_srefspr2L +( + const int, + const float, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_srefspr2U +( + const int, + const float, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_srefsymvL +( + const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefsymvU +( + const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefsyrL +( + const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_srefsyrU +( + const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_srefsyr2L +( + const int, + const float, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_srefsyr2U +( + const int, + const float, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_sreftbmvLNN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_sreftbmvLNU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_sreftbmvLTN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_sreftbmvLTU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_sreftbmvUNN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_sreftbmvUNU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_sreftbmvUTN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_sreftbmvUTU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_sreftpmvLNN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftpmvLNU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftpmvLTN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftpmvLTU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftpmvUNN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftpmvUNU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftpmvUTN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftpmvUTU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftrmvLNN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftrmvLNU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftrmvLTN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftrmvLTU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftrmvUNN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftrmvUNU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftrmvUTN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftrmvUTU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftbsvLNN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_sreftbsvLNU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_sreftbsvLTN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_sreftbsvLTU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_sreftbsvUNN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_sreftbsvUNU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_sreftbsvUTN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_sreftbsvUTU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_sreftpsvLNN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftpsvLNU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftpsvLTN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftpsvLTU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftpsvUNN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftpsvUNU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftpsvUTN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftpsvUTU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftrsvLNN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftrsvLNU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftrsvLTN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftrsvLTU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftrsvUNN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftrsvUNU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftrsvUTN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_sreftrsvUTU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_drefgbmvN +( + const int, const int, + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefgbmvT +( + const int, const int, + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefgpmvUN +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefgpmvUT +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefgpmvLN +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefgpmvLT +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefgemvN +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefgemvT +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefgprL +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_drefgprU +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_drefsbmvL +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefsbmvU +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefspmvL +( + const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefspmvU +( + const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefsprL +( + const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_drefsprU +( + const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_drefspr2L +( + const int, + const double, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_drefspr2U +( + const int, + const double, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_drefsymvL +( + const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefsymvU +( + const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefsyrL +( + const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_drefsyrU +( + const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_drefsyr2L +( + const int, + const double, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_drefsyr2U +( + const int, + const double, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_dreftbmvLNN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_dreftbmvLNU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_dreftbmvLTN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_dreftbmvLTU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_dreftbmvUNN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_dreftbmvUNU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_dreftbmvUTN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_dreftbmvUTU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_dreftpmvLNN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftpmvLNU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftpmvLTN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftpmvLTU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftpmvUNN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftpmvUNU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftpmvUTN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftpmvUTU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftrmvLNN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftrmvLNU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftrmvLTN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftrmvLTU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftrmvUNN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftrmvUNU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftrmvUTN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftrmvUTU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftbsvLNN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_dreftbsvLNU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_dreftbsvLTN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_dreftbsvLTU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_dreftbsvUNN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_dreftbsvUNU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_dreftbsvUTN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_dreftbsvUTU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_dreftpsvLNN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftpsvLNU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftpsvLTN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftpsvLTU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftpsvUNN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftpsvUNU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftpsvUTN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftpsvUTU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftrsvLNN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftrsvLNU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftrsvLTN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftrsvLTU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftrsvUNN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftrsvUNU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftrsvUTN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_dreftrsvUTU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_crefgbmvN +( + const int, const int, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgbmvT +( + const int, const int, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgbmvC +( + const int, const int, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgbmvH +( + const int, const int, + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgpmvUN +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgpmvUT +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgpmvUC +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgpmvUH +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgpmvLN +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgpmvLT +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgpmvLC +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgpmvLH +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgemvN +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgemvT +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgemvC +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgemvH +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgprcL +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_crefgprcU +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_crefgpruL +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_crefgpruU +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_crefhbmvL +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefhbmvU +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefhpmvL +( + const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefhpmvU +( + const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefhprL +( + const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_crefhprU +( + const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_crefhpr2L +( + const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_crefhpr2U +( + const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_crefhemvL +( + const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefhemvU +( + const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefherL +( + const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_crefherU +( + const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_crefher2L +( + const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_crefher2U +( + const int, + const float *, + const float *, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbmvLNN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbmvLNU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbmvLTN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbmvLTU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbmvLCN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbmvLCU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbmvLHN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbmvLHU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbmvUNN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbmvUNU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbmvUTN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbmvUTU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbmvUCN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbmvUCU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbmvUHN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbmvUHU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftpmvLNN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpmvLNU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpmvLTN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpmvLTU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpmvLCN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpmvLCU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpmvLHN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpmvLHU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpmvUNN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpmvUNU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpmvUTN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpmvUTU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpmvUCN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpmvUCU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpmvUHN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpmvUHU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrmvLNN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrmvLNU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrmvLTN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrmvLTU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrmvLCN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrmvLCU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrmvLHN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrmvLHU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrmvUNN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrmvUNU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrmvUTN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrmvUTU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrmvUCN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrmvUCU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrmvUHN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrmvUHU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftbsvLNN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbsvLNU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbsvLTN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbsvLTU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbsvLCN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbsvLCU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbsvLHN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbsvLHU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbsvUNN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbsvUNU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbsvUTN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbsvUTU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbsvUCN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbsvUCU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbsvUHN +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftbsvUHU +( + const int, const int, + const float *, const int, + float *, const int +); + +void ATL_creftpsvLNN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpsvLNU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpsvLTN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpsvLTU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpsvLCN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpsvLCU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpsvLHN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpsvLHU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpsvUNN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpsvUNU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpsvUTN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpsvUTU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpsvUCN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpsvUCU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpsvUHN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftpsvUHU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrsvLNN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrsvLNU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrsvLTN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrsvLTU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrsvLCN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrsvLCU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrsvLHN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrsvLHU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrsvUNN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrsvUNU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrsvUTN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrsvUTU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrsvUCN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrsvUCU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrsvUHN +( + const int, + const float *, const int, + float *, const int +); + +void ATL_creftrsvUHU +( + const int, + const float *, const int, + float *, const int +); + +void ATL_zrefgbmvN +( + const int, const int, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgbmvT +( + const int, const int, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgbmvC +( + const int, const int, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgbmvH +( + const int, const int, + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgpmvUN +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgpmvUT +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgpmvUC +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgpmvUH +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgpmvLN +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgpmvLT +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgpmvLC +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgpmvLH +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgemvN +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgemvT +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgemvC +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgemvH +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgprcL +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zrefgprcU +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zrefgpruL +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zrefgpruU +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zrefhbmvL +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefhbmvU +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefhpmvL +( + const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefhpmvU +( + const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefhprL +( + const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_zrefhprU +( + const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_zrefhpr2L +( + const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zrefhpr2U +( + const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zrefhemvL +( + const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefhemvU +( + const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefherL +( + const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_zrefherU +( + const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_zrefher2L +( + const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zrefher2U +( + const int, + const double *, + const double *, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbmvLNN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbmvLNU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbmvLTN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbmvLTU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbmvLCN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbmvLCU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbmvLHN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbmvLHU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbmvUNN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbmvUNU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbmvUTN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbmvUTU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbmvUCN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbmvUCU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbmvUHN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbmvUHU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpmvLNN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpmvLNU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpmvLTN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpmvLTU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpmvLCN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpmvLCU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpmvLHN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpmvLHU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpmvUNN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpmvUNU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpmvUTN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpmvUTU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpmvUCN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpmvUCU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpmvUHN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpmvUHU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrmvLNN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrmvLNU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrmvLTN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrmvLTU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrmvLCN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrmvLCU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrmvLHN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrmvLHU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrmvUNN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrmvUNU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrmvUTN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrmvUTU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrmvUCN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrmvUCU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrmvUHN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrmvUHU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbsvLNN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbsvLNU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbsvLTN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbsvLTU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbsvLCN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbsvLCU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbsvLHN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbsvLHU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbsvUNN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbsvUNU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbsvUTN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbsvUTU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbsvUCN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbsvUCU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbsvUHN +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftbsvUHU +( + const int, const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpsvLNN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpsvLNU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpsvLTN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpsvLTU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpsvLCN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpsvLCU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpsvLHN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpsvLHU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpsvUNN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpsvUNU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpsvUTN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpsvUTU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpsvUCN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpsvUCU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpsvUHN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftpsvUHU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrsvLNN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrsvLNU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrsvLTN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrsvLTU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrsvLCN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrsvLCU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrsvLHN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrsvLHU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrsvUNN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrsvUNU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrsvUTN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrsvUTU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrsvUCN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrsvUCU +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrsvUHN +( + const int, + const double *, const int, + double *, const int +); + +void ATL_zreftrsvUHU +( + const int, + const double *, const int, + double *, const int +); + +#endif +/* + * End of atlas_reflvl2.h + */ diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_reflvl3.h b/kaldi_io/src/tools/ATLAS/include/atlas_reflvl3.h new file mode 100644 index 0000000..0451ff9 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_reflvl3.h @@ -0,0 +1,2292 @@ +/* --------------------------------------------------------------------- + * + * -- Automatically Tuned Linear Algebra Software (ATLAS) + * (C) Copyright 2000 All Rights Reserved + * + * -- ATLAS routine -- Version 3.2 -- December 25, 2000 + * + * Author : Antoine P. Petitet + * Originally developed at the University of Tennessee, + * Innovative Computing Laboratory, Knoxville TN, 37996-1301, USA. + * + * --------------------------------------------------------------------- + * + * -- Copyright notice and Licensing terms: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in + * the documentation and/or other materials provided with the distri- + * bution. + * 3. The name of the University, the ATLAS group, or the names of its + * contributors may not be used to endorse or promote products deri- + * ved from this software without specific written permission. + * + * -- Disclaimer: + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEO- + * RY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (IN- + * CLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * --------------------------------------------------------------------- + */ +#ifndef ATLAS_REFLVL3_H +#define ATLAS_REFLVL3_H +/* + * ===================================================================== + * Prototypes for Level 3 Reference Internal ATLAS BLAS routines + * ===================================================================== + */ +void ATL_srefgemmNN +( + const int, const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefgemmNT +( + const int, const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefgemmTN +( + const int, const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefgemmTT +( + const int, const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefsymmLL +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefsymmLU +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefsymmRL +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefsymmRU +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefsyrkLN +( + const int, const int, + const float, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefsyrkLT +( + const int, const int, + const float, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefsyrkUN +( + const int, const int, + const float, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefsyrkUT +( + const int, const int, + const float, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefsyr2kLN +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefsyr2kLT +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefsyr2kUN +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_srefsyr2kUT +( + const int, const int, + const float, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_sreftrmmLLNN +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrmmLLNU +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrmmLLTN +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrmmLLTU +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrmmLUNN +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrmmLUNU +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrmmLUTN +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrmmLUTU +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrmmRLNN +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrmmRLNU +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrmmRLTN +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrmmRLTU +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrmmRUNN +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrmmRUNU +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrmmRUTN +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrmmRUTU +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrsmLLNN +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrsmLLNU +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrsmLLTN +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrsmLLTU +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrsmLUNN +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrsmLUNU +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrsmLUTN +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrsmLUTU +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrsmRLNN +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrsmRLNU +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrsmRLTN +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrsmRLTU +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrsmRUNN +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrsmRUNU +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrsmRUTN +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_sreftrsmRUTU +( + const int, const int, + const float, + const float *, const int, + float *, const int +); + +void ATL_drefgemmNN +( + const int, const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefgemmNT +( + const int, const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefgemmTN +( + const int, const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefgemmTT +( + const int, const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefsymmLL +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefsymmLU +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefsymmRL +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefsymmRU +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefsyrkLN +( + const int, const int, + const double, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefsyrkLT +( + const int, const int, + const double, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefsyrkUN +( + const int, const int, + const double, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefsyrkUT +( + const int, const int, + const double, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefsyr2kLN +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefsyr2kLT +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefsyr2kUN +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_drefsyr2kUT +( + const int, const int, + const double, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_dreftrmmLLNN +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrmmLLNU +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrmmLLTN +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrmmLLTU +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrmmLUNN +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrmmLUNU +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrmmLUTN +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrmmLUTU +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrmmRLNN +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrmmRLNU +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrmmRLTN +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrmmRLTU +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrmmRUNN +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrmmRUNU +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrmmRUTN +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrmmRUTU +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrsmLLNN +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrsmLLNU +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrsmLLTN +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrsmLLTU +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrsmLUNN +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrsmLUNU +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrsmLUTN +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrsmLUTU +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrsmRLNN +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrsmRLNU +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrsmRLTN +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrsmRLTU +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrsmRUNN +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrsmRUNU +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrsmRUTN +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_dreftrsmRUTU +( + const int, const int, + const double, + const double *, const int, + double *, const int +); + +void ATL_crefgemmNN +( + const int, const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgemmNT +( + const int, const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgemmNC +( + const int, const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgemmTN +( + const int, const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgemmTT +( + const int, const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgemmTC +( + const int, const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgemmCN +( + const int, const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgemmCT +( + const int, const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefgemmCC +( + const int, const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefhemmLL +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefhemmLU +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefhemmRL +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefhemmRU +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefherkLN +( + const int, const int, + const float, + const float *, const int, + const float, + float *, const int +); + +void ATL_crefherkLC +( + const int, const int, + const float, + const float *, const int, + const float, + float *, const int +); + +void ATL_crefherkUN +( + const int, const int, + const float, + const float *, const int, + const float, + float *, const int +); + +void ATL_crefherkUC +( + const int, const int, + const float, + const float *, const int, + const float, + float *, const int +); + +void ATL_crefher2kLN +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_crefher2kLC +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_crefher2kUN +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_crefher2kUC +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float, + float *, const int +); + +void ATL_crefsymmLL +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefsymmLU +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefsymmRL +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefsymmRU +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefsyrkLN +( + const int, const int, + const float *, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefsyrkLT +( + const int, const int, + const float *, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefsyrkUN +( + const int, const int, + const float *, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefsyrkUT +( + const int, const int, + const float *, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefsyr2kLN +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefsyr2kLT +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefsyr2kUN +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_crefsyr2kUT +( + const int, const int, + const float *, + const float *, const int, + const float *, const int, + const float *, + float *, const int +); + +void ATL_creftrmmLLNN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmLLNU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmLLTN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmLLTU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmLLCN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmLLCU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmLUNN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmLUNU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmLUTN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmLUTU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmLUCN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmLUCU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmRLNN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmRLNU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmRLTN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmRLTU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmRLCN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmRLCU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmRUNN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmRUNU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmRUTN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmRUTU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmRUCN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrmmRUCU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmLLNN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmLLNU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmLLTN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmLLTU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmLLCN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmLLCU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmLUNN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmLUNU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmLUTN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmLUTU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmLUCN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmLUCU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmRLNN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmRLNU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmRLTN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmRLTU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmRLCN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmRLCU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmRUNN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmRUNU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmRUTN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmRUTU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmRUCN +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_creftrsmRUCU +( + const int, const int, + const float *, + const float *, const int, + float *, const int +); + +void ATL_zrefgemmNN +( + const int, const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgemmNT +( + const int, const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgemmNC +( + const int, const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgemmTN +( + const int, const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgemmTT +( + const int, const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgemmTC +( + const int, const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgemmCN +( + const int, const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgemmCT +( + const int, const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefgemmCC +( + const int, const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefhemmLL +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefhemmLU +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefhemmRL +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefhemmRU +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefherkLN +( + const int, const int, + const double, + const double *, const int, + const double, + double *, const int +); + +void ATL_zrefherkLC +( + const int, const int, + const double, + const double *, const int, + const double, + double *, const int +); + +void ATL_zrefherkUN +( + const int, const int, + const double, + const double *, const int, + const double, + double *, const int +); + +void ATL_zrefherkUC +( + const int, const int, + const double, + const double *, const int, + const double, + double *, const int +); + +void ATL_zrefher2kLN +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_zrefher2kLC +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_zrefher2kUN +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_zrefher2kUC +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double, + double *, const int +); + +void ATL_zrefsymmLL +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefsymmLU +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefsymmRL +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefsymmRU +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefsyrkLN +( + const int, const int, + const double *, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefsyrkLT +( + const int, const int, + const double *, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefsyrkUN +( + const int, const int, + const double *, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefsyrkUT +( + const int, const int, + const double *, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefsyr2kLN +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefsyr2kLT +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefsyr2kUN +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zrefsyr2kUT +( + const int, const int, + const double *, + const double *, const int, + const double *, const int, + const double *, + double *, const int +); + +void ATL_zreftrmmLLNN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmLLNU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmLLTN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmLLTU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmLLCN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmLLCU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmLUNN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmLUNU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmLUTN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmLUTU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmLUCN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmLUCU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmRLNN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmRLNU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmRLTN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmRLTU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmRLCN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmRLCU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmRUNN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmRUNU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmRUTN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmRUTU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmRUCN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrmmRUCU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmLLNN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmLLNU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmLLTN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmLLTU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmLLCN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmLLCU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmLUNN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmLUNU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmLUTN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmLUTU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmLUCN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmLUCU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmRLNN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmRLNU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmRLTN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmRLTU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmRLCN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmRLCU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmRUNN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmRUNU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmRUTN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmRUTU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmRUCN +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +void ATL_zreftrsmRUCU +( + const int, const int, + const double *, + const double *, const int, + double *, const int +); + +#endif +/* + * End of atlas_reflvl3.h + */ diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_refmisc.h b/kaldi_io/src/tools/ATLAS/include/atlas_refmisc.h new file mode 100644 index 0000000..d8b600e --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_refmisc.h @@ -0,0 +1,367 @@ +/* --------------------------------------------------------------------- + * + * -- Automatically Tuned Linear Algebra Software (ATLAS) + * (C) Copyright 2000 All Rights Reserved + * + * -- ATLAS routine -- Version 3.2 -- December 25, 2000 + * + * Author : Antoine P. Petitet + * Originally developed at the University of Tennessee, + * Innovative Computing Laboratory, Knoxville TN, 37996-1301, USA. + * + * --------------------------------------------------------------------- + * + * -- Copyright notice and Licensing terms: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in + * the documentation and/or other materials provided with the distri- + * bution. + * 3. The name of the University, the ATLAS group, or the names of its + * contributors may not be used to endorse or promote products deri- + * ved from this software without specific written permission. + * + * -- Disclaimer: + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEO- + * RY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (IN- + * CLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * --------------------------------------------------------------------- + */ +#ifndef ATL_REFMISC_H +#define ATL_REFMISC_H +/* + * ===================================================================== + * Include files + * ===================================================================== + */ +#include +#include "atlas_enum.h" +/* + * ===================================================================== + * #define macro constants + * ===================================================================== + */ +#define ATL_sNONE (-1.0f) +#define ATL_sNTWO (-2.0f) +#define ATL_sONE ( 1.0f) +#define ATL_sZERO ( 0.0f) + +#define ATL_dNONE (-1.0) +#define ATL_dNTWO (-2.0) +#define ATL_dONE ( 1.0) +#define ATL_dZERO ( 0.0) +/* + * ===================================================================== + * # macro functions + * ===================================================================== + */ +#define Msabs( a_ ) ( ( (a_) < ATL_sZERO ) ? -(a_) : (a_) ) + +#define Mszero( a_r_, a_i_ ) \ + ( ( (a_r_) == ATL_sZERO ) && ( (a_i_) == ATL_sZERO ) ) + +#define Msone( a_r_, a_i_ ) \ + ( ( (a_r_) == ATL_sONE ) && ( (a_i_) == ATL_sZERO ) ) + +#define Msscl( a_r_, a_i_, c_r_, c_i_ ) \ + { \ + register float tmp_r_, tmp_i_; \ + tmp_r_ = (a_r_) * c_r_ - (a_i_) * c_i_; \ + tmp_i_ = (a_r_) * c_i_ + (a_i_) * c_r_; \ + c_r_ = tmp_r_; \ + c_i_ = tmp_i_; \ + } +/* + * Msdiv performs complex division in real arithmetic + * a_r_ + i * a_i_ = ( a_r_ + i * a_i_ ) / ( b_r_ + i * b_i_ ); + * The algorithm is due to Robert L. Smith and can be found in D. Knuth, + * The art of Computer Programming, Vol.2, p.195 + */ +#define Msdiv( b_r_, b_i_, a_r_, a_i_ ) \ + { \ + register float c_i_, c_r_, tmp1_, tmp2_; \ + if( Msabs( b_i_ ) < Msabs( b_r_ ) ) \ + { \ + tmp1_ = (b_i_) / (b_r_); \ + tmp2_ = (b_r_) + (b_i_) * tmp1_; \ + c_r_ = ( (a_r_) + (a_i_) * tmp1_ ) / tmp2_; \ + c_i_ = ( (a_i_) - (a_r_) * tmp1_ ) / tmp2_; \ + } \ + else \ + { \ + tmp1_ = (b_r_) / (b_i_); \ + tmp2_ = (b_i_) + (b_r_) * tmp1_; \ + c_r_ = ( (a_i_) + (a_r_) * tmp1_ ) / tmp2_; \ + c_i_ = ( -(a_r_) + (a_i_) * tmp1_ ) / tmp2_; \ + } \ + a_r_ = c_r_; \ + a_i_ = c_i_; \ + } + +#define Mdabs( a_ ) ( ( (a_) < ATL_dZERO ) ? -(a_) : (a_) ) + +#define Mdzero( a_r_, a_i_ ) \ + ( ( (a_r_) == ATL_dZERO ) && ( (a_i_) == ATL_dZERO ) ) + +#define Mdone( a_r_, a_i_ ) \ + ( ( (a_r_) == ATL_dONE ) && ( (a_i_) == ATL_dZERO ) ) + +#define Mdscl( a_r_, a_i_, c_r_, c_i_ ) \ + { \ + register double tmp_r_, tmp_i_; \ + tmp_r_ = (a_r_) * c_r_ - (a_i_) * c_i_; \ + tmp_i_ = (a_r_) * c_i_ + (a_i_) * c_r_; \ + c_r_ = tmp_r_; \ + c_i_ = tmp_i_; \ + } +/* + * Mddiv performs complex division in real arithmetic + * a_r_ + i * a_i_ = ( a_r_ + i * a_i_ ) / ( b_r_ + i * b_i_ ); + * The algorithm is due to Robert L. Smith and can be found in D. Knuth, + * The art of Computer Programming, Vol.2, p.195 + */ +#define Mddiv( b_r_, b_i_, a_r_, a_i_ ) \ + { \ + register double c_i_, c_r_, tmp1_, tmp2_; \ + if( Mdabs( b_i_ ) < Mdabs( b_r_ ) ) \ + { \ + tmp1_ = (b_i_) / (b_r_); \ + tmp2_ = (b_r_) + (b_i_) * tmp1_; \ + c_r_ = ( (a_r_) + (a_i_) * tmp1_ ) / tmp2_; \ + c_i_ = ( (a_i_) - (a_r_) * tmp1_ ) / tmp2_; \ + } \ + else \ + { \ + tmp1_ = (b_r_) / (b_i_); \ + tmp2_ = (b_i_) + (b_r_) * tmp1_; \ + c_r_ = ( (a_i_) + (a_r_) * tmp1_ ) / tmp2_; \ + c_i_ = ( -(a_r_) + (a_i_) * tmp1_ ) / tmp2_; \ + } \ + a_r_ = c_r_; \ + a_i_ = c_i_; \ + } + +#define Mmin( a_, b_ ) ( ( (a_) < (b_) ) ? (a_) : (b_) ) + +#define Mmax( a_, b_ ) ( ( (a_) > (b_) ) ? (a_) : (b_) ) + +#define Mmul( a_r_, a_i_, b_r_, b_i_, c_r_, c_i_ ) \ + { \ + c_r_ = (a_r_) * (b_r_) - (a_i_) * (b_i_); \ + c_i_ = (a_r_) * (b_i_) + (a_i_) * (b_r_); \ + } + +#define Mmla( a_r_, a_i_, b_r_, b_i_, c_r_, c_i_ ) \ + { \ + c_r_ += (a_r_) * (b_r_) - (a_i_) * (b_i_); \ + c_i_ += (a_r_) * (b_i_) + (a_i_) * (b_r_); \ + } + +#define Mmls( a_r_, a_i_, b_r_, b_i_, c_r_, c_i_ ) \ + { \ + c_r_ -= (a_r_) * (b_r_) - (a_i_) * (b_i_); \ + c_i_ -= (a_r_) * (b_i_) + (a_i_) * (b_r_); \ + } + +#define Mset( a_r_, a_i_, b_r_, b_i_ ) \ + { \ + b_r_ = (a_r_); \ + b_i_ = (a_i_); \ + } + +#define Mselscal( al_, a_ ) \ + { \ + if( (al_) == ATL_sZERO ) { (a_) = ATL_sZERO; } \ + else if( (al_) != ATL_sONE ) { (a_) *= (al_); } \ + } + +#define Mdelscal( al_, a_ ) \ + { \ + if( (al_) == ATL_dZERO ) { (a_) = ATL_dZERO; } \ + else if( (al_) != ATL_dONE ) { (a_) *= (al_); } \ + } + +#define Mcelscal( al_r_, al_i_, a_r_, a_i_ ) \ + { \ + if( Mszero( (al_r_), (al_i_) ) ) \ + { (a_r_) = (a_i_) = ATL_sZERO; } \ + else if( ! Msone( (al_r_), (al_i_) ) ) \ + { Msscl( (al_r_), (al_i_), (a_r_), (a_i_) ); } \ + } + +#define Mzelscal( al_r_, al_i_, a_r_, a_i_ ) \ + { \ + if( Mdzero( (al_r_), (al_i_) ) ) \ + { (a_r_) = (a_i_) = ATL_dZERO; } \ + else if( ! Mdone( (al_r_), (al_i_) ) ) \ + { Mdscl( (al_r_), (al_i_), (a_r_), (a_i_) ); } \ + } + +#define Msvscal( n_, al_, x_, incx_ ) \ + { \ + int i_, ix_; \ + if( (al_) == ATL_sZERO ) \ + { \ + for( i_ = 0, ix_ = 0; i_ < (n_); i_++, ix_ += (incx_) ) \ + { (x_)[ix_] = ATL_sZERO; } \ + } \ + else if( (al_) != ATL_sONE ) \ + { \ + for( i_ = 0, ix_ = 0; i_ < (n_); i_++, ix_ += (incx_) ) \ + { (x_)[ix_] *= (al_); } \ + } \ + } + +#define Mdvscal( n_, al_, x_, incx_ ) \ + { \ + int i_, ix_; \ + if( (al_) == ATL_dZERO ) \ + { \ + for( i_ = 0, ix_ = 0; i_ < (n_); i_++, ix_ += (incx_) ) \ + { (x_)[ix_] = ATL_dZERO; } \ + } \ + else if( (al_) != ATL_dONE ) \ + { \ + for( i_ = 0, ix_ = 0; i_ < (n_); i_++, ix_ += (incx_) ) \ + { (x_)[ix_] *= (al_); } \ + } \ + } + +#define Mcvscal( n_, al_, x_, incx_ ) \ + { \ + int i_, ix_, incx2_ = ( 2 * (incx_) ); \ + if( Mszero( (al_)[0], (al_)[1] ) ) \ + { \ + for( i_ = 0, ix_ = 0; i_ < (n_); i_++, ix_ += (incx2_) ) \ + { (x_)[ix_] = (x_)[ix_+1] = ATL_sZERO; } \ + } \ + else if( ! Msone( (al_)[0], (al_)[1] ) ) \ + { \ + for( i_ = 0, ix_ = 0; i_ < (n_); i_++, ix_ += (incx2_) ) \ + { Msscl( (al_)[0], (al_)[1], (x_)[ix_], (x_)[ix_+1] ); } \ + } \ + } + +#define Mzvscal( n_, al_, x_, incx_ ) \ + { \ + int i_, ix_, incx2_ = ( 2 * (incx_) ); \ + if( Mdzero( (al_)[0], (al_)[1] ) ) \ + { \ + for( i_ = 0, ix_ = 0; i_ < (n_); i_++, ix_ += (incx2_) ) \ + { (x_)[ix_] = (x_)[ix_+1] = ATL_dZERO; } \ + } \ + else if( ! Mdone( (al_)[0], (al_)[1] ) ) \ + { \ + for( i_ = 0, ix_ = 0; i_ < (n_); i_++, ix_ += (incx2_) ) \ + { Mdscl( (al_)[0], (al_)[1], (x_)[ix_], (x_)[ix_+1] ); } \ + } \ + } + +#define Msgescal( m_, n_, al_, a_, lda_ ) \ + { \ + int i_, iaij_, j_, jaj_; \ + if( (al_) == ATL_sZERO ) \ + { \ + for( j_ = 0, jaj_ = 0; j_ < (n_); j_++, jaj_ += (lda_) ) \ + { \ + for( i_ = 0, iaij_ = jaj_; i_ < (m_); i_++, iaij_ += 1 ) \ + { (a_)[iaij_] = ATL_sZERO; } \ + } \ + } \ + else if( (al_) != ATL_sONE ) \ + { \ + for( j_ = 0, jaj_ = 0; j_ < (n_); j_++, jaj_ += (lda_) ) \ + { \ + for( i_ = 0, iaij_ = jaj_; i_ < (m_); i_++, iaij_ += 1 ) \ + { (a_)[iaij_] *= (al_); } \ + } \ + } \ + } + +#define Mdgescal( m_, n_, al_, a_, lda_ ) \ + { \ + int i_, iaij_, j_, jaj_; \ + if( (al_) == ATL_dZERO ) \ + { \ + for( j_ = 0, jaj_ = 0; j_ < (n_); j_++, jaj_ += (lda_) ) \ + { \ + for( i_ = 0, iaij_ = jaj_; i_ < (m_); i_++, iaij_ += 1 ) \ + { (a_)[iaij_] = ATL_dZERO; } \ + } \ + } \ + else if( (al_) != ATL_dONE ) \ + { \ + for( j_ = 0, jaj_ = 0; j_ < (n_); j_++, jaj_ += (lda_) ) \ + { \ + for( i_ = 0, iaij_ = jaj_; i_ < (m_); i_++, iaij_ += 1 ) \ + { (a_)[iaij_] *= (al_); } \ + } \ + } \ + } + +#define Mcgescal( m_, n_, al_, a_, lda_ ) \ + { \ + int i_, iaij_, j_, jaj_, lda2_ = ( (lda_) << 1 ); \ + if( Mszero( (al_)[0], (al_)[1] ) ) \ + { \ + for( j_ = 0, jaj_ = 0; j_ < (n_); j_++, jaj_ += lda2_ ) \ + { \ + for( i_ = 0, iaij_ = jaj_; i_ < (m_); i_++, iaij_ += 2 ) \ + { (a_)[iaij_] = (a_)[iaij_+1] = ATL_sZERO; } \ + } \ + } \ + else if( ! Msone( (al_)[0], (al_)[1] ) ) \ + { \ + for( j_ = 0, jaj_ = 0; j_ < (n_); j_++, jaj_ += lda2_ ) \ + { \ + for( i_ = 0, iaij_ = jaj_; i_ < (m_); i_++, iaij_ += 2 ) \ + { \ + Msscl( (al_)[0], (al_)[1], (a_)[iaij_], (a_)[iaij_+1] ); \ + } \ + } \ + } \ + } + +#define Mzgescal( m_, n_, al_, a_, lda_ ) \ + { \ + int i_, iaij_, j_, jaj_, lda2_ = ( (lda_) << 1 ); \ + if( Mdzero( (al_)[0], (al_)[1] ) ) \ + { \ + for( j_ = 0, jaj_ = 0; j_ < (n_); j_++, jaj_ += lda2_ ) \ + { \ + for( i_ = 0, iaij_ = jaj_; i_ < (m_); i_++, iaij_ += 2 ) \ + { (a_)[iaij_] = (a_)[iaij_+1] = ATL_dZERO; } \ + } \ + } \ + else if( ! Mdone( (al_)[0], (al_)[1] ) ) \ + { \ + for( j_ = 0, jaj_ = 0; j_ < (n_); j_++, jaj_ += lda2_ ) \ + { \ + for( i_ = 0, iaij_ = jaj_; i_ < (m_); i_++, iaij_ += 2 ) \ + { \ + Mdscl( (al_)[0], (al_)[1], (a_)[iaij_], (a_)[iaij_+1] ); \ + } \ + } \ + } \ + } + +#endif +/* + * End of atlas_refmisc.h + */ diff --git a/kaldi_io/src/tools/ATLAS/include/atlas_tst.h b/kaldi_io/src/tools/ATLAS/include/atlas_tst.h new file mode 100644 index 0000000..1ea5f5e --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/atlas_tst.h @@ -0,0 +1,909 @@ +/* + * Automatically Tuned Linear Algebra Software v3.8.3 + * (C) Copyright 1999 R. Clint Whaley + * + * Code contributers : R. Clint Whaley, Antoine P. Petitet + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the ATLAS group or the names of its contributers may + * not be used to endorse or promote products derived from this + * software without specific written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef ATLAS_TST_H + #define ATLAS_TST_H + +#include "atlas_enum.h" + +double time00(); +#ifndef UseCRand + void ATL_srand(int iseed); + int ATL_rand(void); + #define dumb_seed(iseed_) ATL_srand(iseed_) + #define dumb_rand() ( 0.5 - ((double)ATL_rand())/(2147483648.0) ) +#else + #define dumb_seed(iseed_) srand(iseed_) + #ifndef RAND_MAX /* rather dangerous non-ansi workaround */ + #define RAND_MAX ((unsigned long)(1<<30)) + #endif + #define dumb_rand() ( 0.5 - ((double)rand())/((double)RAND_MAX) ) +#endif + +void ATL_ststsqtran(const int N, float *A, const int lda); +void ATL_sgeprint + (char *mat, const int M, const int N, const float *A, const int lda); + +float ATL_sgediffnrm1 + (const int M, const int N, const float *A, const int lda, + const float *B, const int ldb); +float ATL_shediffnrm + (const enum ATLAS_ORDER Order, const enum ATLAS_UPLO Uplo, const int N, + const float *A0, const int ld0, const float *A1, const int ld1); +float ATL_sinfnrm(const int N, const float *X, const int incX); +float ATL_sgenrm1 + (const int M, const int N, const float *A, const int lda); +float ATL_strnrm1 + (const enum ATLAS_UPLO Upper, const enum ATLAS_DIAG Diag, const int N, + const float *A, const int lda); +float ATL_sgbnrm1 + (const int M, const int N, const int KL, const int KU, + const float *A, const int lda); +float ATL_stpnrm1 + (const enum ATLAS_UPLO UPLO, const enum ATLAS_DIAG DIAG, const int N, + const float *A); +float ATL_stbnrm1 + (const enum ATLAS_UPLO UPLO, const enum ATLAS_DIAG DIAG, + const int N, const int K, const float *A, const int LDA); +float ATL_ssynrm + (const enum ATLAS_UPLO UPLO, const int N, const float *A, const int LDA); +float ATL_shenrm + (const enum ATLAS_UPLO UPLO, const int N, const float *A, const int LDA); +float ATL_sspnrm + (const enum ATLAS_UPLO UPLO, const int N, const float *A); +float ATL_shpnrm + (const enum ATLAS_UPLO UPLO, const int N, const float *A); +float ATL_ssbnrm + (const enum ATLAS_UPLO UPLO, const int N, const int K, + const float *A, const int LDA); +float ATL_shbnrm + (const enum ATLAS_UPLO UPLO, const int N, const int K, + const float *A, const int LDA); + +void ATL_sgefillgap(const int M, const int N, float *A, const int lda0); +int ATL_sgechkgap(const int M0, const int N, float *A, const int lda0); +void ATL_strgen(const enum ATLAS_UPLO Uplo, const enum ATLAS_DIAG Diag, + const int N, float *A, const int lda, const int seed); +void ATL_sgegen(const int M0, const int N, float *A, const int lda, + const int seed); +float ATL_sepsilon(void); +void ATL_svdiff(const int N, const float *X, const int incX, + const float *Y, const int incY, float *Z, const int incZ); +void ATL_sgediff(const int M, const int N, const float *A, const int lda, + const float *B, const int ldb, float *C, const int ldc); +void ATL_dtstsqtran(const int N, double *A, const int lda); +void ATL_dgeprint + (char *mat, const int M, const int N, const double *A, const int lda); + +double ATL_dgediffnrm1 + (const int M, const int N, const double *A, const int lda, + const double *B, const int ldb); +double ATL_dhediffnrm + (const enum ATLAS_ORDER Order, const enum ATLAS_UPLO Uplo, const int N, + const double *A0, const int ld0, const double *A1, const int ld1); +double ATL_dinfnrm(const int N, const double *X, const int incX); +double ATL_dgenrm1 + (const int M, const int N, const double *A, const int lda); +double ATL_dtrnrm1 + (const enum ATLAS_UPLO Upper, const enum ATLAS_DIAG Diag, const int N, + const double *A, const int lda); +double ATL_dgbnrm1 + (const int M, const int N, const int KL, const int KU, + const double *A, const int lda); +double ATL_dtpnrm1 + (const enum ATLAS_UPLO UPLO, const enum ATLAS_DIAG DIAG, const int N, + const double *A); +double ATL_dtbnrm1 + (const enum ATLAS_UPLO UPLO, const enum ATLAS_DIAG DIAG, + const int N, const int K, const double *A, const int LDA); +double ATL_dsynrm + (const enum ATLAS_UPLO UPLO, const int N, const double *A, const int LDA); +double ATL_dhenrm + (const enum ATLAS_UPLO UPLO, const int N, const double *A, const int LDA); +double ATL_dspnrm + (const enum ATLAS_UPLO UPLO, const int N, const double *A); +double ATL_dhpnrm + (const enum ATLAS_UPLO UPLO, const int N, const double *A); +double ATL_dsbnrm + (const enum ATLAS_UPLO UPLO, const int N, const int K, + const double *A, const int LDA); +double ATL_dhbnrm + (const enum ATLAS_UPLO UPLO, const int N, const int K, + const double *A, const int LDA); + +void ATL_dgefillgap(const int M, const int N, double *A, const int lda0); +int ATL_dgechkgap(const int M0, const int N, double *A, const int lda0); +void ATL_dtrgen(const enum ATLAS_UPLO Uplo, const enum ATLAS_DIAG Diag, + const int N, double *A, const int lda, const int seed); +void ATL_dgegen(const int M0, const int N, double *A, const int lda, + const int seed); +double ATL_depsilon(void); +void ATL_dvdiff(const int N, const double *X, const int incX, + const double *Y, const int incY, double *Z, const int incZ); +void ATL_dgediff(const int M, const int N, const double *A, const int lda, + const double *B, const int ldb, double *C, const int ldc); +void ATL_ctstsqtran(const int N, float *A, const int lda); +void ATL_cgeprint + (char *mat, const int M, const int N, const float *A, const int lda); + +float ATL_cgediffnrm1 + (const int M, const int N, const float *A, const int lda, + const float *B, const int ldb); +float ATL_chediffnrm + (const enum ATLAS_ORDER Order, const enum ATLAS_UPLO Uplo, const int N, + const float *A0, const int ld0, const float *A1, const int ld1); +float ATL_cinfnrm(const int N, const float *X, const int incX); +float ATL_cgenrm1 + (const int M, const int N, const float *A, const int lda); +float ATL_ctrnrm1 + (const enum ATLAS_UPLO Upper, const enum ATLAS_DIAG Diag, const int N, + const float *A, const int lda); +float ATL_cgbnrm1 + (const int M, const int N, const int KL, const int KU, + const float *A, const int lda); +float ATL_ctpnrm1 + (const enum ATLAS_UPLO UPLO, const enum ATLAS_DIAG DIAG, const int N, + const float *A); +float ATL_ctbnrm1 + (const enum ATLAS_UPLO UPLO, const enum ATLAS_DIAG DIAG, + const int N, const int K, const float *A, const int LDA); +float ATL_csynrm + (const enum ATLAS_UPLO UPLO, const int N, const float *A, const int LDA); +float ATL_chenrm + (const enum ATLAS_UPLO UPLO, const int N, const float *A, const int LDA); +float ATL_cspnrm + (const enum ATLAS_UPLO UPLO, const int N, const float *A); +float ATL_chpnrm + (const enum ATLAS_UPLO UPLO, const int N, const float *A); +float ATL_csbnrm + (const enum ATLAS_UPLO UPLO, const int N, const int K, + const float *A, const int LDA); +float ATL_chbnrm + (const enum ATLAS_UPLO UPLO, const int N, const int K, + const float *A, const int LDA); + +void ATL_cgefillgap(const int M, const int N, float *A, const int lda0); +int ATL_cgechkgap(const int M0, const int N, float *A, const int lda0); +void ATL_ctrgen(const enum ATLAS_UPLO Uplo, const enum ATLAS_DIAG Diag, + const int N, float *A, const int lda, const int seed); +void ATL_cgegen(const int M0, const int N, float *A, const int lda, + const int seed); +float ATL_cepsilon(void); +void ATL_cvdiff(const int N, const float *X, const int incX, + const float *Y, const int incY, float *Z, const int incZ); +void ATL_cgediff(const int M, const int N, const float *A, const int lda, + const float *B, const int ldb, float *C, const int ldc); +void ATL_ztstsqtran(const int N, double *A, const int lda); +void ATL_zgeprint + (char *mat, const int M, const int N, const double *A, const int lda); + +double ATL_zgediffnrm1 + (const int M, const int N, const double *A, const int lda, + const double *B, const int ldb); +double ATL_zhediffnrm + (const enum ATLAS_ORDER Order, const enum ATLAS_UPLO Uplo, const int N, + const double *A0, const int ld0, const double *A1, const int ld1); +double ATL_zinfnrm(const int N, const double *X, const int incX); +double ATL_zgenrm1 + (const int M, const int N, const double *A, const int lda); +double ATL_ztrnrm1 + (const enum ATLAS_UPLO Upper, const enum ATLAS_DIAG Diag, const int N, + const double *A, const int lda); +double ATL_zgbnrm1 + (const int M, const int N, const int KL, const int KU, + const double *A, const int lda); +double ATL_ztpnrm1 + (const enum ATLAS_UPLO UPLO, const enum ATLAS_DIAG DIAG, const int N, + const double *A); +double ATL_ztbnrm1 + (const enum ATLAS_UPLO UPLO, const enum ATLAS_DIAG DIAG, + const int N, const int K, const double *A, const int LDA); +double ATL_zsynrm + (const enum ATLAS_UPLO UPLO, const int N, const double *A, const int LDA); +double ATL_zhenrm + (const enum ATLAS_UPLO UPLO, const int N, const double *A, const int LDA); +double ATL_zspnrm + (const enum ATLAS_UPLO UPLO, const int N, const double *A); +double ATL_zhpnrm + (const enum ATLAS_UPLO UPLO, const int N, const double *A); +double ATL_zsbnrm + (const enum ATLAS_UPLO UPLO, const int N, const int K, + const double *A, const int LDA); +double ATL_zhbnrm + (const enum ATLAS_UPLO UPLO, const int N, const int K, + const double *A, const int LDA); + +void ATL_zgefillgap(const int M, const int N, double *A, const int lda0); +int ATL_zgechkgap(const int M0, const int N, double *A, const int lda0); +void ATL_ztrgen(const enum ATLAS_UPLO Uplo, const enum ATLAS_DIAG Diag, + const int N, double *A, const int lda, const int seed); +void ATL_zgegen(const int M0, const int N, double *A, const int lda, + const int seed); +double ATL_zepsilon(void); +void ATL_zvdiff(const int N, const double *X, const int incX, + const double *Y, const int incY, double *Z, const int incZ); +void ATL_zgediff(const int M, const int N, const double *A, const int lda, + const double *B, const int ldb, double *C, const int ldc); + +/* + * Wrappers so that C can call F77 LAPACK + */ +int ATL_sf77getri + (const enum ATLAS_ORDER, const int, float*, const int, int*, + float*, int*); +int ATL_sf77getrf + (const enum ATLAS_ORDER, const int, const int, float*, const int, int*); +int ATL_sf77potrf(const enum ATLAS_UPLO, const int, float*, const int); +int ATL_sf77lauum(const enum ATLAS_UPLO, const int, float*, const int); +int ATL_sf77trtri(const enum ATLAS_UPLO, const enum ATLAS_DIAG, const int, + float*, const int); +int ATL_sf77posv(const enum ATLAS_UPLO, const int, const int, float*, const int, float*, const int); +int ATL_sf77gesv(const int, const int, float*, const int, int*, float*, const int); +int ATL_sf77gels(const enum ATLAS_TRANS, const int, const int, const int, float*, const int, float*, const int); +int ATL_df77getri + (const enum ATLAS_ORDER, const int, double*, const int, int*, + double*, int*); +int ATL_df77getrf + (const enum ATLAS_ORDER, const int, const int, double*, const int, int*); +int ATL_df77potrf(const enum ATLAS_UPLO, const int, double*, const int); +int ATL_df77lauum(const enum ATLAS_UPLO, const int, double*, const int); +int ATL_df77trtri(const enum ATLAS_UPLO, const enum ATLAS_DIAG, const int, + double*, const int); +int ATL_df77posv(const enum ATLAS_UPLO, const int, const int, double*, const int, double*, const int); +int ATL_df77gesv(const int, const int, double*, const int, int*, double*, const int); +int ATL_df77gels(const enum ATLAS_TRANS, const int, const int, const int, double*, const int, double*, const int); +int ATL_cf77getri + (const enum ATLAS_ORDER, const int, float*, const int, int*, + float*, int*); +int ATL_cf77getrf + (const enum ATLAS_ORDER, const int, const int, float*, const int, int*); +int ATL_cf77potrf(const enum ATLAS_UPLO, const int, float*, const int); +int ATL_cf77lauum(const enum ATLAS_UPLO, const int, float*, const int); +int ATL_cf77trtri(const enum ATLAS_UPLO, const enum ATLAS_DIAG, const int, + float*, const int); +int ATL_cf77posv(const enum ATLAS_UPLO, const int, const int, float*, const int, float*, const int); +int ATL_cf77gesv(const int, const int, float*, const int, int*, float*, const int); +int ATL_cf77gels(const enum ATLAS_TRANS, const int, const int, const int, float*, const int, float*, const int); +int ATL_zf77getri + (const enum ATLAS_ORDER, const int, double*, const int, int*, + double*, int*); +int ATL_zf77getrf + (const enum ATLAS_ORDER, const int, const int, double*, const int, int*); +int ATL_zf77potrf(const enum ATLAS_UPLO, const int, double*, const int); +int ATL_zf77lauum(const enum ATLAS_UPLO, const int, double*, const int); +int ATL_zf77trtri(const enum ATLAS_UPLO, const enum ATLAS_DIAG, const int, + double*, const int); +int ATL_zf77posv(const enum ATLAS_UPLO, const int, const int, double*, const int, double*, const int); +int ATL_zf77gesv(const int, const int, double*, const int, int*, double*, const int); +int ATL_zf77gels(const enum ATLAS_TRANS, const int, const int, const int, double*, const int, double*, const int); +/* + * ===================================================================== + * Prototypes for C-callable F77 interface to the Level 1 BLAS routines + * ===================================================================== + */ +void ATL_sf77rotg +( float *, float *, float *, float * ); +void ATL_df77rotg +( double *, double *, double *, double * ); +void ATL_cf77rotg +( float *, const float *, float *, float * ); +void ATL_zf77rotg +( double *, const double *, double *, double * ); + +void ATL_sf77rotmg +( float *, float *, float *, const float, + float * ); +void ATL_df77rotmg +( double *, double *, double *, const double, + double * ); + +float ATL_sf77nrm2 +( const int, const float *, const int ); +double ATL_df77nrm2 +( const int, const double *, const int ); +float ATL_scf77nrm2 +( const int, const float *, const int ); +double ATL_dzf77nrm2 +( const int, const double *, const int ); + +float ATL_sf77asum +( const int, const float *, const int ); +double ATL_df77asum +( const int, const double *, const int ); +float ATL_scf77asum +( const int, const float *, const int ); +double ATL_dzf77asum +( const int, const double *, const int ); + +int ATL_isf77amax +( const int, const float *, const int ); +int ATL_idf77amax +( const int, const double *, const int ); +int ATL_icf77amax +( const int, const float *, const int ); +int ATL_izf77amax +( const int, const double *, const int ); + +void ATL_sf77scal +( const int, const float, float *, const int ); +void ATL_df77scal +( const int, const double, double *, const int ); +void ATL_cf77scal +( const int, const float *, float *, const int ); +void ATL_zf77scal +( const int, const double *, double *, const int ); +void ATL_csf77scal +( const int, const float, float *, const int ); +void ATL_zdf77scal +( const int, const double, double *, const int ); + +void ATL_sf77set(const int, const float, float*, const int); +void ATL_df77set(const int, const double, double*, const int); +void ATL_cf77set(const int, const float*, float*, const int); +void ATL_zf77set(const int, const double*, double*, const int); +void ATL_sf77axpby + (const int, const float, const float*, const int, const float, + float*, const int); +void ATL_df77axpby + (const int, const double, const double*, const int, const double, + double*, const int); +void ATL_cf77axpby + (const int, const float*, const float*, const int, const float*, + float*, const int); +void ATL_zf77axpby + (const int, const double*, const double*, const int, const double*, + double*, const int); + +void ATL_sf77axpy +( const int, const float, const float *, const int, + float *, const int ); +void ATL_df77axpy +( const int, const double, const double *, const int, + double *, const int ); +void ATL_cf77axpy +( const int, const float *, const float *, const int, + float *, const int ); +void ATL_zf77axpy +( const int, const double *, const double *, const int, + double *, const int ); + +void ATL_sf77copy +( const int, const float *, const int, float *, + const int ); +void ATL_df77copy +( const int, const double *, const int, double *, + const int ); +void ATL_cf77copy +( const int, const float *, const int, float *, + const int ); +void ATL_zf77copy +( const int, const double *, const int, double *, + const int ); + +void ATL_sf77swap +( const int, float *, const int, float *, + const int ); +void ATL_df77swap +( const int, double *, const int, double *, + const int ); +void ATL_cf77swap +( const int, float *, const int, float *, + const int ); +void ATL_zf77swap +( const int, double *, const int, double *, + const int ); + +void ATL_sf77rot +( const int, float *, const int, float *, + const int, const float, const float ); +void ATL_df77rot +( const int, double *, const int, double *, + const int, const double, const double ); +void ATL_csf77rot +( const int, float *, const int, float *, + const int, const float, const float ); +void ATL_zdf77rot +( const int, double *, const int, double *, + const int, const double, const double ); + +void ATL_sf77rotm +( const int, float *, const int, float *, + const int, const float * ); +void ATL_df77rotm +( const int, double *, const int, double *, + const int, const double * ); + +float ATL_sf77dot +( const int, const float *, const int, const float *, + const int ); +double ATL_df77dot +( const int, const double *, const int, const double *, + const int ); +void ATL_cf77dotu_sub +( const int, const float *, const int, const float *, + const int, float * ); +void ATL_cf77dotc_sub +( const int, const float *, const int, const float *, + const int, float * ); +void ATL_zf77dotu_sub +( const int, const double *, const int, const double *, + const int, double * ); +void ATL_zf77dotc_sub +( const int, const double *, const int, const double *, + const int, double * ); + +float ATL_sdsf77dot +( const int, const float, const float *, const int, + const float *, const int ); +double ATL_dsf77dot +( const int, const float *, const int, const float *, + const int ); +/* + * ===================================================================== + * Prototypes for C-callable F77 interface to the Level 2 BLAS routines + * ===================================================================== + */ +void ATL_sf77gemv +( const enum ATLAS_TRANS, const int, const int, + const float, const float *, const int, const float *, + const int, const float, float *, const int ); +void ATL_df77gemv +( const enum ATLAS_TRANS, const int, const int, + const double, const double *, const int, const double *, + const int, const double, double *, const int ); +void ATL_cf77gemv +( const enum ATLAS_TRANS, const int, const int, + const float *, const float *, const int, const float *, + const int, const float *, float *, const int ); +void ATL_zf77gemv +( const enum ATLAS_TRANS, const int, const int, + const double *, const double *, const int, const double *, + const int, const double *, double *, const int ); + +void ATL_sf77gbmv +( const enum ATLAS_TRANS, const int, const int, + const int, const int, const float, const float *, + const int, const float *, const int, const float, + float *, const int ); +void ATL_df77gbmv +( const enum ATLAS_TRANS, const int, const int, + const int, const int, const double, const double *, + const int, const double *, const int, const double, + double *, const int ); +void ATL_cf77gbmv +( const enum ATLAS_TRANS, const int, const int, + const int, const int, const float *, const float *, + const int, const float *, const int, const float *, + float *, const int ); +void ATL_zf77gbmv +( const enum ATLAS_TRANS, const int, const int, + const int, const int, const double *, const double *, + const int, const double *, const int, const double *, + double *, const int ); + +void ATL_sf77trmv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const float *, + const int, float *, const int ); +void ATL_df77trmv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const double *, + const int, double *, const int ); +void ATL_cf77trmv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const float *, + const int, float *, const int ); +void ATL_zf77trmv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const double *, + const int, double *, const int ); + +void ATL_sf77tbmv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const int, + const float *, const int, float *, const int ); +void ATL_df77tbmv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const int, + const double *, const int, double *, const int ); +void ATL_cf77tbmv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const int, + const float *, const int, float *, const int ); +void ATL_zf77tbmv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const int, + const double *, const int, double *, const int ); + +void ATL_sf77tpmv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const float *, + float *, const int ); +void ATL_df77tpmv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const double *, + double *, const int ); +void ATL_cf77tpmv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const float *, + float *, const int ); +void ATL_zf77tpmv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const double *, + double *, const int ); + +void ATL_sf77trsv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const float *, + const int, float *, const int ); +void ATL_df77trsv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const double *, + const int, double *, const int ); +void ATL_cf77trsv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const float *, + const int, float *, const int ); +void ATL_zf77trsv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const double *, + const int, double *, const int ); + +void ATL_sf77tbsv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const int, + const float *, const int, float *, const int ); +void ATL_df77tbsv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const int, + const double *, const int, double *, const int ); +void ATL_cf77tbsv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const int, + const float *, const int, float *, const int ); +void ATL_zf77tbsv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const int, + const double *, const int, double *, const int ); + +void ATL_sf77tpsv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const float *, + float *, const int ); +void ATL_df77tpsv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const double *, + double *, const int ); +void ATL_cf77tpsv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const float *, + float *, const int ); +void ATL_zf77tpsv +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const enum ATLAS_DIAG, const int, const double *, + double *, const int ); + +void ATL_sf77symv +( const enum ATLAS_UPLO, const int, const float, + const float *, const int, const float *, const int, + const float, float *, const int ); +void ATL_df77symv +( const enum ATLAS_UPLO, const int, const double, + const double *, const int, const double *, const int, + const double, double *, const int ); + +void ATL_cf77hemv +( const enum ATLAS_UPLO, const int, const float *, + const float *, const int, const float *, const int, + const float *, float *, const int ); +void ATL_zf77hemv +( const enum ATLAS_UPLO, const int, const double *, + const double *, const int, const double *, const int, + const double *, double *, const int ); + +void ATL_sf77sbmv +( const enum ATLAS_UPLO, const int, const int, + const float, const float *, const int, const float *, + const int, const float, float *, const int ); +void ATL_df77sbmv +( const enum ATLAS_UPLO, const int, const int, + const double, const double *, const int, const double *, + const int, const double, double *, const int ); +void ATL_cf77hbmv +( const enum ATLAS_UPLO, const int, const int, + const float *, const float *, const int, const float *, + const int, const float *, float *, const int ); +void ATL_zf77hbmv +( const enum ATLAS_UPLO, const int, const int, + const double *, const double *, const int, const double *, + const int, const double *, double *, const int ); + +void ATL_sf77spmv +( const enum ATLAS_UPLO, const int, const float, + const float *, const float *, const int, const float, + float *, const int ); +void ATL_df77spmv +( const enum ATLAS_UPLO, const int, const double, + const double *, const double *, const int, const double, + double *, const int ); +void ATL_cf77hpmv +( const enum ATLAS_UPLO, const int, const float *, + const float *, const float *, const int, const float *, + float *, const int ); +void ATL_zf77hpmv +( const enum ATLAS_UPLO, const int, const double *, + const double *, const double *, const int, const double *, + double *, const int ); + +void ATL_sf77ger +( const int, const int, const float, const float *, + const int, const float *, const int, float *, + const int ); +void ATL_df77ger +( const int, const int, const double, const double *, + const int, const double *, const int, double *, + const int ); +void ATL_cf77gerc +( const int, const int, const float *, const float *, + const int, const float *, const int, float *, + const int ); +void ATL_cf77geru +( const int, const int, const float *, const float *, + const int, const float *, const int, float *, + const int ); +void ATL_zf77gerc +( const int, const int, const double *, const double *, + const int, const double *, const int, double *, + const int ); +void ATL_zf77geru +( const int, const int, const double *, const double *, + const int, const double *, const int, double *, + const int ); + +void ATL_sf77syr +( const enum ATLAS_UPLO, const int, const float, + const float *, const int, float *, const int ); +void ATL_df77syr +( const enum ATLAS_UPLO, const int, const double, + const double *, const int, double *, const int ); +void ATL_cf77her +( const enum ATLAS_UPLO, const int, const float, + const float *, const int, float *, const int ); +void ATL_zf77her +( const enum ATLAS_UPLO, const int, const double, + const double *, const int, double *, const int ); + +void ATL_sf77spr +( const enum ATLAS_UPLO, const int, const float, + const float *, const int, float * ); +void ATL_df77spr +( const enum ATLAS_UPLO, const int, const double, + const double *, const int, double * ); +void ATL_cf77hpr +( const enum ATLAS_UPLO, const int, const float, + const float *, const int, float * ); +void ATL_zf77hpr +( const enum ATLAS_UPLO, const int, const double, + const double *, const int, double * ); + +void ATL_sf77syr2 +( const enum ATLAS_UPLO, const int, const float, + const float *, const int, const float *, const int, + float *, const int ); +void ATL_df77syr2 +( const enum ATLAS_UPLO, const int, const double, + const double *, const int, const double *, const int, + double *, const int ); +void ATL_cf77her2 +( const enum ATLAS_UPLO, const int, const float *, + const float *, const int, const float *, const int, + float *, const int ); +void ATL_zf77her2 +( const enum ATLAS_UPLO, const int, const double *, + const double *, const int, const double *, const int, + double *, const int ); + +void ATL_sf77spr2 +( const enum ATLAS_UPLO, const int, const float, + const float *, const int, const float *, const int, + float * ); +void ATL_df77spr2 +( const enum ATLAS_UPLO, const int, const double, + const double *, const int, const double *, const int, + double * ); +void ATL_cf77hpr2 +( const enum ATLAS_UPLO, const int, const float *, + const float *, const int, const float *, const int, + float * ); +void ATL_zf77hpr2 +( const enum ATLAS_UPLO, const int, const double *, + const double *, const int, const double *, const int, + double * ); +/* + * ===================================================================== + * Prototypes for C-callable F77 interface to the Level 3 BLAS routines + * ===================================================================== + */ +void ATL_sf77gemm +( const enum ATLAS_TRANS, const enum ATLAS_TRANS, + const int, const int, const int, const float, + const float *, const int, const float *, const int, + const float, float *, const int ); +void ATL_df77gemm +( const enum ATLAS_TRANS, const enum ATLAS_TRANS, + const int, const int, const int, const double, + const double *, const int, const double *, const int, + const double, double *, const int ); +void ATL_cf77gemm +( const enum ATLAS_TRANS, const enum ATLAS_TRANS, + const int, const int, const int, const float *, + const float *, const int, const float *, const int, + const float *, float *, const int ); +void ATL_zf77gemm +( const enum ATLAS_TRANS, const enum ATLAS_TRANS, + const int, const int, const int, const double *, + const double *, const int, const double *, const int, + const double *, double *, const int ); + +void ATL_cf77hemm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const int, const int, const float *, const float *, + const int, const float *, const int, const float *, + float *, const int ); +void ATL_zf77hemm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const int, const int, const double *, const double *, + const int, const double *, const int, const double *, + double *, const int ); + +void ATL_cf77herk +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const float, const float *, + const int, const float, float *, const int ); +void ATL_zf77herk +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const double, const double *, + const int, const double, double *, const int ); + +void ATL_cf77her2k +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const float *, const float *, + const int, const float *, const int, const float, + float *, const int ); +void ATL_zf77her2k +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const double *, const double *, + const int, const double *, const int, const double, + double *, const int ); + +void ATL_sf77symm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const int, const int, const float, const float *, + const int, const float *, const int, const float, + float *, const int ); +void ATL_df77symm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const int, const int, const double, const double *, + const int, const double *, const int, const double, + double *, const int ); +void ATL_cf77symm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const int, const int, const float *, const float *, + const int, const float *, const int, const float *, + float *, const int ); +void ATL_zf77symm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const int, const int, const double *, const double *, + const int, const double *, const int, const double *, + double *, const int ); + +void ATL_sf77syrk +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const float, const float *, + const int, const float, float *, const int ); +void ATL_df77syrk +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const double, const double *, + const int, const double, double *, const int ); +void ATL_cf77syrk +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const float *, const float *, + const int, const float *, float *, const int ); +void ATL_zf77syrk +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const double *, const double *, + const int, const double *, double *, const int ); + +void ATL_sf77syr2k +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const float, const float *, + const int, const float *, const int, const float, + float *, const int ); +void ATL_df77syr2k +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const double, const double *, + const int, const double *, const int, const double, + double *, const int ); +void ATL_cf77syr2k +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const float *, const float *, + const int, const float *, const int, const float *, + float *, const int ); +void ATL_zf77syr2k +( const enum ATLAS_UPLO, const enum ATLAS_TRANS, + const int, const int, const double *, const double *, + const int, const double *, const int, const double *, + double *, const int ); + +void ATL_sf77trmm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const float, const float *, + const int, float *, const int ); +void ATL_df77trmm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const double, const double *, + const int, double *, const int ); +void ATL_cf77trmm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const float *, const float *, + const int, float *, const int ); +void ATL_zf77trmm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const double *, const double *, + const int, double *, const int ); + +void ATL_sf77trsm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const float, const float *, + const int, float *, const int ); +void ATL_df77trsm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const double, const double *, + const int, double *, const int ); +void ATL_cf77trsm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const float *, const float *, + const int, float *, const int ); +void ATL_zf77trsm +( const enum ATLAS_SIDE, const enum ATLAS_UPLO, + const enum ATLAS_TRANS, const enum ATLAS_DIAG, + const int, const int, const double *, const double *, + const int, double *, const int ); + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/cblas.h b/kaldi_io/src/tools/ATLAS/include/cblas.h new file mode 100644 index 0000000..4087ffb --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/cblas.h @@ -0,0 +1,596 @@ +#ifndef CBLAS_H + +#ifndef CBLAS_ENUM_DEFINED_H + #define CBLAS_ENUM_DEFINED_H + enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102 }; + enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113, + AtlasConj=114}; + enum CBLAS_UPLO {CblasUpper=121, CblasLower=122}; + enum CBLAS_DIAG {CblasNonUnit=131, CblasUnit=132}; + enum CBLAS_SIDE {CblasLeft=141, CblasRight=142}; +#endif + +#ifndef CBLAS_ENUM_ONLY +#define CBLAS_H +#define CBLAS_INDEX int + +int cblas_errprn(int ierr, int info, char *form, ...); + +/* + * =========================================================================== + * Prototypes for level 1 BLAS functions (complex are recast as routines) + * =========================================================================== + */ +float cblas_sdsdot(const int N, const float alpha, const float *X, + const int incX, const float *Y, const int incY); +double cblas_dsdot(const int N, const float *X, const int incX, const float *Y, + const int incY); +float cblas_sdot(const int N, const float *X, const int incX, + const float *Y, const int incY); +double cblas_ddot(const int N, const double *X, const int incX, + const double *Y, const int incY); +/* + * Functions having prefixes Z and C only + */ +void cblas_cdotu_sub(const int N, const void *X, const int incX, + const void *Y, const int incY, void *dotu); +void cblas_cdotc_sub(const int N, const void *X, const int incX, + const void *Y, const int incY, void *dotc); + +void cblas_zdotu_sub(const int N, const void *X, const int incX, + const void *Y, const int incY, void *dotu); +void cblas_zdotc_sub(const int N, const void *X, const int incX, + const void *Y, const int incY, void *dotc); + + +/* + * Functions having prefixes S D SC DZ + */ +float cblas_snrm2(const int N, const float *X, const int incX); +float cblas_sasum(const int N, const float *X, const int incX); + +double cblas_dnrm2(const int N, const double *X, const int incX); +double cblas_dasum(const int N, const double *X, const int incX); + +float cblas_scnrm2(const int N, const void *X, const int incX); +float cblas_scasum(const int N, const void *X, const int incX); + +double cblas_dznrm2(const int N, const void *X, const int incX); +double cblas_dzasum(const int N, const void *X, const int incX); + + +/* + * Functions having standard 4 prefixes (S D C Z) + */ +CBLAS_INDEX cblas_isamax(const int N, const float *X, const int incX); +CBLAS_INDEX cblas_idamax(const int N, const double *X, const int incX); +CBLAS_INDEX cblas_icamax(const int N, const void *X, const int incX); +CBLAS_INDEX cblas_izamax(const int N, const void *X, const int incX); + +/* + * =========================================================================== + * Prototypes for level 1 BLAS routines + * =========================================================================== + */ + +/* + * Routines with standard 4 prefixes (s, d, c, z) + */ +void cblas_sswap(const int N, float *X, const int incX, + float *Y, const int incY); +void cblas_scopy(const int N, const float *X, const int incX, + float *Y, const int incY); +void cblas_saxpy(const int N, const float alpha, const float *X, + const int incX, float *Y, const int incY); +void catlas_saxpby(const int N, const float alpha, const float *X, + const int incX, const float beta, float *Y, const int incY); +void catlas_sset + (const int N, const float alpha, float *X, const int incX); + +void cblas_dswap(const int N, double *X, const int incX, + double *Y, const int incY); +void cblas_dcopy(const int N, const double *X, const int incX, + double *Y, const int incY); +void cblas_daxpy(const int N, const double alpha, const double *X, + const int incX, double *Y, const int incY); +void catlas_daxpby(const int N, const double alpha, const double *X, + const int incX, const double beta, double *Y, const int incY); +void catlas_dset + (const int N, const double alpha, double *X, const int incX); + +void cblas_cswap(const int N, void *X, const int incX, + void *Y, const int incY); +void cblas_ccopy(const int N, const void *X, const int incX, + void *Y, const int incY); +void cblas_caxpy(const int N, const void *alpha, const void *X, + const int incX, void *Y, const int incY); +void catlas_caxpby(const int N, const void *alpha, const void *X, + const int incX, const void *beta, void *Y, const int incY); +void catlas_cset + (const int N, const void *alpha, void *X, const int incX); + +void cblas_zswap(const int N, void *X, const int incX, + void *Y, const int incY); +void cblas_zcopy(const int N, const void *X, const int incX, + void *Y, const int incY); +void cblas_zaxpy(const int N, const void *alpha, const void *X, + const int incX, void *Y, const int incY); +void catlas_zaxpby(const int N, const void *alpha, const void *X, + const int incX, const void *beta, void *Y, const int incY); +void catlas_zset + (const int N, const void *alpha, void *X, const int incX); + + +/* + * Routines with S and D prefix only + */ +void cblas_srotg(float *a, float *b, float *c, float *s); +void cblas_srotmg(float *d1, float *d2, float *b1, const float b2, float *P); +void cblas_srot(const int N, float *X, const int incX, + float *Y, const int incY, const float c, const float s); +void cblas_srotm(const int N, float *X, const int incX, + float *Y, const int incY, const float *P); + +void cblas_drotg(double *a, double *b, double *c, double *s); +void cblas_drotmg(double *d1, double *d2, double *b1, const double b2, double *P); +void cblas_drot(const int N, double *X, const int incX, + double *Y, const int incY, const double c, const double s); +void cblas_drotm(const int N, double *X, const int incX, + double *Y, const int incY, const double *P); + + +/* + * Routines with S D C Z CS and ZD prefixes + */ +void cblas_sscal(const int N, const float alpha, float *X, const int incX); +void cblas_dscal(const int N, const double alpha, double *X, const int incX); +void cblas_cscal(const int N, const void *alpha, void *X, const int incX); +void cblas_zscal(const int N, const void *alpha, void *X, const int incX); +void cblas_csscal(const int N, const float alpha, void *X, const int incX); +void cblas_zdscal(const int N, const double alpha, void *X, const int incX); + +/* + * Extra reference routines provided by ATLAS, but not mandated by the standard + */ +void cblas_crotg(void *a, void *b, void *c, void *s); +void cblas_zrotg(void *a, void *b, void *c, void *s); +void cblas_csrot(const int N, void *X, const int incX, void *Y, const int incY, + const float c, const float s); +void cblas_zdrot(const int N, void *X, const int incX, void *Y, const int incY, + const double c, const double s); + +/* + * =========================================================================== + * Prototypes for level 2 BLAS + * =========================================================================== + */ + +/* + * Routines with standard 4 prefixes (S, D, C, Z) + */ +void cblas_sgemv(const enum CBLAS_ORDER Order, + const enum CBLAS_TRANSPOSE TransA, const int M, const int N, + const float alpha, const float *A, const int lda, + const float *X, const int incX, const float beta, + float *Y, const int incY); +void cblas_sgbmv(const enum CBLAS_ORDER Order, + const enum CBLAS_TRANSPOSE TransA, const int M, const int N, + const int KL, const int KU, const float alpha, + const float *A, const int lda, const float *X, + const int incX, const float beta, float *Y, const int incY); +void cblas_strmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const float *A, const int lda, + float *X, const int incX); +void cblas_stbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const int K, const float *A, const int lda, + float *X, const int incX); +void cblas_stpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const float *Ap, float *X, const int incX); +void cblas_strsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const float *A, const int lda, float *X, + const int incX); +void cblas_stbsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const int K, const float *A, const int lda, + float *X, const int incX); +void cblas_stpsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const float *Ap, float *X, const int incX); + +void cblas_dgemv(const enum CBLAS_ORDER Order, + const enum CBLAS_TRANSPOSE TransA, const int M, const int N, + const double alpha, const double *A, const int lda, + const double *X, const int incX, const double beta, + double *Y, const int incY); +void cblas_dgbmv(const enum CBLAS_ORDER Order, + const enum CBLAS_TRANSPOSE TransA, const int M, const int N, + const int KL, const int KU, const double alpha, + const double *A, const int lda, const double *X, + const int incX, const double beta, double *Y, const int incY); +void cblas_dtrmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const double *A, const int lda, + double *X, const int incX); +void cblas_dtbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const int K, const double *A, const int lda, + double *X, const int incX); +void cblas_dtpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const double *Ap, double *X, const int incX); +void cblas_dtrsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const double *A, const int lda, double *X, + const int incX); +void cblas_dtbsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const int K, const double *A, const int lda, + double *X, const int incX); +void cblas_dtpsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const double *Ap, double *X, const int incX); + +void cblas_cgemv(const enum CBLAS_ORDER Order, + const enum CBLAS_TRANSPOSE TransA, const int M, const int N, + const void *alpha, const void *A, const int lda, + const void *X, const int incX, const void *beta, + void *Y, const int incY); +void cblas_cgbmv(const enum CBLAS_ORDER Order, + const enum CBLAS_TRANSPOSE TransA, const int M, const int N, + const int KL, const int KU, const void *alpha, + const void *A, const int lda, const void *X, + const int incX, const void *beta, void *Y, const int incY); +void cblas_ctrmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const void *A, const int lda, + void *X, const int incX); +void cblas_ctbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const int K, const void *A, const int lda, + void *X, const int incX); +void cblas_ctpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const void *Ap, void *X, const int incX); +void cblas_ctrsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const void *A, const int lda, void *X, + const int incX); +void cblas_ctbsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const int K, const void *A, const int lda, + void *X, const int incX); +void cblas_ctpsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const void *Ap, void *X, const int incX); + +void cblas_zgemv(const enum CBLAS_ORDER Order, + const enum CBLAS_TRANSPOSE TransA, const int M, const int N, + const void *alpha, const void *A, const int lda, + const void *X, const int incX, const void *beta, + void *Y, const int incY); +void cblas_zgbmv(const enum CBLAS_ORDER Order, + const enum CBLAS_TRANSPOSE TransA, const int M, const int N, + const int KL, const int KU, const void *alpha, + const void *A, const int lda, const void *X, + const int incX, const void *beta, void *Y, const int incY); +void cblas_ztrmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const void *A, const int lda, + void *X, const int incX); +void cblas_ztbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const int K, const void *A, const int lda, + void *X, const int incX); +void cblas_ztpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const void *Ap, void *X, const int incX); +void cblas_ztrsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const void *A, const int lda, void *X, + const int incX); +void cblas_ztbsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const int K, const void *A, const int lda, + void *X, const int incX); +void cblas_ztpsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, + const int N, const void *Ap, void *X, const int incX); + + +/* + * Routines with S and D prefixes only + */ +void cblas_ssymv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const float alpha, const float *A, + const int lda, const float *X, const int incX, + const float beta, float *Y, const int incY); +void cblas_ssbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const int K, const float alpha, const float *A, + const int lda, const float *X, const int incX, + const float beta, float *Y, const int incY); +void cblas_sspmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const float alpha, const float *Ap, + const float *X, const int incX, + const float beta, float *Y, const int incY); +void cblas_sger(const enum CBLAS_ORDER Order, const int M, const int N, + const float alpha, const float *X, const int incX, + const float *Y, const int incY, float *A, const int lda); +void cblas_ssyr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const float alpha, const float *X, + const int incX, float *A, const int lda); +void cblas_sspr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const float alpha, const float *X, + const int incX, float *Ap); +void cblas_ssyr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const float alpha, const float *X, + const int incX, const float *Y, const int incY, float *A, + const int lda); +void cblas_sspr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const float alpha, const float *X, + const int incX, const float *Y, const int incY, float *A); + +void cblas_dsymv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const double alpha, const double *A, + const int lda, const double *X, const int incX, + const double beta, double *Y, const int incY); +void cblas_dsbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const int K, const double alpha, const double *A, + const int lda, const double *X, const int incX, + const double beta, double *Y, const int incY); +void cblas_dspmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const double alpha, const double *Ap, + const double *X, const int incX, + const double beta, double *Y, const int incY); +void cblas_dger(const enum CBLAS_ORDER Order, const int M, const int N, + const double alpha, const double *X, const int incX, + const double *Y, const int incY, double *A, const int lda); +void cblas_dsyr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const double alpha, const double *X, + const int incX, double *A, const int lda); +void cblas_dspr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const double alpha, const double *X, + const int incX, double *Ap); +void cblas_dsyr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const double alpha, const double *X, + const int incX, const double *Y, const int incY, double *A, + const int lda); +void cblas_dspr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const double alpha, const double *X, + const int incX, const double *Y, const int incY, double *A); + + +/* + * Routines with C and Z prefixes only + */ +void cblas_chemv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const void *alpha, const void *A, + const int lda, const void *X, const int incX, + const void *beta, void *Y, const int incY); +void cblas_chbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const int K, const void *alpha, const void *A, + const int lda, const void *X, const int incX, + const void *beta, void *Y, const int incY); +void cblas_chpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const void *alpha, const void *Ap, + const void *X, const int incX, + const void *beta, void *Y, const int incY); +void cblas_cgeru(const enum CBLAS_ORDER Order, const int M, const int N, + const void *alpha, const void *X, const int incX, + const void *Y, const int incY, void *A, const int lda); +void cblas_cgerc(const enum CBLAS_ORDER Order, const int M, const int N, + const void *alpha, const void *X, const int incX, + const void *Y, const int incY, void *A, const int lda); +void cblas_cher(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const float alpha, const void *X, const int incX, + void *A, const int lda); +void cblas_chpr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const float alpha, const void *X, + const int incX, void *A); +void cblas_cher2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const int N, + const void *alpha, const void *X, const int incX, + const void *Y, const int incY, void *A, const int lda); +void cblas_chpr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const int N, + const void *alpha, const void *X, const int incX, + const void *Y, const int incY, void *Ap); + +void cblas_zhemv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const void *alpha, const void *A, + const int lda, const void *X, const int incX, + const void *beta, void *Y, const int incY); +void cblas_zhbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const int K, const void *alpha, const void *A, + const int lda, const void *X, const int incX, + const void *beta, void *Y, const int incY); +void cblas_zhpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const void *alpha, const void *Ap, + const void *X, const int incX, + const void *beta, void *Y, const int incY); +void cblas_zgeru(const enum CBLAS_ORDER Order, const int M, const int N, + const void *alpha, const void *X, const int incX, + const void *Y, const int incY, void *A, const int lda); +void cblas_zgerc(const enum CBLAS_ORDER Order, const int M, const int N, + const void *alpha, const void *X, const int incX, + const void *Y, const int incY, void *A, const int lda); +void cblas_zher(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const double alpha, const void *X, const int incX, + void *A, const int lda); +void cblas_zhpr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const double alpha, const void *X, + const int incX, void *A); +void cblas_zher2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const int N, + const void *alpha, const void *X, const int incX, + const void *Y, const int incY, void *A, const int lda); +void cblas_zhpr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const int N, + const void *alpha, const void *X, const int incX, + const void *Y, const int incY, void *Ap); + +/* + * =========================================================================== + * Prototypes for level 3 BLAS + * =========================================================================== + */ + +/* + * Routines with standard 4 prefixes (S, D, C, Z) + */ +void cblas_sgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_TRANSPOSE TransB, const int M, const int N, + const int K, const float alpha, const float *A, + const int lda, const float *B, const int ldb, + const float beta, float *C, const int ldc); +void cblas_ssymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const int M, const int N, + const float alpha, const float *A, const int lda, + const float *B, const int ldb, const float beta, + float *C, const int ldc); +void cblas_ssyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const float alpha, const float *A, const int lda, + const float beta, float *C, const int ldc); +void cblas_ssyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const float alpha, const float *A, const int lda, + const float *B, const int ldb, const float beta, + float *C, const int ldc); +void cblas_strmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_DIAG Diag, const int M, const int N, + const float alpha, const float *A, const int lda, + float *B, const int ldb); +void cblas_strsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_DIAG Diag, const int M, const int N, + const float alpha, const float *A, const int lda, + float *B, const int ldb); + +void cblas_dgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_TRANSPOSE TransB, const int M, const int N, + const int K, const double alpha, const double *A, + const int lda, const double *B, const int ldb, + const double beta, double *C, const int ldc); +void cblas_dsymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const int M, const int N, + const double alpha, const double *A, const int lda, + const double *B, const int ldb, const double beta, + double *C, const int ldc); +void cblas_dsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const double alpha, const double *A, const int lda, + const double beta, double *C, const int ldc); +void cblas_dsyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const double alpha, const double *A, const int lda, + const double *B, const int ldb, const double beta, + double *C, const int ldc); +void cblas_dtrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_DIAG Diag, const int M, const int N, + const double alpha, const double *A, const int lda, + double *B, const int ldb); +void cblas_dtrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_DIAG Diag, const int M, const int N, + const double alpha, const double *A, const int lda, + double *B, const int ldb); + +void cblas_cgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_TRANSPOSE TransB, const int M, const int N, + const int K, const void *alpha, const void *A, + const int lda, const void *B, const int ldb, + const void *beta, void *C, const int ldc); +void cblas_csymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const int M, const int N, + const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, + void *C, const int ldc); +void cblas_csyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const void *alpha, const void *A, const int lda, + const void *beta, void *C, const int ldc); +void cblas_csyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, + void *C, const int ldc); +void cblas_ctrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_DIAG Diag, const int M, const int N, + const void *alpha, const void *A, const int lda, + void *B, const int ldb); +void cblas_ctrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_DIAG Diag, const int M, const int N, + const void *alpha, const void *A, const int lda, + void *B, const int ldb); + +void cblas_zgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_TRANSPOSE TransB, const int M, const int N, + const int K, const void *alpha, const void *A, + const int lda, const void *B, const int ldb, + const void *beta, void *C, const int ldc); +void cblas_zsymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const int M, const int N, + const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, + void *C, const int ldc); +void cblas_zsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const void *alpha, const void *A, const int lda, + const void *beta, void *C, const int ldc); +void cblas_zsyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, + void *C, const int ldc); +void cblas_ztrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_DIAG Diag, const int M, const int N, + const void *alpha, const void *A, const int lda, + void *B, const int ldb); +void cblas_ztrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_DIAG Diag, const int M, const int N, + const void *alpha, const void *A, const int lda, + void *B, const int ldb); + + +/* + * Routines with prefixes C and Z only + */ +void cblas_chemm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const int M, const int N, + const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, + void *C, const int ldc); +void cblas_cherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const float alpha, const void *A, const int lda, + const float beta, void *C, const int ldc); +void cblas_cher2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const float beta, + void *C, const int ldc); +void cblas_zhemm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, + const enum CBLAS_UPLO Uplo, const int M, const int N, + const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const void *beta, + void *C, const int ldc); +void cblas_zherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const double alpha, const void *A, const int lda, + const double beta, void *C, const int ldc); +void cblas_zher2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const enum CBLAS_TRANSPOSE Trans, const int N, const int K, + const void *alpha, const void *A, const int lda, + const void *B, const int ldb, const double beta, + void *C, const int ldc); + +int cblas_errprn(int ierr, int info, char *form, ...); + +#endif /* end #ifdef CBLAS_ENUM_ONLY */ +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/cblas_test.h b/kaldi_io/src/tools/ATLAS/include/cblas_test.h new file mode 100644 index 0000000..b871a47 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/cblas_test.h @@ -0,0 +1,542 @@ +/* + * Added by R. Clint Whaley to make compatible with ATLAS + */ +#if defined(Add_) || defined(Add__) + #define ADD_ +#elif defined(NoChange) + #define NOCHANGE +#elif defined(UpCase) + #define UPCASE +#endif + +#ifdef ADD_ + #define F77_crotg crotgtest_ + #define F77_zrotg zrotgtest_ + #define F77_csrot csrottest_ + #define F77_zdrot zdrottest_ +#elif defined NOCHANGE + #define F77_crotg crotgtest + #define F77_zrotg zrotgtest + #define F77_csrot csrottest + #define F77_zdrot zdrottest +#elif defined UPCASE + #define F77_crotg CROTGTEST + #define F77_zrotg ZROTGTEST + #define F77_csrot CSROTTEST + #define F77_zdrot ZDROTTEST +#endif + + +/* + * cblas_test.h + * Written by Keita Teranishi + */ +#ifndef CBLAS_TEST_H +#define CBLAS_TEST_H +#include "cblas.h" + +#define TRUE 1 +#define PASSED 1 +#define TEST_ROW_MJR 1 + +#define FALSE 0 +#define FAILED 0 +#define TEST_COL_MJR 0 + +#define INVALID -1 +#define UNDEFINED -1 + +typedef struct { float real; float imag; } CBLAS_TEST_COMPLEX; +typedef struct { double real; double imag; } CBLAS_TEST_ZOMPLEX; + +#if defined(ADD_) + #define F77_xerbla xerbla_ +/* + * Level 1 BLAS + */ + #define F77_srotg srotgtest_ + #define F77_srotmg srotmgtest_ + #define F77_srot srottest_ + #define F77_srotm srotmtest_ + #define F77_drotg drotgtest_ + #define F77_drotmg drotmgtest_ + #define F77_drot drottest_ + #define F77_drotm drotmtest_ + #define F77_sswap sswaptest_ + #define F77_scopy scopytest_ + #define F77_saxpy saxpytest_ + #define F77_isamax isamaxtest_ + #define F77_dswap dswaptest_ + #define F77_dcopy dcopytest_ + #define F77_daxpy daxpytest_ + #define F77_idamax idamaxtest_ + #define F77_cswap cswaptest_ + #define F77_ccopy ccopytest_ + #define F77_caxpy caxpytest_ + #define F77_icamax icamaxtest_ + #define F77_zswap zswaptest_ + #define F77_zcopy zcopytest_ + #define F77_zaxpy zaxpytest_ + #define F77_izamax izamaxtest_ + #define F77_sdot sdottestsub_ + #define F77_ddot ddottestsub_ + #define F77_dsdot dsdottest_ + #define F77_sscal sscaltest_ + #define F77_dscal dscaltest_ + #define F77_cscal cscaltest_ + #define F77_zscal zscaltest_ + #define F77_csscal csscaltest_ + #define F77_zdscal zdscaltest_ + #define F77_cdotu cdotutest_ + #define F77_cdotc cdotctest_ + #define F77_zdotu zdotutest_ + #define F77_zdotc zdotctest_ + #define F77_snrm2 snrm2testsub_ + #define F77_sasum sasumtestsub_ + #define F77_dnrm2 dnrm2testsub_ + #define F77_dasum dasumtestsub_ + #define F77_scnrm2 scnrm2testsub_ + #define F77_scasum scasumtestsub_ + #define F77_dznrm2 dznrm2testsub_ + #define F77_dzasum dzasumtestsub_ + #define F77_sdsdot sdsdottest_ +/* + * Level 2 BLAS + */ + #define F77_s2chke cs2chke_ + #define F77_d2chke cd2chke_ + #define F77_c2chke cc2chke_ + #define F77_z2chke cz2chke_ + #define F77_ssymv cssymv_ + #define F77_ssbmv cssbmv_ + #define F77_sspmv csspmv_ + #define F77_sger csger_ + #define F77_ssyr cssyr_ + #define F77_sspr csspr_ + #define F77_ssyr2 cssyr2_ + #define F77_sspr2 csspr2_ + #define F77_dsymv cdsymv_ + #define F77_dsbmv cdsbmv_ + #define F77_dspmv cdspmv_ + #define F77_dger cdger_ + #define F77_dsyr cdsyr_ + #define F77_dspr cdspr_ + #define F77_dsyr2 cdsyr2_ + #define F77_dspr2 cdspr2_ + #define F77_chemv cchemv_ + #define F77_chbmv cchbmv_ + #define F77_chpmv cchpmv_ + #define F77_cgeru ccgeru_ + #define F77_cgerc ccgerc_ + #define F77_cher ccher_ + #define F77_chpr cchpr_ + #define F77_cher2 ccher2_ + #define F77_chpr2 cchpr2_ + #define F77_zhemv czhemv_ + #define F77_zhbmv czhbmv_ + #define F77_zhpmv czhpmv_ + #define F77_zgeru czgeru_ + #define F77_zgerc czgerc_ + #define F77_zher czher_ + #define F77_zhpr czhpr_ + #define F77_zher2 czher2_ + #define F77_zhpr2 czhpr2_ + #define F77_sgemv csgemv_ + #define F77_sgbmv csgbmv_ + #define F77_strmv cstrmv_ + #define F77_stbmv cstbmv_ + #define F77_stpmv cstpmv_ + #define F77_strsv cstrsv_ + #define F77_stbsv cstbsv_ + #define F77_stpsv cstpsv_ + #define F77_dgemv cdgemv_ + #define F77_dgbmv cdgbmv_ + #define F77_dtrmv cdtrmv_ + #define F77_dtbmv cdtbmv_ + #define F77_dtpmv cdtpmv_ + #define F77_dtrsv cdtrsv_ + #define F77_dtbsv cdtbsv_ + #define F77_dtpsv cdtpsv_ + #define F77_cgemv ccgemv_ + #define F77_cgbmv ccgbmv_ + #define F77_ctrmv cctrmv_ + #define F77_ctbmv cctbmv_ + #define F77_ctpmv cctpmv_ + #define F77_ctrsv cctrsv_ + #define F77_ctbsv cctbsv_ + #define F77_ctpsv cctpsv_ + #define F77_zgemv czgemv_ + #define F77_zgbmv czgbmv_ + #define F77_ztrmv cztrmv_ + #define F77_ztbmv cztbmv_ + #define F77_ztpmv cztpmv_ + #define F77_ztrsv cztrsv_ + #define F77_ztbsv cztbsv_ + #define F77_ztpsv cztpsv_ +/* + * Level 3 BLAS + */ + #define F77_s3chke cs3chke_ + #define F77_d3chke cd3chke_ + #define F77_c3chke cc3chke_ + #define F77_z3chke cz3chke_ + #define F77_chemm cchemm_ + #define F77_cherk ccherk_ + #define F77_cher2k ccher2k_ + #define F77_zhemm czhemm_ + #define F77_zherk czherk_ + #define F77_zher2k czher2k_ + #define F77_sgemm csgemm_ + #define F77_ssymm cssymm_ + #define F77_ssyrk cssyrk_ + #define F77_ssyr2k cssyr2k_ + #define F77_strmm cstrmm_ + #define F77_strsm cstrsm_ + #define F77_dgemm cdgemm_ + #define F77_dsymm cdsymm_ + #define F77_dsyrk cdsyrk_ + #define F77_dsyr2k cdsyr2k_ + #define F77_dtrmm cdtrmm_ + #define F77_dtrsm cdtrsm_ + #define F77_cgemm ccgemm_ + #define F77_csymm ccsymm_ + #define F77_csyrk ccsyrk_ + #define F77_csyr2k ccsyr2k_ + #define F77_ctrmm cctrmm_ + #define F77_ctrsm cctrsm_ + #define F77_zgemm czgemm_ + #define F77_zsymm czsymm_ + #define F77_zsyrk czsyrk_ + #define F77_zsyr2k czsyr2k_ + #define F77_ztrmm cztrmm_ + #define F77_ztrsm cztrsm_ +#elif defined(UPCASE) + #define F77_xerbla XERBLA +/* + * Level 1 BLAS + */ + #define F77_srotg SROTGTEST + #define F77_srotmg SROTMGTEST + #define F77_srot SROTTEST + #define F77_srotm SROTMTEST + #define F77_drotg DROTGTEST + #define F77_drotmg DROTMGTEST + #define F77_drot DROTTEST + #define F77_drotm DROTMTEST + #define F77_sswap SSWAPTEST + #define F77_scopy SCOPYTEST + #define F77_saxpy SAXPYTEST + #define F77_isamax ISAMAXTEST + #define F77_dswap DSWAPTEST + #define F77_dcopy DCOPYTEST + #define F77_daxpy DAXPYTEST + #define F77_idamax IDAMAXTEST + #define F77_cswap CSWAPTEST + #define F77_ccopy CCOPYTEST + #define F77_caxpy CAXPYTEST + #define F77_icamax ICAMAXTEST + #define F77_zswap ZSWAPTEST + #define F77_zcopy ZCOPYTEST + #define F77_zaxpy ZAXPYTEST + #define F77_izamax IZAMAXTEST + #define F77_sdot SDOTTESTSUB + #define F77_ddot DDOTTESTSUB + #define F77_dsdot DSDOTTEST + #define F77_sscal SSCALTEST + #define F77_dscal DSCALTEST + #define F77_cscal CSCALTEST + #define F77_zscal ZSCALTEST + #define F77_csscal CSSCALTEST + #define F77_zdscal ZDSCALTEST + #define F77_cdotu CDOTUTEST + #define F77_cdotc CDOTCTEST + #define F77_zdotu ZDOTUTEST + #define F77_zdotc ZDOTCTEST + #define F77_snrm2 SNRM2TESTSUB + #define F77_sasum SASUMTESTSUB + #define F77_dnrm2 DNRM2TESTSUB + #define F77_dasum DASUMTESTSUB + #define F77_scnrm2 SCNRM2TESTSUB + #define F77_scasum SCASUMTESTSUB + #define F77_dznrm2 DZNRM2TESTSUB + #define F77_dzasum DZASUMTESTSUB + #define F77_sdsdot SDSDOTTEST +/* + * Level 2 BLAS + */ + #define F77_s2chke CS2CHKE + #define F77_d2chke CD2CHKE + #define F77_c2chke CC2CHKE + #define F77_z2chke CZ2CHKE + #define F77_ssymv CSSYMV + #define F77_ssbmv CSSBMV + #define F77_sspmv CSSPMV + #define F77_sger CSGER + #define F77_ssyr CSSYR + #define F77_sspr CSSPR + #define F77_ssyr2 CSSYR2 + #define F77_sspr2 CSSPR2 + #define F77_dsymv CDSYMV + #define F77_dsbmv CDSBMV + #define F77_dspmv CDSPMV + #define F77_dger CDGER + #define F77_dsyr CDSYR + #define F77_dspr CDSPR + #define F77_dsyr2 CDSYR2 + #define F77_dspr2 CDSPR2 + #define F77_chemv CCHEMV + #define F77_chbmv CCHBMV + #define F77_chpmv CCHPMV + #define F77_cgeru CCGERU + #define F77_cgerc CCGERC + #define F77_cher CCHER + #define F77_chpr CCHPR + #define F77_cher2 CCHER2 + #define F77_chpr2 CCHPR2 + #define F77_zhemv CZHEMV + #define F77_zhbmv CZHBMV + #define F77_zhpmv CZHPMV + #define F77_zgeru CZGERU + #define F77_zgerc CZGERC + #define F77_zher CZHER + #define F77_zhpr CZHPR + #define F77_zher2 CZHER2 + #define F77_zhpr2 CZHPR2 + #define F77_sgemv CSGEMV + #define F77_sgbmv CSGBMV + #define F77_strmv CSTRMV + #define F77_stbmv CSTBMV + #define F77_stpmv CSTPMV + #define F77_strsv CSTRSV + #define F77_stbsv CSTBSV + #define F77_stpsv CSTPSV + #define F77_dgemv CDGEMV + #define F77_dgbmv CDGBMV + #define F77_dtrmv CDTRMV + #define F77_dtbmv CDTBMV + #define F77_dtpmv CDTPMV + #define F77_dtrsv CDTRSV + #define F77_dtbsv CDTBSV + #define F77_dtpsv CDTPSV + #define F77_cgemv CCGEMV + #define F77_cgbmv CCGBMV + #define F77_ctrmv CCTRMV + #define F77_ctbmv CCTBMV + #define F77_ctpmv CCTPMV + #define F77_ctrsv CCTRSV + #define F77_ctbsv CCTBSV + #define F77_ctpsv CCTPSV + #define F77_zgemv CZGEMV + #define F77_zgbmv CZGBMV + #define F77_ztrmv CZTRMV + #define F77_ztbmv CZTBMV + #define F77_ztpmv CZTPMV + #define F77_ztrsv CZTRSV + #define F77_ztbsv CZTBSV + #define F77_ztpsv CZTPSV +/* + * Level 3 BLAS + */ + #define F77_s3chke CS3CHKE + #define F77_d3chke CD3CHKE + #define F77_c3chke CC3CHKE + #define F77_z3chke CZ3CHKE + #define F77_chemm CCHEMM + #define F77_cherk CCHERK + #define F77_cher2k CCHER2K + #define F77_zhemm CZHEMM + #define F77_zherk CZHERK + #define F77_zher2k CZHER2K + #define F77_sgemm CSGEMM + #define F77_ssymm CSSYMM + #define F77_ssyrk CSSYRK + #define F77_ssyr2k CSSYR2K + #define F77_strmm CSTRMM + #define F77_strsm CSTRSM + #define F77_dgemm CDGEMM + #define F77_dsymm CDSYMM + #define F77_dsyrk CDSYRK + #define F77_dsyr2k CDSYR2K + #define F77_dtrmm CDTRMM + #define F77_dtrsm CDTRSM + #define F77_cgemm CCGEMM + #define F77_csymm CCSYMM + #define F77_csyrk CCSYRK + #define F77_csyr2k CCSYR2K + #define F77_ctrmm CCTRMM + #define F77_ctrsm CCTRSM + #define F77_zgemm CZGEMM + #define F77_zsymm CZSYMM + #define F77_zsyrk CZSYRK + #define F77_zsyr2k CZSYR2K + #define F77_ztrmm CZTRMM + #define F77_ztrsm CZTRSM +#elif defined(NOCHANGE) + #define F77_xerbla xerbla +/* + * Level 1 BLAS + */ + #define F77_srotg srotgtest + #define F77_srotmg srotmgtest + #define F77_srot srottest + #define F77_srotm srotmtest + #define F77_drotg drotgtest + #define F77_drotmg drotmgtest + #define F77_drot drottest + #define F77_drotm drotmtest + #define F77_sswap sswaptest + #define F77_scopy scopytest + #define F77_saxpy saxpytest + #define F77_isamax isamaxtest + #define F77_dswap dswaptest + #define F77_dcopy dcopytest + #define F77_daxpy daxpytest + #define F77_idamax idamaxtest + #define F77_cswap cswaptest + #define F77_ccopy ccopytest + #define F77_caxpy caxpytest + #define F77_icamax icamaxtest + #define F77_zswap zswaptest + #define F77_zcopy zcopytest + #define F77_zaxpy zaxpytest + #define F77_izamax izamaxtest + #define F77_sdot sdottestsub + #define F77_ddot ddottestsub + #define F77_dsdot dsdottest + #define F77_sscal sscaltest + #define F77_dscal dscaltest + #define F77_cscal cscaltest + #define F77_zscal zscaltest + #define F77_csscal csscaltest + #define F77_zdscal zdscaltest + #define F77_cdotu cdotutest + #define F77_cdotc cdotctest + #define F77_zdotu zdotutest + #define F77_zdotc zdotctest + #define F77_snrm2 snrm2testsub + #define F77_sasum sasumtestsub + #define F77_dnrm2 dnrm2testsub + #define F77_dasum dasumtestsub + #define F77_scnrm2 scnrm2testsub + #define F77_scasum scasumtestsub + #define F77_dznrm2 dznrm2testsub + #define F77_dzasum dzasumtestsub + #define F77_sdsdot sdsdottest +/* + * Level 2 BLAS + */ + #define F77_s2chke cs2chke + #define F77_d2chke cd2chke + #define F77_c2chke cc2chke + #define F77_z2chke cz2chke + #define F77_ssymv cssymv + #define F77_ssbmv cssbmv + #define F77_sspmv csspmv + #define F77_sger csger + #define F77_ssyr cssyr + #define F77_sspr csspr + #define F77_ssyr2 cssyr2 + #define F77_sspr2 csspr2 + #define F77_dsymv cdsymv + #define F77_dsbmv cdsbmv + #define F77_dspmv cdspmv + #define F77_dger cdger + #define F77_dsyr cdsyr + #define F77_dspr cdspr + #define F77_dsyr2 cdsyr2 + #define F77_dspr2 cdspr2 + #define F77_chemv cchemv + #define F77_chbmv cchbmv + #define F77_chpmv cchpmv + #define F77_cgeru ccgeru + #define F77_cgerc ccgerc + #define F77_cher ccher + #define F77_chpr cchpr + #define F77_cher2 ccher2 + #define F77_chpr2 cchpr2 + #define F77_zhemv czhemv + #define F77_zhbmv czhbmv + #define F77_zhpmv czhpmv + #define F77_zgeru czgeru + #define F77_zgerc czgerc + #define F77_zher czher + #define F77_zhpr czhpr + #define F77_zher2 czher2 + #define F77_zhpr2 czhpr2 + #define F77_sgemv csgemv + #define F77_sgbmv csgbmv + #define F77_strmv cstrmv + #define F77_stbmv cstbmv + #define F77_stpmv cstpmv + #define F77_strsv cstrsv + #define F77_stbsv cstbsv + #define F77_stpsv cstpsv + #define F77_dgemv cdgemv + #define F77_dgbmv cdgbmv + #define F77_dtrmv cdtrmv + #define F77_dtbmv cdtbmv + #define F77_dtpmv cdtpmv + #define F77_dtrsv cdtrsv + #define F77_dtbsv cdtbsv + #define F77_dtpsv cdtpsv + #define F77_cgemv ccgemv + #define F77_cgbmv ccgbmv + #define F77_ctrmv cctrmv + #define F77_ctbmv cctbmv + #define F77_ctpmv cctpmv + #define F77_ctrsv cctrsv + #define F77_ctbsv cctbsv + #define F77_ctpsv cctpsv + #define F77_zgemv czgemv + #define F77_zgbmv czgbmv + #define F77_ztrmv cztrmv + #define F77_ztbmv cztbmv + #define F77_ztpmv cztpmv + #define F77_ztrsv cztrsv + #define F77_ztbsv cztbsv + #define F77_ztpsv cztpsv +/* + * Level 3 BLAS + */ + #define F77_s3chke cs3chke + #define F77_d3chke cd3chke + #define F77_c3chke cc3chke + #define F77_z3chke cz3chke + #define F77_chemm cchemm + #define F77_cherk ccherk + #define F77_cher2k ccher2k + #define F77_zhemm czhemm + #define F77_zherk czherk + #define F77_zher2k czher2k + #define F77_sgemm csgemm + #define F77_ssymm cssymm + #define F77_ssyrk cssyrk + #define F77_ssyr2k cssyr2k + #define F77_strmm cstrmm + #define F77_strsm cstrsm + #define F77_dgemm cdgemm + #define F77_dsymm cdsymm + #define F77_dsyrk cdsyrk + #define F77_dsyr2k cdsyr2k + #define F77_dtrmm cdtrmm + #define F77_dtrsm cdtrsm + #define F77_cgemm ccgemm + #define F77_csymm ccsymm + #define F77_csyrk ccsyrk + #define F77_csyr2k ccsyr2k + #define F77_ctrmm cctrmm + #define F77_ctrsm cctrsm + #define F77_zgemm czgemm + #define F77_zsymm czsymm + #define F77_zsyrk czsyrk + #define F77_zsyr2k czsyr2k + #define F77_ztrmm cztrmm + #define F77_ztrsm cztrsm +#endif + +void get_transpose_type(char *type, enum CBLAS_TRANSPOSE *trans); +void get_uplo_type(char *type, enum CBLAS_UPLO *uplo); +void get_diag_type(char *type, enum CBLAS_DIAG *diag); +void get_side_type(char *type, enum CBLAS_SIDE *side); + +#endif /* CBLAS_TEST_H */ diff --git a/kaldi_io/src/tools/ATLAS/include/clapack.h b/kaldi_io/src/tools/ATLAS/include/clapack.h new file mode 100644 index 0000000..c5dde3f --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/clapack.h @@ -0,0 +1,149 @@ +/* + * Automatically Tuned Linear Algebra Software v3.8.3 + * (C) Copyright 1999 R. Clint Whaley + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the ATLAS group or the names of its contributers may + * not be used to endorse or promote products derived from this + * software without specific written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef CLAPACK_H + +#define CLAPACK_H +#include "cblas.h" + +#ifndef ATLAS_ORDER + #define ATLAS_ORDER CBLAS_ORDER +#endif +#ifndef ATLAS_UPLO + #define ATLAS_UPLO CBLAS_UPLO +#endif +#ifndef ATLAS_DIAG + #define ATLAS_DIAG CBLAS_DIAG +#endif +int clapack_sgesv(const enum CBLAS_ORDER Order, const int N, const int NRHS, + float *A, const int lda, int *ipiv, + float *B, const int ldb); +int clapack_sgetrf(const enum CBLAS_ORDER Order, const int M, const int N, + float *A, const int lda, int *ipiv); +int clapack_sgetrs + (const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE Trans, + const int N, const int NRHS, const float *A, const int lda, + const int *ipiv, float *B, const int ldb); +int clapack_sgetri(const enum CBLAS_ORDER Order, const int N, float *A, + const int lda, const int *ipiv); +int clapack_sposv(const enum ATLAS_ORDER Order, const enum ATLAS_UPLO Uplo, + const int N, const int NRHS, float *A, const int lda, + float *B, const int ldb); +int clapack_spotrf(const enum ATLAS_ORDER Order, const enum ATLAS_UPLO Uplo, + const int N, float *A, const int lda); +int clapack_spotrs(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const int NRHS, const float *A, const int lda, + float *B, const int ldb); +int clapack_spotri(const enum ATLAS_ORDER Order, const enum ATLAS_UPLO Uplo, + const int N, float *A, const int lda); +int clapack_slauum(const enum ATLAS_ORDER Order, const enum ATLAS_UPLO Uplo, + const int N, float *A, const int lda); +int clapack_strtri(const enum ATLAS_ORDER Order,const enum ATLAS_UPLO Uplo, + const enum ATLAS_DIAG Diag,const int N, float *A, const int lda); + +int clapack_dgesv(const enum CBLAS_ORDER Order, const int N, const int NRHS, + double *A, const int lda, int *ipiv, + double *B, const int ldb); +int clapack_dgetrf(const enum CBLAS_ORDER Order, const int M, const int N, + double *A, const int lda, int *ipiv); +int clapack_dgetrs + (const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE Trans, + const int N, const int NRHS, const double *A, const int lda, + const int *ipiv, double *B, const int ldb); +int clapack_dgetri(const enum CBLAS_ORDER Order, const int N, double *A, + const int lda, const int *ipiv); +int clapack_dposv(const enum ATLAS_ORDER Order, const enum ATLAS_UPLO Uplo, + const int N, const int NRHS, double *A, const int lda, + double *B, const int ldb); +int clapack_dpotrf(const enum ATLAS_ORDER Order, const enum ATLAS_UPLO Uplo, + const int N, double *A, const int lda); +int clapack_dpotrs(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const int NRHS, const double *A, const int lda, + double *B, const int ldb); +int clapack_dpotri(const enum ATLAS_ORDER Order, const enum ATLAS_UPLO Uplo, + const int N, double *A, const int lda); +int clapack_dlauum(const enum ATLAS_ORDER Order, const enum ATLAS_UPLO Uplo, + const int N, double *A, const int lda); +int clapack_dtrtri(const enum ATLAS_ORDER Order,const enum ATLAS_UPLO Uplo, + const enum ATLAS_DIAG Diag,const int N, double *A, const int lda); + +int clapack_cgesv(const enum CBLAS_ORDER Order, const int N, const int NRHS, + void *A, const int lda, int *ipiv, + void *B, const int ldb); +int clapack_cgetrf(const enum CBLAS_ORDER Order, const int M, const int N, + void *A, const int lda, int *ipiv); +int clapack_cgetrs + (const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE Trans, + const int N, const int NRHS, const void *A, const int lda, + const int *ipiv, void *B, const int ldb); +int clapack_cgetri(const enum CBLAS_ORDER Order, const int N, void *A, + const int lda, const int *ipiv); +int clapack_cposv(const enum ATLAS_ORDER Order, const enum ATLAS_UPLO Uplo, + const int N, const int NRHS, void *A, const int lda, + void *B, const int ldb); +int clapack_cpotrf(const enum ATLAS_ORDER Order, const enum ATLAS_UPLO Uplo, + const int N, void *A, const int lda); +int clapack_cpotrs(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const int NRHS, const void *A, const int lda, + void *B, const int ldb); +int clapack_cpotri(const enum ATLAS_ORDER Order, const enum ATLAS_UPLO Uplo, + const int N, void *A, const int lda); +int clapack_clauum(const enum ATLAS_ORDER Order, const enum ATLAS_UPLO Uplo, + const int N, void *A, const int lda); +int clapack_ctrtri(const enum ATLAS_ORDER Order,const enum ATLAS_UPLO Uplo, + const enum ATLAS_DIAG Diag,const int N, void *A, const int lda); + +int clapack_zgesv(const enum CBLAS_ORDER Order, const int N, const int NRHS, + void *A, const int lda, int *ipiv, + void *B, const int ldb); +int clapack_zgetrf(const enum CBLAS_ORDER Order, const int M, const int N, + void *A, const int lda, int *ipiv); +int clapack_zgetrs + (const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE Trans, + const int N, const int NRHS, const void *A, const int lda, + const int *ipiv, void *B, const int ldb); +int clapack_zgetri(const enum CBLAS_ORDER Order, const int N, void *A, + const int lda, const int *ipiv); +int clapack_zposv(const enum ATLAS_ORDER Order, const enum ATLAS_UPLO Uplo, + const int N, const int NRHS, void *A, const int lda, + void *B, const int ldb); +int clapack_zpotrf(const enum ATLAS_ORDER Order, const enum ATLAS_UPLO Uplo, + const int N, void *A, const int lda); +int clapack_zpotrs(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, + const int N, const int NRHS, const void *A, const int lda, + void *B, const int ldb); +int clapack_zpotri(const enum ATLAS_ORDER Order, const enum ATLAS_UPLO Uplo, + const int N, void *A, const int lda); +int clapack_zlauum(const enum ATLAS_ORDER Order, const enum ATLAS_UPLO Uplo, + const int N, void *A, const int lda); +int clapack_ztrtri(const enum ATLAS_ORDER Order,const enum ATLAS_UPLO Uplo, + const enum ATLAS_DIAG Diag,const int N, void *A, const int lda); + +#endif diff --git a/kaldi_io/src/tools/ATLAS/include/contrib/ATL_gemv_ger_SSE.h b/kaldi_io/src/tools/ATLAS/include/contrib/ATL_gemv_ger_SSE.h new file mode 100644 index 0000000..118d3de --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/contrib/ATL_gemv_ger_SSE.h @@ -0,0 +1,188 @@ +#ifdef GER +#undef NO_TRANSPOSE +#define NO_TRANSPOSE +#endif + + +#if NDPM > 4 +#error Max NDPM is 4 +#endif + +#if !defined(ATL_SSE1) && ( defined(SREAL) || defined(SCPLX) ) +#error This routine needs ATL_SSE1 defined +#endif + +#if !defined(ATL_SSE2) && ( defined(DREAL) || defined(DCPLX) ) +#error This routine needs ATL_SSE2 defined +#endif + +#include +#include + +#include "camm_util.h" + +#ifndef GER +#if defined(BETAX) || defined(BETAXI0) +#include "camm_scale.h" +#endif +#endif + +#if NDPM >= 4 +#define EXT4 Mjoin(4dp,BLC) +#undef NDP +#define NDP 4 +#undef EXT +#define EXT EXT4 +#include "camm_dpa.h" +#endif + +#if NDPM >= 3 +#define EXT3 Mjoin(3dp,BLC) +#undef NDP +#define NDP 3 +#undef EXT +#define EXT EXT3 +#include "camm_dpa.h" +#endif + +#if NDPM >= 2 +#define EXT2 Mjoin(2dp,BLC) +#undef NDP +#define NDP 2 +#undef EXT +#define EXT EXT2 +#include "camm_dpa.h" +#endif + +#define EXT1 Mjoin(1dp,BLC) +#undef NDP +#define NDP 1 +#undef EXT +#define EXT EXT1 +#include "camm_dpa.h" + +#undef NDP +#define NDP NDPM +#undef EXT +#define EXT Mjoin(Mjoin(NDP,Mjoin(dp,BLC)),m) +#include "camm_dpa.h" + +#ifdef GER +#if defined(SCPLX) || defined(DCPLX) +#ifdef Conj_ +#define IM 1c +#else +#define IM 1u +#endif +#else +#define IM 1 +#endif + + +#define FN Mjoin(Mjoin(Mjoin(ATL_,PREC),Mjoin(ger,IM)),_a1_x1_yX) + +#undef MY_FUNCTION +#define MY_FUNCTION FN + +void +MY_FUNCTION(int m,int n, const SCALAR alpha,const TYPE *c, + int cinc,const TYPE *b,int binc, + TYPE *a,int lda) { + +#else + + +#define FN Mjoin(Mjoin(Mjoin(ATL_,PREC),gemv),Mjoin(FEXT,Mjoin(_a1_x1_,Mjoin(BL,_y1)))) + +#undef MY_FUNCTION +#define MY_FUNCTION FN + +void +MY_FUNCTION(int m,int n, const SCALAR alpha,const TYPE *a, + int lda,const TYPE *b,int binc, + const SCALAR beta,TYPE *c,int cinc) { + +#endif + + int i,mm,nn; + const TYPE *ae; +#ifdef NO_TRANSPOSE + int len=m,w=n; +#define zz b +#else + int len=n,w=m; +#define zz c +#endif + +#ifdef GER +#define zzinc binc +#else +#define zzinc 1 + + +#if defined(NO_TRANSPOSE) && defined(BETA0) + memset(c,0,m*sizeof(*c)); +#endif + +#if defined(BETAX) || defined(BETAXI0) +#if defined(SCPLX) || defined(DCPLX) + SCALE(beta,c,m); +#endif +#if defined(SREAL) || defined(DREAL) + SCALE(&beta,c,m); +#endif +#endif + +#endif + + ae=a+w*lda; + nn=STRIDE*lda; + + +#if NDPM == 1 + for (;a 1 + if (((ae-a)/lda)%STRIDE) + mm++; +#endif + + if (mm == 1) + Mjoin(dp,EXT1)(a,nn,b,c,STRIDE*zzinc,len); + +#if ( NDPM == 2 && STRIDE > 1 ) || NDPM > 2 + else if (mm == 2) + Mjoin(dp,EXT2)(a,nn,b,c,STRIDE*zzinc,len); +#endif + +#if ( NDPM == 3 && STRIDE > 1 ) || NDPM > 3 + else if (mm == 3) + Mjoin(dp,EXT3)(a,nn,b,c,STRIDE*zzinc,len); +#endif + +#if ( NDPM == 4 && STRIDE > 1 ) || NDPM > 4 + else if (mm == 4) + Mjoin(dp,EXT4)(a,nn,b,c,STRIDE*zzinc,len); +#endif + + + } + +#endif + +} + diff --git a/kaldi_io/src/tools/ATLAS/include/contrib/Make.ext b/kaldi_io/src/tools/ATLAS/include/contrib/Make.ext new file mode 100644 index 0000000..f7f9a0a --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/contrib/Make.ext @@ -0,0 +1,39 @@ + +topd = /home/whaley/atlas3.8/AtlasBase +incs = -def topd /home/whaley/atlas3.8/AtlasBase \ + -def incd /home/whaley/atlas3.8/AtlasBase/Clint \ + -def BASEdir /home/whaley/atlas3.8/AtlasBase/Antoine/ \ + -def basd /home/whaley/atlas3.8/AtlasBase/Clint +ext = extract +extF = $(ext) -langF -lnlen71 -Remtblank -llwarn2 -LAPACK1 $(incs) +extC = $(ext) -langC -lnlen79 -Remtblank -llwarn2 $(incs) +extM = $(ext) -langM -lnlen79 -llwarn2 $(incs) + +default: all +force_build: +basd = /home/whaley/atlas3.8/AtlasBase/Clint +basdRCW = /home/whaley/atlas3.8/AtlasBase/Clint +basdAPP = /home/whaley/atlas3.8/AtlasBase/Antoine +incf = /home/whaley/atlas3.8/AtlasBase/gen.inc + +files = ATL_gemv_ger_SSE.h SSE3Dnow.h camm_dpa.h camm_pipe3.h camm_scale.h \ + camm_strat1.h camm_tpipe.h camm_util.h + +all : $(files) + +camm_strat1.h : $(topd)/kernel/CammMaguire/camm_strat1.h + cp $(topd)/kernel/CammMaguire/camm_strat1.h . +camm_tpipe.h : $(topd)/kernel/CammMaguire/camm_tpipe.h + cp $(topd)/kernel/CammMaguire/camm_tpipe.h . +camm_pipe3.h : $(topd)/kernel/CammMaguire/camm_pipe3.h + cp $(topd)/kernel/CammMaguire/camm_pipe3.h . +ATL_gemv_ger_SSE.h : $(topd)/kernel/CammMaguire/ATL_gemv_ger_SSE.h + cp $(topd)/kernel/CammMaguire/ATL_gemv_ger_SSE.h . +camm_util.h : $(topd)/kernel/CammMaguire/camm_util.h + cp $(topd)/kernel/CammMaguire/camm_util.h . +camm_scale.h : $(topd)/kernel/CammMaguire/camm_scale.h + cp $(topd)/kernel/CammMaguire/camm_scale.h . +camm_dpa.h : $(topd)/kernel/CammMaguire/camm_dpa.h + cp $(topd)/kernel/CammMaguire/camm_dpa.h . +SSE3Dnow.h : $(topd)/kernel/PeterSoendergaard/SSE3Dnow.h + cp $(topd)/kernel/PeterSoendergaard/SSE3Dnow.h . diff --git a/kaldi_io/src/tools/ATLAS/include/contrib/SSE3Dnow.h b/kaldi_io/src/tools/ATLAS/include/contrib/SSE3Dnow.h new file mode 100644 index 0000000..a783749 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/contrib/SSE3Dnow.h @@ -0,0 +1,709 @@ +#if !defined(ATL_GAS_x8632) && !defined(ATL_GAS_x8664) + #error "This kernel requires gas x86 assembler!" +#endif +#ifndef Mstr /* Added by RCW to make multiline macros work */ + #define Mstr2(m) # m + #define Mstr(m) Mstr2(m) +#endif +/* The mening of the defined macros is as follows: + * VECLEN: The length of a singleprecision vector register + * vec_add: Add to single precision vectors. + * vec_mul: Multiply to single precision vectors. + * vec_mov: Moves data around + * vec_mov1: Load one element in a vector and zero all other entries! + * vec_splat: Load one element relpicated in all positions in the vector. + * vec_load_apart: Load elements from different memory positions into a register. + * vec_sum: Sums a register. + * vec_store_one: Stores lowest element in vector to memory, no zero-extend! + * Meaning of suffixes is as follows: + * mr means memory to register + * rr means register to register + * rm means register to memory + * a means that instruction needs aligned data + * 1 means that the instructions only operates on the lowest element of the + * vector. + * + * The _1 instructions work under one important assumption: That you never mix + * them with regular instructions, e.g. loading into a register with a normal + * mov, and then using add_rr_1 will not work under 3dnow! since it is in + * reality a normal add. However, if using a mov_1 first, the upper part of + * the register will be zeroed, and it will therefore work. The _1 system is + * more robust under SSE, but other architectures might be implemented the + * same way as 3dnow! + * + * RCW: I added the following functionality for SSE only (note that vw may + * be overwritten with intermediate results, but is not used as input, + * and that all input array may be overwritten wt intermediate results. + * VL : vector length -1): + * vec_red(vd, vw) : vd[0] = sum(vd[0:VL]) + * vec_red2(v1, v2, vw) : v1[0] = sum(v1[0:VL]); v1[1] = sum(v2[0:VL]) + * vec_red4(v0, v1, v2, v3 vw1, vw2) : + * v0[0] = sum(v0[0:VL]); v0[1] = sum(v1[0:VL]) + * if type = double: + * v2[0] = sum(v2[0:VL]); v2[1] = sum(v3[0:VL]) + * else + * v0[2] = sum(v2[0:VL]); v0[3] = sum(v3[0:VL]) + * vec_zero(vd) : vd[0:VL] = 0.0 + */ + + +/* Things to try: + * Non-temporal stores + * Sequences of instructions instead of movups + * + * + * + * + */ + + + +#define gen_vec_rr(op,reg1,reg2) \ + __asm__ __volatile__ (#op " " #reg1 ", " #reg2 \ + : /* nothing */ \ + : /* nothing */) + + +#define w(p) p + +#define nop() __asm__ __volatile__ ("nop") + +#define rep() __asm__ __volatile__ ("rep") + +#define align() __asm__ __volatile__ (".align 16") + + +#ifdef x87double + +#define st0 %%st(0) +#define st1 %%st(1) +#define st2 %%st(2) +#define st3 %%st(3) +#define st4 %%st(4) +#define st5 %%st(5) +#define st6 %%st(6) +#define st7 %%st(7) + + +#define gen_stack_rt(op,reg) \ + __asm__ __volatile__ (#op " " #reg \ + : /* nothing */ \ + : /* nothing */) + +#define gen_stack_tr(op,reg) \ + __asm__ __volatile__ (#op " %%st(0)," #reg \ + : \ + : ) + + +#define gen_stack_rr(op,reg1,reg2) \ + __asm__ __volatile__ (#op " " #reg1 ", " #reg2 \ + : /* nothing */ \ + : /* nothing */) + +#define gen_stack_t(op) \ + __asm__ __volatile__ (#op \ + : /* nothing */ \ + : /* nothing */) + + +#define gen_stack_tm(op,mem) \ + __asm__ __volatile__ (#op " %0" \ + : "=m" (((mem)[0])) \ + : ) + +#define gen_stack_mt(op,mem) \ + __asm__ __volatile__ (#op " %0" \ + : \ + : "m" (((mem)[0]))) + + +#define stack_mov_mt_push(mem) gen_stack_mt(fldl,mem) + +#define stack_add_tr_pop(reg) gen_stack_tr(faddp,reg) +#define stack_add_mt(mem) gen_stack_mt(faddl,mem) + +#define stack_mul_tr(reg) gen_stack_tr(fmul,reg) +#define stack_mul_tr_pop(reg) gen_stack_tr(fmulp,reg) +#define stack_mul_mt(mem) gen_stack_mt(fmul,mem) + +#define stack_mov_tm_pop(mem) gen_stack_tm(fstpl,mem) + +#define stack_zero_push() gen_stack_t(fldz) + +#endif /* x87double */ + +#ifdef SSE + +/* Peculiarities of SSE: Alignment is good, but not mandatory. It is possible to + * load/store from misaligned adresses using movups at a cost of some cycles. Loading + * using mul/add must always be aligned. Alignment is 16 bytes. + * No muladd. + */ + + + +#define gen_vec_mr(op,mem,reg) \ + __asm__ __volatile__ (#op " %0, " #reg \ + : /* nothing */ \ + : "m" (((mem)[0])), "m" (((mem)[1])), "m" (((mem)[2])), "m" (((mem)[3]))) + + +#define gen_vec_rm(op,reg,mem) \ + __asm__ __volatile__ (#op " " #reg ", %0" \ + : "=m" (((mem)[0])), "=m" (((mem)[1])), "=m" (((mem)[2])), "=m" (((mem)[3])) \ + : /* nothing */ ) + + + + +#define VECLEN 4 + +#define reg0 %%xmm0 +#define reg1 %%xmm1 +#define reg2 %%xmm2 +#define reg3 %%xmm3 +#define reg4 %%xmm4 +#define reg5 %%xmm5 +#define reg6 %%xmm6 +#define reg7 %%xmm7 +#ifdef ATL_GAS_x8664 + #define reg8 %%xmm8 + #define reg9 %%xmm9 + #define reg10 %%xmm10 + #define reg11 %%xmm11 + #define reg12 %%xmm12 + #define reg13 %%xmm13 + #define reg14 %%xmm14 + #define reg15 %%xmm15 +#endif + +#define vec_mov_mr(mem,reg) gen_vec_mr(movups,mem,reg) +#define vec_mov_rm(reg,mem) gen_vec_rm(movups,reg,mem) +#define vec_mov_mr_a(mem,reg) gen_vec_mr(movaps,mem,reg) +#define vec_mov_rm_a(reg,mem) gen_vec_rm(movaps,reg,mem) +#define vec_mov_rr(reg1,reg2) gen_vec_rr(movaps,reg1,reg2) + +#define vec_add_mr_a(mem,reg) gen_vec_mr(addps,mem,reg) +#define vec_mul_mr_a(mem,reg) gen_vec_mr(mulps,mem,reg) + +#define vec_add_rr(mem,reg) gen_vec_rr(addps,mem,reg) +#define vec_mul_rr(mem,reg) gen_vec_rr(mulps,mem,reg) + +#define vec_mov_mr_1(mem,reg) gen_vec_mr(movss,mem,reg) +#define vec_mov_rm_1(reg,mem) gen_vec_rm(movss,reg,mem) +#define vec_mov_rr_1(reg1,reg2) gen_vec_rr(movss,reg1,reg2) + +#define vec_add_mr_1(mem,reg) gen_vec_mr(addss,mem,reg) +#define vec_add_rr_1(reg1,reg2) gen_vec_rr(addss,reg1,reg2) + +#define vec_mul_mr_1(mem,reg) gen_vec_mr(mulss,mem,reg) +#define vec_mul_rr_1(reg1,reg2) gen_vec_rr(mulss,reg1,reg2) + +#define vec_unpack_low(reg1,reg2) gen_vec_rr(unpcklps,reg1,reg2) +#define vec_unpack_high(reg1,reg2) gen_vec_rr(unpckhps,reg1,reg2) +#define vec_shuffle(mode,reg1,reg2) vec_shuffle_wrap(mode,reg1,reg2) +#define vec_shuffle_wrap(mode,reg1,reg2) \ + __asm__ __volatile__ ("shufps " #mode ", " #reg1 ", " #reg2 \ + : /* nothing */\ + : /* nothing */) + +/* Hack! */ +/* To use this instruction be sure that register 7 is not in use!!! */ +/* It must be possible to reduce this sequence to only four instructions. + * please tell me how! */ +#define vec_sum(reg) vec_sum_wrap(reg) +#define vec_sum_wrap(reg) \ + __asm__ __volatile__ ("movhlps " #reg ", %%xmm7\n"\ + "addps " #reg ", %%xmm7\n"\ + "movaps %%xmm7, " #reg "\n"\ + "shufps $1, " #reg ", %%xmm7\n"\ + "addss %%xmm7, " #reg "\n"\ + : /* nothing */\ + : /* nothing */) + +/* RCW: added to safely replace vec_sum (vec reduce), and use SSE3 when avail */ +#define vec_zero(vd) __asm__ __volatile__("xorps " Mstr(vd) ", " Mstr(vd) ::) +#ifdef ATL_SSE3 + #define vec_red(vr, vwrk) \ + __asm__ __volatile__("haddps " Mstr(vr) ", " Mstr(vr) "\n"\ + "haddps " Mstr(vr) ", " Mstr(vr) "\n" ::) +/* + * haddps v1 v0 # v0 = {v1cd, v1ab, v0cd, v0ab} + * haddps v0 v0 # v0 = {v1abcd, v0abcd, v1abcd, v0abcd} + */ + #define vec_red2(v0, v1, vwork) \ + __asm__ __volatile__("haddps " Mstr(v1) ", " Mstr(v0) "\n"\ + "haddps " Mstr(v0) ", " Mstr(v0) "\n" ::) +/* + * haddps v1, v0 # v0 = {v1cd,v1ab,v0cd,v0ab} + * haddps v3, v2 # v2 = {v3cd,v3ab,v2cd,v2ab} + * haddps v2, v0 # v0 = {v3abcd,v2abcd,v1abcd, v0abcd} + */ + #define vec_red4(v0, v1, v2, v3, w0, w1) \ + __asm__ __volatile__("haddps " Mstr(v1) ", " Mstr(v0) "\n"\ + "haddps " Mstr(v3) ", " Mstr(v2) "\n"\ + "haddps " Mstr(v2) ", " Mstr(v0) "\n" ::) +#elif defined(ATL_SSE2) + #define vec_red(vr, vwrk) \ + __asm__ __volatile__ ("pshufd $0xEE, " Mstr(vr) ", " Mstr(vwrk) "\n"\ + "addps " Mstr(vwrk) ", " Mstr(vr) "\n"\ + "pshufd $0xE5, " Mstr(vr) ", " Mstr(vwrk) "\n"\ + "addss " Mstr(vwrk) ", " Mstr(vr) "\n"\ + ::) +#else + #define vec_red(vr, vwrk) \ + __asm__ __volatile__ ("movhlps " Mstr(vr) ", " Mstr(vwrk) "\n"\ + "addps " Mstr(vwrk) ", " Mstr(vr) "\n"\ + "movaps " Mstr(vr) ", " Mstr(vwrk) "\n"\ + "shufps $0xE5, " Mstr(vr) ", " Mstr(vr) "\n"\ + "addss " Mstr(vwrk) ", " Mstr(vr) "\n"\ + ::) +#endif +#ifndef ATL_SSE3 /* codes that are the same for SSE2 and SSE1 */ +/* + # v0 = {v0d,v0c,v0b,v0a} + # v1 = {v1d,v1c,v1b,v1a} + movaps v0, vw # vw = {v0d,v0c,v0b,v0a} + unpacklps v1, v0 # v0 = {v1b,v0b,v1a,v0a} + unpackhps v1, vw # vw = {v1d,v0d,v1c,v0c} + addps vw, v0 # v0 = {v1bd,v0bd,v1ac,v0ac} + movhlps v0, vw # vw = {X , X,v1bd,v0bd} + addps vw, v0 # v0 = {X , X,v1abcd,v0abcd} +*/ + #define vec_red2(v0, v1, vw) \ + __asm__ __volatile__ ("movaps " Mstr(v0) ", " Mstr(vw) "\n"\ + "unpcklps " Mstr(v1) ", " Mstr(v0) "\n"\ + "unpckhps " Mstr(v1) ", " Mstr(vw) "\n"\ + "addps " Mstr(vw) ", " Mstr(v0) "\n"\ + "movhlps " Mstr(v0) ", " Mstr(vw) "\n"\ + "addps " Mstr(vw) ", " Mstr(v0) "\n"\ + ::) +/* + * movaps v0, w0 # w0 = {v0d, v0c, v0b, v0a} + * unpcklps v1, v0 # v0 = {v1b, v0b, v1a, v0a} + * movaps v2, w1 # w1 = {v2d, v2c, v2b, v2a} + * unpckhps v1, w0 # w0 = {v1d, v0d, v1c, v0c} + * unpcklps v3, v2 # v2 = {v3b, v2b, v3a, v2a} + * addps w0, v0 # v0 = {v1bd, v0bd, v1ac, v0ac} + * unpckhps v3, w1 # w1 = {v3d, v2d, v3c, v2c} + * movaps v0, w0 # w0 = {v1bd, v0bd, v1ac, v0ac} + * addps w1, v2 # v2 = {v3bd, v2bd, v3ac, v2ac} + * shufps $0x44,v2,v0 # v0 = {v3ac, v2ac, v1ac, v0ac} + * shufps $0xEE,v2,w0 # w0 = {v3bd, v2bd, v1bd, v0bd} + * addps w0, v0 # v0 = {v3abcd, v2abcd, v1abcd, v0abcd} + */ + #define vec_red4(v0, v1, v2, v3, w0, w1) \ + __asm__ __volatile__ ("movaps " Mstr(v0) ", " Mstr(w0) "\n"\ + "unpcklps " Mstr(v1) ", " Mstr(v0) "\n"\ + "movaps " Mstr(v2) ", " Mstr(w1) "\n"\ + "unpckhps " Mstr(v1) ", " Mstr(w0) "\n"\ + "unpcklps " Mstr(v3) ", " Mstr(v2) "\n"\ + "addps " Mstr(w0) ", " Mstr(v0) "\n"\ + "unpckhps " Mstr(v3) ", " Mstr(w1) "\n"\ + "movaps " Mstr(v0) ", " Mstr(w0) "\n"\ + "addps " Mstr(w1) ", " Mstr(v2) "\n"\ + "shufps $0x44, " Mstr(v2) ", " Mstr(v0) "\n"\ + "shufps $0xEE, " Mstr(v2) ", " Mstr(w0) "\n"\ + "addps " Mstr(w0) ", " Mstr(v0) "\n"\ + ::) +#endif + +#define vec_splat(mem,reg) vec_splat_wrap(mem,reg) +#define vec_splat_wrap(mem,reg) \ + __asm__ __volatile__ ("movss %0, " #reg "\n"\ + "unpcklps " #reg ", " #reg "\n"\ + "movlhps " #reg ", " #reg "\n"\ + : /* nothing */ \ + : "m" ((mem)[0])) + + +/* This instruction sequence appears courtesy of Camm Maguire. */ +#define vec_sum_full(reg0,reg1,reg2,reg3,regout,empty0,empty1) vec_sum_full_wrap(reg0,reg1,reg2,reg3,regout,empty0,empty1) +#define vec_sum_full_wrap(reg0,reg1,reg2,reg3,regout,empty0,empty1) \ + __asm__ __volatile__ ("movaps " #reg0 "," #empty0 "\n"\ + "unpcklps " #reg1 "," #reg0 "\n"\ + "movaps " #reg2 "," #empty1 "\n"\ + "unpckhps " #reg1 "," #empty0 "\n"\ + "unpcklps " #reg3 "," #reg2 "\n"\ + "addps " #empty0 "," #reg0 "\n"\ + "unpckhps " #reg3 "," #empty1 "\n"\ + "movaps " #reg0 "," #regout "\n"\ + "addps " #empty1 "," #reg2 "\n"\ + "shufps $0x44," #reg2 "," #reg0 "\n"\ + "shufps $0xee," #reg2 "," #regout "\n"\ + "addps " #reg0 "," #regout "\n"\ + : /* nothing */ \ + : /* nothing */) + + + +typedef float vector[VECLEN]; + +#endif /* end ifdef SSE */ + + +#ifdef SSE2 + +/* Peculiarities of SSE: Alignment is good, but not mandatory. It is possible to + * load/store from misaligned adresses using movups at a cost of some cycles. Loading + * using mul/add must always be aligned. Alignment is 16 bytes. + * No muladd. + */ + + + +#define gen_vec_mr(op,mem,reg) \ + __asm__ __volatile__ (#op " %0, " #reg \ + : /* nothing */ \ + : "m" (((mem)[0])), "m" (((mem)[1]))) + + +#define gen_vec_rm(op,reg,mem) \ + __asm__ __volatile__ (#op " " #reg ", %0" \ + : "=m" (((mem)[0])), "=m" (((mem)[1])) \ + : /* nothing */ ) + + + + +#define VECLEN 2 + +#define reg0 %%xmm0 +#define reg1 %%xmm1 +#define reg2 %%xmm2 +#define reg3 %%xmm3 +#define reg4 %%xmm4 +#define reg5 %%xmm5 +#define reg6 %%xmm6 +#define reg7 %%xmm7 +#ifdef ATL_GAS_x8664 + #define reg8 %%xmm8 + #define reg9 %%xmm9 + #define reg10 %%xmm10 + #define reg11 %%xmm11 + #define reg12 %%xmm12 + #define reg13 %%xmm13 + #define reg14 %%xmm14 + #define reg15 %%xmm15 +#endif + + +#define vec_mov_mr(mem,reg) gen_vec_mr(movupd,mem,reg) +#define vec_mov_rm(reg,mem) gen_vec_rm(movupd,reg,mem) +#define vec_mov_mr_a(mem,reg) gen_vec_mr(movapd,mem,reg) +#define vec_mov_rm_a(reg,mem) gen_vec_rm(movapd,reg,mem) +#define vec_mov_rr(reg1,reg2) gen_vec_rr(movapd,reg1,reg2) + +#define vec_add_mr_a(mem,reg) gen_vec_mr(addpd,mem,reg) +#define vec_mul_mr_a(mem,reg) gen_vec_mr(mulpd,mem,reg) + +#define vec_add_rr(mem,reg) gen_vec_rr(addpd,mem,reg) +#define vec_mul_rr(mem,reg) gen_vec_rr(mulpd,mem,reg) + +#define vec_mov_mr_1(mem,reg) gen_vec_mr(movsd,mem,reg) +#define vec_mov_rm_1(reg,mem) gen_vec_rm(movsd,reg,mem) +#define vec_mov_rr_1(reg1,reg2) gen_vec_rr(movsd,reg1,reg2) + +#define vec_add_mr_1(mem,reg) gen_vec_mr(addsd,mem,reg) +#define vec_add_rr_1(reg1,reg2) gen_vec_rr(addsd,reg1,reg2) + +#define vec_mul_mr_1(mem,reg) gen_vec_mr(mulsd,mem,reg) +#define vec_mul_rr_1(reg1,reg2) gen_vec_rr(mulsd,reg1,reg2) + +#define vec_splat(mem,reg) vec_splat_wrap(mem,reg) +#define vec_splat_wrap(mem,reg) \ + __asm__ __volatile__ ("movsd %0, " #reg "\n"\ + "unpcklpd " #reg ", " #reg \ + : /* nothing */ \ + : "m" ((mem)[0])) + +/* Hack! */ +/* To use this instruction be sure that register 7 is not in use!!! */ +#define vec_sum(reg) vec_sum_wrap(reg) +#define vec_sum_wrap(reg) \ + __asm__ __volatile__ ("movhlps " #reg ", %%xmm7\n"\ + "addpd %%xmm7, " #reg "\n"\ + : /* nothing */\ + : /* nothing */) +/* + * Added by RCW to improve performance and avoid xmm7 hack (replace vec_sum) + */ +#define vec_zero(vd) __asm__ __volatile__("xorps " Mstr(vd) ", " Mstr(vd) ::) +#ifdef ATL_SSE3 + #define vec_red(vr, vwrk) \ + __asm__ __volatile__("haddpd " Mstr(vr) ", " Mstr(vr) "\n" ::) + #define vec_red2(v0, v1, vw) \ + __asm__ __volatile__("haddpd " Mstr(v1) ", " Mstr(v0) "\n" ::) + #define vec_red4(v0, v1, v2, v3, w0, w1) \ + __asm__ __volatile__("haddpd " Mstr(v1) ", " Mstr(v0) "\n"\ + "haddpd " Mstr(v3) ", " Mstr(v2) "\n"\ + ::) +#else + #define vec_red(vr, vwrk) \ + __asm__ __volatile__ ("pshufd $0xEE, " Mstr(vr) ", " Mstr(vwrk) "\n"\ + "addsd " Mstr(vwrk) ", " Mstr(vr) "\n" ::) +/* + * movapd v0, vw # vw = {v0b, v0a} + * unpcklpd v1,v0 # v0 = {v1a, v0a} + * unpckhpd v1, vw # vw = {v1b, v0b} + * addpd vw, v0 # v0 = {v1ab,v0ab} + */ + #define vec_red2(v0, v1, vw) \ + __asm__ __volatile__("movapd " Mstr(v0) ", " Mstr(vw) "\n"\ + "unpcklpd " Mstr(v1) ", " Mstr(v0) "\n"\ + "unpckhpd " Mstr(v1) ", " Mstr(vw) "\n"\ + "addpd " Mstr(vw) ", " Mstr(v0) "\n"\ + ::) +/* + * movapd v0, w0 # w0 = {v0b, v0a} + * movapd v2, w1 # w1 = {v2b, v2a} + * unpcklpd v1, v0 # v0 = {v1a, v0a} + * unpcklpd v3, v2 # v2 = {v3a, v2a} + * unpckhpd v1, w0 # w0 = {v1b, v0b} + * unpckhpd v3, w1 # w1 = {v3b, v2b} + * addpd w0, v0 # v0 = {v1ab, v0ab} + * addpd w1, v2 # v2 = {v3ab, v2ab} + */ + #define vec_red4(v0, v1, v2, v3, w0, w1) \ + __asm__ __volatile__("movapd " Mstr(v0) ", " Mstr(w0) "\n"\ + "movapd " Mstr(v2) ", " Mstr(w1) "\n"\ + "unpcklpd " Mstr(v1) ", " Mstr(v0) "\n"\ + "unpcklpd " Mstr(v3) ", " Mstr(v2) "\n"\ + "unpckhpd " Mstr(v1) ", " Mstr(w0) "\n"\ + "unpckhpd " Mstr(v3) ", " Mstr(w1) "\n"\ + "addpd " Mstr(w0) ", " Mstr(v0) "\n"\ + "addpd " Mstr(w1) ", " Mstr(v2) "\n"\ + ::) +#endif + +#define vec_sum_full(reg1,reg2,empty1) vec_sum_full_wrap(reg1,reg2,empty1) +#define vec_sum_full_wrap(reg1,reg2,empty1) \ + __asm__ __volatile__ ("movhlps " #reg2 ", " #empty1 "\n"\ + "movlhps " #reg2 ", " #empty1 "\n"\ + "addpd " #empty1 ", " #reg1 "\n"\ + : /* nothing */\ + : /* nothing */) + + +typedef double vector[VECLEN]; + +#endif /* end ifdef SSE2 */ + + +#ifdef THREEDNOW + +/* Peculiarities of 3DNOW. Alignment is not an issue, + * all alignments are legal, however alignment gives a speed increase. + * The vec_acc instruction can be used to sum to registers at once more efficiently + * than a series of vec_sum and vec_store_one + * No muladd. + */ + + +#define gen_vec_mr(op,mem,reg) \ + __asm__ __volatile__ (#op " %0, " #reg \ + : /* nothing */ \ + : "m" (((mem)[0])), "m" (((mem)[1]))) + +#define gen_vec_rm(op,reg,mem) \ + __asm__ __volatile__ (#op " " #reg ", %0" \ + : "=m" (((mem)[0])), "=m" (((mem)[1])) \ + : /* nothing */ ) + + + + +#define VECLEN 2 + +#define reg0 %%mm0 +#define reg1 %%mm1 +#define reg2 %%mm2 +#define reg3 %%mm3 +#define reg4 %%mm4 +#define reg5 %%mm5 +#define reg6 %%mm6 +#define reg7 %%mm7 + +#define vec_add_mr(mem,reg) gen_vec_mr(pfadd,mem,reg) +#define vec_mul_mr(mem,reg) gen_vec_mr(pfmul,mem,reg) +#define vec_mov_mr(mem,reg) gen_vec_mr(movq,mem,reg) +#define vec_mov_rm(reg,mem) gen_vec_rm(movq,reg,mem) +#define vec_add_rr(reg1,reg2) gen_vec_rr(pfadd,reg1,reg2) +#define vec_mul_rr(reg1,reg2) gen_vec_rr(pfmul,reg1,reg2) +#define vec_acc_rr(reg1,reg2) gen_vec_rr(pfacc,reg1,reg2) +#define vec_mov_rr(reg1,reg2) gen_vec_rr(movq,reg1,reg2) + +#define vec_sum(reg) gen_vec_rr(pfacc,reg,reg) +#define vec_sum_full(reg1,reg2) gen_vec_rr(pfacc,reg1,reg2) + +#define vec_mov_mr_1(mem,reg) gen_vec_mr(movd,mem,reg) +#define vec_mov_rm_1(reg,mem) gen_vec_rm(movd,reg,mem) +#define vec_mov_rr_1(reg1,reg2) gen_vec_rr(movd,reg1,reg2) + +#define vec_add_rr_1(reg1,reg2) gen_vec_rr(pfadd,reg1,reg2) +#define vec_mul_rr_1(reg1,reg2) gen_vec_rr(pfmul,reg1,reg2) + + +#define vec_splat(mem,reg) vec_splat_wrap(mem,reg) +#define vec_splat_wrap(mem,reg) \ + __asm__ __volatile__ ("movd %0, " #reg "\n"\ + "punpckldq " #reg ", " #reg \ + : /* nothing */ \ + : "m" ((mem)[0])) + + +#define vec_load_apart(mem1,mem2,reg) vec_load_apart_wrap(mem1,mem2,reg) +#define vec_load_apart_wrap(mem1,mem2,reg) \ + __asm__ __volatile__ ("movd %0, " #reg "\n"\ + "punpckldq %1, " #reg \ + : /* nothing */ \ + : "m" ((mem1)[0]), "m" (((mem2)[0]))) + + +#define vec_zero(reg) gen_vec_rr(pxor,reg,reg) + +#define vec_enter() __asm__ __volatile__ ("femms") +#define vec_exit() __asm__ __volatile__ ("femms") + +#define align() __asm__ __volatile__ (".align 16") + + +typedef float vector[VECLEN]; + +#endif + + + + + +#ifdef ALTIVEC + +#define VECLEN 4 + +#define reg0 %%vr0 +#define reg1 %%vr1 +#define reg2 %%vr2 +#define reg3 %%vr3 +#define reg4 %%vr4 +#define reg5 %%vr5 +#define reg6 %%vr6 +#define reg7 %%vr7 +#define reg8 %%vr8 +#define reg9 %%vr9 +#define reg10 %%vr10 +#define reg11 %%vr11 +#define reg12 %%vr12 +#define reg13 %%vr13 +#define reg14 %%vr14 +#define reg15 %%vr15 +#define reg16 %%vr16 +#define reg17 %%vr17 +#define reg18 %%vr18 +#define reg19 %%vr19 +#define reg20 %%vr20 +#define reg21 %%vr21 +#define reg22 %%vr22 +#define reg23 %%vr23 +#define reg24 %%vr24 +#define reg25 %%vr25 +#define reg26 %%vr26 +#define reg27 %%vr27 +#define reg28 %%vr28 +#define reg29 %%vr29 +#define reg30 %%vr30 +#define reg31 %%vr31 + +#define gen_vec_mr(op,mem,reg) \ + __asm__ __volatile__ (#op " %0, " #reg \ + : /* nothing */ \ + : "m" (((mem)[0])), "m" (((mem)[1])), "m" (((mem)[2])), "m" (((mem)[3]))) + + +#define gen_vec_rm(op,reg,mem) \ + __asm__ __volatile__ (#op " " #reg ", %0" \ + : "=m" (((mem)[0])), "=m" (((mem)[1])), "=m" (((mem)[2])), "=m" (((mem)[3])) \ + : /* nothing */ ) + + +#define gen_alti3(op,reg1,reg2,regout) \ + __asm__ __volatile__ (#op " " #reg1 ", " #reg2 ", " #regout \ + : /* nothing */ \ + : /* nothing */) + +#define gen_alti_muladd(op,reg1,reg2,regout) \ + __asm__ __volatile__ (#op " " #reg1 ", " #reg2 ", " #regout ", " #regout \ + : /* nothing */ \ + : /* nothing */) + + + +#define vec_mov_mr_a(mem,reg) gen_vec_mr(lvx,mem,reg) +#define vec_mov_rm_a(reg,mem) gen_vec_rm(svx,reg,mem) +#define vec_muladd(reg1,reg2,regout) gen_alti3(vmaddfp,reg1,reg2,regout) + +#define vec_zero(reg) gen_alti3(vxor,reg,reg,reg) + + +typedef float vector[VECLEN]; + +#endif + + +#ifdef ALTIVEC_C + +/* These macros have been written by, or greatly inspired by, + * Nicholas A. Coult . Thanks. + */ + +/* assumes that last four registers are not in use! */ +#define transpose(x0,x1,x2,x3) \ +reg28 = vec_mergeh(x0,x2); \ +reg29 = vec_mergeh(x1,x3); \ +reg30 = vec_mergel(x0,x2); \ +reg31 = vec_mergel(x1,x3); \ +x0 = vec_mergeh(reg28,reg29); \ +x1 = vec_mergel(reg28,reg29); \ +x2 = vec_mergeh(reg30,reg31); \ +x3 = vec_mergel(reg30,reg31) + +#define vec_mov_rm(v, where) \ +low = vec_ld(0, (where)); \ +high = vec_ld(16, (where)); \ +p_vector = vec_lvsr(0, (int *)(where)); \ +mask = vec_perm((vector unsigned char)(0), (vector unsigned char)(-1), p_vector); \ +v = vec_perm(v, v, p_vector); \ +low = vec_sel(low, v, mask); \ +high = vec_sel(v, high, mask); \ +vec_st(low, 0, (where)); \ +vec_st(high, 16, (where)) + +#define vec_mov_mr_a(mem,reg) reg = vec_ld(0, mem) + +#define vec_mov_mr(u,v) \ +p_vector = (vector unsigned char)vec_lvsl(0, (int*)(v)); \ +low = (vector unsigned char)vec_ld(0, (v)); \ +high = (vector unsigned char)vec_ld(16, (v)); \ +u=(vector float)vec_perm(low, high, p_vector) + +#define vec_muladd(reg1,reg2,regout) regout = vec_madd(reg1,reg2,regout) +#define vec_add_rr(reg1,reg2) reg2 = vec_add(reg1,reg2) + +#define vec_zero(reg) reg = vec_xor(reg,reg) + +#define vec_sum_full(reg0,reg1,reg2,reg3,regout,empty0,empty1) \ +transpose(reg0, reg1,reg2,reg3,regout,empty0,empty1); \ +empty0 = vec_add(reg0,reg1); \ +empty1 = vec_add(reg2,reg3); \ +regout = vec_add(empty0,empty1) + + +#endif /* ALTIVEC_C */ + + + + + + + + diff --git a/kaldi_io/src/tools/ATLAS/include/contrib/camm_dpa.h b/kaldi_io/src/tools/ATLAS/include/contrib/camm_dpa.h new file mode 100644 index 0000000..af9c6b1 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/contrib/camm_dpa.h @@ -0,0 +1,1626 @@ +#include +#include +#include + +#include "camm_util.h" + + +#if defined(ALIGN) +#if( defined(SCPLX) || defined(DCPLX)) +#error Cannot align complex routines +#endif +#if defined(SREAL) && ( NDPM != 1 ) && ( STRIDE % 4 != 0) +#error Can only align SREAL with NDPM 1 or STRIDE % 4 = 0 +#endif +#if defined(DREAL) && ( NDPM != 1 ) && ( STRIDE % 2 != 0) +#error Can only align DREAL with NDPM 1 or STRIDE % 2 = 0 +#endif +#endif + +/****************************************************************************** + * Single Precision Complex Macros + ******************************************************************************/ + +#ifdef SCPLX + +#ifdef NO_TRANSPOSE + +#if NDPM > 3 +#error Max NDPM is 3 for SCPLX NO_TRANSPOSE +#endif + +#undef plax +#define plax + +#undef R1 +#define R1 2 +#undef R2 +#define R2 4 +#undef R3 +#define R3 6 +#undef R4 +#define R4 6 + +#undef TREG +#define TREG 1 +#undef SREG +#define SREG 0 +#undef CREG +#define CREG 0 + +#ifdef GER +#undef AREG +#define AREG 0 +#undef targ +#define targ(a_) AREG +#undef wb +#define wb(a_,b_) pu(AREG,a_,b_) +#undef wbd +#define wbd(a_,b_) pud(AREG,a_,b_) +#undef w +#define w(a_) +#undef w1_2 +#define w1_2(a_) +#else +#undef AREG +#define AREG TREG +#undef targ +#define targ(a_) CREG +#undef wb +#define wb(a_,b_) +#undef wbd +#define wbd(a_,b_) +#undef w +#define w(a_) pu(CREG,a_ ## 0,si) +#undef w1_2 +#define w1_2(a_) pud(CREG,a_ ## 0,si) +#endif + +#undef src +#define src(a_) a_ +#undef mpx +#define mpx(a_) pls(0,si,a_) ps(0,a_,a_) pls(4,si,P(a_,1)) \ + ps(0,P(a_,1),P(a_,1)) sign(a_) +#undef madd +#define madd(a_,b_,c_) pas(a_,b_,c_) +#undef ulfa +#define ulfa(a_) + +#else + +#undef R1 +#define R1 4 +#undef R2 +#define R2 5 +#undef R3 +#define R3 6 +#undef R4 +#define R4 7 + +#undef TREG +#define TREG 3 +#undef SREG +#define SREG 2 +#undef CREG +#define CREG 0 +#undef targ +#define targ(a_) a_ +#undef src +#define src(a_) 0 +#undef w +#define w(a_) +#undef w1_2 +#define w1_2(a_) +#undef mpx +#define mpx(a_) px(a_) +#ifdef BETA0 +#undef ulfa +#define ulfa(a_) phl(a_,0) pa(0,a_) pud(a_,0,si) +#else +#undef ulfa +#define ulfa(a_) pld(0,si,TREG) phl(a_,0) pa(0,a_) pa(TREG,a_) pud(a_,0,si) +#endif +#undef AREG +#define AREG TREG +#undef wb +#define wb(a_,b_) +#undef wbd +#define wbd(a_,b_) +#undef wbs +#define wbs(a_,b_) + + +#undef plax +#define plax pc(CREG,1) ps(160,CREG,CREG) ps(245,1,1) sign(CREG) + + + +#endif + +#if defined(Conj_) && ! defined(GER) +#undef sign +#define sign(a_) pm(SREG,a_) +#else +#undef sign +#define sign(a_) pm(SREG,P(a_,1)) +#endif + + + +#undef plb +#define plb(a_,b_) pl(a_,b_,AREG) +#undef plbd +#define plbd(a_,b_) px(AREG) pld(a_,b_,AREG) + +#undef dpr +#define dpr(a_) pm(src(a_),TREG) pa(TREG,targ(a_)) +#undef dprp +#define dprp(a_,b_,c_) pf(b_,c_) pm(src(a_),TREG) pa(TREG,targ(a_)) +#undef dpi +#define dpi(a_) pm(P(src(a_),1),TREG) ps(177,TREG,TREG) pa(TREG,targ(a_)) + +#ifndef GER + + +#undef plaa +#define plaa(a_) pl(a_ ## 0,si,CREG) plax +#undef wa +#define wa(a_) w(a_) +#undef dp +#define dp(a_,b_,c_) plb(a_ ## 0,b_) dpr(c_) plb(a_ ## 0,b_) dpi(c_) +#undef dpp +#define dpp(a_,b_,c_,d_,e_) plb(a_ ## 0,b_) dprp(c_,d_,e_) plb(a_ ## 0,b_) dpi(c_) +#undef ddp +#define ddp(a_,b_,c_) dp(a_,b_,c_) +#undef ddpp +#define ddpp(a_,b_,c_,d_,e_) dpp(a_,b_,c_,d_,e_) + +#undef plaa1_2 +#define plaa1_2(a_) px(CREG) pld(a_ ## 0,si,CREG) plax +#undef wa1_2 +#define wa1_2(a_) w1_2(a_) +#undef dp1_2 +#define dp1_2(a_,b_,c_) plbd(a_ ## 0,b_) dpr(c_) plbd(a_ ## 0,b_) dpi(c_) +#undef dpp1_2 +#define dpp1_2(a_,b_,c_,d_,e_) plbd(a_ ## 0,b_) dprp(c_,d_,e_) plbd(a_ ## 0,b_) dpi(c_) +#undef ddp1_2 +#define ddp1_2(a_,b_,c_) dp1_2(a_,b_,c_) +#undef ddpp1_2 +#define ddpp1_2(a_,b_,c_,d_,e_) dpp1_2(a_,b_,c_,d_,e_) + + +#else + +#undef lqc +#define lqc(a_) pl(a_ ## 0,si,TREG) +#undef lqc1 +#define lqc1_2(a_) px(TREG) pld(a_ ## 0,si,TREG) + + +#undef plaa +#define plaa(a_) +#undef wa +#define wa(a_) +#undef dp +#define dp(a_,b_,c_) lqc(a_) plb(a_ ## 0,b_) dpr(c_) \ + lqc(a_) dpi(c_) wb(a_ ## 0,b_) +#undef dpp +#define dpp(a_,b_,c_,d_,e_) lqc(a_) plb(a_ ## 0,b_) dpr(c_) pf(d_,e_) \ + lqc(a_) dpi(c_) wb(a_ ## 0,b_) +#undef ddp +#define ddp(a_,b_,c_) dp(a_,b_,c_) +#undef ddpp +#define ddpp(a_,b_,c_,d_,e_) dpp(a_,b_,c_,d_,e_) + +#undef plaa1_2 +#define plaa1_2(a_) +#undef wa1_2 +#define wa1_2(a_) +#undef dp1_2 +#define dp1_2(a_,b_,c_) lqc1_2(a_) plbd(a_ ## 0,b_) dpr(c_) \ + lqc1_2(a_) dpi(c_) wbd(a_ ## 0,b_) +#undef dpp1_2 +#define dpp1_2(a_,b_,c_,d_,e_) lqc1_2(a_) plbd(a_ ## 0,b_) dpr(c_) pf(d_,e_) \ + lqc1_2(a_) dpi(c_) wbd(a_ ## 0,b_) +#undef ddp1_2 +#define ddp1_2(a_,b_,c_) dp1_2(a_,b_,c_) +#undef ddpp1_2 +#define ddpp1_2(a_,b_,c_,d_,e_) dpp1_2(a_,b_,c_,d_,e_) + +#endif + +#endif + +/****************************************************************************** + * Single Precision Real Macros + ******************************************************************************/ + +#ifdef SREAL + +#ifdef NO_TRANSPOSE + +#undef mpx +#define mpx(a_) pls(0,si,a_) ps(0,a_,a_) +#undef madd +#define madd(a_,b_,c_) pas(a_,b_,c_) +#undef TREG +#define TREG 1 +#undef targ +#define targ(a_) 0 +#undef src +#define src(a_) a_ +#undef ulfa +#define ulfa(a_) + +#ifdef GER +#undef w +#define w(a_) +#undef w1_2 +#define w1_2(a_) +#undef w1_4 +#define w1_4(a_) +#undef CREG +#define CREG 2 +#undef AREG +#define AREG 0 +#undef cp +#define cp pc(CREG,TREG) +#undef wb +#define wb(a_,b_) pu(AREG,a_,b_) +#undef wbd +#define wbd(a_,b_) pud(AREG,a_,b_) +#undef wbs +#define wbs(a_,b_) pus(AREG,a_,b_) +#else +#undef CREG +#define CREG 0 +#undef AREG +#define AREG TREG +#undef cp +#define cp +#undef wb +#define wb(a_,b_) +#undef wbd +#define wbd(a_,b_) +#undef wbs +#define wbs(a_,b_) +#undef w +#define w(a_) pu(CREG,a_ ## 0,si) +#undef w1_2 +#define w1_2(a_) pud(CREG,a_ ## 0,si) +#undef w1_4 +#define w1_4(a_) pus(CREG,a_ ## 0,si) +#endif + +#else + +#undef mpx +#define mpx(a_) px(a_) +#ifdef BETA0 +#undef madd +#define madd(a_,b_,c_) +#else +#undef madd +#define madd(a_,b_,c_) pas(a_,b_,c_) +#endif +#undef TREG +#define TREG 3 +#undef targ +#define targ(a_) a_ +#undef src +#define src(a_) 0 +#undef w +#define w(a_) +#undef w1_2 +#define w1_2(a_) +#undef w1_4 +#define w1_4(a_) +#undef ulfa +#undef ulfa +#define ulfa(a_) phl(a_,0) pa(0,a_) pc(a_,0) ps(1,0,0) pa(0,a_) \ + madd(0,si,a_) pus(a_,0,si) + +#undef CREG +#define CREG 0 +#undef AREG +#define AREG TREG +#undef cp +#define cp +#undef wb +#define wb(a_,b_) +#undef wbd +#define wbd(a_,b_) +#undef wbs +#define wbs(a_,b_) + +#endif + +#if defined(ALIGN) +#undef plb +#define plb(a_,b_) pla(a_,b_,AREG) +#else +#undef plb +#define plb(a_,b_) pl(a_,b_,AREG) +#endif +#undef plbd +#define plbd(a_,b_) px(AREG) pld(a_,b_,AREG) +#undef plbs +#define plbs(a_,b_) pls(a_,b_,AREG) +#undef dpr +#define dpr(a_) pm(src(a_),TREG) pa(TREG,targ(a_)) +#undef dprp +#define dprp(a_,b_,c_) pf(b_,c_) pm(src(a_),TREG) pa(TREG,targ(a_)) +#undef dprs +#define dprs(a_) pmsr(src(a_),TREG) pasr(TREG,targ(a_)) +#undef dprps +#define dprps(a_,b_,c_) pf(b_,c_) pmsr(src(a_),TREG) pasr(TREG,targ(a_)) + +#undef plaa +#define plaa(a_) pl(a_ ## 0,si,CREG) +#undef wa +#define wa(a_) w(a_) +#undef dp +#define dp(a_,b_,c_) cp plb(a_ ## 0,b_) dpr(c_) wb(a_ ## 0,b_) +#undef dpp +#define dpp(a_,b_,c_,d_,e_) cp plb(a_ ## 0,b_) dprp(c_,d_,e_) wb(a_ ## 0,b_) +#undef ddp +#define ddp(a_,b_,c_) dp(a_,b_,c_) +#undef ddpp +#define ddpp(a_,b_,c_,d_,e_) dpp(a_,b_,c_,d_,e_) + +#undef plaa1_2 +#define plaa1_2(a_) px(CREG) pld(a_ ## 0,si,CREG) +#undef wa1_2 +#define wa1_2(a_) w1_2(a_) +#undef dp1_2 +#define dp1_2(a_,b_,c_) cp plbd(a_ ## 0,b_) dpr(c_) wbd(a_ ## 0,b_) +#undef dpp1_2 +#define dpp1_2(a_,b_,c_,d_,e_) cp plbd(a_ ## 0,b_) dprp(c_,d_,e_) wbd(a_ ## 0,b_) +#undef ddp1_2 +#define ddp1_2(a_,b_,c_) dp1_2(a_,b_,c_) +#undef ddpp1_2 +#define ddpp1_2(a_,b_,c_,d_,e_) dpp1_2(a_,b_,c_,d_,e_) + +#undef plaa1_4 +#define plaa1_4(a_) pls(a_ ## 0,si,CREG) +#undef wa1_4 +#define wa1_4(a_) w1_4(a_) +#undef dp1_4 +#define dp1_4(a_,b_,c_) cp plbs(a_ ## 0,b_) dprs(c_) wbs(a_ ## 0,b_) +#undef dpp1_4 +#define dpp1_4(a_,b_,c_,d_,e_) cp plbs(a_ ## 0,b_) dprps(c_,d_,e_) wbs(a_ ## 0,b_) +#undef ddp1_4 +#define ddp1_4(a_,b_,c_) dp1_4(a_,b_,c_) +#undef ddpp1_4 +#define ddpp1_4(a_,b_,c_,d_,e_) dpp1_4(a_,b_,c_,d_,e_) + + + +#undef R1 +#define R1 4 +#undef R2 +#define R2 5 +#undef R3 +#define R3 6 +#undef R4 +#define R4 7 + +#endif + +/****************************************************************************** + * Double Precision Real Macros + ******************************************************************************/ + +#ifdef DREAL + +#ifdef ATL_SSE2 + +#ifdef NO_TRANSPOSE + +#undef mpx +#define mpx(a_) pls(0,si,a_) ps(0,a_,a_) +#undef madd +#define madd(a_,b_,c_) pas(a_,b_,c_) +#undef TREG +#define TREG 1 +#undef targ +#define targ(a_) 0 +#undef src +#define src(a_) a_ +#undef ulfa +#define ulfa(a_) + +#ifdef GER +#undef w +#define w(a_) +#undef w1_2 +#define w1_2(a_) +#undef w1_4 +#define w1_4(a_) +#undef CREG +#define CREG 2 +#undef AREG +#define AREG 0 +#undef cp +#define cp pc(CREG,TREG) +#undef wb +#define wb(a_,b_) pu(AREG,a_,b_) +#undef wbd +#define wbd(a_,b_) pus(AREG,a_,b_) +#undef wbs +/* #define wbs(a_,b_) pus(AREG,a_,b_) */ +#else +#undef CREG +#define CREG 0 +#undef AREG +#define AREG TREG +#undef cp +#define cp +#undef wb +#define wb(a_,b_) +#undef wbd +#define wbd(a_,b_) +#undef wbs +/* #define wbs(a_,b_) */ +#undef w +#define w(a_) pu(CREG,a_ ## 0,si) +#undef w1_2 +#define w1_2(a_) pus(CREG,a_ ## 0,si) +#undef w1_4 +/* #define w1_4(a_) pus(CREG,a_ ## 0,si) */ +#endif + +#else + +#undef mpx +#define mpx(a_) px(a_) +#ifdef BETA0 +#undef madd +#define madd(a_,b_,c_) +#else +#undef madd +#define madd(a_,b_,c_) pas(a_,b_,c_) +#endif +#undef TREG +#define TREG 3 +#undef targ +#define targ(a_) a_ +#undef src +#define src(a_) 0 +#undef w +#define w(a_) +#undef w1_2 +#define w1_2(a_) +#undef w1_4 +#define w1_4(a_) +#undef ulfa +#undef ulfa +#define ulfa(a_) /* phl(a_,0) pa(0,a_) */ pc(a_,0) ps(1,0,0) pa(0,a_) \ + madd(0,si,a_) pus(a_,0,si) + +#undef CREG +#define CREG 0 +#undef AREG +#define AREG TREG +#undef cp +#define cp +#undef wb +#define wb(a_,b_) +#undef wbd +#define wbd(a_,b_) +#undef wbs +#define wbs(a_,b_) + +#endif + +#if defined(ALIGN) +#undef plb +#define plb(a_,b_) pla(a_,b_,AREG) +#else +#undef plb +#define plb(a_,b_) pl(a_,b_,AREG) +#endif +#undef plbd +#define plbd(a_,b_) /* px(AREG) */pls(a_,b_,AREG) +#undef plbs +/* #define plbs(a_,b_) pls(a_,b_,AREG) */ +#undef dpr +#define dpr(a_) pm(src(a_),TREG) pa(TREG,targ(a_)) +#undef dprp +#define dprp(a_,b_,c_) pf(b_,c_) pm(src(a_),TREG) pa(TREG,targ(a_)) +#undef dprs +#define dprs(a_) pmsr(src(a_),TREG) pasr(TREG,targ(a_)) +#undef dprps +#define dprps(a_,b_,c_) pf(b_,c_) pmsr(src(a_),TREG) pasr(TREG,targ(a_)) + +#undef plaa +#define plaa(a_) pl(a_ ## 0,si,CREG) +#undef wa +#define wa(a_) w(a_) +#undef dp +#define dp(a_,b_,c_) cp plb(a_ ## 0,b_) dpr(c_) wb(a_ ## 0,b_) +#undef dpp +#define dpp(a_,b_,c_,d_,e_) cp plb(a_ ## 0,b_) dprp(c_,d_,e_) wb(a_ ## 0,b_) +#undef ddp +#define ddp(a_,b_,c_) dp(a_,b_,c_) +#undef ddpp +#define ddpp(a_,b_,c_,d_,e_) dpp(a_,b_,c_,d_,e_) + +#undef plaa1_2 +#define plaa1_2(a_) /* px(CREG) */pls(a_ ## 0,si,CREG) +#undef wa1_2 +#define wa1_2(a_) w1_2(a_) +#undef dp1_2 +#define dp1_2(a_,b_,c_) cp plbd(a_ ## 0,b_) dprs(c_) wbd(a_ ## 0,b_) +#undef dpp1_2 +#define dpp1_2(a_,b_,c_,d_,e_) cp plbd(a_ ## 0,b_) dprps(c_,d_,e_) wbd(a_ ## 0,b_) +#undef ddp1_2 +#define ddp1_2(a_,b_,c_) dp1_2(a_,b_,c_) +#undef ddpp1_2 +#define ddpp1_2(a_,b_,c_,d_,e_) dpp1_2(a_,b_,c_,d_,e_) + +#undef plaa1_4 +/* #define plaa1_4(a_) pls(a_ ## 0,si,CREG) */ +#undef wa1_4 +/* #define wa1_4(a_) w1_4(a_) */ +#undef dp1_4 +/* #define dp1_4(a_,b_,c_) cp plbs(a_ ## 0,b_) dprs(c_) wbs(a_ ## 0,b_) */ +#undef dpp1_4 +/* #define dpp1_4(a_,b_,c_,d_,e_) cp plbs(a_ ## 0,b_) dprps(c_,d_,e_) wbs(a_ ## 0,b_) */ +#undef ddp1_4 +/* #define ddp1_4(a_,b_,c_) dp1_4(a_,b_,c_) */ +#undef ddpp1_4 +/* #define ddpp1_4(a_,b_,c_,d_,e_) dpp1_4(a_,b_,c_,d_,e_) */ + + + +#undef R1 +#define R1 4 +#undef R2 +#define R2 5 +#undef R3 +#define R3 6 +#undef R4 +#define R4 7 + +#else + +#ifdef NO_TRANSPOSE + +#undef t0 +#define t0(a_) 1 +#undef s0 +#define s0(a_) a_ +#undef t8 +#define t8(a_) 2 +#undef s8 +#define s8(a_) a_ +#undef w +#define w(a_) fp(a_ ## 0,si) fp(a_ ## 8,si) +#undef w1_2 +#define w1_2(a_) fp(a_ ## 0,si) +#undef mpx +#define mpx(a_) fl(0,si) fc(M(a_,2)) +#undef madd +#define madd(a_,b_,c_) faa(a_,b_) +#undef ulfa +#define ulfa(a_) fc(0) + +#else + +#undef t0 +#define t0(a_) a_ +#undef s0 +#define s0(a_) 1 +#undef t8 +#define t8(a_) a_ +#undef s8 +#define s8(a_) 2 +#undef w +#define w(a_) +#undef w1_2 +#define w1_2(a_) +#undef mpx +#define mpx(a_) fz +#ifdef BETA0 +#undef madd +#define madd(a_,b_,c_) +#else +#undef madd +#define madd(a_,b_,c_) faa(a_,b_) +#endif +#undef ulfa +#define ulfa(a_) madd(0,si,a_) fp(0,si) + +#endif + + +#ifndef GER + +#undef plaa1_2 +#define plaa1_2(a_) fl(a_ ## 0,si) +#undef wa1_2 +#define wa1_2(a_) w1_2(a_) +#ifdef NO_TRANSPOSE +#undef ddp1_2 +#define ddp1_2(a_,b_,c_) fl(a_ ## 0,b_) fm(M(s0(c_),1),0) fap(0,t0(c_)) +#undef dp1_2 +#define dp1_2(a_,b_,c_) ddp1_2(a_,b_,c_) +#else +#undef ddp1_2 +#define ddp1_2(a_,b_,c_) fl(a_ ## 0,b_) fm(s0(c_),0) fap(0,M(t0(c_),1)) +#undef dp1_2 +#define dp1_2(a_,b_,c_) fl(a_ ## 0,b_) fmp(0,s0(c_)) fap(0,M(t0(c_),2)) +#endif + +#else + +#undef plaa1_2 +#define plaa1_2(a_) fl(a_ ## 0,si) +#undef wa1_2 +#define wa1_2(a_) +#undef ddp1_2 +#define ddp1_2(a_,b_,c_) fd(M(s0(c_),2)) fm(t0(c_),0) faa(a_ ## 0,b_) fp(a_ ## 0,b_) +#undef dp1_2 +#define dp1_2(a_,b_,c_) fm(M(s0(c_),2),0) faa(a_ ## 0,b_) fp(a_ ## 0,b_) + +#endif + + + +#undef plaa +#define plaa(a_) fl(a_ ## 0,si) fl(a_ ## 8,si) fx1 + +#ifndef GER + + +#undef wa +#define wa(a_) w(a_) + + +#undef ddp +#define ddp(a_,b_,c_) fl(a_ ## 0,b_) fm(s0(c_),0) fl(a_ ## 8,b_) \ + fm(P(s8(c_),1),0) fx1 fap(0,P(t0(c_),1)) \ + fap(0,t8(c_)) +#undef ddpp +#define ddpp(a_,b_,c_,d_,e_) fl(a_ ## 0,b_) fm(s0(c_),0) fl(a_ ## 8,b_) \ + fm(P(s8(c_),1),0) pf(d_,e_) fx1 fap(0,P(t0(c_),1)) \ + fap(0,t8(c_)) + +/* #define ddp(a_,b_,c_) fd(M(s0(c_),1)) fma(a_ ## 0,b_) fap(0,t0(c_)) \ */ +/* fd(M(s8(c_),1)) fma(a_ ## 8,b_) fap(0,t8(c_)) */ +/* #define ddpp(a_,b_,c_,d_,e_) fd(M(s0(c_),1)) fma(a_ ## 0,b_) fap(0,t0(c_)) \ */ +/* \ */ +/* fd(M(s8(c_),1)) fma(a_ ## 8,b_) fap(0,t8(c_)) pf(d_,e_) */ + +#ifdef NO_TRANSPOSE + +#undef dp +#define dp(a_,b_,c_) ddp(a_,b_,c_) +#undef dpp +#define dpp(a_,b_,c_,d_,e_) ddpp(a_,b_,c_,d_,e_) + +#else + +#undef dp +#define dp(a_,b_,c_) fl(a_ ## 0,b_) fmp(0,s0(c_)) fl(a_ ## 8,b_) \ + fmp(0,s8(c_)) fap(0,M(t0(c_),1)) fap(0,M(t8(c_),2)) +#undef dpp +#define dpp(a_,b_,c_,d_,e_) fl(a_ ## 0,b_) pf(d_ ,e_) fmp(0,s0(c_)) fl(a_ ## 8,b_) \ + fmp(0,s8(c_)) fap(0,M(t0(c_),1)) fap(0,M(t8(c_),2)) + +/* #define dp(a_,b_,c_) fma(a_ ## 0,b_) fap(0,M(t0(c_),1)) \ */ +/* fma(a_ ## 8,b_) fap(0,M(t8(c_),2)) */ +/* #define dpp(a_,b_,c_,d_,e_) fma(a_ ## 0,b_) fap(0,M(t0(c_),1)) \ */ +/* \ */ +/* fma(a_ ## 8,b_) fap(0,M(t8(c_),2)) pf(d_,e_) */ + +#endif + + +#else + +#undef wa +#define wa(a_) +#undef ddp +#define ddp(a_,b_,c_) fd(M(s0(c_),1)) fm(t0(c_),0) faa(a_ ## 0,b_) fp(a_ ## 0,b_) \ + fd(M(s8(c_),1)) fm(t8(c_),0) faa(a_ ## 8,b_) fp(a_ ## 8,b_) +#undef ddpp +#define ddpp(a_,b_,c_,d_,e_) fd(M(s0(c_),1)) fm(t0(c_),0) faa(a_ ## 0,b_) fp(a_ ## 0,b_) \ + fd(M(s8(c_),1)) fm(t8(c_),0) faa(a_ ## 8,b_) fp(a_ ## 8,b_) pf(d_,e_) + +#undef dp +#define dp(a_,b_,c_) fm(M(s0(c_),1),0) faa(a_ ## 0,b_) fp(a_ ## 0,b_) \ + fm(M(s8(c_),2),0) faa(a_ ## 8,b_) fp(a_ ## 8,b_) +#undef dpp +#define dpp(a_,b_,c_,d_,e_) fm(M(s0(c_),1),0) faa(a_ ## 0,b_) fp(a_ ## 0,b_) \ + fm(M(s8(c_),2),0) faa(a_ ## 8,b_) fp(a_ ## 8,b_) pf(d_,e_) + +#endif + + +#undef R1 +#define R1 3 +#undef R2 +#define R2 4 +#undef R3 +#define R3 5 +#undef R4 +#define R4 6 + +#endif + +#endif + +/****************************************************************************** + * Double Precision Complex Macros + ******************************************************************************/ + +#ifdef DCPLX + +#ifdef ATL_SSE2 +#ifdef NO_TRANSPOSE + +#if NDPM > 3 +#error Max NDPM is 3 for DCPLX NO_TRANSPOSE +#endif + +#undef plax +#define plax + +#undef R1 +#define R1 2 +#undef R2 +#define R2 4 +#undef R3 +#define R3 6 +#undef R4 +#define R4 6 + +#undef TREG +#define TREG 1 +#undef SREG +#define SREG 0 +#undef CREG +#define CREG 0 + +#ifdef GER +#undef AREG +#define AREG 0 +#undef targ +#define targ(a_) AREG +#undef wb +#define wb(a_,b_) pu(AREG,a_,b_) +#undef wbd +/* #define wbd(a_,b_) pud(AREG,a_,b_) */ +#undef w +#define w(a_) +#undef w1_2 +/* #define w1_2(a_) */ +#else +#undef AREG +#define AREG TREG +#undef targ +#define targ(a_) CREG +#undef wb +#define wb(a_,b_) +#undef wbd +/* #define wbd(a_,b_) */ +#undef w +#define w(a_) pu(CREG,a_ ## 0,si) +#undef w1_2 +/* #define w1_2(a_) pud(CREG,a_ ## 0,si) */ +#endif + +#undef src +#define src(a_) a_ +#undef mpx +#define mpx(a_) pls(0,si,a_) ps(0,a_,a_) pls(8,si,P(a_,1)) \ + ps(0,P(a_,1),P(a_,1)) sign(a_) +#undef madd +#define madd(a_,b_,c_) pas(a_,b_,c_) +#undef ulfa +#define ulfa(a_) + +#else + +#undef R1 +#define R1 4 +#undef R2 +#define R2 5 +#undef R3 +#define R3 6 +#undef R4 +#define R4 7 + +#undef TREG +#define TREG 3 +#undef SREG +#define SREG 2 +#undef CREG +#define CREG 0 +#undef targ +#define targ(a_) a_ +#undef src +#define src(a_) 0 +#undef w +#define w(a_) +#undef w1_2 +#define w1_2(a_) +#undef mpx +#define mpx(a_) px(a_) +#ifdef BETA0 +#undef ulfa +#define ulfa(a_) /* phl(a_,0) pa(0,a_) */pu(a_,0,si) +#else +#undef ulfa +#define ulfa(a_) pl(0,si,TREG) /* phl(a_,0) pa(0,a_) */ pa(TREG,a_) pu(a_,0,si) +#endif +#undef AREG +#define AREG TREG +#undef wb +#define wb(a_,b_) +#undef wbd +#define wbd(a_,b_) +#undef wbs +#define wbs(a_,b_) + + +#undef plax +#define plax pc(CREG,1) ps(0,CREG,CREG) ps(3,1,1) sign(CREG) + + + +#endif + +#if defined(Conj_) && ! defined(GER) +#undef sign +#define sign(a_) pm(SREG,a_) +#else +#undef sign +#define sign(a_) pm(SREG,P(a_,1)) +#endif + + + +#undef plb +#define plb(a_,b_) pl(a_,b_,AREG) +#undef plbd +/* #define plbd(a_,b_) px(AREG) pld(a_,b_,AREG) */ + +#undef dpr +#define dpr(a_) pm(src(a_),TREG) pa(TREG,targ(a_)) +#undef dprp +#define dprp(a_,b_,c_) pf(b_,c_) pm(src(a_),TREG) pa(TREG,targ(a_)) +#undef dpi +#define dpi(a_) pm(P(src(a_),1),TREG) ps(1,TREG,TREG) pa(TREG,targ(a_)) + +#ifndef GER + +#undef plaa +#define plaa(a_) pl(a_ ## 0,si,CREG) plax +#undef wa +#define wa(a_) w(a_) +#undef dp +#define dp(a_,b_,c_) plb(a_ ## 0,b_) dpr(c_) plb(a_ ## 0,b_) dpi(c_) +#undef dpp +#define dpp(a_,b_,c_,d_,e_) plb(a_ ## 0,b_) dprp(c_,d_,e_) plb(a_ ## 0,b_) dpi(c_) +#undef ddp +#define ddp(a_,b_,c_) dp(a_,b_,c_) +#undef ddpp +#define ddpp(a_,b_,c_,d_,e_) dpp(a_,b_,c_,d_,e_) + +#undef plaa1_2 +/* #define plaa1_2(a_) px(CREG) pld(a_ ## 0,si,CREG) plax */ +#undef wa1_2 +/* #define wa1_2(a_) w1_2(a_) */ +#undef dp1_2 +/* #define dp1_2(a_,b_,c_) plbd(a_ ## 0,b_) dpr(c_) plbd(a_ ## 0,b_) dpi(c_) */ +#undef dpp1_2 +/* #define dpp1_2(a_,b_,c_,d_,e_) plbd(a_ ## 0,b_) dprp(c_,d_,e_) plbd(a_ ## 0,b_) dpi(c_) */ +#undef ddp1_2 +/* #define ddp1_2(a_,b_,c_) dp1_2(a_,b_,c_) */ +#undef ddpp1_2 +/* #define ddpp1_2(a_,b_,c_,d_,e_) dpp1_2(a_,b_,c_,d_,e_) */ + + +#else + +#undef lqc +#define lqc(a_) pl(a_ ## 0,si,TREG) +#undef lqc1 +/* #define lqc1_2(a_) px(TREG) pld(a_ ## 0,si,TREG) */ + + +#undef plaa +#define plaa(a_) +#undef wa +#define wa(a_) +#undef dp +#define dp(a_,b_,c_) lqc(a_) plb(a_ ## 0,b_) dpr(c_) \ + lqc(a_) dpi(c_) wb(a_ ## 0,b_) +#undef dpp +#define dpp(a_,b_,c_,d_,e_) lqc(a_) plb(a_ ## 0,b_) dpr(c_) pf(d_,e_) \ + lqc(a_) dpi(c_) wb(a_ ## 0,b_) +#undef ddp +#define ddp(a_,b_,c_) dp(a_,b_,c_) +#undef ddpp +#define ddpp(a_,b_,c_,d_,e_) dpp(a_,b_,c_,d_,e_) + +#undef plaa1_2 +/* #define plaa1_2(a_) */ +#undef wa1_2 +/* #define wa1_2(a_) */ +#undef dp1_2 +/* #define dp1_2(a_,b_,c_) lqc1_2(a_) plbd(a_ ## 0,b_) dpr(c_) \ */ +/* lqc1_2(a_) dpi(c_) wbd(a_ ## 0,b_) */ +#undef dpp1_2 +/* #define dpp1_2(a_,b_,c_,d_,e_) lqc1_2(a_) plbd(a_ ## 0,b_) dpr(c_) pf(d_,e_) \ */ +/* lqc1_2(a_) dpi(c_) wbd(a_ ## 0,b_) */ +#undef ddp1_2 +/* #define ddp1_2(a_,b_,c_) dp1_2(a_,b_,c_) */ +#undef ddpp1_2 +/* #define ddpp1_2(a_,b_,c_,d_,e_) dpp1_2(a_,b_,c_,d_,e_) */ + +#endif + +#else + +#if NDPM > 2 +#error Max NDPM is 2 for DCPLX +#endif + +#undef TREG +#define TREG 2 + +#ifdef NO_TRANSPOSE + +#undef w +#define w(a_) fp(a_ ## 0,si) fp(a_ ## 8,si) +#undef plax +#define plax fx1 +#undef srr +#define srr(a_) a_ +#undef sri +#define sri(a_) a_ +#undef sir +#define sir(a_) a_ +#undef sii +#define sii(a_) a_ +#undef trr +#define trr(a_) P(TREG,1) +#undef tri +#define tri(a_) M(TREG,1) +#undef tir +#define tir(a_) TREG +#undef tii +#define tii(a_) TREG +#undef mpx +#define mpx(a_) fl(0,si) fl(8,si) fc(M(a_,2)) fc(M(a_,2)) +#undef madd +#define madd(a_,b_,c_) faa(a_,b_) +#undef ulfa +#define ulfa(a_) fc(0) fc(0) + +#else + +#undef srr +#define srr(a_) P(TREG,1) +#undef sri +#define sri(a_) M(TREG,1) +#undef sir +#define sir(a_) TREG +#undef sii +#define sii(a_) TREG +#undef trr +#define trr(a_) a_ +#undef tri +#define tri(a_) a_ +#undef tir +#define tir(a_) a_ +#undef tii +#define tii(a_) a_ +#undef w +#define w(a_) +#undef plax +#define plax +#undef mpx +#define mpx(a_) fz fz +#ifdef BETA0 +#undef madd +#define madd(a_,b_,c_) +#else +#undef madd +#define madd(a_,b_,c_) faa(a_,b_) +#endif +#undef ulfa +#define ulfa(a_) madd(0,si,a_) fp(0,si) madd(8,si,a_) fp(8,si) + +#endif + + + +#ifdef Conj_ +#undef fapi +#define fapi(a_,b_) fsp(b_) +#undef fspi +#define fspi(a_,b_) fap(a_,b_) +#else +#undef fapi +#define fapi(a_,b_) fap(a_,b_) +#undef fspi +#define fspi(a_,b_) fsp(b_) +#endif + +#ifndef GER + + +#undef plaa +#define plaa(a_) fl(a_ ## 0,si) fl(a_ ## 8,si) plax +#undef wa +#define wa(a_) w(a_) +#undef ddp +#define ddp(a_,b_,c_) fl(a_ ## 0,b_) fd(0) fm(srr(c_),0) fap(0,trr(c_)) \ + fm(sri(c_),0) fap(0,tri(c_))\ + fl(a_ ## 8,b_) fd(0) fm(sir(c_),0) fspi(0,tir(c_)) \ + fm(sii(c_),0) fapi(0,tii(c_)) +#undef ddpp +#define ddpp(a_,b_,c_,d_,e_) fl(a_ ## 0,b_) fd(0) fm(srr(c_),0) fap(0,trr(c_)) \ + fm(sri(c_),0) fap(0,tri(c_))\ + fl(a_ ## 8,b_) fd(0) pf(d_,e_) fm(sir(c_),0) fspi(0,tir(c_))\ + fm(sii(c_),0) fapi(0,tii(c_)) + + + +#ifdef NO_TRANSPOSE + + + +#undef dp +#define dp(a_,b_,c_) ddp(a_,b_,c_) +#undef dpp +#define dpp(a_,b_,c_,d_,e_) ddpp(a_,b_,c_,d_,e_) + + + +#else + +#undef dp +#define dp(a_,b_,c_) fl(a_ ## 0,b_) fd(0) fm(srr(c_),0) fap(0,trr(c_)) \ + fm(sri(c_),0) fap(0,tri(c_))\ + fl(a_ ## 8,b_) fm(0,sir(c_)) fmp(0,M(sir(c_),1)) \ + fspi(0,M(tir(c_),2)) fapi(0,M(tii(c_),2)) + +#undef dpp +#define dpp(a_,b_,c_,d_,e_) fl(a_ ## 0,b_) fd(0) fm(srr(c_),0) fap(0,trr(c_)) \ + pf(d_,e_) fm(sri(c_),0) fap(0,tri(c_))\ + fl(a_ ## 8,b_) fm(0,sir(c_)) fmp(0,M(sir(c_),1)) \ + fspi(0,M(tir(c_),2)) fapi(0,M(tii(c_),2)) + + +#endif + +#else + +#undef plaa +#define plaa(a_) fl(a_ ## 0,si) fl(a_ ## 8,si) plax +#undef wa +#define wa(a_) + +#undef ddprr +#define ddprr(a_,b_,c_) fl(a_ ## 0,b_) \ + fd(tri(c_)) fm(P(sri(c_),1),0) fap(0,1) \ + fd(M(trr(c_),1)) fm(srr(c_),0) fspi(0,1) \ + fp(a_ ## 0,b_) +#undef ddpri +#define ddpri(a_,b_,c_) fl(a_ ## 8,b_) \ + fd(tii(c_)) fm(P(sii(c_),1),0) fap(0,1) \ + fd(M(tir(c_),1)) fm(sir(c_),0) fapi(0,1) \ + fp(a_ ## 8,b_) +#undef dpri +#define dpri(a_,b_,c_) fl(a_ ## 8,b_) \ + fx(2) fm(sir(c_),0) fap(0,2) \ + fm(M(sii(c_),2),0) fapi(0,1) \ + fp(a_ ## 8,b_) + + +#undef ddpp +#define ddpp(a_,b_,c_,d_,e_) ddprr(a_,b_,c_) pf(d_,e_) ddpri(a_,b_,c_) +#undef ddp +#define ddp(a_,b_,c_) ddprr(a_,b_,c_) ddpri(a_,b_,c_) +#undef dpp +#define dpp(a_,b_,c_,d_,e_) ddprr(a_,b_,c_) pf(d_,e_) dpri(a_,b_,c_) +#undef dp +#define dp(a_,b_,c_) ddprr(a_,b_,c_) dpri(a_,b_,c_) + +#endif + + +#undef R1 +#define R1 4 +#undef R2 +#define R2 6 +#undef R3 +#define R3 6 +#undef R4 +#define R4 6 + +#endif + +#endif + + +/****************************************************************************** + * General Macros + ******************************************************************************/ + + + + +#undef bla1 +#define bla1(a_,b_) plaa(a_) dpp(a_,ax,R1,b_,si) wa(a_) +#undef blb1 +#define blb1(a_,b_) plaa(a_) dpp(a_,ax,R1,b_,ax) wa(a_) + +#undef bla2 +#undef bla2 +#define bla2(a_,b_) pf(b_,si) plaa(a_) ddp(a_,ax,R1) pf(b_,ax) dp(a_,bx,R2) wa(a_) +#undef blb2 +#undef blb2 +#define blb2(a_,b_) plaa(a_) ddpp(a_,ax,R1,b_,bx) dp(a_,bx,R2) wa(a_) + +#undef bla3 +#define bla3(a_,b_) plaa(a_) ddpp(a_,ax,R1,b_,si) ddp(a_,bx,R2) \ + dpp(a_,cx,R3,b_,ax) wa(a_) +#undef blb3 +#define blb3(a_,b_) plaa(a_) ddpp(a_,ax,R1,b_,bx) ddp(a_,bx,R2) \ + dpp(a_,cx,R3,b_,cx) wa(a_) + +#undef bla4 +#define bla4(a_,b_) plaa(a_) ddpp(a_,ax,R1,b_,si) ddpp(a_,bx,R2,b_,ax) \ + ddp(a_,cx,R3) dpp(a_,dx,R4,b_,bx) wa(a_) +#undef blb4 +#define blb4(a_,b_) plaa(a_) ddp(a_,ax,R1) ddpp(a_,bx,R2,b_,cx) \ + ddp(a_,cx,R3) dpp(a_,dx,R4,b_,dx) wa(a_) + +#undef bla +#define bla(a_,b_) Mjoin(bla,NDP)(a_,b_) +#undef blb +#define blb(a_,b_) Mjoin(blb,NDP)(a_,b_) + + + +#undef bla11_2 +#define bla11_2(a_) plaa1_2(a_) dp1_2(a_,ax,R1) wa1_2(a_) +#undef bla21_2 +#define bla21_2(a_) plaa1_2(a_) ddp1_2(a_,ax,R1) dp1_2(a_,bx,R2) wa1_2(a_) +#undef bla31_2 +#define bla31_2(a_) plaa1_2(a_) ddp1_2(a_,ax,R1) ddp1_2(a_,bx,R2) \ + dp1_2(a_,cx,R3) wa1_2(a_) +#undef bla41_2 +#define bla41_2(a_) plaa1_2(a_) ddp1_2(a_,ax,R1) ddp1_2(a_,bx,R2) \ + ddp1_2(a_,cx,R3) dp1_2(a_,dx,R4) wa1_2(a_) + +#undef bla1_2 +#define bla1_2(a_) Mjoin(Mjoin(bla,NDP),1_2)(a_) + + + +#undef bla11_4 +#define bla11_4(a_) plaa1_4(a_) dp1_4(a_,ax,R1) wa1_4(a_) +#undef bla21_4 +#define bla21_4(a_) plaa1_4(a_) ddp1_4(a_,ax,R1) dp1_4(a_,bx,R2) wa1_4(a_) +#undef bla31_4 +#define bla31_4(a_) plaa1_4(a_) ddp1_4(a_,ax,R1) ddp1_4(a_,bx,R2) \ + dp1_4(a_,cx,R3) wa1_4(a_) +#undef bla41_4 +#define bla41_4(a_) plaa1_4(a_) ddp1_4(a_,ax,R1) ddp1_4(a_,bx,R2) \ + ddp1_4(a_,cx,R3) dp1_4(a_,dx,R4) wa1_4(a_) + +#undef bla1_4 +#define bla1_4(a_) Mjoin(Mjoin(bla,NDP),1_4)(a_) + + + +#undef inc1 +#define inc1(a_) a(a_,si) a(a_,ax) +#undef inc2 +#define inc2(a_) inc1(a_) a(a_,bx) +#undef inc3 +#define inc3(a_) inc2(a_) a(a_,cx) +#undef inc4 +#define inc4(a_) inc3(a_) a(a_,dx) + +#undef inc +#define inc(a_) Mjoin(inc,NDP)(a_) + + +#ifdef PREFETCH +/* #include "camm_arith.h" */ +#undef S +#define S(a_,b_) (a_) + (b_) +#undef PF1 +#define PF1 PREFETCH +#undef PF2 +#define PF2 S(PF1,32) +#undef PF3 +#define PF3 S(PF1,64) +#undef PF4 +#define PF4 S(PF1,96) +#undef PF5 +#define PF5 S(PF1,128) +#undef PF6 +#define PF6 S(PF1,160) +#undef PF7 +#define PF7 S(PF1,192) +#undef PF8 +#define PF8 S(PF1,224) +#else +#undef PF1 +#define PF1 64 +#undef PF2 +#define PF2 96 +#undef PF3 +#define PF3 128 +#undef PF4 +#define PF4 160 +#undef PF5 +#define PF5 192 +#undef PF6 +#define PF6 224 +#undef PF7 +#define PF7 256 +#undef PF8 +#define PF8 288 +#endif + + +#if defined(NO_TRANSPOSE) && !defined(SREAL) && !defined(GER) +#undef pf +#define pf(a_,b_) f(t0,a_,b_) +#else +#undef pf +#define pf(a_,b_) f(nta,a_,b_) +#endif + +#undef bl1 +#define bl1 bla1_4(0x0) inc(4) +#undef bl2 +#define bl2 bla1_2(0x0) inc(8) +#undef bl4 +#define bl4 bla(0x0,PF1) inc(16) +#undef bl8 +#define bl8 bla(0x0,PF1) blb(0x1,PF1) inc(32) +#undef bl16 +#define bl16 bla(0x0,PF1) blb(0x1,PF1) bla(0x2,PF2) blb(0x3,PF2) inc(64) +#undef bl32 +#define bl32 bla(0x0,PF1) blb(0x1,PF1) bla(0x2,PF2) blb(0x3,PF2) \ + bla(0x4,PF3) blb(0x5,PF3) bla(0x6,PF4) blb(0x7,PF4) inc(128) +#undef bl64 +#define bl64 bla(0x0,PF1) blb(0x1,PF1) bla(0x2,PF2) blb(0x3,PF2) \ + bla(0x4,PF3) blb(0x5,PF3) bla(0x6,PF4) blb(0x7,PF4) \ + bla(0x8,PF5) blb(0x9,PF5) bla(0xa,PF6) blb(0xb,PF6) \ + bla(0xc,PF7) blb(0xd,PF7) bla(0xe,PF8) blb(0xf,PF8) inc(256) + +/* #define in2 inc(8) */ +/* #define in4 inc(16) */ +/* #define in8 inc(32) */ +/* #define in16 inc(64) */ + +#undef in2 +#define in2 +#undef in4 +#define in4 +#undef in8 +#define in8 +#undef in16 +#define in16 + +#ifdef NO_TRANSPOSE +#undef incf +#define incf ra(di,si) +#else +#undef incf +#define incf +#endif + +#undef lf1 +#define lf1 mpx(R1) +#undef lf2 +#define lf2 lf1 incf mpx(R2) +#undef lf3 +#define lf3 lf2 incf mpx(R3) +#undef lf4 +#define lf4 lf3 incf mpx(R4) + +#undef lf +#define lf Mjoin(lf,NDP) + + +#undef ulf1 +#define ulf1 ulfa(R1) +#undef ulf2 +#define ulf2 ulf1 ra(di,si) ulfa(R2) +#undef ulf3 +#define ulf3 ulf2 ra(di,si) ulfa(R3) +#undef ulf4 +#define ulf4 ulf3 ra(di,si) ulfa(R4) + +#undef ulf +#define ulf Mjoin(ulf,NDP) + +#undef lpba +#define lpba(a_) "movl %%esi,%%e" #a_ "\n\t" + +#undef lpb1 +#define lpb1 lpba(ax) +#undef lpb2 +#define lpb2 lpb1 ra(di,si) lpba(bx) +#undef lpb3 +#define lpb3 lpb2 ra(di,si) lpba(cx) +#undef lpb4 +#define lpb4 lpb3 ra(di,si) lpba(dx) + +#undef lpb +#define lpb Mjoin(lpb,NDP) + +#undef ipf1 +#define ipf1(a_) pf(a_,si) pf(a_,ax) +#undef ipf2 +#define ipf2(a_) ipf1(a_) pf(a_,bx) +#undef ipf3 +#define ipf3(a_) ipf2(a_) pf(a_,cx) +#undef ipf4 +#define ipf4(a_) ipf3(a_) pf(a_,dx) + +#undef ipf +#define ipf(a_) Mjoin(ipf,NDP)(a_) + +#ifdef LUNROLL +#undef UNROLL +#ifdef SREAL +#undef UNROLL +#define UNROLL LUNROLL +#elif defined(DREAL) || defined(SCPLX) +#undef UNROLL +#define UNROLL LUNROLL*2 +#elif defined(DCPLX) +#undef UNROLL +#define UNROLL LUNROLL*4 +#endif +#else +#undef UNROLL +#define UNROLL 16 +#endif + +#undef UNROLL1_2 +#if UNROLL == 64 +#undef blUNROLL +#define blUNROLL bl64 +#undef UNROLL1_2 +#define UNROLL1_2 32 +#elif UNROLL == 32 +#undef blUNROLL +#define blUNROLL bl32 +#undef UNROLL1_2 +#define UNROLL1_2 16 +#elif UNROLL == 16 +#undef blUNROLL +#define blUNROLL bl16 +#undef UNROLL1_2 +#define UNROLL1_2 8 +#elif UNROLL == 8 +#undef blUNROLL +#define blUNROLL bl8 +#undef UNROLL1_2 +#define UNROLL1_2 4 +#elif UNROLL == 4 +#undef blUNROLL +#define blUNROLL bl4 +#undef UNROLL1_2 +#define UNROLL1_2 2 +#elif UNROLL == 2 +#undef blUNROLL +#define blUNROLL bl2 +#undef UNROLL1_2 +#define UNROLL1_2 1 +#elif UNROLL == 1 +#undef blUNROLL +#define blUNROLL bl1 +#undef UNROLL1_2 +#define UNROLL1_2 stop +#endif +#ifndef UNROLL1_2 +#error UNROLL must be set to power of 2 < 128 +#endif + + +#ifdef GER +#undef aconst +#define aconst +#undef cconst +#define cconst const +#else +#undef aconst +#define aconst const +#undef cconst +#define cconst +#endif + +#undef MY_FUNCTION +#define MY_FUNCTION Mjoin(dp,EXT) + +static void +MY_FUNCTION(aconst TYPE *a,int lda, + const TYPE *b, + cconst TYPE *c,int stride,int len) { + +#ifdef SCPLX +#if defined(GER) && defined(Conj_) + const TYPE w1[2]={{-1.0,1.0},{-1.0,1.0}},*w=w1; +#else + const TYPE w1[2]={{1.0,-1.0},{1.0,-1.0}},*w=w1; +#endif +#endif + +#if defined(DCPLX) && defined(ATL_SSE2) +#if defined(GER) && defined(Conj_) + const TYPE w1[1]={{-1.0,1.0}},*w=w1; +#else + const TYPE w1[1]={{1.0,-1.0}},*w=w1; +#endif +#endif + +#ifdef NO_TRANSPOSE +#undef movm +#define movm c +#undef fixm +#define fixm b +#else +#undef movm +#define movm b +#undef fixm +#define fixm c +#endif + NO_INLINE + unsigned u1=stride*sizeof(*fixm),u2=lda*sizeof(*a),u3=len*sizeof(*movm)/sizeof(float); + + ASM ( + + "pushl %%ebx\n\t" + a(4,sp) + +#if defined(SCPLX) || (defined(DCPLX) && defined(ATL_SSE2)) + "movl %6,%%esi\n\t" + pl(0,si,SREG) +#endif + +#ifdef NO_TRANSPOSE + "movl %1,%%esi\n\t" /* fixm */ + "movl %2,%%edi\n\t" /* fixm2fixm */ +#endif + + lf + + "movl %3,%%esi\n\t" /* a */ + "movl %4,%%edi\n\t" /* a2a */ + + lpb + + ipf(0) + + "movl %0,%%esi\n\t" /* movm */ + "movl %5,%%edi\n\t" /* len */ + +#if defined(ALIGN) + +#if defined(SREAL) + + test(4,ax) + je(Mjoin(a1,EXT)) + test(-1,di) + je(Mjoin(a1,EXT)) + sub(1,di) + bl1 + + lab(Mjoin(a1,EXT)) + +#endif + +#if defined(DREAL) || defined(SREAL) + + test(8,ax) + je(Mjoin(as,EXT)) + test(-2,di) + je(Mjoin(as,EXT)) + sub(2,di) + bl2 + + lab(Mjoin(as,EXT)) + +#endif + +#endif + + + ipf(32) + + lab(Mjoin(loop,EXT)) + + test(-UNROLL,di) + je(Mjoin(UNROLL1_2,EXT)) + sub(UNROLL,di) + + blUNROLL + + jmp(Mjoin(loop,EXT)) + +#if UNROLL > 32 + lab(Mjoin(32,EXT)) + test(32,di) + je(Mjoin(16,EXT)) + bl32 +#endif + +#if UNROLL > 16 + lab(Mjoin(16,EXT)) + test(16,di) + je(Mjoin(8,EXT)) + bl16 +#endif + +#if UNROLL > 8 + lab(Mjoin(8,EXT)) + test(8,di) + je(Mjoin(4,EXT)) + bl8 +#endif + +#if UNROLL > 4 + lab(Mjoin(4,EXT)) + test(4,di) + je(Mjoin(2,EXT)) + bl4 +#endif + +#if UNROLL > 2 + lab(Mjoin(2,EXT)) +#ifndef DCPLX + test(2,di) + je(Mjoin(1,EXT)) + bl2 +#endif +#endif + +#if UNROLL > 1 + lab(Mjoin(1,EXT)) +#ifdef SREAL + test(1,di) + je(Mjoin(stop,EXT)) + bl1 +#endif +#endif + + lab(Mjoin(stop,EXT)) + +#ifndef NO_TRANSPOSE + "movl %1,%%esi\n\t" /* fixm */ + "movl %2,%%edi\n\t" /* fixm2fixm */ +#endif + + ulf + + a(-4,sp) + "popl %%ebx\n\t" + + + ::"m" (movm),"m" (fixm),"m" (u1),"m" (a),"m" (u2),"m" (u3) + +#if defined(SCPLX) || (defined(DCPLX) && defined(ATL_SSE2)) + ,"m" (w) +#endif + :"ax","bx","cx","dx","si","di"); + + +} + diff --git a/kaldi_io/src/tools/ATLAS/include/contrib/camm_pipe3.h b/kaldi_io/src/tools/ATLAS/include/contrib/camm_pipe3.h new file mode 100644 index 0000000..7fd1404 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/contrib/camm_pipe3.h @@ -0,0 +1,295 @@ +#include "camm_util.h" + +#ifndef N +#error N must be defined in camm_pipe3.h +#endif +#ifndef KB +#error KB must be defined in camm_pipe3.h +#endif + +#undef p1 +#define p1(a_) Mjoin(p1_4_,N)(a_) +#undef p2 +#define p2(a_) Mjoin(p1_2_,N)(a_) +#undef p4 +#define p4(a_) Mjoin(p1_,N)(a_) +#undef load_pipe +#define load_pipe(a_) Mjoin(lp,N)(a_) +#undef drain_pipe +#define drain_pipe(a_) Mjoin(dp,N)(a_) +#undef pipe_len +#define pipe_len Mjoin(pl,N) + +#undef p8 +#if pipe_len > 4 +#define p8(a_) Mjoin(p2_,N)(a_) +#else +#define p8(a_) p4(a_) p4(SS(a_,16)) +#endif + +#undef p16 +#if pipe_len > 8 +#define p16(a_) Mjoin(p4_,N)(a_) +#else +#define p16(a_) p8(a_) p8(SS(a_,32)) +#endif + +#undef p32 +#if pipe_len > 16 +#define p32(a_) Mjoin(p8_,N)(a_) +#else +#define p32(a_) p16(a_) p16(SS(a_,64)) +#endif + +#undef p64 +#if pipe_len > 32 +#define p64(a_) Mjoin(p16_,N)(a_) +#else +#define p64(a_) p32(a_) p32(SS(a_,128)) +#endif + +#undef p128 +#if pipe_len > 64 +#define p128(a_) Mjoin(p32_,N)(a_) +#else +#define p128(a_) p64(a_) p64(SS(a_,256)) +#endif + +#undef p256 +#if pipe_len > 128 +#define p256(a_) Mjoin(p64_,N)(a_) +#else +#define p256(a_) p128(a_) p128(SS(a_,512)) +#endif + +#if KB < pipe_len +#undef pipe_len +#define pipe_len 0 +#undef load_pipe +#define load_pipe(a_) +#undef drain_pipe +#define drain_pipe(a_) +#endif + + +#undef MKB +/* #ifdef SREAL */ +#define MKB KB +/* #elif defined (DCPLX) */ +/* #define MKB ( KB * 4 ) */ +/* #else */ +/* #define MKB ( KB * 2 ) */ +/* #endif */ + +#if MKB >= 512 +#error MKB must be less than 512 +#endif + +#undef x0 +#undef o0 +#define x0 load_pipe(0) +#define o0 0 + +#undef MKBB +#define MKBB ( MKB - pipe_len ) + +#undef xx1 +#undef oo1 +#if MKBB >= 256 +#define xx1 x0 p256(o0) +#define oo1 SS(1024,o0) +#else +#define xx1 x0 +#define oo1 o0 +#endif + +#undef xx1a +#undef oo1a +#if pipe_len == 256 +#define xx1a xx1 drain_pipe(oo1) +#define oo1a SS(1024,oo1) +#undef MKBB +#define MKBB MKB +#else +#define xx1a xx1 +#define oo1a oo1 +#endif + +#undef x1 +#undef o1 +#if ( MKBB / 128 ) % 2 +#define x1 xx1a p128(oo1a) +#define o1 SS(512,oo1a) +#else +#define x1 xx1a +#define o1 oo1a +#endif + +#undef x1a +#undef o1a +#if pipe_len == 128 +#define x1a x1 drain_pipe(o1) +#define o1a SS(512,o1) +#undef MKBB +#define MKBB MKB +#else +#define x1a x1 +#define o1a o1 +#endif + +#undef x2 +#undef o2 +#if ( MKBB / 64 ) % 2 +#define x2 x1a p64(o1a) +#define o2 SS(256,o1a) +#else +#define x2 x1a +#define o2 o1a +#endif + +#undef x2a +#undef o2a +#if pipe_len == 64 +#define x2a x2 drain_pipe(o2) +#define o2a SS(256,o2) +#undef MKBB +#define MKBB MKB +#else +#define x2a x2 +#define o2a o2 +#endif + +#undef x3 +#undef o3 +#if ( MKBB / 32 ) % 2 +#define x3 x2a p32(o2a) +#define o3 SS(128,o2a) +#else +#define x3 x2a +#define o3 o2a +#endif + +#undef x3a +#undef o3a +#if pipe_len == 32 +#define x3a x3 drain_pipe(o3) +#define o3a SS(128,o3) +#undef MKBB +#define MKBB MKB +#else +#define x3a x3 +#define o3a o3 +#endif + +#undef x4 +#undef o4 +#if ( MKBB / 16 ) % 2 +#define x4 x3a p16(o3a) +#define o4 SS(64,o3a) +#else +#define x4 x3a +#define o4 o3a +#endif + +#undef x4a +#undef o4a +#if pipe_len == 16 +#define x4a x4 drain_pipe(o4) +#define o4a SS(64,o4) +#undef MKBB +#define MKBB MKB +#else +#define x4a x4 +#define o4a o4 +#endif + +#undef x5 +#undef o5 +#if ( MKBB / 8 ) % 2 +#define x5 x4a p8(o4a) +#define o5 SS(32,o4a) +#else +#define x5 x4a +#define o5 o4a +#endif + +#undef x5a +#undef o5a +#if pipe_len == 8 +#define x5a x5 drain_pipe(o5) +#define o5a SS(32,o5) +#undef MKBB +#define MKBB MKB +#else +#define x5a x5 +#define o5a o5 +#endif + +#undef x6 +#undef o6 +#if ( MKBB / 4 ) % 2 +#define x6 x5a p4(o5a) +#define o6 SS(16,o5a) +#else +#define x6 x5a +#define o6 o5a +#endif + +#undef x6a +#undef o6a +#if pipe_len == 4 +#define x6a x6 drain_pipe(o6) +#define o6a SS(16,o6) +#undef MKBB +#define MKBB MKB +#else +#define x6a x6 +#define o6a o6 +#endif + +#undef x7 +#undef o7 +#if ( MKB / 2 ) % 2 +#define x7 x6a p2(o6a) +#define o7 SS(8,o6a) +#else +#define x7 x6a +#define o7 o6a +#endif + +#undef x7a +#undef o7a +#if pipe_len == 2 +#define x7a x7 drain_pipe(o7) +#define o7a SS(8,o7) +#undef MKBB +#define MKBB MKB +#else +#define x7a x7 +#define o7a o7 +#endif + +#undef x8 +#undef o8 +#if ( MKB / 1 ) % 2 +#define x8 x7a p1(o7a) +#define o8 SS(4,o7a) +#else +#define x8 x7a +#define o8 o7a +#endif + +#undef x8a +#undef o8a +#if pipe_len == 1 +#define x8a x8 drain_pipe(o8) +#define o8a SS(4,o8) +#undef MKBB +#define MKBB MKB +#else +#define x8a x8 +#define o8a o8 +#endif + +#undef KB_block +#define KB_block x8a diff --git a/kaldi_io/src/tools/ATLAS/include/contrib/camm_scale.h b/kaldi_io/src/tools/ATLAS/include/contrib/camm_scale.h new file mode 100644 index 0000000..35e9e59 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/contrib/camm_scale.h @@ -0,0 +1,215 @@ +#ifndef CAMM_SCALE_H +#define CAMM_SCALE_H /*+ To stop multiple inclusions. +*/ + +#include "camm_util.h" + +#undef spf +#define spf(a_,b_) f(t0,a_,b_) + +#ifdef SCPLX +#ifdef BETAX +#undef SSREG +#define SSREG 2 +#undef lbx +#define lbx pls(4,ax,1) ps(0,1,1) pm(SSREG,1) +#undef cxx +#define cxx pm(1,3) ps(177,3,3) pa(3,2) +#undef pcx +#define pcx pc(2,3) +#else +#undef lbx +#define lbx +#undef cxx +#define cxx +#undef pcx +#define pcx +#endif +#undef lb +#define lb pls(0,ax,0) ps(0,0,0) lbx +#undef c +#define c(a_) pl(a_ ## 0,si,2) pcx pm(0,2) cxx pu(2,a_ ## 0,si) +#undef cp +#define cp(a_,b_) pl(a_ ## 0,si,2) pcx pm(0,2) spf(b_,si) cxx pu(2,a_ ## 0,si) +#undef c1_2 +#define c1_2(a_) px(2) pld(a_ ## 0,si,2) pcx pm(0,2) cxx pud(2,a_ ## 0,si) +#undef ub +#define ub +#endif + +#ifdef SREAL +#undef lb +#define lb pls(0,ax,0) ps(0,0,0) +#undef c +#define c(a_) pl(a_ ## 0,si,2) pm(0,2) pu(2,a_ ## 0,si) +#undef cp +#define cp(a_,b_) pl(a_ ## 0,si,2) spf(b_,si) pm(0,2) pu(2,a_ ## 0,si) +#undef c1_2 +#define c1_2(a_) px(2) pld(a_ ## 0,si,2) pm(0,2) pud(2,a_ ## 0,si) +#undef c1_4 +#define c1_4(a_) pls(a_ ## 0,si,2) pm(0,2) pus(2,a_ ## 0,si) +#undef ub +#define ub +#endif + +#ifdef DREAL +#undef lb +#define lb fl(0,ax) +#undef c +#define c(a_) fl(a_ ## 0,si) fm(1,0) fl(a_ ## 8,si) fm(2,0) fx1 \ + fp(a_ ## 0,si) fp(a_ ## 8,si) +#undef cp +#define cp(a_,b_) fl(a_ ## 0,si) fm(1,0) fl(a_ ## 8,si) spf(b_,si) fm(2,0) fx1 \ + fp(a_ ## 0,si) fp(a_ ## 8,si) +#undef c1_2 +#define c1_2(a_) fl(a_ ## 0,si) fm(1,0) fp(a_ ## 0,si) +#undef ub +#define ub fc(0) +#endif + +#ifdef DCPLX +#undef lb +#define lb fl(0,ax) fl(8,ax) +#undef c +#define c(a_) fl(a_ ## 0,si) fl(a_ ## 8,si) fd(3) fm(2,0) fd(3) \ + fm(2,0) fx(3) fm(4,0) fx(2) fm(5,0) fap(0,2) fx(2) fsp(2) fx1 \ + fp(a_ ## 0,si) fp(a_ ## 8,si) +#undef cp +#define cp(a_,b_) fl(a_ ## 0,si) fl(a_ ## 8,si) fd(3) fm(2,0) fd(3) \ + fm(2,0) fx(3) spf(b_,si) fm(4,0) fx(2) fm(5,0) fap(0,2) fx(2) \ + fsp(2) fx1 fp(a_ ## 0,si) fp(a_ ## 8,si) +#undef ub +#define ub fc(0) fc(0) +#endif + +#undef sbl1 +#define sbl1 c1_4(0x0) +#undef sbl2 +#define sbl2 c1_2(0x0) +#undef sbl4 +#define sbl4 cp(0x0,0x40) +#undef sbl8 +#define sbl8 sbl4 c(0x1) +#undef sbl16 +#define sbl16 sbl8 cp(0x2,0x60) c(0x3) + +#undef sinc16 +#define sinc16 a(0x40,si) +#undef sinc8 +#define sinc8 a(0x20,si) +#undef sinc4 +#define sinc4 a(0x10,si) +#undef sinc2 +#define sinc2 a(0x8,si) +#undef sinc1 +#define sinc1 a(0x4,si) + +#undef SCALE +#define SCALE Mjoin(Mjoin(PREC,Mjoin(scale,BLC)),FEXT) + +#undef MY_FUNCTION +#define MY_FUNCTION SCALE + +static void +MY_FUNCTION(const TYPE *b,TYPE *c,int len) { + + const TYPE *ce=c+len; +#if defined(BETAX) && defined(SCPLX) + const TYPE z1[2]={{1.0,-1.0},{1.0,-1.0}},*z=z1; +#endif + NO_INLINE + +#ifndef SREAL + len+=len; +#endif +#ifdef DCPLX + len+=len; +#endif + + + ASM( + + "pushl %%ebx\n\t" + a(4,sp) + + + "movl %0,%%esi\n\t" + + spf(0x00,si) + spf(0x20,si) + + "movl %1,%%eax\n\t" + "movl %2,%%edi\n\t" + +#if defined(BETAX) && defined(SCPLX) + "movl %3,%%ebx\n\t" + pl(0,bx,SSREG) +#endif + + lb + + lab(loop) + + test(-16,di) + je(8) + sub(16,di) + align + + sbl16 + sinc16 + + jmp(loop) + align + + lab(8) + + test(8,di) + je(4) + + sbl8 + sinc8 + + lab(4) + + test(4,di) + je(2) + + sbl4 + sinc4 + + lab(2) + +#ifndef DCPLX + test(2,di) + je(1) + + sbl2 + sinc2 + + lab(1) + +#ifdef SREAL + test(1,di) + je(stop) + + sbl1 + sinc1 + + lab(stop) +#endif +#endif + + ub + + a(-4,sp) + "popl %%ebx\n\t" + + + ::"m" (c),"m" (b), "m" (len) +#if defined(BETAX) && defined(SCPLX) + ,"m" (z) +#endif + : "si","ax","di"); + + +} +#endif /* CAMM_SCALE_H */ diff --git a/kaldi_io/src/tools/ATLAS/include/contrib/camm_strat1.h b/kaldi_io/src/tools/ATLAS/include/contrib/camm_strat1.h new file mode 100644 index 0000000..4a92006 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/contrib/camm_strat1.h @@ -0,0 +1,2982 @@ +#include "camm_util.h" + +#undef p1_4_swap_1 +#define p1_4_swap_1(a_) \ + pls(a_,ax,1) \ + pls(a_,cx,0) \ + pus(0,a_,ax) \ + pus(1,a_,cx) +#undef p1_2_swap_1 +#define p1_2_swap_1(a_) \ + px(1) \ + pld(a_,ax,1) \ + px(0) \ + pld(a_,cx,0) \ + pud(0,a_,ax) \ + pud(1,a_,cx) +#undef p1_swap_1 +#define p1_swap_1(a_) \ + plq(a_,ax,1) \ + pl(a_,cx,0) \ + puq(0,a_,ax) \ + pu(1,a_,cx) +#undef p2_swap_1 +#define p2_swap_1(a_) \ + plq(SS(a_,RS4),ax,3) \ + pl(SS(a_,RS4),cx,2) \ + puq(0,a_,ax) \ + pu(1,a_,cx) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,1) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + pl(SS(a_,MM(2,RS4)),cx,0) \ + puq(2,SS(a_,RS4),ax) \ + pu(3,SS(a_,RS4),cx) +#undef lpswap_1 +#define lpswap_1(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(SS(a_,MM(0,RS4)),ax,1) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),cx) \ + pl(SS(a_,MM(0,RS4)),cx,0) +#undef dpswap_1 +#define dpswap_1(a_) \ + plq(SS(a_,RS4),ax,3) \ + pl(SS(a_,RS4),cx,2) \ + puq(0,a_,ax) \ + pu(1,a_,cx) \ + puq(2,SS(a_,RS4),ax) \ + pu(3,SS(a_,RS4),cx) +#undef plswap_1 +#define plswap_1 8 + + +#undef p1_4_scal_3 +#define p1_4_scal_3(a_) \ + pls(a_,ax,0) \ + pmsr(6,0) \ + pus(0,a_,ax) +#undef p1_2_scal_3 +#define p1_2_scal_3(a_) \ + pld(a_,ax,0) \ + pm(6,0) \ + pud(0,a_,ax) +#undef p1_scal_3 +#define p1_scal_3(a_) \ + plq(a_,ax,0) \ + pm(6,0) \ + puq(0,a_,ax) +#undef p2_scal_3 +#define p2_scal_3(a_) \ + plq(a_,ax,0) \ + plq(SS(a_,RS4),ax,1) \ + pm(6,0) \ + pm(6,1) \ + puq(0,a_,ax) \ + puq(1,SS(a_,RS4),ax) +#undef p4_scal_3 +#define p4_scal_3(a_) \ + plq(SS(a_,MM(3,RS4)),ax,3) \ + pm(6,2) \ + puq(0,a_,ax) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(4,RS4)),ax,0) \ + pm(6,3) \ + puq(1,SS(a_,RS4),ax) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(5,RS4)),ax,1) \ + pm(6,0) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),ax) \ + plq(SS(a_,MM(6,RS4)),ax,2) \ + pm(6,1) \ + puq(3,SS(a_,MM(3,RS4)),ax) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),ax) +#undef lpscal_3 +#define lpscal_3(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(SS(a_,MM(0,RS4)),ax,0) \ + plq(SS(a_,MM(1,RS4)),ax,1) \ + pm(6,0) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,2) \ + pm(6,1) +#undef dpscal_3 +#define dpscal_3(a_) \ + plq(SS(a_,MM(3,RS4)),ax,3) \ + pm(6,2) \ + puq(0,a_,ax) \ + pm(6,3) \ + puq(1,SS(a_,RS4),ax) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + puq(3,SS(a_,MM(3,RS4)),ax) +#undef plscal_3 +#define plscal_3 16 + +#undef p1_4_scal_3c +#define p1_4_scal_3c(a_) +#undef p1_2_scal_3c +#define p1_2_scal_3c(a_) \ + pld(a_,ax,0) \ + pc(0,1) \ + pm(6,0) \ + ps(CSHUF,1,1) \ + pm(7,1) \ + pa(1,0) \ + pud(0,a_,ax) +#undef p1_scal_3c +#define p1_scal_3c(a_) \ + plq(a_,ax,0) \ + pc(0,1) \ + pm(6,0) \ + ps(CSHUF,1,1) \ + pm(7,1) \ + pa(1,0) \ + puq(0,a_,ax) +#undef p2_scal_3c +#define p2_scal_3c(a_) \ + plq(a_,ax,0) \ + plq(SS(a_,RS4),ax,1) \ + pc(0,2) \ + pm(6,0) \ + ps(CSHUF,2,2) \ + pm(7,2) \ + pa(2,0) \ + puq(0,a_,ax) \ + pc(1,3) \ + pm(6,1) \ + ps(CSHUF,3,3) \ + pm(7,3) \ + pa(3,1) \ + puq(1,SS(a_,RS4),ax) +#undef p4_scal_3c +#define p4_scal_3c(a_) \ + pm(7,5) \ + pa(5,1) \ + puq(0,a_,ax) \ + ps(CSHUF,4,4) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(4,RS4)),ax,0) \ + pc(3,5) \ + pm(6,3) \ + pm(7,4) \ + pa(4,2) \ + puq(1,SS(a_,RS4),ax) \ + ps(CSHUF,5,5) \ + plq(SS(a_,MM(5,RS4)),ax,1) \ + pc(0,4) \ + pm(6,0) \ + pm(7,5) \ + pa(5,3) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + ps(CSHUF,4,4) \ + plq(SS(a_,MM(6,RS4)),ax,2) \ + pc(1,5) \ + pm(6,1) \ + pm(7,4) \ + pa(4,0) \ + puq(3,SS(a_,MM(3,RS4)),ax) \ + ps(CSHUF,5,5) \ + plq(SS(a_,MM(7,RS4)),ax,3) \ + pc(2,4) \ + pm(6,2) +#undef lpscal_3c +#define lpscal_3c(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(SS(a_,MM(0,RS4)),ax,0) \ + plq(SS(a_,MM(1,RS4)),ax,1) \ + pc(0,4) \ + pm(6,0) \ + ps(CSHUF,4,4) \ + plq(SS(a_,MM(2,RS4)),ax,2) \ + pc(1,5) \ + pm(6,1) \ + pm(7,4) \ + pa(4,0) \ + ps(CSHUF,5,5) \ + plq(SS(a_,MM(3,RS4)),ax,3) \ + pc(2,4) \ + pm(6,2) +#undef dpscal_3c +#define dpscal_3c(a_) \ + pm(7,5) \ + pa(5,1) \ + ps(CSHUF,4,4) \ + puq(0,a_,ax) \ + pm(7,4) \ + pa(4,2) \ + pc(3,5) \ + pm(6,3) \ + puq(1,SS(a_,RS4),ax) \ + ps(CSHUF,5,5) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + pm(7,5) \ + pa(5,3) \ + puq(3,SS(a_,MM(3,RS4)),ax) +#undef plscal_3c +#define plscal_3c 16 + +#undef p1_4_scal_4 +#define p1_4_scal_4(a_) \ + pls(SS(a_,MM(0,RS4)),ax,0) \ + pmsr(6,0) \ + pus(0,a_,ax) +#undef p1_2_scal_4 +#define p1_2_scal_4(a_) \ + pld(SS(a_,MM(0,RS4)),ax,0) \ + pm(6,0) \ + pud(0,a_,ax) +#undef p1_scal_4 +#define p1_scal_4(a_) \ + plq(SS(a_,MM(0,RS4)),ax,0) \ + pm(6,0) \ + puq(0,a_,ax) +#undef p2_scal_4 +#define p2_scal_4(a_) \ + plq(SS(a_,MM(0,RS4)),ax,0) \ + plq(SS(a_,MM(1,RS4)),ax,1) \ + pm(6,0) \ + pm(6,1) \ + puq(0,a_,ax) \ + puq(1,SS(a_,RS4),ax) +#undef p4_scal_4 +#define p4_scal_4(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(SS(a_,MM(0,RS4)),ax,0) \ + plq(SS(a_,MM(1,RS4)),ax,1) \ + plq(SS(a_,MM(2,RS4)),ax,2) \ + plq(SS(a_,MM(3,RS4)),ax,3) \ + pm(6,0) \ + pm(6,1) \ + pm(6,2) \ + pm(6,3) \ + puq(0,a_,ax) \ + puq(1,SS(a_,RS4),ax) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + puq(3,SS(a_,MM(3,RS4)),ax) +#undef p8_scal_4 +#define p8_scal_4(a_) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(0,RS4)),ax,0) \ + plq(SS(a_,MM(1,RS4)),ax,1) \ + plq(SS(a_,MM(2,RS4)),ax,2) \ + plq(SS(a_,MM(3,RS4)),ax,3) \ + plq(SS(a_,MM(4,RS4)),ax,4) \ + plq(SS(a_,MM(5,RS4)),ax,5) \ + plq(SS(a_,MM(6,RS4)),ax,7) \ + pm(6,0) \ + pm(6,1) \ + pm(6,2) \ + puq(0,a_,ax) \ + pm(6,3) \ + pm(6,4) \ + pm(6,5) \ + plq(SS(a_,MM(7,RS4)),ax,0) \ + pm(6,7) \ + pm(6,0) \ + puq(1,SS(a_,RS4),ax) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + puq(3,SS(a_,MM(3,RS4)),ax) \ + puq(4,SS(a_,MM(4,RS4)),ax) \ + puq(5,SS(a_,MM(5,RS4)),ax) \ + puq(7,SS(a_,MM(6,RS4)),ax) \ + puq(0,SS(a_,MM(7,RS4)),ax) +#undef lpscal_4 +#define lpscal_4(a_) +#undef dpscal_4 +#define dpscal_4(a_) p4_scal_4(a_) +#undef plscal_4 +#define plscal_4 16 + +#undef p1_4_scal_4c +#define p1_4_scal_4c(a_) +#undef p1_2_scal_4c +#define p1_2_scal_4c(a_) \ + pld(a_,ax,0) \ + pc(0,1) \ + pm(6,0) \ + ps(CSHUF,1,1) \ + pm(7,1) \ + pa(1,0) \ + pud(0,a_,ax) +#undef p1_scal_4c +#define p1_scal_4c(a_) \ + plq(a_,ax,0) \ + pc(0,1) \ + pm(6,0) \ + ps(CSHUF,1,1) \ + pm(7,1) \ + pa(1,0) \ + puq(0,a_,ax) +#undef p2_scal_4c +#define p2_scal_4c(a_) \ + plq(SS(a_,MM(0,RS4)),ax,0) \ + plq(SS(a_,MM(1,RS4)),ax,1) \ + pc(0,4) \ + pc(1,5) \ + pm(6,0) \ + pm(6,1) \ + ps(CSHUF,4,4) \ + ps(CSHUF,5,5) \ + pm(7,4) \ + pa(4,0) \ + pm(7,5) \ + pa(5,1) \ + puq(0,a_,ax) \ + puq(1,SS(a_,RS4),ax) +#undef p4_scal_4c +#define p4_scal_4c(a_) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(0,RS4)),ax,0) \ + plq(SS(a_,MM(1,RS4)),ax,1) \ + plq(SS(a_,MM(2,RS4)),ax,2) \ + plq(SS(a_,MM(3,RS4)),ax,3) \ + pc(0,4) \ + pc(1,5) \ + pm(6,0) \ + pm(6,1) \ + ps(CSHUF,4,4) \ + ps(CSHUF,5,5) \ + pm(7,4) \ + pa(4,0) \ + pc(2,4) \ + pm(7,5) \ + pa(5,1) \ + pc(3,5) \ + pm(6,2) \ + pm(6,3) \ + ps(CSHUF,4,4) \ + ps(CSHUF,5,5) \ + pm(7,4) \ + pa(4,2) \ + pm(7,5) \ + pa(5,3) \ + puq(0,a_,ax) \ + puq(1,SS(a_,RS4),ax) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + puq(3,SS(a_,MM(3,RS4)),ax) +#undef lpscal_4c +#define lpscal_4c(a_) +#undef dpscal_4c +#define dpscal_4c(a_) p4_scal_4c(a_) +#undef plscal_4c +#define plscal_4c 16 + +#undef p1_4_scal_1 +#define p1_4_scal_1(a_) \ + pls(a_,ax,1) \ + pmsr(0,1) \ + pus(1,a_,ax) +#undef p1_2_scal_1 +#define p1_2_scal_1(a_) \ + px(1) \ + pld(a_,ax,1) \ + pm(0,1) \ + pud(1,a_,ax) +#undef p1_scal_1 +#define p1_scal_1(a_) \ + plq(a_,ax,1) \ + pm(0,1) \ + puq(1,a_,ax) +#undef p2_scal_1 +#define p2_scal_1(a_) \ + plq(a_,ax,1) \ + plq(SS(a_,RS4),ax,2) \ + pm(0,1) \ + pm(0,2) \ + puq(1,a_,ax) \ + puq(2,SS(a_,RS4),ax) +#undef p4_scal_1 +#define p4_scal_1(a_) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,1) \ + pm(0,3) \ + puq(7,a_,ax) \ + plq(SS(a_,MM(3,RS4)),ax,2) \ + pm(0,1) \ + puq(3,SS(a_,MM(1,RS4)),ax) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),ax) \ + plq(SS(a_,MM(4,RS4)),ax,7) \ + pm(0,2) \ + puq(1,SS(a_,MM(2,RS4)),ax) \ + plq(SS(a_,MM(5,RS4)),ax,3) \ + pm(0,7) \ + puq(2,SS(a_,MM(3,RS4)),ax) +#undef lpscal_1 +#define lpscal_1(a_) \ + plq(a_,ax,7) \ + plq(SS(a_,MM(1,RS4)),ax,3) \ + pm(0,7) +#undef dpscal_1 +#define dpscal_1(a_) \ + plq(SS(a_,MM(2,RS4)),ax,1) \ + pm(0,3) \ + puq(7,a_,ax) \ + plq(SS(a_,MM(3,RS4)),ax,2) \ + pm(0,1) \ + puq(3,SS(a_,MM(1,RS4)),ax) \ + pm(0,2) \ + puq(1,SS(a_,MM(2,RS4)),ax) \ + puq(2,SS(a_,MM(3,RS4)),ax) +#undef plscal_1 +#define plscal_1 RS4 + + +#undef p1_4_set_1 +#define p1_4_set_1(a_) \ + pls(a_,ax,1) \ + pcs(0,1) \ + pus(1,a_,ax) +#undef p1_2_set_1 +#define p1_2_set_1(a_) \ + px(1) \ + pld(a_,ax,1) \ + pc(0,1) \ + pud(1,a_,ax) +#undef p1_set_1 +#define p1_set_1(a_) \ + plq(a_,ax,1) \ + pc(0,1) \ + puq(1,a_,ax) +#undef p2_set_1 +#define p2_set_1(a_) \ + plq(a_,ax,1) \ + plq(SS(a_,RS4),ax,2) \ + pc(0,1) \ + pc(0,2) \ + puq(1,a_,ax) \ + puq(2,SS(a_,RS4),ax) +#undef p4_set_1 +#define p4_set_1(a_) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,1) \ + pc(0,3) \ + puq(7,a_,ax) \ + plq(SS(a_,MM(3,RS4)),ax,2) \ + pc(0,1) \ + puq(3,SS(a_,MM(1,RS4)),ax) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),ax) \ + plq(SS(a_,MM(4,RS4)),ax,7) \ + pc(0,2) \ + puq(1,SS(a_,MM(2,RS4)),ax) \ + plq(SS(a_,MM(5,RS4)),ax,3) \ + pc(0,7) \ + puq(2,SS(a_,MM(3,RS4)),ax) +#undef lpset_1 +#define lpset_1(a_) \ + plq(a_,ax,7) \ + plq(SS(a_,MM(1,RS4)),ax,3) \ + pc(0,7) +#undef dpset_1 +#define dpset_1(a_) \ + plq(SS(a_,MM(2,RS4)),ax,1) \ + pc(0,3) \ + puq(7,a_,ax) \ + plq(SS(a_,MM(3,RS4)),ax,2) \ + pc(0,1) \ + puq(3,SS(a_,MM(1,RS4)),ax) \ + pc(0,2) \ + puq(1,SS(a_,MM(2,RS4)),ax) \ + puq(2,SS(a_,MM(3,RS4)),ax) +#undef plset_1 +#define plset_1 RS4 + + +#undef p1_4_set_2 +#define p1_4_set_2(a_) \ + pus(0,a_,ax) +#undef p1_2_set_2 +#define p1_2_set_2(a_) \ + pud(0,a_,ax) +#undef p1_set_2 +#define p1_set_2(a_) \ + puq(0,a_,ax) +#undef p2_set_2 +#define p2_set_2(a_) \ + puq(0,a_,ax) \ + puq(0,SS(a_,RS4),ax) +#undef p4_set_2 +#define p4_set_2(a_) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + puq(0,a_,ax) \ + puq(0,SS(a_,MM(1,RS4)),ax) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),ax) \ + puq(0,SS(a_,MM(2,RS4)),ax) \ + puq(0,SS(a_,MM(3,RS4)),ax) +#undef lpset_2 +#define lpset_2(a_) +#undef dpset_2 +#define dpset_2(a_) \ + puq(0,a_,ax) \ + puq(0,SS(a_,MM(1,RS4)),ax) \ + puq(0,SS(a_,MM(2,RS4)),ax) \ + puq(0,SS(a_,MM(3,RS4)),ax) +#undef plset_2 +#define plset_2 RS4 + + +#undef p1_4_set_3 +#define p1_4_set_3(a_) \ + pus(0,a_,ax) +#undef p1_2_set_3 +#define p1_2_set_3(a_) \ + pud(0,a_,ax) +#undef p1_set_3 +#define p1_set_3(a_) \ + puq(0,SS(a_,MM(0,RS4)),ax) +#undef p2_set_3 +#define p2_set_3(a_) \ + puq(0,SS(a_,MM(0,RS4)),ax) \ + puq(0,SS(a_,MM(1,RS4)),ax) +#undef p4_set_3 +#define p4_set_3(a_) \ + puq(0,SS(a_,MM(0,RS4)),ax) \ + puq(0,SS(a_,MM(1,RS4)),ax) \ + puq(0,SS(a_,MM(2,RS4)),ax) \ + puq(0,SS(a_,MM(3,RS4)),ax) +#undef p8_set_3 +#define p8_set_3(a_) \ + puq(0,SS(a_,MM(0,RS4)),ax) \ + puq(0,SS(a_,MM(1,RS4)),ax) \ + puq(0,SS(a_,MM(2,RS4)),ax) \ + puq(0,SS(a_,MM(3,RS4)),ax) \ + puq(0,SS(a_,MM(4,RS4)),ax) \ + puq(0,SS(a_,MM(5,RS4)),ax) \ + puq(0,SS(a_,MM(6,RS4)),ax) \ + puq(0,SS(a_,MM(7,RS4)),ax) +#undef lpset_3 +#define lpset_3(a_) +#undef dpset_3 +#define dpset_3(a_) p8_set_3(a_) +#undef plset_3 +#define plset_3 32 + + +#undef p1_4_0x1_nrm2_1 +#define p1_4_0x1_nrm2_1(a_) \ + pls(a_,ax,1) \ + pmsr(1,1) \ + pasr(1,0) +#undef p1_2_0x1_nrm2_1 +#define p1_2_0x1_nrm2_1(a_) \ + px(1) \ + pld(a_,ax,1) \ + pm(1,1) \ + pa(1,0) +#undef p1_0x1_nrm2_1 +#define p1_0x1_nrm2_1(a_) \ + plq(a_,ax,1) \ + pm(1,1) \ + pa(1,0) +#undef p2_0x1_nrm2_1 +#define p2_0x1_nrm2_1(a_) \ + plq(a_,ax,1) \ + plq(SS(a_,RS4),ax,2) \ + pm(1,1) \ + pm(2,2) \ + pa(1,0) \ + pm(2,0) +#undef p4_0x1_nrm2_1 +#define p4_0x1_nrm2_1(a_) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,1) \ + pm(3,3) \ + pa(7,0) \ + plq(SS(a_,MM(3,RS4)),ax,2) \ + pm(1,1) \ + pa(3,0) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),ax) \ + plq(SS(a_,MM(4,RS4)),ax,7) \ + pm(2,2) \ + pa(1,0) \ + plq(SS(a_,MM(5,RS4)),ax,3) \ + pm(7,7) \ + pa(2,0) +#undef lp0x1_nrm2_1 +#define lp0x1_nrm2_1(a_) \ + plq(a_,ax,7) \ + plq(SS(a_,MM(1,RS4)),ax,3) \ + pm(7,7) +#undef dp0x1_nrm2_1 +#define dp0x1_nrm2_1(a_) \ + plq(SS(a_,MM(2,RS4)),ax,1) \ + pm(3,3) \ + pa(7,0) \ + plq(SS(a_,MM(3,RS4)),ax,2) \ + pm(1,1) \ + pa(3,0) \ + pm(2,2) \ + pa(1,0) \ + pa(2,0) +#undef pl0x1_nrm2_1 +#define pl0x1_nrm2_1 RS4 + + +#undef p1_4_nrm2_2 +#define p1_4_nrm2_2(a_) \ + pls(a_,ax,1) dbg(1) \ + pan(4,1) dbg(1) \ + pcs(5,6) dbg(6) \ + pcs(5,7) dbg(7) \ + paxs(1,5) dbg(5) \ + prps(5,2) dbg(2) \ + px(3) \ + pcms(0,2,3) dbg(3) \ + pan(3,7) dbg(7) \ + pann(5,3) dbg(3) \ + pasr(3,7) dbg(7) \ + pcs(7,5) dbg(5) \ + pdsr(5,6) dbg(6) \ + pdsr(5,1) dbg(1) \ + pmsr(6,6) dbg(6) \ + pmsr(1,1) dbg(1) \ + pm(6,0) dbg(0) \ + pasr(1,0) dbg(0) +#undef p1_2_nrm2_2 +#define p1_2_nrm2_2(a_) \ + px(1) pld(a_,ax,1) dbg(1) \ + pan(4,1) dbg(1) \ + pc(5,6) dbg(6) \ + pc(5,7) dbg(7) \ + pax(1,5) dbg(5) \ + prp(5,2) dbg(2) \ + px(3) \ + pcm(0,2,3)dbg(3) \ + pan(3,7) dbg(7) \ + pann(5,3) dbg(3) \ + pa(3,7) dbg(7) \ + pc(7,5) dbg(5) \ + pd(5,6) dbg(6) \ + pd(5,1) dbg(1) \ + pm(6,6) dbg(6) \ + pm(1,1) dbg(1) \ + pm(6,0) dbg(0) \ + pa(1,0) dbg(0) +#undef p1_nrm2_2 +#define p1_nrm2_2(a_) \ + plq(a_,ax,1) dbg(1) \ + pan(4,1) dbg(1) \ + pc(5,6) dbg(6) \ + pc(5,7) dbg(7) \ + pax(1,5) dbg(5) \ + prp(5,2) dbg(2) \ + px(3) \ + pcm(0,2,3)dbg(3) \ + pan(3,7) dbg(7) \ + pann(5,3) dbg(3) \ + pa(3,7) dbg(7) \ + pc(7,5) dbg(5) \ + pd(5,6) dbg(6) \ + pd(5,1) dbg(1) \ + pm(6,6) dbg(6) \ + pm(1,1) dbg(1) \ + pm(6,0) dbg(0) \ + pa(1,0) dbg(0) +#define p2_nrm2_2(a_) \ + plq(SS(a_,RS4),ax,1) dbg(1) \ + pan(4,1) dbg(1) \ + pc(5,6) dbg(6) \ + pc(5,7) dbg(7) \ + pax(1,5) dbg(5) \ + prp(5,2) dbg(2) \ + px(3) \ + pcm(0,2,3)dbg(3) \ + pan(3,7) dbg(7) \ + pann(5,3) dbg(3) \ + pa(3,7) dbg(7) \ + pc(7,5) dbg(5) \ + pd(5,6) dbg(6) \ + pd(5,1) dbg(1) \ + pm(6,6) dbg(6) \ + pm(1,1) dbg(1) \ + pm(6,0) dbg(0) \ + pa(1,0) dbg(0) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,1) dbg(1) \ + pan(4,1) dbg(1) \ + pc(5,6) dbg(6) \ + pc(5,7) dbg(7) \ + pax(1,5) dbg(5) \ + prp(5,2) dbg(2) \ + px(3) \ + pcm(0,2,3)dbg(3) \ + pan(3,7) dbg(7) \ + pann(5,3) dbg(3) \ + pa(3,7) dbg(7) \ + pc(7,5) dbg(5) \ + pd(5,6) dbg(6) \ + pd(5,1) dbg(1) \ + pm(6,6) dbg(6) \ + pm(1,1) dbg(1) \ + pm(6,0) dbg(0) \ + pa(1,0) dbg(0) +#undef lpnrm2_2 +#define lpnrm2_2(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(SS(a_,MM(0,RS4)),ax,1) dbg(1) \ + pan(4,1) dbg(1) \ + pc(5,6) dbg(6) \ + pc(5,7) dbg(7) \ + pax(1,5) dbg(5) \ + prp(5,2) dbg(2) \ + px(3) \ + pcm(0,2,3)dbg(3) \ + pan(3,7) dbg(7) \ + pann(5,3) dbg(3) \ + pa(3,7) dbg(7) \ + pc(7,5) dbg(5) \ + pd(5,6) dbg(6) \ + pd(5,1) dbg(1) \ + pm(6,6) dbg(6) \ + pm(1,1) dbg(1) \ + pm(6,0) dbg(0) \ + pa(1,0) dbg(0) +#undef dpnrm2_2 +#define dpnrm2_2(a_) \ + plq(SS(a_,RS4),ax,1) dbg(1) \ + pan(4,1) dbg(1) \ + pc(5,6) dbg(6) \ + pc(5,7) dbg(7) \ + pax(1,5) dbg(5) \ + prp(5,2) dbg(2) \ + px(3) \ + pcm(0,2,3)dbg(3) \ + pan(3,7) dbg(7) \ + pann(5,3) dbg(3) \ + pa(3,7) dbg(7) \ + pc(7,5) dbg(5) \ + pd(5,6) dbg(6) \ + pd(5,1) dbg(1) \ + pm(6,6) dbg(6) \ + pm(1,1) dbg(1) \ + pm(6,0) dbg(0) \ + pa(1,0) dbg(0) +#undef plnrm2_2 +#define plnrm2_2 8 + + +#undef p1_4_nrm2_3 +#define p1_4_nrm2_3(a_) \ + pls(a_,ax,1) dbg(1) \ + pcs(5,6) dbg(6) \ + pan(4,1) dbg(1) \ + paxs(1,5) dbg(5) \ + pdsr(5,6) dbg(6) \ + pdsr(5,1) dbg(1) \ + pmsr(6,6) dbg(6) \ + pmsr(1,1) dbg(1) \ + pm(6,0) dbg(0) \ + pasr(1,0) dbg(0) +#undef p1_2_nrm2_3 +#define p1_2_nrm2_3(a_) \ + px(1) pld(a_,ax,1) dbg(1) \ + pc(5,6) dbg(6) \ + pan(4,1) dbg(1) \ + pax(1,5) dbg(5) \ + pd(5,6) dbg(6) \ + pd(5,1) dbg(1) \ + pm(6,6) dbg(6) \ + pm(1,1) dbg(1) \ + pm(6,0) dbg(0) \ + pa(1,0) dbg(0) +#undef p1_nrm2_3 +#define p1_nrm2_3(a_) \ + plq(a_,ax,1) dbg(1) \ + pc(5,6) dbg(6) \ + pan(4,1) dbg(1) \ + pax(1,5) dbg(5) \ + pd(5,6) dbg(6) \ + pd(5,1) dbg(1) \ + pm(6,6) dbg(6) \ + pm(1,1) dbg(1) \ + pm(6,0) dbg(0) \ + pa(1,0) dbg(0) +#define p2_nrm2_3(a_) \ + plq(SS(a_,RS4),ax,1) dbg(1) \ + pc(5,6) dbg(6) \ + pan(4,1) dbg(1) \ + pax(1,5) dbg(5) \ + pd(5,6) dbg(6) \ + pd(5,1) dbg(1) \ + pm(6,6) dbg(6) \ + pm(1,1) dbg(1) \ + pm(6,0) dbg(0) \ + pa(1,0) dbg(0) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,1) dbg(1) \ + pc(5,6) dbg(6) \ + pan(4,1) dbg(1) \ + pax(1,5) dbg(5) \ + pd(5,6) dbg(6) \ + pd(5,1) dbg(1) \ + pm(6,6) dbg(6) \ + pm(1,1) dbg(1) \ + pm(6,0) dbg(0) \ + pa(1,0) dbg(0) +#undef lpnrm2_3 +#define lpnrm2_3(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(SS(a_,MM(0,RS4)),ax,1) dbg(1) \ + pc(5,6) dbg(6) \ + pan(4,1) dbg(1) \ + pax(1,5) dbg(5) \ + pd(5,6) dbg(6) \ + pd(5,1) dbg(1) \ + pm(6,6) dbg(6) \ + pm(1,1) dbg(1) \ + pm(6,0) dbg(0) \ + pa(1,0) dbg(0) +#undef dpnrm2_3 +#define dpnrm2_3(a_) \ + plq(SS(a_,RS4),ax,1) dbg(1) \ + pc(5,6) dbg(6) \ + pan(4,1) dbg(1) \ + pax(1,5) dbg(5) \ + pd(5,6) dbg(6) \ + pd(5,1) dbg(1) \ + pm(6,6) dbg(6) \ + pm(1,1) dbg(1) \ + pm(6,0) dbg(0) \ + pa(1,0) dbg(0) +#undef plnrm2_3 +#define plnrm2_3 8 + +#define block_nrm2_4(a_,b_) \ + Mjoin(pc,a_)(5,6) dbg(6) \ + pan(4,1) dbg(1) \ + Mjoin(pax,a_)(1,5) dbg(5) \ + Mjoin(pc,a_)(2,7) dbg(7) \ + Mjoin(pd,b_)(5,7) dbg(7) \ + Mjoin(pm,b_)(7,6) dbg(6) \ + Mjoin(pm,b_)(7,1) dbg(1) \ + Mjoin(pm,b_)(6,6) dbg(6) \ + Mjoin(pm,b_)(6,0) dbg(0) \ + Mjoin(pm,b_)(1,1) dbg(1) \ + Mjoin(pa,b_)(1,0) dbg(0) + + +/* #undef p1_4_nrm2_4 */ +/* #define p1_4_nrm2_4(a_) \ */ +/* pls(a_,ax,1) dbg(1) \ */ +/* pcs(5,6) dbg(6) \ */ +/* pan(4,1) dbg(1) \ */ +/* paxs(1,5) dbg(5) \ */ +/* pcs(2,7) dbg(7) \ */ +/* pdsr(5,7) dbg(7) \ */ +/* pmsr(7,6) dbg(6) \ */ +/* pmsr(7,1) dbg(1) \ */ +/* pmsr(6,6) dbg(6) \ */ +/* pmsr(6,0) dbg(0) \ */ +/* pmsr(1,1) dbg(1) \ */ +/* pasr(1,0) dbg(0) */ +#undef p1_4_nrm2_4 +#define p1_4_nrm2_4(a_) \ + pls(a_,ax,1) dbg(1) \ + block_nrm2_4(s,sr) +#undef p1_2_nrm2_4 +#define p1_2_nrm2_4(a_) \ + px(1) pld(a_,ax,1) dbg(1) \ + block_nrm2_4(,) +#undef p1_nrm2_4 +#define p1_nrm2_4(a_) \ + plq(a_,ax,1) dbg(1) \ + block_nrm2_4(,) +#define p2_nrm2_4(a_) \ + plq(SS(a_,RS4),ax,1) dbg(1) \ + block_nrm2_4(,) \ + plq(SS(a_,MM(2,RS4)),ax,1) dbg(1) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + block_nrm2_4(,) +#undef lpnrm2_4 +#define lpnrm2_4(a_) \ + plq(SS(a_,MM(0,RS4)),ax,1) dbg(1) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + block_nrm2_4(,) +#undef dpnrm2_4 +#define dpnrm2_4(a_) \ + plq(SS(a_,RS4),ax,1) dbg(1) \ + block_nrm2_4(,) +#undef plnrm2_4 +#define plnrm2_4 8 + + +#undef p1_4_1x1_1 +#define p1_4_1x1_1(a_) \ + pls(a_,ax,1) \ + pls(a_,bx,0) \ + pm(0,1) \ + pa(1,6) +#undef p1_2_1x1_1 +#define p1_2_1x1_1(a_) \ + pld(a_,ax,1) \ + pld(a_,bx,0) \ + pm(0,1) \ + pa(1,6) +#undef p1_1x1_1 +#define p1_1x1_1(a_) \ + plq(a_,ax,1) \ + plq(a_,bx,0) \ + pm(0,1) \ + pa(0,6) +#undef p2_1x1_1 +#define p2_1x1_1(a_) \ + plq(a_,ax,1) \ + plq(a_,bx,0) \ + plq(SS(a_,RS4),ax,2) \ + plq(SS(a_,RS4),bx,3) \ + pm(0,1) \ + pm(2,3) \ + pa(1,6) \ + pa(3,6) +#undef p4_1x1_1 +#define p4_1x1_1(a_) \ + f(nta,SS(a_,MM(4,RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,1) \ + plq(SS(a_,MM(2,RS4)),ax,1) \ + pm(0,3) \ + puq(7,a_,ax) \ + plq(SS(a_,MM(3,RS4)),ax,2) \ + pm(0,1) \ + puq(3,SS(a_,RS4),ax) \ + f(nta,SS(a_,MM(6,RS4)),ax) \ + plq(SS(a_,MM(4,RS4)),ax,7) \ + pm(0,2) \ + puq(1,SS(a_,MM(2,RS4)),ax) \ + plq(SS(a_,MM(5,RS4)),ax,3) \ + pm(0,7) \ + puq(2,SS(a_,MM(3,RS4)),ax) +#undef lp1x1_1 +#define lp1x1_1(a_) \ + plq(a_,ax,7) \ + plq(SS(a_,RS4),ax,3) \ + pm(0,7) +#undef dp1x1_1 +#define dp1x1_1(a_) \ + plq(SS(,a_,MM(2,RS4)),ax,1) \ + pm(0,3) \ + puq(7,a_,ax) \ + plq(SS(a_,MM(3,RS4)),ax,2) \ + pm(0,1) \ + puq(3,SS(a_,RS4),ax) \ + pm(0,2) \ + puq(1,SS(a_,MM(2,RS4)),ax) \ + puq(2,SS(a_,MM(3,RS4)),ax) +#undef pl1x1_1 +#define pl1x1_1 RS4 + + +#undef p1_4_0x1_asum_1 +#define p1_4_0x1_asum_1(a_) \ + pls(a_,ax,1) \ + pan(4,1) \ + pasr(1,0) +#undef p1_2_0x1_asum_1 +#define p1_2_0x1_asum_1(a_) \ + px(1) \ + pld(a_,ax,1) \ + pan(4,1) \ + pa(1,0) +#undef p1_0x1_asum_1 +#define p1_0x1_asum_1(a_) \ + plq(a_,ax,1) \ + pan(4,1) \ + pa(1,0) +#undef p2_0x1_asum_1 +#define p2_0x1_asum_1(a_) \ + plq(a_,ax,1) \ + plq(SS(a_,RS4),ax,2) \ + pan(4,1) \ + pan(4,2) \ + pa(1,0) \ + pa(2,0) +#undef p4_0x1_asum_1 +#define p4_0x1_asum_1(a_) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,1) \ + pan(4,3) \ + pa(7,0) \ + plq(SS(a_,MM(3,RS4)),ax,2) \ + pan(4,1) \ + pa(3,0) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),ax) \ + plq(SS(a_,MM(4,RS4)),ax,7) \ + pan(4,2) \ + pa(1,0) \ + plq(SS(a_,MM(5,RS4)),ax,3) \ + pan(4,7) \ + pa(2,0) +#undef lp0x1_asum_1 +#define lp0x1_asum_1(a_) \ + plq(a_,ax,7) \ + plq(SS(a_,MM(1,RS4)),ax,3) \ + pan(4,7) +#undef dp0x1_asum_1 +#define dp0x1_asum_1(a_) \ + plq(SS(a_,MM(2,RS4)),ax,1) \ + pan(4,3) \ + pa(7,0) \ + plq(SS(a_,MM(3,RS4)),ax,2) \ + pan(4,1) \ + pa(3,0) \ + pan(4,2) \ + pa(1,0) \ + pa(2,0) +#undef pl0x1_asum_1 +#define pl0x1_asum_1 RS4 + + +#undef p1_4_sum_1 +#define p1_4_sum_1(a_) \ + pls(a_,ax,1) \ + pasr(1,0) +#undef p1_2_sum_1 +#define p1_2_sum_1(a_) \ + px(1) \ + pld(a_,ax,1) \ + pa(1,0) +#undef p1_sum_1 +#define p1_sum_1(a_) \ + plq(a_,ax,1) \ + pa(1,0) +#undef p2_sum_1 +#define p2_sum_1(a_) \ + plq(a_,ax,1) \ + plq(SS(a_,RS4),ax,2) \ + pa(1,0) \ + pa(2,0) +#undef p4_sum_1 +#define p4_sum_1(a_) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,1) \ + pa(7,0) \ + plq(SS(a_,MM(3,RS4)),ax,2) \ + pa(3,0) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),ax) \ + plq(SS(a_,MM(4,RS4)),ax,7) \ + pa(1,0) \ + plq(SS(a_,MM(5,RS4)),ax,3) \ + pa(2,0) +#undef lpsum_1 +#define lpsum_1(a_) \ + plq(a_,ax,7) \ + plq(SS(a_,MM(1,RS4)),ax,3) +#undef dpsum_1 +#define dpsum_1(a_) \ + plq(SS(a_,MM(2,RS4)),ax,1) \ + pa(7,0) \ + plq(SS(a_,MM(3,RS4)),ax,2) \ + pa(3,0) \ + pa(1,0) \ + pa(2,0) +#undef plsum_1 +#define plsum_1 RS4 + + +#undef p1_4_dot_1 +#define p1_4_dot_1(a_) \ + pls(a_,ax,1) \ + pls(a_,cx,2) \ + pmsr(2,1) \ + pasr(1,0) +#undef p1_2_dot_1 +#define p1_2_dot_1(a_) \ + px(1) \ + pld(a_,ax,1) \ + px(2) \ + pld(a_,cx,2) \ + pm(2,1) \ + pa(1,0) +#undef p1_dot_1 +#define p1_dot_1(a_) \ + plq(a_,ax,1) \ + pl(a_,cx,2) \ + pm(2,1) \ + pa(1,0) +#undef p2_dot_1 +#define p2_dot_1(a_) \ + plq(SS(a_,MM(1,RS4)),ax,1) \ + pl(SS(a_,MM(1,RS4)),cx,2) \ + pm(4,3) \ + pa(3,0) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,3) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + pl(SS(a_,MM(2,RS4)),cx,4) \ + pm(2,1) \ + pa(1,0) +#undef lpdot_1 +#define lpdot_1(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(a_,ax,3) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),cx) \ + pl(a_,cx,4) +#undef dpdot_1 +#define dpdot_1(a_) \ + plq(SS(a_,MM(1,RS4)),ax,1) \ + pl(SS(a_,MM(1,RS4)),cx,2) \ + pm(4,3) \ + pa(3,0) \ + pm(2,1) \ + pa(1,0) +#undef pldot_1 +#define pldot_1 8 + +#undef p1_4_dot_1c +#define p1_4_dot_1c(a_) +#undef p1_2_dot_1c +#define p1_2_dot_1c(a_) \ + px(1) \ + pld(a_,ax,1) \ + px(2) \ + pld(a_,cx,2) \ + pc(1,3) \ + ps(HSHUF,1,1) \ + ps(LSHUF,3,3) \ + pm(7,1) \ + pm(2,3) \ + pa(3,0) \ + pm(2,1) \ + pa(1,6) +#undef p1_dot_1c +#define p1_dot_1c(a_) \ + plq(a_,ax,1) \ + pl(a_,cx,2) \ + pc(1,3) \ + ps(HSHUF,1,1) \ + ps(LSHUF,3,3) \ + pm(7,1) \ + pm(2,3) \ + pa(3,0) \ + pm(2,1) \ + pa(1,6) +#undef p2_dot_1c +#define p2_dot_1c(a_) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(1,RS4)),ax,1) \ + pl(SS(a_,MM(1,RS4)),cx,2) \ + pc(3,5) \ + ps(HSHUF,3,3) \ + ps(LSHUF,5,5) \ + pm(7,3) \ + pm(4,5) \ + pa(5,0) \ + pm(4,3) \ + pa(3,6) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + pl(SS(a_,MM(2,RS4)),cx,4) \ + plq(SS(a_,MM(2,RS4)),ax,3) \ + pc(1,5) \ + ps(HSHUF,1,1) \ + ps(LSHUF,5,5) \ + pm(7,1) \ + pm(2,5) \ + pa(5,0) \ + pm(2,1) \ + pa(1,6) +#undef lpdot_1c +#define lpdot_1c(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(a_,ax,3) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),cx) \ + pl(a_,cx,4) +#undef dpdot_1c +#define dpdot_1c(a_) \ + plq(SS(a_,MM(1,RS4)),ax,1) \ + pl(SS(a_,MM(1,RS4)),cx,2) \ + pc(3,5) \ + ps(HSHUF,3,3) \ + ps(LSHUF,5,5) \ + pm(7,3) \ + pm(4,5) \ + pa(5,0) \ + pm(4,3) \ + pa(3,6) \ + pc(1,5) \ + ps(HSHUF,1,1) \ + ps(LSHUF,5,5) \ + pm(7,1) \ + pm(2,5) \ + pa(5,0) \ + pm(2,1) \ + pa(1,6) +#undef pldot_1c +#define pldot_1c 8 + +#undef p1_4_dot_2c +#define p1_4_dot_2c(a_) +#undef p1_2_dot_2c +#define p1_2_dot_2c(a_) \ + px(1) \ + pld(a_,ax,1) \ + px(2) \ + pld(a_,cx,2) \ + pc(1,3) \ + ps(CSHUF,1,1) \ + pm(2,3) \ + pa(3,0) \ + pm(2,1) \ + pa(1,6) +#undef p1_dot_2c +#define p1_dot_2c(a_) \ + plq(a_,ax,1) \ + pl(a_,cx,2) \ + pc(1,3) \ + ps(CSHUF,1,1) \ + pm(2,3) \ + pa(3,0) \ + pm(2,1) \ + pa(1,6) +#undef p2_dot_2c +#define p2_dot_2c(a_) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(1,RS4)),ax,1) \ + pl(SS(a_,MM(1,RS4)),cx,2) \ + pc(3,5) \ + ps(CSHUF,3,3) \ + pm(4,5) \ + pa(5,0) \ + pm(4,3) \ + pa(3,6) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + pl(SS(a_,MM(2,RS4)),cx,4) \ + plq(SS(a_,MM(2,RS4)),ax,3) \ + pc(1,5) \ + ps(CSHUF,1,1) \ + pm(2,5) \ + pa(5,0) \ + pm(2,1) \ + pa(1,6) +#undef lpdot_2c +#define lpdot_2c(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(a_,ax,3) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),cx) \ + pl(a_,cx,4) +#undef dpdot_2c +#define dpdot_2c(a_) \ + plq(SS(a_,MM(1,RS4)),ax,1) \ + pl(SS(a_,MM(1,RS4)),cx,2) \ + pc(3,5) \ + ps(CSHUF,3,3) \ + pm(4,5) \ + pa(5,0) \ + pm(4,3) \ + pa(3,6) \ + pc(1,5) \ + ps(CSHUF,1,1) \ + pm(2,5) \ + pa(5,0) \ + pm(2,1) \ + pa(1,6) +#undef pldot_2c +#define pldot_2c 8 + +#undef p1_4_axpby_3 +#define p1_4_axpby_3(a_) \ + pls(a_,ax,0) \ + pls(a_,cx,3) \ + pmsr(5,0) \ + pmsr(6,3) \ + pasr(3,0) \ + pus(0,a_,ax) +#undef p1_2_axpby_3 +#define p1_2_axpby_3(a_) \ + pld(a_,ax,0) \ + pld(a_,cx,3) \ + pm(5,0) \ + pm(6,3) \ + pa(3,0) \ + pud(0,a_,ax) +#undef p1_axpby_3 +#define p1_axpby_3(a_) \ + plq(a_,ax,0) \ + pl(a_,cx,3) \ + pm(5,0) \ + pm(6,3) \ + pa(3,0) \ + punt(0,a_,ax) +#undef p2_axpby_3 +#define p2_axpby_3(a_) \ + plq(a_,ax,0) \ + pl(a_,cx,3) \ + plq(SS(a_,RS4),ax,1) \ + pm(5,0) \ + pm(6,3) \ + pa(3,0) \ + pl(SS(a_,RS4),cx,3) \ + punt(0,a_,ax) \ + pm(5,1) \ + pm(6,3) \ + pa(3,1) \ + punt(1,SS(a_,RS4),ax) +#undef p4_axpby_3 +#define p4_axpby_3(a_) \ + plq(SS(a_,MM(3,RS4)),ax,3) \ + pm(5,2) \ + pl(SS(a_,MM(3,RS4)),cx,7) \ + pm(6,4) \ + pa(4,2) \ + punt(0,a_,ax) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + pl(SS(a_,MM(4,RS4)),cx,4) \ + pm(5,3) \ + plq(SS(a_,MM(4,RS4)),ax,0) \ + pm(6,7) \ + pa(7,3) \ + punt(1,SS(a_,RS4),ax) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(5,RS4)),ax,1) \ + pm(5,0) \ + pl(SS(a_,MM(5,RS4)),cx,7) \ + pm(6,4) \ + pa(4,0) \ + punt(2,SS(a_,MM(2,RS4)),ax) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),cx) \ + pl(SS(a_,MM(6,RS4)),cx,4) \ + pm(5,1) \ + plq(SS(a_,MM(6,RS4)),ax,2) \ + pm(6,7) \ + pa(7,1) \ + punt(3,SS(a_,MM(3,RS4)),ax) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),ax) +#undef lpaxpby_3 +#define lpaxpby_3(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),cx) \ + pl(SS(a_,MM(0,RS4)),cx,4) \ + plq(SS(a_,MM(0,RS4)),ax,0) \ + pl(SS(a_,MM(1,RS4)),cx,7) \ + pm(5,0) \ + plq(SS(a_,MM(1,RS4)),ax,1) \ + pm(6,4) \ + pa(4,0) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,2) \ + pm(5,1) \ + pl(SS(a_,MM(2,RS4)),cx,4) \ + pm(6,7) \ + pa(7,1) +#undef dpaxpby_3 +#define dpaxpby_3(a_) \ + pl(SS(a_,MM(3,RS4)),cx,7) \ + pm(5,2) \ + plq(SS(a_,MM(3,RS4)),ax,3) \ + pm(6,4) \ + pa(4,2) \ + pm(5,3) \ + punt(0,a_,ax) \ + pm(6,7) \ + pa(7,3) \ + punt(1,SS(a_,RS4),ax) \ + punt(2,SS(a_,MM(2,RS4)),ax) \ + punt(3,SS(a_,MM(3,RS4)),ax) +#undef plaxpby_3 +#define plaxpby_3 16 + +#undef p1_4_axpby_3c +#define p1_4_axpby_3c(a_) +#undef p1_2_axpby_3c +#define p1_2_axpby_3c(a_) \ + pld(a_,ax,0) \ + pld(a_,cx,2) \ + pc(0,3) \ + pm(5,0) \ + ps(CSHUF,3,3) \ + pm(4,3) \ + pa(3,0) \ + pc(2,3) \ + pm(6,2) \ + pa(2,0) \ + ps(CSHUF,3,3) \ + pm(7,3) \ + pa(3,0) \ + pud(0,a_,ax) +#undef p1_axpby_3c +#define p1_axpby_3c(a_) \ + plq(a_,ax,0) \ + pl(a_,cx,2) \ + pc(0,3) \ + pm(5,0) \ + ps(CSHUF,3,3) \ + pm(4,3) \ + pa(3,0) \ + pc(2,3) \ + pm(6,2) \ + pa(2,0) \ + ps(CSHUF,3,3) \ + pm(7,3) \ + pa(3,0) \ + puq(0,a_,ax) +#undef p2_axpby_3c +#define p2_axpby_3c(a_) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(1,RS4)),ax,1) \ + pl(SS(a_,MM(1,RS4)),cx,3) \ + pc(1,2) \ + pm(5,1) \ + ps(CSHUF,2,2) \ + pm(4,2) \ + pa(2,1) \ + pc(3,2) \ + pm(6,3) \ + pa(3,1) \ + ps(CSHUF,2,2) \ + pm(7,2) \ + pa(2,1) \ + puq(0,a_,ax) \ + plq(SS(a_,MM(2,RS4)),ax,0) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + pl(SS(a_,MM(2,RS4)),cx,2) \ + pc(0,3) \ + pm(5,0) \ + ps(CSHUF,3,3) \ + pm(4,3) \ + pa(3,0) \ + pc(2,3) \ + pm(6,2) \ + pa(2,0) \ + ps(CSHUF,3,3) \ + pm(7,3) \ + pa(3,0) \ + puq(1,SS(a_,RS4),ax) +#undef lpaxpby_3c +#define lpaxpby_3c(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(SS(a_,MM(0,RS4)),ax,0) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),cx) \ + pl(SS(a_,MM(0,RS4)),cx,2) \ + pc(0,3) \ + pm(5,0) \ + ps(CSHUF,3,3) \ + pm(4,3) \ + pa(3,0) \ + pc(2,3) \ + pm(6,2) \ + pa(2,0) \ + ps(CSHUF,3,3) \ + pm(7,3) \ + pa(3,0) +#undef dpaxpby_3c +#define dpaxpby_3c(a_) \ + plq(SS(a_,MM(1,RS4)),ax,1) \ + pl(SS(a_,MM(1,RS4)),cx,3) \ + pc(1,2) \ + pm(5,1) \ + ps(CSHUF,2,2) \ + pm(4,2) \ + pa(2,1) \ + pc(3,2) \ + pm(6,3) \ + pa(3,1) \ + ps(CSHUF,2,2) \ + pm(7,2) \ + pa(2,1) \ + puq(0,a_,ax) \ + puq(1,SS(a_,RS4),ax) +#undef plaxpby_3c +#define plaxpby_3c 8 + +#undef p1_4_axpby_2 +#define p1_4_axpby_2(a_) \ + pls(a_,cx,5) \ + pls(a_,ax,0) \ + pmsr(6,5) \ + pasr(5,0) \ + pus(0,a_,ax) +#undef p1_2_axpby_2 +#define p1_2_axpby_2(a_) \ + pld(a_,cx,5) \ + pld(a_,ax,0) \ + pm(6,5) \ + pa(5,0) \ + pud(0,a_,ax) +#undef p1_axpby_2 +#define p1_axpby_2(a_) \ + pl(a_,cx,5) \ + plq(a_,ax,0) \ + pm(6,5) \ + pa(5,0) \ + puq(0,a_,ax) +#undef p2_axpby_2 +#define p2_axpby_2(a_) \ + pl(a_,cx,5) \ + plq(a_,ax,0) \ + pl(SS(a_,RS4),cx,4) \ + pm(6,5) \ + pa(5,0) \ + plq(SS(a_,RS4),ax,1) \ + puq(0,a_,ax) \ + pm(6,4) \ + pa(4,1) \ + puq(1,SS(a_,RS4),ax) +#undef p4_axpby_2 +#define p4_axpby_2(a_) \ + plq(SS(a_,MM(3,RS4)),ax,3) \ + pl(SS(a_,MM(3,RS4)),cx,5) \ + pm(6,4) \ + pa(4,2) \ + puq(0,a_,ax) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + pl(SS(a_,MM(4,RS4)),cx,4) \ + plq(SS(a_,MM(4,RS4)),ax,0) \ + pm(6,5) \ + pa(5,3) \ + puq(1,SS(a_,RS4),ax) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(5,RS4)),ax,1) \ + pl(SS(a_,MM(5,RS4)),cx,5) \ + pm(6,4) \ + pa(4,0) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),cx) \ + pl(SS(a_,MM(6,RS4)),cx,4) \ + plq(SS(a_,MM(6,RS4)),ax,2) \ + pm(6,5) \ + pa(5,1) \ + puq(3,SS(a_,MM(3,RS4)),ax) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),ax) +#undef lpaxpby_2 +#define lpaxpby_2(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),cx) \ + pl(SS(a_,MM(0,RS4)),cx,4) \ + plq(SS(a_,MM(0,RS4)),ax,0) \ + pl(SS(a_,MM(1,RS4)),cx,5) \ + plq(SS(a_,MM(1,RS4)),ax,1) \ + pm(6,4) \ + pa(4,0) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,2) \ + pl(SS(a_,MM(2,RS4)),cx,4) \ + pm(6,5) \ + pa(5,1) +#undef dpaxpby_2 +#define dpaxpby_2(a_) \ + pl(SS(a_,MM(3,RS4)),cx,5) \ + plq(SS(a_,MM(3,RS4)),ax,3) \ + pm(6,4) \ + pa(4,2) \ + puq(0,a_,ax) \ + pm(6,5) \ + pa(5,3) \ + puq(1,SS(a_,RS4),ax) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + puq(3,SS(a_,MM(3,RS4)),ax) +#undef plaxpby_2 +#define plaxpby_2 16 + +#undef p1_4_axpby_2c +#define p1_4_axpby_2c(a_) +#undef p1_2_axpby_2c +#define p1_2_axpby_2c(a_) \ + pld(a_,cx,5) \ + pld(a_,ax,0) \ + pc(5,1) \ + pm(6,5) \ + pa(5,0) \ + ps(CSHUF,1,1) \ + pm(7,1) \ + pa(1,0) \ + pud(0,a_,ax) +#undef p1_axpby_2c +#define p1_axpby_2c(a_) \ + pl(a_,cx,5) \ + plq(a_,ax,0) \ + pc(5,1) \ + pm(6,5) \ + pa(5,0) \ + ps(CSHUF,1,1) \ + pm(7,1) \ + pa(1,0) \ + puq(0,a_,ax) +#undef p2_axpby_2c +#define p2_axpby_2c(a_) \ + pl(a_,cx,5) \ + plq(a_,ax,0) \ + pl(SS(a_,RS4),cx,4) \ + pc(5,1) \ + pm(6,5) \ + pa(5,0) \ + ps(CSHUF,2,2) \ + pm(7,2) \ + pa(2,0) \ + plq(SS(a_,RS4),ax,1) \ + puq(0,a_,ax) \ + pc(4,3) \ + pm(6,4) \ + pa(4,1) \ + ps(CSHUF,3,3) \ + pm(7,3) \ + pa(3,1) \ + puq(1,SS(a_,RS4),ax) +#undef p4_axpby_2c +#define p4_axpby_2c(a_) \ + plq(SS(a_,MM(3,RS4)),ax,3) \ + puq(0,a_,ax) \ + pc(4,0) \ + pm(6,4) \ + pa(4,2) \ + ps(CSHUF,0,0) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + pl(SS(a_,MM(4,RS4)),cx,4) \ + pm(7,0) \ + pa(0,2) \ + plq(SS(a_,MM(4,RS4)),ax,0) \ + puq(1,SS(a_,RS4),ax) \ + pc(5,1) \ + pm(6,5) \ + pa(5,3) \ + ps(CSHUF,1,1) \ + pl(SS(a_,MM(5,RS4)),cx,5) \ + pm(7,1) \ + pa(1,3) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(5,RS4)),ax,1) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + pc(4,2) \ + pm(6,4) \ + pa(4,0) \ + ps(CSHUF,2,2) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),cx) \ + pl(SS(a_,MM(6,RS4)),cx,4) \ + pm(7,2) \ + pa(2,0) \ + plq(SS(a_,MM(6,RS4)),ax,2) \ + puq(3,SS(a_,MM(3,RS4)),ax) \ + pc(5,3) \ + pm(6,5) \ + pa(5,1) \ + ps(CSHUF,3,3) \ + pl(SS(a_,MM(7,RS4)),cx,5) \ + pm(7,3) \ + pa(3,1) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),ax) +#undef lpaxpby_2c +#define lpaxpby_2c(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),cx) \ + pl(SS(a_,MM(0,RS4)),cx,4) \ + plq(SS(a_,MM(0,RS4)),ax,0) \ + pl(SS(a_,MM(1,RS4)),cx,5) \ + plq(SS(a_,MM(1,RS4)),ax,1) \ + pc(4,2) \ + pm(6,4) \ + pa(4,0) \ + ps(CSHUF,2,2) \ + pl(SS(a_,MM(2,RS4)),cx,4) \ + pm(7,2) \ + pa(2,0) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,2) \ + pc(5,3) \ + pm(6,5) \ + pa(5,1) \ + ps(CSHUF,3,3) \ + pl(SS(a_,MM(3,RS4)),cx,5) \ + pm(7,3) \ + pa(3,1) +#undef dpaxpby_2c +#define dpaxpby_2c(a_) \ + plq(SS(a_,MM(3,RS4)),ax,3) \ + puq(0,a_,ax) \ + pc(4,0) \ + pm(6,4) \ + pa(4,2) \ + ps(CSHUF,0,0) \ + puq(1,SS(a_,RS4),ax) \ + pm(7,0) \ + pa(0,2) \ + pc(5,1) \ + pm(6,5) \ + pa(5,3) \ + ps(CSHUF,1,1) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + pm(7,1) \ + pa(1,3) \ + puq(3,SS(a_,MM(3,RS4)),ax) +#undef plaxpby_2c +#define plaxpby_2c 16 + +#undef p1_4_axpby_1 +#define p1_4_axpby_1(a_) \ + pls(a_,ax,1) \ + pls(a_,cx,2) \ + pmsr(5,1) \ + pmsr(6,2) \ + pasr(2,1) \ + pus(1,a_,ax) +#undef p1_2_axpby_1 +#define p1_2_axpby_1(a_) \ + pld(a_,ax,1) \ + pld(a_,cx,2) \ + pm(5,1) \ + pm(6,2) \ + pa(2,1) \ + pud(1,a_,ax) +#undef p1_axpby_1 +#define p1_axpby_1(a_) \ + plq(a_,ax,1) \ + pl(a_,cx,2) \ + pm(5,1) \ + pm(6,2) \ + pa(2,1) \ + puq(1,a_,ax) +#undef p2_axpby_1 +#define p2_axpby_1(a_) \ + plq(SS(a_,RS4),ax,3) \ + pl(SS(a_,RS4),cx,4) \ + pm(5,1) \ + pm(6,2) \ + pa(2,1) \ + puq(1,a_,ax) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,1) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + pl(SS(a_,MM(2,RS4)),cx,2) \ + pm(5,3) \ + pm(6,4) \ + pa(4,3) \ + puq(3,SS(a_,RS4),ax) +#undef lpaxpby_1 +#define lpaxpby_1(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(SS(a_,MM(0,RS4)),ax,1) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),cx) \ + pl(SS(a_,MM(0,RS4)),cx,2) +#undef dpaxpby_1 +#define dpaxpby_1(a_) \ + plq(SS(a_,RS4),ax,3) \ + pl(SS(a_,RS4),cx,4) \ + pm(5,1) \ + pm(6,2) \ + pa(2,1) \ + puq(1,a_,ax) \ + pm(5,3) \ + pm(6,4) \ + pa(4,3) \ + puq(3,SS(a_,RS4),ax) +#undef plaxpby_1 +#define plaxpby_1 8 + +#undef p1_4_axpy_0 +#define p1_4_axpy_0(a_) \ + pls(a_,cx,2) \ + pls(a_,ax,1) \ + pmsr(6,2) \ + pasr(2,1) \ + pus(1,a_,ax) +#undef p1_2_axpy_0 +#define p1_2_axpy_0(a_) \ + pld(a_,cx,2) \ + pld(a_,ax,1) \ + pm(6,2) \ + pa(2,1) \ + pud(1,a_,ax) +#undef p1_axpy_0 +#define p1_axpy_0(a_) \ + pl(a_,cx,2) \ + plq(a_,ax,1) \ + pm(6,2) \ + pa(2,1) \ + puq(1,a_,ax) +#undef p2_axpy_0 +#define p2_axpy_0(a_) \ + pl(SS(a_,RS4),cx,4) \ + pm(6,2) \ + pa(2,1) \ + plq(SS(a_,RS4),ax,3) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + pl(SS(a_,MM(2,RS4)),cx,2) \ + puq(1,a_,ax) \ + pm(6,4) \ + pa(4,3) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,1) \ + puq(3,SS(a_,RS4),ax) +#undef lpaxpy_0 +#define lpaxpy_0(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),cx) \ + pl(SS(a_,MM(0,RS4)),cx,2) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(SS(a_,MM(0,RS4)),ax,1) +#undef dpaxpy_0 +#define dpaxpy_0(a_) \ + pl(SS(a_,RS4),cx,4) \ + pm(6,2) \ + pa(2,1) \ + plq(SS(a_,RS4),ax,3) \ + puq(1,a_,ax) \ + pm(6,4) \ + pa(4,3) \ + puq(3,SS(a_,RS4),ax) +#undef plaxpy_0 +#define plaxpy_0 8 + +#undef p1_4_axpy_1 +#define p1_4_axpy_1(a_) \ + pls(a_,cx,2) \ + pls(a_,ax,1) \ + pmsr(6,2) \ + pasr(2,1) \ + pus(1,a_,ax) +#undef p1_2_axpy_1 +#define p1_2_axpy_1(a_) \ + pld(a_,cx,2) \ + pld(a_,ax,1) \ + pm(6,2) \ + pa(2,1) \ + pud(1,a_,ax) +#undef p1_axpy_1 +#define p1_axpy_1(a_) \ + pl(a_,cx,2) \ + pm(6,2) \ + pam(a_,ax,2) \ + puq(2,a_,ax) +#undef p2_axpy_1 +#define p2_axpy_1(a_) \ + pl(a_,cx,2) \ + pm(6,2) \ + pl(SS(a_,RS4),cx,4) \ + pam(a_,ax,2) \ + pm(6,4) \ + puq(2,a_,ax) \ + pam(SS(a_,RS4),ax,4) \ + puq(4,SS(a_,RS4),ax) +#undef p4_axpy_1 +#define p4_axpy_1(a_) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + pl(SS(a_,MM(3,RS4)),cx,3) \ + pm(6,2) \ + pam(SS(a_,MM(2,RS4)),ax,2) \ + puq(0,a_,ax) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + pl(SS(a_,MM(4,RS4)),cx,0) \ + pm(6,3) \ + pam(SS(a_,MM(3,RS4)),ax,3) \ + puq(1,SS(a_,RS4),ax) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),cx) \ + pl(SS(a_,MM(5,RS4)),cx,1) \ + pm(6,0) \ + pam(SS(a_,MM(4,RS4)),ax,0) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),ax) \ + pl(SS(a_,MM(6,RS4)),cx,2) \ + pm(6,1) \ + pam(SS(a_,MM(5,RS4)),ax,1) \ + puq(3,SS(a_,MM(3,RS4)),ax) +#undef lpaxpy_1 +#define lpaxpy_1(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),cx) \ + pl(a_,cx,0) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + pl(SS(a_,RS4),cx,1) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + pm(6,0) \ + pam(a_,ax,0) \ + pl(SS(a_,MM(2,RS4)),cx,2) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + pm(6,1) \ + pam(SS(a_,RS4),ax,1) +#undef dpaxpy_1 +#define dpaxpy_1(a_) \ + pl(SS(a_,MM(3,RS4)),cx,3) \ + pm(6,2) \ + pam(SS(a_,MM(2,RS4)),ax,2) \ + puq(0,a_,ax) \ + pm(6,3) \ + pam(SS(a_,MM(3,RS4)),ax,3) \ + puq(1,SS(a_,RS4),ax) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + puq(3,SS(a_,MM(3,RS4)),ax) +#undef plaxpy_1 +#define plaxpy_1 16 + +#undef p1_4_axpy_2 +#define p1_4_axpy_2(a_) \ + pls(a_,cx,5) \ + pls(a_,ax,0) \ + pmsr(6,5) \ + pasr(5,0) \ + pus(0,a_,ax) +#undef p1_2_axpy_2 +#define p1_2_axpy_2(a_) \ + pld(a_,cx,5) \ + pld(a_,ax,0) \ + pm(6,5) \ + pa(5,0) \ + pud(0,a_,ax) +#undef p1_axpy_2 +#define p1_axpy_2(a_) \ + pl(a_,cx,5) \ + plq(a_,ax,0) \ + pm(6,5) \ + pa(5,0) \ + puq(0,a_,ax) +#undef p2_axpy_2 +#define p2_axpy_2(a_) \ + pl(a_,cx,5) \ + plq(a_,ax,0) \ + pl(SS(a_,RS4),cx,4) \ + pm(6,5) \ + pa(5,0) \ + plq(SS(a_,RS4),ax,1) \ + puq(0,a_,ax) \ + pm(6,4) \ + pa(4,1) \ + puq(1,SS(a_,RS4),ax) +#undef p4_axpy_2 +#define p4_axpy_2(a_) \ + plq(SS(a_,MM(3,RS4)),ax,3) \ + pl(SS(a_,MM(3,RS4)),cx,5) \ + pm(6,4) \ + pa(4,2) \ + puq(0,a_,ax) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + pl(SS(a_,MM(4,RS4)),cx,4) \ + plq(SS(a_,MM(4,RS4)),ax,0) \ + pm(6,5) \ + pa(5,3) \ + puq(1,SS(a_,RS4),ax) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(5,RS4)),ax,1) \ + pl(SS(a_,MM(5,RS4)),cx,5) \ + pm(6,4) \ + pa(4,0) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),cx) \ + pl(SS(a_,MM(6,RS4)),cx,4) \ + plq(SS(a_,MM(6,RS4)),ax,2) \ + pm(6,5) \ + pa(5,1) \ + puq(3,SS(a_,MM(3,RS4)),ax) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),ax) +#undef lpaxpy_2 +#define lpaxpy_2(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),cx) \ + pl(SS(a_,MM(0,RS4)),cx,4) \ + plq(SS(a_,MM(0,RS4)),ax,0) \ + pl(SS(a_,MM(1,RS4)),cx,5) \ + plq(SS(a_,MM(1,RS4)),ax,1) \ + pm(6,4) \ + pa(4,0) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,2) \ + pl(SS(a_,MM(2,RS4)),cx,4) \ + pm(6,5) \ + pa(5,1) +#undef dpaxpy_2 +#define dpaxpy_2(a_) \ + pl(SS(a_,MM(3,RS4)),cx,5) \ + plq(SS(a_,MM(3,RS4)),ax,3) \ + pm(6,4) \ + pa(4,2) \ + puq(0,a_,ax) \ + pm(6,5) \ + pa(5,3) \ + puq(1,SS(a_,RS4),ax) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + puq(3,SS(a_,MM(3,RS4)),ax) +#undef plaxpy_2 +#define plaxpy_2 16 + +#undef p1_4_axpy_2c +#define p1_4_axpy_2c(a_) +#undef p1_2_axpy_2c +#define p1_2_axpy_2c(a_) \ + pld(a_,cx,4) \ + pld(a_,ax,0) \ + pc(4,2) \ + pm(6,4) \ + pa(4,0) \ + ps(CSHUF,2,2) \ + pm(7,2) \ + pa(2,0) \ + pud(0,a_,ax) +#undef p1_axpy_2c +#define p1_axpy_2c(a_) \ + pl(a_,cx,4) \ + plq(a_,ax,0) \ + pc(4,2) \ + pm(6,4) \ + pa(4,0) \ + ps(CSHUF,2,2) \ + pm(7,2) \ + pa(2,0) \ + puq(0,a_,ax) +#undef p2_axpy_2c +#define p2_axpy_2c(a_) \ + pl(a_,cx,4) \ + plq(a_,ax,0) \ + pl(SS(a_,RS4),cx,5) \ + pc(4,2) \ + pm(6,4) \ + pa(4,0) \ + ps(CSHUF,2,2) \ + pm(7,2) \ + pa(2,0) \ + plq(SS(a_,RS4),ax,1) \ + puq(0,a_,ax) \ + pc(5,3) \ + pm(6,5) \ + pa(5,1) \ + ps(CSHUF,3,3) \ + pm(7,3) \ + pa(3,1) \ + puq(1,SS(a_,RS4),ax) +#undef p4_axpy_2c +#define p4_axpy_2c(a_) \ + plq(SS(a_,MM(3,RS4)),ax,3) \ + puq(0,a_,ax) \ + pc(4,0) \ + pm(6,4) \ + pa(4,2) \ + ps(CSHUF,0,0) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + pl(SS(a_,MM(4,RS4)),cx,4) \ + pm(7,0) \ + pa(0,2) \ + plq(SS(a_,MM(4,RS4)),ax,0) \ + puq(1,SS(a_,RS4),ax) \ + pc(5,1) \ + pm(6,5) \ + pa(5,3) \ + ps(CSHUF,1,1) \ + pl(SS(a_,MM(5,RS4)),cx,5) \ + pm(7,1) \ + pa(1,3) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(5,RS4)),ax,1) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + pc(4,2) \ + pm(6,4) \ + pa(4,0) \ + ps(CSHUF,2,2) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),cx) \ + pl(SS(a_,MM(6,RS4)),cx,4) \ + pm(7,2) \ + pa(2,0) \ + plq(SS(a_,MM(6,RS4)),ax,2) \ + puq(3,SS(a_,MM(3,RS4)),ax) \ + pc(5,3) \ + pm(6,5) \ + pa(5,1) \ + ps(CSHUF,3,3) \ + pl(SS(a_,MM(7,RS4)),cx,5) \ + pm(7,3) \ + pa(3,1) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),ax) +#undef lpaxpy_2c +#define lpaxpy_2c(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),cx) \ + pl(SS(a_,MM(0,RS4)),cx,4) \ + plq(SS(a_,MM(0,RS4)),ax,0) \ + pl(SS(a_,MM(1,RS4)),cx,5) \ + plq(SS(a_,MM(1,RS4)),ax,1) \ + pc(4,2) \ + pm(6,4) \ + pa(4,0) \ + ps(CSHUF,2,2) \ + pl(SS(a_,MM(2,RS4)),cx,4) \ + pm(7,2) \ + pa(2,0) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,2) \ + pc(5,3) \ + pm(6,5) \ + pa(5,1) \ + ps(CSHUF,3,3) \ + pl(SS(a_,MM(3,RS4)),cx,5) \ + pm(7,3) \ + pa(3,1) +#undef dpaxpy_2c +#define dpaxpy_2c(a_) \ + plq(SS(a_,MM(3,RS4)),ax,3) \ + puq(0,a_,ax) \ + pc(4,0) \ + pm(6,4) \ + pa(4,2) \ + ps(CSHUF,0,0) \ + puq(1,SS(a_,RS4),ax) \ + pm(7,0) \ + pa(0,2) \ + pc(5,1) \ + pm(6,5) \ + pa(5,3) \ + ps(CSHUF,1,1) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + pm(7,1) \ + pa(1,3) \ + puq(3,SS(a_,MM(3,RS4)),ax) +#undef plaxpy_2c +#define plaxpy_2c 16 + +#undef p1_4_axpy_1c +#define p1_4_axpy_1c(a_) +#undef p1_2_axpy_1c +#define p1_2_axpy_1c(a_) \ + pld(a_,cx,2) \ + pc(2,0) \ + pld(a_,ax,1) \ + ps(CSHUF,0,0) \ + pm(6,2) \ + pa(2,1) \ + pm(7,0) \ + pa(0,1) \ + pud(1,a_,ax) +#undef p1_axpy_1c +#define p1_axpy_1c(a_) \ + pl(a_,cx,2) \ + pc(2,0) \ + plq(a_,ax,1) \ + ps(CSHUF,0,0) \ + pm(6,2) \ + pa(2,1) \ + pm(7,0) \ + pa(0,1) \ + puq(1,a_,ax) +#undef p2_axpy_1c +#define p2_axpy_1c(a_) \ + plq(SS(a_,RS4),ax,3) \ + ps(CSHUF,0,0) \ + pl(SS(a_,RS4),cx,4) \ + pm(6,2) \ + pa(2,1) \ + pm(7,0) \ + pa(0,1) \ + pc(4,0) \ + puq(1,a_,ax) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,1) \ + ps(CSHUF,0,0) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + pl(SS(a_,MM(2,RS4)),cx,2) \ + pm(6,4) \ + pa(4,3) \ + pm(7,0) \ + pa(0,3) \ + pc(2,0) \ + puq(3,SS(a_,RS4),ax) +#undef lpaxpy_1c +#define lpaxpy_1c(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),cx) \ + pl(SS(a_,MM(0,RS4)),cx,2) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(SS(a_,MM(0,RS4)),ax,1) \ + pc(2,0) +#undef dpaxpy_1c +#define dpaxpy_1c(a_) \ + plq(SS(a_,RS4),ax,3) \ + ps(CSHUF,0,0) \ + pl(SS(a_,RS4),cx,4) \ + pm(6,2) \ + pa(2,1) \ + pm(7,0) \ + pa(0,1) \ + pc(4,0) \ + puq(1,a_,ax) \ + ps(CSHUF,0,0) \ + pm(6,4) \ + pa(4,3) \ + pm(7,0) \ + pa(0,3) \ + puq(3,SS(a_,RS4),ax) +#undef plaxpy_1c +#define plaxpy_1c 8 + +#undef p1_4_copy_1 +#define p1_4_copy_1(a_) \ + pls(a_,cx,2) \ + pus(2,a_,ax) +#undef p1_2_copy_1 +#define p1_2_copy_1(a_) \ + pld(a_,cx,2) \ + pud(2,a_,ax) +#undef p1_copy_1 +#define p1_copy_1(a_) \ + pl(a_,cx,2) \ + puq(2,a_,ax) +#undef p2_copy_1 +#define p2_copy_1(a_) \ + pl(SS(a_,RS4),cx,4) \ + puq(2,a_,ax) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + pl(SS(a_,MM(2,RS4)),cx,2) \ + puq(4,SS(a_,RS4),ax) +#undef lpcopy_1 +#define lpcopy_1(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),cx) \ + pl(SS(a_,MM(0,RS4)),cx,2) +#undef dpcopy_1 +#define dpcopy_1(a_) \ + pl(SS(a_,RS4),cx,4) \ + puq(2,a_,ax) \ + puq(4,SS(a_,RS4),ax) +#undef plcopy_1 +#define plcopy_1 8 + +#undef p1_4_copy_2 +#define p1_4_copy_2(a_) \ + pls(a_,ax,2) \ + pus(2,a_,cx) +#undef p1_2_copy_2 +#define p1_2_copy_2(a_) \ + pld(a_,ax,2) \ + pud(2,a_,cx) +#undef p1_copy_2 +#define p1_copy_2(a_) \ + plq(a_,ax,2) \ + pu(2,a_,cx) +#undef p2_copy_2 +#define p2_copy_2(a_) \ + plq(SS(a_,RS4),ax,4) \ + pu(2,a_,cx) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,2) \ + pu(4,SS(a_,RS4),cx) +#undef lpcopy_2 +#define lpcopy_2(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),cx) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(SS(a_,MM(0,RS4)),ax,2) +#undef dpcopy_2 +#define dpcopy_2(a_) \ + plq(SS(a_,RS4),ax,4) \ + pu(2,a_,cx) \ + pu(4,SS(a_,RS4),cx) +#undef plcopy_2 +#define plcopy_2 8 + +#undef p1_4_copy_3 +#define p1_4_copy_3(a_) \ + pls(a_,cx,2) \ + pus(2,a_,ax) +#undef p1_2_copy_3 +#define p1_2_copy_3(a_) \ + pld(a_,cx,2) \ + pud(2,a_,ax) +#undef p1_copy_3 +#define p1_copy_3(a_) \ + pl(a_,cx,2) \ + punt(2,a_,ax) +#undef p2_copy_3 +#define p2_copy_3(a_) \ + pl(SS(a_,MM(0,RS4)),cx,0) \ + pl(SS(a_,MM(1,RS4)),cx,1) \ + punt(0,SS(a_,MM(0,RS4)),ax) \ + punt(1,SS(a_,MM(1,RS4)),ax) +#undef p4_copy_3 +#define p4_copy_3(a_) \ + pl(SS(a_,MM(0,RS4)),cx,0) \ + pl(SS(a_,MM(1,RS4)),cx,1) \ + pl(SS(a_,MM(2,RS4)),cx,2) \ + pl(SS(a_,MM(3,RS4)),cx,3) \ + punt(0,SS(a_,MM(0,RS4)),ax) \ + punt(1,SS(a_,MM(1,RS4)),ax) \ + punt(2,SS(a_,MM(2,RS4)),ax) \ + punt(3,SS(a_,MM(3,RS4)),ax) +#undef p8_copy_3 +#define p8_copy_3(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),cx) \ + pl(SS(a_,MM(0,RS4)),cx,0) \ + pl(SS(a_,MM(1,RS4)),cx,1) \ + pl(SS(a_,MM(2,RS4)),cx,2) \ + pl(SS(a_,MM(3,RS4)),cx,3) \ + pl(SS(a_,MM(4,RS4)),cx,4) \ + pl(SS(a_,MM(5,RS4)),cx,5) \ + pl(SS(a_,MM(6,RS4)),cx,6) \ + pl(SS(a_,MM(7,RS4)),cx,7) \ + punt(0,SS(a_,MM(0,RS4)),ax) \ + punt(1,SS(a_,MM(1,RS4)),ax) \ + punt(2,SS(a_,MM(2,RS4)),ax) \ + punt(3,SS(a_,MM(3,RS4)),ax) \ + punt(4,SS(a_,MM(4,RS4)),ax) \ + punt(5,SS(a_,MM(5,RS4)),ax) \ + punt(6,SS(a_,MM(6,RS4)),ax) \ + punt(7,SS(a_,MM(7,RS4)),ax) +#undef lpcopy_3 +#define lpcopy_3(a_) +#undef dpcopy_3 +#define dpcopy_3(a_) p8_copy_3(a_) +#undef plcopy_3 +#define plcopy_3 32 + +#undef p1_4_cpsc_3 +#define p1_4_cpsc_3(a_) \ + pls(a_,ax,0) \ + pmsr(6,0) \ + pus(0,a_,cx) +#undef p1_2_cpsc_3 +#define p1_2_cpsc_3(a_) \ + pld(a_,ax,0) \ + pm(6,0) \ + pud(0,a_,cx) +#undef p1_cpsc_3 +#define p1_cpsc_3(a_) \ + plq(a_,ax,0) \ + pm(6,0) \ + pu(0,a_,cx) +#undef p2_cpsc_3 +#define p2_cpsc_3(a_) \ + plq(a_,ax,0) \ + plq(SS(a_,RS4),ax,1) \ + pm(6,0) \ + pm(6,1) \ + pu(0,a_,cx) \ + pu(1,SS(a_,RS4),cx) +#undef p4_cpsc_3 +#define p4_cpsc_3(a_) \ + plq(SS(a_,MM(3,RS4)),ax,3) \ + pm(6,2) \ + pu(0,a_,cx) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(4,RS4)),ax,0) \ + pm(6,3) \ + pu(1,SS(a_,RS4),cx) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + plq(SS(a_,MM(5,RS4)),ax,1) \ + pm(6,0) \ + pu(2,SS(a_,MM(2,RS4)),cx) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),ax) \ + plq(SS(a_,MM(6,RS4)),ax,2) \ + pm(6,1) \ + pu(3,SS(a_,MM(3,RS4)),cx) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),cx) +#undef lpcpsc_3 +#define lpcpsc_3(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(SS(a_,MM(0,RS4)),ax,0) \ + plq(SS(a_,MM(1,RS4)),ax,1) \ + pm(6,0) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),cx) \ + plq(SS(a_,MM(2,RS4)),ax,2) \ + pm(6,1) +#undef dpcpsc_3 +#define dpcpsc_3(a_) \ + plq(SS(a_,MM(3,RS4)),ax,3) \ + pm(6,2) \ + pu(0,a_,cx) \ + pm(6,3) \ + pu(1,SS(a_,RS4),cx) \ + pu(2,SS(a_,MM(2,RS4)),cx) \ + pu(3,SS(a_,MM(3,RS4)),cx) +#undef plcpsc_3 +#define plcpsc_3 16 + +#undef p1_4_cpsc_3c +#define p1_4_cpsc_3c(a_) +#undef p1_2_cpsc_3c +#define p1_2_cpsc_3c(a_) \ + pld(a_,ax,0) \ + pc(0,1) \ + pm(6,0) \ + ps(CSHUF,1,1) \ + pm(7,1) \ + pa(1,0) \ + pud(0,a_,cx) +#undef p1_cpsc_3c +#define p1_cpsc_3c(a_) \ + plq(a_,ax,0) \ + pc(0,1) \ + pm(6,0) \ + ps(CSHUF,1,1) \ + pm(7,1) \ + pa(1,0) \ + pu(0,a_,cx) +#undef p2_cpsc_3c +#define p2_cpsc_3c(a_) \ + plq(a_,ax,0) \ + plq(SS(a_,RS4),ax,1) \ + pc(0,2) \ + pm(6,0) \ + ps(CSHUF,2,2) \ + pm(7,2) \ + pa(2,0) \ + pu(0,a_,cx) \ + pc(1,3) \ + pm(6,1) \ + ps(CSHUF,3,3) \ + pm(7,3) \ + pa(3,1) \ + pu(1,SS(a_,RS4),cx) +#undef p4_cpsc_3c +#define p4_cpsc_3c(a_) \ + pu(0,a_,cx) \ + pc(2,4) \ + pm(6,2) \ + ps(CSHUF,4,4) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(4,RS4)),ax,0) \ + pm(7,4) \ + pa(4,2) \ + pu(1,SS(a_,RS4),cx) \ + pc(3,4) \ + pm(6,3) \ + ps(CSHUF,4,4) \ + plq(SS(a_,MM(5,RS4)),ax,1) \ + pm(7,4) \ + pa(4,3) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + pu(2,SS(a_,MM(2,RS4)),cx) \ + pc(0,4) \ + pm(6,0) \ + ps(CSHUF,4,4) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),ax) \ + plq(SS(a_,MM(6,RS4)),ax,2) \ + pm(7,4) \ + pa(4,0) \ + pu(3,SS(a_,MM(3,RS4)),cx) \ + pc(1,4) \ + pm(6,1) \ + ps(CSHUF,4,4) \ + plq(SS(a_,MM(7,RS4)),ax,3) \ + pm(7,4) \ + pa(4,1) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),cx) +#undef lpcpsc_3c +#define lpcpsc_3c(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(SS(a_,MM(0,RS4)),ax,0) \ + plq(SS(a_,MM(1,RS4)),ax,1) \ + pc(0,4) \ + pm(6,0) \ + ps(CSHUF,4,4) \ + plq(SS(a_,MM(2,RS4)),ax,2) \ + pm(7,4) \ + pa(4,0) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),cx) \ + pc(1,4) \ + pm(6,1) \ + ps(CSHUF,4,4) \ + plq(SS(a_,MM(3,RS4)),ax,3) \ + pm(7,4) \ + pa(4,1) +#undef dpcpsc_3c +#define dpcpsc_3c(a_) \ + pu(0,a_,cx) \ + pc(2,4) \ + pm(6,2) \ + ps(CSHUF,4,4) \ + pu(1,SS(a_,RS4),cx) \ + pm(7,4) \ + pa(4,2) \ + pc(3,4) \ + pm(6,3) \ + ps(CSHUF,4,4) \ + pu(2,SS(a_,MM(2,RS4)),cx) \ + pm(7,4) \ + pa(4,3) \ + pu(3,SS(a_,MM(3,RS4)),cx) +#undef plcpsc_3c +#define plcpsc_3c 16 + +#undef p1_4_cpsc_4 +#define p1_4_cpsc_4(a_) \ + pls(a_,cx,0) \ + pmsr(6,0) \ + pus(0,a_,ax) +#undef p1_2_cpsc_4 +#define p1_2_cpsc_4(a_) \ + pld(a_,cx,0) \ + pm(6,0) \ + pud(0,a_,ax) +#undef p1_cpsc_4 +#define p1_cpsc_4(a_) \ + pl(a_,cx,0) \ + pm(6,0) \ + puq(0,a_,ax) +#undef p2_cpsc_4 +#define p2_cpsc_4(a_) \ + pl(a_,cx,0) \ + pl(SS(a_,RS4),cx,1) \ + pm(6,0) \ + pm(6,1) \ + puq(0,a_,ax) \ + puq(1,SS(a_,RS4),ax) +#undef p4_cpsc_4 +#define p4_cpsc_4(a_) \ + pl(SS(a_,MM(3,RS4)),cx,3) \ + pm(6,2) \ + puq(0,a_,ax) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + pl(SS(a_,MM(4,RS4)),cx,0) \ + pm(6,3) \ + puq(1,SS(a_,RS4),ax) \ + pl(SS(a_,MM(5,RS4)),cx,1) \ + pm(6,0) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),cx) \ + pl(SS(a_,MM(6,RS4)),cx,2) \ + pm(6,1) \ + puq(3,SS(a_,MM(3,RS4)),ax) +#undef lpcpsc_4 +#define lpcpsc_4(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),cx) \ + pl(SS(a_,MM(0,RS4)),cx,0) \ + pl(SS(a_,MM(1,RS4)),cx,1) \ + pm(6,0) \ + pl(SS(a_,MM(2,RS4)),cx,2) \ + pm(6,1) +#undef dpcpsc_4 +#define dpcpsc_4(a_) \ + pl(SS(a_,MM(3,RS4)),cx,3) \ + pm(6,2) \ + puq(0,a_,ax) \ + pm(6,3) \ + puq(1,SS(a_,RS4),ax) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + puq(3,SS(a_,MM(3,RS4)),ax) +#undef plcpsc_4 +#define plcpsc_4 16 + +#undef p1_4_cpsc_5 +#define p1_4_cpsc_5(a_) \ + pls(a_,cx,0) \ + pmsr(6,0) \ + pus(0,a_,ax) +#undef p1_2_cpsc_5 +#define p1_2_cpsc_5(a_) \ + pld(a_,cx,0) \ + pm(6,0) \ + pud(0,a_,ax) +#undef p1_cpsc_5 +#define p1_cpsc_5(a_) \ + pl(a_,cx,0) \ + pm(6,0) \ + puq(0,a_,ax) +#undef p2_cpsc_5 +#define p2_cpsc_5(a_) \ + pl(a_,cx,0) \ + pl(SS(a_,RS4),cx,1) \ + pm(6,0) \ + pm(6,1) \ + puq(0,a_,ax) \ + puq(1,SS(a_,RS4),ax) +#undef p4_cpsc_5 +#define p4_cpsc_5(a_) \ + pl(SS(a_,MM(0,RS4)),cx,0) \ + pl(SS(a_,MM(1,RS4)),cx,1) \ + pl(SS(a_,MM(2,RS4)),cx,2) \ + pl(SS(a_,MM(3,RS4)),cx,3) \ + pm(6,0) \ + pm(6,1) \ + pm(6,2) \ + pm(6,3) \ + puq(0,a_,ax) \ + puq(1,SS(a_,RS4),ax) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + puq(3,SS(a_,MM(3,RS4)),ax) +#undef p8_cpsc_5 +#define p8_cpsc_5(a_) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + pl(SS(a_,MM(0,RS4)),cx,0) \ + pl(SS(a_,MM(1,RS4)),cx,1) \ + pl(SS(a_,MM(2,RS4)),cx,2) \ + pl(SS(a_,MM(3,RS4)),cx,3) \ + pl(SS(a_,MM(4,RS4)),cx,4) \ + pl(SS(a_,MM(5,RS4)),cx,5) \ + pl(SS(a_,MM(6,RS4)),cx,7) \ + pm(6,0) \ + pm(6,1) \ + pm(6,2) \ + pm(6,3) \ + puq(0,a_,ax) \ + pl(SS(a_,MM(7,RS4)),cx,0) \ + pm(6,4) \ + pm(6,5) \ + pm(6,7) \ + pm(6,0) \ + puq(1,SS(a_,RS4),ax) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + puq(3,SS(a_,MM(3,RS4)),ax) \ + puq(4,SS(a_,MM(4,RS4)),ax) \ + puq(5,SS(a_,MM(5,RS4)),ax) \ + puq(7,SS(a_,MM(6,RS4)),ax) \ + puq(0,SS(a_,MM(7,RS4)),ax) +#undef lpcpsc_5 +#define lpcpsc_5(a_) +#undef dpcpsc_5 +#define dpcpsc_5(a_) p8_cpsc_5(a_) +#undef plcpsc_5 +#define plcpsc_5 32 + +#undef cpsc_cdp +#define cpsc_cdp(a_) pc(a_,5) pm(6,a_) ps(CSHUF,5,5) pm(7,5) pa(5,a_) +#undef p1_4_cpsc_5c +#define p1_4_cpsc_5c(a_) +#undef p1_2_cpsc_5c +#define p1_2_cpsc_5c(a_) \ + pld(a_,cx,0) \ + cpsc_cdp(0) \ + pud(0,a_,ax) +#undef p1_cpsc_5c +#define p1_cpsc_5c(a_) \ + pl(a_,cx,0) \ + cpsc_cdp(0) \ + puq(0,a_,ax) +#undef p2_cpsc_5c +#define p2_cpsc_5c(a_) \ + pl(a_,cx,0) \ + pl(SS(a_,RS4),cx,1) \ + cpsc_cdp(0) \ + cpsc_cdp(1) \ + puq(0,a_,ax) \ + puq(1,SS(a_,RS4),ax) +#undef p4_cpsc_5c +#define p4_cpsc_5c(a_) \ + pl(SS(a_,MM(0,RS4)),cx,0) \ + pl(SS(a_,MM(1,RS4)),cx,1) \ + pl(SS(a_,MM(2,RS4)),cx,2) \ + pl(SS(a_,MM(3,RS4)),cx,3) \ + cpsc_cdp(0) \ + cpsc_cdp(1) \ + cpsc_cdp(2) \ + cpsc_cdp(3) \ + puq(0,a_,ax) \ + puq(1,SS(a_,RS4),ax) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + puq(3,SS(a_,MM(3,RS4)),ax) +#undef p8_cpsc_5c +#define p8_cpsc_5c(a_) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + pl(SS(a_,MM(0,RS4)),cx,0) \ + pl(SS(a_,MM(1,RS4)),cx,1) \ + pl(SS(a_,MM(2,RS4)),cx,2) \ + pl(SS(a_,MM(3,RS4)),cx,3) \ + pl(SS(a_,MM(4,RS4)),cx,4) \ + cpsc_cdp(0) \ + cpsc_cdp(1) \ + puq(0,a_,ax) \ + pl(SS(a_,MM(5,RS4)),cx,0) \ + cpsc_cdp(2) \ + cpsc_cdp(3) \ + puq(1,SS(a_,RS4),ax) \ + pl(SS(a_,MM(6,RS4)),cx,1) \ + cpsc_cdp(4) \ + cpsc_cdp(0) \ + puq(2,SS(a_,MM(2,RS4)),ax) \ + pl(SS(a_,MM(7,RS4)),cx,2) \ + cpsc_cdp(1) \ + cpsc_cdp(2) \ + puq(3,SS(a_,MM(3,RS4)),ax) \ + puq(4,SS(a_,MM(4,RS4)),ax) \ + puq(0,SS(a_,MM(5,RS4)),ax) \ + puq(1,SS(a_,MM(6,RS4)),ax) \ + puq(2,SS(a_,MM(7,RS4)),ax) +#undef lpcpsc_5c +#define lpcpsc_5c(a_) +#undef dpcpsc_5c +#define dpcpsc_5c(a_) p8_cpsc_5c(a_) +#undef plcpsc_5c +#define plcpsc_5c 32 + +#undef p1_4_cpsc_1 +#define p1_4_cpsc_1(a_) \ + pls(a_,ax,2) \ + pmsr(3,2) \ + pus(2,a_,cx) +#undef p1_2_cpsc_1 +#define p1_2_cpsc_1(a_) \ + pld(a_,ax,2) \ + pm(3,2) \ + pud(2,a_,cx) +#undef p1_cpsc_1 +#define p1_cpsc_1(a_) \ + plq(a_,ax,2) \ + pm(3,2) \ + pu(2,a_,cx) +#undef p2_cpsc_1 +#define p2_cpsc_1(a_) \ + plq(SS(a_,RS4),ax,4) \ + pm(3,2) \ + pu(2,a_,cx) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,2) \ + pm(3,4) \ + pu(4,SS(a_,RS4),cx) +#undef lpcpsc_1 +#define lpcpsc_1(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),cx) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(SS(a_,MM(0,RS4)),ax,2) +#undef dpcpsc_1 +#define dpcpsc_1(a_) \ + plq(SS(a_,RS4),ax,4) \ + pm(3,2) \ + pu(2,a_,cx) \ + pm(3,4) \ + pu(4,SS(a_,RS4),cx) +#undef plcpsc_1 +#define plcpsc_1 8 + +#undef p1_4_cpsc_2 +#define p1_4_cpsc_2(a_) \ + pls(a_,ax,2) \ + pmsr(3,2) \ + pus(2,a_,cx) +#undef p1_2_cpsc_2 +#define p1_2_cpsc_2(a_) \ + pld(a_,ax,2) \ + pm(3,2) \ + pud(2,a_,cx) +#undef p1_cpsc_2 +#define p1_cpsc_2(a_) \ + plq(a_,ax,2) \ + pm(3,2) \ + pu(2,a_,cx) +#undef p2_cpsc_2 +#define p2_cpsc_2(a_) \ + plq(a_,ax,2) \ + plq(SS(a_,RS4),ax,4) \ + pm(3,2) \ + pm(3,4) \ + pu(2,a_,cx) \ + pu(4,SS(a_,RS4),cx) +#undef p4_cpsc_2 +#define p4_cpsc_2(a_) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,7) \ + pm(3,6) \ + pu(4,a_,cx) \ + plq(SS(a_,MM(3,RS4)),ax,2) \ + pm(3,7) \ + pu(6,SS(a_,RS4),cx) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),cx) \ + f(nta,SS(a_,MM((SS(4,CL)),RS4)),ax) \ + plq(SS(a_,MM(4,RS4)),ax,4) \ + pm(3,2) \ + pu(7,SS(a_,MM(2,RS4)),cx) \ + plq(SS(a_,MM(5,RS4)),ax,6) \ + pm(3,4) \ + pu(2,SS(a_,MM(3,RS4)),cx) +#undef lpcpsc_2 +#define lpcpsc_2(a_) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),cx) \ + f(nta,SS(a_,MM((SS(0,CL)),RS4)),ax) \ + plq(SS(a_,MM(0,RS4)),ax,4) \ + plq(SS(a_,MM(1,RS4)),ax,6) \ + pm(3,4) +#undef dpcpsc_2 +#define dpcpsc_2(a_) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),cx) \ + f(nta,SS(a_,MM((SS(2,CL)),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,7) \ + pm(3,6) \ + pu(4,a_,cx) \ + plq(SS(a_,MM(3,RS4)),ax,2) \ + pm(3,7) \ + pu(6,SS(a_,RS4),cx) \ + pm(3,2) \ + pu(7,SS(a_,MM(2,RS4)),cx) \ + pu(2,SS(a_,MM(3,RS4)),cx) +#undef plcpsc_2 +#define plcpsc_2 RS4 + + +#undef p1_4_iamax_1 +#define p1_4_iamax_1(a_) \ + px(4) \ + pls(a_,ax,4) \ + pan(2,4) \ + pc(3,5) \ + pcm(6,4,5) \ + paxs(4,3) \ + pan(5,6) \ + pann(0,5) \ + pasr(5,6) \ + pasr(1,0) \ + ps(57,0,0) +#undef p1_2_iamax_1 +#define p1_2_iamax_1(a_) \ + px(4) \ + pld(a_,ax,4) \ + pan(2,4) \ + pc(3,5) \ + pcm(6,4,5) \ + pax(4,3) \ + pan(5,6) \ + pann(0,5) \ + pa(5,6) \ + pasr(1,0) \ + ps(57,0,0)\ + pasr(1,0) \ + ps(57,0,0) +#undef p1_iamax_1 +#define p1_iamax_1(a_) \ + plq(a_,ax,4) \ + pan(2,4) \ + pc(3,5) \ + pcm(6,4,5) \ + pax(4,3) \ + pan(5,6) \ + pann(0,5) \ + pa(5,6) \ + pa(1,0) +#define p2_iamax_1(a_) \ + plq(SS(a_,RS4),ax,4) \ + pan(2,4) \ + pc(3,5) \ + pcm(6,4,5) \ + pax(4,3) \ + pan(5,6) \ + pann(0,5) \ + pa(5,6) \ + pa(1,0) \ + f(nta,SS(a_,MM(SS(2,CL),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,4) \ + pan(2,4) \ + pc(3,5) \ + pcm(6,4,5) \ + pax(4,3) \ + pan(5,6) \ + pann(0,5) \ + pa(5,6) \ + pa(1,0) +#undef lpiamax_1 +#define lpiamax_1(a_) \ + f(nta,SS(a_,MM(CL,RS4)),ax) \ + plq(a_,ax,4) \ + pan(2,4) \ + pc(3,5) \ + pcm(6,4,5) \ + pax(4,3) \ + pan(5,6) \ + pann(0,5) \ + pa(5,6) \ + pa(1,0) +#undef dpiamax_1 +#define dpiamax_1(a_) \ + plq(SS(a_,RS4),ax,4) \ + pan(2,4) \ + pc(3,5) \ + pcm(6,4,5) \ + pax(4,3) \ + pan(5,6) \ + pann(0,5) \ + pa(5,6) \ + pa(1,0) +#undef pliamax_1 +#define pliamax_1 8 + +#undef p1_4_iamax_1d +#define p1_4_iamax_1d(a_) +#undef p1_2_iamax_1d +#define p1_2_iamax_1d(a_) \ + px(4) \ + pld(a_,ax,4) \ + dbg(2) \ + pan(2,4) \ + dbg(4) \ + pc(3,5) \ + dbg(5) \ + pcm(6,4,5) \ + dbg(5) \ + pax(4,3) \ + dbg(3) \ + pan(5,6) \ + dbg(6) \ + pann(0,5) \ + dbg(5) \ + pa(5,6) \ + dbg(6) \ + pasr(1,0) \ + dbg(0) \ + ps(1,0,0) +#undef p1_iamax_1d +#define p1_iamax_1d(a_) \ + plq(a_,ax,4) \ + dbg(2) \ + pan(2,4) \ + dbg(4) \ + pc(3,5) \ + dbg(5) \ + pcm(6,4,5) \ + dbg(5) \ + pax(4,3) \ + dbg(3) \ + pan(5,6) \ + dbg(6) \ + pann(0,5) \ + dbg(5) \ + pa(5,6) \ + dbg(6) \ + pa(1,0) +#define p2_iamax_1d(a_) \ + plq(SS(a_,RS4),ax,4) \ + dbg(2) \ + pan(2,4) \ + dbg(4) \ + pc(3,5) \ + dbg(5) \ + pcm(6,4,5) \ + dbg(5) \ + pax(4,3) \ + dbg(3) \ + pan(5,6) \ + dbg(6) \ + pann(0,5) \ + dbg(5) \ + pa(5,6) \ + dbg(6) \ + pa(1,0) \ + dbg(0) \ + f(nta,SS(a_,MM(SS(2,CL),RS4)),ax) \ + plq(SS(a_,MM(2,RS4)),ax,4) \ + dbg(2) \ + pan(2,4) \ + dbg(4) \ + pc(3,5) \ + dbg(5) \ + pcm(6,4,5) \ + dbg(5) \ + pax(4,3) \ + dbg(3) \ + pan(5,6) \ + dbg(6) \ + pann(0,5) \ + dbg(5) \ + pa(5,6) \ + dbg(6) \ + pa(1,0) +#undef lpiamax_1d +#define lpiamax_1d(a_) \ + f(nta,SS(a_,MM(CL,RS4)),ax) \ + plq(a_,ax,4) \ + dbg(2) \ + pan(2,4) \ + dbg(4) \ + pc(3,5) \ + dbg(5) \ + pcm(6,4,5) \ + dbg(5) \ + pax(4,3) \ + dbg(3) \ + pan(5,6) \ + dbg(6) \ + pann(0,5) \ + dbg(5) \ + pa(5,6) \ + dbg(6) \ + pa(1,0) +#undef dpiamax_1d +#define dpiamax_1d(a_) \ + plq(SS(a_,RS4),ax,4) \ + dbg(2) \ + pan(2,4) \ + dbg(4) \ + pc(3,5) \ + dbg(5) \ + pcm(6,4,5) \ + dbg(5) \ + pax(4,3) \ + dbg(3) \ + pan(5,6) \ + dbg(6) \ + pann(0,5) \ + dbg(5) \ + pa(5,6) \ + dbg(6) \ + pa(1,0) +#undef pliamax_1d +#define pliamax_1d 8 + diff --git a/kaldi_io/src/tools/ATLAS/include/contrib/camm_tpipe.h b/kaldi_io/src/tools/ATLAS/include/contrib/camm_tpipe.h new file mode 100644 index 0000000..03486cf --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/contrib/camm_tpipe.h @@ -0,0 +1,331 @@ +/*************************************** + $Header: /cvsroot/math-atlas/AtlasBase/kernel/CammMaguire/camm_tpipe.h,v 1.2 2003/10/18 18:13:30 yycamm Exp $ + + +***************************************/ + + +/* #ifndef CAMM_TPIPE_H */ +/* #define CAMM_TPIPE_H */ /*+ To stop multiple inclusions. +*/ + +#ifndef BITS +#error BITS must be defined in camm_tpipe.h +#endif +#ifndef DIV +#error DIV must be defined in camm_tpipe.h +#endif +#ifndef INC +#error INC(a_) must be defined in camm_tpipe.h +#endif +#ifndef LR +#error LR must be defined in camm_tpipe.h +#endif + +#ifdef ALIGN + +#if defined(SREAL) + + test(4,ax) + je(a2) + +#undef KB +#define KB ( 1 /* / DIV */ ) +#include "camm_pipe3.h" + + KB_block + INC(4) + sub(1,LR) + + lab(a2) + +#endif + +#if defined(SREAL) || defined(DREAL) + + test(8,ax) + je(a4) + test(-2,LR) + je(a4) + +#undef KB +#define KB ( 2 /* / DIV */ ) +#include "camm_pipe3.h" + KB_block + INC(8) + sub(2,LR) + + lab(a4) + +#endif +#endif + +/* "movl %%edx,%%edi\n\t" */ + push(LR) + shr(BITS,LR) + shl(BITS,LR) + m(4,LR) + ra(ax,LR) + +#if defined(ALIGN) && ( defined(SCPLX) || defined(DCPLX) ) + test(12,ax) + je(loopa) +#endif + +#if !defined(ALIGN) || defined(SCPLX) || defined(DCPLX) +#undef plq +#define plq(a_,b_,c_) pl(a_,b_,c_) +#undef puq +#define puq(a_,b_,c_) pu(a_,b_,c_) +#undef plqx +#define plqx(a_,b_,c_,d_,e_) plx(a_,b_,c_,d_,e_) +#undef puqx +#define puqx(a_,b_,c_,d_,e_) pux(a_,b_,c_,d_,e_) +#else +#undef plq +#define plq(a_,b_,c_) pla(a_,b_,c_) +#undef puq +#define puq(a_,b_,c_) punt(a_,b_,c_) +#undef plqx +#define plqx(a_,b_,c_,d_,e_) plax(a_,b_,c_,d_,e_) +#undef puqx +#define puqx(a_,b_,c_,d_,e_) puax(a_,b_,c_,d_,e_) +#endif + + align + lab(loop) + cmp(ax,LR) + je(stop) + +#undef KB +#define KB ( (1 << BITS) /* / DIV */ ) +#include "camm_pipe3.h" + KB_block + INC(4*KB/**DIV*/) + + jmp(loop) + + lab(stop) + pop(LR) + +#if ( 1 << BITS ) > 128 + test(128,LR) + je(64) +#undef KB +#define KB ( 128 /* / DIV */ ) +#include "camm_pipe3.h" + KB_block + INC(512) + + lab(64) +#endif + +#if ( 1 << BITS ) > 64 + test(64,LR) + je(32) +#undef KB +#define KB ( 64 /* / DIV */ ) +#include "camm_pipe3.h" + KB_block + INC(256) + + lab(32) +#endif + +#if ( 1 << BITS ) > 32 + test(32,LR) + je(16) +#undef KB +#define KB ( 32 /* / DIV */ ) +#include "camm_pipe3.h" + KB_block + INC(128) + + lab(16) +#endif + +#if ( 1 << BITS ) > 16 + test(16,LR) + je(8) +#undef KB +#define KB ( 16 /* / DIV */ ) +#include "camm_pipe3.h" + KB_block + INC(64) + + lab(8) +#endif + +#if ( 1 << BITS ) > 8 + test(8,LR) + je(4) +#undef KB +#define KB ( 8 /* / DIV */ ) +#include "camm_pipe3.h" + KB_block + INC(32) + + lab(4) +#endif + +#if ( 1 << BITS ) > 4 + test(4,LR) + je(2) +#undef KB +#define KB ( 4 /* / DIV */ ) +#include "camm_pipe3.h" + KB_block + INC(16) + + lab(2) +#endif + +#if DIV != 4 && ( 1 << BITS ) > 2 + test(2,LR) + je(1) +#undef KB +#define KB ( 2 /* / DIV */ ) +#include "camm_pipe3.h" + KB_block + INC(8) + + lab(1) +#endif + +#if DIV == 1 && ( 1 << BITS ) > 1 + test(1,LR) + je(end) +#undef KB +#define KB ( 1 /* / DIV */ ) +#include "camm_pipe3.h" + KB_block + lab(end) +#endif + +#if defined (ALIGN) && ( defined(SCPLX) || defined(DCPLX) ) + + jmp(tend) + +#undef plq +#define plq(a_,b_,c_) pla(a_,b_,c_) +#undef puq +#define puq(a_,b_,c_) punt(a_,b_,c_) +#undef plqx +#define plqx(a_,b_,c_,d_,e_) plax(a_,b_,c_,d_,e_) +#undef puqx +#define puqx(a_,b_,c_,d_,e_) puax(a_,b_,c_,d_,e_) + + align + lab(loopa) + cmp(ax,LR) + je(stopa) + +#undef KB +#define KB ( (1 << BITS) /* / DIV */ ) +#include "camm_pipe3.h" + KB_block + INC(4*KB/**DIV*/) + + jmp(loopa) + + lab(stopa) + pop(LR) + +#if ( 1 << BITS ) > 128 + test(128,LR) + je(64a) +#undef KB +#define KB ( 128 /* / DIV */ ) +#include "camm_pipe3.h" + KB_block + INC(512) + + lab(64a) +#endif + +#if ( 1 << BITS ) > 64 + test(64,LR) + je(32a) +#undef KB +#define KB ( 64 /* / DIV */ ) +#include "camm_pipe3.h" + KB_block + INC(256) + + lab(32a) +#endif + +#if ( 1 << BITS ) > 32 + test(32,LR) + je(16a) +#undef KB +#define KB ( 32 /* / DIV */ ) +#include "camm_pipe3.h" + KB_block + INC(128) + + lab(16a) +#endif + +#if ( 1 << BITS ) > 16 + test(16,LR) + je(8a) +#undef KB +#define KB ( 16 /* / DIV */ ) +#include "camm_pipe3.h" + KB_block + INC(64) + + lab(8a) +#endif + +#if ( 1 << BITS ) > 8 + test(8,LR) + je(4a) +#undef KB +#define KB ( 8 /* / DIV */ ) +#include "camm_pipe3.h" + KB_block + INC(32) + + lab(4a) +#endif + +#if ( 1 << BITS ) > 4 + test(4,LR) + je(2a) +#undef KB +#define KB ( 4 /* / DIV */ ) +#include "camm_pipe3.h" + KB_block + INC(16) + + lab(2a) +#endif + +#if DIV != 4 && ( 1 << BITS ) > 2 + test(2,LR) + je(1a) +#undef KB +#define KB ( 2 /* / DIV */ ) +#include "camm_pipe3.h" + KB_block + INC(8) + + lab(1a) +#endif + +#if DIV == 1 && ( 1 << BITS ) > 1 + test(1,LR) + je(enda) +#undef KB +#define KB ( 1 /* / DIV */ ) +#include "camm_pipe3.h" + KB_block + lab(enda) +#endif + + lab(tend) + +#endif + +/* #endif */ /* CAMM_TPIPE_H */ diff --git a/kaldi_io/src/tools/ATLAS/include/contrib/camm_util.h b/kaldi_io/src/tools/ATLAS/include/contrib/camm_util.h new file mode 100644 index 0000000..6b150d3 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/contrib/camm_util.h @@ -0,0 +1,508 @@ +#ifndef CAMM_UTIL_H +#define CAMM_UTIL_H /*+ To stop multiple inclusions. +*/ + +typedef struct { + float r,i; +} Complex; + +typedef struct { + double r,i; +} Dcomplex; + +#undef str +#define str(a_) xstr(a_) +#undef xstr +#define xstr(a_) #a_ + +#undef val +#define val(a_) xval(a_) +#undef xval +#define xval(a_) a_ + +#ifndef Mjoin +#define Mjoin(a,b) mjoin(a,b) +#ifdef mjoin + #undef mjoin +#endif +#define mjoin(a,b) a ## b +#endif + +#undef VOLATILE +#define VOLATILE __volatile__ +#undef ASM +#define ASM __asm__ VOLATILE + +#ifdef BETA0 +#undef BL +#define BL b0 +#endif +#ifdef BETA1 +#undef BL +#define BL b1 +#endif +#ifdef BETAX +#undef BL +#define BL bX +#endif +#ifdef BETAXI0 +#undef BL +#define BL bXi0 +#endif + +#ifdef NO_TRANSPOSE +#ifdef GER +#ifdef Conj_ +#undef FEXT +#define FEXT Gc +#else +#undef FEXT +#define FEXT Gu +#endif +#else +#ifdef Conj_ +#undef FEXT +#define FEXT Nc +#else +#undef FEXT +#define FEXT N +#endif +#endif +#else +#ifdef Conj_ +#undef FEXT +#define FEXT C +#else +#undef FEXT +#define FEXT T +#endif +#endif + +#undef BLC +#define BLC Mjoin(FEXT,BL) + +#ifdef __GNUC__ +#undef NO_INLINE +#define NO_INLINE double sq(double x) {return x*x;} +#else +#undef NO_INLINE +#define NO_INLINE +#endif + +#undef lab +#define lab(a_) "\n" str(MY_FUNCTION) "_" str(N) "_" str(a_) ":\n\t" +#undef jmp +#define jmp(a_) "jmp " str(MY_FUNCTION) "_" str(N) "_" str(a_) "\n\t" +#undef je +#define je(a_) "je " str(MY_FUNCTION) "_" str(N) "_" str(a_) "\n\t" +#undef jge +#define jge(a_) "jge " str(MY_FUNCTION) "_" str(N) "_" str(a_) "\n\t" +#undef jle +#define jle(a_) "jle " str(MY_FUNCTION) "_" str(N) "_" str(a_) "\n\t" +#undef jl +#define jl(a_) "jl " str(MY_FUNCTION) "_" str(N) "_" str(a_) "\n\t" +#undef jne +#define jne(a_) "jne " str(MY_FUNCTION) "_" str(N) "_" str(a_) "\n\t" +#undef align +#define align ".align 16\n\t" +#undef test +#define test(a_,b_) "testl $" str(a_) ",%%e" str(b_) "\n\t" +#undef and +#define and(a_,b_) "andl $" str(a_) ",%%e" str(b_) "\n\t" +#undef sub +#define sub(a_,b_) "subl $" str(a_) ",%%e" str(b_) "\n\t" +#undef SS +#define SS(a_,b_) a_ + b_ +#undef MM +#define MM(a_,b_) a_ * b_ +#undef E4 +#define E4(a_) (( a_ >> 2 ) << 2 ) + +#undef TYPE +#undef SCALAR +#undef PREC +#undef CSHUF +#undef LSHUF +#undef HSHUF +#undef ISHUF +#undef RSHUF +#undef SINGLE +#undef REAL +#undef DIV + +#ifdef SCPLX +#define TYPE Complex +#define SCALAR Complex * +#define PREC c +#define CSHUF 177 +#define LSHUF 160 +#define HSHUF 245 +#define ISHUF 13*17 +#define RSHUF 8*17 +#define SINGLE +#define DIV 2 +/* #ifdef Conj_ */ +/* static const TYPE signd[2]={{-1.0,1.0},{-1.0,1.0}}; */ +/* #else */ + static const TYPE signd[2]={{1.0,-1.0},{1.0,-1.0}}; +/* #endif */ +#endif + +#ifdef SREAL +#define TYPE float +#define SCALAR float +#define PREC s +#define SINGLE +#define REAL +#define DIV 1 +#endif + +#ifdef DREAL +#define TYPE double +#define SCALAR double +#define PREC d +#define REAL +#define DIV 2 +#endif + +#ifdef DCPLX +#define TYPE Dcomplex +#define SCALAR Dcomplex * +#define PREC z +#define CSHUF 1 +#define LSHUF 0 +#define HSHUF 3 +#define ISHUF 3 +#define RSHUF 0 +#define DIV 4 +/* #ifdef Conj_ */ +/* static const TYPE signd[1]={{-1.0,1.0}}; */ +/* #else */ + static const TYPE signd[1]={{1.0,-1.0}}; +/* #endif */ +#endif + +#undef M11 +#define M11 0 +#undef M12 +#define M12 1 +#undef M13 +#define M13 2 +#undef M14 +#define M14 3 +#undef M15 +#define M15 4 +#undef M16 +#define M16 5 +#undef M17 +#define M17 6 +#undef M18 +#define M18 7 + +#undef M23 +#define M23 1 +#undef M24 +#define M24 2 +#undef M25 +#define M25 3 +#undef M26 +#define M26 4 +#undef M27 +#define M27 5 +#undef M28 +#define M28 6 + +#undef M33 +#define M33 0 +#undef M34 +#define M34 1 +#undef M35 +#define M35 2 +#undef M36 +#define M36 3 +#undef M37 +#define M37 4 +#undef M38 +#define M38 5 + +#undef P10 +#define P10 1 +#undef P11 +#define P11 2 +#undef P12 +#define P12 3 +#undef P13 +#define P13 4 +#undef P14 +#define P14 5 +#undef P15 +#define P15 6 +#undef P16 +#define P16 7 + +#undef XM +#define XM(a_,b_) M ## b_ ## a_ +#undef M +#define M(a_,b_) XM(a_,b_) + +#undef XP +#define XP(a_,b_) P ## b_ ## a_ +#undef P +#define P(a_,b_) XP(a_,b_) + +#undef mex +#define mex(a_) str(%%e ## a_) +#undef msx +#define msx(a_) "%%st(" str(a_) ")" + +#undef cmp +#define cmp(a_,b_) "cmp " mex(a_) "," mex(b_) "\n\t" +#undef icmpr +#define icmpr(a_,b_) "cmp " mex(a_) ",(" mex(b_) ")\n\t" +#undef f +#define f(a_,b_,c_) "prefetch" str(a_) " " str(b_) "(%%e" #c_ ")\n\t" +#undef pfx +#define pfx(a_,b_,c_,d_,e_) "prefetch" str(a_) " " str(b_) "(%%e" #c_ ",%%e" #d_ "," str(e_) ")\n\t" +#undef a +#define a(a_,b_) "addl $" str(a_) "," mex(b_) "\n\t" +#undef m +#define m(a_,b_) "imul $" str(a_) "," mex(b_) "\n\t" +#undef pop +#define pop(a_) "popl %%e" str(a_) "\n\t" +#undef push +#define push(a_) "pushl %%e" str(a_) "\n\t" +#undef d +#define d(a_,b_) "idiv $" str(a_) "," mex(b_) "\n\t" +#undef shl +#define shl(a_,b_) "shl $" str(a_) "," mex(b_) "\n\t" +#undef shr +#define shr(a_,b_) "shr $" str(a_) "," mex(b_) "\n\t" +#undef mm +#define mm(a_,b_) "mov $" str(a_) "," mex(b_) "\n\t" +#undef ra +#define ra(a_,b_) "addl %%e" str(a_) "," mex(b_) "\n\t" +#undef rs +#define rs(a_,b_) "subl %%e" str(a_) "," mex(b_) "\n\t" + +#undef fl +#define fl(a_,b_) "fldl " str(a_) "(" mex(b_) ")\n\t" +#undef fp +#define fp(a_,b_) "fstpl " str(a_) "(" mex(b_) ")\n\t" +#undef fd +#define fd(a_) "fld " msx(a_) "\n\t" +#undef fap +#define fap(a_,b_) "faddp " msx(a_) "," msx(b_) "\n\t" +/* #define fsp(a_) fx(a_) "fsubp %%st," msx(a_) "\n\t" */ +#undef fsp +#define fsp(a_) "fsubrp %%st," msx(a_) "\n\t" +#undef fmp +#define fmp(a_,b_) "fmulp " msx(a_) "," msx(b_) "\n\t" +#undef fa +#define fa(a_,b_) "fadd " msx(a_) "," msx(b_) "\n\t" +#undef fm +#define fm(a_,b_) "fmul " msx(a_) "," msx(b_) "\n\t" +#undef faa +#define faa(a_,b_) "faddl " str(a_) "(" mex(b_) ")\n\t" +#undef fma +#define fma(a_,b_) "fmull " str(a_) "(" mex(b_) ")\n\t" +#undef fz +#define fz "fldz\n\t" +#undef fx +#define fx(a_) "fxch " msx(a_) "\n\t" +#undef fx1 +#define fx1 "fxch\n\t" +#undef fc +#define fc(a_) "fstp " msx(a_) "\n\t" + + +#ifndef ATHLON + + +#if defined(DREAL) || defined(DCPLX) +#undef SSESUF +#define SSESUF "d " +#undef RS4 +#define RS4 16 +#undef RS +#define RS 4 +#else +#undef SSESUF +#define SSESUF "s " +#undef RS4 +#define RS4 16 +#undef RS +#define RS 4 +#endif + +#undef mxx +#define mxx(a_) str(%%xmm ## a_) +#undef prp +#define prp(a_,b_) "rcpp" SSESUF mxx(a_) "," mxx(b_) "\n\t" +#undef prps +#define prps(a_,b_) "rcps" SSESUF mxx(a_) "," mxx(b_) "\n\t" +#undef pann +#define pann(a_,b_) "andnp" SSESUF mxx(a_) "," mxx(b_) "\n\t" +#undef psqs +#define psqs(a_,b_) "sqrts" SSESUF mxx(a_) "," mxx(b_) "\n\t" +#undef por +#define por(a_,b_) "orp" SSESUF mxx(a_) "," mxx(b_) "\n\t" +#undef pan +#define pan(a_,b_) "andp" SSESUF mxx(a_) "," mxx(b_) "\n\t" +#undef pcm +#define pcm(a_,b_,c_) "cmpp" SSESUF " $" str(a_) "," mxx(b_) "," mxx(c_) "\n\t" +#undef pcms +#define pcms(a_,b_,c_) "cmps" SSESUF " $" str(a_) "," mxx(b_) "," mxx(c_) "\n\t" +#undef pax +#define pax(a_,b_) "maxp" SSESUF mxx(a_) "," mxx(b_) "\n\t" +#undef paxs +#define paxs(a_,b_) "maxs" SSESUF mxx(a_) "," mxx(b_) "\n\t" +#undef pd +#define pd(a_,b_) "divp" SSESUF mxx(a_) "," mxx(b_) "\n\t" +#undef pdsr +#define pdsr(a_,b_) "divs" SSESUF mxx(a_) "," mxx(b_) "\n\t" +#undef pxx +#define pxx(a_,b_) "xorp" SSESUF mxx(a_) "," mxx(b_) "\n\t" +#undef px +#define px(a_) "xorp" SSESUF mxx(a_) "," mxx(a_) "\n\t" +#undef pm +#define pm(a_,b_) "mulp" SSESUF mxx(a_) "," mxx(b_) "\n\t" +#undef pa +#define pa(a_,b_) "addp" SSESUF mxx(a_) "," mxx(b_) "\n\t" +#undef pmm +#define pmm(a_,b_,c_) "mulp" SSESUF str(a_) "(" mex(b_) ")," mxx(c_) "\n\t" +#undef pam +#define pam(a_,b_,c_) "addp" SSESUF str(a_) "(" mex(b_) ")," mxx(c_) "\n\t" +#undef pl +#define pl(a_,b_,c_) "movup" SSESUF str(a_) "(" mex(b_) ")," mxx(c_) "\n\t" +#undef pla +#define pla(a_,b_,c_) "movap" SSESUF str(a_) "(" mex(b_) ")," mxx(c_) "\n\t" +#undef pu +#define pu(a_,b_,c_) "movup" SSESUF mxx(a_) "," str(b_) "(" mex(c_) ")\n\t" +#undef punt +#define punt(a_,b_,c_) "movntp" SSESUF mxx(a_) "," str(b_) "(" mex(c_) ")\n\t" +#undef pua +#define pua(a_,b_,c_) "movap" SSESUF mxx(a_) "," str(b_) "(" mex(c_) ")\n\t" +#undef pud +#define pud(a_,b_,c_) "movlp" SSESUF mxx(a_) "," str(b_) "(" mex(c_) ")\n\t" +#undef pudr +#define pudr(a_,b_) "movlp" SSESUF mxx(a_) "," mxx(b_) "\n\t" +#undef pc +#define pc(a_,b_) "movap" SSESUF mxx(a_) "," mxx(b_) "\n\t" +#undef ps +#define ps(a_,b_,c_) "shufp" SSESUF " $" str(a_) "," mxx(b_) "," mxx(c_) "\n\t" +#undef phl +#define phl(a_,b_) "movhlp" SSESUF mxx(a_) "," mxx(b_) "\n\t" +#undef pus +#define pus(a_,b_,c_) "movs" SSESUF mxx(a_) "," str(b_) "(" mex(c_) ")\n\t" +#undef pls +#define pls(a_,b_,c_) "movs" SSESUF str(a_) "(" mex(b_) ")," mxx(c_) "\n\t" +#undef pld +#define pld(a_,b_,c_) "movlp" SSESUF str(a_) "(" mex(b_) ")," mxx(c_) "\n\t" +#undef plh +#define plh(a_,b_) "movlhp" SSESUF mxx(a_) "," mxx(b_) "\n\t" +#undef pas +#define pas(a_,b_,c_) "adds" SSESUF str(a_) "(" mex(b_) ")," mxx(c_) "\n\t" +#undef pms +#define pms(a_,b_,c_) "muls" SSESUF str(a_) "(" mex(b_) ")," mxx(c_) "\n\t" +#undef pcs +#define pcs(a_,b_) "movs" SSESUF mxx(a_) "," mxx(b_) "\n\t" +#undef pasr +#define pasr(a_,b_) "adds" SSESUF mxx(a_) "," mxx(b_) "\n\t" +#undef pmsr +#define pmsr(a_,b_) "muls" SSESUF mxx(a_) "," mxx(b_) "\n\t" +#undef pul +#define pul(a_,b_) "unpcklp" SSESUF mxx(a_) "," mxx(b_) "\n\t" +#undef puh +#define puh(a_,b_) "unpckhp" SSESUF mxx(a_) "," mxx(b_) "\n\t" + +#undef plsx +#define plsx(a_,b_,c_,d_,e_) \ + "movs" SSESUF str(a_) "(" mex(b_) "," mex(c_) "," #d_ ")," mxx(e_) "\n\t" +#undef plx +#define plx(a_,b_,c_,d_,e_) \ + "movup" SSESUF str(a_) "(" mex(b_) "," mex(c_) "," #d_ ")," mxx(e_) "\n\t" +#undef plax +#define plax(a_,b_,c_,d_,e_) \ + "movap" SSESUF str(a_) "(" mex(b_) "," mex(c_) "," #d_ ")," mxx(e_) "\n\t" +#undef pasx +#define pasx(a_,b_,c_,d_,e_) \ + "adds" SSESUF str(a_) "(" mex(b_) "," mex(c_) "," #d_ ")," mxx(e_) "\n\t" +#undef pusx +#define pusx(a_,b_,c_,d_,e_) \ + "movs" SSESUF mxx(a_) "," str(b_) "(" mex(c_) "," mex(d_) "," #e_ ")\n\t" +#undef pux +#define pux(a_,b_,c_,d_,e_) \ + "movup" SSESUF mxx(a_) "," str(b_) "(" mex(c_) "," mex(d_) "," #e_ ")\n\t" +#undef puax +#define puax(a_,b_,c_,d_,e_) \ + "movap" SSESUF mxx(a_) "," str(b_) "(" mex(c_) "," mex(d_) "," #e_ ")\n\t" +#undef pudx +#define pudx(a_,b_,c_,d_,e_) \ + "movlp" SSESUF mxx(a_) "," str(b_) "(" mex(c_) "," mex(d_) "," #e_ ")\n\t" + +#undef pldx +#define pldx(a_,b_,c_,d_,e_) \ + "movlp" SSESUF str(a_) "(" mex(b_) "," mex(c_) "," #d_ ")," mxx(e_) "\n\t" + +#else + +#undef RS4 +#define RS4 8 +#undef RS +#define RS 2 + +#undef mxx +#define mxx(a_) str(%%mm ## a_) +#undef pul +#define pul(a_,b_) "punpckldq " mxx(a_) "," mxx(b_) "\n\t" +#undef puh +#define puh(a_,b_) "punpckhdq " mxx(a_) "," mxx(b_) "\n\t" + +#undef px +#define px(a_) "pxor " mxx(a_) "," mxx(a_) "\n\t" +#undef pm +#define pm(a_,b_) "pfmul " mxx(a_) "," mxx(b_) "\n\t" +#undef pa +#define pa(a_,b_) "pfadd " mxx(a_) "," mxx(b_) "\n\t" +#undef pac +#define pac(a_,b_) "pfacc " mxx(a_) "," mxx(b_) "\n\t" +#undef pmm +#define pmm(a_,b_,c_) "pfmul " str(a_) "(" mex(b_) ")," mxx(c_) "\n\t" +#undef pam +#define pam(a_,b_,c_) "pfadd " str(a_) "(" mex(b_) ")," mxx(c_) "\n\t" +#undef pl +#define pl(a_,b_,c_) "movq " str(a_) "(" mex(b_) ")," mxx(c_) "\n\t" +#undef pla +#define pla(a_,b_,c_) "movq " str(a_) "(" mex(b_) ")," mxx(c_) "\n\t" +#undef pu +#define pu(a_,b_,c_) "movq " mxx(a_) "," str(b_) "(" mex(c_) ")\n\t" +#undef pc +#define pc(a_,b_) "movq " mxx(a_) "," mxx(b_) "\n\t" +#undef ps +#define ps(a_,b_,c_) "pswapd " mxx(b_) "," mxx(c_) "\n\t" +#undef phl +#define phl(a_,b_) "punpckhdq " mxx(a_) "," mxx(b_) "\n\t" +#undef plh +#define plh(a_,b_) "punpckldq " mxx(a_) "," mxx(b_) "\n\t" +#undef pus +#define pus(a_,b_,c_) "movd " mxx(a_) "," str(b_) "(" mex(c_) ")\n\t" +#undef pls +#define pls(a_,b_,c_) "movd " str(a_) "(" mex(b_) ")," mxx(c_) "\n\t" + +#undef plsx +#define plsx(a_,b_,c_,d_,e_) \ + "movd " str(a_) "(" mex(b_) "," mex(c_) "," #d_ ")," mxx(e_) "\n\t" +#undef plx +#define plx(a_,b_,c_,d_,e_) \ + "movq " str(a_) "(" mex(b_) "," mex(c_) "," #d_ ")," mxx(e_) "\n\t" +#undef pasx +#define pasx(a_,b_,c_,d_,e_) \ + "addss " str(a_) "(" mex(b_) "," mex(c_) "," #d_ ")," mxx(e_) "\n\t" +#undef pusx +#define pusx(a_,b_,c_,d_,e_) \ + "movd " mxx(a_) "," str(b_) "(" mex(c_) "," mex(d_) "," #e_ ")\n\t" +#undef pux +#define pux(a_,b_,c_,d_,e_) \ + "movq " mxx(a_) "," str(b_) "(" mex(c_) "," mex(d_) "," #e_ ")\n\t" +#endif + +#endif /* CAMM_UTIL_H */ diff --git a/kaldi_io/src/tools/ATLAS/include/f77wrap_lapack.h b/kaldi_io/src/tools/ATLAS/include/f77wrap_lapack.h new file mode 100644 index 0000000..89417f7 --- /dev/null +++ b/kaldi_io/src/tools/ATLAS/include/f77wrap_lapack.h @@ -0,0 +1,91 @@ +/* + * Automatically Tuned Linear Algebra Software v3.8.3 + * (C) Copyright 1999 R. Clint Whaley + * + * Code contributers : R. Clint Whaley, Antoine P. Petitet + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the ATLAS group or the names of its contributers may + * not be used to endorse or promote products derived from this + * software without specific written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef F77WRAP_LAPACK_H +#define F77WRAP_LAPACK_H + +#include "atlas_misc.h" +#include "atlas_f77.h" + +#ifdef UpCase + #define PFW Mjoin(ATL_F77WRAP_,PREU) +#else + #define PFW Mjoin(atl_f77wrap_,PRE) +#endif + +#ifdef Add_ + #define F77WRAP_GETRI Mjoin(PFW,getri_) + #define F77WRAP_LAUUM Mjoin(PFW,lauum_) + #define F77WRAP_TRTRI Mjoin(PFW,trtri_) + #define F77WRAP_GETNB Mjoin(PFW,getnb_) + #define F77WRAP_GETRS Mjoin(PFW,getrs_) + #define F77WRAP_GETRF Mjoin(PFW,getrf_) + #define F77WRAP_GESV Mjoin(PFW,gesv_) + #define F77WRAP_POTRS Mjoin(PFW,potrs_) + #define F77WRAP_POTRF Mjoin(PFW,potrf_) + #define F77WRAP_POSV Mjoin(PFW,posv_) +#elif defined(Add__) + #define F77WRAP_GETRI Mjoin(PFW,getri__) + #define F77WRAP_LAUUM Mjoin(PFW,lauum__) + #define F77WRAP_TRTRI Mjoin(PFW,trtri__) + #define F77WRAP_GETNB Mjoin(PFW,getnb__) + #define F77WRAP_GETRS Mjoin(PFW,getrs__) + #define F77WRAP_GETRF Mjoin(PFW,getrf__) + #define F77WRAP_GESV Mjoin(PFW,gesv__) + #define F77WRAP_POTRS Mjoin(PFW,potrs__) + #define F77WRAP_POTRF Mjoin(PFW,potrf__) + #define F77WRAP_POSV Mjoin(PFW,posv__) +#elif defined(NoChange) + #define F77WRAP_GETRI Mjoin(PFW,getri) + #define F77WRAP_LAUUM Mjoin(PFW,lauum) + #define F77WRAP_TRTRI Mjoin(PFW,trtri) + #define F77WRAP_GETNB Mjoin(PFW,getnb) + #define F77WRAP_GETRS Mjoin(PFW,getrs) + #define F77WRAP_GETRF Mjoin(PFW,getrf) + #define F77WRAP_GESV Mjoin(PFW,gesv) + #define F77WRAP_POTRS Mjoin(PFW,potrs) + #define F77WRAP_POTRF Mjoin(PFW,potrf) + #define F77WRAP_POSV Mjoin(PFW,posv) +#elif defined(UpCase) + #define F77WRAP_GETRI Mjoin(PFW,GETRI) + #define F77WRAP_LAUUM Mjoin(PFW,LAUUM) + #define F77WRAP_TRTRI Mjoin(PFW,TRTRI) + #define F77WRAP_GETNB Mjoin(PFW,GETNB) + #define F77WRAP_GETRS Mjoin(PFW,GETRS) + #define F77WRAP_GETRF Mjoin(PFW,GETRF) + #define F77WRAP_GESV Mjoin(PFW,GESV) + #define F77WRAP_POTRS Mjoin(PFW,POTRS) + #define F77WRAP_POTRF Mjoin(PFW,POTRF) + #define F77WRAP_POSV Mjoin(PFW,POSV) +#endif + +#endif diff --git a/kaldi_io/src/tools/openfst/include/fst/accumulator.h b/kaldi_io/src/tools/openfst/include/fst/accumulator.h new file mode 100644 index 0000000..81d1847 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/accumulator.h @@ -0,0 +1,745 @@ +// accumulator.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Classes to accumulate arc weights. Useful for weight lookahead. + +#ifndef FST_LIB_ACCUMULATOR_H__ +#define FST_LIB_ACCUMULATOR_H__ + +#include +#include +#include +using std::tr1::unordered_map; +using std::tr1::unordered_multimap; +#include +using std::vector; + +#include +#include +#include +#include +#include + +namespace fst { + +// This class accumulates arc weights using the semiring Plus(). +template +class DefaultAccumulator { + public: + typedef A Arc; + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + DefaultAccumulator() {} + + DefaultAccumulator(const DefaultAccumulator &acc) {} + + void Init(const Fst& fst, bool copy = false) {} + + void SetState(StateId) {} + + Weight Sum(Weight w, Weight v) { + return Plus(w, v); + } + + template + Weight Sum(Weight w, ArcIterator *aiter, ssize_t begin, + ssize_t end) { + Weight sum = w; + aiter->Seek(begin); + for (ssize_t pos = begin; pos < end; aiter->Next(), ++pos) + sum = Plus(sum, aiter->Value().weight); + return sum; + } + + bool Error() const { return false; } + + private: + void operator=(const DefaultAccumulator &); // Disallow +}; + + +// This class accumulates arc weights using the log semiring Plus() +// assuming an arc weight has a WeightConvert specialization to +// and from log64 weights. +template +class LogAccumulator { + public: + typedef A Arc; + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + LogAccumulator() {} + + LogAccumulator(const LogAccumulator &acc) {} + + void Init(const Fst& fst, bool copy = false) {} + + void SetState(StateId) {} + + Weight Sum(Weight w, Weight v) { + return LogPlus(w, v); + } + + template + Weight Sum(Weight w, ArcIterator *aiter, ssize_t begin, + ssize_t end) { + Weight sum = w; + aiter->Seek(begin); + for (ssize_t pos = begin; pos < end; aiter->Next(), ++pos) + sum = LogPlus(sum, aiter->Value().weight); + return sum; + } + + bool Error() const { return false; } + + private: + double LogPosExp(double x) { return log(1.0F + exp(-x)); } + + Weight LogPlus(Weight w, Weight v) { + double f1 = to_log_weight_(w).Value(); + double f2 = to_log_weight_(v).Value(); + if (f1 > f2) + return to_weight_(f2 - LogPosExp(f1 - f2)); + else + return to_weight_(f1 - LogPosExp(f2 - f1)); + } + + WeightConvert to_log_weight_; + WeightConvert to_weight_; + + void operator=(const LogAccumulator &); // Disallow +}; + + +// Stores shareable data for fast log accumulator copies. +class FastLogAccumulatorData { + public: + FastLogAccumulatorData() {} + + vector *Weights() { return &weights_; } + vector *WeightPositions() { return &weight_positions_; } + double *WeightEnd() { return &(weights_[weights_.size() - 1]); }; + int RefCount() const { return ref_count_.count(); } + int IncrRefCount() { return ref_count_.Incr(); } + int DecrRefCount() { return ref_count_.Decr(); } + + private: + // Cummulative weight per state for all states s.t. # of arcs > + // arc_limit_ with arcs in order. Special first element per state + // being Log64Weight::Zero(); + vector weights_; + // Maps from state to corresponding beginning weight position in + // weights_. Position -1 means no pre-computed weights for that + // state. + vector weight_positions_; + RefCounter ref_count_; // Reference count. + + DISALLOW_COPY_AND_ASSIGN(FastLogAccumulatorData); +}; + + +// This class accumulates arc weights using the log semiring Plus() +// assuming an arc weight has a WeightConvert specialization to and +// from log64 weights. The member function Init(fst) has to be called +// to setup pre-computed weight information. +template +class FastLogAccumulator { + public: + typedef A Arc; + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + explicit FastLogAccumulator(ssize_t arc_limit = 20, ssize_t arc_period = 10) + : arc_limit_(arc_limit), + arc_period_(arc_period), + data_(new FastLogAccumulatorData()), + error_(false) {} + + FastLogAccumulator(const FastLogAccumulator &acc) + : arc_limit_(acc.arc_limit_), + arc_period_(acc.arc_period_), + data_(acc.data_), + error_(acc.error_) { + data_->IncrRefCount(); + } + + ~FastLogAccumulator() { + if (!data_->DecrRefCount()) + delete data_; + } + + void SetState(StateId s) { + vector &weights = *data_->Weights(); + vector &weight_positions = *data_->WeightPositions(); + + if (weight_positions.size() <= s) { + FSTERROR() << "FastLogAccumulator::SetState: invalid state id."; + error_ = true; + return; + } + + ssize_t pos = weight_positions[s]; + if (pos >= 0) + state_weights_ = &(weights[pos]); + else + state_weights_ = 0; + } + + Weight Sum(Weight w, Weight v) { + return LogPlus(w, v); + } + + template + Weight Sum(Weight w, ArcIterator *aiter, ssize_t begin, + ssize_t end) { + if (error_) return Weight::NoWeight(); + Weight sum = w; + // Finds begin and end of pre-stored weights + ssize_t index_begin = -1, index_end = -1; + ssize_t stored_begin = end, stored_end = end; + if (state_weights_ != 0) { + index_begin = begin > 0 ? (begin - 1)/ arc_period_ + 1 : 0; + index_end = end / arc_period_; + stored_begin = index_begin * arc_period_; + stored_end = index_end * arc_period_; + } + // Computes sum before pre-stored weights + if (begin < stored_begin) { + ssize_t pos_end = min(stored_begin, end); + aiter->Seek(begin); + for (ssize_t pos = begin; pos < pos_end; aiter->Next(), ++pos) + sum = LogPlus(sum, aiter->Value().weight); + } + // Computes sum between pre-stored weights + if (stored_begin < stored_end) { + sum = LogPlus(sum, LogMinus(state_weights_[index_end], + state_weights_[index_begin])); + } + // Computes sum after pre-stored weights + if (stored_end < end) { + ssize_t pos_start = max(stored_begin, stored_end); + aiter->Seek(pos_start); + for (ssize_t pos = pos_start; pos < end; aiter->Next(), ++pos) + sum = LogPlus(sum, aiter->Value().weight); + } + return sum; + } + + template + void Init(const F &fst, bool copy = false) { + if (copy) + return; + vector &weights = *data_->Weights(); + vector &weight_positions = *data_->WeightPositions(); + if (!weights.empty() || arc_limit_ < arc_period_) { + FSTERROR() << "FastLogAccumulator: initialization error."; + error_ = true; + return; + } + weight_positions.reserve(CountStates(fst)); + + ssize_t weight_position = 0; + for(StateIterator siter(fst); !siter.Done(); siter.Next()) { + StateId s = siter.Value(); + if (fst.NumArcs(s) >= arc_limit_) { + double sum = FloatLimits::PosInfinity(); + weight_positions.push_back(weight_position); + weights.push_back(sum); + ++weight_position; + ssize_t narcs = 0; + for(ArcIterator aiter(fst, s); !aiter.Done(); aiter.Next()) { + const A &arc = aiter.Value(); + sum = LogPlus(sum, arc.weight); + // Stores cumulative weight distribution per arc_period_. + if (++narcs % arc_period_ == 0) { + weights.push_back(sum); + ++weight_position; + } + } + } else { + weight_positions.push_back(-1); + } + } + } + + bool Error() const { return error_; } + + private: + double LogPosExp(double x) { + return x == FloatLimits::PosInfinity() ? + 0.0 : log(1.0F + exp(-x)); + } + + double LogMinusExp(double x) { + return x == FloatLimits::PosInfinity() ? + 0.0 : log(1.0F - exp(-x)); + } + + Weight LogPlus(Weight w, Weight v) { + double f1 = to_log_weight_(w).Value(); + double f2 = to_log_weight_(v).Value(); + if (f1 > f2) + return to_weight_(f2 - LogPosExp(f1 - f2)); + else + return to_weight_(f1 - LogPosExp(f2 - f1)); + } + + double LogPlus(double f1, Weight v) { + double f2 = to_log_weight_(v).Value(); + if (f1 == FloatLimits::PosInfinity()) + return f2; + else if (f1 > f2) + return f2 - LogPosExp(f1 - f2); + else + return f1 - LogPosExp(f2 - f1); + } + + Weight LogMinus(double f1, double f2) { + if (f1 >= f2) { + FSTERROR() << "FastLogAcumulator::LogMinus: f1 >= f2 with f1 = " << f1 + << " and f2 = " << f2; + error_ = true; + return Weight::NoWeight(); + } + if (f2 == FloatLimits::PosInfinity()) + return to_weight_(f1); + else + return to_weight_(f1 - LogMinusExp(f2 - f1)); + } + + WeightConvert to_log_weight_; + WeightConvert to_weight_; + + ssize_t arc_limit_; // Minimum # of arcs to pre-compute state + ssize_t arc_period_; // Save cumulative weights per 'arc_period_'. + bool init_; // Cumulative weights initialized? + FastLogAccumulatorData *data_; + double *state_weights_; + bool error_; + + void operator=(const FastLogAccumulator &); // Disallow +}; + + +// Stores shareable data for cache log accumulator copies. +// All copies share the same cache. +template +class CacheLogAccumulatorData { + public: + typedef A Arc; + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + CacheLogAccumulatorData(bool gc, size_t gc_limit) + : cache_gc_(gc), cache_limit_(gc_limit), cache_size_(0) {} + + ~CacheLogAccumulatorData() { + for(typename unordered_map::iterator it = cache_.begin(); + it != cache_.end(); + ++it) + delete it->second.weights; + } + + bool CacheDisabled() const { return cache_gc_ && cache_limit_ == 0; } + + vector *GetWeights(StateId s) { + typename unordered_map::iterator it = cache_.find(s); + if (it != cache_.end()) { + it->second.recent = true; + return it->second.weights; + } else { + return 0; + } + } + + void AddWeights(StateId s, vector *weights) { + if (cache_gc_ && cache_size_ >= cache_limit_) + GC(false); + cache_.insert(make_pair(s, CacheState(weights, true))); + if (cache_gc_) + cache_size_ += weights->capacity() * sizeof(double); + } + + int RefCount() const { return ref_count_.count(); } + int IncrRefCount() { return ref_count_.Incr(); } + int DecrRefCount() { return ref_count_.Decr(); } + + private: + // Cached information for a given state. + struct CacheState { + vector* weights; // Accumulated weights for this state. + bool recent; // Has this state been accessed since last GC? + + CacheState(vector *w, bool r) : weights(w), recent(r) {} + }; + + // Garbage collect: Delete from cache states that have not been + // accessed since the last GC ('free_recent = false') until + // 'cache_size_' is 2/3 of 'cache_limit_'. If it does not free enough + // memory, start deleting recently accessed states. + void GC(bool free_recent) { + size_t cache_target = (2 * cache_limit_)/3 + 1; + typename unordered_map::iterator it = cache_.begin(); + while (it != cache_.end() && cache_size_ > cache_target) { + CacheState &cs = it->second; + if (free_recent || !cs.recent) { + cache_size_ -= cs.weights->capacity() * sizeof(double); + delete cs.weights; + cache_.erase(it++); + } else { + cs.recent = false; + ++it; + } + } + if (!free_recent && cache_size_ > cache_target) + GC(true); + } + + unordered_map cache_; // Cache + bool cache_gc_; // Enable garbage collection + size_t cache_limit_; // # of bytes cached + size_t cache_size_; // # of bytes allowed before GC + RefCounter ref_count_; + + DISALLOW_COPY_AND_ASSIGN(CacheLogAccumulatorData); +}; + +// This class accumulates arc weights using the log semiring Plus() +// has a WeightConvert specialization to and from log64 weights. It +// is similar to the FastLogAccumator. However here, the accumulated +// weights are pre-computed and stored only for the states that are +// visited. The member function Init(fst) has to be called to setup +// this accumulator. +template +class CacheLogAccumulator { + public: + typedef A Arc; + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + explicit CacheLogAccumulator(ssize_t arc_limit = 10, bool gc = false, + size_t gc_limit = 10 * 1024 * 1024) + : arc_limit_(arc_limit), fst_(0), data_( + new CacheLogAccumulatorData(gc, gc_limit)), s_(kNoStateId), + error_(false) {} + + CacheLogAccumulator(const CacheLogAccumulator &acc) + : arc_limit_(acc.arc_limit_), fst_(acc.fst_ ? acc.fst_->Copy() : 0), + data_(acc.data_), s_(kNoStateId), error_(acc.error_) { + data_->IncrRefCount(); + } + + ~CacheLogAccumulator() { + if (fst_) + delete fst_; + if (!data_->DecrRefCount()) + delete data_; + } + + // Arg 'arc_limit' specifies minimum # of arcs to pre-compute state. + void Init(const Fst &fst, bool copy = false) { + if (copy) { + delete fst_; + } else if (fst_) { + FSTERROR() << "CacheLogAccumulator: initialization error."; + error_ = true; + return; + } + fst_ = fst.Copy(); + } + + void SetState(StateId s, int depth = 0) { + if (s == s_) + return; + s_ = s; + + if (data_->CacheDisabled() || error_) { + weights_ = 0; + return; + } + + if (!fst_) { + FSTERROR() << "CacheLogAccumulator::SetState: incorrectly initialized."; + error_ = true; + weights_ = 0; + return; + } + + weights_ = data_->GetWeights(s); + if ((weights_ == 0) && (fst_->NumArcs(s) >= arc_limit_)) { + weights_ = new vector; + weights_->reserve(fst_->NumArcs(s) + 1); + weights_->push_back(FloatLimits::PosInfinity()); + data_->AddWeights(s, weights_); + } + } + + Weight Sum(Weight w, Weight v) { + return LogPlus(w, v); + } + + template + Weight Sum(Weight w, Iterator *aiter, ssize_t begin, + ssize_t end) { + if (weights_ == 0) { + Weight sum = w; + aiter->Seek(begin); + for (ssize_t pos = begin; pos < end; aiter->Next(), ++pos) + sum = LogPlus(sum, aiter->Value().weight); + return sum; + } else { + if (weights_->size() <= end) + for (aiter->Seek(weights_->size() - 1); + weights_->size() <= end; + aiter->Next()) + weights_->push_back(LogPlus(weights_->back(), + aiter->Value().weight)); + return LogPlus(w, LogMinus((*weights_)[end], (*weights_)[begin])); + } + } + + template + size_t LowerBound(double w, Iterator *aiter) { + if (weights_ != 0) { + return lower_bound(weights_->begin() + 1, + weights_->end(), + w, + std::greater()) + - weights_->begin() - 1; + } else { + size_t n = 0; + double x = FloatLimits::PosInfinity(); + for(aiter->Reset(); !aiter->Done(); aiter->Next(), ++n) { + x = LogPlus(x, aiter->Value().weight); + if (x < w) break; + } + return n; + } + } + + bool Error() const { return error_; } + + private: + double LogPosExp(double x) { + return x == FloatLimits::PosInfinity() ? + 0.0 : log(1.0F + exp(-x)); + } + + double LogMinusExp(double x) { + return x == FloatLimits::PosInfinity() ? + 0.0 : log(1.0F - exp(-x)); + } + + Weight LogPlus(Weight w, Weight v) { + double f1 = to_log_weight_(w).Value(); + double f2 = to_log_weight_(v).Value(); + if (f1 > f2) + return to_weight_(f2 - LogPosExp(f1 - f2)); + else + return to_weight_(f1 - LogPosExp(f2 - f1)); + } + + double LogPlus(double f1, Weight v) { + double f2 = to_log_weight_(v).Value(); + if (f1 == FloatLimits::PosInfinity()) + return f2; + else if (f1 > f2) + return f2 - LogPosExp(f1 - f2); + else + return f1 - LogPosExp(f2 - f1); + } + + Weight LogMinus(double f1, double f2) { + if (f1 >= f2) { + FSTERROR() << "CacheLogAcumulator::LogMinus: f1 >= f2 with f1 = " << f1 + << " and f2 = " << f2; + error_ = true; + return Weight::NoWeight(); + } + if (f2 == FloatLimits::PosInfinity()) + return to_weight_(f1); + else + return to_weight_(f1 - LogMinusExp(f2 - f1)); + } + + WeightConvert to_log_weight_; + WeightConvert to_weight_; + + ssize_t arc_limit_; // Minimum # of arcs to cache a state + vector *weights_; // Accumulated weights for cur. state + const Fst* fst_; // Input fst + CacheLogAccumulatorData *data_; // Cache data + StateId s_; // Current state + bool error_; + + void operator=(const CacheLogAccumulator &); // Disallow +}; + + +// Stores shareable data for replace accumulator copies. +template +class ReplaceAccumulatorData { + public: + typedef typename Accumulator::Arc Arc; + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef T StateTable; + typedef typename T::StateTuple StateTuple; + + ReplaceAccumulatorData() : state_table_(0) {} + + ReplaceAccumulatorData(const vector &accumulators) + : state_table_(0), accumulators_(accumulators) {} + + ~ReplaceAccumulatorData() { + for (size_t i = 0; i < fst_array_.size(); ++i) + delete fst_array_[i]; + for (size_t i = 0; i < accumulators_.size(); ++i) + delete accumulators_[i]; + } + + void Init(const vector*> > &fst_tuples, + const StateTable *state_table) { + state_table_ = state_table; + accumulators_.resize(fst_tuples.size()); + for (size_t i = 0; i < accumulators_.size(); ++i) { + if (!accumulators_[i]) + accumulators_[i] = new Accumulator; + accumulators_[i]->Init(*(fst_tuples[i].second)); + fst_array_.push_back(fst_tuples[i].second->Copy()); + } + } + + const StateTuple &GetTuple(StateId s) const { + return state_table_->Tuple(s); + } + + Accumulator *GetAccumulator(size_t i) { return accumulators_[i]; } + + const Fst *GetFst(size_t i) const { return fst_array_[i]; } + + int RefCount() const { return ref_count_.count(); } + int IncrRefCount() { return ref_count_.Incr(); } + int DecrRefCount() { return ref_count_.Decr(); } + + private: + const T * state_table_; + vector accumulators_; + vector*> fst_array_; + RefCounter ref_count_; + + DISALLOW_COPY_AND_ASSIGN(ReplaceAccumulatorData); +}; + +// This class accumulates weights in a ReplaceFst. The 'Init' method +// takes as input the argument used to build the ReplaceFst and the +// ReplaceFst state table. It uses accumulators of type 'Accumulator' +// in the underlying FSTs. +template > +class ReplaceAccumulator { + public: + typedef typename Accumulator::Arc Arc; + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + typedef T StateTable; + typedef typename T::StateTuple StateTuple; + + ReplaceAccumulator() + : init_(false), data_(new ReplaceAccumulatorData()), + error_(false) {} + + ReplaceAccumulator(const vector &accumulators) + : init_(false), + data_(new ReplaceAccumulatorData(accumulators)), + error_(false) {} + + ReplaceAccumulator(const ReplaceAccumulator &acc) + : init_(acc.init_), data_(acc.data_), error_(acc.error_) { + if (!init_) + FSTERROR() << "ReplaceAccumulator: can't copy unintialized accumulator"; + data_->IncrRefCount(); + } + + ~ReplaceAccumulator() { + if (!data_->DecrRefCount()) + delete data_; + } + + // Does not take ownership of the state table, the state table + // is own by the ReplaceFst + void Init(const vector*> > &fst_tuples, + const StateTable *state_table) { + init_ = true; + data_->Init(fst_tuples, state_table); + } + + void SetState(StateId s) { + if (!init_) { + FSTERROR() << "ReplaceAccumulator::SetState: incorrectly initialized."; + error_ = true; + return; + } + StateTuple tuple = data_->GetTuple(s); + fst_id_ = tuple.fst_id - 1; // Replace FST ID is 1-based + data_->GetAccumulator(fst_id_)->SetState(tuple.fst_state); + if ((tuple.prefix_id != 0) && + (data_->GetFst(fst_id_)->Final(tuple.fst_state) != Weight::Zero())) { + offset_ = 1; + offset_weight_ = data_->GetFst(fst_id_)->Final(tuple.fst_state); + } else { + offset_ = 0; + offset_weight_ = Weight::Zero(); + } + } + + Weight Sum(Weight w, Weight v) { + if (error_) return Weight::NoWeight(); + return data_->GetAccumulator(fst_id_)->Sum(w, v); + } + + template + Weight Sum(Weight w, ArcIterator *aiter, ssize_t begin, + ssize_t end) { + if (error_) return Weight::NoWeight(); + Weight sum = begin == end ? Weight::Zero() + : data_->GetAccumulator(fst_id_)->Sum( + w, aiter, begin ? begin - offset_ : 0, end - offset_); + if (begin == 0 && end != 0 && offset_ > 0) + sum = Sum(offset_weight_, sum); + return sum; + } + + bool Error() const { return error_; } + + private: + bool init_; + ReplaceAccumulatorData *data_; + Label fst_id_; + size_t offset_; + Weight offset_weight_; + bool error_; + + void operator=(const ReplaceAccumulator &); // Disallow +}; + +} // namespace fst + +#endif // FST_LIB_ACCUMULATOR_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/add-on.h b/kaldi_io/src/tools/openfst/include/fst/add-on.h new file mode 100644 index 0000000..ee21a93 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/add-on.h @@ -0,0 +1,306 @@ +// add-on.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Fst implementation class to attach an arbitrary object with a +// read/write method to an FST and its file rep. The FST is given a +// new type name. + +#ifndef FST_LIB_ADD_ON_FST_H__ +#define FST_LIB_ADD_ON_FST_H__ + +#include +#include + +#include + + +namespace fst { + +// Identifies stream data as an add-on fst. +static const int32 kAddOnMagicNumber = 446681434; + + +// +// Some useful add-on objects. +// + +// Nothing to save. +class NullAddOn { + public: + NullAddOn() {} + + static NullAddOn *Read(istream &istrm) { + return new NullAddOn(); + }; + + bool Write(ostream &ostrm) const { return true; } + + int RefCount() const { return ref_count_.count(); } + int IncrRefCount() { return ref_count_.Incr(); } + int DecrRefCount() { return ref_count_.Decr(); } + + private: + RefCounter ref_count_; + + DISALLOW_COPY_AND_ASSIGN(NullAddOn); +}; + + +// Create a new add-on from a pair of add-ons. +template +class AddOnPair { + public: + // Argument reference count incremented. + AddOnPair(A1 *a1, A2 *a2) + : a1_(a1), a2_(a2) { + if (a1_) + a1_->IncrRefCount(); + if (a2_) + a2_->IncrRefCount(); + } + + ~AddOnPair() { + if (a1_ && !a1_->DecrRefCount()) + delete a1_; + if (a2_ && !a2_->DecrRefCount()) + delete a2_; + } + + A1 *First() const { return a1_; } + A2 *Second() const { return a2_; } + + static AddOnPair *Read(istream &istrm) { + A1 *a1 = 0; + bool have_addon1 = false; + ReadType(istrm, &have_addon1); + if (have_addon1) + a1 = A1::Read(istrm); + + A2 *a2 = 0; + bool have_addon2 = false; + ReadType(istrm, &have_addon2); + if (have_addon2) + a2 = A2::Read(istrm); + + AddOnPair *a = new AddOnPair(a1, a2); + if (a1) + a1->DecrRefCount(); + if (a2) + a2->DecrRefCount(); + return a; + }; + + bool Write(ostream &ostrm) const { + bool have_addon1 = a1_; + WriteType(ostrm, have_addon1); + if (have_addon1) + a1_->Write(ostrm); + bool have_addon2 = a2_; + WriteType(ostrm, have_addon2); + if (have_addon2) + a2_->Write(ostrm); + return true; + } + + int RefCount() const { return ref_count_.count(); } + + int IncrRefCount() { + return ref_count_.Incr(); + } + + int DecrRefCount() { + return ref_count_.Decr(); + } + + private: + A1 *a1_; + A2 *a2_; + RefCounter ref_count_; + + DISALLOW_COPY_AND_ASSIGN(AddOnPair); +}; + + +// Add to an Fst F a type T object. T must have a 'T* Read(istream &)', +// a 'bool Write(ostream &)' method, and 'int RecCount(), 'int IncrRefCount()' +// and 'int DecrRefCount()' methods (e.g. 'MatcherData' in matcher-fst.h). +// The result is a new Fst implemenation with type name 'type'. +template +class AddOnImpl : public FstImpl { + public: + typedef typename F::Arc Arc; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + typedef typename Arc::StateId StateId; + + using FstImpl::SetType; + using FstImpl::SetProperties; + using FstImpl::WriteHeader; + + // If 't' is non-zero, its reference count is incremented. + AddOnImpl(const F &fst, const string &type, T *t = 0) + : fst_(fst), t_(t) { + SetType(type); + SetProperties(fst_.Properties(kFstProperties, false)); + if (t_) + t_->IncrRefCount(); + } + + // If 't' is non-zero, its reference count is incremented. + AddOnImpl(const Fst &fst, const string &type, T *t = 0) + : fst_(fst), t_(t) { + SetType(type); + SetProperties(fst_.Properties(kFstProperties, false)); + if (t_) + t_->IncrRefCount(); + } + + AddOnImpl(const AddOnImpl &impl) + : fst_(impl.fst_), t_(impl.t_) { + SetType(impl.Type()); + SetProperties(fst_.Properties(kCopyProperties, false)); + if (t_) + t_->IncrRefCount(); + } + + ~AddOnImpl() { + if (t_ && !t_->DecrRefCount()) + delete t_; + } + + StateId Start() const { return fst_.Start(); } + Weight Final(StateId s) const { return fst_.Final(s); } + size_t NumArcs(StateId s) const { return fst_.NumArcs(s); } + + size_t NumInputEpsilons(StateId s) const { + return fst_.NumInputEpsilons(s); + } + + size_t NumOutputEpsilons(StateId s) const { + return fst_.NumOutputEpsilons(s); + } + + size_t NumStates() const { return fst_.NumStates(); } + + static AddOnImpl *Read(istream &strm, const FstReadOptions &opts) { + FstReadOptions nopts(opts); + FstHeader hdr; + if (!nopts.header) { + hdr.Read(strm, nopts.source); + nopts.header = &hdr; + } + AddOnImpl *impl = new AddOnImpl(nopts.header->FstType()); + if (!impl->ReadHeader(strm, nopts, kMinFileVersion, &hdr)) + return 0; + delete impl; // Used here only for checking types. + + int32 magic_number = 0; + ReadType(strm, &magic_number); // Ensures this is an add-on Fst. + if (magic_number != kAddOnMagicNumber) { + LOG(ERROR) << "AddOnImpl::Read: Bad add-on header: " << nopts.source; + return 0; + } + + FstReadOptions fopts(opts); + fopts.header = 0; // Contained header was written out. + F *fst = F::Read(strm, fopts); + if (!fst) + return 0; + + T *t = 0; + bool have_addon = false; + ReadType(strm, &have_addon); + if (have_addon) { // Read add-on object if present. + t = T::Read(strm); + if (!t) + return 0; + } + impl = new AddOnImpl(*fst, nopts.header->FstType(), t); + delete fst; + if (t) + t->DecrRefCount(); + return impl; + } + + bool Write(ostream &strm, const FstWriteOptions &opts) const { + FstHeader hdr; + FstWriteOptions nopts(opts); + nopts.write_isymbols = false; // Let contained FST hold any symbols. + nopts.write_osymbols = false; + WriteHeader(strm, nopts, kFileVersion, &hdr); + WriteType(strm, kAddOnMagicNumber); // Ensures this is an add-on Fst. + FstWriteOptions fopts(opts); + fopts.write_header = true; // Force writing contained header. + if (!fst_.Write(strm, fopts)) + return false; + bool have_addon = t_; + WriteType(strm, have_addon); + if (have_addon) // Write add-on object if present. + t_->Write(strm); + return true; + } + + void InitStateIterator(StateIteratorData *data) const { + fst_.InitStateIterator(data); + } + + void InitArcIterator(StateId s, ArcIteratorData *data) const { + fst_.InitArcIterator(s, data); + } + + F &GetFst() { return fst_; } + + const F &GetFst() const { return fst_; } + + T *GetAddOn() const { return t_; } + + // If 't' is non-zero, its reference count is incremented. + void SetAddOn(T *t) { + if (t == t_) + return; + if (t_ && !t_->DecrRefCount()) + delete t_; + t_ = t; + if (t_) + t_->IncrRefCount(); + } + + private: + explicit AddOnImpl(const string &type) : t_(0) { + SetType(type); + SetProperties(kExpanded); + } + + // Current file format version + static const int kFileVersion = 1; + // Minimum file format version supported + static const int kMinFileVersion = 1; + + F fst_; + T *t_; + + void operator=(const AddOnImpl &fst); // Disallow +}; + +template const int AddOnImpl::kFileVersion; +template const int AddOnImpl::kMinFileVersion; + + +} // namespace fst + +#endif // FST_LIB_ADD_ON_FST_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/arc-map.h b/kaldi_io/src/tools/openfst/include/fst/arc-map.h new file mode 100644 index 0000000..914f81c --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/arc-map.h @@ -0,0 +1,1146 @@ +// arc-map.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Class to map over/transform arcs e.g., change semirings or +// implement project/invert. Consider using when operation does +// not change the number of arcs (except possibly superfinal arcs). + +#ifndef FST_LIB_ARC_MAP_H__ +#define FST_LIB_ARC_MAP_H__ + +#include +using std::tr1::unordered_map; +using std::tr1::unordered_multimap; +#include +#include +using std::pair; using std::make_pair; + +#include +#include + + +namespace fst { + +// This determines how final weights are mapped. +enum MapFinalAction { + // A final weight is mapped into a final weight. An error + // is raised if this is not possible. + MAP_NO_SUPERFINAL, + + // A final weight is mapped to an arc to the superfinal state + // when the result cannot be represented as a final weight. + // The superfinal state will be added only if it is needed. + MAP_ALLOW_SUPERFINAL, + + // A final weight is mapped to an arc to the superfinal state + // unless the result can be represented as a final weight of weight + // Zero(). The superfinal state is always added (if the input is + // not the empty Fst). + MAP_REQUIRE_SUPERFINAL +}; + +// This determines how symbol tables are mapped. +enum MapSymbolsAction { + // Symbols should be cleared in the result by the map. + MAP_CLEAR_SYMBOLS, + + // Symbols should be copied from the input FST by the map. + MAP_COPY_SYMBOLS, + + // Symbols should not be modified in the result by the map itself. + // (They may set by the mapper). + MAP_NOOP_SYMBOLS +}; + +// ArcMapper Interface - class determinies how arcs and final weights +// are mapped. Useful for implementing operations that do not change +// the number of arcs (expect possibly superfinal arcs). +// +// class ArcMapper { +// public: +// typedef A FromArc; +// typedef B ToArc; +// +// // Maps an arc type A to arc type B. +// B operator()(const A &arc); +// // Specifies final action the mapper requires (see above). +// // The mapper will be passed final weights as arcs of the +// // form A(0, 0, weight, kNoStateId). +// MapFinalAction FinalAction() const; +// // Specifies input symbol table action the mapper requires (see above). +// MapSymbolsAction InputSymbolsAction() const; +// // Specifies output symbol table action the mapper requires (see above). +// MapSymbolsAction OutputSymbolsAction() const; +// // This specifies the known properties of an Fst mapped by this +// // mapper. It takes as argument the input Fst's known properties. +// uint64 Properties(uint64 props) const; +// }; +// +// The ArcMap functions and classes below will use the FinalAction() +// method of the mapper to determine how to treat final weights, +// e.g. whether to add a superfinal state. They will use the Properties() +// method to set the result Fst properties. +// +// We include a various map versions below. One dimension of +// variation is whether the mapping mutates its input, writes to a +// new result Fst, or is an on-the-fly Fst. Another dimension is how +// we pass the mapper. We allow passing the mapper by pointer +// for cases that we need to change the state of the user's mapper. +// This is the case with the encode mapper, which is reused during +// decoding. We also include map versions that pass the mapper +// by value or const reference when this suffices. + + +// Maps an arc type A using a mapper function object C, passed +// by pointer. This version modifies its Fst input. +template +void ArcMap(MutableFst *fst, C* mapper) { + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + if (mapper->InputSymbolsAction() == MAP_CLEAR_SYMBOLS) + fst->SetInputSymbols(0); + + if (mapper->OutputSymbolsAction() == MAP_CLEAR_SYMBOLS) + fst->SetOutputSymbols(0); + + if (fst->Start() == kNoStateId) + return; + + uint64 props = fst->Properties(kFstProperties, false); + + MapFinalAction final_action = mapper->FinalAction(); + StateId superfinal = kNoStateId; + if (final_action == MAP_REQUIRE_SUPERFINAL) { + superfinal = fst->AddState(); + fst->SetFinal(superfinal, Weight::One()); + } + + for (StateId s = 0; s < fst->NumStates(); ++s) { + for (MutableArcIterator< MutableFst > aiter(fst, s); + !aiter.Done(); aiter.Next()) { + const A &arc = aiter.Value(); + aiter.SetValue((*mapper)(arc)); + } + + switch (final_action) { + case MAP_NO_SUPERFINAL: + default: { + A final_arc = (*mapper)(A(0, 0, fst->Final(s), kNoStateId)); + if (final_arc.ilabel != 0 || final_arc.olabel != 0) { + FSTERROR() << "ArcMap: non-zero arc labels for superfinal arc"; + fst->SetProperties(kError, kError); + } + + fst->SetFinal(s, final_arc.weight); + break; + } + case MAP_ALLOW_SUPERFINAL: { + if (s != superfinal) { + A final_arc = (*mapper)(A(0, 0, fst->Final(s), kNoStateId)); + if (final_arc.ilabel != 0 || final_arc.olabel != 0) { + // Add a superfinal state if not already done. + if (superfinal == kNoStateId) { + superfinal = fst->AddState(); + fst->SetFinal(superfinal, Weight::One()); + } + final_arc.nextstate = superfinal; + fst->AddArc(s, final_arc); + fst->SetFinal(s, Weight::Zero()); + } else { + fst->SetFinal(s, final_arc.weight); + } + break; + } + } + case MAP_REQUIRE_SUPERFINAL: { + if (s != superfinal) { + A final_arc = (*mapper)(A(0, 0, fst->Final(s), kNoStateId)); + if (final_arc.ilabel != 0 || final_arc.olabel != 0 || + final_arc.weight != Weight::Zero()) + fst->AddArc(s, A(final_arc.ilabel, final_arc.olabel, + final_arc.weight, superfinal)); + fst->SetFinal(s, Weight::Zero()); + } + break; + } + } + } + fst->SetProperties(mapper->Properties(props), kFstProperties); +} + + +// Maps an arc type A using a mapper function object C, passed +// by value. This version modifies its Fst input. +template +void ArcMap(MutableFst *fst, C mapper) { + ArcMap(fst, &mapper); +} + + +// Maps an arc type A to an arc type B using mapper function +// object C, passed by pointer. This version writes the mapped +// input Fst to an output MutableFst. +template +void ArcMap(const Fst &ifst, MutableFst *ofst, C* mapper) { + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + ofst->DeleteStates(); + + if (mapper->InputSymbolsAction() == MAP_COPY_SYMBOLS) + ofst->SetInputSymbols(ifst.InputSymbols()); + else if (mapper->InputSymbolsAction() == MAP_CLEAR_SYMBOLS) + ofst->SetInputSymbols(0); + + if (mapper->OutputSymbolsAction() == MAP_COPY_SYMBOLS) + ofst->SetOutputSymbols(ifst.OutputSymbols()); + else if (mapper->OutputSymbolsAction() == MAP_CLEAR_SYMBOLS) + ofst->SetOutputSymbols(0); + + uint64 iprops = ifst.Properties(kCopyProperties, false); + + if (ifst.Start() == kNoStateId) { + if (iprops & kError) ofst->SetProperties(kError, kError); + return; + } + + MapFinalAction final_action = mapper->FinalAction(); + if (ifst.Properties(kExpanded, false)) { + ofst->ReserveStates(CountStates(ifst) + + final_action == MAP_NO_SUPERFINAL ? 0 : 1); + } + + // Add all states. + for (StateIterator< Fst > siter(ifst); !siter.Done(); siter.Next()) + ofst->AddState(); + + StateId superfinal = kNoStateId; + if (final_action == MAP_REQUIRE_SUPERFINAL) { + superfinal = ofst->AddState(); + ofst->SetFinal(superfinal, B::Weight::One()); + } + for (StateIterator< Fst > siter(ifst); !siter.Done(); siter.Next()) { + StateId s = siter.Value(); + if (s == ifst.Start()) + ofst->SetStart(s); + + ofst->ReserveArcs(s, ifst.NumArcs(s)); + for (ArcIterator< Fst > aiter(ifst, s); !aiter.Done(); aiter.Next()) + ofst->AddArc(s, (*mapper)(aiter.Value())); + + switch (final_action) { + case MAP_NO_SUPERFINAL: + default: { + B final_arc = (*mapper)(A(0, 0, ifst.Final(s), kNoStateId)); + if (final_arc.ilabel != 0 || final_arc.olabel != 0) { + FSTERROR() << "ArcMap: non-zero arc labels for superfinal arc"; + ofst->SetProperties(kError, kError); + } + ofst->SetFinal(s, final_arc.weight); + break; + } + case MAP_ALLOW_SUPERFINAL: { + B final_arc = (*mapper)(A(0, 0, ifst.Final(s), kNoStateId)); + if (final_arc.ilabel != 0 || final_arc.olabel != 0) { + // Add a superfinal state if not already done. + if (superfinal == kNoStateId) { + superfinal = ofst->AddState(); + ofst->SetFinal(superfinal, B::Weight::One()); + } + final_arc.nextstate = superfinal; + ofst->AddArc(s, final_arc); + ofst->SetFinal(s, B::Weight::Zero()); + } else { + ofst->SetFinal(s, final_arc.weight); + } + break; + } + case MAP_REQUIRE_SUPERFINAL: { + B final_arc = (*mapper)(A(0, 0, ifst.Final(s), kNoStateId)); + if (final_arc.ilabel != 0 || final_arc.olabel != 0 || + final_arc.weight != B::Weight::Zero()) + ofst->AddArc(s, B(final_arc.ilabel, final_arc.olabel, + final_arc.weight, superfinal)); + ofst->SetFinal(s, B::Weight::Zero()); + break; + } + } + } + uint64 oprops = ofst->Properties(kFstProperties, false); + ofst->SetProperties(mapper->Properties(iprops) | oprops, kFstProperties); +} + +// Maps an arc type A to an arc type B using mapper function +// object C, passed by value. This version writes the mapped input +// Fst to an output MutableFst. +template +void ArcMap(const Fst &ifst, MutableFst *ofst, C mapper) { + ArcMap(ifst, ofst, &mapper); +} + + +struct ArcMapFstOptions : public CacheOptions { + // ArcMapFst default caching behaviour is to do no caching. Most + // mappers are cheap and therefore we save memory by not doing + // caching. + ArcMapFstOptions() : CacheOptions(true, 0) {} + ArcMapFstOptions(const CacheOptions& opts) : CacheOptions(opts) {} +}; + + +template class ArcMapFst; + +// Implementation of delayed ArcMapFst. +template +class ArcMapFstImpl : public CacheImpl { + public: + using FstImpl::SetType; + using FstImpl::SetProperties; + using FstImpl::SetInputSymbols; + using FstImpl::SetOutputSymbols; + + using VectorFstBaseImpl::State>::NumStates; + + using CacheImpl::PushArc; + using CacheImpl::HasArcs; + using CacheImpl::HasFinal; + using CacheImpl::HasStart; + using CacheImpl::SetArcs; + using CacheImpl::SetFinal; + using CacheImpl::SetStart; + + friend class StateIterator< ArcMapFst >; + + typedef B Arc; + typedef typename B::Weight Weight; + typedef typename B::StateId StateId; + + ArcMapFstImpl(const Fst &fst, const C &mapper, + const ArcMapFstOptions& opts) + : CacheImpl(opts), + fst_(fst.Copy()), + mapper_(new C(mapper)), + own_mapper_(true), + superfinal_(kNoStateId), + nstates_(0) { + Init(); + } + + ArcMapFstImpl(const Fst &fst, C *mapper, + const ArcMapFstOptions& opts) + : CacheImpl(opts), + fst_(fst.Copy()), + mapper_(mapper), + own_mapper_(false), + superfinal_(kNoStateId), + nstates_(0) { + Init(); + } + + ArcMapFstImpl(const ArcMapFstImpl &impl) + : CacheImpl(impl), + fst_(impl.fst_->Copy(true)), + mapper_(new C(*impl.mapper_)), + own_mapper_(true), + superfinal_(kNoStateId), + nstates_(0) { + Init(); + } + + ~ArcMapFstImpl() { + delete fst_; + if (own_mapper_) delete mapper_; + } + + StateId Start() { + if (!HasStart()) + SetStart(FindOState(fst_->Start())); + return CacheImpl::Start(); + } + + Weight Final(StateId s) { + if (!HasFinal(s)) { + switch (final_action_) { + case MAP_NO_SUPERFINAL: + default: { + B final_arc = (*mapper_)(A(0, 0, fst_->Final(FindIState(s)), + kNoStateId)); + if (final_arc.ilabel != 0 || final_arc.olabel != 0) { + FSTERROR() << "ArcMapFst: non-zero arc labels for superfinal arc"; + SetProperties(kError, kError); + } + SetFinal(s, final_arc.weight); + break; + } + case MAP_ALLOW_SUPERFINAL: { + if (s == superfinal_) { + SetFinal(s, Weight::One()); + } else { + B final_arc = (*mapper_)(A(0, 0, fst_->Final(FindIState(s)), + kNoStateId)); + if (final_arc.ilabel == 0 && final_arc.olabel == 0) + SetFinal(s, final_arc.weight); + else + SetFinal(s, Weight::Zero()); + } + break; + } + case MAP_REQUIRE_SUPERFINAL: { + SetFinal(s, s == superfinal_ ? Weight::One() : Weight::Zero()); + break; + } + } + } + return CacheImpl::Final(s); + } + + size_t NumArcs(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumArcs(s); + } + + size_t NumInputEpsilons(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumInputEpsilons(s); + } + + size_t NumOutputEpsilons(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumOutputEpsilons(s); + } + + uint64 Properties() const { return Properties(kFstProperties); } + + // Set error if found; return FST impl properties. + uint64 Properties(uint64 mask) const { + if ((mask & kError) && (fst_->Properties(kError, false) || + (mapper_->Properties(0) & kError))) + SetProperties(kError, kError); + return FstImpl::Properties(mask); + } + + void InitArcIterator(StateId s, ArcIteratorData *data) { + if (!HasArcs(s)) + Expand(s); + CacheImpl::InitArcIterator(s, data); + } + + void Expand(StateId s) { + // Add exiting arcs. + if (s == superfinal_) { SetArcs(s); return; } + + for (ArcIterator< Fst > aiter(*fst_, FindIState(s)); + !aiter.Done(); aiter.Next()) { + A aarc(aiter.Value()); + aarc.nextstate = FindOState(aarc.nextstate); + const B& barc = (*mapper_)(aarc); + PushArc(s, barc); + } + + // Check for superfinal arcs. + if (!HasFinal(s) || Final(s) == Weight::Zero()) + switch (final_action_) { + case MAP_NO_SUPERFINAL: + default: + break; + case MAP_ALLOW_SUPERFINAL: { + B final_arc = (*mapper_)(A(0, 0, fst_->Final(FindIState(s)), + kNoStateId)); + if (final_arc.ilabel != 0 || final_arc.olabel != 0) { + if (superfinal_ == kNoStateId) + superfinal_ = nstates_++; + final_arc.nextstate = superfinal_; + PushArc(s, final_arc); + } + break; + } + case MAP_REQUIRE_SUPERFINAL: { + B final_arc = (*mapper_)(A(0, 0, fst_->Final(FindIState(s)), + kNoStateId)); + if (final_arc.ilabel != 0 || final_arc.olabel != 0 || + final_arc.weight != B::Weight::Zero()) + PushArc(s, B(final_arc.ilabel, final_arc.olabel, + final_arc.weight, superfinal_)); + break; + } + } + SetArcs(s); + } + + private: + void Init() { + SetType("map"); + + if (mapper_->InputSymbolsAction() == MAP_COPY_SYMBOLS) + SetInputSymbols(fst_->InputSymbols()); + else if (mapper_->InputSymbolsAction() == MAP_CLEAR_SYMBOLS) + SetInputSymbols(0); + + if (mapper_->OutputSymbolsAction() == MAP_COPY_SYMBOLS) + SetOutputSymbols(fst_->OutputSymbols()); + else if (mapper_->OutputSymbolsAction() == MAP_CLEAR_SYMBOLS) + SetOutputSymbols(0); + + if (fst_->Start() == kNoStateId) { + final_action_ = MAP_NO_SUPERFINAL; + SetProperties(kNullProperties); + } else { + final_action_ = mapper_->FinalAction(); + uint64 props = fst_->Properties(kCopyProperties, false); + SetProperties(mapper_->Properties(props)); + if (final_action_ == MAP_REQUIRE_SUPERFINAL) + superfinal_ = 0; + } + } + + // Maps from output state to input state. + StateId FindIState(StateId s) { + if (superfinal_ == kNoStateId || s < superfinal_) + return s; + else + return s - 1; + } + + // Maps from input state to output state. + StateId FindOState(StateId is) { + StateId os; + if (superfinal_ == kNoStateId || is < superfinal_) + os = is; + else + os = is + 1; + + if (os >= nstates_) + nstates_ = os + 1; + + return os; + } + + + const Fst *fst_; + C* mapper_; + bool own_mapper_; + MapFinalAction final_action_; + + StateId superfinal_; + StateId nstates_; + + void operator=(const ArcMapFstImpl &); // disallow +}; + + +// Maps an arc type A to an arc type B using Mapper function object +// C. This version is a delayed Fst. +template +class ArcMapFst : public ImplToFst< ArcMapFstImpl > { + public: + friend class ArcIterator< ArcMapFst >; + friend class StateIterator< ArcMapFst >; + + typedef B Arc; + typedef typename B::Weight Weight; + typedef typename B::StateId StateId; + typedef CacheState State; + typedef ArcMapFstImpl Impl; + + ArcMapFst(const Fst &fst, const C &mapper, const ArcMapFstOptions& opts) + : ImplToFst(new Impl(fst, mapper, opts)) {} + + ArcMapFst(const Fst &fst, C* mapper, const ArcMapFstOptions& opts) + : ImplToFst(new Impl(fst, mapper, opts)) {} + + ArcMapFst(const Fst &fst, const C &mapper) + : ImplToFst(new Impl(fst, mapper, ArcMapFstOptions())) {} + + ArcMapFst(const Fst &fst, C* mapper) + : ImplToFst(new Impl(fst, mapper, ArcMapFstOptions())) {} + + // See Fst<>::Copy() for doc. + ArcMapFst(const ArcMapFst &fst, bool safe = false) + : ImplToFst(fst, safe) {} + + // Get a copy of this ArcMapFst. See Fst<>::Copy() for further doc. + virtual ArcMapFst *Copy(bool safe = false) const { + return new ArcMapFst(*this, safe); + } + + virtual inline void InitStateIterator(StateIteratorData *data) const; + + virtual void InitArcIterator(StateId s, ArcIteratorData *data) const { + GetImpl()->InitArcIterator(s, data); + } + + private: + // Makes visible to friends. + Impl *GetImpl() const { return ImplToFst::GetImpl(); } + + void operator=(const ArcMapFst &fst); // disallow +}; + + +// Specialization for ArcMapFst. +template +class StateIterator< ArcMapFst > : public StateIteratorBase { + public: + typedef typename B::StateId StateId; + + explicit StateIterator(const ArcMapFst &fst) + : impl_(fst.GetImpl()), siter_(*impl_->fst_), s_(0), + superfinal_(impl_->final_action_ == MAP_REQUIRE_SUPERFINAL) + { CheckSuperfinal(); } + + bool Done() const { return siter_.Done() && !superfinal_; } + + StateId Value() const { return s_; } + + void Next() { + ++s_; + if (!siter_.Done()) { + siter_.Next(); + CheckSuperfinal(); + } + else if (superfinal_) + superfinal_ = false; + } + + void Reset() { + s_ = 0; + siter_.Reset(); + superfinal_ = impl_->final_action_ == MAP_REQUIRE_SUPERFINAL; + CheckSuperfinal(); + } + + private: + // This allows base-class virtual access to non-virtual derived- + // class members of the same name. It makes the derived class more + // efficient to use but unsafe to further derive. + bool Done_() const { return Done(); } + StateId Value_() const { return Value(); } + void Next_() { Next(); } + void Reset_() { Reset(); } + + void CheckSuperfinal() { + if (impl_->final_action_ != MAP_ALLOW_SUPERFINAL || superfinal_) + return; + if (!siter_.Done()) { + B final_arc = (*impl_->mapper_)(A(0, 0, impl_->fst_->Final(s_), + kNoStateId)); + if (final_arc.ilabel != 0 || final_arc.olabel != 0) + superfinal_ = true; + } + } + + const ArcMapFstImpl *impl_; + StateIterator< Fst > siter_; + StateId s_; + bool superfinal_; // true if there is a superfinal state and not done + + DISALLOW_COPY_AND_ASSIGN(StateIterator); +}; + + +// Specialization for ArcMapFst. +template +class ArcIterator< ArcMapFst > + : public CacheArcIterator< ArcMapFst > { + public: + typedef typename A::StateId StateId; + + ArcIterator(const ArcMapFst &fst, StateId s) + : CacheArcIterator< ArcMapFst >(fst.GetImpl(), s) { + if (!fst.GetImpl()->HasArcs(s)) + fst.GetImpl()->Expand(s); + } + + private: + DISALLOW_COPY_AND_ASSIGN(ArcIterator); +}; + +template inline +void ArcMapFst::InitStateIterator(StateIteratorData *data) + const { + data->base = new StateIterator< ArcMapFst >(*this); +} + + +// +// Utility Mappers +// + +// Mapper that returns its input. +template +struct IdentityArcMapper { + typedef A FromArc; + typedef A ToArc; + + A operator()(const A &arc) const { return arc; } + + MapFinalAction FinalAction() const { return MAP_NO_SUPERFINAL; } + + MapSymbolsAction InputSymbolsAction() const { return MAP_COPY_SYMBOLS; } + + MapSymbolsAction OutputSymbolsAction() const { return MAP_COPY_SYMBOLS;} + + uint64 Properties(uint64 props) const { return props; } +}; + + +// Mapper that returns its input with final states redirected to +// a single super-final state. +template +struct SuperFinalMapper { + typedef A FromArc; + typedef A ToArc; + + A operator()(const A &arc) const { return arc; } + + MapFinalAction FinalAction() const { return MAP_REQUIRE_SUPERFINAL; } + + MapSymbolsAction InputSymbolsAction() const { return MAP_COPY_SYMBOLS; } + + MapSymbolsAction OutputSymbolsAction() const { return MAP_COPY_SYMBOLS;} + + uint64 Properties(uint64 props) const { + return props & kAddSuperFinalProperties; + } +}; + + +// Mapper that leaves labels and nextstate unchanged and constructs a new weight +// from the underlying value of the arc weight. Requires that there is a +// WeightConvert class specialization that converts the weights. +template +class WeightConvertMapper { + public: + typedef A FromArc; + typedef B ToArc; + typedef typename FromArc::Weight FromWeight; + typedef typename ToArc::Weight ToWeight; + + ToArc operator()(const FromArc &arc) const { + return ToArc(arc.ilabel, arc.olabel, + convert_weight_(arc.weight), arc.nextstate); + } + + MapFinalAction FinalAction() const { return MAP_NO_SUPERFINAL; } + + MapSymbolsAction InputSymbolsAction() const { return MAP_COPY_SYMBOLS; } + + MapSymbolsAction OutputSymbolsAction() const { return MAP_COPY_SYMBOLS;} + + uint64 Properties(uint64 props) const { return props; } + + private: + WeightConvert convert_weight_; +}; + +// Non-precision-changing weight conversions. +// Consider using more efficient Cast (fst.h) instead. +typedef WeightConvertMapper StdToLogMapper; +typedef WeightConvertMapper LogToStdMapper; + +// Precision-changing weight conversions. +typedef WeightConvertMapper StdToLog64Mapper; +typedef WeightConvertMapper LogToLog64Mapper; +typedef WeightConvertMapper Log64ToStdMapper; +typedef WeightConvertMapper Log64ToLogMapper; + +// Mapper from A to GallicArc. +template +struct ToGallicMapper { + typedef A FromArc; + typedef GallicArc ToArc; + + typedef StringWeight SW; + typedef typename A::Weight AW; + typedef typename GallicArc::Weight GW; + + ToArc operator()(const A &arc) const { + // 'Super-final' arc. + if (arc.nextstate == kNoStateId && arc.weight != AW::Zero()) + return ToArc(0, 0, GW(SW::One(), arc.weight), kNoStateId); + // 'Super-non-final' arc. + else if (arc.nextstate == kNoStateId) + return ToArc(0, 0, GW(SW::Zero(), arc.weight), kNoStateId); + // Epsilon label. + else if (arc.olabel == 0) + return ToArc(arc.ilabel, arc.ilabel, + GW(SW::One(), arc.weight), arc.nextstate); + // Regular label. + else + return ToArc(arc.ilabel, arc.ilabel, + GW(SW(arc.olabel), arc.weight), arc.nextstate); + } + + MapFinalAction FinalAction() const { return MAP_NO_SUPERFINAL; } + + MapSymbolsAction InputSymbolsAction() const { return MAP_COPY_SYMBOLS; } + + MapSymbolsAction OutputSymbolsAction() const { return MAP_CLEAR_SYMBOLS;} + + uint64 Properties(uint64 props) const { + return ProjectProperties(props, true) & kWeightInvariantProperties; + } +}; + + +// Mapper from GallicArc to A. +template +struct FromGallicMapper { + typedef GallicArc FromArc; + typedef A ToArc; + + typedef typename A::Label Label; + typedef StringWeight SW; + typedef typename A::Weight AW; + typedef typename GallicArc::Weight GW; + + FromGallicMapper(Label superfinal_label = 0) + : superfinal_label_(superfinal_label), error_(false) {} + + A operator()(const FromArc &arc) const { + // 'Super-non-final' arc. + if (arc.nextstate == kNoStateId && arc.weight == GW::Zero()) + return A(arc.ilabel, 0, AW::Zero(), kNoStateId); + + SW w1 = arc.weight.Value1(); + AW w2 = arc.weight.Value2(); + StringWeightIterator iter1(w1); + + Label l = w1.Size() == 1 ? iter1.Value() : 0; + + if (l == kStringInfinity || l == kStringBad || + arc.ilabel != arc.olabel || w1.Size() > 1) { + FSTERROR() << "FromGallicMapper: unrepesentable weight"; + error_ = true; + } + + if (arc.ilabel == 0 && l != 0 && arc.nextstate == kNoStateId) + return A(superfinal_label_, l, w2, arc.nextstate); + else + return A(arc.ilabel, l, w2, arc.nextstate); + } + + MapFinalAction FinalAction() const { return MAP_ALLOW_SUPERFINAL; } + + MapSymbolsAction InputSymbolsAction() const { return MAP_COPY_SYMBOLS; } + + MapSymbolsAction OutputSymbolsAction() const { return MAP_CLEAR_SYMBOLS;} + + uint64 Properties(uint64 inprops) const { + uint64 outprops = inprops & kOLabelInvariantProperties & + kWeightInvariantProperties & kAddSuperFinalProperties; + if (error_) + outprops |= kError; + return outprops; + } + + private: + Label superfinal_label_; + mutable bool error_; +}; + + +// Mapper from GallicArc to A. +template +struct GallicToNewSymbolsMapper { + typedef GallicArc FromArc; + typedef A ToArc; + + typedef typename A::StateId StateId; + typedef typename A::Label Label; + typedef StringWeight SW; + typedef typename A::Weight AW; + typedef typename GallicArc::Weight GW; + + GallicToNewSymbolsMapper(MutableFst *fst) + : fst_(fst), lmax_(0), osymbols_(fst->OutputSymbols()), + isymbols_(0), error_(false) { + fst_->DeleteStates(); + state_ = fst_->AddState(); + fst_->SetStart(state_); + fst_->SetFinal(state_, AW::One()); + if (osymbols_) { + string name = osymbols_->Name() + "_from_gallic"; + fst_->SetInputSymbols(new SymbolTable(name)); + isymbols_ = fst_->MutableInputSymbols(); + isymbols_->AddSymbol(osymbols_->Find((int64) 0), 0); + } else { + fst_->SetInputSymbols(0); + } + } + + A operator()(const FromArc &arc) { + // 'Super-non-final' arc. + if (arc.nextstate == kNoStateId && arc.weight == GW::Zero()) + return A(arc.ilabel, 0, AW::Zero(), kNoStateId); + + SW w1 = arc.weight.Value1(); + AW w2 = arc.weight.Value2(); + Label l; + + if (w1.Size() == 0) { + l = 0; + } else { + typename Map::iterator miter = map_.find(w1); + if (miter != map_.end()) { + l = (*miter).second; + } else { + l = ++lmax_; + map_.insert(pair(w1, l)); + StringWeightIterator iter1(w1); + StateId n; + string s; + for(size_t i = 0, p = state_; + i < w1.Size(); + ++i, iter1.Next(), p = n) { + n = i == w1.Size() - 1 ? state_ : fst_->AddState(); + fst_->AddArc(p, ToArc(i ? 0 : l, iter1.Value(), AW::One(), n)); + if (isymbols_) { + if (i) s = s + "_"; + s = s + osymbols_->Find(iter1.Value()); + } + } + if (isymbols_) + isymbols_->AddSymbol(s, l); + } + } + + if (l == kStringInfinity || l == kStringBad || arc.ilabel != arc.olabel) { + FSTERROR() << "GallicToNewSymbolMapper: unrepesentable weight"; + error_ = true; + } + + return A(arc.ilabel, l, w2, arc.nextstate); + } + + MapFinalAction FinalAction() const { return MAP_ALLOW_SUPERFINAL; } + + MapSymbolsAction InputSymbolsAction() const { return MAP_COPY_SYMBOLS; } + + MapSymbolsAction OutputSymbolsAction() const { return MAP_CLEAR_SYMBOLS; } + + uint64 Properties(uint64 inprops) const { + uint64 outprops = inprops & kOLabelInvariantProperties & + kWeightInvariantProperties & kAddSuperFinalProperties; + if (error_) + outprops |= kError; + return outprops; + } + + private: + class StringKey { + public: + size_t operator()(const SW &x) const { + return x.Hash(); + } + }; + + typedef unordered_map Map; + + MutableFst *fst_; + Map map_; + Label lmax_; + StateId state_; + const SymbolTable *osymbols_; + SymbolTable *isymbols_; + mutable bool error_; + + DISALLOW_COPY_AND_ASSIGN(GallicToNewSymbolsMapper); +}; + + +// Mapper to add a constant to all weights. +template +struct PlusMapper { + typedef A FromArc; + typedef A ToArc; + typedef typename A::Weight Weight; + + explicit PlusMapper(Weight w) : weight_(w) {} + + A operator()(const A &arc) const { + if (arc.weight == Weight::Zero()) + return arc; + Weight w = Plus(arc.weight, weight_); + return A(arc.ilabel, arc.olabel, w, arc.nextstate); + } + + MapFinalAction FinalAction() const { return MAP_NO_SUPERFINAL; } + + MapSymbolsAction InputSymbolsAction() const { return MAP_COPY_SYMBOLS; } + + MapSymbolsAction OutputSymbolsAction() const { return MAP_COPY_SYMBOLS;} + + uint64 Properties(uint64 props) const { + return props & kWeightInvariantProperties; + } + + private: + + + + Weight weight_; +}; + + +// Mapper to (right) multiply a constant to all weights. +template +struct TimesMapper { + typedef A FromArc; + typedef A ToArc; + typedef typename A::Weight Weight; + + explicit TimesMapper(Weight w) : weight_(w) {} + + A operator()(const A &arc) const { + if (arc.weight == Weight::Zero()) + return arc; + Weight w = Times(arc.weight, weight_); + return A(arc.ilabel, arc.olabel, w, arc.nextstate); + } + + MapFinalAction FinalAction() const { return MAP_NO_SUPERFINAL; } + + MapSymbolsAction InputSymbolsAction() const { return MAP_COPY_SYMBOLS; } + + MapSymbolsAction OutputSymbolsAction() const { return MAP_COPY_SYMBOLS;} + + uint64 Properties(uint64 props) const { + return props & kWeightInvariantProperties; + } + + private: + Weight weight_; +}; + + +// Mapper to reciprocate all non-Zero() weights. +template +struct InvertWeightMapper { + typedef A FromArc; + typedef A ToArc; + typedef typename A::Weight Weight; + + A operator()(const A &arc) const { + if (arc.weight == Weight::Zero()) + return arc; + Weight w = Divide(Weight::One(), arc.weight); + return A(arc.ilabel, arc.olabel, w, arc.nextstate); + } + + MapFinalAction FinalAction() const { return MAP_NO_SUPERFINAL; } + + MapSymbolsAction InputSymbolsAction() const { return MAP_COPY_SYMBOLS; } + + MapSymbolsAction OutputSymbolsAction() const { return MAP_COPY_SYMBOLS;} + + uint64 Properties(uint64 props) const { + return props & kWeightInvariantProperties; + } +}; + + +// Mapper to map all non-Zero() weights to One(). +template +struct RmWeightMapper { + typedef A FromArc; + typedef B ToArc; + typedef typename FromArc::Weight FromWeight; + typedef typename ToArc::Weight ToWeight; + + B operator()(const A &arc) const { + ToWeight w = arc.weight != FromWeight::Zero() ? + ToWeight::One() : ToWeight::Zero(); + return B(arc.ilabel, arc.olabel, w, arc.nextstate); + } + + MapFinalAction FinalAction() const { return MAP_NO_SUPERFINAL; } + + MapSymbolsAction InputSymbolsAction() const { return MAP_COPY_SYMBOLS; } + + MapSymbolsAction OutputSymbolsAction() const { return MAP_COPY_SYMBOLS;} + + uint64 Properties(uint64 props) const { + return (props & kWeightInvariantProperties) | kUnweighted; + } +}; + + +// Mapper to quantize all weights. +template +struct QuantizeMapper { + typedef A FromArc; + typedef B ToArc; + typedef typename FromArc::Weight FromWeight; + typedef typename ToArc::Weight ToWeight; + + QuantizeMapper() : delta_(kDelta) {} + + explicit QuantizeMapper(float d) : delta_(d) {} + + B operator()(const A &arc) const { + ToWeight w = arc.weight.Quantize(delta_); + return B(arc.ilabel, arc.olabel, w, arc.nextstate); + } + + MapFinalAction FinalAction() const { return MAP_NO_SUPERFINAL; } + + MapSymbolsAction InputSymbolsAction() const { return MAP_COPY_SYMBOLS; } + + MapSymbolsAction OutputSymbolsAction() const { return MAP_COPY_SYMBOLS;} + + uint64 Properties(uint64 props) const { + return props & kWeightInvariantProperties; + } + + private: + float delta_; +}; + + +// Mapper from A to B under the assumption: +// B::Weight = A::Weight::ReverseWeight +// B::Label == A::Label +// B::StateId == A::StateId +// The weight is reversed, while the label and nextstate preserved +// in the mapping. +template +struct ReverseWeightMapper { + typedef A FromArc; + typedef B ToArc; + + B operator()(const A &arc) const { + return B(arc.ilabel, arc.olabel, arc.weight.Reverse(), arc.nextstate); + } + + MapFinalAction FinalAction() const { return MAP_NO_SUPERFINAL; } + + MapSymbolsAction InputSymbolsAction() const { return MAP_COPY_SYMBOLS; } + + MapSymbolsAction OutputSymbolsAction() const { return MAP_COPY_SYMBOLS;} + + uint64 Properties(uint64 props) const { return props; } +}; + +} // namespace fst + +#endif // FST_LIB_ARC_MAP_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/arc.h b/kaldi_io/src/tools/openfst/include/fst/arc.h new file mode 100644 index 0000000..5f4014b --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/arc.h @@ -0,0 +1,307 @@ +// arc.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// +// Commonly used Fst arc types. + +#ifndef FST_LIB_ARC_H__ +#define FST_LIB_ARC_H__ + +#include + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace fst { + +template +class ArcTpl { + public: + typedef W Weight; + typedef int Label; + typedef int StateId; + + ArcTpl(Label i, Label o, const Weight& w, StateId s) + : ilabel(i), olabel(o), weight(w), nextstate(s) {} + + ArcTpl() {} + + static const string &Type(void) { + static const string type = + (Weight::Type() == "tropical") ? "standard" : Weight::Type(); + return type; + } + + Label ilabel; + Label olabel; + Weight weight; + StateId nextstate; +}; + +typedef ArcTpl StdArc; +typedef ArcTpl LogArc; +typedef ArcTpl Log64Arc; +typedef ArcTpl SignedLogArc; +typedef ArcTpl SignedLog64Arc; +typedef ArcTpl MinMaxArc; + + +// Arc with integer labels and state Ids and string weights. +template +class StringArc { + public: + typedef int Label; + typedef StringWeight Weight; + typedef int StateId; + + StringArc(Label i, Label o, Weight w, StateId s) + : ilabel(i), olabel(o), weight(w), nextstate(s) {} + + StringArc() {} + + static const string &Type() { // Arc type name + static const string type = + S == STRING_LEFT ? "standard_string" : + (S == STRING_RIGHT ? "right_standard_string" : + (S == STRING_LEFT_RESTRICT ? "restricted_string" : + "right_restricted_string")); + return type; + } + + Label ilabel; // Transition input label + Label olabel; // Transition output label + Weight weight; // Transition weight + StateId nextstate; // Transition destination state +}; + + +// Arc with label and state Id type the same as template arg and with +// weights over the Gallic semiring w.r.t the output labels and weights of A. +template +struct GallicArc { + typedef A Arc; + typedef typename A::Label Label; + typedef typename A::StateId StateId; + typedef GallicWeight Weight; + + GallicArc() {} + + GallicArc(Label i, Label o, Weight w, StateId s) + : ilabel(i), olabel(o), weight(w), nextstate(s) {} + + GallicArc(const A &arc) + : ilabel(arc.ilabel), olabel(arc.ilabel), + weight(arc.olabel, arc.weight), nextstate(arc.nextstate) {} + + static const string &Type() { // Arc type name + static const string type = + (S == STRING_LEFT ? "gallic_" : + (S == STRING_RIGHT ? "right_gallic_" : + (S == STRING_LEFT_RESTRICT ? "restricted_gallic_" : + "right_restricted_gallic_"))) + A::Type(); + return type; + } + + Label ilabel; // Transition input label + Label olabel; // Transition output label + Weight weight; // Transition weight + StateId nextstate; // Transition destination state +}; + + +// Arc with the reverse of the weight found in its template arg. +template struct ReverseArc { + typedef A Arc; + typedef typename A::Label Label; + typedef typename A::Weight AWeight; + typedef typename AWeight::ReverseWeight Weight; + typedef typename A::StateId StateId; + + ReverseArc(Label i, Label o, Weight w, StateId s) + : ilabel(i), olabel(o), weight(w), nextstate(s) {} + + ReverseArc() {} + + static const string &Type() { // Arc type name + static const string type = "reverse_" + Arc::Type(); + return type; + } + + Label ilabel; // Transition input label + Label olabel; // Transition output label + Weight weight; // Transition weight + StateId nextstate; // Transition destination state +}; + + +// Arc with integer labels and state Ids and lexicographic weights. +template +struct LexicographicArc { + typedef int Label; + typedef LexicographicWeight Weight; + typedef int StateId; + + LexicographicArc(Label i, Label o, Weight w, StateId s) + : ilabel(i), olabel(o), weight(w), nextstate(s) {} + + LexicographicArc() {} + + static const string &Type() { // Arc type name + static const string type = Weight::Type(); + return type; + } + + Label ilabel; // Transition input label + Label olabel; // Transition output label + Weight weight; // Transition weight + StateId nextstate; // Transition destination state +}; + + +// Arc with integer labels and state Ids and product weights. +template +struct ProductArc { + typedef int Label; + typedef ProductWeight Weight; + typedef int StateId; + + ProductArc(Label i, Label o, Weight w, StateId s) + : ilabel(i), olabel(o), weight(w), nextstate(s) {} + + ProductArc() {} + + static const string &Type() { // Arc type name + static const string type = Weight::Type(); + return type; + } + + Label ilabel; // Transition input label + Label olabel; // Transition output label + Weight weight; // Transition weight + StateId nextstate; // Transition destination state +}; + + +// Arc with label and state Id type the same as first template arg and with +// weights over the n-th cartesian power of the weight type of the +// template arg. +template +struct PowerArc { + typedef A Arc; + typedef typename A::Label Label; + typedef typename A::StateId StateId; + typedef PowerWeight Weight; + + PowerArc() {} + + PowerArc(Label i, Label o, Weight w, StateId s) + : ilabel(i), olabel(o), weight(w), nextstate(s) {} + + static const string &Type() { // Arc type name + static string type; + if (type.empty()) { + string power; + Int64ToStr(n, &power); + type = A::Type() + "_^" + power; + } + return type; + } + + Label ilabel; // Transition input label + Label olabel; // Transition output label + Weight weight; // Transition weight + StateId nextstate; // Transition destination state +}; + + +// Arc with label and state Id type the same as first template arg and with +// weights over the arbitrary cartesian power of the weight type. +template +struct SparsePowerArc { + typedef A Arc; + typedef typename A::Label Label; + typedef typename A::StateId StateId; + typedef SparsePowerWeight Weight; + + SparsePowerArc() {} + + SparsePowerArc(Label i, Label o, Weight w, StateId s) + : ilabel(i), olabel(o), weight(w), nextstate(s) {} + + static const string &Type() { // Arc type name + static string type; + if (type.empty()) { type = A::Type() + "_^n"; } + if(sizeof(K) != sizeof(uint32)) { + string size; + Int64ToStr(8 * sizeof(K), &size); + type += "_" + size; + } + return type; + } + + Label ilabel; // Transition input label + Label olabel; // Transition output label + Weight weight; // Transition weight + StateId nextstate; // Transition destination state +}; + + +// Arc with label and state Id type the same as first template arg and with +// expectation weight over the first template arg weight type and the +// second template arg. +template +struct ExpectationArc { + typedef A Arc; + typedef typename A::Label Label; + typedef typename A::StateId StateId; + typedef typename A::Weight X1; + typedef ExpectationWeight Weight; + + ExpectationArc() {} + + ExpectationArc(Label i, Label o, Weight w, StateId s) + : ilabel(i), olabel(o), weight(w), nextstate(s) {} + + static const string &Type() { // Arc type name + static string type; + if (type.empty()) { + type = "expectation_" + A::Type() + "_" + X2::Type(); + } + return type; + } + + Label ilabel; // Transition input label + Label olabel; // Transition output label + Weight weight; // Transition weight + StateId nextstate; // Transition destination state +}; + +} // namespace fst + +#endif // FST_LIB_ARC_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/arcfilter.h b/kaldi_io/src/tools/openfst/include/fst/arcfilter.h new file mode 100644 index 0000000..179dc2c --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/arcfilter.h @@ -0,0 +1,99 @@ +// arcfilter.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Function objects to restrict which arcs are traversed in an FST. + +#ifndef FST_LIB_ARCFILTER_H__ +#define FST_LIB_ARCFILTER_H__ + + +#include +#include + + +namespace fst { + +// True for all arcs. +template +class AnyArcFilter { +public: + bool operator()(const A &arc) const { return true; } +}; + + +// True for (input/output) epsilon arcs. +template +class EpsilonArcFilter { +public: + bool operator()(const A &arc) const { + return arc.ilabel == 0 && arc.olabel == 0; + } +}; + + +// True for input epsilon arcs. +template +class InputEpsilonArcFilter { +public: + bool operator()(const A &arc) const { + return arc.ilabel == 0; + } +}; + + +// True for output epsilon arcs. +template +class OutputEpsilonArcFilter { +public: + bool operator()(const A &arc) const { + return arc.olabel == 0; + } +}; + + +// True if specified labels match (don't match) when keep_match is +// true (false). +template +class MultiLabelArcFilter { +public: + typedef typename A::Label Label; + + MultiLabelArcFilter(bool match_input = true, bool keep_match = true) + : match_input_(match_input), + keep_match_(keep_match) {} + + + bool operator()(const A &arc) const { + Label label = match_input_ ? arc.ilabel : arc.olabel; + bool match = labels_.Find(label) != labels_.End(); + return keep_match_ ? match : !match; + } + + void AddLabel(Label label) { + labels_.Insert(label); + } + +private: + CompactSet labels_; + bool match_input_; + bool keep_match_; +}; + +} // namespace fst + +#endif // FST_LIB_ARCFILTER_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/arcsort.h b/kaldi_io/src/tools/openfst/include/fst/arcsort.h new file mode 100644 index 0000000..37a51dc --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/arcsort.h @@ -0,0 +1,217 @@ +// arcsort.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Functions and classes to sort arcs in an FST. + +#ifndef FST_LIB_ARCSORT_H__ +#define FST_LIB_ARCSORT_H__ + +#include +#include +#include +using std::vector; + +#include +#include +#include + + +namespace fst { + +template +class ArcSortMapper { + public: + typedef Arc FromArc; + typedef Arc ToArc; + + typedef typename Arc::StateId StateId; + typedef typename Arc::Weight Weight; + + ArcSortMapper(const Fst &fst, const Compare &comp) + : fst_(fst), comp_(comp), i_(0) {} + + // Allows updating Fst argument; pass only if changed. + ArcSortMapper(const ArcSortMapper &mapper, + const Fst *fst = 0) + : fst_(fst ? *fst : mapper.fst_), comp_(mapper.comp_), i_(0) {} + + StateId Start() { return fst_.Start(); } + Weight Final(StateId s) const { return fst_.Final(s); } + + void SetState(StateId s) { + i_ = 0; + arcs_.clear(); + arcs_.reserve(fst_.NumArcs(s)); + for (ArcIterator< Fst > aiter(fst_, s); !aiter.Done(); aiter.Next()) + arcs_.push_back(aiter.Value()); + sort(arcs_.begin(), arcs_.end(), comp_); + } + + bool Done() const { return i_ >= arcs_.size(); } + const Arc &Value() const { return arcs_[i_]; } + void Next() { ++i_; } + + MapSymbolsAction InputSymbolsAction() const { return MAP_COPY_SYMBOLS; } + MapSymbolsAction OutputSymbolsAction() const { return MAP_COPY_SYMBOLS; } + uint64 Properties(uint64 props) const { return comp_.Properties(props); } + + private: + const Fst &fst_; + const Compare &comp_; + vector arcs_; + ssize_t i_; // current arc position + + void operator=(const ArcSortMapper &); // disallow +}; + + +// Sorts the arcs in an FST according to function object 'comp' of +// type Compare. This version modifies its input. Comparison function +// objects ILabelCompare and OLabelCompare are provived by the +// library. In general, Compare must meet the requirements for an STL +// sort comparision function object. It must also have a member +// Properties(uint64) that specifies the known properties of the +// sorted FST; it takes as argument the input FST's known properties +// before the sort. +// +// Complexity: +// - Time: O(V D log D) +// - Space: O(D) +// where V = # of states and D = maximum out-degree. +template +void ArcSort(MutableFst *fst, Compare comp) { + ArcSortMapper mapper(*fst, comp); + StateMap(fst, mapper); +} + +typedef CacheOptions ArcSortFstOptions; + +// Sorts the arcs in an FST according to function object 'comp' of +// type Compare. This version is a delayed Fst. Comparsion function +// objects ILabelCompare and OLabelCompare are provided by the +// library. In general, Compare must meet the requirements for an STL +// comparision function object (e.g. as used for STL sort). It must +// also have a member Properties(uint64) that specifies the known +// properties of the sorted FST; it takes as argument the input FST's +// known properties. +// +// Complexity: +// - Time: O(v d log d) +// - Space: O(d) +// where v = # of states visited, d = maximum out-degree of states +// visited. Constant time and space to visit an input state is assumed +// and exclusive of caching. +template +class ArcSortFst : public StateMapFst > { + using StateMapFst >::GetImpl; + public: + typedef A Arc; + typedef typename Arc::StateId StateId; + typedef ArcSortMapper M; + + ArcSortFst(const Fst &fst, const C &comp) + : StateMapFst(fst, ArcSortMapper(fst, comp)) {} + + ArcSortFst(const Fst &fst, const C &comp, const ArcSortFstOptions &opts) + : StateMapFst(fst, ArcSortMapper(fst, comp), opts) {} + + // See Fst<>::Copy() for doc. + ArcSortFst(const ArcSortFst &fst, bool safe = false) + : StateMapFst(fst, safe) {} + + // Get a copy of this ArcSortFst. See Fst<>::Copy() for further doc. + virtual ArcSortFst *Copy(bool safe = false) const { + return new ArcSortFst(*this, safe); + } + + virtual size_t NumArcs(StateId s) const { + return GetImpl()->GetFst().NumArcs(s); + } + + virtual size_t NumInputEpsilons(StateId s) const { + return GetImpl()->GetFst().NumInputEpsilons(s); + } + + virtual size_t NumOutputEpsilons(StateId s) const { + return GetImpl()->GetFst().NumOutputEpsilons(s); + } +}; + + +// Specialization for ArcSortFst. +template +class StateIterator< ArcSortFst > + : public StateIterator< StateMapFst > > { + public: + explicit StateIterator(const ArcSortFst &fst) + : StateIterator< StateMapFst > >(fst) {} +}; + + +// Specialization for ArcSortFst. +template +class ArcIterator< ArcSortFst > + : public ArcIterator< StateMapFst > > { + public: + ArcIterator(const ArcSortFst &fst, typename A::StateId s) + : ArcIterator< StateMapFst > >(fst, s) {} +}; + + +// Compare class for comparing input labels of arcs. +template class ILabelCompare { + public: + bool operator() (A arc1, A arc2) const { + return arc1.ilabel < arc2.ilabel; + } + + uint64 Properties(uint64 props) const { + return (props & kArcSortProperties) | kILabelSorted | + (props & kAcceptor ? kOLabelSorted : 0); + } +}; + + +// Compare class for comparing output labels of arcs. +template class OLabelCompare { + public: + bool operator() (const A &arc1, const A &arc2) const { + return arc1.olabel < arc2.olabel; + } + + uint64 Properties(uint64 props) const { + return (props & kArcSortProperties) | kOLabelSorted | + (props & kAcceptor ? kILabelSorted : 0); + } +}; + + +// Useful aliases when using StdArc. +template class StdArcSortFst : public ArcSortFst { + public: + typedef StdArc Arc; + typedef C Compare; +}; + +typedef ILabelCompare StdILabelCompare; + +typedef OLabelCompare StdOLabelCompare; + +} // namespace fst + +#endif // FST_LIB_ARCSORT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/bi-table.h b/kaldi_io/src/tools/openfst/include/fst/bi-table.h new file mode 100644 index 0000000..d220ce4 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/bi-table.h @@ -0,0 +1,532 @@ +// bi-table.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Classes for representing a bijective mapping between an arbitrary entry +// of type T and a signed integral ID. + +#ifndef FST_LIB_BI_TABLE_H__ +#define FST_LIB_BI_TABLE_H__ + +#include +using std::deque; +#include +#include +using std::vector; + +#include +using std::tr1::unordered_set; +using std::tr1::unordered_multiset; + +namespace fst { + +// BI TABLES - these determine a bijective mapping between an +// arbitrary entry of type T and an signed integral ID of type I. The IDs are +// allocated starting from 0 in order. +// +// template +// class BiTable { +// public: +// +// // Required constructors. +// BiTable(); +// +// // Lookup integer ID from entry. If it doesn't exist and 'insert' +// / is true, then add it. Otherwise return -1. +// I FindId(const T &entry, bool insert = true); +// // Lookup entry from integer ID. +// const T &FindEntry(I) const; +// // # of stored entries. +// I Size() const; +// }; + +// An implementation using a hash map for the entry to ID mapping. +// H is the hash function and E is the equality function. +// If passed to the constructor, ownership is given to this class. + +template > +class HashBiTable { + public: + // Reserves space for 'table_size' elements. + explicit HashBiTable(size_t table_size = 0, H *h = 0, E *e = 0) + : hash_func_(h), + hash_equal_(e), + entry2id_(table_size, (h ? *h : H()), (e ? *e : E())) { + if (table_size) + id2entry_.reserve(table_size); + } + + HashBiTable(const HashBiTable &table) + : hash_func_(table.hash_func_ ? new H(*table.hash_func_) : 0), + hash_equal_(table.hash_equal_ ? new E(*table.hash_equal_) : 0), + entry2id_(table.entry2id_.begin(), table.entry2id_.end(), + table.entry2id_.size(), + (hash_func_ ? *hash_func_ : H()), + (hash_equal_ ? *hash_equal_ : E())), + id2entry_(table.id2entry_) { } + + ~HashBiTable() { + delete hash_func_; + delete hash_equal_; + } + + I FindId(const T &entry, bool insert = true) { + I &id_ref = entry2id_[entry]; + if (id_ref == 0) { // T not found + if (insert) { // store and assign it a new ID + id2entry_.push_back(entry); + id_ref = id2entry_.size(); + } else { + return -1; + } + } + return id_ref - 1; // NB: id_ref = ID + 1 + } + + const T &FindEntry(I s) const { + return id2entry_[s]; + } + + I Size() const { return id2entry_.size(); } + + private: + H *hash_func_; + E *hash_equal_; + unordered_map entry2id_; + vector id2entry_; + + void operator=(const HashBiTable &table); // disallow +}; + + +// Enables alternative hash set representations below. +// typedef enum { HS_STL = 0, HS_DENSE = 1, HS_SPARSE = 2 } HSType; +typedef enum { HS_STL = 0, HS_DENSE = 1, HS_SPARSE = 2 } HSType; + +// Default hash set is STL hash_set +template +struct HashSet : public unordered_set { + HashSet(size_t n = 0, const H &h = H(), const E &e = E()) + : unordered_set(n, h, e) { } + + void rehash(size_t n) { } +}; + + +// An implementation using a hash set for the entry to ID mapping. +// The hash set holds 'keys' which are either the ID or kCurrentKey. +// These keys can be mapped to entrys either by looking up in the +// entry vector or, if kCurrentKey, in current_entry_ member. The hash +// and key equality functions map to entries first. H +// is the hash function and E is the equality function. If passed to +// the constructor, ownership is given to this class. +template , HSType HS = HS_DENSE> +class CompactHashBiTable { + public: + friend class HashFunc; + friend class HashEqual; + + // Reserves space for 'table_size' elements. + explicit CompactHashBiTable(size_t table_size = 0, H *h = 0, E *e = 0) + : hash_func_(h), + hash_equal_(e), + compact_hash_func_(*this), + compact_hash_equal_(*this), + keys_(table_size, compact_hash_func_, compact_hash_equal_) { + if (table_size) + id2entry_.reserve(table_size); + } + + CompactHashBiTable(const CompactHashBiTable &table) + : hash_func_(table.hash_func_ ? new H(*table.hash_func_) : 0), + hash_equal_(table.hash_equal_ ? new E(*table.hash_equal_) : 0), + compact_hash_func_(*this), + compact_hash_equal_(*this), + keys_(table.keys_.size(), compact_hash_func_, compact_hash_equal_), + id2entry_(table.id2entry_) { + keys_.insert(table.keys_.begin(), table.keys_.end()); + } + + ~CompactHashBiTable() { + delete hash_func_; + delete hash_equal_; + } + + I FindId(const T &entry, bool insert = true) { + current_entry_ = &entry; + typename KeyHashSet::const_iterator it = keys_.find(kCurrentKey); + if (it == keys_.end()) { // T not found + if (insert) { // store and assign it a new ID + I key = id2entry_.size(); + id2entry_.push_back(entry); + keys_.insert(key); + return key; + } else { + return -1; + } + } else { + return *it; + } + } + + const T &FindEntry(I s) const { return id2entry_[s]; } + + I Size() const { return id2entry_.size(); } + + // Clear content. With argument, erases last n IDs. + void Clear(ssize_t n = -1) { + if (n < 0 || n > id2entry_.size()) + n = id2entry_.size(); + while (n-- > 0) { + I key = id2entry_.size() - 1; + keys_.erase(key); + id2entry_.pop_back(); + } + keys_.rehash(0); + } + + private: + static const I kCurrentKey; // -1 + static const I kEmptyKey; // -2 + static const I kDeletedKey; // -3 + + class HashFunc { + public: + HashFunc(const CompactHashBiTable &ht) : ht_(&ht) {} + + size_t operator()(I k) const { + if (k >= kCurrentKey) { + return (*ht_->hash_func_)(ht_->Key2Entry(k)); + } else { + return 0; + } + } + + private: + const CompactHashBiTable *ht_; + }; + + class HashEqual { + public: + HashEqual(const CompactHashBiTable &ht) : ht_(&ht) {} + + bool operator()(I k1, I k2) const { + if (k1 >= kCurrentKey && k2 >= kCurrentKey) { + return (*ht_->hash_equal_)(ht_->Key2Entry(k1), ht_->Key2Entry(k2)); + } else { + return k1 == k2; + } + } + private: + const CompactHashBiTable *ht_; + }; + + typedef HashSet KeyHashSet; + + const T &Key2Entry(I k) const { + if (k == kCurrentKey) + return *current_entry_; + else + return id2entry_[k]; + } + + H *hash_func_; + E *hash_equal_; + HashFunc compact_hash_func_; + HashEqual compact_hash_equal_; + KeyHashSet keys_; + vector id2entry_; + const T *current_entry_; + + void operator=(const CompactHashBiTable &table); // disallow +}; + + +template +const I CompactHashBiTable::kCurrentKey = -1; + +template +const I CompactHashBiTable::kEmptyKey = -2; + +template +const I CompactHashBiTable::kDeletedKey = -3; + + +// An implementation using a vector for the entry to ID mapping. +// It is passed a function object FP that should fingerprint entries +// uniquely to an integer that can used as a vector index. Normally, +// VectorBiTable constructs the FP object. The user can instead +// pass in this object; in that case, VectorBiTable takes its +// ownership. +template +class VectorBiTable { + public: + // Reserves space for 'table_size' elements. + explicit VectorBiTable(FP *fp = 0, size_t table_size = 0) + : fp_(fp ? fp : new FP()) { + if (table_size) + id2entry_.reserve(table_size); + } + + VectorBiTable(const VectorBiTable &table) + : fp_(table.fp_ ? new FP(*table.fp_) : 0), + fp2id_(table.fp2id_), + id2entry_(table.id2entry_) { } + + ~VectorBiTable() { delete fp_; } + + I FindId(const T &entry, bool insert = true) { + ssize_t fp = (*fp_)(entry); + if (fp >= fp2id_.size()) + fp2id_.resize(fp + 1); + I &id_ref = fp2id_[fp]; + if (id_ref == 0) { // T not found + if (insert) { // store and assign it a new ID + id2entry_.push_back(entry); + id_ref = id2entry_.size(); + } else { + return -1; + } + } + return id_ref - 1; // NB: id_ref = ID + 1 + } + + const T &FindEntry(I s) const { return id2entry_[s]; } + + I Size() const { return id2entry_.size(); } + + const FP &Fingerprint() const { return *fp_; } + + private: + FP *fp_; + vector fp2id_; + vector id2entry_; + + void operator=(const VectorBiTable &table); // disallow +}; + + +// An implementation using a vector and a compact hash table. The +// selecting functor S returns true for entries to be hashed in the +// vector. The fingerprinting functor FP returns a unique fingerprint +// for each entry to be hashed in the vector (these need to be +// suitable for indexing in a vector). The hash functor H is used +// when hashing entry into the compact hash table. If passed to the +// constructor, ownership is given to this class. +template +class VectorHashBiTable { + public: + friend class HashFunc; + friend class HashEqual; + + explicit VectorHashBiTable(S *s, FP *fp = 0, H *h = 0, + size_t vector_size = 0, + size_t entry_size = 0) + : selector_(s), + fp_(fp ? fp : new FP()), + h_(h ? h : new H()), + hash_func_(*this), + hash_equal_(*this), + keys_(0, hash_func_, hash_equal_) { + if (vector_size) + fp2id_.reserve(vector_size); + if (entry_size) + id2entry_.reserve(entry_size); + } + + VectorHashBiTable(const VectorHashBiTable &table) + : selector_(new S(table.s_)), + fp_(table.fp_ ? new FP(*table.fp_) : 0), + h_(table.h_ ? new H(*table.h_) : 0), + id2entry_(table.id2entry_), + fp2id_(table.fp2id_), + hash_func_(*this), + hash_equal_(*this), + keys_(table.keys_.size(), hash_func_, hash_equal_) { + keys_.insert(table.keys_.begin(), table.keys_.end()); + } + + ~VectorHashBiTable() { + delete selector_; + delete fp_; + delete h_; + } + + I FindId(const T &entry, bool insert = true) { + if ((*selector_)(entry)) { // Use the vector if 'selector_(entry) == true' + uint64 fp = (*fp_)(entry); + if (fp2id_.size() <= fp) + fp2id_.resize(fp + 1, 0); + if (fp2id_[fp] == 0) { // T not found + if (insert) { // store and assign it a new ID + id2entry_.push_back(entry); + fp2id_[fp] = id2entry_.size(); + } else { + return -1; + } + } + return fp2id_[fp] - 1; // NB: assoc_value = ID + 1 + } else { // Use the hash table otherwise. + current_entry_ = &entry; + typename KeyHashSet::const_iterator it = keys_.find(kCurrentKey); + if (it == keys_.end()) { + if (insert) { + I key = id2entry_.size(); + id2entry_.push_back(entry); + keys_.insert(key); + return key; + } else { + return -1; + } + } else { + return *it; + } + } + } + + const T &FindEntry(I s) const { + return id2entry_[s]; + } + + I Size() const { return id2entry_.size(); } + + const S &Selector() const { return *selector_; } + + const FP &Fingerprint() const { return *fp_; } + + const H &Hash() const { return *h_; } + + private: + static const I kCurrentKey; // -1 + static const I kEmptyKey; // -2 + + class HashFunc { + public: + HashFunc(const VectorHashBiTable &ht) : ht_(&ht) {} + + size_t operator()(I k) const { + if (k >= kCurrentKey) { + return (*(ht_->h_))(ht_->Key2Entry(k)); + } else { + return 0; + } + } + private: + const VectorHashBiTable *ht_; + }; + + class HashEqual { + public: + HashEqual(const VectorHashBiTable &ht) : ht_(&ht) {} + + bool operator()(I k1, I k2) const { + if (k1 >= kCurrentKey && k2 >= kCurrentKey) { + return ht_->Key2Entry(k1) == ht_->Key2Entry(k2); + } else { + return k1 == k2; + } + } + private: + const VectorHashBiTable *ht_; + }; + + typedef HashSet KeyHashSet; + + const T &Key2Entry(I k) const { + if (k == kCurrentKey) + return *current_entry_; + else + return id2entry_[k]; + } + + S *selector_; // Returns true if entry hashed into vector + FP *fp_; // Fingerprint used when hashing entry into vector + H *h_; // Hash function used when hashing entry into hash_set + + vector id2entry_; // Maps state IDs to entry + vector fp2id_; // Maps entry fingerprints to IDs + + // Compact implementation of the hash table mapping entrys to + // state IDs using the hash function 'h_' + HashFunc hash_func_; + HashEqual hash_equal_; + KeyHashSet keys_; + const T *current_entry_; + + // disallow + void operator=(const VectorHashBiTable &table); +}; + +template +const I VectorHashBiTable::kCurrentKey = -1; + +template +const I VectorHashBiTable::kEmptyKey = -3; + + +// An implementation using a hash map for the entry to ID +// mapping. This version permits erasing of arbitrary states. The +// entry T must have == defined and its default constructor must +// produce a entry that will never be seen. F is the hash function. +template +class ErasableBiTable { + public: + ErasableBiTable() : first_(0) {} + + I FindId(const T &entry, bool insert = true) { + I &id_ref = entry2id_[entry]; + if (id_ref == 0) { // T not found + if (insert) { // store and assign it a new ID + id2entry_.push_back(entry); + id_ref = id2entry_.size() + first_; + } else { + return -1; + } + } + return id_ref - 1; // NB: id_ref = ID + 1 + } + + const T &FindEntry(I s) const { return id2entry_[s - first_]; } + + I Size() const { return id2entry_.size(); } + + void Erase(I s) { + T &entry = id2entry_[s - first_]; + typename unordered_map::iterator it = + entry2id_.find(entry); + entry2id_.erase(it); + id2entry_[s - first_] = empty_entry_; + while (!id2entry_.empty() && id2entry_.front() == empty_entry_) { + id2entry_.pop_front(); + ++first_; + } + } + + private: + unordered_map entry2id_; + deque id2entry_; + const T empty_entry_; + I first_; // I of first element in the deque; + + // disallow + void operator=(const ErasableBiTable &table); //disallow +}; + +} // namespace fst + +#endif // FST_LIB_BI_TABLE_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/cache.h b/kaldi_io/src/tools/openfst/include/fst/cache.h new file mode 100644 index 0000000..7c96fe1 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/cache.h @@ -0,0 +1,861 @@ +// cache.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// An Fst implementation that caches FST elements of a delayed +// computation. + +#ifndef FST_LIB_CACHE_H__ +#define FST_LIB_CACHE_H__ + +#include +using std::vector; +#include + +#include + + +DECLARE_bool(fst_default_cache_gc); +DECLARE_int64(fst_default_cache_gc_limit); + +namespace fst { + +struct CacheOptions { + bool gc; // enable GC + size_t gc_limit; // # of bytes allowed before GC + + CacheOptions(bool g, size_t l) : gc(g), gc_limit(l) {} + CacheOptions() + : gc(FLAGS_fst_default_cache_gc), + gc_limit(FLAGS_fst_default_cache_gc_limit) {} +}; + +// A CacheStateAllocator allocates and frees CacheStates +// template +// struct CacheStateAllocator { +// S *Allocate(StateId s); +// void Free(S *state, StateId s); +// }; +// + +// A simple allocator class, can be overridden as needed, +// maintains a single entry cache. +template +struct DefaultCacheStateAllocator { + typedef typename S::Arc::StateId StateId; + + DefaultCacheStateAllocator() : mru_(NULL) { } + + ~DefaultCacheStateAllocator() { + delete mru_; + } + + S *Allocate(StateId s) { + if (mru_) { + S *state = mru_; + mru_ = NULL; + state->Reset(); + return state; + } + return new S(); + } + + void Free(S *state, StateId s) { + if (mru_) { + delete mru_; + } + mru_ = state; + } + + private: + S *mru_; +}; + +// VectorState but additionally has a flags data member (see +// CacheState below). This class is used to cache FST elements with +// the flags used to indicate what has been cached. Use HasStart() +// HasFinal(), and HasArcs() to determine if cached and SetStart(), +// SetFinal(), AddArc(), (or PushArc() and SetArcs()) to cache. Note +// you must set the final weight even if the state is non-final to +// mark it as cached. If the 'gc' option is 'false', cached items have +// the extent of the FST - minimizing computation. If the 'gc' option +// is 'true', garbage collection of states (not in use in an arc +// iterator and not 'protected') is performed, in a rough +// approximation of LRU order, when 'gc_limit' bytes is reached - +// controlling memory use. When 'gc_limit' is 0, special optimizations +// apply - minimizing memory use. + +template > +class CacheBaseImpl : public VectorFstBaseImpl { + public: + typedef S State; + typedef C Allocator; + typedef typename State::Arc Arc; + typedef typename Arc::Weight Weight; + typedef typename Arc::StateId StateId; + + using FstImpl::Type; + using FstImpl::Properties; + using FstImpl::SetProperties; + using VectorFstBaseImpl::NumStates; + using VectorFstBaseImpl::Start; + using VectorFstBaseImpl::AddState; + using VectorFstBaseImpl::SetState; + using VectorFstBaseImpl::ReserveStates; + + explicit CacheBaseImpl(C *allocator = 0) + : cache_start_(false), nknown_states_(0), min_unexpanded_state_id_(0), + cache_first_state_id_(kNoStateId), cache_first_state_(0), + cache_gc_(FLAGS_fst_default_cache_gc), cache_size_(0), + cache_limit_(FLAGS_fst_default_cache_gc_limit > kMinCacheLimit || + FLAGS_fst_default_cache_gc_limit == 0 ? + FLAGS_fst_default_cache_gc_limit : kMinCacheLimit), + protect_(false) { + allocator_ = allocator ? allocator : new C(); + } + + explicit CacheBaseImpl(const CacheOptions &opts, C *allocator = 0) + : cache_start_(false), nknown_states_(0), + min_unexpanded_state_id_(0), cache_first_state_id_(kNoStateId), + cache_first_state_(0), cache_gc_(opts.gc), cache_size_(0), + cache_limit_(opts.gc_limit > kMinCacheLimit || opts.gc_limit == 0 ? + opts.gc_limit : kMinCacheLimit), + protect_(false) { + allocator_ = allocator ? allocator : new C(); + } + + // Preserve gc parameters. If preserve_cache true, also preserves + // cache data. + CacheBaseImpl(const CacheBaseImpl &impl, bool preserve_cache = false) + : VectorFstBaseImpl(), cache_start_(false), nknown_states_(0), + min_unexpanded_state_id_(0), cache_first_state_id_(kNoStateId), + cache_first_state_(0), cache_gc_(impl.cache_gc_), cache_size_(0), + cache_limit_(impl.cache_limit_), + protect_(impl.protect_) { + allocator_ = new C(); + if (preserve_cache) { + cache_start_ = impl.cache_start_; + nknown_states_ = impl.nknown_states_; + expanded_states_ = impl.expanded_states_; + min_unexpanded_state_id_ = impl.min_unexpanded_state_id_; + if (impl.cache_first_state_id_ != kNoStateId) { + cache_first_state_id_ = impl.cache_first_state_id_; + cache_first_state_ = allocator_->Allocate(cache_first_state_id_); + *cache_first_state_ = *impl.cache_first_state_; + } + cache_states_ = impl.cache_states_; + cache_size_ = impl.cache_size_; + ReserveStates(impl.NumStates()); + for (StateId s = 0; s < impl.NumStates(); ++s) { + const S *state = + static_cast &>(impl).GetState(s); + if (state) { + S *copied_state = allocator_->Allocate(s); + *copied_state = *state; + AddState(copied_state); + } else { + AddState(0); + } + } + VectorFstBaseImpl::SetStart(impl.Start()); + } + } + + ~CacheBaseImpl() { + allocator_->Free(cache_first_state_, cache_first_state_id_); + delete allocator_; + } + + // Gets a state from its ID; state must exist. + const S *GetState(StateId s) const { + if (s == cache_first_state_id_) + return cache_first_state_; + else + return VectorFstBaseImpl::GetState(s); + } + + // Gets a state from its ID; state must exist. + S *GetState(StateId s) { + if (s == cache_first_state_id_) + return cache_first_state_; + else + return VectorFstBaseImpl::GetState(s); + } + + // Gets a state from its ID; return 0 if it doesn't exist. + const S *CheckState(StateId s) const { + if (s == cache_first_state_id_) + return cache_first_state_; + else if (s < NumStates()) + return VectorFstBaseImpl::GetState(s); + else + return 0; + } + + // Gets a state from its ID; add it if necessary. + S *ExtendState(StateId s); + + void SetStart(StateId s) { + VectorFstBaseImpl::SetStart(s); + cache_start_ = true; + if (s >= nknown_states_) + nknown_states_ = s + 1; + } + + void SetFinal(StateId s, Weight w) { + S *state = ExtendState(s); + state->final = w; + state->flags |= kCacheFinal | kCacheRecent | kCacheModified; + } + + // AddArc adds a single arc to state s and does incremental cache + // book-keeping. For efficiency, prefer PushArc and SetArcs below + // when possible. + void AddArc(StateId s, const Arc &arc) { + S *state = ExtendState(s); + state->arcs.push_back(arc); + if (arc.ilabel == 0) { + ++state->niepsilons; + } + if (arc.olabel == 0) { + ++state->noepsilons; + } + const Arc *parc = state->arcs.empty() ? 0 : &(state->arcs.back()); + SetProperties(AddArcProperties(Properties(), s, arc, parc)); + state->flags |= kCacheModified; + if (cache_gc_ && s != cache_first_state_id_ && + !(state->flags & kCacheProtect)) { + cache_size_ += sizeof(Arc); + if (cache_size_ > cache_limit_) + GC(s, false); + } + } + + // Adds a single arc to state s but delays cache book-keeping. + // SetArcs must be called when all PushArc calls at a state are + // complete. Do not mix with calls to AddArc. + void PushArc(StateId s, const Arc &arc) { + S *state = ExtendState(s); + state->arcs.push_back(arc); + } + + // Marks arcs of state s as cached and does cache book-keeping after all + // calls to PushArc have been completed. Do not mix with calls to AddArc. + void SetArcs(StateId s) { + S *state = ExtendState(s); + vector &arcs = state->arcs; + state->niepsilons = state->noepsilons = 0; + for (size_t a = 0; a < arcs.size(); ++a) { + const Arc &arc = arcs[a]; + if (arc.nextstate >= nknown_states_) + nknown_states_ = arc.nextstate + 1; + if (arc.ilabel == 0) + ++state->niepsilons; + if (arc.olabel == 0) + ++state->noepsilons; + } + ExpandedState(s); + state->flags |= kCacheArcs | kCacheRecent | kCacheModified; + if (cache_gc_ && s != cache_first_state_id_ && + !(state->flags & kCacheProtect)) { + cache_size_ += arcs.capacity() * sizeof(Arc); + if (cache_size_ > cache_limit_) + GC(s, false); + } + }; + + void ReserveArcs(StateId s, size_t n) { + S *state = ExtendState(s); + state->arcs.reserve(n); + } + + void DeleteArcs(StateId s, size_t n) { + S *state = ExtendState(s); + const vector &arcs = state->arcs; + for (size_t i = 0; i < n; ++i) { + size_t j = arcs.size() - i - 1; + if (arcs[j].ilabel == 0) + --state->niepsilons; + if (arcs[j].olabel == 0) + --state->noepsilons; + } + + state->arcs.resize(arcs.size() - n); + SetProperties(DeleteArcsProperties(Properties())); + state->flags |= kCacheModified; + if (cache_gc_ && s != cache_first_state_id_ && + !(state->flags & kCacheProtect)) { + cache_size_ -= n * sizeof(Arc); + } + } + + void DeleteArcs(StateId s) { + S *state = ExtendState(s); + size_t n = state->arcs.size(); + state->niepsilons = 0; + state->noepsilons = 0; + state->arcs.clear(); + SetProperties(DeleteArcsProperties(Properties())); + state->flags |= kCacheModified; + if (cache_gc_ && s != cache_first_state_id_ && + !(state->flags & kCacheProtect)) { + cache_size_ -= n * sizeof(Arc); + } + } + + void DeleteStates(const vector &dstates) { + size_t old_num_states = NumStates(); + vector newid(old_num_states, 0); + for (size_t i = 0; i < dstates.size(); ++i) + newid[dstates[i]] = kNoStateId; + StateId nstates = 0; + for (StateId s = 0; s < old_num_states; ++s) { + if (newid[s] != kNoStateId) { + newid[s] = nstates; + ++nstates; + } + } + // just for states_.resize(), does unnecessary walk. + VectorFstBaseImpl::DeleteStates(dstates); + SetProperties(DeleteStatesProperties(Properties())); + // Update list of cached states. + typename list::iterator siter = cache_states_.begin(); + while (siter != cache_states_.end()) { + if (newid[*siter] != kNoStateId) { + *siter = newid[*siter]; + ++siter; + } else { + cache_states_.erase(siter++); + } + } + } + + void DeleteStates() { + cache_states_.clear(); + allocator_->Free(cache_first_state_, cache_first_state_id_); + for (int s = 0; s < NumStates(); ++s) { + allocator_->Free(VectorFstBaseImpl::GetState(s), s); + SetState(s, 0); + } + nknown_states_ = 0; + min_unexpanded_state_id_ = 0; + cache_first_state_id_ = kNoStateId; + cache_first_state_ = 0; + cache_size_ = 0; + cache_start_ = false; + VectorFstBaseImpl::DeleteStates(); + SetProperties(DeleteAllStatesProperties(Properties(), + kExpanded | kMutable)); + } + + // Is the start state cached? + bool HasStart() const { + if (!cache_start_ && Properties(kError)) + cache_start_ = true; + return cache_start_; + } + + // Is the final weight of state s cached? + bool HasFinal(StateId s) const { + const S *state = CheckState(s); + if (state && state->flags & kCacheFinal) { + state->flags |= kCacheRecent; + return true; + } else { + return false; + } + } + + // Are arcs of state s cached? + bool HasArcs(StateId s) const { + const S *state = CheckState(s); + if (state && state->flags & kCacheArcs) { + state->flags |= kCacheRecent; + return true; + } else { + return false; + } + } + + Weight Final(StateId s) const { + const S *state = GetState(s); + return state->final; + } + + size_t NumArcs(StateId s) const { + const S *state = GetState(s); + return state->arcs.size(); + } + + size_t NumInputEpsilons(StateId s) const { + const S *state = GetState(s); + return state->niepsilons; + } + + size_t NumOutputEpsilons(StateId s) const { + const S *state = GetState(s); + return state->noepsilons; + } + + // Provides information needed for generic arc iterator. + void InitArcIterator(StateId s, ArcIteratorData *data) const { + const S *state = GetState(s); + data->base = 0; + data->narcs = state->arcs.size(); + data->arcs = data->narcs > 0 ? &(state->arcs[0]) : 0; + data->ref_count = &(state->ref_count); + ++(*data->ref_count); + } + + // Number of known states. + StateId NumKnownStates() const { return nknown_states_; } + + // Update number of known states taking in account the existence of state s. + void UpdateNumKnownStates(StateId s) { + if (s >= nknown_states_) + nknown_states_ = s + 1; + } + + // Find the mininum never-expanded state Id + StateId MinUnexpandedState() const { + while (min_unexpanded_state_id_ < expanded_states_.size() && + expanded_states_[min_unexpanded_state_id_]) + ++min_unexpanded_state_id_; + return min_unexpanded_state_id_; + } + + // Removes from cache_states_ and uncaches (not referenced-counted + // or protected) states that have not been accessed since the last + // GC until at most cache_fraction * cache_limit_ bytes are cached. + // If that fails to free enough, recurs uncaching recently visited + // states as well. If still unable to free enough memory, then + // widens cache_limit_ to fulfill condition. + void GC(StateId current, bool free_recent, float cache_fraction = 0.666); + + // Setc/clears GC protection: if true, new states are protected + // from garbage collection. + void GCProtect(bool on) { protect_ = on; } + + void ExpandedState(StateId s) { + if (s < min_unexpanded_state_id_) + return; + while (expanded_states_.size() <= s) + expanded_states_.push_back(false); + expanded_states_[s] = true; + } + + C *GetAllocator() const { + return allocator_; + } + + // Caching on/off switch, limit and size accessors. + bool GetCacheGc() const { return cache_gc_; } + size_t GetCacheLimit() const { return cache_limit_; } + size_t GetCacheSize() const { return cache_size_; } + + private: + static const size_t kMinCacheLimit = 8096; // Minimum (non-zero) cache limit + + static const uint32 kCacheFinal = 0x0001; // Final weight has been cached + static const uint32 kCacheArcs = 0x0002; // Arcs have been cached + static const uint32 kCacheRecent = 0x0004; // Mark as visited since GC + static const uint32 kCacheProtect = 0x0008; // Mark state as GC protected + + public: + static const uint32 kCacheModified = 0x0010; // Mark state as modified + static const uint32 kCacheFlags = kCacheFinal | kCacheArcs | kCacheRecent + | kCacheProtect | kCacheModified; + + private: + C *allocator_; // used to allocate new states + mutable bool cache_start_; // Is the start state cached? + StateId nknown_states_; // # of known states + vector expanded_states_; // states that have been expanded + mutable StateId min_unexpanded_state_id_; // minimum never-expanded state Id + StateId cache_first_state_id_; // First cached state id + S *cache_first_state_; // First cached state + list cache_states_; // list of currently cached states + bool cache_gc_; // enable GC + size_t cache_size_; // # of bytes cached + size_t cache_limit_; // # of bytes allowed before GC + bool protect_; // Protect new states from GC + + void operator=(const CacheBaseImpl &impl); // disallow +}; + +// Gets a state from its ID; add it if necessary. +template +S *CacheBaseImpl::ExtendState(typename S::Arc::StateId s) { + // If 'protect_' true and a new state, protects from garbage collection. + if (s == cache_first_state_id_) { + return cache_first_state_; // Return 1st cached state + } else if (cache_limit_ == 0 && cache_first_state_id_ == kNoStateId) { + cache_first_state_id_ = s; // Remember 1st cached state + cache_first_state_ = allocator_->Allocate(s); + if (protect_) cache_first_state_->flags |= kCacheProtect; + return cache_first_state_; + } else if (cache_first_state_id_ != kNoStateId && + cache_first_state_->ref_count == 0 && + !(cache_first_state_->flags & kCacheProtect)) { + // With Default allocator, the Free and Allocate will reuse the same S*. + allocator_->Free(cache_first_state_, cache_first_state_id_); + cache_first_state_id_ = s; + cache_first_state_ = allocator_->Allocate(s); + if (protect_) cache_first_state_->flags |= kCacheProtect; + return cache_first_state_; // Return 1st cached state + } else { + while (NumStates() <= s) // Add state to main cache + AddState(0); + S *state = VectorFstBaseImpl::GetState(s); + if (!state) { + state = allocator_->Allocate(s); + if (protect_) state->flags |= kCacheProtect; + SetState(s, state); + if (cache_first_state_id_ != kNoStateId) { // Forget 1st cached state + while (NumStates() <= cache_first_state_id_) + AddState(0); + SetState(cache_first_state_id_, cache_first_state_); + if (cache_gc_ && !(cache_first_state_->flags & kCacheProtect)) { + cache_states_.push_back(cache_first_state_id_); + cache_size_ += sizeof(S) + + cache_first_state_->arcs.capacity() * sizeof(Arc); + } + cache_limit_ = kMinCacheLimit; + cache_first_state_id_ = kNoStateId; + cache_first_state_ = 0; + } + if (cache_gc_ && !protect_) { + cache_states_.push_back(s); + cache_size_ += sizeof(S); + if (cache_size_ > cache_limit_) + GC(s, false); + } + } + return state; + } +} + +// Removes from cache_states_ and uncaches (not referenced-counted or +// protected) states that have not been accessed since the last GC +// until at most cache_fraction * cache_limit_ bytes are cached. If +// that fails to free enough, recurs uncaching recently visited states +// as well. If still unable to free enough memory, then widens cache_limit_ +// to fulfill condition. +template +void CacheBaseImpl::GC(typename S::Arc::StateId current, + bool free_recent, float cache_fraction) { + if (!cache_gc_) + return; + VLOG(2) << "CacheImpl: Enter GC: object = " << Type() << "(" << this + << "), free recently cached = " << free_recent + << ", cache size = " << cache_size_ + << ", cache frac = " << cache_fraction + << ", cache limit = " << cache_limit_ << "\n"; + typename list::iterator siter = cache_states_.begin(); + + size_t cache_target = cache_fraction * cache_limit_; + while (siter != cache_states_.end()) { + StateId s = *siter; + S* state = VectorFstBaseImpl::GetState(s); + if (cache_size_ > cache_target && state->ref_count == 0 && + (free_recent || !(state->flags & kCacheRecent)) && s != current) { + cache_size_ -= sizeof(S) + state->arcs.capacity() * sizeof(Arc); + allocator_->Free(state, s); + SetState(s, 0); + cache_states_.erase(siter++); + } else { + state->flags &= ~kCacheRecent; + ++siter; + } + } + if (!free_recent && cache_size_ > cache_target) { // recurses on recent + GC(current, true); + } else if (cache_target > 0) { // widens cache limit + while (cache_size_ > cache_target) { + cache_limit_ *= 2; + cache_target *= 2; + } + } else if (cache_size_ > 0) { + FSTERROR() << "CacheImpl:GC: Unable to free all cached states"; + } + VLOG(2) << "CacheImpl: Exit GC: object = " << Type() << "(" << this + << "), free recently cached = " << free_recent + << ", cache size = " << cache_size_ + << ", cache frac = " << cache_fraction + << ", cache limit = " << cache_limit_ << "\n"; +} + +template const uint32 CacheBaseImpl::kCacheFinal; +template const uint32 CacheBaseImpl::kCacheArcs; +template const uint32 CacheBaseImpl::kCacheRecent; +template const uint32 CacheBaseImpl::kCacheModified; +template const size_t CacheBaseImpl::kMinCacheLimit; + +// Arcs implemented by an STL vector per state. Similar to VectorState +// but adds flags and ref count to keep track of what has been cached. +template +struct CacheState { + typedef A Arc; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + + CacheState() : final(Weight::Zero()), flags(0), ref_count(0) {} + + void Reset() { + flags = 0; + ref_count = 0; + arcs.resize(0); + } + + Weight final; // Final weight + vector arcs; // Arcs represenation + size_t niepsilons; // # of input epsilons + size_t noepsilons; // # of output epsilons + mutable uint32 flags; + mutable int ref_count; +}; + +// A CacheBaseImpl with a commonly used CacheState. +template +class CacheImpl : public CacheBaseImpl< CacheState > { + public: + typedef CacheState State; + + CacheImpl() {} + + explicit CacheImpl(const CacheOptions &opts) + : CacheBaseImpl< CacheState >(opts) {} + + CacheImpl(const CacheImpl &impl, bool preserve_cache = false) + : CacheBaseImpl(impl, preserve_cache) {} + + private: + void operator=(const CacheImpl &impl); // disallow +}; + + +// Use this to make a state iterator for a CacheBaseImpl-derived Fst, +// which must have type 'State' defined. Note this iterator only +// returns those states reachable from the initial state, so consider +// implementing a class-specific one. +template +class CacheStateIterator : public StateIteratorBase { + public: + typedef typename F::Arc Arc; + typedef typename Arc::StateId StateId; + typedef typename F::State State; + typedef CacheBaseImpl Impl; + + CacheStateIterator(const F &fst, Impl *impl) + : fst_(fst), impl_(impl), s_(0) { + fst_.Start(); // force start state + } + + bool Done() const { + if (s_ < impl_->NumKnownStates()) + return false; + if (s_ < impl_->NumKnownStates()) + return false; + for (StateId u = impl_->MinUnexpandedState(); + u < impl_->NumKnownStates(); + u = impl_->MinUnexpandedState()) { + // force state expansion + ArcIterator aiter(fst_, u); + aiter.SetFlags(kArcValueFlags, kArcValueFlags | kArcNoCache); + for (; !aiter.Done(); aiter.Next()) + impl_->UpdateNumKnownStates(aiter.Value().nextstate); + impl_->ExpandedState(u); + if (s_ < impl_->NumKnownStates()) + return false; + } + return true; + } + + StateId Value() const { return s_; } + + void Next() { ++s_; } + + void Reset() { s_ = 0; } + + private: + // This allows base class virtual access to non-virtual derived- + // class members of the same name. It makes the derived class more + // efficient to use but unsafe to further derive. + virtual bool Done_() const { return Done(); } + virtual StateId Value_() const { return Value(); } + virtual void Next_() { Next(); } + virtual void Reset_() { Reset(); } + + const F &fst_; + Impl *impl_; + StateId s_; +}; + + +// Use this to make an arc iterator for a CacheBaseImpl-derived Fst, +// which must have types 'Arc' and 'State' defined. +template > > +class CacheArcIterator { + public: + typedef typename F::Arc Arc; + typedef typename F::State State; + typedef typename Arc::StateId StateId; + typedef CacheBaseImpl Impl; + + CacheArcIterator(Impl *impl, StateId s) : i_(0) { + state_ = impl->ExtendState(s); + ++state_->ref_count; + } + + ~CacheArcIterator() { --state_->ref_count; } + + bool Done() const { return i_ >= state_->arcs.size(); } + + const Arc& Value() const { return state_->arcs[i_]; } + + void Next() { ++i_; } + + size_t Position() const { return i_; } + + void Reset() { i_ = 0; } + + void Seek(size_t a) { i_ = a; } + + uint32 Flags() const { + return kArcValueFlags; + } + + void SetFlags(uint32 flags, uint32 mask) {} + + private: + const State *state_; + size_t i_; + + DISALLOW_COPY_AND_ASSIGN(CacheArcIterator); +}; + +// Use this to make a mutable arc iterator for a CacheBaseImpl-derived Fst, +// which must have types 'Arc' and 'State' defined. +template > > +class CacheMutableArcIterator + : public MutableArcIteratorBase { + public: + typedef typename F::State State; + typedef typename F::Arc Arc; + typedef typename Arc::StateId StateId; + typedef typename Arc::Weight Weight; + typedef CacheBaseImpl Impl; + + // You will need to call MutateCheck() in the constructor. + CacheMutableArcIterator(Impl *impl, StateId s) : i_(0), s_(s), impl_(impl) { + state_ = impl_->ExtendState(s_); + ++state_->ref_count; + }; + + ~CacheMutableArcIterator() { + --state_->ref_count; + } + + bool Done() const { return i_ >= state_->arcs.size(); } + + const Arc& Value() const { return state_->arcs[i_]; } + + void Next() { ++i_; } + + size_t Position() const { return i_; } + + void Reset() { i_ = 0; } + + void Seek(size_t a) { i_ = a; } + + void SetValue(const Arc& arc) { + state_->flags |= CacheBaseImpl::kCacheModified; + uint64 properties = impl_->Properties(); + Arc& oarc = state_->arcs[i_]; + if (oarc.ilabel != oarc.olabel) + properties &= ~kNotAcceptor; + if (oarc.ilabel == 0) { + --state_->niepsilons; + properties &= ~kIEpsilons; + if (oarc.olabel == 0) + properties &= ~kEpsilons; + } + if (oarc.olabel == 0) { + --state_->noepsilons; + properties &= ~kOEpsilons; + } + if (oarc.weight != Weight::Zero() && oarc.weight != Weight::One()) + properties &= ~kWeighted; + oarc = arc; + if (arc.ilabel != arc.olabel) { + properties |= kNotAcceptor; + properties &= ~kAcceptor; + } + if (arc.ilabel == 0) { + ++state_->niepsilons; + properties |= kIEpsilons; + properties &= ~kNoIEpsilons; + if (arc.olabel == 0) { + properties |= kEpsilons; + properties &= ~kNoEpsilons; + } + } + if (arc.olabel == 0) { + ++state_->noepsilons; + properties |= kOEpsilons; + properties &= ~kNoOEpsilons; + } + if (arc.weight != Weight::Zero() && arc.weight != Weight::One()) { + properties |= kWeighted; + properties &= ~kUnweighted; + } + properties &= kSetArcProperties | kAcceptor | kNotAcceptor | + kEpsilons | kNoEpsilons | kIEpsilons | kNoIEpsilons | + kOEpsilons | kNoOEpsilons | kWeighted | kUnweighted; + impl_->SetProperties(properties); + } + + uint32 Flags() const { + return kArcValueFlags; + } + + void SetFlags(uint32 f, uint32 m) {} + + private: + virtual bool Done_() const { return Done(); } + virtual const Arc& Value_() const { return Value(); } + virtual void Next_() { Next(); } + virtual size_t Position_() const { return Position(); } + virtual void Reset_() { Reset(); } + virtual void Seek_(size_t a) { Seek(a); } + virtual void SetValue_(const Arc &a) { SetValue(a); } + uint32 Flags_() const { return Flags(); } + void SetFlags_(uint32 f, uint32 m) { SetFlags(f, m); } + + size_t i_; + StateId s_; + Impl *impl_; + State *state_; + + DISALLOW_COPY_AND_ASSIGN(CacheMutableArcIterator); +}; + +} // namespace fst + +#endif // FST_LIB_CACHE_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/closure.h b/kaldi_io/src/tools/openfst/include/fst/closure.h new file mode 100644 index 0000000..541562b --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/closure.h @@ -0,0 +1,155 @@ +// closure.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Functions and classes to compute the concatenative closure of an Fst. + +#ifndef FST_LIB_CLOSURE_H__ +#define FST_LIB_CLOSURE_H__ + +#include +using std::vector; +#include + +#include +#include + + +namespace fst { + +// Computes the concatenative closure. This version modifies its +// MutableFst input. If FST transduces string x to y with weight a, +// then the closure transduces x to y with weight a, xx to yy with +// weight Times(a, a), xxx to yyy with with Times(Times(a, a), a), +// etc. If closure_type == CLOSURE_STAR, then the empty string is +// transduced to itself with weight Weight::One() as well. +// +// Complexity: +// - Time: O(V) +// - Space: O(V) +// where V = # of states. +template +void Closure(MutableFst *fst, ClosureType closure_type) { + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + + uint64 props = fst->Properties(kFstProperties, false); + StateId start = fst->Start(); + for (StateIterator< MutableFst > siter(*fst); + !siter.Done(); + siter.Next()) { + StateId s = siter.Value(); + Weight final = fst->Final(s); + if (final != Weight::Zero()) + fst->AddArc(s, Arc(0, 0, final, start)); + } + if (closure_type == CLOSURE_STAR) { + fst->ReserveStates(fst->NumStates() + 1); + StateId nstart = fst->AddState(); + fst->SetStart(nstart); + fst->SetFinal(nstart, Weight::One()); + if (start != kNoLabel) + fst->AddArc(nstart, Arc(0, 0, Weight::One(), start)); + } + fst->SetProperties(ClosureProperties(props, closure_type == CLOSURE_STAR), + kFstProperties); +} + +// Computes the concatenative closure. This version modifies its +// RationalFst input. +template +void Closure(RationalFst *fst, ClosureType closure_type) { + fst->GetImpl()->AddClosure(closure_type); +} + + +struct ClosureFstOptions : RationalFstOptions { + ClosureType type; + + ClosureFstOptions(const RationalFstOptions &opts, ClosureType t) + : RationalFstOptions(opts), type(t) {} + explicit ClosureFstOptions(ClosureType t) : type(t) {} + ClosureFstOptions() : type(CLOSURE_STAR) {} +}; + + +// Computes the concatenative closure. This version is a delayed +// Fst. If FST transduces string x to y with weight a, then the +// closure transduces x to y with weight a, xx to yy with weight +// Times(a, a), xxx to yyy with weight Times(Times(a, a), a), etc. If +// closure_type == CLOSURE_STAR, then The empty string is transduced +// to itself with weight Weight::One() as well. +// +// Complexity: +// - Time: O(v) +// - Space: O(v) +// where v = # of states visited. Constant time and space to visit an +// input state or arc is assumed and exclusive of caching. +template +class ClosureFst : public RationalFst { + public: + using ImplToFst< RationalFstImpl >::GetImpl; + + typedef A Arc; + + ClosureFst(const Fst &fst, ClosureType closure_type) { + GetImpl()->InitClosure(fst, closure_type); + } + + ClosureFst(const Fst &fst, const ClosureFstOptions &opts) + : RationalFst(opts) { + GetImpl()->InitClosure(fst, opts.type); + } + + // See Fst<>::Copy() for doc. + ClosureFst(const ClosureFst &fst, bool safe = false) + : RationalFst(fst, safe) {} + + // Get a copy of this ClosureFst. See Fst<>::Copy() for further doc. + virtual ClosureFst *Copy(bool safe = false) const { + return new ClosureFst(*this, safe); + } +}; + + +// Specialization for ClosureFst. +template +class StateIterator< ClosureFst > : public StateIterator< RationalFst > { + public: + explicit StateIterator(const ClosureFst &fst) + : StateIterator< RationalFst >(fst) {} +}; + + +// Specialization for ClosureFst. +template +class ArcIterator< ClosureFst > : public ArcIterator< RationalFst > { + public: + typedef typename A::StateId StateId; + + ArcIterator(const ClosureFst &fst, StateId s) + : ArcIterator< RationalFst >(fst, s) {} +}; + + +// Useful alias when using StdArc. +typedef ClosureFst StdClosureFst; + +} // namespace fst + +#endif // FST_LIB_CLOSURE_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/compact-fst.h b/kaldi_io/src/tools/openfst/include/fst/compact-fst.h new file mode 100644 index 0000000..6db3317 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/compact-fst.h @@ -0,0 +1,1438 @@ +// compact-fst.h + + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: allauzen@google.com (Cyril Allauzen) +// +// \file +// FST Class for memory-efficient representation of common types of +// FSTs: linear automata, acceptors, unweighted FSTs, ... + +#ifndef FST_LIB_COMPACT_FST_H__ +#define FST_LIB_COMPACT_FST_H__ + +#include +#include +using std::pair; using std::make_pair; +#include +using std::vector; + +#include +#include +#include // For optional argument declarations +#include +#include +#include +#include + + +namespace fst { + +struct CompactFstOptions : public CacheOptions { + // CompactFst default caching behaviour is to do no caching. Most + // compactors are cheap and therefore we save memory by not doing + // caching. + CompactFstOptions() : CacheOptions(true, 0) {} + CompactFstOptions(const CacheOptions &opts) : CacheOptions(opts) {} +}; + +// Compactor Interface - class determinies how arcs and final weights +// are compacted and expanded. +// +// Final weights are treated as transitions to the superfinal state, +// i.e. ilabel = olabel = kNoLabel and nextstate = kNoStateId. +// +// There are two types of compactors: +// +// * Fixed out-degree compactors: 'compactor.Size()' returns a +// positive integer 's'. An FST can be compacted by this compactor +// only if each state has exactly 's' outgoing transitions (counting a +// non-Zero() final weight as a transition). A typical example is a +// compactor for string FSTs, i.e. 's == 1'. +// +// * Variable out-degree compactors: 'compactor.Size() == -1'. There +// are no out-degree restrictions for these compactors. +// +// +// class Compactor { +// public: +// // Element is the type of the compacted transitions. +// typedef ... Element; +// // Return the compacted representation of a transition 'arc' +// // at a state 's'. +// Element Compact(StateId s, const Arc &arc); +// // Return the transition at state 's' represented by the compacted +// // transition 'e'. +// Arc Expand(StateId s, const Element &e); +// // Return -1 for variable out-degree compactors, and the mandatory +// // out-degree otherwise. +// ssize_t Size(); +// // Test whether 'fst' can be compacted by this compactor. +// bool Compatible(const Fst &fst); +// // Return the properties that are always true for an fst +// // compacted using this compactor +// uint64 Properties(); +// // Return a string identifying the type of compactor. +// static const string &Type(); +// // Write a compactor to a file. +// bool Write(ostream &strm); +// // Read a compactor from a file. +// static Compactor *Read(istream &strm); +// // Default constructor (optional, see comment below). +// Compactor(); +// }; +// +// The default constructor is only required for FST_REGISTER to work +// (i.e. enabling Convert() and the command-line utilities to work +// with this new compactor). However, a default constructor always +// needs to be specify for this code to compile, but one can have it +// simply raised an error when called: +// +// Compactor::Compactor() { +// FSTERROR() << "Compactor: no default constructor"; +// } + + +// Implementation data for Compact Fst, which can shared between otherwise +// independent copies. +// +// The implementation contains two arrays: 'states_' and 'compacts_'. +// +// For fixed out-degree compactors, the 'states_' array is unallocated. +// The 'compacts_' contains the compacted transitions. Its size is +// 'ncompacts_'. The outgoing transitions at a given state are stored +// consecutively. For a given state 's', its 'compactor.Size()' outgoing +// transitions (including superfinal transition when 's' is final), are +// stored in position ['s*compactor.Size()', '(s+1)*compactor_.Size()'). +// +// For variable out-degree compactors, the states_ array has size +// 'nstates_ + 1' and contains pointers to positions into 'compacts_'. +// For a given state 's', the compacted transitions of 's' are +// stored in positions [ 'states_[s]', 'states_[s + 1]' ) in 'compacts_'. +// By convention, 'states_[nstates_] == ncompacts_'. +// +// In both cases, the superfinal transitons (when 's' is final, i.e. +// 'Final(s) != Weight::Zero()') is stored first. +// +// The unsigned type U is used to represent indices into the compacts_ +// array. +template +class CompactFstData { + public: + typedef E CompactElement; + typedef U Unsigned; + + CompactFstData() + : states_region_(0), + compacts_region_(0), + states_(0), + compacts_(0), + nstates_(0), + ncompacts_(0), + narcs_(0), + start_(kNoStateId), + error_(false) {} + + template + CompactFstData(const Fst &fst, const Compactor &compactor); + + template + CompactFstData(const Iterator &begin, const Iterator &end, + const Compactor &compactor); + + ~CompactFstData() { + if (states_region_ == NULL) { + delete [] states_; + } + delete states_region_; + if (compacts_region_ == NULL) { + delete [] compacts_; + } + delete compacts_region_; + } + + template + static CompactFstData *Read(istream &strm, + const FstReadOptions &opts, + const FstHeader &hdr, + const Compactor &compactor); + + bool Write(ostream &strm, const FstWriteOptions &opts) const; + + Unsigned States(ssize_t i) const { return states_[i]; } + const CompactElement &Compacts(size_t i) const { return compacts_[i]; } + size_t NumStates() const { return nstates_; } + size_t NumCompacts() const { return ncompacts_; } + size_t NumArcs() const { return narcs_; } + ssize_t Start() const { return start_; } + + int RefCount() const { return ref_count_.count(); } + int IncrRefCount() { return ref_count_.Incr(); } + int DecrRefCount() { return ref_count_.Decr(); } + + bool Error() const { return error_; } + + private: + MappedFile *states_region_; + MappedFile *compacts_region_; + Unsigned *states_; + CompactElement *compacts_; + size_t nstates_; + size_t ncompacts_; + size_t narcs_; + ssize_t start_; + RefCounter ref_count_; + bool error_; +}; + +template +template +CompactFstData::CompactFstData(const Fst &fst, const C &compactor) + : states_region_(0), + compacts_region_(0), + states_(0), + compacts_(0), + nstates_(0), + ncompacts_(0), + narcs_(0), + start_(kNoStateId), + error_(false) { + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + start_ = fst.Start(); + // Count # of states and arcs. + StateId nfinals = 0; + for (StateIterator< Fst > siter(fst); + !siter.Done(); + siter.Next()) { + ++nstates_; + StateId s = siter.Value(); + for (ArcIterator< Fst > aiter(fst, s); + !aiter.Done(); + aiter.Next()) + ++narcs_; + if (fst.Final(s) != Weight::Zero()) ++nfinals; + } + if (compactor.Size() == -1) { + states_ = new Unsigned[nstates_ + 1]; + ncompacts_ = narcs_ + nfinals; + compacts_ = new CompactElement[ncompacts_]; + states_[nstates_] = ncompacts_; + } else { + states_ = 0; + ncompacts_ = nstates_ * compactor.Size(); + if ((narcs_ + nfinals) != ncompacts_) { + FSTERROR() << "CompactFstData: compactor incompatible with fst"; + error_ = true; + return; + } + compacts_ = new CompactElement[ncompacts_]; + } + size_t pos = 0, fpos = 0; + for (StateId s = 0; s < nstates_; ++s) { + fpos = pos; + if (compactor.Size() == -1) + states_[s] = pos; + if (fst.Final(s) != Weight::Zero()) + compacts_[pos++] = compactor.Compact(s, A(kNoLabel, kNoLabel, + fst.Final(s), kNoStateId)); + for (ArcIterator< Fst > aiter(fst, s); + !aiter.Done(); + aiter.Next()) { + compacts_[pos++] = compactor.Compact(s, aiter.Value()); + } + if ((compactor.Size() != -1) && ((pos - fpos) != compactor.Size())) { + FSTERROR() << "CompactFstData: compactor incompatible with fst"; + error_ = true; + return; + } + } + if (pos != ncompacts_) { + FSTERROR() << "CompactFstData: compactor incompatible with fst"; + error_ = true; + return; + } +} + +template +template +CompactFstData::CompactFstData(const Iterator &begin, + const Iterator &end, + const C &compactor) + : states_region_(0), + compacts_region_(0), + states_(0), + compacts_(0), + nstates_(0), + ncompacts_(0), + narcs_(0), + start_(kNoStateId), + error_(false) { + typedef typename C::Arc Arc; + typedef typename Arc::Weight Weight; + if (compactor.Size() != -1) { + ncompacts_ = distance(begin, end); + if (compactor.Size() == 1) { + // For strings, allow implicit final weight. + // Empty input is the empty string. + if (ncompacts_ == 0) { + ++ncompacts_; + } else { + Arc arc = compactor.Expand(ncompacts_ - 1, + *(begin + (ncompacts_ - 1))); + if (arc.ilabel != kNoLabel) + ++ncompacts_; + } + } + if (ncompacts_ % compactor.Size()) { + FSTERROR() << "CompactFstData: size of input container incompatible" + << " with compactor"; + error_ = true; + return; + } + if (ncompacts_ == 0) + return; + start_ = 0; + nstates_ = ncompacts_ / compactor.Size(); + compacts_ = new CompactElement[ncompacts_]; + size_t i = 0; + Iterator it = begin; + for(; it != end; ++it, ++i){ + compacts_[i] = *it; + if (compactor.Expand(i, *it).ilabel != kNoLabel) + ++narcs_; + } + if (i < ncompacts_) + compacts_[i] = compactor.Compact(i, Arc(kNoLabel, kNoLabel, + Weight::One(), kNoStateId)); + } else { + if (distance(begin, end) == 0) + return; + // Count # of states, arcs and compacts. + Iterator it = begin; + for(size_t i = 0; it != end; ++it, ++i) { + Arc arc = compactor.Expand(i, *it); + if (arc.ilabel != kNoLabel) { + ++narcs_; + ++ncompacts_; + } else { + ++nstates_; + if (arc.weight != Weight::Zero()) + ++ncompacts_; + } + } + start_ = 0; + compacts_ = new CompactElement[ncompacts_]; + states_ = new Unsigned[nstates_ + 1]; + states_[nstates_] = ncompacts_; + size_t i = 0, s = 0; + for(it = begin; it != end; ++it) { + Arc arc = compactor.Expand(i, *it); + if (arc.ilabel != kNoLabel) { + compacts_[i++] = *it; + } else { + states_[s++] = i; + if (arc.weight != Weight::Zero()) + compacts_[i++] = *it; + } + } + if ((s != nstates_) || (i != ncompacts_)) { + FSTERROR() << "CompactFstData: ill-formed input container"; + error_ = true; + return; + } + } +} + +template +template +CompactFstData *CompactFstData::Read( + istream &strm, + const FstReadOptions &opts, + const FstHeader &hdr, + const C &compactor) { + CompactFstData *data = new CompactFstData(); + data->start_ = hdr.Start(); + data->nstates_ = hdr.NumStates(); + data->narcs_ = hdr.NumArcs(); + + if (compactor.Size() == -1) { + if ((hdr.GetFlags() & FstHeader::IS_ALIGNED) && !AlignInput(strm)) { + LOG(ERROR) << "CompactFst::Read: Alignment failed: " << opts.source; + delete data; + return 0; + } + size_t b = (data->nstates_ + 1) * sizeof(Unsigned); + data->states_region_ = MappedFile::Map(&strm, opts, b); + if (!strm || data->states_region_ == NULL) { + LOG(ERROR) << "CompactFst::Read: Read failed: " << opts.source; + delete data; + return 0; + } + data->states_ = static_cast( + data->states_region_->mutable_data()); + } else { + data->states_ = 0; + } + data->ncompacts_ = compactor.Size() == -1 + ? data->states_[data->nstates_] + : data->nstates_ * compactor.Size(); + if ((hdr.GetFlags() & FstHeader::IS_ALIGNED) && !AlignInput(strm)) { + LOG(ERROR) << "CompactFst::Read: Alignment failed: " << opts.source; + delete data; + return 0; + } + size_t b = data->ncompacts_ * sizeof(CompactElement); + data->compacts_region_ = MappedFile::Map(&strm, opts, b); + if (!strm || data->compacts_region_ == NULL) { + LOG(ERROR) << "CompactFst::Read: Read failed: " << opts.source; + delete data; + return 0; + } + data->compacts_ = static_cast( + data->compacts_region_->mutable_data()); + return data; +} + +template +bool CompactFstData::Write(ostream &strm, + const FstWriteOptions &opts) const { + if (states_) { + if (opts.align && !AlignOutput(strm)) { + LOG(ERROR) << "CompactFst::Write: Alignment failed: " << opts.source; + return false; + } + strm.write(reinterpret_cast(states_), + (nstates_ + 1) * sizeof(Unsigned)); + } + if (opts.align && !AlignOutput(strm)) { + LOG(ERROR) << "CompactFst::Write: Alignment failed: " << opts.source; + return false; + } + strm.write(reinterpret_cast(compacts_), + ncompacts_ * sizeof(CompactElement)); + + strm.flush(); + if (!strm) { + LOG(ERROR) << "CompactFst::Write: Write failed: " << opts.source; + return false; + } + return true; +} + +template class CompactFst; +template void Cast(const F &, G *); + +// Implementation class for CompactFst, which contains CompactFstData +// and Fst cache. +template +class CompactFstImpl : public CacheImpl { + public: + using FstImpl::SetType; + using FstImpl::SetProperties; + using FstImpl::Properties; + using FstImpl::SetInputSymbols; + using FstImpl::SetOutputSymbols; + using FstImpl::WriteHeader; + + using CacheImpl::PushArc; + using CacheImpl::HasArcs; + using CacheImpl::HasFinal; + using CacheImpl::HasStart; + using CacheImpl::SetArcs; + using CacheImpl::SetFinal; + using CacheImpl::SetStart; + + typedef A Arc; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + typedef C Compactor; + typedef typename C::Element CompactElement; + typedef U Unsigned; + + CompactFstImpl() + : CacheImpl(CompactFstOptions()), + compactor_(0), + own_compactor_(false), + data_(0) { + string type = "compact"; + if (sizeof(U) != sizeof(uint32)) { + string size; + Int64ToStr(8 * sizeof(U), &size); + type += size; + } + type += "_"; + type += C::Type(); + SetType(type); + SetProperties(kNullProperties | kStaticProperties); + } + + CompactFstImpl(const Fst &fst, const C &compactor, + const CompactFstOptions &opts) + : CacheImpl(opts), + compactor_(new C(compactor)), + own_compactor_(true), + data_(0) { + Init(fst); + } + + CompactFstImpl(const Fst &fst, C *compactor, + const CompactFstOptions &opts) + : CacheImpl(opts), + compactor_(compactor), + own_compactor_(false), + data_(0) { + Init(fst); + } + + template + CompactFstImpl(const Iterator &b, const Iterator &e, const C &compactor, + const CompactFstOptions &opts) + : CacheImpl(opts), + compactor_(new C(compactor)), + own_compactor_(true), + data_(0) { + Init(b, e); + } + + template + CompactFstImpl(const Iterator &b, const Iterator &e, C *compactor, + const CompactFstOptions &opts) + : CacheImpl(opts), + compactor_(compactor), + own_compactor_(false), + data_(0) { + Init(b, e); + } + + CompactFstImpl(const CompactFstImpl &impl) + : CacheImpl(impl), + compactor_(new C(*impl.compactor_)), + own_compactor_(true), + data_(impl.data_) { + if (data_) + data_->IncrRefCount(); + SetType(impl.Type()); + SetProperties(impl.Properties()); + SetInputSymbols(impl.InputSymbols()); + SetOutputSymbols(impl.OutputSymbols()); + } + + ~CompactFstImpl(){ + if (own_compactor_) + delete compactor_; + if (data_ && !data_->DecrRefCount()) + delete data_; + } + + StateId Start() { + if (!HasStart()) { + SetStart(data_->Start()); + } + return CacheImpl::Start(); + } + + Weight Final(StateId s) { + if (HasFinal(s)) + return CacheImpl::Final(s); + Arc arc(kNoLabel, kNoLabel, Weight::Zero(), kNoStateId); + if ((compactor_->Size() != -1) || + (data_->States(s) != data_->States(s + 1))) + arc = ComputeArc(s, + compactor_->Size() == -1 + ? data_->States(s) + : s * compactor_->Size()); + return arc.ilabel == kNoLabel ? arc.weight : Weight::Zero(); + } + + StateId NumStates() const { + if (Properties(kError)) return 0; + return data_->NumStates(); + } + + size_t NumArcs(StateId s) { + if (HasArcs(s)) + return CacheImpl::NumArcs(s); + Unsigned i, num_arcs; + if (compactor_->Size() == -1) { + i = data_->States(s); + num_arcs = data_->States(s + 1) - i; + } else { + i = s * compactor_->Size(); + num_arcs = compactor_->Size(); + } + if (num_arcs > 0) { + const A &arc = ComputeArc(s, i, kArcILabelValue); + if (arc.ilabel == kNoStateId) { + --num_arcs; + } + } + return num_arcs; + } + + size_t NumInputEpsilons(StateId s) { + if (!HasArcs(s) && !Properties(kILabelSorted)) + Expand(s); + if (HasArcs(s)) + return CacheImpl::NumInputEpsilons(s); + return CountEpsilons(s, false); + } + + size_t NumOutputEpsilons(StateId s) { + if (!HasArcs(s) && !Properties(kOLabelSorted)) + Expand(s); + if (HasArcs(s)) + return CacheImpl::NumOutputEpsilons(s); + return CountEpsilons(s, true); + } + + size_t CountEpsilons(StateId s, bool output_epsilons) { + size_t begin = compactor_->Size() == -1 ? + data_->States(s) : s * compactor_->Size(); + size_t end = compactor_->Size() == -1 ? + data_->States(s + 1) : (s + 1) * compactor_->Size(); + size_t num_eps = 0; + for (size_t i = begin; i < end; ++i) { + const A &arc = ComputeArc( + s, i, output_epsilons ? kArcOLabelValue : kArcILabelValue); + const typename A::Label &label = + (output_epsilons ? arc.olabel : arc.ilabel); + if (label == kNoLabel) + continue; + else if (label > 0) + break; + ++num_eps; + } + return num_eps; + } + + static CompactFstImpl *Read(istream &strm, + const FstReadOptions &opts) { + CompactFstImpl *impl = new CompactFstImpl(); + FstHeader hdr; + if (!impl->ReadHeader(strm, opts, kMinFileVersion, &hdr)) { + delete impl; + return 0; + } + + // Ensures compatibility + if (hdr.Version() == kAlignedFileVersion) + hdr.SetFlags(hdr.GetFlags() | FstHeader::IS_ALIGNED); + + impl->compactor_ = C::Read(strm); + if (!impl->compactor_) { + delete impl; + return 0; + } + impl->own_compactor_ = true; + impl->data_ = CompactFstData::Read(strm, opts, hdr, + *impl->compactor_); + if (!impl->data_) { + delete impl; + return 0; + } + return impl; + } + + bool Write(ostream &strm, const FstWriteOptions &opts) const { + FstHeader hdr; + hdr.SetStart(data_->Start()); + hdr.SetNumStates(data_->NumStates()); + hdr.SetNumArcs(data_->NumArcs()); + + // Ensures compatibility + int file_version = opts.align ? kAlignedFileVersion : kFileVersion; + WriteHeader(strm, opts, file_version, &hdr); + compactor_->Write(strm); + return data_->Write(strm, opts); + } + + // Provide information needed for generic state iterator + void InitStateIterator(StateIteratorData *data) const { + data->base = 0; + data->nstates = data_->NumStates(); + } + + void InitArcIterator(StateId s, ArcIteratorData *data) { + if (!HasArcs(s)) + Expand(s); + CacheImpl::InitArcIterator(s, data); + } + + Arc ComputeArc(StateId s, Unsigned i, uint32 f = kArcValueFlags) const { + return compactor_->Expand(s, data_->Compacts(i), f); + } + + void Expand(StateId s) { + size_t begin = compactor_->Size() == -1 ? + data_->States(s) : s * compactor_->Size(); + size_t end = compactor_->Size() == -1 ? + data_->States(s + 1) : (s + 1) * compactor_->Size(); + for (size_t i = begin; i < end; ++i) { + const Arc &arc = ComputeArc(s, i); + if (arc.ilabel == kNoLabel) + SetFinal(s, arc.weight); + else + PushArc(s, arc); + } + if (!HasFinal(s)) + SetFinal(s, Weight::Zero()); + SetArcs(s); + } + + template + void SetCompactElements(const Iterator &b, const Iterator &e) { + if (data_ && !data_->DecrRefCount()) + delete data_; + data_ = new CompactFstData(b, e, *compactor_); + } + + C *GetCompactor() const { return compactor_; } + CompactFstData *Data() const { return data_; } + + // Properties always true of this Fst class + static const uint64 kStaticProperties = kExpanded; + + protected: + template + explicit CompactFstImpl(const CompactFstImpl &impl) + : CacheImpl(CacheOptions(impl.GetCacheGc(), impl.GetCacheLimit())), + compactor_(new C(*impl.GetCompactor())), + own_compactor_(true), + data_(impl.Data()) { + if (data_) + data_->IncrRefCount(); + SetType(impl.Type()); + SetProperties(impl.Properties()); + SetInputSymbols(impl.InputSymbols()); + SetOutputSymbols(impl.OutputSymbols()); + } + + private: + friend class CompactFst; // allow access during write. + + void Init(const Fst &fst) { + string type = "compact"; + if (sizeof(U) != sizeof(uint32)) { + string size; + Int64ToStr(8 * sizeof(U), &size); + type += size; + } + type += "_"; + type += compactor_->Type(); + SetType(type); + SetInputSymbols(fst.InputSymbols()); + SetOutputSymbols(fst.OutputSymbols()); + data_ = new CompactFstData(fst, *compactor_); + if (data_->Error()) + SetProperties(kError, kError); + uint64 copy_properties = fst.Properties(kCopyProperties, true); + if ((copy_properties & kError) || !compactor_->Compatible(fst)) { + FSTERROR() << "CompactFstImpl: input fst incompatible with compactor"; + SetProperties(kError, kError); + return; + } + SetProperties(copy_properties | kStaticProperties); + } + + template + void Init(const Iterator &b, const Iterator &e) { + string type = "compact"; + if (sizeof(U) != sizeof(uint32)) { + string size; + Int64ToStr(8 * sizeof(U), &size); + type += size; + } + type += "_"; + type += compactor_->Type(); + SetType(type); + SetProperties(kStaticProperties | compactor_->Properties()); + data_ = new CompactFstData(b, e, *compactor_); + if (data_->Error()) + SetProperties(kError, kError); + } + + // Current unaligned file format version + static const int kFileVersion = 2; + // Current aligned file format version + static const int kAlignedFileVersion = 1; + // Minimum file format version supported + static const int kMinFileVersion = 1; + + C *compactor_; + bool own_compactor_; + CompactFstData *data_; +}; + +template +const uint64 CompactFstImpl::kStaticProperties; +template +const int CompactFstImpl::kFileVersion; +template +const int CompactFstImpl::kAlignedFileVersion; +template +const int CompactFstImpl::kMinFileVersion; + + +// CompactFst. This class attaches interface to implementation and +// handles reference counting, delegating most methods to +// ImplToExpandedFst. The unsigned type U is used to represent indices +// into the compact arc array (uint32 by default, declared in +// fst-decl.h). +template +class CompactFst : public ImplToExpandedFst< CompactFstImpl > { + public: + friend class StateIterator< CompactFst >; + friend class ArcIterator< CompactFst >; + template void friend Cast(const F &, G *); + + typedef A Arc; + typedef typename A::StateId StateId; + typedef CompactFstImpl Impl; + typedef CacheState State; + typedef U Unsigned; + + CompactFst() : ImplToExpandedFst(new Impl()) {} + + explicit CompactFst(const Fst &fst, const C &compactor = C(), + const CompactFstOptions &opts = CompactFstOptions()) + : ImplToExpandedFst(new Impl(fst, compactor, opts)) {} + + CompactFst(const Fst &fst, C *compactor, + const CompactFstOptions &opts = CompactFstOptions()) + : ImplToExpandedFst(new Impl(fst, compactor, opts)) {} + + // The following 2 constructors take as input two iterators delimiting + // a set of (already) compacted transitions, starting with the + // transitions out of the initial state. The format of the input + // differs for fixed out-degree and variable out-degree compactors. + // + // - For fixed out-degree compactors, the final weight (encoded as a + // compacted transition) needs to be given only for final + // states. All strings (compactor of size 1) will be assume to be + // terminated by a final state even when the final state is not + // implicitely given. + // + // - For variable out-degree compactors, the final weight (encoded + // as a compacted transition) needs to be given for all states and + // must appeared first in the list (for state s, final weight of s, + // followed by outgoing transitons in s). + // + // These 2 constructors allows the direct construction of a CompactFst + // without first creating a more memory hungry 'regular' FST. This + // is useful when memory usage is severely constrained. + template + explicit CompactFst(const Iterator &begin, const Iterator &end, + const C &compactor = C(), + const CompactFstOptions &opts = CompactFstOptions()) + : ImplToExpandedFst(new Impl(begin, end, compactor, opts)) {} + + template + CompactFst(const Iterator &begin, const Iterator &end, + C *compactor, const CompactFstOptions &opts = CompactFstOptions()) + : ImplToExpandedFst(new Impl(begin, end, compactor, opts)) {} + + // See Fst<>::Copy() for doc. + CompactFst(const CompactFst &fst, bool safe = false) + : ImplToExpandedFst(fst, safe) {} + + // Get a copy of this CompactFst. See Fst<>::Copy() for further doc. + virtual CompactFst *Copy(bool safe = false) const { + return new CompactFst(*this, safe); + } + + // Read a CompactFst from an input stream; return NULL on error + static CompactFst *Read(istream &strm, const FstReadOptions &opts) { + Impl* impl = Impl::Read(strm, opts); + return impl ? new CompactFst(impl) : 0; + } + + // Read a CompactFst from a file; return NULL on error + // Empty filename reads from standard input + static CompactFst *Read(const string &filename) { + Impl* impl = ImplToExpandedFst::Read(filename); + return impl ? new CompactFst(impl) : 0; + } + + virtual bool Write(ostream &strm, const FstWriteOptions &opts) const { + return GetImpl()->Write(strm, opts); + } + + virtual bool Write(const string &filename) const { + return Fst::WriteFile(filename); + } + + template + static bool WriteFst(const F &fst, const C &compactor, ostream &strm, + const FstWriteOptions &opts); + + virtual void InitStateIterator(StateIteratorData *data) const { + GetImpl()->InitStateIterator(data); + } + + virtual void InitArcIterator(StateId s, ArcIteratorData *data) const { + GetImpl()->InitArcIterator(s, data); + } + + virtual MatcherBase *InitMatcher(MatchType match_type) const { + return new SortedMatcher >(*this, match_type); + } + + template + void SetCompactElements(const Iterator &b, const Iterator &e) { + GetImpl()->SetCompactElements(b, e); + } + + private: + CompactFst(Impl *impl) : ImplToExpandedFst(impl) {} + + // Makes visible to friends. + Impl *GetImpl() const { return ImplToFst >::GetImpl(); } + + void SetImpl(Impl *impl, bool own_impl = false) { + ImplToFst< Impl, ExpandedFst >::SetImpl(impl, own_impl); + } + + // Use overloading to extract the type of the argument. + static Impl* GetImplIfCompactFst(const CompactFst &compact_fst) { + return compact_fst.GetImpl(); + } + + // This does not give privileged treatment to subclasses of CompactFst. + template + static Impl* GetImplIfCompactFst(const NonCompactFst& fst) { + return NULL; + } + + void operator=(const CompactFst &fst); // disallow +}; + +// Writes Fst in Compact format, potentially with a pass over the machine +// before writing to compute the number of states and arcs. +// +template +template +bool CompactFst::WriteFst(const F &fst, + const C &compactor, + ostream &strm, + const FstWriteOptions &opts) { + typedef U Unsigned; + typedef typename C::Element CompactElement; + typedef typename A::Weight Weight; + int file_version = opts.align ? + CompactFstImpl::kAlignedFileVersion : + CompactFstImpl::kFileVersion; + size_t num_arcs = -1, num_states = -1, num_compacts = -1; + C first_pass_compactor = compactor; + if (Impl* impl = GetImplIfCompactFst(fst)) { + num_arcs = impl->Data()->NumArcs(); + num_states = impl->Data()->NumStates(); + num_compacts = impl->Data()->NumCompacts(); + first_pass_compactor = *impl->GetCompactor(); + } else { + // A first pass is needed to compute the state of the compactor, which + // is saved ahead of the rest of the data structures. This unfortunately + // means forcing a complete double compaction when writing in this format. + // TODO(allauzen): eliminate mutable state from compactors. + num_arcs = 0; + num_states = 0; + for (StateIterator siter(fst); !siter.Done(); siter.Next()) { + const StateId s = siter.Value(); + ++num_states; + if (fst.Final(s) != Weight::Zero()) { + first_pass_compactor.Compact( + s, A(kNoLabel, kNoLabel, fst.Final(s), kNoStateId)); + } + for (ArcIterator aiter(fst, s); !aiter.Done(); aiter.Next()) { + ++num_arcs; + first_pass_compactor.Compact(s, aiter.Value()); + } + } + } + FstHeader hdr; + hdr.SetStart(fst.Start()); + hdr.SetNumStates(num_states); + hdr.SetNumArcs(num_arcs); + string type = "compact"; + if (sizeof(U) != sizeof(uint32)) { + string size; + Int64ToStr(8 * sizeof(U), &size); + type += size; + } + type += "_"; + type += C::Type(); + uint64 copy_properties = fst.Properties(kCopyProperties, true); + if ((copy_properties & kError) || !compactor.Compatible(fst)) { + LOG(ERROR) << "fst incompatible with compactor"; + return false; + } + uint64 properties = copy_properties | + CompactFstImpl::kStaticProperties; + FstImpl::WriteFstHeader(fst, strm, opts, file_version, type, properties, + &hdr); + first_pass_compactor.Write(strm); + if (first_pass_compactor.Size() == -1) { + if (opts.align && !AlignOutput(strm)) { + LOG(ERROR) << "CompactFst::Write: Alignment failed: " << opts.source; + return false; + } + Unsigned compacts = 0; + for (StateIterator siter(fst); !siter.Done(); siter.Next()) { + const StateId s = siter.Value(); + strm.write(reinterpret_cast(&compacts), sizeof(compacts)); + if (fst.Final(s) != Weight::Zero()) { + ++compacts; + } + compacts += fst.NumArcs(s); + } + strm.write(reinterpret_cast(&compacts), sizeof(compacts)); + } + if (opts.align && !AlignOutput(strm)) { + LOG(ERROR) << "Could not align file during write after writing states"; + } + C second_pass_compactor = compactor; + CompactElement element; + for (StateIterator siter(fst); !siter.Done(); siter.Next()) { + const StateId s = siter.Value(); + if (fst.Final(s) != Weight::Zero()) { + element = second_pass_compactor.Compact( + s, A(kNoLabel, kNoLabel, fst.Final(s), kNoStateId)); + strm.write(reinterpret_cast(&element), sizeof(element)); + } + for (ArcIterator aiter(fst, s); !aiter.Done(); aiter.Next()) { + element = second_pass_compactor.Compact(s, aiter.Value()); + strm.write(reinterpret_cast(&element), sizeof(element)); + } + } + strm.flush(); + if (!strm) { + LOG(ERROR) << "CompactFst write failed: " << opts.source; + return false; + } + return true; +} + + +// Specialization for CompactFst; see generic version in fst.h +// for sample usage (but use the CompactFst type!). This version +// should inline. +template +class StateIterator< CompactFst > { + public: + typedef typename A::StateId StateId; + + explicit StateIterator(const CompactFst &fst) + : nstates_(fst.GetImpl()->NumStates()), s_(0) {} + + bool Done() const { return s_ >= nstates_; } + + StateId Value() const { return s_; } + + void Next() { ++s_; } + + void Reset() { s_ = 0; } + + private: + StateId nstates_; + StateId s_; + + DISALLOW_COPY_AND_ASSIGN(StateIterator); +}; + +// Specialization for CompactFst. +// Never caches, always iterates over the underlying compact elements. +template +class ArcIterator< CompactFst > { + public: + typedef typename A::StateId StateId; + typedef typename C::Element CompactElement; + + ArcIterator(const CompactFst &fst, StateId s) + : compactor_(fst.GetImpl()->GetCompactor()), state_(s), compacts_(0), + pos_(0), flags_(kArcValueFlags) { + + const CompactFstData *data = fst.GetImpl()->Data(); + size_t offset; + if (compactor_->Size() == -1) { // Variable out-degree compactor + offset = data->States(s); + num_arcs_ = data->States(s + 1) - offset; + } else { // Fixed out-degree compactor + offset = s * compactor_->Size(); + num_arcs_ = compactor_->Size(); + } + if (num_arcs_ > 0) { + compacts_ = &(data->Compacts(offset)); + arc_ = compactor_->Expand(s, *compacts_, kArcILabelValue); + if (arc_.ilabel == kNoStateId) { + ++compacts_; + --num_arcs_; + } + } + } + + ~ArcIterator() {} + + bool Done() const { return pos_ >= num_arcs_; } + + const A& Value() const { + arc_ = compactor_->Expand(state_, compacts_[pos_], flags_); + return arc_; + } + + void Next() { ++pos_; } + + size_t Position() const { return pos_; } + + void Reset() { pos_ = 0; } + + void Seek(size_t pos) { pos_ = pos; } + + uint32 Flags() const { return flags_; } + + void SetFlags(uint32 f, uint32 m) { + flags_ &= ~m; + flags_ |= (f & kArcValueFlags); + } + + private: + C *compactor_; + StateId state_; + const CompactElement *compacts_; + size_t pos_; + size_t num_arcs_; + mutable A arc_; + uint32 flags_; + + DISALLOW_COPY_AND_ASSIGN(ArcIterator); +}; + +// // Specialization for CompactFst. +// // This is an optionally caching arc iterator. +// // TODO(allauzen): implements the kArcValueFlags, the current +// // implementation only implements the kArcNoCache flag. +// template +// class ArcIterator< CompactFst > { +// public: +// typedef typename A::StateId StateId; + +// ArcIterator(const CompactFst &fst, StateId s) +// : fst_(fst), state_(s), pos_(0), num_arcs_(0), offset_(0), +// flags_(kArcValueFlags) { +// cache_data_.ref_count = 0; + +// if (fst_.GetImpl()->HasArcs(state_)) { +// fst_.GetImpl()->InitArcIterator(s, &cache_data_); +// num_arcs_ = cache_data_.narcs; +// return; +// } + +// const C *compactor = fst_.GetImpl()->GetCompactor(); +// const CompactFstData *data = fst_.GetImpl()->Data(); +// if (compactor->Size() == -1) { // Variable out-degree compactor +// offset_ = data->States(s); +// num_arcs_ = data->States(s + 1) - offset_; +// } else { // Fixed out-degree compactor +// offset_ = s * compactor->Size(); +// num_arcs_ = compactor->Size(); +// } +// if (num_arcs_ > 0) { +// const A &arc = fst_.GetImpl()->ComputeArc(s, offset_); +// if (arc.ilabel == kNoStateId) { +// ++offset_; +// --num_arcs_; +// } +// } +// } + + +// ~ArcIterator() { +// if (cache_data_.ref_count) +// --(*cache_data_.ref_count); +// } + +// bool Done() const { return pos_ >= num_arcs_; } + +// const A& Value() const { +// if (cache_data_.ref_count == 0) { +// if (flags_ & kArcNoCache) { +// arc_ = fst_.GetImpl()->ComputeArc(state_, pos_ + offset_); +// return arc_; +// } else { +// fst_.GetImpl()->InitArcIterator(state_, &cache_data_); +// } +// } +// return cache_data_.arcs[pos_]; +// } + +// void Next() { ++pos_; } + +// size_t Position() const { return pos_; } + +// void Reset() { pos_ = 0; } + +// void Seek(size_t pos) { pos_ = pos; } + +// uint32 Flags() const { return flags_; } + +// void SetFlags(uint32 f, uint32 m) { +// flags_ &= ~m; +// flags_ |= f; + +// if (!(flags_ & kArcNoCache) && cache_data_.ref_count == 0) +// fst_.GetImpl()->InitArcIterator(state_, &cache_data_); +// } + +// private: +// mutable const CompactFst &fst_; +// StateId state_; +// size_t pos_; +// size_t num_arcs_; +// size_t offset_; +// uint32 flags_; +// mutable A arc_; +// mutable ArcIteratorData cache_data_; + +// DISALLOW_COPY_AND_ASSIGN(ArcIterator); +// }; + + +// +// Utility Compactors +// + +// Compactor for unweighted string FSTs +template +class StringCompactor { + public: + typedef A Arc; + typedef typename A::Label Element; + typedef typename A::Label Label; + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + Element Compact(StateId s, const A &arc) const { return arc.ilabel; } + + Arc Expand(StateId s, const Element &p, uint32 f = kArcValueFlags) const { + return Arc(p, p, Weight::One(), p != kNoLabel ? s + 1 : kNoStateId); + } + + ssize_t Size() const { return 1; } + + uint64 Properties() const { + return kString | kAcceptor | kUnweighted; + } + + bool Compatible(const Fst &fst) const { + uint64 props = Properties(); + return fst.Properties(props, true) == props; + } + + static const string &Type() { + static const string type = "string"; + return type; + } + + bool Write(ostream &strm) const { return true; } + + static StringCompactor *Read(istream &strm) { + return new StringCompactor; + } +}; + + +// Compactor for weighted string FSTs +template +class WeightedStringCompactor { + public: + typedef A Arc; + typedef typename A::Label Label; + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + typedef pair Element; + + Element Compact(StateId s, const A &arc) const { + return make_pair(arc.ilabel, arc.weight); + } + + Arc Expand(StateId s, const Element &p, uint32 f = kArcValueFlags) const { + return Arc(p.first, p.first, p.second, + p.first != kNoLabel ? s + 1 : kNoStateId); + } + + ssize_t Size() const { return 1;} + + uint64 Properties() const { + return kString | kAcceptor; + } + + bool Compatible(const Fst &fst) const { + uint64 props = Properties(); + return fst.Properties(props, true) == props; + } + + static const string &Type() { + static const string type = "weighted_string"; + return type; + } + + bool Write(ostream &strm) const { return true; } + + static WeightedStringCompactor *Read(istream &strm) { + return new WeightedStringCompactor; + } +}; + + +// Compactor for unweighted acceptor FSTs +template +class UnweightedAcceptorCompactor { + public: + typedef A Arc; + typedef typename A::Label Label; + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + typedef pair Element; + + Element Compact(StateId s, const A &arc) const { + return make_pair(arc.ilabel, arc.nextstate); + } + + Arc Expand(StateId s, const Element &p, uint32 f = kArcValueFlags) const { + return Arc(p.first, p.first, Weight::One(), p.second); + } + + ssize_t Size() const { return -1;} + + uint64 Properties() const { + return kAcceptor | kUnweighted; + } + + bool Compatible(const Fst &fst) const { + uint64 props = Properties(); + return fst.Properties(props, true) == props; + } + + static const string &Type() { + static const string type = "unweighted_acceptor"; + return type; + } + + bool Write(ostream &strm) const { return true; } + + static UnweightedAcceptorCompactor *Read(istream &istrm) { + return new UnweightedAcceptorCompactor; + } +}; + + +// Compactor for weighted acceptor FSTs +template +class AcceptorCompactor { + public: + typedef A Arc; + typedef typename A::Label Label; + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + typedef pair< pair, StateId > Element; + + Element Compact(StateId s, const A &arc) const { + return make_pair(make_pair(arc.ilabel, arc.weight), arc.nextstate); + } + + Arc Expand(StateId s, const Element &p, uint32 f = kArcValueFlags) const { + return Arc(p.first.first, p.first.first, p.first.second, p.second); + } + + ssize_t Size() const { return -1;} + + uint64 Properties() const { + return kAcceptor; + } + + bool Compatible(const Fst &fst) const { + uint64 props = Properties(); + return fst.Properties(props, true) == props; + } + + static const string &Type() { + static const string type = "acceptor"; + return type; + } + + bool Write(ostream &strm) const { return true; } + + static AcceptorCompactor *Read(istream &strm) { + return new AcceptorCompactor; + } +}; + + +// Compactor for unweighted FSTs +template +class UnweightedCompactor { + public: + typedef A Arc; + typedef typename A::Label Label; + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + typedef pair< pair, StateId > Element; + + Element Compact(StateId s, const A &arc) const { + return make_pair(make_pair(arc.ilabel, arc.olabel), arc.nextstate); + } + + Arc Expand(StateId s, const Element &p, uint32 f = kArcValueFlags) const { + return Arc(p.first.first, p.first.second, Weight::One(), p.second); + } + + ssize_t Size() const { return -1; } + + uint64 Properties() const { + return kUnweighted; + } + + bool Compatible(const Fst &fst) const { + uint64 props = Properties(); + return fst.Properties(props, true) == props; + } + + static const string &Type() { + static const string type = "unweighted"; + return type; + } + + bool Write(ostream &strm) const { return true; } + + static UnweightedCompactor *Read(istream &strm) { + return new UnweightedCompactor; + } +}; + + +// Uselful aliases when using StdArc +typedef CompactFst< StdArc, StringCompactor > +StdCompactStringFst; +typedef CompactFst< StdArc, WeightedStringCompactor > +StdCompactWeightedStringFst; +typedef CompactFst > +StdCompactAcceptorFst; +typedef CompactFst > +StdCompactUnweightedFst; +typedef CompactFst > +StdCompactUnweightedAcceptorFst; + +} // namespace fst + +#endif // FST_LIB_COMPACT_FST_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/compat.h b/kaldi_io/src/tools/openfst/include/fst/compat.h new file mode 100644 index 0000000..3b5275d --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/compat.h @@ -0,0 +1,131 @@ +// compat.h +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Author: riley@google.com (Michael Riley) +// +// \file +// Google compatibility declarations and inline definitions. + +#ifndef FST_LIB_COMPAT_H__ +#define FST_LIB_COMPAT_H__ + +#include + +#include +#include +#include +#include +#include +#include + +// Makes copy constructor and operator= private +#define DISALLOW_COPY_AND_ASSIGN(type) \ + type(const type&); \ + void operator=(const type&) + +#include +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +using std::cerr; +using std::endl; +using std::string; + +void FailedNewHandler(); + +namespace fst { + +using namespace std; + +void SplitToVector(char *line, const char *delim, + std::vector *vec, bool omit_empty_strings); + +// Downcasting +template +inline To down_cast(From* f) { + return static_cast(f); +} + +// Bitcasting +template +inline Dest bit_cast(const Source& source) { + // Compile time assertion: sizeof(Dest) == sizeof(Source) + // A compile error here means your Dest and Source have different sizes. + typedef char VerifySizesAreEqual [sizeof(Dest) == sizeof(Source) ? 1 : + -1]; + Dest dest; + memcpy(&dest, &source, sizeof(dest)); + return dest; +} + +// Check sums +class CheckSummer { + public: + CheckSummer() : count_(0) { + check_sum_.resize(kCheckSumLength, '\0'); + } + + void Reset() { + count_ = 0; + for (int i = 0; i < kCheckSumLength; ++i) + check_sum_[i] = '\0'; + } + + void Update(void const *data, int size) { + const char *p = reinterpret_cast(data); + for (int i = 0; i < size; ++i) + check_sum_[(count_++) % kCheckSumLength] ^= p[i]; + } + + void Update(string const &data) { + for (int i = 0; i < data.size(); ++i) + check_sum_[(count_++) % kCheckSumLength] ^= data[i]; + } + + string Digest() { + return check_sum_; + } + + private: + static const int kCheckSumLength = 32; + int count_; + string check_sum_; + + DISALLOW_COPY_AND_ASSIGN(CheckSummer); +}; + +} // namespace fst + + +// Define missing hash functions if needed +#ifndef HAVE_STD__TR1__HASH_LONG_LONG_UNSIGNED_ +namespace std { +namespace tr1 { + +template class hash; + +template<> struct hash { + size_t operator()(uint64 x) const { return x; } +}; + +} +} +#endif // HAVE_STD__TR1__HASH_LONG_LONG_UNSIGNED_ + +#endif // FST_LIB_COMPAT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/complement.h b/kaldi_io/src/tools/openfst/include/fst/complement.h new file mode 100644 index 0000000..dacf396 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/complement.h @@ -0,0 +1,338 @@ +// complement.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Class to complement an Fst. + +#ifndef FST_LIB_COMPLEMENT_H__ +#define FST_LIB_COMPLEMENT_H__ + +#include +#include +#include +using std::vector; + +#include +#include + + +namespace fst { + +template class ComplementFst; + +// Implementation of delayed ComplementFst. The algorithm used +// completes the (deterministic) FSA and then exchanges final and +// non-final states. Completion, i.e. ensuring that all labels can be +// read from every state, is accomplished by using RHO labels, which +// match all labels that are otherwise not found leaving a state. The +// first state in the output is reserved to be a new state that is the +// destination of all RHO labels. Each remaining output state s +// corresponds to input state s - 1. The first arc in the output at +// these states is the rho label, the remaining arcs correspond to the +// input arcs. +template +class ComplementFstImpl : public FstImpl { + public: + using FstImpl::SetType; + using FstImpl::SetProperties; + using FstImpl::SetInputSymbols; + using FstImpl::SetOutputSymbols; + + friend class StateIterator< ComplementFst >; + friend class ArcIterator< ComplementFst >; + + typedef A Arc; + typedef typename A::Label Label; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + + explicit ComplementFstImpl(const Fst &fst) : fst_(fst.Copy()) { + SetType("complement"); + uint64 props = fst.Properties(kILabelSorted, false); + SetProperties(ComplementProperties(props), kCopyProperties); + SetInputSymbols(fst.InputSymbols()); + SetOutputSymbols(fst.OutputSymbols()); + } + + ComplementFstImpl(const ComplementFstImpl &impl) + : fst_(impl.fst_->Copy()) { + SetType("complement"); + SetProperties(impl.Properties(), kCopyProperties); + SetInputSymbols(impl.InputSymbols()); + SetOutputSymbols(impl.OutputSymbols()); + } + + ~ComplementFstImpl() { delete fst_; } + + StateId Start() const { + if (Properties(kError)) + return kNoStateId; + + StateId start = fst_->Start(); + if (start != kNoStateId) + return start + 1; + else + return 0; + } + + // Exchange final and non-final states; make rho destination state final. + Weight Final(StateId s) const { + if (s == 0 || fst_->Final(s - 1) == Weight::Zero()) + return Weight::One(); + else + return Weight::Zero(); + } + + size_t NumArcs(StateId s) const { + if (s == 0) + return 1; + else + return fst_->NumArcs(s - 1) + 1; + } + + size_t NumInputEpsilons(StateId s) const { + return s == 0 ? 0 : fst_->NumInputEpsilons(s - 1); + } + + size_t NumOutputEpsilons(StateId s) const { + return s == 0 ? 0 : fst_->NumOutputEpsilons(s - 1); + } + + + uint64 Properties() const { return Properties(kFstProperties); } + + // Set error if found; return FST impl properties. + uint64 Properties(uint64 mask) const { + if ((mask & kError) && fst_->Properties(kError, false)) + SetProperties(kError, kError); + return FstImpl::Properties(mask); + } + + + private: + const Fst *fst_; + + void operator=(const ComplementFstImpl &fst); // Disallow +}; + + +// Complements an automaton. This is a library-internal operation that +// introduces a (negative) 'rho' label; use Difference/DifferenceFst in +// user code, which will not see this label. This version is a delayed Fst. +// +// This class attaches interface to implementation and handles +// reference counting, delegating most methods to ImplToFst. +template +class ComplementFst : public ImplToFst< ComplementFstImpl > { + public: + friend class StateIterator< ComplementFst >; + friend class ArcIterator< ComplementFst >; + + using ImplToFst< ComplementFstImpl >::GetImpl; + + typedef A Arc; + typedef typename A::StateId StateId; + typedef typename A::Label Label; + typedef ComplementFstImpl Impl; + + explicit ComplementFst(const Fst &fst) + : ImplToFst(new Impl(fst)) { + uint64 props = kUnweighted | kNoEpsilons | kIDeterministic | kAcceptor; + if (fst.Properties(props, true) != props) { + FSTERROR() << "ComplementFst: argument not an unweighted " + << "epsilon-free deterministic acceptor"; + GetImpl()->SetProperties(kError, kError); + } + } + + // See Fst<>::Copy() for doc. + ComplementFst(const ComplementFst &fst, bool safe = false) + : ImplToFst(fst, safe) {} + + // Get a copy of this ComplementFst. See Fst<>::Copy() for further doc. + virtual ComplementFst *Copy(bool safe = false) const { + return new ComplementFst(*this, safe); + } + + virtual inline void InitStateIterator(StateIteratorData *data) const; + + virtual inline void InitArcIterator(StateId s, + ArcIteratorData *data) const; + + // Label that represents the rho transition. + // We use a negative value, which is thus private to the library and + // which will preserve FST label sort order. + static const Label kRhoLabel = -2; + private: + // Makes visible to friends. + Impl *GetImpl() const { return ImplToFst::GetImpl(); } + + void operator=(const ComplementFst &fst); // disallow +}; + +template const typename A::Label ComplementFst::kRhoLabel; + + +// Specialization for ComplementFst. +template +class StateIterator< ComplementFst > : public StateIteratorBase { + public: + typedef typename A::StateId StateId; + typedef typename A::Label Label; + + explicit StateIterator(const ComplementFst &fst) + : siter_(*fst.GetImpl()->fst_), s_(0) { + } + + bool Done() const { return s_ > 0 && siter_.Done(); } + + StateId Value() const { return s_; } + + void Next() { + if (s_ != 0) + siter_.Next(); + ++s_; + } + + void Reset() { + siter_.Reset(); + s_ = 0; + } + + private: + // This allows base class virtual access to non-virtual derived- + // class members of the same name. It makes the derived class more + // efficient to use but unsafe to further derive. + virtual bool Done_() const { return Done(); } + virtual StateId Value_() const { return Value(); } + virtual void Next_() { Next(); } + virtual void Reset_() { Reset(); } + + StateIterator< Fst > siter_; + StateId s_; + + DISALLOW_COPY_AND_ASSIGN(StateIterator); +}; + + +// Specialization for ComplementFst. +template +class ArcIterator< ComplementFst > : public ArcIteratorBase { + public: + typedef typename A::StateId StateId; + typedef typename A::Label Label; + typedef typename A::Weight Weight; + + ArcIterator(const ComplementFst &fst, StateId s) + : aiter_(0), s_(s), pos_(0) { + if (s_ != 0) + aiter_ = new ArcIterator< Fst >(*fst.GetImpl()->fst_, s - 1); + } + + virtual ~ArcIterator() { delete aiter_; } + + bool Done() const { + if (s_ != 0) + return pos_ > 0 && aiter_->Done(); + else + return pos_ > 0; + } + + // Adds the rho label to the rho destination state. + const A& Value() const { + if (pos_ == 0) { + arc_.ilabel = arc_.olabel = ComplementFst::kRhoLabel; + arc_.weight = Weight::One(); + arc_.nextstate = 0; + } else { + arc_ = aiter_->Value(); + ++arc_.nextstate; + } + return arc_; + } + + void Next() { + if (s_ != 0 && pos_ > 0) + aiter_->Next(); + ++pos_; + } + + size_t Position() const { + return pos_; + } + + void Reset() { + if (s_ != 0) + aiter_->Reset(); + pos_ = 0; + } + + void Seek(size_t a) { + if (s_ != 0) { + if (a == 0) { + aiter_->Reset(); + } else { + aiter_->Seek(a - 1); + } + } + pos_ = a; + } + + uint32 Flags() const { + return kArcValueFlags; + } + + void SetFlags(uint32 f, uint32 m) {} + + private: + // This allows base class virtual access to non-virtual derived- + // class members of the same name. It makes the derived class more + // efficient to use but unsafe to further derive. + virtual bool Done_() const { return Done(); } + virtual const A& Value_() const { return Value(); } + virtual void Next_() { Next(); } + virtual size_t Position_() const { return Position(); } + virtual void Reset_() { Reset(); } + virtual void Seek_(size_t a) { Seek(a); } + uint32 Flags_() const { return Flags(); } + void SetFlags_(uint32 f, uint32 m) { SetFlags(f, m); } + + ArcIterator< Fst > *aiter_; + StateId s_; + size_t pos_; + mutable A arc_; + DISALLOW_COPY_AND_ASSIGN(ArcIterator); +}; + + +template inline void +ComplementFst::InitStateIterator(StateIteratorData *data) const { + data->base = new StateIterator< ComplementFst >(*this); +} + +template inline void +ComplementFst::InitArcIterator(StateId s, ArcIteratorData *data) const { + data->base = new ArcIterator< ComplementFst >(*this, s); +} + + +// Useful alias when using StdArc. +typedef ComplementFst StdComplementFst; + +} // namespace fst + +#endif // FST_LIB_COMPLEMENT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/compose-filter.h b/kaldi_io/src/tools/openfst/include/fst/compose-filter.h new file mode 100644 index 0000000..6bf7736 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/compose-filter.h @@ -0,0 +1,542 @@ +// compose-filter.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Classes for filtering the composition matches, e.g. for correct epsilon +// handling. + +#ifndef FST_LIB_COMPOSE_FILTER_H__ +#define FST_LIB_COMPOSE_FILTER_H__ + +#include +#include // For optional argument declarations +#include + + +namespace fst { + + +// COMPOSITION FILTER STATE - this represents the state of +// the composition filter. It has the form: +// +// class FilterState { +// public: +// // Required constructors +// FilterState(); +// FilterState(const FilterState &f); +// // An invalid filter state. +// static const FilterState NoState(); +// // Maps state to integer for hashing. +// size_t Hash() const; +// // Equality of filter states. +// bool operator==(const FilterState &f) const; +// // Inequality of filter states. +// bool operator!=(const FilterState &f) const; +// // Assignment to filter states. +// FilterState& operator=(const FilterState& f); +// }; + + +// Filter state that is a signed integral type. +template +class IntegerFilterState { + public: + IntegerFilterState() : state_(kNoStateId) {} + explicit IntegerFilterState(T s) : state_(s) {} + + static const IntegerFilterState NoState() { return IntegerFilterState(); } + + size_t Hash() const { return static_cast(state_); } + + bool operator==(const IntegerFilterState &f) const { + return state_ == f.state_; + } + + bool operator!=(const IntegerFilterState &f) const { + return state_ != f.state_; + } + + T GetState() const { return state_; } + + void SetState(T state) { state_ = state; } + +private: + T state_; +}; + +typedef IntegerFilterState CharFilterState; +typedef IntegerFilterState ShortFilterState; +typedef IntegerFilterState IntFilterState; + + +// Filter state that is a weight (class). +template +class WeightFilterState { + public: + WeightFilterState() : weight_(W::Zero()) {} + explicit WeightFilterState(W w) : weight_(w) {} + + static const WeightFilterState NoState() { return WeightFilterState(); } + + size_t Hash() const { return weight_.Hash(); } + + bool operator==(const WeightFilterState &f) const { + return weight_ == f.weight_; + } + + bool operator!=(const WeightFilterState &f) const { + return weight_ != f.weight_; + } + + W GetWeight() const { return weight_; } + + void SetWeight(W w) { weight_ = w; } + +private: + W weight_; +}; + + +// Filter state that is the combination of two filter states. +template +class PairFilterState { + public: + PairFilterState() : f1_(F1::NoState()), f2_(F2::NoState()) {} + + PairFilterState(const F1 &f1, const F2 &f2) : f1_(f1), f2_(f2) {} + + static const PairFilterState NoState() { return PairFilterState(); } + + size_t Hash() const { + size_t h1 = f1_.Hash(); + size_t h2 = f2_.Hash(); + const int lshift = 5; + const int rshift = CHAR_BIT * sizeof(size_t) - 5; + return h1 << lshift ^ h1 >> rshift ^ h2; + } + + bool operator==(const PairFilterState &f) const { + return f1_ == f.f1_ && f2_ == f.f2_; + } + + bool operator!=(const PairFilterState &f) const { + return f1_ != f.f1_ || f2_ != f.f2_; + } + + const F1 &GetState1() const { return f1_; } + const F2 &GetState2() const { return f2_; } + + void SetState(const F1 &f1, const F2 &f2) { + f1_ = f1; + f2_ = f2; + } + +private: + F1 f1_; + F2 f2_; +}; + + +// COMPOSITION FILTERS - these determine which matches are allowed to +// proceed. The filter's state is represented by the type +// ComposeFilter::FilterState. The basic filters handle correct +// epsilon matching. Their interface is: +// +// template +// class ComposeFilter { +// public: +// typedef typename M1::FST1 FST1; +// typedef typename M1::FST2 FST2; +// typedef typename FST1::Arc Arc; +// typedef ... FilterState; +// typedef ... Matcher1; +// typedef ... Matcher2; +// +// // Required constructors. +// ComposeFilter(const FST1 &fst1, const FST2 &fst2, +// // M1 *matcher1 = 0, M2 *matcher2 = 0); +// // If safe=true, the copy is thread-safe. See Fst<>::Copy() +// // for further doc. +// ComposeFilter(const ComposeFilter &filter, +// // bool safe = false); +// // Return start state of filter. +// FilterState Start() const; +// // Specifies current composition state. +// void SetState(StateId s1, StateId s2, const FilterState &f); +// +// // Apply filter at current composition state to these transitions. +// // If an arc label to be matched is kNolabel, then that side +// // does not consume a symbol. Returns the new filter state or, +// // if disallowed, FilterState::NoState(). The filter is permitted to +// // modify its inputs, e.g. for optimizations. +// FilterState FilterArc(Arc *arc1, Arc *arc2) const; + +// // Apply filter at current composition state to these final weights +// // (cf. superfinal transitions). The filter may modify its inputs, +// // e.g. for optimizations. +// void FilterFinal(Weight *final1, Weight *final2) const; +// +// // Return resp matchers. Ownership stays with filter. These +// // methods allow the filter to access and possibly modify +// // the composition matchers (useful e.g. with lookahead). +// Matcher1 *GetMatcher1(); +// Matcher2 *GetMatcher2(); +// +// // This specifies how the filter affects the composition result +// // properties. It takes as argument the properties that would +// // apply with a trivial composition fitler. +// uint64 Properties(uint64 props) const; +// }; + +// This filter requires epsilons on FST1 to be read before epsilons on FST2. +template +class SequenceComposeFilter { + public: + typedef typename M1::FST FST1; + typedef typename M2::FST FST2; + typedef typename FST1::Arc Arc; + typedef CharFilterState FilterState; + typedef M1 Matcher1; + typedef M2 Matcher2; + + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + + SequenceComposeFilter(const FST1 &fst1, const FST2 &fst2, + M1 *matcher1 = 0, M2 *matcher2 = 0) + : matcher1_(matcher1 ? matcher1 : new M1(fst1, MATCH_OUTPUT)), + matcher2_(matcher2 ? matcher2 : new M2(fst2, MATCH_INPUT)), + fst1_(matcher1_->GetFst()), + s1_(kNoStateId), + s2_(kNoStateId), + f_(kNoStateId) {} + + SequenceComposeFilter(const SequenceComposeFilter &filter, + bool safe = false) + : matcher1_(filter.matcher1_->Copy(safe)), + matcher2_(filter.matcher2_->Copy(safe)), + fst1_(matcher1_->GetFst()), + s1_(kNoStateId), + s2_(kNoStateId), + f_(kNoStateId) {} + + ~SequenceComposeFilter() { + delete matcher1_; + delete matcher2_; + } + + FilterState Start() const { return FilterState(0); } + + void SetState(StateId s1, StateId s2, const FilterState &f) { + if (s1_ == s1 && s2_ == s2 && f == f_) + return; + s1_ = s1; + s2_ = s2; + f_ = f; + size_t na1 = internal::NumArcs(fst1_, s1); + size_t ne1 = internal::NumOutputEpsilons(fst1_, s1); + bool fin1 = internal::Final(fst1_, s1) != Weight::Zero(); + alleps1_ = na1 == ne1 && !fin1; + noeps1_ = ne1 == 0; + } + + FilterState FilterArc(Arc *arc1, Arc *arc2) const { + if (arc1->olabel == kNoLabel) + return alleps1_ ? FilterState::NoState() : + noeps1_ ? FilterState(0) : FilterState(1); + else if (arc2->ilabel == kNoLabel) + return f_ != FilterState(0) ? FilterState::NoState() : FilterState(0); + else + return arc1->olabel == 0 ? FilterState::NoState() : FilterState(0); + } + + void FilterFinal(Weight *, Weight *) const {} + + // Return resp matchers. Ownership stays with filter. + Matcher1 *GetMatcher1() { return matcher1_; } + Matcher2 *GetMatcher2() { return matcher2_; } + + uint64 Properties(uint64 props) const { return props; } + + private: + Matcher1 *matcher1_; + Matcher2 *matcher2_; + const FST1 &fst1_; + StateId s1_; // Current fst1_ state; + StateId s2_; // Current fst2_ state; + FilterState f_; // Current filter state + bool alleps1_; // Only epsilons (and non-final) leaving s1_? + bool noeps1_; // No epsilons leaving s1_? + + void operator=(const SequenceComposeFilter &); // disallow +}; + + +// This filter requires epsilons on FST2 to be read before epsilons on FST1. +template +class AltSequenceComposeFilter { + public: + typedef typename M1::FST FST1; + typedef typename M2::FST FST2; + typedef typename FST1::Arc Arc; + typedef CharFilterState FilterState; + typedef M1 Matcher1; + typedef M2 Matcher2; + + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + + AltSequenceComposeFilter(const FST1 &fst1, const FST2 &fst2, + M1 *matcher1 = 0, M2 *matcher2 = 0) + : matcher1_(matcher1 ? matcher1 : new M1(fst1, MATCH_OUTPUT)), + matcher2_(matcher2 ? matcher2 : new M2(fst2, MATCH_INPUT)), + fst2_(matcher2_->GetFst()), + s1_(kNoStateId), + s2_(kNoStateId), + f_(kNoStateId) {} + + AltSequenceComposeFilter(const AltSequenceComposeFilter &filter, + bool safe = false) + : matcher1_(filter.matcher1_->Copy(safe)), + matcher2_(filter.matcher2_->Copy(safe)), + fst2_(matcher2_->GetFst()), + s1_(kNoStateId), + s2_(kNoStateId), + f_(kNoStateId) {} + + ~AltSequenceComposeFilter() { + delete matcher1_; + delete matcher2_; + } + + FilterState Start() const { return FilterState(0); } + + void SetState(StateId s1, StateId s2, const FilterState &f) { + if (s1_ == s1 && s2_ == s2 && f == f_) + return; + s1_ = s1; + s2_ = s2; + f_ = f; + size_t na2 = internal::NumArcs(fst2_, s2); + size_t ne2 = internal::NumInputEpsilons(fst2_, s2); + bool fin2 = internal::Final(fst2_, s2) != Weight::Zero(); + alleps2_ = na2 == ne2 && !fin2; + noeps2_ = ne2 == 0; + } + + FilterState FilterArc(Arc *arc1, Arc *arc2) const { + if (arc2->ilabel == kNoLabel) + return alleps2_ ? FilterState::NoState() : + noeps2_ ? FilterState(0) : FilterState(1); + else if (arc1->olabel == kNoLabel) + return f_ == FilterState(1) ? FilterState::NoState() : FilterState(0); + else + return arc1->olabel == 0 ? FilterState::NoState() : FilterState(0); + } + + void FilterFinal(Weight *, Weight *) const {} + + // Return resp matchers. Ownership stays with filter. + Matcher1 *GetMatcher1() { return matcher1_; } + Matcher2 *GetMatcher2() { return matcher2_; } + + uint64 Properties(uint64 props) const { return props; } + + private: + Matcher1 *matcher1_; + Matcher2 *matcher2_; + const FST2 &fst2_; + StateId s1_; // Current fst1_ state; + StateId s2_; // Current fst2_ state; + FilterState f_; // Current filter state + bool alleps2_; // Only epsilons (and non-final) leaving s2_? + bool noeps2_; // No epsilons leaving s2_? + +void operator=(const AltSequenceComposeFilter &); // disallow +}; + + +// This filter requires epsilons on FST1 to be matched with epsilons on FST2 +// whenever possible. +template +class MatchComposeFilter { + public: + typedef typename M1::FST FST1; + typedef typename M2::FST FST2; + typedef typename FST1::Arc Arc; + typedef CharFilterState FilterState; + typedef M1 Matcher1; + typedef M2 Matcher2; + + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + + MatchComposeFilter(const FST1 &fst1, const FST2 &fst2, + M1 *matcher1 = 0, M2 *matcher2 = 0) + : matcher1_(matcher1 ? matcher1 : new M1(fst1, MATCH_OUTPUT)), + matcher2_(matcher2 ? matcher2 : new M2(fst2, MATCH_INPUT)), + fst1_(matcher1_->GetFst()), + fst2_(matcher2_->GetFst()), + s1_(kNoStateId), + s2_(kNoStateId), + f_(kNoStateId) {} + + MatchComposeFilter(const MatchComposeFilter &filter, + bool safe = false) + : matcher1_(filter.matcher1_->Copy(safe)), + matcher2_(filter.matcher2_->Copy(safe)), + fst1_(matcher1_->GetFst()), + fst2_(matcher2_->GetFst()), + s1_(kNoStateId), + s2_(kNoStateId), + f_(kNoStateId) {} + + ~MatchComposeFilter() { + delete matcher1_; + delete matcher2_; + } + + FilterState Start() const { return FilterState(0); } + + void SetState(StateId s1, StateId s2, const FilterState &f) { + if (s1_ == s1 && s2_ == s2 && f == f_) + return; + s1_ = s1; + s2_ = s2; + f_ = f; + size_t na1 = internal::NumArcs(fst1_, s1); + size_t ne1 = internal::NumOutputEpsilons(fst1_, s1); + bool f1 = internal::Final(fst1_, s1) != Weight::Zero(); + alleps1_ = na1 == ne1 && !f1; + noeps1_ = ne1 == 0; + size_t na2 = internal::NumArcs(fst2_, s2); + size_t ne2 = internal::NumInputEpsilons(fst2_, s2); + bool f2 = internal::Final(fst2_, s2) != Weight::Zero(); + alleps2_ = na2 == ne2 && !f2; + noeps2_ = ne2 == 0; + } + + FilterState FilterArc(Arc *arc1, Arc *arc2) const { + if (arc2->ilabel == kNoLabel) // Epsilon on Fst1 + return f_ == FilterState(0) ? + (noeps2_ ? FilterState(0) : + (alleps2_ ? FilterState::NoState(): FilterState(1))) : + (f_ == FilterState(1) ? FilterState(1) : FilterState::NoState()); + else if (arc1->olabel == kNoLabel) // Epsilon on Fst2 + return f_ == FilterState(0) ? + (noeps1_ ? FilterState(0) : + (alleps1_ ? FilterState::NoState() : FilterState(2))) : + (f_ == FilterState(2) ? FilterState(2) : FilterState::NoState()); + else if (arc1->olabel == 0) // Epsilon on both + return f_ == FilterState(0) ? FilterState(0) : FilterState::NoState(); + else // Both are non-epsilons + return FilterState(0); + } + + void FilterFinal(Weight *, Weight *) const {} + + // Return resp matchers. Ownership stays with filter. + Matcher1 *GetMatcher1() { return matcher1_; } + Matcher2 *GetMatcher2() { return matcher2_; } + + uint64 Properties(uint64 props) const { return props; } + + private: + Matcher1 *matcher1_; + Matcher2 *matcher2_; + const FST1 &fst1_; + const FST2 &fst2_; + StateId s1_; // Current fst1_ state; + StateId s2_; // Current fst2_ state; + FilterState f_; // Current filter state ID + bool alleps1_, alleps2_; // Only epsilons (and non-final) leaving s1, s2? + bool noeps1_, noeps2_; // No epsilons leaving s1, s2? + + void operator=(const MatchComposeFilter &); // disallow +}; + + +// This filter works with the MultiEpsMatcher to determine if +// 'multi-epsilons' are preserved in the composition output +// (rather than rewritten as 0) and ensures correct properties. +template +class MultiEpsFilter { + public: + typedef typename F::FST1 FST1; + typedef typename F::FST2 FST2; + typedef typename F::Arc Arc; + typedef typename F::Matcher1 Matcher1; + typedef typename F::Matcher2 Matcher2; + typedef typename F::FilterState FilterState; + typedef MultiEpsFilter Filter; + + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + + MultiEpsFilter(const FST1 &fst1, const FST2 &fst2, + Matcher1 *matcher1 = 0, Matcher2 *matcher2 = 0, + bool keep_multi_eps = false) + : filter_(fst1, fst2, matcher1, matcher2), + keep_multi_eps_(keep_multi_eps) {} + + MultiEpsFilter(const Filter &filter, bool safe = false) + : filter_(filter.filter_, safe), + keep_multi_eps_(filter.keep_multi_eps_) {} + + FilterState Start() const { return filter_.Start(); } + + void SetState(StateId s1, StateId s2, const FilterState &f) { + return filter_.SetState(s1, s2, f); + } + + FilterState FilterArc(Arc *arc1, Arc *arc2) const { + FilterState f = filter_.FilterArc(arc1, arc2); + if (keep_multi_eps_) { + if (arc1->olabel == kNoLabel) + arc1->ilabel = arc2->ilabel; + if (arc2->ilabel == kNoLabel) + arc2->olabel = arc1->olabel; + } + return f; + } + + void FilterFinal(Weight *w1, Weight *w2) const { + return filter_.FilterFinal(w1, w2); + } + + // Return resp matchers. Ownership stays with filter. + Matcher1 *GetMatcher1() { return filter_.GetMatcher1(); } + Matcher2 *GetMatcher2() { return filter_.GetMatcher2(); } + + uint64 Properties(uint64 iprops) const { + uint64 oprops = filter_.Properties(iprops); + return oprops & kILabelInvariantProperties & kOLabelInvariantProperties; + } + + private: + F filter_; + bool keep_multi_eps_; +}; + +} // namespace fst + + +#endif // FST_LIB_COMPOSE_FILTER_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/compose.h b/kaldi_io/src/tools/openfst/include/fst/compose.h new file mode 100644 index 0000000..db5ea3a --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/compose.h @@ -0,0 +1,728 @@ +// compose.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Class to compute the composition of two FSTs + +#ifndef FST_LIB_COMPOSE_H__ +#define FST_LIB_COMPOSE_H__ + +#include +#include +#include +using std::vector; + +#include +#include +#include +#include +#include +#include + + +namespace fst { + +// Delayed composition options templated on the arc type, the matcher, +// the composition filter, and the composition state table. By +// default, the matchers, filter, and state table are constructed by +// composition. If set below, the user can instead pass in these +// objects; in that case, ComposeFst takes their ownership. This +// version controls composition implemented between generic Fst +// types and a shared matcher type M for Fst. This should be +// adequate for most applications, giving a reasonable tradeoff +// between efficiency and code sharing (but see ComposeFstImplOptions). +template >, + class F = SequenceComposeFilter, + class T = GenericComposeStateTable > +struct ComposeFstOptions : public CacheOptions { + M *matcher1; // FST1 matcher (see matcher.h) + M *matcher2; // FST2 matcher + F *filter; // Composition filter (see compose-filter.h) + T *state_table; // Composition state table (see compose-state-table.h) + + explicit ComposeFstOptions(const CacheOptions &opts, + M *mat1 = 0, M *mat2 = 0, + F *filt = 0, T *sttable= 0) + : CacheOptions(opts), matcher1(mat1), matcher2(mat2), + filter(filt), state_table(sttable) {} + + ComposeFstOptions() : matcher1(0), matcher2(0), filter(0), state_table(0) {} +}; + + +// Delayed composition options templated on the two matcher types, the +// composition filter, and the composition state table. By default, +// the matchers, filter, and state table are constructed by +// composition. If set below, the user can instead pass in these +// objects; in that case, ComposeFst takes their ownership. This +// version controls composition implemented using arbitrary matchers +// (of the same Arc type but otherwise arbitrary Fst type). The user +// must ensure the matchers are compatible. These options permit the +// most efficient use, but shares the least code. This is for advanced +// use only in the most demanding or specialized applications that can +// benefit from it (o.w. prefer ComposeFstOptions). +template , + class T = GenericComposeStateTable > +struct ComposeFstImplOptions : public CacheOptions { + M1 *matcher1; // FST1 matcher (see matcher.h) + M2 *matcher2; // FST2 matcher + F *filter; // Composition filter (see compose-filter.h) + T *state_table; // Composition state table (see compose-state-table.h) + + explicit ComposeFstImplOptions(const CacheOptions &opts, + M1 *mat1 = 0, M2 *mat2 = 0, + F *filt = 0, T *sttable= 0) + : CacheOptions(opts), matcher1(mat1), matcher2(mat2), + filter(filt), state_table(sttable) {} + + ComposeFstImplOptions() + : matcher1(0), matcher2(0), filter(0), state_table(0) {} +}; + + +// Implementation of delayed composition. This base class is +// common to the variants with different matchers, composition filters +// and state tables. +template +class ComposeFstImplBase : public CacheImpl { + public: + using FstImpl::SetType; + using FstImpl::SetProperties; + using FstImpl::Properties; + using FstImpl::SetInputSymbols; + using FstImpl::SetOutputSymbols; + + using CacheBaseImpl< CacheState >::HasStart; + using CacheBaseImpl< CacheState >::HasFinal; + using CacheBaseImpl< CacheState >::HasArcs; + using CacheBaseImpl< CacheState >::SetFinal; + using CacheBaseImpl< CacheState >::SetStart; + + typedef typename A::Label Label; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + typedef CacheState State; + + ComposeFstImplBase(const Fst &fst1, const Fst &fst2, + const CacheOptions &opts) + : CacheImpl(opts) { + VLOG(2) << "ComposeFst(" << this << "): Begin"; + SetType("compose"); + + if (!CompatSymbols(fst2.InputSymbols(), fst1.OutputSymbols())) { + FSTERROR() << "ComposeFst: output symbol table of 1st argument " + << "does not match input symbol table of 2nd argument"; + SetProperties(kError, kError); + } + + SetInputSymbols(fst1.InputSymbols()); + SetOutputSymbols(fst2.OutputSymbols()); + } + + ComposeFstImplBase(const ComposeFstImplBase &impl) + : CacheImpl(impl, true) { + SetProperties(impl.Properties(), kCopyProperties); + SetInputSymbols(impl.InputSymbols()); + SetOutputSymbols(impl.OutputSymbols()); + } + + virtual ComposeFstImplBase *Copy() = 0; + + virtual ~ComposeFstImplBase() {} + + StateId Start() { + if (!HasStart()) { + StateId start = ComputeStart(); + if (start != kNoStateId) { + SetStart(start); + } + } + return CacheImpl::Start(); + } + + Weight Final(StateId s) { + if (!HasFinal(s)) { + Weight final = ComputeFinal(s); + SetFinal(s, final); + } + return CacheImpl::Final(s); + } + + virtual void Expand(StateId s) = 0; + + size_t NumArcs(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumArcs(s); + } + + size_t NumInputEpsilons(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumInputEpsilons(s); + } + + size_t NumOutputEpsilons(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumOutputEpsilons(s); + } + + void InitArcIterator(StateId s, ArcIteratorData *data) { + if (!HasArcs(s)) + Expand(s); + CacheImpl::InitArcIterator(s, data); + } + + protected: + virtual StateId ComputeStart() = 0; + virtual Weight ComputeFinal(StateId s) = 0; +}; + + +// Implementaion of delayed composition templated on the matchers (see +// matcher.h), composition filter (see compose-filter-inl.h) and +// the composition state table (see compose-state-table.h). +template +class ComposeFstImpl : public ComposeFstImplBase { + typedef typename M1::FST FST1; + typedef typename M2::FST FST2; + typedef typename M1::Arc Arc; + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + typedef typename F::FilterState FilterState; + typedef typename F::Matcher1 Matcher1; + typedef typename F::Matcher2 Matcher2; + + using CacheBaseImpl >::SetArcs; + using FstImpl::SetType; + using FstImpl::SetProperties; + + typedef ComposeStateTuple StateTuple; + + public: + ComposeFstImpl(const FST1 &fst1, const FST2 &fst2, + const ComposeFstImplOptions &opts); + + ComposeFstImpl(const ComposeFstImpl &impl) + : ComposeFstImplBase(impl), + filter_(new F(*impl.filter_, true)), + matcher1_(filter_->GetMatcher1()), + matcher2_(filter_->GetMatcher2()), + fst1_(matcher1_->GetFst()), + fst2_(matcher2_->GetFst()), + state_table_(new T(*impl.state_table_)), + match_type_(impl.match_type_) {} + + ~ComposeFstImpl() { + VLOG(2) << "ComposeFst(" << this + << "): End: # of visited states: " << state_table_->Size(); + + delete filter_; + delete state_table_; + } + + virtual ComposeFstImpl *Copy() { + return new ComposeFstImpl(*this); + } + + uint64 Properties() const { return Properties(kFstProperties); } + + // Set error if found; return FST impl properties. + uint64 Properties(uint64 mask) const { + if ((mask & kError) && + (fst1_.Properties(kError, false) || + fst2_.Properties(kError, false) || + (matcher1_->Properties(0) & kError) || + (matcher2_->Properties(0) & kError) | + (filter_->Properties(0) & kError) || + state_table_->Error())) { + SetProperties(kError, kError); + } + return FstImpl::Properties(mask); + } + + // Arranges it so that the first arg to OrderedExpand is the Fst + // that will be matched on. + void Expand(StateId s) { + const StateTuple &tuple = state_table_->Tuple(s); + StateId s1 = tuple.state_id1; + StateId s2 = tuple.state_id2; + filter_->SetState(s1, s2, tuple.filter_state); + if (match_type_ == MATCH_OUTPUT || + (match_type_ == MATCH_BOTH && + internal::NumArcs(fst1_, s1) > internal::NumArcs(fst2_, s2))) + OrderedExpand(s, fst1_, s1, fst2_, s2, matcher1_, false); + else + OrderedExpand(s, fst2_, s2, fst1_, s1, matcher2_, true); + } + + const FST1 &GetFst1() { return fst1_; } + const FST2 &GetFst2() { return fst2_; } + M1 *GetMatcher1() { return matcher1_; } + M2 *GetMatcher2() { return matcher2_; } + F *GetFilter() { return filter_; } + T *GetStateTable() { return state_table_; } + + private: + // This does that actual matching of labels in the composition. The + // arguments are ordered so matching is called on state 'sa' of + // 'fsta' for each arc leaving state 'sb' of 'fstb'. The 'match_input' arg + // determines whether the input or output label of arcs at 'sb' is + // the one to match on. + template + void OrderedExpand(StateId s, const Fst &, StateId sa, + const FST &fstb, StateId sb, + Matcher *matchera, bool match_input) { + matchera->SetState(sa); + + // First process non-consuming symbols (e.g., epsilons) on FSTA. + Arc loop(match_input ? 0 : kNoLabel, match_input ? kNoLabel : 0, + Weight::One(), sb); + MatchArc(s, matchera, loop, match_input); + + // Then process matches on FSTB. + for (ArcIterator iterb(fstb, sb); !iterb.Done(); iterb.Next()) + MatchArc(s, matchera, iterb.Value(), match_input); + + SetArcs(s); + } + + // Matches a single transition from 'fstb' against 'fata' at 's'. + template + void MatchArc(StateId s, Matcher *matchera, + const Arc &arc, bool match_input) { + if (matchera->Find(match_input ? arc.olabel : arc.ilabel)) { + for (; !matchera->Done(); matchera->Next()) { + Arc arca = matchera->Value(); + Arc arcb = arc; + if (match_input) { + const FilterState &f = filter_->FilterArc(&arcb, &arca); + if (f != FilterState::NoState()) + AddArc(s, arcb, arca, f); + } else { + const FilterState &f = filter_->FilterArc(&arca, &arcb); + if (f != FilterState::NoState()) + AddArc(s, arca, arcb, f); + } + } + } + } + + // Add a matching transition at 's'. + void AddArc(StateId s, const Arc &arc1, const Arc &arc2, + const FilterState &f) { + StateTuple tuple(arc1.nextstate, arc2.nextstate, f); + Arc oarc(arc1.ilabel, arc2.olabel, Times(arc1.weight, arc2.weight), + state_table_->FindState(tuple)); + CacheImpl::PushArc(s, oarc); + } + + StateId ComputeStart() { + StateId s1 = fst1_.Start(); + if (s1 == kNoStateId) + return kNoStateId; + + StateId s2 = fst2_.Start(); + if (s2 == kNoStateId) + return kNoStateId; + + const FilterState &f = filter_->Start(); + StateTuple tuple(s1, s2, f); + return state_table_->FindState(tuple); + } + + Weight ComputeFinal(StateId s) { + const StateTuple &tuple = state_table_->Tuple(s); + StateId s1 = tuple.state_id1; + Weight final1 = internal::Final(fst1_, s1); + if (final1 == Weight::Zero()) + return final1; + + StateId s2 = tuple.state_id2; + Weight final2 = internal::Final(fst2_, s2); + if (final2 == Weight::Zero()) + return final2; + + filter_->SetState(s1, s2, tuple.filter_state); + filter_->FilterFinal(&final1, &final2); + return Times(final1, final2); + } + + // Identifies and verifies the capabilities of the matcher to be used for + // composition. + void SetMatchType(); + + F *filter_; + Matcher1 *matcher1_; + Matcher2 *matcher2_; + const FST1 &fst1_; + const FST2 &fst2_; + T *state_table_; + + MatchType match_type_; + + void operator=(const ComposeFstImpl &); // disallow +}; + +template inline +ComposeFstImpl::ComposeFstImpl( + const FST1 &fst1, const FST2 &fst2, + const ComposeFstImplOptions &opts) + : ComposeFstImplBase(fst1, fst2, opts), + filter_(opts.filter ? opts.filter : + new F(fst1, fst2, opts.matcher1, opts.matcher2)), + matcher1_(filter_->GetMatcher1()), + matcher2_(filter_->GetMatcher2()), + fst1_(matcher1_->GetFst()), + fst2_(matcher2_->GetFst()), + state_table_(opts.state_table ? opts.state_table : + new T(fst1_, fst2_)) { + SetMatchType(); + if (match_type_ == MATCH_NONE) + SetProperties(kError, kError); + VLOG(2) << "ComposeFst(" << this << "): Match type: " + << (match_type_ == MATCH_OUTPUT ? "output" : + (match_type_ == MATCH_INPUT ? "input" : + (match_type_ == MATCH_BOTH ? "both" : + (match_type_ == MATCH_NONE ? "none" : "unknown")))); + + uint64 fprops1 = fst1.Properties(kFstProperties, false); + uint64 fprops2 = fst2.Properties(kFstProperties, false); + uint64 mprops1 = matcher1_->Properties(fprops1); + uint64 mprops2 = matcher2_->Properties(fprops2); + uint64 cprops = ComposeProperties(mprops1, mprops2); + SetProperties(filter_->Properties(cprops), kCopyProperties); + if (state_table_->Error()) SetProperties(kError, kError); + VLOG(2) << "ComposeFst(" << this << "): Initialized"; +} + +template +void ComposeFstImpl::SetMatchType() { + MatchType type1 = matcher1_->Type(false); + MatchType type2 = matcher2_->Type(false); + uint32 flags1 = matcher1_->Flags(); + uint32 flags2 = matcher2_->Flags(); + if (flags1 & flags2 & kRequireMatch) { + FSTERROR() << "ComposeFst: only one argument can require matching."; + match_type_ = MATCH_NONE; + } else if (flags1 & kRequireMatch) { + if (matcher1_->Type(true) != MATCH_OUTPUT) { + FSTERROR() << "ComposeFst: 1st argument requires matching but cannot."; + match_type_ = MATCH_NONE; + } + match_type_ = MATCH_OUTPUT; + } else if (flags2 & kRequireMatch) { + if (matcher2_->Type(true) != MATCH_INPUT) { + FSTERROR() << "ComposeFst: 2nd argument requires matching but cannot."; + match_type_ = MATCH_NONE; + } + match_type_ = MATCH_INPUT; + } else if (flags1 & flags2 & kPreferMatch && + type1 == MATCH_OUTPUT && type2 == MATCH_INPUT) { + match_type_ = MATCH_BOTH; + } else if (flags1 & kPreferMatch && type1 == MATCH_OUTPUT) { + match_type_ = MATCH_OUTPUT; + } else if (flags2 & kPreferMatch && type2 == MATCH_INPUT) { + match_type_ = MATCH_INPUT; + } else if (type1 == MATCH_OUTPUT && type2 == MATCH_INPUT) { + match_type_ = MATCH_BOTH; + } else if (type1 == MATCH_OUTPUT) { + match_type_ = MATCH_OUTPUT; + } else if (type2 == MATCH_INPUT) { + match_type_ = MATCH_INPUT; + } else if (flags1 & kPreferMatch && matcher1_->Type(true) == MATCH_OUTPUT) { + match_type_ = MATCH_OUTPUT; + } else if (flags2 & kPreferMatch && matcher2_->Type(true) == MATCH_INPUT) { + match_type_ = MATCH_INPUT; + } else if (matcher1_->Type(true) == MATCH_OUTPUT) { + match_type_ = MATCH_OUTPUT; + } else if (matcher2_->Type(true) == MATCH_INPUT) { + match_type_ = MATCH_INPUT; + } else { + FSTERROR() << "ComposeFst: 1st argument cannot match on output labels " + << "and 2nd argument cannot match on input labels (sort?)."; + match_type_ = MATCH_NONE; + } +} + + +// Computes the composition of two transducers. This version is a +// delayed Fst. If FST1 transduces string x to y with weight a and FST2 +// transduces y to z with weight b, then their composition transduces +// string x to z with weight Times(x, z). +// +// The output labels of the first transducer or the input labels of +// the second transducer must be sorted (with the default matcher). +// The weights need to form a commutative semiring (valid for +// TropicalWeight and LogWeight). +// +// Complexity: +// Assuming the first FST is unsorted and the second is sorted: +// - Time: O(v1 v2 d1 (log d2 + m2)), +// - Space: O(v1 v2) +// where vi = # of states visited, di = maximum out-degree, and mi the +// maximum multiplicity of the states visited for the ith +// FST. Constant time and space to visit an input state or arc is +// assumed and exclusive of caching. +// +// Caveats: +// - ComposeFst does not trim its output (since it is a delayed operation). +// - The efficiency of composition can be strongly affected by several factors: +// - the choice of which tnansducer is sorted - prefer sorting the FST +// that has the greater average out-degree. +// - the amount of non-determinism +// - the presence and location of epsilon transitions - avoid epsilon +// transitions on the output side of the first transducer or +// the input side of the second transducer or prefer placing +// them later in a path since they delay matching and can +// introduce non-coaccessible states and transitions. +// +// This class attaches interface to implementation and handles +// reference counting, delegating most methods to ImplToFst. +template +class ComposeFst : public ImplToFst< ComposeFstImplBase > { + public: + friend class ArcIterator< ComposeFst >; + friend class StateIterator< ComposeFst >; + + typedef A Arc; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + typedef CacheState State; + typedef ComposeFstImplBase Impl; + + using ImplToFst::SetImpl; + + // Compose specifying only caching options. + ComposeFst(const Fst &fst1, const Fst &fst2, + const CacheOptions &opts = CacheOptions()) + : ImplToFst(CreateBase(fst1, fst2, opts)) {} + + // Compose specifying one shared matcher type M. Requires input + // Fsts and matcher FST type (M::FST) be Fst. Recommended for + // best code-sharing and matcher compatiblity. + template + ComposeFst(const Fst &fst1, const Fst &fst2, + const ComposeFstOptions &opts) + : ImplToFst(CreateBase1(fst1, fst2, opts)) {} + + // Compose specifying two matcher types M1 and M2. Requires input + // Fsts (of the same Arc type but o.w. arbitrary) match the + // corresponding matcher FST types (M1::FST, M2::FST). Recommended + // only for advanced use in demanding or specialized applications + // due to potential code bloat and matcher incompatibilities. + template + ComposeFst(const typename M1::FST &fst1, const typename M2::FST &fst2, + const ComposeFstImplOptions &opts) + : ImplToFst(CreateBase2(fst1, fst2, opts)) {} + + // See Fst<>::Copy() for doc. + ComposeFst(const ComposeFst &fst, bool safe = false) { + if (safe) + SetImpl(fst.GetImpl()->Copy()); + else + SetImpl(fst.GetImpl(), false); + } + + // Get a copy of this ComposeFst. See Fst<>::Copy() for further doc. + virtual ComposeFst *Copy(bool safe = false) const { + return new ComposeFst(*this, safe); + } + + virtual inline void InitStateIterator(StateIteratorData *data) const; + + virtual void InitArcIterator(StateId s, ArcIteratorData *data) const { + GetImpl()->InitArcIterator(s, data); + } + + protected: + ComposeFst() {} + + // Create compose implementation specifying two matcher types. + template + static Impl *CreateBase2( + const typename M1::FST &fst1, const typename M2::FST &fst2, + const ComposeFstImplOptions &opts) { + Impl *impl = new ComposeFstImpl(fst1, fst2, opts); + if (!(Weight::Properties() & kCommutative)) { + int64 props1 = fst1.Properties(kUnweighted, true); + int64 props2 = fst2.Properties(kUnweighted, true); + if (!(props1 & kUnweighted) && !(props2 & kUnweighted)) { + FSTERROR() << "ComposeFst: Weights must be a commutative semiring: " + << Weight::Type(); + impl->SetProperties(kError, kError); + } + } + return impl; + } + + // Create compose implementation specifying one matcher type. + // Requires input Fsts and matcher FST type (M::FST) be Fst + template + static Impl *CreateBase1(const Fst &fst1, const Fst &fst2, + const ComposeFstOptions &opts) { + ComposeFstImplOptions nopts(opts, opts.matcher1, opts.matcher2, + opts.filter, opts.state_table); + return CreateBase2(fst1, fst2, nopts); + } + + // Create compose implementation specifying no matcher type. + static Impl *CreateBase(const Fst &fst1, const Fst &fst2, + const CacheOptions &opts) { + switch (LookAheadMatchType(fst1, fst2)) { // Check for lookahead matchers + default: + case MATCH_NONE: { // Default composition (no look-ahead) + VLOG(2) << "ComposeFst: Default composition (no look-ahead)"; + ComposeFstOptions nopts(opts); + return CreateBase1(fst1, fst2, nopts); + } + case MATCH_OUTPUT: { // Lookahead on fst1 + VLOG(2) << "ComposeFst: Lookahead on fst1"; + typedef typename DefaultLookAhead::FstMatcher M; + typedef typename DefaultLookAhead::ComposeFilter F; + ComposeFstOptions nopts(opts); + return CreateBase1(fst1, fst2, nopts); + } + case MATCH_INPUT: { // Lookahead on fst2 + VLOG(2) << "ComposeFst: Lookahead on fst2"; + typedef typename DefaultLookAhead::FstMatcher M; + typedef typename DefaultLookAhead::ComposeFilter F; + ComposeFstOptions nopts(opts); + return CreateBase1(fst1, fst2, nopts); + } + } + } + + private: + // Makes visible to friends. + Impl *GetImpl() const { return ImplToFst::GetImpl(); } + + void operator=(const ComposeFst &fst); // disallow +}; + + +// Specialization for ComposeFst. +template +class StateIterator< ComposeFst > + : public CacheStateIterator< ComposeFst > { + public: + explicit StateIterator(const ComposeFst &fst) + : CacheStateIterator< ComposeFst >(fst, fst.GetImpl()) {} +}; + + +// Specialization for ComposeFst. +template +class ArcIterator< ComposeFst > + : public CacheArcIterator< ComposeFst > { + public: + typedef typename A::StateId StateId; + + ArcIterator(const ComposeFst &fst, StateId s) + : CacheArcIterator< ComposeFst >(fst.GetImpl(), s) { + if (!fst.GetImpl()->HasArcs(s)) + fst.GetImpl()->Expand(s); + } + + private: + DISALLOW_COPY_AND_ASSIGN(ArcIterator); +}; + +template inline +void ComposeFst::InitStateIterator(StateIteratorData *data) const { + data->base = new StateIterator< ComposeFst >(*this); +} + +// Useful alias when using StdArc. +typedef ComposeFst StdComposeFst; + +enum ComposeFilter { AUTO_FILTER, SEQUENCE_FILTER, ALT_SEQUENCE_FILTER, + MATCH_FILTER }; + +struct ComposeOptions { + bool connect; // Connect output + ComposeFilter filter_type; // Which pre-defined filter to use + + ComposeOptions(bool c, ComposeFilter ft = AUTO_FILTER) + : connect(c), filter_type(ft) {} + ComposeOptions() : connect(true), filter_type(AUTO_FILTER) {} +}; + +// Computes the composition of two transducers. This version writes +// the composed FST into a MurableFst. If FST1 transduces string x to +// y with weight a and FST2 transduces y to z with weight b, then +// their composition transduces string x to z with weight +// Times(x, z). +// +// The output labels of the first transducer or the input labels of +// the second transducer must be sorted. The weights need to form a +// commutative semiring (valid for TropicalWeight and LogWeight). +// +// Complexity: +// Assuming the first FST is unsorted and the second is sorted: +// - Time: O(V1 V2 D1 (log D2 + M2)), +// - Space: O(V1 V2 D1 M2) +// where Vi = # of states, Di = maximum out-degree, and Mi is +// the maximum multiplicity for the ith FST. +// +// Caveats: +// - Compose trims its output. +// - The efficiency of composition can be strongly affected by several factors: +// - the choice of which tnansducer is sorted - prefer sorting the FST +// that has the greater average out-degree. +// - the amount of non-determinism +// - the presence and location of epsilon transitions - avoid epsilon +// transitions on the output side of the first transducer or +// the input side of the second transducer or prefer placing +// them later in a path since they delay matching and can +// introduce non-coaccessible states and transitions. +template +void Compose(const Fst &ifst1, const Fst &ifst2, + MutableFst *ofst, + const ComposeOptions &opts = ComposeOptions()) { + typedef Matcher< Fst > M; + + if (opts.filter_type == AUTO_FILTER) { + CacheOptions nopts; + nopts.gc_limit = 0; // Cache only the last state for fastest copy. + *ofst = ComposeFst(ifst1, ifst2, nopts); + } else if (opts.filter_type == SEQUENCE_FILTER) { + ComposeFstOptions copts; + copts.gc_limit = 0; // Cache only the last state for fastest copy. + *ofst = ComposeFst(ifst1, ifst2, copts); + } else if (opts.filter_type == ALT_SEQUENCE_FILTER) { + ComposeFstOptions > copts; + copts.gc_limit = 0; // Cache only the last state for fastest copy. + *ofst = ComposeFst(ifst1, ifst2, copts); + } else if (opts.filter_type == MATCH_FILTER) { + ComposeFstOptions > copts; + copts.gc_limit = 0; // Cache only the last state for fastest copy. + *ofst = ComposeFst(ifst1, ifst2, copts); + } + + if (opts.connect) + Connect(ofst); +} + +} // namespace fst + +#endif // FST_LIB_COMPOSE_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/concat.h b/kaldi_io/src/tools/openfst/include/fst/concat.h new file mode 100644 index 0000000..8500d50 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/concat.h @@ -0,0 +1,246 @@ +// concat.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Functions and classes to compute the concat of two FSTs. + +#ifndef FST_LIB_CONCAT_H__ +#define FST_LIB_CONCAT_H__ + +#include +using std::vector; +#include + +#include +#include + + +namespace fst { + +// Computes the concatenation (product) of two FSTs. If FST1 +// transduces string x to y with weight a and FST2 transduces string w +// to v with weight b, then their concatenation transduces string xw +// to yv with Times(a, b). +// +// This version modifies its MutableFst argument (in first position). +// +// Complexity: +// - Time: O(V1 + V2 + E2) +// - Space: O(V1 + V2 + E2) +// where Vi = # of states and Ei = # of arcs of the ith FST. +// +template +void Concat(MutableFst *fst1, const Fst &fst2) { + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + + // TODO(riley): restore when voice actions issues fixed + // Check that the symbol table are compatible + if (!CompatSymbols(fst1->InputSymbols(), fst2.InputSymbols()) || + !CompatSymbols(fst1->OutputSymbols(), fst2.OutputSymbols())) { + LOG(ERROR) << "Concat: input/output symbol tables of 1st argument " + << "do not match input/output symbol tables of 2nd argument"; + // fst1->SetProperties(kError, kError); + // return; + } + + uint64 props1 = fst1->Properties(kFstProperties, false); + uint64 props2 = fst2.Properties(kFstProperties, false); + + StateId start1 = fst1->Start(); + if (start1 == kNoStateId) { + if (props2 & kError) fst1->SetProperties(kError, kError); + return; + } + + StateId numstates1 = fst1->NumStates(); + if (fst2.Properties(kExpanded, false)) + fst1->ReserveStates(numstates1 + CountStates(fst2)); + + for (StateIterator< Fst > siter2(fst2); + !siter2.Done(); + siter2.Next()) { + StateId s1 = fst1->AddState(); + StateId s2 = siter2.Value(); + fst1->SetFinal(s1, fst2.Final(s2)); + fst1->ReserveArcs(s1, fst2.NumArcs(s2)); + for (ArcIterator< Fst > aiter(fst2, s2); + !aiter.Done(); + aiter.Next()) { + Arc arc = aiter.Value(); + arc.nextstate += numstates1; + fst1->AddArc(s1, arc); + } + } + + StateId start2 = fst2.Start(); + for (StateId s1 = 0; s1 < numstates1; ++s1) { + Weight final = fst1->Final(s1); + if (final != Weight::Zero()) { + fst1->SetFinal(s1, Weight::Zero()); + if (start2 != kNoStateId) + fst1->AddArc(s1, Arc(0, 0, final, start2 + numstates1)); + } + } + if (start2 != kNoStateId) + fst1->SetProperties(ConcatProperties(props1, props2), kFstProperties); +} + +// Computes the concatentation of two FSTs. This version modifies its +// MutableFst argument (in second position). +// +// Complexity: +// - Time: O(V1 + E1) +// - Space: O(V1 + E1) +// where Vi = # of states and Ei = # of arcs of the ith FST. +// +template +void Concat(const Fst &fst1, MutableFst *fst2) { + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + + // Check that the symbol table are compatible + if (!CompatSymbols(fst1.InputSymbols(), fst2->InputSymbols()) || + !CompatSymbols(fst1.OutputSymbols(), fst2->OutputSymbols())) { + LOG(ERROR) << "Concat: input/output symbol tables of 1st argument " + << "do not match input/output symbol tables of 2nd argument"; + // fst2->SetProperties(kError, kError); + // return; + } + + uint64 props1 = fst1.Properties(kFstProperties, false); + uint64 props2 = fst2->Properties(kFstProperties, false); + + StateId start2 = fst2->Start(); + if (start2 == kNoStateId) { + if (props1 & kError) fst2->SetProperties(kError, kError); + return; + } + + StateId numstates2 = fst2->NumStates(); + if (fst1.Properties(kExpanded, false)) + fst2->ReserveStates(numstates2 + CountStates(fst1)); + + for (StateIterator< Fst > siter(fst1); + !siter.Done(); + siter.Next()) { + StateId s1 = siter.Value(); + StateId s2 = fst2->AddState(); + Weight final = fst1.Final(s1); + fst2->ReserveArcs(s2, fst1.NumArcs(s1) + (final != Weight::Zero() ? 1 : 0)); + if (final != Weight::Zero()) + fst2->AddArc(s2, Arc(0, 0, final, start2)); + for (ArcIterator< Fst > aiter(fst1, s1); + !aiter.Done(); + aiter.Next()) { + Arc arc = aiter.Value(); + arc.nextstate += numstates2; + fst2->AddArc(s2, arc); + } + } + StateId start1 = fst1.Start(); + fst2->SetStart(start1 == kNoStateId ? fst2->AddState() : start1 + numstates2); + if (start1 != kNoStateId) + fst2->SetProperties(ConcatProperties(props1, props2), kFstProperties); +} + + +// Computes the concatentation of two FSTs. This version modifies its +// RationalFst input (in first position). +template +void Concat(RationalFst *fst1, const Fst &fst2) { + fst1->GetImpl()->AddConcat(fst2, true); +} + +// Computes the concatentation of two FSTs. This version modifies its +// RationalFst input (in second position). +template +void Concat(const Fst &fst1, RationalFst *fst2) { + fst2->GetImpl()->AddConcat(fst1, false); +} + +typedef RationalFstOptions ConcatFstOptions; + + +// Computes the concatenation (product) of two FSTs; this version is a +// delayed Fst. If FST1 transduces string x to y with weight a and FST2 +// transduces string w to v with weight b, then their concatenation +// transduces string xw to yv with Times(a, b). +// +// Complexity: +// - Time: O(v1 + e1 + v2 + e2), +// - Space: O(v1 + v2) +// where vi = # of states visited and ei = # of arcs visited of the +// ith FST. Constant time and space to visit an input state or arc is +// assumed and exclusive of caching. +template +class ConcatFst : public RationalFst { + public: + using ImplToFst< RationalFstImpl >::GetImpl; + + typedef A Arc; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + + ConcatFst(const Fst &fst1, const Fst &fst2) { + GetImpl()->InitConcat(fst1, fst2); + } + + ConcatFst(const Fst &fst1, const Fst &fst2, + const ConcatFstOptions &opts) : RationalFst(opts) { + GetImpl()->InitConcat(fst1, fst2); + } + + // See Fst<>::Copy() for doc. + ConcatFst(const ConcatFst &fst, bool safe = false) + : RationalFst(fst, safe) {} + + // Get a copy of this ConcatFst. See Fst<>::Copy() for further doc. + virtual ConcatFst *Copy(bool safe = false) const { + return new ConcatFst(*this, safe); + } +}; + + +// Specialization for ConcatFst. +template +class StateIterator< ConcatFst > : public StateIterator< RationalFst > { + public: + explicit StateIterator(const ConcatFst &fst) + : StateIterator< RationalFst >(fst) {} +}; + + +// Specialization for ConcatFst. +template +class ArcIterator< ConcatFst > : public ArcIterator< RationalFst > { + public: + typedef typename A::StateId StateId; + + ArcIterator(const ConcatFst &fst, StateId s) + : ArcIterator< RationalFst >(fst, s) {} +}; + + +// Useful alias when using StdArc. +typedef ConcatFst StdConcatFst; + +} // namespace fst + +#endif // FST_LIB_CONCAT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/config.h b/kaldi_io/src/tools/openfst/include/fst/config.h new file mode 100644 index 0000000..046b49c --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/config.h @@ -0,0 +1,12 @@ +/* src/include/fst/config.h. Generated from config.h.in by configure. */ +// OpenFst config file + +/* Define to 1 if you have the ICU library. */ +/* #undef HAVE_ICU */ + +/* Define to 1 if the system has the type `std::tr1::hash'. */ +#define HAVE_STD__TR1__HASH_LONG_LONG_UNSIGNED_ 1 + +/* Define to 1 if the system has the type `__gnu_cxx::slist'. */ +#define HAVE___GNU_CXX__SLIST_INT_ 1 diff --git a/kaldi_io/src/tools/openfst/include/fst/connect.h b/kaldi_io/src/tools/openfst/include/fst/connect.h new file mode 100644 index 0000000..427808c --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/connect.h @@ -0,0 +1,319 @@ +// connect.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Classes and functions to remove unsuccessful paths from an Fst. + +#ifndef FST_LIB_CONNECT_H__ +#define FST_LIB_CONNECT_H__ + +#include +using std::vector; + +#include +#include +#include + + +namespace fst { + +// Finds and returns connected components. Use with Visit(). +template +class CcVisitor { + public: + typedef A Arc; + typedef typename Arc::Weight Weight; + typedef typename A::StateId StateId; + + // cc[i]: connected component number for state i. + CcVisitor(vector *cc) + : comps_(new UnionFind(0, kNoStateId)), + cc_(cc), + nstates_(0) { } + + // comps: connected components equiv classes. + CcVisitor(UnionFind *comps) + : comps_(comps), + cc_(0), + nstates_(0) { } + + ~CcVisitor() { + if (cc_) // own comps_? + delete comps_; + } + + void InitVisit(const Fst &fst) { } + + bool InitState(StateId s, StateId root) { + ++nstates_; + if (comps_->FindSet(s) == kNoStateId) + comps_->MakeSet(s); + return true; + } + + bool WhiteArc(StateId s, const A &arc) { + comps_->MakeSet(arc.nextstate); + comps_->Union(s, arc.nextstate); + return true; + } + + bool GreyArc(StateId s, const A &arc) { + comps_->Union(s, arc.nextstate); + return true; + } + + bool BlackArc(StateId s, const A &arc) { + comps_->Union(s, arc.nextstate); + return true; + } + + void FinishState(StateId s) { } + + void FinishVisit() { + if (cc_) + GetCcVector(cc_); + } + + // cc[i]: connected component number for state i. + // Returns number of components. + int GetCcVector(vector *cc) { + cc->clear(); + cc->resize(nstates_, kNoStateId); + StateId ncomp = 0; + for (StateId i = 0; i < nstates_; ++i) { + StateId rep = comps_->FindSet(i); + StateId &comp = (*cc)[rep]; + if (comp == kNoStateId) { + comp = ncomp; + ++ncomp; + } + (*cc)[i] = comp; + } + return ncomp; + } + + private: + UnionFind *comps_; // Components + vector *cc_; // State's cc number + StateId nstates_; // State count +}; + + +// Finds and returns strongly-connected components, accessible and +// coaccessible states and related properties. Uses Tarjan's single +// DFS SCC algorithm (see Aho, et al, "Design and Analysis of Computer +// Algorithms", 189pp). Use with DfsVisit(); +template +class SccVisitor { + public: + typedef A Arc; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + + // scc[i]: strongly-connected component number for state i. + // SCC numbers will be in topological order for acyclic input. + // access[i]: accessibility of state i. + // coaccess[i]: coaccessibility of state i. + // Any of above can be NULL. + // props: related property bits (cyclicity, initial cyclicity, + // accessibility, coaccessibility) set/cleared (o.w. unchanged). + SccVisitor(vector *scc, vector *access, + vector *coaccess, uint64 *props) + : scc_(scc), access_(access), coaccess_(coaccess), props_(props) {} + SccVisitor(uint64 *props) + : scc_(0), access_(0), coaccess_(0), props_(props) {} + + void InitVisit(const Fst &fst); + + bool InitState(StateId s, StateId root); + + bool TreeArc(StateId s, const A &arc) { return true; } + + bool BackArc(StateId s, const A &arc) { + StateId t = arc.nextstate; + if ((*dfnumber_)[t] < (*lowlink_)[s]) + (*lowlink_)[s] = (*dfnumber_)[t]; + if ((*coaccess_)[t]) + (*coaccess_)[s] = true; + *props_ |= kCyclic; + *props_ &= ~kAcyclic; + if (arc.nextstate == start_) { + *props_ |= kInitialCyclic; + *props_ &= ~kInitialAcyclic; + } + return true; + } + + bool ForwardOrCrossArc(StateId s, const A &arc) { + StateId t = arc.nextstate; + if ((*dfnumber_)[t] < (*dfnumber_)[s] /* cross edge */ && + (*onstack_)[t] && (*dfnumber_)[t] < (*lowlink_)[s]) + (*lowlink_)[s] = (*dfnumber_)[t]; + if ((*coaccess_)[t]) + (*coaccess_)[s] = true; + return true; + } + + void FinishState(StateId s, StateId p, const A *); + + void FinishVisit() { + // Numbers SCC's in topological order when acyclic. + if (scc_) + for (StateId i = 0; i < scc_->size(); ++i) + (*scc_)[i] = nscc_ - 1 - (*scc_)[i]; + if (coaccess_internal_) + delete coaccess_; + delete dfnumber_; + delete lowlink_; + delete onstack_; + delete scc_stack_; + } + + private: + vector *scc_; // State's scc number + vector *access_; // State's accessibility + vector *coaccess_; // State's coaccessibility + uint64 *props_; + const Fst *fst_; + StateId start_; + StateId nstates_; // State count + StateId nscc_; // SCC count + bool coaccess_internal_; + vector *dfnumber_; // state discovery times + vector *lowlink_; // lowlink[s] == dfnumber[s] => SCC root + vector *onstack_; // is a state on the SCC stack + vector *scc_stack_; // SCC stack (w/ random access) +}; + +template inline +void SccVisitor::InitVisit(const Fst &fst) { + if (scc_) + scc_->clear(); + if (access_) + access_->clear(); + if (coaccess_) { + coaccess_->clear(); + coaccess_internal_ = false; + } else { + coaccess_ = new vector; + coaccess_internal_ = true; + } + *props_ |= kAcyclic | kInitialAcyclic | kAccessible | kCoAccessible; + *props_ &= ~(kCyclic | kInitialCyclic | kNotAccessible | kNotCoAccessible); + fst_ = &fst; + start_ = fst.Start(); + nstates_ = 0; + nscc_ = 0; + dfnumber_ = new vector; + lowlink_ = new vector; + onstack_ = new vector; + scc_stack_ = new vector; +} + +template inline +bool SccVisitor::InitState(StateId s, StateId root) { + scc_stack_->push_back(s); + while (dfnumber_->size() <= s) { + if (scc_) + scc_->push_back(-1); + if (access_) + access_->push_back(false); + coaccess_->push_back(false); + dfnumber_->push_back(-1); + lowlink_->push_back(-1); + onstack_->push_back(false); + } + (*dfnumber_)[s] = nstates_; + (*lowlink_)[s] = nstates_; + (*onstack_)[s] = true; + if (root == start_) { + if (access_) + (*access_)[s] = true; + } else { + if (access_) + (*access_)[s] = false; + *props_ |= kNotAccessible; + *props_ &= ~kAccessible; + } + ++nstates_; + return true; +} + +template inline +void SccVisitor::FinishState(StateId s, StateId p, const A *) { + if (fst_->Final(s) != Weight::Zero()) + (*coaccess_)[s] = true; + if ((*dfnumber_)[s] == (*lowlink_)[s]) { // root of new SCC + bool scc_coaccess = false; + size_t i = scc_stack_->size(); + StateId t; + do { + t = (*scc_stack_)[--i]; + if ((*coaccess_)[t]) + scc_coaccess = true; + } while (s != t); + do { + t = scc_stack_->back(); + if (scc_) + (*scc_)[t] = nscc_; + if (scc_coaccess) + (*coaccess_)[t] = true; + (*onstack_)[t] = false; + scc_stack_->pop_back(); + } while (s != t); + if (!scc_coaccess) { + *props_ |= kNotCoAccessible; + *props_ &= ~kCoAccessible; + } + ++nscc_; + } + if (p != kNoStateId) { + if ((*coaccess_)[s]) + (*coaccess_)[p] = true; + if ((*lowlink_)[s] < (*lowlink_)[p]) + (*lowlink_)[p] = (*lowlink_)[s]; + } +} + + +// Trims an FST, removing states and arcs that are not on successful +// paths. This version modifies its input. +// +// Complexity: +// - Time: O(V + E) +// - Space: O(V + E) +// where V = # of states and E = # of arcs. +template +void Connect(MutableFst *fst) { + typedef typename Arc::StateId StateId; + + vector access; + vector coaccess; + uint64 props = 0; + SccVisitor scc_visitor(0, &access, &coaccess, &props); + DfsVisit(*fst, &scc_visitor); + vector dstates; + for (StateId s = 0; s < access.size(); ++s) + if (!access[s] || !coaccess[s]) + dstates.push_back(s); + fst->DeleteStates(dstates); + fst->SetProperties(kAccessible | kCoAccessible, kAccessible | kCoAccessible); +} + +} // namespace fst + +#endif // FST_LIB_CONNECT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/const-fst.h b/kaldi_io/src/tools/openfst/include/fst/const-fst.h new file mode 100644 index 0000000..e6e85af --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/const-fst.h @@ -0,0 +1,497 @@ +// const-fst.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Simple concrete immutable FST whose states and arcs are each stored +// in single arrays. + +#ifndef FST_LIB_CONST_FST_H__ +#define FST_LIB_CONST_FST_H__ + +#include +#include +using std::vector; + +#include +#include // For optional argument declarations +#include +#include +#include + + +namespace fst { + +template class ConstFst; +template void Cast(const F &, G *); + +// States and arcs each implemented by single arrays, templated on the +// Arc definition. The unsigned type U is used to represent indices into +// the arc array. +template +class ConstFstImpl : public FstImpl { + public: + using FstImpl::SetInputSymbols; + using FstImpl::SetOutputSymbols; + using FstImpl::SetType; + using FstImpl::SetProperties; + using FstImpl::Properties; + + typedef A Arc; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + typedef U Unsigned; + + ConstFstImpl() + : states_region_(0), arcs_region_(0), states_(0), arcs_(0), nstates_(0), + narcs_(0), start_(kNoStateId) { + string type = "const"; + if (sizeof(U) != sizeof(uint32)) { + string size; + Int64ToStr(8 * sizeof(U), &size); + type += size; + } + SetType(type); + SetProperties(kNullProperties | kStaticProperties); + } + + explicit ConstFstImpl(const Fst &fst); + + ~ConstFstImpl() { + delete arcs_region_; + delete states_region_; + } + + StateId Start() const { return start_; } + + Weight Final(StateId s) const { return states_[s].final; } + + StateId NumStates() const { return nstates_; } + + size_t NumArcs(StateId s) const { return states_[s].narcs; } + + size_t NumInputEpsilons(StateId s) const { return states_[s].niepsilons; } + + size_t NumOutputEpsilons(StateId s) const { return states_[s].noepsilons; } + + static ConstFstImpl *Read(istream &strm, const FstReadOptions &opts); + + A *Arcs(StateId s) { return arcs_ + states_[s].pos; } + + // Provide information needed for generic state iterator + void InitStateIterator(StateIteratorData *data) const { + data->base = 0; + data->nstates = nstates_; + } + + // Provide information needed for the generic arc iterator + void InitArcIterator(StateId s, ArcIteratorData *data) const { + data->base = 0; + data->arcs = arcs_ + states_[s].pos; + data->narcs = states_[s].narcs; + data->ref_count = 0; + } + + private: + friend class ConstFst; // Allow finding narcs_, nstates_ during Write + + // States implemented by array *states_ below, arcs by (single) *arcs_. + struct State { + Weight final; // Final weight + Unsigned pos; // Start of state's arcs in *arcs_ + Unsigned narcs; // Number of arcs (per state) + Unsigned niepsilons; // # of input epsilons + Unsigned noepsilons; // # of output epsilons + State() : final(Weight::Zero()), niepsilons(0), noepsilons(0) {} + }; + + // Properties always true of this Fst class + static const uint64 kStaticProperties = kExpanded; + // Current unaligned file format version. The unaligned version was added and + // made the default since the aligned version does not work on pipes. + static const int kFileVersion = 2; + // Current aligned file format version + static const int kAlignedFileVersion = 1; + // Minimum file format version supported + static const int kMinFileVersion = 1; + + MappedFile *states_region_; // Mapped file for states + MappedFile *arcs_region_; // Mapped file for arcs + State *states_; // States represenation + A *arcs_; // Arcs representation + StateId nstates_; // Number of states + size_t narcs_; // Number of arcs (per FST) + StateId start_; // Initial state + + DISALLOW_COPY_AND_ASSIGN(ConstFstImpl); +}; + +template +const uint64 ConstFstImpl::kStaticProperties; +template +const int ConstFstImpl::kFileVersion; +template +const int ConstFstImpl::kAlignedFileVersion; +template +const int ConstFstImpl::kMinFileVersion; + + +template +ConstFstImpl::ConstFstImpl(const Fst &fst) : nstates_(0), narcs_(0) { + string type = "const"; + if (sizeof(U) != sizeof(uint32)) { + string size; + Int64ToStr(sizeof(U) * 8, &size); + type += size; + } + SetType(type); + SetInputSymbols(fst.InputSymbols()); + SetOutputSymbols(fst.OutputSymbols()); + start_ = fst.Start(); + + // Count # of states and arcs. + for (StateIterator< Fst > siter(fst); + !siter.Done(); + siter.Next()) { + ++nstates_; + StateId s = siter.Value(); + for (ArcIterator< Fst > aiter(fst, s); + !aiter.Done(); + aiter.Next()) + ++narcs_; + } + states_region_ = MappedFile::Allocate(nstates_ * sizeof(*states_)); + arcs_region_ = MappedFile::Allocate(narcs_ * sizeof(*arcs_)); + states_ = reinterpret_cast(states_region_->mutable_data()); + arcs_ = reinterpret_cast(arcs_region_->mutable_data()); + size_t pos = 0; + for (StateId s = 0; s < nstates_; ++s) { + states_[s].final = fst.Final(s); + states_[s].pos = pos; + states_[s].narcs = 0; + states_[s].niepsilons = 0; + states_[s].noepsilons = 0; + for (ArcIterator< Fst > aiter(fst, s); + !aiter.Done(); + aiter.Next()) { + const A &arc = aiter.Value(); + ++states_[s].narcs; + if (arc.ilabel == 0) + ++states_[s].niepsilons; + if (arc.olabel == 0) + ++states_[s].noepsilons; + arcs_[pos++] = arc; + } + } + SetProperties(fst.Properties(kCopyProperties, true) | kStaticProperties); +} + + +template +ConstFstImpl *ConstFstImpl::Read(istream &strm, + const FstReadOptions &opts) { + ConstFstImpl *impl = new ConstFstImpl; + FstHeader hdr; + if (!impl->ReadHeader(strm, opts, kMinFileVersion, &hdr)) { + delete impl; + return 0; + } + impl->start_ = hdr.Start(); + impl->nstates_ = hdr.NumStates(); + impl->narcs_ = hdr.NumArcs(); + + // Ensures compatibility + if (hdr.Version() == kAlignedFileVersion) + hdr.SetFlags(hdr.GetFlags() | FstHeader::IS_ALIGNED); + + if ((hdr.GetFlags() & FstHeader::IS_ALIGNED) && !AlignInput(strm)) { + LOG(ERROR) << "ConstFst::Read: Alignment failed: " << opts.source; + delete impl; + return 0; + } + + size_t b = impl->nstates_ * sizeof(typename ConstFstImpl::State); + impl->states_region_ = MappedFile::Map(&strm, opts, b); + if (!strm || impl->states_region_ == NULL) { + LOG(ERROR) << "ConstFst::Read: Read failed: " << opts.source; + delete impl; + return 0; + } + impl->states_ = reinterpret_cast( + impl->states_region_->mutable_data()); + if ((hdr.GetFlags() & FstHeader::IS_ALIGNED) && !AlignInput(strm)) { + LOG(ERROR) << "ConstFst::Read: Alignment failed: " << opts.source; + delete impl; + return 0; + } + + b = impl->narcs_ * sizeof(A); + impl->arcs_region_ = MappedFile::Map(&strm, opts, b); + if (!strm || impl->arcs_region_ == NULL) { + LOG(ERROR) << "ConstFst::Read: Read failed: " << opts.source; + delete impl; + return 0; + } + impl->arcs_ = reinterpret_cast(impl->arcs_region_->mutable_data()); + return impl; +} + +// Simple concrete immutable FST. This class attaches interface to +// implementation and handles reference counting, delegating most +// methods to ImplToExpandedFst. The unsigned type U is used to +// represent indices into the arc array (uint32 by default, declared +// in fst-decl.h). +template +class ConstFst : public ImplToExpandedFst< ConstFstImpl > { + public: + friend class StateIterator< ConstFst >; + friend class ArcIterator< ConstFst >; + template void friend Cast(const F &, G *); + + typedef A Arc; + typedef typename A::StateId StateId; + typedef ConstFstImpl Impl; + typedef U Unsigned; + + ConstFst() : ImplToExpandedFst(new Impl()) {} + + explicit ConstFst(const Fst &fst) + : ImplToExpandedFst(new Impl(fst)) {} + + ConstFst(const ConstFst &fst) : ImplToExpandedFst(fst) {} + + // Get a copy of this ConstFst. See Fst<>::Copy() for further doc. + virtual ConstFst *Copy(bool safe = false) const { + return new ConstFst(*this); + } + + // Read a ConstFst from an input stream; return NULL on error + static ConstFst *Read(istream &strm, const FstReadOptions &opts) { + Impl* impl = Impl::Read(strm, opts); + return impl ? new ConstFst(impl) : 0; + } + + // Read a ConstFst from a file; return NULL on error + // Empty filename reads from standard input + static ConstFst *Read(const string &filename) { + Impl* impl = ImplToExpandedFst::Read(filename); + return impl ? new ConstFst(impl) : 0; + } + + virtual bool Write(ostream &strm, const FstWriteOptions &opts) const { + return WriteFst(*this, strm, opts); + } + + virtual bool Write(const string &filename) const { + return Fst::WriteFile(filename); + } + + template + static bool WriteFst(const F &fst, ostream &strm, + const FstWriteOptions &opts); + + virtual void InitStateIterator(StateIteratorData *data) const { + GetImpl()->InitStateIterator(data); + } + + virtual void InitArcIterator(StateId s, ArcIteratorData *data) const { + GetImpl()->InitArcIterator(s, data); + } + + private: + explicit ConstFst(Impl *impl) : ImplToExpandedFst(impl) {} + + // Makes visible to friends. + Impl *GetImpl() const { return ImplToFst >::GetImpl(); } + + void SetImpl(Impl *impl, bool own_impl = true) { + ImplToFst< Impl, ExpandedFst >::SetImpl(impl, own_impl); + } + + // Use overloading to extract the type of the argument. + static Impl* GetImplIfConstFst(const ConstFst &const_fst) { + return const_fst.GetImpl(); + } + + // Note that this does not give privileged treatment to subtypes of ConstFst. + template + static Impl* GetImplIfConstFst(const NonConstFst& fst) { + return NULL; + } + + void operator=(const ConstFst &fst); // disallow +}; + +// Writes Fst in Const format, potentially with a pass over the machine +// before writing to compute number of states and arcs. +// +template +template +bool ConstFst::WriteFst(const F &fst, ostream &strm, + const FstWriteOptions &opts) { + int file_version = opts.align ? ConstFstImpl::kAlignedFileVersion : + ConstFstImpl::kFileVersion; + size_t num_arcs = -1, num_states = -1; + size_t start_offset = 0; + bool update_header = true; + if (Impl* impl = GetImplIfConstFst(fst)) { + num_arcs = impl->narcs_; + num_states = impl->nstates_; + update_header = false; + } else if ((start_offset = strm.tellp()) == -1) { + // precompute values needed for header when we cannot seek to rewrite it. + num_arcs = 0; + num_states = 0; + for (StateIterator siter(fst); !siter.Done(); siter.Next()) { + num_arcs += fst.NumArcs(siter.Value()); + ++num_states; + } + update_header = false; + } + FstHeader hdr; + hdr.SetStart(fst.Start()); + hdr.SetNumStates(num_states); + hdr.SetNumArcs(num_arcs); + string type = "const"; + if (sizeof(U) != sizeof(uint32)) { + string size; + Int64ToStr(8 * sizeof(U), &size); + type += size; + } + uint64 properties = fst.Properties(kCopyProperties, true) | + ConstFstImpl::kStaticProperties; + FstImpl::WriteFstHeader(fst, strm, opts, file_version, type, properties, + &hdr); + if (opts.align && !AlignOutput(strm)) { + LOG(ERROR) << "Could not align file during write after header"; + return false; + } + size_t pos = 0, states = 0; + typename ConstFstImpl::State state; + for (StateIterator siter(fst); !siter.Done(); siter.Next()) { + state.final = fst.Final(siter.Value()); + state.pos = pos; + state.narcs = fst.NumArcs(siter.Value()); + state.niepsilons = fst.NumInputEpsilons(siter.Value()); + state.noepsilons = fst.NumOutputEpsilons(siter.Value()); + strm.write(reinterpret_cast(&state), sizeof(state)); + pos += state.narcs; + ++states; + } + hdr.SetNumStates(states); + hdr.SetNumArcs(pos); + if (opts.align && !AlignOutput(strm)) { + LOG(ERROR) << "Could not align file during write after writing states"; + } + for (StateIterator siter(fst); !siter.Done(); siter.Next()) { + StateId s = siter.Value(); + for (ArcIterator aiter(fst, s); !aiter.Done(); aiter.Next()) { + const A &arc = aiter.Value(); + strm.write(reinterpret_cast(&arc), sizeof(arc)); + } + } + strm.flush(); + if (!strm) { + LOG(ERROR) << "ConstFst Write write failed: " << opts.source; + return false; + } + if (update_header) { + return FstImpl::UpdateFstHeader(fst, strm, opts, file_version, type, + properties, &hdr, start_offset); + } else { + if (hdr.NumStates() != num_states) { + LOG(ERROR) << "Inconsistent number of states observed during write"; + return false; + } + if (hdr.NumArcs() != num_arcs) { + LOG(ERROR) << "Inconsistent number of arcs observed during write"; + return false; + } + } + return true; +} + +// Specialization for ConstFst; see generic version in fst.h +// for sample usage (but use the ConstFst type!). This version +// should inline. +template +class StateIterator< ConstFst > { + public: + typedef typename A::StateId StateId; + + explicit StateIterator(const ConstFst &fst) + : nstates_(fst.GetImpl()->NumStates()), s_(0) {} + + bool Done() const { return s_ >= nstates_; } + + StateId Value() const { return s_; } + + void Next() { ++s_; } + + void Reset() { s_ = 0; } + + private: + StateId nstates_; + StateId s_; + + DISALLOW_COPY_AND_ASSIGN(StateIterator); +}; + + +// Specialization for ConstFst; see generic version in fst.h +// for sample usage (but use the ConstFst type!). This version +// should inline. +template +class ArcIterator< ConstFst > { + public: + typedef typename A::StateId StateId; + + ArcIterator(const ConstFst &fst, StateId s) + : arcs_(fst.GetImpl()->Arcs(s)), + narcs_(fst.GetImpl()->NumArcs(s)), i_(0) {} + + bool Done() const { return i_ >= narcs_; } + + const A& Value() const { return arcs_[i_]; } + + void Next() { ++i_; } + + size_t Position() const { return i_; } + + void Reset() { i_ = 0; } + + void Seek(size_t a) { i_ = a; } + + uint32 Flags() const { + return kArcValueFlags; + } + + void SetFlags(uint32 f, uint32 m) {} + + private: + const A *arcs_; + size_t narcs_; + size_t i_; + + DISALLOW_COPY_AND_ASSIGN(ArcIterator); +}; + +// A useful alias when using StdArc. +typedef ConstFst StdConstFst; + +} // namespace fst + +#endif // FST_LIB_CONST_FST_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/determinize.h b/kaldi_io/src/tools/openfst/include/fst/determinize.h new file mode 100644 index 0000000..9ff8723 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/determinize.h @@ -0,0 +1,1015 @@ +// determinize.h + + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Functions and classes to determinize an FST. + +#ifndef FST_LIB_DETERMINIZE_H__ +#define FST_LIB_DETERMINIZE_H__ + +#include +#include +#include +using std::tr1::unordered_map; +using std::tr1::unordered_multimap; +#include +#include +#include +#include +using std::vector; + +#include +#include +#include +#include +#include +#include + + +namespace fst { + +// +// COMMON DIVISORS - these are used in determinization to compute +// the transition weights. In the simplest case, it is just the same +// as the semiring Plus(). However, other choices permit more efficient +// determinization when the output contains strings. +// + +// The default common divisor uses the semiring Plus. +template +class DefaultCommonDivisor { + public: + typedef W Weight; + + W operator()(const W &w1, const W &w2) const { return Plus(w1, w2); } +}; + + +// The label common divisor for a (left) string semiring selects a +// single letter common prefix or the empty string. This is used in +// the determinization of output strings so that at most a single +// letter will appear in the output of a transtion. +template +class LabelCommonDivisor { + public: + typedef StringWeight Weight; + + Weight operator()(const Weight &w1, const Weight &w2) const { + StringWeightIterator iter1(w1); + StringWeightIterator iter2(w2); + + if (!(StringWeight::Properties() & kLeftSemiring)) { + FSTERROR() << "LabelCommonDivisor: Weight needs to be left semiring"; + return Weight::NoWeight(); + } else if (w1.Size() == 0 || w2.Size() == 0) { + return Weight::One(); + } else if (w1 == Weight::Zero()) { + return Weight(iter2.Value()); + } else if (w2 == Weight::Zero()) { + return Weight(iter1.Value()); + } else if (iter1.Value() == iter2.Value()) { + return Weight(iter1.Value()); + } else { + return Weight::One(); + } + } +}; + + +// The gallic common divisor uses the label common divisor on the +// string component and the template argument D common divisor on the +// weight component, which defaults to the default common divisor. +template > +class GallicCommonDivisor { + public: + typedef GallicWeight Weight; + + Weight operator()(const Weight &w1, const Weight &w2) const { + return Weight(label_common_divisor_(w1.Value1(), w2.Value1()), + weight_common_divisor_(w1.Value2(), w2.Value2())); + } + + private: + LabelCommonDivisor label_common_divisor_; + D weight_common_divisor_; +}; + + +// Represents an element in a subset +template +struct DeterminizeElement { + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + DeterminizeElement() {} + + DeterminizeElement(StateId s, Weight w) : state_id(s), weight(w) {} + + bool operator==(const DeterminizeElement & element) const { + return state_id == element.state_id && weight == element.weight; + } + + bool operator<(const DeterminizeElement & element) const { + return state_id < element.state_id || + (state_id == element.state_id && weight == element.weight); + } + + StateId state_id; // Input state Id + Weight weight; // Residual weight +}; + + +// +// DETERMINIZE FILTERS - these can be used in determinization to compute +// transformations on the subsets prior to their being added as destination +// states. The filter operates on a map between a label and the +// corresponding destination subsets. The possibly modified map is +// then used to construct the destination states for arcs exiting state 's'. +// It must define the ordered map type LabelMap and have a default +// and copy constructor. + +// A determinize filter that does not modify its input. +template +struct IdentityDeterminizeFilter { + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef slist< DeterminizeElement > Subset; + typedef map LabelMap; + + static uint64 Properties(uint64 props) { return props; } + + void operator()(StateId s, LabelMap *label_map) {} +}; + + +// +// DETERMINIZATION STATE TABLES +// +// The determiziation state table has the form: +// +// template +// class DeterminizeStateTable { +// public: +// typedef typename Arc::StateId StateId; +// typedef DeterminizeElement Element; +// typedef slist Subset; +// +// // Required constuctor +// DeterminizeStateTable(); +// +// // Required copy constructor that does not copy state +// DeterminizeStateTable(const DeterminizeStateTable &table); +// +// // Lookup state ID by subset (not depending of the element order). +// // If it doesn't exist, then add it. FindState takes +// // ownership of the subset argument (so that it doesn't have to +// // copy it if it creates a new state). +// StateId FindState(Subset *subset); +// +// // Lookup subset by ID. +// const Subset *FindSubset(StateId id) const; +// }; +// + +// The default determinization state table based on the +// compact hash bi-table. +template +class DefaultDeterminizeStateTable { + public: + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + typedef DeterminizeElement Element; + typedef slist Subset; + + explicit DefaultDeterminizeStateTable(size_t table_size = 0) + : table_size_(table_size), + subsets_(table_size_, new SubsetKey(), new SubsetEqual(&elements_)) { } + + DefaultDeterminizeStateTable(const DefaultDeterminizeStateTable &table) + : table_size_(table.table_size_), + subsets_(table_size_, new SubsetKey(), new SubsetEqual(&elements_)) { } + + ~DefaultDeterminizeStateTable() { + for (StateId s = 0; s < subsets_.Size(); ++s) + delete subsets_.FindEntry(s); + } + + // Finds the state corresponding to a subset. Only creates a new + // state if the subset is not found. FindState takes ownership of + // the subset argument (so that it doesn't have to copy it if it + // creates a new state). + StateId FindState(Subset *subset) { + StateId ns = subsets_.Size(); + StateId s = subsets_.FindId(subset); + if (s != ns) delete subset; // subset found + return s; + } + + const Subset* FindSubset(StateId s) { return subsets_.FindEntry(s); } + + private: + // Comparison object for hashing Subset(s). Subsets are not sorted in this + // implementation, so ordering must not be assumed in the equivalence + // test. + class SubsetEqual { + public: + SubsetEqual() { // needed for compilation but should never be called + FSTERROR() << "SubsetEqual: default constructor not implemented"; + } + + // Constructor takes vector needed to check equality. See immediately + // below for constraints on it. + explicit SubsetEqual(vector *elements) + : elements_(elements) {} + + // At each call to operator(), the elements_ vector should contain + // only NULLs. When this operator returns, elements_ will still + // have this property. + bool operator()(Subset* subset1, Subset* subset2) const { + if (!subset1 && !subset2) + return true; + if ((subset1 && !subset2) || (!subset1 && subset2)) + return false; + + if (subset1->size() != subset2->size()) + return false; + + // Loads first subset elements in element vector. + for (typename Subset::iterator iter1 = subset1->begin(); + iter1 != subset1->end(); + ++iter1) { + Element &element1 = *iter1; + while (elements_->size() <= element1.state_id) + elements_->push_back(0); + (*elements_)[element1.state_id] = &element1; + } + + // Checks second subset matches first via element vector. + for (typename Subset::iterator iter2 = subset2->begin(); + iter2 != subset2->end(); + ++iter2) { + Element &element2 = *iter2; + while (elements_->size() <= element2.state_id) + elements_->push_back(0); + Element *element1 = (*elements_)[element2.state_id]; + if (!element1 || element1->weight != element2.weight) { + // Mismatch found. Resets element vector before returning false. + for (typename Subset::iterator iter1 = subset1->begin(); + iter1 != subset1->end(); + ++iter1) + (*elements_)[iter1->state_id] = 0; + return false; + } else { + (*elements_)[element2.state_id] = 0; // Clears entry + } + } + return true; + } + private: + vector *elements_; + }; + + // Hash function for Subset to Fst states. Subset elements are not + // sorted in this implementation, so the hash must be invariant + // under subset reordering. + class SubsetKey { + public: + size_t operator()(const Subset* subset) const { + size_t hash = 0; + if (subset) { + for (typename Subset::const_iterator iter = subset->begin(); + iter != subset->end(); + ++iter) { + const Element &element = *iter; + int lshift = element.state_id % (CHAR_BIT * sizeof(size_t) - 1) + 1; + int rshift = CHAR_BIT * sizeof(size_t) - lshift; + size_t n = element.state_id; + hash ^= n << lshift ^ n >> rshift ^ element.weight.Hash(); + } + } + return hash; + } + }; + + size_t table_size_; + + typedef CompactHashBiTable SubsetTable; + + SubsetTable subsets_; + vector elements_; + + void operator=(const DefaultDeterminizeStateTable &); // disallow +}; + +// Options for finite-state transducer determinization templated on +// the arc type, common divisor, the determinization filter and the +// state table. DeterminizeFst takes ownership of the determinization +// filter and state table if provided. +template , + class F = IdentityDeterminizeFilter, + class T = DefaultDeterminizeStateTable > +struct DeterminizeFstOptions : CacheOptions { + typedef typename Arc::Label Label; + float delta; // Quantization delta for subset weights + Label subsequential_label; // Label used for residual final output + // when producing subsequential transducers. + F *filter; // Determinization filter + T *state_table; // Determinization state table + + explicit DeterminizeFstOptions(const CacheOptions &opts, + float del = kDelta, Label lab = 0, + F *filt = 0, + T *table = 0) + : CacheOptions(opts), delta(del), subsequential_label(lab), + filter(filt), state_table(table) {} + + explicit DeterminizeFstOptions(float del = kDelta, Label lab = 0, + F *filt = 0, T *table = 0) + : delta(del), subsequential_label(lab), filter(filt), + state_table(table) {} +}; + +// Implementation of delayed DeterminizeFst. This base class is +// common to the variants that implement acceptor and transducer +// determinization. +template +class DeterminizeFstImplBase : public CacheImpl { + public: + using FstImpl::SetType; + using FstImpl::SetProperties; + using FstImpl::Properties; + using FstImpl::SetInputSymbols; + using FstImpl::SetOutputSymbols; + + using CacheBaseImpl< CacheState >::HasStart; + using CacheBaseImpl< CacheState >::HasFinal; + using CacheBaseImpl< CacheState >::HasArcs; + using CacheBaseImpl< CacheState >::SetFinal; + using CacheBaseImpl< CacheState >::SetStart; + + typedef typename A::Label Label; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + typedef CacheState State; + + template + DeterminizeFstImplBase(const Fst &fst, + const DeterminizeFstOptions &opts) + : CacheImpl(opts), fst_(fst.Copy()) { + SetType("determinize"); + uint64 iprops = fst.Properties(kFstProperties, false); + uint64 dprops = DeterminizeProperties(iprops, + opts.subsequential_label != 0); + SetProperties(F::Properties(dprops), kCopyProperties); + SetInputSymbols(fst.InputSymbols()); + SetOutputSymbols(fst.OutputSymbols()); + } + + DeterminizeFstImplBase(const DeterminizeFstImplBase &impl) + : CacheImpl(impl), + fst_(impl.fst_->Copy(true)) { + SetType("determinize"); + SetProperties(impl.Properties(), kCopyProperties); + SetInputSymbols(impl.InputSymbols()); + SetOutputSymbols(impl.OutputSymbols()); + } + + virtual ~DeterminizeFstImplBase() { delete fst_; } + + virtual DeterminizeFstImplBase *Copy() = 0; + + StateId Start() { + if (!HasStart()) { + StateId start = ComputeStart(); + if (start != kNoStateId) { + SetStart(start); + } + } + return CacheImpl::Start(); + } + + Weight Final(StateId s) { + if (!HasFinal(s)) { + Weight final = ComputeFinal(s); + SetFinal(s, final); + } + return CacheImpl::Final(s); + } + + virtual void Expand(StateId s) = 0; + + size_t NumArcs(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumArcs(s); + } + + size_t NumInputEpsilons(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumInputEpsilons(s); + } + + size_t NumOutputEpsilons(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumOutputEpsilons(s); + } + + void InitArcIterator(StateId s, ArcIteratorData *data) { + if (!HasArcs(s)) + Expand(s); + CacheImpl::InitArcIterator(s, data); + } + + virtual StateId ComputeStart() = 0; + + virtual Weight ComputeFinal(StateId s) = 0; + + const Fst &GetFst() const { return *fst_; } + + private: + const Fst *fst_; // Input Fst + + void operator=(const DeterminizeFstImplBase &); // disallow +}; + + +// Implementation of delayed determinization for weighted acceptors. +// It is templated on the arc type A and the common divisor D. +template +class DeterminizeFsaImpl : public DeterminizeFstImplBase { + public: + using FstImpl::SetProperties; + using DeterminizeFstImplBase::GetFst; + using DeterminizeFstImplBase::SetArcs; + + typedef typename A::Label Label; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + typedef DeterminizeElement Element; + typedef slist Subset; + typedef typename F::LabelMap LabelMap; + + DeterminizeFsaImpl(const Fst &fst, + const vector *in_dist, vector *out_dist, + const DeterminizeFstOptions &opts) + : DeterminizeFstImplBase(fst, opts), + delta_(opts.delta), + in_dist_(in_dist), + out_dist_(out_dist), + filter_(opts.filter ? opts.filter : new F()), + state_table_(opts.state_table ? opts.state_table : new T()) { + if (!fst.Properties(kAcceptor, true)) { + FSTERROR() << "DeterminizeFst: argument not an acceptor"; + SetProperties(kError, kError); + } + if (!(Weight::Properties() & kLeftSemiring)) { + FSTERROR() << "DeterminizeFst: Weight needs to be left distributive: " + << Weight::Type(); + SetProperties(kError, kError); + } + if (out_dist_) + out_dist_->clear(); + } + + DeterminizeFsaImpl(const DeterminizeFsaImpl &impl) + : DeterminizeFstImplBase(impl), + delta_(impl.delta_), + in_dist_(0), + out_dist_(0), + filter_(new F(*impl.filter_)), + state_table_(new T(*impl.state_table_)) { + if (impl.out_dist_) { + FSTERROR() << "DeterminizeFsaImpl: cannot copy with out_dist vector"; + SetProperties(kError, kError); + } + } + + virtual ~DeterminizeFsaImpl() { + delete filter_; + delete state_table_; + } + + virtual DeterminizeFsaImpl *Copy() { + return new DeterminizeFsaImpl(*this); + } + + uint64 Properties() const { return Properties(kFstProperties); } + + // Set error if found; return FST impl properties. + uint64 Properties(uint64 mask) const { + if ((mask & kError) && (GetFst().Properties(kError, false))) + SetProperties(kError, kError); + return FstImpl::Properties(mask); + } + + virtual StateId ComputeStart() { + StateId s = GetFst().Start(); + if (s == kNoStateId) + return kNoStateId; + Element element(s, Weight::One()); + Subset *subset = new Subset; + subset->push_front(element); + return FindState(subset); + } + + virtual Weight ComputeFinal(StateId s) { + const Subset *subset = state_table_->FindSubset(s); + Weight final = Weight::Zero(); + for (typename Subset::const_iterator siter = subset->begin(); + siter != subset->end(); + ++siter) { + const Element &element = *siter; + final = Plus(final, Times(element.weight, + GetFst().Final(element.state_id))); + if (!final.Member()) + SetProperties(kError, kError); + } + return final; + } + + StateId FindState(Subset *subset) { + StateId s = state_table_->FindState(subset); + if (in_dist_ && out_dist_->size() <= s) + out_dist_->push_back(ComputeDistance(subset)); + return s; + } + + // Compute distance from a state to the final states in the DFA + // given the distances in the NFA. + Weight ComputeDistance(const Subset *subset) { + Weight outd = Weight::Zero(); + for (typename Subset::const_iterator siter = subset->begin(); + siter != subset->end(); ++siter) { + const Element &element = *siter; + Weight ind = element.state_id < in_dist_->size() ? + (*in_dist_)[element.state_id] : Weight::Zero(); + outd = Plus(outd, Times(element.weight, ind)); + } + return outd; + } + + // Computes the outgoing transitions from a state, creating new destination + // states as needed. + virtual void Expand(StateId s) { + + LabelMap label_map; + LabelSubsets(s, &label_map); + + for (typename LabelMap::iterator liter = label_map.begin(); + liter != label_map.end(); + ++liter) + AddArc(s, liter->first, liter->second); + SetArcs(s); + } + + private: + // Constructs destination subsets per label. At return, subset + // element weights include the input automaton label weights and the + // subsets may contain duplicate states. + void LabelSubsets(StateId s, LabelMap *label_map) { + const Subset *src_subset = state_table_->FindSubset(s); + + for (typename Subset::const_iterator siter = src_subset->begin(); + siter != src_subset->end(); + ++siter) { + const Element &src_element = *siter; + for (ArcIterator< Fst > aiter(GetFst(), src_element.state_id); + !aiter.Done(); + aiter.Next()) { + const A &arc = aiter.Value(); + Element dest_element(arc.nextstate, + Times(src_element.weight, arc.weight)); + + // The LabelMap may be a e.g. multimap with more complex + // determinization filters, so we insert efficiently w/o using []. + typename LabelMap::iterator liter = label_map->lower_bound(arc.ilabel); + Subset* dest_subset; + if (liter == label_map->end() || liter->first != arc.ilabel) { + dest_subset = new Subset; + label_map->insert(liter, make_pair(arc.ilabel, dest_subset)); + } else { + dest_subset = liter->second; + } + + dest_subset->push_front(dest_element); + } + } + // Applies the determinization filter + (*filter_)(s, label_map); + } + + // Adds an arc from state S to the destination state associated + // with subset DEST_SUBSET (as created by LabelSubsets). + void AddArc(StateId s, Label label, Subset *dest_subset) { + A arc; + arc.ilabel = label; + arc.olabel = label; + arc.weight = Weight::Zero(); + + typename Subset::iterator oiter; + for (typename Subset::iterator diter = dest_subset->begin(); + diter != dest_subset->end();) { + Element &dest_element = *diter; + // Computes label weight. + arc.weight = common_divisor_(arc.weight, dest_element.weight); + + while (elements_.size() <= dest_element.state_id) + elements_.push_back(0); + Element *matching_element = elements_[dest_element.state_id]; + if (matching_element) { + // Found duplicate state: sums state weight and deletes dup. + matching_element->weight = Plus(matching_element->weight, + dest_element.weight); + if (!matching_element->weight.Member()) + SetProperties(kError, kError); + ++diter; + dest_subset->erase_after(oiter); + } else { + // Saves element so we can check for duplicate for this state. + elements_[dest_element.state_id] = &dest_element; + oiter = diter; + ++diter; + } + } + + // Divides out label weight from destination subset elements. + // Quantizes to ensure comparisons are effective. + // Clears element vector. + for (typename Subset::iterator diter = dest_subset->begin(); + diter != dest_subset->end(); + ++diter) { + Element &dest_element = *diter; + dest_element.weight = Divide(dest_element.weight, arc.weight, + DIVIDE_LEFT); + dest_element.weight = dest_element.weight.Quantize(delta_); + elements_[dest_element.state_id] = 0; + } + + arc.nextstate = FindState(dest_subset); + CacheImpl::PushArc(s, arc); + } + + float delta_; // Quantization delta for subset weights + const vector *in_dist_; // Distance to final NFA states + vector *out_dist_; // Distance to final DFA states + + D common_divisor_; + F *filter_; + T *state_table_; + + vector elements_; + + void operator=(const DeterminizeFsaImpl &); // disallow +}; + + +// Implementation of delayed determinization for transducers. +// Transducer determinization is implemented by mapping the input to +// the Gallic semiring as an acceptor whose weights contain the output +// strings and using acceptor determinization above to determinize +// that acceptor. +template +class DeterminizeFstImpl : public DeterminizeFstImplBase { + public: + using FstImpl::SetProperties; + using DeterminizeFstImplBase::GetFst; + using CacheBaseImpl< CacheState >::GetCacheGc; + using CacheBaseImpl< CacheState >::GetCacheLimit; + + typedef typename A::Label Label; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + + typedef ToGallicMapper ToMapper; + typedef FromGallicMapper FromMapper; + + typedef typename ToMapper::ToArc ToArc; + typedef ArcMapFst ToFst; + typedef ArcMapFst FromFst; + + typedef GallicCommonDivisor CommonDivisor; + typedef GallicFactor FactorIterator; + + DeterminizeFstImpl(const Fst &fst, + const DeterminizeFstOptions &opts) + : DeterminizeFstImplBase(fst, opts), + delta_(opts.delta), + subsequential_label_(opts.subsequential_label) { + Init(GetFst()); + } + + DeterminizeFstImpl(const DeterminizeFstImpl &impl) + : DeterminizeFstImplBase(impl), + delta_(impl.delta_), + subsequential_label_(impl.subsequential_label_) { + Init(GetFst()); + } + + ~DeterminizeFstImpl() { delete from_fst_; } + + virtual DeterminizeFstImpl *Copy() { + return new DeterminizeFstImpl(*this); + } + + uint64 Properties() const { return Properties(kFstProperties); } + + // Set error if found; return FST impl properties. + uint64 Properties(uint64 mask) const { + if ((mask & kError) && (GetFst().Properties(kError, false) || + from_fst_->Properties(kError, false))) + SetProperties(kError, kError); + return FstImpl::Properties(mask); + } + + virtual StateId ComputeStart() { return from_fst_->Start(); } + + virtual Weight ComputeFinal(StateId s) { return from_fst_->Final(s); } + + virtual void Expand(StateId s) { + for (ArcIterator aiter(*from_fst_, s); + !aiter.Done(); + aiter.Next()) + CacheImpl::PushArc(s, aiter.Value()); + CacheImpl::SetArcs(s); + } + + private: + // Initialization of transducer determinization implementation, which + // is defined after DeterminizeFst since it calls it. + void Init(const Fst &fst); + + float delta_; + Label subsequential_label_; + FromFst *from_fst_; + + void operator=(const DeterminizeFstImpl &); // disallow +}; + + +// Determinizes a weighted transducer. This version is a delayed +// Fst. The result will be an equivalent FST that has the property +// that no state has two transitions with the same input label. +// For this algorithm, epsilon transitions are treated as regular +// symbols (cf. RmEpsilon). +// +// The transducer must be functional. The weights must be (weakly) +// left divisible (valid for TropicalWeight and LogWeight for instance) +// and be zero-sum-free if for all a,b: (Plus(a, b) = 0 => a = b = 0. +// +// Complexity: +// - Determinizable: exponential (polynomial in the size of the output) +// - Non-determinizable) does not terminate +// +// The determinizable automata include all unweighted and all acyclic input. +// +// References: +// - Mehryar Mohri, "Finite-State Transducers in Language and Speech +// Processing". Computational Linguistics, 23:2, 1997. +// +// This class attaches interface to implementation and handles +// reference counting, delegating most methods to ImplToFst. +template +class DeterminizeFst : public ImplToFst< DeterminizeFstImplBase > { + public: + friend class ArcIterator< DeterminizeFst >; + friend class StateIterator< DeterminizeFst >; + template + friend class DeterminizeFstImpl; + + typedef A Arc; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + typedef typename A::Label Label; + typedef CacheState State; + typedef DeterminizeFstImplBase Impl; + + using ImplToFst::SetImpl; + + explicit DeterminizeFst(const Fst &fst) { + typedef DefaultCommonDivisor D; + typedef IdentityDeterminizeFilter F; + typedef DefaultDeterminizeStateTable T; + DeterminizeFstOptions opts; + if (fst.Properties(kAcceptor, true)) { + // Calls implementation for acceptors. + SetImpl(new DeterminizeFsaImpl(fst, 0, 0, opts)); + } else { + // Calls implementation for transducers. + SetImpl(new + DeterminizeFstImpl(fst, opts)); + } + } + + template + DeterminizeFst(const Fst &fst, + const DeterminizeFstOptions &opts) { + if (fst.Properties(kAcceptor, true)) { + // Calls implementation for acceptors. + SetImpl(new DeterminizeFsaImpl(fst, 0, 0, opts)); + } else { + // Calls implementation for transducers. + SetImpl(new + DeterminizeFstImpl(fst, opts)); + } + } + + // This acceptor-only version additionally computes the distance to + // final states in the output if provided with those distances for the + // input. Useful for e.g. unique N-shortest paths. + template + DeterminizeFst(const Fst &fst, + const vector *in_dist, vector *out_dist, + const DeterminizeFstOptions &opts) { + if (!fst.Properties(kAcceptor, true)) { + FSTERROR() << "DeterminizeFst:" + << " distance to final states computed for acceptors only"; + GetImpl()->SetProperties(kError, kError); + } + SetImpl(new DeterminizeFsaImpl(fst, in_dist, out_dist, opts)); + } + + // See Fst<>::Copy() for doc. + DeterminizeFst(const DeterminizeFst &fst, bool safe = false) { + if (safe) + SetImpl(fst.GetImpl()->Copy()); + else + SetImpl(fst.GetImpl(), false); + } + + // Get a copy of this DeterminizeFst. See Fst<>::Copy() for further doc. + virtual DeterminizeFst *Copy(bool safe = false) const { + return new DeterminizeFst(*this, safe); + } + + virtual inline void InitStateIterator(StateIteratorData *data) const; + + virtual void InitArcIterator(StateId s, ArcIteratorData *data) const { + GetImpl()->InitArcIterator(s, data); + } + + private: + // Makes visible to friends. + Impl *GetImpl() const { return ImplToFst::GetImpl(); } + + void operator=(const DeterminizeFst &fst); // Disallow +}; + + +// Initialization of transducer determinization implementation. which +// is defined after DeterminizeFst since it calls it. +template +void DeterminizeFstImpl::Init(const Fst &fst) { + // Mapper to an acceptor. + ToFst to_fst(fst, ToMapper()); + + // Determinizes acceptor. + // This recursive call terminates since it passes the common divisor + // to a private constructor. + CacheOptions copts(GetCacheGc(), GetCacheLimit()); + DeterminizeFstOptions dopts(copts, delta_); + // Uses acceptor-only constructor to avoid template recursion + DeterminizeFst det_fsa(to_fst, 0, 0, dopts); + + // Mapper back to transducer. + FactorWeightOptions fopts(CacheOptions(true, 0), delta_, + kFactorFinalWeights, + subsequential_label_, + subsequential_label_); + FactorWeightFst factored_fst(det_fsa, fopts); + from_fst_ = new FromFst(factored_fst, FromMapper(subsequential_label_)); +} + + +// Specialization for DeterminizeFst. +template +class StateIterator< DeterminizeFst > + : public CacheStateIterator< DeterminizeFst > { + public: + explicit StateIterator(const DeterminizeFst &fst) + : CacheStateIterator< DeterminizeFst >(fst, fst.GetImpl()) {} +}; + + +// Specialization for DeterminizeFst. +template +class ArcIterator< DeterminizeFst > + : public CacheArcIterator< DeterminizeFst > { + public: + typedef typename A::StateId StateId; + + ArcIterator(const DeterminizeFst &fst, StateId s) + : CacheArcIterator< DeterminizeFst >(fst.GetImpl(), s) { + if (!fst.GetImpl()->HasArcs(s)) + fst.GetImpl()->Expand(s); + } + + private: + DISALLOW_COPY_AND_ASSIGN(ArcIterator); +}; + + +template inline +void DeterminizeFst::InitStateIterator(StateIteratorData *data) const +{ + data->base = new StateIterator< DeterminizeFst >(*this); +} + + +// Useful aliases when using StdArc. +typedef DeterminizeFst StdDeterminizeFst; + + +template +struct DeterminizeOptions { + typedef typename Arc::StateId StateId; + typedef typename Arc::Weight Weight; + typedef typename Arc::Label Label; + + float delta; // Quantization delta for subset weights. + Weight weight_threshold; // Pruning weight threshold. + StateId state_threshold; // Pruning state threshold. + Label subsequential_label; // Label used for residual final output + // when producing subsequential transducers. + + explicit DeterminizeOptions(float d = kDelta, Weight w = Weight::Zero(), + StateId n = kNoStateId, Label l = 0) + : delta(d), weight_threshold(w), state_threshold(n), + subsequential_label(l) {} +}; + + +// Determinizes a weighted transducer. This version writes the +// determinized Fst to an output MutableFst. The result will be an +// equivalent FST that has the property that no state has two +// transitions with the same input label. For this algorithm, epsilon +// transitions are treated as regular symbols (cf. RmEpsilon). +// +// The transducer must be functional. The weights must be (weakly) +// left divisible (valid for TropicalWeight and LogWeight). +// +// Complexity: +// - Determinizable: exponential (polynomial in the size of the output) +// - Non-determinizable: does not terminate +// +// The determinizable automata include all unweighted and all acyclic input. +// +// References: +// - Mehryar Mohri, "Finite-State Transducers in Language and Speech +// Processing". Computational Linguistics, 23:2, 1997. +template +void Determinize(const Fst &ifst, MutableFst *ofst, + const DeterminizeOptions &opts + = DeterminizeOptions()) { + typedef typename Arc::StateId StateId; + typedef typename Arc::Weight Weight; + + DeterminizeFstOptions nopts; + nopts.delta = opts.delta; + nopts.subsequential_label = opts.subsequential_label; + + nopts.gc_limit = 0; // Cache only the last state for fastest copy. + + if (opts.weight_threshold != Weight::Zero() || + opts.state_threshold != kNoStateId) { + if (ifst.Properties(kAcceptor, false)) { + vector idistance, odistance; + ShortestDistance(ifst, &idistance, true); + DeterminizeFst dfst(ifst, &idistance, &odistance, nopts); + PruneOptions< Arc, AnyArcFilter > popts(opts.weight_threshold, + opts.state_threshold, + AnyArcFilter(), + &odistance); + Prune(dfst, ofst, popts); + } else { + *ofst = DeterminizeFst(ifst, nopts); + Prune(ofst, opts.weight_threshold, opts.state_threshold); + } + } else { + *ofst = DeterminizeFst(ifst, nopts); + } +} + + +} // namespace fst + +#endif // FST_LIB_DETERMINIZE_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/dfs-visit.h b/kaldi_io/src/tools/openfst/include/fst/dfs-visit.h new file mode 100644 index 0000000..4d93a39 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/dfs-visit.h @@ -0,0 +1,205 @@ +// dfs-visit.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Depth-first search visitation. See visit.h for more general +// search queue disciplines. + +#ifndef FST_LIB_DFS_VISIT_H__ +#define FST_LIB_DFS_VISIT_H__ + +#include +#include +using std::vector; + +#include +#include + + +namespace fst { + +// Visitor Interface - class determines actions taken during a Dfs. +// If any of the boolean member functions return false, the DFS is +// aborted by first calling FinishState() on all currently grey states +// and then calling FinishVisit(). +// +// Note this is similar to the more general visitor interface in visit.h +// except that FinishState returns additional information appropriate only for +// a DFS and some methods names here are better suited to a DFS. +// +// template +// class Visitor { +// public: +// typedef typename Arc::StateId StateId; +// +// Visitor(T *return_data); +// // Invoked before DFS visit +// void InitVisit(const Fst &fst); +// // Invoked when state discovered (2nd arg is DFS tree root) +// bool InitState(StateId s, StateId root); +// // Invoked when tree arc examined (to white/undiscovered state) +// bool TreeArc(StateId s, const Arc &a); +// // Invoked when back arc examined (to grey/unfinished state) +// bool BackArc(StateId s, const Arc &a); +// // Invoked when forward or cross arc examined (to black/finished state) +// bool ForwardOrCrossArc(StateId s, const Arc &a); +// // Invoked when state finished (PARENT is kNoStateID and ARC == NULL +// // when S is tree root) +// void FinishState(StateId s, StateId parent, const Arc *parent_arc); +// // Invoked after DFS visit +// void FinishVisit(); +// }; + +// An Fst state's DFS status +const int kDfsWhite = 0; // Undiscovered +const int kDfsGrey = 1; // Discovered & unfinished +const int kDfsBlack = 2; // Finished + +// An Fst state's DFS stack state +template +struct DfsState { + typedef typename Arc::StateId StateId; + + DfsState(const Fst &fst, StateId s): state_id(s), arc_iter(fst, s) {} + + StateId state_id; // Fst state ... + ArcIterator< Fst > arc_iter; // and its corresponding arcs +}; + + +// Performs depth-first visitation. Visitor class argument determines +// actions and contains any return data. ArcFilter determines arcs +// that are considered. +// +// Note this is similar to Visit() in visit.h called with a LIFO +// queue except this version has a Visitor class specialized and +// augmented for a DFS. +template +void DfsVisit(const Fst &fst, V *visitor, ArcFilter filter) { + typedef typename Arc::StateId StateId; + + visitor->InitVisit(fst); + + StateId start = fst.Start(); + if (start == kNoStateId) { + visitor->FinishVisit(); + return; + } + + vector state_color; // Fst state DFS status + stack *> state_stack; // DFS execution stack + + StateId nstates = start + 1; // # of known states in general case + bool expanded = false; + if (fst.Properties(kExpanded, false)) { // tests if expanded case, then + nstates = CountStates(fst); // uses ExpandedFst::NumStates(). + expanded = true; + } + + state_color.resize(nstates, kDfsWhite); + StateIterator< Fst > siter(fst); + + // Continue DFS while true + bool dfs = true; + + // Iterate over trees in DFS forest. + for (StateId root = start; dfs && root < nstates;) { + state_color[root] = kDfsGrey; + state_stack.push(new DfsState(fst, root)); + dfs = visitor->InitState(root, root); + while (!state_stack.empty()) { + DfsState *dfs_state = state_stack.top(); + StateId s = dfs_state->state_id; + if (s >= state_color.size()) { + nstates = s + 1; + state_color.resize(nstates, kDfsWhite); + } + ArcIterator< Fst > &aiter = dfs_state->arc_iter; + if (!dfs || aiter.Done()) { + state_color[s] = kDfsBlack; + delete dfs_state; + state_stack.pop(); + if (!state_stack.empty()) { + DfsState *parent_state = state_stack.top(); + StateId p = parent_state->state_id; + ArcIterator< Fst > &piter = parent_state->arc_iter; + visitor->FinishState(s, p, &piter.Value()); + piter.Next(); + } else { + visitor->FinishState(s, kNoStateId, 0); + } + continue; + } + const Arc &arc = aiter.Value(); + if (arc.nextstate >= state_color.size()) { + nstates = arc.nextstate + 1; + state_color.resize(nstates, kDfsWhite); + } + if (!filter(arc)) { + aiter.Next(); + continue; + } + int next_color = state_color[arc.nextstate]; + switch (next_color) { + default: + case kDfsWhite: + dfs = visitor->TreeArc(s, arc); + if (!dfs) break; + state_color[arc.nextstate] = kDfsGrey; + state_stack.push(new DfsState(fst, arc.nextstate)); + dfs = visitor->InitState(arc.nextstate, root); + break; + case kDfsGrey: + dfs = visitor->BackArc(s, arc); + aiter.Next(); + break; + case kDfsBlack: + dfs = visitor->ForwardOrCrossArc(s, arc); + aiter.Next(); + break; + } + } + + // Find next tree root + for (root = root == start ? 0 : root + 1; + root < nstates && state_color[root] != kDfsWhite; + ++root) { + } + + // Check for a state beyond the largest known state + if (!expanded && root == nstates) { + for (; !siter.Done(); siter.Next()) { + if (siter.Value() == nstates) { + ++nstates; + state_color.push_back(kDfsWhite); + break; + } + } + } + } + visitor->FinishVisit(); +} + + +template +void DfsVisit(const Fst &fst, V *visitor) { + DfsVisit(fst, visitor, AnyArcFilter()); +} + +} // namespace fst + +#endif // FST_LIB_DFS_VISIT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/difference.h b/kaldi_io/src/tools/openfst/include/fst/difference.h new file mode 100644 index 0000000..8a3306f --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/difference.h @@ -0,0 +1,189 @@ +// difference.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Class to compute the difference between two FSAs + +#ifndef FST_LIB_DIFFERENCE_H__ +#define FST_LIB_DIFFERENCE_H__ + +#include +using std::vector; +#include + +#include +#include +#include + + +namespace fst { + +template >, + class F = SequenceComposeFilter, + class T = GenericComposeStateTable > +struct DifferenceFstOptions : public ComposeFstOptions { + explicit DifferenceFstOptions(const CacheOptions &opts, + M *mat1 = 0, M *mat2 = 0, + F *filt = 0, T *sttable= 0) + : ComposeFstOptions(mat1, mat2, filt, sttable) { } + + DifferenceFstOptions() {} +}; + +// Computes the difference between two FSAs. This version is a delayed +// Fst. Only strings that are in the first automaton but not in second +// are retained in the result. +// +// The first argument must be an acceptor; the second argument must be +// an unweighted, epsilon-free, deterministic acceptor. One of the +// arguments must be label-sorted. +// +// Complexity: same as ComposeFst. +// +// Caveats: same as ComposeFst. +template +class DifferenceFst : public ComposeFst { + public: + using ImplToFst< ComposeFstImplBase >::SetImpl; + using ImplToFst< ComposeFstImplBase >::GetImpl; + + using ComposeFst::CreateBase1; + + typedef A Arc; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + + // A - B = A ^ B'. + DifferenceFst(const Fst &fst1, const Fst &fst2, + const CacheOptions &opts = CacheOptions()) { + typedef RhoMatcher< Matcher > > R; + + ComplementFst cfst(fst2); + ComposeFstOptions copts(CacheOptions(), + new R(fst1, MATCH_NONE), + new R(cfst, MATCH_INPUT, + ComplementFst::kRhoLabel)); + SetImpl(CreateBase1(fst1, cfst, copts)); + + if (!fst1.Properties(kAcceptor, true)) { + FSTERROR() << "DifferenceFst: 1st argument not an acceptor"; + GetImpl()->SetProperties(kError, kError); + } + } + + template + DifferenceFst(const Fst &fst1, const Fst &fst2, + const DifferenceFstOptions &opts) { + typedef RhoMatcher R; + + ComplementFst cfst(fst2); + ComposeFstOptions copts(opts); + copts.matcher1 = new R(fst1, MATCH_NONE, kNoLabel, MATCHER_REWRITE_ALWAYS, + opts.matcher1); + copts.matcher2 = new R(cfst, MATCH_INPUT, ComplementFst::kRhoLabel, + MATCHER_REWRITE_ALWAYS, opts.matcher2); + + SetImpl(CreateBase1(fst1, cfst, copts)); + + if (!fst1.Properties(kAcceptor, true)) { + FSTERROR() << "DifferenceFst: 1st argument not an acceptor"; + GetImpl()->SetProperties(kError, kError); + } + } + + // See Fst<>::Copy() for doc. + DifferenceFst(const DifferenceFst &fst, bool safe = false) + : ComposeFst(fst, safe) {} + + // Get a copy of this DifferenceFst. See Fst<>::Copy() for further doc. + virtual DifferenceFst *Copy(bool safe = false) const { + return new DifferenceFst(*this, safe); + } +}; + + +// Specialization for DifferenceFst. +template +class StateIterator< DifferenceFst > + : public StateIterator< ComposeFst > { + public: + explicit StateIterator(const DifferenceFst &fst) + : StateIterator< ComposeFst >(fst) {} +}; + + +// Specialization for DifferenceFst. +template +class ArcIterator< DifferenceFst > + : public ArcIterator< ComposeFst > { + public: + typedef typename A::StateId StateId; + + ArcIterator(const DifferenceFst &fst, StateId s) + : ArcIterator< ComposeFst >(fst, s) {} +}; + +// Useful alias when using StdArc. +typedef DifferenceFst StdDifferenceFst; + + +typedef ComposeOptions DifferenceOptions; + + +// Computes the difference between two FSAs. This version is writes +// the difference to an output MutableFst. Only strings that are in +// the first automaton but not in second are retained in the result. +// +// The first argument must be an acceptor; the second argument must be +// an unweighted, epsilon-free, deterministic acceptor. One of the +// arguments must be label-sorted. +// +// Complexity: same as Compose. +// +// Caveats: same as Compose. +template +void Difference(const Fst &ifst1, const Fst &ifst2, + MutableFst *ofst, + const DifferenceOptions &opts = DifferenceOptions()) { + typedef Matcher< Fst > M; + + if (opts.filter_type == AUTO_FILTER) { + CacheOptions nopts; + nopts.gc_limit = 0; // Cache only the last state for fastest copy. + *ofst = DifferenceFst(ifst1, ifst2, nopts); + } else if (opts.filter_type == SEQUENCE_FILTER) { + DifferenceFstOptions dopts; + dopts.gc_limit = 0; // Cache only the last state for fastest copy. + *ofst = DifferenceFst(ifst1, ifst2, dopts); + } else if (opts.filter_type == ALT_SEQUENCE_FILTER) { + DifferenceFstOptions > dopts; + dopts.gc_limit = 0; // Cache only the last state for fastest copy. + *ofst = DifferenceFst(ifst1, ifst2, dopts); + } else if (opts.filter_type == MATCH_FILTER) { + DifferenceFstOptions > dopts; + dopts.gc_limit = 0; // Cache only the last state for fastest copy. + *ofst = DifferenceFst(ifst1, ifst2, dopts); + } + + if (opts.connect) + Connect(ofst); +} + +} // namespace fst + +#endif // FST_LIB_DIFFERENCE_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/edit-fst.h b/kaldi_io/src/tools/openfst/include/fst/edit-fst.h new file mode 100644 index 0000000..bd33b9d --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/edit-fst.h @@ -0,0 +1,779 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: dbikel@google.com (Dan Bikel) +// +// An \ref Fst implementation that allows non-destructive edit operations on an +// existing fst. + +#ifndef FST_LIB_EDIT_FST_H_ +#define FST_LIB_EDIT_FST_H_ + +#include +using std::vector; + +#include + +#include +using std::tr1::unordered_map; +using std::tr1::unordered_multimap; + +namespace fst { + +// The EditFst class enables non-destructive edit operations on a wrapped +// ExpandedFst. The implementation uses copy-on-write semantics at the node +// level: if a user has an underlying fst on which he or she wants to perform a +// relatively small number of edits (read: mutations), then this implementation +// will copy the edited node to an internal MutableFst and perform any edits in +// situ on that copied node. This class supports all the methods of MutableFst +// except for DeleteStates(const vector &); thus, new nodes may also be +// added, and one may add transitions from existing nodes of the wrapped fst to +// new nodes. +// +// N.B.: The documentation for Fst::Copy(true) says that its behavior is +// undefined if invoked on an fst that has already been accessed. This class +// requires that the Fst implementation it wraps provides consistent, reliable +// behavior when its Copy(true) method is invoked, where consistent means +// the graph structure, graph properties and state numbering and do not change. +// VectorFst and CompactFst, for example, are both well-behaved in this regard. + +// The EditFstData class is a container for all mutable data for EditFstImpl; +// also, this class provides most of the actual implementation of what EditFst +// does (that is, most of EditFstImpl's methods delegate to methods in this, the +// EditFstData class). Instances of this class are reference-counted and can be +// shared between otherwise independent EditFstImpl instances. This scheme +// allows EditFstImpl to implement the thread-safe, copy-on-write semantics +// required by Fst::Copy(true). +// +// template parameters: +// A the type of arc to use +// WrappedFstT the type of fst wrapped by the EditFst instance that +// this EditFstData instance is backing +// MutableFstT the type of mutable fst to use internally for edited states; +// crucially, MutableFstT::Copy(false) *must* yield an fst that is +// thread-safe for reading (VectorFst, for example, has this property) +template , + typename MutableFstT = VectorFst > +class EditFstData { + public: + typedef A Arc; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + typedef typename unordered_map::const_iterator + IdMapIterator; + typedef typename unordered_map::const_iterator + FinalWeightIterator; + + + EditFstData() : num_new_states_(0) { + SetEmptyAndDeleteKeysForInternalMaps(); + } + + EditFstData(const EditFstData &other) : + edits_(other.edits_), + external_to_internal_ids_(other.external_to_internal_ids_), + edited_final_weights_(other.edited_final_weights_), + num_new_states_(other.num_new_states_) { + } + + ~EditFstData() { + } + + static EditFstData *Read(istream &strm, + const FstReadOptions &opts); + + bool Write(ostream &strm, const FstWriteOptions &opts) const { + // Serialize all private data members of this class. + FstWriteOptions edits_opts(opts); + edits_opts.write_header = true; // Force writing contained header. + edits_.Write(strm, edits_opts); + WriteType(strm, external_to_internal_ids_); + WriteType(strm, edited_final_weights_); + WriteType(strm, num_new_states_); + if (!strm) { + LOG(ERROR) << "EditFstData::Write: write failed: " << opts.source; + return false; + } + return true; + } + + int RefCount() const { return ref_count_.count(); } + int IncrRefCount() { return ref_count_.Incr(); } + int DecrRefCount() { return ref_count_.Decr(); } + + StateId NumNewStates() const { + return num_new_states_; + } + + // accessor methods for the fst holding edited states + StateId EditedStart() const { + return edits_.Start(); + } + + Weight Final(StateId s, const WrappedFstT *wrapped) const { + FinalWeightIterator final_weight_it = GetFinalWeightIterator(s); + if (final_weight_it == NotInFinalWeightMap()) { + IdMapIterator it = GetEditedIdMapIterator(s); + return it == NotInEditedMap() ? + wrapped->Final(s) : edits_.Final(it->second); + } + else { + return final_weight_it->second; + } + } + + size_t NumArcs(StateId s, const WrappedFstT *wrapped) const { + IdMapIterator it = GetEditedIdMapIterator(s); + return it == NotInEditedMap() ? + wrapped->NumArcs(s) : edits_.NumArcs(it->second); + } + + size_t NumInputEpsilons(StateId s, const WrappedFstT *wrapped) const { + IdMapIterator it = GetEditedIdMapIterator(s); + return it == NotInEditedMap() ? + wrapped->NumInputEpsilons(s) : + edits_.NumInputEpsilons(it->second); + } + + size_t NumOutputEpsilons(StateId s, const WrappedFstT *wrapped) const { + IdMapIterator it = GetEditedIdMapIterator(s); + return it == NotInEditedMap() ? + wrapped->NumOutputEpsilons(s) : + edits_.NumOutputEpsilons(it->second); + } + + void SetEditedProperties(uint64 props, uint64 mask) { + edits_.SetProperties(props, mask); + } + + // non-const MutableFst operations + + // Sets the start state for this fst. + void SetStart(StateId s) { + edits_.SetStart(s); + } + + // Sets the final state for this fst. + Weight SetFinal(StateId s, Weight w, const WrappedFstT *wrapped) { + Weight old_weight = Final(s, wrapped); + IdMapIterator it = GetEditedIdMapIterator(s); + // if we haven't already edited state s, don't add it to edited_ (which can + // be expensive if s has many transitions); just use the + // edited_final_weights_ map + if (it == NotInEditedMap()) { + edited_final_weights_[s] = w; + } + else { + edits_.SetFinal(GetEditableInternalId(s, wrapped), w); + } + return old_weight; + } + + // Adds a new state to this fst, initially with no arcs. + StateId AddState(StateId curr_num_states) { + StateId internal_state_id = edits_.AddState(); + StateId external_state_id = curr_num_states; + external_to_internal_ids_[external_state_id] = internal_state_id; + num_new_states_++; + return external_state_id; + } + + // Adds the specified arc to the specified state of this fst. + const A *AddArc(StateId s, const Arc &arc, const WrappedFstT *wrapped) { + StateId internal_id = GetEditableInternalId(s, wrapped); + + size_t num_arcs = edits_.NumArcs(internal_id); + ArcIterator arc_it(edits_, internal_id); + const A *prev_arc = NULL; + if (num_arcs > 0) { + // grab the final arc associated with this state in edits_ + arc_it.Seek(num_arcs - 1); + prev_arc = &(arc_it.Value()); + } + edits_.AddArc(internal_id, arc); + return prev_arc; + } + + void DeleteStates() { + edits_.DeleteStates(); + num_new_states_ = 0; + external_to_internal_ids_.clear(); + edited_final_weights_.clear(); + } + + // Removes all but the first n outgoing arcs of the specified state. + void DeleteArcs(StateId s, size_t n, const WrappedFstT *wrapped) { + edits_.DeleteArcs(GetEditableInternalId(s, wrapped), n); + } + + // Removes all outgoing arcs from the specified state. + void DeleteArcs(StateId s, const WrappedFstT *wrapped) { + edits_.DeleteArcs(GetEditableInternalId(s, wrapped)); + } + + // end methods for non-const MutableFst operations + + // Provides information for the generic arc iterator. + void InitArcIterator(StateId s, ArcIteratorData *data, + const WrappedFstT *wrapped) const { + IdMapIterator id_map_it = GetEditedIdMapIterator(s); + if (id_map_it == NotInEditedMap()) { + VLOG(3) << "EditFstData::InitArcIterator: iterating on state " + << s << " of original fst"; + wrapped->InitArcIterator(s, data); + } else { + VLOG(2) << "EditFstData::InitArcIterator: iterating on edited state " + << s << " (internal state id: " << id_map_it->second << ")"; + edits_.InitArcIterator(id_map_it->second, data); + } + } + + // Provides information for the generic mutable arc iterator. + void InitMutableArcIterator(StateId s, MutableArcIteratorData *data, + const WrappedFstT *wrapped) { + data->base = + new MutableArcIterator(&edits_, + GetEditableInternalId(s, wrapped)); + } + + // Prints out the map from external to internal state id's (for debugging + // purposes). + void PrintMap() { + for (IdMapIterator map_it = external_to_internal_ids_.begin(); + map_it != NotInEditedMap(); ++map_it) { + LOG(INFO) << "(external,internal)=(" + << map_it->first << "," << map_it->second << ")"; + } + } + + + private: + void SetEmptyAndDeleteKeysForInternalMaps() { + } + + // Returns the iterator of the map from external to internal state id's + // of edits_ for the specified external state id. + IdMapIterator GetEditedIdMapIterator(StateId s) const { + return external_to_internal_ids_.find(s); + } + IdMapIterator NotInEditedMap() const { + return external_to_internal_ids_.end(); + } + + FinalWeightIterator GetFinalWeightIterator(StateId s) const { + return edited_final_weights_.find(s); + } + FinalWeightIterator NotInFinalWeightMap() const { + return edited_final_weights_.end(); + } + + // Returns the internal state id of the specified external id if the state has + // already been made editable, or else copies the state from wrapped_ + // to edits_ and returns the state id of the newly editable state in edits_. + // + // \return makes the specified state editable if it isn't already and returns + // its state id in edits_ + StateId GetEditableInternalId(StateId s, const WrappedFstT *wrapped) { + IdMapIterator id_map_it = GetEditedIdMapIterator(s); + if (id_map_it == NotInEditedMap()) { + StateId new_internal_id = edits_.AddState(); + VLOG(2) << "EditFstData::GetEditableInternalId: editing state " << s + << " of original fst; new internal state id:" << new_internal_id; + external_to_internal_ids_[s] = new_internal_id; + for (ArcIterator< Fst > arc_iterator(*wrapped, s); + !arc_iterator.Done(); + arc_iterator.Next()) { + edits_.AddArc(new_internal_id, arc_iterator.Value()); + } + // copy the final weight + FinalWeightIterator final_weight_it = GetFinalWeightIterator(s); + if (final_weight_it == NotInFinalWeightMap()) { + edits_.SetFinal(new_internal_id, wrapped->Final(s)); + } else { + edits_.SetFinal(new_internal_id, final_weight_it->second); + edited_final_weights_.erase(s); + } + return new_internal_id; + } else { + return id_map_it->second; + } + } + + // A mutable fst (by default, a VectorFst) to contain new states, and/or + // copies of states from a wrapped ExpandedFst that have been modified in + // some way. + MutableFstT edits_; + // A mapping from external state id's to the internal id's of states that + // appear in edits_. + unordered_map external_to_internal_ids_; + // A mapping from external state id's to final state weights assigned to + // those states. The states in this map are *only* those whose final weight + // has been modified; if any other part of the state has been modified, + // the entire state is copied to edits_, and all modifications reside there. + unordered_map edited_final_weights_; + // The number of new states added to this mutable fst impl, which is <= the + // number of states in edits_ (since edits_ contains both edited *and* new + // states). + StateId num_new_states_; + RefCounter ref_count_; +}; + +// EditFstData method implementations: just the Read method. +template +EditFstData * +EditFstData::Read(istream &strm, + const FstReadOptions &opts) { + EditFstData *data = + new EditFstData(); + // next read in MutabelFstT machine that stores edits + FstReadOptions edits_opts(opts); + edits_opts.header = 0; // Contained header was written out, so read it in. + + // Because our internal representation of edited states is a solid object + // of type MutableFstT (defaults to VectorFst) and not a pointer, + // and because the static Read method allocates a new object on the heap, + // we need to call Read, check if there was a failure, use + // MutableFstT::operator= to assign the object (not the pointer) to the + // edits_ data member (which will increase the ref count by 1 on the impl) + // and, finally, delete the heap-allocated object. + MutableFstT *edits = MutableFstT::Read(strm, edits_opts); + if (!edits) { + return 0; + } + data->edits_ = *edits; + delete edits; + // finally, read in rest of private data members + ReadType(strm, &data->external_to_internal_ids_); + ReadType(strm, &data->edited_final_weights_); + ReadType(strm, &data->num_new_states_); + if (!strm) { + LOG(ERROR) << "EditFst::Read: read failed: " << opts.source; + return 0; + } + return data; +} + +// This class enables non-destructive edit operations on a wrapped ExpandedFst. +// The implementation uses copy-on-write semantics at the node level: if a user +// has an underlying fst on which he or she wants to perform a relatively small +// number of edits (read: mutations), then this implementation will copy the +// edited node to an internal MutableFst and perform any edits in situ on that +// copied node. This class supports all the methods of MutableFst except for +// DeleteStates(const vector &); thus, new nodes may also be added, and +// one may add transitions from existing nodes of the wrapped fst to new nodes. +// +// template parameters: +// A the type of arc to use +// WrappedFstT the type of fst wrapped by the EditFst instance that +// this EditFstImpl instance is backing +// MutableFstT the type of mutable fst to use internally for edited states; +// crucially, MutableFstT::Copy(false) *must* yield an fst that is +// thread-safe for reading (VectorFst, for example, has this property) +template , + typename MutableFstT = VectorFst > +class EditFstImpl : public FstImpl { + public: + using FstImpl::SetProperties; + using FstImpl::SetInputSymbols; + using FstImpl::SetOutputSymbols; + using FstImpl::WriteHeader; + + typedef A Arc; + typedef typename Arc::Weight Weight; + typedef typename Arc::StateId StateId; + + // Constructs an editable fst implementation with no states. Effectively, + // this initially-empty fst will in every way mimic the behavior of + // a VectorFst--more precisely, a VectorFstImpl instance--but with slightly + // slower performance (by a constant factor), due to the fact that + // this class maintains a mapping between external state id's and + // their internal equivalents. + EditFstImpl() { + FstImpl::SetType("edit"); + wrapped_ = new MutableFstT(); + InheritPropertiesFromWrapped(); + data_ = new EditFstData(); + } + + // Wraps the specified ExpandedFst. This constructor requires that the + // specified Fst is an ExpandedFst instance. This requirement is only enforced + // at runtime. (See below for the reason.) + // + // This library uses the pointer-to-implementation or "PIMPL" design pattern. + // In particular, to make it convenient to bind an implementation class to its + // interface, there are a pair of template "binder" classes, one for immutable + // and one for mutable fst's (ImplToFst and ImplToMutableFst, respectively). + // As it happens, the API for the ImplToMutableFst class requires that + // the implementation class--the template parameter "I"--have a constructor + // taking a const Fst reference. Accordingly, the constructor here must + // perform a static_cast to the WrappedFstT type required by EditFst and + // therefore EditFstImpl. + explicit EditFstImpl(const Fst &wrapped) + : wrapped_(static_cast(wrapped.Copy())) { + FstImpl::SetType("edit"); + + data_ = new EditFstData(); + // have edits_ inherit all properties from wrapped_ + data_->SetEditedProperties(wrapped_->Properties(kFstProperties, false), + kFstProperties); + InheritPropertiesFromWrapped(); + } + + // A copy constructor for this implementation class, used to implement + // the Copy() method of the Fst interface. + EditFstImpl(const EditFstImpl &impl) + : FstImpl(), + wrapped_(static_cast(impl.wrapped_->Copy(true))), + data_(impl.data_) { + data_->IncrRefCount(); + SetProperties(impl.Properties()); + } + + ~EditFstImpl() { + delete wrapped_; + if (!data_->DecrRefCount()) { + delete data_; + } + } + + // const Fst/ExpandedFst operations, declared in the Fst and ExpandedFst + // interfaces + StateId Start() const { + StateId edited_start = data_->EditedStart(); + return edited_start == kNoStateId ? wrapped_->Start() : edited_start; + } + + Weight Final(StateId s) const { + return data_->Final(s, wrapped_); + } + + size_t NumArcs(StateId s) const { + return data_->NumArcs(s, wrapped_); + } + + size_t NumInputEpsilons(StateId s) const { + return data_->NumInputEpsilons(s, wrapped_); + } + + size_t NumOutputEpsilons(StateId s) const { + return data_->NumOutputEpsilons(s, wrapped_); + } + + StateId NumStates() const { + return wrapped_->NumStates() + data_->NumNewStates(); + } + + static EditFstImpl * + Read(istream &strm, + const FstReadOptions &opts); + + bool Write(ostream &strm, const FstWriteOptions &opts) const { + FstHeader hdr; + hdr.SetStart(Start()); + hdr.SetNumStates(NumStates()); + FstWriteOptions header_opts(opts); + header_opts.write_isymbols = false; // Let contained FST hold any symbols. + header_opts.write_osymbols = false; + WriteHeader(strm, header_opts, kFileVersion, &hdr); + + // First, serialize wrapped fst to stream. + FstWriteOptions wrapped_opts(opts); + wrapped_opts.write_header = true; // Force writing contained header. + wrapped_->Write(strm, wrapped_opts); + + data_->Write(strm, opts); + + strm.flush(); + if (!strm) { + LOG(ERROR) << "EditFst::Write: write failed: " << opts.source; + return false; + } + return true; + } + // end const Fst operations + + // non-const MutableFst operations + + // Sets the start state for this fst. + void SetStart(StateId s) { + MutateCheck(); + data_->SetStart(s); + SetProperties(SetStartProperties(FstImpl::Properties())); + } + + // Sets the final state for this fst. + void SetFinal(StateId s, Weight w) { + MutateCheck(); + Weight old_weight = data_->SetFinal(s, w, wrapped_); + SetProperties(SetFinalProperties(FstImpl::Properties(), old_weight, w)); + } + + // Adds a new state to this fst, initially with no arcs. + StateId AddState() { + MutateCheck(); + SetProperties(AddStateProperties(FstImpl::Properties())); + return data_->AddState(NumStates()); + } + + // Adds the specified arc to the specified state of this fst. + void AddArc(StateId s, const Arc &arc) { + MutateCheck(); + const A *prev_arc = data_->AddArc(s, arc, wrapped_); + SetProperties(AddArcProperties(FstImpl::Properties(), s, arc, prev_arc)); + } + + void DeleteStates(const vector& dstates) { + FSTERROR() << ": EditFstImpl::DeleteStates(const std::vector&): " + << " not implemented"; + SetProperties(kError, kError); + } + + // Deletes all states in this fst. + void DeleteStates(); + + // Removes all but the first n outgoing arcs of the specified state. + void DeleteArcs(StateId s, size_t n) { + MutateCheck(); + data_->DeleteArcs(s, n, wrapped_); + SetProperties(DeleteArcsProperties(FstImpl::Properties())); + } + + // Removes all outgoing arcs from the specified state. + void DeleteArcs(StateId s) { + MutateCheck(); + data_->DeleteArcs(s, wrapped_); + SetProperties(DeleteArcsProperties(FstImpl::Properties())); + } + + void ReserveStates(StateId s) { + } + + void ReserveArcs(StateId s, size_t n) { + } + + // end non-const MutableFst operations + + // Provides information for the generic state iterator. + void InitStateIterator(StateIteratorData *data) const { + data->base = 0; + data->nstates = NumStates(); + } + + // Provides information for the generic arc iterator. + void InitArcIterator(StateId s, ArcIteratorData *data) const { + data_->InitArcIterator(s, data, wrapped_); + } + + // Provides information for the generic mutable arc iterator. + void InitMutableArcIterator(StateId s, MutableArcIteratorData *data) { + MutateCheck(); + data_->InitMutableArcIterator(s, data, wrapped_); + } + + private: + typedef typename unordered_map::const_iterator + IdMapIterator; + typedef typename unordered_map::const_iterator + FinalWeightIterator; + // Properties always true of this Fst class + static const uint64 kStaticProperties = kExpanded | kMutable; + // Current file format version + static const int kFileVersion = 2; + // Minimum file format version supported + static const int kMinFileVersion = 2; + + // Causes this fst to inherit all the properties from its wrapped fst, except + // for the two properties that always apply to EditFst instances: kExpanded + // and kMutable. + void InheritPropertiesFromWrapped() { + SetProperties(wrapped_->Properties(kCopyProperties, false) | + kStaticProperties); + SetInputSymbols(wrapped_->InputSymbols()); + SetOutputSymbols(wrapped_->OutputSymbols()); + } + + // This method ensures that any operations that alter the mutable data + // portion of this EditFstImpl cause the data_ member to be copied when its + // reference count is greater than 1. Note that this method is distinct from + // MutableFst::Mutate, which gets invoked whenever one of the basic mutation + // methods defined in MutableFst is invoked, such as SetInputSymbols. + // The MutateCheck here in EditFstImpl is invoked whenever one of the + // mutating methods specifically related to the types of edits provided + // by EditFst is performed, such as changing an arc of an existing state + // of the wrapped fst via a MutableArcIterator, or adding a new state via + // AddState(). + void MutateCheck() { + if (data_->RefCount() > 1) { + EditFstData *data_copy = + new EditFstData(*data_); + if (data_ && !data_->DecrRefCount()) { + delete data_; + } + data_ = data_copy; + } + } + + // The fst that this fst wraps. The purpose of this class is to enable + // non-destructive edits on this wrapped fst. + const WrappedFstT *wrapped_; + // The mutable data for this EditFst instance, with delegates for all the + // methods that can mutate data. + EditFstData *data_; +}; + +template +const uint64 EditFstImpl::kStaticProperties; + +// EditFstImpl IMPLEMENTATION STARTS HERE + +template +inline void EditFstImpl::DeleteStates() { + data_->DeleteStates(); + delete wrapped_; + // we are deleting all states, so just forget about pointer to wrapped_ + // and do what default constructor does: set wrapped_ to a new VectorFst + wrapped_ = new MutableFstT(); + uint64 newProps = DeleteAllStatesProperties(FstImpl::Properties(), + kStaticProperties); + FstImpl::SetProperties(newProps); +} + +template +EditFstImpl * +EditFstImpl::Read(istream &strm, + const FstReadOptions &opts) { + EditFstImpl *impl = new EditFstImpl(); + FstHeader hdr; + if (!impl->ReadHeader(strm, opts, kMinFileVersion, &hdr)) { + return 0; + } + impl->SetStart(hdr.Start()); + + // first, read in wrapped fst + FstReadOptions wrapped_opts(opts); + wrapped_opts.header = 0; // Contained header was written out, so read it in. + Fst *wrapped_fst = Fst::Read(strm, wrapped_opts); + if (!wrapped_fst) { + return 0; + } + impl->wrapped_ = static_cast(wrapped_fst); + + impl->data_ = EditFstData::Read(strm, opts); + + if (!impl->data_) { + delete wrapped_fst; + return 0; + } + + return impl; +} + +// END EditFstImpl IMPLEMENTATION + +// Concrete, editable FST. This class attaches interface to implementation. +template , + typename MutableFstT = VectorFst > +class EditFst : + public ImplToMutableFst< EditFstImpl > { + public: + friend class MutableArcIterator< EditFst >; + + typedef A Arc; + typedef typename A::StateId StateId; + typedef EditFstImpl Impl; + + EditFst() : ImplToMutableFst(new Impl()) {} + + explicit EditFst(const Fst &fst) : + ImplToMutableFst(new Impl(fst)) {} + + explicit EditFst(const WrappedFstT &fst) : + ImplToMutableFst(new Impl(fst)) {} + + // See Fst<>::Copy() for doc. + EditFst(const EditFst &fst, bool safe = false) : + ImplToMutableFst(fst, safe) {} + + virtual ~EditFst() {} + + // Get a copy of this EditFst. See Fst<>::Copy() for further doc. + virtual EditFst *Copy(bool safe = false) const { + return new EditFst(*this, safe); + } + + EditFst & + operator=(const EditFst &fst) { + SetImpl(fst.GetImpl(), false); + return *this; + } + + virtual EditFst &operator=(const Fst &fst) { + if (this != &fst) { + SetImpl(new Impl(fst)); + } + return *this; + } + + // Read an EditFst from an input stream; return NULL on error. + static EditFst * + Read(istream &strm, + const FstReadOptions &opts) { + Impl* impl = Impl::Read(strm, opts); + return impl ? new EditFst(impl) : 0; + } + + // Read an EditFst from a file; return NULL on error. + // Empty filename reads from standard input. + static EditFst *Read(const string &filename) { + Impl* impl = ImplToExpandedFst >::Read(filename); + return impl ? new EditFst(impl) : 0; + } + + virtual bool Write(ostream &strm, const FstWriteOptions &opts) const { + return GetImpl()->Write(strm, opts); + } + + virtual bool Write(const string &filename) const { + return Fst::WriteFile(filename); + } + + virtual void InitStateIterator(StateIteratorData *data) const { + GetImpl()->InitStateIterator(data); + } + + virtual void InitArcIterator(StateId s, ArcIteratorData *data) const { + GetImpl()->InitArcIterator(s, data); + } + + virtual + void InitMutableArcIterator(StateId s, MutableArcIteratorData *data) { + GetImpl()->InitMutableArcIterator(s, data); + } + private: + explicit EditFst(Impl *impl) : ImplToMutableFst(impl) {} + + // Makes visible to friends. + Impl *GetImpl() const { return ImplToFst< Impl, MutableFst >::GetImpl(); } + + void SetImpl(Impl *impl, bool own_impl = true) { + ImplToFst< Impl, MutableFst >::SetImpl(impl, own_impl); + } +}; + +} // namespace fst + +#endif // FST_LIB_EDIT_FST_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/encode.h b/kaldi_io/src/tools/openfst/include/fst/encode.h new file mode 100644 index 0000000..08b84cb --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/encode.h @@ -0,0 +1,599 @@ +// encode.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: johans@google.com (Johan Schalkwyk) +// +// \file +// Class to encode and decoder an fst. + +#ifndef FST_LIB_ENCODE_H__ +#define FST_LIB_ENCODE_H__ + +#include +#include +using std::tr1::unordered_map; +using std::tr1::unordered_multimap; +#include +#include +using std::vector; + +#include +#include + + +namespace fst { + +static const uint32 kEncodeLabels = 0x0001; +static const uint32 kEncodeWeights = 0x0002; +static const uint32 kEncodeFlags = 0x0003; // All non-internal flags + +static const uint32 kEncodeHasISymbols = 0x0004; // For internal use +static const uint32 kEncodeHasOSymbols = 0x0008; // For internal use + +enum EncodeType { ENCODE = 1, DECODE = 2 }; + +// Identifies stream data as an encode table (and its endianity) +static const int32 kEncodeMagicNumber = 2129983209; + + +// The following class encapsulates implementation details for the +// encoding and decoding of label/weight tuples used for encoding +// and decoding of Fsts. The EncodeTable is bidirectional. I.E it +// stores both the Tuple of encode labels and weights to a unique +// label, and the reverse. +template class EncodeTable { + public: + typedef typename A::Label Label; + typedef typename A::Weight Weight; + + // Encoded data consists of arc input/output labels and arc weight + struct Tuple { + Tuple() {} + Tuple(Label ilabel_, Label olabel_, Weight weight_) + : ilabel(ilabel_), olabel(olabel_), weight(weight_) {} + Tuple(const Tuple& tuple) + : ilabel(tuple.ilabel), olabel(tuple.olabel), weight(tuple.weight) {} + + Label ilabel; + Label olabel; + Weight weight; + }; + + // Comparison object for hashing EncodeTable Tuple(s). + class TupleEqual { + public: + bool operator()(const Tuple* x, const Tuple* y) const { + return (x->ilabel == y->ilabel && + x->olabel == y->olabel && + x->weight == y->weight); + } + }; + + // Hash function for EncodeTabe Tuples. Based on the encode flags + // we either hash the labels, weights or combination of them. + class TupleKey { + public: + TupleKey() + : encode_flags_(kEncodeLabels | kEncodeWeights) {} + + TupleKey(const TupleKey& key) + : encode_flags_(key.encode_flags_) {} + + explicit TupleKey(uint32 encode_flags) + : encode_flags_(encode_flags) {} + + size_t operator()(const Tuple* x) const { + size_t hash = x->ilabel; + const int lshift = 5; + const int rshift = CHAR_BIT * sizeof(size_t) - 5; + if (encode_flags_ & kEncodeLabels) + hash = hash << lshift ^ hash >> rshift ^ x->olabel; + if (encode_flags_ & kEncodeWeights) + hash = hash << lshift ^ hash >> rshift ^ x->weight.Hash(); + return hash; + } + + private: + int32 encode_flags_; + }; + + typedef unordered_map EncodeHash; + + explicit EncodeTable(uint32 encode_flags) + : flags_(encode_flags), + encode_hash_(1024, TupleKey(encode_flags)), + isymbols_(0), osymbols_(0) {} + + ~EncodeTable() { + for (size_t i = 0; i < encode_tuples_.size(); ++i) { + delete encode_tuples_[i]; + } + delete isymbols_; + delete osymbols_; + } + + // Given an arc encode either input/ouptut labels or input/costs or both + Label Encode(const A &arc) { + const Tuple tuple(arc.ilabel, + flags_ & kEncodeLabels ? arc.olabel : 0, + flags_ & kEncodeWeights ? arc.weight : Weight::One()); + typename EncodeHash::const_iterator it = encode_hash_.find(&tuple); + if (it == encode_hash_.end()) { + encode_tuples_.push_back(new Tuple(tuple)); + encode_hash_[encode_tuples_.back()] = encode_tuples_.size(); + return encode_tuples_.size(); + } else { + return it->second; + } + } + + // Given an arc, look up its encoded label. Returns kNoLabel if not found. + Label GetLabel(const A &arc) const { + const Tuple tuple(arc.ilabel, + flags_ & kEncodeLabels ? arc.olabel : 0, + flags_ & kEncodeWeights ? arc.weight : Weight::One()); + typename EncodeHash::const_iterator it = encode_hash_.find(&tuple); + if (it == encode_hash_.end()) { + return kNoLabel; + } else { + return it->second; + } + } + + // Given an encode arc Label decode back to input/output labels and costs + const Tuple* Decode(Label key) const { + if (key < 1 || key > encode_tuples_.size()) { + LOG(ERROR) << "EncodeTable::Decode: unknown decode key: " << key; + return 0; + } + return encode_tuples_[key - 1]; + } + + size_t Size() const { return encode_tuples_.size(); } + + bool Write(ostream &strm, const string &source) const; + + static EncodeTable *Read(istream &strm, const string &source); + + const uint32 flags() const { return flags_ & kEncodeFlags; } + + int RefCount() const { return ref_count_.count(); } + int IncrRefCount() { return ref_count_.Incr(); } + int DecrRefCount() { return ref_count_.Decr(); } + + + SymbolTable *InputSymbols() const { return isymbols_; } + + SymbolTable *OutputSymbols() const { return osymbols_; } + + void SetInputSymbols(const SymbolTable* syms) { + if (isymbols_) delete isymbols_; + if (syms) { + isymbols_ = syms->Copy(); + flags_ |= kEncodeHasISymbols; + } else { + isymbols_ = 0; + flags_ &= ~kEncodeHasISymbols; + } + } + + void SetOutputSymbols(const SymbolTable* syms) { + if (osymbols_) delete osymbols_; + if (syms) { + osymbols_ = syms->Copy(); + flags_ |= kEncodeHasOSymbols; + } else { + osymbols_ = 0; + flags_ &= ~kEncodeHasOSymbols; + } + } + + private: + uint32 flags_; + vector encode_tuples_; + EncodeHash encode_hash_; + RefCounter ref_count_; + SymbolTable *isymbols_; // Pre-encoded ilabel symbol table + SymbolTable *osymbols_; // Pre-encoded olabel symbol table + + DISALLOW_COPY_AND_ASSIGN(EncodeTable); +}; + +template inline +bool EncodeTable::Write(ostream &strm, const string &source) const { + WriteType(strm, kEncodeMagicNumber); + WriteType(strm, flags_); + int64 size = encode_tuples_.size(); + WriteType(strm, size); + for (size_t i = 0; i < size; ++i) { + const Tuple* tuple = encode_tuples_[i]; + WriteType(strm, tuple->ilabel); + WriteType(strm, tuple->olabel); + tuple->weight.Write(strm); + } + + if (flags_ & kEncodeHasISymbols) + isymbols_->Write(strm); + + if (flags_ & kEncodeHasOSymbols) + osymbols_->Write(strm); + + strm.flush(); + if (!strm) { + LOG(ERROR) << "EncodeTable::Write: write failed: " << source; + return false; + } + return true; +} + +template inline +EncodeTable *EncodeTable::Read(istream &strm, const string &source) { + int32 magic_number = 0; + ReadType(strm, &magic_number); + if (magic_number != kEncodeMagicNumber) { + LOG(ERROR) << "EncodeTable::Read: Bad encode table header: " << source; + return 0; + } + uint32 flags; + ReadType(strm, &flags); + EncodeTable *table = new EncodeTable(flags); + + int64 size; + ReadType(strm, &size); + if (!strm) { + LOG(ERROR) << "EncodeTable::Read: read failed: " << source; + return 0; + } + + for (size_t i = 0; i < size; ++i) { + Tuple* tuple = new Tuple(); + ReadType(strm, &tuple->ilabel); + ReadType(strm, &tuple->olabel); + tuple->weight.Read(strm); + if (!strm) { + LOG(ERROR) << "EncodeTable::Read: read failed: " << source; + return 0; + } + table->encode_tuples_.push_back(tuple); + table->encode_hash_[table->encode_tuples_.back()] = + table->encode_tuples_.size(); + } + + if (flags & kEncodeHasISymbols) + table->isymbols_ = SymbolTable::Read(strm, source); + + if (flags & kEncodeHasOSymbols) + table->osymbols_ = SymbolTable::Read(strm, source); + + return table; +} + + +// A mapper to encode/decode weighted transducers. Encoding of an +// Fst is useful for performing classical determinization or minimization +// on a weighted transducer by treating it as an unweighted acceptor over +// encoded labels. +// +// The Encode mapper stores the encoding in a local hash table (EncodeTable) +// This table is shared (and reference counted) between the encoder and +// decoder. A decoder has read only access to the EncodeTable. +// +// The EncodeMapper allows on the fly encoding of the machine. As the +// EncodeTable is generated the same table may by used to decode the machine +// on the fly. For example in the following sequence of operations +// +// Encode -> Determinize -> Decode +// +// we will use the encoding table generated during the encode step in the +// decode, even though the encoding is not complete. +// +template class EncodeMapper { + typedef typename A::Weight Weight; + typedef typename A::Label Label; + public: + EncodeMapper(uint32 flags, EncodeType type) + : flags_(flags), + type_(type), + table_(new EncodeTable(flags)), + error_(false) {} + + EncodeMapper(const EncodeMapper& mapper) + : flags_(mapper.flags_), + type_(mapper.type_), + table_(mapper.table_), + error_(false) { + table_->IncrRefCount(); + } + + // Copy constructor but setting the type, typically to DECODE + EncodeMapper(const EncodeMapper& mapper, EncodeType type) + : flags_(mapper.flags_), + type_(type), + table_(mapper.table_), + error_(mapper.error_) { + table_->IncrRefCount(); + } + + ~EncodeMapper() { + if (!table_->DecrRefCount()) delete table_; + } + + A operator()(const A &arc); + + MapFinalAction FinalAction() const { + return (type_ == ENCODE && (flags_ & kEncodeWeights)) ? + MAP_REQUIRE_SUPERFINAL : MAP_NO_SUPERFINAL; + } + + MapSymbolsAction InputSymbolsAction() const { return MAP_CLEAR_SYMBOLS; } + + MapSymbolsAction OutputSymbolsAction() const { return MAP_CLEAR_SYMBOLS;} + + uint64 Properties(uint64 inprops) { + uint64 outprops = inprops; + if (error_) outprops |= kError; + + uint64 mask = kFstProperties; + if (flags_ & kEncodeLabels) + mask &= kILabelInvariantProperties & kOLabelInvariantProperties; + if (flags_ & kEncodeWeights) + mask &= kILabelInvariantProperties & kWeightInvariantProperties & + (type_ == ENCODE ? kAddSuperFinalProperties : + kRmSuperFinalProperties); + + return outprops & mask; + } + + const uint32 flags() const { return flags_; } + const EncodeType type() const { return type_; } + const EncodeTable &table() const { return *table_; } + + bool Write(ostream &strm, const string& source) { + return table_->Write(strm, source); + } + + bool Write(const string& filename) { + ofstream strm(filename.c_str(), ofstream::out | ofstream::binary); + if (!strm) { + LOG(ERROR) << "EncodeMap: Can't open file: " << filename; + return false; + } + return Write(strm, filename); + } + + static EncodeMapper *Read(istream &strm, + const string& source, + EncodeType type = ENCODE) { + EncodeTable *table = EncodeTable::Read(strm, source); + return table ? new EncodeMapper(table->flags(), type, table) : 0; + } + + static EncodeMapper *Read(const string& filename, + EncodeType type = ENCODE) { + ifstream strm(filename.c_str(), ifstream::in | ifstream::binary); + if (!strm) { + LOG(ERROR) << "EncodeMap: Can't open file: " << filename; + return NULL; + } + return Read(strm, filename, type); + } + + SymbolTable *InputSymbols() const { return table_->InputSymbols(); } + + SymbolTable *OutputSymbols() const { return table_->OutputSymbols(); } + + void SetInputSymbols(const SymbolTable* syms) { + table_->SetInputSymbols(syms); + } + + void SetOutputSymbols(const SymbolTable* syms) { + table_->SetOutputSymbols(syms); + } + + private: + uint32 flags_; + EncodeType type_; + EncodeTable* table_; + bool error_; + + explicit EncodeMapper(uint32 flags, EncodeType type, EncodeTable *table) + : flags_(flags), type_(type), table_(table) {} + void operator=(const EncodeMapper &); // Disallow. +}; + +template inline +A EncodeMapper::operator()(const A &arc) { + if (type_ == ENCODE) { // labels and/or weights to single label + if ((arc.nextstate == kNoStateId && !(flags_ & kEncodeWeights)) || + (arc.nextstate == kNoStateId && (flags_ & kEncodeWeights) && + arc.weight == Weight::Zero())) { + return arc; + } else { + Label label = table_->Encode(arc); + return A(label, + flags_ & kEncodeLabels ? label : arc.olabel, + flags_ & kEncodeWeights ? Weight::One() : arc.weight, + arc.nextstate); + } + } else { // type_ == DECODE + if (arc.nextstate == kNoStateId) { + return arc; + } else { + if (arc.ilabel == 0) return arc; + if (flags_ & kEncodeLabels && arc.ilabel != arc.olabel) { + FSTERROR() << "EncodeMapper: Label-encoded arc has different " + "input and output labels"; + error_ = true; + } + if (flags_ & kEncodeWeights && arc.weight != Weight::One()) { + FSTERROR() << + "EncodeMapper: Weight-encoded arc has non-trivial weight"; + error_ = true; + } + const typename EncodeTable::Tuple* tuple = table_->Decode(arc.ilabel); + if (!tuple) { + FSTERROR() << "EncodeMapper: decode failed"; + error_ = true; + return A(kNoLabel, kNoLabel, Weight::NoWeight(), arc.nextstate); + } else { + return A(tuple->ilabel, + flags_ & kEncodeLabels ? tuple->olabel : arc.olabel, + flags_ & kEncodeWeights ? tuple->weight : arc.weight, + arc.nextstate); + } + } + } +} + + +// Complexity: O(nstates + narcs) +template inline +void Encode(MutableFst *fst, EncodeMapper* mapper) { + mapper->SetInputSymbols(fst->InputSymbols()); + mapper->SetOutputSymbols(fst->OutputSymbols()); + ArcMap(fst, mapper); +} + +template inline +void Decode(MutableFst* fst, const EncodeMapper& mapper) { + ArcMap(fst, EncodeMapper(mapper, DECODE)); + RmFinalEpsilon(fst); + fst->SetInputSymbols(mapper.InputSymbols()); + fst->SetOutputSymbols(mapper.OutputSymbols()); +} + + +// On the fly label and/or weight encoding of input Fst +// +// Complexity: +// - Constructor: O(1) +// - Traversal: O(nstates_visited + narcs_visited), assuming constant +// time to visit an input state or arc. +template +class EncodeFst : public ArcMapFst > { + public: + typedef A Arc; + typedef EncodeMapper C; + typedef ArcMapFstImpl< A, A, EncodeMapper > Impl; + using ImplToFst::GetImpl; + + EncodeFst(const Fst &fst, EncodeMapper* encoder) + : ArcMapFst(fst, encoder, ArcMapFstOptions()) { + encoder->SetInputSymbols(fst.InputSymbols()); + encoder->SetOutputSymbols(fst.OutputSymbols()); + } + + EncodeFst(const Fst &fst, const EncodeMapper& encoder) + : ArcMapFst(fst, encoder, ArcMapFstOptions()) {} + + // See Fst<>::Copy() for doc. + EncodeFst(const EncodeFst &fst, bool copy = false) + : ArcMapFst(fst, copy) {} + + // Get a copy of this EncodeFst. See Fst<>::Copy() for further doc. + virtual EncodeFst *Copy(bool safe = false) const { + if (safe) { + FSTERROR() << "EncodeFst::Copy(true): not allowed."; + GetImpl()->SetProperties(kError, kError); + } + return new EncodeFst(*this); + } +}; + + +// On the fly label and/or weight encoding of input Fst +// +// Complexity: +// - Constructor: O(1) +// - Traversal: O(nstates_visited + narcs_visited), assuming constant +// time to visit an input state or arc. +template +class DecodeFst : public ArcMapFst > { + public: + typedef A Arc; + typedef EncodeMapper C; + typedef ArcMapFstImpl< A, A, EncodeMapper > Impl; + using ImplToFst::GetImpl; + + DecodeFst(const Fst &fst, const EncodeMapper& encoder) + : ArcMapFst(fst, + EncodeMapper(encoder, DECODE), + ArcMapFstOptions()) { + GetImpl()->SetInputSymbols(encoder.InputSymbols()); + GetImpl()->SetOutputSymbols(encoder.OutputSymbols()); + } + + // See Fst<>::Copy() for doc. + DecodeFst(const DecodeFst &fst, bool safe = false) + : ArcMapFst(fst, safe) {} + + // Get a copy of this DecodeFst. See Fst<>::Copy() for further doc. + virtual DecodeFst *Copy(bool safe = false) const { + return new DecodeFst(*this, safe); + } +}; + + +// Specialization for EncodeFst. +template +class StateIterator< EncodeFst > + : public StateIterator< ArcMapFst > > { + public: + explicit StateIterator(const EncodeFst &fst) + : StateIterator< ArcMapFst > >(fst) {} +}; + + +// Specialization for EncodeFst. +template +class ArcIterator< EncodeFst > + : public ArcIterator< ArcMapFst > > { + public: + ArcIterator(const EncodeFst &fst, typename A::StateId s) + : ArcIterator< ArcMapFst > >(fst, s) {} +}; + + +// Specialization for DecodeFst. +template +class StateIterator< DecodeFst > + : public StateIterator< ArcMapFst > > { + public: + explicit StateIterator(const DecodeFst &fst) + : StateIterator< ArcMapFst > >(fst) {} +}; + + +// Specialization for DecodeFst. +template +class ArcIterator< DecodeFst > + : public ArcIterator< ArcMapFst > > { + public: + ArcIterator(const DecodeFst &fst, typename A::StateId s) + : ArcIterator< ArcMapFst > >(fst, s) {} +}; + + +// Useful aliases when using StdArc. +typedef EncodeFst StdEncodeFst; + +typedef DecodeFst StdDecodeFst; + +} // namespace fst + +#endif // FST_LIB_ENCODE_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/epsnormalize.h b/kaldi_io/src/tools/openfst/include/fst/epsnormalize.h new file mode 100644 index 0000000..9d178b1 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/epsnormalize.h @@ -0,0 +1,73 @@ +// epsnormalize.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: allauzen@google.com (Cyril Allauzen) +// +// \file +// Function that implements epsilon normalization. + +#ifndef FST_LIB_EPSNORMALIZE_H__ +#define FST_LIB_EPSNORMALIZE_H__ + +#include +using std::tr1::unordered_map; +using std::tr1::unordered_multimap; + + +#include +#include +#include +#include + + +namespace fst { + +enum EpsNormalizeType {EPS_NORM_INPUT, EPS_NORM_OUTPUT}; + +// Returns an equivalent FST that is epsilon-normalized. An acceptor is +// epsilon-normalized if it is epsilon-removed. A transducer is input +// epsilon-normalized if additionally if on each path any epsilon input +// label follows all non-epsilon input labels. Output epsilon-normalized +// is defined similarly. +// +// The input FST needs to be functional. +// +// References: +// - Mehryar Mohri. "Generic epsilon-removal and input epsilon-normalization +// algorithms for weighted transducers", International Journal of Computer +// Science, 13(1): 129-143, 2002. +template +void EpsNormalize(const Fst &ifst, MutableFst *ofst, + EpsNormalizeType type = EPS_NORM_INPUT) { + VectorFst< GallicArc > gfst; + if (type == EPS_NORM_INPUT) + ArcMap(ifst, &gfst, ToGallicMapper()); + else // type == EPS_NORM_OUTPUT + ArcMap(InvertFst(ifst), &gfst, + ToGallicMapper()); + RmEpsilon(&gfst); + FactorWeightFst< GallicArc, + GallicFactor > + fwfst(gfst); + ArcMap(fwfst, ofst, FromGallicMapper()); + ofst->SetOutputSymbols(ifst.OutputSymbols()); + if(type == EPS_NORM_OUTPUT) + Invert(ofst); +} + +} // namespace fst + +#endif // FST_LIB_EPSNORMALIZE_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/equal.h b/kaldi_io/src/tools/openfst/include/fst/equal.h new file mode 100644 index 0000000..33be198 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/equal.h @@ -0,0 +1,124 @@ +// test.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Function to test equality of two Fsts. + +#ifndef FST_LIB_EQUAL_H__ +#define FST_LIB_EQUAL_H__ + +#include + + +namespace fst { + +// Tests if two Fsts have the same states and arcs in the same order. +template +bool Equal(const Fst &fst1, const Fst &fst2, float delta = kDelta) { + typedef typename Arc::StateId StateId; + typedef typename Arc::Weight Weight; + + if (fst1.Start() != fst2.Start()) { + VLOG(1) << "Equal: mismatched start states"; + return false; + } + + StateIterator< Fst > siter1(fst1); + StateIterator< Fst > siter2(fst2); + + while (!siter1.Done() || !siter2.Done()) { + if (siter1.Done() || siter2.Done()) { + VLOG(1) << "Equal: mismatched # of states"; + return false; + } + StateId s1 = siter1.Value(); + StateId s2 = siter2.Value(); + if (s1 != s2) { + VLOG(1) << "Equal: mismatched states:" + << ", state1 = " << s1 + << ", state2 = " << s2; + return false; + } + Weight final1 = fst1.Final(s1); + Weight final2 = fst2.Final(s2); + if (!ApproxEqual(final1, final2, delta)) { + VLOG(1) << "Equal: mismatched final weights:" + << " state = " << s1 + << ", final1 = " << final1 + << ", final2 = " << final2; + return false; + } + ArcIterator< Fst > aiter1(fst1, s1); + ArcIterator< Fst > aiter2(fst2, s2); + for (size_t a = 0; !aiter1.Done() || !aiter2.Done(); ++a) { + if (aiter1.Done() || aiter2.Done()) { + VLOG(1) << "Equal: mismatched # of arcs" + << " state = " << s1; + return false; + } + Arc arc1 = aiter1.Value(); + Arc arc2 = aiter2.Value(); + if (arc1.ilabel != arc2.ilabel) { + VLOG(1) << "Equal: mismatched arc input labels:" + << " state = " << s1 + << ", arc = " << a + << ", ilabel1 = " << arc1.ilabel + << ", ilabel2 = " << arc2.ilabel; + return false; + } else if (arc1.olabel != arc2.olabel) { + VLOG(1) << "Equal: mismatched arc output labels:" + << " state = " << s1 + << ", arc = " << a + << ", olabel1 = " << arc1.olabel + << ", olabel2 = " << arc2.olabel; + return false; + } else if (!ApproxEqual(arc1.weight, arc2.weight, delta)) { + VLOG(1) << "Equal: mismatched arc weights:" + << " state = " << s1 + << ", arc = " << a + << ", weight1 = " << arc1.weight + << ", weight2 = " << arc2.weight; + return false; + } else if (arc1.nextstate != arc2.nextstate) { + VLOG(1) << "Equal: mismatched input label:" + << " state = " << s1 + << ", arc = " << a + << ", nextstate1 = " << arc1.nextstate + << ", nextstate2 = " << arc2.nextstate; + return false; + } + aiter1.Next(); + aiter2.Next(); + + } + // Sanity checks: should never fail + if (fst1.NumArcs(s1) != fst2.NumArcs(s2) || + fst1.NumInputEpsilons(s1) != fst2.NumInputEpsilons(s2) || + fst1.NumOutputEpsilons(s1) != fst2.NumOutputEpsilons(s2)) { + FSTERROR() << "Equal: inconsistent arc/epsilon counts"; + } + + siter1.Next(); + siter2.Next(); + } + return true; +} + +} // namespace fst + + +#endif // FST_LIB_EQUAL_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/equivalent.h b/kaldi_io/src/tools/openfst/include/fst/equivalent.h new file mode 100644 index 0000000..e28fea1 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/equivalent.h @@ -0,0 +1,275 @@ +// equivalent.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: wojciech@google.com (Wojciech Skut) +// +// \file Functions and classes to determine the equivalence of two +// FSTs. + +#ifndef FST_LIB_EQUIVALENT_H__ +#define FST_LIB_EQUIVALENT_H__ + +#include +#include +using std::deque; +#include +using std::tr1::unordered_map; +using std::tr1::unordered_multimap; +#include +using std::pair; using std::make_pair; +#include +using std::vector; + +#include +#include +#include +#include + + +namespace fst { + +// Traits-like struct holding utility functions/typedefs/constants for +// the equivalence algorithm. +// +// Encoding device: in order to make the statesets of the two acceptors +// disjoint, we map Arc::StateId on the type MappedId. The states of +// the first acceptor are mapped on odd numbers (s -> 2s + 1), and +// those of the second one on even numbers (s -> 2s + 2). The number 0 +// is reserved for an implicit (non-final) 'dead state' (required for +// the correct treatment of non-coaccessible states; kNoStateId is +// mapped to kDeadState for both acceptors). The union-find algorithm +// operates on the mapped IDs. +template +struct EquivalenceUtil { + typedef typename Arc::StateId StateId; + typedef typename Arc::Weight Weight; + typedef StateId MappedId; // ID for an equivalence class. + + // MappedId for an implicit dead state. + static const MappedId kDeadState = 0; + + // MappedId for lookup failure. + static const MappedId kInvalidId = -1; + + // Maps state ID to the representative of the corresponding + // equivalence class. The parameter 'which_fst' takes the values 1 + // and 2, identifying the input FST. + static MappedId MapState(StateId s, int32 which_fst) { + return + (kNoStateId == s) + ? + kDeadState + : + (static_cast(s) << 1) + which_fst; + } + // Maps set ID to State ID. + static StateId UnMapState(MappedId id) { + return static_cast((--id) >> 1); + } + // Convenience function: checks if state with MappedId 's' is final + // in acceptor 'fa'. + static bool IsFinal(const Fst &fa, MappedId s) { + return + (kDeadState == s) ? + false : (fa.Final(UnMapState(s)) != Weight::Zero()); + } + // Convenience function: returns the representative of 'id' in 'sets', + // creating a new set if needed. + static MappedId FindSet(UnionFind *sets, MappedId id) { + MappedId repr = sets->FindSet(id); + if (repr != kInvalidId) { + return repr; + } else { + sets->MakeSet(id); + return id; + } + } +}; + +template const +typename EquivalenceUtil::MappedId EquivalenceUtil::kDeadState; + +template const +typename EquivalenceUtil::MappedId EquivalenceUtil::kInvalidId; + + +// Equivalence checking algorithm: determines if the two FSTs +// fst1 and fst2 are equivalent. The input +// FSTs must be deterministic input-side epsilon-free acceptors, +// unweighted or with weights over a left semiring. Two acceptors are +// considered equivalent if they accept exactly the same set of +// strings (with the same weights). +// +// The algorithm (cf. Aho, Hopcroft and Ullman, "The Design and +// Analysis of Computer Programs") successively constructs sets of +// states that can be reached by the same prefixes, starting with a +// set containing the start states of both acceptors. A disjoint tree +// forest (the union-find algorithm) is used to represent the sets of +// states. The algorithm returns 'false' if one of the constructed +// sets contains both final and non-final states. Returns optional error +// value (when FLAGS_error_fatal = false). +// +// Complexity: quasi-linear, i.e. O(n G(n)), where +// n = |S1| + |S2| is the number of states in both acceptors +// G(n) is a very slowly growing function that can be approximated +// by 4 by all practical purposes. +// +template +bool Equivalent(const Fst &fst1, + const Fst &fst2, + double delta = kDelta, bool *error = 0) { + typedef typename Arc::Weight Weight; + if (error) *error = false; + + // Check that the symbol table are compatible + if (!CompatSymbols(fst1.InputSymbols(), fst2.InputSymbols()) || + !CompatSymbols(fst1.OutputSymbols(), fst2.OutputSymbols())) { + FSTERROR() << "Equivalent: input/output symbol tables of 1st argument " + << "do not match input/output symbol tables of 2nd argument"; + if (error) *error = true; + return false; + } + // Check properties first: + uint64 props = kNoEpsilons | kIDeterministic | kAcceptor; + if (fst1.Properties(props, true) != props) { + FSTERROR() << "Equivalent: first argument not an" + << " epsilon-free deterministic acceptor"; + if (error) *error = true; + return false; + } + if (fst2.Properties(props, true) != props) { + FSTERROR() << "Equivalent: second argument not an" + << " epsilon-free deterministic acceptor"; + if (error) *error = true; + return false; + } + + if ((fst1.Properties(kUnweighted , true) != kUnweighted) + || (fst2.Properties(kUnweighted , true) != kUnweighted)) { + VectorFst efst1(fst1); + VectorFst efst2(fst2); + Push(&efst1, REWEIGHT_TO_INITIAL, delta); + Push(&efst2, REWEIGHT_TO_INITIAL, delta); + ArcMap(&efst1, QuantizeMapper(delta)); + ArcMap(&efst2, QuantizeMapper(delta)); + EncodeMapper mapper(kEncodeWeights|kEncodeLabels, ENCODE); + ArcMap(&efst1, &mapper); + ArcMap(&efst2, &mapper); + return Equivalent(efst1, efst2); + } + + // Convenience typedefs: + typedef typename Arc::StateId StateId; + typedef EquivalenceUtil Util; + typedef typename Util::MappedId MappedId; + enum { FST1 = 1, FST2 = 2 }; // Required by Util::MapState(...) + + MappedId s1 = Util::MapState(fst1.Start(), FST1); + MappedId s2 = Util::MapState(fst2.Start(), FST2); + + // The union-find structure. + UnionFind eq_classes(1000, Util::kInvalidId); + + // Initialize the union-find structure. + eq_classes.MakeSet(s1); + eq_classes.MakeSet(s2); + + // Data structure for the (partial) acceptor transition function of + // fst1 and fst2: input labels mapped to pairs of MappedId's + // representing destination states of the corresponding arcs in fst1 + // and fst2, respectively. + typedef + unordered_map > + Label2StatePairMap; + + Label2StatePairMap arc_pairs; + + // Pairs of MappedId's to be processed, organized in a queue. + deque > q; + + bool ret = true; + // Early return if the start states differ w.r.t. being final. + if (Util::IsFinal(fst1, s1) != Util::IsFinal(fst2, s2)) { + ret = false; + } + + // Main loop: explores the two acceptors in a breadth-first manner, + // updating the equivalence relation on the statesets. Loop + // invariant: each block of states contains either final states only + // or non-final states only. + for (q.push_back(make_pair(s1, s2)); ret && !q.empty(); q.pop_front()) { + s1 = q.front().first; + s2 = q.front().second; + + // Representatives of the equivalence classes of s1/s2. + MappedId rep1 = Util::FindSet(&eq_classes, s1); + MappedId rep2 = Util::FindSet(&eq_classes, s2); + + if (rep1 != rep2) { + eq_classes.Union(rep1, rep2); + arc_pairs.clear(); + + // Copy outgoing arcs starting at s1 into the hashtable. + if (Util::kDeadState != s1) { + ArcIterator > arc_iter(fst1, Util::UnMapState(s1)); + for (; !arc_iter.Done(); arc_iter.Next()) { + const Arc &arc = arc_iter.Value(); + if (arc.weight != Weight::Zero()) { // Zero-weight arcs + // are treated as + // non-exisitent. + arc_pairs[arc.ilabel].first = Util::MapState(arc.nextstate, FST1); + } + } + } + // Copy outgoing arcs starting at s2 into the hashtable. + if (Util::kDeadState != s2) { + ArcIterator > arc_iter(fst2, Util::UnMapState(s2)); + for (; !arc_iter.Done(); arc_iter.Next()) { + const Arc &arc = arc_iter.Value(); + if (arc.weight != Weight::Zero()) { // Zero-weight arcs + // are treated as + // non-existent. + arc_pairs[arc.ilabel].second = Util::MapState(arc.nextstate, FST2); + } + } + } + // Iterate through the hashtable and process pairs of target + // states. + for (typename Label2StatePairMap::const_iterator + arc_iter = arc_pairs.begin(); + arc_iter != arc_pairs.end(); + ++arc_iter) { + const pair &p = arc_iter->second; + if (Util::IsFinal(fst1, p.first) != Util::IsFinal(fst2, p.second)) { + // Detected inconsistency: return false. + ret = false; + break; + } + q.push_back(p); + } + } + } + + if (fst1.Properties(kError, false) || fst2.Properties(kError, false)) { + if (error) *error = true; + return false; + } + + return ret; +} + +} // namespace fst + +#endif // FST_LIB_EQUIVALENT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/expanded-fst.h b/kaldi_io/src/tools/openfst/include/fst/expanded-fst.h new file mode 100644 index 0000000..676ceb3 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/expanded-fst.h @@ -0,0 +1,189 @@ +// expanded-fst.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Generic FST augmented with state count - interface class definition. +// + +#ifndef FST_LIB_EXPANDED_FST_H__ +#define FST_LIB_EXPANDED_FST_H__ + +#include +#include + +#include + + +namespace fst { + +// A generic FST plus state count. +template +class ExpandedFst : public Fst { + public: + typedef A Arc; + typedef typename A::StateId StateId; + + virtual StateId NumStates() const = 0; // State count + + // Get a copy of this ExpandedFst. See Fst<>::Copy() for further doc. + virtual ExpandedFst *Copy(bool safe = false) const = 0; + + // Read an ExpandedFst from an input stream; return NULL on error. + static ExpandedFst *Read(istream &strm, const FstReadOptions &opts) { + FstReadOptions ropts(opts); + FstHeader hdr; + if (ropts.header) + hdr = *opts.header; + else { + if (!hdr.Read(strm, opts.source)) + return 0; + ropts.header = &hdr; + } + if (!(hdr.Properties() & kExpanded)) { + LOG(ERROR) << "ExpandedFst::Read: Not an ExpandedFst: " << ropts.source; + return 0; + } + FstRegister *registr = FstRegister::GetRegister(); + const typename FstRegister::Reader reader = + registr->GetReader(hdr.FstType()); + if (!reader) { + LOG(ERROR) << "ExpandedFst::Read: Unknown FST type \"" << hdr.FstType() + << "\" (arc type = \"" << A::Type() + << "\"): " << ropts.source; + return 0; + } + Fst *fst = reader(strm, ropts); + if (!fst) return 0; + return static_cast *>(fst); + } + + // Read an ExpandedFst from a file; return NULL on error. + // Empty filename reads from standard input. + static ExpandedFst *Read(const string &filename) { + if (!filename.empty()) { + ifstream strm(filename.c_str(), ifstream::in | ifstream::binary); + if (!strm) { + LOG(ERROR) << "ExpandedFst::Read: Can't open file: " << filename; + return 0; + } + return Read(strm, FstReadOptions(filename)); + } else { + return Read(cin, FstReadOptions("standard input")); + } + } +}; + + +namespace internal { + +// ExpandedFst case - abstract methods. +template inline +typename A::Weight Final(const ExpandedFst &fst, typename A::StateId s) { + return fst.Final(s); +} + +template inline +ssize_t NumArcs(const ExpandedFst &fst, typename A::StateId s) { + return fst.NumArcs(s); +} + +template inline +ssize_t NumInputEpsilons(const ExpandedFst &fst, typename A::StateId s) { + return fst.NumInputEpsilons(s); +} + +template inline +ssize_t NumOutputEpsilons(const ExpandedFst &fst, typename A::StateId s) { + return fst.NumOutputEpsilons(s); +} + +} // namespace internal + + +// A useful alias when using StdArc. +typedef ExpandedFst StdExpandedFst; + + +// This is a helper class template useful for attaching an ExpandedFst +// interface to its implementation, handling reference counting. It +// delegates to ImplToFst the handling of the Fst interface methods. +template < class I, class F = ExpandedFst > +class ImplToExpandedFst : public ImplToFst { + public: + typedef typename I::Arc Arc; + typedef typename Arc::Weight Weight; + typedef typename Arc::StateId StateId; + + using ImplToFst::GetImpl; + + virtual StateId NumStates() const { return GetImpl()->NumStates(); } + + protected: + ImplToExpandedFst() : ImplToFst() {} + + ImplToExpandedFst(I *impl) : ImplToFst(impl) {} + + ImplToExpandedFst(const ImplToExpandedFst &fst) + : ImplToFst(fst) {} + + ImplToExpandedFst(const ImplToExpandedFst &fst, bool safe) + : ImplToFst(fst, safe) {} + + // Read FST implementation from a file; return NULL on error. + // Empty filename reads from standard input. + static I *Read(const string &filename) { + if (!filename.empty()) { + ifstream strm(filename.c_str(), ifstream::in | ifstream::binary); + if (!strm) { + LOG(ERROR) << "ExpandedFst::Read: Can't open file: " << filename; + return 0; + } + return I::Read(strm, FstReadOptions(filename)); + } else { + return I::Read(cin, FstReadOptions("standard input")); + } + } + + private: + // Disallow + ImplToExpandedFst &operator=(const ImplToExpandedFst &fst); + + ImplToExpandedFst &operator=(const Fst &fst) { + FSTERROR() << "ImplToExpandedFst: Assignment operator disallowed"; + GetImpl()->SetProperties(kError, kError); + return *this; + } +}; + +// Function to return the number of states in an FST, counting them +// if necessary. +template +typename Arc::StateId CountStates(const Fst &fst) { + if (fst.Properties(kExpanded, false)) { + const ExpandedFst *efst = static_cast *>(&fst); + return efst->NumStates(); + } else { + typename Arc::StateId nstates = 0; + for (StateIterator< Fst > siter(fst); !siter.Done(); siter.Next()) + ++nstates; + return nstates; + } +} + +} // namespace fst + +#endif // FST_LIB_EXPANDED_FST_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/expectation-weight.h b/kaldi_io/src/tools/openfst/include/fst/expectation-weight.h new file mode 100644 index 0000000..5226cad --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/expectation-weight.h @@ -0,0 +1,142 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: krr@google.com (Kasturi Rangan Raghavan) +// Inspiration: shumash@google.com (Masha Maria Shugrina) +// \file +// Expectation semiring as described by Jason Eisner: +// See: doi=10.1.1.22.9398 +// Multiplex semiring operations and identities: +// One: +// Zero: +// Plus: + = < (a1 + a2) , (b1 + b2) > +// Times: * = < (a1 * a2) , [(a1 * b2) + (a2 * b1)] > +// Division: Undefined (currently) +// +// Usually used to store the pair so that +// ShortestDistance[Fst > >] +// == < PosteriorProbability, Expected_Value[V] > + +#ifndef FST_LIB_EXPECTATION_WEIGHT_H_ +#define FST_LIB_EXPECTATION_WEIGHT_H_ + +#include + +#include + + +namespace fst { + +// X1 is usually a probability weight like LogWeight +// X2 is usually a random variable or vector +// see SignedLogWeight or SparsePowerWeight +// +// If X1 is distinct from X2, it is required that there is an external +// product between X1 and X2 and if both semriring are commutative, or +// left or right semirings, then result must have those properties. +template +class ExpectationWeight : public PairWeight { + public: + using PairWeight::Value1; + using PairWeight::Value2; + + using PairWeight::Reverse; + using PairWeight::Quantize; + using PairWeight::Member; + + typedef X1 W1; + typedef X2 W2; + + typedef ExpectationWeight ReverseWeight; + + ExpectationWeight() : PairWeight(Zero()) { } + + ExpectationWeight(const ExpectationWeight& w) + : PairWeight (w) { } + + ExpectationWeight(const PairWeight& w) + : PairWeight (w) { } + + ExpectationWeight(const X1& x1, const X2& x2) + : PairWeight(x1, x2) { } + + static const ExpectationWeight &Zero() { + static const ExpectationWeight zero(X1::Zero(), X2::Zero()); + return zero; + } + + static const ExpectationWeight &One() { + static const ExpectationWeight one(X1::One(), X2::Zero()); + return one; + } + + static const ExpectationWeight &NoWeight() { + static const ExpectationWeight no_weight(X1::NoWeight(), + X2::NoWeight()); + return no_weight; + } + + static const string &Type() { + static const string type = "expectation_" + X1::Type() + "_" + X2::Type(); + return type; + } + + PairWeight Quantize(float delta = kDelta) const { + return PairWeight::Quantize(); + } + + ReverseWeight Reverse() const { + return PairWeight::Reverse(); + } + + bool Member() const { + return PairWeight::Member(); + } + + static uint64 Properties() { + uint64 props1 = W1::Properties(); + uint64 props2 = W2::Properties(); + return props1 & props2 & (kLeftSemiring | kRightSemiring | + kCommutative | kIdempotent); + } +}; + +template +inline ExpectationWeight Plus(const ExpectationWeight &w, + const ExpectationWeight &v) { + return ExpectationWeight(Plus(w.Value1(), v.Value1()), + Plus(w.Value2(), v.Value2())); +} + + +template +inline ExpectationWeight Times(const ExpectationWeight &w, + const ExpectationWeight &v) { + return ExpectationWeight(Times(w.Value1(), v.Value1()), + Plus(Times(w.Value1(), v.Value2()), + Times(w.Value2(), v.Value1()))); +} + +template +inline ExpectationWeight Divide(const ExpectationWeight &w, + const ExpectationWeight &v, + DivideType typ = DIVIDE_ANY) { + FSTERROR() << "ExpectationWeight::Divide: not implemented"; + return ExpectationWeight::NoWeight(); +} + +} // namespace fst + +#endif // FST_LIB_EXPECTATION_WEIGHT_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/extensions/far/compile-strings.h b/kaldi_io/src/tools/openfst/include/fst/extensions/far/compile-strings.h new file mode 100644 index 0000000..ca247db --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/extensions/far/compile-strings.h @@ -0,0 +1,304 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Authors: allauzen@google.com (Cyril Allauzen) +// ttai@google.com (Terry Tai) +// jpr@google.com (Jake Ratkiewicz) + + +#ifndef FST_EXTENSIONS_FAR_COMPILE_STRINGS_H_ +#define FST_EXTENSIONS_FAR_COMPILE_STRINGS_H_ + +#include +#include +#include +using std::vector; + +#include +#include + +namespace fst { + +// Construct a reader that provides FSTs from a file (stream) either on a +// line-by-line basis or on a per-stream basis. Note that the freshly +// constructed reader is already set to the first input. +// +// Sample Usage: +// for (StringReader reader(...); !reader.Done(); reader.Next()) { +// Fst *fst = reader.GetVectorFst(); +// } +template +class StringReader { + public: + typedef A Arc; + typedef typename A::Label Label; + typedef typename A::Weight Weight; + typedef typename StringCompiler::TokenType TokenType; + + enum EntryType { LINE = 1, FILE = 2 }; + + StringReader(istream &istrm, + const string &source, + EntryType entry_type, + TokenType token_type, + bool allow_negative_labels, + const SymbolTable *syms = 0, + Label unknown_label = kNoStateId) + : nline_(0), strm_(istrm), source_(source), entry_type_(entry_type), + token_type_(token_type), symbols_(syms), done_(false), + compiler_(token_type, syms, unknown_label, allow_negative_labels) { + Next(); // Initialize the reader to the first input. + } + + bool Done() { + return done_; + } + + void Next() { + VLOG(1) << "Processing source " << source_ << " at line " << nline_; + if (!strm_) { // We're done if we have no more input. + done_ = true; + return; + } + if (entry_type_ == LINE) { + getline(strm_, content_); + ++nline_; + } else { + content_.clear(); + string line; + while (getline(strm_, line)) { + ++nline_; + content_.append(line); + content_.append("\n"); + } + } + if (!strm_ && content_.empty()) // We're also done if we read off all the + done_ = true; // whitespace at the end of a file. + } + + VectorFst *GetVectorFst(bool keep_symbols = false) { + VectorFst *fst = new VectorFst; + if (keep_symbols) { + fst->SetInputSymbols(symbols_); + fst->SetOutputSymbols(symbols_); + } + if (compiler_(content_, fst)) { + return fst; + } else { + delete fst; + return NULL; + } + } + + CompactFst > *GetCompactFst(bool keep_symbols = false) { + CompactFst > *fst; + if (keep_symbols) { + VectorFst tmp; + tmp.SetInputSymbols(symbols_); + tmp.SetOutputSymbols(symbols_); + fst = new CompactFst >(tmp); + } else { + fst = new CompactFst >; + } + if (compiler_(content_, fst)) { + return fst; + } else { + delete fst; + return NULL; + } + } + + private: + size_t nline_; + istream &strm_; + string source_; + EntryType entry_type_; + TokenType token_type_; + const SymbolTable *symbols_; + bool done_; + StringCompiler compiler_; + string content_; // The actual content of the input stream's next FST. + + DISALLOW_COPY_AND_ASSIGN(StringReader); +}; + +// Compute the minimal length required to encode each line number as a decimal +// number. +int KeySize(const char *filename); + +template +void FarCompileStrings(const vector &in_fnames, + const string &out_fname, + const string &fst_type, + const FarType &far_type, + int32 generate_keys, + FarEntryType fet, + FarTokenType tt, + const string &symbols_fname, + const string &unknown_symbol, + bool keep_symbols, + bool initial_symbols, + bool allow_negative_labels, + bool file_list_input, + const string &key_prefix, + const string &key_suffix) { + typename StringReader::EntryType entry_type; + if (fet == FET_LINE) { + entry_type = StringReader::LINE; + } else if (fet == FET_FILE) { + entry_type = StringReader::FILE; + } else { + FSTERROR() << "FarCompileStrings: unknown entry type"; + return; + } + + typename StringCompiler::TokenType token_type; + if (tt == FTT_SYMBOL) { + token_type = StringCompiler::SYMBOL; + } else if (tt == FTT_BYTE) { + token_type = StringCompiler::BYTE; + } else if (tt == FTT_UTF8) { + token_type = StringCompiler::UTF8; + } else { + FSTERROR() << "FarCompileStrings: unknown token type"; + return; + } + + bool compact; + if (fst_type.empty() || (fst_type == "vector")) { + compact = false; + } else if (fst_type == "compact") { + compact = true; + } else { + FSTERROR() << "FarCompileStrings: unknown fst type: " + << fst_type; + return; + } + + const SymbolTable *syms = 0; + typename Arc::Label unknown_label = kNoLabel; + if (!symbols_fname.empty()) { + SymbolTableTextOptions opts; + opts.allow_negative = allow_negative_labels; + syms = SymbolTable::ReadText(symbols_fname, opts); + if (!syms) { + FSTERROR() << "FarCompileStrings: error reading symbol table: " + << symbols_fname; + return; + } + if (!unknown_symbol.empty()) { + unknown_label = syms->Find(unknown_symbol); + if (unknown_label == kNoLabel) { + FSTERROR() << "FarCompileStrings: unknown label \"" << unknown_label + << "\" missing from symbol table: " << symbols_fname; + return; + } + } + } + + FarWriter *far_writer = + FarWriter::Create(out_fname, far_type); + if (!far_writer) return; + + vector inputs; + if (file_list_input) { + for (int i = 1; i < in_fnames.size(); ++i) { + istream *istrm = in_fnames.empty() ? &cin : + new ifstream(in_fnames[i].c_str()); + string str; + while (getline(*istrm, str)) + inputs.push_back(str); + if (!in_fnames.empty()) + delete istrm; + } + } else { + inputs = in_fnames; + } + + for (int i = 0, n = 0; i < inputs.size(); ++i) { + if (generate_keys == 0 && inputs[i].empty()) { + FSTERROR() << "FarCompileStrings: read from a file instead of stdin or" + << " set the --generate_keys flags."; + delete far_writer; + delete syms; + return; + } + int key_size = generate_keys ? generate_keys : + (entry_type == StringReader::FILE ? 1 : + KeySize(inputs[i].c_str())); + istream *istrm = inputs[i].empty() ? &cin : + new ifstream(inputs[i].c_str()); + + bool keep_syms = keep_symbols; + for (StringReader reader( + *istrm, inputs[i].empty() ? "stdin" : inputs[i], + entry_type, token_type, allow_negative_labels, + syms, unknown_label); + !reader.Done(); + reader.Next()) { + ++n; + const Fst *fst; + if (compact) + fst = reader.GetCompactFst(keep_syms); + else + fst = reader.GetVectorFst(keep_syms); + if (initial_symbols) + keep_syms = false; + if (!fst) { + FSTERROR() << "FarCompileStrings: compiling string number " << n + << " in file " << inputs[i] << " failed with token_type = " + << (tt == FTT_BYTE ? "byte" : + (tt == FTT_UTF8 ? "utf8" : + (tt == FTT_SYMBOL ? "symbol" : "unknown"))) + << " and entry_type = " + << (fet == FET_LINE ? "line" : + (fet == FET_FILE ? "file" : "unknown")); + delete far_writer; + delete syms; + if (!inputs[i].empty()) delete istrm; + return; + } + ostringstream keybuf; + keybuf.width(key_size); + keybuf.fill('0'); + keybuf << n; + string key; + if (generate_keys > 0) { + key = keybuf.str(); + } else { + char* filename = new char[inputs[i].size() + 1]; + strcpy(filename, inputs[i].c_str()); + key = basename(filename); + if (entry_type != StringReader::FILE) { + key += "-"; + key += keybuf.str(); + } + delete[] filename; + } + far_writer->Add(key_prefix + key + key_suffix, *fst); + delete fst; + } + if (generate_keys == 0) + n = 0; + if (!inputs[i].empty()) + delete istrm; + } + + delete far_writer; +} + +} // namespace fst + + +#endif // FST_EXTENSIONS_FAR_COMPILE_STRINGS_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/extensions/far/create.h b/kaldi_io/src/tools/openfst/include/fst/extensions/far/create.h new file mode 100644 index 0000000..edb31e7 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/extensions/far/create.h @@ -0,0 +1,87 @@ +// create-main.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// Modified: jpr@google.com (Jake Ratkiewicz) to use new dispatch +// +// \file +// Creates a finite-state archive from component FSTs. Includes +// helper function for farcreate.cc that templates the main on the arc +// type to support multiple and extensible arc types. +// + +#ifndef FST_EXTENSIONS_FAR_CREATE_H__ +#define FST_EXTENSIONS_FAR_CREATE_H__ + +#include +#include +#include +using std::vector; + +#include + +namespace fst { + +template +void FarCreate(const vector &in_fnames, + const string &out_fname, + const int32 generate_keys, + const bool file_list_input, + const FarType &far_type, + const string &key_prefix, + const string &key_suffix) { + FarWriter *far_writer = + FarWriter::Create(out_fname, far_type); + if (!far_writer) return; + + vector inputs; + if (file_list_input) { + for (int i = 1; i < in_fnames.size(); ++i) { + ifstream istrm(in_fnames[i].c_str()); + string str; + while (getline(istrm, str)) + inputs.push_back(str); + } + } else { + inputs = in_fnames; + } + + for (int i = 0; i < inputs.size(); ++i) { + Fst *ifst = Fst::Read(inputs[i]); + if (!ifst) return; + string key; + if (generate_keys > 0) { + ostringstream keybuf; + keybuf.width(generate_keys); + keybuf.fill('0'); + keybuf << i + 1; + key = keybuf.str(); + } else { + char* filename = new char[inputs[i].size() + 1]; + strcpy(filename, inputs[i].c_str()); + key = basename(filename); + delete[] filename; + } + + far_writer->Add(key_prefix + key + key_suffix, *ifst); + delete ifst; + } + + delete far_writer; +} + +} // namespace fst + +#endif // FST_EXTENSIONS_FAR_CREATE_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/extensions/far/equal.h b/kaldi_io/src/tools/openfst/include/fst/extensions/far/equal.h new file mode 100644 index 0000000..be82e2d --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/extensions/far/equal.h @@ -0,0 +1,99 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: allauzen@google.com (Cyril Allauzen) + +#ifndef FST_EXTENSIONS_FAR_EQUAL_H_ +#define FST_EXTENSIONS_FAR_EQUAL_H_ + +#include + +#include +#include + +namespace fst { + +template +bool FarEqual(const string &filename1, + const string &filename2, + float delta = kDelta, + const string &begin_key = string(), + const string &end_key = string()) { + + FarReader *reader1 = FarReader::Open(filename1); + FarReader *reader2 = FarReader::Open(filename2); + if (!reader1 || !reader2) { + delete reader1; + delete reader2; + VLOG(1) << "FarEqual: cannot open input Far file(s)"; + return false; + } + + if (!begin_key.empty()) { + bool find_begin1 = reader1->Find(begin_key); + bool find_begin2 = reader2->Find(begin_key); + if (!find_begin1 || !find_begin2) { + bool ret = !find_begin1 && !find_begin2; + if (!ret) { + VLOG(1) << "FarEqual: key \"" << begin_key << "\" missing from " + << (find_begin1 ? "second" : "first") << " archive."; + } + delete reader1; + delete reader2; + return ret; + } + } + + for(; !reader1->Done() && !reader2->Done(); + reader1->Next(), reader2->Next()) { + const string key1 = reader1->GetKey(); + const string key2 = reader2->GetKey(); + if (!end_key.empty() && end_key < key1 && end_key < key2) { + delete reader1; + delete reader2; + return true; + } + if (key1 != key2) { + VLOG(1) << "FarEqual: mismatched keys \"" + << key1 << "\" <> \"" << key2 << "\"."; + delete reader1; + delete reader2; + return false; + } + if (!Equal(reader1->GetFst(), reader2->GetFst(), delta)) { + VLOG(1) << "FarEqual: Fsts for key \"" << key1 << "\" are not equal."; + delete reader1; + delete reader2; + return false; + } + } + + if (!reader1->Done() || !reader2->Done()) { + VLOG(1) << "FarEqual: key \"" + << (reader1->Done() ? reader2->GetKey() : reader1->GetKey()) + << "\" missing form " << (reader2->Done() ? "first" : "second") + << " archive."; + delete reader1; + delete reader2; + return false; + } + + delete reader1; + delete reader2; + return true; +} + +} // namespace fst + +#endif // FST_EXTENSIONS_FAR_EQUAL_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/extensions/far/extract.h b/kaldi_io/src/tools/openfst/include/fst/extensions/far/extract.h new file mode 100644 index 0000000..95866de --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/extensions/far/extract.h @@ -0,0 +1,140 @@ +// extract-main.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// Modified: jpr@google.com (Jake Ratkiewicz) to use the new arc-dispatch + +// \file +// Extracts component FSTs from an finite-state archive. +// + +#ifndef FST_EXTENSIONS_FAR_EXTRACT_H__ +#define FST_EXTENSIONS_FAR_EXTRACT_H__ + +#include +#include +using std::vector; + +#include + +namespace fst { + +template +inline void FarWriteFst(const Fst* fst, string key, + string* okey, int* nrep, + const int32 &generate_filenames, int i, + const string &filename_prefix, + const string &filename_suffix) { + if (key == *okey) + ++*nrep; + else + *nrep = 0; + + *okey = key; + + string ofilename; + if (generate_filenames) { + ostringstream tmp; + tmp.width(generate_filenames); + tmp.fill('0'); + tmp << i; + ofilename = tmp.str(); + } else { + if (*nrep > 0) { + ostringstream tmp; + tmp << '.' << nrep; + key.append(tmp.str().data(), tmp.str().size()); + } + ofilename = key; + } + fst->Write(filename_prefix + ofilename + filename_suffix); +} + +template +void FarExtract(const vector &ifilenames, + const int32 &generate_filenames, + const string &keys, + const string &key_separator, + const string &range_delimiter, + const string &filename_prefix, + const string &filename_suffix) { + FarReader *far_reader = FarReader::Open(ifilenames); + if (!far_reader) return; + + string okey; + int nrep = 0; + + vector key_vector; + // User has specified a set of fsts to extract, where some of the "fsts" could + // be ranges. + if (!keys.empty()) { + char *keys_cstr = new char[keys.size()+1]; + strcpy(keys_cstr, keys.c_str()); + SplitToVector(keys_cstr, key_separator.c_str(), &key_vector, true); + int i = 0; + for (int k = 0; k < key_vector.size(); ++k, ++i) { + string key = string(key_vector[k]); + char *key_cstr = new char[key.size()+1]; + strcpy(key_cstr, key.c_str()); + vector range_vector; + SplitToVector(key_cstr, range_delimiter.c_str(), &range_vector, false); + if (range_vector.size() == 1) { // Not a range + if (!far_reader->Find(key)) { + LOG(ERROR) << "FarExtract: Cannot find key: " << key; + return; + } + const Fst &fst = far_reader->GetFst(); + FarWriteFst(&fst, key, &okey, &nrep, generate_filenames, i, + filename_prefix, filename_suffix); + } else if (range_vector.size() == 2) { // A legal range + string begin_key = string(range_vector[0]); + string end_key = string(range_vector[1]); + if (begin_key.empty() || end_key.empty()) { + LOG(ERROR) << "FarExtract: Illegal range specification: " << key; + return; + } + if (!far_reader->Find(begin_key)) { + LOG(ERROR) << "FarExtract: Cannot find key: " << begin_key; + return; + } + for ( ; !far_reader->Done(); far_reader->Next(), ++i) { + string ikey = far_reader->GetKey(); + if (end_key < ikey) break; + const Fst &fst = far_reader->GetFst(); + FarWriteFst(&fst, ikey, &okey, &nrep, generate_filenames, i, + filename_prefix, filename_suffix); + } + } else { + LOG(ERROR) << "FarExtract: Illegal range specification: " << key; + return; + } + delete key_cstr; + } + delete keys_cstr; + return; + } + // Nothing specified: extract everything. + for (int i = 1; !far_reader->Done(); far_reader->Next(), ++i) { + string key = far_reader->GetKey(); + const Fst &fst = far_reader->GetFst(); + FarWriteFst(&fst, key, &okey, &nrep, generate_filenames, i, + filename_prefix, filename_suffix); + } + return; +} + +} // namespace fst + +#endif // FST_EXTENSIONS_FAR_EXTRACT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/extensions/far/far.h b/kaldi_io/src/tools/openfst/include/fst/extensions/far/far.h new file mode 100644 index 0000000..acce76e --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/extensions/far/far.h @@ -0,0 +1,532 @@ +// far.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Finite-State Transducer (FST) archive classes. +// + +#ifndef FST_EXTENSIONS_FAR_FAR_H__ +#define FST_EXTENSIONS_FAR_FAR_H__ + +#include +#include +#include +#include + +namespace fst { + +enum FarEntryType { FET_LINE, FET_FILE }; +enum FarTokenType { FTT_SYMBOL, FTT_BYTE, FTT_UTF8 }; + +inline bool IsFst(const string &filename) { + ifstream strm(filename.c_str()); + if (!strm) + return false; + return IsFstHeader(strm, filename); +} + +// FST archive header class +class FarHeader { + public: + const string &FarType() const { return fartype_; } + const string &ArcType() const { return arctype_; } + + bool Read(const string &filename) { + FstHeader fsthdr; + if (filename.empty()) { + // Header reading unsupported on stdin. Assumes STList and StdArc. + fartype_ = "stlist"; + arctype_ = "standard"; + return true; + } else if (IsSTTable(filename)) { // Check if STTable + ReadSTTableHeader(filename, &fsthdr); + fartype_ = "sttable"; + arctype_ = fsthdr.ArcType().empty() ? "unknown" : fsthdr.ArcType(); + return true; + } else if (IsSTList(filename)) { // Check if STList + ReadSTListHeader(filename, &fsthdr); + fartype_ = "sttable"; + arctype_ = fsthdr.ArcType().empty() ? "unknown" : fsthdr.ArcType(); + return true; + } else if (IsFst(filename)) { // Check if Fst + ifstream istrm(filename.c_str()); + fsthdr.Read(istrm, filename); + fartype_ = "fst"; + arctype_ = fsthdr.ArcType().empty() ? "unknown" : fsthdr.ArcType(); + return true; + } + return false; + } + + private: + string fartype_; + string arctype_; +}; + +enum FarType { + FAR_DEFAULT = 0, + FAR_STTABLE = 1, + FAR_STLIST = 2, + FAR_FST = 3, +}; + +// This class creates an archive of FSTs. +template +class FarWriter { + public: + typedef A Arc; + + // Creates a new (empty) FST archive; returns NULL on error. + static FarWriter *Create(const string &filename, FarType type = FAR_DEFAULT); + + // Adds an FST to the end of an archive. Keys must be non-empty and + // in lexicographic order. FSTs must have a suitable write method. + virtual void Add(const string &key, const Fst &fst) = 0; + + virtual FarType Type() const = 0; + + virtual bool Error() const = 0; + + virtual ~FarWriter() {} + + protected: + FarWriter() {} + + private: + DISALLOW_COPY_AND_ASSIGN(FarWriter); +}; + + +// This class iterates through an existing archive of FSTs. +template +class FarReader { + public: + typedef A Arc; + + // Opens an existing FST archive in a single file; returns NULL on error. + // Sets current position to the beginning of the achive. + static FarReader *Open(const string &filename); + + // Opens an existing FST archive in multiple files; returns NULL on error. + // Sets current position to the beginning of the achive. + static FarReader *Open(const vector &filenames); + + // Resets current posision to beginning of archive. + virtual void Reset() = 0; + + // Sets current position to first entry >= key. Returns true if a match. + virtual bool Find(const string &key) = 0; + + // Current position at end of archive? + virtual bool Done() const = 0; + + // Move current position to next FST. + virtual void Next() = 0; + + // Returns key at the current position. This reference is invalidated if + // the current position in the archive is changed. + virtual const string &GetKey() const = 0; + + // Returns FST at the current position. This reference is invalidated if + // the current position in the archive is changed. + virtual const Fst &GetFst() const = 0; + + virtual FarType Type() const = 0; + + virtual bool Error() const = 0; + + virtual ~FarReader() {} + + protected: + FarReader() {} + + private: + DISALLOW_COPY_AND_ASSIGN(FarReader); +}; + + +template +class FstWriter { + public: + void operator()(ostream &strm, const Fst &fst) const { + fst.Write(strm, FstWriteOptions()); + } +}; + + +template +class STTableFarWriter : public FarWriter { + public: + typedef A Arc; + + static STTableFarWriter *Create(const string &filename) { + STTableWriter, FstWriter > *writer = + STTableWriter, FstWriter >::Create(filename); + return new STTableFarWriter(writer); + } + + void Add(const string &key, const Fst &fst) { writer_->Add(key, fst); } + + FarType Type() const { return FAR_STTABLE; } + + bool Error() const { return writer_->Error(); } + + ~STTableFarWriter() { delete writer_; } + + private: + explicit STTableFarWriter(STTableWriter, FstWriter > *writer) + : writer_(writer) {} + + private: + STTableWriter, FstWriter > *writer_; + + DISALLOW_COPY_AND_ASSIGN(STTableFarWriter); +}; + + +template +class STListFarWriter : public FarWriter { + public: + typedef A Arc; + + static STListFarWriter *Create(const string &filename) { + STListWriter, FstWriter > *writer = + STListWriter, FstWriter >::Create(filename); + return new STListFarWriter(writer); + } + + void Add(const string &key, const Fst &fst) { writer_->Add(key, fst); } + + FarType Type() const { return FAR_STLIST; } + + bool Error() const { return writer_->Error(); } + + ~STListFarWriter() { delete writer_; } + + private: + explicit STListFarWriter(STListWriter, FstWriter > *writer) + : writer_(writer) {} + + private: + STListWriter, FstWriter > *writer_; + + DISALLOW_COPY_AND_ASSIGN(STListFarWriter); +}; + + +template +class FstFarWriter : public FarWriter { + public: + typedef A Arc; + + explicit FstFarWriter(const string &filename) + : filename_(filename), error_(false), written_(false) {} + + static FstFarWriter *Create(const string &filename) { + return new FstFarWriter(filename); + } + + void Add(const string &key, const Fst &fst) { + if (written_) { + LOG(WARNING) << "FstFarWriter::Add: only one Fst supported," + << " subsequent entries discarded."; + } else { + error_ = !fst.Write(filename_); + written_ = true; + } + } + + FarType Type() const { return FAR_FST; } + + bool Error() const { return error_; } + + ~FstFarWriter() {} + + private: + string filename_; + bool error_; + bool written_; + + DISALLOW_COPY_AND_ASSIGN(FstFarWriter); +}; + + +template +FarWriter *FarWriter::Create(const string &filename, FarType type) { + switch(type) { + case FAR_DEFAULT: + if (filename.empty()) + return STListFarWriter::Create(filename); + case FAR_STTABLE: + return STTableFarWriter::Create(filename); + break; + case FAR_STLIST: + return STListFarWriter::Create(filename); + break; + case FAR_FST: + return FstFarWriter::Create(filename); + break; + default: + LOG(ERROR) << "FarWriter::Create: unknown far type"; + return 0; + } +} + + +template +class FstReader { + public: + Fst *operator()(istream &strm) const { + return Fst::Read(strm, FstReadOptions()); + } +}; + + +template +class STTableFarReader : public FarReader { + public: + typedef A Arc; + + static STTableFarReader *Open(const string &filename) { + STTableReader, FstReader > *reader = + STTableReader, FstReader >::Open(filename); + // TODO: error check + return new STTableFarReader(reader); + } + + static STTableFarReader *Open(const vector &filenames) { + STTableReader, FstReader > *reader = + STTableReader, FstReader >::Open(filenames); + // TODO: error check + return new STTableFarReader(reader); + } + + void Reset() { reader_->Reset(); } + + bool Find(const string &key) { return reader_->Find(key); } + + bool Done() const { return reader_->Done(); } + + void Next() { return reader_->Next(); } + + const string &GetKey() const { return reader_->GetKey(); } + + const Fst &GetFst() const { return reader_->GetEntry(); } + + FarType Type() const { return FAR_STTABLE; } + + bool Error() const { return reader_->Error(); } + + ~STTableFarReader() { delete reader_; } + + private: + explicit STTableFarReader(STTableReader, FstReader > *reader) + : reader_(reader) {} + + private: + STTableReader, FstReader > *reader_; + + DISALLOW_COPY_AND_ASSIGN(STTableFarReader); +}; + + +template +class STListFarReader : public FarReader { + public: + typedef A Arc; + + static STListFarReader *Open(const string &filename) { + STListReader, FstReader > *reader = + STListReader, FstReader >::Open(filename); + // TODO: error check + return new STListFarReader(reader); + } + + static STListFarReader *Open(const vector &filenames) { + STListReader, FstReader > *reader = + STListReader, FstReader >::Open(filenames); + // TODO: error check + return new STListFarReader(reader); + } + + void Reset() { reader_->Reset(); } + + bool Find(const string &key) { return reader_->Find(key); } + + bool Done() const { return reader_->Done(); } + + void Next() { return reader_->Next(); } + + const string &GetKey() const { return reader_->GetKey(); } + + const Fst &GetFst() const { return reader_->GetEntry(); } + + FarType Type() const { return FAR_STLIST; } + + bool Error() const { return reader_->Error(); } + + ~STListFarReader() { delete reader_; } + + private: + explicit STListFarReader(STListReader, FstReader > *reader) + : reader_(reader) {} + + private: + STListReader, FstReader > *reader_; + + DISALLOW_COPY_AND_ASSIGN(STListFarReader); +}; + +template +class FstFarReader : public FarReader { + public: + typedef A Arc; + + static FstFarReader *Open(const string &filename) { + vector filenames; + filenames.push_back(filename); + return new FstFarReader(filenames); + } + + static FstFarReader *Open(const vector &filenames) { + return new FstFarReader(filenames); + } + + FstFarReader(const vector &filenames) + : keys_(filenames), has_stdin_(false), pos_(0), fst_(0), error_(false) { + sort(keys_.begin(), keys_.end()); + streams_.resize(keys_.size(), 0); + for (size_t i = 0; i < keys_.size(); ++i) { + if (keys_[i].empty()) { + if (!has_stdin_) { + streams_[i] = &cin; + //sources_[i] = "stdin"; + has_stdin_ = true; + } else { + FSTERROR() << "FstFarReader::FstFarReader: stdin should only " + << "appear once in the input file list."; + error_ = true; + return; + } + } else { + streams_[i] = new ifstream( + keys_[i].c_str(), ifstream::in | ifstream::binary); + } + } + if (pos_ >= keys_.size()) return; + ReadFst(); + } + + void Reset() { + if (has_stdin_) { + FSTERROR() << "FstFarReader::Reset: operation not supported on stdin"; + error_ = true; + return; + } + pos_ = 0; + ReadFst(); + } + + bool Find(const string &key) { + if (has_stdin_) { + FSTERROR() << "FstFarReader::Find: operation not supported on stdin"; + error_ = true; + return false; + } + pos_ = 0;//TODO + ReadFst(); + return true; + } + + bool Done() const { return error_ || pos_ >= keys_.size(); } + + void Next() { + ++pos_; + ReadFst(); + } + + const string &GetKey() const { + return keys_[pos_]; + } + + const Fst &GetFst() const { + return *fst_; + } + + FarType Type() const { return FAR_FST; } + + bool Error() const { return error_; } + + ~FstFarReader() { + if (fst_) delete fst_; + for (size_t i = 0; i < keys_.size(); ++i) + delete streams_[i]; + } + + private: + void ReadFst() { + if (fst_) delete fst_; + if (pos_ >= keys_.size()) return; + streams_[pos_]->seekg(0); + fst_ = Fst::Read(*streams_[pos_], FstReadOptions()); + if (!fst_) { + FSTERROR() << "FstFarReader: error reading Fst from: " << keys_[pos_]; + error_ = true; + } + } + + private: + vector keys_; + vector streams_; + bool has_stdin_; + size_t pos_; + mutable Fst *fst_; + mutable bool error_; + + DISALLOW_COPY_AND_ASSIGN(FstFarReader); +}; + +template +FarReader *FarReader::Open(const string &filename) { + if (filename.empty()) + return STListFarReader::Open(filename); + else if (IsSTTable(filename)) + return STTableFarReader::Open(filename); + else if (IsSTList(filename)) + return STListFarReader::Open(filename); + else if (IsFst(filename)) + return FstFarReader::Open(filename); + return 0; +} + + +template +FarReader *FarReader::Open(const vector &filenames) { + if (!filenames.empty() && filenames[0].empty()) + return STListFarReader::Open(filenames); + else if (!filenames.empty() && IsSTTable(filenames[0])) + return STTableFarReader::Open(filenames); + else if (!filenames.empty() && IsSTList(filenames[0])) + return STListFarReader::Open(filenames); + else if (!filenames.empty() && IsFst(filenames[0])) + return FstFarReader::Open(filenames); + return 0; +} + +} // namespace fst + +#endif // FST_EXTENSIONS_FAR_FAR_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/extensions/far/farlib.h b/kaldi_io/src/tools/openfst/include/fst/extensions/far/farlib.h new file mode 100644 index 0000000..91ba224 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/extensions/far/farlib.h @@ -0,0 +1,31 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +// A finite-state archive (FAR) is used to store an indexable collection of +// FSTs in a single file. Utilities are provided to create FARs from FSTs, +// to iterate over FARs, and to extract specific FSTs from FARs. + +#ifndef FST_EXTENSIONS_FAR_FARLIB_H_ +#define FST_EXTENSIONS_FAR_FARLIB_H_ + +#include +#include +#include +#include +#include +#include + +#endif // FST_EXTENSIONS_FAR_FARLIB_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/extensions/far/farscript.h b/kaldi_io/src/tools/openfst/include/fst/extensions/far/farscript.h new file mode 100644 index 0000000..cfd9167 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/extensions/far/farscript.h @@ -0,0 +1,273 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +// Convenience file for including all of the FAR operations, +// or registering them for new arc types. + +#ifndef FST_EXTENSIONS_FAR_FARSCRIPT_H_ +#define FST_EXTENSIONS_FAR_FARSCRIPT_H_ + +#include +using std::vector; +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace fst { +namespace script { + +// Note: it is safe to pass these strings as references because +// this struct is only used to pass them deeper in the call graph. +// Be sure you understand why this is so before using this struct +// for anything else! +struct FarCompileStringsArgs { + const vector &in_fnames; + const string &out_fname; + const string &fst_type; + const FarType &far_type; + const int32 generate_keys; + const FarEntryType fet; + const FarTokenType tt; + const string &symbols_fname; + const string &unknown_symbol; + const bool keep_symbols; + const bool initial_symbols; + const bool allow_negative_labels; + const bool file_list_input; + const string &key_prefix; + const string &key_suffix; + + FarCompileStringsArgs(const vector &in_fnames, + const string &out_fname, + const string &fst_type, + const FarType &far_type, + int32 generate_keys, + FarEntryType fet, + FarTokenType tt, + const string &symbols_fname, + const string &unknown_symbol, + bool keep_symbols, + bool initial_symbols, + bool allow_negative_labels, + bool file_list_input, + const string &key_prefix, + const string &key_suffix) : + in_fnames(in_fnames), out_fname(out_fname), fst_type(fst_type), + far_type(far_type), generate_keys(generate_keys), fet(fet), + tt(tt), symbols_fname(symbols_fname), unknown_symbol(unknown_symbol), + keep_symbols(keep_symbols), initial_symbols(initial_symbols), + allow_negative_labels(allow_negative_labels), + file_list_input(file_list_input), key_prefix(key_prefix), + key_suffix(key_suffix) { } +}; + +template +void FarCompileStrings(FarCompileStringsArgs *args) { + fst::FarCompileStrings( + args->in_fnames, args->out_fname, args->fst_type, args->far_type, + args->generate_keys, args->fet, args->tt, args->symbols_fname, + args->unknown_symbol, args->keep_symbols, args->initial_symbols, + args->allow_negative_labels, args->file_list_input, + args->key_prefix, args->key_suffix); +} + +void FarCompileStrings( + const vector &in_fnames, + const string &out_fname, + const string &arc_type, + const string &fst_type, + const FarType &far_type, + int32 generate_keys, + FarEntryType fet, + FarTokenType tt, + const string &symbols_fname, + const string &unknown_symbol, + bool keep_symbols, + bool initial_symbols, + bool allow_negative_labels, + bool file_list_input, + const string &key_prefix, + const string &key_suffix); + + +// Note: it is safe to pass these strings as references because +// this struct is only used to pass them deeper in the call graph. +// Be sure you understand why this is so before using this struct +// for anything else! +struct FarCreateArgs { + const vector &in_fnames; + const string &out_fname; + const int32 generate_keys; + const bool file_list_input; + const FarType &far_type; + const string &key_prefix; + const string &key_suffix; + + FarCreateArgs( + const vector &in_fnames, const string &out_fname, + const int32 generate_keys, const bool file_list_input, + const FarType &far_type, const string &key_prefix, + const string &key_suffix) + : in_fnames(in_fnames), out_fname(out_fname), + generate_keys(generate_keys), file_list_input(file_list_input), + far_type(far_type), key_prefix(key_prefix), key_suffix(key_suffix) { } +}; + +template +void FarCreate(FarCreateArgs *args) { + fst::FarCreate(args->in_fnames, args->out_fname, args->generate_keys, + args->file_list_input, args->far_type, + args->key_prefix, args->key_suffix); +} + +void FarCreate(const vector &in_fnames, + const string &out_fname, + const string &arc_type, + const int32 generate_keys, + const bool file_list_input, + const FarType &far_type, + const string &key_prefix, + const string &key_suffix); + + +typedef args::Package FarEqualInnerArgs; +typedef args::WithReturnValue FarEqualArgs; + +template +void FarEqual(FarEqualArgs *args) { + args->retval = fst::FarEqual( + args->args.arg1, args->args.arg2, args->args.arg3, + args->args.arg4, args->args.arg5); +} + +bool FarEqual(const string &filename1, + const string &filename2, + const string &arc_type, + float delta = kDelta, + const string &begin_key = string(), + const string &end_key = string()); + + +typedef args::Package &, int32, + const string&, const string&, const string&, + const string&, const string&> FarExtractArgs; + +template +void FarExtract(FarExtractArgs *args) { + fst::FarExtract( + args->arg1, args->arg2, args->arg3, args->arg4, args->arg5, args->arg6, + args->arg7); +} + +void FarExtract(const vector &ifilenames, + const string &arc_type, + int32 generate_filenames, + const string &keys, + const string &key_separator, + const string &range_delimiter, + const string &filename_prefix, + const string &filename_suffix); + +typedef args::Package &, const string &, + const string &, const bool> FarInfoArgs; + +template +void FarInfo(FarInfoArgs *args) { + fst::FarInfo(args->arg1, args->arg2, args->arg3, args->arg4); +} + +void FarInfo(const vector &filenames, + const string &arc_type, + const string &begin_key, + const string &end_key, + const bool list_fsts); + +struct FarPrintStringsArgs { + const vector &ifilenames; + const FarEntryType entry_type; + const FarTokenType token_type; + const string &begin_key; + const string &end_key; + const bool print_key; + const bool print_weight; + const string &symbols_fname; + const bool initial_symbols; + const int32 generate_filenames; + const string &filename_prefix; + const string &filename_suffix; + + FarPrintStringsArgs( + const vector &ifilenames, const FarEntryType entry_type, + const FarTokenType token_type, const string &begin_key, + const string &end_key, const bool print_key, const bool print_weight, + const string &symbols_fname, const bool initial_symbols, + const int32 generate_filenames, + const string &filename_prefix, const string &filename_suffix) : + ifilenames(ifilenames), entry_type(entry_type), token_type(token_type), + begin_key(begin_key), end_key(end_key), + print_key(print_key), print_weight(print_weight), + symbols_fname(symbols_fname), initial_symbols(initial_symbols), + generate_filenames(generate_filenames), filename_prefix(filename_prefix), + filename_suffix(filename_suffix) { } +}; + +template +void FarPrintStrings(FarPrintStringsArgs *args) { + fst::FarPrintStrings( + args->ifilenames, args->entry_type, args->token_type, + args->begin_key, args->end_key, args->print_key, args->print_weight, + args->symbols_fname, args->initial_symbols, args->generate_filenames, + args->filename_prefix, args->filename_suffix); +} + + +void FarPrintStrings(const vector &ifilenames, + const string &arc_type, + const FarEntryType entry_type, + const FarTokenType token_type, + const string &begin_key, + const string &end_key, + const bool print_key, + const bool print_weight, + const string &symbols_fname, + const bool initial_symbols, + const int32 generate_filenames, + const string &filename_prefix, + const string &filename_suffix); + +} // namespace script +} // namespace fst + + +#define REGISTER_FST_FAR_OPERATIONS(ArcType) \ + REGISTER_FST_OPERATION(FarCompileStrings, ArcType, FarCompileStringsArgs); \ + REGISTER_FST_OPERATION(FarCreate, ArcType, FarCreateArgs); \ + REGISTER_FST_OPERATION(FarEqual, ArcType, FarEqualArgs); \ + REGISTER_FST_OPERATION(FarExtract, ArcType, FarExtractArgs); \ + REGISTER_FST_OPERATION(FarInfo, ArcType, FarInfoArgs); \ + REGISTER_FST_OPERATION(FarPrintStrings, ArcType, FarPrintStringsArgs) + +#endif // FST_EXTENSIONS_FAR_FARSCRIPT_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/extensions/far/info.h b/kaldi_io/src/tools/openfst/include/fst/extensions/far/info.h new file mode 100644 index 0000000..100fe68 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/extensions/far/info.h @@ -0,0 +1,128 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: allauzen@google.com (Cyril Allauzen) +// Modified: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_EXTENSIONS_FAR_INFO_H_ +#define FST_EXTENSIONS_FAR_INFO_H_ + +#include +#include +#include +#include +using std::vector; + +#include +#include // For FarTypeToString + +namespace fst { + +template +void CountStatesAndArcs(const Fst &fst, size_t *nstate, size_t *narc) { + StateIterator > siter(fst); + for (; !siter.Done(); siter.Next(), ++(*nstate)) { + ArcIterator > aiter(fst, siter.Value()); + for (; !aiter.Done(); aiter.Next(), ++(*narc)) {} + } +} + +struct KeyInfo { + string key; + string type; + size_t nstate; + size_t narc; + + KeyInfo(string k, string t, int64 ns = 0, int64 na = 0) + : key(k), type(t), nstate(ns), narc(na) {} +}; + +template +void FarInfo(const vector &filenames, const string &begin_key, + const string &end_key, const bool list_fsts) { + FarReader *far_reader = FarReader::Open(filenames); + if (!far_reader) return; + + if (!begin_key.empty()) + far_reader->Find(begin_key); + + vector *infos = list_fsts ? new vector() : 0; + size_t nfst = 0, nstate = 0, narc = 0; + set fst_types; + for (; !far_reader->Done(); far_reader->Next()) { + string key = far_reader->GetKey(); + if (!end_key.empty() && end_key < key) + break; + ++nfst; + const Fst &fst = far_reader->GetFst(); + fst_types.insert(fst.Type()); + if (infos) { + KeyInfo info(key, fst.Type()); + CountStatesAndArcs(fst, &info.nstate, &info.narc); + nstate += info.nstate; + nstate += info.narc; + infos->push_back(info); + } else { + CountStatesAndArcs(fst, &nstate, &narc); + } + } + + if (!infos) { + cout << std::left << setw(50) << "far type" + << FarTypeToString(far_reader->Type()) << endl; + cout << std::left << setw(50) << "arc type" << Arc::Type() << endl; + cout << std::left << setw(50) << "fst type"; + for (set::const_iterator iter = fst_types.begin(); + iter != fst_types.end(); + ++iter) { + if (iter != fst_types.begin()) + cout << ","; + cout << *iter; + } + cout << endl; + cout << std::left << setw(50) << "# of FSTs" << nfst << endl; + cout << std::left << setw(50) << "total # of states" << nstate << endl; + cout << std::left << setw(50) << "total # of arcs" << narc << endl; + + } else { + int wkey = 10, wtype = 10, wnstate = 16, wnarc = 16; + for (size_t i = 0; i < infos->size(); ++i) { + const KeyInfo &info = (*infos)[i]; + if (info.key.size() + 2 > wkey) + wkey = info.key.size() + 2; + if (info.type.size() + 2 > wtype) + wtype = info.type.size() + 2; + if (ceil(log10(info.nstate)) + 2 > wnstate) + wnstate = ceil(log10(info.nstate)) + 2; + if (ceil(log10(info.narc)) + 2 > wnarc) + wnarc = ceil(log10(info.narc)) + 2; + } + + cout << std::left << setw(wkey) << "key" << setw(wtype) << "type" + << std::right << setw(wnstate) << "# of states" + << setw(wnarc) << "# of arcs" << endl; + + for (size_t i = 0; i < infos->size(); ++i) { + const KeyInfo &info = (*infos)[i]; + cout << std::left << setw(wkey) << info.key << setw(wtype) << info.type + << std::right << setw(wnstate) << info.nstate + << setw(wnarc) << info.narc << endl; + } + } +} + +} // namespace fst + + +#endif // FST_EXTENSIONS_FAR_INFO_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/extensions/far/main.h b/kaldi_io/src/tools/openfst/include/fst/extensions/far/main.h new file mode 100644 index 0000000..00ccfef --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/extensions/far/main.h @@ -0,0 +1,43 @@ +// main.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Classes and functions for registering and invoking Far main +// functions that support multiple and extensible arc types. + +#ifndef FST_EXTENSIONS_FAR_MAIN_H__ +#define FST_EXTENSIONS_FAR_MAIN_H__ + +#include + +namespace fst { + +FarEntryType StringToFarEntryType(const string &s); +FarTokenType StringToFarTokenType(const string &s); + +// Return the 'FarType' value corresponding to a far type name. +FarType FarTypeFromString(const string &str); + +// Return the textual name corresponding to a 'FarType;. +string FarTypeToString(FarType type); + +string LoadArcTypeFromFar(const string& far_fname); +string LoadArcTypeFromFst(const string& far_fname); + +} // namespace fst + +#endif // FST_EXTENSIONS_FAR_MAIN_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/extensions/far/print-strings.h b/kaldi_io/src/tools/openfst/include/fst/extensions/far/print-strings.h new file mode 100644 index 0000000..dcc7351 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/extensions/far/print-strings.h @@ -0,0 +1,138 @@ +// printstrings-main.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: allauzen@google.com (Cyril Allauzen) +// Modified by: jpr@google.com (Jake Ratkiewicz) +// +// \file +// Output as strings the string FSTs in a finite-state archive. + +#ifndef FST_EXTENSIONS_FAR_PRINT_STRINGS_H__ +#define FST_EXTENSIONS_FAR_PRINT_STRINGS_H__ + +#include +#include +using std::vector; + +#include +#include +#include + +DECLARE_string(far_field_separator); + +namespace fst { + +template +void FarPrintStrings( + const vector &ifilenames, const FarEntryType entry_type, + const FarTokenType far_token_type, const string &begin_key, + const string &end_key, const bool print_key, const bool print_weight, + const string &symbols_fname, const bool initial_symbols, + const int32 generate_filenames, + const string &filename_prefix, const string &filename_suffix) { + + typename StringPrinter::TokenType token_type; + if (far_token_type == FTT_SYMBOL) { + token_type = StringPrinter::SYMBOL; + } else if (far_token_type == FTT_BYTE) { + token_type = StringPrinter::BYTE; + } else if (far_token_type == FTT_UTF8) { + token_type = StringPrinter::UTF8; + } else { + FSTERROR() << "FarPrintStrings: unknown token type"; + return; + } + + const SymbolTable *syms = 0; + if (!symbols_fname.empty()) { + // allow negative flag? + SymbolTableTextOptions opts; + opts.allow_negative = true; + syms = SymbolTable::ReadText(symbols_fname, opts); + if (!syms) { + FSTERROR() << "FarPrintStrings: error reading symbol table: " + << symbols_fname; + return; + } + } + + FarReader *far_reader = FarReader::Open(ifilenames); + if (!far_reader) return; + + if (!begin_key.empty()) + far_reader->Find(begin_key); + + string okey; + int nrep = 0; + for (int i = 1; !far_reader->Done(); far_reader->Next(), ++i) { + string key = far_reader->GetKey(); + if (!end_key.empty() && end_key < key) + break; + if (okey == key) + ++nrep; + else + nrep = 0; + okey = key; + + const Fst &fst = far_reader->GetFst(); + if (i == 1 && initial_symbols && syms == 0 && fst.InputSymbols() != 0) + syms = fst.InputSymbols()->Copy(); + string str; + VLOG(2) << "Handling key: " << key; + StringPrinter string_printer( + token_type, syms ? syms : fst.InputSymbols()); + string_printer(fst, &str); + + if (entry_type == FET_LINE) { + if (print_key) + cout << key << FLAGS_far_field_separator[0]; + cout << str; + if (print_weight) + cout << FLAGS_far_field_separator[0] << ShortestDistance(fst); + cout << endl; + } else if (entry_type == FET_FILE) { + stringstream sstrm; + if (generate_filenames) { + sstrm.fill('0'); + sstrm << std::right << setw(generate_filenames) << i; + } else { + sstrm << key; + if (nrep > 0) + sstrm << "." << nrep; + } + + string filename; + filename = filename_prefix + sstrm.str() + filename_suffix; + + ofstream ostrm(filename.c_str()); + if (!ostrm) { + FSTERROR() << "FarPrintStrings: Can't open file:" << filename; + delete syms; + delete far_reader; + return; + } + ostrm << str; + if (token_type == StringPrinter::SYMBOL) + ostrm << "\n"; + } + } + delete syms; +} + + + +} // namespace fst + +#endif // FST_EXTENSIONS_FAR_PRINT_STRINGS_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/extensions/far/stlist.h b/kaldi_io/src/tools/openfst/include/fst/extensions/far/stlist.h new file mode 100644 index 0000000..ff3d98b --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/extensions/far/stlist.h @@ -0,0 +1,305 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: allauzen@google.com (Cyril Allauzen) +// +// \file +// A generic (string,type) list file format. +// +// This is a stripped-down version of STTable that does +// not support the Find() operation but that does support +// reading/writting from standard in/out. + +#ifndef FST_EXTENSIONS_FAR_STLIST_H_ +#define FST_EXTENSIONS_FAR_STLIST_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +using std::pair; using std::make_pair; +#include +using std::vector; + +namespace fst { + +static const int32 kSTListMagicNumber = 5656924; +static const int32 kSTListFileVersion = 1; + +// String-type list writing class for object of type 'T' using functor 'W' +// to write an object of type 'T' from a stream. 'W' must conform to the +// following interface: +// +// struct Writer { +// void operator()(ostream &, const T &) const; +// }; +// +template +class STListWriter { + public: + typedef T EntryType; + typedef W EntryWriter; + + explicit STListWriter(const string filename) + : stream_( + filename.empty() ? &cout : + new ofstream(filename.c_str(), ofstream::out | ofstream::binary)), + error_(false) { + WriteType(*stream_, kSTListMagicNumber); + WriteType(*stream_, kSTListFileVersion); + if (!stream_) { + FSTERROR() << "STListWriter::STListWriter: error writing to file: " + << filename; + error_ = true; + } + } + + static STListWriter *Create(const string &filename) { + return new STListWriter(filename); + } + + void Add(const string &key, const T &t) { + if (key == "") { + FSTERROR() << "STListWriter::Add: key empty: " << key; + error_ = true; + } else if (key < last_key_) { + FSTERROR() << "STListWriter::Add: key disorder: " << key; + error_ = true; + } + if (error_) return; + last_key_ = key; + WriteType(*stream_, key); + entry_writer_(*stream_, t); + } + + bool Error() const { return error_; } + + ~STListWriter() { + WriteType(*stream_, string()); + if (stream_ != &cout) + delete stream_; + } + + private: + EntryWriter entry_writer_; // Write functor for 'EntryType' + ostream *stream_; // Output stream + string last_key_; // Last key + bool error_; + + DISALLOW_COPY_AND_ASSIGN(STListWriter); +}; + + +// String-type list reading class for object of type 'T' using functor 'R' +// to read an object of type 'T' form a stream. 'R' must conform to the +// following interface: +// +// struct Reader { +// T *operator()(istream &) const; +// }; +// +template +class STListReader { + public: + typedef T EntryType; + typedef R EntryReader; + + explicit STListReader(const vector &filenames) + : sources_(filenames), entry_(0), error_(false) { + streams_.resize(filenames.size(), 0); + bool has_stdin = false; + for (size_t i = 0; i < filenames.size(); ++i) { + if (filenames[i].empty()) { + if (!has_stdin) { + streams_[i] = &cin; + sources_[i] = "stdin"; + has_stdin = true; + } else { + FSTERROR() << "STListReader::STListReader: stdin should only " + << "appear once in the input file list."; + error_ = true; + return; + } + } else { + streams_[i] = new ifstream( + filenames[i].c_str(), ifstream::in | ifstream::binary); + } + int32 magic_number = 0, file_version = 0; + ReadType(*streams_[i], &magic_number); + ReadType(*streams_[i], &file_version); + if (magic_number != kSTListMagicNumber) { + FSTERROR() << "STListReader::STListReader: wrong file type: " + << filenames[i]; + error_ = true; + return; + } + if (file_version != kSTListFileVersion) { + FSTERROR() << "STListReader::STListReader: wrong file version: " + << filenames[i]; + error_ = true; + return; + } + string key; + ReadType(*streams_[i], &key); + if (!key.empty()) + heap_.push(make_pair(key, i)); + if (!*streams_[i]) { + FSTERROR() << "STListReader: error reading file: " << sources_[i]; + error_ = true; + return; + } + } + if (heap_.empty()) return; + size_t current = heap_.top().second; + entry_ = entry_reader_(*streams_[current]); + if (!entry_ || !*streams_[current]) { + FSTERROR() << "STListReader: error reading entry for key: " + << heap_.top().first << ", file: " << sources_[current]; + error_ = true; + } + } + + ~STListReader() { + for (size_t i = 0; i < streams_.size(); ++i) { + if (streams_[i] != &cin) + delete streams_[i]; + } + if (entry_) + delete entry_; + } + + static STListReader *Open(const string &filename) { + vector filenames; + filenames.push_back(filename); + return new STListReader(filenames); + } + + static STListReader *Open(const vector &filenames) { + return new STListReader(filenames); + } + + void Reset() { + FSTERROR() + << "STListReader::Reset: stlist does not support reset operation"; + error_ = true; + } + + bool Find(const string &key) { + FSTERROR() + << "STListReader::Find: stlist does not support find operation"; + error_ = true; + return false; + } + + bool Done() const { + return error_ || heap_.empty(); + } + + void Next() { + if (error_) return; + size_t current = heap_.top().second; + string key; + heap_.pop(); + ReadType(*(streams_[current]), &key); + if (!*streams_[current]) { + FSTERROR() << "STListReader: error reading file: " + << sources_[current]; + error_ = true; + return; + } + if (!key.empty()) + heap_.push(make_pair(key, current)); + + if(!heap_.empty()) { + current = heap_.top().second; + if (entry_) + delete entry_; + entry_ = entry_reader_(*streams_[current]); + if (!entry_ || !*streams_[current]) { + FSTERROR() << "STListReader: error reading entry for key: " + << heap_.top().first << ", file: " << sources_[current]; + error_ = true; + } + } + } + + const string &GetKey() const { + return heap_.top().first; + } + + const EntryType &GetEntry() const { + return *entry_; + } + + bool Error() const { return error_; } + + private: + EntryReader entry_reader_; // Read functor for 'EntryType' + vector streams_; // Input streams + vector sources_; // and corresponding file names + priority_queue< + pair, vector >, + greater > > heap_; // (Key, stream id) heap + mutable EntryType *entry_; // Pointer to the currently read entry + bool error_; + + DISALLOW_COPY_AND_ASSIGN(STListReader); +}; + + +// String-type list header reading function template on the entry header +// type 'H' having a member function: +// Read(istream &strm, const string &filename); +// Checks that 'filename' is an STList and call the H::Read() on the last +// entry in the STList. +// Does not support reading from stdin. +template +bool ReadSTListHeader(const string &filename, H *header) { + if (filename.empty()) { + LOG(ERROR) << "ReadSTListHeader: reading header not supported on stdin"; + return false; + } + ifstream strm(filename.c_str(), ifstream::in | ifstream::binary); + int32 magic_number = 0, file_version = 0; + ReadType(strm, &magic_number); + ReadType(strm, &file_version); + if (magic_number != kSTListMagicNumber) { + LOG(ERROR) << "ReadSTListHeader: wrong file type: " << filename; + return false; + } + if (file_version != kSTListFileVersion) { + LOG(ERROR) << "ReadSTListHeader: wrong file version: " << filename; + return false; + } + string key; + ReadType(strm, &key); + header->Read(strm, filename + ":" + key); + if (!strm) { + LOG(ERROR) << "ReadSTListHeader: error reading file: " << filename; + return false; + } + return true; +} + +bool IsSTList(const string &filename); + +} // namespace fst + +#endif // FST_EXTENSIONS_FAR_STLIST_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/extensions/far/sttable.h b/kaldi_io/src/tools/openfst/include/fst/extensions/far/sttable.h new file mode 100644 index 0000000..3ce0a4b --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/extensions/far/sttable.h @@ -0,0 +1,371 @@ +// sttable.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: allauzen@google.com (Cyril Allauzen) +// +// \file +// A generic string-to-type table file format +// +// This is not meant as a generalization of SSTable. This is more of +// a simple replacement for SSTable in order to provide an open-source +// implementation of the FAR format for the external version of the +// FST Library. + +#ifndef FST_EXTENSIONS_FAR_STTABLE_H_ +#define FST_EXTENSIONS_FAR_STTABLE_H_ + +#include +#include +#include +#include +#include + +namespace fst { + +static const int32 kSTTableMagicNumber = 2125656924; +static const int32 kSTTableFileVersion = 1; + +// String-to-type table writing class for object of type 'T' using functor 'W' +// to write an object of type 'T' from a stream. 'W' must conform to the +// following interface: +// +// struct Writer { +// void operator()(ostream &, const T &) const; +// }; +// +template +class STTableWriter { + public: + typedef T EntryType; + typedef W EntryWriter; + + explicit STTableWriter(const string &filename) + : stream_(filename.c_str(), ofstream::out | ofstream::binary), + error_(false) { + WriteType(stream_, kSTTableMagicNumber); + WriteType(stream_, kSTTableFileVersion); + if (!stream_) { + FSTERROR() << "STTableWriter::STTableWriter: error writing to file: " + << filename; + error_=true; + } + } + + static STTableWriter *Create(const string &filename) { + if (filename.empty()) { + LOG(ERROR) << "STTableWriter: writing to standard out unsupported."; + return 0; + } + return new STTableWriter(filename); + } + + void Add(const string &key, const T &t) { + if (key == "") { + FSTERROR() << "STTableWriter::Add: key empty: " << key; + error_ = true; + } else if (key < last_key_) { + FSTERROR() << "STTableWriter::Add: key disorder: " << key; + error_ = true; + } + if (error_) return; + last_key_ = key; + positions_.push_back(stream_.tellp()); + WriteType(stream_, key); + entry_writer_(stream_, t); + } + + bool Error() const { return error_; } + + ~STTableWriter() { + WriteType(stream_, positions_); + WriteType(stream_, static_cast(positions_.size())); + } + + private: + EntryWriter entry_writer_; // Write functor for 'EntryType' + ofstream stream_; // Output stream + vector positions_; // Position in file of each key-entry pair + string last_key_; // Last key + bool error_; + + DISALLOW_COPY_AND_ASSIGN(STTableWriter); +}; + + +// String-to-type table reading class for object of type 'T' using functor 'R' +// to read an object of type 'T' form a stream. 'R' must conform to the +// following interface: +// +// struct Reader { +// T *operator()(istream &) const; +// }; +// +template +class STTableReader { + public: + typedef T EntryType; + typedef R EntryReader; + + explicit STTableReader(const vector &filenames) + : sources_(filenames), entry_(0), error_(false) { + compare_ = new Compare(&keys_); + keys_.resize(filenames.size()); + streams_.resize(filenames.size(), 0); + positions_.resize(filenames.size()); + for (size_t i = 0; i < filenames.size(); ++i) { + streams_[i] = new ifstream( + filenames[i].c_str(), ifstream::in | ifstream::binary); + int32 magic_number = 0, file_version = 0; + ReadType(*streams_[i], &magic_number); + ReadType(*streams_[i], &file_version); + if (magic_number != kSTTableMagicNumber) { + FSTERROR() << "STTableReader::STTableReader: wrong file type: " + << filenames[i]; + error_ = true; + return; + } + if (file_version != kSTTableFileVersion) { + FSTERROR() << "STTableReader::STTableReader: wrong file version: " + << filenames[i]; + error_ = true; + return; + } + int64 num_entries; + streams_[i]->seekg(-static_cast(sizeof(int64)), ios_base::end); + ReadType(*streams_[i], &num_entries); + streams_[i]->seekg(-static_cast(sizeof(int64)) * + (num_entries + 1), ios_base::end); + positions_[i].resize(num_entries); + for (size_t j = 0; (j < num_entries) && (*streams_[i]); ++j) + ReadType(*streams_[i], &(positions_[i][j])); + streams_[i]->seekg(positions_[i][0]); + if (!*streams_[i]) { + FSTERROR() << "STTableReader::STTableReader: error reading file: " + << filenames[i]; + error_ = true; + return; + } + + } + MakeHeap(); + } + + ~STTableReader() { + for (size_t i = 0; i < streams_.size(); ++i) + delete streams_[i]; + delete compare_; + if (entry_) + delete entry_; + } + + static STTableReader *Open(const string &filename) { + if (filename.empty()) { + LOG(ERROR) << "STTableReader: reading from standard in not supported"; + return 0; + } + vector filenames; + filenames.push_back(filename); + return new STTableReader(filenames); + } + + static STTableReader *Open(const vector &filenames) { + return new STTableReader(filenames); + } + + void Reset() { + if (error_) return; + for (size_t i = 0; i < streams_.size(); ++i) + streams_[i]->seekg(positions_[i].front()); + MakeHeap(); + } + + bool Find(const string &key) { + if (error_) return false; + for (size_t i = 0; i < streams_.size(); ++i) + LowerBound(i, key); + MakeHeap(); + return keys_[current_] == key; + } + + bool Done() const { return error_ || heap_.empty(); } + + void Next() { + if (error_) return; + if (streams_[current_]->tellg() <= positions_[current_].back()) { + ReadType(*(streams_[current_]), &(keys_[current_])); + if (!*streams_[current_]) { + FSTERROR() << "STTableReader: error reading file: " + << sources_[current_]; + error_ = true; + return; + } + push_heap(heap_.begin(), heap_.end(), *compare_); + } else { + heap_.pop_back(); + } + if (!heap_.empty()) + PopHeap(); + } + + const string &GetKey() const { + return keys_[current_]; + } + + const EntryType &GetEntry() const { + return *entry_; + } + + bool Error() const { return error_; } + + private: + // Comparison functor used to compare stream IDs in the heap + struct Compare { + Compare(const vector *keys) : keys_(keys) {} + + bool operator()(size_t i, size_t j) const { + return (*keys_)[i] > (*keys_)[j]; + }; + + private: + const vector *keys_; + }; + + // Position the stream with ID 'id' at the position corresponding + // to the lower bound for key 'find_key' + void LowerBound(size_t id, const string &find_key) { + ifstream *strm = streams_[id]; + const vector &positions = positions_[id]; + size_t low = 0, high = positions.size() - 1; + + while (low < high) { + size_t mid = (low + high)/2; + strm->seekg(positions[mid]); + string key; + ReadType(*strm, &key); + if (key > find_key) { + high = mid; + } else if (key < find_key) { + low = mid + 1; + } else { + for (size_t i = mid; i > low; --i) { + strm->seekg(positions[i - 1]); + ReadType(*strm, &key); + if (key != find_key) { + strm->seekg(positions[i]); + return; + } + } + strm->seekg(positions[low]); + return; + } + } + strm->seekg(positions[low]); + } + + // Add all streams to the heap + void MakeHeap() { + heap_.clear(); + for (size_t i = 0; i < streams_.size(); ++i) { + ReadType(*streams_[i], &(keys_[i])); + if (!*streams_[i]) { + FSTERROR() << "STTableReader: error reading file: " << sources_[i]; + error_ = true; + return; + } + heap_.push_back(i); + } + make_heap(heap_.begin(), heap_.end(), *compare_); + PopHeap(); + } + + // Position the stream with the lowest key at the top + // of the heap, set 'current_' to the ID of that stream + // and read the current entry from that stream + void PopHeap() { + pop_heap(heap_.begin(), heap_.end(), *compare_); + current_ = heap_.back(); + if (entry_) + delete entry_; + entry_ = entry_reader_(*streams_[current_]); + if (!entry_) + error_ = true; + if (!*streams_[current_]) { + FSTERROR() << "STTableReader: error reading entry for key: " + << keys_[current_] << ", file: " << sources_[current_]; + error_ = true; + } + } + + + EntryReader entry_reader_; // Read functor for 'EntryType' + vector streams_; // Input streams + vector sources_; // and corresponding file names + vector > positions_; // Index of positions for each stream + vector keys_; // Lowest unread key for each stream + vector heap_; // Heap containing ID of streams with unread keys + int64 current_; // Id of current stream to be read + Compare *compare_; // Functor comparing stream IDs for the heap + mutable EntryType *entry_; // Pointer to the currently read entry + bool error_; + + DISALLOW_COPY_AND_ASSIGN(STTableReader); +}; + + +// String-to-type table header reading function template on the entry header +// type 'H' having a member function: +// Read(istream &strm, const string &filename); +// Checks that 'filename' is an STTable and call the H::Read() on the last +// entry in the STTable. +template +bool ReadSTTableHeader(const string &filename, H *header) { + ifstream strm(filename.c_str(), ifstream::in | ifstream::binary); + int32 magic_number = 0, file_version = 0; + ReadType(strm, &magic_number); + ReadType(strm, &file_version); + if (magic_number != kSTTableMagicNumber) { + LOG(ERROR) << "ReadSTTableHeader: wrong file type: " << filename; + return false; + } + if (file_version != kSTTableFileVersion) { + LOG(ERROR) << "ReadSTTableHeader: wrong file version: " << filename; + return false; + } + int64 i = -1; + strm.seekg(-static_cast(sizeof(int64)), ios_base::end); + ReadType(strm, &i); // Read number of entries + if (!strm) { + LOG(ERROR) << "ReadSTTableHeader: error reading file: " << filename; + return false; + } + if (i == 0) return true; // No entry header to read + strm.seekg(-2 * static_cast(sizeof(int64)), ios_base::end); + ReadType(strm, &i); // Read position for last entry in file + strm.seekg(i); + string key; + ReadType(strm, &key); + header->Read(strm, filename + ":" + key); + if (!strm) { + LOG(ERROR) << "ReadSTTableHeader: error reading file: " << filename; + return false; + } + return true; +} + +bool IsSTTable(const string &filename); + +} // namespace fst + +#endif // FST_EXTENSIONS_FAR_STTABLE_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/extensions/ngram/bitmap-index.h b/kaldi_io/src/tools/openfst/include/fst/extensions/ngram/bitmap-index.h new file mode 100644 index 0000000..f5a5ba7 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/extensions/ngram/bitmap-index.h @@ -0,0 +1,183 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: sorenj@google.com (Jeffrey Sorensen) + +#ifndef FST_EXTENSIONS_NGRAM_BITMAP_INDEX_H_ +#define FST_EXTENSIONS_NGRAM_BITMAP_INDEX_H_ + +#include +using std::vector; + +#include + +// This class is a bitstring storage class with an index that allows +// seeking to the Nth set or clear bit in time O(Log(N)) where N is +// the length of the bit vector. In addition, it allows counting set or +// clear bits over ranges in constant time. +// +// This is accomplished by maintaining an "secondary" index of limited +// size in bits that maintains a running count of the number of bits set +// in each block of bitmap data. A block is defined as the number of +// uint64 values that can fit in the secondary index before an overflow +// occurs. +// +// To handle overflows, a "primary" index containing a running count of +// bits set in each block is created using the type uint64. + +namespace fst { + +class BitmapIndex { + public: + static size_t StorageSize(size_t size) { + return ((size + kStorageBlockMask) >> kStorageLogBitSize); + } + + BitmapIndex() : bits_(NULL), size_(0) { } + + bool Get(size_t index) const { + return (bits_[index >> kStorageLogBitSize] & + (kOne << (index & kStorageBlockMask))) != 0; + } + + static void Set(uint64* bits, size_t index) { + bits[index >> kStorageLogBitSize] |= (kOne << (index & kStorageBlockMask)); + } + + static void Clear(uint64* bits, size_t index) { + bits[index >> kStorageLogBitSize] &= ~(kOne << (index & kStorageBlockMask)); + } + + size_t Bits() const { + return size_; + } + + size_t ArraySize() const { + return StorageSize(size_); + } + + // Returns the number of one bits in the bitmap + size_t GetOnesCount() const { + return primary_index_[primary_index_size() - 1]; + } + + // Returns the number of one bits in positions 0 to limit - 1. + // REQUIRES: limit <= Bits() + size_t Rank1(size_t end) const; + + // Returns the number of one bits in the range start to end - 1. + // REQUIRES: limit <= Bits() + size_t GetOnesCountInRange(size_t start, size_t end) const { + return Rank1(end) - Rank1(start); + } + + // Returns the number of zero bits in positions 0 to limit - 1. + // REQUIRES: limit <= Bits() + size_t Rank0(size_t end) const { + return end - Rank1(end); + } + + // Returns the number of zero bits in the range start to end - 1. + // REQUIRES: limit <= Bits() + size_t GetZeroesCountInRange(size_t start, size_t end) const { + return end - start - GetOnesCountInRange(start, end); + } + + // Return true if any bit between begin inclusive and end exclusive + // is set. 0 <= begin <= end <= Bits() is required. + // + bool TestRange(size_t start, size_t end) const { + return Rank1(end) > Rank1(start); + } + + // Returns the offset to the nth set bit (zero based) + // or Bits() if index >= number of ones + size_t Select1(size_t bit_index) const; + + // Returns the offset to the nth clear bit (zero based) + // or Bits() if index > number of + size_t Select0(size_t bit_index) const; + + // Rebuilds from index for the associated Bitmap, should be called + // whenever changes have been made to the Bitmap or else behavior + // of the indexed bitmap methods will be undefined. + void BuildIndex(const uint64 *bits, size_t size); + + // the secondary index accumulates counts until it can possibly overflow + // this constant computes the number of uint64 units that can fit into + // units the size of uint16. + static const uint64 kOne = 1; + static const uint32 kStorageBitSize = 64; + static const uint32 kStorageLogBitSize = 6; + static const uint32 kSecondaryBlockSize = ((1 << 16) - 1) + >> kStorageLogBitSize; + + private: + static const uint32 kStorageBlockMask = kStorageBitSize - 1; + + // returns, from the index, the count of ones up to array_index + size_t get_index_ones_count(size_t array_index) const; + + // because the indexes, both primary and secondary, contain a running + // count of the population of one bits contained in [0,i), there is + // no reason to have an element in the zeroth position as this value would + // necessarily be zero. (The bits are indexed in a zero based way.) Thus + // we don't store the 0th element in either index. Both of the following + // functions, if greater than 0, must be decremented by one before retreiving + // the value from the corresponding array. + // returns the 1 + the block that contains the bitindex in question + // the inverted version works the same but looks for zeros using an inverted + // view of the index + size_t find_primary_block(size_t bit_index) const; + + size_t find_inverted_primary_block(size_t bit_index) const; + + // similarly, the secondary index (which resets its count to zero at + // the end of every kSecondaryBlockSize entries) does not store the element + // at 0. Note that the rem_bit_index parameter is the number of bits + // within the secondary block, after the bits accounted for by the primary + // block have been removed (i.e. the remaining bits) And, because we + // reset to zero with each new block, there is no need to store those + // actual zeros. + // returns 1 + the secondary block that contains the bitindex in question + size_t find_secondary_block(size_t block, size_t rem_bit_index) const; + + size_t find_inverted_secondary_block(size_t block, size_t rem_bit_index) + const; + + // We create a primary index based upon the number of secondary index + // blocks. The primary index uses fields wide enough to accomodate any + // index of the bitarray so cannot overflow + // The primary index is the actual running + // count of one bits set for all blocks (and, thus, all uint64s). + size_t primary_index_size() const { + return (ArraySize() + kSecondaryBlockSize - 1) / kSecondaryBlockSize; + } + + const uint64* bits_; + size_t size_; + + // The primary index contains the running popcount of all blocks + // which means the nth value contains the popcounts of + // [0,n*kSecondaryBlockSize], however, the 0th element is omitted. + vector primary_index_; + // The secondary index contains the running popcount of the associated + // bitmap. It is the same length (in units of uint16) as the + // bitmap's map is in units of uint64s. + vector secondary_index_; +}; + +} // end namespace fst + +#endif // FST_EXTENSIONS_NGRAM_BITMAP_INDEX_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/extensions/ngram/ngram-fst.h b/kaldi_io/src/tools/openfst/include/fst/extensions/ngram/ngram-fst.h new file mode 100644 index 0000000..d113fb3 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/extensions/ngram/ngram-fst.h @@ -0,0 +1,934 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: sorenj@google.com (Jeffrey Sorensen) +// +#ifndef FST_EXTENSIONS_NGRAM_NGRAM_FST_H_ +#define FST_EXTENSIONS_NGRAM_NGRAM_FST_H_ + +#include +#include +#include +#include +#include +using std::vector; + +#include +#include +#include +#include + +// NgramFst implements a n-gram language model based upon the LOUDS data +// structure. Please refer to "Unary Data Strucutres for Language Models" +// http://research.google.com/pubs/archive/37218.pdf + +namespace fst { +template class NGramFst; +template class NGramFstMatcher; + +// Instance data containing mutable state for bookkeeping repeated access to +// the same state. +template +struct NGramFstInst { + typedef typename A::Label Label; + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + StateId state_; + size_t num_futures_; + size_t offset_; + size_t node_; + StateId node_state_; + vector { + using FstImpl::SetInputSymbols; + using FstImpl::SetOutputSymbols; + using FstImpl::SetType; + using FstImpl::WriteHeader; + + friend class ArcIterator >; + friend class NGramFstMatcher; + + public: + using FstImpl::InputSymbols; + using FstImpl::SetProperties; + using FstImpl::Properties; + + typedef A Arc; + typedef typename A::Label Label; + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + NGramFstImpl() : data_region_(0), data_(0), owned_(false) { + SetType("ngram"); + SetInputSymbols(NULL); + SetOutputSymbols(NULL); + SetProperties(kStaticProperties); + } + + NGramFstImpl(const Fst &fst, vector* order_out); + + ~NGramFstImpl() { + if (owned_) { + delete [] data_; + } + delete data_region_; + } + + static NGramFstImpl* Read(istream &strm, // NOLINT + const FstReadOptions &opts) { + NGramFstImpl* impl = new NGramFstImpl(); + FstHeader hdr; + if (!impl->ReadHeader(strm, opts, kMinFileVersion, &hdr)) return 0; + uint64 num_states, num_futures, num_final; + const size_t offset = sizeof(num_states) + sizeof(num_futures) + + sizeof(num_final); + // Peek at num_states and num_futures to see how much more needs to be read. + strm.read(reinterpret_cast(&num_states), sizeof(num_states)); + strm.read(reinterpret_cast(&num_futures), sizeof(num_futures)); + strm.read(reinterpret_cast(&num_final), sizeof(num_final)); + size_t size = Storage(num_states, num_futures, num_final); + MappedFile *data_region = MappedFile::Allocate(size); + char *data = reinterpret_cast(data_region->mutable_data()); + // Copy num_states, num_futures and num_final back into data. + memcpy(data, reinterpret_cast(&num_states), sizeof(num_states)); + memcpy(data + sizeof(num_states), reinterpret_cast(&num_futures), + sizeof(num_futures)); + memcpy(data + sizeof(num_states) + sizeof(num_futures), + reinterpret_cast(&num_final), sizeof(num_final)); + strm.read(data + offset, size - offset); + if (!strm) { + delete impl; + return NULL; + } + impl->Init(data, false, data_region); + return impl; + } + + bool Write(ostream &strm, // NOLINT + const FstWriteOptions &opts) const { + FstHeader hdr; + hdr.SetStart(Start()); + hdr.SetNumStates(num_states_); + WriteHeader(strm, opts, kFileVersion, &hdr); + strm.write(data_, Storage(num_states_, num_futures_, num_final_)); + return strm; + } + + StateId Start() const { + return 1; + } + + Weight Final(StateId state) const { + if (final_index_.Get(state)) { + return final_probs_[final_index_.Rank1(state)]; + } else { + return Weight::Zero(); + } + } + + size_t NumArcs(StateId state, NGramFstInst *inst = NULL) const { + if (inst == NULL) { + const size_t next_zero = future_index_.Select0(state + 1); + const size_t this_zero = future_index_.Select0(state); + return next_zero - this_zero - 1; + } + SetInstFuture(state, inst); + return inst->num_futures_ + ((state == 0) ? 0 : 1); + } + + size_t NumInputEpsilons(StateId state) const { + // State 0 has no parent, thus no backoff. + if (state == 0) return 0; + return 1; + } + + size_t NumOutputEpsilons(StateId state) const { + return NumInputEpsilons(state); + } + + StateId NumStates() const { + return num_states_; + } + + void InitStateIterator(StateIteratorData* data) const { + data->base = 0; + data->nstates = num_states_; + } + + static size_t Storage(uint64 num_states, uint64 num_futures, + uint64 num_final) { + uint64 b64; + Weight weight; + Label label; + size_t offset = sizeof(num_states) + sizeof(num_futures) + + sizeof(num_final); + offset += sizeof(b64) * ( + BitmapIndex::StorageSize(num_states * 2 + 1) + + BitmapIndex::StorageSize(num_futures + num_states + 1) + + BitmapIndex::StorageSize(num_states)); + offset += (num_states + 1) * sizeof(label) + num_futures * sizeof(label); + // Pad for alignemnt, see + // http://en.wikipedia.org/wiki/Data_structure_alignment#Computing_padding + offset = (offset + sizeof(weight) - 1) & ~(sizeof(weight) - 1); + offset += (num_states + 1) * sizeof(weight) + num_final * sizeof(weight) + + (num_futures + 1) * sizeof(weight); + return offset; + } + + void SetInstFuture(StateId state, NGramFstInst *inst) const { + if (inst->state_ != state) { + inst->state_ = state; + const size_t next_zero = future_index_.Select0(state + 1); + const size_t this_zero = future_index_.Select0(state); + inst->num_futures_ = next_zero - this_zero - 1; + inst->offset_ = future_index_.Rank1(future_index_.Select0(state) + 1); + } + } + + void SetInstNode(NGramFstInst *inst) const { + if (inst->node_state_ != inst->state_) { + inst->node_state_ = inst->state_; + inst->node_ = context_index_.Select1(inst->state_); + } + } + + void SetInstContext(NGramFstInst *inst) const { + SetInstNode(inst); + if (inst->context_state_ != inst->state_) { + inst->context_state_ = inst->state_; + inst->context_.clear(); + size_t node = inst->node_; + while (node != 0) { + inst->context_.push_back(context_words_[context_index_.Rank1(node)]); + node = context_index_.Select1(context_index_.Rank0(node) - 1); + } + } + } + + // Access to the underlying representation + const char* GetData(size_t* data_size) const { + *data_size = Storage(num_states_, num_futures_, num_final_); + return data_; + } + + void Init(const char* data, bool owned, MappedFile *file = 0); + + const vector *inst) const { + SetInstFuture(s, inst); + SetInstContext(inst); + return inst->context_; + } + + private: + StateId Transition(const vector &); // Disallow +}; + +template +NGramFstImpl::NGramFstImpl(const Fst &fst, vector* order_out) + : data_region_(0), data_(0), owned_(false) { + typedef A Arc; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + typedef typename Arc::StateId StateId; + SetType("ngram"); + SetInputSymbols(fst.InputSymbols()); + SetOutputSymbols(fst.OutputSymbols()); + SetProperties(kStaticProperties); + + // Check basic requirements for an OpenGRM language model Fst. + int64 props = kAcceptor | kIDeterministic | kIEpsilons | kILabelSorted; + if (fst.Properties(props, true) != props) { + FSTERROR() << "NGramFst only accepts OpenGRM langauge models as input"; + SetProperties(kError, kError); + return; + } + + int64 num_states = CountStates(fst); + Label* context = new Label[num_states]; + + // Find the unigram state by starting from the start state, following + // epsilons. + StateId unigram = fst.Start(); + while (1) { + if (unigram == kNoStateId) { + FSTERROR() << "Could not identify unigram state."; + SetProperties(kError, kError); + return; + } + ArcIterator > aiter(fst, unigram); + if (aiter.Done()) { + LOG(WARNING) << "Unigram state " << unigram << " has no arcs."; + break; + } + if (aiter.Value().ilabel != 0) break; + unigram = aiter.Value().nextstate; + } + + // Each state's context is determined by the subtree it is under from the + // unigram state. + queue > label_queue; + vector visited(num_states); + // Force an epsilon link to the start state. + label_queue.push(make_pair(fst.Start(), 0)); + for (ArcIterator > aiter(fst, unigram); + !aiter.Done(); aiter.Next()) { + label_queue.push(make_pair(aiter.Value().nextstate, aiter.Value().ilabel)); + } + // investigate states in breadth first fashion to assign context words. + while (!label_queue.empty()) { + pair &now = label_queue.front(); + if (!visited[now.first]) { + context[now.first] = now.second; + visited[now.first] = true; + for (ArcIterator > aiter(fst, now.first); + !aiter.Done(); aiter.Next()) { + const Arc &arc = aiter.Value(); + if (arc.ilabel != 0) { + label_queue.push(make_pair(arc.nextstate, now.second)); + } + } + } + label_queue.pop(); + } + visited.clear(); + + // The arc from the start state should be assigned an epsilon to put it + // in front of the all other labels (which makes Start state 1 after + // unigram which is state 0). + context[fst.Start()] = 0; + + // Build the tree of contexts fst by reversing the epsilon arcs from fst. + VectorFst context_fst; + uint64 num_final = 0; + for (int i = 0; i < num_states; ++i) { + if (fst.Final(i) != Weight::Zero()) { + ++num_final; + } + context_fst.SetFinal(context_fst.AddState(), fst.Final(i)); + } + context_fst.SetStart(unigram); + context_fst.SetInputSymbols(fst.InputSymbols()); + context_fst.SetOutputSymbols(fst.OutputSymbols()); + int64 num_context_arcs = 0; + int64 num_futures = 0; + for (StateIterator > siter(fst); !siter.Done(); siter.Next()) { + const StateId &state = siter.Value(); + num_futures += fst.NumArcs(state) - fst.NumInputEpsilons(state); + ArcIterator > aiter(fst, state); + if (!aiter.Done()) { + const Arc &arc = aiter.Value(); + // this arc goes from state to arc.nextstate, so create an arc from + // arc.nextstate to state to reverse it. + if (arc.ilabel == 0) { + context_fst.AddArc(arc.nextstate, Arc(context[state], context[state], + arc.weight, state)); + num_context_arcs++; + } + } + } + if (num_context_arcs != context_fst.NumStates() - 1) { + FSTERROR() << "Number of contexts arcs != number of states - 1"; + SetProperties(kError, kError); + return; + } + if (context_fst.NumStates() != num_states) { + FSTERROR() << "Number of contexts != number of states"; + SetProperties(kError, kError); + return; + } + int64 context_props = context_fst.Properties(kIDeterministic | + kILabelSorted, true); + if (!(context_props & kIDeterministic)) { + FSTERROR() << "Input fst is not structured properly"; + SetProperties(kError, kError); + return; + } + if (!(context_props & kILabelSorted)) { + ArcSort(&context_fst, ILabelCompare()); + } + + delete [] context; + + uint64 b64; + Weight weight; + Label label = kNoLabel; + const size_t storage = Storage(num_states, num_futures, num_final); + MappedFile *data_region = MappedFile::Allocate(storage); + char *data = reinterpret_cast(data_region->mutable_data()); + memset(data, 0, storage); + size_t offset = 0; + memcpy(data + offset, reinterpret_cast(&num_states), + sizeof(num_states)); + offset += sizeof(num_states); + memcpy(data + offset, reinterpret_cast(&num_futures), + sizeof(num_futures)); + offset += sizeof(num_futures); + memcpy(data + offset, reinterpret_cast(&num_final), + sizeof(num_final)); + offset += sizeof(num_final); + uint64* context_bits = reinterpret_cast(data + offset); + offset += BitmapIndex::StorageSize(num_states * 2 + 1) * sizeof(b64); + uint64* future_bits = reinterpret_cast(data + offset); + offset += + BitmapIndex::StorageSize(num_futures + num_states + 1) * sizeof(b64); + uint64* final_bits = reinterpret_cast(data + offset); + offset += BitmapIndex::StorageSize(num_states) * sizeof(b64); + Label* context_words = reinterpret_cast(data + offset); + offset += (num_states + 1) * sizeof(label); + Label* future_words = reinterpret_cast(data + offset); + offset += num_futures * sizeof(label); + offset = (offset + sizeof(weight) - 1) & ~(sizeof(weight) - 1); + Weight* backoff = reinterpret_cast(data + offset); + offset += (num_states + 1) * sizeof(weight); + Weight* final_probs = reinterpret_cast(data + offset); + offset += num_final * sizeof(weight); + Weight* future_probs = reinterpret_cast(data + offset); + int64 context_arc = 0, future_arc = 0, context_bit = 0, future_bit = 0, + final_bit = 0; + + // pseudo-root bits + BitmapIndex::Set(context_bits, context_bit++); + ++context_bit; + context_words[context_arc] = label; + backoff[context_arc] = Weight::Zero(); + context_arc++; + + ++future_bit; + if (order_out) { + order_out->clear(); + order_out->resize(num_states); + } + + queue context_q; + context_q.push(context_fst.Start()); + StateId state_number = 0; + while (!context_q.empty()) { + const StateId &state = context_q.front(); + if (order_out) { + (*order_out)[state] = state_number; + } + + const Weight &final = context_fst.Final(state); + if (final != Weight::Zero()) { + BitmapIndex::Set(final_bits, state_number); + final_probs[final_bit] = final; + ++final_bit; + } + + for (ArcIterator > aiter(context_fst, state); + !aiter.Done(); aiter.Next()) { + const Arc &arc = aiter.Value(); + context_words[context_arc] = arc.ilabel; + backoff[context_arc] = arc.weight; + ++context_arc; + BitmapIndex::Set(context_bits, context_bit++); + context_q.push(arc.nextstate); + } + ++context_bit; + + for (ArcIterator > aiter(fst, state); !aiter.Done(); aiter.Next()) { + const Arc &arc = aiter.Value(); + if (arc.ilabel != 0) { + future_words[future_arc] = arc.ilabel; + future_probs[future_arc] = arc.weight; + ++future_arc; + BitmapIndex::Set(future_bits, future_bit++); + } + } + ++future_bit; + ++state_number; + context_q.pop(); + } + + if ((state_number != num_states) || + (context_bit != num_states * 2 + 1) || + (context_arc != num_states) || + (future_arc != num_futures) || + (future_bit != num_futures + num_states + 1) || + (final_bit != num_final)) { + FSTERROR() << "Structure problems detected during construction"; + SetProperties(kError, kError); + return; + } + + Init(data, false, data_region); +} + +template +inline void NGramFstImpl::Init(const char* data, bool owned, + MappedFile *data_region) { + if (owned_) { + delete [] data_; + } + delete data_region_; + data_region_ = data_region; + owned_ = owned; + data_ = data; + size_t offset = 0; + num_states_ = *(reinterpret_cast(data_ + offset)); + offset += sizeof(num_states_); + num_futures_ = *(reinterpret_cast(data_ + offset)); + offset += sizeof(num_futures_); + num_final_ = *(reinterpret_cast(data_ + offset)); + offset += sizeof(num_final_); + uint64 bits; + size_t context_bits = num_states_ * 2 + 1; + size_t future_bits = num_futures_ + num_states_ + 1; + context_ = reinterpret_cast(data_ + offset); + offset += BitmapIndex::StorageSize(context_bits) * sizeof(bits); + future_ = reinterpret_cast(data_ + offset); + offset += BitmapIndex::StorageSize(future_bits) * sizeof(bits); + final_ = reinterpret_cast(data_ + offset); + offset += BitmapIndex::StorageSize(num_states_) * sizeof(bits); + context_words_ = reinterpret_cast(data_ + offset); + offset += (num_states_ + 1) * sizeof(*context_words_); + future_words_ = reinterpret_cast(data_ + offset); + offset += num_futures_ * sizeof(*future_words_); + offset = (offset + sizeof(*backoff_) - 1) & ~(sizeof(*backoff_) - 1); + backoff_ = reinterpret_cast(data_ + offset); + offset += (num_states_ + 1) * sizeof(*backoff_); + final_probs_ = reinterpret_cast(data_ + offset); + offset += num_final_ * sizeof(*final_probs_); + future_probs_ = reinterpret_cast(data_ + offset); + + context_index_.BuildIndex(context_, context_bits); + future_index_.BuildIndex(future_, future_bits); + final_index_.BuildIndex(final_, num_states_); + + const size_t node_rank = context_index_.Rank1(0); + root_first_child_ = context_index_.Select0(node_rank) + 1; + if (context_index_.Get(root_first_child_) == false) { + FSTERROR() << "Missing unigrams"; + SetProperties(kError, kError); + return; + } + const size_t last_child = context_index_.Select0(node_rank + 1) - 1; + root_num_children_ = last_child - root_first_child_ + 1; + root_children_ = context_words_ + context_index_.Rank1(root_first_child_); +} + +template +inline typename A::StateId NGramFstImpl::Transition( + const vector; + + public: + typedef A Arc; + typedef typename A::StateId StateId; + typedef typename A::Label Label; + typedef typename A::Weight Weight; + typedef NGramFstImpl Impl; + + explicit NGramFst(const Fst &dst) + : ImplToExpandedFst(new Impl(dst, NULL)) {} + + NGramFst(const Fst &fst, vector* order_out) + : ImplToExpandedFst(new Impl(fst, order_out)) {} + + // Because the NGramFstImpl is a const stateless data structure, there + // is never a need to do anything beside copy the reference. + NGramFst(const NGramFst &fst, bool safe = false) + : ImplToExpandedFst(fst, false) {} + + NGramFst() : ImplToExpandedFst(new Impl()) {} + + // Non-standard constructor to initialize NGramFst directly from data. + NGramFst(const char* data, bool owned) : ImplToExpandedFst(new Impl()) { + GetImpl()->Init(data, owned, NULL); + } + + // Get method that gets the data associated with Init(). + const char* GetData(size_t* data_size) const { + return GetImpl()->GetData(data_size); + } + + const vector* Copy(bool safe = false) const { + return new NGramFst(*this, safe); + } + + static NGramFst* Read(istream &strm, const FstReadOptions &opts) { + Impl* impl = Impl::Read(strm, opts); + return impl ? new NGramFst(impl) : 0; + } + + static NGramFst* Read(const string &filename) { + if (!filename.empty()) { + ifstream strm(filename.c_str(), ifstream::in | ifstream::binary); + if (!strm) { + LOG(ERROR) << "NGramFst::Read: Can't open file: " << filename; + return 0; + } + return Read(strm, FstReadOptions(filename)); + } else { + return Read(cin, FstReadOptions("standard input")); + } + } + + virtual bool Write(ostream &strm, const FstWriteOptions &opts) const { + return GetImpl()->Write(strm, opts); + } + + virtual bool Write(const string &filename) const { + return Fst::WriteFile(filename); + } + + virtual inline void InitStateIterator(StateIteratorData* data) const { + GetImpl()->InitStateIterator(data); + } + + virtual inline void InitArcIterator( + StateId s, ArcIteratorData* data) const; + + virtual MatcherBase* InitMatcher(MatchType match_type) const { + return new NGramFstMatcher(*this, match_type); + } + + private: + explicit NGramFst(Impl* impl) : ImplToExpandedFst(impl) {} + + Impl* GetImpl() const { + return + ImplToExpandedFst >::GetImpl(); + } + + void SetImpl(Impl* impl, bool own_impl = true) { + ImplToExpandedFst >::SetImpl(impl, own_impl); + } + + mutable NGramFstInst inst_; +}; + +template inline void +NGramFst::InitArcIterator(StateId s, ArcIteratorData* data) const { + GetImpl()->SetInstFuture(s, &inst_); + GetImpl()->SetInstNode(&inst_); + data->base = new ArcIterator >(*this, s); +} + +/*****************************************************************************/ +template +class NGramFstMatcher : public MatcherBase { + public: + typedef A Arc; + typedef typename A::Label Label; + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + NGramFstMatcher(const NGramFst &fst, MatchType match_type) + : fst_(fst), inst_(fst.inst_), match_type_(match_type), + current_loop_(false), + loop_(kNoLabel, 0, A::Weight::One(), kNoStateId) { + if (match_type_ == MATCH_OUTPUT) { + swap(loop_.ilabel, loop_.olabel); + } + } + + NGramFstMatcher(const NGramFstMatcher &matcher, bool safe = false) + : fst_(matcher.fst_), inst_(matcher.inst_), + match_type_(matcher.match_type_), current_loop_(false), + loop_(kNoLabel, 0, A::Weight::One(), kNoStateId) { + if (match_type_ == MATCH_OUTPUT) { + swap(loop_.ilabel, loop_.olabel); + } + } + + virtual NGramFstMatcher* Copy(bool safe = false) const { + return new NGramFstMatcher(*this, safe); + } + + virtual MatchType Type(bool test) const { + return match_type_; + } + + virtual const Fst &GetFst() const { + return fst_; + } + + virtual uint64 Properties(uint64 props) const { + return props; + } + + private: + virtual void SetState_(StateId s) { + fst_.GetImpl()->SetInstFuture(s, &inst_); + current_loop_ = false; + } + + virtual bool Find_(Label label) { + const Label nolabel = kNoLabel; + done_ = true; + if (label == 0 || label == nolabel) { + if (label == 0) { + current_loop_ = true; + loop_.nextstate = inst_.state_; + } + // The unigram state has no epsilon arc. + if (inst_.state_ != 0) { + arc_.ilabel = arc_.olabel = 0; + fst_.GetImpl()->SetInstNode(&inst_); + arc_.nextstate = fst_.GetImpl()->context_index_.Rank1( + fst_.GetImpl()->context_index_.Select1( + fst_.GetImpl()->context_index_.Rank0(inst_.node_) - 1)); + arc_.weight = fst_.GetImpl()->backoff_[inst_.state_]; + done_ = false; + } + } else { + const Label *start = fst_.GetImpl()->future_words_ + inst_.offset_; + const Label *end = start + inst_.num_futures_; + const Label* search = lower_bound(start, end, label); + if (search != end && *search == label) { + size_t state = search - start; + arc_.ilabel = arc_.olabel = label; + arc_.weight = fst_.GetImpl()->future_probs_[inst_.offset_ + state]; + fst_.GetImpl()->SetInstContext(&inst_); + arc_.nextstate = fst_.GetImpl()->Transition(inst_.context_, label); + done_ = false; + } + } + return !Done_(); + } + + virtual bool Done_() const { + return !current_loop_ && done_; + } + + virtual const Arc& Value_() const { + return (current_loop_) ? loop_ : arc_; + } + + virtual void Next_() { + if (current_loop_) { + current_loop_ = false; + } else { + done_ = true; + } + } + + const NGramFst& fst_; + NGramFstInst inst_; + MatchType match_type_; // Supplied by caller + bool done_; + Arc arc_; + bool current_loop_; // Current arc is the implicit loop + Arc loop_; +}; + +/*****************************************************************************/ +template +class ArcIterator > : public ArcIteratorBase { + public: + typedef A Arc; + typedef typename A::Label Label; + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + ArcIterator(const NGramFst &fst, StateId state) + : lazy_(~0), impl_(fst.GetImpl()), i_(0), flags_(kArcValueFlags) { + inst_ = fst.inst_; + impl_->SetInstFuture(state, &inst_); + impl_->SetInstNode(&inst_); + } + + bool Done() const { + return i_ >= ((inst_.node_ == 0) ? inst_.num_futures_ : + inst_.num_futures_ + 1); + } + + const Arc &Value() const { + bool eps = (inst_.node_ != 0 && i_ == 0); + StateId state = (inst_.node_ == 0) ? i_ : i_ - 1; + if (flags_ & lazy_ & (kArcILabelValue | kArcOLabelValue)) { + arc_.ilabel = + arc_.olabel = eps ? 0 : impl_->future_words_[inst_.offset_ + state]; + lazy_ &= ~(kArcILabelValue | kArcOLabelValue); + } + if (flags_ & lazy_ & kArcNextStateValue) { + if (eps) { + arc_.nextstate = impl_->context_index_.Rank1( + impl_->context_index_.Select1( + impl_->context_index_.Rank0(inst_.node_) - 1)); + } else { + if (lazy_ & kArcNextStateValue) { + impl_->SetInstContext(&inst_); // first time only. + } + arc_.nextstate = + impl_->Transition(inst_.context_, + impl_->future_words_[inst_.offset_ + state]); + } + lazy_ &= ~kArcNextStateValue; + } + if (flags_ & lazy_ & kArcWeightValue) { + arc_.weight = eps ? impl_->backoff_[inst_.state_] : + impl_->future_probs_[inst_.offset_ + state]; + lazy_ &= ~kArcWeightValue; + } + return arc_; + } + + void Next() { + ++i_; + lazy_ = ~0; + } + + size_t Position() const { return i_; } + + void Reset() { + i_ = 0; + lazy_ = ~0; + } + + void Seek(size_t a) { + if (i_ != a) { + i_ = a; + lazy_ = ~0; + } + } + + uint32 Flags() const { + return flags_; + } + + void SetFlags(uint32 f, uint32 m) { + flags_ &= ~m; + flags_ |= (f & kArcValueFlags); + } + + private: + virtual bool Done_() const { return Done(); } + virtual const Arc& Value_() const { return Value(); } + virtual void Next_() { Next(); } + virtual size_t Position_() const { return Position(); } + virtual void Reset_() { Reset(); } + virtual void Seek_(size_t a) { Seek(a); } + uint32 Flags_() const { return Flags(); } + void SetFlags_(uint32 f, uint32 m) { SetFlags(f, m); } + + mutable Arc arc_; + mutable uint32 lazy_; + const NGramFstImpl *impl_; + mutable NGramFstInst inst_; + + size_t i_; + uint32 flags_; + + DISALLOW_COPY_AND_ASSIGN(ArcIterator); +}; + +/*****************************************************************************/ +// Specialization for NGramFst; see generic version in fst.h +// for sample usage (but use the ProdLmFst type!). This version +// should inline. +template +class StateIterator > : public StateIteratorBase { + public: + typedef typename A::StateId StateId; + + explicit StateIterator(const NGramFst &fst) + : s_(0), num_states_(fst.NumStates()) { } + + bool Done() const { return s_ >= num_states_; } + StateId Value() const { return s_; } + void Next() { ++s_; } + void Reset() { s_ = 0; } + + private: + virtual bool Done_() const { return Done(); } + virtual StateId Value_() const { return Value(); } + virtual void Next_() { Next(); } + virtual void Reset_() { Reset(); } + + StateId s_, num_states_; + + DISALLOW_COPY_AND_ASSIGN(StateIterator); +}; +} // namespace fst +#endif // FST_EXTENSIONS_NGRAM_NGRAM_FST_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/extensions/ngram/nthbit.h b/kaldi_io/src/tools/openfst/include/fst/extensions/ngram/nthbit.h new file mode 100644 index 0000000..d4a9a5a --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/extensions/ngram/nthbit.h @@ -0,0 +1,46 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: sorenj@google.com (Jeffrey Sorensen) +// dr@google.com (Doug Rohde) + +#ifndef FST_EXTENSIONS_NGRAM_NTHBIT_H_ +#define FST_EXTENSIONS_NGRAM_NTHBIT_H_ + +#include + +extern uint32 nth_bit_bit_offset[]; + +inline uint32 nth_bit(uint64 v, uint32 r) { + uint32 shift = 0; + uint32 c = __builtin_popcount(v & 0xffffffff); + uint32 mask = -(r > c); + r -= c & mask; + shift += (32 & mask); + + c = __builtin_popcount((v >> shift) & 0xffff); + mask = -(r > c); + r -= c & mask; + shift += (16 & mask); + + c = __builtin_popcount((v >> shift) & 0xff); + mask = -(r > c); + r -= c & mask; + shift += (8 & mask); + + return shift + ((nth_bit_bit_offset[(v >> shift) & 0xff] >> + ((r - 1) << 2)) & 0xf); +} + +#endif // FST_EXTENSIONS_NGRAM_NTHBIT_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/factor-weight.h b/kaldi_io/src/tools/openfst/include/fst/factor-weight.h new file mode 100644 index 0000000..685155c --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/factor-weight.h @@ -0,0 +1,475 @@ +// factor-weight.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: allauzen@google.com (Cyril Allauzen) +// +// \file +// Classes to factor weights in an FST. + +#ifndef FST_LIB_FACTOR_WEIGHT_H__ +#define FST_LIB_FACTOR_WEIGHT_H__ + +#include +#include +using std::tr1::unordered_map; +using std::tr1::unordered_multimap; +#include +#include +using std::pair; using std::make_pair; +#include +using std::vector; + +#include +#include + + +namespace fst { + +const uint32 kFactorFinalWeights = 0x00000001; +const uint32 kFactorArcWeights = 0x00000002; + +template +struct FactorWeightOptions : CacheOptions { + typedef typename Arc::Label Label; + float delta; + uint32 mode; // factor arc weights and/or final weights + Label final_ilabel; // input label of arc created when factoring final w's + Label final_olabel; // output label of arc created when factoring final w's + + FactorWeightOptions(const CacheOptions &opts, float d, + uint32 m = kFactorArcWeights | kFactorFinalWeights, + Label il = 0, Label ol = 0) + : CacheOptions(opts), delta(d), mode(m), final_ilabel(il), + final_olabel(ol) {} + + explicit FactorWeightOptions( + float d, uint32 m = kFactorArcWeights | kFactorFinalWeights, + Label il = 0, Label ol = 0) + : delta(d), mode(m), final_ilabel(il), final_olabel(ol) {} + + FactorWeightOptions(uint32 m = kFactorArcWeights | kFactorFinalWeights, + Label il = 0, Label ol = 0) + : delta(kDelta), mode(m), final_ilabel(il), final_olabel(ol) {} +}; + + +// A factor iterator takes as argument a weight w and returns a +// sequence of pairs of weights (xi,yi) such that the sum of the +// products xi times yi is equal to w. If w is fully factored, +// the iterator should return nothing. +// +// template +// class FactorIterator { +// public: +// FactorIterator(W w); +// bool Done() const; +// void Next(); +// pair Value() const; +// void Reset(); +// } + + +// Factor trivially. +template +class IdentityFactor { + public: + IdentityFactor(const W &w) {} + bool Done() const { return true; } + void Next() {} + pair Value() const { return make_pair(W::One(), W::One()); } // unused + void Reset() {} +}; + + +// Factor a StringWeight w as 'ab' where 'a' is a label. +template +class StringFactor { + public: + StringFactor(const StringWeight &w) + : weight_(w), done_(w.Size() <= 1) {} + + bool Done() const { return done_; } + + void Next() { done_ = true; } + + pair< StringWeight, StringWeight > Value() const { + StringWeightIterator iter(weight_); + StringWeight w1(iter.Value()); + StringWeight w2; + for (iter.Next(); !iter.Done(); iter.Next()) + w2.PushBack(iter.Value()); + return make_pair(w1, w2); + } + + void Reset() { done_ = weight_.Size() <= 1; } + + private: + StringWeight weight_; + bool done_; +}; + + +// Factor a GallicWeight using StringFactor. +template +class GallicFactor { + public: + GallicFactor(const GallicWeight &w) + : weight_(w), done_(w.Value1().Size() <= 1) {} + + bool Done() const { return done_; } + + void Next() { done_ = true; } + + pair< GallicWeight, GallicWeight > Value() const { + StringFactor iter(weight_.Value1()); + GallicWeight w1(iter.Value().first, weight_.Value2()); + GallicWeight w2(iter.Value().second, W::One()); + return make_pair(w1, w2); + } + + void Reset() { done_ = weight_.Value1().Size() <= 1; } + + private: + GallicWeight weight_; + bool done_; +}; + + +// Implementation class for FactorWeight +template +class FactorWeightFstImpl + : public CacheImpl { + public: + using FstImpl::SetType; + using FstImpl::SetProperties; + using FstImpl::SetInputSymbols; + using FstImpl::SetOutputSymbols; + + using CacheBaseImpl< CacheState >::PushArc; + using CacheBaseImpl< CacheState >::HasStart; + using CacheBaseImpl< CacheState >::HasFinal; + using CacheBaseImpl< CacheState >::HasArcs; + using CacheBaseImpl< CacheState >::SetArcs; + using CacheBaseImpl< CacheState >::SetFinal; + using CacheBaseImpl< CacheState >::SetStart; + + typedef A Arc; + typedef typename A::Label Label; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + typedef F FactorIterator; + + struct Element { + Element() {} + + Element(StateId s, Weight w) : state(s), weight(w) {} + + StateId state; // Input state Id + Weight weight; // Residual weight + }; + + FactorWeightFstImpl(const Fst &fst, const FactorWeightOptions &opts) + : CacheImpl(opts), + fst_(fst.Copy()), + delta_(opts.delta), + mode_(opts.mode), + final_ilabel_(opts.final_ilabel), + final_olabel_(opts.final_olabel) { + SetType("factor_weight"); + uint64 props = fst.Properties(kFstProperties, false); + SetProperties(FactorWeightProperties(props), kCopyProperties); + + SetInputSymbols(fst.InputSymbols()); + SetOutputSymbols(fst.OutputSymbols()); + + if (mode_ == 0) + LOG(WARNING) << "FactorWeightFst: factor mode is set to 0: " + << "factoring neither arc weights nor final weights."; + } + + FactorWeightFstImpl(const FactorWeightFstImpl &impl) + : CacheImpl(impl), + fst_(impl.fst_->Copy(true)), + delta_(impl.delta_), + mode_(impl.mode_), + final_ilabel_(impl.final_ilabel_), + final_olabel_(impl.final_olabel_) { + SetType("factor_weight"); + SetProperties(impl.Properties(), kCopyProperties); + SetInputSymbols(impl.InputSymbols()); + SetOutputSymbols(impl.OutputSymbols()); + } + + ~FactorWeightFstImpl() { + delete fst_; + } + + StateId Start() { + if (!HasStart()) { + StateId s = fst_->Start(); + if (s == kNoStateId) + return kNoStateId; + StateId start = FindState(Element(fst_->Start(), Weight::One())); + SetStart(start); + } + return CacheImpl::Start(); + } + + Weight Final(StateId s) { + if (!HasFinal(s)) { + const Element &e = elements_[s]; + // TODO: fix so cast is unnecessary + Weight w = e.state == kNoStateId + ? e.weight + : (Weight) Times(e.weight, fst_->Final(e.state)); + FactorIterator f(w); + if (!(mode_ & kFactorFinalWeights) || f.Done()) + SetFinal(s, w); + else + SetFinal(s, Weight::Zero()); + } + return CacheImpl::Final(s); + } + + size_t NumArcs(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumArcs(s); + } + + size_t NumInputEpsilons(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumInputEpsilons(s); + } + + size_t NumOutputEpsilons(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumOutputEpsilons(s); + } + + uint64 Properties() const { return Properties(kFstProperties); } + + // Set error if found; return FST impl properties. + uint64 Properties(uint64 mask) const { + if ((mask & kError) && fst_->Properties(kError, false)) + SetProperties(kError, kError); + return FstImpl::Properties(mask); + } + + void InitArcIterator(StateId s, ArcIteratorData *data) { + if (!HasArcs(s)) + Expand(s); + CacheImpl::InitArcIterator(s, data); + } + + + // Find state corresponding to an element. Create new state + // if element not found. + StateId FindState(const Element &e) { + if (!(mode_ & kFactorArcWeights) && e.weight == Weight::One()) { + while (unfactored_.size() <= e.state) + unfactored_.push_back(kNoStateId); + if (unfactored_[e.state] == kNoStateId) { + unfactored_[e.state] = elements_.size(); + elements_.push_back(e); + } + return unfactored_[e.state]; + } else { + typename ElementMap::iterator eit = element_map_.find(e); + if (eit != element_map_.end()) { + return (*eit).second; + } else { + StateId s = elements_.size(); + elements_.push_back(e); + element_map_.insert(pair(e, s)); + return s; + } + } + } + + // Computes the outgoing transitions from a state, creating new destination + // states as needed. + void Expand(StateId s) { + Element e = elements_[s]; + if (e.state != kNoStateId) { + for (ArcIterator< Fst > ait(*fst_, e.state); + !ait.Done(); + ait.Next()) { + const A &arc = ait.Value(); + Weight w = Times(e.weight, arc.weight); + FactorIterator fit(w); + if (!(mode_ & kFactorArcWeights) || fit.Done()) { + StateId d = FindState(Element(arc.nextstate, Weight::One())); + PushArc(s, Arc(arc.ilabel, arc.olabel, w, d)); + } else { + for (; !fit.Done(); fit.Next()) { + const pair &p = fit.Value(); + StateId d = FindState(Element(arc.nextstate, + p.second.Quantize(delta_))); + PushArc(s, Arc(arc.ilabel, arc.olabel, p.first, d)); + } + } + } + } + + if ((mode_ & kFactorFinalWeights) && + ((e.state == kNoStateId) || + (fst_->Final(e.state) != Weight::Zero()))) { + Weight w = e.state == kNoStateId + ? e.weight + : Times(e.weight, fst_->Final(e.state)); + for (FactorIterator fit(w); + !fit.Done(); + fit.Next()) { + const pair &p = fit.Value(); + StateId d = FindState(Element(kNoStateId, + p.second.Quantize(delta_))); + PushArc(s, Arc(final_ilabel_, final_olabel_, p.first, d)); + } + } + SetArcs(s); + } + + private: + static const size_t kPrime = 7853; + + // Equality function for Elements, assume weights have been quantized. + class ElementEqual { + public: + bool operator()(const Element &x, const Element &y) const { + return x.state == y.state && x.weight == y.weight; + } + }; + + // Hash function for Elements to Fst states. + class ElementKey { + public: + size_t operator()(const Element &x) const { + return static_cast(x.state * kPrime + x.weight.Hash()); + } + private: + }; + + typedef unordered_map ElementMap; + + const Fst *fst_; + float delta_; + uint32 mode_; // factoring arc and/or final weights + Label final_ilabel_; // ilabel of arc created when factoring final w's + Label final_olabel_; // olabel of arc created when factoring final w's + vector elements_; // mapping Fst state to Elements + ElementMap element_map_; // mapping Elements to Fst state + // mapping between old/new 'StateId' for states that do not need to + // be factored when 'mode_' is '0' or 'kFactorFinalWeights' + vector unfactored_; + + void operator=(const FactorWeightFstImpl &); // disallow +}; + +template const size_t FactorWeightFstImpl::kPrime; + + +// FactorWeightFst takes as template parameter a FactorIterator as +// defined above. The result of weight factoring is a transducer +// equivalent to the input whose path weights have been factored +// according to the FactorIterator. States and transitions will be +// added as necessary. The algorithm is a generalization to arbitrary +// weights of the second step of the input epsilon-normalization +// algorithm due to Mohri, "Generic epsilon-removal and input +// epsilon-normalization algorithms for weighted transducers", +// International Journal of Computer Science 13(1): 129-143 (2002). +// +// This class attaches interface to implementation and handles +// reference counting, delegating most methods to ImplToFst. +template +class FactorWeightFst : public ImplToFst< FactorWeightFstImpl > { + public: + friend class ArcIterator< FactorWeightFst >; + friend class StateIterator< FactorWeightFst >; + + typedef A Arc; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + typedef CacheState State; + typedef FactorWeightFstImpl Impl; + + FactorWeightFst(const Fst &fst) + : ImplToFst(new Impl(fst, FactorWeightOptions())) {} + + FactorWeightFst(const Fst &fst, const FactorWeightOptions &opts) + : ImplToFst(new Impl(fst, opts)) {} + + // See Fst<>::Copy() for doc. + FactorWeightFst(const FactorWeightFst &fst, bool copy) + : ImplToFst(fst, copy) {} + + // Get a copy of this FactorWeightFst. See Fst<>::Copy() for further doc. + virtual FactorWeightFst *Copy(bool copy = false) const { + return new FactorWeightFst(*this, copy); + } + + virtual inline void InitStateIterator(StateIteratorData *data) const; + + virtual void InitArcIterator(StateId s, ArcIteratorData *data) const { + GetImpl()->InitArcIterator(s, data); + } + + private: + // Makes visible to friends. + Impl *GetImpl() const { return ImplToFst::GetImpl(); } + + void operator=(const FactorWeightFst &fst); // Disallow +}; + + +// Specialization for FactorWeightFst. +template +class StateIterator< FactorWeightFst > + : public CacheStateIterator< FactorWeightFst > { + public: + explicit StateIterator(const FactorWeightFst &fst) + : CacheStateIterator< FactorWeightFst >(fst, fst.GetImpl()) {} +}; + + +// Specialization for FactorWeightFst. +template +class ArcIterator< FactorWeightFst > + : public CacheArcIterator< FactorWeightFst > { + public: + typedef typename A::StateId StateId; + + ArcIterator(const FactorWeightFst &fst, StateId s) + : CacheArcIterator< FactorWeightFst >(fst.GetImpl(), s) { + if (!fst.GetImpl()->HasArcs(s)) + fst.GetImpl()->Expand(s); + } + + private: + DISALLOW_COPY_AND_ASSIGN(ArcIterator); +}; + +template inline +void FactorWeightFst::InitStateIterator(StateIteratorData *data) const +{ + data->base = new StateIterator< FactorWeightFst >(*this); +} + + +} // namespace fst + +#endif // FST_LIB_FACTOR_WEIGHT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/flags.h b/kaldi_io/src/tools/openfst/include/fst/flags.h new file mode 100644 index 0000000..b3bb66c --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/flags.h @@ -0,0 +1,242 @@ +// flags.h +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Author: riley@google.com (Michael Riley) +// +// \file +// Google-style flag handling declarations and inline definitions. + +#ifndef FST_LIB_FLAGS_H__ +#define FST_LIB_FLAGS_H__ + +#include +#include +#include +#include +#include + +#include +#include + +using std::string; + +// +// FLAGS USAGE: +// +// Definition example: +// +// DEFINE_int32(length, 0, "length"); +// +// This defines variable FLAGS_length, initialized to 0. +// +// Declaration example: +// +// DECLARE_int32(length); +// +// SET_FLAGS() can be used to set flags from the command line +// using, for example, '--length=2'. +// +// ShowUsage() can be used to print out command and flag usage. +// + +#define DECLARE_bool(name) extern bool FLAGS_ ## name +#define DECLARE_string(name) extern string FLAGS_ ## name +#define DECLARE_int32(name) extern int32 FLAGS_ ## name +#define DECLARE_int64(name) extern int64 FLAGS_ ## name +#define DECLARE_double(name) extern double FLAGS_ ## name + +template +struct FlagDescription { + FlagDescription(T *addr, const char *doc, const char *type, + const char *file, const T val) + : address(addr), + doc_string(doc), + type_name(type), + file_name(file), + default_value(val) {} + + T *address; + const char *doc_string; + const char *type_name; + const char *file_name; + const T default_value; +}; + +template +class FlagRegister { + public: + static FlagRegister *GetRegister() { + fst::FstOnceInit(®ister_init_, &FlagRegister::Init); + return register_; + } + + const FlagDescription &GetFlagDescription(const string &name) const { + fst::MutexLock l(register_lock_); + typename std::map< string, FlagDescription >::const_iterator it = + flag_table_.find(name); + return it != flag_table_.end() ? it->second : 0; + } + void SetDescription(const string &name, + const FlagDescription &desc) { + fst::MutexLock l(register_lock_); + flag_table_.insert(make_pair(name, desc)); + } + + bool SetFlag(const string &val, bool *address) const { + if (val == "true" || val == "1" || val.empty()) { + *address = true; + return true; + } else if (val == "false" || val == "0") { + *address = false; + return true; + } + else { + return false; + } + } + bool SetFlag(const string &val, string *address) const { + *address = val; + return true; + } + bool SetFlag(const string &val, int32 *address) const { + char *p = 0; + *address = strtol(val.c_str(), &p, 0); + return !val.empty() && *p == '\0'; + } + bool SetFlag(const string &val, int64 *address) const { + char *p = 0; + *address = strtoll(val.c_str(), &p, 0); + return !val.empty() && *p == '\0'; + } + bool SetFlag(const string &val, double *address) const { + char *p = 0; + *address = strtod(val.c_str(), &p); + return !val.empty() && *p == '\0'; + } + + bool SetFlag(const string &arg, const string &val) const { + for (typename std::map< string, FlagDescription >::const_iterator it = + flag_table_.begin(); + it != flag_table_.end(); + ++it) { + const string &name = it->first; + const FlagDescription &desc = it->second; + if (arg == name) + return SetFlag(val, desc.address); + } + return false; + } + + void GetUsage(std::set< std::pair > *usage_set) const { + for (typename std::map< string, + FlagDescription >::const_iterator it = + flag_table_.begin(); + it != flag_table_.end(); + ++it) { + const string &name = it->first; + const FlagDescription &desc = it->second; + string usage = " --" + name; + usage += ": type = "; + usage += desc.type_name; + usage += ", default = "; + usage += GetDefault(desc.default_value) + "\n "; + usage += desc.doc_string; + usage_set->insert(make_pair(desc.file_name, usage)); + } + } + + private: + static void Init() { + register_lock_ = new fst::Mutex; + register_ = new FlagRegister; + } + + std::map< string, FlagDescription > flag_table_; + + string GetDefault(bool default_value) const { + return default_value ? "true" : "false"; + } + + string GetDefault(const string &default_value) const { + return "\"" + default_value + "\""; + } + + template string GetDefault(const V& default_value) const { + std::ostringstream strm; + strm << default_value; + return strm.str(); + } + + static fst::FstOnceType register_init_; // ensures only called once + static fst::Mutex* register_lock_; // multithreading lock + static FlagRegister *register_; +}; + +template +fst::FstOnceType FlagRegister::register_init_ = fst::FST_ONCE_INIT; + +template +fst::Mutex *FlagRegister::register_lock_ = 0; + +template +FlagRegister *FlagRegister::register_ = 0; + + +template +class FlagRegisterer { + public: + FlagRegisterer(const string &name, const FlagDescription &desc) { + FlagRegister *registr = FlagRegister::GetRegister(); + registr->SetDescription(name, desc); + } + + private: + DISALLOW_COPY_AND_ASSIGN(FlagRegisterer); +}; + + +#define DEFINE_VAR(type, name, value, doc) \ + type FLAGS_ ## name = value; \ + static FlagRegisterer \ + name ## _flags_registerer(#name, FlagDescription(&FLAGS_ ## name, \ + doc, \ + #type, \ + __FILE__, \ + value)) + +#define DEFINE_bool(name, value, doc) DEFINE_VAR(bool, name, value, doc) +#define DEFINE_string(name, value, doc) \ + DEFINE_VAR(string, name, value, doc) +#define DEFINE_int32(name, value, doc) DEFINE_VAR(int32, name, value, doc) +#define DEFINE_int64(name, value, doc) DEFINE_VAR(int64, name, value, doc) +#define DEFINE_double(name, value, doc) DEFINE_VAR(double, name, value, doc) + + +// Temporary directory +DECLARE_string(tmpdir); + +void SetFlags(const char *usage, int *argc, char ***argv, bool remove_flags, + const char *src = ""); + +#define SET_FLAGS(usage, argc, argv, rmflags) \ +SetFlags(usage, argc, argv, rmflags, __FILE__) + +// Deprecated - for backward compatibility +inline void InitFst(const char *usage, int *argc, char ***argv, bool rmflags) { + return SetFlags(usage, argc, argv, rmflags); +} + +void ShowUsage(bool long_usage = true); + +#endif // FST_LIB_FLAGS_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/float-weight.h b/kaldi_io/src/tools/openfst/include/fst/float-weight.h new file mode 100644 index 0000000..eb22638 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/float-weight.h @@ -0,0 +1,601 @@ +// float-weight.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Float weight set and associated semiring operation definitions. +// + +#ifndef FST_LIB_FLOAT_WEIGHT_H__ +#define FST_LIB_FLOAT_WEIGHT_H__ + +#include +#include +#include +#include + +#include +#include + + +namespace fst { + +// numeric limits class +template +class FloatLimits { + public: + static const T PosInfinity() { + static const T pos_infinity = numeric_limits::infinity(); + return pos_infinity; + } + + static const T NegInfinity() { + static const T neg_infinity = -PosInfinity(); + return neg_infinity; + } + + static const T NumberBad() { + static const T number_bad = numeric_limits::quiet_NaN(); + return number_bad; + } + +}; + +// weight class to be templated on floating-points types +template +class FloatWeightTpl { + public: + FloatWeightTpl() {} + + FloatWeightTpl(T f) : value_(f) {} + + FloatWeightTpl(const FloatWeightTpl &w) : value_(w.value_) {} + + FloatWeightTpl &operator=(const FloatWeightTpl &w) { + value_ = w.value_; + return *this; + } + + istream &Read(istream &strm) { + return ReadType(strm, &value_); + } + + ostream &Write(ostream &strm) const { + return WriteType(strm, value_); + } + + size_t Hash() const { + union { + T f; + size_t s; + } u; + u.s = 0; + u.f = value_; + return u.s; + } + + const T &Value() const { return value_; } + + protected: + void SetValue(const T &f) { value_ = f; } + + inline static string GetPrecisionString() { + int64 size = sizeof(T); + if (size == sizeof(float)) return ""; + size *= CHAR_BIT; + + string result; + Int64ToStr(size, &result); + return result; + } + + private: + T value_; +}; + +// Single-precision float weight +typedef FloatWeightTpl FloatWeight; + +template +inline bool operator==(const FloatWeightTpl &w1, + const FloatWeightTpl &w2) { + // Volatile qualifier thwarts over-aggressive compiler optimizations + // that lead to problems esp. with NaturalLess(). + volatile T v1 = w1.Value(); + volatile T v2 = w2.Value(); + return v1 == v2; +} + +inline bool operator==(const FloatWeightTpl &w1, + const FloatWeightTpl &w2) { + return operator==(w1, w2); +} + +inline bool operator==(const FloatWeightTpl &w1, + const FloatWeightTpl &w2) { + return operator==(w1, w2); +} + +template +inline bool operator!=(const FloatWeightTpl &w1, + const FloatWeightTpl &w2) { + return !(w1 == w2); +} + +inline bool operator!=(const FloatWeightTpl &w1, + const FloatWeightTpl &w2) { + return operator!=(w1, w2); +} + +inline bool operator!=(const FloatWeightTpl &w1, + const FloatWeightTpl &w2) { + return operator!=(w1, w2); +} + +template +inline bool ApproxEqual(const FloatWeightTpl &w1, + const FloatWeightTpl &w2, + float delta = kDelta) { + return w1.Value() <= w2.Value() + delta && w2.Value() <= w1.Value() + delta; +} + +template +inline ostream &operator<<(ostream &strm, const FloatWeightTpl &w) { + if (w.Value() == FloatLimits::PosInfinity()) + return strm << "Infinity"; + else if (w.Value() == FloatLimits::NegInfinity()) + return strm << "-Infinity"; + else if (w.Value() != w.Value()) // Fails for NaN + return strm << "BadNumber"; + else + return strm << w.Value(); +} + +template +inline istream &operator>>(istream &strm, FloatWeightTpl &w) { + string s; + strm >> s; + if (s == "Infinity") { + w = FloatWeightTpl(FloatLimits::PosInfinity()); + } else if (s == "-Infinity") { + w = FloatWeightTpl(FloatLimits::NegInfinity()); + } else { + char *p; + T f = strtod(s.c_str(), &p); + if (p < s.c_str() + s.size()) + strm.clear(std::ios::badbit); + else + w = FloatWeightTpl(f); + } + return strm; +} + + +// Tropical semiring: (min, +, inf, 0) +template +class TropicalWeightTpl : public FloatWeightTpl { + public: + using FloatWeightTpl::Value; + + typedef TropicalWeightTpl ReverseWeight; + + TropicalWeightTpl() : FloatWeightTpl() {} + + TropicalWeightTpl(T f) : FloatWeightTpl(f) {} + + TropicalWeightTpl(const TropicalWeightTpl &w) : FloatWeightTpl(w) {} + + static const TropicalWeightTpl Zero() { + return TropicalWeightTpl(FloatLimits::PosInfinity()); } + + static const TropicalWeightTpl One() { + return TropicalWeightTpl(0.0F); } + + static const TropicalWeightTpl NoWeight() { + return TropicalWeightTpl(FloatLimits::NumberBad()); } + + static const string &Type() { + static const string type = "tropical" + + FloatWeightTpl::GetPrecisionString(); + return type; + } + + bool Member() const { + // First part fails for IEEE NaN + return Value() == Value() && Value() != FloatLimits::NegInfinity(); + } + + TropicalWeightTpl Quantize(float delta = kDelta) const { + if (Value() == FloatLimits::NegInfinity() || + Value() == FloatLimits::PosInfinity() || + Value() != Value()) + return *this; + else + return TropicalWeightTpl(floor(Value()/delta + 0.5F) * delta); + } + + TropicalWeightTpl Reverse() const { return *this; } + + static uint64 Properties() { + return kLeftSemiring | kRightSemiring | kCommutative | + kPath | kIdempotent; + } +}; + +// Single precision tropical weight +typedef TropicalWeightTpl TropicalWeight; + +template +inline TropicalWeightTpl Plus(const TropicalWeightTpl &w1, + const TropicalWeightTpl &w2) { + if (!w1.Member() || !w2.Member()) + return TropicalWeightTpl::NoWeight(); + return w1.Value() < w2.Value() ? w1 : w2; +} + +inline TropicalWeightTpl Plus(const TropicalWeightTpl &w1, + const TropicalWeightTpl &w2) { + return Plus(w1, w2); +} + +inline TropicalWeightTpl Plus(const TropicalWeightTpl &w1, + const TropicalWeightTpl &w2) { + return Plus(w1, w2); +} + +template +inline TropicalWeightTpl Times(const TropicalWeightTpl &w1, + const TropicalWeightTpl &w2) { + if (!w1.Member() || !w2.Member()) + return TropicalWeightTpl::NoWeight(); + T f1 = w1.Value(), f2 = w2.Value(); + if (f1 == FloatLimits::PosInfinity()) + return w1; + else if (f2 == FloatLimits::PosInfinity()) + return w2; + else + return TropicalWeightTpl(f1 + f2); +} + +inline TropicalWeightTpl Times(const TropicalWeightTpl &w1, + const TropicalWeightTpl &w2) { + return Times(w1, w2); +} + +inline TropicalWeightTpl Times(const TropicalWeightTpl &w1, + const TropicalWeightTpl &w2) { + return Times(w1, w2); +} + +template +inline TropicalWeightTpl Divide(const TropicalWeightTpl &w1, + const TropicalWeightTpl &w2, + DivideType typ = DIVIDE_ANY) { + if (!w1.Member() || !w2.Member()) + return TropicalWeightTpl::NoWeight(); + T f1 = w1.Value(), f2 = w2.Value(); + if (f2 == FloatLimits::PosInfinity()) + return FloatLimits::NumberBad(); + else if (f1 == FloatLimits::PosInfinity()) + return FloatLimits::PosInfinity(); + else + return TropicalWeightTpl(f1 - f2); +} + +inline TropicalWeightTpl Divide(const TropicalWeightTpl &w1, + const TropicalWeightTpl &w2, + DivideType typ = DIVIDE_ANY) { + return Divide(w1, w2, typ); +} + +inline TropicalWeightTpl Divide(const TropicalWeightTpl &w1, + const TropicalWeightTpl &w2, + DivideType typ = DIVIDE_ANY) { + return Divide(w1, w2, typ); +} + + +// Log semiring: (log(e^-x + e^y), +, inf, 0) +template +class LogWeightTpl : public FloatWeightTpl { + public: + using FloatWeightTpl::Value; + + typedef LogWeightTpl ReverseWeight; + + LogWeightTpl() : FloatWeightTpl() {} + + LogWeightTpl(T f) : FloatWeightTpl(f) {} + + LogWeightTpl(const LogWeightTpl &w) : FloatWeightTpl(w) {} + + static const LogWeightTpl Zero() { + return LogWeightTpl(FloatLimits::PosInfinity()); + } + + static const LogWeightTpl One() { + return LogWeightTpl(0.0F); + } + + static const LogWeightTpl NoWeight() { + return LogWeightTpl(FloatLimits::NumberBad()); } + + static const string &Type() { + static const string type = "log" + FloatWeightTpl::GetPrecisionString(); + return type; + } + + bool Member() const { + // First part fails for IEEE NaN + return Value() == Value() && Value() != FloatLimits::NegInfinity(); + } + + LogWeightTpl Quantize(float delta = kDelta) const { + if (Value() == FloatLimits::NegInfinity() || + Value() == FloatLimits::PosInfinity() || + Value() != Value()) + return *this; + else + return LogWeightTpl(floor(Value()/delta + 0.5F) * delta); + } + + LogWeightTpl Reverse() const { return *this; } + + static uint64 Properties() { + return kLeftSemiring | kRightSemiring | kCommutative; + } +}; + +// Single-precision log weight +typedef LogWeightTpl LogWeight; +// Double-precision log weight +typedef LogWeightTpl Log64Weight; + +template +inline T LogExp(T x) { return log(1.0F + exp(-x)); } + +template +inline LogWeightTpl Plus(const LogWeightTpl &w1, + const LogWeightTpl &w2) { + T f1 = w1.Value(), f2 = w2.Value(); + if (f1 == FloatLimits::PosInfinity()) + return w2; + else if (f2 == FloatLimits::PosInfinity()) + return w1; + else if (f1 > f2) + return LogWeightTpl(f2 - LogExp(f1 - f2)); + else + return LogWeightTpl(f1 - LogExp(f2 - f1)); +} + +inline LogWeightTpl Plus(const LogWeightTpl &w1, + const LogWeightTpl &w2) { + return Plus(w1, w2); +} + +inline LogWeightTpl Plus(const LogWeightTpl &w1, + const LogWeightTpl &w2) { + return Plus(w1, w2); +} + +template +inline LogWeightTpl Times(const LogWeightTpl &w1, + const LogWeightTpl &w2) { + if (!w1.Member() || !w2.Member()) + return LogWeightTpl::NoWeight(); + T f1 = w1.Value(), f2 = w2.Value(); + if (f1 == FloatLimits::PosInfinity()) + return w1; + else if (f2 == FloatLimits::PosInfinity()) + return w2; + else + return LogWeightTpl(f1 + f2); +} + +inline LogWeightTpl Times(const LogWeightTpl &w1, + const LogWeightTpl &w2) { + return Times(w1, w2); +} + +inline LogWeightTpl Times(const LogWeightTpl &w1, + const LogWeightTpl &w2) { + return Times(w1, w2); +} + +template +inline LogWeightTpl Divide(const LogWeightTpl &w1, + const LogWeightTpl &w2, + DivideType typ = DIVIDE_ANY) { + if (!w1.Member() || !w2.Member()) + return LogWeightTpl::NoWeight(); + T f1 = w1.Value(), f2 = w2.Value(); + if (f2 == FloatLimits::PosInfinity()) + return FloatLimits::NumberBad(); + else if (f1 == FloatLimits::PosInfinity()) + return FloatLimits::PosInfinity(); + else + return LogWeightTpl(f1 - f2); +} + +inline LogWeightTpl Divide(const LogWeightTpl &w1, + const LogWeightTpl &w2, + DivideType typ = DIVIDE_ANY) { + return Divide(w1, w2, typ); +} + +inline LogWeightTpl Divide(const LogWeightTpl &w1, + const LogWeightTpl &w2, + DivideType typ = DIVIDE_ANY) { + return Divide(w1, w2, typ); +} + +// MinMax semiring: (min, max, inf, -inf) +template +class MinMaxWeightTpl : public FloatWeightTpl { + public: + using FloatWeightTpl::Value; + + typedef MinMaxWeightTpl ReverseWeight; + + MinMaxWeightTpl() : FloatWeightTpl() {} + + MinMaxWeightTpl(T f) : FloatWeightTpl(f) {} + + MinMaxWeightTpl(const MinMaxWeightTpl &w) : FloatWeightTpl(w) {} + + static const MinMaxWeightTpl Zero() { + return MinMaxWeightTpl(FloatLimits::PosInfinity()); + } + + static const MinMaxWeightTpl One() { + return MinMaxWeightTpl(FloatLimits::NegInfinity()); + } + + static const MinMaxWeightTpl NoWeight() { + return MinMaxWeightTpl(FloatLimits::NumberBad()); } + + static const string &Type() { + static const string type = "minmax" + + FloatWeightTpl::GetPrecisionString(); + return type; + } + + bool Member() const { + // Fails for IEEE NaN + return Value() == Value(); + } + + MinMaxWeightTpl Quantize(float delta = kDelta) const { + // If one of infinities, or a NaN + if (Value() == FloatLimits::NegInfinity() || + Value() == FloatLimits::PosInfinity() || + Value() != Value()) + return *this; + else + return MinMaxWeightTpl(floor(Value()/delta + 0.5F) * delta); + } + + MinMaxWeightTpl Reverse() const { return *this; } + + static uint64 Properties() { + return kLeftSemiring | kRightSemiring | kCommutative | kIdempotent | kPath; + } +}; + +// Single-precision min-max weight +typedef MinMaxWeightTpl MinMaxWeight; + +// Min +template +inline MinMaxWeightTpl Plus( + const MinMaxWeightTpl &w1, const MinMaxWeightTpl &w2) { + if (!w1.Member() || !w2.Member()) + return MinMaxWeightTpl::NoWeight(); + return w1.Value() < w2.Value() ? w1 : w2; +} + +inline MinMaxWeightTpl Plus( + const MinMaxWeightTpl &w1, const MinMaxWeightTpl &w2) { + return Plus(w1, w2); +} + +inline MinMaxWeightTpl Plus( + const MinMaxWeightTpl &w1, const MinMaxWeightTpl &w2) { + return Plus(w1, w2); +} + +// Max +template +inline MinMaxWeightTpl Times( + const MinMaxWeightTpl &w1, const MinMaxWeightTpl &w2) { + if (!w1.Member() || !w2.Member()) + return MinMaxWeightTpl::NoWeight(); + return w1.Value() >= w2.Value() ? w1 : w2; +} + +inline MinMaxWeightTpl Times( + const MinMaxWeightTpl &w1, const MinMaxWeightTpl &w2) { + return Times(w1, w2); +} + +inline MinMaxWeightTpl Times( + const MinMaxWeightTpl &w1, const MinMaxWeightTpl &w2) { + return Times(w1, w2); +} + +// Defined only for special cases +template +inline MinMaxWeightTpl Divide(const MinMaxWeightTpl &w1, + const MinMaxWeightTpl &w2, + DivideType typ = DIVIDE_ANY) { + if (!w1.Member() || !w2.Member()) + return MinMaxWeightTpl::NoWeight(); + // min(w1, x) = w2, w1 >= w2 => min(w1, x) = w2, x = w2 + return w1.Value() >= w2.Value() ? w1 : FloatLimits::NumberBad(); +} + +inline MinMaxWeightTpl Divide(const MinMaxWeightTpl &w1, + const MinMaxWeightTpl &w2, + DivideType typ = DIVIDE_ANY) { + return Divide(w1, w2, typ); +} + +inline MinMaxWeightTpl Divide(const MinMaxWeightTpl &w1, + const MinMaxWeightTpl &w2, + DivideType typ = DIVIDE_ANY) { + return Divide(w1, w2, typ); +} + +// +// WEIGHT CONVERTER SPECIALIZATIONS. +// + +// Convert to tropical +template <> +struct WeightConvert { + TropicalWeight operator()(LogWeight w) const { return w.Value(); } +}; + +template <> +struct WeightConvert { + TropicalWeight operator()(Log64Weight w) const { return w.Value(); } +}; + +// Convert to log +template <> +struct WeightConvert { + LogWeight operator()(TropicalWeight w) const { return w.Value(); } +}; + +template <> +struct WeightConvert { + LogWeight operator()(Log64Weight w) const { return w.Value(); } +}; + +// Convert to log64 +template <> +struct WeightConvert { + Log64Weight operator()(TropicalWeight w) const { return w.Value(); } +}; + +template <> +struct WeightConvert { + Log64Weight operator()(LogWeight w) const { return w.Value(); } +}; + +} // namespace fst + +#endif // FST_LIB_FLOAT_WEIGHT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/fst-decl.h b/kaldi_io/src/tools/openfst/include/fst/fst-decl.h new file mode 100644 index 0000000..f27ded8 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/fst-decl.h @@ -0,0 +1,124 @@ +// fst-decl.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// This file contains declarations of classes in the Fst template library. +// + +#ifndef FST_LIB_FST_DECL_H__ +#define FST_LIB_FST_DECL_H__ + +#include + +namespace fst { + +class SymbolTable; +class SymbolTableIterator; + +template class FloatWeightTpl; +template class TropicalWeightTpl; +template class LogWeightTpl; +template class MinMaxWeightTpl; + +typedef FloatWeightTpl FloatWeight; +typedef TropicalWeightTpl TropicalWeight; +typedef LogWeightTpl LogWeight; +typedef MinMaxWeightTpl MinMaxWeight; + +template class ArcTpl; +typedef ArcTpl StdArc; +typedef ArcTpl LogArc; + +template class CompactFst; +template class ConstFst; +template class EditFst; +template class ExpandedFst; +template class Fst; +template class MutableFst; +template class VectorFst; + +template class ArcSortFst; +template class ClosureFst; +template class ComposeFst; +template class ConcatFst; +template class DeterminizeFst; +template class DifferenceFst; +template class IntersectFst; +template class InvertFst; +template class ArcMapFst; +template class ProjectFst; +template class RandGenFst; +template class RelabelFst; +template class ReplaceFst; +template class RmEpsilonFst; +template class UnionFst; + +template class Heap; + +template class AcceptorCompactor; +template class StringCompactor; +template class UnweightedAcceptorCompactor; +template class UnweightedCompactor; +template class WeightedStringCompactor; + +template class DefaultReplaceStateTable; + +typedef CompactFst > +StdCompactAcceptorFst; +typedef CompactFst< StdArc, StringCompactor > +StdCompactStringFst; +typedef CompactFst > +StdCompactUnweightedAcceptorFst; +typedef CompactFst > +StdCompactUnweightedFst; +typedef CompactFst< StdArc, WeightedStringCompactor > +StdCompactWeightedStringFst; +typedef ConstFst StdConstFst; +typedef ExpandedFst StdExpandedFst; +typedef Fst StdFst; +typedef MutableFst StdMutableFst; +typedef VectorFst StdVectorFst; + + +template class StdArcSortFst; +typedef ClosureFst StdClosureFst; +typedef ComposeFst StdComposeFst; +typedef ConcatFst StdConcatFst; +typedef DeterminizeFst StdDeterminizeFst; +typedef DifferenceFst StdDifferenceFst; +typedef IntersectFst StdIntersectFst; +typedef InvertFst StdInvertFst; +typedef ProjectFst StdProjectFst; +typedef RelabelFst StdRelabelFst; +typedef ReplaceFst > +StdReplaceFst; +typedef RmEpsilonFst StdRmEpsilonFst; +typedef UnionFst StdUnionFst; + +template class IntegerFilterState; +typedef IntegerFilterState CharFilterState; +typedef IntegerFilterState ShortFilterState; +typedef IntegerFilterState IntFilterState; + +template class Matcher; +template class SequenceComposeFilter; +template class AltSequenceComposeFilter; +template class MatchComposeFilter; + +} // namespace fst + +#endif // FST_LIB_FST_DECL_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/fst.h b/kaldi_io/src/tools/openfst/include/fst/fst.h new file mode 100644 index 0000000..150fc4e --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/fst.h @@ -0,0 +1,949 @@ +// fst.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Finite-State Transducer (FST) - abstract base class definition, +// state and arc iterator interface, and suggested base implementation. +// + +#ifndef FST_LIB_FST_H__ +#define FST_LIB_FST_H__ + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + + +DECLARE_bool(fst_align); + +namespace fst { + +bool IsFstHeader(istream &, const string &); + +class FstHeader; +template class StateIteratorData; +template class ArcIteratorData; +template class MatcherBase; + +struct FstReadOptions { + // FileReadMode(s) are advisory, there are many conditions than prevent a + // file from being mapped, READ mode will be selected in these cases with + // a warning indicating why it was chosen. + enum FileReadMode { READ, MAP }; + + string source; // Where you're reading from + const FstHeader *header; // Pointer to Fst header. If non-zero, use + // this info (don't read a stream header) + const SymbolTable* isymbols; // Pointer to input symbols. If non-zero, use + // this info (read and skip stream isymbols) + const SymbolTable* osymbols; // Pointer to output symbols. If non-zero, use + // this info (read and skip stream osymbols) + FileReadMode mode; // Read or map files (advisory, if possible) + + explicit FstReadOptions(const string& src = "", + const FstHeader *hdr = 0, + const SymbolTable* isym = 0, + const SymbolTable* osym = 0); + + explicit FstReadOptions(const string& src, + const SymbolTable* isym, + const SymbolTable* osym = 0); + + // Helper function to convert strings FileReadModes into their enum value. + static FileReadMode ReadMode(const string &mode); +}; + +struct FstWriteOptions { + string source; // Where you're writing to + bool write_header; // Write the header? + bool write_isymbols; // Write input symbols? + bool write_osymbols; // Write output symbols? + bool align; // Write data aligned where appropriate; + // this may fail on pipes + + explicit FstWriteOptions(const string& src = "", + bool hdr = true, bool isym = true, + bool osym = true, bool alig = FLAGS_fst_align) + : source(src), write_header(hdr), + write_isymbols(isym), write_osymbols(osym), align(alig) {} +}; + +// +// Fst HEADER CLASS +// +// This is the recommended Fst file header representation. +// +class FstHeader { + public: + enum { + HAS_ISYMBOLS = 0x1, // Has input symbol table + HAS_OSYMBOLS = 0x2, // Has output symbol table + IS_ALIGNED = 0x4, // Memory-aligned (where appropriate) + } Flags; + + FstHeader() : version_(0), flags_(0), properties_(0), start_(-1), + numstates_(0), numarcs_(0) {} + const string &FstType() const { return fsttype_; } + const string &ArcType() const { return arctype_; } + int32 Version() const { return version_; } + int32 GetFlags() const { return flags_; } + uint64 Properties() const { return properties_; } + int64 Start() const { return start_; } + int64 NumStates() const { return numstates_; } + int64 NumArcs() const { return numarcs_; } + + void SetFstType(const string& type) { fsttype_ = type; } + void SetArcType(const string& type) { arctype_ = type; } + void SetVersion(int32 version) { version_ = version; } + void SetFlags(int32 flags) { flags_ = flags; } + void SetProperties(uint64 properties) { properties_ = properties; } + void SetStart(int64 start) { start_ = start; } + void SetNumStates(int64 numstates) { numstates_ = numstates; } + void SetNumArcs(int64 numarcs) { numarcs_ = numarcs; } + + bool Read(istream &strm, const string &source, bool rewind = false); + bool Write(ostream &strm, const string &source) const; + + private: + + string fsttype_; // E.g. "vector" + string arctype_; // E.g. "standard" + int32 version_; // Type version # + int32 flags_; // File format bits + uint64 properties_; // FST property bits + int64 start_; // Start state + int64 numstates_; // # of states + int64 numarcs_; // # of arcs +}; + + +// Specifies matcher action. +enum MatchType { MATCH_INPUT, // Match input label. + MATCH_OUTPUT, // Match output label. + MATCH_BOTH, // Match input or output label. + MATCH_NONE, // Match nothing. + MATCH_UNKNOWN }; // Match type unknown. + +// +// Fst INTERFACE CLASS DEFINITION +// + +// A generic FST, templated on the arc definition, with +// common-demoninator methods (use StateIterator and ArcIterator to +// iterate over its states and arcs). +template +class Fst { + public: + typedef A Arc; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + + virtual ~Fst() {} + + virtual StateId Start() const = 0; // Initial state + + virtual Weight Final(StateId) const = 0; // State's final weight + + virtual size_t NumArcs(StateId) const = 0; // State's arc count + + virtual size_t NumInputEpsilons(StateId) + const = 0; // State's input epsilon count + + virtual size_t NumOutputEpsilons(StateId) + const = 0; // State's output epsilon count + + // If test=false, return stored properties bits for mask (some poss. unknown) + // If test=true, return property bits for mask (computing o.w. unknown) + virtual uint64 Properties(uint64 mask, bool test) + const = 0; // Property bits + + virtual const string& Type() const = 0; // Fst type name + + // Get a copy of this Fst. The copying behaves as follows: + // + // (1) The copying is constant time if safe = false or if safe = true + // and is on an otherwise unaccessed Fst. + // + // (2) If safe = true, the copy is thread-safe in that the original + // and copy can be safely accessed (but not necessarily mutated) by + // separate threads. For some Fst types, 'Copy(true)' should only be + // called on an Fst that has not otherwise been accessed. Its behavior + // is undefined otherwise. + // + // (3) If a MutableFst is copied and then mutated, then the original is + // unmodified and vice versa (often by a copy-on-write on the initial + // mutation, which may not be constant time). + virtual Fst *Copy(bool safe = false) const = 0; + + // Read an Fst from an input stream; returns NULL on error + static Fst *Read(istream &strm, const FstReadOptions &opts) { + FstReadOptions ropts(opts); + FstHeader hdr; + if (ropts.header) + hdr = *opts.header; + else { + if (!hdr.Read(strm, opts.source)) + return 0; + ropts.header = &hdr; + } + FstRegister *registr = FstRegister::GetRegister(); + const typename FstRegister::Reader reader = + registr->GetReader(hdr.FstType()); + if (!reader) { + LOG(ERROR) << "Fst::Read: Unknown FST type \"" << hdr.FstType() + << "\" (arc type = \"" << A::Type() + << "\"): " << ropts.source; + return 0; + } + return reader(strm, ropts); + }; + + // Read an Fst from a file; return NULL on error + // Empty filename reads from standard input + static Fst *Read(const string &filename) { + if (!filename.empty()) { + ifstream strm(filename.c_str(), ifstream::in | ifstream::binary); + if (!strm) { + LOG(ERROR) << "Fst::Read: Can't open file: " << filename; + return 0; + } + return Read(strm, FstReadOptions(filename)); + } else { + return Read(cin, FstReadOptions("standard input")); + } + } + + // Write an Fst to an output stream; return false on error + virtual bool Write(ostream &strm, const FstWriteOptions &opts) const { + LOG(ERROR) << "Fst::Write: No write stream method for " << Type() + << " Fst type"; + return false; + } + + // Write an Fst to a file; return false on error + // Empty filename writes to standard output + virtual bool Write(const string &filename) const { + LOG(ERROR) << "Fst::Write: No write filename method for " << Type() + << " Fst type"; + return false; + } + + // Return input label symbol table; return NULL if not specified + virtual const SymbolTable* InputSymbols() const = 0; + + // Return output label symbol table; return NULL if not specified + virtual const SymbolTable* OutputSymbols() const = 0; + + // For generic state iterator construction; not normally called + // directly by users. + virtual void InitStateIterator(StateIteratorData *) const = 0; + + // For generic arc iterator construction; not normally called + // directly by users. + virtual void InitArcIterator(StateId s, ArcIteratorData *) const = 0; + + // For generic matcher construction; not normally called + // directly by users. + virtual MatcherBase *InitMatcher(MatchType match_type) const; + + protected: + bool WriteFile(const string &filename) const { + if (!filename.empty()) { + ofstream strm(filename.c_str(), ofstream::out | ofstream::binary); + if (!strm) { + LOG(ERROR) << "Fst::Write: Can't open file: " << filename; + return false; + } + return Write(strm, FstWriteOptions(filename)); + } else { + return Write(cout, FstWriteOptions("standard output")); + } + } +}; + + +// +// STATE and ARC ITERATOR DEFINITIONS +// + +// State iterator interface templated on the Arc definition; used +// for StateIterator specializations returned by the InitStateIterator +// Fst method. +template +class StateIteratorBase { + public: + typedef A Arc; + typedef typename A::StateId StateId; + + virtual ~StateIteratorBase() {} + + bool Done() const { return Done_(); } // End of iterator? + StateId Value() const { return Value_(); } // Current state (when !Done) + void Next() { Next_(); } // Advance to next state (when !Done) + void Reset() { Reset_(); } // Return to initial condition + + private: + // This allows base class virtual access to non-virtual derived- + // class members of the same name. It makes the derived class more + // efficient to use but unsafe to further derive. + virtual bool Done_() const = 0; + virtual StateId Value_() const = 0; + virtual void Next_() = 0; + virtual void Reset_() = 0; +}; + + +// StateIterator initialization data + +template struct StateIteratorData { + StateIteratorBase *base; // Specialized iterator if non-zero + typename A::StateId nstates; // O.w. total # of states +}; + + +// Generic state iterator, templated on the FST definition +// - a wrapper around pointer to specific one. +// Here is a typical use: \code +// for (StateIterator siter(fst); +// !siter.Done(); +// siter.Next()) { +// StateId s = siter.Value(); +// ... +// } \endcode +template +class StateIterator { + public: + typedef F FST; + typedef typename F::Arc Arc; + typedef typename Arc::StateId StateId; + + explicit StateIterator(const F &fst) : s_(0) { + fst.InitStateIterator(&data_); + } + + ~StateIterator() { if (data_.base) delete data_.base; } + + bool Done() const { + return data_.base ? data_.base->Done() : s_ >= data_.nstates; + } + + StateId Value() const { return data_.base ? data_.base->Value() : s_; } + + void Next() { + if (data_.base) + data_.base->Next(); + else + ++s_; + } + + void Reset() { + if (data_.base) + data_.base->Reset(); + else + s_ = 0; + } + + private: + StateIteratorData data_; + StateId s_; + + DISALLOW_COPY_AND_ASSIGN(StateIterator); +}; + + +// Flags to control the behavior on an arc iterator: +static const uint32 kArcILabelValue = 0x0001; // Value() gives valid ilabel +static const uint32 kArcOLabelValue = 0x0002; // " " " olabel +static const uint32 kArcWeightValue = 0x0004; // " " " weight +static const uint32 kArcNextStateValue = 0x0008; // " " " nextstate +static const uint32 kArcNoCache = 0x0010; // No need to cache arcs + +static const uint32 kArcValueFlags = + kArcILabelValue | kArcOLabelValue | + kArcWeightValue | kArcNextStateValue; + +static const uint32 kArcFlags = kArcValueFlags | kArcNoCache; + + +// Arc iterator interface, templated on the Arc definition; used +// for Arc iterator specializations that are returned by the InitArcIterator +// Fst method. +template +class ArcIteratorBase { + public: + typedef A Arc; + typedef typename A::StateId StateId; + + virtual ~ArcIteratorBase() {} + + bool Done() const { return Done_(); } // End of iterator? + const A& Value() const { return Value_(); } // Current arc (when !Done) + void Next() { Next_(); } // Advance to next arc (when !Done) + size_t Position() const { return Position_(); } // Return current position + void Reset() { Reset_(); } // Return to initial condition + void Seek(size_t a) { Seek_(a); } // Random arc access by position + uint32 Flags() const { return Flags_(); } // Return current behavorial flags + void SetFlags(uint32 flags, uint32 mask) { // Set behavorial flags + SetFlags_(flags, mask); + } + + private: + // This allows base class virtual access to non-virtual derived- + // class members of the same name. It makes the derived class more + // efficient to use but unsafe to further derive. + virtual bool Done_() const = 0; + virtual const A& Value_() const = 0; + virtual void Next_() = 0; + virtual size_t Position_() const = 0; + virtual void Reset_() = 0; + virtual void Seek_(size_t a) = 0; + virtual uint32 Flags_() const = 0; + virtual void SetFlags_(uint32 flags, uint32 mask) = 0; +}; + + +// ArcIterator initialization data +template struct ArcIteratorData { + ArcIteratorBase *base; // Specialized iterator if non-zero + const A *arcs; // O.w. arcs pointer + size_t narcs; // ... and arc count + int *ref_count; // ... and reference count if non-zero +}; + + +// Generic arc iterator, templated on the FST definition +// - a wrapper around pointer to specific one. +// Here is a typical use: \code +// for (ArcIterator aiter(fst, s)); +// !aiter.Done(); +// aiter.Next()) { +// StdArc &arc = aiter.Value(); +// ... +// } \endcode +template +class ArcIterator { + public: + typedef F FST; + typedef typename F::Arc Arc; + typedef typename Arc::StateId StateId; + + ArcIterator(const F &fst, StateId s) : i_(0) { + fst.InitArcIterator(s, &data_); + } + + explicit ArcIterator(const ArcIteratorData &data) : data_(data), i_(0) { + if (data_.ref_count) + ++(*data_.ref_count); + } + + ~ArcIterator() { + if (data_.base) + delete data_.base; + else if (data_.ref_count) + --(*data_.ref_count); + } + + bool Done() const { + return data_.base ? data_.base->Done() : i_ >= data_.narcs; + } + + const Arc& Value() const { + return data_.base ? data_.base->Value() : data_.arcs[i_]; + } + + void Next() { + if (data_.base) + data_.base->Next(); + else + ++i_; + } + + void Reset() { + if (data_.base) + data_.base->Reset(); + else + i_ = 0; + } + + void Seek(size_t a) { + if (data_.base) + data_.base->Seek(a); + else + i_ = a; + } + + size_t Position() const { + return data_.base ? data_.base->Position() : i_; + } + + uint32 Flags() const { + if (data_.base) + return data_.base->Flags(); + else + return kArcValueFlags; + } + + void SetFlags(uint32 flags, uint32 mask) { + if (data_.base) + data_.base->SetFlags(flags, mask); + } + + private: + ArcIteratorData data_; + size_t i_; + DISALLOW_COPY_AND_ASSIGN(ArcIterator); +}; + +// +// MATCHER DEFINITIONS +// + +template +MatcherBase *Fst::InitMatcher(MatchType match_type) const { + return 0; // Use the default matcher +} + + +// +// FST ACCESSORS - Useful functions in high-performance cases. +// + +namespace internal { + +// General case - requires non-abstract, 'final' methods. Use for inlining. +template inline +typename F::Arc::Weight Final(const F &fst, typename F::Arc::StateId s) { + return fst.F::Final(s); +} + +template inline +ssize_t NumArcs(const F &fst, typename F::Arc::StateId s) { + return fst.F::NumArcs(s); +} + +template inline +ssize_t NumInputEpsilons(const F &fst, typename F::Arc::StateId s) { + return fst.F::NumInputEpsilons(s); +} + +template inline +ssize_t NumOutputEpsilons(const F &fst, typename F::Arc::StateId s) { + return fst.F::NumOutputEpsilons(s); +} + + +// Fst case - abstract methods. +template inline +typename A::Weight Final(const Fst &fst, typename A::StateId s) { + return fst.Final(s); +} + +template inline +ssize_t NumArcs(const Fst &fst, typename A::StateId s) { + return fst.NumArcs(s); +} + +template inline +ssize_t NumInputEpsilons(const Fst &fst, typename A::StateId s) { + return fst.NumInputEpsilons(s); +} + +template inline +ssize_t NumOutputEpsilons(const Fst &fst, typename A::StateId s) { + return fst.NumOutputEpsilons(s); +} + +} // namespace internal + +// A useful alias when using StdArc. +typedef Fst StdFst; + + +// +// CONSTANT DEFINITIONS +// + +const int kNoStateId = -1; // Not a valid state ID +const int kNoLabel = -1; // Not a valid label + +// +// Fst IMPLEMENTATION BASE +// +// This is the recommended Fst implementation base class. It will +// handle reference counts, property bits, type information and symbols. +// + +template class FstImpl { + public: + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + + FstImpl() + : properties_(0), type_("null"), isymbols_(0), osymbols_(0) {} + + FstImpl(const FstImpl &impl) + : properties_(impl.properties_), type_(impl.type_), + isymbols_(impl.isymbols_ ? impl.isymbols_->Copy() : 0), + osymbols_(impl.osymbols_ ? impl.osymbols_->Copy() : 0) {} + + virtual ~FstImpl() { + delete isymbols_; + delete osymbols_; + } + + const string& Type() const { return type_; } + + void SetType(const string &type) { type_ = type; } + + virtual uint64 Properties() const { return properties_; } + + virtual uint64 Properties(uint64 mask) const { return properties_ & mask; } + + void SetProperties(uint64 props) { + properties_ &= kError; // kError can't be cleared + properties_ |= props; + } + + void SetProperties(uint64 props, uint64 mask) { + properties_ &= ~mask | kError; // kError can't be cleared + properties_ |= props & mask; + } + + // Allows (only) setting error bit on const FST impls + void SetProperties(uint64 props, uint64 mask) const { + if (mask != kError) + FSTERROR() << "FstImpl::SetProperties() const: can only set kError"; + properties_ |= kError; + } + + const SymbolTable* InputSymbols() const { return isymbols_; } + + const SymbolTable* OutputSymbols() const { return osymbols_; } + + SymbolTable* InputSymbols() { return isymbols_; } + + SymbolTable* OutputSymbols() { return osymbols_; } + + void SetInputSymbols(const SymbolTable* isyms) { + if (isymbols_) delete isymbols_; + isymbols_ = isyms ? isyms->Copy() : 0; + } + + void SetOutputSymbols(const SymbolTable* osyms) { + if (osymbols_) delete osymbols_; + osymbols_ = osyms ? osyms->Copy() : 0; + } + + int RefCount() const { + return ref_count_.count(); + } + + int IncrRefCount() { + return ref_count_.Incr(); + } + + int DecrRefCount() { + return ref_count_.Decr(); + } + + // Read-in header and symbols from input stream, initialize Fst, and + // return the header. If opts.header is non-null, skip read-in and + // use the option value. If opts.[io]symbols is non-null, read-in + // (if present), but use the option value. + bool ReadHeader(istream &strm, const FstReadOptions& opts, + int min_version, FstHeader *hdr); + + // Write-out header and symbols from output stream. + // If a opts.header is false, skip writing header. + // If opts.[io]symbols is false, skip writing those symbols. + // This method is needed for Impl's that implement Write methods. + void WriteHeader(ostream &strm, const FstWriteOptions& opts, + int version, FstHeader *hdr) const { + if (opts.write_header) { + hdr->SetFstType(type_); + hdr->SetArcType(A::Type()); + hdr->SetVersion(version); + hdr->SetProperties(properties_); + int32 file_flags = 0; + if (isymbols_ && opts.write_isymbols) + file_flags |= FstHeader::HAS_ISYMBOLS; + if (osymbols_ && opts.write_osymbols) + file_flags |= FstHeader::HAS_OSYMBOLS; + if (opts.align) + file_flags |= FstHeader::IS_ALIGNED; + hdr->SetFlags(file_flags); + hdr->Write(strm, opts.source); + } + if (isymbols_ && opts.write_isymbols) isymbols_->Write(strm); + if (osymbols_ && opts.write_osymbols) osymbols_->Write(strm); + } + + // Write-out header and symbols to output stream. + // If a opts.header is false, skip writing header. + // If opts.[io]symbols is false, skip writing those symbols. + // type is the Fst type being written. + // This method is used in the cross-type serialization methods Fst::WriteFst. + static void WriteFstHeader(const Fst &fst, ostream &strm, + const FstWriteOptions& opts, int version, + const string &type, uint64 properties, + FstHeader *hdr) { + if (opts.write_header) { + hdr->SetFstType(type); + hdr->SetArcType(A::Type()); + hdr->SetVersion(version); + hdr->SetProperties(properties); + int32 file_flags = 0; + if (fst.InputSymbols() && opts.write_isymbols) + file_flags |= FstHeader::HAS_ISYMBOLS; + if (fst.OutputSymbols() && opts.write_osymbols) + file_flags |= FstHeader::HAS_OSYMBOLS; + if (opts.align) + file_flags |= FstHeader::IS_ALIGNED; + hdr->SetFlags(file_flags); + hdr->Write(strm, opts.source); + } + if (fst.InputSymbols() && opts.write_isymbols) { + fst.InputSymbols()->Write(strm); + } + if (fst.OutputSymbols() && opts.write_osymbols) { + fst.OutputSymbols()->Write(strm); + } + } + + // In serialization routines where the header cannot be written until after + // the machine has been serialized, this routine can be called to seek to + // the beginning of the file an rewrite the header with updated fields. + // It repositions the file pointer back at the end of the file. + // returns true on success, false on failure. + static bool UpdateFstHeader(const Fst &fst, ostream &strm, + const FstWriteOptions& opts, int version, + const string &type, uint64 properties, + FstHeader *hdr, size_t header_offset) { + strm.seekp(header_offset); + if (!strm) { + LOG(ERROR) << "Fst::UpdateFstHeader: write failed: " << opts.source; + return false; + } + WriteFstHeader(fst, strm, opts, version, type, properties, hdr); + if (!strm) { + LOG(ERROR) << "Fst::UpdateFstHeader: write failed: " << opts.source; + return false; + } + strm.seekp(0, ios_base::end); + if (!strm) { + LOG(ERROR) << "Fst::UpdateFstHeader: write failed: " << opts.source; + return false; + } + return true; + } + + protected: + mutable uint64 properties_; // Property bits + + private: + string type_; // Unique name of Fst class + SymbolTable *isymbols_; // Ilabel symbol table + SymbolTable *osymbols_; // Olabel symbol table + RefCounter ref_count_; // Reference count + + void operator=(const FstImpl &impl); // disallow +}; + +template inline +bool FstImpl::ReadHeader(istream &strm, const FstReadOptions& opts, + int min_version, FstHeader *hdr) { + if (opts.header) + *hdr = *opts.header; + else if (!hdr->Read(strm, opts.source)) + return false; + + if (FLAGS_v >= 2) { + LOG(INFO) << "FstImpl::ReadHeader: source: " << opts.source + << ", fst_type: " << hdr->FstType() + << ", arc_type: " << A::Type() + << ", version: " << hdr->Version() + << ", flags: " << hdr->GetFlags(); + } + + if (hdr->FstType() != type_) { + LOG(ERROR) << "FstImpl::ReadHeader: Fst not of type \"" << type_ + << "\": " << opts.source; + return false; + } + if (hdr->ArcType() != A::Type()) { + LOG(ERROR) << "FstImpl::ReadHeader: Arc not of type \"" << A::Type() + << "\": " << opts.source; + return false; + } + if (hdr->Version() < min_version) { + LOG(ERROR) << "FstImpl::ReadHeader: Obsolete " << type_ + << " Fst version: " << opts.source; + return false; + } + properties_ = hdr->Properties(); + if (hdr->GetFlags() & FstHeader::HAS_ISYMBOLS) + isymbols_ = SymbolTable::Read(strm, opts.source); + if (hdr->GetFlags() & FstHeader::HAS_OSYMBOLS) + osymbols_ =SymbolTable::Read(strm, opts.source); + + if (opts.isymbols) { + delete isymbols_; + isymbols_ = opts.isymbols->Copy(); + } + if (opts.osymbols) { + delete osymbols_; + osymbols_ = opts.osymbols->Copy(); + } + return true; +} + + +template +uint64 TestProperties(const Fst &fst, uint64 mask, uint64 *known); + + +// This is a helper class template useful for attaching an Fst interface to +// its implementation, handling reference counting. +template < class I, class F = Fst > +class ImplToFst : public F { + public: + typedef typename I::Arc Arc; + typedef typename Arc::Weight Weight; + typedef typename Arc::StateId StateId; + + virtual ~ImplToFst() { if (!impl_->DecrRefCount()) delete impl_; } + + virtual StateId Start() const { return impl_->Start(); } + + virtual Weight Final(StateId s) const { return impl_->Final(s); } + + virtual size_t NumArcs(StateId s) const { return impl_->NumArcs(s); } + + virtual size_t NumInputEpsilons(StateId s) const { + return impl_->NumInputEpsilons(s); + } + + virtual size_t NumOutputEpsilons(StateId s) const { + return impl_->NumOutputEpsilons(s); + } + + virtual uint64 Properties(uint64 mask, bool test) const { + if (test) { + uint64 knownprops, testprops = TestProperties(*this, mask, &knownprops); + impl_->SetProperties(testprops, knownprops); + return testprops & mask; + } else { + return impl_->Properties(mask); + } + } + + virtual const string& Type() const { return impl_->Type(); } + + virtual const SymbolTable* InputSymbols() const { + return impl_->InputSymbols(); + } + + virtual const SymbolTable* OutputSymbols() const { + return impl_->OutputSymbols(); + } + + protected: + ImplToFst() : impl_(0) {} + + ImplToFst(I *impl) : impl_(impl) {} + + ImplToFst(const ImplToFst &fst) { + impl_ = fst.impl_; + impl_->IncrRefCount(); + } + + // This constructor presumes there is a copy constructor for the + // implementation. + ImplToFst(const ImplToFst &fst, bool safe) { + if (safe) { + impl_ = new I(*(fst.impl_)); + } else { + impl_ = fst.impl_; + impl_->IncrRefCount(); + } + } + + I *GetImpl() const { return impl_; } + + // Change Fst implementation pointer. If 'own_impl' is true, + // ownership of the input implementation is given to this + // object; otherwise, the input implementation's reference count + // should be incremented. + void SetImpl(I *impl, bool own_impl = true) { + if (!own_impl) + impl->IncrRefCount(); + if (impl_ && !impl_->DecrRefCount()) delete impl_; + impl_ = impl; + } + + private: + // Disallow + ImplToFst &operator=(const ImplToFst &fst); + + ImplToFst &operator=(const Fst &fst) { + FSTERROR() << "ImplToFst: Assignment operator disallowed"; + GetImpl()->SetProperties(kError, kError); + return *this; + } + + I *impl_; +}; + + +// Converts FSTs by casting their implementations, where this makes +// sense (which excludes implementations with weight-dependent virtual +// methods). Must be a friend of the Fst classes involved (currently +// the concrete Fsts: VectorFst, ConstFst, CompactFst). +template void Cast(const F &ifst, G *ofst) { + ofst->SetImpl(reinterpret_cast(ifst.GetImpl()), false); +} + +// Fst Serialization +template +void FstToString(const Fst &fst, string *result) { + ostringstream ostrm; + fst.Write(ostrm, FstWriteOptions("FstToString")); + *result = ostrm.str(); +} + +template +Fst *StringToFst(const string &s) { + istringstream istrm(s); + return Fst::Read(istrm, FstReadOptions("StringToFst")); +} + +} // namespace fst + +#endif // FST_LIB_FST_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/fstlib.h b/kaldi_io/src/tools/openfst/include/fst/fstlib.h new file mode 100644 index 0000000..de5976d --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/fstlib.h @@ -0,0 +1,153 @@ +// fstlib.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \page FstLib FST - Weighted Finite State Transducers +// This is a library for constructing, combining, optimizing, and +// searching "weighted finite-state transducers" (FSTs). Weighted +// finite-state transducers are automata where each transition has an +// input label, an output label, and a weight. The more familiar +// finite-state acceptor is represented as a transducer with each +// transition's input and output the same. Finite-state acceptors +// are used to represent sets of strings (specifically, "regular" or +// "rational sets"); finite-state transducers are used to represent +// binary relations between pairs of strings (specifically, "rational +// transductions"). The weights can be used to represent the cost of +// taking a particular transition. +// +// In this library, the transducers are templated on the Arc +// (transition) definition, which allows changing the label, weight, +// and state ID sets. Labels and state IDs are restricted to signed +// integral types but the weight can be an arbitrary type whose +// members satisfy certain algebraic ("semiring") properties. +// +// For more information, see the FST Library Wiki page: +// http://wiki.corp.google.com/twiki/bin/view/Main/FstLibrary + +// \file +// This convenience file includes all other FST inl.h files. +// + +#ifndef FST_LIB_FSTLIB_H__ +#define FST_LIB_FSTLIB_H__ + + +// Abstract FST classes +#include +#include +#include + +// Concrete FST classes +#include +#include +#include +#include + +// FST algorithms and delayed FST classes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Weights +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Auxiliary classes for composition +#include +#include +#include +#include +#include +#include + +// Data structures +#include +#include +#include +#include + +// Miscellaneous +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#endif // FST_LIB_FSTLIB_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/generic-register.h b/kaldi_io/src/tools/openfst/include/fst/generic-register.h new file mode 100644 index 0000000..4f8b512 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/generic-register.h @@ -0,0 +1,159 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_LIB_GENERIC_REGISTER_H_ +#define FST_LIB_GENERIC_REGISTER_H_ + +#include +#include + +#include +#include + +// Generic class representing a globally-stored correspondence between +// objects of KeyType and EntryType. +// KeyType must: +// a) be such as can be stored as a key in a map<> +// b) be concatenable with a const char* with the + operator +// (or you must subclass and redefine LoadEntryFromSharedObject) +// EntryType must be default constructible. +// +// The third template parameter should be the type of a subclass of this class +// (think CRTP). This is to allow GetRegister() to instantiate and return +// an object of the appropriate type. + +namespace fst { + +template +class GenericRegister { + public: + typedef KeyType Key; + typedef EntryType Entry; + + static RegisterType *GetRegister() { + FstOnceInit(®ister_init_, + &RegisterType::Init); + + return register_; + } + + void SetEntry(const KeyType &key, + const EntryType &entry) { + MutexLock l(register_lock_); + + register_table_.insert(make_pair(key, entry)); + } + + EntryType GetEntry(const KeyType &key) const { + const EntryType *entry = LookupEntry(key); + if (entry) { + return *entry; + } else { + return LoadEntryFromSharedObject(key); + } + } + + virtual ~GenericRegister() { } + + protected: + // Override this if you want to be able to load missing definitions from + // shared object files. + virtual EntryType LoadEntryFromSharedObject(const KeyType &key) const { + string so_filename = ConvertKeyToSoFilename(key); + + void *handle = dlopen(so_filename.c_str(), RTLD_LAZY); + if (handle == 0) { + LOG(ERROR) << "GenericRegister::GetEntry : " << dlerror(); + return EntryType(); + } + + // We assume that the DSO constructs a static object in its global + // scope that does the registration. Thus we need only load it, not + // call any methods. + const EntryType *entry = this->LookupEntry(key); + if (entry == 0) { + LOG(ERROR) << "GenericRegister::GetEntry : " + << "lookup failed in shared object: " << so_filename; + return EntryType(); + } + return *entry; + } + + // Override this to define how to turn a key into an SO filename. + virtual string ConvertKeyToSoFilename(const KeyType& key) const = 0; + + virtual const EntryType *LookupEntry( + const KeyType &key) const { + MutexLock l(register_lock_); + + typename RegisterMapType::const_iterator it = register_table_.find(key); + + if (it != register_table_.end()) { + return &it->second; + } else { + return 0; + } + } + + private: + typedef map RegisterMapType; + + static void Init() { + register_lock_ = new Mutex; + register_ = new RegisterType; + } + + static FstOnceType register_init_; + static Mutex *register_lock_; + static RegisterType *register_; + + RegisterMapType register_table_; +}; + +template +FstOnceType GenericRegister::register_init_ = FST_ONCE_INIT; + +template +Mutex *GenericRegister::register_lock_ = 0; + +template +RegisterType *GenericRegister::register_ = 0; + +// +// GENERIC REGISTRATION +// + +// Generic register-er class capable of creating new register entries in the +// given RegisterType template parameter. This type must define types Key +// and Entry, and have appropriate static GetRegister() and instance +// SetEntry() functions. An easy way to accomplish this is to have RegisterType +// be the type of a subclass of GenericRegister. +template +class GenericRegisterer { + public: + typedef typename RegisterType::Key Key; + typedef typename RegisterType::Entry Entry; + + GenericRegisterer(Key key, Entry entry) { + RegisterType *reg = RegisterType::GetRegister(); + reg->SetEntry(key, entry); + } +}; + +} // namespace fst + +#endif // FST_LIB_GENERIC_REGISTER_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/heap.h b/kaldi_io/src/tools/openfst/include/fst/heap.h new file mode 100644 index 0000000..a7affbd --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/heap.h @@ -0,0 +1,206 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// All Rights Reserved. +// Author: Johan Schalkwyk (johans@google.com) +// +// \file +// Implementation of a heap as in STL, but allows tracking positions +// in heap using a key. The key can be used to do an in-place update of +// values in the heap. + +#ifndef FST_LIB_HEAP_H__ +#define FST_LIB_HEAP_H__ + +#include +using std::vector; +#include + +#include +namespace fst { + +// +// \class Heap +// \brief A templated heap implementation that support in-place update +// of values. +// +// The templated heap implementation is a little different from the +// STL priority_queue and the *_heap operations in STL. This heap +// supports indexing of values in the heap via an associated key. +// +// Each value is internally associated with a key which is returned +// to the calling functions on heap insert. This key can be used +// to later update the specific value in the heap. +// +// \param T the element type of the hash, can be POD, Data or Ptr to Data +// \param Compare Comparison class for determiningg min-heapness. +// \param whether heap top should be max or min element w.r.t. Compare +// + +static const int kNoKey = -1; +template +class Heap { + public: + + // Initialize with a specific comparator + Heap(Compare comp) : comp_(comp), size_(0) { } + + // Create a heap with initial size of internal arrays of 0 + Heap() : size_(0) { } + + ~Heap() { } + + // Insert a value into the heap + int Insert(const T& val) { + if (size_ < A_.size()) { + A_[size_] = val; + pos_[key_[size_]] = size_; + } else { + A_.push_back(val); + pos_.push_back(size_); + key_.push_back(size_); + } + + ++size_; + return Insert(val, size_ - 1); + } + + // Update a value at position given by the key. The pos array is first + // indexed by the key. The position gives the position in the heap array. + // Once we have the position we can then use the standard heap operations + // to calculate the parent and child positions. + void Update(int key, const T& val) { + int i = pos_[key]; + if (Better(val, A_[Parent(i)])) { + Insert(val, i); + } else { + A_[i] = val; + Heapify(i); + } + } + + // Return the greatest (max=true) / least (max=false) value w.r.t. + // from the heap. + T Pop() { + T top = A_[0]; + + Swap(0, size_-1); + size_--; + Heapify(0); + return top; + } + + // Return the greatest (max=true) / least (max=false) value w.r.t. + // comp object from the heap. + T Top() const { + return A_[0]; + } + + // Check if the heap is empty + bool Empty() const { + return size_ == 0; + } + + void Clear() { + size_ = 0; + } + + + // + // The following protected routines are used in a supportive role + // for managing the heap and keeping the heap properties. + // + private: + // Compute left child of parent + int Left(int i) { + return 2*(i+1)-1; // 0 -> 1, 1 -> 3 + } + + // Compute right child of parent + int Right(int i) { + return 2*(i+1); // 0 -> 2, 1 -> 4 + } + + // Given a child compute parent + int Parent(int i) { + return (i-1)/2; // 1 -> 0, 2 -> 0, 3 -> 1, 4-> 1 + } + + // Swap a child, parent. Use to move element up/down tree. + // Note a little tricky here. When we swap we need to swap: + // the value + // the associated keys + // the position of the value in the heap + void Swap(int j, int k) { + int tkey = key_[j]; + pos_[key_[j] = key_[k]] = j; + pos_[key_[k] = tkey] = k; + + T val = A_[j]; + A_[j] = A_[k]; + A_[k] = val; + } + + // Returns the greater (max=true) / least (max=false) of two + // elements. + bool Better(const T& x, const T& y) { + return max ? comp_(y, x) : comp_(x, y); + } + + // Heapify subtree rooted at index i. + void Heapify(int i) { + int l = Left(i); + int r = Right(i); + int largest; + + if (l < size_ && Better(A_[l], A_[i]) ) + largest = l; + else + largest = i; + + if (r < size_ && Better(A_[r], A_[largest]) ) + largest = r; + + if (largest != i) { + Swap(i, largest); + Heapify(largest); + } + } + + + // Insert (update) element at subtree rooted at index i + int Insert(const T& val, int i) { + int p; + while (i > 0 && !Better(A_[p = Parent(i)], val)) { + Swap(i, p); + i = p; + } + + return key_[i]; + } + + private: + Compare comp_; + + vector pos_; + vector key_; + vector A_; + int size_; + + // DISALLOW_COPY_AND_ASSIGN(Heap); +}; + +} // namespace fst + +#endif // FST_LIB_HEAP_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/icu.h b/kaldi_io/src/tools/openfst/include/fst/icu.h new file mode 100644 index 0000000..3947716 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/icu.h @@ -0,0 +1,116 @@ +// icu.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: sorenj@google.com (Jeffrey Sorensen) +// roubert@google.com (Fredrik Roubert) +// +// This library implements an unrestricted Thompson/Pike UTF-8 parser and +// serializer. UTF-8 is a restricted subset of this byte stream encoding. See +// http://en.wikipedia.org/wiki/UTF-8 for a good description of the encoding +// details. + +#ifndef FST_LIB_ICU_H_ +#define FST_LIB_ICU_H_ + +#include +#include +#include + +namespace fst { + +template +bool UTF8StringToLabels(const string &str, vector { + public: + using ComposeFst::CreateBase; + using ComposeFst::CreateBase1; + using ComposeFst::Properties; + using ImplToFst< ComposeFstImplBase >::GetImpl; + using ImplToFst< ComposeFstImplBase >::SetImpl; + + typedef A Arc; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + + IntersectFst(const Fst &fst1, const Fst &fst2, + const CacheOptions opts = CacheOptions()) { + bool acceptors = fst1.Properties(kAcceptor, true) && + fst2.Properties(kAcceptor, true); + SetImpl(CreateBase(fst1, fst2, opts)); + if (!acceptors) { + FSTERROR() << "IntersectFst: input FSTs are not acceptors"; + GetImpl()->SetProperties(kError); + } + } + + template + IntersectFst(const Fst &fst1, const Fst &fst2, + const IntersectFstOptions &opts) { + bool acceptors = fst1.Properties(kAcceptor, true) && + fst2.Properties(kAcceptor, true); + SetImpl(CreateBase1(fst1, fst2, opts)); + if (!acceptors) { + FSTERROR() << "IntersectFst: input FSTs are not acceptors"; + GetImpl()->SetProperties(kError); + } + } + + // See Fst<>::Copy() for doc. + IntersectFst(const IntersectFst &fst, bool safe = false) : + ComposeFst(fst, safe) {} + + // Get a copy of this IntersectFst. See Fst<>::Copy() for further doc. + virtual IntersectFst *Copy(bool safe = false) const { + return new IntersectFst(*this, safe); + } +}; + + +// Specialization for IntersectFst. +template +class StateIterator< IntersectFst > + : public StateIterator< ComposeFst > { + public: + explicit StateIterator(const IntersectFst &fst) + : StateIterator< ComposeFst >(fst) {} +}; + + +// Specialization for IntersectFst. +template +class ArcIterator< IntersectFst > + : public ArcIterator< ComposeFst > { + public: + typedef typename A::StateId StateId; + + ArcIterator(const IntersectFst &fst, StateId s) + : ArcIterator< ComposeFst >(fst, s) {} +}; + +// Useful alias when using StdArc. +typedef IntersectFst StdIntersectFst; + + +typedef ComposeOptions IntersectOptions; + + +// Computes the intersection (Hadamard product) of two FSAs. This +// version writes the intersection to an output MurableFst. Only +// strings that are in both automata are retained in the result. +// +// The two arguments must be acceptors. One of the arguments must be +// label-sorted. +// +// Complexity: same as Compose. +// +// Caveats: same as Compose. +template +void Intersect(const Fst &ifst1, const Fst &ifst2, + MutableFst *ofst, + const IntersectOptions &opts = IntersectOptions()) { + typedef Matcher< Fst > M; + + if (opts.filter_type == AUTO_FILTER) { + CacheOptions nopts; + nopts.gc_limit = 0; // Cache only the last state for fastest copy. + *ofst = IntersectFst(ifst1, ifst2, nopts); + } else if (opts.filter_type == SEQUENCE_FILTER) { + IntersectFstOptions iopts; + iopts.gc_limit = 0; // Cache only the last state for fastest copy. + *ofst = IntersectFst(ifst1, ifst2, iopts); + } else if (opts.filter_type == ALT_SEQUENCE_FILTER) { + IntersectFstOptions > iopts; + iopts.gc_limit = 0; // Cache only the last state for fastest copy. + *ofst = IntersectFst(ifst1, ifst2, iopts); + } else if (opts.filter_type == MATCH_FILTER) { + IntersectFstOptions > iopts; + iopts.gc_limit = 0; // Cache only the last state for fastest copy. + *ofst = IntersectFst(ifst1, ifst2, iopts); + } + + if (opts.connect) + Connect(ofst); +} + +} // namespace fst + +#endif // FST_LIB_INTERSECT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/interval-set.h b/kaldi_io/src/tools/openfst/include/fst/interval-set.h new file mode 100644 index 0000000..58cad44 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/interval-set.h @@ -0,0 +1,381 @@ +// interval-set.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Class to represent and operate on sets of intervals. + +#ifndef FST_LIB_INTERVAL_SET_H__ +#define FST_LIB_INTERVAL_SET_H__ + +#include +#include +using std::vector; + + +#include + + +namespace fst { + +// Stores and operates on a set of half-open integral intervals [a,b) +// of signed integers of type T. +template +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; + } + }; + + IntervalSet() : count_(-1) {} + + // Returns the interval set as a vector. + vector *Intervals() { return &intervals_; } + + const vector *Intervals() const { return &intervals_; } + + bool Empty() const { return intervals_.empty(); } + + T Size() const { return intervals_.size(); } + + // Number of points in the intervals (undefined if not normalized). + T Count() const { return count_; } + + void Clear() { + intervals_.clear(); + count_ = 0; + } + + // Adds an interval set to the set. The result may not be normalized. + void Union(const IntervalSet &iset) { + const vector *intervals = iset.Intervals(); + for (typename vector::const_iterator it = intervals->begin(); + it != intervals->end(); ++it) + intervals_.push_back(*it); + } + + // Requires intervals be normalized. + bool Member(T value) const { + Interval interval(value, value); + typename vector::const_iterator lb = + lower_bound(intervals_.begin(), intervals_.end(), interval); + if (lb == intervals_.begin()) + return false; + return (--lb)->end_ > value; + } + + // Requires intervals be normalized. + bool operator==(const IntervalSet& iset) const { + return *(iset.Intervals()) == intervals_; + } + + // Requires intervals be normalized. + bool operator!=(const IntervalSet& iset) const { + return *(iset.Intervals()) != intervals_; + } + + bool Singleton() const { + return intervals_.size() == 1 && + intervals_[0].begin_ + 1 == intervals_[0].end_; + } + + + // Sorts; collapses overlapping and adjacent interals; sets count. + void Normalize(); + + // Intersects an interval set with the set. Requires intervals be + // normalized. The result is normalized. + void Intersect(const IntervalSet &iset, IntervalSet *oset) const; + + // Complements the set w.r.t [0, maxval). Requires intervals be + // normalized. The result is normalized. + void Complement(T maxval, IntervalSet *oset) const; + + // Subtract an interval set from the set. Requires intervals be + // normalized. The result is normalized. + void Difference(const IntervalSet &iset, IntervalSet *oset) const; + + // Determines if an interval set overlaps with the set. Requires + // intervals be normalized. + bool Overlaps(const IntervalSet &iset) const; + + // Determines if an interval set overlaps with the set but neither + // is contained in the other. Requires intervals be normalized. + bool StrictlyOverlaps(const IntervalSet &iset) const; + + // Determines if an interval set is contained within the set. Requires + // intervals be normalized. + bool Contains(const IntervalSet &iset) const; + + istream &Read(istream &strm) { + ReadType(strm, &intervals_); + return ReadType(strm, &count_); + } + + ostream &Write(ostream &strm) const { + WriteType(strm, intervals_); + return WriteType(strm, count_); + } + + private: + vector intervals_; + T count_; +}; + +// Sorts; collapses overlapping and adjacent interavls; sets count. +template +void IntervalSet::Normalize() { + sort(intervals_.begin(), intervals_.end()); + + count_ = 0; + 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); +} + +// Intersects an interval set with the set. Requires intervals be normalized. +// The result is normalized. +template +void IntervalSet::Intersect(const IntervalSet &iset, + IntervalSet *oset) const { + const vector *iintervals = iset.Intervals(); + vector *ointervals = oset->Intervals(); + typename vector::const_iterator it1 = intervals_.begin(); + typename vector::const_iterator it2 = iintervals->begin(); + + ointervals->clear(); + 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; + } + } +} + +// Complements the set w.r.t [0, maxval). Requires intervals be normalized. +// The result is normalized. +template +void IntervalSet::Complement(T maxval, IntervalSet *oset) const { + vector *ointervals = oset->Intervals(); + ointervals->clear(); + oset->count_ = 0; + + Interval interval; + interval.begin_ = 0; + for (typename vector::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_; + } +} + +// Subtract an interval set from the set. Requires intervals be normalized. +// The result is normalized. +template +void IntervalSet::Difference(const IntervalSet &iset, + IntervalSet *oset) const { + if (intervals_.empty()) { + oset->Intervals()->clear(); + oset->count_ = 0; + } else { + IntervalSet cset; + iset.Complement(intervals_.back().end_, &cset); + Intersect(cset, oset); + } +} + +// Determines if an interval set overlaps with the set. Requires +// intervals be normalized. +template +bool IntervalSet::Overlaps(const IntervalSet &iset) const { + const vector *intervals = iset.Intervals(); + typename vector::const_iterator it1 = intervals_.begin(); + typename vector::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; + } + } + return false; +} + +// Determines if an interval set overlaps with the set but neither +// is contained in the other. Requires intervals be normalized. +template +bool IntervalSet::StrictlyOverlaps(const IntervalSet &iset) const { + const vector *intervals = iset.Intervals(); + typename vector::const_iterator it1 = intervals_.begin(); + typename vector::const_iterator it2 = intervals->begin(); + bool only1 = false; // point in intervals_ but not intervals + bool only2 = false; // point in intervals but not intervals_ + 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; + } else { // strict overlap + only1 = true; + only2 = true; + overlap = true; + } + if (only1 == true && only2 == true && overlap == true) + return true; + } + if (it1 != intervals_.end()) + only1 = true; + if (it2 != intervals->end()) + only2 = true; + + return only1 == true && only2 == true && overlap == true; +} + +// Determines if an interval set is contained within the set. Requires +// intervals be normalized. +template +bool IntervalSet::Contains(const IntervalSet &iset) const { + if (iset.Count() > Count()) + return false; + + const vector *intervals = iset.Intervals(); + typename vector::const_iterator it1 = intervals_.begin(); + typename vector::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 { + ++it2; + } + } + return it2 == intervals->end(); +} + +template +ostream &operator<<(ostream &strm, const IntervalSet &s) { + typedef typename IntervalSet::Interval Interval; + const vector *intervals = s.Intervals(); + strm << "{"; + for (typename vector::const_iterator it = intervals->begin(); + it != intervals->end(); + ++it) { + if (it != intervals->begin()) + strm << ","; + strm << "[" << it->begin_ << "," << it->end_ << ")"; + } + strm << "}"; + return strm; +} + +} // namespace fst + +#endif // FST_LIB_INTERVAL_SET_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/invert.h b/kaldi_io/src/tools/openfst/include/fst/invert.h new file mode 100644 index 0000000..bc83a5d --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/invert.h @@ -0,0 +1,125 @@ +// invert.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Functions and classes to invert an Fst. + +#ifndef FST_LIB_INVERT_H__ +#define FST_LIB_INVERT_H__ + +#include +#include + + +namespace fst { + +// Mapper to implement inversion of an arc. +template struct InvertMapper { + InvertMapper() {} + + A operator()(const A &arc) { + return A(arc.olabel, arc.ilabel, arc.weight, arc.nextstate); + } + + MapFinalAction FinalAction() const { return MAP_NO_SUPERFINAL; } + + MapSymbolsAction InputSymbolsAction() const { return MAP_CLEAR_SYMBOLS; } + + MapSymbolsAction OutputSymbolsAction() const { return MAP_CLEAR_SYMBOLS;} + + uint64 Properties(uint64 props) { return InvertProperties(props); } +}; + + +// Inverts the transduction corresponding to an FST by exchanging the +// FST's input and output labels. This version modifies its input. +// +// Complexity: +// - Time: O(V + E) +// - Space: O(1) +// where V = # of states and E = # of arcs. +template inline +void Invert(MutableFst *fst) { + SymbolTable *input = fst->InputSymbols() ? fst->InputSymbols()->Copy() : 0; + SymbolTable *output = fst->OutputSymbols() ? fst->OutputSymbols()->Copy() : 0; + ArcMap(fst, InvertMapper()); + fst->SetInputSymbols(output); + fst->SetOutputSymbols(input); + delete input; + delete output; +} + + +// Inverts the transduction corresponding to an FST by exchanging the +// FST's input and output labels. This version is a delayed Fst. +// +// Complexity: +// - Time: O(v + e) +// - Space: O(1) +// where v = # of states visited, e = # of arcs visited. Constant +// time and to visit an input state or arc is assumed and exclusive +// of caching. +template +class InvertFst : public ArcMapFst > { + public: + typedef A Arc; + typedef InvertMapper C; + typedef ArcMapFstImpl< A, A, InvertMapper > Impl; + using ImplToFst::GetImpl; + + explicit InvertFst(const Fst &fst) : ArcMapFst(fst, C()) { + GetImpl()->SetOutputSymbols(fst.InputSymbols()); + GetImpl()->SetInputSymbols(fst.OutputSymbols()); + } + + // See Fst<>::Copy() for doc. + InvertFst(const InvertFst &fst, bool safe = false) + : ArcMapFst(fst, safe) {} + + // Get a copy of this InvertFst. See Fst<>::Copy() for further doc. + virtual InvertFst *Copy(bool safe = false) const { + return new InvertFst(*this, safe); + } +}; + + +// Specialization for InvertFst. +template +class StateIterator< InvertFst > + : public StateIterator< ArcMapFst > > { + public: + explicit StateIterator(const InvertFst &fst) + : StateIterator< ArcMapFst > >(fst) {} +}; + + +// Specialization for InvertFst. +template +class ArcIterator< InvertFst > + : public ArcIterator< ArcMapFst > > { + public: + ArcIterator(const InvertFst &fst, typename A::StateId s) + : ArcIterator< ArcMapFst > >(fst, s) {} +}; + + +// Useful alias when using StdArc. +typedef InvertFst StdInvertFst; + +} // namespace fst + +#endif // FST_LIB_INVERT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/label-reachable.h b/kaldi_io/src/tools/openfst/include/fst/label-reachable.h new file mode 100644 index 0000000..af06eef --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/label-reachable.h @@ -0,0 +1,565 @@ +// label_reachable.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Class to determine if a non-epsilon label can be read as the +// first non-epsilon symbol along some path from a given state. + + +#ifndef FST_LIB_LABEL_REACHABLE_H__ +#define FST_LIB_LABEL_REACHABLE_H__ + +#include +using std::tr1::unordered_map; +using std::tr1::unordered_multimap; +#include +using std::vector; + +#include +#include +#include +#include +#include + + +namespace fst { + +// Stores shareable data for label reachable class copies. +template +class LabelReachableData { + public: + typedef L Label; + typedef typename IntervalSet::Interval Interval; + + explicit LabelReachableData(bool reach_input, bool keep_relabel_data = true) + : reach_input_(reach_input), + keep_relabel_data_(keep_relabel_data), + have_relabel_data_(true), + final_label_(kNoLabel) {} + + ~LabelReachableData() {} + + bool ReachInput() const { return reach_input_; } + + vector< IntervalSet > *IntervalSets() { return &isets_; } + + unordered_map *Label2Index() { + if (!have_relabel_data_) + FSTERROR() << "LabelReachableData: no relabeling data"; + return &label2index_; + } + + Label FinalLabel() { + if (final_label_ == kNoLabel) + final_label_ = label2index_[kNoLabel]; + return final_label_; + } + + static LabelReachableData *Read(istream &istrm) { + LabelReachableData *data = new LabelReachableData(); + + ReadType(istrm, &data->reach_input_); + ReadType(istrm, &data->keep_relabel_data_); + data->have_relabel_data_ = data->keep_relabel_data_; + if (data->keep_relabel_data_) + ReadType(istrm, &data->label2index_); + ReadType(istrm, &data->final_label_); + ReadType(istrm, &data->isets_); + return data; + } + + bool Write(ostream &ostrm) { + WriteType(ostrm, reach_input_); + WriteType(ostrm, keep_relabel_data_); + if (keep_relabel_data_) + WriteType(ostrm, label2index_); + WriteType(ostrm, FinalLabel()); + WriteType(ostrm, isets_); + return true; + } + + int RefCount() const { return ref_count_.count(); } + int IncrRefCount() { return ref_count_.Incr(); } + int DecrRefCount() { return ref_count_.Decr(); } + + private: + LabelReachableData() {} + + bool reach_input_; // Input or output labels considered? + bool keep_relabel_data_; // Save label2index_ to file? + bool have_relabel_data_; // Using label2index_? + Label final_label_; // Final label + RefCounter ref_count_; // Reference count. + unordered_map label2index_; // Finds index for a label. + vector > isets_; // Interval sets per state. + + DISALLOW_COPY_AND_ASSIGN(LabelReachableData); +}; + + +// Tests reachability of labels from a given state. If reach_input = +// true, then input labels are considered, o.w. output labels are +// considered. To test for reachability from a state s, first do +// SetState(s). Then a label l can be reached from state s of FST f +// iff Reach(r) is true where r = Relabel(l). The relabeling is +// required to ensure a compact representation of the reachable +// labels. + +// The whole FST can be relabeled instead with Relabel(&f, +// reach_input) so that the test Reach(r) applies directly to the +// labels of the transformed FST f. The relabeled FST will also be +// sorted appropriately for composition. +// +// Reachablity of a final state from state s (via an epsilon path) +// can be tested with ReachFinal(); +// +// Reachability can also be tested on the set of labels specified by +// an arc iterator, useful for FST composition. In particular, +// Reach(aiter, ...) is true if labels on the input (output) side of +// the transitions of the arc iterator, when iter_input is true +// (false), can be reached from the state s. The iterator labels must +// have already been relabeled. +// +// With the arc iterator test of reachability, the begin position, end +// position and accumulated arc weight of the matches can be +// returned. The optional template argument controls how reachable arc +// weights are accumulated. The default uses the semiring +// Plus(). Alternative ones can be used to distribute the weights in +// composition in various ways. +template > +class LabelReachable { + public: + typedef A Arc; + typedef typename A::StateId StateId; + typedef typename A::Label Label; + typedef typename A::Weight Weight; + typedef typename IntervalSet &fst, bool reach_input, S *s = 0, + bool keep_relabel_data = true) + : fst_(new VectorFst(fst)), + s_(kNoStateId), + data_(new LabelReachableData > M; + typedef SequenceComposeFilter ComposeFilter; + typedef M FstMatcher; +}; + +// Specializes for MATCH_INPUT to allow lookahead. +template +class DefaultLookAhead { + public: + typedef LookAheadMatcher< Fst > M; + typedef SequenceComposeFilter SF; + typedef LookAheadComposeFilter ComposeFilter; + typedef M FstMatcher; +}; + +// Specializes for MATCH_OUTPUT to allow lookahead. +template +class DefaultLookAhead { + public: + typedef LookAheadMatcher< Fst > M; + typedef AltSequenceComposeFilter SF; + typedef LookAheadComposeFilter ComposeFilter; + typedef M FstMatcher; +}; + +// Specializes for StdArc to allow weight and label pushing. +template <> +class DefaultLookAhead { + public: + typedef StdArc A; + typedef LookAheadMatcher< Fst > M; + typedef SequenceComposeFilter SF; + typedef LookAheadComposeFilter LF; + typedef PushWeightsComposeFilter WF; + typedef PushLabelsComposeFilter ComposeFilter; + typedef M FstMatcher; +}; + +// Specializes for StdArc to allow weight and label pushing. +template <> +class DefaultLookAhead { + public: + typedef StdArc A; + typedef LookAheadMatcher< Fst > M; + typedef AltSequenceComposeFilter SF; + typedef LookAheadComposeFilter LF; + typedef PushWeightsComposeFilter WF; + typedef PushLabelsComposeFilter ComposeFilter; + typedef M FstMatcher; +}; + +// Specializes for LogArc to allow weight and label pushing. +template <> +class DefaultLookAhead { + public: + typedef LogArc A; + typedef LookAheadMatcher< Fst > M; + typedef SequenceComposeFilter SF; + typedef LookAheadComposeFilter LF; + typedef PushWeightsComposeFilter WF; + typedef PushLabelsComposeFilter ComposeFilter; + typedef M FstMatcher; +}; + +// Specializes for LogArc to allow weight and label pushing. +template <> +class DefaultLookAhead { + public: + typedef LogArc A; + typedef LookAheadMatcher< Fst > M; + typedef AltSequenceComposeFilter SF; + typedef LookAheadComposeFilter LF; + typedef PushWeightsComposeFilter WF; + typedef PushLabelsComposeFilter ComposeFilter; + typedef M FstMatcher; +}; + +} // namespace fst + +#endif // FST_LIB_LOOKAHEAD_FILTER_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/lookahead-matcher.h b/kaldi_io/src/tools/openfst/include/fst/lookahead-matcher.h new file mode 100644 index 0000000..f927d65 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/lookahead-matcher.h @@ -0,0 +1,812 @@ +// lookahead-matcher.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Classes to add lookahead to FST matchers, useful e.g. for improving +// composition efficiency with certain inputs. + +#ifndef FST_LIB_LOOKAHEAD_MATCHER_H__ +#define FST_LIB_LOOKAHEAD_MATCHER_H__ + +#include +#include +#include +#include +#include + + +DECLARE_string(save_relabel_ipairs); +DECLARE_string(save_relabel_opairs); + +namespace fst { + +// LOOKAHEAD MATCHERS - these have the interface of Matchers (see +// matcher.h) and these additional methods: +// +// template +// class LookAheadMatcher { +// public: +// typedef F FST; +// typedef F::Arc Arc; +// typedef typename Arc::StateId StateId; +// typedef typename Arc::Label Label; +// typedef typename Arc::Weight Weight; +// +// // Required constructors. +// LookAheadMatcher(const F &fst, MatchType match_type); +// // If safe=true, the copy is thread-safe (except the lookahead Fst is +// // preserved). See Fst<>::Cop() for further doc. +// LookAheadMatcher(const LookAheadMatcher &matcher, bool safe = false); +// +// Below are methods for looking ahead for a match to a label and +// more generally, to a rational set. Each returns false if there is +// definitely not a match and returns true if there possibly is a +// match. + +// // LABEL LOOKAHEAD: Can 'label' be read from the current matcher state +// // after possibly following epsilon transitions? +// bool LookAheadLabel(Label label) const; +// +// // RATIONAL LOOKAHEAD: The next methods allow looking ahead for an +// // arbitrary rational set of strings, specified by an FST and a state +// // from which to begin the matching. If the lookahead FST is a +// // transducer, this looks on the side different from the matcher +// // 'match_type' (cf. composition). +// +// // Are there paths P from 's' in the lookahead FST that can be read from +// // the cur. matcher state? +// bool LookAheadFst(const Fst& fst, StateId s); +// +// // Gives an estimate of the combined weight of the paths P in the +// // lookahead and matcher FSTs for the last call to LookAheadFst. +// // A trivial implementation returns Weight::One(). Non-trivial +// // implementations are useful for weight-pushing in composition. +// Weight LookAheadWeight() const; +// +// // Is there is a single non-epsilon arc found in the lookahead FST +// // that begins P (after possibly following any epsilons) in the last +// // call LookAheadFst? If so, return true and copy it to '*arc', o.w. +// // return false. A trivial implementation returns false. Non-trivial +// // implementations are useful for label-pushing in composition. +// bool LookAheadPrefix(Arc *arc); +// +// // Optionally pre-specifies the lookahead FST that will be passed +// // to LookAheadFst() for possible precomputation. If copy is true, +// // then 'fst' is a copy of the FST used in the previous call to +// // this method (useful to avoid unnecessary updates). +// void InitLookAheadFst(const Fst& fst, bool copy = false); +// +// }; + +// +// LOOK-AHEAD FLAGS (see also kMatcherFlags in matcher.h): +// +// Matcher is a lookahead matcher when 'match_type' is MATCH_INPUT. +const uint32 kInputLookAheadMatcher = 0x00000010; + +// Matcher is a lookahead matcher when 'match_type' is MATCH_OUTPUT. +const uint32 kOutputLookAheadMatcher = 0x00000020; + +// A non-trivial implementation of LookAheadWeight() method defined and +// should be used? +const uint32 kLookAheadWeight = 0x00000040; + +// A non-trivial implementation of LookAheadPrefix() method defined and +// should be used? +const uint32 kLookAheadPrefix = 0x00000080; + +// Look-ahead of matcher FST non-epsilon arcs? +const uint32 kLookAheadNonEpsilons = 0x00000100; + +// Look-ahead of matcher FST epsilon arcs? +const uint32 kLookAheadEpsilons = 0x00000200; + +// Ignore epsilon paths for the lookahead prefix? Note this gives +// correct results in composition only with an appropriate composition +// filter since it depends on the filter blocking the ignored paths. +const uint32 kLookAheadNonEpsilonPrefix = 0x00000400; + +// For LabelLookAheadMatcher, save relabeling data to file +const uint32 kLookAheadKeepRelabelData = 0x00000800; + +// Flags used for lookahead matchers. +const uint32 kLookAheadFlags = 0x00000ff0; + +// LookAhead Matcher interface, templated on the Arc definition; used +// for lookahead matcher specializations that are returned by the +// InitMatcher() Fst method. +template +class LookAheadMatcherBase : public MatcherBase { + public: + typedef A Arc; + typedef typename A::StateId StateId; + typedef typename A::Label Label; + typedef typename A::Weight Weight; + + LookAheadMatcherBase() + : weight_(Weight::One()), + prefix_arc_(kNoLabel, kNoLabel, Weight::One(), kNoStateId) {} + + virtual ~LookAheadMatcherBase() {} + + bool LookAheadLabel(Label label) const { return LookAheadLabel_(label); } + + bool LookAheadFst(const Fst &fst, StateId s) { + return LookAheadFst_(fst, s); + } + + Weight LookAheadWeight() const { return weight_; } + + bool LookAheadPrefix(Arc *arc) const { + if (prefix_arc_.nextstate != kNoStateId) { + *arc = prefix_arc_; + return true; + } else { + return false; + } + } + + virtual void InitLookAheadFst(const Fst& fst, bool copy = false) = 0; + + protected: + void SetLookAheadWeight(const Weight &w) { weight_ = w; } + + void SetLookAheadPrefix(const Arc &arc) { prefix_arc_ = arc; } + + void ClearLookAheadPrefix() { prefix_arc_.nextstate = kNoStateId; } + + private: + virtual bool LookAheadLabel_(Label label) const = 0; + virtual bool LookAheadFst_(const Fst &fst, + StateId s) = 0; // This must set l.a. weight and + // prefix if non-trivial. + Weight weight_; // Look-ahead weight + Arc prefix_arc_; // Look-ahead prefix arc +}; + + +// Don't really lookahead, just declare future looks good regardless. +template +class TrivialLookAheadMatcher + : public LookAheadMatcherBase { + public: + typedef typename M::FST FST; + typedef typename M::Arc Arc; + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + + TrivialLookAheadMatcher(const FST &fst, MatchType match_type) + : matcher_(fst, match_type) {} + + TrivialLookAheadMatcher(const TrivialLookAheadMatcher &lmatcher, + bool safe = false) + : matcher_(lmatcher.matcher_, safe) {} + + // General matcher methods + TrivialLookAheadMatcher *Copy(bool safe = false) const { + return new TrivialLookAheadMatcher(*this, safe); + } + + MatchType Type(bool test) const { return matcher_.Type(test); } + void SetState(StateId s) { return matcher_.SetState(s); } + bool Find(Label label) { return matcher_.Find(label); } + bool Done() const { return matcher_.Done(); } + const Arc& Value() const { return matcher_.Value(); } + void Next() { matcher_.Next(); } + virtual const FST &GetFst() const { return matcher_.GetFst(); } + uint64 Properties(uint64 props) const { return matcher_.Properties(props); } + uint32 Flags() const { + return matcher_.Flags() | kInputLookAheadMatcher | kOutputLookAheadMatcher; + } + + // Look-ahead methods. + bool LookAheadLabel(Label label) const { return true; } + bool LookAheadFst(const Fst &fst, StateId s) {return true; } + Weight LookAheadWeight() const { return Weight::One(); } + bool LookAheadPrefix(Arc *arc) const { return false; } + void InitLookAheadFst(const Fst& fst, bool copy = false) {} + + private: + // This allows base class virtual access to non-virtual derived- + // class members of the same name. It makes the derived class more + // efficient to use but unsafe to further derive. + virtual void SetState_(StateId s) { SetState(s); } + virtual bool Find_(Label label) { return Find(label); } + virtual bool Done_() const { return Done(); } + virtual const Arc& Value_() const { return Value(); } + virtual void Next_() { Next(); } + + bool LookAheadLabel_(Label l) const { return LookAheadLabel(l); } + + bool LookAheadFst_(const Fst &fst, StateId s) { + return LookAheadFst(fst, s); + } + + Weight LookAheadWeight_() const { return LookAheadWeight(); } + bool LookAheadPrefix_(Arc *arc) const { return LookAheadPrefix(arc); } + + M matcher_; +}; + +// Look-ahead of one transition. Template argument F accepts flags to +// control behavior. +template +class ArcLookAheadMatcher + : public LookAheadMatcherBase { + public: + typedef typename M::FST FST; + typedef typename M::Arc Arc; + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + typedef NullAddOn MatcherData; + + using LookAheadMatcherBase::LookAheadWeight; + using LookAheadMatcherBase::SetLookAheadPrefix; + using LookAheadMatcherBase::SetLookAheadWeight; + using LookAheadMatcherBase::ClearLookAheadPrefix; + + ArcLookAheadMatcher(const FST &fst, MatchType match_type, + MatcherData *data = 0) + : matcher_(fst, match_type), + fst_(matcher_.GetFst()), + lfst_(0), + s_(kNoStateId) {} + + ArcLookAheadMatcher(const ArcLookAheadMatcher &lmatcher, + bool safe = false) + : matcher_(lmatcher.matcher_, safe), + fst_(matcher_.GetFst()), + lfst_(lmatcher.lfst_), + s_(kNoStateId) {} + + // General matcher methods + ArcLookAheadMatcher *Copy(bool safe = false) const { + return new ArcLookAheadMatcher(*this, safe); + } + + MatchType Type(bool test) const { return matcher_.Type(test); } + + void SetState(StateId s) { + s_ = s; + matcher_.SetState(s); + } + + bool Find(Label label) { return matcher_.Find(label); } + bool Done() const { return matcher_.Done(); } + const Arc& Value() const { return matcher_.Value(); } + void Next() { matcher_.Next(); } + const FST &GetFst() const { return fst_; } + uint64 Properties(uint64 props) const { return matcher_.Properties(props); } + uint32 Flags() const { + return matcher_.Flags() | kInputLookAheadMatcher | + kOutputLookAheadMatcher | F; + } + + // Writable matcher methods + MatcherData *GetData() const { return 0; } + + // Look-ahead methods. + bool LookAheadLabel(Label label) const { return matcher_.Find(label); } + + // Checks if there is a matching (possibly super-final) transition + // at (s_, s). + bool LookAheadFst(const Fst &fst, StateId s); + + void InitLookAheadFst(const Fst& fst, bool copy = false) { + lfst_ = &fst; + } + + private: + // This allows base class virtual access to non-virtual derived- + // class members of the same name. It makes the derived class more + // efficient to use but unsafe to further derive. + virtual void SetState_(StateId s) { SetState(s); } + virtual bool Find_(Label label) { return Find(label); } + virtual bool Done_() const { return Done(); } + virtual const Arc& Value_() const { return Value(); } + virtual void Next_() { Next(); } + + bool LookAheadLabel_(Label l) const { return LookAheadLabel(l); } + bool LookAheadFst_(const Fst &fst, StateId s) { + return LookAheadFst(fst, s); + } + + mutable M matcher_; + const FST &fst_; // Matcher FST + const Fst *lfst_; // Look-ahead FST + StateId s_; // Matcher state +}; + +template +bool ArcLookAheadMatcher::LookAheadFst(const Fst &fst, StateId s) { + if (&fst != lfst_) + InitLookAheadFst(fst); + + bool ret = false; + ssize_t nprefix = 0; + if (F & kLookAheadWeight) + SetLookAheadWeight(Weight::Zero()); + if (F & kLookAheadPrefix) + ClearLookAheadPrefix(); + if (fst_.Final(s_) != Weight::Zero() && + lfst_->Final(s) != Weight::Zero()) { + if (!(F & (kLookAheadWeight | kLookAheadPrefix))) + return true; + ++nprefix; + if (F & kLookAheadWeight) + SetLookAheadWeight(Plus(LookAheadWeight(), + Times(fst_.Final(s_), lfst_->Final(s)))); + ret = true; + } + if (matcher_.Find(kNoLabel)) { + if (!(F & (kLookAheadWeight | kLookAheadPrefix))) + return true; + ++nprefix; + if (F & kLookAheadWeight) + for (; !matcher_.Done(); matcher_.Next()) + SetLookAheadWeight(Plus(LookAheadWeight(), matcher_.Value().weight)); + ret = true; + } + for (ArcIterator< Fst > aiter(*lfst_, s); + !aiter.Done(); + aiter.Next()) { + const Arc &arc = aiter.Value(); + Label label = kNoLabel; + switch (matcher_.Type(false)) { + case MATCH_INPUT: + label = arc.olabel; + break; + case MATCH_OUTPUT: + label = arc.ilabel; + break; + default: + FSTERROR() << "ArcLookAheadMatcher::LookAheadFst: bad match type"; + return true; + } + if (label == 0) { + if (!(F & (kLookAheadWeight | kLookAheadPrefix))) + return true; + if (!(F & kLookAheadNonEpsilonPrefix)) + ++nprefix; + if (F & kLookAheadWeight) + SetLookAheadWeight(Plus(LookAheadWeight(), arc.weight)); + ret = true; + } else if (matcher_.Find(label)) { + if (!(F & (kLookAheadWeight | kLookAheadPrefix))) + return true; + for (; !matcher_.Done(); matcher_.Next()) { + ++nprefix; + if (F & kLookAheadWeight) + SetLookAheadWeight(Plus(LookAheadWeight(), + Times(arc.weight, + matcher_.Value().weight))); + if ((F & kLookAheadPrefix) && nprefix == 1) + SetLookAheadPrefix(arc); + } + ret = true; + } + } + if (F & kLookAheadPrefix) { + if (nprefix == 1) + SetLookAheadWeight(Weight::One()); // Avoids double counting. + else + ClearLookAheadPrefix(); + } + return ret; +} + + +// Template argument F accepts flags to control behavior. +// It must include precisely one of KInputLookAheadMatcher or +// KOutputLookAheadMatcher. +template > +class LabelLookAheadMatcher + : public LookAheadMatcherBase { + public: + typedef typename M::FST FST; + typedef typename M::Arc Arc; + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + typedef LabelReachableData *fst, const L &mfst, + bool relabel_input) { + typename L::Impl *impl = mfst.GetImpl(); + D *data = impl->GetAddOn(); + LabelReachable reachable(data->First() ? + data->First() : data->Second()); + reachable.Relabel(fst, relabel_input); + } + + // Returns relabeling pairs (cf. relabel.h::Relabel()). + // Class L should be a label-lookahead Fst. + // If 'avoid_collisions' is true, extra pairs are added to + // ensure no collisions when relabeling automata that have + // labels unseen here. + template + static void RelabelPairs(const L &mfst, vector > *pairs, + bool avoid_collisions = false) { + typename L::Impl *impl = mfst.GetImpl(); + D *data = impl->GetAddOn(); + LabelReachable reachable(data->First() ? + data->First() : data->Second()); + reachable.RelabelPairs(pairs, avoid_collisions); + } +}; + +template +template inline +LabelLookAheadRelabeler::LabelLookAheadRelabeler(I **impl) { + Fst &fst = (*impl)->GetFst(); + D *data = (*impl)->GetAddOn(); + const string name = (*impl)->Type(); + bool is_mutable = fst.Properties(kMutable, false); + MutableFst *mfst = 0; + if (is_mutable) { + mfst = static_cast *>(&fst); + } else { + mfst = new VectorFst(fst); + data->IncrRefCount(); + delete *impl; + } + if (data->First()) { // reach_input + LabelReachable reachable(data->First()); + reachable.Relabel(mfst, true); + if (!FLAGS_save_relabel_ipairs.empty()) { + vector > pairs; + reachable.RelabelPairs(&pairs, true); + WriteLabelPairs(FLAGS_save_relabel_ipairs, pairs); + } + } else { + LabelReachable reachable(data->Second()); + reachable.Relabel(mfst, false); + if (!FLAGS_save_relabel_opairs.empty()) { + vector > pairs; + reachable.RelabelPairs(&pairs, true); + WriteLabelPairs(FLAGS_save_relabel_opairs, pairs); + } + } + if (!is_mutable) { + *impl = new I(*mfst, name); + (*impl)->SetAddOn(data); + delete mfst; + data->DecrRefCount(); + } +} + + +// Generic lookahead matcher, templated on the FST definition +// - a wrapper around pointer to specific one. +template +class LookAheadMatcher { + public: + typedef F FST; + typedef typename F::Arc Arc; + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + typedef LookAheadMatcherBase LBase; + + LookAheadMatcher(const F &fst, MatchType match_type) { + base_ = fst.InitMatcher(match_type); + if (!base_) + base_ = new SortedMatcher(fst, match_type); + lookahead_ = false; + } + + LookAheadMatcher(const LookAheadMatcher &matcher, bool safe = false) { + base_ = matcher.base_->Copy(safe); + lookahead_ = matcher.lookahead_; + } + + ~LookAheadMatcher() { delete base_; } + + // General matcher methods + LookAheadMatcher *Copy(bool safe = false) const { + return new LookAheadMatcher(*this, safe); + } + + MatchType Type(bool test) const { return base_->Type(test); } + void SetState(StateId s) { base_->SetState(s); } + bool Find(Label label) { return base_->Find(label); } + bool Done() const { return base_->Done(); } + const Arc& Value() const { return base_->Value(); } + void Next() { base_->Next(); } + const F &GetFst() const { return static_cast(base_->GetFst()); } + + uint64 Properties(uint64 props) const { return base_->Properties(props); } + + uint32 Flags() const { return base_->Flags(); } + + // Look-ahead methods + bool LookAheadLabel(Label label) const { + if (LookAheadCheck()) { + LBase *lbase = static_cast(base_); + return lbase->LookAheadLabel(label); + } else { + return true; + } + } + + bool LookAheadFst(const Fst &fst, StateId s) { + if (LookAheadCheck()) { + LBase *lbase = static_cast(base_); + return lbase->LookAheadFst(fst, s); + } else { + return true; + } + } + + Weight LookAheadWeight() const { + if (LookAheadCheck()) { + LBase *lbase = static_cast(base_); + return lbase->LookAheadWeight(); + } else { + return Weight::One(); + } + } + + bool LookAheadPrefix(Arc *arc) const { + if (LookAheadCheck()) { + LBase *lbase = static_cast(base_); + return lbase->LookAheadPrefix(arc); + } else { + return false; + } + } + + void InitLookAheadFst(const Fst& fst, bool copy = false) { + if (LookAheadCheck()) { + LBase *lbase = static_cast(base_); + lbase->InitLookAheadFst(fst, copy); + } + } + + private: + bool LookAheadCheck() const { + if (!lookahead_) { + lookahead_ = base_->Flags() & + (kInputLookAheadMatcher | kOutputLookAheadMatcher); + if (!lookahead_) { + FSTERROR() << "LookAheadMatcher: No look-ahead matcher defined"; + } + } + return lookahead_; + } + + MatcherBase *base_; + mutable bool lookahead_; + + void operator=(const LookAheadMatcher &); // disallow +}; + +} // namespace fst + +#endif // FST_LIB_LOOKAHEAD_MATCHER_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/map.h b/kaldi_io/src/tools/openfst/include/fst/map.h new file mode 100644 index 0000000..419cac4 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/map.h @@ -0,0 +1,121 @@ +// map.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Compatability file for old-style Map() functions and MapFst class +// that have been renamed to ArcMap (cf. StateMap). + +#ifndef FST_LIB_MAP_H__ +#define FST_LIB_MAP_H__ + + +#include + + +namespace fst { + +template +void Map(MutableFst *fst, C* mapper) { + ArcMap(fst, mapper); +} + +template +void Map(MutableFst *fst, C mapper) { + ArcMap(fst, mapper); +} + +template +void Map(const Fst &ifst, MutableFst *ofst, C* mapper) { + ArcMap(ifst, ofst, mapper); +} + +template +void Map(const Fst &ifst, MutableFst *ofst, C mapper) { + ArcMap(ifst, ofst, mapper); +} + +typedef ArcMapFstOptions MapFstOptions; + +template +class MapFst : public ArcMapFst { + public: + typedef B Arc; + typedef typename B::Weight Weight; + typedef typename B::StateId StateId; + typedef CacheState State; + + MapFst(const Fst &fst, const C &mapper, const MapFstOptions& opts) + : ArcMapFst(fst, mapper, opts) {} + + MapFst(const Fst &fst, C* mapper, const MapFstOptions& opts) + : ArcMapFst(fst, mapper, opts) {} + + MapFst(const Fst &fst, const C &mapper) + : ArcMapFst(fst, mapper) {} + + MapFst(const Fst &fst, C* mapper) : ArcMapFst(fst, mapper) {} + + // See Fst<>::Copy() for doc. + MapFst(const ArcMapFst &fst, bool safe = false) + : ArcMapFst(fst, safe) {} + + // Get a copy of this MapFst. See Fst<>::Copy() for further doc. +virtual MapFst *Copy(bool safe = false) const { + return new MapFst(*this, safe); + } +}; + + +// Specialization for MapFst. +template +class StateIterator< MapFst > + : public StateIterator< ArcMapFst > { + public: + explicit StateIterator(const ArcMapFst &fst) + : StateIterator< ArcMapFst >(fst) {} +}; + + +// Specialization for MapFst. +template +class ArcIterator< MapFst > + : public ArcIterator< ArcMapFst > { + public: + ArcIterator(const ArcMapFst &fst, typename A::StateId s) + : ArcIterator< ArcMapFst >(fst, s) {} +}; + + +template +struct IdentityMapper { + typedef A FromArc; + typedef A ToArc; + + A operator()(const A &arc) const { return arc; } + + MapFinalAction FinalAction() const { return MAP_NO_SUPERFINAL; } + + MapSymbolsAction InputSymbolsAction() const { return MAP_COPY_SYMBOLS; } + + MapSymbolsAction OutputSymbolsAction() const { return MAP_COPY_SYMBOLS;} + + uint64 Properties(uint64 props) const { return props; } +}; + +} // namespace fst + +#endif // FST_LIB_MAP_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/mapped-file.h b/kaldi_io/src/tools/openfst/include/fst/mapped-file.h new file mode 100644 index 0000000..d61bc14 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/mapped-file.h @@ -0,0 +1,83 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: sorenj@google.com (Jeffrey Sorensen) + +#ifndef FST_LIB_MAPPED_FILE_H_ +#define FST_LIB_MAPPED_FILE_H_ + +#include +#include + +#include +#include +#include +#include + +DECLARE_int32(fst_arch_alignment); // defined in mapped-file.h + +namespace fst { + +// A memory region is a simple abstraction for allocated memory or data from +// mmap'ed files. If mmap equals NULL, then data represents an owned region of +// size bytes. Otherwise, mmap and size refer to the mapping and data is a +// casted pointer to a region contained within [mmap, mmap + size). +// If size is 0, then mmap refers and data refer to a block of memory managed +// externally by some other allocator. +struct MemoryRegion { + void *data; + void *mmap; + size_t size; +}; + +class MappedFile { + public: + virtual ~MappedFile(); + + void* mutable_data() const { + return reinterpret_cast(region_.data); + } + + const void* data() const { + return reinterpret_cast(region_.data); + } + + // Returns a MappedFile object that contains the contents of the input + // stream s starting from the current file position with size bytes. + // The file name must also be provided in the FstReadOptions as opts.source + // or else mapping will fail. If mapping is not possible, then a MappedFile + // object with a new[]'ed block of memory will be created. + static MappedFile* Map(istream* s, const FstReadOptions& opts, size_t size); + + // Creates a MappedFile object with a new[]'ed block of memory of size. + // RECOMMENDED FOR INTERNAL USE ONLY, may change in future releases. + static MappedFile* Allocate(size_t size); + + // Creates a MappedFile object pointing to a borrowed reference to data. + // This block of memory is not owned by the MappedFile object and will not + // be freed. + // RECOMMENDED FOR INTERNAL USE ONLY, may change in future releases. + static MappedFile* Borrow(void *data); + + static const int kArchAlignment; + + private: + explicit MappedFile(const MemoryRegion ®ion); + + MemoryRegion region_; + DISALLOW_COPY_AND_ASSIGN(MappedFile); +}; +} // namespace fst + +#endif // FST_LIB_MAPPED_FILE_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/matcher-fst.h b/kaldi_io/src/tools/openfst/include/fst/matcher-fst.h new file mode 100644 index 0000000..73e64ad --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/matcher-fst.h @@ -0,0 +1,359 @@ +// matcher-fst.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Class to add a matcher to an FST. + +#ifndef FST_LIB_MATCHER_FST_FST_H__ +#define FST_LIB_MATCHER_FST_FST_H__ + +#include +#include +#include + + +namespace fst { + +// WRITABLE MATCHERS - these have the interface of Matchers (see +// matcher.h) and these additional methods: +// +// template +// class Matcher { +// public: +// typedef ... MatcherData; // Initialization data +// ... +// // Constructor with additional argument for external initialization +// // data; matcher increments its reference count on construction and +// // decrements the reference count, and if 0 deletes, on destruction. +// Matcher(const F &fst, MatchType type, MatcherData *data); +// +// // Returns pointer to initialization data that can be +// // passed to a Matcher constructor. +// MatcherData *GetData() const; +// }; + +// The matcher initialization data class must have the form: +// class MatcherData { +// public: +// // Required copy constructor. +// MatcherData(const MatcherData &); +// // +// // Required I/O methods. +// static MatcherData *Read(istream &istrm); +// bool Write(ostream &ostrm); +// +// // Required reference counting. +// int RefCount() const; +// int IncrRefCount(); +// int DecrRefCount(); +// }; + +// Default MatcherFst initializer - does nothing. +template +class NullMatcherFstInit { + public: + typedef AddOnPair D; + typedef AddOnImpl Impl; + NullMatcherFstInit(Impl **) {} +}; + +// Class to add a matcher M to an Fst F. Creates a new Fst of type name N. +// Optional function object I can be used to initialize the Fst. +template > +class MatcherFst + : public ImplToExpandedFst< + AddOnImpl > > { + public: + friend class StateIterator< MatcherFst >; + friend class ArcIterator< MatcherFst >; + + typedef F FST; + typedef M FstMatcher; + typedef typename F::Arc Arc; + typedef typename Arc::StateId StateId; + typedef AddOnPair D; + typedef AddOnImpl Impl; + + MatcherFst() : ImplToExpandedFst(new Impl(F(), N)) {} + + explicit MatcherFst(const F &fst) + : ImplToExpandedFst(CreateImpl(fst, N)) {} + + explicit MatcherFst(const Fst &fst) + : ImplToExpandedFst(CreateImpl(fst, N)) {} + + // See Fst<>::Copy() for doc. + MatcherFst(const MatcherFst &fst, bool safe = false) + : ImplToExpandedFst(fst, safe) {} + + // Get a copy of this MatcherFst. See Fst<>::Copy() for further doc. + virtual MatcherFst *Copy(bool safe = false) const { + return new MatcherFst(*this, safe); + } + + // Read a MatcherFst from an input stream; return NULL on error + static MatcherFst *Read(istream &strm, + const FstReadOptions &opts) { + Impl *impl = Impl::Read(strm, opts); + return impl ? new MatcherFst(impl) : 0; + } + + // Read a MatcherFst from a file; return NULL on error + // Empty filename reads from standard input + static MatcherFst *Read(const string &filename) { + Impl *impl = ImplToExpandedFst::Read(filename); + return impl ? new MatcherFst(impl) : 0; + } + + virtual bool Write(ostream &strm, const FstWriteOptions &opts) const { + return GetImpl()->Write(strm, opts); + } + + virtual bool Write(const string &filename) const { + return Fst::WriteFile(filename); + } + + virtual void InitStateIterator(StateIteratorData *data) const { + return GetImpl()->InitStateIterator(data); + } + + virtual void InitArcIterator(StateId s, ArcIteratorData *data) const { + return GetImpl()->InitArcIterator(s, data); + } + + virtual M *InitMatcher(MatchType match_type) const { + return new M(GetFst(), match_type, GetData(match_type)); + } + + // Allows access to MatcherFst components. + Impl *GetImpl() const { + return ImplToFst >::GetImpl(); + } + + F& GetFst() const { return GetImpl()->GetFst(); } + + typename M::MatcherData *GetData(MatchType match_type) const { + D *data = GetImpl()->GetAddOn(); + return match_type == MATCH_INPUT ? data->First() : data->Second(); + } + + private: + static Impl *CreateImpl(const F &fst, const string &name) { + M imatcher(fst, MATCH_INPUT); + M omatcher(fst, MATCH_OUTPUT); + D *data = new D(imatcher.GetData(), omatcher.GetData()); + Impl *impl = new Impl(fst, name); + impl->SetAddOn(data); + I init(&impl); + data->DecrRefCount(); + return impl; + } + + static Impl *CreateImpl(const Fst &fst, const string &name) { + F ffst(fst); + return CreateImpl(ffst, name); + } + + explicit MatcherFst(Impl *impl) : ImplToExpandedFst(impl) {} + + // Makes visible to friends. + void SetImpl(Impl *impl, bool own_impl = true) { + ImplToFst< Impl, ExpandedFst >::SetImpl(impl, own_impl); + } + + void operator=(const MatcherFst &fst); // disallow +}; + + +// Specialization fo MatcherFst. +template +class StateIterator< MatcherFst > : public StateIterator { + public: + explicit StateIterator(const MatcherFst &fst) : + StateIterator(fst.GetImpl()->GetFst()) {} +}; + + +// Specialization for MatcherFst. +template +class ArcIterator< MatcherFst > : public ArcIterator { + public: + ArcIterator(const MatcherFst &fst, typename F::Arc::StateId s) + : ArcIterator(fst.GetImpl()->GetFst(), s) {} +}; + + +// Specialization for MatcherFst +template +class Matcher< MatcherFst > { + public: + typedef MatcherFst FST; + typedef typename F::Arc Arc; + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + + Matcher(const FST &fst, MatchType match_type) { + matcher_ = fst.InitMatcher(match_type); + } + + Matcher(const Matcher &matcher) { + matcher_ = matcher.matcher_->Copy(); + } + + ~Matcher() { delete matcher_; } + + Matcher *Copy() const { + return new Matcher(*this); + } + + MatchType Type(bool test) const { return matcher_->Type(test); } + void SetState(StateId s) { matcher_->SetState(s); } + bool Find(Label label) { return matcher_->Find(label); } + bool Done() const { return matcher_->Done(); } + const Arc& Value() const { return matcher_->Value(); } + void Next() { matcher_->Next(); } + uint64 Properties(uint64 props) const { return matcher_->Properties(props); } + uint32 Flags() const { return matcher_->Flags(); } + + private: + M *matcher_; + + void operator=(const Matcher &); // disallow +}; + + +// Specialization for MatcherFst +template +class LookAheadMatcher< MatcherFst > { + public: + typedef MatcherFst FST; + typedef typename F::Arc Arc; + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + + LookAheadMatcher(const FST &fst, MatchType match_type) { + matcher_ = fst.InitMatcher(match_type); + } + + LookAheadMatcher(const LookAheadMatcher &matcher, bool safe = false) { + matcher_ = matcher.matcher_->Copy(safe); + } + + ~LookAheadMatcher() { delete matcher_; } + + // General matcher methods + LookAheadMatcher *Copy(bool safe = false) const { + return new LookAheadMatcher(*this, safe); + } + + MatchType Type(bool test) const { return matcher_->Type(test); } + void SetState(StateId s) { matcher_->SetState(s); } + bool Find(Label label) { return matcher_->Find(label); } + bool Done() const { return matcher_->Done(); } + const Arc& Value() const { return matcher_->Value(); } + void Next() { matcher_->Next(); } + const FST &GetFst() const { return matcher_->GetFst(); } + uint64 Properties(uint64 props) const { return matcher_->Properties(props); } + uint32 Flags() const { return matcher_->Flags(); } + + // Look-ahead methods + bool LookAheadLabel(Label label) const { + return matcher_->LookAheadLabel(label); + } + + bool LookAheadFst(const Fst &fst, StateId s) { + return matcher_->LookAheadFst(fst, s); + } + + Weight LookAheadWeight() const { return matcher_->LookAheadWeight(); } + + bool LookAheadPrefix(Arc *arc) const { + return matcher_->LookAheadPrefix(arc); + } + + void InitLookAheadFst(const Fst& fst, bool copy = false) { + matcher_->InitLookAheadFst(fst, copy); + } + + private: + M *matcher_; + + void operator=(const LookAheadMatcher &); // disallow +}; + +// +// Useful aliases when using StdArc and LogArc. +// + +// Arc look-ahead matchers +extern const char arc_lookahead_fst_type[]; + +typedef MatcherFst, + ArcLookAheadMatcher > >, + arc_lookahead_fst_type> StdArcLookAheadFst; + +typedef MatcherFst, + ArcLookAheadMatcher > >, + arc_lookahead_fst_type> LogArcLookAheadFst; + + +// Label look-ahead matchers +extern const char ilabel_lookahead_fst_type[]; +extern const char olabel_lookahead_fst_type[]; + +static const uint32 ilabel_lookahead_flags = kInputLookAheadMatcher | + kLookAheadWeight | kLookAheadPrefix | + kLookAheadEpsilons | kLookAheadNonEpsilonPrefix; +static const uint32 olabel_lookahead_flags = kOutputLookAheadMatcher | + kLookAheadWeight | kLookAheadPrefix | + kLookAheadEpsilons | kLookAheadNonEpsilonPrefix; + +typedef MatcherFst, + LabelLookAheadMatcher >, + ilabel_lookahead_flags, + FastLogAccumulator >, + ilabel_lookahead_fst_type, + LabelLookAheadRelabeler > StdILabelLookAheadFst; + +typedef MatcherFst, + LabelLookAheadMatcher >, + ilabel_lookahead_flags, + FastLogAccumulator >, + ilabel_lookahead_fst_type, + LabelLookAheadRelabeler > LogILabelLookAheadFst; + +typedef MatcherFst, + LabelLookAheadMatcher >, + olabel_lookahead_flags, + FastLogAccumulator >, + olabel_lookahead_fst_type, + LabelLookAheadRelabeler > StdOLabelLookAheadFst; + +typedef MatcherFst, + LabelLookAheadMatcher >, + olabel_lookahead_flags, + FastLogAccumulator >, + olabel_lookahead_fst_type, + LabelLookAheadRelabeler > LogOLabelLookAheadFst; + +} // namespace fst + +#endif // FST_LIB_MATCHER_FST_FST_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/matcher.h b/kaldi_io/src/tools/openfst/include/fst/matcher.h new file mode 100644 index 0000000..89ed9be --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/matcher.h @@ -0,0 +1,1205 @@ +// matcher.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Classes to allow matching labels leaving FST states. + +#ifndef FST_LIB_MATCHER_H__ +#define FST_LIB_MATCHER_H__ + +#include +#include + +#include // for all internal FST accessors + + +namespace fst { + +// MATCHERS - these can find and iterate through requested labels at +// FST states. In the simplest form, these are just some associative +// map or search keyed on labels. More generally, they may +// implement matching special labels that represent sets of labels +// such as 'sigma' (all), 'rho' (rest), or 'phi' (fail). +// The Matcher interface is: +// +// template +// class Matcher { +// public: +// typedef F FST; +// typedef F::Arc Arc; +// typedef typename Arc::StateId StateId; +// typedef typename Arc::Label Label; +// typedef typename Arc::Weight Weight; +// +// // Required constructors. +// Matcher(const F &fst, MatchType type); +// // If safe=true, the copy is thread-safe. See Fst<>::Copy() +// // for further doc. +// Matcher(const Matcher &matcher, bool safe = false); +// +// // If safe=true, the copy is thread-safe. See Fst<>::Copy() +// // for further doc. +// Matcher *Copy(bool safe = false) const; +// +// // Returns the match type that can be provided (depending on +// // compatibility of the input FST). It is either +// // the requested match type, MATCH_NONE, or MATCH_UNKNOWN. +// // If 'test' is false, a constant time test is performed, but +// // MATCH_UNKNOWN may be returned. If 'test' is true, +// // a definite answer is returned, but may involve more costly +// // computation (e.g., visiting the Fst). +// MatchType Type(bool test) const; +// // Specifies the current state. +// void SetState(StateId s); +// +// // This finds matches to a label at the current state. +// // Returns true if a match found. kNoLabel matches any +// // 'non-consuming' transitions, e.g., epsilon transitions, +// // which do not require a matching symbol. +// bool Find(Label label); +// // These iterate through any matches found: +// bool Done() const; // No more matches. +// const A& Value() const; // Current arc (when !Done) +// void Next(); // Advance to next arc (when !Done) +// // Initially and after SetState() the iterator methods +// // have undefined behavior until Find() is called. +// +// // Return matcher FST. +// const F& GetFst() const; +// // This specifies the known Fst properties as viewed from this +// // matcher. It takes as argument the input Fst's known properties. +// uint64 Properties(uint64 props) const; +// }; + +// +// MATCHER FLAGS (see also kLookAheadFlags in lookahead-matcher.h) +// +// Matcher prefers being used as the matching side in composition. +const uint32 kPreferMatch = 0x00000001; + +// Matcher needs to be used as the matching side in composition. +const uint32 kRequireMatch = 0x00000002; + +// Flags used for basic matchers (see also lookahead.h). +const uint32 kMatcherFlags = kPreferMatch | kRequireMatch; + +// Matcher interface, templated on the Arc definition; used +// for matcher specializations that are returned by the +// InitMatcher Fst method. +template +class MatcherBase { + public: + typedef A Arc; + typedef typename A::StateId StateId; + typedef typename A::Label Label; + typedef typename A::Weight Weight; + + virtual ~MatcherBase() {} + + virtual MatcherBase *Copy(bool safe = false) const = 0; + virtual MatchType Type(bool test) const = 0; + void SetState(StateId s) { SetState_(s); } + bool Find(Label label) { return Find_(label); } + bool Done() const { return Done_(); } + const A& Value() const { return Value_(); } + void Next() { Next_(); } + virtual const Fst &GetFst() const = 0; + virtual uint64 Properties(uint64 props) const = 0; + virtual uint32 Flags() const { return 0; } + private: + virtual void SetState_(StateId s) = 0; + virtual bool Find_(Label label) = 0; + virtual bool Done_() const = 0; + virtual const A& Value_() const = 0; + virtual void Next_() = 0; +}; + + +// A matcher that expects sorted labels on the side to be matched. +// If match_type == MATCH_INPUT, epsilons match the implicit self loop +// Arc(kNoLabel, 0, Weight::One(), current_state) as well as any +// actual epsilon transitions. If match_type == MATCH_OUTPUT, then +// Arc(0, kNoLabel, Weight::One(), current_state) is instead matched. +template +class SortedMatcher : public MatcherBase { + public: + typedef F FST; + typedef typename F::Arc Arc; + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + + // Labels >= binary_label will be searched for by binary search, + // o.w. linear search is used. + SortedMatcher(const F &fst, MatchType match_type, + Label binary_label = 1) + : fst_(fst.Copy()), + s_(kNoStateId), + aiter_(0), + match_type_(match_type), + binary_label_(binary_label), + match_label_(kNoLabel), + narcs_(0), + loop_(kNoLabel, 0, Weight::One(), kNoStateId), + error_(false) { + switch(match_type_) { + case MATCH_INPUT: + case MATCH_NONE: + break; + case MATCH_OUTPUT: + swap(loop_.ilabel, loop_.olabel); + break; + default: + FSTERROR() << "SortedMatcher: bad match type"; + match_type_ = MATCH_NONE; + error_ = true; + } + } + + SortedMatcher(const SortedMatcher &matcher, bool safe = false) + : fst_(matcher.fst_->Copy(safe)), + s_(kNoStateId), + aiter_(0), + match_type_(matcher.match_type_), + binary_label_(matcher.binary_label_), + match_label_(kNoLabel), + narcs_(0), + loop_(matcher.loop_), + error_(matcher.error_) {} + + virtual ~SortedMatcher() { + if (aiter_) + delete aiter_; + delete fst_; + } + + virtual SortedMatcher *Copy(bool safe = false) const { + return new SortedMatcher(*this, safe); + } + + virtual MatchType Type(bool test) const { + if (match_type_ == MATCH_NONE) + return match_type_; + + uint64 true_prop = match_type_ == MATCH_INPUT ? + kILabelSorted : kOLabelSorted; + uint64 false_prop = match_type_ == MATCH_INPUT ? + kNotILabelSorted : kNotOLabelSorted; + uint64 props = fst_->Properties(true_prop | false_prop, test); + + if (props & true_prop) + return match_type_; + else if (props & false_prop) + return MATCH_NONE; + else + return MATCH_UNKNOWN; + } + + void SetState(StateId s) { + if (s_ == s) + return; + s_ = s; + if (match_type_ == MATCH_NONE) { + FSTERROR() << "SortedMatcher: bad match type"; + error_ = true; + } + if (aiter_) + delete aiter_; + aiter_ = new ArcIterator(*fst_, s); + aiter_->SetFlags(kArcNoCache, kArcNoCache); + narcs_ = internal::NumArcs(*fst_, s); + loop_.nextstate = s; + } + + bool Find(Label match_label) { + exact_match_ = true; + if (error_) { + current_loop_ = false; + match_label_ = kNoLabel; + return false; + } + current_loop_ = match_label == 0; + match_label_ = match_label == kNoLabel ? 0 : match_label; + if (Search()) { + return true; + } else { + return current_loop_; + } + } + + // Positions matcher to the first position where inserting + // match_label would maintain the sort order. + void LowerBound(Label match_label) { + exact_match_ = false; + current_loop_ = false; + if (error_) { + match_label_ = kNoLabel; + return; + } + match_label_ = match_label; + Search(); + } + + // After Find(), returns false if no more exact matches. + // After LowerBound(), returns false if no more arcs. + bool Done() const { + if (current_loop_) + return false; + if (aiter_->Done()) + return true; + if (!exact_match_) + return false; + aiter_->SetFlags( + match_type_ == MATCH_INPUT ? kArcILabelValue : kArcOLabelValue, + kArcValueFlags); + Label label = match_type_ == MATCH_INPUT ? + aiter_->Value().ilabel : aiter_->Value().olabel; + return label != match_label_; + } + + const Arc& Value() const { + if (current_loop_) { + return loop_; + } + aiter_->SetFlags(kArcValueFlags, kArcValueFlags); + return aiter_->Value(); + } + + void Next() { + if (current_loop_) + current_loop_ = false; + else + aiter_->Next(); + } + + virtual const F &GetFst() const { return *fst_; } + + virtual uint64 Properties(uint64 inprops) const { + uint64 outprops = inprops; + if (error_) outprops |= kError; + return outprops; + } + + size_t Position() const { return aiter_ ? aiter_->Position() : 0; } + + private: + virtual void SetState_(StateId s) { SetState(s); } + virtual bool Find_(Label label) { return Find(label); } + virtual bool Done_() const { return Done(); } + virtual const Arc& Value_() const { return Value(); } + virtual void Next_() { Next(); } + + bool Search(); + + const F *fst_; + StateId s_; // Current state + ArcIterator *aiter_; // Iterator for current state + MatchType match_type_; // Type of match to perform + Label binary_label_; // Least label for binary search + Label match_label_; // Current label to be matched + size_t narcs_; // Current state arc count + Arc loop_; // For non-consuming symbols + bool current_loop_; // Current arc is the implicit loop + bool exact_match_; // Exact match or lower bound? + bool error_; // Error encountered + + void operator=(const SortedMatcher &); // Disallow +}; + +// Returns true iff match to match_label_. Positions arc iterator at +// lower bound regardless. +template inline +bool SortedMatcher::Search() { + aiter_->SetFlags( + match_type_ == MATCH_INPUT ? kArcILabelValue : kArcOLabelValue, + kArcValueFlags); + if (match_label_ >= binary_label_) { + // Binary search for match. + size_t low = 0; + size_t high = narcs_; + while (low < high) { + size_t mid = (low + high) / 2; + aiter_->Seek(mid); + Label label = match_type_ == MATCH_INPUT ? + aiter_->Value().ilabel : aiter_->Value().olabel; + if (label > match_label_) { + high = mid; + } else if (label < match_label_) { + low = mid + 1; + } else { + // find first matching label (when non-determinism) + for (size_t i = mid; i > low; --i) { + aiter_->Seek(i - 1); + label = match_type_ == MATCH_INPUT ? aiter_->Value().ilabel : + aiter_->Value().olabel; + if (label != match_label_) { + aiter_->Seek(i); + return true; + } + } + return true; + } + } + aiter_->Seek(low); + return false; + } else { + // Linear search for match. + for (aiter_->Reset(); !aiter_->Done(); aiter_->Next()) { + Label label = match_type_ == MATCH_INPUT ? + aiter_->Value().ilabel : aiter_->Value().olabel; + if (label == match_label_) { + return true; + } + if (label > match_label_) + break; + } + return false; + } +} + + +// Specifies whether during matching we rewrite both the input and output sides. +enum MatcherRewriteMode { + MATCHER_REWRITE_AUTO = 0, // Rewrites both sides iff acceptor. + MATCHER_REWRITE_ALWAYS, + MATCHER_REWRITE_NEVER +}; + + +// For any requested label that doesn't match at a state, this matcher +// considers all transitions that match the label 'rho_label' (rho = +// 'rest'). Each such rho transition found is returned with the +// rho_label rewritten as the requested label (both sides if an +// acceptor, or if 'rewrite_both' is true and both input and output +// labels of the found transition are 'rho_label'). If 'rho_label' is +// kNoLabel, this special matching is not done. RhoMatcher is +// templated itself on a matcher, which is used to perform the +// underlying matching. By default, the underlying matcher is +// constructed by RhoMatcher. The user can instead pass in this +// object; in that case, RhoMatcher takes its ownership. +template +class RhoMatcher : public MatcherBase { + public: + typedef typename M::FST FST; + typedef typename M::Arc Arc; + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + + RhoMatcher(const FST &fst, + MatchType match_type, + Label rho_label = kNoLabel, + MatcherRewriteMode rewrite_mode = MATCHER_REWRITE_AUTO, + M *matcher = 0) + : matcher_(matcher ? matcher : new M(fst, match_type)), + match_type_(match_type), + rho_label_(rho_label), + error_(false) { + if (match_type == MATCH_BOTH) { + FSTERROR() << "RhoMatcher: bad match type"; + match_type_ = MATCH_NONE; + error_ = true; + } + if (rho_label == 0) { + FSTERROR() << "RhoMatcher: 0 cannot be used as rho_label"; + rho_label_ = kNoLabel; + error_ = true; + } + + if (rewrite_mode == MATCHER_REWRITE_AUTO) + rewrite_both_ = fst.Properties(kAcceptor, true); + else if (rewrite_mode == MATCHER_REWRITE_ALWAYS) + rewrite_both_ = true; + else + rewrite_both_ = false; + } + + RhoMatcher(const RhoMatcher &matcher, bool safe = false) + : matcher_(new M(*matcher.matcher_, safe)), + match_type_(matcher.match_type_), + rho_label_(matcher.rho_label_), + rewrite_both_(matcher.rewrite_both_), + error_(matcher.error_) {} + + virtual ~RhoMatcher() { + delete matcher_; + } + + virtual RhoMatcher *Copy(bool safe = false) const { + return new RhoMatcher(*this, safe); + } + + virtual MatchType Type(bool test) const { return matcher_->Type(test); } + + void SetState(StateId s) { + matcher_->SetState(s); + has_rho_ = rho_label_ != kNoLabel; + } + + bool Find(Label match_label) { + if (match_label == rho_label_ && rho_label_ != kNoLabel) { + FSTERROR() << "RhoMatcher::Find: bad label (rho)"; + error_ = true; + return false; + } + if (matcher_->Find(match_label)) { + rho_match_ = kNoLabel; + return true; + } else if (has_rho_ && match_label != 0 && match_label != kNoLabel && + (has_rho_ = matcher_->Find(rho_label_))) { + rho_match_ = match_label; + return true; + } else { + return false; + } + } + + bool Done() const { return matcher_->Done(); } + + const Arc& Value() const { + if (rho_match_ == kNoLabel) { + return matcher_->Value(); + } else { + rho_arc_ = matcher_->Value(); + if (rewrite_both_) { + if (rho_arc_.ilabel == rho_label_) + rho_arc_.ilabel = rho_match_; + if (rho_arc_.olabel == rho_label_) + rho_arc_.olabel = rho_match_; + } else if (match_type_ == MATCH_INPUT) { + rho_arc_.ilabel = rho_match_; + } else { + rho_arc_.olabel = rho_match_; + } + return rho_arc_; + } + } + + void Next() { matcher_->Next(); } + + virtual const FST &GetFst() const { return matcher_->GetFst(); } + + virtual uint64 Properties(uint64 props) const; + + virtual uint32 Flags() const { + if (rho_label_ == kNoLabel || match_type_ == MATCH_NONE) + return matcher_->Flags(); + return matcher_->Flags() | kRequireMatch; + } + + private: + virtual void SetState_(StateId s) { SetState(s); } + virtual bool Find_(Label label) { return Find(label); } + virtual bool Done_() const { return Done(); } + virtual const Arc& Value_() const { return Value(); } + virtual void Next_() { Next(); } + + M *matcher_; + MatchType match_type_; // Type of match requested + Label rho_label_; // Label that represents the rho transition + bool rewrite_both_; // Rewrite both sides when both are 'rho_label_' + bool has_rho_; // Are there possibly rhos at the current state? + Label rho_match_; // Current label that matches rho transition + mutable Arc rho_arc_; // Arc to return when rho match + bool error_; // Error encountered + + void operator=(const RhoMatcher &); // Disallow +}; + +template inline +uint64 RhoMatcher::Properties(uint64 inprops) const { + uint64 outprops = matcher_->Properties(inprops); + if (error_) outprops |= kError; + + if (match_type_ == MATCH_NONE) { + return outprops; + } else if (match_type_ == MATCH_INPUT) { + if (rewrite_both_) { + return outprops & ~(kODeterministic | kNonODeterministic | kString | + kILabelSorted | kNotILabelSorted | + kOLabelSorted | kNotOLabelSorted); + } else { + return outprops & ~(kODeterministic | kAcceptor | kString | + kILabelSorted | kNotILabelSorted); + } + } else if (match_type_ == MATCH_OUTPUT) { + if (rewrite_both_) { + return outprops & ~(kIDeterministic | kNonIDeterministic | kString | + kILabelSorted | kNotILabelSorted | + kOLabelSorted | kNotOLabelSorted); + } else { + return outprops & ~(kIDeterministic | kAcceptor | kString | + kOLabelSorted | kNotOLabelSorted); + } + } else { + // Shouldn't ever get here. + FSTERROR() << "RhoMatcher:: bad match type: " << match_type_; + return 0; + } +} + + +// For any requested label, this matcher considers all transitions +// that match the label 'sigma_label' (sigma = "any"), and this in +// additions to transitions with the requested label. Each such sigma +// transition found is returned with the sigma_label rewritten as the +// requested label (both sides if an acceptor, or if 'rewrite_both' is +// true and both input and output labels of the found transition are +// 'sigma_label'). If 'sigma_label' is kNoLabel, this special +// matching is not done. SigmaMatcher is templated itself on a +// matcher, which is used to perform the underlying matching. By +// default, the underlying matcher is constructed by SigmaMatcher. +// The user can instead pass in this object; in that case, +// SigmaMatcher takes its ownership. +template +class SigmaMatcher : public MatcherBase { + public: + typedef typename M::FST FST; + typedef typename M::Arc Arc; + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + + SigmaMatcher(const FST &fst, + MatchType match_type, + Label sigma_label = kNoLabel, + MatcherRewriteMode rewrite_mode = MATCHER_REWRITE_AUTO, + M *matcher = 0) + : matcher_(matcher ? matcher : new M(fst, match_type)), + match_type_(match_type), + sigma_label_(sigma_label), + error_(false) { + if (match_type == MATCH_BOTH) { + FSTERROR() << "SigmaMatcher: bad match type"; + match_type_ = MATCH_NONE; + error_ = true; + } + if (sigma_label == 0) { + FSTERROR() << "SigmaMatcher: 0 cannot be used as sigma_label"; + sigma_label_ = kNoLabel; + error_ = true; + } + + if (rewrite_mode == MATCHER_REWRITE_AUTO) + rewrite_both_ = fst.Properties(kAcceptor, true); + else if (rewrite_mode == MATCHER_REWRITE_ALWAYS) + rewrite_both_ = true; + else + rewrite_both_ = false; + } + + SigmaMatcher(const SigmaMatcher &matcher, bool safe = false) + : matcher_(new M(*matcher.matcher_, safe)), + match_type_(matcher.match_type_), + sigma_label_(matcher.sigma_label_), + rewrite_both_(matcher.rewrite_both_), + error_(matcher.error_) {} + + virtual ~SigmaMatcher() { + delete matcher_; + } + + virtual SigmaMatcher *Copy(bool safe = false) const { + return new SigmaMatcher(*this, safe); + } + + virtual MatchType Type(bool test) const { return matcher_->Type(test); } + + void SetState(StateId s) { + matcher_->SetState(s); + has_sigma_ = + sigma_label_ != kNoLabel ? matcher_->Find(sigma_label_) : false; + } + + bool Find(Label match_label) { + match_label_ = match_label; + if (match_label == sigma_label_ && sigma_label_ != kNoLabel) { + FSTERROR() << "SigmaMatcher::Find: bad label (sigma)"; + error_ = true; + return false; + } + if (matcher_->Find(match_label)) { + sigma_match_ = kNoLabel; + return true; + } else if (has_sigma_ && match_label != 0 && match_label != kNoLabel && + matcher_->Find(sigma_label_)) { + sigma_match_ = match_label; + return true; + } else { + return false; + } + } + + bool Done() const { + return matcher_->Done(); + } + + const Arc& Value() const { + if (sigma_match_ == kNoLabel) { + return matcher_->Value(); + } else { + sigma_arc_ = matcher_->Value(); + if (rewrite_both_) { + if (sigma_arc_.ilabel == sigma_label_) + sigma_arc_.ilabel = sigma_match_; + if (sigma_arc_.olabel == sigma_label_) + sigma_arc_.olabel = sigma_match_; + } else if (match_type_ == MATCH_INPUT) { + sigma_arc_.ilabel = sigma_match_; + } else { + sigma_arc_.olabel = sigma_match_; + } + return sigma_arc_; + } + } + + void Next() { + matcher_->Next(); + if (matcher_->Done() && has_sigma_ && (sigma_match_ == kNoLabel) && + (match_label_ > 0)) { + matcher_->Find(sigma_label_); + sigma_match_ = match_label_; + } + } + + virtual const FST &GetFst() const { return matcher_->GetFst(); } + + virtual uint64 Properties(uint64 props) const; + + virtual uint32 Flags() const { + if (sigma_label_ == kNoLabel || match_type_ == MATCH_NONE) + return matcher_->Flags(); + // kRequireMatch temporarily disabled until issues + // in //speech/gaudi/annotation/util/denorm are resolved. + // return matcher_->Flags() | kRequireMatch; + return matcher_->Flags(); + } + +private: + virtual void SetState_(StateId s) { SetState(s); } + virtual bool Find_(Label label) { return Find(label); } + virtual bool Done_() const { return Done(); } + virtual const Arc& Value_() const { return Value(); } + virtual void Next_() { Next(); } + + M *matcher_; + MatchType match_type_; // Type of match requested + Label sigma_label_; // Label that represents the sigma transition + bool rewrite_both_; // Rewrite both sides when both are 'sigma_label_' + bool has_sigma_; // Are there sigmas at the current state? + Label sigma_match_; // Current label that matches sigma transition + mutable Arc sigma_arc_; // Arc to return when sigma match + Label match_label_; // Label being matched + bool error_; // Error encountered + + void operator=(const SigmaMatcher &); // disallow +}; + +template inline +uint64 SigmaMatcher::Properties(uint64 inprops) const { + uint64 outprops = matcher_->Properties(inprops); + if (error_) outprops |= kError; + + if (match_type_ == MATCH_NONE) { + return outprops; + } else if (rewrite_both_) { + return outprops & ~(kIDeterministic | kNonIDeterministic | + kODeterministic | kNonODeterministic | + kILabelSorted | kNotILabelSorted | + kOLabelSorted | kNotOLabelSorted | + kString); + } else if (match_type_ == MATCH_INPUT) { + return outprops & ~(kIDeterministic | kNonIDeterministic | + kODeterministic | kNonODeterministic | + kILabelSorted | kNotILabelSorted | + kString | kAcceptor); + } else if (match_type_ == MATCH_OUTPUT) { + return outprops & ~(kIDeterministic | kNonIDeterministic | + kODeterministic | kNonODeterministic | + kOLabelSorted | kNotOLabelSorted | + kString | kAcceptor); + } else { + // Shouldn't ever get here. + FSTERROR() << "SigmaMatcher:: bad match type: " << match_type_; + return 0; + } +} + + +// For any requested label that doesn't match at a state, this matcher +// considers the *unique* transition that matches the label 'phi_label' +// (phi = 'fail'), and recursively looks for a match at its +// destination. When 'phi_loop' is true, if no match is found but a +// phi self-loop is found, then the phi transition found is returned +// with the phi_label rewritten as the requested label (both sides if +// an acceptor, or if 'rewrite_both' is true and both input and output +// labels of the found transition are 'phi_label'). If 'phi_label' is +// kNoLabel, this special matching is not done. PhiMatcher is +// templated itself on a matcher, which is used to perform the +// underlying matching. By default, the underlying matcher is +// constructed by PhiMatcher. The user can instead pass in this +// object; in that case, PhiMatcher takes its ownership. +// Warning: phi non-determinism not supported (for simplicity). +template +class PhiMatcher : public MatcherBase { + public: + typedef typename M::FST FST; + typedef typename M::Arc Arc; + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + + PhiMatcher(const FST &fst, + MatchType match_type, + Label phi_label = kNoLabel, + bool phi_loop = true, + MatcherRewriteMode rewrite_mode = MATCHER_REWRITE_AUTO, + M *matcher = 0) + : matcher_(matcher ? matcher : new M(fst, match_type)), + match_type_(match_type), + phi_label_(phi_label), + state_(kNoStateId), + phi_loop_(phi_loop), + error_(false) { + if (match_type == MATCH_BOTH) { + FSTERROR() << "PhiMatcher: bad match type"; + match_type_ = MATCH_NONE; + error_ = true; + } + + if (rewrite_mode == MATCHER_REWRITE_AUTO) + rewrite_both_ = fst.Properties(kAcceptor, true); + else if (rewrite_mode == MATCHER_REWRITE_ALWAYS) + rewrite_both_ = true; + else + rewrite_both_ = false; + } + + PhiMatcher(const PhiMatcher &matcher, bool safe = false) + : matcher_(new M(*matcher.matcher_, safe)), + match_type_(matcher.match_type_), + phi_label_(matcher.phi_label_), + rewrite_both_(matcher.rewrite_both_), + state_(kNoStateId), + phi_loop_(matcher.phi_loop_), + error_(matcher.error_) {} + + virtual ~PhiMatcher() { + delete matcher_; + } + + virtual PhiMatcher *Copy(bool safe = false) const { + return new PhiMatcher(*this, safe); + } + + virtual MatchType Type(bool test) const { return matcher_->Type(test); } + + void SetState(StateId s) { + matcher_->SetState(s); + state_ = s; + has_phi_ = phi_label_ != kNoLabel; + } + + bool Find(Label match_label); + + bool Done() const { return matcher_->Done(); } + + const Arc& Value() const { + if ((phi_match_ == kNoLabel) && (phi_weight_ == Weight::One())) { + return matcher_->Value(); + } else if (phi_match_ == 0) { // Virtual epsilon loop + phi_arc_ = Arc(kNoLabel, 0, Weight::One(), state_); + if (match_type_ == MATCH_OUTPUT) + swap(phi_arc_.ilabel, phi_arc_.olabel); + return phi_arc_; + } else { + phi_arc_ = matcher_->Value(); + phi_arc_.weight = Times(phi_weight_, phi_arc_.weight); + if (phi_match_ != kNoLabel) { // Phi loop match + if (rewrite_both_) { + if (phi_arc_.ilabel == phi_label_) + phi_arc_.ilabel = phi_match_; + if (phi_arc_.olabel == phi_label_) + phi_arc_.olabel = phi_match_; + } else if (match_type_ == MATCH_INPUT) { + phi_arc_.ilabel = phi_match_; + } else { + phi_arc_.olabel = phi_match_; + } + } + return phi_arc_; + } + } + + void Next() { matcher_->Next(); } + + virtual const FST &GetFst() const { return matcher_->GetFst(); } + + virtual uint64 Properties(uint64 props) const; + + virtual uint32 Flags() const { + if (phi_label_ == kNoLabel || match_type_ == MATCH_NONE) + return matcher_->Flags(); + return matcher_->Flags() | kRequireMatch; + } + +private: + virtual void SetState_(StateId s) { SetState(s); } + virtual bool Find_(Label label) { return Find(label); } + virtual bool Done_() const { return Done(); } + virtual const Arc& Value_() const { return Value(); } + virtual void Next_() { Next(); } + + M *matcher_; + MatchType match_type_; // Type of match requested + Label phi_label_; // Label that represents the phi transition + bool rewrite_both_; // Rewrite both sides when both are 'phi_label_' + bool has_phi_; // Are there possibly phis at the current state? + Label phi_match_; // Current label that matches phi loop + mutable Arc phi_arc_; // Arc to return + StateId state_; // State where looking for matches + Weight phi_weight_; // Product of the weights of phi transitions taken + bool phi_loop_; // When true, phi self-loop are allowed and treated + // as rho (required for Aho-Corasick) + bool error_; // Error encountered + + void operator=(const PhiMatcher &); // disallow +}; + +template inline +bool PhiMatcher::Find(Label match_label) { + if (match_label == phi_label_ && phi_label_ != kNoLabel && phi_label_ != 0) { + FSTERROR() << "PhiMatcher::Find: bad label (phi): " << phi_label_; + error_ = true; + return false; + } + matcher_->SetState(state_); + phi_match_ = kNoLabel; + phi_weight_ = Weight::One(); + if (phi_label_ == 0) { // When 'phi_label_ == 0', + if (match_label == kNoLabel) // there are no more true epsilon arcs, + return false; + if (match_label == 0) { // but virtual eps loop need to be returned + if (!matcher_->Find(kNoLabel)) { + return matcher_->Find(0); + } else { + phi_match_ = 0; + return true; + } + } + } + if (!has_phi_ || match_label == 0 || match_label == kNoLabel) + return matcher_->Find(match_label); + StateId state = state_; + while (!matcher_->Find(match_label)) { + // Look for phi transition (if phi_label_ == 0, we need to look + // for -1 to avoid getting the virtual self-loop) + if (!matcher_->Find(phi_label_ == 0 ? -1 : phi_label_)) + return false; + if (phi_loop_ && matcher_->Value().nextstate == state) { + phi_match_ = match_label; + return true; + } + phi_weight_ = Times(phi_weight_, matcher_->Value().weight); + state = matcher_->Value().nextstate; + matcher_->Next(); + if (!matcher_->Done()) { + FSTERROR() << "PhiMatcher: phi non-determinism not supported"; + error_ = true; + } + matcher_->SetState(state); + } + return true; +} + +template inline +uint64 PhiMatcher::Properties(uint64 inprops) const { + uint64 outprops = matcher_->Properties(inprops); + if (error_) outprops |= kError; + + if (match_type_ == MATCH_NONE) { + return outprops; + } else if (match_type_ == MATCH_INPUT) { + if (phi_label_ == 0) { + outprops &= ~kEpsilons | ~kIEpsilons | ~kOEpsilons; + outprops |= kNoEpsilons | kNoIEpsilons; + } + if (rewrite_both_) { + return outprops & ~(kODeterministic | kNonODeterministic | kString | + kILabelSorted | kNotILabelSorted | + kOLabelSorted | kNotOLabelSorted); + } else { + return outprops & ~(kODeterministic | kAcceptor | kString | + kILabelSorted | kNotILabelSorted | + kOLabelSorted | kNotOLabelSorted); + } + } else if (match_type_ == MATCH_OUTPUT) { + if (phi_label_ == 0) { + outprops &= ~kEpsilons | ~kIEpsilons | ~kOEpsilons; + outprops |= kNoEpsilons | kNoOEpsilons; + } + if (rewrite_both_) { + return outprops & ~(kIDeterministic | kNonIDeterministic | kString | + kILabelSorted | kNotILabelSorted | + kOLabelSorted | kNotOLabelSorted); + } else { + return outprops & ~(kIDeterministic | kAcceptor | kString | + kILabelSorted | kNotILabelSorted | + kOLabelSorted | kNotOLabelSorted); + } + } else { + // Shouldn't ever get here. + FSTERROR() << "PhiMatcher:: bad match type: " << match_type_; + return 0; + } +} + + +// +// MULTI-EPS MATCHER FLAGS +// + +// Return multi-epsilon arcs for Find(kNoLabel). +const uint32 kMultiEpsList = 0x00000001; + +// Return a kNolabel loop for Find(multi_eps). +const uint32 kMultiEpsLoop = 0x00000002; + +// MultiEpsMatcher: allows treating multiple non-0 labels as +// non-consuming labels in addition to 0 that is always +// non-consuming. Precise behavior controlled by 'flags' argument. By +// default, the underlying matcher is constructed by +// MultiEpsMatcher. The user can instead pass in this object; in that +// case, MultiEpsMatcher takes its ownership iff 'own_matcher' is +// true. +template +class MultiEpsMatcher { + public: + typedef typename M::FST FST; + typedef typename M::Arc Arc; + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + + MultiEpsMatcher(const FST &fst, MatchType match_type, + uint32 flags = (kMultiEpsLoop | kMultiEpsList), + M *matcher = 0, bool own_matcher = true) + : matcher_(matcher ? matcher : new M(fst, match_type)), + flags_(flags), + own_matcher_(matcher ? own_matcher : true) { + if (match_type == MATCH_INPUT) { + loop_.ilabel = kNoLabel; + loop_.olabel = 0; + } else { + loop_.ilabel = 0; + loop_.olabel = kNoLabel; + } + loop_.weight = Weight::One(); + loop_.nextstate = kNoStateId; + } + + MultiEpsMatcher(const MultiEpsMatcher &matcher, bool safe = false) + : matcher_(new M(*matcher.matcher_, safe)), + flags_(matcher.flags_), + own_matcher_(true), + multi_eps_labels_(matcher.multi_eps_labels_), + loop_(matcher.loop_) { + loop_.nextstate = kNoStateId; + } + + ~MultiEpsMatcher() { + if (own_matcher_) + delete matcher_; + } + + MultiEpsMatcher *Copy(bool safe = false) const { + return new MultiEpsMatcher(*this, safe); + } + + MatchType Type(bool test) const { return matcher_->Type(test); } + + void SetState(StateId s) { + matcher_->SetState(s); + loop_.nextstate = s; + } + + bool Find(Label match_label); + + bool Done() const { + return done_; + } + + const Arc& Value() const { + return current_loop_ ? loop_ : matcher_->Value(); + } + + void Next() { + if (!current_loop_) { + matcher_->Next(); + done_ = matcher_->Done(); + if (done_ && multi_eps_iter_ != multi_eps_labels_.End()) { + ++multi_eps_iter_; + while ((multi_eps_iter_ != multi_eps_labels_.End()) && + !matcher_->Find(*multi_eps_iter_)) + ++multi_eps_iter_; + if (multi_eps_iter_ != multi_eps_labels_.End()) + done_ = false; + else + done_ = !matcher_->Find(kNoLabel); + + } + } else { + done_ = true; + } + } + + const FST &GetFst() const { return matcher_->GetFst(); } + + uint64 Properties(uint64 props) const { return matcher_->Properties(props); } + + uint32 Flags() const { return matcher_->Flags(); } + + void AddMultiEpsLabel(Label label) { + if (label == 0) { + FSTERROR() << "MultiEpsMatcher: Bad multi-eps label: 0"; + } else { + multi_eps_labels_.Insert(label); + } + } + + void RemoveMultiEpsLabel(Label label) { + if (label == 0) { + FSTERROR() << "MultiEpsMatcher: Bad multi-eps label: 0"; + } else { + multi_eps_labels_.Erase(label); + } + } + + void ClearMultiEpsLabels() { + multi_eps_labels_.Clear(); + } + +private: + M *matcher_; + uint32 flags_; + bool own_matcher_; // Does this class delete the matcher? + + // Multi-eps label set + CompactSet multi_eps_labels_; + typename CompactSet::const_iterator multi_eps_iter_; + + bool current_loop_; // Current arc is the implicit loop + mutable Arc loop_; // For non-consuming symbols + bool done_; // Matching done + + void operator=(const MultiEpsMatcher &); // Disallow +}; + +template inline +bool MultiEpsMatcher::Find(Label match_label) { + multi_eps_iter_ = multi_eps_labels_.End(); + current_loop_ = false; + bool ret; + if (match_label == 0) { + ret = matcher_->Find(0); + } else if (match_label == kNoLabel) { + if (flags_ & kMultiEpsList) { + // return all non-consuming arcs (incl. epsilon) + multi_eps_iter_ = multi_eps_labels_.Begin(); + while ((multi_eps_iter_ != multi_eps_labels_.End()) && + !matcher_->Find(*multi_eps_iter_)) + ++multi_eps_iter_; + if (multi_eps_iter_ != multi_eps_labels_.End()) + ret = true; + else + ret = matcher_->Find(kNoLabel); + } else { + // return all epsilon arcs + ret = matcher_->Find(kNoLabel); + } + } else if ((flags_ & kMultiEpsLoop) && + multi_eps_labels_.Find(match_label) != multi_eps_labels_.End()) { + // return 'implicit' loop + current_loop_ = true; + ret = true; + } else { + ret = matcher_->Find(match_label); + } + done_ = !ret; + return ret; +} + + +// Generic matcher, templated on the FST definition +// - a wrapper around pointer to specific one. +// Here is a typical use: \code +// Matcher matcher(fst, MATCH_INPUT); +// matcher.SetState(state); +// if (matcher.Find(label)) +// for (; !matcher.Done(); matcher.Next()) { +// StdArc &arc = matcher.Value(); +// ... +// } \endcode +template +class Matcher { + public: + typedef F FST; + typedef typename F::Arc Arc; + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + + Matcher(const F &fst, MatchType match_type) { + base_ = fst.InitMatcher(match_type); + if (!base_) + base_ = new SortedMatcher(fst, match_type); + } + + Matcher(const Matcher &matcher, bool safe = false) { + base_ = matcher.base_->Copy(safe); + } + + // Takes ownership of the provided matcher + Matcher(MatcherBase* base_matcher) { base_ = base_matcher; } + + ~Matcher() { delete base_; } + + Matcher *Copy(bool safe = false) const { + return new Matcher(*this, safe); + } + + MatchType Type(bool test) const { return base_->Type(test); } + void SetState(StateId s) { base_->SetState(s); } + bool Find(Label label) { return base_->Find(label); } + bool Done() const { return base_->Done(); } + const Arc& Value() const { return base_->Value(); } + void Next() { base_->Next(); } + const F &GetFst() const { return static_cast(base_->GetFst()); } + uint64 Properties(uint64 props) const { return base_->Properties(props); } + uint32 Flags() const { return base_->Flags() & kMatcherFlags; } + + private: + MatcherBase *base_; + + void operator=(const Matcher &); // disallow +}; + +} // namespace fst + + + +#endif // FST_LIB_MATCHER_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/minimize.h b/kaldi_io/src/tools/openfst/include/fst/minimize.h new file mode 100644 index 0000000..6e9dd3d --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/minimize.h @@ -0,0 +1,591 @@ +// minimize.h +// minimize.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: johans@google.com (Johan Schalkwyk) +// +// \file Functions and classes to minimize a finite state acceptor +// + +#ifndef FST_LIB_MINIMIZE_H__ +#define FST_LIB_MINIMIZE_H__ + +#include + +#include +#include +#include +#include +using std::vector; + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace fst { + +// comparator for creating partition based on sorting on +// - states +// - final weight +// - out degree, +// - (input label, output label, weight, destination_block) +template +class StateComparator { + public: + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + static const uint32 kCompareFinal = 0x00000001; + static const uint32 kCompareOutDegree = 0x00000002; + static const uint32 kCompareArcs = 0x00000004; + static const uint32 kCompareAll = 0x00000007; + + StateComparator(const Fst& fst, + const Partition& partition, + uint32 flags = kCompareAll) + : fst_(fst), partition_(partition), flags_(flags) {} + + // compare state x with state y based on sort criteria + bool operator()(const StateId x, const StateId y) const { + // check for final state equivalence + if (flags_ & kCompareFinal) { + const size_t xfinal = fst_.Final(x).Hash(); + const size_t yfinal = fst_.Final(y).Hash(); + if (xfinal < yfinal) return true; + else if (xfinal > yfinal) return false; + } + + if (flags_ & kCompareOutDegree) { + // check for # arcs + if (fst_.NumArcs(x) < fst_.NumArcs(y)) return true; + if (fst_.NumArcs(x) > fst_.NumArcs(y)) return false; + + if (flags_ & kCompareArcs) { + // # arcs are equal, check for arc match + for (ArcIterator > aiter1(fst_, x), aiter2(fst_, y); + !aiter1.Done() && !aiter2.Done(); aiter1.Next(), aiter2.Next()) { + const A& arc1 = aiter1.Value(); + const A& arc2 = aiter2.Value(); + if (arc1.ilabel < arc2.ilabel) return true; + if (arc1.ilabel > arc2.ilabel) return false; + + if (partition_.class_id(arc1.nextstate) < + partition_.class_id(arc2.nextstate)) return true; + if (partition_.class_id(arc1.nextstate) > + partition_.class_id(arc2.nextstate)) return false; + } + } + } + + return false; + } + + private: + const Fst& fst_; + const Partition& partition_; + const uint32 flags_; +}; + +template const uint32 StateComparator::kCompareFinal; +template const uint32 StateComparator::kCompareOutDegree; +template const uint32 StateComparator::kCompareArcs; +template const uint32 StateComparator::kCompareAll; + + +// Computes equivalence classes for cyclic Fsts. For cyclic minimization +// we use the classic HopCroft minimization algorithm, which is of +// +// O(E)log(N), +// +// where E is the number of edges in the machine and N is number of states. +// +// The following paper describes the original algorithm +// An N Log N algorithm for minimizing states in a finite automaton +// by John HopCroft, January 1971 +// +template +class CyclicMinimizer { + public: + typedef typename A::Label Label; + typedef typename A::StateId StateId; + typedef typename A::StateId ClassId; + typedef typename A::Weight Weight; + typedef ReverseArc RevA; + + CyclicMinimizer(const ExpandedFst& 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); + } + + ~CyclicMinimizer() { + delete aiter_queue_; + } + + const Partition& partition() const { + return P_; + } + + // helper classes + private: + typedef ArcIterator > ArcIter; + class ArcIterCompare { + public: + ArcIterCompare(const Partition& partition) + : partition_(partition) {} + + ArcIterCompare(const ArcIterCompare& comp) + : partition_(comp.partition_) {} + + // compare two iterators based on there input labels, and proto state + // (partition class Ids) + bool operator()(const ArcIter* x, const ArcIter* y) const { + const RevA& xarc = x->Value(); + const RevA& yarc = y->Value(); + return (xarc.ilabel > yarc.ilabel); + } + + private: + const Partition& partition_; + }; + + typedef priority_queue, ArcIterCompare> + ArcIterQueue; + + // helper methods + private: + // prepartitions the space into equivalence classes with + // same final weight + // same # arcs per state + // same outgoing arcs + void PrePartition(const Fst& fst) { + VLOG(5) << "PrePartition"; + + typedef map > EquivalenceMap; + StateComparator comp(fst, P_, StateComparator::kCompareFinal); + EquivalenceMap equiv_map(comp); + + StateIterator > siter(fst); + StateId class_id = P_.AddClass(); + P_.Add(siter.Value(), class_id); + equiv_map[siter.Value()] = class_id; + L_.Enqueue(class_id); + for (siter.Next(); !siter.Done(); siter.Next()) { + StateId s = siter.Value(); + typename EquivalenceMap::const_iterator it = equiv_map.find(s); + if (it == equiv_map.end()) { + class_id = P_.AddClass(); + P_.Add(s, class_id); + equiv_map[s] = class_id; + L_.Enqueue(class_id); + } else { + P_.Add(s, it->second); + equiv_map[s] = it->second; + } + } + + VLOG(5) << "Initial Partition: " << P_.num_classes(); + } + + // - Create inverse transition Tr_ = rev(fst) + // - loop over states in fst and split on final, creating two blocks + // in the partition corresponding to final, non-final + void Initialize(const Fst& fst) { + // construct Tr + Reverse(fst, &Tr_); + ILabelCompare ilabel_comp; + ArcSort(&Tr_, ilabel_comp); + + // initial split (F, S - F) + P_.Initialize(Tr_.NumStates() - 1); + + // prep partition + PrePartition(fst); + + // allocate arc iterator queue + ArcIterCompare comp(P_); + aiter_queue_ = new ArcIterQueue(comp); + } + + // partition all classes with destination C + void Split(ClassId C) { + // Prep priority queue. Open arc iterator for each state in C, and + // insert into priority queue. + for (PartitionIterator siter(P_, C); + !siter.Done(); siter.Next()) { + StateId s = siter.Value(); + if (Tr_.NumArcs(s + 1)) + aiter_queue_->push(new ArcIterator >(Tr_, s + 1)); + } + + // Now pop arc iterator from queue, split entering equivalence class + // re-insert updated iterator into queue. + Label prev_label = -1; + while (!aiter_queue_->empty()) { + ArcIterator >* aiter = aiter_queue_->top(); + aiter_queue_->pop(); + if (aiter->Done()) { + delete aiter; + continue; + } + + const RevA& arc = aiter->Value(); + StateId from_state = aiter->Value().nextstate - 1; + Label from_label = arc.ilabel; + if (prev_label != from_label) + P_.FinalizeSplit(&L_); + + StateId from_class = P_.class_id(from_state); + if (P_.class_size(from_class) > 1) + P_.SplitOn(from_state); + + prev_label = from_label; + aiter->Next(); + if (aiter->Done()) + delete aiter; + else + aiter_queue_->push(aiter); + } + P_.FinalizeSplit(&L_); + } + + // Main loop for hopcroft minimization. + void Compute(const Fst& fst) { + // process active classes (FIFO, or FILO) + while (!L_.Empty()) { + ClassId C = L_.Head(); + L_.Dequeue(); + + // split on C, all labels in C + Split(C); + } + } + + // helper data + private: + // Partioning of states into equivalence classes + Partition P_; + + // L = set of active classes to be processed in partition P + Queue L_; + + // reverse transition function + VectorFst Tr_; + + // Priority queue of open arc iterators for all states in the 'splitter' + // equivalence class + ArcIterQueue* aiter_queue_; +}; + + +// Computes equivalence classes for acyclic Fsts. The implementation details +// for this algorithms is documented by the following paper. +// +// Minimization of acyclic deterministic automata in linear time +// Dominque Revuz +// +// Complexity O(|E|) +// +template +class AcyclicMinimizer { + public: + typedef typename A::Label Label; + typedef typename A::StateId StateId; + typedef typename A::StateId ClassId; + typedef typename A::Weight Weight; + + AcyclicMinimizer(const ExpandedFst& 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); + } + + const Partition& partition() { + return partition_; + } + + // helper classes + private: + // DFS visitor to compute the height (distance) to final state. + class HeightVisitor { + public: + HeightVisitor() : max_height_(0), num_states_(0) { } + + // invoked before dfs visit + void InitVisit(const Fst& fst) {} + + // invoked when state is discovered (2nd arg is DFS tree root) + bool InitState(StateId s, StateId root) { + // extend height array and initialize height (distance) to 0 + for (size_t i = height_.size(); i <= s; ++i) + height_.push_back(-1); + + if (s >= num_states_) num_states_ = s + 1; + return true; + } + + // invoked when tree arc examined (to undiscoverted state) + bool TreeArc(StateId s, const A& arc) { + return true; + } + + // invoked when back arc examined (to unfinished state) + bool BackArc(StateId s, const A& arc) { + return true; + } + + // invoked when forward or cross arc examined (to finished state) + bool ForwardOrCrossArc(StateId s, const A& arc) { + if (height_[arc.nextstate] + 1 > height_[s]) + height_[s] = height_[arc.nextstate] + 1; + return true; + } + + // invoked when state finished (parent is kNoStateId for tree root) + void FinishState(StateId s, StateId parent, const A* parent_arc) { + if (height_[s] == -1) height_[s] = 0; + StateId h = height_[s] + 1; + if (parent >= 0) { + if (h > height_[parent]) height_[parent] = h; + if (h > max_height_) max_height_ = h; + } + } + + // invoked after DFS visit + void FinishVisit() {} + + size_t max_height() const { return max_height_; } + + const vector& height() const { return height_; } + + const size_t num_states() const { return num_states_; } + + private: + vector height_; + size_t max_height_; + size_t num_states_; + }; + + // helper methods + private: + // cluster states according to height (distance to final state) + void Initialize(const Fst& fst) { + // compute height (distance to final state) + HeightVisitor hvisitor; + DfsVisit(fst, &hvisitor); + + // create initial partition based on height + partition_.Initialize(hvisitor.num_states()); + partition_.AllocateClasses(hvisitor.max_height() + 1); + const vector& hstates = hvisitor.height(); + for (size_t s = 0; s < hstates.size(); ++s) + partition_.Add(s, hstates[s]); + } + + // refine states based on arc sort (out degree, arc equivalence) + void Refine(const Fst& fst) { + typedef map > EquivalenceMap; + StateComparator comp(fst, partition_); + + // start with tail (height = 0) + size_t height = partition_.num_classes(); + for (size_t h = 0; h < height; ++h) { + EquivalenceMap equiv_classes(comp); + + // sort states within equivalence class + PartitionIterator siter(partition_, h); + equiv_classes[siter.Value()] = h; + for (siter.Next(); !siter.Done(); siter.Next()) { + const StateId s = siter.Value(); + typename EquivalenceMap::const_iterator it = equiv_classes.find(s); + if (it == equiv_classes.end()) + equiv_classes[s] = partition_.AddClass(); + else + equiv_classes[s] = it->second; + } + + // create refined partition + for (siter.Reset(); !siter.Done();) { + const StateId s = siter.Value(); + const StateId old_class = partition_.class_id(s); + const StateId new_class = equiv_classes[s]; + + // a move operation can invalidate the iterator, so + // we first update the iterator to the next element + // before we move the current element out of the list + siter.Next(); + if (old_class != new_class) + partition_.Move(s, new_class); + } + } + } + + private: + Partition partition_; +}; + + +// Given a partition and a mutable fst, merge states of Fst inplace +// (i.e. destructively). Merging works by taking the first state in +// a class of the partition to be the representative state for the class. +// Each arc is then reconnected to this state. All states in the class +// are merged by adding there arcs to the representative state. +template +void MergeStates( + const Partition& partition, MutableFst* fst) { + typedef typename A::StateId StateId; + + vector state_map(partition.num_classes()); + for (size_t i = 0; i < partition.num_classes(); ++i) { + PartitionIterator siter(partition, i); + state_map[i] = siter.Value(); // first state in partition; + } + + // relabel destination states + for (size_t c = 0; c < partition.num_classes(); ++c) { + for (PartitionIterator siter(partition, c); + !siter.Done(); siter.Next()) { + StateId s = siter.Value(); + for (MutableArcIterator > aiter(fst, s); + !aiter.Done(); aiter.Next()) { + A arc = aiter.Value(); + arc.nextstate = state_map[partition.class_id(arc.nextstate)]; + + if (s == state_map[c]) // first state just set destination + aiter.SetValue(arc); + else + fst->AddArc(state_map[c], arc); + } + } + } + fst->SetStart(state_map[partition.class_id(fst->Start())]); + + Connect(fst); +} + +template +void AcceptorMinimize(MutableFst* fst) { + typedef typename A::StateId StateId; + if (!(fst->Properties(kAcceptor | kUnweighted, true))) { + FSTERROR() << "FST is not an unweighted acceptor"; + fst->SetProperties(kError, kError); + return; + } + + // connect fst before minimization, handles disconnected states + Connect(fst); + if (fst->NumStates() == 0) return; + + if (fst->Properties(kAcyclic, true)) { + // Acyclic minimization (revuz) + VLOG(2) << "Acyclic Minimization"; + ArcSort(fst, ILabelCompare()); + AcyclicMinimizer minimizer(*fst); + MergeStates(minimizer.partition(), fst); + + } else { + // Cyclic minimizaton (hopcroft) + VLOG(2) << "Cyclic Minimization"; + CyclicMinimizer > minimizer(*fst); + MergeStates(minimizer.partition(), fst); + } + + // Merge in appropriate semiring + ArcUniqueMapper mapper(*fst); + StateMap(fst, mapper); +} + + +// In place minimization of deterministic weighted automata and transducers. +// For transducers, then the 'sfst' argument is not null, the algorithm +// produces a compact factorization of the minimal transducer. +// +// In the acyclic case, we use an algorithm from Dominique Revuz that +// is linear in the number of arcs (edges) in the machine. +// Complexity = O(E) +// +// In the cyclic case, we use the classical hopcroft minimization. +// Complexity = O(|E|log(|N|) +// +template +void Minimize(MutableFst* fst, + MutableFst* sfst = 0, + float delta = kDelta) { + uint64 props = fst->Properties(kAcceptor | kWeighted | kUnweighted, true); + + if (!(props & kAcceptor)) { // weighted transducer + VectorFst< GallicArc > gfst; + ArcMap(*fst, &gfst, ToGallicMapper()); + fst->DeleteStates(); + gfst.SetProperties(kAcceptor, kAcceptor); + Push(&gfst, REWEIGHT_TO_INITIAL, delta); + ArcMap(&gfst, QuantizeMapper< GallicArc >(delta)); + EncodeMapper< GallicArc > + encoder(kEncodeLabels | kEncodeWeights, ENCODE); + Encode(&gfst, &encoder); + AcceptorMinimize(&gfst); + Decode(&gfst, encoder); + + if (sfst == 0) { + FactorWeightFst< GallicArc, + GallicFactor > fwfst(gfst); + SymbolTable *osyms = fst->OutputSymbols() ? + fst->OutputSymbols()->Copy() : 0; + ArcMap(fwfst, fst, FromGallicMapper()); + fst->SetOutputSymbols(osyms); + delete osyms; + } else { + sfst->SetOutputSymbols(fst->OutputSymbols()); + GallicToNewSymbolsMapper mapper(sfst); + ArcMap(gfst, fst, &mapper); + fst->SetOutputSymbols(sfst->InputSymbols()); + } + } else if (props & kWeighted) { // weighted acceptor + Push(fst, REWEIGHT_TO_INITIAL, delta); + ArcMap(fst, QuantizeMapper(delta)); + EncodeMapper encoder(kEncodeLabels | kEncodeWeights, ENCODE); + Encode(fst, &encoder); + AcceptorMinimize(fst); + Decode(fst, encoder); + } else { // unweighted acceptor + AcceptorMinimize(fst); + } +} + +} // namespace fst + +#endif // FST_LIB_MINIMIZE_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/mutable-fst.h b/kaldi_io/src/tools/openfst/include/fst/mutable-fst.h new file mode 100644 index 0000000..09eb237 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/mutable-fst.h @@ -0,0 +1,378 @@ +// mutable-fst.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Expanded FST augmented with mutators - interface class definition +// and mutable arc iterator interface. +// + +#ifndef FST_LIB_MUTABLE_FST_H__ +#define FST_LIB_MUTABLE_FST_H__ + +#include +#include +#include +#include +using std::vector; + +#include + + +namespace fst { + +template class MutableArcIteratorData; + +// An expanded FST plus mutators (use MutableArcIterator to modify arcs). +template +class MutableFst : public ExpandedFst { + public: + typedef A Arc; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + + virtual MutableFst &operator=(const Fst &fst) = 0; + + MutableFst &operator=(const MutableFst &fst) { + return operator=(static_cast &>(fst)); + } + + virtual void SetStart(StateId) = 0; // Set the initial state + virtual void SetFinal(StateId, Weight) = 0; // Set a state's final weight + virtual void SetProperties(uint64 props, + uint64 mask) = 0; // Set property bits wrt mask + + virtual StateId AddState() = 0; // Add a state, return its ID + virtual void AddArc(StateId, const A &arc) = 0; // Add an arc to state + + virtual void DeleteStates(const vector&) = 0; // Delete some states + virtual void DeleteStates() = 0; // Delete all states + virtual void DeleteArcs(StateId, size_t n) = 0; // Delete some arcs at state + virtual void DeleteArcs(StateId) = 0; // Delete all arcs at state + + virtual void ReserveStates(StateId n) { } // Optional, best effort only. + virtual void ReserveArcs(StateId s, size_t n) { } // Optional, Best effort. + + // Return input label symbol table; return NULL if not specified + virtual const SymbolTable* InputSymbols() const = 0; + // Return output label symbol table; return NULL if not specified + virtual const SymbolTable* OutputSymbols() const = 0; + + // Return input label symbol table; return NULL if not specified + virtual SymbolTable* MutableInputSymbols() = 0; + // Return output label symbol table; return NULL if not specified + virtual SymbolTable* MutableOutputSymbols() = 0; + + // Set input label symbol table; NULL signifies not unspecified + virtual void SetInputSymbols(const SymbolTable* isyms) = 0; + // Set output label symbol table; NULL signifies not unspecified + virtual void SetOutputSymbols(const SymbolTable* osyms) = 0; + + // Get a copy of this MutableFst. See Fst<>::Copy() for further doc. + virtual MutableFst *Copy(bool safe = false) const = 0; + + // Read an MutableFst from an input stream; return NULL on error. + static MutableFst *Read(istream &strm, const FstReadOptions &opts) { + FstReadOptions ropts(opts); + FstHeader hdr; + if (ropts.header) + hdr = *opts.header; + else { + if (!hdr.Read(strm, opts.source)) + return 0; + ropts.header = &hdr; + } + if (!(hdr.Properties() & kMutable)) { + LOG(ERROR) << "MutableFst::Read: Not an MutableFst: " << ropts.source; + return 0; + } + FstRegister *registr = FstRegister::GetRegister(); + const typename FstRegister::Reader reader = + registr->GetReader(hdr.FstType()); + if (!reader) { + LOG(ERROR) << "MutableFst::Read: Unknown FST type \"" << hdr.FstType() + << "\" (arc type = \"" << A::Type() + << "\"): " << ropts.source; + return 0; + } + Fst *fst = reader(strm, ropts); + if (!fst) return 0; + return static_cast *>(fst); + } + + // Read a MutableFst from a file; return NULL on error. + // Empty filename reads from standard input. If 'convert' is true, + // convert to a mutable FST of type 'convert_type' if file is + // a non-mutable FST. + static MutableFst *Read(const string &filename, bool convert = false, + const string &convert_type = "vector") { + if (convert == false) { + if (!filename.empty()) { + ifstream strm(filename.c_str(), ifstream::in | ifstream::binary); + if (!strm) { + LOG(ERROR) << "MutableFst::Read: Can't open file: " << filename; + return 0; + } + return Read(strm, FstReadOptions(filename)); + } else { + return Read(cin, FstReadOptions("standard input")); + } + } else { // Converts to 'convert_type' if not mutable. + Fst *ifst = Fst::Read(filename); + if (!ifst) return 0; + if (ifst->Properties(kMutable, false)) { + return static_cast(ifst); + } else { + Fst *ofst = Convert(*ifst, convert_type); + delete ifst; + if (!ofst) return 0; + if (!ofst->Properties(kMutable, false)) + LOG(ERROR) << "MutableFst: bad convert type: " << convert_type; + return static_cast(ofst); + } + } + } + + // For generic mutuble arc iterator construction; not normally called + // directly by users. + virtual void InitMutableArcIterator(StateId s, + MutableArcIteratorData *) = 0; +}; + +// Mutable arc iterator interface, templated on the Arc definition; used +// for mutable Arc iterator specializations that are returned by +// the InitMutableArcIterator MutableFst method. +template +class MutableArcIteratorBase : public ArcIteratorBase { + public: + typedef A Arc; + + void SetValue(const A &arc) { SetValue_(arc); } // Set current arc's content + + private: + virtual void SetValue_(const A &arc) = 0; +}; + +template +struct MutableArcIteratorData { + MutableArcIteratorBase *base; // Specific iterator +}; + +// Generic mutable arc iterator, templated on the FST definition +// - a wrapper around pointer to specific one. +// Here is a typical use: \code +// for (MutableArcIterator aiter(&fst, s)); +// !aiter.Done(); +// aiter.Next()) { +// StdArc arc = aiter.Value(); +// arc.ilabel = 7; +// aiter.SetValue(arc); +// ... +// } \endcode +// This version requires function calls. +template +class MutableArcIterator { + public: + typedef F FST; + typedef typename F::Arc Arc; + typedef typename Arc::StateId StateId; + + MutableArcIterator(F *fst, StateId s) { + fst->InitMutableArcIterator(s, &data_); + } + ~MutableArcIterator() { delete data_.base; } + + bool Done() const { return data_.base->Done(); } + const Arc& Value() const { return data_.base->Value(); } + void Next() { data_.base->Next(); } + size_t Position() const { return data_.base->Position(); } + void Reset() { data_.base->Reset(); } + void Seek(size_t a) { data_.base->Seek(a); } + void SetValue(const Arc &a) { data_.base->SetValue(a); } + uint32 Flags() const { return data_.base->Flags(); } + void SetFlags(uint32 f, uint32 m) { + return data_.base->SetFlags(f, m); + } + + private: + MutableArcIteratorData data_; + DISALLOW_COPY_AND_ASSIGN(MutableArcIterator); +}; + + +namespace internal { + +// MutableFst case - abstract methods. +template inline +typename A::Weight Final(const MutableFst &fst, typename A::StateId s) { + return fst.Final(s); +} + +template inline +ssize_t NumArcs(const MutableFst &fst, typename A::StateId s) { + return fst.NumArcs(s); +} + +template inline +ssize_t NumInputEpsilons(const MutableFst &fst, typename A::StateId s) { + return fst.NumInputEpsilons(s); +} + +template inline +ssize_t NumOutputEpsilons(const MutableFst &fst, typename A::StateId s) { + return fst.NumOutputEpsilons(s); +} + +} // namespace internal + + +// A useful alias when using StdArc. +typedef MutableFst StdMutableFst; + + +// This is a helper class template useful for attaching a MutableFst +// interface to its implementation, handling reference counting and +// copy-on-write. +template > +class ImplToMutableFst : public ImplToExpandedFst { + public: + typedef typename I::Arc Arc; + typedef typename Arc::Weight Weight; + typedef typename Arc::StateId StateId; + + using ImplToFst::GetImpl; + using ImplToFst::SetImpl; + + virtual void SetStart(StateId s) { + MutateCheck(); + GetImpl()->SetStart(s); + } + + virtual void SetFinal(StateId s, Weight w) { + MutateCheck(); + GetImpl()->SetFinal(s, w); + } + + virtual void SetProperties(uint64 props, uint64 mask) { + // Can skip mutate check if extrinsic properties don't change, + // since it is then safe to update all (shallow) copies + uint64 exprops = kExtrinsicProperties & mask; + if (GetImpl()->Properties(exprops) != (props & exprops)) + MutateCheck(); + GetImpl()->SetProperties(props, mask); + } + + virtual StateId AddState() { + MutateCheck(); + return GetImpl()->AddState(); + } + + virtual void AddArc(StateId s, const Arc &arc) { + MutateCheck(); + GetImpl()->AddArc(s, arc); + } + + virtual void DeleteStates(const vector &dstates) { + MutateCheck(); + GetImpl()->DeleteStates(dstates); + } + + virtual void DeleteStates() { + MutateCheck(); + GetImpl()->DeleteStates(); + } + + virtual void DeleteArcs(StateId s, size_t n) { + MutateCheck(); + GetImpl()->DeleteArcs(s, n); + } + + virtual void DeleteArcs(StateId s) { + MutateCheck(); + GetImpl()->DeleteArcs(s); + } + + virtual void ReserveStates(StateId s) { + MutateCheck(); + GetImpl()->ReserveStates(s); + } + + virtual void ReserveArcs(StateId s, size_t n) { + MutateCheck(); + GetImpl()->ReserveArcs(s, n); + } + + virtual const SymbolTable* InputSymbols() const { + return GetImpl()->InputSymbols(); + } + + virtual const SymbolTable* OutputSymbols() const { + return GetImpl()->OutputSymbols(); + } + + virtual SymbolTable* MutableInputSymbols() { + MutateCheck(); + return GetImpl()->InputSymbols(); + } + + virtual SymbolTable* MutableOutputSymbols() { + MutateCheck(); + return GetImpl()->OutputSymbols(); + } + + virtual void SetInputSymbols(const SymbolTable* isyms) { + MutateCheck(); + GetImpl()->SetInputSymbols(isyms); + } + + virtual void SetOutputSymbols(const SymbolTable* osyms) { + MutateCheck(); + GetImpl()->SetOutputSymbols(osyms); + } + + protected: + ImplToMutableFst() : ImplToExpandedFst() {} + + ImplToMutableFst(I *impl) : ImplToExpandedFst(impl) {} + + + ImplToMutableFst(const ImplToMutableFst &fst) + : ImplToExpandedFst(fst) {} + + ImplToMutableFst(const ImplToMutableFst &fst, bool safe) + : ImplToExpandedFst(fst, safe) {} + + void MutateCheck() { + // Copy on write + if (GetImpl()->RefCount() > 1) + SetImpl(new I(*this)); + } + + private: + // Disallow + ImplToMutableFst &operator=(const ImplToMutableFst &fst); + + ImplToMutableFst &operator=(const Fst &fst) { + FSTERROR() << "ImplToMutableFst: Assignment operator disallowed"; + GetImpl()->SetProperties(kError, kError); + return *this; + } +}; + + +} // namespace fst + +#endif // FST_LIB_MUTABLE_FST_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/pair-weight.h b/kaldi_io/src/tools/openfst/include/fst/pair-weight.h new file mode 100644 index 0000000..7d8aa11 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/pair-weight.h @@ -0,0 +1,280 @@ +// pair-weight.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: shumash@google.com (Masha Maria Shugrina) +// +// \file +// Pair weight templated base class for weight classes that +// contain two weights (e.g. Product, Lexicographic) + +#ifndef FST_LIB_PAIR_WEIGHT_H_ +#define FST_LIB_PAIR_WEIGHT_H_ + +#include +#include +#include + +#include + + +DECLARE_string(fst_weight_parentheses); +DECLARE_string(fst_weight_separator); + +namespace fst { + +template class PairWeight; +template +istream &operator>>(istream &strm, PairWeight &w); + +template +class PairWeight { + public: + friend istream &operator>>(istream&, PairWeight&); + + typedef PairWeight + ReverseWeight; + + PairWeight() {} + + PairWeight(const PairWeight& w) : value1_(w.value1_), value2_(w.value2_) {} + + PairWeight(W1 w1, W2 w2) : value1_(w1), value2_(w2) {} + + static const PairWeight &Zero() { + static const PairWeight zero(W1::Zero(), W2::Zero()); + return zero; + } + + static const PairWeight &One() { + static const PairWeight one(W1::One(), W2::One()); + return one; + } + + static const PairWeight &NoWeight() { + static const PairWeight no_weight(W1::NoWeight(), W2::NoWeight()); + return no_weight; + } + + istream &Read(istream &strm) { + value1_.Read(strm); + return value2_.Read(strm); + } + + ostream &Write(ostream &strm) const { + value1_.Write(strm); + return value2_.Write(strm); + } + + PairWeight &operator=(const PairWeight &w) { + value1_ = w.Value1(); + value2_ = w.Value2(); + return *this; + } + + bool Member() const { return value1_.Member() && value2_.Member(); } + + size_t Hash() const { + size_t h1 = value1_.Hash(); + size_t h2 = value2_.Hash(); + const int lshift = 5; + const int rshift = CHAR_BIT * sizeof(size_t) - 5; + return h1 << lshift ^ h1 >> rshift ^ h2; + } + + PairWeight Quantize(float delta = kDelta) const { + return PairWeight(value1_.Quantize(delta), + value2_.Quantize(delta)); + } + + ReverseWeight Reverse() const { + return ReverseWeight(value1_.Reverse(), value2_.Reverse()); + } + + const W1& Value1() const { return value1_; } + + const W2& Value2() const { return value2_; } + + protected: + void SetValue1(const W1 &w) { value1_ = w; } + void SetValue2(const W2 &w) { value2_ = w; } + + // Reads PairWeight when there are not parentheses around pair terms + inline static istream &ReadNoParen( + istream &strm, PairWeight& w, char separator) { + int c; + do { + c = strm.get(); + } while (isspace(c)); + + string s1; + while (c != separator) { + if (c == EOF) { + strm.clear(std::ios::badbit); + return strm; + } + s1 += c; + c = strm.get(); + } + istringstream strm1(s1); + W1 w1 = W1::Zero(); + strm1 >> w1; + + // read second element + W2 w2 = W2::Zero(); + strm >> w2; + + w = PairWeight(w1, w2); + return strm; + } + + // Reads PairWeight when there are parentheses around pair terms + inline static istream &ReadWithParen( + istream &strm, PairWeight& w, + char separator, char open_paren, char close_paren) { + int c; + do { + c = strm.get(); + } while (isspace(c)); + if (c != open_paren) { + FSTERROR() << " is fst_weight_parentheses flag set correcty? "; + strm.clear(std::ios::failbit); + return strm; + } + c = strm.get(); + + // read first element + stack parens; + string s1; + while (c != separator || !parens.empty()) { + if (c == EOF) { + strm.clear(std::ios::badbit); + return strm; + } + s1 += c; + // if parens encountered before separator, they must be matched + if (c == open_paren) { + parens.push(1); + } else if (c == close_paren) { + // Fail for mismatched parens + if (parens.empty()) { + strm.clear(std::ios::failbit); + return strm; + } + parens.pop(); + } + c = strm.get(); + } + istringstream strm1(s1); + W1 w1 = W1::Zero(); + strm1 >> w1; + + // read second element + string s2; + c = strm.get(); + while (c != EOF) { + s2 += c; + c = strm.get(); + } + if (s2.empty() || (s2[s2.size() - 1] != close_paren)) { + FSTERROR() << " is fst_weight_parentheses flag set correcty? "; + strm.clear(std::ios::failbit); + return strm; + } + + s2.erase(s2.size() - 1, 1); + istringstream strm2(s2); + W2 w2 = W2::Zero(); + strm2 >> w2; + + w = PairWeight(w1, w2); + return strm; + } + + private: + W1 value1_; + W2 value2_; + +}; + +template +inline bool operator==(const PairWeight &w, + const PairWeight &v) { + return w.Value1() == v.Value1() && w.Value2() == v.Value2(); +} + +template +inline bool operator!=(const PairWeight &w1, + const PairWeight &w2) { + return w1.Value1() != w2.Value1() || w1.Value2() != w2.Value2(); +} + + +template +inline bool ApproxEqual(const PairWeight &w1, + const PairWeight &w2, + float delta = kDelta) { + return ApproxEqual(w1.Value1(), w2.Value1(), delta) && + ApproxEqual(w1.Value2(), w2.Value2(), delta); +} + +template +inline ostream &operator<<(ostream &strm, const PairWeight &w) { + if(FLAGS_fst_weight_separator.size() != 1) { + FSTERROR() << "FLAGS_fst_weight_separator.size() is not equal to 1"; + strm.clear(std::ios::badbit); + return strm; + } + char separator = FLAGS_fst_weight_separator[0]; + if (FLAGS_fst_weight_parentheses.empty()) + return strm << w.Value1() << separator << w.Value2(); + + if (FLAGS_fst_weight_parentheses.size() != 2) { + FSTERROR() << "FLAGS_fst_weight_parentheses.size() is not equal to 2"; + strm.clear(std::ios::badbit); + return strm; + } + char open_paren = FLAGS_fst_weight_parentheses[0]; + char close_paren = FLAGS_fst_weight_parentheses[1]; + return strm << open_paren << w.Value1() << separator + << w.Value2() << close_paren ; +} + +template +inline istream &operator>>(istream &strm, PairWeight &w) { + if(FLAGS_fst_weight_separator.size() != 1) { + FSTERROR() << "FLAGS_fst_weight_separator.size() is not equal to 1"; + strm.clear(std::ios::badbit); + return strm; + } + char separator = FLAGS_fst_weight_separator[0]; + bool read_parens = !FLAGS_fst_weight_parentheses.empty(); + if (read_parens) { + if (FLAGS_fst_weight_parentheses.size() != 2) { + FSTERROR() << "FLAGS_fst_weight_parentheses.size() is not equal to 2"; + strm.clear(std::ios::badbit); + return strm; + } + return PairWeight::ReadWithParen( + strm, w, separator, FLAGS_fst_weight_parentheses[0], + FLAGS_fst_weight_parentheses[1]); + } else { + return PairWeight::ReadNoParen(strm, w, separator); + } +} + +} // namespace fst + +#endif // FST_LIB_PAIR_WEIGHT_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/partition.h b/kaldi_io/src/tools/openfst/include/fst/partition.h new file mode 100644 index 0000000..40b849a --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/partition.h @@ -0,0 +1,305 @@ +// partition.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: johans@google.com (Johan Schalkwyk) +// +// \file Functions and classes to create a partition of states +// + +#ifndef FST_LIB_PARTITION_H__ +#define FST_LIB_PARTITION_H__ + +#include +using std::vector; +#include + + +#include + + + +namespace fst { + +template class PartitionIterator; + +// \class Partition +// \brief Defines a partitioning of states. Typically used to represent +// equivalence classes for Fst operations like minimization. +// +template +class Partition { + friend class PartitionIterator; + + struct Element { + Element() : value(0), next(0), prev(0) {} + Element(T v) : value(v), next(0), prev(0) {} + + T value; + Element* next; + Element* prev; + }; + + 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); + } + + ~Partition() { + for (size_t i = 0; i < elements_.size(); ++i) + delete elements_[i]; + } + + // Create an empty partition for num_states. At initialization time + // all elements are not assigned to a class (i.e class_index = -1). + // Initialize just creates num_states of elements. All element + // operations are then done by simply disconnecting the element from + // it current class and placing it at the head of the next class. + void Initialize(size_t num_states) { + for (size_t i = 0; i < elements_.size(); ++i) + delete elements_[i]; + elements_.clear(); + classes_.clear(); + class_index_.clear(); + + elements_.resize(num_states); + class_index_.resize(num_states, -1); + class_size_.reserve(num_states); + for (size_t i = 0; i < num_states; ++i) + elements_[i] = new Element(i); + num_states_ = num_states; + } + + // Add a class, resize classes_ and class_size_ resource by 1. + size_t AddClass() { + size_t num_classes = classes_.size(); + classes_.resize(num_classes + 1, 0); + class_size_.resize(num_classes + 1, 0); + class_split_.resize(num_classes + 1, 0); + split_size_.resize(num_classes + 1, 0); + return num_classes; + } + + void AllocateClasses(T num_classes) { + size_t n = classes_.size() + num_classes; + classes_.resize(n, 0); + class_size_.resize(n, 0); + class_split_.resize(n, 0); + split_size_.resize(n, 0); + } + + // Add element_id to class_id. The Add method is used to initialize + // partition. Once elements have been added to a class, you need to + // use the Move() method move an element from once class to another. + void Add(T element_id, T class_id) { + Element* element = elements_[element_id]; + + if (classes_[class_id]) + classes_[class_id]->prev = element; + element->next = classes_[class_id]; + element->prev = 0; + classes_[class_id] = element; + + class_index_[element_id] = class_id; + class_size_[class_id]++; + } + + // Move and element_id to class_id. Disconnects (removes) element + // from it current class and + void Move(T element_id, T class_id) { + T old_class_id = class_index_[element_id]; + + Element* element = elements_[element_id]; + if (element->next) element->next->prev = element->prev; + if (element->prev) element->prev->next = element->next; + else classes_[old_class_id] = element->next; + + Add(element_id, class_id); + class_size_[old_class_id]--; + } + + // split class on the element_id + void SplitOn(T element_id) { + T class_id = class_index_[element_id]; + 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 + Move(element_id, class_id); + } + + // Finalize class_id, split if required, and update class_splits, + // 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]; + split_el->prev->next = 0; + split_el->prev = 0; + classes_[class_id] = split_el; + } + + // update class index for element in new class + for (Element* el = classes_[new_class]; el; el = el->next) + class_index_[el->value] = new_class; + + class_split_[class_id] = 0; + split_size_[class_id] = 0; + + return new_class; + } + } + + // Once all states have been processed for a particular class C, we + // can finalize the split. FinalizeSplit() will update each block in the + // partition, create new once and update the queue of active classes + // that require further refinement. + template + void FinalizeSplit(Queue* L) { + for (size_t i = 0; i < visited_classes_.size(); ++i) { + T new_class = SplitRefine(visited_classes_[i]); + if (new_class != -1 && L) + L->Enqueue(new_class); + } + visited_classes_.clear(); + } + + + const T class_id(T element_id) const { + return class_index_[element_id]; + } + + const vector& class_sizes() const { + return class_size_; + } + + const size_t class_size(T class_id) const { + return class_size_[class_id]; + } + + const T num_classes() const { + return classes_.size(); + } + + + private: + int num_states_; + + // container of all elements (owner of ptrs) + vector elements_; + + // linked list of elements belonging to class + vector classes_; + + // pointer to split point for each class + vector class_split_; + + // class index of element + vector class_index_; + + // class sizes + vector 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 split_size_; + + // set of visited classes to be used in split refine + vector 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_; +}; + + +// iterate over members of a class in a partition +template +class PartitionIterator { + typedef typename Partition::Element Element; + public: + PartitionIterator(const Partition& partition, T class_id) + : p_(partition), + element_(p_.classes_[class_id]), + class_id_(class_id) {} + + bool Done() { + return (element_ == 0); + } + + const T Value() { + return (element_->value); + } + + void Next() { + element_ = element_->next; + } + + void Reset() { + element_ = p_.classes_[class_id_]; + } + + private: + const Partition& p_; + + const Element* element_; + + T class_id_; +}; +} // namespace fst + +#endif // FST_LIB_PARTITION_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/power-weight.h b/kaldi_io/src/tools/openfst/include/fst/power-weight.h new file mode 100644 index 0000000..256928d --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/power-weight.h @@ -0,0 +1,159 @@ +// power-weight.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: allauzen@google.com (Cyril Allauzen) +// +// \file +// Cartesian power weight semiring operation definitions. + +#ifndef FST_LIB_POWER_WEIGHT_H__ +#define FST_LIB_POWER_WEIGHT_H__ + +#include +#include + + +namespace fst { + +// Cartesian power semiring: W ^ n +// Forms: +// - a left semimodule when W is a left semiring, +// - a right semimodule when W is a right semiring, +// - a bisemimodule when W is a semiring, +// the free semimodule of rank n over W +// The Times operation is overloaded to provide the +// left and right scalar products. +template +class PowerWeight : public TupleWeight { + public: + using TupleWeight::Zero; + using TupleWeight::One; + using TupleWeight::NoWeight; + using TupleWeight::Quantize; + using TupleWeight::Reverse; + + typedef PowerWeight ReverseWeight; + + PowerWeight() {} + + PowerWeight(const TupleWeight &w) : TupleWeight(w) {} + + template + PowerWeight(Iterator begin, Iterator end) : TupleWeight(begin, end) {} + + static const PowerWeight &Zero() { + static const PowerWeight zero(TupleWeight::Zero()); + return zero; + } + + static const PowerWeight &One() { + static const PowerWeight one(TupleWeight::One()); + return one; + } + + static const PowerWeight &NoWeight() { + static const PowerWeight no_weight(TupleWeight::NoWeight()); + return no_weight; + } + + static const string &Type() { + static string type; + if (type.empty()) { + string power; + Int64ToStr(n, &power); + type = W::Type() + "_^" + power; + } + return type; + } + + static uint64 Properties() { + uint64 props = W::Properties(); + return props & (kLeftSemiring | kRightSemiring | + kCommutative | kIdempotent); + } + + PowerWeight Quantize(float delta = kDelta) const { + return TupleWeight::Quantize(delta); + } + + ReverseWeight Reverse() const { + return TupleWeight::Reverse(); + } +}; + + +// Semiring plus operation +template +inline PowerWeight Plus(const PowerWeight &w1, + const PowerWeight &w2) { + PowerWeight w; + for (size_t i = 0; i < n; ++i) + w.SetValue(i, Plus(w1.Value(i), w2.Value(i))); + return w; +} + +// Semiring times operation +template +inline PowerWeight Times(const PowerWeight &w1, + const PowerWeight &w2) { + PowerWeight w; + for (size_t i = 0; i < n; ++i) + w.SetValue(i, Times(w1.Value(i), w2.Value(i))); + return w; +} + +// Semiring divide operation +template +inline PowerWeight Divide(const PowerWeight &w1, + const PowerWeight &w2, + DivideType type = DIVIDE_ANY) { + PowerWeight w; + for (size_t i = 0; i < n; ++i) + w.SetValue(i, Divide(w1.Value(i), w2.Value(i), type)); + return w; +} + +// Semimodule left scalar product +template +inline PowerWeight Times(const W &s, const PowerWeight &w) { + PowerWeight sw; + for (size_t i = 0; i < n; ++i) + sw.SetValue(i, Times(s, w.Value(i))); + return w; +} + +// Semimodule right scalar product +template +inline PowerWeight Times(const PowerWeight &w, const W &s) { + PowerWeight ws; + for (size_t i = 0; i < n; ++i) + ws.SetValue(i, Times(w.Value(i), s)); + return w; +} + +// Semimodule dot product +template +inline W DotProduct(const PowerWeight &w1, + const PowerWeight &w2) { + W w = W::Zero(); + for (size_t i = 0; i < n; ++i) + w = Plus(w, Times(w1.Value(i), w2.Value(i))); + return w; +} + + +} // namespace fst + +#endif // FST_LIB_POWER_WEIGHT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/product-weight.h b/kaldi_io/src/tools/openfst/include/fst/product-weight.h new file mode 100644 index 0000000..16dede8 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/product-weight.h @@ -0,0 +1,115 @@ +// product-weight.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Product weight set and associated semiring operation definitions. + +#ifndef FST_LIB_PRODUCT_WEIGHT_H__ +#define FST_LIB_PRODUCT_WEIGHT_H__ + +#include +#include + +#include +#include + + +namespace fst { + +// Product semiring: W1 * W2 +template +class ProductWeight : public PairWeight { + public: + using PairWeight::Zero; + using PairWeight::One; + using PairWeight::NoWeight; + using PairWeight::Quantize; + using PairWeight::Reverse; + + typedef ProductWeight + ReverseWeight; + + ProductWeight() {} + + ProductWeight(const PairWeight& w) : PairWeight(w) {} + + ProductWeight(W1 w1, W2 w2) : PairWeight(w1, w2) {} + + static const ProductWeight &Zero() { + static const ProductWeight zero(PairWeight::Zero()); + return zero; + } + + static const ProductWeight &One() { + static const ProductWeight one(PairWeight::One()); + return one; + } + + static const ProductWeight &NoWeight() { + static const ProductWeight no_weight( + PairWeight::NoWeight()); + return no_weight; + } + + static const string &Type() { + static const string type = W1::Type() + "_X_" + W2::Type(); + return type; + } + + static uint64 Properties() { + uint64 props1 = W1::Properties(); + uint64 props2 = W2::Properties(); + return props1 & props2 & (kLeftSemiring | kRightSemiring | + kCommutative | kIdempotent); + } + + ProductWeight Quantize(float delta = kDelta) const { + return PairWeight::Quantize(delta); + } + + ReverseWeight Reverse() const { + return PairWeight::Reverse(); + } + + +}; + +template +inline ProductWeight Plus(const ProductWeight &w, + const ProductWeight &v) { + return ProductWeight(Plus(w.Value1(), v.Value1()), + Plus(w.Value2(), v.Value2())); +} + +template +inline ProductWeight Times(const ProductWeight &w, + const ProductWeight &v) { + return ProductWeight(Times(w.Value1(), v.Value1()), + Times(w.Value2(), v.Value2())); +} + +template +inline ProductWeight Divide(const ProductWeight &w, + const ProductWeight &v, + DivideType typ = DIVIDE_ANY) { + return ProductWeight(Divide(w.Value1(), v.Value1(), typ), + Divide(w.Value2(), v.Value2(), typ)); +} + +} // namespace fst + +#endif // FST_LIB_PRODUCT_WEIGHT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/project.h b/kaldi_io/src/tools/openfst/include/fst/project.h new file mode 100644 index 0000000..07946c3 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/project.h @@ -0,0 +1,148 @@ +// project.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Functions and classes to project an Fst on to its domain or range. + +#ifndef FST_LIB_PROJECT_H__ +#define FST_LIB_PROJECT_H__ + +#include +#include + + +namespace fst { + +// This specifies whether to project on input or output. +enum ProjectType { PROJECT_INPUT = 1, PROJECT_OUTPUT = 2 }; + + +// Mapper to implement projection per arc. +template class ProjectMapper { + public: + explicit ProjectMapper(ProjectType project_type) + : project_type_(project_type) {} + + A operator()(const A &arc) { + typename A::Label label = project_type_ == PROJECT_INPUT + ? arc.ilabel : arc.olabel; + return A(label, label, arc.weight, arc.nextstate); + } + + MapFinalAction FinalAction() const { return MAP_NO_SUPERFINAL; } + + MapSymbolsAction InputSymbolsAction() const { + return project_type_ == PROJECT_INPUT ? MAP_COPY_SYMBOLS : + MAP_CLEAR_SYMBOLS; + } + + MapSymbolsAction OutputSymbolsAction() const { + return project_type_ == PROJECT_OUTPUT ? MAP_COPY_SYMBOLS : + MAP_CLEAR_SYMBOLS; + } + + uint64 Properties(uint64 props) { + return ProjectProperties(props, project_type_ == PROJECT_INPUT); + } + + + private: + ProjectType project_type_; +}; + + +// Projects an FST onto its domain or range by either copying each arcs' +// input label to the output label or vice versa. This version modifies +// its input. +// +// Complexity: +// - Time: O(V + E) +// - Space: O(1) +// where V = # of states and E = # of arcs. +template inline +void Project(MutableFst *fst, ProjectType project_type) { + ArcMap(fst, ProjectMapper(project_type)); + if (project_type == PROJECT_INPUT) + fst->SetOutputSymbols(fst->InputSymbols()); + if (project_type == PROJECT_OUTPUT) + fst->SetInputSymbols(fst->OutputSymbols()); +} + + +// Projects an FST onto its domain or range by either copying each arc's +// input label to the output label or vice versa. This version is a delayed +// Fst. +// +// Complexity: +// - Time: O(v + e) +// - Space: O(1) +// where v = # of states visited, e = # of arcs visited. Constant +// time and to visit an input state or arc is assumed and exclusive +// of caching. +template +class ProjectFst : public ArcMapFst > { + public: + typedef A Arc; + typedef ProjectMapper C; + typedef ArcMapFstImpl< A, A, ProjectMapper > Impl; + using ImplToFst::GetImpl; + + ProjectFst(const Fst &fst, ProjectType project_type) + : ArcMapFst(fst, C(project_type)) { + if (project_type == PROJECT_INPUT) + GetImpl()->SetOutputSymbols(fst.InputSymbols()); + if (project_type == PROJECT_OUTPUT) + GetImpl()->SetInputSymbols(fst.OutputSymbols()); + } + + // See Fst<>::Copy() for doc. + ProjectFst(const ProjectFst &fst, bool safe = false) + : ArcMapFst(fst, safe) {} + + // Get a copy of this ProjectFst. See Fst<>::Copy() for further doc. + virtual ProjectFst *Copy(bool safe = false) const { + return new ProjectFst(*this, safe); + } +}; + + +// Specialization for ProjectFst. +template +class StateIterator< ProjectFst > + : public StateIterator< ArcMapFst > > { + public: + explicit StateIterator(const ProjectFst &fst) + : StateIterator< ArcMapFst > >(fst) {} +}; + + +// Specialization for ProjectFst. +template +class ArcIterator< ProjectFst > + : public ArcIterator< ArcMapFst > > { + public: + ArcIterator(const ProjectFst &fst, typename A::StateId s) + : ArcIterator< ArcMapFst > >(fst, s) {} +}; + + +// Useful alias when using StdArc. +typedef ProjectFst StdProjectFst; + +} // namespace fst + +#endif // FST_LIB_PROJECT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/properties.h b/kaldi_io/src/tools/openfst/include/fst/properties.h new file mode 100644 index 0000000..8fab16f --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/properties.h @@ -0,0 +1,460 @@ +// properties.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: Michael Riley +// \file +// FST property bits. + +#ifndef FST_LIB_PROPERTIES_H__ +#define FST_LIB_PROPERTIES_H__ + +#include +#include +using std::vector; + +#include + +namespace fst { + +// The property bits here assert facts about an FST. If individual +// bits are added, then the composite properties below, the property +// functions and property names in properties.cc, and +// TestProperties() in test-properties.h should be updated. + +// +// BINARY PROPERTIES +// +// For each property below, there is a single bit. If it is set, +// the property is true. If it is not set, the property is false. +// + +// The Fst is an ExpandedFst +const uint64 kExpanded = 0x0000000000000001ULL; + +// The Fst is a MutableFst +const uint64 kMutable = 0x0000000000000002ULL; + +// An error was detected while constructing/using the FST +const uint64 kError = 0x0000000000000004ULL; + +// +// TRINARY PROPERTIES +// +// For each of these properties below there is a pair of property bits +// - one positive and one negative. If the positive bit is set, the +// property is true. If the negative bit is set, the property is +// false. If neither is set, the property has unknown value. Both +// should never be simultaneously set. The individual positive and +// negative bit pairs should be adjacent with the positive bit +// at an odd and lower position. + +// ilabel == olabel for each arc +const uint64 kAcceptor = 0x0000000000010000ULL; +// ilabel != olabel for some arc +const uint64 kNotAcceptor = 0x0000000000020000ULL; + +// ilabels unique leaving each state +const uint64 kIDeterministic = 0x0000000000040000ULL; +// ilabels not unique leaving some state +const uint64 kNonIDeterministic = 0x0000000000080000ULL; + +// olabels unique leaving each state +const uint64 kODeterministic = 0x0000000000100000ULL; +// olabels not unique leaving some state +const uint64 kNonODeterministic = 0x0000000000200000ULL; + +// FST has input/output epsilons +const uint64 kEpsilons = 0x0000000000400000ULL; +// FST has no input/output epsilons +const uint64 kNoEpsilons = 0x0000000000800000ULL; + +// FST has input epsilons +const uint64 kIEpsilons = 0x0000000001000000ULL; +// FST has no input epsilons +const uint64 kNoIEpsilons = 0x0000000002000000ULL; + +// FST has output epsilons +const uint64 kOEpsilons = 0x0000000004000000ULL; +// FST has no output epsilons +const uint64 kNoOEpsilons = 0x0000000008000000ULL; + +// ilabels sorted wrt < for each state +const uint64 kILabelSorted = 0x0000000010000000ULL; +// ilabels not sorted wrt < for some state +const uint64 kNotILabelSorted = 0x0000000020000000ULL; + +// olabels sorted wrt < for each state +const uint64 kOLabelSorted = 0x0000000040000000ULL; +// olabels not sorted wrt < for some state +const uint64 kNotOLabelSorted = 0x0000000080000000ULL; + +// Non-trivial arc or final weights +const uint64 kWeighted = 0x0000000100000000ULL; +// Only trivial arc and final weights +const uint64 kUnweighted = 0x0000000200000000ULL; + +// FST has cycles +const uint64 kCyclic = 0x0000000400000000ULL; +// FST has no cycles +const uint64 kAcyclic = 0x0000000800000000ULL; + +// FST has cycles containing the initial state +const uint64 kInitialCyclic = 0x0000001000000000ULL; +// FST has no cycles containing the initial state +const uint64 kInitialAcyclic = 0x0000002000000000ULL; + +// FST is topologically sorted +const uint64 kTopSorted = 0x0000004000000000ULL; +// FST is not topologically sorted +const uint64 kNotTopSorted = 0x0000008000000000ULL; + +// All states reachable from the initial state +const uint64 kAccessible = 0x0000010000000000ULL; +// Not all states reachable from the initial state +const uint64 kNotAccessible = 0x0000020000000000ULL; + +// All states can reach a final state +const uint64 kCoAccessible = 0x0000040000000000ULL; +// Not all states can reach a final state +const uint64 kNotCoAccessible = 0x0000080000000000ULL; + +// If NumStates() > 0, then state 0 is initial, state NumStates()-1 is +// final, there is a transition from each non-final state i to +// state i+1, and there are no other transitions. +const uint64 kString = 0x0000100000000000ULL; + +// Not a string FST +const uint64 kNotString = 0x0000200000000000ULL; + +// +// COMPOSITE PROPERTIES +// + +// Properties of an empty machine +const uint64 kNullProperties + = kAcceptor | kIDeterministic | kODeterministic | kNoEpsilons | + kNoIEpsilons | kNoOEpsilons | kILabelSorted | kOLabelSorted | + kUnweighted | kAcyclic | kInitialAcyclic | kTopSorted | + kAccessible | kCoAccessible | kString; + +// Properties that are preserved when an FST is copied +const uint64 kCopyProperties + = kError | kAcceptor | kNotAcceptor | kIDeterministic | kNonIDeterministic | + kODeterministic | kNonODeterministic | kEpsilons | kNoEpsilons | + kIEpsilons | kNoIEpsilons | kOEpsilons | kNoOEpsilons | + kILabelSorted | kNotILabelSorted | kOLabelSorted | + kNotOLabelSorted | kWeighted | kUnweighted | kCyclic | kAcyclic | + kInitialCyclic | kInitialAcyclic | kTopSorted | kNotTopSorted | + kAccessible | kNotAccessible | kCoAccessible | kNotCoAccessible | + kString | kNotString; + +// Properites that are intrinsic to the FST +const uint64 kIntrinsicProperties + = kExpanded | kMutable | kAcceptor | kNotAcceptor | kIDeterministic | + kNonIDeterministic | kODeterministic | kNonODeterministic | + kEpsilons | kNoEpsilons | kIEpsilons | kNoIEpsilons | kOEpsilons | + kNoOEpsilons | kILabelSorted | kNotILabelSorted | kOLabelSorted | + kNotOLabelSorted | kWeighted | kUnweighted | kCyclic | kAcyclic | + kInitialCyclic | kInitialAcyclic | kTopSorted | kNotTopSorted | + kAccessible | kNotAccessible | kCoAccessible | kNotCoAccessible | + kString | kNotString; + +// Properites that are (potentially) extrinsic to the FST +const uint64 kExtrinsicProperties = kError; + +// Properties that are preserved when an FST start state is set +const uint64 kSetStartProperties + = kExpanded | kMutable | kError | kAcceptor | kNotAcceptor | + kIDeterministic | kNonIDeterministic | kODeterministic | + kNonODeterministic | kEpsilons | kNoEpsilons | kIEpsilons | + kNoIEpsilons | kOEpsilons | kNoOEpsilons | kILabelSorted | + kNotILabelSorted | kOLabelSorted | kNotOLabelSorted | kWeighted | + kUnweighted | kCyclic | kAcyclic | kTopSorted | kNotTopSorted | + kCoAccessible | kNotCoAccessible; + +// Properties that are preserved when an FST final weight is set +const uint64 kSetFinalProperties + = kExpanded | kMutable | kError | kAcceptor | kNotAcceptor | + kIDeterministic | kNonIDeterministic | kODeterministic | + kNonODeterministic | kEpsilons | kNoEpsilons | kIEpsilons | + kNoIEpsilons | kOEpsilons | kNoOEpsilons | kILabelSorted | + kNotILabelSorted | kOLabelSorted | kNotOLabelSorted | kCyclic | + kAcyclic | kInitialCyclic | kInitialAcyclic | kTopSorted | + kNotTopSorted | kAccessible | kNotAccessible; + +// Properties that are preserved when an FST state is added +const uint64 kAddStateProperties + = kExpanded | kMutable | kError | kAcceptor | kNotAcceptor | + kIDeterministic | kNonIDeterministic | kODeterministic | + kNonODeterministic | kEpsilons | kNoEpsilons | kIEpsilons | + kNoIEpsilons | kOEpsilons | kNoOEpsilons | kILabelSorted | + kNotILabelSorted | kOLabelSorted | kNotOLabelSorted | kWeighted | + kUnweighted | kCyclic | kAcyclic | kInitialCyclic | + kInitialAcyclic | kTopSorted | kNotTopSorted | kNotAccessible | + kNotCoAccessible | kNotString; + +// Properties that are preserved when an FST arc is added +const uint64 kAddArcProperties = kExpanded | kMutable | kError | kNotAcceptor | + kNonIDeterministic | kNonODeterministic | kEpsilons | kIEpsilons | + kOEpsilons | kNotILabelSorted | kNotOLabelSorted | kWeighted | + kCyclic | kInitialCyclic | kNotTopSorted | kAccessible | kCoAccessible; + +// Properties that are preserved when an FST arc is set +const uint64 kSetArcProperties = kExpanded | kMutable | kError; + +// Properties that are preserved when FST states are deleted +const uint64 kDeleteStatesProperties + = kExpanded | kMutable | kError | kAcceptor | kIDeterministic | + kODeterministic | kNoEpsilons | kNoIEpsilons | kNoOEpsilons | + kILabelSorted | kOLabelSorted | kUnweighted | kAcyclic | + kInitialAcyclic | kTopSorted; + +// Properties that are preserved when FST arcs are deleted +const uint64 kDeleteArcsProperties + = kExpanded | kMutable | kError | kAcceptor | kIDeterministic | + kODeterministic | kNoEpsilons | kNoIEpsilons | kNoOEpsilons | + kILabelSorted | kOLabelSorted | kUnweighted | kAcyclic | + kInitialAcyclic | kTopSorted | kNotAccessible | kNotCoAccessible; + +// Properties that are preserved when an FST's states are reordered +const uint64 kStateSortProperties = kExpanded | kMutable | kError | kAcceptor | + kNotAcceptor | kIDeterministic | kNonIDeterministic | + kODeterministic | kNonODeterministic | kEpsilons | kNoEpsilons | + kIEpsilons | kNoIEpsilons | kOEpsilons | kNoOEpsilons | + kILabelSorted | kNotILabelSorted | kOLabelSorted | kNotOLabelSorted + | kWeighted | kUnweighted | kCyclic | kAcyclic | kInitialCyclic | + kInitialAcyclic | kAccessible | kNotAccessible | kCoAccessible | + kNotCoAccessible; + +// Properties that are preserved when an FST's arcs are reordered +const uint64 kArcSortProperties = + kExpanded | kMutable | kError | kAcceptor | kNotAcceptor | kIDeterministic | + kNonIDeterministic | kODeterministic | kNonODeterministic | + kEpsilons | kNoEpsilons | kIEpsilons | kNoIEpsilons | kOEpsilons | + kNoOEpsilons | kWeighted | kUnweighted | kCyclic | kAcyclic | + kInitialCyclic | kInitialAcyclic | kTopSorted | kNotTopSorted | + kAccessible | kNotAccessible | kCoAccessible | kNotCoAccessible | + kString | kNotString; + +// Properties that are preserved when an FST's input labels are changed. +const uint64 kILabelInvariantProperties = + kExpanded | kMutable | kError | kODeterministic | kNonODeterministic | + kOEpsilons | kNoOEpsilons | kOLabelSorted | kNotOLabelSorted | + kWeighted | kUnweighted | kCyclic | kAcyclic | kInitialCyclic | + kInitialAcyclic | kTopSorted | kNotTopSorted | kAccessible | + kNotAccessible | kCoAccessible | kNotCoAccessible | kString | kNotString; + +// Properties that are preserved when an FST's output labels are changed. +const uint64 kOLabelInvariantProperties = + kExpanded | kMutable | kError | kIDeterministic | kNonIDeterministic | + kIEpsilons | kNoIEpsilons | kILabelSorted | kNotILabelSorted | + kWeighted | kUnweighted | kCyclic | kAcyclic | kInitialCyclic | + kInitialAcyclic | kTopSorted | kNotTopSorted | kAccessible | + kNotAccessible | kCoAccessible | kNotCoAccessible | kString | kNotString; + +// Properties that are preserved when an FST's weights are changed. +// This assumes that the set of states that are non-final is not changed. +const uint64 kWeightInvariantProperties = + kExpanded | kMutable | kError | kAcceptor | kNotAcceptor | kIDeterministic | + kNonIDeterministic | kODeterministic | kNonODeterministic | + kEpsilons | kNoEpsilons | kIEpsilons | kNoIEpsilons | kOEpsilons | + kNoOEpsilons | kILabelSorted | kNotILabelSorted | kOLabelSorted | + kNotOLabelSorted | kCyclic | kAcyclic | kInitialCyclic | kInitialAcyclic | + kTopSorted | kNotTopSorted | kAccessible | kNotAccessible | kCoAccessible | + kNotCoAccessible | kString | kNotString; + +// Properties that are preserved when a superfinal state is added +// and an FSTs final weights are directed to it via new transitions. +const uint64 kAddSuperFinalProperties = kExpanded | kMutable | kError | + kAcceptor | kNotAcceptor | kNonIDeterministic | kNonODeterministic | + kEpsilons | kIEpsilons | kOEpsilons | kNotILabelSorted | kNotOLabelSorted | + kWeighted | kUnweighted | kCyclic | kAcyclic | kInitialCyclic | + kInitialAcyclic | kNotTopSorted | kNotAccessible | kCoAccessible | + kNotCoAccessible | kNotString; + +// Properties that are preserved when a superfinal state is removed +// and the epsilon transitions directed to it are made final weights. +const uint64 kRmSuperFinalProperties = kExpanded | kMutable | kError | + kAcceptor | kNotAcceptor | kIDeterministic | kODeterministic | + kNoEpsilons | kNoIEpsilons | kNoOEpsilons | kILabelSorted | kOLabelSorted | + kWeighted | kUnweighted | kCyclic | kAcyclic | kInitialCyclic | + kInitialAcyclic | kTopSorted | kAccessible | kCoAccessible | + kNotCoAccessible | kString; + +// All binary properties +const uint64 kBinaryProperties = 0x0000000000000007ULL; + +// All trinary properties +const uint64 kTrinaryProperties = 0x00003fffffff0000ULL; + +// +// COMPUTED PROPERTIES +// + +// 1st bit of trinary properties +const uint64 kPosTrinaryProperties = + kTrinaryProperties & 0x5555555555555555ULL; + +// 2nd bit of trinary properties +const uint64 kNegTrinaryProperties = + kTrinaryProperties & 0xaaaaaaaaaaaaaaaaULL; + +// All properties +const uint64 kFstProperties = kBinaryProperties | kTrinaryProperties; + +// +// PROPERTY FUNCTIONS and STRING NAMES (defined in properties.cc) +// + +// Below are functions for getting property bit vectors when executing +// mutating fst operations. +inline uint64 SetStartProperties(uint64 inprops); +template +uint64 SetFinalProperties(uint64 inprops, Weight old_weight, + Weight new_weight); +inline uint64 AddStateProperties(uint64 inprops); +template +uint64 AddArcProperties(uint64 inprops, typename A::StateId s, const A &arc, + const A *prev_arc); +inline uint64 DeleteStatesProperties(uint64 inprops); +inline uint64 DeleteAllStatesProperties(uint64 inprops, uint64 staticProps); +inline uint64 DeleteArcsProperties(uint64 inprops); + +uint64 ClosureProperties(uint64 inprops, bool star, bool delayed = false); +uint64 ComplementProperties(uint64 inprops); +uint64 ComposeProperties(uint64 inprops1, uint64 inprops2); +uint64 ConcatProperties(uint64 inprops1, uint64 inprops2, + bool delayed = false); +uint64 DeterminizeProperties(uint64 inprops, bool has_subsequential_label); +uint64 FactorWeightProperties(uint64 inprops); +uint64 InvertProperties(uint64 inprops); +uint64 ProjectProperties(uint64 inprops, bool project_input); +uint64 RandGenProperties(uint64 inprops, bool weighted); +uint64 RelabelProperties(uint64 inprops); +uint64 ReplaceProperties(const vector& inprops, + ssize_t root, + bool epsilon_on_replace, + bool no_empty_fst); +uint64 ReverseProperties(uint64 inprops); +uint64 ReweightProperties(uint64 inprops); +uint64 RmEpsilonProperties(uint64 inprops, bool delayed = false); +uint64 ShortestPathProperties(uint64 props); +uint64 SynchronizeProperties(uint64 inprops); +uint64 UnionProperties(uint64 inprops1, uint64 inprops2, bool delayed = false); + +// Definitions of inlined functions. + +uint64 SetStartProperties(uint64 inprops) { + uint64 outprops = inprops & kSetStartProperties; + if (inprops & kAcyclic) { + outprops |= kInitialAcyclic; + } + return outprops; +} + +uint64 AddStateProperties(uint64 inprops) { + return inprops & kAddStateProperties; +} + +uint64 DeleteStatesProperties(uint64 inprops) { + return inprops & kDeleteStatesProperties; +} + +uint64 DeleteAllStatesProperties(uint64 inprops, uint64 staticprops) { + uint64 outprops = inprops & kError; + return outprops | kNullProperties | staticprops; +} + +uint64 DeleteArcsProperties(uint64 inprops) { + return inprops & kDeleteArcsProperties; +} + +// Definitions of template functions. + +// +template +uint64 SetFinalProperties(uint64 inprops, Weight old_weight, + Weight new_weight) { + uint64 outprops = inprops; + if (old_weight != Weight::Zero() && old_weight != Weight::One()) { + outprops &= ~kWeighted; + } + if (new_weight != Weight::Zero() && new_weight != Weight::One()) { + outprops |= kWeighted; + outprops &= ~kUnweighted; + } + outprops &= kSetFinalProperties | kWeighted | kUnweighted; + return outprops; +} + +/// Gets the properties for the MutableFst::AddArc method. +/// +/// \param inprops the current properties of the fst +/// \param s the id of the state to which an arc is being added +/// \param arc the arc being added to the state with the specified id +/// \param prev_arc the previously-added (or "last") arc of state s, or NULL if +/// s currently has no arcs +template +uint64 AddArcProperties(uint64 inprops, typename A::StateId s, + const A &arc, const A *prev_arc) { + uint64 outprops = inprops; + if (arc.ilabel != arc.olabel) { + outprops |= kNotAcceptor; + outprops &= ~kAcceptor; + } + if (arc.ilabel == 0) { + outprops |= kIEpsilons; + outprops &= ~kNoIEpsilons; + if (arc.olabel == 0) { + outprops |= kEpsilons; + outprops &= ~kNoEpsilons; + } + } + if (arc.olabel == 0) { + outprops |= kOEpsilons; + outprops &= ~kNoOEpsilons; + } + if (prev_arc != 0) { + if (prev_arc->ilabel > arc.ilabel) { + outprops |= kNotILabelSorted; + outprops &= ~kILabelSorted; + } + if (prev_arc->olabel > arc.olabel) { + outprops |= kNotOLabelSorted; + outprops &= ~kOLabelSorted; + } + } + if (arc.weight != A::Weight::Zero() && arc.weight != A::Weight::One()) { + outprops |= kWeighted; + outprops &= ~kUnweighted; + } + if (arc.nextstate <= s) { + outprops |= kNotTopSorted; + outprops &= ~kTopSorted; + } + outprops &= kAddArcProperties | kAcceptor | + kNoEpsilons | kNoIEpsilons | kNoOEpsilons | + kILabelSorted | kOLabelSorted | kUnweighted | kTopSorted; + if (outprops & kTopSorted) { + outprops |= kAcyclic | kInitialAcyclic; + } + return outprops; +} + +extern const char *PropertyNames[]; + +} // namespace fst + +#endif // FST_LIB_PROPERTIES_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/prune.h b/kaldi_io/src/tools/openfst/include/fst/prune.h new file mode 100644 index 0000000..5ea5b4d --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/prune.h @@ -0,0 +1,339 @@ +// prune.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: allauzen@google.com (Cyril Allauzen) +// +// \file +// Functions implementing pruning. + +#ifndef FST_LIB_PRUNE_H__ +#define FST_LIB_PRUNE_H__ + +#include +using std::vector; + +#include +#include +#include + + +namespace fst { + +template +class PruneOptions { + public: + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + + // Pruning weight threshold. + Weight weight_threshold; + // Pruning state threshold. + StateId state_threshold; + // Arc filter. + ArcFilter filter; + // If non-zero, passes in pre-computed shortest distance to final states. + const vector *distance; + // Determines the degree of convergence required when computing shortest + // distances. + float delta; + + explicit PruneOptions(const Weight& w, StateId s, ArcFilter f, + vector *d = 0, float e = kDelta) + : weight_threshold(w), + state_threshold(s), + filter(f), + distance(d), + delta(e) {} + private: + PruneOptions(); // disallow +}; + + +template +class PruneCompare { + public: + typedef S StateId; + typedef W Weight; + + PruneCompare(const vector &idistance, + const vector &fdistance) + : idistance_(idistance), fdistance_(fdistance) {} + + bool operator()(const StateId x, const StateId y) const { + Weight wx = Times(x < idistance_.size() ? idistance_[x] : Weight::Zero(), + x < fdistance_.size() ? fdistance_[x] : Weight::Zero()); + Weight wy = Times(y < idistance_.size() ? idistance_[y] : Weight::Zero(), + y < fdistance_.size() ? fdistance_[y] : Weight::Zero()); + return less_(wx, wy); + } + + private: + const vector &idistance_; + const vector &fdistance_; + NaturalLess less_; +}; + + + +// Pruning algorithm: this version modifies its input and it takes an +// options class as an argment. Delete states and arcs in 'fst' that +// do not belong to a successful path whose weight is no more than +// the weight of the shortest path Times() 'opts.weight_threshold'. +// When 'opts.state_threshold != kNoStateId', the resulting transducer +// will restricted further to have at most 'opts.state_threshold' +// states. Weights need to be commutative and have the path +// property. The weight 'w' of any cycle needs to be bounded, i.e., +// 'Plus(w, W::One()) = One()'. +template +void Prune(MutableFst *fst, + const PruneOptions &opts) { + typedef typename Arc::Weight Weight; + typedef typename Arc::StateId StateId; + + if ((Weight::Properties() & (kPath | kCommutative)) + != (kPath | kCommutative)) { + FSTERROR() << "Prune: Weight needs to have the path property and" + << " be commutative: " + << Weight::Type(); + fst->SetProperties(kError, kError); + return; + } + StateId ns = fst->NumStates(); + if (ns == 0) return; + vector idistance(ns, Weight::Zero()); + vector tmp; + if (!opts.distance) { + tmp.reserve(ns); + ShortestDistance(*fst, &tmp, true, opts.delta); + } + const vector *fdistance = opts.distance ? opts.distance : &tmp; + + if ((opts.state_threshold == 0) || + (fdistance->size() <= fst->Start()) || + ((*fdistance)[fst->Start()] == Weight::Zero())) { + fst->DeleteStates(); + return; + } + PruneCompare compare(idistance, *fdistance); + Heap< StateId, PruneCompare, false> heap(compare); + vector visited(ns, false); + vector enqueued(ns, kNoKey); + vector dead; + dead.push_back(fst->AddState()); + NaturalLess less; + Weight limit = Times((*fdistance)[fst->Start()], opts.weight_threshold); + + StateId num_visited = 0; + StateId s = fst->Start(); + if (!less(limit, (*fdistance)[s])) { + idistance[s] = Weight::One(); + enqueued[s] = heap.Insert(s); + ++num_visited; + } + + while (!heap.Empty()) { + s = heap.Top(); + heap.Pop(); + enqueued[s] = kNoKey; + visited[s] = true; + if (less(limit, Times(idistance[s], fst->Final(s)))) + fst->SetFinal(s, Weight::Zero()); + for (MutableArcIterator< MutableFst > ait(fst, s); + !ait.Done(); + ait.Next()) { + Arc arc = ait.Value(); + if (!opts.filter(arc)) continue; + Weight weight = Times(Times(idistance[s], arc.weight), + arc.nextstate < fdistance->size() + ? (*fdistance)[arc.nextstate] + : Weight::Zero()); + if (less(limit, weight)) { + arc.nextstate = dead[0]; + ait.SetValue(arc); + continue; + } + if (less(Times(idistance[s], arc.weight), idistance[arc.nextstate])) + idistance[arc.nextstate] = Times(idistance[s], arc.weight); + if (visited[arc.nextstate]) continue; + if ((opts.state_threshold != kNoStateId) && + (num_visited >= opts.state_threshold)) + continue; + if (enqueued[arc.nextstate] == kNoKey) { + enqueued[arc.nextstate] = heap.Insert(arc.nextstate); + ++num_visited; + } else { + heap.Update(enqueued[arc.nextstate], arc.nextstate); + } + } + } + for (size_t i = 0; i < visited.size(); ++i) + if (!visited[i]) dead.push_back(i); + fst->DeleteStates(dead); +} + + +// Pruning algorithm: this version modifies its input and simply takes +// the pruning threshold as an argument. Delete states and arcs in +// 'fst' that do not belong to a successful path whose weight is no +// more than the weight of the shortest path Times() +// 'weight_threshold'. When 'state_threshold != kNoStateId', the +// resulting transducer will be restricted further to have at most +// 'opts.state_threshold' states. Weights need to be commutative and +// have the path property. The weight 'w' of any cycle needs to be +// bounded, i.e., 'Plus(w, W::One()) = One()'. +template +void Prune(MutableFst *fst, + typename Arc::Weight weight_threshold, + typename Arc::StateId state_threshold = kNoStateId, + double delta = kDelta) { + PruneOptions > opts(weight_threshold, state_threshold, + AnyArcFilter(), 0, delta); + Prune(fst, opts); +} + + +// Pruning algorithm: this version writes the pruned input Fst to an +// output MutableFst and it takes an options class as an argument. +// 'ofst' contains states and arcs that belong to a successful path in +// 'ifst' whose weight is no more than the weight of the shortest path +// Times() 'opts.weight_threshold'. When 'opts.state_threshold != +// kNoStateId', 'ofst' will be restricted further to have at most +// 'opts.state_threshold' states. Weights need to be commutative and +// have the path property. The weight 'w' of any cycle needs to be +// bounded, i.e., 'Plus(w, W::One()) = One()'. +template +void Prune(const Fst &ifst, + MutableFst *ofst, + const PruneOptions &opts) { + typedef typename Arc::Weight Weight; + typedef typename Arc::StateId StateId; + + if ((Weight::Properties() & (kPath | kCommutative)) + != (kPath | kCommutative)) { + FSTERROR() << "Prune: Weight needs to have the path property and" + << " be commutative: " + << Weight::Type(); + ofst->SetProperties(kError, kError); + return; + } + ofst->DeleteStates(); + ofst->SetInputSymbols(ifst.InputSymbols()); + ofst->SetOutputSymbols(ifst.OutputSymbols()); + if (ifst.Start() == kNoStateId) + return; + NaturalLess less; + if (less(opts.weight_threshold, Weight::One()) || + (opts.state_threshold == 0)) + return; + vector idistance; + vector tmp; + if (!opts.distance) + ShortestDistance(ifst, &tmp, true, opts.delta); + const vector *fdistance = opts.distance ? opts.distance : &tmp; + + if ((fdistance->size() <= ifst.Start()) || + ((*fdistance)[ifst.Start()] == Weight::Zero())) { + return; + } + PruneCompare compare(idistance, *fdistance); + Heap< StateId, PruneCompare, false> heap(compare); + vector copy; + vector enqueued; + vector visited; + + StateId s = ifst.Start(); + Weight limit = Times(s < fdistance->size() ? (*fdistance)[s] : Weight::Zero(), + opts.weight_threshold); + while (copy.size() <= s) + copy.push_back(kNoStateId); + copy[s] = ofst->AddState(); + ofst->SetStart(copy[s]); + while (idistance.size() <= s) + idistance.push_back(Weight::Zero()); + idistance[s] = Weight::One(); + while (enqueued.size() <= s) { + enqueued.push_back(kNoKey); + visited.push_back(false); + } + enqueued[s] = heap.Insert(s); + + while (!heap.Empty()) { + s = heap.Top(); + heap.Pop(); + enqueued[s] = kNoKey; + visited[s] = true; + if (!less(limit, Times(idistance[s], ifst.Final(s)))) + ofst->SetFinal(copy[s], ifst.Final(s)); + for (ArcIterator< Fst > ait(ifst, s); + !ait.Done(); + ait.Next()) { + const Arc &arc = ait.Value(); + if (!opts.filter(arc)) continue; + Weight weight = Times(Times(idistance[s], arc.weight), + arc.nextstate < fdistance->size() + ? (*fdistance)[arc.nextstate] + : Weight::Zero()); + if (less(limit, weight)) continue; + if ((opts.state_threshold != kNoStateId) && + (ofst->NumStates() >= opts.state_threshold)) + continue; + while (idistance.size() <= arc.nextstate) + idistance.push_back(Weight::Zero()); + if (less(Times(idistance[s], arc.weight), + idistance[arc.nextstate])) + idistance[arc.nextstate] = Times(idistance[s], arc.weight); + while (copy.size() <= arc.nextstate) + copy.push_back(kNoStateId); + if (copy[arc.nextstate] == kNoStateId) + copy[arc.nextstate] = ofst->AddState(); + ofst->AddArc(copy[s], Arc(arc.ilabel, arc.olabel, arc.weight, + copy[arc.nextstate])); + while (enqueued.size() <= arc.nextstate) { + enqueued.push_back(kNoKey); + visited.push_back(false); + } + if (visited[arc.nextstate]) continue; + if (enqueued[arc.nextstate] == kNoKey) + enqueued[arc.nextstate] = heap.Insert(arc.nextstate); + else + heap.Update(enqueued[arc.nextstate], arc.nextstate); + } + } +} + + +// Pruning algorithm: this version writes the pruned input Fst to an +// output MutableFst and simply takes the pruning threshold as an +// argument. 'ofst' contains states and arcs that belong to a +// successful path in 'ifst' whose weight is no more than +// the weight of the shortest path Times() 'weight_threshold'. When +// 'state_threshold != kNoStateId', 'ofst' will be restricted further +// to have at most 'opts.state_threshold' states. Weights need to be +// commutative and have the path property. The weight 'w' of any cycle +// needs to be bounded, i.e., 'Plus(w, W::One()) = W::One()'. +template +void Prune(const Fst &ifst, + MutableFst *ofst, + typename Arc::Weight weight_threshold, + typename Arc::StateId state_threshold = kNoStateId, + float delta = kDelta) { + PruneOptions > opts(weight_threshold, state_threshold, + AnyArcFilter(), 0, delta); + Prune(ifst, ofst, opts); +} + +} // namespace fst + +#endif // FST_LIB_PRUNE_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/push.h b/kaldi_io/src/tools/openfst/include/fst/push.h new file mode 100644 index 0000000..1f7a8fa --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/push.h @@ -0,0 +1,175 @@ +// push.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: allauzen@google.com (Cyril Allauzen) +// +// \file +// Class to reweight/push an FST. + +#ifndef FST_LIB_PUSH_H__ +#define FST_LIB_PUSH_H__ + +#include +using std::vector; + +#include +#include +#include +#include +#include + + +namespace fst { + +// Private helper functions for Push +namespace internal { + +// Compute the total weight (sum of the weights of all accepting paths) from +// the output of ShortestDistance. 'distance' is the shortest distance from the +// initial state when 'reverse == false' and to the final states when +// 'reverse == true'. +template +typename Arc::Weight ComputeTotalWeight( + const Fst &fst, + const vector &distance, + bool reverse) { + if (reverse) + return fst.Start() < distance.size() ? + distance[fst.Start()] : Arc::Weight::Zero(); + + typename Arc::Weight sum = Arc::Weight::Zero(); + for (typename Arc::StateId s = 0; s < distance.size(); ++s) + sum = Plus(sum, Times(distance[s], fst.Final(s))); + return sum; +} + +// Divide the weight of every accepting path by 'w'. The weight 'w' is +// divided at the final states if 'at_final == true' and at the +// initial state otherwise. +template +void RemoveWeight(MutableFst *fst, typename Arc::Weight w, bool at_final) { + if ((w == Arc::Weight::One()) || (w == Arc::Weight::Zero())) + return; + + if (at_final) { + // Remove 'w' from the final states + for (StateIterator< MutableFst > sit(*fst); + !sit.Done(); + sit.Next()) + fst->SetFinal(sit.Value(), + Divide(fst->Final(sit.Value()), w, DIVIDE_RIGHT)); + } else { // at_final == false + // Remove 'w' from the initial state + typename Arc::StateId start = fst->Start(); + for (MutableArcIterator > ait(fst, start); + !ait.Done(); + ait.Next()) { + Arc arc = ait.Value(); + arc.weight = Divide(arc.weight, w, DIVIDE_LEFT); + ait.SetValue(arc); + } + fst->SetFinal(start, Divide(fst->Final(start), w, DIVIDE_LEFT)); + } +} +} // namespace internal + +// Pushes the weights in FST in the direction defined by TYPE. If +// pushing towards the initial state, the sum of the weight of the +// outgoing transitions and final weight at a non-initial state is +// equal to One() in the resulting machine. If pushing towards the +// final state, the same property holds on the reverse machine. +// +// Weight needs to be left distributive when pushing towards the +// initial state and right distributive when pushing towards the final +// states. +template +void Push(MutableFst *fst, + ReweightType type, + float delta = kDelta, + bool remove_total_weight = false) { + vector distance; + ShortestDistance(*fst, &distance, type == REWEIGHT_TO_INITIAL, delta); + typename Arc::Weight total_weight = Arc::Weight::One(); + if (remove_total_weight) + total_weight = internal::ComputeTotalWeight(*fst, distance, + type == REWEIGHT_TO_INITIAL); + Reweight(fst, distance, type); + if (remove_total_weight) + internal::RemoveWeight(fst, total_weight, type == REWEIGHT_TO_FINAL); +} + +const uint32 kPushWeights = 0x0001; +const uint32 kPushLabels = 0x0002; +const uint32 kPushRemoveTotalWeight = 0x0004; +const uint32 kPushRemoveCommonAffix = 0x0008; + +// OFST obtained from IFST by pushing weights and/or labels according +// to PTYPE in the direction defined by RTYPE. Weight needs to be +// left distributive when pushing weights towards the initial state +// and right distributive when pushing weights towards the final +// states. +template +void Push(const Fst &ifst, + MutableFst *ofst, + uint32 ptype, + float delta = kDelta) { + + if ((ptype & (kPushWeights | kPushLabels)) == kPushWeights) { + *ofst = ifst; + Push(ofst, rtype, delta, ptype & kPushRemoveTotalWeight); + } else if (ptype & kPushLabels) { + const StringType stype = rtype == REWEIGHT_TO_INITIAL + ? STRING_LEFT + : STRING_RIGHT; + vector::Weight> gdistance; + VectorFst > gfst; + ArcMap(ifst, &gfst, ToGallicMapper()); + if (ptype & kPushWeights ) { + ShortestDistance(gfst, &gdistance, rtype == REWEIGHT_TO_INITIAL, delta); + } else { + ArcMapFst > + uwfst(ifst, RmWeightMapper()); + ArcMapFst, ToGallicMapper > + guwfst(uwfst, ToGallicMapper()); + ShortestDistance(guwfst, &gdistance, rtype == REWEIGHT_TO_INITIAL, delta); + } + typename GallicArc::Weight total_weight = + GallicArc::Weight::One(); + if (ptype & (kPushRemoveTotalWeight | kPushRemoveCommonAffix)) { + total_weight = internal::ComputeTotalWeight( + gfst, gdistance, rtype == REWEIGHT_TO_INITIAL); + total_weight = typename GallicArc::Weight( + ptype & kPushRemoveCommonAffix ? total_weight.Value1() + : StringWeight::One(), + ptype & kPushRemoveTotalWeight ? total_weight.Value2() + : Arc::Weight::One()); + } + Reweight(&gfst, gdistance, rtype); + if (ptype & (kPushRemoveTotalWeight | kPushRemoveCommonAffix)) + internal::RemoveWeight(&gfst, total_weight, rtype == REWEIGHT_TO_FINAL); + FactorWeightFst< GallicArc, GallicFactor > fwfst(gfst); + ArcMap(fwfst, ofst, FromGallicMapper()); + ofst->SetOutputSymbols(ifst.OutputSymbols()); + } else { + LOG(WARNING) << "Push: pushing type is set to 0: " + << "pushing neither labels nor weights."; + *ofst = ifst; + } +} + +} // namespace fst + +#endif /* FST_LIB_PUSH_H_ */ diff --git a/kaldi_io/src/tools/openfst/include/fst/queue.h b/kaldi_io/src/tools/openfst/include/fst/queue.h new file mode 100644 index 0000000..95a082d --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/queue.h @@ -0,0 +1,938 @@ +// queue.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: allauzen@google.com (Cyril Allauzen) +// +// \file +// Functions and classes for various Fst state queues with +// a unified interface. + +#ifndef FST_LIB_QUEUE_H__ +#define FST_LIB_QUEUE_H__ + +#include +using std::deque; +#include +using std::vector; + +#include +#include +#include +#include + + +namespace fst { + +// template +// class Queue { +// public: +// typedef typename S StateId; +// +// // Ctr: may need args (e.g., Fst, comparator) for some queues +// Queue(...); +// // Returns the head of the queue +// StateId Head() const; +// // Inserts a state +// void Enqueue(StateId s); +// // Removes the head of the queue +// void Dequeue(); +// // Updates ordering of state s when weight changes, if necessary +// void Update(StateId s); +// // Does the queue contain no elements? +// bool Empty() const; +// // Remove all states from queue +// void Clear(); +// }; + +// State queue types. +enum QueueType { + TRIVIAL_QUEUE = 0, // Single state queue + FIFO_QUEUE = 1, // First-in, first-out queue + LIFO_QUEUE = 2, // Last-in, first-out queue + SHORTEST_FIRST_QUEUE = 3, // Shortest-first queue + TOP_ORDER_QUEUE = 4, // Topologically-ordered queue + STATE_ORDER_QUEUE = 5, // State-ID ordered queue + SCC_QUEUE = 6, // Component graph top-ordered meta-queue + AUTO_QUEUE = 7, // Auto-selected queue + OTHER_QUEUE = 8 + }; + + +// QueueBase, templated on the StateId, is the base class shared by the +// queues considered by AutoQueue. +template +class QueueBase { + public: + typedef S StateId; + + QueueBase(QueueType type) : queue_type_(type), error_(false) {} + virtual ~QueueBase() {} + StateId Head() const { return Head_(); } + void Enqueue(StateId s) { Enqueue_(s); } + void Dequeue() { Dequeue_(); } + void Update(StateId s) { Update_(s); } + bool Empty() const { return Empty_(); } + void Clear() { Clear_(); } + QueueType Type() { return queue_type_; } + bool Error() const { return error_; } + void SetError(bool error) { error_ = error; } + + private: + // This allows base-class virtual access to non-virtual derived- + // class members of the same name. It makes the derived class more + // efficient to use but unsafe to further derive. + virtual StateId Head_() const = 0; + virtual void Enqueue_(StateId s) = 0; + virtual void Dequeue_() = 0; + virtual void Update_(StateId s) = 0; + virtual bool Empty_() const = 0; + virtual void Clear_() = 0; + + QueueType queue_type_; + bool error_; +}; + + +// Trivial queue discipline, templated on the StateId. You may enqueue +// at most one state at a time. It is used for strongly connected components +// with only one state and no self loops. +template +class TrivialQueue : public QueueBase { +public: + typedef S StateId; + + TrivialQueue() : QueueBase(TRIVIAL_QUEUE), front_(kNoStateId) {} + StateId Head() const { return front_; } + void Enqueue(StateId s) { front_ = s; } + void Dequeue() { front_ = kNoStateId; } + void Update(StateId s) {} + bool Empty() const { return front_ == kNoStateId; } + void Clear() { front_ = kNoStateId; } + + +private: + // This allows base-class virtual access to non-virtual derived- + // class members of the same name. It makes the derived class more + // efficient to use but unsafe to further derive. + virtual StateId Head_() const { return Head(); } + virtual void Enqueue_(StateId s) { Enqueue(s); } + virtual void Dequeue_() { Dequeue(); } + virtual void Update_(StateId s) { Update(s); } + virtual bool Empty_() const { return Empty(); } + virtual void Clear_() { return Clear(); } + + StateId front_; +}; + + +// First-in, first-out queue discipline, templated on the StateId. +template +class FifoQueue : public QueueBase, public deque { + public: + using deque::back; + using deque::push_front; + using deque::pop_back; + using deque::empty; + using deque::clear; + + typedef S StateId; + + FifoQueue() : QueueBase(FIFO_QUEUE) {} + StateId Head() const { return back(); } + void Enqueue(StateId s) { push_front(s); } + void Dequeue() { pop_back(); } + void Update(StateId s) {} + bool Empty() const { return empty(); } + void Clear() { clear(); } + + private: + // This allows base-class virtual access to non-virtual derived- + // class members of the same name. It makes the derived class more + // efficient to use but unsafe to further derive. + virtual StateId Head_() const { return Head(); } + virtual void Enqueue_(StateId s) { Enqueue(s); } + virtual void Dequeue_() { Dequeue(); } + virtual void Update_(StateId s) { Update(s); } + virtual bool Empty_() const { return Empty(); } + virtual void Clear_() { return Clear(); } +}; + + +// Last-in, first-out queue discipline, templated on the StateId. +template +class LifoQueue : public QueueBase, public deque { + public: + using deque::front; + using deque::push_front; + using deque::pop_front; + using deque::empty; + using deque::clear; + + typedef S StateId; + + LifoQueue() : QueueBase(LIFO_QUEUE) {} + StateId Head() const { return front(); } + void Enqueue(StateId s) { push_front(s); } + void Dequeue() { pop_front(); } + void Update(StateId s) {} + bool Empty() const { return empty(); } + void Clear() { clear(); } + + private: + // This allows base-class virtual access to non-virtual derived- + // class members of the same name. It makes the derived class more + // efficient to use but unsafe to further derive. + virtual StateId Head_() const { return Head(); } + virtual void Enqueue_(StateId s) { Enqueue(s); } + virtual void Dequeue_() { Dequeue(); } + virtual void Update_(StateId s) { Update(s); } + virtual bool Empty_() const { return Empty(); } + virtual void Clear_() { return Clear(); } +}; + + +// Shortest-first queue discipline, templated on the StateId and +// comparison function object. Comparison function object COMP is +// used to compare two StateIds. If a (single) state's order changes, +// it can be reordered in the queue with a call to Update(). +// If 'update == false', call to Update() does not reorder the queue. +template +class ShortestFirstQueue : public QueueBase { + public: + typedef S StateId; + typedef C Compare; + + ShortestFirstQueue(C comp) + : QueueBase(SHORTEST_FIRST_QUEUE), heap_(comp) {} + + StateId Head() const { return heap_.Top(); } + + void Enqueue(StateId s) { + if (update) { + for (StateId i = key_.size(); i <= s; ++i) + key_.push_back(kNoKey); + key_[s] = heap_.Insert(s); + } else { + heap_.Insert(s); + } + } + + void Dequeue() { + if (update) + key_[heap_.Pop()] = kNoKey; + else + heap_.Pop(); + } + + void Update(StateId s) { + if (!update) + return; + if (s >= key_.size() || key_[s] == kNoKey) { + Enqueue(s); + } else { + heap_.Update(key_[s], s); + } + } + + bool Empty() const { return heap_.Empty(); } + + void Clear() { + heap_.Clear(); + if (update) key_.clear(); + } + + private: + Heap heap_; + vector key_; + + // This allows base-class virtual access to non-virtual derived- + // class members of the same name. It makes the derived class more + // efficient to use but unsafe to further derive. + virtual StateId Head_() const { return Head(); } + virtual void Enqueue_(StateId s) { Enqueue(s); } + virtual void Dequeue_() { Dequeue(); } + virtual void Update_(StateId s) { Update(s); } + virtual bool Empty_() const { return Empty(); } + virtual void Clear_() { return Clear(); } +}; + + +// Given a vector that maps from states to weights and a Less +// comparison function object between weights, this class defines a +// comparison function object between states. +template +class StateWeightCompare { + public: + typedef L Less; + typedef typename L::Weight Weight; + typedef S StateId; + + StateWeightCompare(const vector& weights, const L &less) + : weights_(weights), less_(less) {} + + bool operator()(const S x, const S y) const { + return less_(weights_[x], weights_[y]); + } + + private: + const vector& weights_; + L less_; +}; + + +// Shortest-first queue discipline, templated on the StateId and Weight, is +// specialized to use the weight's natural order for the comparison function. +template +class NaturalShortestFirstQueue : + public ShortestFirstQueue > > { + public: + typedef StateWeightCompare > C; + + NaturalShortestFirstQueue(const vector &distance) : + ShortestFirstQueue(C(distance, less_)) {} + + private: + NaturalLess less_; +}; + +// Topological-order queue discipline, templated on the StateId. +// States are ordered in the queue topologically. The FST must be acyclic. +template +class TopOrderQueue : public QueueBase { + public: + typedef S StateId; + + // This constructor computes the top. order. It accepts an arc filter + // to limit the transitions considered in that computation (e.g., only + // the epsilon graph). + template + TopOrderQueue(const Fst &fst, ArcFilter filter) + : QueueBase(TOP_ORDER_QUEUE), front_(0), back_(kNoStateId), + order_(0), state_(0) { + bool acyclic; + TopOrderVisitor top_order_visitor(&order_, &acyclic); + DfsVisit(fst, &top_order_visitor, filter); + if (!acyclic) { + FSTERROR() << "TopOrderQueue: fst is not acyclic."; + QueueBase::SetError(true); + } + state_.resize(order_.size(), kNoStateId); + } + + // This constructor is passed the top. order, useful when we know it + // beforehand. + TopOrderQueue(const vector &order) + : QueueBase(TOP_ORDER_QUEUE), front_(0), back_(kNoStateId), + order_(order), state_(order.size(), kNoStateId) {} + + StateId Head() const { return state_[front_]; } + + void Enqueue(StateId s) { + if (front_ > back_) front_ = back_ = order_[s]; + else if (order_[s] > back_) back_ = order_[s]; + else if (order_[s] < front_) front_ = order_[s]; + state_[order_[s]] = s; + } + + void Dequeue() { + state_[front_] = kNoStateId; + while ((front_ <= back_) && (state_[front_] == kNoStateId)) ++front_; + } + + void Update(StateId s) {} + + bool Empty() const { return front_ > back_; } + + void Clear() { + for (StateId i = front_; i <= back_; ++i) state_[i] = kNoStateId; + back_ = kNoStateId; + front_ = 0; + } + + private: + StateId front_; + StateId back_; + vector order_; + vector state_; + + // This allows base-class virtual access to non-virtual derived- + // class members of the same name. It makes the derived class more + // efficient to use but unsafe to further derive. + virtual StateId Head_() const { return Head(); } + virtual void Enqueue_(StateId s) { Enqueue(s); } + virtual void Dequeue_() { Dequeue(); } + virtual void Update_(StateId s) { Update(s); } + virtual bool Empty_() const { return Empty(); } + virtual void Clear_() { return Clear(); } +}; + + +// State order queue discipline, templated on the StateId. +// States are ordered in the queue by state Id. +template +class StateOrderQueue : public QueueBase { +public: + typedef S StateId; + + StateOrderQueue() + : QueueBase(STATE_ORDER_QUEUE), front_(0), back_(kNoStateId) {} + + StateId Head() const { return front_; } + + void Enqueue(StateId s) { + if (front_ > back_) front_ = back_ = s; + else if (s > back_) back_ = s; + else if (s < front_) front_ = s; + while (enqueued_.size() <= s) enqueued_.push_back(false); + enqueued_[s] = true; + } + + void Dequeue() { + enqueued_[front_] = false; + while ((front_ <= back_) && (enqueued_[front_] == false)) ++front_; + } + + void Update(StateId s) {} + + bool Empty() const { return front_ > back_; } + + void Clear() { + for (StateId i = front_; i <= back_; ++i) enqueued_[i] = false; + front_ = 0; + back_ = kNoStateId; + } + +private: + StateId front_; + StateId back_; + vector enqueued_; + + // This allows base-class virtual access to non-virtual derived- + // class members of the same name. It makes the derived class more + // efficient to use but unsafe to further derive. + virtual StateId Head_() const { return Head(); } + virtual void Enqueue_(StateId s) { Enqueue(s); } + virtual void Dequeue_() { Dequeue(); } + virtual void Update_(StateId s) { Update(s); } + virtual bool Empty_() const { return Empty(); } + virtual void Clear_() { return Clear(); } + +}; + + +// SCC topological-order meta-queue discipline, templated on the StateId S +// and a queue Q, which is used inside each SCC. It visits the SCC's +// of an FST in topological order. Its constructor is passed the queues to +// to use within an SCC. +template +class SccQueue : public QueueBase { + public: + typedef S StateId; + typedef Q Queue; + + // Constructor takes a vector specifying the SCC number per state + // and a vector giving the queue to use per SCC number. + SccQueue(const vector &scc, vector *queue) + : QueueBase(SCC_QUEUE), queue_(queue), scc_(scc), front_(0), + back_(kNoStateId) {} + + StateId Head() const { + while ((front_ <= back_) && + (((*queue_)[front_] && (*queue_)[front_]->Empty()) + || (((*queue_)[front_] == 0) && + ((front_ >= trivial_queue_.size()) + || (trivial_queue_[front_] == kNoStateId))))) + ++front_; + if ((*queue_)[front_]) + return (*queue_)[front_]->Head(); + else + return trivial_queue_[front_]; + } + + void Enqueue(StateId s) { + if (front_ > back_) front_ = back_ = scc_[s]; + else if (scc_[s] > back_) back_ = scc_[s]; + else if (scc_[s] < front_) front_ = scc_[s]; + if ((*queue_)[scc_[s]]) { + (*queue_)[scc_[s]]->Enqueue(s); + } else { + while (trivial_queue_.size() <= scc_[s]) + trivial_queue_.push_back(kNoStateId); + trivial_queue_[scc_[s]] = s; + } + } + + void Dequeue() { + if ((*queue_)[front_]) + (*queue_)[front_]->Dequeue(); + else if (front_ < trivial_queue_.size()) + trivial_queue_[front_] = kNoStateId; + } + + void Update(StateId s) { + if ((*queue_)[scc_[s]]) + (*queue_)[scc_[s]]->Update(s); + } + + bool Empty() const { + if (front_ < back_) // Queue scc # back_ not empty unless back_==front_ + return false; + else if (front_ > back_) + return true; + else if ((*queue_)[front_]) + return (*queue_)[front_]->Empty(); + else + return (front_ >= trivial_queue_.size()) + || (trivial_queue_[front_] == kNoStateId); + } + + void Clear() { + for (StateId i = front_; i <= back_; ++i) + if ((*queue_)[i]) + (*queue_)[i]->Clear(); + else if (i < trivial_queue_.size()) + trivial_queue_[i] = kNoStateId; + front_ = 0; + back_ = kNoStateId; + } + +private: + vector *queue_; + const vector &scc_; + mutable StateId front_; + StateId back_; + vector trivial_queue_; + + // This allows base-class virtual access to non-virtual derived- + // class members of the same name. It makes the derived class more + // efficient to use but unsafe to further derive. + virtual StateId Head_() const { return Head(); } + virtual void Enqueue_(StateId s) { Enqueue(s); } + virtual void Dequeue_() { Dequeue(); } + virtual void Update_(StateId s) { Update(s); } + virtual bool Empty_() const { return Empty(); } + virtual void Clear_() { return Clear(); } + + DISALLOW_COPY_AND_ASSIGN(SccQueue); +}; + + +// Automatic queue discipline, templated on the StateId. It selects a +// queue discipline for a given FST based on its properties. +template +class AutoQueue : public QueueBase { +public: + typedef S StateId; + + // This constructor takes a state distance vector that, if non-null and if + // the Weight type has the path property, will entertain the + // shortest-first queue using the natural order w.r.t to the distance. + template + AutoQueue(const Fst &fst, const vector *distance, + ArcFilter filter) : QueueBase(AUTO_QUEUE) { + typedef typename Arc::Weight Weight; + typedef StateWeightCompare< StateId, NaturalLess > Compare; + + // First check if the FST is known to have these properties. + uint64 props = fst.Properties(kAcyclic | kCyclic | + kTopSorted | kUnweighted, false); + if ((props & kTopSorted) || fst.Start() == kNoStateId) { + queue_ = new StateOrderQueue(); + VLOG(2) << "AutoQueue: using state-order discipline"; + } else if (props & kAcyclic) { + queue_ = new TopOrderQueue(fst, filter); + VLOG(2) << "AutoQueue: using top-order discipline"; + } else if ((props & kUnweighted) && (Weight::Properties() & kIdempotent)) { + queue_ = new LifoQueue(); + VLOG(2) << "AutoQueue: using LIFO discipline"; + } else { + uint64 properties; + // Decompose into strongly-connected components. + SccVisitor scc_visitor(&scc_, 0, 0, &properties); + DfsVisit(fst, &scc_visitor, filter); + StateId nscc = *max_element(scc_.begin(), scc_.end()) + 1; + vector queue_types(nscc); + NaturalLess *less = 0; + Compare *comp = 0; + if (distance && (Weight::Properties() & kPath)) { + less = new NaturalLess; + comp = new Compare(*distance, *less); + } + // Find the queue type to use per SCC. + bool unweighted; + bool all_trivial; + SccQueueType(fst, scc_, &queue_types, filter, less, &all_trivial, + &unweighted); + // If unweighted and semiring is idempotent, use lifo queue. + if (unweighted) { + queue_ = new LifoQueue(); + VLOG(2) << "AutoQueue: using LIFO discipline"; + delete comp; + delete less; + return; + } + // If all the scc are trivial, FST is acyclic and the scc# gives + // the topological order. + if (all_trivial) { + queue_ = new TopOrderQueue(scc_); + VLOG(2) << "AutoQueue: using top-order discipline"; + delete comp; + delete less; + return; + } + VLOG(2) << "AutoQueue: using SCC meta-discipline"; + queues_.resize(nscc); + for (StateId i = 0; i < nscc; ++i) { + switch(queue_types[i]) { + case TRIVIAL_QUEUE: + queues_[i] = 0; + VLOG(3) << "AutoQueue: SCC #" << i + << ": using trivial discipline"; + break; + case SHORTEST_FIRST_QUEUE: + queues_[i] = new ShortestFirstQueue(*comp); + VLOG(3) << "AutoQueue: SCC #" << i << + ": using shortest-first discipline"; + break; + case LIFO_QUEUE: + queues_[i] = new LifoQueue(); + VLOG(3) << "AutoQueue: SCC #" << i + << ": using LIFO disciplle"; + break; + case FIFO_QUEUE: + default: + queues_[i] = new FifoQueue(); + VLOG(3) << "AutoQueue: SCC #" << i + << ": using FIFO disciplle"; + break; + } + } + queue_ = new SccQueue< StateId, QueueBase >(scc_, &queues_); + delete comp; + delete less; + } + } + + ~AutoQueue() { + for (StateId i = 0; i < queues_.size(); ++i) + delete queues_[i]; + delete queue_; + } + + StateId Head() const { return queue_->Head(); } + + void Enqueue(StateId s) { queue_->Enqueue(s); } + + void Dequeue() { queue_->Dequeue(); } + + void Update(StateId s) { queue_->Update(s); } + + bool Empty() const { return queue_->Empty(); } + + void Clear() { queue_->Clear(); } + + + private: + QueueBase *queue_; + vector< QueueBase* > queues_; + vector scc_; + + template + static void SccQueueType(const Fst &fst, + const vector &scc, + vector *queue_types, + ArcFilter filter, Less *less, + bool *all_trivial, bool *unweighted); + + // This allows base-class virtual access to non-virtual derived- + // class members of the same name. It makes the derived class more + // efficient to use but unsafe to further derive. + virtual StateId Head_() const { return Head(); } + + virtual void Enqueue_(StateId s) { Enqueue(s); } + + virtual void Dequeue_() { Dequeue(); } + + virtual void Update_(StateId s) { Update(s); } + + virtual bool Empty_() const { return Empty(); } + + virtual void Clear_() { return Clear(); } + + DISALLOW_COPY_AND_ASSIGN(AutoQueue); +}; + + +// Examines the states in an Fst's strongly connected components and +// determines which type of queue to use per SCC. Stores result in +// vector QUEUE_TYPES, which is assumed to have length equal to the +// number of SCCs. An arc filter is used to limit the transitions +// considered (e.g., only the epsilon graph). ALL_TRIVIAL is set +// to true if every queue is the trivial queue. UNWEIGHTED is set to +// true if the semiring is idempotent and all the arc weights are equal to +// Zero() or One(). +template +template +void AutoQueue::SccQueueType(const Fst &fst, + const vector &scc, + vector *queue_type, + ArcFilter filter, Less *less, + bool *all_trivial, bool *unweighted) { + typedef A Arc; + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + *all_trivial = true; + *unweighted = true; + + for (StateId i = 0; i < queue_type->size(); ++i) + (*queue_type)[i] = TRIVIAL_QUEUE; + + for (StateIterator< Fst > sit(fst); !sit.Done(); sit.Next()) { + StateId state = sit.Value(); + for (ArcIterator< Fst > ait(fst, state); + !ait.Done(); + ait.Next()) { + const Arc &arc = ait.Value(); + if (!filter(arc)) continue; + if (scc[state] == scc[arc.nextstate]) { + QueueType &type = (*queue_type)[scc[state]]; + if (!less || ((*less)(arc.weight, Weight::One()))) + type = FIFO_QUEUE; + else if ((type == TRIVIAL_QUEUE) || (type == LIFO_QUEUE)) { + if (!(Weight::Properties() & kIdempotent) || + (arc.weight != Weight::Zero() && arc.weight != Weight::One())) + type = SHORTEST_FIRST_QUEUE; + else + type = LIFO_QUEUE; + } + if (type != TRIVIAL_QUEUE) *all_trivial = false; + } + if (!(Weight::Properties() & kIdempotent) || + (arc.weight != Weight::Zero() && arc.weight != Weight::One())) + *unweighted = false; + } + } +} + + +// An A* estimate is a function object that maps from a state ID to a +// an estimate of the shortest distance to the final states. +// The trivial A* estimate is always One(). +template +struct TrivialAStarEstimate { + W operator()(S s) const { return W::One(); } +}; + + +// Given a vector that maps from states to weights representing the +// shortest distance from the initial state, a Less comparison +// function object between weights, and an estimate E of the +// shortest distance to the final states, this class defines a +// comparison function object between states. +template +class AStarWeightCompare { + public: + typedef L Less; + typedef typename L::Weight Weight; + typedef S StateId; + + AStarWeightCompare(const vector& weights, const L &less, + const E &estimate) + : weights_(weights), less_(less), estimate_(estimate) {} + + bool operator()(const S x, const S y) const { + Weight wx = Times(weights_[x], estimate_(x)); + Weight wy = Times(weights_[y], estimate_(y)); + return less_(wx, wy); + } + + private: + const vector& weights_; + L less_; + const E &estimate_; +}; + + +// A* queue discipline, templated on the StateId, Weight and an +// estimate E of the shortest distance to the final states, is specialized +// to use the weight's natural order for the comparison function. +template +class NaturalAStarQueue : + public ShortestFirstQueue, E> > { + public: + typedef AStarWeightCompare, E> C; + + NaturalAStarQueue(const vector &distance, const E &estimate) : + ShortestFirstQueue(C(distance, less_, estimate)) {} + + private: + NaturalLess less_; +}; + + +// A state equivalence class is a function object that +// maps from a state ID to an equivalence class (state) ID. +// The trivial equivalence class maps a state to itself. +template +struct TrivialStateEquivClass { + S operator()(S s) const { return s; } +}; + + +// Distance-based pruning queue discipline: Enqueues a state 's' +// only when its shortest distance (so far), as specified by +// 'distance', is less than (as specified by 'comp') the shortest +// distance Times() the 'threshold' to any state in the same +// equivalence class, as specified by the function object +// 'class_func'. The underlying queue discipline is specified by +// 'queue'. The ownership of 'queue' is given to this class. +template +class PruneQueue : public QueueBase { + public: + typedef typename Q::StateId StateId; + typedef typename L::Weight Weight; + + PruneQueue(const vector &distance, Q *queue, L comp, + const C &class_func, Weight threshold) + : QueueBase(OTHER_QUEUE), + distance_(distance), + queue_(queue), + less_(comp), + class_func_(class_func), + threshold_(threshold) {} + + ~PruneQueue() { delete queue_; } + + StateId Head() const { return queue_->Head(); } + + void Enqueue(StateId s) { + StateId c = class_func_(s); + if (c >= class_distance_.size()) + class_distance_.resize(c + 1, Weight::Zero()); + if (less_(distance_[s], class_distance_[c])) + class_distance_[c] = distance_[s]; + + // Enqueue only if below threshold limit + Weight limit = Times(class_distance_[c], threshold_); + if (less_(distance_[s], limit)) + queue_->Enqueue(s); + } + + void Dequeue() { queue_->Dequeue(); } + + void Update(StateId s) { + StateId c = class_func_(s); + if (less_(distance_[s], class_distance_[c])) + class_distance_[c] = distance_[s]; + queue_->Update(s); + } + + bool Empty() const { return queue_->Empty(); } + void Clear() { queue_->Clear(); } + + private: + // This allows base-class virtual access to non-virtual derived- + // class members of the same name. It makes the derived class more + // efficient to use but unsafe to further derive. + virtual StateId Head_() const { return Head(); } + virtual void Enqueue_(StateId s) { Enqueue(s); } + virtual void Dequeue_() { Dequeue(); } + virtual void Update_(StateId s) { Update(s); } + virtual bool Empty_() const { return Empty(); } + virtual void Clear_() { return Clear(); } + + const vector &distance_; // shortest distance to state + Q *queue_; + L less_; + const C &class_func_; // eqv. class function object + Weight threshold_; // pruning weight threshold + vector class_distance_; // shortest distance to class + + DISALLOW_COPY_AND_ASSIGN(PruneQueue); +}; + + +// Pruning queue discipline (see above) using the weight's natural +// order for the comparison function. The ownership of 'queue' is +// given to this class. +template +class NaturalPruneQueue : + public PruneQueue, C> { + public: + typedef typename Q::StateId StateId; + typedef W Weight; + + NaturalPruneQueue(const vector &distance, Q *queue, + const C &class_func_, Weight threshold) : + PruneQueue, C>(distance, queue, less_, + class_func_, threshold) {} + + private: + NaturalLess less_; +}; + + +// Filter-based pruning queue discipline: Enqueues a state 's' only +// if allowed by the filter, specified by the function object 'state_filter'. +// The underlying queue discipline is specified by 'queue'. The ownership +// of 'queue' is given to this class. +template +class FilterQueue : public QueueBase { + public: + typedef typename Q::StateId StateId; + + FilterQueue(Q *queue, const F &state_filter) + : QueueBase(OTHER_QUEUE), + queue_(queue), + state_filter_(state_filter) {} + + ~FilterQueue() { delete queue_; } + + StateId Head() const { return queue_->Head(); } + + // Enqueues only if allowed by state filter. + void Enqueue(StateId s) { + if (state_filter_(s)) { + queue_->Enqueue(s); + } + } + + void Dequeue() { queue_->Dequeue(); } + + void Update(StateId s) {} + bool Empty() const { return queue_->Empty(); } + void Clear() { queue_->Clear(); } + + private: + // This allows base-class virtual access to non-virtual derived- + // class members of the same name. It makes the derived class more + // efficient to use but unsafe to further derive. + virtual StateId Head_() const { return Head(); } + virtual void Enqueue_(StateId s) { Enqueue(s); } + virtual void Dequeue_() { Dequeue(); } + virtual void Update_(StateId s) { Update(s); } + virtual bool Empty_() const { return Empty(); } + virtual void Clear_() { return Clear(); } + + Q *queue_; + const F &state_filter_; // Filter to prune states + + DISALLOW_COPY_AND_ASSIGN(FilterQueue); +}; + +} // namespace fst + +#endif diff --git a/kaldi_io/src/tools/openfst/include/fst/randequivalent.h b/kaldi_io/src/tools/openfst/include/fst/randequivalent.h new file mode 100644 index 0000000..1aaccf7 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/randequivalent.h @@ -0,0 +1,135 @@ +// randequivalent.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: allauzen@google.com (Cyril Allauzen) +// +// \file +// Tests if two FSTS are equivalent by checking if random +// strings from one FST are transduced the same by both FSTs. + +#ifndef FST_RANDEQUIVALENT_H__ +#define FST_RANDEQUIVALENT_H__ + +#include +#include +#include +#include +#include +#include + + +namespace fst { + +// Test if two FSTs are equivalent by randomly generating 'num_paths' +// paths (as specified by the RandGenOptions 'opts') in these FSTs. +// +// For each randomly generated path, the algorithm computes for each +// of the two FSTs the sum of the weights of all the successful paths +// sharing the same input and output labels as the considered randomly +// generated path and checks that these two values are within +// 'delta'. Returns optional error value (when FLAGS_error_fatal = false). +template +bool RandEquivalent(const Fst &fst1, const Fst &fst2, + ssize_t num_paths, float delta, + const RandGenOptions &opts, + bool *error = 0) { + typedef typename Arc::Weight Weight; + if (error) *error = false; + + // Check that the symbol table are compatible + if (!CompatSymbols(fst1.InputSymbols(), fst2.InputSymbols()) || + !CompatSymbols(fst1.OutputSymbols(), fst2.OutputSymbols())) { + FSTERROR() << "RandEquivalent: input/output symbol tables of 1st " + << "argument do not match input/output symbol tables of 2nd " + << "argument"; + if (error) *error = true; + return false; + } + + ILabelCompare icomp; + OLabelCompare ocomp; + VectorFst sfst1(fst1); + VectorFst sfst2(fst2); + Connect(&sfst1); + Connect(&sfst2); + ArcSort(&sfst1, icomp); + ArcSort(&sfst2, icomp); + + bool ret = true; + for (ssize_t n = 0; n < num_paths; ++n) { + VectorFst path; + const Fst &fst = rand() % 2 ? sfst1 : sfst2; + RandGen(fst, &path, opts); + + VectorFst ipath(path); + VectorFst opath(path); + Project(&ipath, PROJECT_INPUT); + Project(&opath, PROJECT_OUTPUT); + + VectorFst cfst1, pfst1; + Compose(ipath, sfst1, &cfst1); + ArcSort(&cfst1, ocomp); + Compose(cfst1, opath, &pfst1); + // Give up if there are epsilon cycles in a non-idempotent semiring + if (!(Weight::Properties() & kIdempotent) && + pfst1.Properties(kCyclic, true)) + continue; + Weight sum1 = ShortestDistance(pfst1); + + VectorFst cfst2, pfst2; + Compose(ipath, sfst2, &cfst2); + ArcSort(&cfst2, ocomp); + Compose(cfst2, opath, &pfst2); + // Give up if there are epsilon cycles in a non-idempotent semiring + if (!(Weight::Properties() & kIdempotent) && + pfst2.Properties(kCyclic, true)) + continue; + Weight sum2 = ShortestDistance(pfst2); + + if (!ApproxEqual(sum1, sum2, delta)) { + VLOG(1) << "Sum1 = " << sum1; + VLOG(1) << "Sum2 = " << sum2; + ret = false; + break; + } + } + + if (fst1.Properties(kError, false) || fst2.Properties(kError, false)) { + if (error) *error = true; + return false; + } + + return ret; +} + + +// Test if two FSTs are equivalent by randomly generating 'num_paths' paths +// of length no more than 'path_length' using the seed 'seed' in these FSTs. +// Returns optional error value (when FLAGS_error_fatal = false). +template +bool RandEquivalent(const Fst &fst1, const Fst &fst2, + ssize_t num_paths, float delta = kDelta, + int seed = time(0), int path_length = INT_MAX, + bool *error = 0) { + UniformArcSelector uniform_selector(seed); + RandGenOptions< UniformArcSelector > + opts(uniform_selector, path_length); + return RandEquivalent(fst1, fst2, num_paths, delta, opts, error); +} + + +} // namespace fst + +#endif // FST_LIB_RANDEQUIVALENT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/randgen.h b/kaldi_io/src/tools/openfst/include/fst/randgen.h new file mode 100644 index 0000000..82ddffa --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/randgen.h @@ -0,0 +1,712 @@ +// randgen.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Classes and functions to generate random paths through an FST. + +#ifndef FST_LIB_RANDGEN_H__ +#define FST_LIB_RANDGEN_H__ + +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace fst { + +// +// ARC SELECTORS - these function objects are used to select a random +// transition to take from an FST's state. They should return a number +// N s.t. 0 <= N <= NumArcs(). If N < NumArcs(), then the N-th +// transition is selected. If N == NumArcs(), then the final weight at +// that state is selected (i.e., the 'super-final' transition is selected). +// It can be assumed these will not be called unless either there +// are transitions leaving the state and/or the state is final. +// + +// Randomly selects a transition using the uniform distribution. +template +struct UniformArcSelector { + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + UniformArcSelector(int seed = time(0)) { srand(seed); } + + size_t operator()(const Fst &fst, StateId s) const { + double r = rand()/(RAND_MAX + 1.0); + size_t n = fst.NumArcs(s); + if (fst.Final(s) != Weight::Zero()) + ++n; + return static_cast(r * n); + } +}; + + +// Randomly selects a transition w.r.t. the weights treated as negative +// log probabilities after normalizing for the total weight leaving +// the state. Weight::zero transitions are disregarded. +// Assumes Weight::Value() accesses the floating point +// representation of the weight. +template +class LogProbArcSelector { + public: + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + LogProbArcSelector(int seed = time(0)) { srand(seed); } + + size_t operator()(const Fst &fst, StateId s) const { + // Find total weight leaving state + double sum = 0.0; + for (ArcIterator< Fst > aiter(fst, s); !aiter.Done(); + aiter.Next()) { + const A &arc = aiter.Value(); + sum += exp(-to_log_weight_(arc.weight).Value()); + } + sum += exp(-to_log_weight_(fst.Final(s)).Value()); + + double r = rand()/(RAND_MAX + 1.0); + double p = 0.0; + int n = 0; + for (ArcIterator< Fst > aiter(fst, s); !aiter.Done(); + aiter.Next(), ++n) { + const A &arc = aiter.Value(); + p += exp(-to_log_weight_(arc.weight).Value()); + if (p > r * sum) return n; + } + return n; + } + + private: + WeightConvert to_log_weight_; +}; + +// Convenience definitions +typedef LogProbArcSelector StdArcSelector; +typedef LogProbArcSelector LogArcSelector; + + +// Same as LogProbArcSelector but use CacheLogAccumulator to cache +// the cummulative weight computations. +template +class FastLogProbArcSelector : public LogProbArcSelector { + public: + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + using LogProbArcSelector::operator(); + + FastLogProbArcSelector(int seed = time(0)) + : LogProbArcSelector(seed), + seed_(seed) {} + + size_t operator()(const Fst &fst, StateId s, + CacheLogAccumulator *accumulator) const { + accumulator->SetState(s); + ArcIterator< Fst > aiter(fst, s); + // Find total weight leaving state + double sum = to_log_weight_(accumulator->Sum(fst.Final(s), &aiter, 0, + fst.NumArcs(s))).Value(); + double r = -log(rand()/(RAND_MAX + 1.0)); + return accumulator->LowerBound(r + sum, &aiter); + } + + int Seed() const { return seed_; } + private: + int seed_; + WeightConvert to_log_weight_; +}; + +// Random path state info maintained by RandGenFst and passed to samplers. +template +struct RandState { + typedef typename A::StateId StateId; + + StateId state_id; // current input FST state + size_t nsamples; // # of samples to be sampled at this state + size_t length; // length of path to this random state + size_t select; // previous sample arc selection + const RandState *parent; // previous random state on this path + + RandState(StateId s, size_t n, size_t l, size_t k, const RandState *p) + : state_id(s), nsamples(n), length(l), select(k), parent(p) {} + + RandState() + : state_id(kNoStateId), nsamples(0), length(0), select(0), parent(0) {} +}; + +// This class, given an arc selector, samples, with raplacement, +// multiple random transitions from an FST's state. This is a generic +// version with a straight-forward use of the arc selector. +// Specializations may be defined for arc selectors for greater +// efficiency or special behavior. +template +class ArcSampler { + public: + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + // The 'max_length' may be interpreted (including ignored) by a + // sampler as it chooses. This generic version interprets this literally. + ArcSampler(const Fst &fst, const S &arc_selector, + int max_length = INT_MAX) + : fst_(fst), + arc_selector_(arc_selector), + max_length_(max_length) {} + + // Allow updating Fst argument; pass only if changed. + ArcSampler(const ArcSampler &sampler, const Fst *fst = 0) + : fst_(fst ? *fst : sampler.fst_), + arc_selector_(sampler.arc_selector_), + max_length_(sampler.max_length_) { + Reset(); + } + + // Samples 'rstate.nsamples' from state 'state_id'. The 'rstate.length' is + // the length of the path to 'rstate'. Returns true if samples were + // collected. No samples may be collected if either there are no (including + // 'super-final') transitions leaving that state or if the + // 'max_length' has been deemed reached. Use the iterator members to + // read the samples. The samples will be in their original order. + bool Sample(const RandState &rstate) { + sample_map_.clear(); + if ((fst_.NumArcs(rstate.state_id) == 0 && + fst_.Final(rstate.state_id) == Weight::Zero()) || + rstate.length == max_length_) { + Reset(); + return false; + } + + for (size_t i = 0; i < rstate.nsamples; ++i) + ++sample_map_[arc_selector_(fst_, rstate.state_id)]; + Reset(); + return true; + } + + // More samples? + bool Done() const { return sample_iter_ == sample_map_.end(); } + + // Gets the next sample. + void Next() { ++sample_iter_; } + + // Returns a pair (N, K) where 0 <= N <= NumArcs(s) and 0 < K <= nsamples. + // If N < NumArcs(s), then the N-th transition is specified. + // If N == NumArcs(s), then the final weight at that state is + // specified (i.e., the 'super-final' transition is specified). + // For the specified transition, K repetitions have been sampled. + pair Value() const { return *sample_iter_; } + + void Reset() { sample_iter_ = sample_map_.begin(); } + + bool Error() const { return false; } + + private: + const Fst &fst_; + const S &arc_selector_; + int max_length_; + + // Stores (N, K) as described for Value(). + map sample_map_; + map::const_iterator sample_iter_; + + // disallow + ArcSampler & operator=(const ArcSampler &s); +}; + + +// Specialization for FastLogProbArcSelector. +template +class ArcSampler > { + public: + typedef FastLogProbArcSelector S; + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + typedef CacheLogAccumulator C; + + ArcSampler(const Fst &fst, const S &arc_selector, int max_length = INT_MAX) + : fst_(fst), + arc_selector_(arc_selector), + max_length_(max_length), + accumulator_(new C()) { + accumulator_->Init(fst); + } + + ArcSampler(const ArcSampler &sampler, const Fst *fst = 0) + : fst_(fst ? *fst : sampler.fst_), + arc_selector_(sampler.arc_selector_), + max_length_(sampler.max_length_) { + if (fst) { + accumulator_ = new C(); + accumulator_->Init(*fst); + } else { // shallow copy + accumulator_ = new C(*sampler.accumulator_); + } + } + + ~ArcSampler() { + delete accumulator_; + } + + bool Sample(const RandState &rstate) { + sample_map_.clear(); + if ((fst_.NumArcs(rstate.state_id) == 0 && + fst_.Final(rstate.state_id) == Weight::Zero()) || + rstate.length == max_length_) { + Reset(); + return false; + } + + for (size_t i = 0; i < rstate.nsamples; ++i) + ++sample_map_[arc_selector_(fst_, rstate.state_id, accumulator_)]; + Reset(); + return true; + } + + bool Done() const { return sample_iter_ == sample_map_.end(); } + void Next() { ++sample_iter_; } + pair Value() const { return *sample_iter_; } + void Reset() { sample_iter_ = sample_map_.begin(); } + + bool Error() const { return accumulator_->Error(); } + + private: + const Fst &fst_; + const S &arc_selector_; + int max_length_; + + // Stores (N, K) as described for Value(). + map sample_map_; + map::const_iterator sample_iter_; + C *accumulator_; + + // disallow + ArcSampler & operator=(const ArcSampler &s); +}; + + +// Options for random path generation with RandGenFst. The template argument +// is an arc sampler, typically class 'ArcSampler' above. Ownership of +// the sampler is taken by RandGenFst. +template +struct RandGenFstOptions : public CacheOptions { + S *arc_sampler; // How to sample transitions at a state + size_t npath; // # of paths to generate + bool weighted; // Output tree weighted by path count; o.w. + // output unweighted DAG + bool remove_total_weight; // Remove total weight when output is weighted. + + RandGenFstOptions(const CacheOptions &copts, S *samp, + size_t n = 1, bool w = true, bool rw = false) + : CacheOptions(copts), + arc_sampler(samp), + npath(n), + weighted(w), + remove_total_weight(rw) {} +}; + + +// Implementation of RandGenFst. +template +class RandGenFstImpl : public CacheImpl { + public: + using FstImpl::SetType; + using FstImpl::SetProperties; + using FstImpl::SetInputSymbols; + using FstImpl::SetOutputSymbols; + + using CacheBaseImpl< CacheState >::AddArc; + using CacheBaseImpl< CacheState >::HasArcs; + using CacheBaseImpl< CacheState >::HasFinal; + using CacheBaseImpl< CacheState >::HasStart; + using CacheBaseImpl< CacheState >::SetArcs; + using CacheBaseImpl< CacheState >::SetFinal; + using CacheBaseImpl< CacheState >::SetStart; + + typedef B Arc; + typedef typename A::Label Label; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + + RandGenFstImpl(const Fst &fst, const RandGenFstOptions &opts) + : CacheImpl(opts), + fst_(fst.Copy()), + arc_sampler_(opts.arc_sampler), + npath_(opts.npath), + weighted_(opts.weighted), + remove_total_weight_(opts.remove_total_weight), + superfinal_(kNoLabel) { + SetType("randgen"); + + uint64 props = fst.Properties(kFstProperties, false); + SetProperties(RandGenProperties(props, weighted_), kCopyProperties); + + SetInputSymbols(fst.InputSymbols()); + SetOutputSymbols(fst.OutputSymbols()); + } + + RandGenFstImpl(const RandGenFstImpl &impl) + : CacheImpl(impl), + fst_(impl.fst_->Copy(true)), + arc_sampler_(new S(*impl.arc_sampler_, fst_)), + npath_(impl.npath_), + weighted_(impl.weighted_), + superfinal_(kNoLabel) { + SetType("randgen"); + SetProperties(impl.Properties(), kCopyProperties); + SetInputSymbols(impl.InputSymbols()); + SetOutputSymbols(impl.OutputSymbols()); + } + + ~RandGenFstImpl() { + for (int i = 0; i < state_table_.size(); ++i) + delete state_table_[i]; + delete fst_; + delete arc_sampler_; + } + + StateId Start() { + if (!HasStart()) { + StateId s = fst_->Start(); + if (s == kNoStateId) + return kNoStateId; + StateId start = state_table_.size(); + SetStart(start); + RandState *rstate = new RandState(s, npath_, 0, 0, 0); + state_table_.push_back(rstate); + } + return CacheImpl::Start(); + } + + Weight Final(StateId s) { + if (!HasFinal(s)) { + Expand(s); + } + return CacheImpl::Final(s); + } + + size_t NumArcs(StateId s) { + if (!HasArcs(s)) { + Expand(s); + } + return CacheImpl::NumArcs(s); + } + + size_t NumInputEpsilons(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumInputEpsilons(s); + } + + size_t NumOutputEpsilons(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumOutputEpsilons(s); + } + + uint64 Properties() const { return Properties(kFstProperties); } + + // Set error if found; return FST impl properties. + uint64 Properties(uint64 mask) const { + if ((mask & kError) && + (fst_->Properties(kError, false) || arc_sampler_->Error())) { + SetProperties(kError, kError); + } + return FstImpl::Properties(mask); + } + + void InitArcIterator(StateId s, ArcIteratorData *data) { + if (!HasArcs(s)) + Expand(s); + CacheImpl::InitArcIterator(s, data); + } + + // Computes the outgoing transitions from a state, creating new destination + // states as needed. + void Expand(StateId s) { + if (s == superfinal_) { + SetFinal(s, Weight::One()); + SetArcs(s); + return; + } + + SetFinal(s, Weight::Zero()); + const RandState &rstate = *state_table_[s]; + arc_sampler_->Sample(rstate); + ArcIterator< Fst > aiter(*fst_, rstate.state_id); + size_t narcs = fst_->NumArcs(rstate.state_id); + for (;!arc_sampler_->Done(); arc_sampler_->Next()) { + const pair &sample_pair = arc_sampler_->Value(); + size_t pos = sample_pair.first; + size_t count = sample_pair.second; + double prob = static_cast(count)/rstate.nsamples; + if (pos < narcs) { // regular transition + aiter.Seek(sample_pair.first); + const A &aarc = aiter.Value(); + Weight weight = weighted_ ? to_weight_(-log(prob)) : Weight::One(); + B barc(aarc.ilabel, aarc.olabel, weight, state_table_.size()); + AddArc(s, barc); + RandState *nrstate = + new RandState(aarc.nextstate, count, rstate.length + 1, + pos, &rstate); + state_table_.push_back(nrstate); + } else { // super-final transition + if (weighted_) { + Weight weight = remove_total_weight_ ? + to_weight_(-log(prob)) : to_weight_(-log(prob * npath_)); + SetFinal(s, weight); + } else { + if (superfinal_ == kNoLabel) { + superfinal_ = state_table_.size(); + RandState *nrstate = new RandState(kNoStateId, 0, 0, 0, 0); + state_table_.push_back(nrstate); + } + for (size_t n = 0; n < count; ++n) { + B barc(0, 0, Weight::One(), superfinal_); + AddArc(s, barc); + } + } + } + } + SetArcs(s); + } + + private: + Fst *fst_; + S *arc_sampler_; + size_t npath_; + vector *> state_table_; + bool weighted_; + bool remove_total_weight_; + StateId superfinal_; + WeightConvert to_weight_; + + void operator=(const RandGenFstImpl &); // disallow +}; + + +// Fst class to randomly generate paths through an FST; details controlled +// by RandGenOptionsFst. Output format is a tree weighted by the +// path count. +template +class RandGenFst : public ImplToFst< RandGenFstImpl > { + public: + friend class ArcIterator< RandGenFst >; + friend class StateIterator< RandGenFst >; + typedef B Arc; + typedef S Sampler; + typedef typename A::Label Label; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + typedef CacheState State; + typedef RandGenFstImpl Impl; + + RandGenFst(const Fst &fst, const RandGenFstOptions &opts) + : ImplToFst(new Impl(fst, opts)) {} + + // See Fst<>::Copy() for doc. + RandGenFst(const RandGenFst &fst, bool safe = false) + : ImplToFst(fst, safe) {} + + // Get a copy of this RandGenFst. See Fst<>::Copy() for further doc. + virtual RandGenFst *Copy(bool safe = false) const { + return new RandGenFst(*this, safe); + } + + virtual inline void InitStateIterator(StateIteratorData *data) const; + + virtual void InitArcIterator(StateId s, ArcIteratorData *data) const { + GetImpl()->InitArcIterator(s, data); + } + + private: + // Makes visible to friends. + Impl *GetImpl() const { return ImplToFst::GetImpl(); } + + void operator=(const RandGenFst &fst); // Disallow +}; + + + +// Specialization for RandGenFst. +template +class StateIterator< RandGenFst > + : public CacheStateIterator< RandGenFst > { + public: + explicit StateIterator(const RandGenFst &fst) + : CacheStateIterator< RandGenFst >(fst, fst.GetImpl()) {} + + private: + DISALLOW_COPY_AND_ASSIGN(StateIterator); +}; + + +// Specialization for RandGenFst. +template +class ArcIterator< RandGenFst > + : public CacheArcIterator< RandGenFst > { + public: + typedef typename A::StateId StateId; + + ArcIterator(const RandGenFst &fst, StateId s) + : CacheArcIterator< RandGenFst >(fst.GetImpl(), s) { + if (!fst.GetImpl()->HasArcs(s)) + fst.GetImpl()->Expand(s); + } + + private: + DISALLOW_COPY_AND_ASSIGN(ArcIterator); +}; + + +template inline +void RandGenFst::InitStateIterator(StateIteratorData *data) const +{ + data->base = new StateIterator< RandGenFst >(*this); +} + +// Options for random path generation. +template +struct RandGenOptions { + const S &arc_selector; // How an arc is selected at a state + int max_length; // Maximum path length + size_t npath; // # of paths to generate + bool weighted; // Output is tree weighted by path count; o.w. + // output unweighted union of paths. + bool remove_total_weight; // Remove total weight when output is weighted. + + RandGenOptions(const S &sel, int len = INT_MAX, size_t n = 1, + bool w = false, bool rw = false) + : arc_selector(sel), + max_length(len), + npath(n), + weighted(w), + remove_total_weight(rw) {} +}; + + +template +class RandGenVisitor { + public: + typedef typename IArc::Weight Weight; + typedef typename IArc::StateId StateId; + + RandGenVisitor(MutableFst *ofst) : ofst_(ofst) {} + + void InitVisit(const Fst &ifst) { + ifst_ = &ifst; + + ofst_->DeleteStates(); + ofst_->SetInputSymbols(ifst.InputSymbols()); + ofst_->SetOutputSymbols(ifst.OutputSymbols()); + if (ifst.Properties(kError, false)) + ofst_->SetProperties(kError, kError); + path_.clear(); + } + + bool InitState(StateId s, StateId root) { return true; } + + bool TreeArc(StateId s, const IArc &arc) { + if (ifst_->Final(arc.nextstate) == Weight::Zero()) { + path_.push_back(arc); + } else { + OutputPath(); + } + return true; + } + + bool BackArc(StateId s, const IArc &arc) { + FSTERROR() << "RandGenVisitor: cyclic input"; + ofst_->SetProperties(kError, kError); + return false; + } + + bool ForwardOrCrossArc(StateId s, const IArc &arc) { + OutputPath(); + return true; + } + + void FinishState(StateId s, StateId p, const IArc *) { + if (p != kNoStateId && ifst_->Final(s) == Weight::Zero()) + path_.pop_back(); + } + + void FinishVisit() {} + + private: + void OutputPath() { + if (ofst_->Start() == kNoStateId) { + StateId start = ofst_->AddState(); + ofst_->SetStart(start); + } + + StateId src = ofst_->Start(); + for (size_t i = 0; i < path_.size(); ++i) { + StateId dest = ofst_->AddState(); + OArc arc(path_[i].ilabel, path_[i].olabel, Weight::One(), dest); + ofst_->AddArc(src, arc); + src = dest; + } + ofst_->SetFinal(src, Weight::One()); + } + + const Fst *ifst_; + MutableFst *ofst_; + vector path_; + + DISALLOW_COPY_AND_ASSIGN(RandGenVisitor); +}; + + +// Randomly generate paths through an FST; details controlled by +// RandGenOptions. +template +void RandGen(const Fst &ifst, MutableFst *ofst, + const RandGenOptions &opts) { + typedef ArcSampler Sampler; + typedef RandGenFst RandFst; + typedef typename OArc::StateId StateId; + typedef typename OArc::Weight Weight; + + Sampler* arc_sampler = new Sampler(ifst, opts.arc_selector, opts.max_length); + RandGenFstOptions fopts(CacheOptions(true, 0), arc_sampler, + opts.npath, opts.weighted, + opts.remove_total_weight); + RandFst rfst(ifst, fopts); + if (opts.weighted) { + *ofst = rfst; + } else { + RandGenVisitor rand_visitor(ofst); + DfsVisit(rfst, &rand_visitor); + } +} + +// Randomly generate a path through an FST with the uniform distribution +// over the transitions. +template +void RandGen(const Fst &ifst, MutableFst *ofst) { + UniformArcSelector uniform_selector; + RandGenOptions< UniformArcSelector > opts(uniform_selector); + RandGen(ifst, ofst, opts); +} + +} // namespace fst + +#endif // FST_LIB_RANDGEN_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/random-weight.h b/kaldi_io/src/tools/openfst/include/fst/random-weight.h new file mode 100644 index 0000000..0ccd95d --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/random-weight.h @@ -0,0 +1,348 @@ +// random-weight.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Function objects to generate random weights in various semirings +// for testing purposes. + +#ifndef FST_LIB_RANDOM_WEIGHT_H__ +#define FST_LIB_RANDOM_WEIGHT_H__ + +#include +#include +#include +using std::vector; + + +#include +#include +#include +#include +#include +#include +#include + + +namespace fst { + +// The boolean 'allow_zero' below determines whether Zero() and zero +// divisors should be returned in the random weight generation. + +// This function object returns TropicalWeightTpl's that are random integers +// chosen from [0, kNumRandomWeights). +template +class TropicalWeightGenerator_ { + public: + typedef TropicalWeightTpl Weight; + + TropicalWeightGenerator_(int seed = time(0), bool allow_zero = true) + : allow_zero_(allow_zero) { + srand(seed); + } + + Weight operator() () const { + int n = rand() % (kNumRandomWeights + allow_zero_); + if (allow_zero_ && n == kNumRandomWeights) + return Weight::Zero(); + + return Weight(static_cast(n)); + } + + private: + // The number of alternative random weights. + static const int kNumRandomWeights = 5; + + bool allow_zero_; // permit Zero() and zero divisors +}; + +template const int TropicalWeightGenerator_::kNumRandomWeights; + +typedef TropicalWeightGenerator_ TropicalWeightGenerator; + + +// This function object returns LogWeightTpl's that are random integers +// chosen from [0, kNumRandomWeights). +template +class LogWeightGenerator_ { + public: + typedef LogWeightTpl Weight; + + LogWeightGenerator_(int seed = time(0), bool allow_zero = true) + : allow_zero_(allow_zero) { + srand(seed); + } + + Weight operator() () const { + int n = rand() % (kNumRandomWeights + allow_zero_); + if (allow_zero_ && n == kNumRandomWeights) + return Weight::Zero(); + + return Weight(static_cast(n)); + } + + private: + // Number of alternative random weights. + static const int kNumRandomWeights = 5; + + bool allow_zero_; // permit Zero() and zero divisors +}; + +template const int LogWeightGenerator_::kNumRandomWeights; + +typedef LogWeightGenerator_ LogWeightGenerator; + + +// This function object returns MinMaxWeightTpl's that are random integers +// chosen from (-kNumRandomWeights, kNumRandomWeights) in addition to +// One(), and Zero() if zero is allowed. +template +class MinMaxWeightGenerator_ { + public: + typedef MinMaxWeightTpl Weight; + + MinMaxWeightGenerator_(int seed = time(0), bool allow_zero = true) + : allow_zero_(allow_zero) { + srand(seed); + } + + Weight operator() () const { + int n = (rand() % (2*kNumRandomWeights + allow_zero_)) - kNumRandomWeights; + if (allow_zero_ && n == kNumRandomWeights) + return Weight::Zero(); + else if (n == -kNumRandomWeights) + return Weight::One(); + + return Weight(static_cast(n)); + } + + private: + // Parameters controlling the number of alternative random weights. + static const int kNumRandomWeights = 5; + + bool allow_zero_; // permit Zero() and zero divisors +}; + +template const int MinMaxWeightGenerator_::kNumRandomWeights; + +typedef MinMaxWeightGenerator_ MinMaxWeightGenerator; + + +// This function object returns StringWeights that are random integer +// strings chosen from {1,...,kAlphabetSize}^{0,kMaxStringLength} U { Zero } +template +class StringWeightGenerator { + public: + typedef StringWeight Weight; + + StringWeightGenerator(int seed = time(0), bool allow_zero = true) + : allow_zero_(allow_zero) { + srand(seed); + } + + Weight operator() () const { + int n = rand() % (kMaxStringLength + allow_zero_); + if (allow_zero_ && n == kMaxStringLength) + return Weight::Zero(); + + vector v; + for (int i = 0; i < n; ++i) + v.push_back(rand() % kAlphabetSize + 1); + return Weight(v.begin(), v.end()); + } + + private: + // Alphabet size for random weights. + static const int kAlphabetSize = 5; + // Number of alternative random weights. + static const int kMaxStringLength = 5; + + bool allow_zero_; // permit Zero() and zero +}; + +template +const int StringWeightGenerator::kAlphabetSize; +template +const int StringWeightGenerator::kMaxStringLength; + + +// This function object returns a weight generator over the product of the +// weights (by default) for the generators G1 and G2. +template > +class ProductWeightGenerator { + public: + typedef typename G1::Weight W1; + typedef typename G2::Weight W2; + typedef W Weight; + + ProductWeightGenerator(int seed = time(0), bool allow_zero = true) + : generator1_(seed, allow_zero), generator2_(seed, allow_zero) {} + + Weight operator() () const { + W1 w1 = generator1_(); + W2 w2 = generator2_(); + return Weight(w1, w2); + } + + private: + G1 generator1_; + G2 generator2_; +}; + + +// This function object returns a weight generator for a lexicographic weight +// composed out of weights for the generators G1 and G2. For lexicographic +// weights, we cannot generate zeroes for the two subweights separately: +// weights are members iff both members are zero or both members are non-zero. +template +class LexicographicWeightGenerator { + public: + typedef typename G1::Weight W1; + typedef typename G2::Weight W2; + typedef LexicographicWeight Weight; + + LexicographicWeightGenerator(int seed = time(0), bool allow_zero = true) + : generator1_(seed, false), generator2_(seed, false), + allow_zero_(allow_zero) {} + + Weight operator() () const { + if (allow_zero_) { + int n = rand() % (kNumRandomWeights + allow_zero_); + if (n == kNumRandomWeights) + return Weight(W1::Zero(), W2::Zero()); + } + W1 w1 = generator1_(); + W2 w2 = generator2_(); + return Weight(w1, w2); + } + + private: + G1 generator1_; + G2 generator2_; + static const int kNumRandomWeights = 5; + bool allow_zero_; +}; + +template +const int LexicographicWeightGenerator::kNumRandomWeights; + + +// Product generator of a string weight generator and an +// arbitrary weight generator. +template +class GallicWeightGenerator + : public ProductWeightGenerator, G> { + + public: + typedef ProductWeightGenerator, G> PG; + typedef typename G::Weight W; + typedef GallicWeight Weight; + + GallicWeightGenerator(int seed = time(0), bool allow_zero = true) + : PG(seed, allow_zero) {} + + GallicWeightGenerator(const PG &pg) : PG(pg) {} +}; + +// This function object returms a weight generator over the catersian power +// of rank n of the weights for the generator G. +template +class PowerWeightGenerator { + public: + typedef typename G::Weight W; + typedef PowerWeight Weight; + + PowerWeightGenerator(int seed = time(0), bool allow_zero = true) + : generator_(seed, allow_zero) {} + + Weight operator()() const { + Weight w; + for (size_t i = 0; i < n; ++i) { + W r = generator_(); + w.SetValue(i, r); + } + return w; + } + + private: + G generator_; +}; + +// This function object returns SignedLogWeightTpl's that are +// random integers chosen from [0, kNumRandomWeights). +// The sign is randomly chosen as well. +template +class SignedLogWeightGenerator_ { + public: + typedef SignedLogWeightTpl Weight; + + SignedLogWeightGenerator_(int seed = time(0), bool allow_zero = true) + : allow_zero_(allow_zero) { + srand(seed); + } + + Weight operator() () const { + int m = rand() % 2; + int n = rand() % (kNumRandomWeights + allow_zero_); + + return SignedLogWeightTpl( + (m == 0) ? + TropicalWeight(-1.0) : + TropicalWeight(1.0), + (allow_zero_ && n == kNumRandomWeights) ? + LogWeightTpl::Zero() : + LogWeightTpl(static_cast(n))); + } + + private: + // Number of alternative random weights. + static const int kNumRandomWeights = 5; + bool allow_zero_; // permit Zero() and zero divisors +}; + +template const int SignedLogWeightGenerator_::kNumRandomWeights; + +typedef SignedLogWeightGenerator_ SignedLogWeightGenerator; + +// This function object returms a weight generator over the catersian power +// of rank n of the weights for the generator G. +template +class SparsePowerWeightGenerator { + public: + typedef typename G::Weight W; + typedef SparsePowerWeight Weight; + + SparsePowerWeightGenerator(int seed = time(0), bool allow_zero = true) + : generator_(seed, allow_zero) {} + + Weight operator()() const { + Weight w; + for (size_t i = 1; i <= n; ++i) { + W r = generator_(); + K p = i; + w.Push(p, r, true); + } + return w; + } + + private: + G generator_; +}; + +} // namespace fst + +#endif // FST_LIB_RANDOM_WEIGHT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/rational.h b/kaldi_io/src/tools/openfst/include/fst/rational.h new file mode 100644 index 0000000..96aa00d --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/rational.h @@ -0,0 +1,330 @@ +// rational.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// An Fst implementation and base interface for delayed unions, +// concatenations and closures. + +#ifndef FST_LIB_RATIONAL_H__ +#define FST_LIB_RATIONAL_H__ + +#include +#include +#include +using std::vector; + +#include +#include +#include + + +namespace fst { + +typedef CacheOptions RationalFstOptions; + +// This specifies whether to add the empty string. +enum ClosureType { CLOSURE_STAR = 0, // T* -> add the empty string + CLOSURE_PLUS = 1 }; // T+ -> don't add the empty string + +template class RationalFst; +template void Union(RationalFst *fst1, const Fst &fst2); +template void Concat(RationalFst *fst1, const Fst &fst2); +template void Concat(const Fst &fst1, RationalFst *fst2); +template void Closure(RationalFst *fst, ClosureType closure_type); + + +// Implementation class for delayed unions, concatenations and closures. +template +class RationalFstImpl : public FstImpl { + public: + using FstImpl::SetType; + using FstImpl::SetProperties; + using FstImpl::WriteHeader; + using FstImpl::SetInputSymbols; + using FstImpl::SetOutputSymbols; + + typedef A Arc; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + typedef typename A::Label Label; + + explicit RationalFstImpl(const RationalFstOptions &opts) + : nonterminals_(0), + replace_(0), + replace_options_(opts, 0) { + SetType("rational"); + fst_tuples_.push_back(pair*>(0, 0)); + } + + RationalFstImpl(const RationalFstImpl &impl) + : rfst_(impl.rfst_), + nonterminals_(impl.nonterminals_), + + replace_(impl.replace_ ? impl.replace_->Copy(true) : 0), + replace_options_(impl.replace_options_) { + SetType("rational"); + fst_tuples_.reserve(impl.fst_tuples_.size()); + for (size_t i = 0; i < impl.fst_tuples_.size(); ++i) + fst_tuples_.push_back(make_pair(impl.fst_tuples_[i].first, + impl.fst_tuples_[i].second + ? impl.fst_tuples_[i].second->Copy(true) + : 0)); + } + + virtual ~RationalFstImpl() { + for (size_t i = 0; i < fst_tuples_.size(); ++i) + if (fst_tuples_[i].second) + delete fst_tuples_[i].second; + if (replace_) + delete replace_; + } + + StateId Start() { return Replace()->Start(); } + + Weight Final(StateId s) { return Replace()->Final(s); } + + size_t NumArcs(StateId s) { return Replace()->NumArcs(s); } + + size_t NumInputEpsilons(StateId s) { + return Replace()->NumInputEpsilons(s); + } + + size_t NumOutputEpsilons(StateId s) { + return Replace()->NumOutputEpsilons(s); + } + + uint64 Properties() const { return Properties(kFstProperties); } + + // Set error if found; return FST impl properties. + uint64 Properties(uint64 mask) const { + if ((mask & kError) && Replace()->Properties(kError, false)) + SetProperties(kError, kError); + return FstImpl::Properties(mask); + } + + // Implementation of UnionFst(fst1,fst2) + void InitUnion(const Fst &fst1, const Fst &fst2) { + if (replace_) + delete replace_; + uint64 props1 = fst1.Properties(kFstProperties, false); + uint64 props2 = fst2.Properties(kFstProperties, false); + SetInputSymbols(fst1.InputSymbols()); + SetOutputSymbols(fst1.OutputSymbols()); + rfst_.AddState(); + rfst_.AddState(); + rfst_.SetStart(0); + rfst_.SetFinal(1, Weight::One()); + rfst_.SetInputSymbols(fst1.InputSymbols()); + rfst_.SetOutputSymbols(fst1.OutputSymbols()); + nonterminals_ = 2; + rfst_.AddArc(0, A(0, -1, Weight::One(), 1)); + rfst_.AddArc(0, A(0, -2, Weight::One(), 1)); + fst_tuples_.push_back(make_pair(-1, fst1.Copy())); + fst_tuples_.push_back(make_pair(-2, fst2.Copy())); + SetProperties(UnionProperties(props1, props2, true), kCopyProperties); + } + + // Implementation of ConcatFst(fst1,fst2) + void InitConcat(const Fst &fst1, const Fst &fst2) { + if (replace_) + delete replace_; + uint64 props1 = fst1.Properties(kFstProperties, false); + uint64 props2 = fst2.Properties(kFstProperties, false); + SetInputSymbols(fst1.InputSymbols()); + SetOutputSymbols(fst1.OutputSymbols()); + rfst_.AddState(); + rfst_.AddState(); + rfst_.AddState(); + rfst_.SetStart(0); + rfst_.SetFinal(2, Weight::One()); + rfst_.SetInputSymbols(fst1.InputSymbols()); + rfst_.SetOutputSymbols(fst1.OutputSymbols()); + nonterminals_ = 2; + rfst_.AddArc(0, A(0, -1, Weight::One(), 1)); + rfst_.AddArc(1, A(0, -2, Weight::One(), 2)); + fst_tuples_.push_back(make_pair(-1, fst1.Copy())); + fst_tuples_.push_back(make_pair(-2, fst2.Copy())); + SetProperties(ConcatProperties(props1, props2, true), kCopyProperties); + } + + // Implementation of ClosureFst(fst, closure_type) + void InitClosure(const Fst &fst, ClosureType closure_type) { + if (replace_) + delete replace_; + uint64 props = fst.Properties(kFstProperties, false); + SetInputSymbols(fst.InputSymbols()); + SetOutputSymbols(fst.OutputSymbols()); + if (closure_type == CLOSURE_STAR) { + rfst_.AddState(); + rfst_.SetStart(0); + rfst_.SetFinal(0, Weight::One()); + rfst_.AddArc(0, A(0, -1, Weight::One(), 0)); + } else { + rfst_.AddState(); + rfst_.AddState(); + rfst_.SetStart(0); + rfst_.SetFinal(1, Weight::One()); + rfst_.AddArc(0, A(0, -1, Weight::One(), 1)); + rfst_.AddArc(1, A(0, 0, Weight::One(), 0)); + } + rfst_.SetInputSymbols(fst.InputSymbols()); + rfst_.SetOutputSymbols(fst.OutputSymbols()); + fst_tuples_.push_back(make_pair(-1, fst.Copy())); + nonterminals_ = 1; + SetProperties(ClosureProperties(props, closure_type == CLOSURE_STAR, true), + kCopyProperties); + } + + // Implementation of Union(Fst &, RationalFst *) + void AddUnion(const Fst &fst) { + if (replace_) + delete replace_; + uint64 props1 = FstImpl::Properties(); + uint64 props2 = fst.Properties(kFstProperties, false); + VectorFst afst; + afst.AddState(); + afst.AddState(); + afst.SetStart(0); + afst.SetFinal(1, Weight::One()); + ++nonterminals_; + afst.AddArc(0, A(0, -nonterminals_, Weight::One(), 1)); + Union(&rfst_, afst); + fst_tuples_.push_back(make_pair(-nonterminals_, fst.Copy())); + SetProperties(UnionProperties(props1, props2, true), kCopyProperties); + } + + // Implementation of Concat(Fst &, RationalFst *) + void AddConcat(const Fst &fst, bool append) { + if (replace_) + delete replace_; + uint64 props1 = FstImpl::Properties(); + uint64 props2 = fst.Properties(kFstProperties, false); + VectorFst afst; + afst.AddState(); + afst.AddState(); + afst.SetStart(0); + afst.SetFinal(1, Weight::One()); + ++nonterminals_; + afst.AddArc(0, A(0, -nonterminals_, Weight::One(), 1)); + if (append) + Concat(&rfst_, afst); + else + Concat(afst, &rfst_); + fst_tuples_.push_back(make_pair(-nonterminals_, fst.Copy())); + SetProperties(ConcatProperties(props1, props2, true), kCopyProperties); + } + + // Implementation of Closure(RationalFst *, closure_type) + void AddClosure(ClosureType closure_type) { + if (replace_) + delete replace_; + uint64 props = FstImpl::Properties(); + Closure(&rfst_, closure_type); + SetProperties(ClosureProperties(props, closure_type == CLOSURE_STAR, true), + kCopyProperties); + } + + // Returns the underlying ReplaceFst. + ReplaceFst *Replace() const { + if (!replace_) { + fst_tuples_[0].second = rfst_.Copy(); + replace_ = new ReplaceFst(fst_tuples_, replace_options_); + } + return replace_; + } + + private: + VectorFst rfst_; // rational topology machine; uses neg. nonterminals + Label nonterminals_; // # of nonterminals used + // Contains the nonterminals and their corresponding FSTs. + mutable vector*> > fst_tuples_; + mutable ReplaceFst *replace_; // Underlying ReplaceFst + ReplaceFstOptions replace_options_; // Options for creating 'replace_' + + void operator=(const RationalFstImpl &impl); // disallow +}; + +// Parent class for the delayed rational operations - delayed union, +// concatenation, and closure. +// +// This class attaches interface to implementation and handles +// reference counting, delegating most methods to ImplToFst. +template +class RationalFst : public ImplToFst< RationalFstImpl > { + public: + friend class StateIterator< RationalFst >; + friend class ArcIterator< RationalFst >; + friend void Union<>(RationalFst *fst1, const Fst &fst2); + friend void Concat<>(RationalFst *fst1, const Fst &fst2); + friend void Concat<>(const Fst &fst1, RationalFst *fst2); + friend void Closure<>(RationalFst *fst, ClosureType closure_type); + + typedef A Arc; + typedef typename A::StateId StateId; + typedef RationalFstImpl Impl; + + virtual void InitStateIterator(StateIteratorData *data) const { + GetImpl()->Replace()->InitStateIterator(data); + } + + virtual void InitArcIterator(StateId s, ArcIteratorData *data) const { + GetImpl()->Replace()->InitArcIterator(s, data); + } + + protected: + RationalFst() + : ImplToFst(new Impl(RationalFstOptions())) {} + + explicit RationalFst(const RationalFstOptions &opts) + : ImplToFst(new Impl(opts)) {} + + // See Fst<>::Copy() for doc. + RationalFst(const RationalFst &fst , bool safe = false) + : ImplToFst(fst, safe) {} + + private: + // Makes visible to friends. + Impl *GetImpl() const { return ImplToFst::GetImpl(); } + + void operator=(const RationalFst &fst); // disallow +}; + + +// Specialization for RationalFst. +template +class StateIterator< RationalFst > + : public StateIterator< ReplaceFst > { + public: + explicit StateIterator(const RationalFst &fst) + : StateIterator< ReplaceFst >(*(fst.GetImpl()->Replace())) {} +}; + + +// Specialization for RationalFst. +template +class ArcIterator< RationalFst > + : public CacheArcIterator< ReplaceFst > { + public: + typedef typename A::StateId StateId; + + ArcIterator(const RationalFst &fst, StateId s) + : ArcIterator< ReplaceFst >(*(fst.GetImpl()->Replace()), s) {} +}; + +} // namespace fst + +#endif // FST_LIB_RATIONAL_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/register.h b/kaldi_io/src/tools/openfst/include/fst/register.h new file mode 100644 index 0000000..ea3f4d8 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/register.h @@ -0,0 +1,133 @@ +// register.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley), jpr@google.com (Jake Ratkiewicz) +// +// \file +// Classes for registering derived Fsts for generic reading +// + +#ifndef FST_LIB_REGISTER_H__ +#define FST_LIB_REGISTER_H__ + +#include + + +#include +#include +#include +#include +#include +#include + + +#include + +namespace fst { + +template class Fst; +struct FstReadOptions; + +// This class represents a single entry in a FstRegister +template +struct FstRegisterEntry { + typedef Fst *(*Reader)(istream &strm, const FstReadOptions &opts); + typedef Fst *(*Converter)(const Fst &fst); + + Reader reader; + Converter converter; + FstRegisterEntry() : reader(0), converter(0) {} + FstRegisterEntry(Reader r, Converter c) : reader(r), converter(c) { } +}; + +// This class maintains the correspondence between a string describing +// an FST type, and its reader and converter. +template +class FstRegister : public GenericRegister, + FstRegister > { + public: + typedef typename FstRegisterEntry::Reader Reader; + typedef typename FstRegisterEntry::Converter Converter; + + const Reader GetReader(const string &type) const { + return this->GetEntry(type).reader; + } + + const Converter GetConverter(const string &type) const { + return this->GetEntry(type).converter; + } + + protected: + virtual string ConvertKeyToSoFilename(const string& key) const { + string legal_type(key); + + ConvertToLegalCSymbol(&legal_type); + + return legal_type + "-fst.so"; + } +}; + + +// This class registers an Fst type for generic reading and creating. +// The Fst type must have a default constructor and a copy constructor +// from 'Fst' for this to work. +template +class FstRegisterer + : public GenericRegisterer > { + public: + typedef typename F::Arc Arc; + typedef typename FstRegister::Entry Entry; + typedef typename FstRegister::Reader Reader; + + FstRegisterer() : + GenericRegisterer >( + F().Type(), BuildEntry()) { } + + private: + Entry BuildEntry() { + F *(*reader)(istream &strm, + const FstReadOptions &opts) = &F::Read; + + return Entry(reinterpret_cast(reader), + &FstRegisterer::Convert); + } + + static Fst *Convert(const Fst &fst) { return new F(fst); } +}; + + +// Convenience macro to generate static FstRegisterer instance. +#define REGISTER_FST(F, A) \ +static fst::FstRegisterer< F > F ## _ ## A ## _registerer + + +// Converts an fst to type 'type'. +template +Fst *Convert(const Fst &fst, const string &ftype) { + FstRegister *registr = FstRegister::GetRegister(); + const typename FstRegister::Converter + converter = registr->GetConverter(ftype); + if (!converter) { + string atype = A::Type(); + LOG(ERROR) << "Fst::Convert: Unknown FST type \"" << ftype + << "\" (arc type = \"" << atype << "\")"; + return 0; + } + return converter(fst); +} + +} // namespace fst + +#endif // FST_LIB_REGISTER_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/relabel.h b/kaldi_io/src/tools/openfst/include/fst/relabel.h new file mode 100644 index 0000000..dc675b6 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/relabel.h @@ -0,0 +1,528 @@ +// relabel.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: johans@google.com (Johan Schalkwyk) +// +// \file +// Functions and classes to relabel an Fst (either on input or output) +// +#ifndef FST_LIB_RELABEL_H__ +#define FST_LIB_RELABEL_H__ + +#include +using std::tr1::unordered_map; +using std::tr1::unordered_multimap; +#include +#include +using std::pair; using std::make_pair; +#include +using std::vector; + +#include +#include + + +#include +using std::tr1::unordered_map; +using std::tr1::unordered_multimap; + +namespace fst { + +// +// Relabels either the input labels or output labels. The old to +// new labels are specified using a vector of pair. +// Any label associations not specified are assumed to be identity +// mapping. +// +// \param fst input fst, must be mutable +// \param ipairs vector of input label pairs indicating old to new mapping +// \param opairs vector of output label pairs indicating old to new mapping +// +template +void Relabel( + MutableFst *fst, + const vector >& ipairs, + const vector >& opairs) { + typedef typename A::StateId StateId; + typedef typename A::Label Label; + + uint64 props = fst->Properties(kFstProperties, false); + + // construct label to label hash. + unordered_map input_map; + for (size_t i = 0; i < ipairs.size(); ++i) { + input_map[ipairs[i].first] = ipairs[i].second; + } + + unordered_map output_map; + for (size_t i = 0; i < opairs.size(); ++i) { + output_map[opairs[i].first] = opairs[i].second; + } + + for (StateIterator > siter(*fst); + !siter.Done(); siter.Next()) { + StateId s = siter.Value(); + for (MutableArcIterator > aiter(fst, s); + !aiter.Done(); aiter.Next()) { + A arc = aiter.Value(); + + // relabel input + // only relabel if relabel pair defined + typename unordered_map::iterator it = + input_map.find(arc.ilabel); + if (it != input_map.end()) { + if (it->second == kNoLabel) { + FSTERROR() << "Input symbol id " << arc.ilabel + << " missing from target vocabulary"; + fst->SetProperties(kError, kError); + return; + } + arc.ilabel = it->second; + } + + // relabel output + it = output_map.find(arc.olabel); + if (it != output_map.end()) { + if (it->second == kNoLabel) { + FSTERROR() << "Output symbol id " << arc.olabel + << " missing from target vocabulary"; + fst->SetProperties(kError, kError); + return; + } + arc.olabel = it->second; + } + + aiter.SetValue(arc); + } + } + + fst->SetProperties(RelabelProperties(props), kFstProperties); +} + +// +// Relabels either the input labels or output labels. The old to +// new labels mappings are specified using an input Symbol set. +// Any label associations not specified are assumed to be identity +// mapping. +// +// \param fst input fst, must be mutable +// \param new_isymbols symbol set indicating new mapping of input symbols +// \param new_osymbols symbol set indicating new mapping of output symbols +// +template +void Relabel(MutableFst *fst, + const SymbolTable* new_isymbols, + const SymbolTable* new_osymbols) { + Relabel(fst, + fst->InputSymbols(), new_isymbols, true, + fst->OutputSymbols(), new_osymbols, true); +} + +template +void Relabel(MutableFst *fst, + const SymbolTable* old_isymbols, + const SymbolTable* new_isymbols, + bool attach_new_isymbols, + const SymbolTable* old_osymbols, + const SymbolTable* new_osymbols, + bool attach_new_osymbols) { + typedef typename A::StateId StateId; + typedef typename A::Label Label; + + vector > ipairs; + if (old_isymbols && new_isymbols) { + for (SymbolTableIterator syms_iter(*old_isymbols); !syms_iter.Done(); + syms_iter.Next()) { + string isymbol = syms_iter.Symbol(); + int isymbol_val = syms_iter.Value(); + int new_isymbol_val = new_isymbols->Find(isymbol); + ipairs.push_back(make_pair(isymbol_val, new_isymbol_val)); + } + if (attach_new_isymbols) + fst->SetInputSymbols(new_isymbols); + } + + vector > opairs; + if (old_osymbols && new_osymbols) { + for (SymbolTableIterator syms_iter(*old_osymbols); !syms_iter.Done(); + syms_iter.Next()) { + string osymbol = syms_iter.Symbol(); + int osymbol_val = syms_iter.Value(); + int new_osymbol_val = new_osymbols->Find(osymbol); + opairs.push_back(make_pair(osymbol_val, new_osymbol_val)); + } + if (attach_new_osymbols) + fst->SetOutputSymbols(new_osymbols); + } + + // call relabel using vector of relabel pairs. + Relabel(fst, ipairs, opairs); +} + + +typedef CacheOptions RelabelFstOptions; + +template class RelabelFst; + +// +// \class RelabelFstImpl +// \brief Implementation for delayed relabeling +// +// Relabels an FST from one symbol set to another. Relabeling +// can either be on input or output space. RelabelFst implements +// a delayed version of the relabel. Arcs are relabeled on the fly +// and not cached. I.e each request is recomputed. +// +template +class RelabelFstImpl : public CacheImpl { + friend class StateIterator< RelabelFst >; + public: + using FstImpl::SetType; + using FstImpl::SetProperties; + using FstImpl::WriteHeader; + using FstImpl::SetInputSymbols; + using FstImpl::SetOutputSymbols; + + using CacheImpl::PushArc; + using CacheImpl::HasArcs; + using CacheImpl::HasFinal; + using CacheImpl::HasStart; + using CacheImpl::SetArcs; + using CacheImpl::SetFinal; + using CacheImpl::SetStart; + + typedef A Arc; + typedef typename A::Label Label; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + typedef CacheState State; + + RelabelFstImpl(const Fst& fst, + const vector >& ipairs, + const vector >& opairs, + const RelabelFstOptions &opts) + : CacheImpl(opts), fst_(fst.Copy()), + relabel_input_(false), relabel_output_(false) { + uint64 props = fst.Properties(kCopyProperties, false); + SetProperties(RelabelProperties(props)); + SetType("relabel"); + + // create input label map + if (ipairs.size() > 0) { + for (size_t i = 0; i < ipairs.size(); ++i) { + input_map_[ipairs[i].first] = ipairs[i].second; + } + relabel_input_ = true; + } + + // create output label map + if (opairs.size() > 0) { + for (size_t i = 0; i < opairs.size(); ++i) { + output_map_[opairs[i].first] = opairs[i].second; + } + relabel_output_ = true; + } + } + + RelabelFstImpl(const Fst& fst, + const SymbolTable* old_isymbols, + const SymbolTable* new_isymbols, + const SymbolTable* old_osymbols, + const SymbolTable* new_osymbols, + const RelabelFstOptions &opts) + : CacheImpl(opts), fst_(fst.Copy()), + relabel_input_(false), relabel_output_(false) { + SetType("relabel"); + + uint64 props = fst.Properties(kCopyProperties, false); + SetProperties(RelabelProperties(props)); + SetInputSymbols(old_isymbols); + SetOutputSymbols(old_osymbols); + + if (old_isymbols && new_isymbols && + old_isymbols->LabeledCheckSum() != new_isymbols->LabeledCheckSum()) { + for (SymbolTableIterator syms_iter(*old_isymbols); !syms_iter.Done(); + syms_iter.Next()) { + input_map_[syms_iter.Value()] = new_isymbols->Find(syms_iter.Symbol()); + } + SetInputSymbols(new_isymbols); + relabel_input_ = true; + } + + if (old_osymbols && new_osymbols && + old_osymbols->LabeledCheckSum() != new_osymbols->LabeledCheckSum()) { + for (SymbolTableIterator syms_iter(*old_osymbols); !syms_iter.Done(); + syms_iter.Next()) { + output_map_[syms_iter.Value()] = + new_osymbols->Find(syms_iter.Symbol()); + } + SetOutputSymbols(new_osymbols); + relabel_output_ = true; + } + } + + RelabelFstImpl(const RelabelFstImpl& impl) + : CacheImpl(impl), + fst_(impl.fst_->Copy(true)), + input_map_(impl.input_map_), + output_map_(impl.output_map_), + relabel_input_(impl.relabel_input_), + relabel_output_(impl.relabel_output_) { + SetType("relabel"); + SetProperties(impl.Properties(), kCopyProperties); + SetInputSymbols(impl.InputSymbols()); + SetOutputSymbols(impl.OutputSymbols()); + } + + ~RelabelFstImpl() { delete fst_; } + + StateId Start() { + if (!HasStart()) { + StateId s = fst_->Start(); + SetStart(s); + } + return CacheImpl::Start(); + } + + Weight Final(StateId s) { + if (!HasFinal(s)) { + SetFinal(s, fst_->Final(s)); + } + return CacheImpl::Final(s); + } + + size_t NumArcs(StateId s) { + if (!HasArcs(s)) { + Expand(s); + } + return CacheImpl::NumArcs(s); + } + + size_t NumInputEpsilons(StateId s) { + if (!HasArcs(s)) { + Expand(s); + } + return CacheImpl::NumInputEpsilons(s); + } + + size_t NumOutputEpsilons(StateId s) { + if (!HasArcs(s)) { + Expand(s); + } + return CacheImpl::NumOutputEpsilons(s); + } + + uint64 Properties() const { return Properties(kFstProperties); } + + // Set error if found; return FST impl properties. + uint64 Properties(uint64 mask) const { + if ((mask & kError) && fst_->Properties(kError, false)) + SetProperties(kError, kError); + return FstImpl::Properties(mask); + } + + void InitArcIterator(StateId s, ArcIteratorData* data) { + if (!HasArcs(s)) { + Expand(s); + } + CacheImpl::InitArcIterator(s, data); + } + + void Expand(StateId s) { + for (ArcIterator > aiter(*fst_, s); !aiter.Done(); aiter.Next()) { + A arc = aiter.Value(); + + // relabel input + if (relabel_input_) { + typename unordered_map::iterator it = + input_map_.find(arc.ilabel); + if (it != input_map_.end()) { arc.ilabel = it->second; } + } + + // relabel output + if (relabel_output_) { + typename unordered_map::iterator it = + output_map_.find(arc.olabel); + if (it != output_map_.end()) { arc.olabel = it->second; } + } + + PushArc(s, arc); + } + SetArcs(s); + } + + + private: + const Fst *fst_; + + unordered_map input_map_; + unordered_map output_map_; + bool relabel_input_; + bool relabel_output_; + + void operator=(const RelabelFstImpl &); // disallow +}; + + +// +// \class RelabelFst +// \brief Delayed implementation of arc relabeling +// +// This class attaches interface to implementation and handles +// reference counting, delegating most methods to ImplToFst. +template +class RelabelFst : public ImplToFst< RelabelFstImpl > { + public: + friend class ArcIterator< RelabelFst >; + friend class StateIterator< RelabelFst >; + + typedef A Arc; + typedef typename A::Label Label; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + typedef CacheState State; + typedef RelabelFstImpl Impl; + + RelabelFst(const Fst& fst, + const vector >& ipairs, + const vector >& opairs) + : ImplToFst(new Impl(fst, ipairs, opairs, RelabelFstOptions())) {} + + RelabelFst(const Fst& fst, + const vector >& ipairs, + const vector >& opairs, + const RelabelFstOptions &opts) + : ImplToFst(new Impl(fst, ipairs, opairs, opts)) {} + + RelabelFst(const Fst& fst, + const SymbolTable* new_isymbols, + const SymbolTable* new_osymbols) + : ImplToFst(new Impl(fst, fst.InputSymbols(), new_isymbols, + fst.OutputSymbols(), new_osymbols, + RelabelFstOptions())) {} + + RelabelFst(const Fst& fst, + const SymbolTable* new_isymbols, + const SymbolTable* new_osymbols, + const RelabelFstOptions &opts) + : ImplToFst(new Impl(fst, fst.InputSymbols(), new_isymbols, + fst.OutputSymbols(), new_osymbols, opts)) {} + + RelabelFst(const Fst& fst, + const SymbolTable* old_isymbols, + const SymbolTable* new_isymbols, + const SymbolTable* old_osymbols, + const SymbolTable* new_osymbols) + : ImplToFst(new Impl(fst, old_isymbols, new_isymbols, old_osymbols, + new_osymbols, RelabelFstOptions())) {} + + RelabelFst(const Fst& fst, + const SymbolTable* old_isymbols, + const SymbolTable* new_isymbols, + const SymbolTable* old_osymbols, + const SymbolTable* new_osymbols, + const RelabelFstOptions &opts) + : ImplToFst(new Impl(fst, old_isymbols, new_isymbols, old_osymbols, + new_osymbols, opts)) {} + + // See Fst<>::Copy() for doc. + RelabelFst(const RelabelFst &fst, bool safe = false) + : ImplToFst(fst, safe) {} + + // Get a copy of this RelabelFst. See Fst<>::Copy() for further doc. + virtual RelabelFst *Copy(bool safe = false) const { + return new RelabelFst(*this, safe); + } + + virtual void InitStateIterator(StateIteratorData *data) const; + + virtual void InitArcIterator(StateId s, ArcIteratorData *data) const { + return GetImpl()->InitArcIterator(s, data); + } + + private: + // Makes visible to friends. + Impl *GetImpl() const { return ImplToFst::GetImpl(); } + + void operator=(const RelabelFst &fst); // disallow +}; + +// Specialization for RelabelFst. +template +class StateIterator< RelabelFst > : public StateIteratorBase { + public: + typedef typename A::StateId StateId; + + explicit StateIterator(const RelabelFst &fst) + : impl_(fst.GetImpl()), siter_(*impl_->fst_), s_(0) {} + + bool Done() const { return siter_.Done(); } + + StateId Value() const { return s_; } + + void Next() { + if (!siter_.Done()) { + ++s_; + siter_.Next(); + } + } + + void Reset() { + s_ = 0; + siter_.Reset(); + } + + private: + bool Done_() const { return Done(); } + StateId Value_() const { return Value(); } + void Next_() { Next(); } + void Reset_() { Reset(); } + + const RelabelFstImpl *impl_; + StateIterator< Fst > siter_; + StateId s_; + + DISALLOW_COPY_AND_ASSIGN(StateIterator); +}; + + +// Specialization for RelabelFst. +template +class ArcIterator< RelabelFst > + : public CacheArcIterator< RelabelFst > { + public: + typedef typename A::StateId StateId; + + ArcIterator(const RelabelFst &fst, StateId s) + : CacheArcIterator< RelabelFst >(fst.GetImpl(), s) { + if (!fst.GetImpl()->HasArcs(s)) + fst.GetImpl()->Expand(s); + } + + private: + DISALLOW_COPY_AND_ASSIGN(ArcIterator); +}; + +template inline +void RelabelFst::InitStateIterator(StateIteratorData *data) const { + data->base = new StateIterator< RelabelFst >(*this); +} + +// Useful alias when using StdArc. +typedef RelabelFst StdRelabelFst; + +} // namespace fst + +#endif // FST_LIB_RELABEL_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/replace-util.h b/kaldi_io/src/tools/openfst/include/fst/replace-util.h new file mode 100644 index 0000000..d58cb15 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/replace-util.h @@ -0,0 +1,550 @@ +// replace-util.h + + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// + +// \file +// Utility classes for the recursive replacement of Fsts (RTNs). + +#ifndef FST_LIB_REPLACE_UTIL_H__ +#define FST_LIB_REPLACE_UTIL_H__ + +#include +using std::vector; +#include +using std::tr1::unordered_map; +using std::tr1::unordered_multimap; +#include +using std::tr1::unordered_set; +using std::tr1::unordered_multiset; +#include + +#include +#include +#include + + +namespace fst { + +template +void Replace(const vector* > >&, + MutableFst *, typename Arc::Label, bool); + + +// Utility class for the recursive replacement of Fsts (RTNs). The +// user provides a set of Label, Fst pairs at construction. These are +// used by methods for testing cyclic dependencies and connectedness +// and doing RTN connection and specific Fst replacement by label or +// for various optimization properties. The modified results can be +// obtained with the GetFstPairs() or GetMutableFstPairs() methods. +template +class ReplaceUtil { + public: + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + typedef typename Arc::StateId StateId; + + typedef pair*> FstPair; + typedef pair*> MutableFstPair; + typedef unordered_map NonTerminalHash; + + // Constructs from mutable Fsts; Fst ownership given to ReplaceUtil. + ReplaceUtil(const vector &fst_pairs, + Label root_label, bool epsilon_on_replace = false); + + // Constructs from Fsts; Fst ownership retained by caller. + ReplaceUtil(const vector &fst_pairs, + Label root_label, bool epsilon_on_replace = false); + + // Constructs from ReplaceFst internals; ownership retained by caller. + ReplaceUtil(const vector *> &fst_array, + const NonTerminalHash &nonterminal_hash, Label root_fst, + bool epsilon_on_replace = false); + + ~ReplaceUtil() { + for (Label i = 0; i < fst_array_.size(); ++i) + delete fst_array_[i]; + } + + // True if the non-terminal dependencies are cyclic. Cyclic + // dependencies will result in an unexpandable replace fst. + bool CyclicDependencies() const { + GetDependencies(false); + return depprops_ & kCyclic; + } + + // Returns true if no useless Fsts, states or transitions. + bool Connected() const { + GetDependencies(false); + uint64 props = kAccessible | kCoAccessible; + for (Label i = 0; i < fst_array_.size(); ++i) { + if (!fst_array_[i]) + continue; + if (fst_array_[i]->Properties(props, true) != props || !depaccess_[i]) + return false; + } + return true; + } + + // Removes useless Fsts, states and transitions. + void Connect(); + + // Replaces Fsts specified by labels. + // Does nothing if there are cyclic dependencies. + void ReplaceLabels(const vector { + friend class ReplaceFstMatcher; + + public: + using FstImpl::SetType; + using FstImpl::SetProperties; + using FstImpl::WriteHeader; + using FstImpl::SetInputSymbols; + using FstImpl::SetOutputSymbols; + using FstImpl::InputSymbols; + using FstImpl::OutputSymbols; + + using CacheImpl::PushArc; + using CacheImpl::HasArcs; + using CacheImpl::HasFinal; + using CacheImpl::HasStart; + using CacheImpl::SetArcs; + using CacheImpl::SetFinal; + using CacheImpl::SetStart; + + typedef typename A::Label Label; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + typedef CacheState State; + typedef A Arc; + typedef unordered_map NonTerminalHash; + + typedef T StateTable; + typedef typename T::PrefixId PrefixId; + typedef ReplaceStateTuple StateTuple; + + // constructor for replace class implementation. + // \param fst_tuples array of label/fst tuples, one for each non-terminal + ReplaceFstImpl(const vector< pair* > >& fst_tuples, + const ReplaceFstOptions &opts) + : CacheImpl(opts), + epsilon_on_replace_(opts.epsilon_on_replace), + state_table_(opts.state_table ? opts.state_table : + new StateTable(fst_tuples, opts.root)) { + + SetType("replace"); + + if (fst_tuples.size() > 0) { + SetInputSymbols(fst_tuples[0].second->InputSymbols()); + SetOutputSymbols(fst_tuples[0].second->OutputSymbols()); + } + + bool all_negative = true; // all nonterminals are negative? + bool dense_range = true; // all nonterminals are positive + // and form a dense range containing 1? + for (size_t i = 0; i < fst_tuples.size(); ++i) { + Label nonterminal = fst_tuples[i].first; + if (nonterminal >= 0) + all_negative = false; + if (nonterminal > fst_tuples.size() || nonterminal <= 0) + dense_range = false; + } + + vector inprops; + bool all_ilabel_sorted = true; + bool all_olabel_sorted = true; + bool all_non_empty = true; + fst_array_.push_back(0); + for (size_t i = 0; i < fst_tuples.size(); ++i) { + Label label = fst_tuples[i].first; + const Fst *fst = fst_tuples[i].second; + nonterminal_hash_[label] = fst_array_.size(); + nonterminal_set_.insert(label); + fst_array_.push_back(opts.take_ownership ? fst : fst->Copy()); + if (fst->Start() == kNoStateId) + all_non_empty = false; + if(!fst->Properties(kILabelSorted, false)) + all_ilabel_sorted = false; + if(!fst->Properties(kOLabelSorted, false)) + all_olabel_sorted = false; + inprops.push_back(fst->Properties(kCopyProperties, false)); + if (i) { + if (!CompatSymbols(InputSymbols(), fst->InputSymbols())) { + FSTERROR() << "ReplaceFstImpl: input symbols of Fst " << i + << " does not match input symbols of base Fst (0'th fst)"; + SetProperties(kError, kError); + } + if (!CompatSymbols(OutputSymbols(), fst->OutputSymbols())) { + FSTERROR() << "ReplaceFstImpl: output symbols of Fst " << i + << " does not match output symbols of base Fst " + << "(0'th fst)"; + SetProperties(kError, kError); + } + } + } + Label nonterminal = nonterminal_hash_[opts.root]; + if ((nonterminal == 0) && (fst_array_.size() > 1)) { + FSTERROR() << "ReplaceFstImpl: no Fst corresponding to root label '" + << opts.root << "' in the input tuple vector"; + SetProperties(kError, kError); + } + root_ = (nonterminal > 0) ? nonterminal : 1; + + SetProperties(ReplaceProperties(inprops, root_ - 1, epsilon_on_replace_, + all_non_empty)); + // We assume that all terminals are positive. The resulting + // ReplaceFst is known to be kILabelSorted when all sub-FSTs are + // kILabelSorted and one of the 3 following conditions is satisfied: + // 1. 'epsilon_on_replace' is false, or + // 2. all non-terminals are negative, or + // 3. all non-terninals are positive and form a dense range containing 1. + if (all_ilabel_sorted && + (!epsilon_on_replace_ || all_negative || dense_range)) + SetProperties(kILabelSorted, kILabelSorted); + // Similarly, the resulting ReplaceFst is known to be + // kOLabelSorted when all sub-FSTs are kOLabelSorted and one of + // the 2 following conditions is satisfied: + // 1. all non-terminals are negative, or + // 2. all non-terninals are positive and form a dense range containing 1. + if (all_olabel_sorted && (all_negative || dense_range)) + SetProperties(kOLabelSorted, kOLabelSorted); + + // Enable optional caching as long as sorted and all non empty. + if (Properties(kILabelSorted | kOLabelSorted) && all_non_empty) + always_cache_ = false; + else + always_cache_ = true; + VLOG(2) << "ReplaceFstImpl::ReplaceFstImpl: always_cache = " + << (always_cache_ ? "true" : "false"); + } + + ReplaceFstImpl(const ReplaceFstImpl& impl) + : CacheImpl(impl), + epsilon_on_replace_(impl.epsilon_on_replace_), + always_cache_(impl.always_cache_), + state_table_(new StateTable(*(impl.state_table_))), + nonterminal_set_(impl.nonterminal_set_), + nonterminal_hash_(impl.nonterminal_hash_), + root_(impl.root_) { + SetType("replace"); + SetProperties(impl.Properties(), kCopyProperties); + SetInputSymbols(impl.InputSymbols()); + SetOutputSymbols(impl.OutputSymbols()); + fst_array_.reserve(impl.fst_array_.size()); + fst_array_.push_back(0); + for (size_t i = 1; i < impl.fst_array_.size(); ++i) { + fst_array_.push_back(impl.fst_array_[i]->Copy(true)); + } + } + + ~ReplaceFstImpl() { + VLOG(2) << "~ReplaceFstImpl: gc = " + << (CacheImpl::GetCacheGc() ? "true" : "false") + << ", gc_size = " << CacheImpl::GetCacheSize() + << ", gc_limit = " << CacheImpl::GetCacheLimit(); + + delete state_table_; + for (size_t i = 1; i < fst_array_.size(); ++i) { + delete fst_array_[i]; + } + } + + // Computes the dependency graph of the replace class and returns + // true if the dependencies are cyclic. Cyclic dependencies will result + // in an un-expandable replace fst. + bool CyclicDependencies() const { + ReplaceUtil replace_util(fst_array_, nonterminal_hash_, root_); + return replace_util.CyclicDependencies(); + } + + // Return or compute start state of replace fst + StateId Start() { + if (!HasStart()) { + if (fst_array_.size() == 1) { // no fsts defined for replace + SetStart(kNoStateId); + return kNoStateId; + } else { + const Fst* fst = fst_array_[root_]; + StateId fst_start = fst->Start(); + if (fst_start == kNoStateId) // root Fst is empty + return kNoStateId; + + PrefixId prefix = GetPrefixId(StackPrefix()); + StateId start = state_table_->FindState( + StateTuple(prefix, root_, fst_start)); + SetStart(start); + return start; + } + } else { + return CacheImpl::Start(); + } + } + + // return final weight of state (kInfWeight means state is not final) + Weight Final(StateId s) { + if (!HasFinal(s)) { + const StateTuple& tuple = state_table_->Tuple(s); + const StackPrefix& stack = stackprefix_array_[tuple.prefix_id]; + const Fst* fst = fst_array_[tuple.fst_id]; + StateId fst_state = tuple.fst_state; + + if (fst->Final(fst_state) != Weight::Zero() && stack.Depth() == 0) + SetFinal(s, fst->Final(fst_state)); + else + SetFinal(s, Weight::Zero()); + } + return CacheImpl::Final(s); + } + + size_t NumArcs(StateId s) { + if (HasArcs(s)) { // If state cached, use the cached value. + return CacheImpl::NumArcs(s); + } else if (always_cache_) { // If always caching, expand and cache state. + Expand(s); + return CacheImpl::NumArcs(s); + } else { // Otherwise compute the number of arcs without expanding. + StateTuple tuple = state_table_->Tuple(s); + if (tuple.fst_state == kNoStateId) + return 0; + + const Fst* fst = fst_array_[tuple.fst_id]; + size_t num_arcs = fst->NumArcs(tuple.fst_state); + if (ComputeFinalArc(tuple, 0)) + num_arcs++; + + return num_arcs; + } + } + + // Returns whether a given label is a non terminal + bool IsNonTerminal(Label l) const { + // TODO(allauzen): be smarter and take advantage of + // all_dense or all_negative. + // Use also in ComputeArc, this would require changes to replace + // so that recursing into an empty fst lead to a non co-accessible + // state instead of deleting the arc as done currently. + // Current use correct, since i/olabel sorted iff all_non_empty. + typename NonTerminalHash::const_iterator it = + nonterminal_hash_.find(l); + return it != nonterminal_hash_.end(); + } + + size_t NumInputEpsilons(StateId s) { + if (HasArcs(s)) { + // If state cached, use the cached value. + return CacheImpl::NumInputEpsilons(s); + } else if (always_cache_ || !Properties(kILabelSorted)) { + // If always caching or if the number of input epsilons is too expensive + // to compute without caching (i.e. not ilabel sorted), + // then expand and cache state. + Expand(s); + return CacheImpl::NumInputEpsilons(s); + } else { + // Otherwise, compute the number of input epsilons without caching. + StateTuple tuple = state_table_->Tuple(s); + if (tuple.fst_state == kNoStateId) + return 0; + const Fst* fst = fst_array_[tuple.fst_id]; + size_t num = 0; + if (!epsilon_on_replace_) { + // If epsilon_on_replace is false, all input epsilon arcs + // are also input epsilons arcs in the underlying machine. + fst->NumInputEpsilons(tuple.fst_state); + } else { + // Otherwise, one need to consider that all non-terminal arcs + // in the underlying machine also become input epsilon arc. + ArcIterator > aiter(*fst, tuple.fst_state); + for (; !aiter.Done() && + ((aiter.Value().ilabel == 0) || + IsNonTerminal(aiter.Value().olabel)); + aiter.Next()) + ++num; + } + if (ComputeFinalArc(tuple, 0)) + num++; + return num; + } + } + + size_t NumOutputEpsilons(StateId s) { + if (HasArcs(s)) { + // If state cached, use the cached value. + return CacheImpl::NumOutputEpsilons(s); + } else if(always_cache_ || !Properties(kOLabelSorted)) { + // If always caching or if the number of output epsilons is too expensive + // to compute without caching (i.e. not olabel sorted), + // then expand and cache state. + Expand(s); + return CacheImpl::NumOutputEpsilons(s); + } else { + // Otherwise, compute the number of output epsilons without caching. + StateTuple tuple = state_table_->Tuple(s); + if (tuple.fst_state == kNoStateId) + return 0; + const Fst* fst = fst_array_[tuple.fst_id]; + size_t num = 0; + ArcIterator > aiter(*fst, tuple.fst_state); + for (; !aiter.Done() && + ((aiter.Value().olabel == 0) || + IsNonTerminal(aiter.Value().olabel)); + aiter.Next()) + ++num; + if (ComputeFinalArc(tuple, 0)) + num++; + return num; + } + } + + uint64 Properties() const { return Properties(kFstProperties); } + + // Set error if found; return FST impl properties. + uint64 Properties(uint64 mask) const { + if (mask & kError) { + for (size_t i = 1; i < fst_array_.size(); ++i) { + if (fst_array_[i]->Properties(kError, false)) + SetProperties(kError, kError); + } + } + return FstImpl::Properties(mask); + } + + // return the base arc iterator, if arcs have not been computed yet, + // extend/recurse for new arcs. + void InitArcIterator(StateId s, ArcIteratorData *data) { + if (!HasArcs(s)) + Expand(s); + CacheImpl::InitArcIterator(s, data); + // TODO(allauzen): Set behaviour of generic iterator + // Warning: ArcIterator >::InitCache() + // relies on current behaviour. + } + + + // Extend current state (walk arcs one level deep) + void Expand(StateId s) { + StateTuple tuple = state_table_->Tuple(s); + + // If local fst is empty + if (tuple.fst_state == kNoStateId) { + SetArcs(s); + return; + } + + ArcIterator< Fst > aiter( + *(fst_array_[tuple.fst_id]), tuple.fst_state); + Arc arc; + + // Create a final arc when needed + if (ComputeFinalArc(tuple, &arc)) + PushArc(s, arc); + + // Expand all arcs leaving the state + for (;!aiter.Done(); aiter.Next()) { + if (ComputeArc(tuple, aiter.Value(), &arc)) + PushArc(s, arc); + } + + SetArcs(s); + } + + void Expand(StateId s, const StateTuple &tuple, + const ArcIteratorData &data) { + // If local fst is empty + if (tuple.fst_state == kNoStateId) { + SetArcs(s); + return; + } + + ArcIterator< Fst > aiter(data); + Arc arc; + + // Create a final arc when needed + if (ComputeFinalArc(tuple, &arc)) + AddArc(s, arc); + + // Expand all arcs leaving the state + for (; !aiter.Done(); aiter.Next()) { + if (ComputeArc(tuple, aiter.Value(), &arc)) + AddArc(s, arc); + } + + SetArcs(s); + } + + // If arcp == 0, only returns if a final arc is required, does not + // actually compute it. + bool ComputeFinalArc(const StateTuple &tuple, A* arcp, + uint32 flags = kArcValueFlags) { + const Fst* fst = fst_array_[tuple.fst_id]; + StateId fst_state = tuple.fst_state; + if (fst_state == kNoStateId) + return false; + + // if state is final, pop up stack + const StackPrefix& stack = stackprefix_array_[tuple.prefix_id]; + if (fst->Final(fst_state) != Weight::Zero() && stack.Depth()) { + if (arcp) { + arcp->ilabel = 0; + arcp->olabel = 0; + if (flags & kArcNextStateValue) { + PrefixId prefix_id = PopPrefix(stack); + const PrefixTuple& top = stack.Top(); + arcp->nextstate = state_table_->FindState( + StateTuple(prefix_id, top.fst_id, top.nextstate)); + } + if (flags & kArcWeightValue) + arcp->weight = fst->Final(fst_state); + } + return true; + } else { + return false; + } + } + + // Compute the arc in the replace fst corresponding to a given + // in the underlying machine. Returns false if the underlying arc + // corresponds to no arc in the replace. + bool ComputeArc(const StateTuple &tuple, const A &arc, A* arcp, + uint32 flags = kArcValueFlags) { + if (!epsilon_on_replace_ && + (flags == (flags & (kArcILabelValue | kArcWeightValue)))) { + *arcp = arc; + return true; + } + + if (arc.olabel == 0) { // expand local fst + StateId nextstate = flags & kArcNextStateValue + ? state_table_->FindState( + StateTuple(tuple.prefix_id, tuple.fst_id, arc.nextstate)) + : kNoStateId; + *arcp = A(arc.ilabel, arc.olabel, arc.weight, nextstate); + } else { + // check for non terminal + typename NonTerminalHash::const_iterator it = + nonterminal_hash_.find(arc.olabel); + if (it != nonterminal_hash_.end()) { // recurse into non terminal + Label nonterminal = it->second; + const Fst* nt_fst = fst_array_[nonterminal]; + PrefixId nt_prefix = PushPrefix(stackprefix_array_[tuple.prefix_id], + tuple.fst_id, arc.nextstate); + + // if start state is valid replace, else arc is implicitly + // deleted + StateId nt_start = nt_fst->Start(); + if (nt_start != kNoStateId) { + StateId nt_nextstate = flags & kArcNextStateValue + ? state_table_->FindState( + StateTuple(nt_prefix, nonterminal, nt_start)) + : kNoStateId; + Label ilabel = (epsilon_on_replace_) ? 0 : arc.ilabel; + *arcp = A(ilabel, 0, arc.weight, nt_nextstate); + } else { + return false; + } + } else { + StateId nextstate = flags & kArcNextStateValue + ? state_table_->FindState( + StateTuple(tuple.prefix_id, tuple.fst_id, arc.nextstate)) + : kNoStateId; + *arcp = A(arc.ilabel, arc.olabel, arc.weight, nextstate); + } + } + return true; + } + + // Returns the arc iterator flags supported by this Fst. + uint32 ArcIteratorFlags() const { + uint32 flags = kArcValueFlags; + if (!always_cache_) + flags |= kArcNoCache; + return flags; + } + + T* GetStateTable() const { + return state_table_; + } + + const Fst* GetFst(Label fst_id) const { + return fst_array_[fst_id]; + } + + bool EpsilonOnReplace() const { return epsilon_on_replace_; } + + // private helper classes + private: + static const size_t kPrime0; + + // \class PrefixTuple + // \brief Tuple of fst_id and destination state (entry in stack prefix) + struct PrefixTuple { + PrefixTuple(Label f, StateId s) : fst_id(f), nextstate(s) {} + + Label fst_id; + StateId nextstate; + }; + + // \class StackPrefix + // \brief Container for stack prefix. + class StackPrefix { + public: + StackPrefix() {} + + // copy constructor + StackPrefix(const StackPrefix& x) : + prefix_(x.prefix_) { + } + + void Push(StateId fst_id, StateId nextstate) { + prefix_.push_back(PrefixTuple(fst_id, nextstate)); + } + + void Pop() { + prefix_.pop_back(); + } + + const PrefixTuple& Top() const { + return prefix_[prefix_.size()-1]; + } + + size_t Depth() const { + return prefix_.size(); + } + + public: + vector prefix_; + }; + + + // \class StackPrefixEqual + // \brief Compare two stack prefix classes for equality + class StackPrefixEqual { + public: + bool operator()(const StackPrefix& x, const StackPrefix& y) const { + if (x.prefix_.size() != y.prefix_.size()) return false; + for (size_t i = 0; i < x.prefix_.size(); ++i) { + if (x.prefix_[i].fst_id != y.prefix_[i].fst_id || + x.prefix_[i].nextstate != y.prefix_[i].nextstate) return false; + } + return true; + } + }; + + // + // \class StackPrefixKey + // \brief Hash function for stack prefix to prefix id + class StackPrefixKey { + public: + size_t operator()(const StackPrefix& x) const { + size_t sum = 0; + for (size_t i = 0; i < x.prefix_.size(); ++i) { + sum += x.prefix_[i].fst_id + x.prefix_[i].nextstate*kPrime0; + } + return sum; + } + }; + + typedef unordered_map + StackPrefixHash; + + // private methods + private: + // hash stack prefix (return unique index into stackprefix array) + PrefixId GetPrefixId(const StackPrefix& prefix) { + typename StackPrefixHash::iterator it = prefix_hash_.find(prefix); + if (it == prefix_hash_.end()) { + PrefixId prefix_id = stackprefix_array_.size(); + stackprefix_array_.push_back(prefix); + prefix_hash_[prefix] = prefix_id; + return prefix_id; + } else { + return it->second; + } + } + + // prefix id after a stack pop + PrefixId PopPrefix(StackPrefix prefix) { + prefix.Pop(); + return GetPrefixId(prefix); + } + + // prefix id after a stack push + PrefixId PushPrefix(StackPrefix prefix, Label fst_id, StateId nextstate) { + prefix.Push(fst_id, nextstate); + return GetPrefixId(prefix); + } + + + // private data + private: + // runtime options + bool epsilon_on_replace_; + bool always_cache_; // Optionally caching arc iterator disabled when true + + // state table + StateTable *state_table_; + + // cross index of unique stack prefix + // could potentially have one copy of prefix array + StackPrefixHash prefix_hash_; + vector stackprefix_array_; + + set > +// The ReplaceFst need to be built such that it is known to be ilabel +// or olabel sorted (see usage below). +// +// Observe that Matcher > will use the optionally caching arc +// iterator when available (Fst is ilabel sorted and matching on the +// input, or Fst is olabel sorted and matching on the output). +// In order to obtain the most efficient behaviour, it is recommended +// to set 'epsilon_on_replace' to false (this means constructing acceptors +// as transducers with epsilons on the input side of nonterminal arcs) +// and matching on the input side. +// +// This class attaches interface to implementation and handles +// reference counting, delegating most methods to ImplToFst. +template > +class ReplaceFst : public ImplToFst< ReplaceFstImpl > { + public: + friend class ArcIterator< ReplaceFst >; + friend class StateIterator< ReplaceFst >; + friend class ReplaceFstMatcher; + + typedef A Arc; + typedef typename A::Label Label; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + typedef CacheState State; + typedef ReplaceFstImpl Impl; + + using ImplToFst::Properties; + + ReplaceFst(const vector* > >& fst_array, + Label root) + : ImplToFst(new Impl(fst_array, ReplaceFstOptions(root))) {} + + ReplaceFst(const vector* > >& fst_array, + const ReplaceFstOptions &opts) + : ImplToFst(new Impl(fst_array, opts)) {} + + // See Fst<>::Copy() for doc. + ReplaceFst(const ReplaceFst& fst, bool safe = false) + : ImplToFst(fst, safe) {} + + // Get a copy of this ReplaceFst. See Fst<>::Copy() for further doc. + virtual ReplaceFst *Copy(bool safe = false) const { + return new ReplaceFst(*this, safe); + } + + virtual inline void InitStateIterator(StateIteratorData *data) const; + + virtual void InitArcIterator(StateId s, ArcIteratorData *data) const { + GetImpl()->InitArcIterator(s, data); + } + + virtual MatcherBase *InitMatcher(MatchType match_type) const { + if ((GetImpl()->ArcIteratorFlags() & kArcNoCache) && + ((match_type == MATCH_INPUT && Properties(kILabelSorted, false)) || + (match_type == MATCH_OUTPUT && Properties(kOLabelSorted, false)))) { + return new ReplaceFstMatcher(*this, match_type); + } + else { + VLOG(2) << "Not using replace matcher"; + return 0; + } + } + + bool CyclicDependencies() const { + return GetImpl()->CyclicDependencies(); + } + + private: + // Makes visible to friends. + Impl *GetImpl() const { return ImplToFst::GetImpl(); } + + void operator=(const ReplaceFst &fst); // disallow +}; + + +// Specialization for ReplaceFst. +template +class StateIterator< ReplaceFst > + : public CacheStateIterator< ReplaceFst > { + public: + explicit StateIterator(const ReplaceFst &fst) + : CacheStateIterator< ReplaceFst >(fst, fst.GetImpl()) {} + + private: + DISALLOW_COPY_AND_ASSIGN(StateIterator); +}; + + +// Specialization for ReplaceFst. +// Implements optional caching. It can be used as follows: +// +// ReplaceFst replace; +// ArcIterator< ReplaceFst > aiter(replace, s); +// // Note: ArcIterator< Fst > is always a caching arc iterator. +// aiter.SetFlags(kArcNoCache, kArcNoCache); +// // Use the arc iterator, no arc will be cached, no state will be expanded. +// // The varied 'kArcValueFlags' can be used to decide which part +// // of arc values needs to be computed. +// aiter.SetFlags(kArcILabelValue, kArcValueFlags); +// // Only want the ilabel for this arc +// aiter.Value(); // Does not compute the destination state. +// aiter.Next(); +// aiter.SetFlags(kArcNextStateValue, kArcNextStateValue); +// // Want both ilabel and nextstate for that arc +// aiter.Value(); // Does compute the destination state and inserts it +// // in the replace state table. +// // No Arc has been cached at that point. +// +template +class ArcIterator< ReplaceFst > { + public: + typedef A Arc; + typedef typename A::StateId StateId; + + ArcIterator(const ReplaceFst &fst, StateId s) + : fst_(fst), state_(s), pos_(0), offset_(0), flags_(0), arcs_(0), + data_flags_(0), final_flags_(0) { + cache_data_.ref_count = 0; + local_data_.ref_count = 0; + + // If FST does not support optional caching, force caching. + if(!(fst_.GetImpl()->ArcIteratorFlags() & kArcNoCache) && + !(fst_.GetImpl()->HasArcs(state_))) + fst_.GetImpl()->Expand(state_); + + // If state is already cached, use cached arcs array. + if (fst_.GetImpl()->HasArcs(state_)) { + (fst_.GetImpl())->template CacheImpl::InitArcIterator(state_, + &cache_data_); + num_arcs_ = cache_data_.narcs; + arcs_ = cache_data_.arcs; // 'arcs_' is a ptr to the cached arcs. + data_flags_ = kArcValueFlags; // All the arc member values are valid. + } else { // Otherwise delay decision until Value() is called. + tuple_ = fst_.GetImpl()->GetStateTable()->Tuple(state_); + if (tuple_.fst_state == kNoStateId) { + num_arcs_ = 0; + } else { + // The decision to cache or not to cache has been defered + // until Value() or SetFlags() is called. However, the arc + // iterator is set up now to be ready for non-caching in order + // to keep the Value() method simple and efficient. + const Fst* fst = fst_.GetImpl()->GetFst(tuple_.fst_id); + fst->InitArcIterator(tuple_.fst_state, &local_data_); + // 'arcs_' is a pointer to the arcs in the underlying machine. + arcs_ = local_data_.arcs; + // Compute the final arc (but not its destination state) + // if a final arc is required. + bool has_final_arc = fst_.GetImpl()->ComputeFinalArc( + tuple_, + &final_arc_, + kArcValueFlags & ~kArcNextStateValue); + // Set the arc value flags that hold for 'final_arc_'. + final_flags_ = kArcValueFlags & ~kArcNextStateValue; + // Compute the number of arcs. + num_arcs_ = local_data_.narcs; + if (has_final_arc) + ++num_arcs_; + // Set the offset between the underlying arc positions and + // the positions in the arc iterator. + offset_ = num_arcs_ - local_data_.narcs; + // Defers the decision to cache or not until Value() or + // SetFlags() is called. + data_flags_ = 0; + } + } + } + + ~ArcIterator() { + if (cache_data_.ref_count) + --(*cache_data_.ref_count); + if (local_data_.ref_count) + --(*local_data_.ref_count); + } + + void ExpandAndCache() const { + // TODO(allauzen): revisit this + // fst_.GetImpl()->Expand(state_, tuple_, local_data_); + // (fst_.GetImpl())->CacheImpl*>::InitArcIterator(state_, + // &cache_data_); + // + fst_.InitArcIterator(state_, &cache_data_); // Expand and cache state. + arcs_ = cache_data_.arcs; // 'arcs_' is a pointer to the cached arcs. + data_flags_ = kArcValueFlags; // All the arc member values are valid. + offset_ = 0; // No offset + + } + + void Init() { + if (flags_ & kArcNoCache) { // If caching is disabled + // 'arcs_' is a pointer to the arcs in the underlying machine. + arcs_ = local_data_.arcs; + // Set the arcs value flags that hold for 'arcs_'. + data_flags_ = kArcWeightValue; + if (!fst_.GetImpl()->EpsilonOnReplace()) + data_flags_ |= kArcILabelValue; + // Set the offset between the underlying arc positions and + // the positions in the arc iterator. + offset_ = num_arcs_ - local_data_.narcs; + } else { // Otherwise, expand and cache + ExpandAndCache(); + } + } + + bool Done() const { return pos_ >= num_arcs_; } + + const A& Value() const { + // If 'data_flags_' was set to 0, non-caching was not requested + if (!data_flags_) { + // TODO(allauzen): revisit this. + if (flags_ & kArcNoCache) { + // Should never happen. + FSTERROR() << "ReplaceFst: inconsistent arc iterator flags"; + } + ExpandAndCache(); // Expand and cache. + } + + if (pos_ - offset_ >= 0) { // The requested arc is not the 'final' arc. + const A& arc = arcs_[pos_ - offset_]; + if ((data_flags_ & flags_) == (flags_ & kArcValueFlags)) { + // If the value flags for 'arc' match the recquired value flags + // then return 'arc'. + return arc; + } else { + // Otherwise, compute the corresponding arc on-the-fly. + fst_.GetImpl()->ComputeArc(tuple_, arc, &arc_, flags_ & kArcValueFlags); + return arc_; + } + } else { // The requested arc is the 'final' arc. + if ((final_flags_ & flags_) != (flags_ & kArcValueFlags)) { + // If the arc value flags that hold for the final arc + // do not match the requested value flags, then + // 'final_arc_' needs to be updated. + fst_.GetImpl()->ComputeFinalArc(tuple_, &final_arc_, + flags_ & kArcValueFlags); + final_flags_ = flags_ & kArcValueFlags; + } + return final_arc_; + } + } + + void Next() { ++pos_; } + + size_t Position() const { return pos_; } + + void Reset() { pos_ = 0; } + + void Seek(size_t pos) { pos_ = pos; } + + uint32 Flags() const { return flags_; } + + void SetFlags(uint32 f, uint32 mask) { + // Update the flags taking into account what flags are supported + // by the Fst. + flags_ &= ~mask; + flags_ |= (f & fst_.GetImpl()->ArcIteratorFlags()); + // If non-caching is not requested (and caching has not already + // been performed), then flush 'data_flags_' to request caching + // during the next call to Value(). + if (!(flags_ & kArcNoCache) && data_flags_ != kArcValueFlags) { + if (!fst_.GetImpl()->HasArcs(state_)) + data_flags_ = 0; + } + // If 'data_flags_' has been flushed but non-caching is requested + // before calling Value(), then set up the iterator for non-caching. + if ((f & kArcNoCache) && (!data_flags_)) + Init(); + } + + private: + const ReplaceFst &fst_; // Reference to the FST + StateId state_; // State in the FST + mutable typename T::StateTuple tuple_; // Tuple corresponding to state_ + + ssize_t pos_; // Current position + mutable ssize_t offset_; // Offset between position in iterator and in arcs_ + ssize_t num_arcs_; // Number of arcs at state_ + uint32 flags_; // Behavorial flags for the arc iterator + mutable Arc arc_; // Memory to temporarily store computed arcs + + mutable ArcIteratorData cache_data_; // Arc iterator data in cache + mutable ArcIteratorData local_data_; // Arc iterator data in local fst + + mutable const A* arcs_; // Array of arcs + mutable uint32 data_flags_; // Arc value flags valid for data in arcs_ + mutable Arc final_arc_; // Final arc (when required) + mutable uint32 final_flags_; // Arc value flags valid for final_arc_ + + DISALLOW_COPY_AND_ASSIGN(ArcIterator); +}; + + +template +class ReplaceFstMatcher : public MatcherBase { + public: + typedef A Arc; + typedef typename A::StateId StateId; + typedef typename A::Label Label; + typedef MultiEpsMatcher > > LocalMatcher; + + ReplaceFstMatcher(const ReplaceFst &fst, fst::MatchType match_type) + : fst_(fst), + impl_(fst_.GetImpl()), + s_(fst::kNoStateId), + match_type_(match_type), + current_loop_(false), + final_arc_(false), + loop_(fst::kNoLabel, 0, A::Weight::One(), fst::kNoStateId) { + if (match_type_ == fst::MATCH_OUTPUT) + swap(loop_.ilabel, loop_.olabel); + InitMatchers(); + } + + ReplaceFstMatcher(const ReplaceFstMatcher &matcher, bool safe = false) + : fst_(matcher.fst_), + impl_(fst_.GetImpl()), + s_(fst::kNoStateId), + match_type_(matcher.match_type_), + current_loop_(false), + loop_(fst::kNoLabel, 0, A::Weight::One(), fst::kNoStateId) { + if (match_type_ == fst::MATCH_OUTPUT) + swap(loop_.ilabel, loop_.olabel); + InitMatchers(); + } + + // Create a local matcher for each component Fst of replace. + // LocalMatcher is a multi epsilon wrapper matcher. MultiEpsilonMatcher + // is used to match each non-terminal arc, since these non-terminal + // turn into epsilons on recursion. + void InitMatchers() { + const vector*>& fst_array = impl_->fst_array_; + matcher_.resize(fst_array.size(), 0); + for (size_t i = 0; i < fst_array.size(); ++i) { + if (fst_array[i]) { + matcher_[i] = + new LocalMatcher(*fst_array[i], match_type_, kMultiEpsList); + + typename set &GetFst() const { + return fst_; + } + + virtual uint64 Properties(uint64 props) const { + return props; + } + + private: + // Set the sate from which our matching happens. + virtual void SetState_(StateId s) { + if (s_ == s) return; + + s_ = s; + tuple_ = impl_->GetStateTable()->Tuple(s_); + if (tuple_.fst_state == kNoStateId) { + done_ = true; + return; + } + // Get current matcher. Used for non epsilon matching + current_matcher_ = matcher_[tuple_.fst_id]; + current_matcher_->SetState(tuple_.fst_state); + loop_.nextstate = s_; + + final_arc_ = false; + } + + // Search for label, from previous set state. If label == 0, first + // hallucinate and epsilon loop, else use the underlying matcher to + // search for the label or epsilons. + // - Note since the ReplaceFST recursion on non-terminal arcs causes + // epsilon transitions to be created we use the MultiEpsilonMatcher + // to search for possible matches of non terminals. + // - If the component Fst reaches a final state we also need to add + // the exiting final arc. + virtual bool Find_(Label label) { + bool found = false; + label_ = label; + if (label_ == 0 || label_ == kNoLabel) { + // Compute loop directly, saving Replace::ComputeArc + if (label_ == 0) { + current_loop_ = true; + found = true; + } + // Search for matching multi epsilons + final_arc_ = impl_->ComputeFinalArc(tuple_, 0); + found = current_matcher_->Find(kNoLabel) || final_arc_ || found; + } else { + // Search on sub machine directly using sub machine matcher. + found = current_matcher_->Find(label_); + } + return found; + } + + virtual bool Done_() const { + return !current_loop_ && !final_arc_ && current_matcher_->Done(); + } + + virtual const Arc& Value_() const { + if (current_loop_) { + return loop_; + } + if (final_arc_) { + impl_->ComputeFinalArc(tuple_, &arc_); + return arc_; + } + const Arc& component_arc = current_matcher_->Value(); + impl_->ComputeArc(tuple_, component_arc, &arc_); + return arc_; + } + + virtual void Next_() { + if (current_loop_) { + current_loop_ = false; + return; + } + if (final_arc_) { + final_arc_ = false; + return; + } + current_matcher_->Next(); + } + + const ReplaceFst& fst_; + ReplaceFstImpl *impl_; + LocalMatcher* current_matcher_; + vector matcher_; + + StateId s_; // Current state + Label label_; // Current label + + MatchType match_type_; // Supplied by caller + mutable bool done_; + mutable bool current_loop_; // Current arc is the implicit loop + mutable bool final_arc_; // Current arc for exiting recursion + mutable typename T::StateTuple tuple_; // Tuple corresponding to state_ + mutable Arc arc_; + Arc loop_; +}; + +template inline +void ReplaceFst::InitStateIterator(StateIteratorData *data) const { + data->base = new StateIterator< ReplaceFst >(*this); +} + +typedef ReplaceFst StdReplaceFst; + + +// // Recursivively replaces arcs in the root Fst with other Fsts. +// This version writes the result of replacement to an output MutableFst. +// +// Replace supports replacement of arcs in one Fst with another +// Fst. This replacement is recursive. Replace takes an array of +// Fst(s). One Fst represents the root (or topology) machine. The root +// Fst refers to other Fsts by recursively replacing arcs labeled as +// non-terminals with the matching non-terminal Fst. Currently Replace +// uses the output symbols of the arcs to determine whether the arc is +// a non-terminal arc or not. A non-terminal can be any label that is +// not a non-zero terminal label in the output alphabet. Note that +// input argument is a vector of pair<>. These correspond to the tuple +// of non-terminal Label and corresponding Fst. +template +void Replace(const vector* > >& ifst_array, + MutableFst *ofst, typename Arc::Label root, + bool epsilon_on_replace) { + ReplaceFstOptions opts(root, epsilon_on_replace); + opts.gc_limit = 0; // Cache only the last state for fastest copy. + *ofst = ReplaceFst(ifst_array, opts); +} + +template +void Replace(const vector* > >& ifst_array, + MutableFst *ofst, typename Arc::Label root) { + Replace(ifst_array, ofst, root, false); +} + +} // namespace fst + +#endif // FST_LIB_REPLACE_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/reverse.h b/kaldi_io/src/tools/openfst/include/fst/reverse.h new file mode 100644 index 0000000..4d4c75c --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/reverse.h @@ -0,0 +1,91 @@ +// reverse.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Functions and classes to sort arcs in an FST. + +#ifndef FST_LIB_REVERSE_H__ +#define FST_LIB_REVERSE_H__ + +#include +#include +using std::vector; + +#include + + +namespace fst { + +// Reverses an FST. The reversed result is written to an output +// MutableFst. If A transduces string x to y with weight a, then the +// reverse of A transduces the reverse of x to the reverse of y with +// weight a.Reverse(). +// +// Typically, a = a.Reverse() and Arc = RevArc (e.g. for +// TropicalWeight or LogWeight). In general, e.g. when the weights +// only form a left or right semiring, the output arc type must match +// the input arc type except having the reversed Weight type. +template +void Reverse(const Fst &ifst, MutableFst *ofst) { + typedef typename Arc::StateId StateId; + typedef typename Arc::Weight Weight; + typedef typename RevArc::Weight RevWeight; + + ofst->DeleteStates(); + ofst->SetInputSymbols(ifst.InputSymbols()); + ofst->SetOutputSymbols(ifst.OutputSymbols()); + if (ifst.Properties(kExpanded, false)) + ofst->ReserveStates(CountStates(ifst) + 1); + StateId istart = ifst.Start(); + StateId ostart = ofst->AddState(); + ofst->SetStart(ostart); + + for (StateIterator< Fst > siter(ifst); + !siter.Done(); + siter.Next()) { + StateId is = siter.Value(); + StateId os = is + 1; + while (ofst->NumStates() <= os) + ofst->AddState(); + if (is == istart) + ofst->SetFinal(os, RevWeight::One()); + + Weight final = ifst.Final(is); + if (final != Weight::Zero()) { + RevArc oarc(0, 0, final.Reverse(), os); + ofst->AddArc(0, oarc); + } + + for (ArcIterator< Fst > aiter(ifst, is); + !aiter.Done(); + aiter.Next()) { + const Arc &iarc = aiter.Value(); + RevArc oarc(iarc.ilabel, iarc.olabel, iarc.weight.Reverse(), os); + StateId nos = iarc.nextstate + 1; + while (ofst->NumStates() <= nos) + ofst->AddState(); + ofst->AddArc(nos, oarc); + } + } + uint64 iprops = ifst.Properties(kCopyProperties, false); + uint64 oprops = ofst->Properties(kFstProperties, false); + ofst->SetProperties(ReverseProperties(iprops) | oprops, kFstProperties); +} + +} // namespace fst + +#endif // FST_LIB_REVERSE_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/reweight.h b/kaldi_io/src/tools/openfst/include/fst/reweight.h new file mode 100644 index 0000000..c051c2a --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/reweight.h @@ -0,0 +1,146 @@ +// reweight.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: allauzen@google.com (Cyril Allauzen) +// +// \file +// Function to reweight an FST. + +#ifndef FST_LIB_REWEIGHT_H__ +#define FST_LIB_REWEIGHT_H__ + +#include +using std::vector; + +#include + + +namespace fst { + +enum ReweightType { REWEIGHT_TO_INITIAL, REWEIGHT_TO_FINAL }; + +// Reweight FST according to the potentials defined by the POTENTIAL +// vector in the direction defined by TYPE. Weight needs to be left +// distributive when reweighting towards the initial state and right +// distributive when reweighting towards the final states. +// +// An arc of weight w, with an origin state of potential p and +// destination state of potential q, is reweighted by p\wq when +// reweighting towards the initial state and by pw/q when reweighting +// towards the final states. +template +void Reweight(MutableFst *fst, + const vector &potential, + ReweightType type) { + typedef typename Arc::Weight Weight; + + if (fst->NumStates() == 0) + return; + + if (type == REWEIGHT_TO_FINAL && !(Weight::Properties() & kRightSemiring)) { + FSTERROR() << "Reweight: Reweighting to the final states requires " + << "Weight to be right distributive: " + << Weight::Type(); + fst->SetProperties(kError, kError); + return; + } + + if (type == REWEIGHT_TO_INITIAL && !(Weight::Properties() & kLeftSemiring)) { + FSTERROR() << "Reweight: Reweighting to the initial state requires " + << "Weight to be left distributive: " + << Weight::Type(); + fst->SetProperties(kError, kError); + return; + } + + StateIterator< MutableFst > sit(*fst); + for (; !sit.Done(); sit.Next()) { + typename Arc::StateId state = sit.Value(); + if (state == potential.size()) + break; + typename Arc::Weight weight = potential[state]; + if (weight != Weight::Zero()) { + for (MutableArcIterator< MutableFst > ait(fst, state); + !ait.Done(); + ait.Next()) { + Arc arc = ait.Value(); + if (arc.nextstate >= potential.size()) + continue; + typename Arc::Weight nextweight = potential[arc.nextstate]; + if (nextweight == Weight::Zero()) + continue; + if (type == REWEIGHT_TO_INITIAL) + arc.weight = Divide(Times(arc.weight, nextweight), weight, + DIVIDE_LEFT); + if (type == REWEIGHT_TO_FINAL) + arc.weight = Divide(Times(weight, arc.weight), nextweight, + DIVIDE_RIGHT); + ait.SetValue(arc); + } + if (type == REWEIGHT_TO_INITIAL) + fst->SetFinal(state, Divide(fst->Final(state), weight, DIVIDE_LEFT)); + } + if (type == REWEIGHT_TO_FINAL) + fst->SetFinal(state, Times(weight, fst->Final(state))); + } + + // This handles elements past the end of the potentials array. + for (; !sit.Done(); sit.Next()) { + typename Arc::StateId state = sit.Value(); + if (type == REWEIGHT_TO_FINAL) + fst->SetFinal(state, Times(Weight::Zero(), fst->Final(state))); + } + + typename Arc::Weight startweight = fst->Start() < potential.size() ? + potential[fst->Start()] : Weight::Zero(); + if ((startweight != Weight::One()) && (startweight != Weight::Zero())) { + if (fst->Properties(kInitialAcyclic, true) & kInitialAcyclic) { + typename Arc::StateId state = fst->Start(); + for (MutableArcIterator< MutableFst > ait(fst, state); + !ait.Done(); + ait.Next()) { + Arc arc = ait.Value(); + if (type == REWEIGHT_TO_INITIAL) + arc.weight = Times(startweight, arc.weight); + else + arc.weight = Times( + Divide(Weight::One(), startweight, DIVIDE_RIGHT), + arc.weight); + ait.SetValue(arc); + } + if (type == REWEIGHT_TO_INITIAL) + fst->SetFinal(state, Times(startweight, fst->Final(state))); + else + fst->SetFinal(state, Times(Divide(Weight::One(), startweight, + DIVIDE_RIGHT), + fst->Final(state))); + } else { + typename Arc::StateId state = fst->AddState(); + Weight w = type == REWEIGHT_TO_INITIAL ? startweight : + Divide(Weight::One(), startweight, DIVIDE_RIGHT); + Arc arc(0, 0, w, fst->Start()); + fst->AddArc(state, arc); + fst->SetStart(state); + } + } + + fst->SetProperties(ReweightProperties( + fst->Properties(kFstProperties, false)), + kFstProperties); +} + +} // namespace fst + +#endif // FST_LIB_REWEIGHT_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/rmepsilon.h b/kaldi_io/src/tools/openfst/include/fst/rmepsilon.h new file mode 100644 index 0000000..89b8178 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/rmepsilon.h @@ -0,0 +1,600 @@ +// rmepsilon.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: allauzen@google.com (Cyril Allauzen) +// +// \file +// Functions and classes that implemement epsilon-removal. + +#ifndef FST_LIB_RMEPSILON_H__ +#define FST_LIB_RMEPSILON_H__ + +#include +using std::tr1::unordered_map; +using std::tr1::unordered_multimap; +#include +#include +#include +#include +using std::pair; using std::make_pair; +#include +using std::vector; + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace fst { + +template +class RmEpsilonOptions + : public ShortestDistanceOptions > { + public: + typedef typename Arc::StateId StateId; + typedef typename Arc::Weight Weight; + + bool connect; // Connect output + Weight weight_threshold; // Pruning weight threshold. + StateId state_threshold; // Pruning state threshold. + + explicit RmEpsilonOptions(Queue *q, float d = kDelta, bool c = true, + Weight w = Weight::Zero(), + StateId n = kNoStateId) + : ShortestDistanceOptions< Arc, Queue, EpsilonArcFilter >( + q, EpsilonArcFilter(), kNoStateId, d), + connect(c), weight_threshold(w), state_threshold(n) {} + private: + RmEpsilonOptions(); // disallow +}; + +// Computation state of the epsilon-removal algorithm. +template +class RmEpsilonState { + public: + typedef typename Arc::Label Label; + typedef typename Arc::StateId StateId; + typedef typename Arc::Weight Weight; + + RmEpsilonState(const Fst &fst, + vector *distance, + const RmEpsilonOptions &opts) + : fst_(fst), distance_(distance), sd_state_(fst_, distance, opts, true), + expand_id_(0) {} + + // Compute arcs and final weight for state 's' + void Expand(StateId s); + + // Returns arcs of expanded state. + vector &Arcs() { return arcs_; } + + // Returns final weight of expanded state. + const Weight &Final() const { return final_; } + + // Return true if an error has occured. + bool Error() const { return sd_state_.Error(); } + + private: + static const size_t kPrime0 = 7853; + static const size_t kPrime1 = 7867; + + struct Element { + Label ilabel; + Label olabel; + StateId nextstate; + + Element() {} + + Element(Label i, Label o, StateId s) + : ilabel(i), olabel(o), nextstate(s) {} + }; + + class ElementKey { + public: + size_t operator()(const Element& e) const { + return static_cast(e.nextstate + + e.ilabel * kPrime0 + + e.olabel * kPrime1); + } + + private: + }; + + class ElementEqual { + public: + bool operator()(const Element &e1, const Element &e2) const { + return (e1.ilabel == e2.ilabel) && (e1.olabel == e2.olabel) + && (e1.nextstate == e2.nextstate); + } + }; + + typedef unordered_map, + ElementKey, ElementEqual> ElementMap; + + const Fst &fst_; + // Distance from state being expanded in epsilon-closure. + vector *distance_; + // Shortest distance algorithm computation state. + ShortestDistanceState > sd_state_; + // Maps an element 'e' to a pair 'p' corresponding to a position + // in the arcs vector of the state being expanded. 'e' corresponds + // to the position 'p.second' in the 'arcs_' vector if 'p.first' is + // equal to the state being expanded. + ElementMap element_map_; + EpsilonArcFilter eps_filter_; + stack eps_queue_; // Queue used to visit the epsilon-closure + vector visited_; // '[i] = true' if state 'i' has been visited + slist visited_states_; // List of visited states + vector arcs_; // Arcs of state being expanded + Weight final_; // Final weight of state being expanded + StateId expand_id_; // Unique ID for each call to Expand + + DISALLOW_COPY_AND_ASSIGN(RmEpsilonState); +}; + +template +const size_t RmEpsilonState::kPrime0; +template +const size_t RmEpsilonState::kPrime1; + + +template +void RmEpsilonState::Expand(typename Arc::StateId source) { + final_ = Weight::Zero(); + arcs_.clear(); + sd_state_.ShortestDistance(source); + if (sd_state_.Error()) + return; + eps_queue_.push(source); + + while (!eps_queue_.empty()) { + StateId state = eps_queue_.top(); + eps_queue_.pop(); + + while (visited_.size() <= state) visited_.push_back(false); + if (visited_[state]) continue; + visited_[state] = true; + visited_states_.push_front(state); + + for (ArcIterator< Fst > ait(fst_, state); + !ait.Done(); + ait.Next()) { + Arc arc = ait.Value(); + arc.weight = Times((*distance_)[state], arc.weight); + + if (eps_filter_(arc)) { + while (visited_.size() <= arc.nextstate) + visited_.push_back(false); + if (!visited_[arc.nextstate]) + eps_queue_.push(arc.nextstate); + } else { + Element element(arc.ilabel, arc.olabel, arc.nextstate); + typename ElementMap::iterator it = element_map_.find(element); + if (it == element_map_.end()) { + element_map_.insert( + pair > + (element, pair(expand_id_, arcs_.size()))); + arcs_.push_back(arc); + } else { + if (((*it).second).first == expand_id_) { + Weight &w = arcs_[((*it).second).second].weight; + w = Plus(w, arc.weight); + } else { + ((*it).second).first = expand_id_; + ((*it).second).second = arcs_.size(); + arcs_.push_back(arc); + } + } + } + } + final_ = Plus(final_, Times((*distance_)[state], fst_.Final(state))); + } + + while (!visited_states_.empty()) { + visited_[visited_states_.front()] = false; + visited_states_.pop_front(); + } + ++expand_id_; +} + +// Removes epsilon-transitions (when both the input and output label +// are an epsilon) from a transducer. The result will be an equivalent +// FST that has no such epsilon transitions. This version modifies +// its input. It allows fine control via the options argument; see +// below for a simpler interface. +// +// The vector 'distance' will be used to hold the shortest distances +// during the epsilon-closure computation. The state queue discipline +// and convergence delta are taken in the options argument. +template +void RmEpsilon(MutableFst *fst, + vector *distance, + const RmEpsilonOptions &opts) { + typedef typename Arc::StateId StateId; + typedef typename Arc::Weight Weight; + typedef typename Arc::Label Label; + + if (fst->Start() == kNoStateId) { + return; + } + + // 'noneps_in[s]' will be set to true iff 's' admits a non-epsilon + // incoming transition or is the start state. + vector noneps_in(fst->NumStates(), false); + noneps_in[fst->Start()] = true; + for (StateId i = 0; i < fst->NumStates(); ++i) { + for (ArcIterator > aiter(*fst, i); + !aiter.Done(); + aiter.Next()) { + if (aiter.Value().ilabel != 0 || aiter.Value().olabel != 0) + noneps_in[aiter.Value().nextstate] = true; + } + } + + // States sorted in topological order when (acyclic) or generic + // topological order (cyclic). + vector states; + states.reserve(fst->NumStates()); + + if (fst->Properties(kTopSorted, false) & kTopSorted) { + for (StateId i = 0; i < fst->NumStates(); i++) + states.push_back(i); + } else if (fst->Properties(kAcyclic, false) & kAcyclic) { + vector order; + bool acyclic; + TopOrderVisitor top_order_visitor(&order, &acyclic); + DfsVisit(*fst, &top_order_visitor, EpsilonArcFilter()); + // Sanity check: should be acyclic if property bit is set. + if(!acyclic) { + FSTERROR() << "RmEpsilon: inconsistent acyclic property bit"; + fst->SetProperties(kError, kError); + return; + } + states.resize(order.size()); + for (StateId i = 0; i < order.size(); i++) + states[order[i]] = i; + } else { + uint64 props; + vector scc; + SccVisitor scc_visitor(&scc, 0, 0, &props); + DfsVisit(*fst, &scc_visitor, EpsilonArcFilter()); + vector first(scc.size(), kNoStateId); + vector next(scc.size(), kNoStateId); + for (StateId i = 0; i < scc.size(); i++) { + if (first[scc[i]] != kNoStateId) + next[i] = first[scc[i]]; + first[scc[i]] = i; + } + for (StateId i = 0; i < first.size(); i++) + for (StateId j = first[i]; j != kNoStateId; j = next[j]) + states.push_back(j); + } + + RmEpsilonState + rmeps_state(*fst, distance, opts); + + while (!states.empty()) { + StateId state = states.back(); + states.pop_back(); + if (!noneps_in[state]) + continue; + rmeps_state.Expand(state); + fst->SetFinal(state, rmeps_state.Final()); + fst->DeleteArcs(state); + vector &arcs = rmeps_state.Arcs(); + fst->ReserveArcs(state, arcs.size()); + while (!arcs.empty()) { + fst->AddArc(state, arcs.back()); + arcs.pop_back(); + } + } + + for (StateId s = 0; s < fst->NumStates(); ++s) { + if (!noneps_in[s]) + fst->DeleteArcs(s); + } + + if(rmeps_state.Error()) + fst->SetProperties(kError, kError); + fst->SetProperties( + RmEpsilonProperties(fst->Properties(kFstProperties, false)), + kFstProperties); + + if (opts.weight_threshold != Weight::Zero() || + opts.state_threshold != kNoStateId) + Prune(fst, opts.weight_threshold, opts.state_threshold); + if (opts.connect && (opts.weight_threshold == Weight::Zero() || + opts.state_threshold != kNoStateId)) + Connect(fst); +} + +// Removes epsilon-transitions (when both the input and output label +// are an epsilon) from a transducer. The result will be an equivalent +// FST that has no such epsilon transitions. This version modifies its +// input. It has a simplified interface; see above for a version that +// allows finer control. +// +// Complexity: +// - Time: +// - Unweighted: O(V2 + V E) +// - Acyclic: O(V2 + V E) +// - Tropical semiring: O(V2 log V + V E) +// - General: exponential +// - Space: O(V E) +// where V = # of states visited, E = # of arcs. +// +// References: +// - Mehryar Mohri. Generic Epsilon-Removal and Input +// Epsilon-Normalization Algorithms for Weighted Transducers, +// "International Journal of Computer Science", 13(1):129-143 (2002). +template +void RmEpsilon(MutableFst *fst, + bool connect = true, + typename Arc::Weight weight_threshold = Arc::Weight::Zero(), + typename Arc::StateId state_threshold = kNoStateId, + float delta = kDelta) { + typedef typename Arc::StateId StateId; + typedef typename Arc::Weight Weight; + typedef typename Arc::Label Label; + + vector distance; + AutoQueue state_queue(*fst, &distance, EpsilonArcFilter()); + RmEpsilonOptions > + opts(&state_queue, delta, connect, weight_threshold, state_threshold); + + RmEpsilon(fst, &distance, opts); +} + + +struct RmEpsilonFstOptions : CacheOptions { + float delta; + + RmEpsilonFstOptions(const CacheOptions &opts, float delta = kDelta) + : CacheOptions(opts), delta(delta) {} + + explicit RmEpsilonFstOptions(float delta = kDelta) : delta(delta) {} +}; + + +// Implementation of delayed RmEpsilonFst. +template +class RmEpsilonFstImpl : public CacheImpl { + public: + using FstImpl::SetType; + using FstImpl::SetProperties; + using FstImpl::SetInputSymbols; + using FstImpl::SetOutputSymbols; + + using CacheBaseImpl< CacheState >::PushArc; + using CacheBaseImpl< CacheState >::HasArcs; + using CacheBaseImpl< CacheState >::HasFinal; + using CacheBaseImpl< CacheState >::HasStart; + using CacheBaseImpl< CacheState >::SetArcs; + using CacheBaseImpl< CacheState >::SetFinal; + using CacheBaseImpl< CacheState >::SetStart; + + typedef typename A::Label Label; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + typedef CacheState State; + + RmEpsilonFstImpl(const Fst& fst, const RmEpsilonFstOptions &opts) + : CacheImpl(opts), + fst_(fst.Copy()), + delta_(opts.delta), + rmeps_state_( + *fst_, + &distance_, + RmEpsilonOptions >(&queue_, delta_, false)) { + SetType("rmepsilon"); + uint64 props = fst.Properties(kFstProperties, false); + SetProperties(RmEpsilonProperties(props, true), kCopyProperties); + SetInputSymbols(fst.InputSymbols()); + SetOutputSymbols(fst.OutputSymbols()); + } + + RmEpsilonFstImpl(const RmEpsilonFstImpl &impl) + : CacheImpl(impl), + fst_(impl.fst_->Copy(true)), + delta_(impl.delta_), + rmeps_state_( + *fst_, + &distance_, + RmEpsilonOptions >(&queue_, delta_, false)) { + SetType("rmepsilon"); + SetProperties(impl.Properties(), kCopyProperties); + SetInputSymbols(impl.InputSymbols()); + SetOutputSymbols(impl.OutputSymbols()); + } + + ~RmEpsilonFstImpl() { + delete fst_; + } + + StateId Start() { + if (!HasStart()) { + SetStart(fst_->Start()); + } + return CacheImpl::Start(); + } + + Weight Final(StateId s) { + if (!HasFinal(s)) { + Expand(s); + } + return CacheImpl::Final(s); + } + + size_t NumArcs(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumArcs(s); + } + + size_t NumInputEpsilons(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumInputEpsilons(s); + } + + size_t NumOutputEpsilons(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumOutputEpsilons(s); + } + + uint64 Properties() const { return Properties(kFstProperties); } + + // Set error if found; return FST impl properties. + uint64 Properties(uint64 mask) const { + if ((mask & kError) && + (fst_->Properties(kError, false) || rmeps_state_.Error())) + SetProperties(kError, kError); + return FstImpl::Properties(mask); + } + + void InitArcIterator(StateId s, ArcIteratorData *data) { + if (!HasArcs(s)) + Expand(s); + CacheImpl::InitArcIterator(s, data); + } + + void Expand(StateId s) { + rmeps_state_.Expand(s); + SetFinal(s, rmeps_state_.Final()); + vector &arcs = rmeps_state_.Arcs(); + while (!arcs.empty()) { + PushArc(s, arcs.back()); + arcs.pop_back(); + } + SetArcs(s); + } + + private: + const Fst *fst_; + float delta_; + vector distance_; + FifoQueue queue_; + RmEpsilonState > rmeps_state_; + + void operator=(const RmEpsilonFstImpl &); // disallow +}; + + +// Removes epsilon-transitions (when both the input and output label +// are an epsilon) from a transducer. The result will be an equivalent +// FST that has no such epsilon transitions. This version is a +// delayed Fst. +// +// Complexity: +// - Time: +// - Unweighted: O(v^2 + v e) +// - General: exponential +// - Space: O(v e) +// where v = # of states visited, e = # of arcs visited. Constant time +// to visit an input state or arc is assumed and exclusive of caching. +// +// References: +// - Mehryar Mohri. Generic Epsilon-Removal and Input +// Epsilon-Normalization Algorithms for Weighted Transducers, +// "International Journal of Computer Science", 13(1):129-143 (2002). +// +// This class attaches interface to implementation and handles +// reference counting, delegating most methods to ImplToFst. +template +class RmEpsilonFst : public ImplToFst< RmEpsilonFstImpl > { + public: + friend class ArcIterator< RmEpsilonFst >; + friend class StateIterator< RmEpsilonFst >; + + typedef A Arc; + typedef typename A::StateId StateId; + typedef CacheState State; + typedef RmEpsilonFstImpl Impl; + + RmEpsilonFst(const Fst &fst) + : ImplToFst(new Impl(fst, RmEpsilonFstOptions())) {} + + RmEpsilonFst(const Fst &fst, const RmEpsilonFstOptions &opts) + : ImplToFst(new Impl(fst, opts)) {} + + // See Fst<>::Copy() for doc. + RmEpsilonFst(const RmEpsilonFst &fst, bool safe = false) + : ImplToFst(fst, safe) {} + + // Get a copy of this RmEpsilonFst. See Fst<>::Copy() for further doc. + virtual RmEpsilonFst *Copy(bool safe = false) const { + return new RmEpsilonFst(*this, safe); + } + + virtual inline void InitStateIterator(StateIteratorData *data) const; + + virtual void InitArcIterator(StateId s, ArcIteratorData *data) const { + GetImpl()->InitArcIterator(s, data); + } + + private: + // Makes visible to friends. + Impl *GetImpl() const { return ImplToFst::GetImpl(); } + + void operator=(const RmEpsilonFst &fst); // disallow +}; + +// Specialization for RmEpsilonFst. +template +class StateIterator< RmEpsilonFst > + : public CacheStateIterator< RmEpsilonFst > { + public: + explicit StateIterator(const RmEpsilonFst &fst) + : CacheStateIterator< RmEpsilonFst >(fst, fst.GetImpl()) {} +}; + + +// Specialization for RmEpsilonFst. +template +class ArcIterator< RmEpsilonFst > + : public CacheArcIterator< RmEpsilonFst > { + public: + typedef typename A::StateId StateId; + + ArcIterator(const RmEpsilonFst &fst, StateId s) + : CacheArcIterator< RmEpsilonFst >(fst.GetImpl(), s) { + if (!fst.GetImpl()->HasArcs(s)) + fst.GetImpl()->Expand(s); + } + + private: + DISALLOW_COPY_AND_ASSIGN(ArcIterator); +}; + + +template inline +void RmEpsilonFst::InitStateIterator(StateIteratorData *data) const { + data->base = new StateIterator< RmEpsilonFst >(*this); +} + + +// Useful alias when using StdArc. +typedef RmEpsilonFst StdRmEpsilonFst; + +} // namespace fst + +#endif // FST_LIB_RMEPSILON_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/rmfinalepsilon.h b/kaldi_io/src/tools/openfst/include/fst/rmfinalepsilon.h new file mode 100644 index 0000000..eb0f937 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/rmfinalepsilon.h @@ -0,0 +1,107 @@ +// rmfinalepsilon.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: johans@google.com (Johan Schalkwyk) +// +// \file +// Function to remove of final states that have epsilon only input arcs. + +#ifndef FST_LIB_RMFINALEPSILON_H__ +#define FST_LIB_RMFINALEPSILON_H__ + +#include +using std::tr1::unordered_set; +using std::tr1::unordered_multiset; +#include +using std::vector; + +#include +#include + + +namespace fst { + +template +void RmFinalEpsilon(MutableFst* fst) { + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + // Determine the coaccesibility of states. + vector access; + vector coaccess; + uint64 props = 0; + SccVisitor scc_visitor(0, &access, &coaccess, &props); + DfsVisit(*fst, &scc_visitor); + + // Find potential list of removable final states. These are final states + // that have no outgoing transitions or final states that have a + // non-coaccessible future. Complexity O(S) + unordered_set finals; + for (StateIterator > siter(*fst); !siter.Done(); siter.Next()) { + StateId s = siter.Value(); + if (fst->Final(s) != Weight::Zero()) { + bool future_coaccess = false; + for (ArcIterator > aiter(*fst, s); !aiter.Done(); aiter.Next()) { + const A& arc = aiter.Value(); + if (coaccess[arc.nextstate]) { + future_coaccess = true; + break; + } + } + if (!future_coaccess) { + finals.insert(s); + } + } + } + + // Move the final weight. Complexity O(E) + vector arcs; + for (StateIterator > siter(*fst); !siter.Done(); siter.Next()) { + StateId s = siter.Value(); + Weight w(fst->Final(s)); + + arcs.clear(); + for (ArcIterator > aiter(*fst, s); !aiter.Done(); aiter.Next()) { + const A& arc = aiter.Value(); + // is next state in the list of finals + if (finals.find(arc.nextstate) != finals.end()) { + // sum up all epsilon arcs + if (arc.ilabel == 0 && arc.olabel == 0) { + w = Plus(Times(fst->Final(arc.nextstate), arc.weight), w); + } else { + arcs.push_back(arc); + } + } else { + arcs.push_back(arc); + } + } + + // If some arcs (epsilon arcs) were deleted, delete all + // arcs and add back only the non epsilon arcs + if (arcs.size() < fst->NumArcs(s)) { + fst->DeleteArcs(s); + fst->SetFinal(s, w); + for (size_t i = 0; i < arcs.size(); ++i) { + fst->AddArc(s, arcs[i]); + } + } + } + + Connect(fst); +} + +} // namespace fst + +#endif // FST_LIB_RMFINALEPSILON_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/arcsort.h b/kaldi_io/src/tools/openfst/include/fst/script/arcsort.h new file mode 100644 index 0000000..4277332 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/arcsort.h @@ -0,0 +1,49 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_ARCSORT_H_ +#define FST_SCRIPT_ARCSORT_H_ + +#include +#include +#include + +namespace fst { +namespace script { + +enum ArcSortType { ILABEL_COMPARE, OLABEL_COMPARE }; + +typedef args::Package ArcSortArgs; + +template +void ArcSort(ArcSortArgs *args) { + MutableFst *fst = args->arg1->GetMutableFst(); + + if (args->arg2 == ILABEL_COMPARE) { + ILabelCompare icomp; + ArcSort(fst, icomp); + } else { // OLABEL_COMPARE + OLabelCompare ocomp; + ArcSort(fst, ocomp); + } +} + +void ArcSort(MutableFstClass *ofst, ArcSortType sort_type); + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_ARCSORT_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/arg-packs.h b/kaldi_io/src/tools/openfst/include/fst/script/arg-packs.h new file mode 100644 index 0000000..8ebf8d8 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/arg-packs.h @@ -0,0 +1,240 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +// Convenience templates for defining arg packs for the FstClass operations. + +// See operation-templates.h for a discussion about why these are needed; the +// short story is that all FstClass operations must be implemented by a version +// that takes one argument, most likely a struct bundling all the +// logical arguments together. These template structs provide convenient ways +// to specify these bundles (e.g. by means of appropriate typedefs). + +// The ArgPack template is sufficient for bundling together all the args for +// a particular function. The function is assumed to be void-returning. If +// you want a space for a return value, use the WithReturnValue template +// as follows: + +// WithReturnValue > + +#ifndef FST_SCRIPT_ARG_PACKS_H_ +#define FST_SCRIPT_ARG_PACKS_H_ + +namespace fst { +namespace script { +namespace args { + +// Sentinel value that means "no arg here." +class none_type { }; + +// Base arg pack template class. Specializations follow that allow +// fewer numbers of arguments (down to 2). If the maximum number of arguments +// increases, you will need to change three things: +// 1) Add more template parameters to this template +// 2) Add more specializations to allow fewer numbers of parameters than +// the new max. +// 3) Add extra none_types to all existing specializations to fill +// the new slots. + + +// 9 args (max) +template +struct Package { + T1 arg1; + T2 arg2; + T3 arg3; + T4 arg4; + T5 arg5; + T6 arg6; + T7 arg7; + T8 arg8; + T9 arg9; + + Package(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, + T7 arg7, T8 arg8, T9 arg9) : + arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4), arg5(arg5), + arg6(arg6), arg7(arg7), arg8(arg8), arg9(arg9) { } +}; + +// 8 args +template +struct Package { + T1 arg1; + T2 arg2; + T3 arg3; + T4 arg4; + T5 arg5; + T6 arg6; + T7 arg7; + T8 arg8; + + Package(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, + T7 arg7, T8 arg8) : + arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4), arg5(arg5), + arg6(arg6), arg7(arg7), arg8(arg8) { } +}; + +// 7 args +template +struct Package { + T1 arg1; + T2 arg2; + T3 arg3; + T4 arg4; + T5 arg5; + T6 arg6; + T7 arg7; + + Package(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, + T7 arg7) : + arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4), arg5(arg5), + arg6(arg6), arg7(arg7) { } +}; + +// 6 args +template +struct Package { + T1 arg1; + T2 arg2; + T3 arg3; + T4 arg4; + T5 arg5; + T6 arg6; + + Package(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) : + arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4), arg5(arg5), + arg6(arg6) { } +}; + +// 5 args +template +struct Package { + T1 arg1; + T2 arg2; + T3 arg3; + T4 arg4; + T5 arg5; + + Package(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) : + arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4), arg5(arg5) { } +}; + +// 4 args +template +struct Package { + T1 arg1; + T2 arg2; + T3 arg3; + T4 arg4; + + Package(T1 arg1, T2 arg2, T3 arg3, T4 arg4) : + arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4) { } +}; + +// 3 args +template +struct Package { + T1 arg1; + T2 arg2; + T3 arg3; + + Package(T1 arg1, T2 arg2, T3 arg3) : + arg1(arg1), arg2(arg2), arg3(arg3) { } +}; + +// 2 args (minimum) +template +struct Package { + T1 arg1; + T2 arg2; + + Package(T1 arg1, T2 arg2) : + arg1(arg1), arg2(arg2) { } +}; + +// Tack this on to an existing arg pack to add a return value. +// The syntax for accessing the args is then slightly more stilted, +// as you must do an extra member access (since the args are stored +// as a member of this class). +// The alternative is to declare another slew of templates for functions +// that return a value, analogous to the above. + +template +struct WithReturnValue { + Retval retval; + const ArgPackage &args; + + explicit WithReturnValue(const ArgPackage &args) : args(args) { } +}; + +// We don't want to store a reference to a reference, if ArgPackage is +// already some reference type. +template +struct WithReturnValue { + Retval retval; + const ArgPackage &args; + + explicit WithReturnValue(const ArgPackage &args) : args(args) { } +}; + +} // namespace args +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_ARG_PACKS_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/closure.h b/kaldi_io/src/tools/openfst/include/fst/script/closure.h new file mode 100644 index 0000000..93b5ec3 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/closure.h @@ -0,0 +1,41 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_CLOSURE_H_ +#define FST_SCRIPT_CLOSURE_H_ + +#include +#include +#include + +namespace fst { +namespace script { + +typedef args::Package ClosureArgs; + +template +void Closure(ClosureArgs *args) { + MutableFst *fst = args->arg1->GetMutableFst(); + + Closure(fst, args->arg2); +} + +void Closure(MutableFstClass *ofst, ClosureType closure_type); + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_CLOSURE_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/compile-impl.h b/kaldi_io/src/tools/openfst/include/fst/script/compile-impl.h new file mode 100644 index 0000000..68f37c3 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/compile-impl.h @@ -0,0 +1,216 @@ +// compile.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Class to to compile a binary Fst from textual input. + +#ifndef FST_SCRIPT_COMPILE_IMPL_H_ +#define FST_SCRIPT_COMPILE_IMPL_H_ + +#include +using std::tr1::unordered_map; +using std::tr1::unordered_multimap; +#include +#include +#include +using std::vector; + +#include +#include +#include +#include +#include +#include + +DECLARE_string(fst_field_separator); + +namespace fst { + +// Compile a binary Fst from textual input, helper class for fstcompile.cc +// WARNING: Stand-alone use of this class not recommended, most code should +// read/write using the binary format which is much more efficient. +template class FstCompiler { + public: + typedef A Arc; + typedef typename A::StateId StateId; + typedef typename A::Label Label; + typedef typename A::Weight Weight; + + // WARNING: use of 'allow_negative_labels = true' not recommended; may + // cause conflicts + FstCompiler(istream &istrm, const string &source, + const SymbolTable *isyms, const SymbolTable *osyms, + const SymbolTable *ssyms, bool accep, bool ikeep, + bool okeep, bool nkeep, bool allow_negative_labels = false) + : nline_(0), source_(source), + isyms_(isyms), osyms_(osyms), ssyms_(ssyms), + nstates_(0), keep_state_numbering_(nkeep), + allow_negative_labels_(allow_negative_labels) { + char line[kLineLen]; + while (istrm.getline(line, kLineLen)) { + ++nline_; + vector col; + string separator = FLAGS_fst_field_separator + "\n"; + SplitToVector(line, separator.c_str(), &col, true); + if (col.size() == 0 || col[0][0] == '\0') // empty line + continue; + if (col.size() > 5 || + (col.size() > 4 && accep) || + (col.size() == 3 && !accep)) { + FSTERROR() << "FstCompiler: Bad number of columns, source = " + << source_ + << ", line = " << nline_; + fst_.SetProperties(kError, kError); + return; + } + StateId s = StrToStateId(col[0]); + while (s >= fst_.NumStates()) + fst_.AddState(); + if (nline_ == 1) + fst_.SetStart(s); + + Arc arc; + StateId d = s; + switch (col.size()) { + case 1: + fst_.SetFinal(s, Weight::One()); + break; + case 2: + fst_.SetFinal(s, StrToWeight(col[1], true)); + break; + case 3: + arc.nextstate = d = StrToStateId(col[1]); + arc.ilabel = StrToILabel(col[2]); + arc.olabel = arc.ilabel; + arc.weight = Weight::One(); + fst_.AddArc(s, arc); + break; + case 4: + arc.nextstate = d = StrToStateId(col[1]); + arc.ilabel = StrToILabel(col[2]); + if (accep) { + arc.olabel = arc.ilabel; + arc.weight = StrToWeight(col[3], false); + } else { + arc.olabel = StrToOLabel(col[3]); + arc.weight = Weight::One(); + } + fst_.AddArc(s, arc); + break; + case 5: + arc.nextstate = d = StrToStateId(col[1]); + arc.ilabel = StrToILabel(col[2]); + arc.olabel = StrToOLabel(col[3]); + arc.weight = StrToWeight(col[4], false); + fst_.AddArc(s, arc); + } + while (d >= fst_.NumStates()) + fst_.AddState(); + } + if (ikeep) + fst_.SetInputSymbols(isyms); + if (okeep) + fst_.SetOutputSymbols(osyms); + } + + const VectorFst &Fst() const { + return fst_; + } + + private: + // Maximum line length in text file. + static const int kLineLen = 8096; + + int64 StrToId(const char *s, const SymbolTable *syms, + const char *name, bool allow_negative = false) const { + int64 n = 0; + + if (syms) { + n = syms->Find(s); + if (n == -1 || (!allow_negative && n < 0)) { + FSTERROR() << "FstCompiler: Symbol \"" << s + << "\" is not mapped to any integer " << name + << ", symbol table = " << syms->Name() + << ", source = " << source_ << ", line = " << nline_; + fst_.SetProperties(kError, kError); + } + } else { + char *p; + n = strtoll(s, &p, 10); + if (p < s + strlen(s) || (!allow_negative && n < 0)) { + FSTERROR() << "FstCompiler: Bad " << name << " integer = \"" << s + << "\", source = " << source_ << ", line = " << nline_; + fst_.SetProperties(kError, kError); + } + } + return n; + } + + StateId StrToStateId(const char *s) { + StateId n = StrToId(s, ssyms_, "state ID"); + + if (keep_state_numbering_) + return n; + + // remap state IDs to make dense set + typename unordered_map::const_iterator it = states_.find(n); + if (it == states_.end()) { + states_[n] = nstates_; + return nstates_++; + } else { + return it->second; + } + } + + StateId StrToILabel(const char *s) const { + return StrToId(s, isyms_, "arc ilabel", allow_negative_labels_); + } + + StateId StrToOLabel(const char *s) const { + return StrToId(s, osyms_, "arc olabel", allow_negative_labels_); + } + + Weight StrToWeight(const char *s, bool allow_zero) const { + Weight w; + istringstream strm(s); + strm >> w; + if (!strm || (!allow_zero && w == Weight::Zero())) { + FSTERROR() << "FstCompiler: Bad weight = \"" << s + << "\", source = " << source_ << ", line = " << nline_; + fst_.SetProperties(kError, kError); + w = Weight::NoWeight(); + } + return w; + } + + mutable VectorFst fst_; + size_t nline_; + string source_; // text FST source name + const SymbolTable *isyms_; // ilabel symbol table + const SymbolTable *osyms_; // olabel symbol table + const SymbolTable *ssyms_; // slabel symbol table + unordered_map states_; // state ID map + StateId nstates_; // number of seen states + bool keep_state_numbering_; + bool allow_negative_labels_; // not recommended; may cause conflicts + + DISALLOW_COPY_AND_ASSIGN(FstCompiler); +}; + +} // namespace fst + +#endif // FST_SCRIPT_COMPILE_IMPL_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/compile.h b/kaldi_io/src/tools/openfst/include/fst/script/compile.h new file mode 100644 index 0000000..bb6ea56 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/compile.h @@ -0,0 +1,92 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_COMPILE_H_ +#define FST_SCRIPT_COMPILE_H_ + +#include +#include +#include + +namespace fst { +namespace script { + +// Note: it is safe to pass these strings as references because +// this struct is only used to pass them deeper in the call graph. +// Be sure you understand why this is so before using this struct +// for anything else! +struct FstCompileArgs { + fst::istream &istrm; + const string &source; + const string &dest; + const string &fst_type; + const fst::SymbolTable *isyms; + const fst::SymbolTable *osyms; + const fst::SymbolTable *ssyms; + const bool accep; + const bool ikeep; + const bool okeep; + const bool nkeep; + const bool allow_negative_labels; + + FstCompileArgs(istream &istrm, const string &source, const string &dest, + const string &fst_type, const fst::SymbolTable *isyms, + const fst::SymbolTable *osyms, + const fst::SymbolTable *ssyms, + bool accep, bool ikeep, bool okeep, bool nkeep, + bool allow_negative_labels = false) : + istrm(istrm), source(source), dest(dest), fst_type(fst_type), + isyms(isyms), osyms(osyms), ssyms(ssyms), accep(accep), ikeep(ikeep), + okeep(okeep), nkeep(nkeep), + allow_negative_labels(allow_negative_labels) { } +}; + +template +void CompileFst(FstCompileArgs *args) { + using fst::FstCompiler; + using fst::Convert; + using fst::Fst; + + FstCompiler fstcompiler(args->istrm, args->source, args->isyms, + args->osyms, args->ssyms, + args->accep, args->ikeep, + args->okeep, args->nkeep, + args->allow_negative_labels); + + const Fst *fst = &fstcompiler.Fst(); + if (args->fst_type != "vector") { + fst = Convert(*fst, args->fst_type); + if (!fst) { + FSTERROR() << "Failed to convert FST to desired type: " + << args->fst_type; + return; + } + } + + fst->Write(args->dest); +} + +void CompileFst(istream &istrm, const string &source, const string &dest, + const string &fst_type, const string &arc_type, + const SymbolTable *isyms, + const SymbolTable *osyms, const SymbolTable *ssyms, + bool accep, bool ikeep, bool okeep, bool nkeep, + bool allow_negative_labels); + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_COMPILE_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/compose.h b/kaldi_io/src/tools/openfst/include/fst/script/compose.h new file mode 100644 index 0000000..96375f7 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/compose.h @@ -0,0 +1,63 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_COMPOSE_H_ +#define FST_SCRIPT_COMPOSE_H_ + +#include +#include +#include + +namespace fst { +namespace script { + +typedef args::Package ComposeArgs1; + +template +void Compose(ComposeArgs1 *args) { + const Fst &ifst1 = *(args->arg1.GetFst()); + const Fst &ifst2 = *(args->arg2.GetFst()); + MutableFst *ofst = args->arg3->GetMutableFst(); + + Compose(ifst1, ifst2, ofst, args->arg4); +} + +typedef fst::ComposeOptions ComposeOptions; + +typedef args::Package ComposeArgs2; + +template +void Compose(ComposeArgs2 *args) { + const Fst &ifst1 = *(args->arg1.GetFst()); + const Fst &ifst2 = *(args->arg2.GetFst()); + MutableFst *ofst = args->arg3->GetMutableFst(); + + Compose(ifst1, ifst2, ofst, args->arg4); +} + +void Compose(const FstClass &ifst1, const FstClass &ifst2, + MutableFstClass *ofst, + const ComposeOptions &opts = fst::script::ComposeOptions()); + +void Compose(const FstClass &ifst1, const FstClass &ifst2, + MutableFstClass *ofst, ComposeFilter compose_filter); + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_COMPOSE_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/concat.h b/kaldi_io/src/tools/openfst/include/fst/script/concat.h new file mode 100644 index 0000000..46c4407 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/concat.h @@ -0,0 +1,54 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_CONCAT_H_ +#define FST_SCRIPT_CONCAT_H_ + +#include +#include +#include + +namespace fst { +namespace script { + +typedef args::Package ConcatArgs1; +typedef args::Package ConcatArgs2; + +template +void Concat(ConcatArgs1 *args) { + MutableFst *ofst = args->arg1->GetMutableFst(); + const Fst &ifst = *(args->arg2.GetFst()); + + Concat(ofst, ifst); +} + +template +void Concat(ConcatArgs2 *args) { + const Fst &ifst = *(args->arg1.GetFst()); + MutableFst *ofst = args->arg2->GetMutableFst(); + + Concat(ifst, ofst); +} + +void Concat(MutableFstClass *ofst, const FstClass &ifst); +void Concat(const FstClass &ifst, MutableFstClass *ofst); + +} // namespace script +} // namespace fst + + + +#endif // FST_SCRIPT_CONCAT_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/connect.h b/kaldi_io/src/tools/openfst/include/fst/script/connect.h new file mode 100644 index 0000000..19c4390 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/connect.h @@ -0,0 +1,45 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_CONNECT_H_ +#define FST_SCRIPT_CONNECT_H_ + +#include +#include +#include +#include + +namespace fst { +namespace script { + +// This function confuses SWIG, because both versions have the same args +#ifndef SWIG +template +void Connect(MutableFstClass *fst) { + MutableFst *typed_fst = fst->GetMutableFst(); + + Connect(typed_fst); +} +#endif + +void Connect(MutableFstClass *fst); + +} // namespace script +} // namespace fst + + + +#endif // FST_SCRIPT_CONNECT_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/convert.h b/kaldi_io/src/tools/openfst/include/fst/script/convert.h new file mode 100644 index 0000000..4a3ce6b --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/convert.h @@ -0,0 +1,49 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_CONVERT_H_ +#define FST_SCRIPT_CONVERT_H_ + +#include + +#include +#include + +namespace fst { +namespace script { + +typedef args::Package ConvertInnerArgs; +typedef args::WithReturnValue ConvertArgs; + +template +void Convert(ConvertArgs *args) { + const Fst &fst = *(args->args.arg1.GetFst()); + const string &new_type = args->args.arg2; + + Fst *result = Convert(fst, new_type); + args->retval = new FstClass(*result); + delete result; +} + +#ifdef SWIG +%newobject Convert; +#endif +FstClass *Convert(const FstClass& f, const string &new_type); + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_CONVERT_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/decode.h b/kaldi_io/src/tools/openfst/include/fst/script/decode.h new file mode 100644 index 0000000..1064ad5 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/decode.h @@ -0,0 +1,46 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_DECODE_H_ +#define FST_SCRIPT_DECODE_H_ + +#include + +#include +#include +#include + +namespace fst { +namespace script { + +typedef args::Package DecodeArgs; + +template +void Decode(DecodeArgs *args) { + MutableFst *ofst = args->arg1->GetMutableFst(); + + EncodeMapper *decoder = EncodeMapper::Read(args->arg2, DECODE); + Decode(ofst, *decoder); + + delete decoder; +} + +void Decode(MutableFstClass *fst, const string &coder_fname); + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_DECODE_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/determinize.h b/kaldi_io/src/tools/openfst/include/fst/script/determinize.h new file mode 100644 index 0000000..38fd7ad --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/determinize.h @@ -0,0 +1,68 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_DETERMINIZE_H_ +#define FST_SCRIPT_DETERMINIZE_H_ + +#include +#include +#include +#include + +namespace fst { +namespace script { + +struct DeterminizeOptions { + float delta; + WeightClass weight_threshold; + int64 state_threshold; + int64 subsequential_label; + + explicit DeterminizeOptions(float d = fst::kDelta, + WeightClass w = + fst::script::WeightClass::Zero(), + int64 n = fst::kNoStateId, int64 l = 0) + : delta(d), weight_threshold(w), state_threshold(n), + subsequential_label(l) {} +}; + +typedef args::Package DeterminizeArgs; + +template +void Determinize(DeterminizeArgs *args) { + const Fst &ifst = *(args->arg1.GetFst()); + MutableFst *ofst = args->arg2->GetMutableFst(); + const DeterminizeOptions &opts = args->arg3; + + fst::DeterminizeOptions detargs; + detargs.delta = opts.delta; + detargs.weight_threshold = + *(opts.weight_threshold.GetWeight()); + detargs.state_threshold = opts.state_threshold; + detargs.subsequential_label = opts.subsequential_label; + + Determinize(ifst, ofst, detargs); +} + +void Determinize(const FstClass &ifst, MutableFstClass *ofst, + const DeterminizeOptions &opts = + fst::script::DeterminizeOptions()); + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_DETERMINIZE_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/difference.h b/kaldi_io/src/tools/openfst/include/fst/script/difference.h new file mode 100644 index 0000000..76490d4 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/difference.h @@ -0,0 +1,67 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_DIFFERENCE_H_ +#define FST_SCRIPT_DIFFERENCE_H_ + +#include +#include +#include // for ComposeFilter +#include + +namespace fst { +namespace script { + +typedef args::Package DifferenceArgs1; + +template +void Difference(DifferenceArgs1 *args) { + const Fst &ifst1 = *(args->arg1.GetFst()); + const Fst &ifst2 = *(args->arg2.GetFst()); + MutableFst *ofst = args->arg3->GetMutableFst(); + + Difference(ifst1, ifst2, ofst, args->arg4); +} + +typedef args::Package DifferenceArgs2; + +template +void Difference(DifferenceArgs2 *args) { + const Fst &ifst1 = *(args->arg1.GetFst()); + const Fst &ifst2 = *(args->arg2.GetFst()); + MutableFst *ofst = args->arg3->GetMutableFst(); + + Difference(ifst1, ifst2, ofst, args->arg4); +} + + +void Difference(const FstClass &ifst1, const FstClass &ifst2, + MutableFstClass *ofst, + ComposeFilter compose_filter); + +void Difference(const FstClass &ifst1, const FstClass &ifst2, + MutableFstClass *ofst, + const ComposeOptions &opts = fst::script::ComposeOptions()); + + +} // namespace script +} // namespace fst + + + +#endif // FST_SCRIPT_DIFFERENCE_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/disambiguate.h b/kaldi_io/src/tools/openfst/include/fst/script/disambiguate.h new file mode 100644 index 0000000..e42a9c2 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/disambiguate.h @@ -0,0 +1,68 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_DISAMBIGUATE_H_ +#define FST_SCRIPT_DISAMBIGUATE_H_ + +#include +#include +#include +#include + +namespace fst { +namespace script { + +struct DisambiguateOptions { + float delta; + WeightClass weight_threshold; + int64 state_threshold; + int64 subsequential_label; + + explicit DisambiguateOptions(float d = fst::kDelta, + WeightClass w = + fst::script::WeightClass::Zero(), + int64 n = fst::kNoStateId, int64 l = 0) + : delta(d), weight_threshold(w), state_threshold(n), + subsequential_label(l) {} +}; + +typedef args::Package DisambiguateArgs; + +template +void Disambiguate(DisambiguateArgs *args) { + const Fst &ifst = *(args->arg1.GetFst()); + MutableFst *ofst = args->arg2->GetMutableFst(); + const DisambiguateOptions &opts = args->arg3; + + fst::DisambiguateOptions detargs; + detargs.delta = opts.delta; + detargs.weight_threshold = + *(opts.weight_threshold.GetWeight()); + detargs.state_threshold = opts.state_threshold; + detargs.subsequential_label = opts.subsequential_label; + + Disambiguate(ifst, ofst, detargs); +} + +void Disambiguate(const FstClass &ifst, MutableFstClass *ofst, + const DisambiguateOptions &opts = + fst::script::DisambiguateOptions()); + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_DISAMBIGUATE_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/draw-impl.h b/kaldi_io/src/tools/openfst/include/fst/script/draw-impl.h new file mode 100644 index 0000000..893e258 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/draw-impl.h @@ -0,0 +1,234 @@ +// draw.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: allauzen@google.com (Cyril Allauzen) +// +// \file +// Class to draw a binary FST by producing a text file in dot format, +// helper class to fstdraw.cc + +#ifndef FST_SCRIPT_DRAW_IMPL_H_ +#define FST_SCRIPT_DRAW_IMPL_H_ + +#include +#include + +#include +#include +#include + +namespace fst { + +// Print a binary Fst in the dot textual format, helper class for fstdraw.cc +// WARNING: Stand-alone use not recommend. +template class FstDrawer { + public: + typedef A Arc; + typedef typename A::StateId StateId; + typedef typename A::Label Label; + typedef typename A::Weight Weight; + + FstDrawer(const Fst &fst, + const SymbolTable *isyms, + const SymbolTable *osyms, + const SymbolTable *ssyms, + bool accep, + string title, + float width, + float height, + bool portrait, + bool vertical, + float ranksep, + float nodesep, + int fontsize, + int precision, + bool show_weight_one) + : fst_(fst), isyms_(isyms), osyms_(osyms), ssyms_(ssyms), + accep_(accep && fst.Properties(kAcceptor, true)), ostrm_(0), + title_(title), width_(width), height_(height), portrait_(portrait), + vertical_(vertical), ranksep_(ranksep), nodesep_(nodesep), + fontsize_(fontsize), precision_(precision), + show_weight_one_(show_weight_one) {} + + // Draw Fst to an output buffer (or stdout if buf = 0) + void Draw(ostream *strm, const string &dest) { + ostrm_ = strm; + dest_ = dest; + StateId start = fst_.Start(); + if (start == kNoStateId) + return; + + PrintString("digraph FST {\n"); + if (vertical_) + PrintString("rankdir = BT;\n"); + else + PrintString("rankdir = LR;\n"); + PrintString("size = \""); + Print(width_); + PrintString(","); + Print(height_); + PrintString("\";\n"); + if (!dest_.empty()) + PrintString("label = \"" + title_ + "\";\n"); + PrintString("center = 1;\n"); + if (portrait_) + PrintString("orientation = Portrait;\n"); + else + PrintString("orientation = Landscape;\n"); + PrintString("ranksep = \""); + Print(ranksep_); + PrintString("\";\n"); + PrintString("nodesep = \""); + Print(nodesep_); + PrintString("\";\n"); + // initial state first + DrawState(start); + for (StateIterator< Fst > siter(fst_); + !siter.Done(); + siter.Next()) { + StateId s = siter.Value(); + if (s != start) + DrawState(s); + } + PrintString("}\n"); + } + + private: + // Maximum line length in text file. + static const int kLineLen = 8096; + + void PrintString(const string &s) const { + *ostrm_ << s; + } + + // Escapes backslash and double quote if these occur in the string. Dot will + // not deal gracefully with these if they are not escaped. + inline void EscapeChars(const string &s, string* ns) const { + const char* c = s.c_str(); + while (*c) { + if (*c == '\\' || *c == '"') ns->push_back('\\'); + ns->push_back(*c); + ++c; + } + } + + void PrintId(int64 id, const SymbolTable *syms, + const char *name) const { + if (syms) { + string symbol = syms->Find(id); + if (symbol == "") { + FSTERROR() << "FstDrawer: Integer " << id + << " is not mapped to any textual symbol" + << ", symbol table = " << syms->Name() + << ", destination = " << dest_; + symbol = "?"; + } + string nsymbol; + EscapeChars(symbol, &nsymbol); + PrintString(nsymbol); + } else { + string idstr; + Int64ToStr(id, &idstr); + PrintString(idstr); + } + } + + void PrintStateId(StateId s) const { + PrintId(s, ssyms_, "state ID"); + } + + void PrintILabel(Label l) const { + PrintId(l, isyms_, "arc input label"); + } + + void PrintOLabel(Label l) const { + PrintId(l, osyms_, "arc output label"); + } + + template + void Print(T t) const { + *ostrm_ << t; + } + + void DrawState(StateId s) const { + Print(s); + PrintString(" [label = \""); + PrintStateId(s); + Weight final = fst_.Final(s); + if (final != Weight::Zero()) { + if (show_weight_one_ || (final != Weight::One())) { + PrintString("/"); + Print(final); + } + PrintString("\", shape = doublecircle,"); + } else { + PrintString("\", shape = circle,"); + } + if (s == fst_.Start()) + PrintString(" style = bold,"); + else + PrintString(" style = solid,"); + PrintString(" fontsize = "); + Print(fontsize_); + PrintString("]\n"); + for (ArcIterator< Fst > aiter(fst_, s); + !aiter.Done(); + aiter.Next()) { + Arc arc = aiter.Value(); + PrintString("\t"); + Print(s); + PrintString(" -> "); + Print(arc.nextstate); + PrintString(" [label = \""); + PrintILabel(arc.ilabel); + if (!accep_) { + PrintString(":"); + PrintOLabel(arc.olabel); + } + if (show_weight_one_ || (arc.weight != Weight::One())) { + PrintString("/"); + Print(arc.weight); + } + PrintString("\", fontsize = "); + Print(fontsize_); + PrintString("];\n"); + } + } + + const Fst &fst_; + const SymbolTable *isyms_; // ilabel symbol table + const SymbolTable *osyms_; // olabel symbol table + const SymbolTable *ssyms_; // slabel symbol table + bool accep_; // print as acceptor when possible + ostream *ostrm_; // drawn FST destination + string dest_; // drawn FST destination name + + string title_; + float width_; + float height_; + bool portrait_; + bool vertical_; + float ranksep_; + float nodesep_; + int fontsize_; + int precision_; + bool show_weight_one_; + + DISALLOW_COPY_AND_ASSIGN(FstDrawer); +}; + +} // namespace fst + +#endif // FST_SCRIPT_DRAW_IMPL_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/draw.h b/kaldi_io/src/tools/openfst/include/fst/script/draw.h new file mode 100644 index 0000000..2b66373 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/draw.h @@ -0,0 +1,114 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_DRAW_H_ +#define FST_SCRIPT_DRAW_H_ + +#include +#include +#include +#include +#include +#include + +namespace fst { +namespace script { + +// Note: it is safe to pass these strings as references because +// this struct is only used to pass them deeper in the call graph. +// Be sure you understand why this is so before using this struct +// for anything else! +struct FstDrawerArgs { + const FstClass &fst; + const SymbolTable *isyms; + const SymbolTable *osyms; + const SymbolTable *ssyms; + const bool accep; + const string& title; + const float width; + const float height; + const bool portrait; + const bool vertical; + const float ranksep; + const float nodesep; + const int fontsize; + const int precision; + const bool show_weight_one; + ostream *ostrm; + const string &dest; + + FstDrawerArgs(const FstClass &fst, + const SymbolTable *isyms, + const SymbolTable *osyms, + const SymbolTable *ssyms, + bool accep, + const string &title, + float width, + float height, + bool portrait, + bool vertical, + float ranksep, + float nodesep, + int fontsize, + int precision, + bool show_weight_one, + ostream *ostrm, + const string &dest) : + fst(fst), isyms(isyms), osyms(osyms), ssyms(ssyms), accep(accep), + title(title), width(width), height(height), portrait(portrait), + vertical(vertical), ranksep(ranksep), nodesep(nodesep), + fontsize(fontsize), precision(precision), + show_weight_one(show_weight_one), ostrm(ostrm), dest(dest) { } +}; + + +template +void DrawFst(FstDrawerArgs *args) { + const Fst &fst = *(args->fst.GetFst()); + + FstDrawer fstdrawer(fst, args->isyms, args->osyms, args->ssyms, + args->accep, args->title, args->width, + args->height, args->portrait, + args->vertical, args->ranksep, + args->nodesep, args->fontsize, + args->precision, args->show_weight_one); + fstdrawer.Draw(args->ostrm, args->dest); +} + +void DrawFst(const FstClass &fst, + const SymbolTable *isyms, + const SymbolTable *osyms, + const SymbolTable *ssyms, + bool accep, + const string &title, + float width, + float height, + bool portrait, + bool vertical, + float ranksep, + float nodesep, + int fontsize, + int precision, + bool show_weight_one, + ostream *ostrm, + const string &dest); + +} // namespace script +} // namespace fst + + + +#endif // FST_SCRIPT_DRAW_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/encode.h b/kaldi_io/src/tools/openfst/include/fst/script/encode.h new file mode 100644 index 0000000..dc1a290 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/encode.h @@ -0,0 +1,58 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_ENCODE_H_ +#define FST_SCRIPT_ENCODE_H_ + +#include + +#include +#include +#include + +namespace fst { +namespace script { + +typedef args::Package EncodeArgs; + +template +void Encode(EncodeArgs *args) { + MutableFst *ofst = args->arg1->GetMutableFst(); + bool reuse_encoder = args->arg3; + const string &coder_fname = args->arg4; + uint32 flags = args->arg2; + + EncodeMapper *encoder = reuse_encoder + ? EncodeMapper::Read(coder_fname, ENCODE) + : new EncodeMapper(flags, ENCODE); + + Encode(ofst, encoder); + if (!args->arg3) + encoder->Write(coder_fname); + + delete encoder; +} + +void Encode(MutableFstClass *fst, uint32 flags, bool reuse_encoder, + const string &coder_fname); + +} // namespace script +} // namespace fst + + + +#endif // FST_SCRIPT_ENCODE_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/epsnormalize.h b/kaldi_io/src/tools/openfst/include/fst/script/epsnormalize.h new file mode 100644 index 0000000..50b12da --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/epsnormalize.h @@ -0,0 +1,44 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_EPSNORMALIZE_H_ +#define FST_SCRIPT_EPSNORMALIZE_H_ + +#include +#include +#include + +namespace fst { +namespace script { + +typedef args::Package EpsNormalizeArgs; + +template +void EpsNormalize(EpsNormalizeArgs *args) { + const Fst &ifst = *(args->arg1.GetFst()); + MutableFst *ofst = args->arg2->GetMutableFst(); + + EpsNormalize(ifst, ofst, args->arg3); +} + +void EpsNormalize(const FstClass &ifst, MutableFstClass *ofst, + EpsNormalizeType norm_type = EPS_NORM_INPUT); + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_EPSNORMALIZE_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/equal.h b/kaldi_io/src/tools/openfst/include/fst/script/equal.h new file mode 100644 index 0000000..9fb2d3c --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/equal.h @@ -0,0 +1,45 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_EQUAL_H_ +#define FST_SCRIPT_EQUAL_H_ + +#include +#include +#include + +namespace fst { +namespace script { + +typedef args::Package EqualInnerArgs; +typedef args::WithReturnValue EqualArgs; + +template +void Equal(EqualArgs *args) { + const Fst &fst1 = *(args->args.arg1.GetFst()); + const Fst &fst2 = *(args->args.arg2.GetFst()); + + args->retval = Equal(fst1, fst2, args->args.arg3); +} + +bool Equal(const FstClass &fst1, const FstClass &fst2, + float delta = kDelta); + +} // namespace script +} // namespace fst + + +#endif // FST_SCRIPT_EQUAL_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/equivalent.h b/kaldi_io/src/tools/openfst/include/fst/script/equivalent.h new file mode 100644 index 0000000..43460c6 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/equivalent.h @@ -0,0 +1,47 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_EQUIVALENT_H_ +#define FST_SCRIPT_EQUIVALENT_H_ + +#include +#include +#include + +namespace fst { +namespace script { + +typedef args::Package EquivalentInnerArgs; +typedef args::WithReturnValue EquivalentArgs; + +template +void Equivalent(EquivalentArgs *args) { + const Fst &fst1 = *(args->args.arg1.GetFst()); + const Fst &fst2 = *(args->args.arg2.GetFst()); + + args->retval = Equivalent(fst1, fst2, args->args.arg3); +} + +bool Equivalent(const FstClass &fst1, const FstClass &fst2, + float delta = kDelta); + +} // namespace script +} // namespace fst + + + +#endif // FST_SCRIPT_EQUIVALENT_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/fst-class.h b/kaldi_io/src/tools/openfst/include/fst/script/fst-class.h new file mode 100644 index 0000000..fe2cf53 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/fst-class.h @@ -0,0 +1,382 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_FST_CLASS_H_ +#define FST_SCRIPT_FST_CLASS_H_ + +#include + +#include +#include +#include +#include +#include +#include + +// Classes to support "boxing" all existing types of FST arcs in a single +// FstClass which hides the arc types. This allows clients to load +// and work with FSTs without knowing the arc type. + +// These classes are only recommended for use in high-level scripting +// applications. Most users should use the lower-level templated versions +// corresponding to these classes. + +namespace fst { +namespace script { + +// +// Abstract base class defining the set of functionalities implemented +// in all impls, and passed through by all bases Below FstClassBase +// the class hierarchy bifurcates; FstClassImplBase serves as the base +// class for all implementations (of which FstClassImpl is currently +// the only one) and FstClass serves as the base class for all +// interfaces. +// +class FstClassBase { + public: + virtual const string &ArcType() const = 0; + virtual const string &FstType() const = 0; + virtual const string &WeightType() const = 0; + virtual const SymbolTable *InputSymbols() const = 0; + virtual const SymbolTable *OutputSymbols() const = 0; + virtual bool Write(const string& fname) const = 0; + virtual bool Write(ostream &ostr, const FstWriteOptions &opts) const = 0; + virtual uint64 Properties(uint64 mask, bool test) const = 0; + virtual ~FstClassBase() { } +}; + +class FstClassImplBase : public FstClassBase { + public: + virtual FstClassImplBase *Copy() = 0; + virtual void SetInputSymbols(SymbolTable *is) = 0; + virtual void SetOutputSymbols(SymbolTable *is) = 0; + virtual ~FstClassImplBase() { } +}; + + +// +// CONTAINER CLASS +// Wraps an Fst, hiding its arc type. Whether this Fst +// pointer refers to a special kind of FST (e.g. a MutableFst) is +// known by the type of interface class that owns the pointer to this +// container. +// + +template +class FstClassImpl : public FstClassImplBase { + public: + explicit FstClassImpl(Fst *impl, + bool should_own = false) : + impl_(should_own ? impl : impl->Copy()) { } + + explicit FstClassImpl(const Fst &impl) : impl_(impl.Copy()) { } + + virtual const string &ArcType() const { + return Arc::Type(); + } + + virtual const string &FstType() const { + return impl_->Type(); + } + + virtual const string &WeightType() const { + return Arc::Weight::Type(); + } + + virtual const SymbolTable *InputSymbols() const { + return impl_->InputSymbols(); + } + + virtual const SymbolTable *OutputSymbols() const { + return impl_->OutputSymbols(); + } + + // Warning: calling this method casts the FST to a mutable FST. + virtual void SetInputSymbols(SymbolTable *is) { + static_cast *>(impl_)->SetInputSymbols(is); + } + + // Warning: calling this method casts the FST to a mutable FST. + virtual void SetOutputSymbols(SymbolTable *os) { + static_cast *>(impl_)->SetOutputSymbols(os); + } + + virtual bool Write(const string &fname) const { + return impl_->Write(fname); + } + + virtual bool Write(ostream &ostr, const FstWriteOptions &opts) const { + return impl_->Write(ostr, opts); + } + + virtual uint64 Properties(uint64 mask, bool test) const { + return impl_->Properties(mask, test); + } + + virtual ~FstClassImpl() { delete impl_; } + + Fst *GetImpl() const { return impl_; } + + Fst *GetImpl() { return impl_; } + + virtual FstClassImpl *Copy() { + return new FstClassImpl(impl_); + } + + private: + Fst *impl_; +}; + +// +// BASE CLASS DEFINITIONS +// + +class MutableFstClass; + +class FstClass : public FstClassBase { + public: + template + static FstClass *Read(istream &stream, + const FstReadOptions &opts) { + if (!opts.header) { + FSTERROR() << "FstClass::Read: options header not specified"; + return 0; + } + const FstHeader &hdr = *opts.header; + + if (hdr.Properties() & kMutable) { + return ReadTypedFst >(stream, opts); + } else { + return ReadTypedFst >(stream, opts); + } + } + + FstClass() : impl_(NULL) { + } + + template + explicit FstClass(const Fst &fst) : impl_(new FstClassImpl(fst)) { + } + + FstClass(const FstClass &other) : impl_(other.impl_->Copy()) { } + + FstClass &operator=(const FstClass &other) { + delete impl_; + impl_ = other.impl_->Copy(); + return *this; + } + + static FstClass *Read(const string &fname); + + static FstClass *Read(istream &istr, const string &source); + + virtual const string &ArcType() const { + return impl_->ArcType(); + } + + virtual const string& FstType() const { + return impl_->FstType(); + } + + virtual const SymbolTable *InputSymbols() const { + return impl_->InputSymbols(); + } + + virtual const SymbolTable *OutputSymbols() const { + return impl_->OutputSymbols(); + } + + virtual const string& WeightType() const { + return impl_->WeightType(); + } + + virtual bool Write(const string &fname) const { + return impl_->Write(fname); + } + + virtual bool Write(ostream &ostr, const FstWriteOptions &opts) const { + return impl_->Write(ostr, opts); + } + + virtual uint64 Properties(uint64 mask, bool test) const { + return impl_->Properties(mask, test); + } + + template + const Fst *GetFst() const { + if (Arc::Type() != ArcType()) { + return NULL; + } else { + FstClassImpl *typed_impl = static_cast *>(impl_); + return typed_impl->GetImpl(); + } + } + + virtual ~FstClass() { delete impl_; } + + // These methods are required by IO registration + template + static FstClassImplBase *Convert(const FstClass &other) { + LOG(ERROR) << "Doesn't make sense to convert any class to type FstClass."; + return 0; + } + + template + static FstClassImplBase *Create() { + LOG(ERROR) << "Doesn't make sense to create an FstClass with a " + << "particular arc type."; + return 0; + } + + + protected: + explicit FstClass(FstClassImplBase *impl) : impl_(impl) { } + + // Generic template method for reading an arc-templated FST of type + // UnderlyingT, and returning it wrapped as FstClassT, with appropriate + // error checking. Called from arc-templated Read() static methods. + template + static FstClassT* ReadTypedFst(istream &stream, + const FstReadOptions &opts) { + UnderlyingT *u = UnderlyingT::Read(stream, opts); + if (!u) { + return 0; + } else { + FstClassT *r = new FstClassT(*u); + delete u; + return r; + } + } + + FstClassImplBase *GetImpl() const { return impl_; } + + FstClassImplBase *GetImpl() { return impl_; } + +// friend ostream &operator<<(ostream&, const FstClass&); + + private: + FstClassImplBase *impl_; +}; + +// +// Specific types of FstClass with special properties +// + +class MutableFstClass : public FstClass { + public: + template + explicit MutableFstClass(const MutableFst &fst) : + FstClass(fst) { } + + template + MutableFst *GetMutableFst() { + Fst *fst = const_cast *>(this->GetFst()); + MutableFst *mfst = static_cast *>(fst); + + return mfst; + } + + template + static MutableFstClass *Read(istream &stream, + const FstReadOptions &opts) { + MutableFst *mfst = MutableFst::Read(stream, opts); + if (!mfst) { + return 0; + } else { + MutableFstClass *retval = new MutableFstClass(*mfst); + delete mfst; + return retval; + } + } + + virtual bool Write(const string &fname) const { + return GetImpl()->Write(fname); + } + + virtual bool Write(ostream &ostr, const FstWriteOptions &opts) const { + return GetImpl()->Write(ostr, opts); + } + + static MutableFstClass *Read(const string &fname, bool convert = false); + + virtual void SetInputSymbols(SymbolTable *is) { + GetImpl()->SetInputSymbols(is); + } + + virtual void SetOutputSymbols(SymbolTable *os) { + GetImpl()->SetOutputSymbols(os); + } + + // These methods are required by IO registration + template + static FstClassImplBase *Convert(const FstClass &other) { + LOG(ERROR) << "Doesn't make sense to convert any class to type " + << "MutableFstClass."; + return 0; + } + + template + static FstClassImplBase *Create() { + LOG(ERROR) << "Doesn't make sense to create a MutableFstClass with a " + << "particular arc type."; + return 0; + } + + protected: + explicit MutableFstClass(FstClassImplBase *impl) : FstClass(impl) { } +}; + + +class VectorFstClass : public MutableFstClass { + public: + explicit VectorFstClass(const FstClass &other); + explicit VectorFstClass(const string &arc_type); + + template + explicit VectorFstClass(const VectorFst &fst) : + MutableFstClass(fst) { } + + template + static VectorFstClass *Read(istream &stream, + const FstReadOptions &opts) { + VectorFst *vfst = VectorFst::Read(stream, opts); + if (!vfst) { + return 0; + } else { + VectorFstClass *retval = new VectorFstClass(*vfst); + delete vfst; + return retval; + } + } + + static VectorFstClass *Read(const string &fname); + + // Converter / creator for known arc types + template + static FstClassImplBase *Convert(const FstClass &other) { + return new FstClassImpl(new VectorFst( + *other.GetFst()), true); + } + + template + static FstClassImplBase *Create() { + return new FstClassImpl(new VectorFst(), true); + } +}; + +} // namespace script +} // namespace fst +#endif // FST_SCRIPT_FST_CLASS_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/fstscript-decl.h b/kaldi_io/src/tools/openfst/include/fst/script/fstscript-decl.h new file mode 100644 index 0000000..fee813e --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/fstscript-decl.h @@ -0,0 +1,35 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +// Forward declarations for the FST and FST-script classes. + +#ifndef FST_SCRIPT_FSTSCRIPT_DECL_H_ +#define FST_SCRIPT_FSTSCRIPT_DECL_H_ + +#include + +namespace fst { +namespace script { + +class FstClass; +class MutableFstClass; +class VectorFstClass; +class WeightClass; + +} // namespace script +} // namespace fst; + +#endif // FST_SCRIPT_FSTSCRIPT_DECL_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/fstscript.h b/kaldi_io/src/tools/openfst/include/fst/script/fstscript.h new file mode 100644 index 0000000..90e1e75 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/fstscript.h @@ -0,0 +1,154 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +// Convenience file that includes all FstScript functionality + +#ifndef FST_SCRIPT_FSTSCRIPT_H_ +#define FST_SCRIPT_FSTSCRIPT_H_ + +// Major classes +#include +#include +#include + +// Templates like Operation< >, Apply< > +#include + +// Operations +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// +// REGISTER OPERATIONS +// + + +// This class is necessary because registering each of the operations +// separately overfills the stack, as there's so many of them. +namespace fst { +namespace script { +template +class AllFstOperationsRegisterer { + public: + AllFstOperationsRegisterer() { + RegisterBatch1(); + RegisterBatch2(); + } + + private: + void RegisterBatch1() { + REGISTER_FST_OPERATION(ArcSort, Arc, ArcSortArgs); + REGISTER_FST_OPERATION(Closure, Arc, ClosureArgs); + REGISTER_FST_OPERATION(CompileFst, Arc, FstCompileArgs); + REGISTER_FST_OPERATION(Compose, Arc, ComposeArgs1); + REGISTER_FST_OPERATION(Compose, Arc, ComposeArgs2); + REGISTER_FST_OPERATION(Concat, Arc, ConcatArgs1); + REGISTER_FST_OPERATION(Concat, Arc, ConcatArgs2); + REGISTER_FST_OPERATION(Connect, Arc, MutableFstClass); + REGISTER_FST_OPERATION(Convert, Arc, ConvertArgs); + REGISTER_FST_OPERATION(Decode, Arc, DecodeArgs); + REGISTER_FST_OPERATION(Determinize, Arc, DeterminizeArgs); + REGISTER_FST_OPERATION(Difference, Arc, DifferenceArgs1); + REGISTER_FST_OPERATION(Difference, Arc, DifferenceArgs2); + REGISTER_FST_OPERATION(DrawFst, Arc, FstDrawerArgs); + REGISTER_FST_OPERATION(Encode, Arc, EncodeArgs); + REGISTER_FST_OPERATION(EpsNormalize, Arc, EpsNormalizeArgs); + REGISTER_FST_OPERATION(Equal, Arc, EqualArgs); + REGISTER_FST_OPERATION(Equivalent, Arc, EquivalentArgs); + REGISTER_FST_OPERATION(PrintFstInfo, Arc, InfoArgs); + REGISTER_FST_OPERATION(Intersect, Arc, IntersectArgs1); + REGISTER_FST_OPERATION(Intersect, Arc, IntersectArgs2); + REGISTER_FST_OPERATION(Invert, Arc, MutableFstClass); + REGISTER_FST_OPERATION(Map, Arc, MapArgs); + REGISTER_FST_OPERATION(Minimize, Arc, MinimizeArgs); + } + + void RegisterBatch2() { + REGISTER_FST_OPERATION(PrintFst, Arc, FstPrinterArgs); + REGISTER_FST_OPERATION(Project, Arc, ProjectArgs); + REGISTER_FST_OPERATION(Prune, Arc, PruneArgs1); + REGISTER_FST_OPERATION(Prune, Arc, PruneArgs2); + REGISTER_FST_OPERATION(Prune, Arc, PruneArgs3); + REGISTER_FST_OPERATION(Prune, Arc, PruneArgs4); + REGISTER_FST_OPERATION(Push, Arc, PushArgs1); + REGISTER_FST_OPERATION(Push, Arc, PushArgs2); + REGISTER_FST_OPERATION(RandEquivalent, Arc, RandEquivalentArgs1); + REGISTER_FST_OPERATION(RandEquivalent, Arc, RandEquivalentArgs2); + REGISTER_FST_OPERATION(RandGen, Arc, RandGenArgs); + REGISTER_FST_OPERATION(Relabel, Arc, RelabelArgs1); + REGISTER_FST_OPERATION(Relabel, Arc, RelabelArgs2); + REGISTER_FST_OPERATION(Relabel, Arc, RelabelArgs3); + REGISTER_FST_OPERATION(Replace, Arc, ReplaceArgs); + REGISTER_FST_OPERATION(Reverse, Arc, ReverseArgs); + REGISTER_FST_OPERATION(Reweight, Arc, ReweightArgs); + REGISTER_FST_OPERATION(RmEpsilon, Arc, RmEpsilonArgs1); + REGISTER_FST_OPERATION(RmEpsilon, Arc, RmEpsilonArgs2); + REGISTER_FST_OPERATION(RmEpsilon, Arc, RmEpsilonArgs3); + REGISTER_FST_OPERATION(ShortestDistance, Arc, ShortestDistanceArgs1); + REGISTER_FST_OPERATION(ShortestDistance, Arc, ShortestDistanceArgs2); + REGISTER_FST_OPERATION(ShortestDistance, Arc, ShortestDistanceArgs3); + REGISTER_FST_OPERATION(ShortestPath, Arc, ShortestPathArgs1); + REGISTER_FST_OPERATION(ShortestPath, Arc, ShortestPathArgs2); + REGISTER_FST_OPERATION(Synchronize, Arc, SynchronizeArgs); + REGISTER_FST_OPERATION(TopSort, Arc, TopSortArgs); + REGISTER_FST_OPERATION(Union, Arc, UnionArgs); + REGISTER_FST_OPERATION(Verify, Arc, VerifyArgs); + } +}; +} // namespace script +} // namespace fst + + +#define REGISTER_FST_OPERATIONS(Arc) \ + AllFstOperationsRegisterer register_all_fst_operations ## Arc; + +#endif // FST_SCRIPT_FSTSCRIPT_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/info-impl.h b/kaldi_io/src/tools/openfst/include/fst/script/info-impl.h new file mode 100644 index 0000000..408fbcd --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/info-impl.h @@ -0,0 +1,325 @@ +// info.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Class to compute various information about FSTs, helper class for fstinfo.cc + +#ifndef FST_SCRIPT_INFO_IMPL_H_ +#define FST_SCRIPT_INFO_IMPL_H_ + +#include +#include +using std::vector; + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace fst { + +// Compute various information about FSTs, helper class for fstinfo.cc. +// WARNING: Stand-alone use of this class is not recommended, most code +// should call directly the relevant library functions: Fst::NumStates, +// Fst::NumArcs, TestProperties, ... +template class FstInfo { + public: + typedef A Arc; + typedef typename A::StateId StateId; + typedef typename A::Label Label; + typedef typename A::Weight Weight; + + // When info_type is "short" (or "auto" and not an ExpandedFst) + // then only minimal info is computed and can be requested. + FstInfo(const Fst &fst, bool test_properties, + const string &arc_filter_type = "any", + string info_type = "auto", bool verify = true) + : fst_type_(fst.Type()), + input_symbols_(fst.InputSymbols() ? + fst.InputSymbols()->Name() : "none"), + output_symbols_(fst.OutputSymbols() ? + fst.OutputSymbols()->Name() : "none"), + nstates_(0), narcs_(0), start_(kNoStateId), nfinal_(0), + nepsilons_(0), niepsilons_(0), noepsilons_(0), + naccess_(0), ncoaccess_(0), nconnect_(0), ncc_(0), nscc_(0), + input_match_type_(MATCH_NONE), output_match_type_(MATCH_NONE), + input_lookahead_(false), output_lookahead_(false), + properties_(0), arc_filter_type_(arc_filter_type), long_info_(true) { + if (info_type == "long") { + long_info_ = true; + } else if (info_type == "short") { + long_info_ = false; + } else if (info_type == "auto") { + long_info_ = fst.Properties(kExpanded, false); + } else { + FSTERROR() << "Bad info type: " << info_type; + return; + } + + if (!long_info_) + return; + + // If the FST is not sane, we return. + if (verify && !Verify(fst)) { + FSTERROR() << "FstInfo: Verify: FST not well-formed."; + return; + } + + start_ = fst.Start(); + properties_ = fst.Properties(kFstProperties, test_properties); + + for (StateIterator< Fst > siter(fst); + !siter.Done(); + siter.Next()) { + ++nstates_; + StateId s = siter.Value(); + if (fst.Final(s) != Weight::Zero()) + ++nfinal_; + for (ArcIterator< Fst > aiter(fst, s); + !aiter.Done(); + aiter.Next()) { + const A &arc = aiter.Value(); + ++narcs_; + if (arc.ilabel == 0 && arc.olabel == 0) + ++nepsilons_; + if (arc.ilabel == 0) + ++niepsilons_; + if (arc.olabel == 0) + ++noepsilons_; + } + } + + { + vector cc; + CcVisitor cc_visitor(&cc); + FifoQueue fifo_queue; + if (arc_filter_type == "any") { + Visit(fst, &cc_visitor, &fifo_queue); + } else if (arc_filter_type == "epsilon") { + Visit(fst, &cc_visitor, &fifo_queue, EpsilonArcFilter()); + } else if (arc_filter_type == "iepsilon") { + Visit(fst, &cc_visitor, &fifo_queue, InputEpsilonArcFilter()); + } else if (arc_filter_type == "oepsilon") { + Visit(fst, &cc_visitor, &fifo_queue, OutputEpsilonArcFilter()); + } else { + FSTERROR() << "Bad arc filter type: " << arc_filter_type; + return; + } + + for (StateId s = 0; s < cc.size(); ++s) { + if (cc[s] >= ncc_) + ncc_ = cc[s] + 1; + } + } + + { + vector scc; + vector access, coaccess; + uint64 props = 0; + SccVisitor scc_visitor(&scc, &access, &coaccess, &props); + if (arc_filter_type == "any") { + DfsVisit(fst, &scc_visitor); + } else if (arc_filter_type == "epsilon") { + DfsVisit(fst, &scc_visitor, EpsilonArcFilter()); + } else if (arc_filter_type == "iepsilon") { + DfsVisit(fst, &scc_visitor, InputEpsilonArcFilter()); + } else if (arc_filter_type == "oepsilon") { + DfsVisit(fst, &scc_visitor, OutputEpsilonArcFilter()); + } else { + FSTERROR() << "Bad arc filter type: " << arc_filter_type; + return; + } + + for (StateId s = 0; s < scc.size(); ++s) { + if (access[s]) + ++naccess_; + if (coaccess[s]) + ++ncoaccess_; + if (access[s] && coaccess[s]) + ++nconnect_; + if (scc[s] >= nscc_) + nscc_ = scc[s] + 1; + } + } + + LookAheadMatcher< Fst > imatcher(fst, MATCH_INPUT); + input_match_type_ = imatcher.Type(test_properties); + input_lookahead_ = imatcher.Flags() & kInputLookAheadMatcher; + + LookAheadMatcher< Fst > omatcher(fst, MATCH_OUTPUT); + output_match_type_ = omatcher.Type(test_properties); + output_lookahead_ = omatcher.Flags() & kOutputLookAheadMatcher; + } + + // Short info + const string& FstType() const { return fst_type_; } + const string& ArcType() const { return A::Type(); } + const string& InputSymbols() const { return input_symbols_; } + const string& OutputSymbols() const { return output_symbols_; } + const bool LongInfo() const { return long_info_; } + const string& ArcFilterType() const { return arc_filter_type_; } + + // Long info + MatchType InputMatchType() const { CheckLong(); return input_match_type_; } + MatchType OutputMatchType() const { CheckLong(); return output_match_type_; } + bool InputLookAhead() const { CheckLong(); return input_lookahead_; } + bool OutputLookAhead() const { CheckLong(); return output_lookahead_; } + int64 NumStates() const { CheckLong(); return nstates_; } + int64 NumArcs() const { CheckLong(); return narcs_; } + int64 Start() const { CheckLong(); return start_; } + int64 NumFinal() const { CheckLong(); return nfinal_; } + int64 NumEpsilons() const { CheckLong(); return nepsilons_; } + int64 NumInputEpsilons() const { CheckLong(); return niepsilons_; } + int64 NumOutputEpsilons() const { CheckLong(); return noepsilons_; } + int64 NumAccessible() const { CheckLong(); return naccess_; } + int64 NumCoAccessible() const { CheckLong(); return ncoaccess_; } + int64 NumConnected() const { CheckLong(); return nconnect_; } + int64 NumCc() const { CheckLong(); return ncc_; } + int64 NumScc() const { CheckLong(); return nscc_; } + uint64 Properties() const { CheckLong(); return properties_; } + + private: + void CheckLong() const { + if (!long_info_) + FSTERROR() << "FstInfo: method only available with long info version"; + } + + string fst_type_; + string input_symbols_; + string output_symbols_; + int64 nstates_; + int64 narcs_; + int64 start_; + int64 nfinal_; + int64 nepsilons_; + int64 niepsilons_; + int64 noepsilons_; + int64 naccess_; + int64 ncoaccess_; + int64 nconnect_; + int64 ncc_; + int64 nscc_; + MatchType input_match_type_; + MatchType output_match_type_; + bool input_lookahead_; + bool output_lookahead_; + uint64 properties_; + string arc_filter_type_; + bool long_info_; + DISALLOW_COPY_AND_ASSIGN(FstInfo); +}; + +template +void PrintFstInfo(const FstInfo &fstinfo, bool pipe = false) { + ostream &os = pipe ? cerr : cout; + + ios_base::fmtflags old = os.setf(ios::left); + os.width(50); + os << "fst type" << fstinfo.FstType() << endl; + os.width(50); + os << "arc type" << fstinfo.ArcType() << endl; + os.width(50); + os << "input symbol table" << fstinfo.InputSymbols() << endl; + os.width(50); + os << "output symbol table" << fstinfo.OutputSymbols() << endl; + + if (!fstinfo.LongInfo()) { + os.setf(old); + return; + } + + os.width(50); + os << "# of states" << fstinfo.NumStates() << endl; + os.width(50); + os << "# of arcs" << fstinfo.NumArcs() << endl; + os.width(50); + os << "initial state" << fstinfo.Start() << endl; + os.width(50); + os << "# of final states" << fstinfo.NumFinal() << endl; + os.width(50); + os << "# of input/output epsilons" << fstinfo.NumEpsilons() << endl; + os.width(50); + os << "# of input epsilons" << fstinfo.NumInputEpsilons() << endl; + os.width(50); + os << "# of output epsilons" << fstinfo.NumOutputEpsilons() << endl; + os.width(50); + + string arc_type = ""; + if (fstinfo.ArcFilterType() == "epsilon") + arc_type = "epsilon "; + else if (fstinfo.ArcFilterType() == "iepsilon") + arc_type = "input-epsilon "; + else if (fstinfo.ArcFilterType() == "oepsilon") + arc_type = "output-epsilon "; + + string accessible_label = "# of " + arc_type + "accessible states"; + os.width(50); + os << accessible_label << fstinfo.NumAccessible() << endl; + string coaccessible_label = "# of " + arc_type + "coaccessible states"; + os.width(50); + os << coaccessible_label << fstinfo.NumCoAccessible() << endl; + string connected_label = "# of " + arc_type + "connected states"; + os.width(50); + os << connected_label << fstinfo.NumConnected() << endl; + string numcc_label = "# of " + arc_type + "connected components"; + os.width(50); + os << numcc_label << fstinfo.NumCc() << endl; + string numscc_label = "# of " + arc_type + "strongly conn components"; + os.width(50); + os << numscc_label << fstinfo.NumScc() << endl; + + os.width(50); + os << "input matcher" + << (fstinfo.InputMatchType() == MATCH_INPUT ? 'y' : + fstinfo.InputMatchType() == MATCH_NONE ? 'n' : '?') << endl; + os.width(50); + os << "output matcher" + << (fstinfo.OutputMatchType() == MATCH_OUTPUT ? 'y' : + fstinfo.OutputMatchType() == MATCH_NONE ? 'n' : '?') << endl; + os.width(50); + os << "input lookahead" + << (fstinfo.InputLookAhead() ? 'y' : 'n') << endl; + os.width(50); + os << "output lookahead" + << (fstinfo.OutputLookAhead() ? 'y' : 'n') << endl; + + uint64 prop = 1; + for (int i = 0; i < 64; ++i, prop <<= 1) { + if (prop & kBinaryProperties) { + char value = 'n'; + if (fstinfo.Properties() & prop) value = 'y'; + os.width(50); + os << PropertyNames[i] << value << endl; + } else if (prop & kPosTrinaryProperties) { + char value = '?'; + if (fstinfo.Properties() & prop) value = 'y'; + else if (fstinfo.Properties() & prop << 1) value = 'n'; + os.width(50); + os << PropertyNames[i] << value << endl; + } + } + os.setf(old); +} + +} // namespace fst + +#endif // FST_SCRIPT_INFO_IMPL_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/info.h b/kaldi_io/src/tools/openfst/include/fst/script/info.h new file mode 100644 index 0000000..f434bd5 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/info.h @@ -0,0 +1,48 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_INFO_H_ +#define FST_SCRIPT_INFO_H_ + +#include +#include +#include + +namespace fst { +namespace script { + +typedef args::Package InfoArgs; + +template +void PrintFstInfo(InfoArgs *args) { + const Fst &fst = *(args->arg1.GetFst()); + FstInfo fstinfo(fst, args->arg2, args->arg3, + args->arg4, args->arg5); + PrintFstInfo(fstinfo, args->arg6); + + if (args->arg6) + fst.Write(""); +} + +void PrintFstInfo(const FstClass &f, bool test_properties, + const string &arc_filter, const string &info_type, + bool pipe, bool verify); + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_INFO_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/intersect.h b/kaldi_io/src/tools/openfst/include/fst/script/intersect.h new file mode 100644 index 0000000..8011024 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/intersect.h @@ -0,0 +1,65 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_INTERSECT_H_ +#define FST_SCRIPT_INTERSECT_H_ + +#include +#include +#include +#include // for ComposeOptions, ComposeFilter + +namespace fst { +namespace script { + +typedef args::Package IntersectArgs1; + +template +void Intersect(IntersectArgs1 *args) { + const Fst &ifst1 = *(args->arg1.GetFst()); + const Fst &ifst2 = *(args->arg2.GetFst()); + MutableFst *ofst = args->arg3->GetMutableFst(); + + Intersect(ifst1, ifst2, ofst, args->arg4); +} + +typedef args::Package IntersectArgs2; + +template +void Intersect(IntersectArgs2 *args) { + const Fst &ifst1 = *(args->arg1.GetFst()); + const Fst &ifst2 = *(args->arg2.GetFst()); + MutableFst *ofst = args->arg3->GetMutableFst(); + + Intersect(ifst1, ifst2, ofst, args->arg4); +} + +void Intersect(const FstClass &ifst1, const FstClass &ifst2, + MutableFstClass *ofst, + ComposeFilter compose_filter); + +void Intersect(const FstClass &ifst, const FstClass &ifst2, + MutableFstClass *ofst, + const ComposeOptions &opts = fst::script::ComposeOptions()); + +} // namespace script +} // namespace fst + + + +#endif // FST_SCRIPT_INTERSECT_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/invert.h b/kaldi_io/src/tools/openfst/include/fst/script/invert.h new file mode 100644 index 0000000..1befd9f --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/invert.h @@ -0,0 +1,43 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_INVERT_H_ +#define FST_SCRIPT_INVERT_H_ + +#include +#include +#include + +namespace fst { +namespace script { + +// The following confuses swig, because it has the same arguments +// as the non-templated version +#ifndef SWIG +template +void Invert(MutableFstClass *fst) { + MutableFst *typed_fst = fst->GetMutableFst(); + + Invert(typed_fst); +} +#endif + +void Invert(MutableFstClass *fst); + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_INVERT_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/map.h b/kaldi_io/src/tools/openfst/include/fst/script/map.h new file mode 100644 index 0000000..3caaa9f --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/map.h @@ -0,0 +1,123 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_MAP_H_ +#define FST_SCRIPT_MAP_H_ + +#include +#include +#include +#include +#include + +namespace fst { +namespace script { + +template +Fst *ArcMap(const Fst &fst, + const M &mapper) { + typedef typename M::ToArc ToArc; + VectorFst *ofst = new VectorFst; + ArcMap(fst, ofst, mapper); + return ofst; +} + +template +Fst *StateMap(const Fst &fst, + const M &mapper) { + typedef typename M::ToArc ToArc; + VectorFst *ofst = new VectorFst; + StateMap(fst, ofst, mapper); + return ofst; +} + +enum MapType { ARC_SUM_MAPPER, IDENTITY_MAPPER, INVERT_MAPPER, PLUS_MAPPER, + QUANTIZE_MAPPER, RMWEIGHT_MAPPER, SUPERFINAL_MAPPER, + TIMES_MAPPER, TO_LOG_MAPPER, TO_LOG64_MAPPER, TO_STD_MAPPER }; + +typedef args::Package MapInnerArgs; +typedef args::WithReturnValue MapArgs; + +template +void Map(MapArgs *args) { + const Fst &ifst = *(args->args.arg1.GetFst()); + MapType map_type = args->args.arg2; + float delta = args->args.arg3; + typename Arc::Weight w = *(args->args.arg4.GetWeight()); + + Fst *fst = NULL; + Fst *lfst = NULL; + Fst *l64fst = NULL; + Fst *sfst = NULL; + if (map_type == ARC_SUM_MAPPER) { + args->retval = new FstClass(*(fst = + script::StateMap(ifst, ArcSumMapper(ifst)))); + } else if (map_type == IDENTITY_MAPPER) { + args->retval = new FstClass(*(fst = + script::ArcMap(ifst, IdentityArcMapper()))); + } else if (map_type == INVERT_MAPPER) { + args->retval = new FstClass(*(fst = + script::ArcMap(ifst, InvertWeightMapper()))); + } else if (map_type == PLUS_MAPPER) { + args->retval = new FstClass(*(fst = + script::ArcMap(ifst, PlusMapper(w)))); + } else if (map_type == QUANTIZE_MAPPER) { + args->retval = new FstClass(*(fst = + script::ArcMap(ifst, QuantizeMapper(delta)))); + } else if (map_type == RMWEIGHT_MAPPER) { + args->retval = new FstClass(*(fst = + script::ArcMap(ifst, RmWeightMapper()))); + } else if (map_type == SUPERFINAL_MAPPER) { + args->retval = new FstClass(*(fst = + script::ArcMap(ifst, SuperFinalMapper()))); + } else if (map_type == TIMES_MAPPER) { + args->retval = new FstClass(*(fst = + script::ArcMap(ifst, TimesMapper(w)))); + } else if (map_type == TO_LOG_MAPPER) { + args->retval = new FstClass(*(lfst = + script::ArcMap(ifst, WeightConvertMapper()))); + } else if (map_type == TO_LOG64_MAPPER) { + args->retval = new FstClass(*(l64fst = + script::ArcMap(ifst, WeightConvertMapper()))); + } else if (map_type == TO_STD_MAPPER) { + args->retval = new FstClass(*(sfst = + script::ArcMap(ifst, WeightConvertMapper()))); + } else { + FSTERROR() << "Error: unknown/unsupported mapper type: " + << map_type; + VectorFst *ofst = new VectorFst; + ofst->SetProperties(kError, kError); + args->retval = new FstClass(*(fst =ofst)); + } + delete sfst; + delete l64fst; + delete lfst; + delete fst; +} + + +#ifdef SWIG +%newobject Map; +#endif +FstClass *Map(const FstClass& f, MapType map_type, + float delta = fst::kDelta, + const WeightClass &w = fst::script::WeightClass::Zero()); + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_MAP_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/minimize.h b/kaldi_io/src/tools/openfst/include/fst/script/minimize.h new file mode 100644 index 0000000..f250d03 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/minimize.h @@ -0,0 +1,45 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_MINIMIZE_H_ +#define FST_SCRIPT_MINIMIZE_H_ + +#include +#include +#include + +namespace fst { +namespace script { + +typedef args::Package MinimizeArgs; + +template +void Minimize(MinimizeArgs *args) { + MutableFst *ofst1 = args->arg1->GetMutableFst(); + MutableFst *ofst2 = args->arg2 ? args->arg2->GetMutableFst() : 0; + + Minimize(ofst1, ofst2, args->arg3); +} + +void Minimize(MutableFstClass *ofst1, MutableFstClass *ofst2 = 0, + float delta = kDelta); + +} // namespace script +} // namespace fst + + + +#endif // FST_SCRIPT_MINIMIZE_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/print-impl.h b/kaldi_io/src/tools/openfst/include/fst/script/print-impl.h new file mode 100644 index 0000000..1433a29 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/print-impl.h @@ -0,0 +1,149 @@ +// print.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Stand-alone class to print out binary FSTs in the AT&T format, +// helper class for fstprint.cc + +#ifndef FST_SCRIPT_PRINT_IMPL_H_ +#define FST_SCRIPT_PRINT_IMPL_H_ + +#include +#include + +#include +#include + +DECLARE_string(fst_field_separator); + +namespace fst { + +// Print a binary Fst in textual format, helper class for fstprint.cc +// WARNING: Stand-alone use of this class not recommended, most code should +// read/write using the binary format which is much more efficient. +template class FstPrinter { + public: + typedef A Arc; + typedef typename A::StateId StateId; + typedef typename A::Label Label; + typedef typename A::Weight Weight; + + FstPrinter(const Fst &fst, + const SymbolTable *isyms, + const SymbolTable *osyms, + const SymbolTable *ssyms, + bool accep, + bool show_weight_one) + : fst_(fst), isyms_(isyms), osyms_(osyms), ssyms_(ssyms), + accep_(accep && fst.Properties(kAcceptor, true)), ostrm_(0), + show_weight_one_(show_weight_one) {} + + // Print Fst to an output stream + void Print(ostream *ostrm, const string &dest) { + ostrm_ = ostrm; + dest_ = dest; + StateId start = fst_.Start(); + if (start == kNoStateId) + return; + // initial state first + PrintState(start); + for (StateIterator< Fst > siter(fst_); + !siter.Done(); + siter.Next()) { + StateId s = siter.Value(); + if (s != start) + PrintState(s); + } + } + + private: + // Maximum line length in text file. + static const int kLineLen = 8096; + + void PrintId(int64 id, const SymbolTable *syms, + const char *name) const { + if (syms) { + string symbol = syms->Find(id); + if (symbol == "") { + FSTERROR() << "FstPrinter: Integer " << id + << " is not mapped to any textual symbol" + << ", symbol table = " << syms->Name() + << ", destination = " << dest_; + symbol = "?"; + } + *ostrm_ << symbol; + } else { + *ostrm_ << id; + } + } + + void PrintStateId(StateId s) const { + PrintId(s, ssyms_, "state ID"); + } + + void PrintILabel(Label l) const { + PrintId(l, isyms_, "arc input label"); + } + + void PrintOLabel(Label l) const { + PrintId(l, osyms_, "arc output label"); + } + + void PrintState(StateId s) const { + bool output = false; + for (ArcIterator< Fst > aiter(fst_, s); + !aiter.Done(); + aiter.Next()) { + Arc arc = aiter.Value(); + PrintStateId(s); + *ostrm_ << FLAGS_fst_field_separator[0]; + PrintStateId(arc.nextstate); + *ostrm_ << FLAGS_fst_field_separator[0]; + PrintILabel(arc.ilabel); + if (!accep_) { + *ostrm_ << FLAGS_fst_field_separator[0]; + PrintOLabel(arc.olabel); + } + if (show_weight_one_ || arc.weight != Weight::One()) + *ostrm_ << FLAGS_fst_field_separator[0] << arc.weight; + *ostrm_ << "\n"; + output = true; + } + Weight final = fst_.Final(s); + if (final != Weight::Zero() || !output) { + PrintStateId(s); + if (show_weight_one_ || final != Weight::One()) { + *ostrm_ << FLAGS_fst_field_separator[0] << final; + } + *ostrm_ << "\n"; + } + } + + const Fst &fst_; + const SymbolTable *isyms_; // ilabel symbol table + const SymbolTable *osyms_; // olabel symbol table + const SymbolTable *ssyms_; // slabel symbol table + bool accep_; // print as acceptor when possible + ostream *ostrm_; // text FST destination + string dest_; // text FST destination name + bool show_weight_one_; // print weights equal to Weight::One() + DISALLOW_COPY_AND_ASSIGN(FstPrinter); +}; + +} // namespace fst + +#endif // FST_SCRIPT_PRINT_IMPL_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/print.h b/kaldi_io/src/tools/openfst/include/fst/script/print.h new file mode 100644 index 0000000..f82b19b --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/print.h @@ -0,0 +1,86 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_PRINT_H_ +#define FST_SCRIPT_PRINT_H_ + +#include +#include +#include + +namespace fst { +namespace script { + +// Note: it is safe to pass these strings as references because +// this struct is only used to pass them deeper in the call graph. +// Be sure you understand why this is so before using this struct +// for anything else! +struct FstPrinterArgs { + const FstClass &fst; + const SymbolTable *isyms; + const SymbolTable *osyms; + const SymbolTable *ssyms; + const bool accept; + const bool show_weight_one; + ostream *ostrm; + const string &dest; + + FstPrinterArgs(const FstClass &fst, + const SymbolTable *isyms, + const SymbolTable *osyms, + const SymbolTable *ssyms, + bool accept, + bool show_weight_one, + ostream *ostrm, + const string &dest) : + fst(fst), isyms(isyms), osyms(osyms), ssyms(ssyms), accept(accept), + show_weight_one(show_weight_one), ostrm(ostrm), dest(dest) { } +}; + +template +void PrintFst(FstPrinterArgs *args) { + const Fst &fst = *(args->fst.GetFst()); + + fst::FstPrinter fstprinter(fst, args->isyms, args->osyms, + args->ssyms, args->accept, + args->show_weight_one); + fstprinter.Print(args->ostrm, args->dest); +} + +void PrintFst(const FstClass &fst, ostream &ostrm, const string &dest, + const SymbolTable *isyms, + const SymbolTable *osyms, + const SymbolTable *ssyms, + bool accept, bool show_weight_one); + + +// Below are two printing methods with useful defaults for a few of +// the fst printer arguments. +template +void PrintFst(const Fst &fst, ostream &os, const string dest = "", + const SymbolTable *isyms = NULL, + const SymbolTable *osyms = NULL, + const SymbolTable *ssyms = NULL) { + fst::FstPrinter fstprinter(fst, isyms, osyms, ssyms, true, true); + fstprinter.Print(&os, dest); +} + +} // namespace script +} // namespace fst + + + +#endif // FST_SCRIPT_PRINT_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/project.h b/kaldi_io/src/tools/openfst/include/fst/script/project.h new file mode 100644 index 0000000..12ee890 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/project.h @@ -0,0 +1,43 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_PROJECT_H_ +#define FST_SCRIPT_PROJECT_H_ + +#include +#include +#include // for ProjectType + +namespace fst { +namespace script { + +typedef args::Package ProjectArgs; + +template +void Project(ProjectArgs *args) { + MutableFst *ofst = args->arg1->GetMutableFst(); + + Project(ofst, args->arg2); +} + +void Project(MutableFstClass *ofst, ProjectType project_type); + +} // namespace script +} // namespace fst + + + +#endif // FST_SCRIPT_PROJECT_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/prune.h b/kaldi_io/src/tools/openfst/include/fst/script/prune.h new file mode 100644 index 0000000..7118ff1 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/prune.h @@ -0,0 +1,153 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_PRUNE_H_ +#define FST_SCRIPT_PRUNE_H_ + +#include +using std::vector; + +#include +#include +#include +#include +#include + +namespace fst { +namespace script { + +struct PruneOptions { + WeightClass weight_threshold; + int64 state_threshold; + const vector *distance; + float delta; + + explicit PruneOptions(const WeightClass& w, int64 s, + vector *d = 0, float e = kDelta) + : weight_threshold(w), + state_threshold(s), + distance(d), + delta(e) {} + private: + PruneOptions(); // disallow +}; + +// converts a script::PruneOptions into a fst::PruneOptions. +// Notes: +// If the original opts.distance is not NULL, a new distance will be +// created with new; it's the client's responsibility to delete this. + +template +fst::PruneOptions > ConvertPruneOptions( + const PruneOptions &opts) { + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + + Weight weight_threshold = *(opts.weight_threshold.GetWeight()); + StateId state_threshold = opts.state_threshold; + vector *distance = 0; + + if (opts.distance) { + distance = new vector(opts.distance->size()); + for (unsigned i = 0; i < opts.distance->size(); ++i) { + (*distance)[i] = *((*opts.distance)[i].GetWeight()); + } + } + + return fst::PruneOptions >( + weight_threshold, state_threshold, AnyArcFilter(), distance, + opts.delta); +} + +// 1 +typedef args::Package PruneArgs1; + +template +void Prune(PruneArgs1 *args) { + MutableFst *ofst = args->arg1->GetMutableFst(); + + typedef typename Arc::Weight Weight; + typedef typename Arc::StateId StateId; + + fst::PruneOptions > opts = + ConvertPruneOptions(args->arg2); + Prune(ofst, opts); + delete opts.distance; +} + +// 2 +typedef args::Package PruneArgs2; + +template +void Prune(PruneArgs2 *args) { + const Fst& ifst = *(args->arg1.GetFst()); + MutableFst *ofst = args->arg2->GetMutableFst(); + + fst::PruneOptions > opts = + ConvertPruneOptions(args->arg3); + Prune(ifst, ofst, opts); + delete opts.distance; +} + +// 3 +typedef args::Package PruneArgs3; + +template +void Prune(PruneArgs3 *args) { + const Fst& ifst = *(args->arg1.GetFst()); + MutableFst *ofst = args->arg2->GetMutableFst(); + typename Arc::Weight w = *(args->arg3.GetWeight()); + + Prune(ifst, ofst, w, args->arg4, args->arg5); +} + +// 4 +typedef args::Package PruneArgs4; +template +void Prune(PruneArgs4 *args) { + MutableFst *fst = args->arg1->GetMutableFst(); + typename Arc::Weight w = *(args->arg2.GetWeight()); + Prune(fst, w, args->arg3, args->arg4); +} + + +// 1 +void Prune(MutableFstClass *fst, const PruneOptions &opts); + +// 2 +void Prune(const FstClass &ifst, MutableFstClass *fst, + const PruneOptions &opts); + +// 3 +void Prune(const FstClass &ifst, MutableFstClass *ofst, + const WeightClass &weight_threshold, + int64 state_threshold = kNoStateId, + float delta = kDelta); + +// 4 +void Prune(MutableFstClass *fst, const WeightClass& weight_threshold, + int64 state_threshold, float delta); + +} // namespace script +} // namespace fst + + + +#endif // FST_SCRIPT_PRUNE_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/push.h b/kaldi_io/src/tools/openfst/include/fst/script/push.h new file mode 100644 index 0000000..cebd655 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/push.h @@ -0,0 +1,70 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_PUSH_H_ +#define FST_SCRIPT_PUSH_H_ + +#include +#include +#include + +namespace fst { +namespace script { + +// 1 +typedef args::Package PushArgs1; + +template +void Push(PushArgs1 *args) { + MutableFst *ofst = args->arg1->GetMutableFst(); + + if (args->arg2 == REWEIGHT_TO_FINAL) { + fst::Push(ofst, REWEIGHT_TO_FINAL, args->arg3, args->arg4); + } else { + fst::Push(ofst, REWEIGHT_TO_INITIAL, args->arg3, args->arg4); + } +} + +// 2 +typedef args::Package PushArgs2; + +template +void Push(PushArgs2 *args) { + const Fst &ifst = *(args->arg1.GetFst()); + MutableFst *ofst = args->arg2->GetMutableFst(); + + if (args->arg4 == REWEIGHT_TO_FINAL) { + fst::Push(ifst, ofst, args->arg3, args->arg5); + } else { + fst::Push(ifst, ofst, args->arg3, args->arg5); + } +} + +// 1 +void Push(MutableFstClass *ofst, ReweightType type, float delta = kDelta, + bool remove_total_weight = false); + +// 2 +void Push(const FstClass &ifst, MutableFstClass *ofst, uint32 flags, + ReweightType dir, float delta); + +} // namespace script +} // namespace fst + + + +#endif // FST_SCRIPT_PUSH_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/randequivalent.h b/kaldi_io/src/tools/openfst/include/fst/script/randequivalent.h new file mode 100644 index 0000000..b929683 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/randequivalent.h @@ -0,0 +1,105 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_RANDEQUIVALENT_H_ +#define FST_SCRIPT_RANDEQUIVALENT_H_ + +#include +#include +#include // for RandArcSelection +#include + +namespace fst { +namespace script { + +// 1 +typedef args::Package RandEquivalentInnerArgs1; +typedef args::WithReturnValue RandEquivalentArgs1; + +template +void RandEquivalent(RandEquivalentArgs1 *args) { + const Fst &fst1 = *(args->args.arg1.GetFst()); + const Fst &fst2 = *(args->args.arg2.GetFst()); + + args->retval = RandEquivalent(fst1, fst2, args->args.arg3, args->args.arg4, + args->args.arg5, args->args.arg6); +} + +// 2 +typedef args::Package &> + RandEquivalentInnerArgs2; + +typedef args::WithReturnValue RandEquivalentArgs2; + +template +void RandEquivalent(RandEquivalentArgs2 *args) { + const Fst &fst1 = *(args->args.arg1.GetFst()); + const Fst &fst2 = *(args->args.arg2.GetFst()); + const RandGenOptions &opts = args->args.arg6; + int32 seed = args->args.arg3; + + if (opts.arc_selector == UNIFORM_ARC_SELECTOR) { + UniformArcSelector arc_selector(seed); + RandGenOptions< UniformArcSelector > + ropts(arc_selector, opts.max_length, opts.npath); + + args->retval = RandEquivalent(fst1, fst2, args->args.arg4, + args->args.arg5, ropts); + } else if (opts.arc_selector == FAST_LOG_PROB_ARC_SELECTOR) { + FastLogProbArcSelector arc_selector(seed); + RandGenOptions< FastLogProbArcSelector > + ropts(arc_selector, opts.max_length, opts.npath); + + args->retval = RandEquivalent(fst1, fst2, args->args.arg4, + args->args.arg5, ropts); + } else { + LogProbArcSelector arc_selector(seed); + RandGenOptions< LogProbArcSelector > + ropts(arc_selector, opts.max_length, opts.npath); + args->retval = RandEquivalent(fst1, fst2, args->args.arg4, + args->args.arg5, ropts); + } +} + + +// 1 +bool RandEquivalent(const FstClass &fst1, + const FstClass &fst2, + int32 seed = time(0), + ssize_t num_paths = 1, + float delta = fst::kDelta, + int path_length = INT_MAX); + +// 2 +bool RandEquivalent(const FstClass &fst1, + const FstClass &fst2, + int32 seed, + ssize_t num_paths, + float delta, + const fst::RandGenOptions< + fst::script::RandArcSelection> &opts); + +} // namespace script +} // namespace fst + + + +#endif // FST_SCRIPT_RANDEQUIVALENT_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/randgen.h b/kaldi_io/src/tools/openfst/include/fst/script/randgen.h new file mode 100644 index 0000000..817f9c1 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/randgen.h @@ -0,0 +1,76 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_RANDGEN_H_ +#define FST_SCRIPT_RANDGEN_H_ + +#include +#include +#include + +namespace fst { +namespace script { + +enum RandArcSelection { + UNIFORM_ARC_SELECTOR, + LOG_PROB_ARC_SELECTOR, + FAST_LOG_PROB_ARC_SELECTOR +}; + +typedef args::Package &> RandGenArgs; + +template +void RandGen(RandGenArgs *args) { + const Fst &ifst = *(args->arg1.GetFst()); + MutableFst *ofst = args->arg2->GetMutableFst(); + int32 seed = args->arg3; + const RandGenOptions &opts = args->arg4; + + if (opts.arc_selector == UNIFORM_ARC_SELECTOR) { + UniformArcSelector arc_selector(seed); + RandGenOptions< UniformArcSelector > + ropts(arc_selector, opts.max_length, + opts.npath, opts.weighted); + RandGen(ifst, ofst, ropts); + } else if (opts.arc_selector == FAST_LOG_PROB_ARC_SELECTOR) { + FastLogProbArcSelector arc_selector(seed); + RandGenOptions< FastLogProbArcSelector > + ropts(arc_selector, opts.max_length, + opts.npath, opts.weighted); + RandGen(ifst, ofst, ropts); + } else { + LogProbArcSelector arc_selector(seed); + RandGenOptions< LogProbArcSelector > + ropts(arc_selector, opts.max_length, + opts.npath, opts.weighted); + RandGen(ifst, ofst, ropts); + } +} + + +// Client-facing prototype +void RandGen(const FstClass &ifst, MutableFstClass *ofst, int32 seed = time(0), + const RandGenOptions &opts = + fst::RandGenOptions( + fst::script::UNIFORM_ARC_SELECTOR)); + +} // namespace script +} // namespace fst + + + +#endif // FST_SCRIPT_RANDGEN_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/register.h b/kaldi_io/src/tools/openfst/include/fst/script/register.h new file mode 100644 index 0000000..03e0e36 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/register.h @@ -0,0 +1,120 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_REGISTER_H_ +#define FST_SCRIPT_REGISTER_H_ + +#include + +#include +#include +#include + +// Holds methods and classes responsible for maintaining +// the register for FstClass arc types. + +namespace fst { +namespace script { + +// +// Registers for reading and converting various kinds of FST classes. +// + +// This class definition is to avoid a nested class definition inside +// the IORegistration struct. +template +struct FstClassRegEntry { + Reader reader; + Creator creator; + Converter converter; + + FstClassRegEntry(Reader r, Creator cr, Converter co) : + reader(r), creator(cr), converter(co) { } + FstClassRegEntry() : reader(0), creator(0), converter(0) { } +}; + +template +class FstClassIORegister + : public GenericRegister, + FstClassIORegister > { + public: + Reader GetReader(const string &arc_type) const { + return this->GetEntry(arc_type).reader; + } + + Creator GetCreator(const string &arc_type) const { + return this->GetEntry(arc_type).creator; + } + + Converter GetConverter(const string &arc_type) const { + return this->GetEntry(arc_type).converter; + } + + protected: + virtual string ConvertKeyToSoFilename( + const string& key) const { + string legal_type(key); + ConvertToLegalCSymbol(&legal_type); + + return legal_type + "-arc.so"; + } +}; + +// +// Struct containing everything needed to register a particular type +// of FST class (e.g. a plain FstClass, or a MutableFstClass, etc) +// +template +struct IORegistration { + typedef FstClassType *(*Reader)(istream &stream, + const FstReadOptions &opts); + + typedef FstClassImplBase *(*Creator)(); + typedef FstClassImplBase *(*Converter)(const FstClass &other); + + typedef FstClassRegEntry Entry; + + // FST class Register + typedef FstClassIORegister Register; + + // FST class Register-er + typedef GenericRegisterer > + Registerer; +}; + + +// +// REGISTRATION MACROS +// + +#define REGISTER_FST_CLASS(Class, Arc) \ + static IORegistration::Registerer Class ## _ ## Arc ## _registerer( \ + Arc::Type(), \ + IORegistration::Entry(Class::Read, \ + Class::Create, \ + Class::Convert)) + +#define REGISTER_FST_CLASSES(Arc) \ + REGISTER_FST_CLASS(FstClass, Arc); \ + REGISTER_FST_CLASS(MutableFstClass, Arc); \ + REGISTER_FST_CLASS(VectorFstClass, Arc); + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_REGISTER_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/relabel.h b/kaldi_io/src/tools/openfst/include/fst/script/relabel.h new file mode 100644 index 0000000..6bbb4c5 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/relabel.h @@ -0,0 +1,102 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_RELABEL_H_ +#define FST_SCRIPT_RELABEL_H_ + +#include +using std::pair; using std::make_pair; +#include +#include +using std::vector; + +#include +#include +#include + +namespace fst { +namespace script { + +// 1 +typedef args::Package RelabelArgs1; + +template +void Relabel(RelabelArgs1 *args) { + MutableFst *ofst = args->arg1->GetMutableFst(); + + Relabel(ofst, args->arg2, args->arg3, args->arg4, + args->arg5, args->arg6, args->arg7); +} + +// 2 +typedef args::Package > &, + const vector > > RelabelArgs2; + +template +void Relabel(RelabelArgs2 *args) { + MutableFst *ofst = args->arg1->GetMutableFst(); + + // In case int64 is not the same as Arc::Label, + // copy the reassignments + typedef typename Arc::Label Label; + + vector > converted_ipairs(args->arg2.size()); + copy(args->arg2.begin(), args->arg2.end(), converted_ipairs.begin()); + + vector > converted_opairs(args->arg3.size()); + copy(args->arg3.begin(), args->arg3.end(), converted_opairs.begin()); + + Relabel(ofst, converted_ipairs, converted_opairs); +} + +// 3 +typedef args::Package RelabelArgs3; +template +void Relabel(args::Package *args) { + MutableFst *fst = args->arg1->GetMutableFst(); + Relabel(fst, args->arg2, args->arg3); +} + + +// 1 +void Relabel(MutableFstClass *ofst, + const SymbolTable *old_isyms, const SymbolTable *relabel_isyms, + bool attach_new_isyms, + const SymbolTable *old_osyms, const SymbolTable *relabel_osyms, + bool attch_new_osyms); + +// 2 +void Relabel(MutableFstClass *ofst, + const vector > &ipairs, + const vector > &opairs); + + +// 3 +void Relabel(MutableFstClass *fst, + const SymbolTable *new_isymbols, + const SymbolTable *new_osymbols); + + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_RELABEL_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/replace.h b/kaldi_io/src/tools/openfst/include/fst/script/replace.h new file mode 100644 index 0000000..5eaf5bf --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/replace.h @@ -0,0 +1,62 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_REPLACE_H_ +#define FST_SCRIPT_REPLACE_H_ + +#include +using std::pair; using std::make_pair; +#include +using std::vector; + +#include +#include +#include + +namespace fst { +namespace script { + +typedef args::Package > &, + MutableFstClass *, const int64, bool> ReplaceArgs; + +template +void Replace(ReplaceArgs *args) { + // Now that we know the arc type, we construct a vector of + // pair that the real Replace will use + const vector >& untyped_tuples = + args->arg1; + + vector *> > fst_tuples( + untyped_tuples.size()); + + for (unsigned i = 0; i < untyped_tuples.size(); ++i) { + fst_tuples[i].first = untyped_tuples[i].first; // convert label + fst_tuples[i].second = untyped_tuples[i].second->GetFst(); + } + + MutableFst *ofst = args->arg2->GetMutableFst(); + + Replace(fst_tuples, ofst, args->arg3, args->arg4); +} + +void Replace(const vector > &tuples, + MutableFstClass *ofst, const int64 &root, + bool epsilon_on_replace = false); + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_REPLACE_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/reverse.h b/kaldi_io/src/tools/openfst/include/fst/script/reverse.h new file mode 100644 index 0000000..3930875 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/reverse.h @@ -0,0 +1,42 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_REVERSE_H_ +#define FST_SCRIPT_REVERSE_H_ + +#include +#include +#include + +namespace fst { +namespace script { + +typedef args::Package ReverseArgs; + +template +void Reverse(ReverseArgs *args) { + const Fst &fst1 = *(args->arg1.GetFst()); + MutableFst *fst2 = args->arg2->GetMutableFst(); + + Reverse(fst1, fst2); +} + +void Reverse(const FstClass &fst1, MutableFstClass *fst2); + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_REVERSE_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/reweight.h b/kaldi_io/src/tools/openfst/include/fst/script/reweight.h new file mode 100644 index 0000000..7bce839 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/reweight.h @@ -0,0 +1,53 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_REWEIGHT_H_ +#define FST_SCRIPT_REWEIGHT_H_ + +#include +using std::vector; + +#include +#include +#include +#include + +namespace fst { +namespace script { + +typedef args::Package &, + ReweightType> ReweightArgs; + +template +void Reweight(ReweightArgs *args) { + MutableFst *fst = args->arg1->GetMutableFst(); + typedef typename Arc::Weight Weight; + vector potentials(args->arg2.size()); + + for (unsigned i = 0; i < args->arg2.size(); ++i) { + potentials[i] = *(args->arg2[i].GetWeight()); + } + + Reweight(fst, potentials, args->arg3); +} + +void Reweight(MutableFstClass *fst, const vector &potential, + ReweightType reweight_type); + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_REWEIGHT_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/rmepsilon.h b/kaldi_io/src/tools/openfst/include/fst/script/rmepsilon.h new file mode 100644 index 0000000..62fed03 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/rmepsilon.h @@ -0,0 +1,211 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_RMEPSILON_H_ +#define FST_SCRIPT_RMEPSILON_H_ + +#include +using std::vector; + +#include +#include +#include +#include // for ShortestDistanceOptions +#include +#include + +// the following is necessary, or SWIG complains mightily about +// shortestdistanceoptions not being defined before being used as a base. +#ifdef SWIG +%include "nlp/fst/script/shortest-distance.h" +#endif + + +namespace fst { +namespace script { + +// +// OPTIONS +// + +struct RmEpsilonOptions : public fst::script::ShortestDistanceOptions { + bool connect; + WeightClass weight_threshold; + int64 state_threshold; + + RmEpsilonOptions(QueueType qt = AUTO_QUEUE, float d = kDelta, bool c = true, + WeightClass w = fst::script::WeightClass::Zero(), + int64 n = kNoStateId) + : ShortestDistanceOptions(qt, EPSILON_ARC_FILTER, + kNoStateId, d), + connect(c), weight_threshold(w), state_threshold(n) { } +}; + + +// +// TEMPLATES +// + +// this function takes care of transforming a script-land RmEpsilonOptions +// into a lib-land RmEpsilonOptions +template +void RmEpsilonHelper(MutableFst *fst, + vector *distance, + const RmEpsilonOptions &opts) { + typedef typename Arc::StateId StateId; + typedef typename Arc::Weight Weight; + + typename Arc::Weight weight_thresh = + *(opts.weight_threshold.GetWeight()); + + switch (opts.queue_type) { + case AUTO_QUEUE: { + AutoQueue queue(*fst, distance, EpsilonArcFilter()); + fst::RmEpsilonOptions > ropts( + &queue, opts.delta, opts.connect, weight_thresh, + opts.state_threshold); + RmEpsilon(fst, distance, ropts); + break; + } + case FIFO_QUEUE: { + FifoQueue queue; + fst::RmEpsilonOptions > ropts( + &queue, opts.delta, opts.connect, weight_thresh, + opts.state_threshold); + RmEpsilon(fst, distance, ropts); + break; + } + case LIFO_QUEUE: { + LifoQueue queue; + fst::RmEpsilonOptions > ropts( + &queue, opts.delta, opts.connect, weight_thresh, + opts.state_threshold); + RmEpsilon(fst, distance, ropts); + break; + } + case SHORTEST_FIRST_QUEUE: { + NaturalShortestFirstQueue queue(*distance); + fst::RmEpsilonOptions > ropts( + &queue, opts.delta, opts.connect, weight_thresh, + opts.state_threshold); + RmEpsilon(fst, distance, ropts); + break; + } + case STATE_ORDER_QUEUE: { + StateOrderQueue queue; + fst::RmEpsilonOptions > ropts( + &queue, opts.delta, opts.connect, weight_thresh, + opts.state_threshold); + RmEpsilon(fst, distance, ropts); + break; + } + case TOP_ORDER_QUEUE: { + TopOrderQueue queue(*fst, EpsilonArcFilter()); + fst::RmEpsilonOptions > ropts( + &queue, opts.delta, opts.connect, weight_thresh, + opts.state_threshold); + RmEpsilon(fst, distance, ropts); + break; + } + default: + FSTERROR() << "Unknown or unsupported queue type: " << opts.queue_type; + fst->SetProperties(kError, kError); + } +} + +// 1 +typedef args::Package RmEpsilonArgs1; + +template +void RmEpsilon(RmEpsilonArgs1 *args) { + const Fst &ifst = *(args->arg1.GetFst()); + MutableFst *ofst = args->arg2->GetMutableFst(); + vector distance; + bool reverse = args->arg3; + + if (reverse) { + VectorFst rfst; + Reverse(ifst, &rfst); + RmEpsilonHelper(&rfst, &distance, args->arg4); + Reverse(rfst, ofst); + } else { + *ofst = ifst; + } + RmEpsilonHelper(ofst, &distance, args->arg4); +} + +// 2 +typedef args::Package RmEpsilonArgs2; + +template +void RmEpsilon(RmEpsilonArgs2 *args) { + MutableFst *fst = args->arg1->GetMutableFst(); + typename Arc::Weight w = *(args->arg3.GetWeight()); + + RmEpsilon(fst, args->arg2, w, args->arg4, args->arg5); +} + +// 3 +typedef args::Package *, + const RmEpsilonOptions &> RmEpsilonArgs3; + +template +void RmEpsilon(RmEpsilonArgs3 *args) { + MutableFst *fst = args->arg1->GetMutableFst(); + const RmEpsilonOptions &opts = args->arg3; + + vector weights; + + RmEpsilonHelper(fst, &weights, opts); + + // Copy the weights back + args->arg2->resize(weights.size()); + for (unsigned i = 0; i < weights.size(); ++i) { + (*args->arg2)[i] = WeightClass(weights[i]); + } +} + +// +// PROTOTYPES +// + +// 1 +void RmEpsilon(const FstClass &ifst, MutableFstClass *ofst, + bool reverse = false, + const RmEpsilonOptions& opts = + fst::script::RmEpsilonOptions()); + +// 2 +void RmEpsilon(MutableFstClass *arc, bool connect = true, + const WeightClass &weight_threshold = + fst::script::WeightClass::Zero(), + int64 state_threshold = fst::kNoStateId, + float delta = fst::kDelta); + +// 3 +void RmEpsilon(MutableFstClass *fst, vector *distance, + const RmEpsilonOptions &opts); + + +} // namespace script +} // namespace fst + + +#endif // FST_SCRIPT_RMEPSILON_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/script-impl.h b/kaldi_io/src/tools/openfst/include/fst/script/script-impl.h new file mode 100644 index 0000000..452c7c5 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/script-impl.h @@ -0,0 +1,206 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +// This file defines the registration mechanism for new operations. +// These operations are designed to enable scripts to work with FST classes +// at a high level. + +// If you have a new arc type and want these operations to work with FSTs +// with that arc type, see below for the registration steps +// you must take. + +// These methods are only recommended for use in high-level scripting +// applications. Most users should use the lower-level templated versions +// corresponding to these. + +// If you have a new arc type you'd like these operations to work with, +// use the REGISTER_FST_OPERATIONS macro defined in fstcsript.h + +// If you have a custom operation you'd like to define, you need four +// components. In the following, assume you want to create a new operation +// with the signature +// +// void Foo(const FstClass &ifst, MutableFstClass *ofst); +// +// You need: +// +// 1) A way to bundle the args that your new Foo operation will take, as +// a single struct. The template structs in arg-packs.h provide a handy +// way to do this. In Foo's case, that might look like this: +// +// typedef args::Package FooArgs; +// +// Note: this package of args is going to be passed by non-const pointer. +// +// 2) A function template that is able to perform Foo, given the args and +// arc type. Yours might look like this: +// +// template +// void Foo(FooArgs *args) { +// // Pull out the actual, arc-templated FSTs +// const Fst &ifst = args->arg1.GetFst(); +// MutableFst *ofst = args->arg2->GetMutableFst(); +// +// // actually perform foo on ifst and ofst... +// } +// +// 3) a client-facing function for your operation. This would look like +// the following: +// +// void Foo(const FstClass &ifst, MutableFstClass *ofst) { +// // Check that the arc types of the FSTs match +// if (!ArcTypesMatch(ifst, *ofst, "Foo")) return; +// // package the args +// FooArgs args(ifst, ofst); +// // Finally, call the operation +// Apply >("Foo", ifst->ArcType(), &args); +// } +// +// The Apply<> function template takes care of the link between 2 and 3, +// provided you also have: +// +// 4) A registration for your new operation, on the arc types you care about. +// This can be provided easily by the REGISTER_FST_OPERATION macro in +// operations.h: +// +// REGISTER_FST_OPERATION(Foo, StdArc, FooArgs); +// REGISTER_FST_OPERATION(Foo, MyArc, FooArgs); +// // .. etc +// +// +// That's it! Now when you call Foo(const FstClass &, MutableFstClass *), +// it dispatches (in #3) via the Apply<> function to the correct +// instantiation of the template function in #2. +// + + +#ifndef FST_SCRIPT_SCRIPT_IMPL_H_ +#define FST_SCRIPT_SCRIPT_IMPL_H_ + +// +// This file contains general-purpose templates which are used in the +// implementation of the operations. +// + +#include +using std::pair; using std::make_pair; +#include + +#include +#include +#include + +#include + +namespace fst { +namespace script { + +// +// A generic register for operations with various kinds of signatures. +// Needed since every function signature requires a new registration class. +// The pair is understood to be the operation name and arc +// type; subclasses (or typedefs) need only provide the operation signature. +// + +template +class GenericOperationRegister + : public GenericRegister, + OperationSignature, + GenericOperationRegister > { + public: + void RegisterOperation(const string &operation_name, + const string &arc_type, + OperationSignature op) { + this->SetEntry(make_pair(operation_name, arc_type), op); + } + + OperationSignature GetOperation( + const string &operation_name, const string &arc_type) { + return this->GetEntry(make_pair(operation_name, arc_type)); + } + + protected: + virtual string ConvertKeyToSoFilename( + const pair& key) const { + // Just use the old-style FST for now. + string legal_type(key.second); // the arc type + ConvertToLegalCSymbol(&legal_type); + + return legal_type + "-arc.so"; + } +}; + + +// Operation package - everything you need to register a new type of operation + +// The ArgPack should be the type that's passed into each wrapped function - +// for instance, it might be a struct containing all the args. +// It's always passed by pointer, so const members should be used to enforce +// constness where it's needed. Return values should be implemented as a +// member of ArgPack as well. + +template +struct Operation { + typedef ArgPack Args; + typedef void (*OpType)(ArgPack *args); + + // The register (hash) type + typedef GenericOperationRegister Register; + + // The register-er type + typedef GenericRegisterer Registerer; +}; + + +// Macro for registering new types of operations. + +#define REGISTER_FST_OPERATION(Op, Arc, ArgPack) \ + static fst::script::Operation::Registerer \ + arc_dispatched_operation_ ## ArgPack ## Op ## Arc ## _registerer( \ + make_pair(#Op, Arc::Type()), Op) + + +// +// Template function to apply an operation by name +// + +template +void Apply(const string &op_name, const string &arc_type, + typename OpReg::Args *args) { + typename OpReg::Register *reg = OpReg::Register::GetRegister(); + + typename OpReg::OpType op = reg->GetOperation(op_name, arc_type); + + if (op == 0) { + FSTERROR() << "No operation found for \"" << op_name << "\" on " + << "arc type " << arc_type; + return; + } + + op(args); +} + + +// Helper that logs to ERROR if the arc types of a and b don't match. +// The op_name is also printed. +bool ArcTypesMatch(const FstClass &a, const FstClass &b, + const string &op_name); + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_SCRIPT_IMPL_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/shortest-distance.h b/kaldi_io/src/tools/openfst/include/fst/script/shortest-distance.h new file mode 100644 index 0000000..5fc2976 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/shortest-distance.h @@ -0,0 +1,250 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_SHORTEST_DISTANCE_H_ +#define FST_SCRIPT_SHORTEST_DISTANCE_H_ + +#include +using std::vector; + +#include +#include +#include +#include // for ArcFilterType +#include // for QueueType +#include + +namespace fst { +namespace script { + +enum ArcFilterType { ANY_ARC_FILTER, EPSILON_ARC_FILTER, + INPUT_EPSILON_ARC_FILTER, OUTPUT_EPSILON_ARC_FILTER }; + +// See nlp/fst/lib/shortest-distance.h for the template options class +// that this one shadows +struct ShortestDistanceOptions { + const QueueType queue_type; + const ArcFilterType arc_filter_type; + const int64 source; + const float delta; + const bool first_path; + + ShortestDistanceOptions(QueueType qt, ArcFilterType aft, int64 s, + float d) + : queue_type(qt), arc_filter_type(aft), source(s), delta(d), + first_path(false) { } +}; + + + +// 1 +typedef args::Package *, + const ShortestDistanceOptions &> ShortestDistanceArgs1; + +template +struct QueueConstructor { + // template + static Queue *Construct(const Fst &, + const vector *) { + return new Queue(); + } +}; + +// Specializations to deal with AutoQueue, NaturalShortestFirstQueue, +// and TopOrderQueue's different constructors +template +struct QueueConstructor, Arc, ArcFilter> { + // template + static AutoQueue *Construct( + const Fst &fst, + const vector *distance) { + return new AutoQueue(fst, distance, ArcFilter()); + } +}; + +template +struct QueueConstructor, + Arc, ArcFilter> { + // template + static NaturalShortestFirstQueue + *Construct(const Fst &fst, + const vector *distance) { + return new NaturalShortestFirstQueue(*distance); + } +}; + +template +struct QueueConstructor, Arc, ArcFilter> { + // template + static TopOrderQueue *Construct( + const Fst &fst, const vector *weights) { + return new TopOrderQueue(fst, ArcFilter()); + } +}; + + +template +void ShortestDistanceHelper(ShortestDistanceArgs1 *args) { + const Fst &fst = *(args->arg1.GetFst()); + const ShortestDistanceOptions &opts = args->arg3; + + vector weights; + + switch (opts.arc_filter_type) { + case ANY_ARC_FILTER: { + Queue *queue = + QueueConstructor >::Construct( + fst, &weights); + fst::ShortestDistanceOptions > sdopts( + queue, AnyArcFilter(), opts.source, opts.delta); + ShortestDistance(fst, &weights, sdopts); + delete queue; + break; + } + case EPSILON_ARC_FILTER: { + Queue *queue = + QueueConstructor >::Construct( + fst, &weights); + fst::ShortestDistanceOptions > sdopts( + queue, EpsilonArcFilter(), opts.source, opts.delta); + ShortestDistance(fst, &weights, sdopts); + delete queue; + break; + } + case INPUT_EPSILON_ARC_FILTER: { + Queue *queue = + QueueConstructor >::Construct( + fst, &weights); + fst::ShortestDistanceOptions > sdopts( + queue, InputEpsilonArcFilter(), opts.source, opts.delta); + ShortestDistance(fst, &weights, sdopts); + delete queue; + break; + } + case OUTPUT_EPSILON_ARC_FILTER: { + Queue *queue = + QueueConstructor >::Construct( + fst, &weights); + fst::ShortestDistanceOptions > sdopts( + queue, OutputEpsilonArcFilter(), opts.source, opts.delta); + ShortestDistance(fst, &weights, sdopts); + delete queue; + break; + } + } + + // Copy the weights back + args->arg2->resize(weights.size()); + for (unsigned i = 0; i < weights.size(); ++i) { + (*args->arg2)[i] = WeightClass(weights[i]); + } +} + +template +void ShortestDistance(ShortestDistanceArgs1 *args) { + const ShortestDistanceOptions &opts = args->arg3; + typedef typename Arc::StateId StateId; + typedef typename Arc::Weight Weight; + + // Must consider (opts.queue_type x opts.filter_type) options + switch (opts.queue_type) { + default: + FSTERROR() << "Unknown queue type." << opts.queue_type; + + case AUTO_QUEUE: + ShortestDistanceHelper >(args); + return; + + case FIFO_QUEUE: + ShortestDistanceHelper >(args); + return; + + case LIFO_QUEUE: + ShortestDistanceHelper >(args); + return; + + case SHORTEST_FIRST_QUEUE: + ShortestDistanceHelper >(args); + return; + + case STATE_ORDER_QUEUE: + ShortestDistanceHelper >(args); + return; + + case TOP_ORDER_QUEUE: + ShortestDistanceHelper >(args); + return; + } +} + +// 2 +typedef args::Package*, + bool, double> ShortestDistanceArgs2; + +template +void ShortestDistance(ShortestDistanceArgs2 *args) { + const Fst &fst = *(args->arg1.GetFst()); + vector distance; + + ShortestDistance(fst, &distance, args->arg3, args->arg4); + + // convert the typed weights back into weightclass + vector *retval = args->arg2; + retval->resize(distance.size()); + + for (unsigned i = 0; i < distance.size(); ++i) { + (*retval)[i] = WeightClass(distance[i]); + } +} + +// 3 +typedef args::WithReturnValue ShortestDistanceArgs3; + +template +void ShortestDistance(ShortestDistanceArgs3 *args) { + const Fst &fst = *(args->args.GetFst()); + + args->retval = WeightClass(ShortestDistance(fst)); +} + + +// 1 +void ShortestDistance(const FstClass &fst, vector *distance, + const ShortestDistanceOptions &opts); + +// 2 +void ShortestDistance(const FstClass &ifst, vector *distance, + bool reverse = false, double delta = fst::kDelta); + +#ifndef SWIG +// 3 +WeightClass ShortestDistance(const FstClass &ifst); +#endif + +} // namespace script +} // namespace fst + + + +#endif // FST_SCRIPT_SHORTEST_DISTANCE_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/shortest-path.h b/kaldi_io/src/tools/openfst/include/fst/script/shortest-path.h new file mode 100644 index 0000000..b3a3eb9 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/shortest-path.h @@ -0,0 +1,190 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_SHORTEST_PATH_H_ +#define FST_SCRIPT_SHORTEST_PATH_H_ + +#include +using std::vector; + +#include +#include +#include +#include +#include // for ShortestDistanceOptions + +namespace fst { +namespace script { + +struct ShortestPathOptions + : public fst::script::ShortestDistanceOptions { + const size_t nshortest; + const bool unique; + const bool has_distance; + const bool first_path; + const WeightClass weight_threshold; + const int64 state_threshold; + + ShortestPathOptions(QueueType qt, size_t n = 1, + bool u = false, bool hasdist = false, + float d = fst::kDelta, bool fp = false, + WeightClass w = fst::script::WeightClass::Zero(), + int64 s = fst::kNoStateId) + : ShortestDistanceOptions(qt, ANY_ARC_FILTER, kNoStateId, d), + nshortest(n), unique(u), has_distance(hasdist), first_path(fp), + weight_threshold(w), state_threshold(s) { } +}; + +typedef args::Package *, const ShortestPathOptions &> + ShortestPathArgs1; + + +template +void ShortestPath(ShortestPathArgs1 *args) { + const Fst &ifst = *(args->arg1.GetFst()); + MutableFst *ofst = args->arg2->GetMutableFst(); + const ShortestPathOptions &opts = args->arg4; + typedef typename Arc::StateId StateId; + typedef typename Arc::Weight Weight; + typedef AnyArcFilter ArcFilter; + + vector weights; + typename Arc::Weight weight_threshold = + *(opts.weight_threshold.GetWeight()); + + switch (opts.queue_type) { + case AUTO_QUEUE: { + typedef AutoQueue Queue; + Queue *queue = QueueConstructor::Construct(ifst, &weights); + fst::ShortestPathOptions spopts( + queue, ArcFilter(), opts.nshortest, opts.unique, + opts.has_distance, opts.delta, opts.first_path, + weight_threshold, opts.state_threshold); + ShortestPath(ifst, ofst, &weights, spopts); + delete queue; + return; + } + case FIFO_QUEUE: { + typedef FifoQueue Queue; + Queue *queue = QueueConstructor::Construct(ifst, &weights); + fst::ShortestPathOptions spopts( + queue, ArcFilter(), opts.nshortest, opts.unique, + opts.has_distance, opts.delta, opts.first_path, + weight_threshold, opts.state_threshold); + ShortestPath(ifst, ofst, &weights, spopts); + delete queue; + return; + } + case LIFO_QUEUE: { + typedef LifoQueue Queue; + Queue *queue = QueueConstructor::Construct(ifst, &weights); + fst::ShortestPathOptions spopts( + queue, ArcFilter(), opts.nshortest, opts.unique, + opts.has_distance, opts.delta, opts.first_path, + weight_threshold, opts.state_threshold); + ShortestPath(ifst, ofst, &weights, spopts); + delete queue; + return; + } + case SHORTEST_FIRST_QUEUE: { + typedef NaturalShortestFirstQueue Queue; + Queue *queue = QueueConstructor::Construct(ifst, &weights); + fst::ShortestPathOptions spopts( + queue, ArcFilter(), opts.nshortest, opts.unique, + opts.has_distance, opts.delta, opts.first_path, + weight_threshold, opts.state_threshold); + ShortestPath(ifst, ofst, &weights, spopts); + delete queue; + return; + } + case STATE_ORDER_QUEUE: { + typedef StateOrderQueue Queue; + Queue *queue = QueueConstructor::Construct(ifst, &weights); + fst::ShortestPathOptions spopts( + queue, ArcFilter(), opts.nshortest, opts.unique, + opts.has_distance, opts.delta, opts.first_path, + weight_threshold, opts.state_threshold); + ShortestPath(ifst, ofst, &weights, spopts); + delete queue; + return; + } + case TOP_ORDER_QUEUE: { + typedef TopOrderQueue Queue; + Queue *queue = QueueConstructor::Construct(ifst, &weights); + fst::ShortestPathOptions spopts( + queue, ArcFilter(), opts.nshortest, opts.unique, + opts.has_distance, opts.delta, opts.first_path, + weight_threshold, opts.state_threshold); + ShortestPath(ifst, ofst, &weights, spopts); + delete queue; + return; + } + default: + FSTERROR() << "Unknown queue type: " << opts.queue_type; + ofst->SetProperties(kError, kError); + } + + // Copy the weights back + args->arg3->resize(weights.size()); + for (unsigned i = 0; i < weights.size(); ++i) { + (*args->arg3)[i] = WeightClass(weights[i]); + } +} + +// 2 +typedef args::Package ShortestPathArgs2; + +template +void ShortestPath(ShortestPathArgs2 *args) { + const Fst &ifst = *(args->arg1.GetFst()); + MutableFst *ofst = args->arg2->GetMutableFst(); + typename Arc::Weight weight_threshold = + *(args->arg6.GetWeight()); + + ShortestPath(ifst, ofst, args->arg3, args->arg4, args->arg5, + weight_threshold, args->arg7); +} + + +// 1 +void ShortestPath(const FstClass &ifst, MutableFstClass *ofst, + vector *distance, + const ShortestPathOptions &opts); + + +// 2 +void ShortestPath(const FstClass &ifst, MutableFstClass *ofst, + size_t n = 1, bool unique = false, + bool first_path = false, + WeightClass weight_threshold = + fst::script::WeightClass::Zero(), + int64 state_threshold = fst::kNoStateId); + +} // namespace script +} // namespace fst + + + +#endif // FST_SCRIPT_SHORTEST_PATH_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/symbols.h b/kaldi_io/src/tools/openfst/include/fst/script/symbols.h new file mode 100644 index 0000000..927600a --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/symbols.h @@ -0,0 +1,20 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_SYMBOLS_H_ +#define FST_SCRIPT_SYMBOLS_H_ + +#endif // FST_SCRIPT_SYMBOLS_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/synchronize.h b/kaldi_io/src/tools/openfst/include/fst/script/synchronize.h new file mode 100644 index 0000000..3c0c905 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/synchronize.h @@ -0,0 +1,42 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_SYNCHRONIZE_H_ +#define FST_SCRIPT_SYNCHRONIZE_H_ + +#include +#include +#include + +namespace fst { +namespace script { + +typedef args::Package SynchronizeArgs; + +template +void Synchronize(SynchronizeArgs *args) { + const Fst &ifst = *(args->arg1.GetFst()); + MutableFst *ofst = args->arg2->GetMutableFst(); + + Synchronize(ifst, ofst); +} + +void Synchronize(const FstClass &ifst, MutableFstClass *ofst); + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_SYNCHRONIZE_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/text-io.h b/kaldi_io/src/tools/openfst/include/fst/script/text-io.h new file mode 100644 index 0000000..d97a007 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/text-io.h @@ -0,0 +1,51 @@ +// text-io.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// Modified: jpr@google.com (Jake Ratkiewicz) to work with generic WeightClass +// +// \file +// Utilities for reading and writing textual strings representing +// states, labels, and weights and files specifying label-label pairs +// and potentials (state-weight pairs). +// + +#ifndef FST_SCRIPT_TEXT_IO_H__ +#define FST_SCRIPT_TEXT_IO_H__ + +#include +#include +using std::vector; + + +#include +#include +#include +#include + +namespace fst { +namespace script { + +bool ReadPotentials(const string &weight_type, + const string& filename, + vector* potential); + +bool WritePotentials(const string& filename, + const vector& potential); + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_TEXT_IO_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/topsort.h b/kaldi_io/src/tools/openfst/include/fst/script/topsort.h new file mode 100644 index 0000000..4e27e48 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/topsort.h @@ -0,0 +1,40 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_TOPSORT_H_ +#define FST_SCRIPT_TOPSORT_H_ + +#include +#include +#include + +namespace fst { +namespace script { + +typedef args::WithReturnValue TopSortArgs; + +template +void TopSort(TopSortArgs *args) { + MutableFst *fst = args->args->GetMutableFst(); + args->retval = TopSort(fst); +} + +bool TopSort(MutableFstClass *fst); + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_TOPSORT_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/union.h b/kaldi_io/src/tools/openfst/include/fst/script/union.h new file mode 100644 index 0000000..780e484 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/union.h @@ -0,0 +1,42 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +#ifndef FST_SCRIPT_UNION_H_ +#define FST_SCRIPT_UNION_H_ + +#include +#include +#include + +namespace fst { +namespace script { + +typedef args::Package UnionArgs; + +template +void Union(UnionArgs *args) { + MutableFst *fst1 = args->arg1->GetMutableFst(); + const Fst &fst2 = *(args->arg2.GetFst()); + + Union(fst1, fst2); +} + +void Union(MutableFstClass *fst1, const FstClass &fst2); + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_UNION_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/verify.h b/kaldi_io/src/tools/openfst/include/fst/script/verify.h new file mode 100644 index 0000000..6904003 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/verify.h @@ -0,0 +1,40 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: sorenj@google.com (Jeffrey Sorensen) + +#ifndef FST_SCRIPT_VERIFY_H_ +#define FST_SCRIPT_VERIFY_H_ + +#include +#include +#include + +namespace fst { +namespace script { + +typedef args::WithReturnValue VerifyArgs; + +template +void Verify(VerifyArgs *args) { + const Fst *fst = args->args->GetFst(); + args->retval = Verify(*fst); +} + +bool Verify(const FstClass &fst1); + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_VERIFY_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/script/weight-class.h b/kaldi_io/src/tools/openfst/include/fst/script/weight-class.h new file mode 100644 index 0000000..b9f7ddf --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/script/weight-class.h @@ -0,0 +1,223 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: jpr@google.com (Jake Ratkiewicz) + +// Represents a generic weight in an FST -- that is, represents a specific +// type of weight underneath while hiding that type from a client. + + +#ifndef FST_SCRIPT_WEIGHT_CLASS_H_ +#define FST_SCRIPT_WEIGHT_CLASS_H_ + +#include + +#include +#include + +namespace fst { +namespace script { + +class WeightImplBase { + public: + virtual WeightImplBase *Copy() const = 0; + virtual void Print(ostream *o) const = 0; + virtual const string &Type() const = 0; + virtual string to_string() const = 0; + virtual bool operator == (const WeightImplBase &other) const = 0; + virtual ~WeightImplBase() { } +}; + +template +struct WeightClassImpl : public WeightImplBase { + W weight; + + explicit WeightClassImpl(const W& weight) : weight(weight) { } + + virtual WeightClassImpl *Copy() const { + return new WeightClassImpl(weight); + } + + virtual const string &Type() const { return W::Type(); } + + virtual void Print(ostream *o) const { + *o << weight; + } + + virtual string to_string() const { + string str; + WeightToStr(weight, &str); + return str; + } + + virtual bool operator == (const WeightImplBase &other) const { + if (Type() != other.Type()) { + return false; + } else { + const WeightClassImpl *typed_other = + static_cast *>(&other); + + return typed_other->weight == weight; + } + } +}; + + +class WeightClass { + public: + WeightClass() : element_type_(ZERO), impl_(0) { } + + template + explicit WeightClass(const W& weight) + : element_type_(OTHER), impl_(new WeightClassImpl(weight)) { } + + WeightClass(const string &weight_type, const string &weight_str); + + WeightClass(const WeightClass &other) : + element_type_(other.element_type_), + impl_(other.impl_ ? other.impl_->Copy() : 0) { } + + WeightClass &operator = (const WeightClass &other) { + if (impl_) delete impl_; + impl_ = other.impl_ ? other.impl_->Copy() : 0; + element_type_ = other.element_type_; + return *this; + } + + template + const W* GetWeight() const; + + string to_string() const { + switch (element_type_) { + case ZERO: + return "ZERO"; + case ONE: + return "ONE"; + default: + case OTHER: + return impl_->to_string(); + } + } + + bool operator == (const WeightClass &other) const { + return element_type_ == other.element_type_ && + ((impl_ && other.impl_ && (*impl_ == *other.impl_)) || + (impl_ == 0 && other.impl_ == 0)); + } + + static const WeightClass &Zero() { + static WeightClass w(ZERO); + + return w; + } + + static const WeightClass &One() { + static WeightClass w(ONE); + + return w; + } + + const string &Type() const { + if (impl_) return impl_->Type(); + static const string no_type = "none"; + return no_type; + } + + + ~WeightClass() { if (impl_) delete impl_; } + private: + enum ElementType { ZERO, ONE, OTHER }; + ElementType element_type_; + + WeightImplBase *impl_; + + explicit WeightClass(ElementType et) : element_type_(et), impl_(0) { } + + friend ostream &operator << (ostream &o, const WeightClass &c); +}; + +template +const W* WeightClass::GetWeight() const { + // We need to store zero and one as statics, because the weight type + // W might return them as temporaries. We're returning a pointer, + // and it won't do to get the address of a temporary. + static const W zero = W::Zero(); + static const W one = W::One(); + + if (element_type_ == ZERO) { + return &zero; + } else if (element_type_ == ONE) { + return &one; + } else { + if (W::Type() != impl_->Type()) { + return NULL; + } else { + WeightClassImpl *typed_impl = + static_cast *>(impl_); + return &typed_impl->weight; + } + } +} + +// +// Registration for generic weight types. +// + +typedef WeightImplBase* (*StrToWeightImplBaseT)(const string &str, + const string &src, + size_t nline); + +template +WeightImplBase* StrToWeightImplBase(const string &str, + const string &src, size_t nline) { + return new WeightClassImpl(StrToWeight(str, src, nline)); +} + +// The following confuses swig, and doesn't need to be wrapped anyway. +#ifndef SWIG +ostream& operator << (ostream &o, const WeightClass &c); + +class WeightClassRegister : public GenericRegister { + protected: + virtual string ConvertKeyToSoFilename(const string &key) const { + return key + ".so"; + } +}; + +typedef GenericRegisterer WeightClassRegisterer; +#endif + +// internal version, needs to be called by wrapper in order for +// macro args to expand +#define REGISTER_FST_WEIGHT__(Weight, line) \ + static WeightClassRegisterer weight_registerer ## _ ## line( \ + Weight::Type(), \ + StrToWeightImplBase) + +// This layer is where __FILE__ and __LINE__ are expanded +#define REGISTER_FST_WEIGHT_EXPANDER(Weight, line) \ + REGISTER_FST_WEIGHT__(Weight, line) + +// +// Macro for registering new weight types. Clients call this. +// +#define REGISTER_FST_WEIGHT(Weight) \ + REGISTER_FST_WEIGHT_EXPANDER(Weight, __LINE__) + +} // namespace script +} // namespace fst + +#endif // FST_SCRIPT_WEIGHT_CLASS_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/shortest-distance.h b/kaldi_io/src/tools/openfst/include/fst/shortest-distance.h new file mode 100644 index 0000000..ec47a14 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/shortest-distance.h @@ -0,0 +1,348 @@ +// shortest-distance.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: allauzen@google.com (Cyril Allauzen) +// +// \file +// Functions and classes to find shortest distance in an FST. + +#ifndef FST_LIB_SHORTEST_DISTANCE_H__ +#define FST_LIB_SHORTEST_DISTANCE_H__ + +#include +using std::deque; +#include +using std::vector; + +#include +#include +#include +#include +#include + + +namespace fst { + +template +struct ShortestDistanceOptions { + typedef typename Arc::StateId StateId; + + Queue *state_queue; // Queue discipline used; owned by caller + ArcFilter arc_filter; // Arc filter (e.g., limit to only epsilon graph) + StateId source; // If kNoStateId, use the Fst's initial state + float delta; // Determines the degree of convergence required + bool first_path; // For a semiring with the path property (o.w. + // undefined), compute the shortest-distances along + // along the first path to a final state found + // by the algorithm. That path is the shortest-path + // only if the FST has a unique final state (or all + // the final states have the same final weight), the + // queue discipline is shortest-first and all the + // weights in the FST are between One() and Zero() + // according to NaturalLess. + + ShortestDistanceOptions(Queue *q, ArcFilter filt, StateId src = kNoStateId, + float d = kDelta) + : state_queue(q), arc_filter(filt), source(src), delta(d), + first_path(false) {} +}; + + +// Computation state of the shortest-distance algorithm. Reusable +// information is maintained across calls to member function +// ShortestDistance(source) when 'retain' is true for improved +// efficiency when calling multiple times from different source states +// (e.g., in epsilon removal). Contrary to usual conventions, 'fst' +// may not be freed before this class. Vector 'distance' should not be +// modified by the user between these calls. +// The Error() method returns true if an error was encountered. +template +class ShortestDistanceState { + public: + typedef typename Arc::StateId StateId; + typedef typename Arc::Weight Weight; + + ShortestDistanceState( + const Fst &fst, + vector *distance, + const ShortestDistanceOptions &opts, + bool retain) + : fst_(fst), distance_(distance), state_queue_(opts.state_queue), + arc_filter_(opts.arc_filter), delta_(opts.delta), + first_path_(opts.first_path), retain_(retain), source_id_(0), + error_(false) { + distance_->clear(); + } + + ~ShortestDistanceState() {} + + void ShortestDistance(StateId source); + + bool Error() const { return error_; } + + private: + const Fst &fst_; + vector *distance_; + Queue *state_queue_; + ArcFilter arc_filter_; + float delta_; + bool first_path_; + bool retain_; // Retain and reuse information across calls + + vector rdistance_; // Relaxation distance. + vector enqueued_; // Is state enqueued? + vector sources_; // Source ID for ith state in 'distance_', + // 'rdistance_', and 'enqueued_' if retained. + StateId source_id_; // Unique ID characterizing each call to SD + + bool error_; +}; + +// Compute the shortest distance. If 'source' is kNoStateId, use +// the initial state of the Fst. +template +void ShortestDistanceState::ShortestDistance( + StateId source) { + if (fst_.Start() == kNoStateId) { + if (fst_.Properties(kError, false)) error_ = true; + return; + } + + if (!(Weight::Properties() & kRightSemiring)) { + FSTERROR() << "ShortestDistance: Weight needs to be right distributive: " + << Weight::Type(); + error_ = true; + return; + } + + if (first_path_ && !(Weight::Properties() & kPath)) { + FSTERROR() << "ShortestDistance: first_path option disallowed when " + << "Weight does not have the path property: " + << Weight::Type(); + error_ = true; + return; + } + + state_queue_->Clear(); + + if (!retain_) { + distance_->clear(); + rdistance_.clear(); + enqueued_.clear(); + } + + if (source == kNoStateId) + source = fst_.Start(); + + while (distance_->size() <= source) { + distance_->push_back(Weight::Zero()); + rdistance_.push_back(Weight::Zero()); + enqueued_.push_back(false); + } + if (retain_) { + while (sources_.size() <= source) + sources_.push_back(kNoStateId); + sources_[source] = source_id_; + } + (*distance_)[source] = Weight::One(); + rdistance_[source] = Weight::One(); + enqueued_[source] = true; + + state_queue_->Enqueue(source); + + while (!state_queue_->Empty()) { + StateId s = state_queue_->Head(); + state_queue_->Dequeue(); + while (distance_->size() <= s) { + distance_->push_back(Weight::Zero()); + rdistance_.push_back(Weight::Zero()); + enqueued_.push_back(false); + } + if (first_path_ && (fst_.Final(s) != Weight::Zero())) + break; + enqueued_[s] = false; + Weight r = rdistance_[s]; + rdistance_[s] = Weight::Zero(); + for (ArcIterator< Fst > aiter(fst_, s); + !aiter.Done(); + aiter.Next()) { + const Arc &arc = aiter.Value(); + if (!arc_filter_(arc)) + continue; + while (distance_->size() <= arc.nextstate) { + distance_->push_back(Weight::Zero()); + rdistance_.push_back(Weight::Zero()); + enqueued_.push_back(false); + } + if (retain_) { + while (sources_.size() <= arc.nextstate) + sources_.push_back(kNoStateId); + if (sources_[arc.nextstate] != source_id_) { + (*distance_)[arc.nextstate] = Weight::Zero(); + rdistance_[arc.nextstate] = Weight::Zero(); + enqueued_[arc.nextstate] = false; + sources_[arc.nextstate] = source_id_; + } + } + Weight &nd = (*distance_)[arc.nextstate]; + Weight &nr = rdistance_[arc.nextstate]; + Weight w = Times(r, arc.weight); + if (!ApproxEqual(nd, Plus(nd, w), delta_)) { + nd = Plus(nd, w); + nr = Plus(nr, w); + if (!nd.Member() || !nr.Member()) { + error_ = true; + return; + } + if (!enqueued_[arc.nextstate]) { + state_queue_->Enqueue(arc.nextstate); + enqueued_[arc.nextstate] = true; + } else { + state_queue_->Update(arc.nextstate); + } + } + } + } + ++source_id_; + if (fst_.Properties(kError, false)) error_ = true; +} + + +// Shortest-distance algorithm: this version allows fine control +// via the options argument. See below for a simpler interface. +// +// This computes the shortest distance from the 'opts.source' state to +// each visited state S and stores the value in the 'distance' vector. +// An unvisited state S has distance Zero(), which will be stored in +// the 'distance' vector if S is less than the maximum visited state. +// The state queue discipline, arc filter, and convergence delta are +// taken in the options argument. +// The 'distance' vector will contain a unique element for which +// Member() is false if an error was encountered. +// +// The weights must must be right distributive and k-closed (i.e., 1 + +// x + x^2 + ... + x^(k +1) = 1 + x + x^2 + ... + x^k). +// +// The algorithm is from Mohri, "Semiring Framweork and Algorithms for +// Shortest-Distance Problems", Journal of Automata, Languages and +// Combinatorics 7(3):321-350, 2002. The complexity of algorithm +// depends on the properties of the semiring and the queue discipline +// used. Refer to the paper for more details. +template +void ShortestDistance( + const Fst &fst, + vector *distance, + const ShortestDistanceOptions &opts) { + + ShortestDistanceState + sd_state(fst, distance, opts, false); + sd_state.ShortestDistance(opts.source); + if (sd_state.Error()) { + distance->clear(); + distance->resize(1, Arc::Weight::NoWeight()); + } +} + +// Shortest-distance algorithm: simplified interface. See above for a +// version that allows finer control. +// +// If 'reverse' is false, this computes the shortest distance from the +// initial state to each state S and stores the value in the +// 'distance' vector. If 'reverse' is true, this computes the shortest +// distance from each state to the final states. An unvisited state S +// has distance Zero(), which will be stored in the 'distance' vector +// if S is less than the maximum visited state. The state queue +// discipline is automatically-selected. +// The 'distance' vector will contain a unique element for which +// Member() is false if an error was encountered. +// +// The weights must must be right (left) distributive if reverse is +// false (true) and k-closed (i.e., 1 + x + x^2 + ... + x^(k +1) = 1 + +// x + x^2 + ... + x^k). +// +// The algorithm is from Mohri, "Semiring Framweork and Algorithms for +// Shortest-Distance Problems", Journal of Automata, Languages and +// Combinatorics 7(3):321-350, 2002. The complexity of algorithm +// depends on the properties of the semiring and the queue discipline +// used. Refer to the paper for more details. +template +void ShortestDistance(const Fst &fst, + vector *distance, + bool reverse = false, + float delta = kDelta) { + typedef typename Arc::StateId StateId; + typedef typename Arc::Weight Weight; + + if (!reverse) { + AnyArcFilter arc_filter; + AutoQueue state_queue(fst, distance, arc_filter); + ShortestDistanceOptions< Arc, AutoQueue, AnyArcFilter > + opts(&state_queue, arc_filter); + opts.delta = delta; + ShortestDistance(fst, distance, opts); + } else { + typedef ReverseArc ReverseArc; + typedef typename ReverseArc::Weight ReverseWeight; + AnyArcFilter rarc_filter; + VectorFst rfst; + Reverse(fst, &rfst); + vector rdistance; + AutoQueue state_queue(rfst, &rdistance, rarc_filter); + ShortestDistanceOptions< ReverseArc, AutoQueue, + AnyArcFilter > + ropts(&state_queue, rarc_filter); + ropts.delta = delta; + ShortestDistance(rfst, &rdistance, ropts); + distance->clear(); + if (rdistance.size() == 1 && !rdistance[0].Member()) { + distance->resize(1, Arc::Weight::NoWeight()); + return; + } + while (distance->size() < rdistance.size() - 1) + distance->push_back(rdistance[distance->size() + 1].Reverse()); + } +} + + +// Return the sum of the weight of all successful paths in an FST, i.e., +// the shortest-distance from the initial state to the final states. +// Returns a weight such that Member() is false if an error was encountered. +template +typename Arc::Weight ShortestDistance(const Fst &fst, float delta = kDelta) { + typedef typename Arc::Weight Weight; + typedef typename Arc::StateId StateId; + vector distance; + if (Weight::Properties() & kRightSemiring) { + ShortestDistance(fst, &distance, false, delta); + if (distance.size() == 1 && !distance[0].Member()) + return Arc::Weight::NoWeight(); + Weight sum = Weight::Zero(); + for (StateId s = 0; s < distance.size(); ++s) + sum = Plus(sum, Times(distance[s], fst.Final(s))); + return sum; + } else { + ShortestDistance(fst, &distance, true, delta); + StateId s = fst.Start(); + if (distance.size() == 1 && !distance[0].Member()) + return Arc::Weight::NoWeight(); + return s != kNoStateId && s < distance.size() ? + distance[s] : Weight::Zero(); + } +} + + +} // namespace fst + +#endif // FST_LIB_SHORTEST_DISTANCE_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/shortest-path.h b/kaldi_io/src/tools/openfst/include/fst/shortest-path.h new file mode 100644 index 0000000..9cd13d9 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/shortest-path.h @@ -0,0 +1,501 @@ +// shortest-path.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: allauzen@google.com (Cyril Allauzen) +// +// \file +// Functions to find shortest paths in an FST. + +#ifndef FST_LIB_SHORTEST_PATH_H__ +#define FST_LIB_SHORTEST_PATH_H__ + +#include +#include +using std::pair; using std::make_pair; +#include +using std::vector; + +#include +#include +#include +#include +#include + + +namespace fst { + +template +struct ShortestPathOptions + : public ShortestDistanceOptions { + typedef typename Arc::StateId StateId; + typedef typename Arc::Weight Weight; + size_t nshortest; // return n-shortest paths + bool unique; // only return paths with distinct input strings + bool has_distance; // distance vector already contains the + // shortest distance from the initial state + bool first_path; // Single shortest path stops after finding the first + // path to a final state. That path is the shortest path + // only when using the ShortestFirstQueue and + // only when all the weights in the FST are between + // One() and Zero() according to NaturalLess. + Weight weight_threshold; // pruning weight threshold. + StateId state_threshold; // pruning state threshold. + + ShortestPathOptions(Queue *q, ArcFilter filt, size_t n = 1, bool u = false, + bool hasdist = false, float d = kDelta, + bool fp = false, Weight w = Weight::Zero(), + StateId s = kNoStateId) + : ShortestDistanceOptions(q, filt, kNoStateId, d), + nshortest(n), unique(u), has_distance(hasdist), first_path(fp), + weight_threshold(w), state_threshold(s) {} +}; + + +// Shortest-path algorithm: normally not called directly; prefer +// 'ShortestPath' below with n=1. 'ofst' contains the shortest path in +// 'ifst'. 'distance' returns the shortest distances from the source +// state to each state in 'ifst'. 'opts' is used to specify options +// such as the queue discipline, the arc filter and delta. +// +// The shortest path is the lowest weight path w.r.t. the natural +// semiring order. +// +// The weights need to be right distributive and have the path (kPath) +// property. +template +void SingleShortestPath(const Fst &ifst, + MutableFst *ofst, + vector *distance, + ShortestPathOptions &opts) { + typedef typename Arc::StateId StateId; + typedef typename Arc::Weight Weight; + + ofst->DeleteStates(); + ofst->SetInputSymbols(ifst.InputSymbols()); + ofst->SetOutputSymbols(ifst.OutputSymbols()); + + if (ifst.Start() == kNoStateId) { + if (ifst.Properties(kError, false)) ofst->SetProperties(kError, kError); + return; + } + + vector enqueued; + vector parent; + vector arc_parent; + + Queue *state_queue = opts.state_queue; + StateId source = opts.source == kNoStateId ? ifst.Start() : opts.source; + Weight f_distance = Weight::Zero(); + StateId f_parent = kNoStateId; + + distance->clear(); + state_queue->Clear(); + if (opts.nshortest != 1) { + FSTERROR() << "SingleShortestPath: for nshortest > 1, use ShortestPath" + << " instead"; + ofst->SetProperties(kError, kError); + return; + } + if (opts.weight_threshold != Weight::Zero() || + opts.state_threshold != kNoStateId) { + FSTERROR() << + "SingleShortestPath: weight and state thresholds not applicable"; + ofst->SetProperties(kError, kError); + return; + } + if ((Weight::Properties() & (kPath | kRightSemiring)) + != (kPath | kRightSemiring)) { + FSTERROR() << "SingleShortestPath: Weight needs to have the path" + << " property and be right distributive: " << Weight::Type(); + ofst->SetProperties(kError, kError); + return; + } + while (distance->size() < source) { + distance->push_back(Weight::Zero()); + enqueued.push_back(false); + parent.push_back(kNoStateId); + arc_parent.push_back(Arc(kNoLabel, kNoLabel, Weight::Zero(), kNoStateId)); + } + distance->push_back(Weight::One()); + parent.push_back(kNoStateId); + arc_parent.push_back(Arc(kNoLabel, kNoLabel, Weight::Zero(), kNoStateId)); + state_queue->Enqueue(source); + enqueued.push_back(true); + + while (!state_queue->Empty()) { + StateId s = state_queue->Head(); + state_queue->Dequeue(); + enqueued[s] = false; + Weight sd = (*distance)[s]; + if (ifst.Final(s) != Weight::Zero()) { + Weight w = Times(sd, ifst.Final(s)); + if (f_distance != Plus(f_distance, w)) { + f_distance = Plus(f_distance, w); + f_parent = s; + } + if (!f_distance.Member()) { + ofst->SetProperties(kError, kError); + return; + } + if (opts.first_path) + break; + } + for (ArcIterator< Fst > aiter(ifst, s); + !aiter.Done(); + aiter.Next()) { + const Arc &arc = aiter.Value(); + while (distance->size() <= arc.nextstate) { + distance->push_back(Weight::Zero()); + enqueued.push_back(false); + parent.push_back(kNoStateId); + arc_parent.push_back(Arc(kNoLabel, kNoLabel, Weight::Zero(), + kNoStateId)); + } + Weight &nd = (*distance)[arc.nextstate]; + Weight w = Times(sd, arc.weight); + if (nd != Plus(nd, w)) { + nd = Plus(nd, w); + if (!nd.Member()) { + ofst->SetProperties(kError, kError); + return; + } + parent[arc.nextstate] = s; + arc_parent[arc.nextstate] = arc; + if (!enqueued[arc.nextstate]) { + state_queue->Enqueue(arc.nextstate); + enqueued[arc.nextstate] = true; + } else { + state_queue->Update(arc.nextstate); + } + } + } + } + + StateId s_p = kNoStateId, d_p = kNoStateId; + for (StateId s = f_parent, d = kNoStateId; + s != kNoStateId; + d = s, s = parent[s]) { + d_p = s_p; + s_p = ofst->AddState(); + if (d == kNoStateId) { + ofst->SetFinal(s_p, ifst.Final(f_parent)); + } else { + arc_parent[d].nextstate = d_p; + ofst->AddArc(s_p, arc_parent[d]); + } + } + ofst->SetStart(s_p); + if (ifst.Properties(kError, false)) ofst->SetProperties(kError, kError); + ofst->SetProperties( + ShortestPathProperties(ofst->Properties(kFstProperties, false)), + kFstProperties); +} + + +template +class ShortestPathCompare { + public: + typedef S StateId; + typedef W Weight; + typedef pair Pair; + + ShortestPathCompare(const vector& pairs, + const vector& distance, + StateId sfinal, float d) + : pairs_(pairs), distance_(distance), superfinal_(sfinal), delta_(d) {} + + bool operator()(const StateId x, const StateId y) const { + const Pair &px = pairs_[x]; + const Pair &py = pairs_[y]; + Weight dx = px.first == superfinal_ ? Weight::One() : + px.first < distance_.size() ? distance_[px.first] : Weight::Zero(); + Weight dy = py.first == superfinal_ ? Weight::One() : + py.first < distance_.size() ? distance_[py.first] : Weight::Zero(); + Weight wx = Times(dx, px.second); + Weight wy = Times(dy, py.second); + // Penalize complete paths to ensure correct results with inexact weights. + // This forms a strict weak order so long as ApproxEqual(a, b) => + // ApproxEqual(a, c) for all c s.t. less_(a, c) && less_(c, b). + if (px.first == superfinal_ && py.first != superfinal_) { + return less_(wy, wx) || ApproxEqual(wx, wy, delta_); + } else if (py.first == superfinal_ && px.first != superfinal_) { + return less_(wy, wx) && !ApproxEqual(wx, wy, delta_); + } else { + return less_(wy, wx); + } + } + + private: + const vector &pairs_; + const vector &distance_; + StateId superfinal_; + float delta_; + NaturalLess less_; +}; + + +// N-Shortest-path algorithm: implements the core n-shortest path +// algorithm. The output is built REVERSED. See below for versions with +// more options and not reversed. +// +// 'ofst' contains the REVERSE of 'n'-shortest paths in 'ifst'. +// 'distance' must contain the shortest distance from each state to a final +// state in 'ifst'. 'delta' is the convergence delta. +// +// The n-shortest paths are the n-lowest weight paths w.r.t. the +// natural semiring order. The single path that can be read from the +// ith of at most n transitions leaving the initial state of 'ofst' is +// the ith shortest path. Disregarding the initial state and initial +// transitions, the n-shortest paths, in fact, form a tree rooted at +// the single final state. +// +// The weights need to be left and right distributive (kSemiring) and +// have the path (kPath) property. +// +// The algorithm is from Mohri and Riley, "An Efficient Algorithm for +// the n-best-strings problem", ICSLP 2002. The algorithm relies on +// the shortest-distance algorithm. There are some issues with the +// pseudo-code as written in the paper (viz., line 11). +// +// IMPLEMENTATION NOTE: The input fst 'ifst' can be a delayed fst and +// and at any state in its expansion the values of distance vector need only +// be defined at that time for the states that are known to exist. +template +void NShortestPath(const Fst &ifst, + MutableFst *ofst, + const vector &distance, + size_t n, + float delta = kDelta, + typename Arc::Weight weight_threshold = Arc::Weight::Zero(), + typename Arc::StateId state_threshold = kNoStateId) { + typedef typename Arc::StateId StateId; + typedef typename Arc::Weight Weight; + typedef pair Pair; + typedef typename RevArc::Weight RevWeight; + + if (n <= 0) return; + if ((Weight::Properties() & (kPath | kSemiring)) != (kPath | kSemiring)) { + FSTERROR() << "NShortestPath: Weight needs to have the " + << "path property and be distributive: " + << Weight::Type(); + ofst->SetProperties(kError, kError); + return; + } + ofst->DeleteStates(); + ofst->SetInputSymbols(ifst.InputSymbols()); + ofst->SetOutputSymbols(ifst.OutputSymbols()); + // Each state in 'ofst' corresponds to a path with weight w from the + // initial state of 'ifst' to a state s in 'ifst', that can be + // characterized by a pair (s,w). The vector 'pairs' maps each + // state in 'ofst' to the corresponding pair maps states in OFST to + // the corresponding pair (s,w). + vector pairs; + // The supefinal state is denoted by -1, 'compare' knows that the + // distance from 'superfinal' to the final state is 'Weight::One()', + // hence 'distance[superfinal]' is not needed. + StateId superfinal = -1; + ShortestPathCompare + compare(pairs, distance, superfinal, delta); + vector heap; + // 'r[s + 1]', 's' state in 'fst', is the number of states in 'ofst' + // which corresponding pair contains 's' ,i.e. , it is number of + // paths computed so far to 's'. Valid for 's == -1' (superfinal). + vector r; + NaturalLess less; + if (ifst.Start() == kNoStateId || + distance.size() <= ifst.Start() || + distance[ifst.Start()] == Weight::Zero() || + less(weight_threshold, Weight::One()) || + state_threshold == 0) { + if (ifst.Properties(kError, false)) ofst->SetProperties(kError, kError); + return; + } + ofst->SetStart(ofst->AddState()); + StateId final = ofst->AddState(); + ofst->SetFinal(final, Weight::One()); + while (pairs.size() <= final) + pairs.push_back(Pair(kNoStateId, Weight::Zero())); + pairs[final] = Pair(ifst.Start(), Weight::One()); + heap.push_back(final); + Weight limit = Times(distance[ifst.Start()], weight_threshold); + + while (!heap.empty()) { + pop_heap(heap.begin(), heap.end(), compare); + StateId state = heap.back(); + Pair p = pairs[state]; + heap.pop_back(); + Weight d = p.first == superfinal ? Weight::One() : + p.first < distance.size() ? distance[p.first] : Weight::Zero(); + + if (less(limit, Times(d, p.second)) || + (state_threshold != kNoStateId && + ofst->NumStates() >= state_threshold)) + continue; + + while (r.size() <= p.first + 1) r.push_back(0); + ++r[p.first + 1]; + if (p.first == superfinal) + ofst->AddArc(ofst->Start(), Arc(0, 0, Weight::One(), state)); + if ((p.first == superfinal) && (r[p.first + 1] == n)) break; + if (r[p.first + 1] > n) continue; + if (p.first == superfinal) continue; + + for (ArcIterator< Fst > aiter(ifst, p.first); + !aiter.Done(); + aiter.Next()) { + const RevArc &rarc = aiter.Value(); + Arc arc(rarc.ilabel, rarc.olabel, rarc.weight.Reverse(), rarc.nextstate); + Weight w = Times(p.second, arc.weight); + StateId next = ofst->AddState(); + pairs.push_back(Pair(arc.nextstate, w)); + arc.nextstate = state; + ofst->AddArc(next, arc); + heap.push_back(next); + push_heap(heap.begin(), heap.end(), compare); + } + + Weight finalw = ifst.Final(p.first).Reverse(); + if (finalw != Weight::Zero()) { + Weight w = Times(p.second, finalw); + StateId next = ofst->AddState(); + pairs.push_back(Pair(superfinal, w)); + ofst->AddArc(next, Arc(0, 0, finalw, state)); + heap.push_back(next); + push_heap(heap.begin(), heap.end(), compare); + } + } + Connect(ofst); + if (ifst.Properties(kError, false)) ofst->SetProperties(kError, kError); + ofst->SetProperties( + ShortestPathProperties(ofst->Properties(kFstProperties, false)), + kFstProperties); +} + + +// N-Shortest-path algorithm: this version allow fine control +// via the options argument. See below for a simpler interface. +// +// 'ofst' contains the n-shortest paths in 'ifst'. 'distance' returns +// the shortest distances from the source state to each state in +// 'ifst'. 'opts' is used to specify options such as the number of +// paths to return, whether they need to have distinct input +// strings, the queue discipline, the arc filter and the convergence +// delta. +// +// The n-shortest paths are the n-lowest weight paths w.r.t. the +// natural semiring order. The single path that can be read from the +// ith of at most n transitions leaving the initial state of 'ofst' is +// the ith shortest path. Disregarding the initial state and initial +// transitions, The n-shortest paths, in fact, form a tree rooted at +// the single final state. + +// The weights need to be right distributive and have the path (kPath) +// property. They need to be left distributive as well for nshortest +// > 1. +// +// The algorithm is from Mohri and Riley, "An Efficient Algorithm for +// the n-best-strings problem", ICSLP 2002. The algorithm relies on +// the shortest-distance algorithm. There are some issues with the +// pseudo-code as written in the paper (viz., line 11). +template +void ShortestPath(const Fst &ifst, MutableFst *ofst, + vector *distance, + ShortestPathOptions &opts) { + typedef typename Arc::StateId StateId; + typedef typename Arc::Weight Weight; + typedef ReverseArc ReverseArc; + + size_t n = opts.nshortest; + if (n == 1) { + SingleShortestPath(ifst, ofst, distance, opts); + return; + } + if (n <= 0) return; + if ((Weight::Properties() & (kPath | kSemiring)) != (kPath | kSemiring)) { + FSTERROR() << "ShortestPath: n-shortest: Weight needs to have the " + << "path property and be distributive: " + << Weight::Type(); + ofst->SetProperties(kError, kError); + return; + } + if (!opts.has_distance) { + ShortestDistance(ifst, distance, opts); + if (distance->size() == 1 && !(*distance)[0].Member()) { + ofst->SetProperties(kError, kError); + return; + } + } + // Algorithm works on the reverse of 'fst' : 'rfst', 'distance' is + // the distance to the final state in 'rfst', 'ofst' is built as the + // reverse of the tree of n-shortest path in 'rfst'. + VectorFst rfst; + Reverse(ifst, &rfst); + Weight d = Weight::Zero(); + for (ArcIterator< VectorFst > aiter(rfst, 0); + !aiter.Done(); aiter.Next()) { + const ReverseArc &arc = aiter.Value(); + StateId s = arc.nextstate - 1; + if (s < distance->size()) + d = Plus(d, Times(arc.weight.Reverse(), (*distance)[s])); + } + distance->insert(distance->begin(), d); + + if (!opts.unique) { + NShortestPath(rfst, ofst, *distance, n, opts.delta, + opts.weight_threshold, opts.state_threshold); + } else { + vector ddistance; + DeterminizeFstOptions dopts(opts.delta); + DeterminizeFst dfst(rfst, distance, &ddistance, dopts); + NShortestPath(dfst, ofst, ddistance, n, opts.delta, + opts.weight_threshold, opts.state_threshold); + } + distance->erase(distance->begin()); +} + + +// Shortest-path algorithm: simplified interface. See above for a +// version that allows finer control. +// +// 'ofst' contains the 'n'-shortest paths in 'ifst'. The queue +// discipline is automatically selected. When 'unique' == true, only +// paths with distinct input labels are returned. +// +// The n-shortest paths are the n-lowest weight paths w.r.t. the +// natural semiring order. The single path that can be read from the +// ith of at most n transitions leaving the initial state of 'ofst' is +// the ith best path. +// +// The weights need to be right distributive and have the path +// (kPath) property. +template +void ShortestPath(const Fst &ifst, MutableFst *ofst, + size_t n = 1, bool unique = false, + bool first_path = false, + typename Arc::Weight weight_threshold = Arc::Weight::Zero(), + typename Arc::StateId state_threshold = kNoStateId) { + vector distance; + AnyArcFilter arc_filter; + AutoQueue state_queue(ifst, &distance, arc_filter); + ShortestPathOptions< Arc, AutoQueue, + AnyArcFilter > opts(&state_queue, arc_filter, n, unique, false, + kDelta, first_path, weight_threshold, + state_threshold); + ShortestPath(ifst, ofst, &distance, opts); +} + +} // namespace fst + +#endif // FST_LIB_SHORTEST_PATH_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/signed-log-weight.h b/kaldi_io/src/tools/openfst/include/fst/signed-log-weight.h new file mode 100644 index 0000000..61adefb --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/signed-log-weight.h @@ -0,0 +1,367 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: krr@google.com (Kasturi Rangan Raghavan) +// \file +// LogWeight along with sign information that represents the value X in the +// linear domain as +// The sign is a TropicalWeight: +// positive, TropicalWeight.Value() > 0.0, recommended value 1.0 +// negative, TropicalWeight.Value() <= 0.0, recommended value -1.0 + +#ifndef FST_LIB_SIGNED_LOG_WEIGHT_H_ +#define FST_LIB_SIGNED_LOG_WEIGHT_H_ + +#include +#include + + +namespace fst { +template +class SignedLogWeightTpl + : public PairWeight > { + public: + typedef TropicalWeight X1; + typedef LogWeightTpl X2; + using PairWeight::Value1; + using PairWeight::Value2; + + using PairWeight::Reverse; + using PairWeight::Quantize; + using PairWeight::Member; + + typedef SignedLogWeightTpl ReverseWeight; + + SignedLogWeightTpl() : PairWeight() {} + + SignedLogWeightTpl(const SignedLogWeightTpl& w) + : PairWeight (w) { } + + SignedLogWeightTpl(const PairWeight& w) + : PairWeight (w) { } + + SignedLogWeightTpl(const X1& x1, const X2& x2) + : PairWeight(x1, x2) { } + + static const SignedLogWeightTpl &Zero() { + static const SignedLogWeightTpl zero(X1(1.0), X2::Zero()); + return zero; + } + + static const SignedLogWeightTpl &One() { + static const SignedLogWeightTpl one(X1(1.0), X2::One()); + return one; + } + + static const SignedLogWeightTpl &NoWeight() { + static const SignedLogWeightTpl no_weight(X1(1.0), X2::NoWeight()); + return no_weight; + } + + static const string &Type() { + static const string type = "signed_log_" + X1::Type() + "_" + X2::Type(); + return type; + } + + ProductWeight Quantize(float delta = kDelta) const { + return PairWeight::Quantize(); + } + + ReverseWeight Reverse() const { + return PairWeight::Reverse(); + } + + bool Member() const { + return PairWeight::Member(); + } + + static uint64 Properties() { + // not idempotent nor path + return kLeftSemiring | kRightSemiring | kCommutative; + } + + size_t Hash() const { + size_t h1; + if (Value2() == X2::Zero() || Value1().Value() > 0.0) + h1 = TropicalWeight(1.0).Hash(); + else + h1 = TropicalWeight(-1.0).Hash(); + size_t h2 = Value2().Hash(); + const int lshift = 5; + const int rshift = CHAR_BIT * sizeof(size_t) - 5; + return h1 << lshift ^ h1 >> rshift ^ h2; + } +}; + +template +inline SignedLogWeightTpl Plus(const SignedLogWeightTpl &w1, + const SignedLogWeightTpl &w2) { + if (!w1.Member() || !w2.Member()) + return SignedLogWeightTpl::NoWeight(); + bool s1 = w1.Value1().Value() > 0.0; + bool s2 = w2.Value1().Value() > 0.0; + T f1 = w1.Value2().Value(); + T f2 = w2.Value2().Value(); + if (f1 == FloatLimits::PosInfinity()) + return w2; + else if (f2 == FloatLimits::PosInfinity()) + return w1; + else if (f1 == f2) { + if (s1 == s2) + return SignedLogWeightTpl(w1.Value1(), (f2 - log(2.0F))); + else + return SignedLogWeightTpl::Zero(); + } else if (f1 > f2) { + if (s1 == s2) { + return SignedLogWeightTpl( + w1.Value1(), (f2 - log(1.0F + exp(f2 - f1)))); + } else { + return SignedLogWeightTpl( + w2.Value1(), (f2 - log(1.0F - exp(f2 - f1)))); + } + } else { + if (s2 == s1) { + return SignedLogWeightTpl( + w2.Value1(), (f1 - log(1.0F + exp(f1 - f2)))); + } else { + return SignedLogWeightTpl( + w1.Value1(), (f1 - log(1.0F - exp(f1 - f2)))); + } + } +} + +template +inline SignedLogWeightTpl Minus(const SignedLogWeightTpl &w1, + const SignedLogWeightTpl &w2) { + SignedLogWeightTpl minus_w2(-w2.Value1().Value(), w2.Value2()); + return Plus(w1, minus_w2); +} + +template +inline SignedLogWeightTpl Times(const SignedLogWeightTpl &w1, + const SignedLogWeightTpl &w2) { + if (!w1.Member() || !w2.Member()) + return SignedLogWeightTpl::NoWeight(); + bool s1 = w1.Value1().Value() > 0.0; + bool s2 = w2.Value1().Value() > 0.0; + T f1 = w1.Value2().Value(); + T f2 = w2.Value2().Value(); + if (s1 == s2) + return SignedLogWeightTpl(TropicalWeight(1.0), (f1 + f2)); + else + return SignedLogWeightTpl(TropicalWeight(-1.0), (f1 + f2)); +} + +template +inline SignedLogWeightTpl Divide(const SignedLogWeightTpl &w1, + const SignedLogWeightTpl &w2, + DivideType typ = DIVIDE_ANY) { + if (!w1.Member() || !w2.Member()) + return SignedLogWeightTpl::NoWeight(); + bool s1 = w1.Value1().Value() > 0.0; + bool s2 = w2.Value1().Value() > 0.0; + T f1 = w1.Value2().Value(); + T f2 = w2.Value2().Value(); + if (f2 == FloatLimits::PosInfinity()) + return SignedLogWeightTpl(TropicalWeight(1.0), + FloatLimits::NumberBad()); + else if (f1 == FloatLimits::PosInfinity()) + return SignedLogWeightTpl(TropicalWeight(1.0), + FloatLimits::PosInfinity()); + else if (s1 == s2) + return SignedLogWeightTpl(TropicalWeight(1.0), (f1 - f2)); + else + return SignedLogWeightTpl(TropicalWeight(-1.0), (f1 - f2)); +} + +template +inline bool ApproxEqual(const SignedLogWeightTpl &w1, + const SignedLogWeightTpl &w2, + float delta = kDelta) { + bool s1 = w1.Value1().Value() > 0.0; + bool s2 = w2.Value1().Value() > 0.0; + if (s1 == s2) { + return ApproxEqual(w1.Value2(), w2.Value2(), delta); + } else { + return w1.Value2() == LogWeightTpl::Zero() + && w2.Value2() == LogWeightTpl::Zero(); + } +} + +template +inline bool operator==(const SignedLogWeightTpl &w1, + const SignedLogWeightTpl &w2) { + bool s1 = w1.Value1().Value() > 0.0; + bool s2 = w2.Value1().Value() > 0.0; + if (s1 == s2) + return w1.Value2() == w2.Value2(); + else + return (w1.Value2() == LogWeightTpl::Zero()) && + (w2.Value2() == LogWeightTpl::Zero()); +} + + +// Single-precision signed-log weight +typedef SignedLogWeightTpl SignedLogWeight; +// Double-precision signed-log weight +typedef SignedLogWeightTpl SignedLog64Weight; + +// +// WEIGHT CONVERTER SPECIALIZATIONS. +// + +template +bool SignedLogConvertCheck(W1 w) { + if (w.Value1().Value() < 0.0) { + FSTERROR() << "WeightConvert: can't convert weight from \"" + << W1::Type() << "\" to \"" << W2::Type(); + return false; + } + return true; +} + +// Convert to tropical +template <> +struct WeightConvert { + TropicalWeight operator()(SignedLogWeight w) const { + if (!SignedLogConvertCheck(w)) + return TropicalWeight::NoWeight(); + return w.Value2().Value(); + } +}; + +template <> +struct WeightConvert { + TropicalWeight operator()(SignedLog64Weight w) const { + if (!SignedLogConvertCheck(w)) + return TropicalWeight::NoWeight(); + return w.Value2().Value(); + } +}; + +// Convert to log +template <> +struct WeightConvert { + LogWeight operator()(SignedLogWeight w) const { + if (!SignedLogConvertCheck(w)) + return LogWeight::NoWeight(); + return w.Value2().Value(); + } +}; + +template <> +struct WeightConvert { + LogWeight operator()(SignedLog64Weight w) const { + if (!SignedLogConvertCheck(w)) + return LogWeight::NoWeight(); + return w.Value2().Value(); + } +}; + +// Convert to log64 +template <> +struct WeightConvert { + Log64Weight operator()(SignedLogWeight w) const { + if (!SignedLogConvertCheck(w)) + return Log64Weight::NoWeight(); + return w.Value2().Value(); + } +}; + +template <> +struct WeightConvert { + Log64Weight operator()(SignedLog64Weight w) const { + if (!SignedLogConvertCheck(w)) + return Log64Weight::NoWeight(); + return w.Value2().Value(); + } +}; + +// Convert to signed log +template <> +struct WeightConvert { + SignedLogWeight operator()(TropicalWeight w) const { + TropicalWeight x1 = 1.0; + LogWeight x2 = w.Value(); + return SignedLogWeight(x1, x2); + } +}; + +template <> +struct WeightConvert { + SignedLogWeight operator()(LogWeight w) const { + TropicalWeight x1 = 1.0; + LogWeight x2 = w.Value(); + return SignedLogWeight(x1, x2); + } +}; + +template <> +struct WeightConvert { + SignedLogWeight operator()(Log64Weight w) const { + TropicalWeight x1 = 1.0; + LogWeight x2 = w.Value(); + return SignedLogWeight(x1, x2); + } +}; + +template <> +struct WeightConvert { + SignedLogWeight operator()(SignedLog64Weight w) const { + TropicalWeight x1 = w.Value1(); + LogWeight x2 = w.Value2().Value(); + return SignedLogWeight(x1, x2); + } +}; + +// Convert to signed log64 +template <> +struct WeightConvert { + SignedLog64Weight operator()(TropicalWeight w) const { + TropicalWeight x1 = 1.0; + Log64Weight x2 = w.Value(); + return SignedLog64Weight(x1, x2); + } +}; + +template <> +struct WeightConvert { + SignedLog64Weight operator()(LogWeight w) const { + TropicalWeight x1 = 1.0; + Log64Weight x2 = w.Value(); + return SignedLog64Weight(x1, x2); + } +}; + +template <> +struct WeightConvert { + SignedLog64Weight operator()(Log64Weight w) const { + TropicalWeight x1 = 1.0; + Log64Weight x2 = w.Value(); + return SignedLog64Weight(x1, x2); + } +}; + +template <> +struct WeightConvert { + SignedLog64Weight operator()(SignedLogWeight w) const { + TropicalWeight x1 = w.Value1(); + Log64Weight x2 = w.Value2().Value(); + return SignedLog64Weight(x1, x2); + } +}; + +} // namespace fst + +#endif // FST_LIB_SIGNED_LOG_WEIGHT_H_ diff --git a/kaldi_io/src/tools/openfst/include/fst/slist.h b/kaldi_io/src/tools/openfst/include/fst/slist.h new file mode 100644 index 0000000..b800522 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/slist.h @@ -0,0 +1,61 @@ +// slist.h +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Author: riley@google.com (Michael Riley) +// +// \file +// Includes slist definition or defines in terms of STL list as a fallback. + +#ifndef FST_LIB_SLIST_H__ +#define FST_LIB_SLIST_H__ + +#include + +#ifdef HAVE___GNU_CXX__SLIST_INT_ + +#include + +namespace fst { + +using __gnu_cxx::slist; + +} + +#else + +#include + +namespace fst { + +using std::list; + +template class slist : public list { + public: + typedef typename list::iterator iterator; + typedef typename list::const_iterator const_iterator; + + using list::erase; + + iterator erase_after(iterator pos) { + iterator npos = pos; + erase(++npos); + return pos; + } +}; + +} // namespace fst + +#endif // HAVE___GNU_CXX__SLIST_INT_ + +#endif // FST_LIB_SLIST_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/sparse-power-weight.h b/kaldi_io/src/tools/openfst/include/fst/sparse-power-weight.h new file mode 100644 index 0000000..a1ff56a --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/sparse-power-weight.h @@ -0,0 +1,225 @@ +// sparse-power-weight.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: krr@google.com (Kasturi Rangan Raghavan) +// Inspiration: allauzen@google.com (Cyril Allauzen) +// +// \file +// Cartesian power weight semiring operation definitions. +// Uses SparseTupleWeight as underlying representation. + +#ifndef FST_LIB_SPARSE_POWER_WEIGHT_H__ +#define FST_LIB_SPARSE_POWER_WEIGHT_H__ + +#include + +#include +#include + + +namespace fst { + +// Below SparseTupleWeight*Mapper are used in conjunction with +// SparseTupleWeightMap to compute the respective semiring operations +template +struct SparseTupleWeightPlusMapper { + W Map(const K& k, const W& v1, const W& v2) const { + return Plus(v1, v2); + } +}; + +template +struct SparseTupleWeightTimesMapper { + W Map(const K& k, const W& v1, const W& v2) const { + return Times(v1, v2); + } +}; + +template +struct SparseTupleWeightDivideMapper { + SparseTupleWeightDivideMapper(DivideType divide_type) { + divide_type_ = divide_type; + } + W Map(const K& k, const W& v1, const W& v2) const { + return Divide(v1, v2, divide_type_); + } + DivideType divide_type_; +}; + +template +struct SparseTupleWeightApproxMapper { + SparseTupleWeightApproxMapper(float delta) { delta_ = delta; } + W Map(const K& k, const W& v1, const W& v2) const { + return ApproxEqual(v1, v2, delta_) ? W::One() : W::Zero(); + } + float delta_; +}; + +// Sparse cartesian power semiring: W ^ n +// Forms: +// - a left semimodule when W is a left semiring, +// - a right semimodule when W is a right semiring, +// - a bisemimodule when W is a semiring, +// the free semimodule of rank n over W +// The Times operation is overloaded to provide the +// left and right scalar products. +// K is the key value type. kNoKey(-1) is reserved for internal use +template +class SparsePowerWeight : public SparseTupleWeight { + public: + using SparseTupleWeight::Zero; + using SparseTupleWeight::One; + using SparseTupleWeight::NoWeight; + using SparseTupleWeight::Quantize; + using SparseTupleWeight::Reverse; + + typedef SparsePowerWeight ReverseWeight; + + SparsePowerWeight() {} + + SparsePowerWeight(const SparseTupleWeight &w) : + SparseTupleWeight(w) { } + + template + SparsePowerWeight(Iterator begin, Iterator end) : + SparseTupleWeight(begin, end) { } + + SparsePowerWeight(const K &key, const W &w) : + SparseTupleWeight(key, w) { } + + static const SparsePowerWeight &Zero() { + static const SparsePowerWeight zero(SparseTupleWeight::Zero()); + return zero; + } + + static const SparsePowerWeight &One() { + static const SparsePowerWeight one(SparseTupleWeight::One()); + return one; + } + + static const SparsePowerWeight &NoWeight() { + static const SparsePowerWeight no_weight( + SparseTupleWeight::NoWeight()); + return no_weight; + } + + // Overide this: Overwrite the Type method to reflect the key type + // if using non-default key type. + static const string &Type() { + static string type; + if(type.empty()) { + type = W::Type() + "_^n"; + if(sizeof(K) != sizeof(uint32)) { + string size; + Int64ToStr(8 * sizeof(K), &size); + type += "_" + size; + } + } + return type; + } + + static uint64 Properties() { + uint64 props = W::Properties(); + return props & (kLeftSemiring | kRightSemiring | + kCommutative | kIdempotent); + } + + SparsePowerWeight Quantize(float delta = kDelta) const { + return SparseTupleWeight::Quantize(delta); + } + + ReverseWeight Reverse() const { + return SparseTupleWeight::Reverse(); + } +}; + +// Semimodule plus operation +template +inline SparsePowerWeight Plus(const SparsePowerWeight &w1, + const SparsePowerWeight &w2) { + SparsePowerWeight ret; + SparseTupleWeightPlusMapper operator_mapper; + SparseTupleWeightMap(&ret, w1, w2, operator_mapper); + return ret; +} + +// Semimodule times operation +template +inline SparsePowerWeight Times(const SparsePowerWeight &w1, + const SparsePowerWeight &w2) { + SparsePowerWeight ret; + SparseTupleWeightTimesMapper operator_mapper; + SparseTupleWeightMap(&ret, w1, w2, operator_mapper); + return ret; +} + +// Semimodule divide operation +template +inline SparsePowerWeight Divide(const SparsePowerWeight &w1, + const SparsePowerWeight &w2, + DivideType type = DIVIDE_ANY) { + SparsePowerWeight ret; + SparseTupleWeightDivideMapper operator_mapper(type); + SparseTupleWeightMap(&ret, w1, w2, operator_mapper); + return ret; +} + +// Semimodule dot product +template +inline const W& DotProduct(const SparsePowerWeight &w1, + const SparsePowerWeight &w2) { + const SparsePowerWeight& product = Times(w1, w2); + W ret(W::Zero()); + for (SparseTupleWeightIterator it(product); !it.Done(); it.Next()) { + ret = Plus(ret, it.Value().second); + } + return ret; +} + +template +inline bool ApproxEqual(const SparsePowerWeight &w1, + const SparsePowerWeight &w2, + float delta = kDelta) { + SparseTupleWeight ret; + SparseTupleWeightApproxMapper operator_mapper(kDelta); + SparseTupleWeightMap(&ret, w1, w2, operator_mapper); + return ret == SparsePowerWeight::One(); +} + +template +inline SparsePowerWeight Times(const W &k, + const SparsePowerWeight &w2) { + SparsePowerWeight w1(k); + return Times(w1, w2); +} + +template +inline SparsePowerWeight Times(const SparsePowerWeight &w1, + const W &k) { + SparsePowerWeight w2(k); + return Times(w1, w2); +} + +template +inline SparsePowerWeight Divide(const SparsePowerWeight &w1, + const W &k, + DivideType divide_type = DIVIDE_ANY) { + SparsePowerWeight w2(k); + return Divide(w1, w2, divide_type); +} + +} // namespace fst + +#endif // FST_LIB_SPARSE_POWER_WEIGHT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/sparse-tuple-weight.h b/kaldi_io/src/tools/openfst/include/fst/sparse-tuple-weight.h new file mode 100644 index 0000000..c12ef4f --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/sparse-tuple-weight.h @@ -0,0 +1,640 @@ +// sparse-tuple-weight.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: krr@google.com (Kasturi Rangan Raghavan) +// Inspiration: allauzen@google.com (Cyril Allauzen) +// \file +// Sparse version of tuple-weight, based on tuple-weight.h +// Internally stores sparse key, value pairs in linked list +// Default value elemnt is the assumed value of unset keys +// Internal singleton implementation that stores first key, +// value pair as a initialized member variable to avoide +// unnecessary allocation on heap. +// Use SparseTupleWeightIterator to iterate through the key,value pairs +// Note: this does NOT iterate through the default value. +// +// Sparse tuple weight set operation definitions. + +#ifndef FST_LIB_SPARSE_TUPLE_WEIGHT_H__ +#define FST_LIB_SPARSE_TUPLE_WEIGHT_H__ + +#include +#include +#include +#include +using std::tr1::unordered_map; +using std::tr1::unordered_multimap; + +#include + + +DECLARE_string(fst_weight_parentheses); +DECLARE_string(fst_weight_separator); + +namespace fst { + +template class SparseTupleWeight; + +template +class SparseTupleWeightIterator; + +template +istream &operator>>(istream &strm, SparseTupleWeight &w); + +// Arbitrary dimension tuple weight, stored as a sorted linked-list +// W is any weight class, +// K is the key value type. kNoKey(-1) is reserved for internal use +template +class SparseTupleWeight { + public: + typedef pair Pair; + typedef SparseTupleWeight ReverseWeight; + + const static K kNoKey = -1; + SparseTupleWeight() { + Init(); + } + + template + SparseTupleWeight(Iterator begin, Iterator end) { + Init(); + // Assumes input iterator is sorted + for (Iterator it = begin; it != end; ++it) + Push(*it); + } + + + SparseTupleWeight(const K& key, const W &w) { + Init(); + Push(key, w); + } + + SparseTupleWeight(const W &w) { + Init(w); + } + + SparseTupleWeight(const SparseTupleWeight &w) { + Init(w.DefaultValue()); + SetDefaultValue(w.DefaultValue()); + for (SparseTupleWeightIterator it(w); !it.Done(); it.Next()) { + Push(it.Value()); + } + } + + static const SparseTupleWeight &Zero() { + static SparseTupleWeight zero; + return zero; + } + + static const SparseTupleWeight &One() { + static SparseTupleWeight one(W::One()); + return one; + } + + static const SparseTupleWeight &NoWeight() { + static SparseTupleWeight no_weight(W::NoWeight()); + return no_weight; + } + + istream &Read(istream &strm) { + ReadType(strm, &default_); + ReadType(strm, &first_); + return ReadType(strm, &rest_); + } + + ostream &Write(ostream &strm) const { + WriteType(strm, default_); + WriteType(strm, first_); + return WriteType(strm, rest_); + } + + SparseTupleWeight &operator=(const SparseTupleWeight &w) { + if (this == &w) return *this; // check for w = w + Init(w.DefaultValue()); + for (SparseTupleWeightIterator it(w); !it.Done(); it.Next()) { + Push(it.Value()); + } + return *this; + } + + bool Member() const { + if (!DefaultValue().Member()) return false; + for (SparseTupleWeightIterator it(*this); !it.Done(); it.Next()) { + if (!it.Value().second.Member()) return false; + } + return true; + } + + // Assumes H() function exists for the hash of the key value + size_t Hash() const { + uint64 h = 0; + std::tr1::hash H; + for (SparseTupleWeightIterator it(*this); !it.Done(); it.Next()) { + h = 5 * h + H(it.Value().first); + h = 13 * h + it.Value().second.Hash(); + } + return size_t(h); + } + + SparseTupleWeight Quantize(float delta = kDelta) const { + SparseTupleWeight w; + for (SparseTupleWeightIterator it(*this); !it.Done(); it.Next()) { + w.Push(it.Value().first, it.Value().second.Quantize(delta)); + } + return w; + } + + ReverseWeight Reverse() const { + SparseTupleWeight w; + for (SparseTupleWeightIterator it(*this); !it.Done(); it.Next()) { + w.Push(it.Value().first, it.Value().second.Reverse()); + } + return w; + } + + // Common initializer among constructors. + void Init() { + Init(W::Zero()); + } + + void Init(const W& default_value) { + first_.first = kNoKey; + /* initialized to the reserved key value */ + default_ = default_value; + rest_.clear(); + } + + size_t Size() const { + if (first_.first == kNoKey) + return 0; + else + return rest_.size() + 1; + } + + inline void Push(const K &k, const W &w, bool default_value_check = true) { + Push(make_pair(k, w), default_value_check); + } + + inline void Push(const Pair &p, bool default_value_check = true) { + if (default_value_check && p.second == default_) return; + if (first_.first == kNoKey) { + first_ = p; + } else { + rest_.push_back(p); + } + } + + void SetDefaultValue(const W& val) { default_ = val; } + + const W& DefaultValue() const { return default_; } + + protected: + static istream& ReadNoParen( + istream&, SparseTupleWeight&, char separator); + + static istream& ReadWithParen( + istream&, SparseTupleWeight&, + char separator, char open_paren, char close_paren); + + private: + // Assumed default value of uninitialized keys, by default W::Zero() + W default_; + + // Key values pairs are first stored in first_, then fill rest_ + // this way we can avoid dynamic allocation in the common case + // where the weight is a single key,val pair. + Pair first_; + list rest_; + + friend istream &operator>>(istream&, SparseTupleWeight&); + friend class SparseTupleWeightIterator; +}; + +template +class SparseTupleWeightIterator { + public: + typedef typename SparseTupleWeight::Pair Pair; + typedef typename list::const_iterator const_iterator; + typedef typename list::iterator iterator; + + explicit SparseTupleWeightIterator(const SparseTupleWeight& w) + : first_(w.first_), rest_(w.rest_), init_(true), + iter_(rest_.begin()) {} + + bool Done() const { + if (init_) + return first_.first == SparseTupleWeight::kNoKey; + else + return iter_ == rest_.end(); + } + + const Pair& Value() const { return init_ ? first_ : *iter_; } + + void Next() { + if (init_) + init_ = false; + else + ++iter_; + } + + void Reset() { + init_ = true; + iter_ = rest_.begin(); + } + + private: + const Pair &first_; + const list & rest_; + bool init_; // in the initialized state? + typename list::const_iterator iter_; + + DISALLOW_COPY_AND_ASSIGN(SparseTupleWeightIterator); +}; + +template +inline void SparseTupleWeightMap( + SparseTupleWeight* ret, + const SparseTupleWeight& w1, + const SparseTupleWeight& w2, + const M& operator_mapper) { + SparseTupleWeightIterator w1_it(w1); + SparseTupleWeightIterator w2_it(w2); + const W& v1_def = w1.DefaultValue(); + const W& v2_def = w2.DefaultValue(); + ret->SetDefaultValue(operator_mapper.Map(0, v1_def, v2_def)); + while (!w1_it.Done() || !w2_it.Done()) { + const K& k1 = (w1_it.Done()) ? w2_it.Value().first : w1_it.Value().first; + const K& k2 = (w2_it.Done()) ? w1_it.Value().first : w2_it.Value().first; + const W& v1 = (w1_it.Done()) ? v1_def : w1_it.Value().second; + const W& v2 = (w2_it.Done()) ? v2_def : w2_it.Value().second; + if (k1 == k2) { + ret->Push(k1, operator_mapper.Map(k1, v1, v2)); + if (!w1_it.Done()) w1_it.Next(); + if (!w2_it.Done()) w2_it.Next(); + } else if (k1 < k2) { + ret->Push(k1, operator_mapper.Map(k1, v1, v2_def)); + w1_it.Next(); + } else { + ret->Push(k2, operator_mapper.Map(k2, v1_def, v2)); + w2_it.Next(); + } + } +} + +template +inline bool operator==(const SparseTupleWeight &w1, + const SparseTupleWeight &w2) { + const W& v1_def = w1.DefaultValue(); + const W& v2_def = w2.DefaultValue(); + if (v1_def != v2_def) return false; + + SparseTupleWeightIterator w1_it(w1); + SparseTupleWeightIterator w2_it(w2); + while (!w1_it.Done() || !w2_it.Done()) { + const K& k1 = (w1_it.Done()) ? w2_it.Value().first : w1_it.Value().first; + const K& k2 = (w2_it.Done()) ? w1_it.Value().first : w2_it.Value().first; + const W& v1 = (w1_it.Done()) ? v1_def : w1_it.Value().second; + const W& v2 = (w2_it.Done()) ? v2_def : w2_it.Value().second; + if (k1 == k2) { + if (v1 != v2) return false; + if (!w1_it.Done()) w1_it.Next(); + if (!w2_it.Done()) w2_it.Next(); + } else if (k1 < k2) { + if (v1 != v2_def) return false; + w1_it.Next(); + } else { + if (v1_def != v2) return false; + w2_it.Next(); + } + } + return true; +} + +template +inline bool operator!=(const SparseTupleWeight &w1, + const SparseTupleWeight &w2) { + return !(w1 == w2); +} + +template +inline ostream &operator<<(ostream &strm, const SparseTupleWeight &w) { + if(FLAGS_fst_weight_separator.size() != 1) { + FSTERROR() << "FLAGS_fst_weight_separator.size() is not equal to 1"; + strm.clear(std::ios::badbit); + return strm; + } + char separator = FLAGS_fst_weight_separator[0]; + bool write_parens = false; + if (!FLAGS_fst_weight_parentheses.empty()) { + if (FLAGS_fst_weight_parentheses.size() != 2) { + FSTERROR() << "FLAGS_fst_weight_parentheses.size() is not equal to 2"; + strm.clear(std::ios::badbit); + return strm; + } + write_parens = true; + } + + if (write_parens) + strm << FLAGS_fst_weight_parentheses[0]; + + strm << w.DefaultValue(); + strm << separator; + + size_t n = w.Size(); + strm << n; + strm << separator; + + for (SparseTupleWeightIterator it(w); !it.Done(); it.Next()) { + strm << it.Value().first; + strm << separator; + strm << it.Value().second; + strm << separator; + } + + if (write_parens) + strm << FLAGS_fst_weight_parentheses[1]; + + return strm; +} + +template +inline istream &operator>>(istream &strm, SparseTupleWeight &w) { + if(FLAGS_fst_weight_separator.size() != 1) { + FSTERROR() << "FLAGS_fst_weight_separator.size() is not equal to 1"; + strm.clear(std::ios::badbit); + return strm; + } + char separator = FLAGS_fst_weight_separator[0]; + + if (!FLAGS_fst_weight_parentheses.empty()) { + if (FLAGS_fst_weight_parentheses.size() != 2) { + FSTERROR() << "FLAGS_fst_weight_parentheses.size() is not equal to 2"; + strm.clear(std::ios::badbit); + return strm; + } + return SparseTupleWeight::ReadWithParen( + strm, w, separator, FLAGS_fst_weight_parentheses[0], + FLAGS_fst_weight_parentheses[1]); + } else { + return SparseTupleWeight::ReadNoParen(strm, w, separator); + } +} + +// Reads SparseTupleWeight when there are no parentheses around tuple terms +template +inline istream& SparseTupleWeight::ReadNoParen( + istream &strm, + SparseTupleWeight &w, + char separator) { + int c; + size_t n; + + do { + c = strm.get(); + } while (isspace(c)); + + + { // Read default weight + W default_value; + string s; + while (c != separator) { + if (c == EOF) { + strm.clear(std::ios::badbit); + return strm; + } + s += c; + c = strm.get(); + } + istringstream sstrm(s); + sstrm >> default_value; + w.SetDefaultValue(default_value); + } + + c = strm.get(); + + { // Read n + string s; + while (c != separator) { + if (c == EOF) { + strm.clear(std::ios::badbit); + return strm; + } + s += c; + c = strm.get(); + } + istringstream sstrm(s); + sstrm >> n; + } + + // Read n elements + for (size_t i = 0; i < n; ++i) { + // discard separator + c = strm.get(); + K p; + W r; + + { // read key + string s; + while (c != separator) { + if (c == EOF) { + strm.clear(std::ios::badbit); + return strm; + } + s += c; + c = strm.get(); + } + istringstream sstrm(s); + sstrm >> p; + } + + c = strm.get(); + + { // read weight + string s; + while (c != separator) { + if (c == EOF) { + strm.clear(std::ios::badbit); + return strm; + } + s += c; + c = strm.get(); + } + istringstream sstrm(s); + sstrm >> r; + } + + w.Push(p, r); + } + + c = strm.get(); + if (c != separator) { + strm.clear(std::ios::badbit); + } + + return strm; +} + +// Reads SparseTupleWeight when there are parentheses around tuple terms +template +inline istream& SparseTupleWeight::ReadWithParen( + istream &strm, + SparseTupleWeight &w, + char separator, + char open_paren, + char close_paren) { + int c; + size_t n; + + do { + c = strm.get(); + } while (isspace(c)); + + if (c != open_paren) { + FSTERROR() << "is fst_weight_parentheses flag set correcty? "; + strm.clear(std::ios::badbit); + return strm; + } + + c = strm.get(); + + { // Read weight + W default_value; + stack parens; + string s; + while (c != separator || !parens.empty()) { + if (c == EOF) { + strm.clear(std::ios::badbit); + return strm; + } + s += c; + // If parens encountered before separator, they must be matched + if (c == open_paren) { + parens.push(1); + } else if (c == close_paren) { + // Fail for mismatched parens + if (parens.empty()) { + strm.clear(std::ios::failbit); + return strm; + } + parens.pop(); + } + c = strm.get(); + } + istringstream sstrm(s); + sstrm >> default_value; + w.SetDefaultValue(default_value); + } + + c = strm.get(); + + { // Read n + string s; + while (c != separator) { + if (c == EOF) { + strm.clear(std::ios::badbit); + return strm; + } + s += c; + c = strm.get(); + } + istringstream sstrm(s); + sstrm >> n; + } + + // Read n elements + for (size_t i = 0; i < n; ++i) { + // discard separator + c = strm.get(); + K p; + W r; + + { // Read key + stack parens; + string s; + while (c != separator || !parens.empty()) { + if (c == EOF) { + strm.clear(std::ios::badbit); + return strm; + } + s += c; + // If parens encountered before separator, they must be matched + if (c == open_paren) { + parens.push(1); + } else if (c == close_paren) { + // Fail for mismatched parens + if (parens.empty()) { + strm.clear(std::ios::failbit); + return strm; + } + parens.pop(); + } + c = strm.get(); + } + istringstream sstrm(s); + sstrm >> p; + } + + c = strm.get(); + + { // Read weight + stack parens; + string s; + while (c != separator || !parens.empty()) { + if (c == EOF) { + strm.clear(std::ios::badbit); + return strm; + } + s += c; + // If parens encountered before separator, they must be matched + if (c == open_paren) { + parens.push(1); + } else if (c == close_paren) { + // Fail for mismatched parens + if (parens.empty()) { + strm.clear(std::ios::failbit); + return strm; + } + parens.pop(); + } + c = strm.get(); + } + istringstream sstrm(s); + sstrm >> r; + } + + w.Push(p, r); + } + + if (c != separator) { + FSTERROR() << " separator expected, not found! "; + strm.clear(std::ios::badbit); + return strm; + } + + c = strm.get(); + if (c != close_paren) { + FSTERROR() << " is fst_weight_parentheses flag set correcty? "; + strm.clear(std::ios::badbit); + return strm; + } + + return strm; +} + + + +} // namespace fst + +#endif // FST_LIB_SPARSE_TUPLE_WEIGHT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/state-map.h b/kaldi_io/src/tools/openfst/include/fst/state-map.h new file mode 100644 index 0000000..9d6db74 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/state-map.h @@ -0,0 +1,605 @@ +// map.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Class to map over/transform states e.g., sort transitions +// Consider using when operation does not change the number of states. + +#ifndef FST_LIB_STATE_MAP_H__ +#define FST_LIB_STATE_MAP_H__ + +#include +#include +using std::tr1::unordered_map; +using std::tr1::unordered_multimap; +#include +#include +using std::pair; using std::make_pair; + +#include +#include +#include + + +namespace fst { + +// StateMapper Interface - class determinies how states are mapped. +// Useful for implementing operations that do not change the number of states. +// +// class StateMapper { +// public: +// typedef A FromArc; +// typedef B ToArc; +// +// // Typical constructor +// StateMapper(const Fst &fst); +// // Required copy constructor that allows updating Fst argument; +// // pass only if relevant and changed. +// StateMapper(const StateMapper &mapper, const Fst *fst = 0); +// +// // Specifies initial state of result +// B::StateId Start() const; +// // Specifies state's final weight in result +// B::Weight Final(B::StateId s) const; +// +// // These methods iterate through a state's arcs in result +// // Specifies state to iterate over +// void SetState(B::StateId s); +// // End of arcs? +// bool Done() const; +// // Current arc + +// const B &Value() const; +// // Advance to next arc (when !Done) +// void Next(); +// +// // Specifies input symbol table action the mapper requires (see above). +// MapSymbolsAction InputSymbolsAction() const; +// // Specifies output symbol table action the mapper requires (see above). +// MapSymbolsAction OutputSymbolsAction() const; +// // This specifies the known properties of an Fst mapped by this +// // mapper. It takes as argument the input Fst's known properties. +// uint64 Properties(uint64 props) const; +// }; +// +// We include a various state map versions below. One dimension of +// variation is whether the mapping mutates its input, writes to a +// new result Fst, or is an on-the-fly Fst. Another dimension is how +// we pass the mapper. We allow passing the mapper by pointer +// for cases that we need to change the state of the user's mapper. +// We also include map versions that pass the mapper +// by value or const reference when this suffices. + +// Maps an arc type A using a mapper function object C, passed +// by pointer. This version modifies its Fst input. +template +void StateMap(MutableFst *fst, C* mapper) { + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + if (mapper->InputSymbolsAction() == MAP_CLEAR_SYMBOLS) + fst->SetInputSymbols(0); + + if (mapper->OutputSymbolsAction() == MAP_CLEAR_SYMBOLS) + fst->SetOutputSymbols(0); + + if (fst->Start() == kNoStateId) + return; + + uint64 props = fst->Properties(kFstProperties, false); + + fst->SetStart(mapper->Start()); + + for (StateId s = 0; s < fst->NumStates(); ++s) { + mapper->SetState(s); + fst->DeleteArcs(s); + for (; !mapper->Done(); mapper->Next()) + fst->AddArc(s, mapper->Value()); + fst->SetFinal(s, mapper->Final(s)); + } + + fst->SetProperties(mapper->Properties(props), kFstProperties); +} + +// Maps an arc type A using a mapper function object C, passed +// by value. This version modifies its Fst input. +template +void StateMap(MutableFst *fst, C mapper) { + StateMap(fst, &mapper); +} + + +// Maps an arc type A to an arc type B using mapper function +// object C, passed by pointer. This version writes the mapped +// input Fst to an output MutableFst. +template +void StateMap(const Fst &ifst, MutableFst *ofst, C* mapper) { + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + ofst->DeleteStates(); + + if (mapper->InputSymbolsAction() == MAP_COPY_SYMBOLS) + ofst->SetInputSymbols(ifst.InputSymbols()); + else if (mapper->InputSymbolsAction() == MAP_CLEAR_SYMBOLS) + ofst->SetInputSymbols(0); + + if (mapper->OutputSymbolsAction() == MAP_COPY_SYMBOLS) + ofst->SetOutputSymbols(ifst.OutputSymbols()); + else if (mapper->OutputSymbolsAction() == MAP_CLEAR_SYMBOLS) + ofst->SetOutputSymbols(0); + + uint64 iprops = ifst.Properties(kCopyProperties, false); + + if (ifst.Start() == kNoStateId) { + if (iprops & kError) ofst->SetProperties(kError, kError); + return; + } + + // Add all states. + if (ifst.Properties(kExpanded, false)) + ofst->ReserveStates(CountStates(ifst)); + for (StateIterator< Fst > siter(ifst); !siter.Done(); siter.Next()) + ofst->AddState(); + + ofst->SetStart(mapper->Start()); + + for (StateIterator< Fst > siter(ifst); !siter.Done(); siter.Next()) { + StateId s = siter.Value(); + mapper->SetState(s); + for (; !mapper->Done(); mapper->Next()) + ofst->AddArc(s, mapper->Value()); + ofst->SetFinal(s, mapper->Final(s)); + } + + uint64 oprops = ofst->Properties(kFstProperties, false); + ofst->SetProperties(mapper->Properties(iprops) | oprops, kFstProperties); +} + +// Maps an arc type A to an arc type B using mapper function +// object C, passed by value. This version writes the mapped input +// Fst to an output MutableFst. +template +void StateMap(const Fst &ifst, MutableFst *ofst, C mapper) { + StateMap(ifst, ofst, &mapper); +} + +typedef CacheOptions StateMapFstOptions; + +template class StateMapFst; + +// Implementation of delayed StateMapFst. +template +class StateMapFstImpl : public CacheImpl { + public: + using FstImpl::SetType; + using FstImpl::SetProperties; + using FstImpl::SetInputSymbols; + using FstImpl::SetOutputSymbols; + + using VectorFstBaseImpl::State>::NumStates; + + using CacheImpl::PushArc; + using CacheImpl::HasArcs; + using CacheImpl::HasFinal; + using CacheImpl::HasStart; + using CacheImpl::SetArcs; + using CacheImpl::SetFinal; + using CacheImpl::SetStart; + + friend class StateIterator< StateMapFst >; + + typedef B Arc; + typedef typename B::Weight Weight; + typedef typename B::StateId StateId; + + StateMapFstImpl(const Fst &fst, const C &mapper, + const StateMapFstOptions& opts) + : CacheImpl(opts), + fst_(fst.Copy()), + mapper_(new C(mapper, fst_)), + own_mapper_(true) { + Init(); + } + + StateMapFstImpl(const Fst &fst, C *mapper, + const StateMapFstOptions& opts) + : CacheImpl(opts), + fst_(fst.Copy()), + mapper_(mapper), + own_mapper_(false) { + Init(); + } + + StateMapFstImpl(const StateMapFstImpl &impl) + : CacheImpl(impl), + fst_(impl.fst_->Copy(true)), + mapper_(new C(*impl.mapper_, fst_)), + own_mapper_(true) { + Init(); + } + + ~StateMapFstImpl() { + delete fst_; + if (own_mapper_) delete mapper_; + } + + StateId Start() { + if (!HasStart()) + SetStart(mapper_->Start()); + return CacheImpl::Start(); + } + + Weight Final(StateId s) { + if (!HasFinal(s)) + SetFinal(s, mapper_->Final(s)); + return CacheImpl::Final(s); + } + + size_t NumArcs(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumArcs(s); + } + + size_t NumInputEpsilons(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumInputEpsilons(s); + } + + size_t NumOutputEpsilons(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumOutputEpsilons(s); + } + + void InitStateIterator(StateIteratorData *data) const { + fst_->InitStateIterator(data); + } + + void InitArcIterator(StateId s, ArcIteratorData *data) { + if (!HasArcs(s)) + Expand(s); + CacheImpl::InitArcIterator(s, data); + } + + uint64 Properties() const { return Properties(kFstProperties); } + + // Set error if found; return FST impl properties. + uint64 Properties(uint64 mask) const { + if ((mask & kError) && (fst_->Properties(kError, false) || + (mapper_->Properties(0) & kError))) + SetProperties(kError, kError); + return FstImpl::Properties(mask); + } + + void Expand(StateId s) { + // Add exiting arcs. + for (mapper_->SetState(s); !mapper_->Done(); mapper_->Next()) + PushArc(s, mapper_->Value()); + SetArcs(s); + } + + const Fst &GetFst() const { + return *fst_; + } + + private: + void Init() { + SetType("statemap"); + + if (mapper_->InputSymbolsAction() == MAP_COPY_SYMBOLS) + SetInputSymbols(fst_->InputSymbols()); + else if (mapper_->InputSymbolsAction() == MAP_CLEAR_SYMBOLS) + SetInputSymbols(0); + + if (mapper_->OutputSymbolsAction() == MAP_COPY_SYMBOLS) + SetOutputSymbols(fst_->OutputSymbols()); + else if (mapper_->OutputSymbolsAction() == MAP_CLEAR_SYMBOLS) + SetOutputSymbols(0); + + uint64 props = fst_->Properties(kCopyProperties, false); + SetProperties(mapper_->Properties(props)); + } + + const Fst *fst_; + C* mapper_; + bool own_mapper_; + + void operator=(const StateMapFstImpl &); // disallow +}; + + +// Maps an arc type A to an arc type B using Mapper function object +// C. This version is a delayed Fst. +template +class StateMapFst : public ImplToFst< StateMapFstImpl > { + public: + friend class ArcIterator< StateMapFst >; + + typedef B Arc; + typedef typename B::Weight Weight; + typedef typename B::StateId StateId; + typedef CacheState State; + typedef StateMapFstImpl Impl; + + StateMapFst(const Fst &fst, const C &mapper, + const StateMapFstOptions& opts) + : ImplToFst(new Impl(fst, mapper, opts)) {} + + StateMapFst(const Fst &fst, C* mapper, const StateMapFstOptions& opts) + : ImplToFst(new Impl(fst, mapper, opts)) {} + + StateMapFst(const Fst &fst, const C &mapper) + : ImplToFst(new Impl(fst, mapper, StateMapFstOptions())) {} + + StateMapFst(const Fst &fst, C* mapper) + : ImplToFst(new Impl(fst, mapper, StateMapFstOptions())) {} + + // See Fst<>::Copy() for doc. + StateMapFst(const StateMapFst &fst, bool safe = false) + : ImplToFst(fst, safe) {} + + // Get a copy of this StateMapFst. See Fst<>::Copy() for further doc. + virtual StateMapFst *Copy(bool safe = false) const { + return new StateMapFst(*this, safe); + } + + virtual void InitStateIterator(StateIteratorData *data) const { + GetImpl()->InitStateIterator(data); + } + + virtual void InitArcIterator(StateId s, ArcIteratorData *data) const { + GetImpl()->InitArcIterator(s, data); + } + + protected: + Impl *GetImpl() const { return ImplToFst::GetImpl(); } + + private: + void operator=(const StateMapFst &fst); // disallow +}; + + +// Specialization for StateMapFst. +template +class ArcIterator< StateMapFst > + : public CacheArcIterator< StateMapFst > { + public: + typedef typename A::StateId StateId; + + ArcIterator(const StateMapFst &fst, StateId s) + : CacheArcIterator< StateMapFst >(fst.GetImpl(), s) { + if (!fst.GetImpl()->HasArcs(s)) + fst.GetImpl()->Expand(s); + } + + private: + DISALLOW_COPY_AND_ASSIGN(ArcIterator); +}; + +// +// Utility Mappers +// + +// Mapper that returns its input. +template +class IdentityStateMapper { + public: + typedef A FromArc; + typedef A ToArc; + + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + explicit IdentityStateMapper(const Fst &fst) : fst_(fst), aiter_(0) {} + + // Allows updating Fst argument; pass only if changed. + IdentityStateMapper(const IdentityStateMapper &mapper, + const Fst *fst = 0) + : fst_(fst ? *fst : mapper.fst_), aiter_(0) {} + + ~IdentityStateMapper() { delete aiter_; } + + StateId Start() const { return fst_.Start(); } + + Weight Final(StateId s) const { return fst_.Final(s); } + + void SetState(StateId s) { + if (aiter_) delete aiter_; + aiter_ = new ArcIterator< Fst >(fst_, s); + } + + bool Done() const { return aiter_->Done(); } + const A &Value() const { return aiter_->Value(); } + void Next() { aiter_->Next(); } + + MapSymbolsAction InputSymbolsAction() const { return MAP_COPY_SYMBOLS; } + MapSymbolsAction OutputSymbolsAction() const { return MAP_COPY_SYMBOLS;} + + uint64 Properties(uint64 props) const { return props; } + + private: + const Fst &fst_; + ArcIterator< Fst > *aiter_; +}; + +template +class ArcSumMapper { + public: + typedef A FromArc; + typedef A ToArc; + + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + explicit ArcSumMapper(const Fst &fst) : fst_(fst), i_(0) {} + + // Allows updating Fst argument; pass only if changed. + ArcSumMapper(const ArcSumMapper &mapper, + const Fst *fst = 0) + : fst_(fst ? *fst : mapper.fst_), i_(0) {} + + StateId Start() const { return fst_.Start(); } + Weight Final(StateId s) const { return fst_.Final(s); } + + void SetState(StateId s) { + i_ = 0; + arcs_.clear(); + arcs_.reserve(fst_.NumArcs(s)); + for (ArcIterator > aiter(fst_, s); !aiter.Done(); aiter.Next()) + arcs_.push_back(aiter.Value()); + + // First sorts the exiting arcs by input label, output label + // and destination state and then sums weights of arcs with + // the same input label, output label, and destination state. + sort(arcs_.begin(), arcs_.end(), comp_); + size_t narcs = 0; + for (size_t i = 0; i < arcs_.size(); ++i) { + if (narcs > 0 && equal_(arcs_[i], arcs_[narcs - 1])) { + arcs_[narcs - 1].weight = Plus(arcs_[narcs - 1].weight, + arcs_[i].weight); + } else { + arcs_[narcs++] = arcs_[i]; + } + } + arcs_.resize(narcs); + } + + bool Done() const { return i_ >= arcs_.size(); } + const A &Value() const { return arcs_[i_]; } + void Next() { ++i_; } + + MapSymbolsAction InputSymbolsAction() const { return MAP_COPY_SYMBOLS; } + MapSymbolsAction OutputSymbolsAction() const { return MAP_COPY_SYMBOLS; } + + uint64 Properties(uint64 props) const { + return props & kArcSortProperties & + kDeleteArcsProperties & kWeightInvariantProperties; + } + + private: + struct Compare { + bool operator()(const A& x, const A& y) { + if (x.ilabel < y.ilabel) return true; + if (x.ilabel > y.ilabel) return false; + if (x.olabel < y.olabel) return true; + if (x.olabel > y.olabel) return false; + if (x.nextstate < y.nextstate) return true; + if (x.nextstate > y.nextstate) return false; + return false; + } + }; + + struct Equal { + bool operator()(const A& x, const A& y) { + return (x.ilabel == y.ilabel && + x.olabel == y.olabel && + x.nextstate == y.nextstate); + } + }; + + const Fst &fst_; + Compare comp_; + Equal equal_; + vector arcs_; + ssize_t i_; // current arc position + + void operator=(const ArcSumMapper &); // disallow +}; + +template +class ArcUniqueMapper { + public: + typedef A FromArc; + typedef A ToArc; + + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + explicit ArcUniqueMapper(const Fst &fst) : fst_(fst), i_(0) {} + + // Allows updating Fst argument; pass only if changed. + ArcUniqueMapper(const ArcUniqueMapper &mapper, + const Fst *fst = 0) + : fst_(fst ? *fst : mapper.fst_), i_(0) {} + + StateId Start() const { return fst_.Start(); } + Weight Final(StateId s) const { return fst_.Final(s); } + + void SetState(StateId s) { + i_ = 0; + arcs_.clear(); + arcs_.reserve(fst_.NumArcs(s)); + for (ArcIterator > aiter(fst_, s); !aiter.Done(); aiter.Next()) + arcs_.push_back(aiter.Value()); + + // First sorts the exiting arcs by input label, output label + // and destination state and then uniques identical arcs + sort(arcs_.begin(), arcs_.end(), comp_); + typename vector::iterator unique_end = + unique(arcs_.begin(), arcs_.end(), equal_); + arcs_.resize(unique_end - arcs_.begin()); + } + + bool Done() const { return i_ >= arcs_.size(); } + const A &Value() const { return arcs_[i_]; } + void Next() { ++i_; } + + MapSymbolsAction InputSymbolsAction() const { return MAP_COPY_SYMBOLS; } + MapSymbolsAction OutputSymbolsAction() const { return MAP_COPY_SYMBOLS; } + + uint64 Properties(uint64 props) const { + return props & kArcSortProperties & kDeleteArcsProperties; + } + + private: + struct Compare { + bool operator()(const A& x, const A& y) { + if (x.ilabel < y.ilabel) return true; + if (x.ilabel > y.ilabel) return false; + if (x.olabel < y.olabel) return true; + if (x.olabel > y.olabel) return false; + if (x.nextstate < y.nextstate) return true; + if (x.nextstate > y.nextstate) return false; + return false; + } + }; + + struct Equal { + bool operator()(const A& x, const A& y) { + return (x.ilabel == y.ilabel && + x.olabel == y.olabel && + x.nextstate == y.nextstate && + x.weight == y.weight); + } + }; + + const Fst &fst_; + Compare comp_; + Equal equal_; + vector arcs_; + ssize_t i_; // current arc position + + void operator=(const ArcUniqueMapper &); // disallow +}; + + +} // namespace fst + +#endif // FST_LIB_STATE_MAP_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/state-reachable.h b/kaldi_io/src/tools/openfst/include/fst/state-reachable.h new file mode 100644 index 0000000..6d0c971 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/state-reachable.h @@ -0,0 +1,198 @@ +// state-reachable.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Class to determine whether a given (final) state can be reached from some +// other given state. + +#ifndef FST_LIB_STATE_REACHABLE_H__ +#define FST_LIB_STATE_REACHABLE_H__ + +#include +using std::vector; + +#include +#include +#include + + +namespace fst { + +// Computes the (final) states reachable from a given state in an FST. +// After this visitor has been called, a final state f can be reached +// from a state s iff (*isets)[s].Member(state2index[f]) is true, where +// (*isets[s]) is a set of half-open inteval of final state indices +// and state2index[f] maps from a final state to its index. +// +// If state2index is empty, it is filled-in with suitable indices. +// If it is non-empty, those indices are used; in this case, the +// final states must have out-degree 0. +template +class IntervalReachVisitor { + public: + typedef typename A::StateId StateId; + typedef typename A::Label Label; + typedef typename A::Weight Weight; + typedef typename IntervalSet::Interval Interval; + + IntervalReachVisitor(const Fst &fst, + vector< IntervalSet > *isets, + vector *state2index) + : fst_(fst), + isets_(isets), + state2index_(state2index), + index_(state2index->empty() ? 1 : -1), + error_(false) { + isets_->clear(); + } + + void InitVisit(const Fst &fst) { error_ = false; } + + bool InitState(StateId s, StateId r) { + while (isets_->size() <= s) + isets_->push_back(IntervalSet &fst_; + vector< IntervalSet > *isets_; + vector *state2index_; + I index_; + bool error_; +}; + + +// Tests reachability of final states from a given state. To test for +// reachability from a state s, first do SetState(s). Then a final +// state f can be reached from state s of FST iff Reach(f) is true. +template +class StateReachable { + public: + typedef A Arc; + typedef I Index; + typedef typename A::StateId StateId; + typedef typename A::Label Label; + typedef typename A::Weight Weight; + typedef typename IntervalSet::Interval Interval; + + StateReachable(const Fst &fst) + : error_(false) { + IntervalReachVisitor reach_visitor(fst, &isets_, &state2index_); + DfsVisit(fst, &reach_visitor); + if (reach_visitor.Error()) error_ = true; + } + + StateReachable(const StateReachable &reachable) { + FSTERROR() << "Copy constructor for state reachable class " + << "not yet implemented."; + error_ = true; + } + + // Set current state. + void SetState(StateId s) { s_ = s; } + + // Can reach this label from current state? + bool Reach(StateId s) { + if (s >= state2index_.size()) + return false; + + I i = state2index_[s]; + if (i < 0) { + FSTERROR() << "StateReachable: state non-final: " << s; + error_ = true; + return false; + } + return isets_[s_].Member(i); + } + + // Access to the state-to-index mapping. Unassigned states have index -1. + vector &State2Index() { return state2index_; } + + // Access to the interval sets. These specify the reachability + // to the final states as intervals of the final state indices. + const vector< IntervalSet > &IntervalSets() { return isets_; } + + bool Error() const { return error_; } + + private: + StateId s_; // Current state + vector< IntervalSet > isets_; // Interval sets per state + vector state2index_; // Finds index for a final state + bool error_; + + void operator=(const StateReachable &); // Disallow +}; + +} // namespace fst + +#endif // FST_LIB_STATE_REACHABLE_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/state-table.h b/kaldi_io/src/tools/openfst/include/fst/state-table.h new file mode 100644 index 0000000..d8107a1 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/state-table.h @@ -0,0 +1,481 @@ +// state-table.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Classes for representing the mapping between state tuples and state Ids. + +#ifndef FST_LIB_STATE_TABLE_H__ +#define FST_LIB_STATE_TABLE_H__ + +#include +using std::deque; +#include +using std::vector; + +#include +#include + + +namespace fst { + +// STATE TABLES - these determine the bijective mapping between state +// tuples (e.g. in composition triples of two FST states and a +// composition filter state) and their corresponding state IDs. +// They are classes, templated on state tuples, of the form: +// +// template +// class StateTable { +// public: +// typedef typename T StateTuple; +// +// // Required constructors. +// StateTable(); +// +// // Lookup state ID by tuple. If it doesn't exist, then add it. +// StateId FindState(const StateTuple &); +// // Lookup state tuple by state ID. +// const StateTuple &Tuple(StateId) const; +// // # of stored tuples. +// StateId Size() const; +// }; +// +// A state tuple has the form: +// +// template +// struct StateTuple { +// typedef typename S StateId; +// +// // Required constructors. +// StateTuple(); +// StateTuple(const StateTuple &); +// }; + + +// An implementation using a hash map for the tuple to state ID mapping. +// The state tuple T must have == defined. H is the hash function. +template +class HashStateTable : public HashBiTable { + public: + typedef T StateTuple; + typedef typename StateTuple::StateId StateId; + using HashBiTable::FindId; + using HashBiTable::FindEntry; + using HashBiTable::Size; + + HashStateTable() : HashBiTable() {} + + // Reserves space for table_size elements. + explicit HashStateTable(size_t table_size) + : HashBiTable(table_size) {} + + StateId FindState(const StateTuple &tuple) { return FindId(tuple); } + const StateTuple &Tuple(StateId s) const { return FindEntry(s); } +}; + + +// An implementation using a hash map for the tuple to state ID mapping. +// The state tuple T must have == defined. H is the hash function. +template +class CompactHashStateTable + : public CompactHashBiTable { + public: + typedef T StateTuple; + typedef typename StateTuple::StateId StateId; + using CompactHashBiTable::FindId; + using CompactHashBiTable::FindEntry; + using CompactHashBiTable::Size; + + CompactHashStateTable() : CompactHashBiTable() {} + + // Reserves space for 'table_size' elements. + explicit CompactHashStateTable(size_t table_size) + : CompactHashBiTable(table_size) {} + + StateId FindState(const StateTuple &tuple) { return FindId(tuple); } + const StateTuple &Tuple(StateId s) const { return FindEntry(s); } +}; + +// An implementation using a vector for the tuple to state mapping. +// It is passed a function object FP that should fingerprint tuples +// uniquely to an integer that can used as a vector index. Normally, +// VectorStateTable constructs the FP object. The user can instead +// pass in this object; in that case, VectorStateTable takes its +// ownership. +template +class VectorStateTable + : public VectorBiTable { + public: + typedef T StateTuple; + typedef typename StateTuple::StateId StateId; + using VectorBiTable::FindId; + using VectorBiTable::FindEntry; + using VectorBiTable::Size; + using VectorBiTable::Fingerprint; + + // Reserves space for 'table_size' elements. + explicit VectorStateTable(FP *fp = 0, size_t table_size = 0) + : VectorBiTable(fp, table_size) {} + + StateId FindState(const StateTuple &tuple) { return FindId(tuple); } + const StateTuple &Tuple(StateId s) const { return FindEntry(s); } +}; + + +// An implementation using a vector and a compact hash table. The +// selecting functor S returns true for tuples to be hashed in the +// vector. The fingerprinting functor FP returns a unique fingerprint +// for each tuple to be hashed in the vector (these need to be +// suitable for indexing in a vector). The hash functor H is used when +// hashing tuple into the compact hash table. +template +class VectorHashStateTable + : public VectorHashBiTable { + public: + typedef T StateTuple; + typedef typename StateTuple::StateId StateId; + using VectorHashBiTable::FindId; + using VectorHashBiTable::FindEntry; + using VectorHashBiTable::Size; + using VectorHashBiTable::Selector; + using VectorHashBiTable::Fingerprint; + using VectorHashBiTable::Hash; + + VectorHashStateTable(S *s, FP *fp, H *h, + size_t vector_size = 0, + size_t tuple_size = 0) + : VectorHashBiTable( + s, fp, h, vector_size, tuple_size) {} + + StateId FindState(const StateTuple &tuple) { return FindId(tuple); } + const StateTuple &Tuple(StateId s) const { return FindEntry(s); } +}; + + +// An implementation using a hash map for the tuple to state ID +// mapping. This version permits erasing of states. The state tuple T +// must have == defined and its default constructor must produce a +// tuple that will never be seen. F is the hash function. +template +class ErasableStateTable : public ErasableBiTable { + public: + typedef T StateTuple; + typedef typename StateTuple::StateId StateId; + using ErasableBiTable::FindId; + using ErasableBiTable::FindEntry; + using ErasableBiTable::Size; + using ErasableBiTable::Erase; + + ErasableStateTable() : ErasableBiTable() {} + StateId FindState(const StateTuple &tuple) { return FindId(tuple); } + const StateTuple &Tuple(StateId s) const { return FindEntry(s); } +}; + +// +// COMPOSITION STATE TUPLES AND TABLES +// +// The composition state table has the form: +// +// template +// class ComposeStateTable { +// public: +// typedef A Arc; +// typedef F FilterState; +// typedef typename A::StateId StateId; +// typedef ComposeStateTuple StateTuple; +// +// // Required constructors. Copy constructor does not copy state. +// ComposeStateTable(const Fst &fst1, const Fst &fst2); +// ComposeStateTable(const ComposeStateTable &table); +// // Lookup state ID by tuple. If it doesn't exist, then add it. +// StateId FindState(const StateTuple &); +// // Lookup state tuple by state ID. +// const StateTuple &Tuple(StateId) const; +// // # of stored tuples. +// StateId Size() const; +// // Return true if error encountered +// bool Error() const; +// }; + +// Represents the composition state. +template +struct ComposeStateTuple { + typedef S StateId; + typedef F FilterState; + + ComposeStateTuple() + : state_id1(kNoStateId), state_id2(kNoStateId), + filter_state(FilterState::NoState()) {} + + ComposeStateTuple(StateId s1, StateId s2, const FilterState &f) + : state_id1(s1), state_id2(s2), filter_state(f) {} + + StateId state_id1; // State Id on fst1 + StateId state_id2; // State Id on fst2 + FilterState filter_state; // State of composition filter +}; + +// Equality of composition state tuples. +template +inline bool operator==(const ComposeStateTuple& x, + const ComposeStateTuple& y) { + if (&x == &y) + return true; + return x.state_id1 == y.state_id1 && + x.state_id2 == y.state_id2 && + x.filter_state == y.filter_state; +} + + +// Hashing of composition state tuples. +template +class ComposeHash { + public: + size_t operator()(const ComposeStateTuple& t) const { + return t.state_id1 + t.state_id2 * kPrime0 + + t.filter_state.Hash() * kPrime1; + } + private: + static const size_t kPrime0; + static const size_t kPrime1; +}; + +template +const size_t ComposeHash::kPrime0 = 7853; + +template +const size_t ComposeHash::kPrime1 = 7867; + + +// A HashStateTable over composition tuples. +template , + ComposeHash > > +class GenericComposeStateTable : public H { + public: + typedef A Arc; + typedef typename A::StateId StateId; + typedef F FilterState; + typedef ComposeStateTuple StateTuple; + + GenericComposeStateTable(const Fst &fst1, const Fst &fst2) {} + + // Reserves space for 'table_size' elements. + GenericComposeStateTable(const Fst &fst1, const Fst &fst2, + size_t table_size) : H(table_size) {} + + bool Error() const { return false; } + + private: + void operator=(const GenericComposeStateTable &table); // disallow +}; + + +// Fingerprint for general composition tuples. +template +class ComposeFingerprint { + public: + typedef S StateId; + typedef F FilterState; + typedef ComposeStateTuple StateTuple; + + // Required but suboptimal constructor. + ComposeFingerprint() : mult1_(8192), mult2_(8192) { + LOG(WARNING) << "TupleFingerprint: # of FST states should be provided."; + } + + // Constructor is provided the sizes of the input FSTs + ComposeFingerprint(StateId nstates1, StateId nstates2) + : mult1_(nstates1), mult2_(nstates1 * nstates2) { } + + size_t operator()(const StateTuple &tuple) { + return tuple.state_id1 + tuple.state_id2 * mult1_ + + tuple.filter_state.Hash() * mult2_; + } + + private: + ssize_t mult1_; + ssize_t mult2_; +}; + + +// Useful when the first composition state determines the tuple. +template +class ComposeState1Fingerprint { + public: + typedef S StateId; + typedef F FilterState; + typedef ComposeStateTuple StateTuple; + + size_t operator()(const StateTuple &tuple) { return tuple.state_id1; } +}; + + +// Useful when the second composition state determines the tuple. +template +class ComposeState2Fingerprint { + public: + typedef S StateId; + typedef F FilterState; + typedef ComposeStateTuple StateTuple; + + size_t operator()(const StateTuple &tuple) { return tuple.state_id2; } +}; + + +// A VectorStateTable over composition tuples. This can be used when +// the product of number of states in FST1 and FST2 (and the +// composition filter state hash) is manageable. If the FSTs are not +// expanded Fsts, they will first have their states counted. +template +class ProductComposeStateTable : public +VectorStateTable, + ComposeFingerprint > { + public: + typedef A Arc; + typedef typename A::StateId StateId; + typedef F FilterState; + typedef ComposeStateTuple StateTuple; + typedef VectorStateTable > StateTable; + + // Reserves space for 'table_size' elements. + ProductComposeStateTable(const Fst &fst1, const Fst &fst2, + size_t table_size = 0) + : StateTable(new ComposeFingerprint(CountStates(fst1), + CountStates(fst2)), + table_size) {} + + ProductComposeStateTable(const ProductComposeStateTable &table) + : StateTable(new ComposeFingerprint(table.Fingerprint())) {} + + bool Error() const { return false; } + + private: + void operator=(const ProductComposeStateTable &table); // disallow +}; + +// A VectorStateTable over composition tuples. This can be used when +// FST1 is a string (satisfies kStringProperties) and FST2 is +// epsilon-free and deterministic. It should be used with a +// composition filter that creates at most one filter state per tuple +// under these conditions (e.g. SequenceComposeFilter or +// MatchComposeFilter). +template +class StringDetComposeStateTable : public +VectorStateTable, + ComposeState1Fingerprint > { + public: + typedef A Arc; + typedef typename A::StateId StateId; + typedef F FilterState; + typedef ComposeStateTuple StateTuple; + typedef VectorStateTable > StateTable; + + StringDetComposeStateTable(const Fst &fst1, const Fst &fst2) + : error_(false) { + uint64 props1 = kString; + uint64 props2 = kIDeterministic | kNoIEpsilons; + if (fst1.Properties(props1, true) != props1 || + fst2.Properties(props2, true) != props2) { + FSTERROR() << "StringDetComposeStateTable: fst1 not a string or" + << " fst2 not input deterministic and epsilon-free"; + error_ = true; + } + } + + StringDetComposeStateTable(const StringDetComposeStateTable &table) + : StateTable(table), error_(table.error_) {} + + bool Error() const { return error_; } + + private: + bool error_; + + void operator=(const StringDetComposeStateTable &table); // disallow +}; + + +// A VectorStateTable over composition tuples. This can be used when +// FST2 is a string (satisfies kStringProperties) and FST1 is +// epsilon-free and deterministic. It should be used with a +// composition filter that creates at most one filter state per tuple +// under these conditions (e.g. SequenceComposeFilter or +// MatchComposeFilter). +template +class DetStringComposeStateTable : public +VectorStateTable, + ComposeState2Fingerprint > { + public: + typedef A Arc; + typedef typename A::StateId StateId; + typedef F FilterState; + typedef ComposeStateTuple StateTuple; + typedef VectorStateTable > StateTable; + + DetStringComposeStateTable(const Fst &fst1, const Fst &fst2) + :error_(false) { + uint64 props1 = kODeterministic | kNoOEpsilons; + uint64 props2 = kString; + if (fst1.Properties(props1, true) != props1 || + fst2.Properties(props2, true) != props2) { + FSTERROR() << "StringDetComposeStateTable: fst2 not a string or" + << " fst1 not output deterministic and epsilon-free"; + error_ = true; + } + } + + DetStringComposeStateTable(const DetStringComposeStateTable &table) + : StateTable(table), error_(table.error_) {} + + bool Error() const { return error_; } + + private: + bool error_; + + void operator=(const DetStringComposeStateTable &table); // disallow +}; + + +// An ErasableStateTable over composition tuples. The Erase(StateId) method +// can be called if the user either is sure that composition will never return +// to that tuple or doesn't care that if it does, it is assigned a new +// state ID. +template +class ErasableComposeStateTable : public +ErasableStateTable, + ComposeHash > { + public: + typedef A Arc; + typedef typename A::StateId StateId; + typedef F FilterState; + typedef ComposeStateTuple StateTuple; + + ErasableComposeStateTable(const Fst &fst1, const Fst &fst2) {} + + bool Error() const { return false; } + + private: + void operator=(const ErasableComposeStateTable &table); // disallow +}; + +} // namespace fst + +#endif // FST_LIB_STATE_TABLE_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/statesort.h b/kaldi_io/src/tools/openfst/include/fst/statesort.h new file mode 100644 index 0000000..6f827f4 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/statesort.h @@ -0,0 +1,97 @@ +// statesort.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Function to sort states of an Fst. + +#ifndef FST_LIB_STATESORT_H__ +#define FST_LIB_STATESORT_H__ + +#include +using std::vector; +#include + +#include + + +namespace fst { + +// Sorts the input states of an FST, modifying it. ORDER[i] gives the +// the state Id after sorting that corresponds to state Id i before +// sorting. ORDER must be a permutation of FST's states ID sequence: +// (0, 1, 2, ..., fst->NumStates() - 1). +template +void StateSort(MutableFst *fst, + const vector &order) { + typedef typename Arc::StateId StateId; + typedef typename Arc::Weight Weight; + + if (order.size() != fst->NumStates()) { + FSTERROR() << "StateSort: bad order vector size: " << order.size(); + fst->SetProperties(kError, kError); + return; + } + + if (fst->Start() == kNoStateId) + return; + + uint64 props = fst->Properties(kStateSortProperties, false); + + vector done(order.size(), false); + vector arcsa, arcsb; + vector *arcs1 = &arcsa, *arcs2 = &arcsb; + + fst->SetStart(order[fst->Start()]); + + for (StateIterator< MutableFst > siter(*fst); + !siter.Done(); + siter.Next()) { + StateId s1 = siter.Value(), s2; + if (done[s1]) + continue; + Weight final1 = fst->Final(s1), final2 = Weight::Zero(); + arcs1->clear(); + for (ArcIterator< MutableFst > aiter(*fst, s1); + !aiter.Done(); + aiter.Next()) + arcs1->push_back(aiter.Value()); + for (; !done[s1]; s1 = s2, final1 = final2, swap(arcs1, arcs2)) { + s2 = order[s1]; + if (!done[s2]) { + final2 = fst->Final(s2); + arcs2->clear(); + for (ArcIterator< MutableFst > aiter(*fst, s2); + !aiter.Done(); + aiter.Next()) + arcs2->push_back(aiter.Value()); + } + fst->SetFinal(s2, final1); + fst->DeleteArcs(s2); + for (size_t i = 0; i < arcs1->size(); ++i) { + Arc arc = (*arcs1)[i]; + arc.nextstate = order[arc.nextstate]; + fst->AddArc(s2, arc); + } + done[s1] = true; + } + } + fst->SetProperties(props, kFstProperties); +} + +} // namespace fst + +#endif // FST_LIB_STATESORT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/string-weight.h b/kaldi_io/src/tools/openfst/include/fst/string-weight.h new file mode 100644 index 0000000..1beeb33 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/string-weight.h @@ -0,0 +1,560 @@ +// string-weight.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// String weight set and associated semiring operation definitions. + +#ifndef FST_LIB_STRING_WEIGHT_H__ +#define FST_LIB_STRING_WEIGHT_H__ + +#include +#include + +#include +#include + +namespace fst { + +const int kStringInfinity = -1; // Label for the infinite string +const int kStringBad = -2; // Label for a non-string +const char kStringSeparator = '_'; // Label separator in strings + +// Determines whether to use left or right string semiring. Includes +// restricted versions that signal an error if proper prefixes +// (suffixes) would otherwise be returned by Plus, useful with various +// algorithms that require functional transducer input with the +// string semirings. +enum StringType { STRING_LEFT = 0, STRING_RIGHT = 1 , + STRING_LEFT_RESTRICT = 2, STRING_RIGHT_RESTRICT }; + +#define REVERSE_STRING_TYPE(S) \ + ((S) == STRING_LEFT ? STRING_RIGHT : \ + ((S) == STRING_RIGHT ? STRING_LEFT : \ + ((S) == STRING_LEFT_RESTRICT ? STRING_RIGHT_RESTRICT : \ + STRING_LEFT_RESTRICT))) + +template +class StringWeight; + +template +class StringWeightIterator; + +template +class StringWeightReverseIterator; + +template +bool operator==(const StringWeight &, const StringWeight &); + + +// String semiring: (longest_common_prefix/suffix, ., Infinity, Epsilon) +template +class StringWeight { + public: + typedef L Label; + typedef StringWeight ReverseWeight; + + friend class StringWeightIterator; + friend class StringWeightReverseIterator; + friend bool operator==<>(const StringWeight &, + const StringWeight &); + + StringWeight() { Init(); } + + template + StringWeight(const Iter &begin, const Iter &end) { + Init(); + for (Iter iter = begin; iter != end; ++iter) + PushBack(*iter); + } + + explicit StringWeight(L l) { Init(); PushBack(l); } + + static const StringWeight &Zero() { + static const StringWeight zero(kStringInfinity); + return zero; + } + + static const StringWeight &One() { + static const StringWeight one; + return one; + } + + static const StringWeight &NoWeight() { + static const StringWeight no_weight(kStringBad); + return no_weight; + } + + static const string &Type() { + static const string type = + S == STRING_LEFT ? "string" : + (S == STRING_RIGHT ? "right_string" : + (S == STRING_LEFT_RESTRICT ? "restricted_string" : + "right_restricted_string")); + return type; + } + + bool Member() const; + + istream &Read(istream &strm); + + ostream &Write(ostream &strm) const; + + size_t Hash() const; + + StringWeight Quantize(float delta = kDelta) const { + return *this; + } + + ReverseWeight Reverse() const; + + static uint64 Properties() { + return (S == STRING_LEFT || S == STRING_LEFT_RESTRICT ? + kLeftSemiring : kRightSemiring) | kIdempotent; + } + + // NB: This needs to be uncommented only if default fails for this impl. + // StringWeight &operator=(const StringWeight &w); + + // These operations combined with the StringWeightIterator and + // StringWeightReverseIterator provide the access and mutation of + // the string internal elements. + + // Common initializer among constructors. + void Init() { first_ = 0; } + + // Clear existing StringWeight. + void Clear() { first_ = 0; rest_.clear(); } + + size_t Size() const { return first_ ? rest_.size() + 1 : 0; } + + void PushFront(L l) { + if (first_) + rest_.push_front(first_); + first_ = l; + } + + void PushBack(L l) { + if (!first_) + first_ = l; + else + rest_.push_back(l); + } + + private: + L first_; // first label in string (0 if empty) + list rest_; // remaining labels in string +}; + + +// Traverses string in forward direction. +template +class StringWeightIterator { + public: + explicit StringWeightIterator(const StringWeight& w) + : first_(w.first_), rest_(w.rest_), init_(true), + iter_(rest_.begin()) {} + + bool Done() const { + if (init_) return first_ == 0; + else return iter_ == rest_.end(); + } + + const L& Value() const { return init_ ? first_ : *iter_; } + + void Next() { + if (init_) init_ = false; + else ++iter_; + } + + void Reset() { + init_ = true; + iter_ = rest_.begin(); + } + + private: + const L &first_; + const list &rest_; + bool init_; // in the initialized state? + typename list::const_iterator iter_; + + DISALLOW_COPY_AND_ASSIGN(StringWeightIterator); +}; + + +// Traverses string in backward direction. +template +class StringWeightReverseIterator { + public: + explicit StringWeightReverseIterator(const StringWeight& w) + : first_(w.first_), rest_(w.rest_), fin_(first_ == 0), + iter_(rest_.rbegin()) {} + + bool Done() const { return fin_; } + + const L& Value() const { return iter_ == rest_.rend() ? first_ : *iter_; } + + void Next() { + if (iter_ == rest_.rend()) fin_ = true; + else ++iter_; + } + + void Reset() { + fin_ = false; + iter_ = rest_.rbegin(); + } + + private: + const L &first_; + const list &rest_; + bool fin_; // in the final state? + typename list::const_reverse_iterator iter_; + + DISALLOW_COPY_AND_ASSIGN(StringWeightReverseIterator); +}; + + +// StringWeight member functions follow that require +// StringWeightIterator or StringWeightReverseIterator. + +template +inline istream &StringWeight::Read(istream &strm) { + Clear(); + int32 size; + ReadType(strm, &size); + for (int i = 0; i < size; ++i) { + L label; + ReadType(strm, &label); + PushBack(label); + } + return strm; +} + +template +inline ostream &StringWeight::Write(ostream &strm) const { + int32 size = Size(); + WriteType(strm, size); + for (StringWeightIterator iter(*this); !iter.Done(); iter.Next()) { + L label = iter.Value(); + WriteType(strm, label); + } + return strm; +} + +template +inline bool StringWeight::Member() const { + if (Size() != 1) + return true; + StringWeightIterator iter(*this); + return iter.Value() != kStringBad; +} + +template +inline typename StringWeight::ReverseWeight +StringWeight::Reverse() const { + ReverseWeight rw; + for (StringWeightIterator iter(*this); !iter.Done(); iter.Next()) + rw.PushFront(iter.Value()); + return rw; +} + +template +inline size_t StringWeight::Hash() const { + size_t h = 0; + for (StringWeightIterator iter(*this); !iter.Done(); iter.Next()) + h ^= h<<1 ^ iter.Value(); + return h; +} + +// NB: This needs to be uncommented only if default fails for this the impl. +// +// template +// inline StringWeight +// &StringWeight::operator=(const StringWeight &w) { +// if (this != &w) { +// Clear(); +// for (StringWeightIterator iter(w); !iter.Done(); iter.Next()) +// PushBack(iter.Value()); +// } +// return *this; +// } + +template +inline bool operator==(const StringWeight &w1, + const StringWeight &w2) { + if (w1.Size() != w2.Size()) + return false; + + StringWeightIterator iter1(w1); + StringWeightIterator iter2(w2); + + for (; !iter1.Done() ; iter1.Next(), iter2.Next()) + if (iter1.Value() != iter2.Value()) + return false; + + return true; +} + +template +inline bool operator!=(const StringWeight &w1, + const StringWeight &w2) { + return !(w1 == w2); +} + +template +inline bool ApproxEqual(const StringWeight &w1, + const StringWeight &w2, + float delta = kDelta) { + return w1 == w2; +} + +template +inline ostream &operator<<(ostream &strm, const StringWeight &w) { + StringWeightIterator iter(w); + if (iter.Done()) + return strm << "Epsilon"; + else if (iter.Value() == kStringInfinity) + return strm << "Infinity"; + else if (iter.Value() == kStringBad) + return strm << "BadString"; + else + for (size_t i = 0; !iter.Done(); ++i, iter.Next()) { + if (i > 0) + strm << kStringSeparator; + strm << iter.Value(); + } + return strm; +} + +template +inline istream &operator>>(istream &strm, StringWeight &w) { + string s; + strm >> s; + if (s == "Infinity") { + w = StringWeight::Zero(); + } else if (s == "Epsilon") { + w = StringWeight::One(); + } else { + w.Clear(); + char *p = 0; + for (const char *cs = s.c_str(); !p || *p != '\0'; cs = p + 1) { + int l = strtoll(cs, &p, 10); + if (p == cs || (*p != 0 && *p != kStringSeparator)) { + strm.clear(std::ios::badbit); + break; + } + w.PushBack(l); + } + } + return strm; +} + + +// Default is for the restricted left and right semirings. String +// equality is required (for non-Zero() input. This restriction +// is used in e.g. Determinize to ensure functional input. +template inline StringWeight +Plus(const StringWeight &w1, + const StringWeight &w2) { + if (!w1.Member() || !w2.Member()) + return StringWeight::NoWeight(); + if (w1 == StringWeight::Zero()) + return w2; + if (w2 == StringWeight::Zero()) + return w1; + + if (w1 != w2) { + FSTERROR() << "StringWeight::Plus: unequal arguments " + << "(non-functional FST?)" + << " w1 = " << w1 + << " w2 = " << w2; + return StringWeight::NoWeight(); + } + + return w1; +} + + +// Longest common prefix for left string semiring. +template inline StringWeight +Plus(const StringWeight &w1, + const StringWeight &w2) { + if (!w1.Member() || !w2.Member()) + return StringWeight::NoWeight(); + if (w1 == StringWeight::Zero()) + return w2; + if (w2 == StringWeight::Zero()) + return w1; + + StringWeight sum; + StringWeightIterator iter1(w1); + StringWeightIterator iter2(w2); + for (; !iter1.Done() && !iter2.Done() && iter1.Value() == iter2.Value(); + iter1.Next(), iter2.Next()) + sum.PushBack(iter1.Value()); + return sum; +} + + +// Longest common suffix for right string semiring. +template inline StringWeight +Plus(const StringWeight &w1, + const StringWeight &w2) { + if (!w1.Member() || !w2.Member()) + return StringWeight::NoWeight(); + if (w1 == StringWeight::Zero()) + return w2; + if (w2 == StringWeight::Zero()) + return w1; + + StringWeight sum; + StringWeightReverseIterator iter1(w1); + StringWeightReverseIterator iter2(w2); + for (; !iter1.Done() && !iter2.Done() && iter1.Value() == iter2.Value(); + iter1.Next(), iter2.Next()) + sum.PushFront(iter1.Value()); + return sum; +} + + +template +inline StringWeight Times(const StringWeight &w1, + const StringWeight &w2) { + if (!w1.Member() || !w2.Member()) + return StringWeight::NoWeight(); + if (w1 == StringWeight::Zero() || w2 == StringWeight::Zero()) + return StringWeight::Zero(); + + StringWeight prod(w1); + for (StringWeightIterator iter(w2); !iter.Done(); iter.Next()) + prod.PushBack(iter.Value()); + + return prod; +} + + +// Default is for left division in the left string and the +// left restricted string semirings. +template inline StringWeight +Divide(const StringWeight &w1, + const StringWeight &w2, + DivideType typ) { + + if (typ != DIVIDE_LEFT) { + FSTERROR() << "StringWeight::Divide: only left division is defined " + << "for the " << StringWeight::Type() << " semiring"; + return StringWeight::NoWeight(); + } + + if (!w1.Member() || !w2.Member()) + return StringWeight::NoWeight(); + + if (w2 == StringWeight::Zero()) + return StringWeight(kStringBad); + else if (w1 == StringWeight::Zero()) + return StringWeight::Zero(); + + StringWeight div; + StringWeightIterator iter(w1); + for (int i = 0; !iter.Done(); iter.Next(), ++i) { + if (i >= w2.Size()) + div.PushBack(iter.Value()); + } + return div; +} + + +// Right division in the right string semiring. +template inline StringWeight +Divide(const StringWeight &w1, + const StringWeight &w2, + DivideType typ) { + + if (typ != DIVIDE_RIGHT) { + FSTERROR() << "StringWeight::Divide: only right division is defined " + << "for the right string semiring"; + return StringWeight::NoWeight(); + } + + if (!w1.Member() || !w2.Member()) + return StringWeight::NoWeight(); + + if (w2 == StringWeight::Zero()) + return StringWeight(kStringBad); + else if (w1 == StringWeight::Zero()) + return StringWeight::Zero(); + + StringWeight div; + StringWeightReverseIterator iter(w1); + for (int i = 0; !iter.Done(); iter.Next(), ++i) { + if (i >= w2.Size()) + div.PushFront(iter.Value()); + } + return div; +} + + +// Right division in the right restricted string semiring. +template inline StringWeight +Divide(const StringWeight &w1, + const StringWeight &w2, + DivideType typ) { + + if (typ != DIVIDE_RIGHT) { + FSTERROR() << "StringWeight::Divide: only right division is defined " + << "for the right restricted string semiring"; + return StringWeight::NoWeight(); + } + + if (!w1.Member() || !w2.Member()) + return StringWeight::NoWeight(); + + if (w2 == StringWeight::Zero()) + return StringWeight(kStringBad); + else if (w1 == StringWeight::Zero()) + return StringWeight::Zero(); + + StringWeight div; + StringWeightReverseIterator iter(w1); + for (int i = 0; !iter.Done(); iter.Next(), ++i) { + if (i >= w2.Size()) + div.PushFront(iter.Value()); + } + return div; +} + + +// Product of string weight and an arbitray weight. +template +struct GallicWeight : public ProductWeight, W> { + typedef GallicWeight + ReverseWeight; + + GallicWeight() {} + + GallicWeight(StringWeight w1, W w2) + : ProductWeight, W>(w1, w2) {} + + explicit GallicWeight(const string &s, int *nread = 0) + : ProductWeight, W>(s, nread) {} + + GallicWeight(const ProductWeight, W> &w) + : ProductWeight, W>(w) {} +}; + +} // namespace fst + +#endif // FST_LIB_STRING_WEIGHT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/string.h b/kaldi_io/src/tools/openfst/include/fst/string.h new file mode 100644 index 0000000..9eaf7a3 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/string.h @@ -0,0 +1,271 @@ + +// string.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: allauzen@google.com (Cyril Allauzen) +// +// \file +// Utilities to convert strings into FSTs. +// + +#ifndef FST_LIB_STRING_H_ +#define FST_LIB_STRING_H_ + +#include +#include +#include + +DECLARE_string(fst_field_separator); + +namespace fst { + +// Functor compiling a string in an FST +template +class StringCompiler { + public: + typedef A Arc; + typedef typename A::Label Label; + typedef typename A::Weight Weight; + + enum TokenType { SYMBOL = 1, BYTE = 2, UTF8 = 3 }; + + StringCompiler(TokenType type, const SymbolTable *syms = 0, + Label unknown_label = kNoLabel, + bool allow_negative = false) + : token_type_(type), syms_(syms), unknown_label_(unknown_label), + allow_negative_(allow_negative) {} + + // Compile string 's' into FST 'fst'. + template + bool operator()(const string &s, F *fst) const { + vector *fst, + const Weight &weight = Weight::One()) const { + fst->DeleteStates(); + while (fst->NumStates() <= labels.size()) + fst->AddState(); + for (size_t i = 0; i < labels.size(); ++i) + fst->AddArc(i, Arc(labels[i], labels[i], Weight::One(), i + 1)); + fst->SetStart(0); + fst->SetFinal(labels.size(), weight); + } + + template + void Compile(const vector &fst, string *output) { + bool is_a_string = FstToLabels(fst); + if (!is_a_string) { + VLOG(1) << "StringPrinter::operator(): Fst is not a string."; + return false; + } + + output->clear(); + + if (token_type_ == SYMBOL) { + stringstream sstrm; + for (size_t i = 0; i < labels_.size(); ++i) { + if (i) + sstrm << *(FLAGS_fst_field_separator.rbegin()); + if (!PrintLabel(labels_[i], sstrm)) + return false; + } + *output = sstrm.str(); + } else if (token_type_ == BYTE) { + output->reserve(labels_.size()); + for (size_t i = 0; i < labels_.size(); ++i) { + output->push_back(labels_[i]); + } + } else if (token_type_ == UTF8) { + return LabelsToUTF8String(labels_, output); + } else { + VLOG(1) << "StringPrinter::operator(): Unknown token type: " + << token_type_; + return false; + } + return true; + } + + private: + bool FstToLabels(const Fst &fst) { + labels_.clear(); + + StateId s = fst.Start(); + if (s == kNoStateId) { + VLOG(2) << "StringPrinter::FstToLabels: Invalid starting state for " + << "string fst."; + return false; + } + + while (fst.Final(s) == Weight::Zero()) { + ArcIterator > aiter(fst, s); + if (aiter.Done()) { + VLOG(2) << "StringPrinter::FstToLabels: String fst traversal does " + << "not reach final state."; + return false; + } + + const A& arc = aiter.Value(); + labels_.push_back(arc.olabel); + + s = arc.nextstate; + if (s == kNoStateId) { + VLOG(2) << "StringPrinter::FstToLabels: Transition to invalid " + << "state."; + return false; + } + + aiter.Next(); + if (!aiter.Done()) { + VLOG(2) << "StringPrinter::FstToLabels: State with multiple " + << "outgoing arcs found."; + return false; + } + } + + return true; + } + + bool PrintLabel(Label lab, ostream& ostrm) { + if (syms_) { + string symbol = syms_->Find(lab); + if (symbol == "") { + VLOG(2) << "StringPrinter::PrintLabel: Integer " << lab << " is not " + << "mapped to any textual symbol, symbol table = " + << syms_->Name(); + return false; + } + ostrm << symbol; + } else { + ostrm << lab; + } + return true; + } + + TokenType token_type_; // Token type: symbol, byte or utf8 encoded + const SymbolTable *syms_; // Symbol table used when token type is symbol + vector { + public: + using FstImpl::SetType; + using FstImpl::SetProperties; + using FstImpl::SetInputSymbols; + using FstImpl::SetOutputSymbols; + + using CacheBaseImpl< CacheState >::PushArc; + using CacheBaseImpl< CacheState >::HasArcs; + using CacheBaseImpl< CacheState >::HasFinal; + using CacheBaseImpl< CacheState >::HasStart; + using CacheBaseImpl< CacheState >::SetArcs; + using CacheBaseImpl< CacheState >::SetFinal; + using CacheBaseImpl< CacheState >::SetStart; + + typedef A Arc; + typedef typename A::Label Label; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + + typedef basic_string &fst, const SynchronizeFstOptions &opts) + : CacheImpl(opts), fst_(fst.Copy()) { + SetType("synchronize"); + uint64 props = fst.Properties(kFstProperties, false); + SetProperties(SynchronizeProperties(props), kCopyProperties); + + SetInputSymbols(fst.InputSymbols()); + SetOutputSymbols(fst.OutputSymbols()); + } + + SynchronizeFstImpl(const SynchronizeFstImpl &impl) + : CacheImpl(impl), + fst_(impl.fst_->Copy(true)) { + SetType("synchronize"); + SetProperties(impl.Properties(), kCopyProperties); + SetInputSymbols(impl.InputSymbols()); + SetOutputSymbols(impl.OutputSymbols()); + } + + ~SynchronizeFstImpl() { + delete fst_; + // Extract pointers from the hash set + vector strings; + typename StringSet::iterator it = string_set_.begin(); + for (; it != string_set_.end(); ++it) + strings.push_back(*it); + // Free the extracted pointers + for (size_t i = 0; i < strings.size(); ++i) + delete strings[i]; + } + + StateId Start() { + if (!HasStart()) { + StateId s = fst_->Start(); + if (s == kNoStateId) + return kNoStateId; + const String *empty = FindString(new String()); + StateId start = FindState(Element(fst_->Start(), empty, empty)); + SetStart(start); + } + return CacheImpl::Start(); + } + + Weight Final(StateId s) { + if (!HasFinal(s)) { + const Element &e = elements_[s]; + Weight w = e.state == kNoStateId ? Weight::One() : fst_->Final(e.state); + if ((w != Weight::Zero()) && (e.istring)->empty() && (e.ostring)->empty()) + SetFinal(s, w); + else + SetFinal(s, Weight::Zero()); + } + return CacheImpl::Final(s); + } + + size_t NumArcs(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumArcs(s); + } + + size_t NumInputEpsilons(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumInputEpsilons(s); + } + + size_t NumOutputEpsilons(StateId s) { + if (!HasArcs(s)) + Expand(s); + return CacheImpl::NumOutputEpsilons(s); + } + + uint64 Properties() const { return Properties(kFstProperties); } + + // Set error if found; return FST impl properties. + uint64 Properties(uint64 mask) const { + if ((mask & kError) && fst_->Properties(kError, false)) + SetProperties(kError, kError); + return FstImpl::Properties(mask); + } + + void InitArcIterator(StateId s, ArcIteratorData *data) { + if (!HasArcs(s)) + Expand(s); + CacheImpl::InitArcIterator(s, data); + } + + // Returns the first character of the string obtained by + // concatenating s and l. + Label Car(const String *s, Label l = 0) const { + if (!s->empty()) + return (*s)[0]; + else + return l; + } + + // Computes the residual string obtained by removing the first + // character in the concatenation of s and l. + const String *Cdr(const String *s, Label l = 0) { + String *r = new String(); + for (int i = 1; i < s->size(); ++i) + r->push_back((*s)[i]); + if (l && !(s->empty())) r->push_back(l); + return FindString(r); + } + + // Computes the concatenation of s and l. + const String *Concat(const String *s, Label l = 0) { + String *r = new String(); + for (int i = 0; i < s->size(); ++i) + r->push_back((*s)[i]); + if (l) r->push_back(l); + return FindString(r); + } + + // Tests if the concatenation of s and l is empty + bool Empty(const String *s, Label l = 0) const { + if (s->empty()) + return l == 0; + else + return false; + } + + // Finds the string pointed by s in the hash set. Transfers the + // pointer ownership to the hash set. + const String *FindString(const String *s) { + typename StringSet::iterator it = string_set_.find(s); + if (it != string_set_.end()) { + delete s; + return (*it); + } else { + string_set_.insert(s); + return s; + } + } + + // Finds state corresponding to an element. Creates new state + // if element not found. + StateId FindState(const Element &e) { + typename ElementMap::iterator eit = element_map_.find(e); + if (eit != element_map_.end()) { + return (*eit).second; + } else { + StateId s = elements_.size(); + elements_.push_back(e); + element_map_.insert(pair(e, s)); + return s; + } + } + + + // Computes the outgoing transitions from a state, creating new destination + // states as needed. + void Expand(StateId s) { + Element e = elements_[s]; + + if (e.state != kNoStateId) + for (ArcIterator< Fst > ait(*fst_, e.state); + !ait.Done(); + ait.Next()) { + const A &arc = ait.Value(); + if (!Empty(e.istring, arc.ilabel) && !Empty(e.ostring, arc.olabel)) { + const String *istring = Cdr(e.istring, arc.ilabel); + const String *ostring = Cdr(e.ostring, arc.olabel); + StateId d = FindState(Element(arc.nextstate, istring, ostring)); + PushArc(s, Arc(Car(e.istring, arc.ilabel), + Car(e.ostring, arc.olabel), arc.weight, d)); + } else { + const String *istring = Concat(e.istring, arc.ilabel); + const String *ostring = Concat(e.ostring, arc.olabel); + StateId d = FindState(Element(arc.nextstate, istring, ostring)); + PushArc(s, Arc(0 , 0, arc.weight, d)); + } + } + + Weight w = e.state == kNoStateId ? Weight::One() : fst_->Final(e.state); + if ((w != Weight::Zero()) && + ((e.istring)->size() + (e.ostring)->size() > 0)) { + const String *istring = Cdr(e.istring); + const String *ostring = Cdr(e.ostring); + StateId d = FindState(Element(kNoStateId, istring, ostring)); + PushArc(s, Arc(Car(e.istring), Car(e.ostring), w, d)); + } + SetArcs(s); + } + + private: + // Equality function for Elements, assume strings have been hashed. + class ElementEqual { + public: + bool operator()(const Element &x, const Element &y) const { + return x.state == y.state && + x.istring == y.istring && + x.ostring == y.ostring; + } + }; + + // Hash function for Elements to Fst states. + class ElementKey { + public: + size_t operator()(const Element &x) const { + size_t key = x.state; + key = (key << 1) ^ (x.istring)->size(); + for (size_t i = 0; i < (x.istring)->size(); ++i) + key = (key << 1) ^ (*x.istring)[i]; + key = (key << 1) ^ (x.ostring)->size(); + for (size_t i = 0; i < (x.ostring)->size(); ++i) + key = (key << 1) ^ (*x.ostring)[i]; + return key; + } + }; + + // Equality function for strings + class StringEqual { + public: + bool operator()(const String * const &x, const String * const &y) const { + if (x->size() != y->size()) return false; + for (size_t i = 0; i < x->size(); ++i) + if ((*x)[i] != (*y)[i]) return false; + return true; + } + }; + + // Hash function for set of strings + class StringKey{ + public: + size_t operator()(const String * const & x) const { + size_t key = x->size(); + for (size_t i = 0; i < x->size(); ++i) + key = (key << 1) ^ (*x)[i]; + return key; + } + }; + + + typedef unordered_map ElementMap; + typedef unordered_set StringSet; + + const Fst *fst_; + vector elements_; // mapping Fst state to Elements + ElementMap element_map_; // mapping Elements to Fst state + StringSet string_set_; + + void operator=(const SynchronizeFstImpl &); // disallow +}; + + +// Synchronizes a transducer. This version is a delayed Fst. The +// result will be an equivalent FST that has the property that during +// the traversal of a path, the delay is either zero or strictly +// increasing, where the delay is the difference between the number of +// non-epsilon output labels and input labels along the path. +// +// For the algorithm to terminate, the input transducer must have +// bounded delay, i.e., the delay of every cycle must be zero. +// +// Complexity: +// - A has bounded delay: exponential +// - A does not have bounded delay: does not terminate +// +// References: +// - Mehryar Mohri. Edit-Distance of Weighted Automata: General +// Definitions and Algorithms, International Journal of Computer +// Science, 14(6): 957-982 (2003). +// +// This class attaches interface to implementation and handles +// reference counting, delegating most methods to ImplToFst. +template +class SynchronizeFst : public ImplToFst< SynchronizeFstImpl > { + public: + friend class ArcIterator< SynchronizeFst >; + friend class StateIterator< SynchronizeFst >; + + typedef A Arc; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + typedef CacheState State; + typedef SynchronizeFstImpl Impl; + + SynchronizeFst(const Fst &fst) + : ImplToFst(new Impl(fst, SynchronizeFstOptions())) {} + + SynchronizeFst(const Fst &fst, const SynchronizeFstOptions &opts) + : ImplToFst(new Impl(fst, opts)) {} + + // See Fst<>::Copy() for doc. + SynchronizeFst(const SynchronizeFst &fst, bool safe = false) + : ImplToFst(fst, safe) {} + + // Get a copy of this SynchronizeFst. See Fst<>::Copy() for further doc. + virtual SynchronizeFst *Copy(bool safe = false) const { + return new SynchronizeFst(*this, safe); + } + + virtual inline void InitStateIterator(StateIteratorData *data) const; + + virtual void InitArcIterator(StateId s, ArcIteratorData *data) const { + GetImpl()->InitArcIterator(s, data); + } + + private: + // Makes visible to friends. + Impl *GetImpl() const { return ImplToFst::GetImpl(); } + + void operator=(const SynchronizeFst &fst); // Disallow +}; + + +// Specialization for SynchronizeFst. +template +class StateIterator< SynchronizeFst > + : public CacheStateIterator< SynchronizeFst > { + public: + explicit StateIterator(const SynchronizeFst &fst) + : CacheStateIterator< SynchronizeFst >(fst, fst.GetImpl()) {} +}; + + +// Specialization for SynchronizeFst. +template +class ArcIterator< SynchronizeFst > + : public CacheArcIterator< SynchronizeFst > { + public: + typedef typename A::StateId StateId; + + ArcIterator(const SynchronizeFst &fst, StateId s) + : CacheArcIterator< SynchronizeFst >(fst.GetImpl(), s) { + if (!fst.GetImpl()->HasArcs(s)) + fst.GetImpl()->Expand(s); + } + + private: + DISALLOW_COPY_AND_ASSIGN(ArcIterator); +}; + + +template inline +void SynchronizeFst::InitStateIterator(StateIteratorData *data) const +{ + data->base = new StateIterator< SynchronizeFst >(*this); +} + + + +// Synchronizes a transducer. This version writes the synchronized +// result to a MutableFst. The result will be an equivalent FST that +// has the property that during the traversal of a path, the delay is +// either zero or strictly increasing, where the delay is the +// difference between the number of non-epsilon output labels and +// input labels along the path. +// +// For the algorithm to terminate, the input transducer must have +// bounded delay, i.e., the delay of every cycle must be zero. +// +// Complexity: +// - A has bounded delay: exponential +// - A does not have bounded delay: does not terminate +// +// References: +// - Mehryar Mohri. Edit-Distance of Weighted Automata: General +// Definitions and Algorithms, International Journal of Computer +// Science, 14(6): 957-982 (2003). +template +void Synchronize(const Fst &ifst, MutableFst *ofst) { + SynchronizeFstOptions opts; + opts.gc_limit = 0; // Cache only the last state for fastest copy. + *ofst = SynchronizeFst(ifst, opts); +} + +} // namespace fst + +#endif // FST_LIB_SYNCHRONIZE_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/test-properties.h b/kaldi_io/src/tools/openfst/include/fst/test-properties.h new file mode 100644 index 0000000..80af593 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/test-properties.h @@ -0,0 +1,250 @@ +// test-properties.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Functions to manipulate and test property bits + +#ifndef FST_LIB_TEST_PROPERTIES_H__ +#define FST_LIB_TEST_PROPERTIES_H__ + +#include +using std::tr1::unordered_set; +using std::tr1::unordered_multiset; + +#include +#include + + +DECLARE_bool(fst_verify_properties); + +namespace fst { + +// For a binary property, the bit is always returned set. +// For a trinary (i.e. two-bit) property, both bits are +// returned set iff either corresponding input bit is set. +inline uint64 KnownProperties(uint64 props) { + return kBinaryProperties | (props & kTrinaryProperties) | + ((props & kPosTrinaryProperties) << 1) | + ((props & kNegTrinaryProperties) >> 1); +} + +// Tests compatibility between two sets of properties +inline bool CompatProperties(uint64 props1, uint64 props2) { + uint64 known_props1 = KnownProperties(props1); + uint64 known_props2 = KnownProperties(props2); + uint64 known_props = known_props1 & known_props2; + uint64 incompat_props = (props1 & known_props) ^ (props2 & known_props); + if (incompat_props) { + uint64 prop = 1; + for (int i = 0; i < 64; ++i, prop <<= 1) + if (prop & incompat_props) + LOG(ERROR) << "CompatProperties: mismatch: " << PropertyNames[i] + << ": props1 = " << (props1 & prop ? "true" : "false") + << ", props2 = " << (props2 & prop ? "true" : "false"); + return false; + } else { + return true; + } +} + +// Computes FST property values defined in properties.h. The value of +// each property indicated in the mask will be determined and returned +// (these will never be unknown here). In the course of determining +// the properties specifically requested in the mask, certain other +// properties may be determined (those with little additional expense) +// and their values will be returned as well. The complete set of +// known properties (whether true or false) determined by this +// operation will be assigned to the the value pointed to by KNOWN. +// If 'use_stored' is true, pre-computed FST properties may be used +// when possible. This routine is seldom called directly; instead it +// is used to implement fst.Properties(mask, true). +template +uint64 ComputeProperties(const Fst &fst, uint64 mask, uint64 *known, + bool use_stored) { + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + typedef typename Arc::StateId StateId; + + uint64 fst_props = fst.Properties(kFstProperties, false); // Fst-stored + + // Check stored FST properties first if allowed. + if (use_stored) { + uint64 known_props = KnownProperties(fst_props); + // If FST contains required info, return it. + if ((known_props & mask) == mask) { + *known = known_props; + return fst_props; + } + } + + // Compute (trinary) properties explicitly. + + // Initialize with binary properties (already known). + uint64 comp_props = fst_props & kBinaryProperties; + + // Compute these trinary properties with a DFS. We compute only those + // that need a DFS here, since we otherwise would like to avoid a DFS + // since its stack could grow large. + uint64 dfs_props = kCyclic | kAcyclic | kInitialCyclic | kInitialAcyclic | + kAccessible | kNotAccessible | + kCoAccessible | kNotCoAccessible; + if (mask & dfs_props) { + SccVisitor scc_visitor(&comp_props); + DfsVisit(fst, &scc_visitor); + } + + // Compute any remaining trinary properties via a state and arcs iterations + if (mask & ~(kBinaryProperties | dfs_props)) { + comp_props |= kAcceptor | kNoEpsilons | kNoIEpsilons | kNoOEpsilons | + kILabelSorted | kOLabelSorted | kUnweighted | kTopSorted | kString; + if (mask & (kIDeterministic | kNonIDeterministic)) + comp_props |= kIDeterministic; + if (mask & (kODeterministic | kNonODeterministic)) + comp_props |= kODeterministic; + + unordered_set &fst) { + finish_ = new vector; + *acyclic_ = true; + } + + bool InitState(StateId s, StateId r) { return true; } + + bool TreeArc(StateId s, const A &arc) { return true; } + + bool BackArc(StateId s, const A &arc) { return (*acyclic_ = false); } + + bool ForwardOrCrossArc(StateId s, const A &arc) { return true; } + + void FinishState(StateId s, StateId p, const A *) { finish_->push_back(s); } + + void FinishVisit() { + if (*acyclic_) { + order_->clear(); + for (StateId s = 0; s < finish_->size(); ++s) + order_->push_back(kNoStateId); + for (StateId s = 0; s < finish_->size(); ++s) + (*order_)[(*finish_)[finish_->size() - s - 1]] = s; + } + delete finish_; + } + + private: + vector *order_; + bool *acyclic_; + vector *finish_; // states in finishing-time order +}; + + +// Topologically sorts its input if acyclic, modifying it. Otherwise, +// the input is unchanged. When sorted, all transitions are from +// lower to higher state IDs. +// +// Complexity: +// - Time: O(V + E) +// - Space: O(V + E) +// where V = # of states and E = # of arcs. +template +bool TopSort(MutableFst *fst) { + typedef typename Arc::StateId StateId; + + vector order; + bool acyclic; + + TopOrderVisitor top_order_visitor(&order, &acyclic); + DfsVisit(*fst, &top_order_visitor); + + if (acyclic) { + StateSort(fst, order); + fst->SetProperties(kAcyclic | kInitialAcyclic | kTopSorted, + kAcyclic | kInitialAcyclic | kTopSorted); + } else { + fst->SetProperties(kCyclic | kNotTopSorted, kCyclic | kNotTopSorted); + } + return acyclic; +} + +} // namespace fst + +#endif // FST_LIB_TOPSORT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/tuple-weight.h b/kaldi_io/src/tools/openfst/include/fst/tuple-weight.h new file mode 100644 index 0000000..184026c --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/tuple-weight.h @@ -0,0 +1,332 @@ +// tuple-weight.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: allauzen@google (Cyril Allauzen) +// +// \file +// Tuple weight set operation definitions. + +#ifndef FST_LIB_TUPLE_WEIGHT_H__ +#define FST_LIB_TUPLE_WEIGHT_H__ + +#include +#include +using std::vector; + +#include + + +DECLARE_string(fst_weight_parentheses); +DECLARE_string(fst_weight_separator); + +namespace fst { + +template class TupleWeight; +template +istream &operator>>(istream &strm, TupleWeight &w); + +// n-tuple weight, element of the n-th catersian power of W +template +class TupleWeight { + public: + typedef TupleWeight ReverseWeight; + + TupleWeight() {} + + TupleWeight(const TupleWeight &w) { + for (size_t i = 0; i < n; ++i) + values_[i] = w.values_[i]; + } + + template + TupleWeight(Iterator begin, Iterator end) { + for (Iterator iter = begin; iter != end; ++iter) + values_[iter - begin] = *iter; + } + + TupleWeight(const W &w) { + for (size_t i = 0; i < n; ++i) + values_[i] = w; + } + + static const TupleWeight &Zero() { + static const TupleWeight zero(W::Zero()); + return zero; + } + + static const TupleWeight &One() { + static const TupleWeight one(W::One()); + return one; + } + + static const TupleWeight &NoWeight() { + static const TupleWeight no_weight(W::NoWeight()); + return no_weight; + } + + static unsigned int Length() { + return n; + } + + istream &Read(istream &strm) { + for (size_t i = 0; i < n; ++i) + values_[i].Read(strm); + return strm; + } + + ostream &Write(ostream &strm) const { + for (size_t i = 0; i < n; ++i) + values_[i].Write(strm); + return strm; + } + + TupleWeight &operator=(const TupleWeight &w) { + for (size_t i = 0; i < n; ++i) + values_[i] = w.values_[i]; + return *this; + } + + bool Member() const { + bool member = true; + for (size_t i = 0; i < n; ++i) + member = member && values_[i].Member(); + return member; + } + + size_t Hash() const { + uint64 hash = 0; + for (size_t i = 0; i < n; ++i) + hash = 5 * hash + values_[i].Hash(); + return size_t(hash); + } + + TupleWeight Quantize(float delta = kDelta) const { + TupleWeight w; + for (size_t i = 0; i < n; ++i) + w.values_[i] = values_[i].Quantize(delta); + return w; + } + + ReverseWeight Reverse() const { + TupleWeight w; + for (size_t i = 0; i < n; ++i) + w.values_[i] = values_[i].Reverse(); + return w; + } + + const W& Value(size_t i) const { return values_[i]; } + + void SetValue(size_t i, const W &w) { values_[i] = w; } + + protected: + // Reads TupleWeight when there are no parentheses around tuple terms + inline static istream &ReadNoParen(istream &strm, + TupleWeight &w, + char separator) { + int c; + do { + c = strm.get(); + } while (isspace(c)); + + for (size_t i = 0; i < n - 1; ++i) { + string s; + if (i) + c = strm.get(); + while (c != separator) { + if (c == EOF) { + strm.clear(std::ios::badbit); + return strm; + } + s += c; + c = strm.get(); + } + // read (i+1)-th element + istringstream sstrm(s); + W r = W::Zero(); + sstrm >> r; + w.SetValue(i, r); + } + + // read n-th element + W r = W::Zero(); + strm >> r; + w.SetValue(n - 1, r); + + return strm; + } + + // Reads TupleWeight when there are parentheses around tuple terms + inline static istream &ReadWithParen(istream &strm, + TupleWeight &w, + char separator, + char open_paren, + char close_paren) { + int c; + do { + c = strm.get(); + } while (isspace(c)); + + if (c != open_paren) { + FSTERROR() << " is fst_weight_parentheses flag set correcty? "; + strm.clear(std::ios::badbit); + return strm; + } + + for (size_t i = 0; i < n - 1; ++i) { + // read (i+1)-th element + stack parens; + string s; + c = strm.get(); + while (c != separator || !parens.empty()) { + if (c == EOF) { + strm.clear(std::ios::badbit); + return strm; + } + s += c; + // if parens encountered before separator, they must be matched + if (c == open_paren) { + parens.push(1); + } else if (c == close_paren) { + // Fail for mismatched parens + if (parens.empty()) { + strm.clear(std::ios::failbit); + return strm; + } + parens.pop(); + } + c = strm.get(); + } + istringstream sstrm(s); + W r = W::Zero(); + sstrm >> r; + w.SetValue(i, r); + } + + // read n-th element + string s; + c = strm.get(); + while (c != EOF) { + s += c; + c = strm.get(); + } + if (s.empty() || *s.rbegin() != close_paren) { + FSTERROR() << " is fst_weight_parentheses flag set correcty? "; + strm.clear(std::ios::failbit); + return strm; + } + s.erase(s.size() - 1, 1); + istringstream sstrm(s); + W r = W::Zero(); + sstrm >> r; + w.SetValue(n - 1, r); + + return strm; + } + + + private: + W values_[n]; + + friend istream &operator>>(istream&, TupleWeight&); +}; + +template +inline bool operator==(const TupleWeight &w1, + const TupleWeight &w2) { + bool equal = true; + for (size_t i = 0; i < n; ++i) + equal = equal && (w1.Value(i) == w2.Value(i)); + return equal; +} + +template +inline bool operator!=(const TupleWeight &w1, + const TupleWeight &w2) { + bool not_equal = false; + for (size_t i = 0; (i < n) && !not_equal; ++i) + not_equal = not_equal || (w1.Value(i) != w2.Value(i)); + return not_equal; +} + +template +inline bool ApproxEqual(const TupleWeight &w1, + const TupleWeight &w2, + float delta = kDelta) { + bool approx_equal = true; + for (size_t i = 0; i < n; ++i) + approx_equal = approx_equal && + ApproxEqual(w1.Value(i), w2.Value(i), delta); + return approx_equal; +} + +template +inline ostream &operator<<(ostream &strm, const TupleWeight &w) { + if(FLAGS_fst_weight_separator.size() != 1) { + FSTERROR() << "FLAGS_fst_weight_separator.size() is not equal to 1"; + strm.clear(std::ios::badbit); + return strm; + } + char separator = FLAGS_fst_weight_separator[0]; + bool write_parens = false; + if (!FLAGS_fst_weight_parentheses.empty()) { + if (FLAGS_fst_weight_parentheses.size() != 2) { + FSTERROR() << "FLAGS_fst_weight_parentheses.size() is not equal to 2"; + strm.clear(std::ios::badbit); + return strm; + } + write_parens = true; + } + + if (write_parens) + strm << FLAGS_fst_weight_parentheses[0]; + for (size_t i = 0; i < n; ++i) { + if(i) + strm << separator; + strm << w.Value(i); + } + if (write_parens) + strm << FLAGS_fst_weight_parentheses[1]; + + return strm; +} + +template +inline istream &operator>>(istream &strm, TupleWeight &w) { + if(FLAGS_fst_weight_separator.size() != 1) { + FSTERROR() << "FLAGS_fst_weight_separator.size() is not equal to 1"; + strm.clear(std::ios::badbit); + return strm; + } + char separator = FLAGS_fst_weight_separator[0]; + + if (!FLAGS_fst_weight_parentheses.empty()) { + if (FLAGS_fst_weight_parentheses.size() != 2) { + FSTERROR() << "FLAGS_fst_weight_parentheses.size() is not equal to 2"; + strm.clear(std::ios::badbit); + return strm; + } + return TupleWeight::ReadWithParen( + strm, w, separator, FLAGS_fst_weight_parentheses[0], + FLAGS_fst_weight_parentheses[1]); + } else { + return TupleWeight::ReadNoParen(strm, w, separator); + } +} + + + +} // namespace fst + +#endif // FST_LIB_TUPLE_WEIGHT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/types.h b/kaldi_io/src/tools/openfst/include/fst/types.h new file mode 100644 index 0000000..8c4367a --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/types.h @@ -0,0 +1,38 @@ +// types.h +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Author: riley@google.com (Michael Riley) +// +// \file +// Various type definitions (mostly for Google compatibility). + +#include // for ssize_t +#include // *int*_t + +#include // for DISALLOW_COPY_AND_ASSIGN + +#ifndef FST_LIB_TYPES_H__ +#define FST_LIB_TYPES_H__ + +typedef int8_t int8; +typedef int16_t int16; +typedef int32_t int32; +typedef int64_t int64; + +typedef uint8_t uint8; +typedef uint16_t uint16; +typedef uint32_t uint32; +typedef uint64_t uint64; + +#endif // FST_LIB_TYPES_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/union-find.h b/kaldi_io/src/tools/openfst/include/fst/union-find.h new file mode 100644 index 0000000..c8633e0 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/union-find.h @@ -0,0 +1,110 @@ + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: wojciech@google.com (Wojciech Skut) +// +// \file Union-Find algorithm for dense sets of non-negative +// integers. Implemented using disjoint tree forests with rank +// heuristics and path compression. + +#ifndef __fst_union_find_inl_h__ +#define __fst_union_find_inl_h__ + +#include +#include +using std::vector; +#include + +namespace fst { + +// Union-Find algorithm for dense sets of non-negative integers +// (exact type: T). +template +class UnionFind { + public: + // Ctor: creates a disjoint set forest for the range [0;max). + // 'fail' is a value indicating that an element hasn't been + // initialized using MakeSet(...). The upper bound of the range + // can be reset (increased) using MakeSet(...). + UnionFind(T max, T fail) + : parent_(max, fail), rank_(max), fail_(fail) { } + + // Finds the representative of the set 'item' belongs to. + // Performs path compression if needed. + T FindSet(T item) { + if (item >= parent_.size() + || item == fail_ + || parent_[item] == fail_) return fail_; + + T *p = &parent_[item]; + for (; *p != item; item = *p, p = &parent_[item]) { + exec_stack_.push(p); + } + for (; ! exec_stack_.empty(); exec_stack_.pop()) { + *exec_stack_.top() = *p; + } + return *p; + } + + // Creates the (destructive) union of the sets x and y belong to. + void Union(T x, T y) { + Link(FindSet(x), FindSet(y)); + } + + // Initialization of an element: creates a singleton set containing + // 'item'. The range [0;max) is reset if item >= max. + T MakeSet(T item) { + if (item >= parent_.size()) { + // New value in parent_ should be initialized to fail_ + size_t nitem = item > 0 ? 2 * item : 2; + parent_.resize(nitem, fail_); + rank_.resize(nitem); + } + parent_[item] = item; + return item; + } + + // Initialization of all elements starting from 0 to max - 1 to distinct sets + void MakeAllSet(T max) { + parent_.resize(max); + for (T item = 0; item < max; ++item) { + parent_[item] = item; + } + } + + private: + vector parent_; // Parent nodes. + vector rank_; // Rank of an element = min. depth in tree. + T fail_; // Value indicating lookup failure. + stack exec_stack_; // Used for path compression. + + // Links trees rooted in 'x' and 'y'. + void Link(T x, T y) { + if (x == y) return; + + if (rank_[x] > rank_[y]) { + parent_[y] = x; + } else { + parent_[x] = y; + if (rank_[x] == rank_[y]) { + ++rank_[y]; + } + } + } + DISALLOW_COPY_AND_ASSIGN(UnionFind); +}; + +} // namespace fst + +#endif // __fst_union_find_inl_h__ diff --git a/kaldi_io/src/tools/openfst/include/fst/union.h b/kaldi_io/src/tools/openfst/include/fst/union.h new file mode 100644 index 0000000..a2f97fb --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/union.h @@ -0,0 +1,185 @@ +// union.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Functions and classes to compute the union of two FSTs. + +#ifndef FST_LIB_UNION_H__ +#define FST_LIB_UNION_H__ + +#include +using std::vector; +#include + +#include +#include + + +namespace fst { + +// Computes the union (sum) of two FSTs. This version writes the +// union to an output MurableFst. If A transduces string x to y with +// weight a and B transduces string w to v with weight b, then their +// union transduces x to y with weight a and w to v with weight b. +// +// Complexity: +// - Time: (V2 + E2) +// - Space: O(V2 + E2) +// where Vi = # of states and Ei = # of arcs of the ith FST. +template +void Union(MutableFst *fst1, const Fst &fst2) { + typedef typename Arc::StateId StateId; + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + + // TODO(riley): restore when voice actions issues fixed + // Check that the symbol table are compatible + if (!CompatSymbols(fst1->InputSymbols(), fst2.InputSymbols()) || + !CompatSymbols(fst1->OutputSymbols(), fst2.OutputSymbols())) { + LOG(ERROR) << "Union: input/output symbol tables of 1st argument " + << "do not match input/output symbol tables of 2nd argument"; + // fst1->SetProperties(kError, kError); + // return; + } + + StateId numstates1 = fst1->NumStates(); + bool initial_acyclic1 = fst1->Properties(kInitialAcyclic, true); + uint64 props1 = fst1->Properties(kFstProperties, false); + uint64 props2 = fst2.Properties(kFstProperties, false); + + StateId start2 = fst2.Start(); + if (start2 == kNoStateId) { + if (props2 & kError) fst1->SetProperties(kError, kError); + return; + } + + if (fst2.Properties(kExpanded, false)) { + fst1->ReserveStates( + numstates1 + CountStates(fst2) + (initial_acyclic1 ? 0 : 1)); + } + + for (StateIterator< Fst > siter(fst2); + !siter.Done(); + siter.Next()) { + StateId s1 = fst1->AddState(); + StateId s2 = siter.Value(); + fst1->SetFinal(s1, fst2.Final(s2)); + fst1->ReserveArcs(s1, fst2.NumArcs(s2)); + for (ArcIterator< Fst > aiter(fst2, s2); + !aiter.Done(); + aiter.Next()) { + Arc arc = aiter.Value(); + arc.nextstate += numstates1; + fst1->AddArc(s1, arc); + } + } + StateId start1 = fst1->Start(); + if (start1 == kNoStateId) { + fst1->SetStart(start2); + fst1->SetProperties(props2, kCopyProperties); + return; + } + + if (initial_acyclic1) { + fst1->AddArc(start1, Arc(0, 0, Weight::One(), start2 + numstates1)); + } else { + StateId nstart1 = fst1->AddState(); + fst1->SetStart(nstart1); + fst1->AddArc(nstart1, Arc(0, 0, Weight::One(), start1)); + fst1->AddArc(nstart1, Arc(0, 0, Weight::One(), start2 + numstates1)); + } + fst1->SetProperties(UnionProperties(props1, props2), kFstProperties); +} + + +// Computes the union of two FSTs; this version modifies its +// RationalFst argument. +template +void Union(RationalFst *fst1, const Fst &fst2) { + fst1->GetImpl()->AddUnion(fst2); +} + + +typedef RationalFstOptions UnionFstOptions; + + +// Computes the union (sum) of two FSTs. This version is a delayed +// Fst. If A transduces string x to y with weight a and B transduces +// string w to v with weight b, then their union transduces x to y +// with weight a and w to v with weight b. +// +// Complexity: +// - Time: O(v1 + e1 + v2 + e2) +// - Sapce: O(v1 + v2) +// where vi = # of states visited and ei = # of arcs visited of the +// ith FST. Constant time and space to visit an input state or arc +// is assumed and exclusive of caching. +template +class UnionFst : public RationalFst { + public: + using ImplToFst< RationalFstImpl >::GetImpl; + + typedef A Arc; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + + UnionFst(const Fst &fst1, const Fst &fst2) { + GetImpl()->InitUnion(fst1, fst2); + } + + UnionFst(const Fst &fst1, const Fst &fst2, const UnionFstOptions &opts) + : RationalFst(opts) { + GetImpl()->InitUnion(fst1, fst2); + } + + // See Fst<>::Copy() for doc. + UnionFst(const UnionFst &fst, bool safe = false) + : RationalFst(fst, safe) {} + + // Get a copy of this UnionFst. See Fst<>::Copy() for further doc. + virtual UnionFst *Copy(bool safe = false) const { + return new UnionFst(*this, safe); + } +}; + + +// Specialization for UnionFst. +template +class StateIterator< UnionFst > : public StateIterator< RationalFst > { + public: + explicit StateIterator(const UnionFst &fst) + : StateIterator< RationalFst >(fst) {} +}; + + +// Specialization for UnionFst. +template +class ArcIterator< UnionFst > : public ArcIterator< RationalFst > { + public: + typedef typename A::StateId StateId; + + ArcIterator(const UnionFst &fst, StateId s) + : ArcIterator< RationalFst >(fst, s) {} +}; + + +// Useful alias when using StdArc. +typedef UnionFst StdUnionFst; + +} // namespace fst + +#endif // FST_LIB_UNION_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/util.h b/kaldi_io/src/tools/openfst/include/fst/util.h new file mode 100644 index 0000000..57d7c4b --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/util.h @@ -0,0 +1,437 @@ +// util.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// FST utility inline definitions. + +#ifndef FST_LIB_UTIL_H__ +#define FST_LIB_UTIL_H__ + +#include +using std::tr1::unordered_map; +using std::tr1::unordered_multimap; +#include +using std::tr1::unordered_set; +using std::tr1::unordered_multiset; +#include +#include +#include +#include +#include +#include +using std::vector; + + +#include +#include + +#include +#include +#include + +// +// UTILITY FOR ERROR HANDLING +// + +DECLARE_bool(fst_error_fatal); + +#define FSTERROR() (FLAGS_fst_error_fatal ? LOG(FATAL) : LOG(ERROR)) + +namespace fst { + +// +// UTILITIES FOR TYPE I/O +// + +// Read some types from an input stream. + +// Generic case. +template +inline istream &ReadType(istream &strm, T *t) { + return t->Read(strm); +} + +// Fixed size, contiguous memory read. +#define READ_POD_TYPE(T) \ +inline istream &ReadType(istream &strm, T *t) { \ + return strm.read(reinterpret_cast(t), sizeof(T)); \ +} + +READ_POD_TYPE(bool); +READ_POD_TYPE(char); +READ_POD_TYPE(signed char); +READ_POD_TYPE(unsigned char); +READ_POD_TYPE(short); +READ_POD_TYPE(unsigned short); +READ_POD_TYPE(int); +READ_POD_TYPE(unsigned int); +READ_POD_TYPE(long); +READ_POD_TYPE(unsigned long); +READ_POD_TYPE(long long); +READ_POD_TYPE(unsigned long long); +READ_POD_TYPE(float); +READ_POD_TYPE(double); + +// String case. +inline istream &ReadType(istream &strm, string *s) { + s->clear(); + int32 ns = 0; + strm.read(reinterpret_cast(&ns), sizeof(ns)); + for (int i = 0; i < ns; ++i) { + char c; + strm.read(&c, 1); + *s += c; + } + return strm; +} + +// Pair case. +template +inline istream &ReadType(istream &strm, pair *p) { + ReadType(strm, &p->first); + ReadType(strm, &p->second); + return strm; +} + +template +inline istream &ReadType(istream &strm, pair *p) { + ReadType(strm, const_cast(&p->first)); + ReadType(strm, &p->second); + return strm; +} + +// General case - no-op. +template +void StlReserve(C *c, int64 n) {} + +// Specialization for vectors. +template +void StlReserve(vector *c, int64 n) { + c->reserve(n); +} + +// STL sequence container. +#define READ_STL_SEQ_TYPE(C) \ +template \ +inline istream &ReadType(istream &strm, C *c) { \ + c->clear(); \ + int64 n = 0; \ + strm.read(reinterpret_cast(&n), sizeof(n)); \ + StlReserve(c, n); \ + for (ssize_t i = 0; i < n; ++i) { \ + typename C::value_type value; \ + ReadType(strm, &value); \ + c->insert(c->end(), value); \ + } \ + return strm; \ +} + +READ_STL_SEQ_TYPE(vector); +READ_STL_SEQ_TYPE(list); + +// STL associative container. +#define READ_STL_ASSOC_TYPE(C) \ +template \ +inline istream &ReadType(istream &strm, C *c) { \ + c->clear(); \ + int64 n = 0; \ + strm.read(reinterpret_cast(&n), sizeof(n)); \ + for (ssize_t i = 0; i < n; ++i) { \ + typename C::value_type value; \ + ReadType(strm, &value); \ + c->insert(value); \ + } \ + return strm; \ +} + +READ_STL_ASSOC_TYPE(set); +READ_STL_ASSOC_TYPE(unordered_set); +READ_STL_ASSOC_TYPE(map); +READ_STL_ASSOC_TYPE(unordered_map); + +// Write some types to an output stream. + +// Generic case. +template +inline ostream &WriteType(ostream &strm, const T t) { + t.Write(strm); + return strm; +} + +// Fixed size, contiguous memory write. +#define WRITE_POD_TYPE(T) \ +inline ostream &WriteType(ostream &strm, const T t) { \ + return strm.write(reinterpret_cast(&t), sizeof(T)); \ +} + +WRITE_POD_TYPE(bool); +WRITE_POD_TYPE(char); +WRITE_POD_TYPE(signed char); +WRITE_POD_TYPE(unsigned char); +WRITE_POD_TYPE(short); +WRITE_POD_TYPE(unsigned short); +WRITE_POD_TYPE(int); +WRITE_POD_TYPE(unsigned int); +WRITE_POD_TYPE(long); +WRITE_POD_TYPE(unsigned long); +WRITE_POD_TYPE(long long); +WRITE_POD_TYPE(unsigned long long); +WRITE_POD_TYPE(float); +WRITE_POD_TYPE(double); + +// String case. +inline ostream &WriteType(ostream &strm, const string &s) { + int32 ns = s.size(); + strm.write(reinterpret_cast(&ns), sizeof(ns)); + return strm.write(s.data(), ns); +} + +// Pair case. +template +inline ostream &WriteType(ostream &strm, const pair &p) { + WriteType(strm, p.first); + WriteType(strm, p.second); + return strm; +} + +// STL sequence container. +#define WRITE_STL_SEQ_TYPE(C) \ +template \ +inline ostream &WriteType(ostream &strm, const C &c) { \ + int64 n = c.size(); \ + strm.write(reinterpret_cast(&n), sizeof(n)); \ + for (typename C::const_iterator it = c.begin(); \ + it != c.end(); ++it) \ + WriteType(strm, *it); \ + return strm; \ +} + +WRITE_STL_SEQ_TYPE(vector); +WRITE_STL_SEQ_TYPE(list); + +// STL associative container. +#define WRITE_STL_ASSOC_TYPE(C) \ +template \ +inline ostream &WriteType(ostream &strm, const C &c) { \ + int64 n = c.size(); \ + strm.write(reinterpret_cast(&n), sizeof(n)); \ + for (typename C::const_iterator it = c.begin(); \ + it != c.end(); ++it) \ + WriteType(strm, *it); \ + return strm; \ +} + +WRITE_STL_ASSOC_TYPE(set); +WRITE_STL_ASSOC_TYPE(unordered_set); +WRITE_STL_ASSOC_TYPE(map); +WRITE_STL_ASSOC_TYPE(unordered_map); + +// Utilities for converting between int64 or Weight and string. + +int64 StrToInt64(const string &s, const string &src, size_t nline, + bool allow_negative, bool *error = 0); + +template +Weight StrToWeight(const string &s, const string &src, size_t nline) { + Weight w; + istringstream strm(s); + strm >> w; + if (!strm) { + FSTERROR() << "StrToWeight: Bad weight = \"" << s + << "\", source = " << src << ", line = " << nline; + return Weight::NoWeight(); + } + return w; +} + +void Int64ToStr(int64 n, string *s); + +template +void WeightToStr(Weight w, string *s) { + ostringstream strm; + strm.precision(9); + strm << w; + s->append(strm.str().data(), strm.str().size()); +} + +// Utilities for reading/writing label pairs + +// Returns true on success +template +bool ReadLabelPairs(const string& filename, + vector >* pairs, + bool allow_negative = false) { + ifstream strm(filename.c_str()); + + if (!strm) { + LOG(ERROR) << "ReadLabelPairs: Can't open file: " << filename; + return false; + } + + const int kLineLen = 8096; + char line[kLineLen]; + size_t nline = 0; + + pairs->clear(); + while (strm.getline(line, kLineLen)) { + ++nline; + vector col; + SplitToVector(line, "\n\t ", &col, true); + if (col.size() == 0 || col[0][0] == '\0') // empty line + continue; + if (col.size() != 2) { + LOG(ERROR) << "ReadLabelPairs: Bad number of columns, " + << "file = " << filename << ", line = " << nline; + return false; + } + + bool err; + Label frmlabel = StrToInt64(col[0], filename, nline, allow_negative, &err); + if (err) return false; + Label tolabel = StrToInt64(col[1], filename, nline, allow_negative, &err); + if (err) return false; + pairs->push_back(make_pair(frmlabel, tolabel)); + } + return true; +} + +// Returns true on success +template +bool WriteLabelPairs(const string& filename, + const vector >& pairs) { + ostream *strm = &cout; + if (!filename.empty()) { + strm = new ofstream(filename.c_str()); + if (!*strm) { + LOG(ERROR) << "WriteLabelPairs: Can't open file: " << filename; + return false; + } + } + + for (ssize_t n = 0; n < pairs.size(); ++n) + *strm << pairs[n].first << "\t" << pairs[n].second << "\n"; + + if (!*strm) { + LOG(ERROR) << "WriteLabelPairs: Write failed: " + << (filename.empty() ? "standard output" : filename); + return false; + } + if (strm != &cout) + delete strm; + return true; +} + +// Utilities for converting a type name to a legal C symbol. + +void ConvertToLegalCSymbol(string *s); + + +// +// UTILITIES FOR STREAM I/O +// + +bool AlignInput(istream &strm); +bool AlignOutput(ostream &strm); + +// +// UTILITIES FOR PROTOCOL BUFFER I/O +// + + +// An associative container for which testing membership is +// faster than an STL set if members are restricted to an interval +// that excludes most non-members. A 'Key' must have ==, !=, and < defined. +// Element 'NoKey' should be a key that marks an uninitialized key and +// is otherwise unused. 'Find()' returns an STL const_iterator to the match +// found, otherwise it equals 'End()'. +template +class CompactSet { +public: + typedef typename set::const_iterator const_iterator; + + CompactSet() + : min_key_(NoKey), + max_key_(NoKey) { } + + CompactSet(const CompactSet &compact_set) + : set_(compact_set.set_), + min_key_(compact_set.min_key_), + max_key_(compact_set.max_key_) { } + + void Insert(Key key) { + set_.insert(key); + if (min_key_ == NoKey || key < min_key_) + min_key_ = key; + if (max_key_ == NoKey || max_key_ < key) + max_key_ = key; + } + + void Erase(Key key) { + set_.erase(key); + if (set_.empty()) { + min_key_ = max_key_ = NoKey; + } else if (key == min_key_) { + ++min_key_; + } else if (key == max_key_) { + --max_key_; + } + } + + void Clear() { + set_.clear(); + min_key_ = max_key_ = NoKey; + } + + const_iterator Find(Key key) const { + if (min_key_ == NoKey || + key < min_key_ || max_key_ < key) + return set_.end(); + else + return set_.find(key); + } + + bool Member(Key key) const { + if (min_key_ == NoKey || key < min_key_ || max_key_ < key) { + return false; // out of range + } else if (min_key_ != NoKey && max_key_ + 1 == min_key_ + set_.size()) { + return true; // dense range + } else { + return set_.find(key) != set_.end(); + } + } + + const_iterator Begin() const { return set_.begin(); } + + const_iterator End() const { return set_.end(); } + + // All stored keys are greater than or equal to this value. + Key LowerBound() const { return min_key_; } + + // All stored keys are less than or equal to this value. + Key UpperBound() const { return max_key_; } + +private: + set set_; + Key min_key_; + Key max_key_; + + void operator=(const CompactSet &); //disallow +}; + +} // namespace fst + +#endif // FST_LIB_UTIL_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/vector-fst.h b/kaldi_io/src/tools/openfst/include/fst/vector-fst.h new file mode 100644 index 0000000..8b80876 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/vector-fst.h @@ -0,0 +1,731 @@ +// vector-fst.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Simple concrete, mutable FST whose states and arcs are stored in STL +// vectors. + +#ifndef FST_LIB_VECTOR_FST_H__ +#define FST_LIB_VECTOR_FST_H__ + +#include +#include +using std::vector; + +#include +#include + + +namespace fst { + +template class VectorFst; +template void Cast(const F &, G *); + + +// States and arcs implemented by STL vectors, templated on the +// State definition. This does not manage the Fst properties. +template +class VectorFstBaseImpl : public FstImpl { + public: + typedef typename State::Arc Arc; + typedef typename Arc::Weight Weight; + typedef typename Arc::StateId StateId; + + VectorFstBaseImpl() : start_(kNoStateId) {} + + ~VectorFstBaseImpl() { + for (StateId s = 0; s < states_.size(); ++s) + delete states_[s]; + } + + StateId Start() const { return start_; } + + Weight Final(StateId s) const { return states_[s]->final; } + + StateId NumStates() const { return states_.size(); } + + size_t NumArcs(StateId s) const { return states_[s]->arcs.size(); } + + void SetStart(StateId s) { start_ = s; } + + void SetFinal(StateId s, Weight w) { states_[s]->final = w; } + + StateId AddState() { + states_.push_back(new State); + return states_.size() - 1; + } + + StateId AddState(State *state) { + states_.push_back(state); + return states_.size() - 1; + } + + void AddArc(StateId s, const Arc &arc) { + states_[s]->arcs.push_back(arc); + } + + void DeleteStates(const vector& dstates) { + vector newid(states_.size(), 0); + for (size_t i = 0; i < dstates.size(); ++i) + newid[dstates[i]] = kNoStateId; + StateId nstates = 0; + for (StateId s = 0; s < states_.size(); ++s) { + if (newid[s] != kNoStateId) { + newid[s] = nstates; + if (s != nstates) + states_[nstates] = states_[s]; + ++nstates; + } else { + delete states_[s]; + } + } + states_.resize(nstates); + for (StateId s = 0; s < states_.size(); ++s) { + vector &arcs = states_[s]->arcs; + size_t narcs = 0; + for (size_t i = 0; i < arcs.size(); ++i) { + StateId t = newid[arcs[i].nextstate]; + if (t != kNoStateId) { + arcs[i].nextstate = t; + if (i != narcs) + arcs[narcs] = arcs[i]; + ++narcs; + } else { + if (arcs[i].ilabel == 0) + --states_[s]->niepsilons; + if (arcs[i].olabel == 0) + --states_[s]->noepsilons; + } + } + arcs.resize(narcs); + } + if (Start() != kNoStateId) + SetStart(newid[Start()]); + } + + void DeleteStates() { + for (StateId s = 0; s < states_.size(); ++s) + delete states_[s]; + states_.clear(); + SetStart(kNoStateId); + } + + void DeleteArcs(StateId s, size_t n) { + states_[s]->arcs.resize(states_[s]->arcs.size() - n); + } + + void DeleteArcs(StateId s) { states_[s]->arcs.clear(); } + + State *GetState(StateId s) { return states_[s]; } + + const State *GetState(StateId s) const { return states_[s]; } + + void SetState(StateId s, State *state) { states_[s] = state; } + + void ReserveStates(StateId n) { states_.reserve(n); } + + void ReserveArcs(StateId s, size_t n) { states_[s]->arcs.reserve(n); } + + // Provide information needed for generic state iterator + void InitStateIterator(StateIteratorData *data) const { + data->base = 0; + data->nstates = states_.size(); + } + + // Provide information needed for generic arc iterator + void InitArcIterator(StateId s, ArcIteratorData *data) const { + data->base = 0; + data->narcs = states_[s]->arcs.size(); + data->arcs = data->narcs > 0 ? &states_[s]->arcs[0] : 0; + data->ref_count = 0; + } + + private: + vector states_; // States represenation. + StateId start_; // initial state + + DISALLOW_COPY_AND_ASSIGN(VectorFstBaseImpl); +}; + +// Arcs implemented by an STL vector per state. +template +struct VectorState { + typedef A Arc; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + + VectorState() : final(Weight::Zero()), niepsilons(0), noepsilons(0) {} + + Weight final; // Final weight + vector arcs; // Arcs represenation + size_t niepsilons; // # of input epsilons + size_t noepsilons; // # of output epsilons +}; + +// This is a VectorFstBaseImpl container that holds VectorState's. It +// manages Fst properties and the # of input and output epsilons. +template +class VectorFstImpl : public VectorFstBaseImpl< VectorState > { + public: + using FstImpl::SetInputSymbols; + using FstImpl::SetOutputSymbols; + using FstImpl::SetType; + using FstImpl::SetProperties; + using FstImpl::Properties; + + using VectorFstBaseImpl >::Start; + using VectorFstBaseImpl >::NumStates; + using VectorFstBaseImpl >::GetState; + using VectorFstBaseImpl >::ReserveArcs; + + friend class MutableArcIterator< VectorFst >; + + typedef VectorFstBaseImpl< VectorState > BaseImpl; + typedef typename A::Weight Weight; + typedef typename A::StateId StateId; + + VectorFstImpl() { + SetType("vector"); + SetProperties(kNullProperties | kStaticProperties); + } + explicit VectorFstImpl(const Fst &fst); + + static VectorFstImpl *Read(istream &strm, const FstReadOptions &opts); + + size_t NumInputEpsilons(StateId s) const { return GetState(s)->niepsilons; } + + size_t NumOutputEpsilons(StateId s) const { return GetState(s)->noepsilons; } + + void SetStart(StateId s) { + BaseImpl::SetStart(s); + SetProperties(SetStartProperties(Properties())); + } + + void SetFinal(StateId s, Weight w) { + Weight ow = BaseImpl::Final(s); + BaseImpl::SetFinal(s, w); + SetProperties(SetFinalProperties(Properties(), ow, w)); + } + + StateId AddState() { + StateId s = BaseImpl::AddState(); + SetProperties(AddStateProperties(Properties())); + return s; + } + + void AddArc(StateId s, const A &arc) { + VectorState *state = GetState(s); + if (arc.ilabel == 0) { + ++state->niepsilons; + } + if (arc.olabel == 0) { + ++state->noepsilons; + } + + const A *parc = state->arcs.empty() ? 0 : &(state->arcs.back()); + SetProperties(AddArcProperties(Properties(), s, arc, parc)); + + BaseImpl::AddArc(s, arc); + } + + void DeleteStates(const vector &dstates) { + BaseImpl::DeleteStates(dstates); + SetProperties(DeleteStatesProperties(Properties())); + } + + void DeleteStates() { + BaseImpl::DeleteStates(); + SetProperties(DeleteAllStatesProperties(Properties(), + kStaticProperties)); + } + + void DeleteArcs(StateId s, size_t n) { + const vector &arcs = GetState(s)->arcs; + for (size_t i = 0; i < n; ++i) { + size_t j = arcs.size() - i - 1; + if (arcs[j].ilabel == 0) + --GetState(s)->niepsilons; + if (arcs[j].olabel == 0) + --GetState(s)->noepsilons; + } + BaseImpl::DeleteArcs(s, n); + SetProperties(DeleteArcsProperties(Properties())); + } + + void DeleteArcs(StateId s) { + GetState(s)->niepsilons = 0; + GetState(s)->noepsilons = 0; + BaseImpl::DeleteArcs(s); + SetProperties(DeleteArcsProperties(Properties())); + } + + // Properties always true of this Fst class + static const uint64 kStaticProperties = kExpanded | kMutable; + + private: + // Current file format version + static const int kFileVersion = 2; + // Minimum file format version supported + static const int kMinFileVersion = 1; + + DISALLOW_COPY_AND_ASSIGN(VectorFstImpl); +}; + +template const uint64 VectorFstImpl::kStaticProperties; +template const int VectorFstImpl::kFileVersion; +template const int VectorFstImpl::kMinFileVersion; + + +template +VectorFstImpl::VectorFstImpl(const Fst &fst) { + SetType("vector"); + SetInputSymbols(fst.InputSymbols()); + SetOutputSymbols(fst.OutputSymbols()); + BaseImpl::SetStart(fst.Start()); + if (fst.Properties(kExpanded, false)) + BaseImpl::ReserveStates(CountStates(fst)); + + for (StateIterator< Fst > siter(fst); + !siter.Done(); + siter.Next()) { + StateId s = siter.Value(); + BaseImpl::AddState(); + BaseImpl::SetFinal(s, fst.Final(s)); + ReserveArcs(s, fst.NumArcs(s)); + for (ArcIterator< Fst > aiter(fst, s); + !aiter.Done(); + aiter.Next()) { + const A &arc = aiter.Value(); + BaseImpl::AddArc(s, arc); + if (arc.ilabel == 0) + ++GetState(s)->niepsilons; + if (arc.olabel == 0) + ++GetState(s)->noepsilons; + } + } + SetProperties(fst.Properties(kCopyProperties, false) | kStaticProperties); +} + +template +VectorFstImpl *VectorFstImpl::Read(istream &strm, + const FstReadOptions &opts) { + VectorFstImpl *impl = new VectorFstImpl; + FstHeader hdr; + if (!impl->ReadHeader(strm, opts, kMinFileVersion, &hdr)) { + delete impl; + return 0; + } + impl->BaseImpl::SetStart(hdr.Start()); + if (hdr.NumStates() != kNoStateId) { + impl->ReserveStates(hdr.NumStates()); + } + + StateId s = 0; + for (;hdr.NumStates() == kNoStateId || s < hdr.NumStates(); ++s) { + typename A::Weight final; + if (!final.Read(strm)) break; + impl->BaseImpl::AddState(); + VectorState *state = impl->GetState(s); + state->final = final; + int64 narcs; + ReadType(strm, &narcs); + if (!strm) { + LOG(ERROR) << "VectorFst::Read: read failed: " << opts.source; + delete impl; + return 0; + } + impl->ReserveArcs(s, narcs); + for (size_t j = 0; j < narcs; ++j) { + A arc; + ReadType(strm, &arc.ilabel); + ReadType(strm, &arc.olabel); + arc.weight.Read(strm); + ReadType(strm, &arc.nextstate); + if (!strm) { + LOG(ERROR) << "VectorFst::Read: read failed: " << opts.source; + delete impl; + return 0; + } + impl->BaseImpl::AddArc(s, arc); + if (arc.ilabel == 0) + ++state->niepsilons; + if (arc.olabel == 0) + ++state->noepsilons; + } + } + if (hdr.NumStates() != kNoStateId && s != hdr.NumStates()) { + LOG(ERROR) << "VectorFst::Read: unexpected end of file: " << opts.source; + delete impl; + return 0; + } + return impl; +} + +// Converts a string into a weight. +template class WeightFromString { + public: + W operator()(const string &s); +}; + +// Generic case fails. +template inline +W WeightFromString::operator()(const string &s) { + FSTERROR() << "VectorFst::Read: Obsolete file format"; + return W::NoWeight(); +} + +// TropicalWeight version. +template <> inline +TropicalWeight WeightFromString::operator()(const string &s) { + float f; + memcpy(&f, s.data(), sizeof(f)); + return TropicalWeight(f); +} + +// LogWeight version. +template <> inline +LogWeight WeightFromString::operator()(const string &s) { + float f; + memcpy(&f, s.data(), sizeof(f)); + return LogWeight(f); +} + +// Simple concrete, mutable FST. This class attaches interface to +// implementation and handles reference counting, delegating most +// methods to ImplToMutableFst. Supports additional operations: +// ReserveStates and ReserveArcs (cf. STL vectors). +template +class VectorFst : public ImplToMutableFst< VectorFstImpl > { + public: + friend class StateIterator< VectorFst >; + friend class ArcIterator< VectorFst >; + friend class MutableArcIterator< VectorFst >; + template friend void Cast(const F &, G *); + + typedef A Arc; + typedef typename A::StateId StateId; + typedef VectorFstImpl Impl; + + VectorFst() : ImplToMutableFst(new Impl) {} + + explicit VectorFst(const Fst &fst) + : ImplToMutableFst(new Impl(fst)) {} + + VectorFst(const VectorFst &fst) : ImplToMutableFst(fst) {} + + // Get a copy of this VectorFst. See Fst<>::Copy() for further doc. + virtual VectorFst *Copy(bool safe = false) const { + return new VectorFst(*this); + } + + VectorFst &operator=(const VectorFst &fst) { + SetImpl(fst.GetImpl(), false); + return *this; + } + + virtual VectorFst &operator=(const Fst &fst) { + if (this != &fst) SetImpl(new Impl(fst)); + return *this; + } + + // Read a VectorFst from an input stream; return NULL on error + static VectorFst *Read(istream &strm, const FstReadOptions &opts) { + Impl* impl = Impl::Read(strm, opts); + return impl ? new VectorFst(impl) : 0; + } + + // Read a VectorFst from a file; return NULL on error + // Empty filename reads from standard input + static VectorFst *Read(const string &filename) { + Impl* impl = ImplToExpandedFst >::Read(filename); + return impl ? new VectorFst(impl) : 0; + } + + virtual bool Write(ostream &strm, const FstWriteOptions &opts) const { + return WriteFst(*this, strm, opts); + } + + virtual bool Write(const string &filename) const { + return Fst::WriteFile(filename); + } + + template + static bool WriteFst(const F &fst, ostream &strm, + const FstWriteOptions &opts); + + void ReserveStates(StateId n) { + MutateCheck(); + GetImpl()->ReserveStates(n); + } + + void ReserveArcs(StateId s, size_t n) { + MutateCheck(); + GetImpl()->ReserveArcs(s, n); + } + + virtual void InitStateIterator(StateIteratorData *data) const { + GetImpl()->InitStateIterator(data); + } + + virtual void InitArcIterator(StateId s, ArcIteratorData *data) const { + GetImpl()->InitArcIterator(s, data); + } + + virtual inline + void InitMutableArcIterator(StateId s, MutableArcIteratorData *); + + private: + explicit VectorFst(Impl *impl) : ImplToMutableFst(impl) {} + + // Makes visible to friends. + Impl *GetImpl() const { return ImplToFst< Impl, MutableFst >::GetImpl(); } + + void SetImpl(Impl *impl, bool own_impl = true) { + ImplToFst< Impl, MutableFst >::SetImpl(impl, own_impl); + } + + void MutateCheck() { return ImplToMutableFst::MutateCheck(); } +}; + +// Specialization for VectorFst; see generic version in fst.h +// for sample usage (but use the VectorFst type!). This version +// should inline. +template +class StateIterator< VectorFst > { + public: + typedef typename A::StateId StateId; + + explicit StateIterator(const VectorFst &fst) + : nstates_(fst.GetImpl()->NumStates()), s_(0) {} + + bool Done() const { return s_ >= nstates_; } + + StateId Value() const { return s_; } + + void Next() { ++s_; } + + void Reset() { s_ = 0; } + + private: + StateId nstates_; + StateId s_; + + DISALLOW_COPY_AND_ASSIGN(StateIterator); +}; + +// Writes Fst to file, will call CountStates so may involve two passes if +// called from an Fst that is not derived from Expanded. +template +template +bool VectorFst::WriteFst(const F &fst, ostream &strm, + const FstWriteOptions &opts) { + static const int kFileVersion = 2; + bool update_header = true; + FstHeader hdr; + hdr.SetStart(fst.Start()); + hdr.SetNumStates(kNoStateId); + size_t start_offset = 0; + if (fst.Properties(kExpanded, false) || (start_offset = strm.tellp()) != -1) { + hdr.SetNumStates(CountStates(fst)); + update_header = false; + } + uint64 properties = fst.Properties(kCopyProperties, false) | + VectorFstImpl::kStaticProperties; + FstImpl::WriteFstHeader(fst, strm, opts, kFileVersion, "vector", + properties, &hdr); + StateId num_states = 0; + for (StateIterator siter(fst); !siter.Done(); siter.Next()) { + typename A::StateId s = siter.Value(); + fst.Final(s).Write(strm); + int64 narcs = fst.NumArcs(s); + WriteType(strm, narcs); + for (ArcIterator aiter(fst, s); !aiter.Done(); aiter.Next()) { + const A &arc = aiter.Value(); + WriteType(strm, arc.ilabel); + WriteType(strm, arc.olabel); + arc.weight.Write(strm); + WriteType(strm, arc.nextstate); + } + num_states++; + } + strm.flush(); + if (!strm) { + LOG(ERROR) << "VectorFst::Write: write failed: " << opts.source; + return false; + } + if (update_header) { + hdr.SetNumStates(num_states); + return FstImpl::UpdateFstHeader(fst, strm, opts, kFileVersion, "vector", + properties, &hdr, start_offset); + } else { + if (num_states != hdr.NumStates()) { + LOG(ERROR) << "Inconsistent number of states observed during write"; + return false; + } + } + return true; +} + +// Specialization for VectorFst; see generic version in fst.h +// for sample usage (but use the VectorFst type!). This version +// should inline. +template +class ArcIterator< VectorFst > { + public: + typedef typename A::StateId StateId; + + ArcIterator(const VectorFst &fst, StateId s) + : arcs_(fst.GetImpl()->GetState(s)->arcs), i_(0) {} + + bool Done() const { return i_ >= arcs_.size(); } + + const A& Value() const { return arcs_[i_]; } + + void Next() { ++i_; } + + void Reset() { i_ = 0; } + + void Seek(size_t a) { i_ = a; } + + size_t Position() const { return i_; } + + uint32 Flags() const { + return kArcValueFlags; + } + + void SetFlags(uint32 f, uint32 m) {} + + private: + const vector& arcs_; + size_t i_; + + DISALLOW_COPY_AND_ASSIGN(ArcIterator); +}; + +// Specialization for VectorFst; see generic version in fst.h +// for sample usage (but use the VectorFst type!). This version +// should inline. +template +class MutableArcIterator< VectorFst > + : public MutableArcIteratorBase { + public: + typedef typename A::StateId StateId; + typedef typename A::Weight Weight; + + MutableArcIterator(VectorFst *fst, StateId s) : i_(0) { + fst->MutateCheck(); + state_ = fst->GetImpl()->GetState(s); + properties_ = &fst->GetImpl()->properties_; + } + + bool Done() const { return i_ >= state_->arcs.size(); } + + const A& Value() const { return state_->arcs[i_]; } + + void Next() { ++i_; } + + size_t Position() const { return i_; } + + void Reset() { i_ = 0; } + + void Seek(size_t a) { i_ = a; } + + void SetValue(const A &arc) { + A& oarc = state_->arcs[i_]; + if (oarc.ilabel != oarc.olabel) + *properties_ &= ~kNotAcceptor; + if (oarc.ilabel == 0) { + --state_->niepsilons; + *properties_ &= ~kIEpsilons; + if (oarc.olabel == 0) + *properties_ &= ~kEpsilons; + } + if (oarc.olabel == 0) { + --state_->noepsilons; + *properties_ &= ~kOEpsilons; + } + if (oarc.weight != Weight::Zero() && oarc.weight != Weight::One()) + *properties_ &= ~kWeighted; + oarc = arc; + if (arc.ilabel != arc.olabel) { + *properties_ |= kNotAcceptor; + *properties_ &= ~kAcceptor; + } + if (arc.ilabel == 0) { + ++state_->niepsilons; + *properties_ |= kIEpsilons; + *properties_ &= ~kNoIEpsilons; + if (arc.olabel == 0) { + *properties_ |= kEpsilons; + *properties_ &= ~kNoEpsilons; + } + } + if (arc.olabel == 0) { + ++state_->noepsilons; + *properties_ |= kOEpsilons; + *properties_ &= ~kNoOEpsilons; + } + if (arc.weight != Weight::Zero() && arc.weight != Weight::One()) { + *properties_ |= kWeighted; + *properties_ &= ~kUnweighted; + } + *properties_ &= kSetArcProperties | kAcceptor | kNotAcceptor | + kEpsilons | kNoEpsilons | kIEpsilons | kNoIEpsilons | + kOEpsilons | kNoOEpsilons | kWeighted | kUnweighted; + } + + uint32 Flags() const { + return kArcValueFlags; + } + + void SetFlags(uint32 f, uint32 m) {} + + + private: + // This allows base-class virtual access to non-virtual derived- + // class members of the same name. It makes the derived class more + // efficient to use but unsafe to further derive. + virtual bool Done_() const { return Done(); } + virtual const A& Value_() const { return Value(); } + virtual void Next_() { Next(); } + virtual size_t Position_() const { return Position(); } + virtual void Reset_() { Reset(); } + virtual void Seek_(size_t a) { Seek(a); } + virtual void SetValue_(const A &a) { SetValue(a); } + uint32 Flags_() const { return Flags(); } + void SetFlags_(uint32 f, uint32 m) { SetFlags(f, m); } + + struct VectorState *state_; + uint64 *properties_; + size_t i_; + + DISALLOW_COPY_AND_ASSIGN(MutableArcIterator); +}; + +// Provide information needed for the generic mutable arc iterator +template inline +void VectorFst::InitMutableArcIterator( + StateId s, MutableArcIteratorData *data) { + data->base = new MutableArcIterator< VectorFst >(this, s); +} + +// A useful alias when using StdArc. +typedef VectorFst StdVectorFst; + +} // namespace fst + +#endif // FST_LIB_VECTOR_FST_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/verify.h b/kaldi_io/src/tools/openfst/include/fst/verify.h new file mode 100644 index 0000000..576cfca --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/verify.h @@ -0,0 +1,126 @@ +// verify.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Function to verify an Fst's contents + +#ifndef FST_LIB_VERIFY_H__ +#define FST_LIB_VERIFY_H__ + +#include +#include + + +namespace fst { + +// Verifies that an Fst's contents are sane. +template +bool Verify(const Fst &fst, bool allow_negative_labels = false) { + typedef typename Arc::Label Label; + typedef typename Arc::Weight Weight; + typedef typename Arc::StateId StateId; + + StateId start = fst.Start(); + const SymbolTable *isyms = fst.InputSymbols(); + const SymbolTable *osyms = fst.OutputSymbols(); + + // Count states + StateId ns = 0; + for (StateIterator< Fst > siter(fst); + !siter.Done(); + siter.Next()) + ++ns; + + if (start == kNoStateId && ns > 0) { + LOG(ERROR) << "Verify: Fst start state ID unset"; + return false; + } else if (start >= ns) { + LOG(ERROR) << "Verify: Fst start state ID exceeds number of states"; + return false; + } + + for (StateIterator< Fst > siter(fst); + !siter.Done(); + siter.Next()) { + StateId s = siter.Value(); + size_t na = 0; + for (ArcIterator< Fst > aiter(fst, s); + !aiter.Done(); + aiter.Next()) { + const Arc &arc =aiter.Value(); + if (!allow_negative_labels && arc.ilabel < 0) { + LOG(ERROR) << "Verify: Fst input label ID of arc at position " + << na << " of state " << s << " is negative"; + return false; + } else if (isyms && isyms->Find(arc.ilabel) == "") { + LOG(ERROR) << "Verify: Fst input label ID " << arc.ilabel + << " of arc at position " << na << " of state " << s + << " is missing from input symbol table \"" + << isyms->Name() << "\""; + return false; + } else if (!allow_negative_labels && arc.olabel < 0) { + LOG(ERROR) << "Verify: Fst output label ID of arc at position " + << na << " of state " << s << " is negative"; + return false; + } else if (osyms && osyms->Find(arc.olabel) == "") { + LOG(ERROR) << "Verify: Fst output label ID " << arc.olabel + << " of arc at position " << na << " of state " << s + << " is missing from output symbol table \"" + << osyms->Name() << "\""; + return false; + } else if (!arc.weight.Member() || arc.weight == Weight::Zero()) { + LOG(ERROR) << "Verify: Fst weight of arc at position " + << na << " of state " << s << " is invalid"; + return false; + } else if (arc.nextstate < 0) { + LOG(ERROR) << "Verify: Fst destination state ID of arc at position " + << na << " of state " << s << " is negative"; + return false; + } else if (arc.nextstate >= ns) { + LOG(ERROR) << "Verify: Fst destination state ID of arc at position " + << na << " of state " << s + << " exceeds number of states"; + return false; + } + ++na; + } + if (!fst.Final(s).Member()) { + LOG(ERROR) << "Verify: Fst final weight of state " << s << " is invalid"; + return false; + } + } + uint64 fst_props = fst.Properties(kFstProperties, false); + if (fst_props & kError) { + LOG(ERROR) << "Verify: Fst error property is set"; + return false; + } + + uint64 known_props; + uint64 test_props = ComputeProperties(fst, kFstProperties, &known_props, + false); + if (!CompatProperties(fst_props, test_props)) { + LOG(ERROR) << "Verify: stored Fst properties incorrect " + << "(props1 = stored props, props2 = tested)"; + return false; + } else { + return true; + } +} + +} // namespace fst + +#endif // FST_LIB_VERIFY_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/visit.h b/kaldi_io/src/tools/openfst/include/fst/visit.h new file mode 100644 index 0000000..5f5059a --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/visit.h @@ -0,0 +1,284 @@ +// visit.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// Queue-dependent visitation of finite-state transducers. See also +// dfs-visit.h. + +#ifndef FST_LIB_VISIT_H__ +#define FST_LIB_VISIT_H__ + + +#include +#include + + +namespace fst { + +// Visitor Interface - class determines actions taken during a visit. +// If any of the boolean member functions return false, the visit is +// aborted by first calling FinishState() on all unfinished (grey) +// states and then calling FinishVisit(). +// +// Note this is more general than the visitor interface in +// dfs-visit.h but lacks some DFS-specific behavior. +// +// template +// class Visitor { +// public: +// typedef typename Arc::StateId StateId; +// +// Visitor(T *return_data); +// // Invoked before visit +// void InitVisit(const Fst &fst); +// // Invoked when state discovered (2nd arg is visitation root) +// bool InitState(StateId s, StateId root); +// // Invoked when arc to white/undiscovered state examined +// bool WhiteArc(StateId s, const Arc &a); +// // Invoked when arc to grey/unfinished state examined +// bool GreyArc(StateId s, const Arc &a); +// // Invoked when arc to black/finished state examined +// bool BlackArc(StateId s, const Arc &a); +// // Invoked when state finished. +// void FinishState(StateId s); +// // Invoked after visit +// void FinishVisit(); +// }; + +// Performs queue-dependent visitation. Visitor class argument +// determines actions and contains any return data. ArcFilter +// determines arcs that are considered. +// +// Note this is more general than DfsVisit() in dfs-visit.h but lacks +// some DFS-specific Visitor behavior. +template +void Visit(const Fst &fst, V *visitor, Q *queue, ArcFilter filter) { + + typedef typename Arc::StateId StateId; + typedef ArcIterator< Fst > AIterator; + + visitor->InitVisit(fst); + + StateId start = fst.Start(); + if (start == kNoStateId) { + visitor->FinishVisit(); + return; + } + + // An Fst state's visit color + const unsigned kWhiteState = 0x01; // Undiscovered + const unsigned kGreyState = 0x02; // Discovered & unfinished + const unsigned kBlackState = 0x04; // Finished + + // We destroy an iterator as soon as possible and mark it so + const unsigned kArcIterDone = 0x08; // Arc iterator done and destroyed + + vector state_status; + vector arc_iterator; + + StateId nstates = start + 1; // # of known states in general case + bool expanded = false; + if (fst.Properties(kExpanded, false)) { // tests if expanded case, then + nstates = CountStates(fst); // uses ExpandedFst::NumStates(). + expanded = true; + } + + state_status.resize(nstates, kWhiteState); + arc_iterator.resize(nstates); + StateIterator< Fst > siter(fst); + + // Continues visit while true + bool visit = true; + + // Iterates over trees in visit forest. + for (StateId root = start; visit && root < nstates;) { + visit = visitor->InitState(root, root); + state_status[root] = kGreyState; + queue->Enqueue(root); + while (!queue->Empty()) { + StateId s = queue->Head(); + if (s >= state_status.size()) { + nstates = s + 1; + state_status.resize(nstates, kWhiteState); + arc_iterator.resize(nstates); + } + // Creates arc iterator if needed. + if (arc_iterator[s] == 0 && !(state_status[s] & kArcIterDone) && visit) + arc_iterator[s] = new AIterator(fst, s); + // Deletes arc iterator if done. + AIterator *aiter = arc_iterator[s]; + if ((aiter && aiter->Done()) || !visit) { + delete aiter; + arc_iterator[s] = 0; + state_status[s] |= kArcIterDone; + } + // Dequeues state and marks black if done + if (state_status[s] & kArcIterDone) { + queue->Dequeue(); + visitor->FinishState(s); + state_status[s] = kBlackState; + continue; + } + + const Arc &arc = aiter->Value(); + if (arc.nextstate >= state_status.size()) { + nstates = arc.nextstate + 1; + state_status.resize(nstates, kWhiteState); + arc_iterator.resize(nstates); + } + // Visits respective arc types + if (filter(arc)) { + // Enqueues destination state and marks grey if white + if (state_status[arc.nextstate] == kWhiteState) { + visit = visitor->WhiteArc(s, arc); + if (!visit) continue; + visit = visitor->InitState(arc.nextstate, root); + state_status[arc.nextstate] = kGreyState; + queue->Enqueue(arc.nextstate); + } else if (state_status[arc.nextstate] == kBlackState) { + visit = visitor->BlackArc(s, arc); + } else { + visit = visitor->GreyArc(s, arc); + } + } + aiter->Next(); + // Destroys an iterator ASAP for efficiency. + if (aiter->Done()) { + delete aiter; + arc_iterator[s] = 0; + state_status[s] |= kArcIterDone; + } + } + // Finds next tree root + for (root = root == start ? 0 : root + 1; + root < nstates && state_status[root] != kWhiteState; + ++root) { + } + + // Check for a state beyond the largest known state + if (!expanded && root == nstates) { + for (; !siter.Done(); siter.Next()) { + if (siter.Value() == nstates) { + ++nstates; + state_status.push_back(kWhiteState); + arc_iterator.push_back(0); + break; + } + } + } + } + visitor->FinishVisit(); +} + + +template +inline void Visit(const Fst &fst, V *visitor, Q* queue) { + Visit(fst, visitor, queue, AnyArcFilter()); +} + +// Copies input FST to mutable FST following queue order. +template +class CopyVisitor { + public: + typedef A Arc; + typedef typename A::StateId StateId; + + CopyVisitor(MutableFst *ofst) : ifst_(0), ofst_(ofst) {} + + void InitVisit(const Fst &ifst) { + ifst_ = &ifst; + ofst_->DeleteStates(); + ofst_->SetStart(ifst_->Start()); + } + + bool InitState(StateId s, StateId) { + while (ofst_->NumStates() <= s) + ofst_->AddState(); + return true; + } + + bool WhiteArc(StateId s, const Arc &arc) { + ofst_->AddArc(s, arc); + return true; + } + + bool GreyArc(StateId s, const Arc &arc) { + ofst_->AddArc(s, arc); + return true; + } + + bool BlackArc(StateId s, const Arc &arc) { + ofst_->AddArc(s, arc); + return true; + } + + void FinishState(StateId s) { + ofst_->SetFinal(s, ifst_->Final(s)); + } + + void FinishVisit() {} + + private: + const Fst *ifst_; + MutableFst *ofst_; +}; + + +// Visits input FST up to a state limit following queue order. If +// 'access_only' is true, aborts on visiting first state not +// accessible from the initial state. +template +class PartialVisitor { + public: + typedef A Arc; + typedef typename A::StateId StateId; + + explicit PartialVisitor(StateId maxvisit, bool access_only = false) + : maxvisit_(maxvisit), + access_only_(access_only), + start_(kNoStateId) {} + + void InitVisit(const Fst &ifst) { + nvisit_ = 0; + start_ = ifst.Start(); + } + + bool InitState(StateId s, StateId root) { + if (access_only_ && root != start_) + return false; + ++nvisit_; + return nvisit_ <= maxvisit_; + } + + bool WhiteArc(StateId s, const Arc &arc) { return true; } + bool GreyArc(StateId s, const Arc &arc) { return true; } + bool BlackArc(StateId s, const Arc &arc) { return true; } + void FinishState(StateId s) {} + void FinishVisit() {} + + private: + StateId maxvisit_; + bool access_only_; + StateId nvisit_; + StateId start_; + +}; + + +} // namespace fst + +#endif // FST_LIB_VISIT_H__ diff --git a/kaldi_io/src/tools/openfst/include/fst/weight.h b/kaldi_io/src/tools/openfst/include/fst/weight.h new file mode 100644 index 0000000..7eb4bb1 --- /dev/null +++ b/kaldi_io/src/tools/openfst/include/fst/weight.h @@ -0,0 +1,179 @@ +// weight.h + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright 2005-2010 Google, Inc. +// Author: riley@google.com (Michael Riley) +// +// \file +// General weight set and associated semiring operation definitions. +// +// A semiring is specified by two binary operations Plus and Times and +// two designated elements Zero and One with the following properties: +// Plus: associative, commutative, and has Zero as its identity. +// Times: associative and has identity One, distributes w.r.t. Plus, and +// has Zero as an annihilator: +// Times(Zero(), a) == Times(a, Zero()) = Zero(). +// +// A left semiring distributes on the left; a right semiring is +// similarly defined. +// +// A Weight class must have binary functions =Plus= and =Times= and +// static member functions =Zero()= and =One()= and these must form +// (at least) a left or right semiring. +// +// In addition, the following should be defined for a Weight: +// Member: predicate on set membership. +// NoWeight: static member function that returns an element that is +// not a set member; used to signal an error. +// >>: reads textual representation of a weight. +// <<: prints textual representation of a weight. +// Read(istream &strm): reads binary representation of a weight. +// Write(ostream &strm): writes binary representation of a weight. +// Hash: maps weight to size_t. +// ApproxEqual: approximate equality (for inexact weights) +// Quantize: quantizes wrt delta (for inexact weights) +// Divide: for all a,b,c s.t. Times(a, b) == c +// --> b' = Divide(c, a, DIVIDE_LEFT) if a left semiring, b'.Member() +// and Times(a, b') == c +// --> a' = Divide(c, b, DIVIDE_RIGHT) if a right semiring, a'.Member() +// and Times(a', b) == c +// --> b' = Divide(c, a) = Divide(c, a, DIVIDE_ANY) = +// Divide(c, a, DIVIDE_LEFT) = Divide(c, a, DIVIDE_RIGHT) if a +// commutative semiring, b'.Member() and Times(a, b') = Times(b', a) = c +// ReverseWeight: the type of the corresponding reverse weight. +// Typically the same type as Weight for a (both left and right) semiring. +// For the left string semiring, it is the right string semiring. +// Reverse: a mapping from Weight to ReverseWeight s.t. +// --> Reverse(Reverse(a)) = a +// --> Reverse(Plus(a, b)) = Plus(Reverse(a), Reverse(b)) +// --> Reverse(Times(a, b)) = Times(Reverse(b), Reverse(a)) +// Typically the identity mapping in a (both left and right) semiring. +// In the left string semiring, it maps to the reverse string +// in the right string semiring. +// Properties: specifies additional properties that hold: +// LeftSemiring: indicates weights form a left semiring. +// RightSemiring: indicates weights form a right semiring. +// Commutative: for all a,b: Times(a,b) == Times(b,a) +// Idempotent: for all a: Plus(a, a) == a. +// Path: for all a, b: Plus(a, b) == a or Plus(a, b) == b. + + +#ifndef FST_LIB_WEIGHT_H__ +#define FST_LIB_WEIGHT_H__ + +#include +#include +#include +#include + +#include + +#include + + +namespace fst { + +// +// CONSTANT DEFINITIONS +// + +// A representable float near .001 +const float kDelta = 1.0F/1024.0F; + +// For all a,b,c: Times(c, Plus(a,b)) = Plus(Times(c,a), Times(c, b)) +const uint64 kLeftSemiring = 0x0000000000000001ULL; + +// For all a,b,c: Times(Plus(a,b), c) = Plus(Times(a,c), Times(b, c)) +const uint64 kRightSemiring = 0x0000000000000002ULL; + +const uint64 kSemiring = kLeftSemiring | kRightSemiring; + +// For all a,b: Times(a,b) = Times(b,a) +const uint64 kCommutative = 0x0000000000000004ULL; + +// For all a: Plus(a, a) = a +const uint64 kIdempotent = 0x0000000000000008ULL; + +// For all a,b: Plus(a,b) = a or Plus(a,b) = b +const uint64 kPath = 0x0000000000000010ULL; + + +// Determines direction of division. +enum DivideType { DIVIDE_LEFT, // left division + DIVIDE_RIGHT, // right division + DIVIDE_ANY }; // division in a commutative semiring + +// NATURAL ORDER +// +// By definition: +// a <= b iff a + b = a +// The natural order is a negative partial order iff the semiring is +// idempotent. It is trivially monotonic for plus. It is left +// (resp. right) monotonic for times iff the semiring is left +// (resp. right) distributive. It is a total order iff the semiring +// has the path property. See Mohri, "Semiring Framework and +// Algorithms for Shortest-Distance Problems", Journal of Automata, +// Languages and Combinatorics 7(3):321-350, 2002. We define the +// strict version of this order below. + +template +class NaturalLess { + public: + typedef W Weight; + + NaturalLess() { + if (!(W::Properties() & kIdempotent)) { + FSTERROR() << "NaturalLess: Weight type is not idempotent: " + << W::Type(); + } + } + + bool operator()(const W &w1, const W &w2) const { + return (Plus(w1, w2) == w1) && w1 != w2; + } +}; + + +// Power is the iterated product for arbitrary semirings such that +// Power(w, 0) is One() for the semiring, and +// Power(w, n) = Times(Power(w, n-1), w) + +template +W Power(W w, size_t n) { + W result = W::One(); + for (size_t i = 0; i < n; ++i) { + result = Times(result, w); + } + return result; +} + +// General weight converter - raises error. +template +struct WeightConvert { + W2 operator()(W1 w1) const { + FSTERROR() << "WeightConvert: can't convert weight from \"" + << W1::Type() << "\" to \"" << W2::Type(); + return W2::NoWeight(); + } +}; + +// Specialized weight converter to self. +template +struct WeightConvert { + W operator()(W w) const { return w; } +}; + +} // namespace fst + +#endif // FST_LIB_WEIGHT_H__ -- cgit v1.2.3-70-g09d2