matrix-dim.cc File Reference
Include dependency graph for matrix-dim.cc:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 25 of file matrix-dim.cc.

References kaldi::ClassifyRspecifier(), SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), KALDI_WARN, SequentialTableReader< Holder >::Key(), kaldi::kNoRspecifier, SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), ParseOptions::PrintUsage(), ParseOptions::Read(), kaldi::ReadKaldiObject(), and SequentialTableReader< Holder >::Value().

25  {
26  try {
27  using namespace kaldi;
28 
29  const char *usage =
30  "Print dimension info on an input matrix (rows then cols, separated by tab), to\n"
31  "standard output. Output for single filename: rows[tab]cols. Output per line for\n"
32  "archive of files: key[tab]rows[tab]cols\n"
33  "Usage: matrix-dim [options] <matrix-in>|<in-rspecifier>\n"
34  "e.g.: matrix-dim final.mat | cut -f 2\n"
35  "See also: feat-to-len, feat-to-dim\n";
36 
37  ParseOptions po(usage);
38 
39  po.Read(argc, argv);
40 
41  if (po.NumArgs() != 1) {
42  po.PrintUsage();
43  exit(1);
44  }
45 
46  if (ClassifyRspecifier(po.GetArg(1), NULL, NULL) != kNoRspecifier) {
47  std::string matrix_rspecifier = po.GetArg(1);
48  SequentialBaseFloatMatrixReader matrix_reader(matrix_rspecifier);
49  int32 num_read = 0;
50  for (; !matrix_reader.Done(); matrix_reader.Next(), num_read++) {
51  const Matrix<BaseFloat> &mat = matrix_reader.Value();
52  std::cout << matrix_reader.Key() << '\t'
53  << mat.NumRows() << '\t' << mat.NumCols() << '\n';
54  }
55  if (num_read == 0)
56  KALDI_WARN << "No features read from rspecifier '"
57  << matrix_rspecifier << "'";
58  return (num_read == 0 ? 1 : 0);
59  } else {
60  std::string matrix_rxfilename = po.GetArg(1);
62  ReadKaldiObject(matrix_rxfilename, &mat);
63  std::cout << mat.NumRows() << '\t' << mat.NumCols() << '\n';
64  return 0;
65  }
66  } catch(const std::exception &e) {
67  std::cerr << e.what();
68  return -1;
69  }
70 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
kaldi::int32 int32
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
Definition: kaldi-table.cc:225
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
Definition: kaldi-io.cc:832
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
#define KALDI_WARN
Definition: kaldi-error.h:150
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64