All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
"Classes and functions related to context expansion"

Namespaces

 fst::internal
 

Classes

class  ContextFstImpl< Arc, LabelT >
 
class  ContextFst< Arc, LabelT >
 
class  StateIterator< ContextFst< A > >
 
class  ArcIterator< ContextFst< A > >
 
class  ContextMatcher< Arc, LabelT >
 

Functions

template<class Arc >
void AddSubsequentialLoop (typename Arc::Label subseq_symbol, MutableFst< Arc > *fst)
 Modifies an FST so that it transuces the same paths, but the input side of the paths can all have the subsequential symbol '$' appended to them any number of times (we could easily specify the number of times, but accepting any number of repetitions is just more convenient). More...
 
template<class I >
void WriteILabelInfo (std::ostream &os, bool binary, const vector< vector< I > > &info)
 Useful utility function for writing these vectors to disk. More...
 
template<class I >
void ReadILabelInfo (std::istream &is, bool binary, vector< vector< I > > *info)
 Useful utility function for reading these vectors from disk. More...
 
template<class I >
SymbolTable * CreateILabelInfoSymbolTable (const vector< vector< I > > &info, const SymbolTable &phones_symtab, std::string separator, std::string disambig_prefix)
 The following function is mainly of use for printing and debugging. More...
 
void ComposeContext (const vector< int32 > &disambig_syms, int N, int P, VectorFst< StdArc > *ifst, VectorFst< StdArc > *ofst, vector< vector< int32 > > *ilabels_out)
 Used in the command-line tool fstcomposecontext. More...
 
template<class Arc , class LabelT >
void ComposeContextFst (const ContextFst< Arc, LabelT > &ifst1, const Fst< Arc > &ifst2, MutableFst< Arc > *ofst, const ComposeOptions &opts=ComposeOptions())
 
StateId FindState (const vector< LabelT > &seq)
 Finds state-id corresponding to this vector of phones. Inserts it if necessary. More...
 
Label FindLabel (const vector< LabelT > &label_info)
 Finds the label index corresponding to this context-window of phones. More...
 
StateId Start ()
 
 ContextFstImpl (const ContextFstImpl &other)
 
Weight Final (StateId s)
 
size_t NumArcs (StateId s)
 
size_t NumInputEpsilons (StateId s)
 
void InitArcIterator (StateId s, ArcIteratorData< Arc > *data)
 
void CreateDisambigArc (StateId s, Label olabel, Arc *oarc)
 
bool CreatePhoneOrEpsArc (StateId src, StateId dst, Label olabel, const vector< LabelT > &phone_seq, Arc *oarc)
 
bool CreateArc (StateId s, Label olabel, Arc *oarc)
 
void Expand (StateId s)
 
bool Find (Label match_label)
 
void InitStateIterator (StateIteratorData< Arc > *data) const override
 

Detailed Description

Function Documentation

void AddSubsequentialLoop ( typename Arc::Label  subseq_symbol,
MutableFst< Arc > *  fst 
)

Modifies an FST so that it transuces the same paths, but the input side of the paths can all have the subsequential symbol '$' appended to them any number of times (we could easily specify the number of times, but accepting any number of repetitions is just more convenient).

The actual way we do this is for each final state, we add a transition with weight equal to the final-weight of that state, with input-symbol '$' and output-symbols <eps>, and ending in a new super-final state that has unit final-probability and a unit-weight self-loop with '$' on its input and <eps> on its output. The reason we don't just add a loop to each final-state has to do with preserving stochasticity (see Preserving stochasticity and testing it). We keep the final-probability in all the original final-states rather than setting them to zero, so the resulting FST can accept zero '$' symbols at the end (in case we had no right context).

Definition at line 369 of file context-fst-inl.h.

References rnnlm::i.

Referenced by fst::ComposeContext(), main(), and TrainingGraphCompiler::TrainingGraphCompiler().

