29 if (new_dimension < d)
30 KALDI_ERR <<
"--new-dimension argument invalid or not specified: " 31 << new_dimension <<
" < " <<
d;
34 for (
int32 i = d;
i < new_dimension;
i++)
36 }
else if (mat->
NumCols() == d+1) {
41 for (
int32 i = d;
i < new_dimension;
i++)
44 (*mat)(
i, new_dimension) = offset(
i);
46 KALDI_ERR <<
"Input matrix has unexpected dimension " << d
54 int main(
int argc,
char *argv[]) {
56 using namespace kaldi;
59 "Read in transform from dimension d -> d (affine or linear), and output a transform\n" 60 "from dimension e -> e (with e >= d, and e controlled by option --new-dimension).\n" 61 "This new transform will leave the extra dimension unaffected, and transform the old\n" 62 "dimensions in the same way.\n" 63 "Usage: extend-transform-dim [options] (transform-A-rspecifier|transform-A-rxfilename) (transform-out-wspecifier|transform-out-wxfilename)\n" 64 "E.g.: extend-transform-dim --new-dimension=117 in.mat big.mat\n";
67 int32 new_dimension = -1;
70 po.
Register(
"binary", &binary,
"Write in binary mode (only relevant if output is a wxfilename)");
71 po.
Register(
"new-dimension", &new_dimension,
72 "Larger dimension we are changing matrix to");
81 std::string transform_in_fn = po.
GetArg(1);
82 std::string transform_out_fn = po.
GetArg(2);
85 bool in_is_rspecifier =
92 if (in_is_rspecifier != out_is_wspecifier)
93 KALDI_ERR <<
"Either none or both of the (input, output) must be a Table.";
95 if (in_is_rspecifier) {
99 for (; !reader.
Done(); reader.
Next()) {
100 std::string key = reader.
Key();
103 writer.
Write(key, mat);
106 KALDI_LOG <<
"Increased transform dim to " << new_dimension
107 <<
" for " << num_done <<
" matrices.";
108 return (num_done != 0 ? 0 : 1);
115 KALDI_LOG <<
"Increased transform dim from " << old_dim <<
" to " 116 << mat.
NumRows() <<
" and wrote to " << transform_out_fn;
119 }
catch(
const std::exception &e) {
120 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
A templated class for writing objects to an archive or script file; see The Table concept...
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
WspecifierType ClassifyWspecifier(const std::string &wspecifier, std::string *archive_wxfilename, std::string *script_wxfilename, WspecifierOptions *opts)
int NumArgs() const
Number of positional parameters (c.f. argc-1).
void CopyColFromMat(const MatrixBase< OtherReal > &M, MatrixIndexT col)
Extracts a column of the matrix M.
A class representing a vector.
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
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).
void IncreaseTransformDimension(int32 new_dimension, Matrix< BaseFloat > *mat)