Index Struct Reference

struct Index is intended to represent the various indexes by which we number the rows of the matrices that the Components process: mainly 'n', the index of the member of the minibatch, 't', used for the frame index in speech recognition, and 'x', which is a catch-all extra index which we might use in convolutional setups or for other reasons. More...

#include <nnet-common.h>

Collaboration diagram for Index:

Public Member Functions

 Index ()
 
 Index (int32 n, int32 t, int32 x=0)
 
bool operator== (const Index &a) const
 
bool operator!= (const Index &a) const
 
bool operator< (const Index &a) const
 
Index operator+ (const Index &other) const
 
Indexoperator+= (const Index &other)
 
void Write (std::ostream &os, bool binary) const
 
void Read (std::istream &os, bool binary)
 

Public Attributes

int32 n
 
int32 t
 
int32 x
 

Detailed Description

struct Index is intended to represent the various indexes by which we number the rows of the matrices that the Components process: mainly 'n', the index of the member of the minibatch, 't', used for the frame index in speech recognition, and 'x', which is a catch-all extra index which we might use in convolutional setups or for other reasons.

It is possible to extend this by adding new indexes if needed.

Definition at line 44 of file nnet-common.h.

Constructor & Destructor Documentation

◆ Index() [1/2]

Index ( )
inline

Definition at line 49 of file nnet-common.h.

Referenced by Index::operator+().

49 : n(0), t(0), x(0) { }

◆ Index() [2/2]

Index ( int32  n,
int32  t,
int32  x = 0 
)
inline

Definition at line 50 of file nnet-common.h.

50 : n(n), t(t), x(x) { }

Member Function Documentation

◆ operator!=()

bool operator!= ( const Index a) const
inline

Definition at line 55 of file nnet-common.h.

References Index::n, Index::t, and Index::x.

55  {
56  return n != a.n || t != a.t || x != a.x;
57  }

◆ operator+()

Index operator+ ( const Index other) const
inline

Definition at line 65 of file nnet-common.h.

References Index::Index(), Index::n, Index::t, and Index::x.

65  {
66  return Index(n+other.n, t+other.t, x+other.x);
67  }

◆ operator+=()

Index& operator+= ( const Index other)
inline

Definition at line 68 of file nnet-common.h.

References kaldi::nnet3::kNoTime, Index::n, Index::Read(), Index::t, Index::Write(), and Index::x.

68  {
69  n += other.n;
70  t += other.t;
71  x += other.x;
72  return *this;
73  }

◆ operator<()

bool operator< ( const Index a) const
inline

Definition at line 58 of file nnet-common.h.

References Index::n, Index::t, and Index::x.

58  {
59  if (t < a.t) { return true; }
60  else if (t > a.t) { return false; }
61  else if (x < a.x) { return true; }
62  else if (x > a.x) { return false; }
63  else return (n < a.n);
64  }

◆ operator==()

bool operator== ( const Index a) const
inline

Definition at line 52 of file nnet-common.h.

References Index::n, Index::t, and Index::x.

52  {
53  return n == a.n && t == a.t && x == a.x;
54  }

◆ Read()

void Read ( std::istream &  os,
bool  binary 
)

Definition at line 37 of file nnet-common.cc.

References kaldi::nnet3::ExpectToken(), Index::n, kaldi::ReadBasicType(), Index::t, and Index::x.

Referenced by Index::operator+=().

37  {
38  ExpectToken(is, binary, "<I1>");
39  ReadBasicType(is, binary, &n);
40  ReadBasicType(is, binary, &t);
41  ReadBasicType(is, binary, &x);
42 }
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
static void ExpectToken(const std::string &token, const std::string &what_we_are_parsing, const std::string **next_token)

◆ Write()

void Write ( std::ostream &  os,
bool  binary 
) const

Definition at line 27 of file nnet-common.cc.

References Index::n, Index::t, kaldi::WriteBasicType(), kaldi::WriteToken(), and Index::x.

Referenced by Index::operator+=(), and kaldi::nnet3::WriteIndexVector().

27  {
28  // writing this token will make it easier to write back-compatible code later
29  // on.
30  WriteToken(os, binary, "<I1>");
31  WriteBasicType(os, binary, n);
32  WriteBasicType(os, binary, t);
33  WriteBasicType(os, binary, x);
34 }
void WriteToken(std::ostream &os, bool binary, const char *token)
The WriteToken functions are for writing nonempty sequences of non-space characters.
Definition: io-funcs.cc:134
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

Member Data Documentation

◆ n

◆ t

◆ x


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