370  {
371  typedef typename Arc::StateId StateId;
372  typedef typename Arc::Weight Weight;
373 
374  vector<StateId> final_states;
375  for (StateIterator<MutableFst<Arc> > siter(*fst); !siter.Done(); siter.Next()) {
376  StateId s = siter.Value();
377  if (fst->Final(s) != Weight::Zero()) final_states.push_back(s);
378  }
379 
380  StateId superfinal = fst->AddState();
381  Arc arc(subseq_symbol, 0, Weight::One(), superfinal);
382  fst->AddArc(superfinal, arc); // loop at superfinal.
383  fst->SetFinal(superfinal, Weight::One());
384 
385  for (size_t i = 0; i < final_states.size(); i++) {
386  StateId s = final_states[i];
387  fst->AddArc(s, Arc(subseq_symbol, 0, fst->Final(s), superfinal));
388  // No, don't remove the final-weights of the original states..
389  // this is so we can add the subsequential loop in cases where
390  // there is no context, and it won't hurt.
391  // fst->SetFinal(s, Weight::Zero());
392  arc.nextstate = final_states[i];
393  }
394 }
fst::StdArc::StateId StateId
Definition: graph.dox:21
fst::StdArc::Weight Weight
void ComposeContext ( const vector< int32 > &  disambig_syms,
int  N,
int  P,
VectorFst< StdArc > *  ifst,
VectorFst< StdArc > *  ofst,
vector< vector< int32 > > *  ilabels_out 
)
inline

Used in the command-line tool fstcomposecontext.

It creates a context FST and composes it on the left with "ifst" to make "ofst". It outputs the label information to ilabels_out. "ifst" is mutable because we need to add the subsequential loop.

Definition at line 476 of file context-fst-inl.h.

References fst::AddSubsequentialLoop(), fst::ComposeContextFst(), fst::GetInputSymbols(), rnnlm::i, and ContextFst< Arc, LabelT >::ILabelInfo().

Referenced by main().

