All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
matrix-sum.cc File Reference
Include dependency graph for matrix-sum.cc:

Go to the source code of this file.

Namespaces

 kaldi
 Relabels neural network egs with the read pdf-id alignments.
 

Functions

int32 TypeOneUsage (const ParseOptions &po, BaseFloat scale1, BaseFloat scale2)
 
int32 TypeTwoUsage (const ParseOptions &po, bool binary)
 
int32 TypeThreeUsage (const ParseOptions &po, bool binary)
 
int main (int argc, char *argv[])
 

Function Documentation

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

Definition at line 186 of file matrix-sum.cc.

References kaldi::ClassifyRspecifier(), kaldi::ClassifyWspecifier(), ParseOptions::GetArg(), KALDI_ASSERT, kaldi::kNoRspecifier, kaldi::kNoWspecifier, ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), ParseOptions::Register(), kaldi::TypeOneUsage(), kaldi::TypeThreeUsage(), and kaldi::TypeTwoUsage().

186  {
187  try {
188  using namespace kaldi;
189 
190 
191  const char *usage =
192  "Add matrices (supports various forms)\n"
193  "\n"
194  "Type one usage:\n"
195  " matrix-sum [options] <matrix-in-rspecifier1> [<matrix-in-rspecifier2>"
196  " <matrix-in-rspecifier3> ...] <matrix-out-wspecifier>\n"
197  " e.g.: matrix-sum ark:1.weights ark:2.weights ark:combine.weights\n"
198  " This usage supports the --scale1 and --scale2 options to scale the\n"
199  " first two input tables.\n"
200  "Type two usage (sums a single table input to produce a single output):\n"
201  " matrix-sum [options] <matrix-in-rspecifier> <matrix-out-wxfilename>\n"
202  " e.g.: matrix-sum --binary=false mats.ark sum.mat\n"
203  "Type three usage (sums single-file inputs to produce a single output):\n"
204  " matrix-sum [options] <matrix-in-rxfilename1> <matrix-in-rxfilename2> ..."
205  " <matrix-out-wxfilename>\n"
206  " e.g.: matrix-sum --binary=false 1.mat 2.mat 3.mat sum.mat\n"
207  "See also: matrix-sum-rows\n";
208 
209 
210  BaseFloat scale1 = 1.0, scale2 = 1.0;
211  bool binary = true;
212 
213  ParseOptions po(usage);
214 
215  po.Register("scale1", &scale1, "Scale applied to first matrix "
216  "(only for type one usage)");
217  po.Register("scale2", &scale2, "Scale applied to second matrix "
218  "(only for type one usage)");
219  po.Register("binary", &binary, "If true, write output as binary (only "
220  "relevant for usage types two or three");
221 
222  po.Read(argc, argv);
223 
224  int32 N = po.NumArgs(), exit_status;
225 
226  if (po.NumArgs() >= 2 &&
227  ClassifyWspecifier(po.GetArg(N), NULL, NULL, NULL) != kNoWspecifier) {
228  // output to table.
229  exit_status = TypeOneUsage(po, scale1, scale2);
230  } else if (po.NumArgs() == 2 &&
231  ClassifyRspecifier(po.GetArg(1), NULL, NULL) != kNoRspecifier &&
232  ClassifyWspecifier(po.GetArg(N), NULL, NULL, NULL) ==
233  kNoWspecifier) {
234  KALDI_ASSERT(scale1 == 1.0 && scale2 == 1.0);
235  // input from a single table, output not to table.
236  exit_status = TypeTwoUsage(po, binary);
237  } else if (po.NumArgs() >= 2 &&
238  ClassifyRspecifier(po.GetArg(1), NULL, NULL) == kNoRspecifier &&
239  ClassifyWspecifier(po.GetArg(N), NULL, NULL, NULL) == kNoWspecifier) {
240  KALDI_ASSERT(scale1 == 1.0 && scale2 == 1.0);
241  // summing flat files.
242  exit_status = TypeThreeUsage(po, binary);
243  } else {
244  po.PrintUsage();
245  exit(1);
246  }
247  return exit_status;
248  } catch(const std::exception &e) {
249  std::cerr << e.what();
250  return -1;
251  }
252 }
Relabels neural network egs with the read pdf-id alignments.
Definition: chain.dox:20
int32 TypeTwoUsage(const ParseOptions &po, bool binary)
Definition: matrix-sum.cc:106
int32 TypeOneUsage(const ParseOptions &po, BaseFloat scale1, BaseFloat scale2)
Definition: matrix-sum.cc:30
float BaseFloat
Definition: kaldi-types.h:29
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
int32 TypeThreeUsage(const ParseOptions &po, bool binary)
Definition: matrix-sum.cc:153
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *wxfilename, RspecifierOptions *opts)
Definition: kaldi-table.cc:225
WspecifierType ClassifyWspecifier(const std::string &wspecifier, std::string *archive_wxfilename, std::string *script_wxfilename, WspecifierOptions *opts)
Definition: kaldi-table.cc:135
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169