34 const int rows,
const int cols,
35 std::vector<int32> *row_range,
36 std::vector<int32> *col_range) {
41 std::vector<std::string> splits;
43 if (!((splits.size() == 1 && !splits[0].empty()) ||
44 (splits.size() == 2 && !splits[0].empty() && !splits[1].empty()))) {
45 KALDI_ERR <<
"Invalid range specifier for matrix: " << range;
54 if (splits.size() == 2 && splits[1] !=
":") {
57 if (row_range->size() == 0) {
58 row_range->push_back(0);
59 row_range->push_back(rows - 1);
61 if (col_range->size() == 0) {
62 col_range->push_back(0);
63 col_range->push_back(cols - 1);
69 int32 length_tolerance = 3;
70 if (!(status && row_range->size() == 2 && col_range->size() == 2 &&
71 row_range->at(0) >= 0 && row_range->at(0) <= row_range->at(1) &&
72 row_range->at(1) < rows + length_tolerance &&
73 col_range->at(0) >=0 &&
74 col_range->at(0) <= col_range->at(1) && col_range->at(1) < cols)) {
75 KALDI_ERR <<
"Invalid range specifier: " << range
76 <<
" for matrix of size " << rows
81 if (row_range->at(1) >= rows)
82 KALDI_WARN <<
"Row range " << row_range->at(0) <<
":" << row_range->at(1)
83 <<
" goes beyond the number of rows of the " 116 std::vector<int32> row_range, col_range;
119 &row_range, &col_range)) {
120 KALDI_ERR <<
"Could not parse range specifier \"" << range <<
"\".";
123 int32 row_size = std::min(row_range[1], input.
NumRows() - 1)
125 col_size = col_range[1] - col_range[0] + 1;
128 input.
CopyToMat(row_range[0], col_range[0], output);
141 std::vector<int32> row_range, col_range;
144 &row_range, &col_range)) {
145 KALDI_ERR <<
"Could not parse range specifier \"" << range <<
"\".";
148 int32 row_size = std::min(row_range[1], input.
NumRows() - 1)
150 col_size = col_range[1] - col_range[0] + 1;
153 col_range[0], col_size));
170 std::vector<std::string> splits;
172 if (!((splits.size() == 1 && !splits[0].empty()))) {
173 KALDI_ERR <<
"Invalid range specifier for vector: " << range;
176 std::vector<int32> index_range;
178 if (splits[0] !=
":")
181 if (index_range.size() == 0) {
182 index_range.push_back(0);
183 index_range.push_back(input.
Dim() - 1);
189 int32 length_tolerance = 3;
190 if (!(status && index_range.size() == 2 &&
191 index_range[0] >= 0 && index_range[0] <= index_range[1] &&
192 index_range[1] < input.
Dim() + length_tolerance)) {
193 KALDI_ERR <<
"Invalid range specifier: " << range
194 <<
" for vector of size " << input.
Dim();
198 if (index_range[1] >= input.
Dim())
199 KALDI_WARN <<
"Range " << index_range[0] <<
":" << index_range[1]
200 <<
" goes beyond the vector dimension " << input.
Dim();
201 int32 size = std::min(index_range[1], input.
Dim() - 1) - index_range[0] + 1;
214 std::string *data_rxfilename,
215 std::string *range) {
216 if (rxfilename_with_range.empty() ||
217 rxfilename_with_range[rxfilename_with_range.size()-1] !=
']')
218 KALDI_ERR <<
"ExtractRangeRspecifier called wrongly.";
219 std::vector<std::string> splits;
221 if (splits.size() == 2 && !splits[0].empty() && splits[1].size() > 1) {
222 *data_rxfilename = splits[0];
223 range->assign(splits[1], 0, splits[1].size()-1);
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
This class is a wrapper that enables you to store a matrix in one of three forms: either as a Matrix<...
void GetMatrix(Matrix< BaseFloat > *mat) const
Outputs the contents as a matrix.
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
bool SplitStringToIntegers(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< I > *out)
Split a string (e.g.
const CompressedMatrix & GetCompressedMatrix() const
Returns the contents as a compressed matrix.
const Matrix< BaseFloat > & GetFullMatrix() const
Returns the contents as a Matrix<BaseFloat>.
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
void CopyFromMat(const MatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans)
Copy given matrix. (no resize is done).
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
bool ExtractObjectRange(const GeneralMatrix &input, const std::string &range, GeneralMatrix *output)
GeneralMatrix is always of type BaseFloat.
GeneralMatrixType Type() const
Returns the type of the matrix: kSparseMatrix, kCompressedMatrix or kFullMatrix.
void SplitStringToVector(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< std::string > *out)
Split a string using any of the single character delimiters.
MatrixIndexT Dim() const
Returns the dimension of the vector.
A class representing a vector.
MatrixIndexT NumRows() const
Returns number of rows (or zero for emtpy matrix).
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void SwapFullMatrix(Matrix< BaseFloat > *mat)
Swaps the with the given Matrix.
SubMatrix< Real > Range(const MatrixIndexT row_offset, const MatrixIndexT num_rows, const MatrixIndexT col_offset, const MatrixIndexT num_cols) const
Return a sub-part of matrix.
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).
bool ExtractRangeSpecifier(const std::string &rxfilename_with_range, std::string *data_rxfilename, std::string *range)
MatrixIndexT NumCols() const
Returns number of columns (or zero for emtpy matrix).
void CopyToMat(MatrixBase< Real > *mat, MatrixTransposeType trans=kNoTrans) const
Copies contents to matrix.
bool ParseMatrixRangeSpecifier(const std::string &range, const int rows, const int cols, std::vector< int32 > *row_range, std::vector< int32 > *col_range)
SubVector< Real > Range(const MatrixIndexT o, const MatrixIndexT l)
Returns a sub-vector of a vector (a range of elements).