480  {
481  assert(ifst != NULL && ofst != NULL);
482  assert(N > 0);
483  assert(P >= 0);
484  assert(P < N);
485 
486  vector<int32> disambig_syms(disambig_syms_in);
487  std::sort(disambig_syms.begin(), disambig_syms.end());
488  vector<int32> all_syms;
489  GetInputSymbols(*ifst, false/*no eps*/, &all_syms);
490  std::sort(all_syms.begin(), all_syms.end());
491  vector<int32> phones;
492  for (size_t i = 0; i < all_syms.size(); i++)
493  if (!std::binary_search(disambig_syms.begin(),
494  disambig_syms.end(), all_syms[i]))
495  phones.push_back(all_syms[i]);
496 
497  // Get subsequential symbol that does not clash with
498  // any disambiguation symbol or symbol in the FST.
499  int32 subseq_sym = 1;
500  if (!all_syms.empty())
501  subseq_sym = std::max(subseq_sym, all_syms.back() + 1);
502  if (!disambig_syms.empty())
503  subseq_sym = std::max(subseq_sym, disambig_syms.back() + 1);
504 
505  // if P == N-1, it's left-context, and no subsequential symbol needed.
506  if (P != N-1)
507  AddSubsequentialLoop(subseq_sym, ifst);
508  ContextFst<StdArc, int32> cfst(subseq_sym, phones, disambig_syms, N, P);
509  ComposeContextFst(cfst, *ifst, ofst);
510  *ilabels_out = cfst.ILabelInfo();
511 }
void GetInputSymbols(const Fst< Arc > &fst, bool include_eps, vector< I > *symbols)
GetInputSymbols gets the list of symbols on the input of fst (including epsilon, if include_eps == tr...
void AddSubsequentialLoop(typename Arc::Label subseq_symbol, MutableFst< Arc > *fst)
Modifies an FST so that it transuces the same paths, but the input side of the paths can all have the...
void ComposeContextFst(const ContextFst< Arc, LabelT > &ifst1, const Fst< Arc > &ifst2, MutableFst< Arc > *ofst, const ComposeOptions &opts=ComposeOptions())
Definition: context-fst.h:432
void fst::ComposeContextFst ( const ContextFst< Arc, LabelT > &  ifst1,
const Fst< Arc > &  ifst2,
MutableFst< Arc > *  ofst,
const ComposeOptions &  opts = ComposeOptions() 
)

Definition at line 432 of file context-fst.h.

Referenced by TrainingGraphCompiler::CompileGraph(), TrainingGraphCompiler::CompileGraphs(), fst::ComposeContext(), and fst::TestContextFst().

434  {
435  ComposeFstOptions<Arc, ContextMatcher<Arc, LabelT> > nopts;
436  nopts.gc_limit = 0; // Cache only the most recent state for fastest copy.
437  *ofst = ComposeFst<Arc>(ifst1, ifst2, nopts);
438  if (opts.connect)
439  Connect(ofst);
440 }
ContextFstImpl ( const ContextFstImpl< Arc, LabelT > &  other)

Definition at line 83 of file context-fst-inl.h.

References KALDI_ERR.

83  :
84  phone_syms_(other.phone_syms_),
85  disambig_syms_(other.disambig_syms_) {
86  KALDI_ERR << "ContextFst copying not yet supported "
87  << "[not hard, but would have to test.]";
88 }
kaldi::ConstIntegerSet< Label > disambig_syms_
Definition: context-fst.h:170
#define KALDI_ERR
Definition: kaldi-error.h:127
kaldi::ConstIntegerSet< Label > phone_syms_
Definition: context-fst.h:169
bool CreateArc ( StateId  s,
Label  olabel,
Arc *  oarc 
)

Definition at line 267 of file context-fst-inl.h.

References rnnlm::i, and KALDI_ERR.

269  {
270  // Returns true to indicate the arc exists.
271 
272  if (olabel == 0) return false; // No epsilon-output arcs in this FST.
273 
274  const vector<LabelT> &seq = state_seqs_[s];
275 
276  if (IsDisambigSymbol(olabel)) { // Disambiguation-symbol arcs.. create self-loop.
277  CreateDisambigArc(s, olabel, oarc);
278  return true;
279  } else if (IsPhoneSymbol(olabel) || olabel == subsequential_symbol_) {
280  // If all is OK, we shift the old sequence left by 1 and push on the new phone.
281 
282  if (olabel != subsequential_symbol_ && !seq.empty() &&
283  seq.back() == subsequential_symbol_) {
284  return false; // Phone not allowed to follow subsequential symbol.
285  }
286 
287  if (olabel == subsequential_symbol_ &&
288  (P_ == N_-1 || seq[P_] == subsequential_symbol_)) {
289  // We already had "enough" subsequential symbols in a row and don't want to
290  // accept any more, or we'd be making the subsequential symbol the central phone.
291  return false;
292  }
293 
294  vector<LabelT> newseq(N_-1); // seq shifted left by 1.
295  for (int i = 0;i < N_-2;i++) newseq[i] = seq[i+1];
296  if (N_ > 1) newseq[N_-2] = olabel;
297 
298  vector<LabelT> phoneseq(seq); // copy it before FindState which
299  // possibly changes the address.
300  StateId nextstate = FindState(newseq);
301 
302  phoneseq.push_back(olabel); // Now it's the full context window of size N_.
303  for (int i = 1; i < N_ ; i++)
304  if (phoneseq[i] == subsequential_symbol_) phoneseq[i] = 0; // don't put subseq. symbol on
305  // the output arcs, just 0.
306  return CreatePhoneOrEpsArc(s, nextstate, olabel, phoneseq, oarc);
307  } else {
308  KALDI_ERR << "ContextFst: CreateArc, invalid olabel supplied [confusion "
309  << "about phone list or disambig symbols?]: " << olabel;
310  }
311  return false; // won't get here. suppress compiler error.
312 }
bool CreatePhoneOrEpsArc(StateId src, StateId dst, Label olabel, const vector< LabelT > &phone_seq, Arc *oarc)
vector< vector< LabelT > > state_seqs_
Definition: context-fst.h:162
bool IsDisambigSymbol(Label lab)
Definition: context-fst.h:150
void CreateDisambigArc(StateId s, Label olabel, Arc *oarc)
StateId FindState(const vector< LabelT > &seq)
Finds state-id corresponding to this vector of phones. Inserts it if necessary.
bool IsPhoneSymbol(Label lab)
Definition: context-fst.h:153
#define KALDI_ERR
Definition: kaldi-error.h:127
void CreateDisambigArc ( StateId  s,
Label  olabel,
Arc *  oarc 
)
inlineprivate

Definition at line 216 of file context-fst-inl.h.

218  { // called from CreateArc.
219  // Creates a self-loop arc corresponding to the disambiguation symbol.
220  vector<LabelT> label_info; // (olabel);
221  label_info.push_back(-olabel); // olabel is a disambiguation symbol. Use its negative
222  // so we can easily distinguish them.
223  Label ilabel = FindLabel(label_info);
224  oarc->ilabel = ilabel;
225  oarc->olabel = olabel;
226  oarc->weight = Weight::One();
227  oarc->nextstate = s; // self-loop.
228 }
Label FindLabel(const vector< LabelT > &label_info)
Finds the label index corresponding to this context-window of phones.
SymbolTable * CreateILabelInfoSymbolTable ( const vector< vector< I > > &  info,
const SymbolTable &  phones_symtab,
std::string  separator,
std::string  initial_disambig 
)

The following function is mainly of use for printing and debugging.

Definition at line 421 of file context-fst-inl.h.

References rnnlm::i, rnnlm::j, and KALDI_ERR.

Referenced by main().

424  { // e.g. separator = "/", initial-disambig="#-1"
425  assert(std::numeric_limits<I>::is_signed); // make sure is signed type.
426  assert(!info.empty());
427  assert(info[0].empty());
428  SymbolTable *ans = new SymbolTable("ilabel-info-symtab");
429  int64 s = ans->AddSymbol(phones_symtab.Find(static_cast<int64>(0)));
430  assert(s == 0);
431  for (size_t i = 1; i < info.size(); i++) {
432  if (info[i].size() == 0) {
433  KALDI_ERR << "Invalid ilabel-info";
434  }
435  if (info[i].size() == 1 &&
436  info[i][0] <= 0) {
437  if (info[i][0] == 0) { // special symbol at start that we want to call #-1.
438  s = ans->AddSymbol(initial_disambig);
439  if (s != i) {
440  KALDI_ERR << "Disambig symbol " << initial_disambig
441  << " already in vocab";
442  }
443  } else {
444  std::string disambig_sym = phones_symtab.Find(-info[i][0]);
445  if (disambig_sym == "") {
446  KALDI_ERR << "Disambig symbol " << -info[i][0]
447  << " not in phone symbol-table";
448  }
449  s = ans->AddSymbol(disambig_sym);
450  if (s != i) {
451  KALDI_ERR << "Disambig symbol " << disambig_sym
452  << " already in vocab";
453  }
454  }
455  } else {
456  // is a phone-context-window.
457  std::string newsym;
458  for (size_t j = 0; j < info[i].size(); j++) {
459  std::string phonesym = phones_symtab.Find(info[i][j]);
460  if (phonesym == "") {
461  KALDI_ERR << "Symbol " << info[i][j]
462  << " not in phone symbol-table";
463  }
464  if (j != 0) newsym += separator;
465  newsym += phonesym;
466  }
467  int64 s = ans->AddSymbol(newsym);
468  if (s != static_cast<int64>(i)) {
469  KALDI_ERR << "Some problem with duplicate symbols";
470  }
471  }
472  }
473  return ans;
474 }
#define KALDI_ERR
Definition: kaldi-error.h:127
bool CreatePhoneOrEpsArc ( StateId  src,
StateId  dst,
Label  olabel,
const vector< LabelT > &  phone_seq,
Arc *  oarc 
)
inlineprivate

Definition at line 231 of file context-fst-inl.h.

235  {
236  // called from CreateArc.
237  // creates the arc with a phone's state on its input labels (or epsilon).
238  // returns true if it created the arc.
239  // returns false if it could not create an arc due to the decision-tree returning false
240  // [this only happens if opts_.behavior_on_failure == ContextFstOptions::kNoArc].
241 
242  assert(phone_seq[P_] != subsequential_symbol_); // would be coding error.
243 
244  if (phone_seq[P_] == 0) { // this can happen at the beginning of the graph.
245  // we don't output a real phone. Epsilon arc (but sometimes we need to
246  // use a special disambiguation symbol instead of epsilon).
247  *oarc = Arc(pseudo_eps_symbol_, olabel, Weight::One(), dst);
248  // This 1 is a "special" disambiguation symbol (#-1 in printed form) that
249  // we use to represent epsilons.
250  return true;
251  } else {
252  // have a phone in central position.
253  Label ilabel = FindLabel(phone_seq);
254  *oarc = Arc(ilabel, olabel, Weight::One(), dst);
255  return true;
256  }
257 }
Label FindLabel(const vector< LabelT > &label_info)
Finds the label index corresponding to this context-window of phones.
void Expand ( StateId  s)

Definition at line 317 of file context-fst-inl.h.

317  { // expands arcs only [not final state weight].
318  assert(static_cast<size_t>(s) < state_seqs_.size()); // make sure state exists already.
319 
320  // We just try adding all possible symbols on the output side.
321  Arc arc;
322  if (this->CreateArc(s, subsequential_symbol_, &arc)) {
323  this->PushArc(s, arc);
324  }
326  iter != phone_syms_.end(); ++iter) {
327  Label phone = *iter;
328  if (this->CreateArc(s, phone, &arc)) {
329  this->PushArc(s, arc);
330  }
331  }
333  iter != disambig_syms_.end(); ++iter) {
334  Label disambig_sym = *iter;
335  if (this->CreateArc(s, disambig_sym, &arc)) {
336  this->PushArc(s, arc);
337  }
338  }
339  this->SetArcs(s); // mark the arcs as "done". [so HasArcs returns true].
340 }
vector< vector< LabelT > > state_seqs_
Definition: context-fst.h:162
kaldi::ConstIntegerSet< Label > disambig_syms_
Definition: context-fst.h:170
iterator begin() const
iterator end() const
kaldi::ConstIntegerSet< Label > phone_syms_
Definition: context-fst.h:169
bool CreateArc(StateId s, Label olabel, Arc *oarc)
std::vector< I >::const_iterator iterator
ContextFstImpl< Arc, LabelT >::Weight Final ( StateId  s)

