47     const std::vector<Index> &vec,
    50   const Index &index = vec[
i];
    55     if (index.
n == 0 && index.
x == 0 &&
    56         index.
t > -125 && index.
t < 125) {
    58       os.put(static_cast<signed char>(index.
t));
    66     Index last_index = vec[i-1];
    70     if (index.
n == last_index.
n && index.
x == last_index.
x &&
    71         index.
t - last_index.
t < 125 &&
    72         index.
t - last_index.
t > -125) {
    73       signed char c = index.
t - last_index.
t;
    83     KALDI_ERR << 
"Output stream error detected";
    90     std::vector<Index> *vec) {
    94     KALDI_ERR << 
"End of file while reading vector of Index.";
    95   signed char c = is.get();
    97     if (std::abs(
int(c)) < 125) {
   103         KALDI_ERR << 
"Unexpected character " << c
   104                   << 
" encountered while reading Index vector.";
   110     Index &last_index = (*vec)[i-1];
   111     if (std::abs(
int(c)) < 125) {
   112       index.
n = last_index.
n;
   113       index.
t = last_index.
t + c;
   114       index.
x = last_index.
x;
   117         KALDI_ERR << 
"Unexpected character " << c
   118                   << 
" encountered while reading Index vector.";
   127                       const std::vector<Index> &vec) {
   131   int32 size = vec.size();
   144                      std::vector<Index> *vec) {
   149     KALDI_ERR << 
"Error reading Index vector: size = "   155       (*vec)[
i].Read(is, binary);
   164     const std::vector<Cindex> &vec,
   167   int32 node_index = vec[
i].first;
   168   const Index &index = vec[
i].second;
   169   if (i == 0 || node_index != vec[i-1].first) {
   184     if (index.
n == 0 && index.
x == 0 &&
   185         index.
t > -125 && index.
t < 125) {
   187       os.put(static_cast<signed char>(index.
t));
   188     } 
else if (index.
t == 0 && index.
x == 0 &&
   189                (index.
n == 0 || index.
n == 1)) {
   191       os.put(static_cast<signed char>(index.
n + 125));
   199     const Index &last_index = vec[i-1].second;
   203     if (index.
n == last_index.
n && index.
x == last_index.
x &&
   204         index.
t - last_index.
t < 124 &&
   205         index.
t - last_index.
t > -124) {
   206       signed char c = index.
t - last_index.
t;
   210     } 
else if (index.
t == last_index.
t && index.
x == last_index.
x &&
   211               (index.
n == last_index.
n || index.
n == last_index.
n + 1)) {
   212       os.put(125 + index.
n - last_index.
n);
   221     KALDI_ERR << 
"Output stream error detected";
   227     std::vector<Cindex> *vec) {
   229   Index &index = (*vec)[
i].second;
   231     KALDI_ERR << 
"End of file while reading vector of Cindex.";
   232   if (is.peek() == 
static_cast<int>(
'|')) {
   237     (*vec)[
i].first = (*vec)[i-1].first;
   239   signed char c = is.get();
   241     if (std::abs(
int(c)) < 125) {
   245     } 
else if (c == 125 || c == 126) {
   251         KALDI_ERR << 
"Unexpected character " << c
   252                   << 
" encountered while reading Cindex vector.";
   258     Index &last_index = (*vec)[i-1].second;
   259     if (std::abs(
int(c)) < 124) {
   260       index.
n = last_index.
n;
   261       index.
t = last_index.
t + c;
   262       index.
x = last_index.
x;
   263     } 
else if (c == 125 || c == 126) {
   264       index.
n = last_index.
n + c - 125;
   265       index.
t = last_index.
t;
   266       index.
x = last_index.
x;
   269         KALDI_ERR << 
"Unexpected character " << c
   270                   << 
" encountered while reading Cindex vector.";
   283                        const std::vector<Cindex> &vec) {
   287   int32 size = vec.size();
   291       int32 node_index = vec[
i].first;
   292       if (
i == 0 || node_index != vec[
i-1].first) {
   299       vec[
i].second.Write(os, binary);
   310                       std::vector<Cindex> *vec) {
   315     KALDI_ERR << 
"Error reading Index vector: size = "   322       if (is.peek() == 
static_cast<int>(
']') || 
i == 0) {
   326         if (is.peek() == 
static_cast<int>(
'[')) {
   329           KALDI_ERR << 
"ReadCintegerVector: expected to see [, saw "   330                     << is.peek() << 
", at file position " << is.tellg();
   334         if (is.peek() == 
static_cast<int>(
':')) {
   337           KALDI_ERR << 
"ReadCintegerVector: expected to see :, saw "   338                     << is.peek() << 
", at file position " << is.tellg();
   341         (*vec)[
i].first = (*vec)[
i-1].first;
   343       (*vec)[
i].second.Read(is, binary);
   346         if (is.peek() == 
static_cast<int>(
']')) {
   349           KALDI_ERR << 
"ReadCintegerVector: expected to see ], saw "   350                     << is.peek() << 
", at file position " << is.tellg();
   369   return cindex.first +
   370        1619 * cindex.second.n +
   371       15649 * cindex.second.t +
   372       89809 * cindex.second.x;
   377     const std::vector<Cindex> &cindex_vector) 
const noexcept {
   379   size_t kPrime = 23539, ans = 0;
   380   std::vector<Cindex>::const_iterator iter = cindex_vector.begin(),
   381       end = cindex_vector.end();
   383   for (; iter != end; ++iter)
   384     ans = cindex_hasher(*iter) + kPrime * ans;
   389     const std::vector<Index> &index_vector) 
const noexcept {
   390   size_t n1 = 15, n2 = 10;  
   395   size_t len = index_vector.size();
   397   size_t ans = 1433 + 34949 * len;
   398   std::vector<Index>::const_iterator iter = index_vector.begin(),
   399       end = index_vector.end(), med = end;
   403   for (; iter != med; ++iter) {
   404     ans += iter->n * 1619;
   405     ans += iter->t * 15649;
   406     ans += iter->x * 89809;
   412   for (; iter < end; iter += n2) {
   413     ans += iter->n * 1619;
   414     ans += iter->t * 15649;
   415     ans += iter->x * 89809;
   418     if (n2 > len || iter >= end - n2) 
   425   return ostream << 
'(' << index.
n << 
' ' << index.
t << 
' ' << index.
x << 
')';
   429   return ostream << 
'(' << cindex.first << 
' ' << cindex.second << 
')';
   433                  const std::vector<std::string> &node_names) {
   434   KALDI_ASSERT(static_cast<size_t>(cindex.first) < node_names.size());
   435   os << node_names[cindex.first] << 
"(" << cindex.second.n << 
","   437   if (cindex.second.x != 0)
   438     os << 
"," << cindex.second.x;
   443                   const std::vector<Index> &indexes) {
   444   if (indexes.empty()) {
   450   size_t max_string_length = 200;
   451   std::ostringstream os_temp;
   456   std::vector<int32> range_starts;
   457   int32 cur_start = 0, end = indexes.size();
   458   for (
int32 i = cur_start; 
i < end; 
i++) {
   459     const Index &index = indexes[
i];
   461         (index.
t != indexes[
i-1].t + 1 ||
   462          index.
n != indexes[
i-1].n ||
   463          index.
x != indexes[
i-1].x)) {
   464       range_starts.push_back(cur_start);
   468   range_starts.push_back(cur_start);
   469   range_starts.push_back(end);
   471   int32 num_ranges = range_starts.size() - 1;
   472   for (
int32 r = 0; r < num_ranges; r++) {
   473     int32 range_start = range_starts[r], range_end = range_starts[r+1];
   475     os_temp << 
"(" << indexes[range_start].n << 
",";
   476     if (range_end == range_start + 1)
   477       os_temp << indexes[range_start].t;
   479       os_temp << indexes[range_start].t << 
":" << indexes[range_end - 1].t;
   480     if (indexes[range_start].
x != 0)
   481       os_temp << 
"," << indexes[range_start].x;
   483     if (r + 1 < num_ranges)
   488   std::string str = os_temp.str();
   489   if (str.size() <= max_string_length) {
   492     size_t len = str.size();
   493     os << str.substr(0, max_string_length / 2) << 
" ... "   494        << str.substr(len - max_string_length / 2);
   499                    const std::vector<Cindex> &cindexes,
   500                    const std::vector<std::string> &node_names) {
   501   int32 num_cindexes = cindexes.size();
   502   if (num_cindexes == 0) {
   506   int32 cur_offset = 0;
   507   std::vector<Index> indexes;
   508   indexes.reserve(cindexes.size());
   509   while (cur_offset < num_cindexes) {
   510     int32 cur_node_index = cindexes[cur_offset].first;
   511     while (cur_offset < num_cindexes &&
   512            cindexes[cur_offset].first == cur_node_index) {
   513       indexes.push_back(cindexes[cur_offset].second);
   516     KALDI_ASSERT(static_cast<size_t>(cur_node_index) < node_names.size());
   517     const std::string &node_name = node_names[cur_node_index];
   518     ostream << node_name;
   526                         const std::vector<int32> &ints) {
   534   std::vector<int32> range_starts;
   535   int32 cur_start = 0, end = ints.size();
   536   for (
int32 i = cur_start; 
i < end; 
i++) {
   538       int32 range_start_val = ints[cur_start],
   539           range_start_plus_one_val = ints[cur_start+1],
   542       if (!((range_start_plus_one_val == range_start_val &&
   543              cur_val == range_start_val) ||
   544             (range_start_plus_one_val == range_start_val + 1 &&
   545              cur_val == range_start_val + 
i - cur_start))) {
   546         range_starts.push_back(cur_start);
   551   range_starts.push_back(cur_start);
   552   range_starts.push_back(end);
   554   int32 num_ranges = range_starts.size() - 1;
   555   for (
int32 r = 0; r < num_ranges; r++) {
   556     int32 range_start = range_starts[r], range_end = range_starts[r+1];
   558     if (range_end == range_start + 1)
   559       os << ints[range_start];
   560     else if (range_end == range_start + 2)  
   561       os << ints[range_start] << 
", " << ints[range_start+1];
   562     else if (ints[range_start] == ints[range_start+1])
   563       os << ints[range_start] << 
"x" << (range_end - range_start);
   565       os << ints[range_start] << 
":" << ints[range_end - 1];
   566     if (r + 1 < num_ranges)
   573 const int kNoTime = std::numeric_limits<int32>::min();
 This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
 
void WriteIndexVector(std::ostream &os, bool binary, const std::vector< Index > &vec)
 
size_t operator()(const std::vector< Cindex > &cindex_vector) const noexcept
 
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...
 
static void WriteIndexVectorElementBinary(std::ostream &os, const std::vector< Index > &vec, int32 i)
 
void PrintCindex(std::ostream &os, const Cindex &cindex, const std::vector< std::string > &node_names)
 
void ReadCindexVector(std::istream &is, bool binary, std::vector< Cindex > *vec)
 
void PrintIndexes(std::ostream &os, const std::vector< Index > &indexes)
this will only be used for pretty-printing. 
 
std::ostream & operator<<(std::ostream &ostream, const Index &index)
 
static void ReadIndexVectorElementBinary(std::istream &is, int32 i, std::vector< Index > *vec)
 
struct Index is intended to represent the various indexes by which we number the rows of the matrices...
 
std::pair< int32, Index > Cindex
 
void Read(std::istream &os, bool binary)
 
void WriteCindexVector(std::ostream &os, bool binary, const std::vector< Cindex > &vec)
 
static void ExpectToken(const std::string &token, const std::string &what_we_are_parsing, const std::string **next_token)
 
void Write(std::ostream &os, bool binary) const
 
static void ReadCindexVectorElementBinary(std::istream &is, int32 i, std::vector< Cindex > *vec)
 
size_t operator()(const Cindex &cindex) const noexcept
 
void PrintIntegerVector(std::ostream &os, const std::vector< int32 > &ints)
 
size_t operator()(const Index &cindex) const noexcept
 
void WriteToken(std::ostream &os, bool binary, const char *token)
The WriteToken functions are for writing nonempty sequences of non-space characters. 
 
void ReadIndexVector(std::istream &is, bool binary, std::vector< Index > *vec)
 
void PrintCindexes(std::ostream &ostream, const std::vector< Cindex > &cindexes, const std::vector< std::string > &node_names)
this will only be used for pretty-printing. 
 
#define KALDI_ASSERT(cond)
 
static void WriteCindexVectorElementBinary(std::ostream &os, const std::vector< Cindex > &vec, int32 i)
 
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...
 
size_t operator()(const std::vector< Index > &index_vector) const noexcept