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

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 26 of file vector-scale.cc.

References SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), ParseOptions::Register(), VectorBase< Real >::Scale(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

26  {
27  try {
28  using namespace kaldi;
29 
30  const char *usage =
31  "Scale a set of vectors in a Table (useful for speaker vectors and "
32  "per-frame weights)\n"
33  "Usage: vector-scale [options] <in-rspecifier> <out-wspecifier>\n";
34 
35  ParseOptions po(usage);
36  BaseFloat scale = 1.0;
37 
38  po.Register("scale", &scale, "Scaling factor for vectors");
39  po.Read(argc, argv);
40 
41  if (po.NumArgs() != 2) {
42  po.PrintUsage();
43  exit(1);
44  }
45 
46  std::string rspecifier = po.GetArg(1);
47  std::string wspecifier = po.GetArg(2);
48 
49  BaseFloatVectorWriter vec_writer(wspecifier);
50 
51  SequentialBaseFloatVectorReader vec_reader(rspecifier);
52  for (; !vec_reader.Done(); vec_reader.Next()) {
53  Vector<BaseFloat> vec(vec_reader.Value());
54  vec.Scale(scale);
55  vec_writer.Write(vec_reader.Key(), vec);
56  }
57  return 0;
58  } catch(const std::exception &e) {
59  std::cerr << e.what();
60  return -1;
61  }
62 }
Relabels neural network egs with the read pdf-id alignments.
Definition: chain.dox:20
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:366
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
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
void Scale(Real alpha)
Multiplies all elements by this constant.