matrix-dim.cc
Go to the documentation of this file.
1 // bin/matrix-dim.cc
2 
3 // Copyright 2015 Johns Hopkins University (author: Daniel Povey)
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 #include "base/kaldi-common.h"
21 #include "util/common-utils.h"
22 #include "matrix/kaldi-matrix.h"
23 
24 
25 int main(int argc, char *argv[]) {
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 }
71 
72 
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
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
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
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
#define KALDI_WARN
Definition: kaldi-error.h:150
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
int main(int argc, char *argv[])
Definition: matrix-dim.cc:25
int NumArgs() const
Number of positional parameters (c.f. argc-1).
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64