GaussPostHolder Class Reference

#include <posterior.h>

Collaboration diagram for GaussPostHolder:

Public Types

typedef GaussPost T
 

Public Member Functions

 GaussPostHolder ()
 
void Clear ()
 
bool Read (std::istream &is)
 
const TValue () const
 
void Swap (GaussPostHolder *other)
 
bool ExtractRange (const GaussPostHolder &other, const std::string &range)
 

Static Public Member Functions

static bool Write (std::ostream &os, bool binary, const T &t)
 
static bool IsReadInBinary ()
 

Private Member Functions

 KALDI_DISALLOW_COPY_AND_ASSIGN (GaussPostHolder)
 

Private Attributes

T t_
 

Detailed Description

Definition at line 102 of file posterior.h.

Member Typedef Documentation

◆ T

typedef GaussPost T

Definition at line 104 of file posterior.h.

Constructor & Destructor Documentation

◆ GaussPostHolder()

GaussPostHolder ( )
inline

Definition at line 106 of file posterior.h.

References PosteriorHolder::Write().

106 { }

Member Function Documentation

◆ Clear()

void Clear ( )
inline

Definition at line 110 of file posterior.h.

References PosteriorHolder::Read(), kaldi::swap(), and PosteriorHolder::t_.

110 { GaussPost tmp; std::swap(tmp, t_); }
void swap(basic_filebuf< CharT, Traits > &x, basic_filebuf< CharT, Traits > &y)
std::vector< std::vector< std::pair< int32, Vector< BaseFloat > > > > GaussPost
GaussPost is a typedef for storing Gaussian-level posteriors for an utterance.
Definition: posterior.h:51

◆ ExtractRange()

bool ExtractRange ( const GaussPostHolder other,
const std::string &  range 
)
inline

Definition at line 125 of file posterior.h.

References PosteriorHolder::KALDI_DISALLOW_COPY_AND_ASSIGN(), and KALDI_ERR.

125  {
126  KALDI_ERR << "ExtractRange is not defined for this type of holder.";
127  return false;
128  }
#define KALDI_ERR
Definition: kaldi-error.h:147

◆ IsReadInBinary()

static bool IsReadInBinary ( )
inlinestatic

Definition at line 117 of file posterior.h.

117 { return true; }

◆ KALDI_DISALLOW_COPY_AND_ASSIGN()

KALDI_DISALLOW_COPY_AND_ASSIGN ( GaussPostHolder  )
private

◆ Read()

bool Read ( std::istream &  is)

Definition at line 181 of file posterior.cc.

References kaldi::InitKaldiInputStream(), KALDI_ERR, KALDI_WARN, kaldi::ReadBasicType(), and PosteriorHolder::t_.

181  {
182  t_.clear();
183 
184  bool is_binary;
185  if (!InitKaldiInputStream(is, &is_binary)) {
186  KALDI_WARN << "Reading Table object, failed reading binary header";
187  return false;
188  }
189  try {
190  int32 sz;
191  ReadBasicType(is, is_binary, &sz);
192  if (sz < 0)
193  KALDI_ERR << "Reading posteriors: got negative size";
194  t_.resize(sz);
195  for (GaussPost::iterator iter = t_.begin(); iter != t_.end(); ++iter) {
196  int32 sz2;
197  ReadBasicType(is, is_binary, &sz2);
198  if (sz2 < 0)
199  KALDI_ERR << "Reading posteriors: got negative size";
200  iter->resize(sz2);
201  for (std::vector<std::pair<int32, Vector<BaseFloat> > >::iterator
202  iter2=iter->begin();
203  iter2 != iter->end();
204  iter2++) {
205  ReadBasicType(is, is_binary, &(iter2->first));
206  iter2->second.Read(is, is_binary);
207  }
208  }
209  return true;
210  } catch (std::exception &e) {
211  KALDI_WARN << "Exception caught reading table of posteriors. " << e.what();
212  t_.clear();
213  return false;
214  }
215 }
bool InitKaldiInputStream(std::istream &is, bool *binary)
Initialize an opened stream for reading by detecting the binary header and.
Definition: io-funcs-inl.h:306
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
kaldi::int32 int32
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150

◆ Swap()

void Swap ( GaussPostHolder other)
inline

Definition at line 121 of file posterior.h.

References PosteriorHolder::t_, and GaussPostHolder::t_.

121  {
122  t_.swap(other->t_);
123  }

◆ Value()

const T& Value ( ) const
inline

Definition at line 119 of file posterior.h.

References PosteriorHolder::t_.

119 { return t_; }

◆ Write()

bool Write ( std::ostream &  os,
bool  binary,
const T t 
)
static

Definition at line 157 of file posterior.cc.

References kaldi::InitKaldiOutputStream(), KALDI_WARN, and kaldi::WriteBasicType().

157  {
158  InitKaldiOutputStream(os, binary); // Puts binary header if binary mode.
159  try {
160  // We don't bother making this a one-line format.
161  int32 sz = t.size();
162  WriteBasicType(os, binary, sz);
163  for (GaussPost::const_iterator iter = t.begin(); iter != t.end(); ++iter) {
164  int32 sz2 = iter->size();
165  WriteBasicType(os, binary, sz2);
166  for (std::vector<std::pair<int32, Vector<BaseFloat> > >::const_iterator iter2=iter->begin();
167  iter2 != iter->end();
168  iter2++) {
169  WriteBasicType(os, binary, iter2->first);
170  iter2->second.Write(os, binary);
171  }
172  }
173  if(!binary) os << '\n';
174  return os.good();
175  } catch (const std::exception &e) {
176  KALDI_WARN << "Exception caught writing table of posteriors. " << e.what();
177  return false; // Write failure.
178  }
179 }
kaldi::int32 int32
#define KALDI_WARN
Definition: kaldi-error.h:150
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
void InitKaldiOutputStream(std::ostream &os, bool binary)
InitKaldiOutputStream initializes an opened stream for writing by writing an optional binary header a...
Definition: io-funcs-inl.h:291

Member Data Documentation

◆ t_

T t_
private

Definition at line 131 of file posterior.h.

Referenced by GaussPostHolder::Swap().


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