CompactLatticeWeightTpl< WeightType, IntType > Class Template Reference

#include <lattice-weight.h>

Collaboration diagram for CompactLatticeWeightTpl< WeightType, IntType >:

Public Types

typedef WeightType W
 
typedef CompactLatticeWeightTpl< WeightType, IntType > ReverseWeight
 

Public Member Functions

 CompactLatticeWeightTpl ()
 
 CompactLatticeWeightTpl (const WeightType &w, const std::vector< IntType > &s)
 
CompactLatticeWeightTploperator= (const CompactLatticeWeightTpl< WeightType, IntType > &w)
 
const WWeight () const
 
const std::vector< IntType > & String () const
 
void SetWeight (const W &w)
 
void SetString (const std::vector< IntType > &s)
 
CompactLatticeWeightTpl< WeightType, IntType > Reverse () const
 
bool Member () const
 
CompactLatticeWeightTpl Quantize (float delta=kDelta) const
 
std::istream & Read (std::istream &strm)
 
std::ostream & Write (std::ostream &strm) const
 
size_t Hash () const
 

Static Public Member Functions

static const CompactLatticeWeightTpl< WeightType, IntType > Zero ()
 
static const CompactLatticeWeightTpl< WeightType, IntType > One ()
 
static std::string GetIntSizeString ()
 
static const std::string & Type ()
 
static const CompactLatticeWeightTpl< WeightType, IntType > NoWeight ()
 
static constexpr uint64 Properties ()
 

Private Attributes

W weight_
 
std::vector< IntType > string_
 

Detailed Description

template<class WeightType, class IntType>
class fst::CompactLatticeWeightTpl< WeightType, IntType >

Definition at line 423 of file lattice-weight.h.

Member Typedef Documentation

◆ ReverseWeight

typedef CompactLatticeWeightTpl<WeightType, IntType> ReverseWeight

Definition at line 427 of file lattice-weight.h.

◆ W

typedef WeightType W

Definition at line 425 of file lattice-weight.h.

Constructor & Destructor Documentation

◆ CompactLatticeWeightTpl() [1/2]

Definition at line 436 of file lattice-weight.h.

436 { }

◆ CompactLatticeWeightTpl() [2/2]

CompactLatticeWeightTpl ( const WeightType &  w,
const std::vector< IntType > &  s 
)
inline

Definition at line 438 of file lattice-weight.h.

438  :
439  weight_(w), string_(s) { }
std::vector< IntType > string_

Member Function Documentation

◆ GetIntSizeString()

static std::string GetIntSizeString ( )
inlinestatic

Definition at line 465 of file lattice-weight.h.

465  {
466  char buf[2];
467  buf[0] = '0' + sizeof(IntType);
468  buf[1] = '\0';
469  return buf;
470  }

◆ Hash()

size_t Hash ( ) const
inline

Definition at line 541 of file lattice-weight.h.

References rnnlm::i.

541  {
542  size_t ans = weight_.Hash();
543  // any weird numbers here are largish primes
544  size_t sz = string_.size(), mult = 6967;
545  for(size_t i = 0; i < sz; i++) {
546  ans += string_[i] * mult;
547  mult *= 7499;
548  }
549  return ans;
550  }
std::vector< IntType > string_

◆ Member()

bool Member ( ) const
inline

Definition at line 491 of file lattice-weight.h.

Referenced by fst::CompactLatticeWeightTest().

491  {
492  // a semiring has only one zero, this is the important property
493  // we're trying to maintain here. So force string_ to be empty if
494  // w_ == zero.
495  if (!weight_.Member()) return false;
496  if (weight_ == WeightType::Zero())
497  return string_.empty();
498  else
499  return true;
500  }
std::vector< IntType > string_

◆ NoWeight()

static const CompactLatticeWeightTpl<WeightType, IntType> NoWeight ( )
inlinestatic

Definition at line 477 of file lattice-weight.h.