Definition at line 143 of file context-fst-inl.h.

143  {
144  assert(static_cast<size_t>(s) < state_seqs_.size()); // make sure state exists already.
145  if (!this->HasFinal(s)) { // Work out final-state weight.
146  const vector<LabelT> &seq = state_seqs_[s];
147 
148  bool final_ok;
149  assert(static_cast<int32>(seq.size()) == N_-1);
150 
151  if (P_ < N_ - 1) {
152  /* Note that P_ (in zero based indexing) is the "central position", and for arcs out of
153  this state the thing at P_ will be the one we expand. If this is the subsequential symbol,
154  it means we will output nothing (and will obviously never output anything). Thus we make
155  this state the final state.
156  */
157  final_ok = (seq[P_] == subsequential_symbol_);
158  } else {
159  /* If P_ == N_-1, then the "central phone" is the last one in the list (we have a left-context system).
160  In this case everything is output immediately and there is no need for a subsequential symbol.
161  Here, any state in the FST can be the final state.
162  */
163  final_ok = true;
164  }
165  Weight w = final_ok ? Weight::One() : Weight::Zero();
166  this->SetFinal(s, w);
167  return w;
168  }
169  return CacheImpl<Arc>::Final(s);
170 }
vector< vector< LabelT > > state_seqs_
Definition: context-fst.h:162
bool Find ( typename Arc::Label  match_label)

