sum-matrices.cc
Go to the documentation of this file.
1 // bin/sum-matrices.cc
2 
3 // Copyright 2012 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 
23 
24 int main(int argc, char *argv[]) {
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 }
64 
65 
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.
int main(int argc, char *argv[])
Definition: sum-matrices.cc:24
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
void Register(const std::string &name, bool *ptr, const std::string &doc)
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
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.
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
#define KALDI_LOG
Definition: kaldi-error.h:153