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

Go to the source code of this file.

Namespaces

 kaldi
 This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for mispronunciations detection tasks, the reference:
 

Functions

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

Function Documentation

◆ main()

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

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

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

264  {
265  try {
266  using namespace kaldi;
267 
268 
269  const char *usage =
270  "Add matrices (supports various forms)\n"
271  "\n"
272  "Type one usage:\n"
273  " matrix-sum [options] <matrix-in-rspecifier1> [<matrix-in-rspecifier2>"
274  " <matrix-in-rspecifier3> ...] <matrix-out-wspecifier>\n"
275  " e.g.: matrix-sum ark:1.weights ark:2.weights ark:combine.weights\n"
276  " This usage supports the --scale1 and --scale2 options to scale the\n"
277  " first two input tables.\n"
278  "Type two usage (sums a single table input to produce a single output):\n"
279  " matrix-sum [options] <matrix-in-rspecifier> <matrix-out-wxfilename>\n"
280  " e.g.: matrix-sum --binary=false mats.ark sum.mat\n"
281  "Type three usage (sums or averages single-file inputs to produce\n"
282  "a single output):\n"
283  " matrix-sum [options] <matrix-in-rxfilename1> <matrix-in-rxfilename2> ..."
284  " <matrix-out-wxfilename>\n"
285  " e.g.: matrix-sum --binary=false 1.mat 2.mat 3.mat sum.mat\n"
286  "See also: matrix-sum-rows, copy-matrix\n";
287 
288 
289  BaseFloat scale1 = 1.0, scale2 = 1.0;
290  bool average = false;
291  bool binary = true;
292 
293  ParseOptions po(usage);
294 
295  po.Register("scale1", &scale1, "Scale applied to first matrix "
296  "(only for type one usage)");
297  po.Register("scale2", &scale2, "Scale applied to second matrix "
298  "(only for type one usage)");
299  po.Register("binary", &binary, "If true, write output as binary (only "
300  "relevant for usage types two or three");
301  po.Register("average", &average, "If true, compute average instead of "
302  "sum; currently compatible with type 3 or type 1 usage.");
303 
304  po.Read(argc, argv);
305 
306  int32 N = po.NumArgs(), exit_status;
307 
308  if (po.NumArgs() >= 2 &&
309  ClassifyWspecifier(po.GetArg(N), NULL, NULL, NULL) != kNoWspecifier) {
310  if (average)
311  // average option with type one usage.";
312  exit_status = TypeOneUsageAverage(po);
313  else
314  // output to table.
315  exit_status = TypeOneUsage(po, scale1, scale2);
316  } else if (po.NumArgs() == 2 &&
317  ClassifyRspecifier(po.GetArg(1), NULL, NULL) != kNoRspecifier &&
318  ClassifyWspecifier(po.GetArg(N), NULL, NULL, NULL) ==
319  kNoWspecifier) {
320  KALDI_ASSERT(scale1 == 1.0 && scale2 == 1.0);
321  if (average)
322  KALDI_ERR << "--average option not compatible with type two usage.";
323  // input from a single table, output not to table.
324  exit_status = TypeTwoUsage(po, binary);
325  } else if (po.NumArgs() >= 2 &&
326  ClassifyRspecifier(po.GetArg(1), NULL, NULL) == kNoRspecifier &&
327  ClassifyWspecifier(po.GetArg(N), NULL, NULL, NULL) == kNoWspecifier) {
328  KALDI_ASSERT(scale1 == 1.0 && scale2 == 1.0);
329  // summing flat files.
330  exit_status = TypeThreeUsage(po, binary, average);
331  } else {
332  po.PrintUsage();
333  exit(1);
334  }
335  return exit_status;
336  } catch(const std::exception &e) {
337  std::cerr << e.what();
338  return -1;
339  }
340 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
kaldi::int32 int32
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
Definition: kaldi-table.cc:225
int32 TypeTwoUsage(const ParseOptions &po, bool binary)
Definition: matrix-sum.cc:179
int32 TypeOneUsageAverage(const ParseOptions &po)
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
#define KALDI_ERR
Definition: kaldi-error.h:147
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:185
int32 TypeThreeUsage(const ParseOptions &po, bool binary, bool average)
Definition: matrix-sum.cc:226