Definition at line 345 of file context-fst-inl.h.

References ContextFst< Arc, LabelT >::CreateArc().

Referenced by ContextMatcher< Arc, LabelT >::Find_().

345  {
346  assert(s_ != kNoStateId);
347  // we know at this point that match_type_ == MATCH_OUTPUT. we are matching output.
348 
349  if (match_label == kNoLabel) {
350  // A ContextFst has no epsilons on its output. So
351  // we don't need to match self-loops on the other FST.
352  ready_ = false;
353  return false;
354  } else if (match_label == 0) {
355  arc_.ilabel = 0;
356  arc_.olabel = kNoLabel; // epsilon_L
357  arc_.weight = Weight::One();
358  arc_.nextstate = s_; // loop.
359  ready_ = true;
360  return true; // epsilon_L loop.
361  } else {
362  const ContextFst<Arc, LabelT> *cfst = static_cast<const ContextFst<Arc, LabelT>*> (fst_); // we checked in initializer, that it is.
363  ready_ = cfst->CreateArc(s_, match_label, &arc_);
364  return ready_;
365  }
366 }
const FST * fst_
Definition: context-fst.h:410
ContextFstImpl< Arc, LabelT >::Label FindLabel ( const vector< LabelT > &  label_info)
private

Finds the label index corresponding to this context-window of phones.