477  {
478  return CompactLatticeWeightTpl<WeightType, IntType>(
479  WeightType::NoWeight(), std::vector<IntType>());
480  }

◆ One()

static const CompactLatticeWeightTpl<WeightType, IntType> One ( )
inlinestatic

◆ operator=()

CompactLatticeWeightTpl& operator= ( const CompactLatticeWeightTpl< WeightType, IntType > &  w)
inline

Definition at line 441 of file lattice-weight.h.

References CompactLatticeWeightTpl< WeightType, IntType >::string_, and CompactLatticeWeightTpl< WeightType, IntType >::weight_.

441  {
442  weight_ = w.weight_;
443  string_ = w.string_;
444  return *this;
445  }
std::vector< IntType > string_

◆ Properties()

static constexpr uint64 Properties ( )
inlinestatic

Definition at line 506 of file lattice-weight.h.

506  {
507  return kLeftSemiring | kRightSemiring | kPath | kIdempotent;
508  }

◆ Quantize()

CompactLatticeWeightTpl Quantize ( float  delta = kDelta) const
inline

Definition at line 502 of file lattice-weight.h.

Referenced by fst::CompactLatticeWeightTest().

502  {
503  return CompactLatticeWeightTpl(weight_.Quantize(delta), string_);
504  }
std::vector< IntType > string_

◆ Read()

std::istream& Read ( std::istream &  strm)
inline

Definition at line 512 of file lattice-weight.h.

References rnnlm::i, and KALDI_WARN.

Referenced by fst::CompactLatticeWeightTest().

512  {
513  weight_.Read(strm);
514  if (strm.fail()){ return strm; }
515  int32 sz;
516  ReadType(strm, &sz);
517  if (strm.fail()){ return strm; }
518  if (sz < 0) {
519  KALDI_WARN << "Negative string size! Read failure";
520  strm.clear(std::ios::badbit);
521  return strm;
522  }
523  string_.resize(sz);
524  for(int32 i = 0; i < sz; i++) {
525  ReadType(strm, &(string_[i]));
526  }
527  return strm;
528  }
kaldi::int32 int32
#define KALDI_WARN
Definition: kaldi-error.h:150
std::vector< IntType > string_

◆ Reverse()

CompactLatticeWeightTpl<WeightType, IntType> Reverse ( ) const
inline

Definition at line 483 of file lattice-weight.h.

References rnnlm::i.

483  {
484  size_t s = string_.size();
485  std::vector<IntType> v(s);
486  for(size_t i = 0; i < s; i++)
487  v[i] = string_[s-i-1];
488  return CompactLatticeWeightTpl<WeightType, IntType>(weight_, v);
489  }
std::vector< IntType > string_

◆ SetString()

void SetString ( const std::vector< IntType > &  s)
inline

Definition at line 453 of file lattice-weight.h.

Referenced by fst::operator>>().

453 { string_ = s; }
std::vector< IntType > string_

◆ SetWeight()

◆ String()

◆ Type()

static const std::string& Type ( )
inlinestatic

Definition at line 471 of file lattice-weight.h.

471  {
472  static const std::string type = "compact" + WeightType::Type()
473  + GetIntSizeString();
474  return type;
475  }
static std::string GetIntSizeString()

◆ Weight()

◆ Write()

std::ostream& Write ( std::ostream &  strm) const
inline

Definition at line 532 of file lattice-weight.h.

References rnnlm::i.

532  {
533  weight_.Write(strm);
534  if (strm.fail()){ return strm; }
535  int32 sz = static_cast<int32>(string_.size());
536  WriteType(strm, sz);
537  for(int32 i = 0; i < sz; i++)
538  WriteType(strm, string_[i]);
539  return strm;
540  }
kaldi::int32 int32
std::vector< IntType > string_

◆ Zero()

Member Data Documentation

◆ string_

std::vector<IntType> string_
private

◆ weight_

W weight_
private

The documentation for this class was generated from the following file: