34   std::string matrix_in_fn1 = po.
GetArg(1),
    35       matrix_out_fn = po.
GetArg(num_args);
    42   std::vector<RandomAccessBaseFloatMatrixReader*>
    43       matrix_readers(num_args-2,
    44                      static_cast<RandomAccessBaseFloatMatrixReader*>(NULL));
    45   std::vector<std::string> matrix_in_fns(num_args-2);
    46   for (
int32 i = 2; 
i < num_args; ++
i) {
    51   int32 n_utts = 0, n_total_matrices = 0,
    52       n_success = 0, n_missing = 0, n_other_errors = 0;
    54   for (; !matrix_reader1.
Done(); matrix_reader1.
Next()) {
    55     std::string key = matrix_reader1.
Key();
    61     matrix1.
Scale(scale1);
    65     for (
int32 i = 0; 
i < num_args-2; ++
i) {
    66       if (matrix_readers[
i]->HasKey(key)) {
    69         if (
SameDim(matrix2, matrix_out)) {
    74           KALDI_WARN << 
"Dimension mismatch for utterance " << key
    75                      << 
" : " << matrix2.
NumRows() << 
" by "    77                      << 
"system " << (
i + 2) << 
", rspecifier: "    78                      << matrix_in_fns[
i] << 
" vs " << matrix_out.
NumRows()
    79                      << 
" by " << matrix_out.
NumCols()
    80                      << 
" primary matrix, rspecifier:" << matrix_in_fn1;
    84         KALDI_WARN << 
"No matrix found for utterance " << key << 
" for "    85                    << 
"system " << (
i + 2) << 
", rspecifier: "    91     matrix_writer.
Write(key, matrix_out);
    95   KALDI_LOG << 
"Processed " << n_utts << 
" utterances: with a total of "    96             << n_total_matrices << 
" matrices across " << (num_args-1)
    97             << 
" different systems";
    98   KALDI_LOG << 
"Produced output for " << n_success << 
" utterances; "    99             << n_missing << 
" total missing matrices";
   103   return (n_success != 0 && n_missing < (n_success - n_missing)) ? 0 : 1;
   108   std::string matrix_in_fn1 = po.
GetArg(1),
   109       matrix_out_fn = po.
GetArg(num_args);
   117   std::vector<RandomAccessBaseFloatMatrixReader*>
   118       matrix_readers(num_args-2,
   119                      static_cast<RandomAccessBaseFloatMatrixReader*>(NULL));
   120   std::vector<std::string> matrix_in_fns(num_args-2);
   121   for (
int32 i = 2; 
i < num_args; ++
i) {
   126   int32 n_utts = 0, n_total_matrices = 0,
   127       n_success = 0, n_missing = 0, n_other_errors = 0;
   129   for (; !matrix_reader1.
Done(); matrix_reader1.
Next()) {
   130     std::string key = matrix_reader1.
Key();
   136     matrix1.
Scale(scale);
   140     for (
int32 i = 0; 
i < num_args-2; ++
i) {
   141       if (matrix_readers[
i]->HasKey(key)) {
   144         if (
SameDim(matrix2, matrix_out)) {
   147           KALDI_WARN << 
"Dimension mismatch for utterance " << key
   148                      << 
" : " << matrix2.
NumRows() << 
" by "   149                      << matrix2.
NumCols() << 
" for "   150                      << 
"system " << (
i + 2) << 
", rspecifier: "   151                      << matrix_in_fns[
i] << 
" vs " << matrix_out.
NumRows()
   152                      << 
" by " << matrix_out.
NumCols()
   153                      << 
" primary matrix, rspecifier:" << matrix_in_fn1;
   157         KALDI_WARN << 
"No matrix found for utterance " << key << 
" for "   158                    << 
"system " << (
i + 2) << 
", rspecifier: "   164     matrix_writer.
Write(key, matrix_out);
   168   KALDI_LOG << 
"Processed " << n_utts << 
" utterances: with a total of "   169             << n_total_matrices << 
" matrices across " << (num_args-1)
   170             << 
" different systems";
   171   KALDI_LOG << 
"Produced output for " << n_success << 
" utterances; "   172             << n_missing << 
" total missing matrices";
   176   return (n_success != 0 && n_missing < (n_success - n_missing)) ? 0 : 1;
   183                "matrix-sum: first argument must be an rspecifier");
   193   int32 num_done = 0, num_err = 0;
   195   for (; !mat_reader.Done(); mat_reader.Next()) {
   198       KALDI_WARN << 
"Zero matrix input for key " << mat_reader.Key();
   202       if (sum.NumRows() != mat.
NumRows() || sum.NumCols() != mat.
NumCols()) {
   203         KALDI_WARN << 
"Dimension mismatch for key " << mat_reader.Key()
   205                    << sum.NumRows() << 
" by " << sum.NumCols();
   218   KALDI_LOG << 
"Summed " << num_done << 
" matrices, "   219             << num_err << 
" with errors; wrote sum to "   221   return (num_done > 0 && num_err < num_done) ? 0 : 1;
   227                      bool binary, 
bool average) {
   231       KALDI_ERR << 
"Wrong usage (type 3): if first and last arguments are not "   232                 << 
"tables, the intermediate arguments must not be tables.";
   237     KALDI_ERR << 
"Wrong usage (type 3): if first and last arguments are not "   238               << 
"tables, the intermediate arguments must not be tables.";
   250     sum.
AddMat(1.0, this_mat);
   264 int main(
int argc, 
char *argv[]) {
   266     using namespace kaldi;
   270         "Add matrices (supports various forms)\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";
   290     bool average = 
false;
   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.");
   316     } 
else if (po.
NumArgs() == 2 &&
   322         KALDI_ERR << 
"--average option not compatible with type two usage.";
   325     } 
else if (po.
NumArgs() >= 2 &&
   336   } 
catch(
const std::exception &e) {
   337     std::cerr << e.what();
 This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
 
void DeletePointers(std::vector< A *> *v)
Deletes any non-NULL pointers in the vector v, and sets the corresponding entries of v to NULL...
 
RandomAccessTableReader< KaldiObjectHolder< Matrix< BaseFloat > > > RandomAccessBaseFloatMatrixReader
 
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix). 
 
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor]. 
 
void AddMat(const Real alpha, const MatrixBase< Real > &M, MatrixTransposeType transA=kNoTrans)
*this += alpha * M [or M^T] 
 
A templated class for writing objects to an archive or script file; see The Table concept...
 
void Write(const std::string &key, const T &value) const
 
void Register(const std::string &name, bool *ptr, const std::string &doc)
 
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
 
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
 
bool SameDim(const MatrixBase< Real > &M, const MatrixBase< Real > &N)
 
int32 TypeTwoUsage(const ParseOptions &po, bool binary)
 
int32 TypeOneUsageAverage(const ParseOptions &po)
 
int32 TypeOneUsage(const ParseOptions &po, BaseFloat scale1, BaseFloat scale2)
 
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
 
void Scale(Real alpha)
Multiply each element with a scalar value. 
 
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
 
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. 
 
WspecifierType ClassifyWspecifier(const std::string &wspecifier, std::string *archive_wxfilename, std::string *script_wxfilename, WspecifierOptions *opts)
 
int NumArgs() const
Number of positional parameters (c.f. argc-1). 
 
#define KALDI_ASSERT(cond)
 
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix). 
 
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
 
std::string PrintableWxfilename(const std::string &wxfilename)
PrintableWxfilename turns the wxfilename into a more human-readable form for error reporting...
 
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero). 
 
int main(int argc, char *argv[])
 
int32 TypeThreeUsage(const ParseOptions &po, bool binary, bool average)