Inserts it if necessary.

Definition at line 55 of file context-fst-inl.h.

55  {
56  // Finds ilabel corresponding to this information.. Creates new ilabel if necessary.
57  VectorToLabelIter iter = ilabel_map_.find(label_vec);
58  if (iter == ilabel_map_.end()) { // Not already in map.
59  Label this_label = ilabel_info_.size();
60  ilabel_info_.push_back(label_vec);
61  ilabel_map_[label_vec] = this_label;
62  return this_label;
63  } else {
64  return iter->second;
65  }
66 }
VectorToLabelType::const_iterator VectorToLabelIter
Definition: context-fst.h:98
vector< vector< LabelT > > ilabel_info_
Definition: context-fst.h:166
VectorToLabelType ilabel_map_
Definition: context-fst.h:165
ContextFstImpl< Arc, LabelT >::StateId FindState ( const vector< LabelT > &  seq)
private

Finds state-id corresponding to this vector of phones. Inserts it if necessary.

Definition at line 38 of file context-fst-inl.h.

38  {
39  // Finds state-id corresponding to this vector of phones. Inserts it if
40  // necessary.
41  assert(static_cast<int32>(seq.size()) == N_-1);
42  VectorToStateIter iter = state_map_.find(seq);
43  if (iter == state_map_.end()) { // Not already in map.
44  StateId this_state_id = (StateId)state_seqs_.size();
45  state_seqs_.push_back(seq);
46  state_map_[seq] = this_state_id;
47  return this_state_id;
48  } else {
49  return iter->second;
50  }
51 }
vector< vector< LabelT > > state_seqs_
Definition: context-fst.h:162
VectorToStateType::const_iterator VectorToStateIter
Definition: context-fst.h:97
VectorToStateType state_map_
Definition: context-fst.h:161
void InitArcIterator ( StateId  s,
ArcIteratorData< Arc > *  data 
)

Definition at line 208 of file context-fst-inl.h.

208  {
209  if (!this->HasArcs(s))
210  Expand(s);
212 }
void InitStateIterator ( StateIteratorData< Arc > *  data) const
inlineoverride

Definition at line 313 of file context-fst.h.

313  {
314  data->base = new StateIterator< ContextFst<A> >(*this);
315 }
size_t NumArcs ( StateId  s)

Definition at line 175 of file context-fst-inl.h.

References KALDI_ASSERT, and fst::NumArcs().

175  {
176  if (this->HasArcs(s)) {
177  return CacheImpl<Arc>::NumArcs(s);
178  }
179  KALDI_ASSERT(s >= 0 && s < state_seqs_.size());
180  const vector<LabelT> &seq = state_seqs_[s];
181  KALDI_ASSERT(seq.size() == N_ - 1);
182  if (!seq.empty() && seq.back() == subsequential_symbol_) {
183  // State is not a "normal" state because it just saw the subsequential symbol,
184  // hence it cannot accept phones.
185 
186  if (P_ == N_ - 1 || seq[P_] == subsequential_symbol_) { // don't
187  // accept subsequential symbol.. c.f. logic in CreateArc().
188  return disambig_syms_.size();
189  } else {
190  return disambig_syms_.size() + 1; // Accept disambig syms and
191  // subsequential symbol.
192  }
193  } else {
194  // For normal states, in general there is potentially an arc for each phone and an arc
195  // for each disambiguation symbol, plus one for the subsequential symbol.
196  return phone_syms_.size() + disambig_syms_.size() + 1;
197  }
198 }
vector< vector< LabelT > > state_seqs_
Definition: context-fst.h:162
kaldi::ConstIntegerSet< Label > disambig_syms_
Definition: context-fst.h:170
kaldi::ConstIntegerSet< Label > phone_syms_
Definition: context-fst.h:169
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
Arc::StateId NumArcs(const ExpandedFst< Arc > &fst)
Returns the total number of arcs in an FST.
size_t NumInputEpsilons ( StateId  s)

Definition at line 201 of file context-fst-inl.h.

201  {
202  if (!this->HasArcs(s))
203  Expand(s);
205 }
void ReadILabelInfo ( std::istream &  is,
bool  binary,
vector< vector< I > > *  info 
)

Useful utility function for reading these vectors from disk.

writes as int32 (see WriteILabelInfo above).

Definition at line 408 of file context-fst-inl.h.

References rnnlm::i, kaldi::ReadBasicType(), and kaldi::ReadIntegerVector().

Referenced by main(), and fst::TestContextFst().

409  {
410  I sz = info->size();
411  kaldi::ReadBasicType(is, binary, &sz);
412  assert(info != NULL);
413  info->resize(sz);
414  for (int i = 0; i < sz; i++) {
415  kaldi::ReadIntegerVector(is, binary, &((*info)[i]));
416  }
417 }
void ReadBasicType(std::istream &is, bool binary, T *t)
ReadBasicType is the name of the read function for bool, integer types, and floating-point types...
Definition: io-funcs-inl.h:55
void ReadIntegerVector(std::istream &is, bool binary, std::vector< T > *v)
Function for reading STL vector of integer types.
Definition: io-funcs-inl.h:232
ContextFstImpl< Arc, LabelT >::StateId Start ( )

Definition at line 70 of file context-fst-inl.h.

70  {
71  if (! CacheImpl<Arc>::HasStart()) {
72  vector<LabelT> vec(N_-1, 0); // Vector of N_-1 epsilons. [e.g. N = 3].
73  StateId s = FindState(vec);
74  assert(s == 0);
75  this->SetStart(s);
76  }
77  return CacheImpl<Arc>::Start();
78 }
StateId FindState(const vector< LabelT > &seq)
Finds state-id corresponding to this vector of phones. Inserts it if necessary.
void WriteILabelInfo ( std::ostream &  os,
bool  binary,
const vector< vector< I > > &  info 
)

Useful utility function for writing these vectors to disk.

writes as int32 for binary compatibility since it will typically be "int".

Definition at line 397 of file context-fst-inl.h.

References rnnlm::i, kaldi::WriteBasicType(), and kaldi::WriteIntegerVector().

Referenced by main(), and fst::TestContextFst().

398  {
399  I sz = info.size();
400  kaldi::WriteBasicType(os, binary, sz);
401  for (I i = 0; i < sz; i++) {
402  kaldi::WriteIntegerVector(os, binary, info[i]);
403  }
404 }
void WriteIntegerVector(std::ostream &os, bool binary, const std::vector< T > &v)
Function for writing STL vectors of integer types.
Definition: io-funcs-inl.h:198
void WriteBasicType(std::ostream &os, bool binary, T t)
WriteBasicType is the name of the write function for bool, integer types, and floating-point types...
Definition: io-funcs-inl.h:34