sum-matrices.cc File Reference
Include dependency graph for sum-matrices.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 24 of file sum-matrices.cc.

References ParseOptions::GetArg(), rnnlm::i, KALDI_LOG, ParseOptions::NumArgs(), MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), ParseOptions::PrintUsage(), ParseOptions::Read(), Matrix< Real >::Read(), ParseOptions::Register(), and MatrixBase< Real >::Write().

24  {
25  using namespace kaldi;
26  typedef kaldi::int32 int32;
27  try {
28  const char *usage =
29  "Sum matrices, e.g. stats for fMPE training\n"
30  "Usage: sum-matrices [options] <mat-out> <mat-in1> <mat-in2> ...\n"
31  "e.g.:\n"
32  " sum-matrices mat 1.mat 2.mat 3.mat\n";
33 
34  ParseOptions po(usage);
35  bool binary = true;
36 
37  po.Register("binary", &binary, "Write output in binary mode");
38  po.Read(argc, argv);
39 
40  if (po.NumArgs() < 2) {
41  po.PrintUsage();
42  exit(1);
43  }
44 
46 
47  for (int32 i = 2; i <= po.NumArgs(); i++) {
48  bool binary_in;
49  Input ki(po.GetArg(i), &binary_in);
50  mat.Read(ki.Stream(), binary_in, true); // true == add.
51  // This will crash if dimensions do not match.
52  }
53 
54  Output ko(po.GetArg(1), binary);
55  mat.Write(ko.Stream(), binary);
56 
57  KALDI_LOG << "Summed " << (po.NumArgs()-1) << " matrices "
58  << " of dimension " << mat.NumRows() << " by " << mat.NumCols();
59  } catch(const std::exception &e) {
60  std::cerr << e.what();
61  return -1;
62  }
63 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void Write(std::ostream &out, bool binary) const
write to stream.
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
kaldi::int32 int32
void Read(std::istream &in, bool binary, bool add=false)
read from stream.
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
#define KALDI_LOG
Definition: kaldi-error.h:153