20 sprintf (tmp,
"%s", ctime (&t) );
21 tmp[strlen (tmp) - 1] =
' ';
22 tmp[strlen (tmp)] = 0;
23 return std::string (tmp);
26 void ReplacePattern (std::string& newname, std::string pattern,
const char *pat,
28 std::string::size_type pos = 0;
31 while ( (pos = newname.find (pat, pos) ) != std::string::npos) {
32 newname.replace (pos, i, rep);
36 void ReplacePattern (std::string& newname, std::string pattern,
const char *pat,
38 std::ostringstream si;
44 void ReplacePattern (std::string& newname, std::string pattern,
const char *pat,
46 std::ostringstream si;
51 std::string
ExpandPath (std::string pattern,
const int idx) {
57 unsigned int idxmin = 0;
58 unsigned int idxmax = 0;
59 sscanf (range.c_str(),
"%d:%d", &idxmin, &idxmax);
60 for (
unsigned int idx = idxmin; idx <= idxmax; idx++) {
66 std::ifstream ifs (filename.c_str() );
68 std::cerr <<
"ERROR: unable to open file " << filename <<
'\n';
79 for (
unsigned int i = 0; i < s.size(); ++i) {
88 static const char* CMD_LINE_TOKEN_FILE =
"file:";
89 static const char* CMD_LINE_TOKEN_RANDOM =
"random";
92 std::vector<PARAMS> vws;
93 std::ifstream ifs (filename.c_str() );
95 cerr <<
"ERROR: unable to open file " << filename <<
'\n';
109 std::vector<PARAMS> vws;
110 for (
unsigned int k = 0; k < dim; ++k) {
112 for (
unsigned int i = 0; i < dim; ++i) {
116 vws.push_back (axis);
122 cerr <<
"ERROR: 'random' vector initialization not supported";
127 std::vector<PARAMS> vws;
128 if (pattern.find (CMD_LINE_TOKEN_FILE) == 0) {
129 std::string filename = pattern.substr (strlen (CMD_LINE_TOKEN_FILE) );
141 std::ifstream ifs (filename.c_str() );
143 cerr <<
"ERROR: unable to open file " << filename <<
'\n';
153 char separator =
',';
154 for (uint k = 0; k < vw.size(); ++k) {
164 if (vw1.size() != vw2.size() ) {
165 cerr <<
"Cannot subtract two vectors of different sizes. V1: " 166 << vw1.size() <<
" V2:" << vw2.size() << endl;
170 for (
unsigned int k = 0; k < vw1.size(); ++k) {
171 vv[k] = vw1[k] - vw2[k];
177 if (vw1.size() != vw2.size() ) {
178 cerr <<
"Cannot sum two vectors of different sizes. V1: " << vw1.size()
179 <<
" V2:" << vw2.size() << endl;
183 for (
unsigned int k = 0; k < vw1.size(); ++k) {
184 vv[k] = vw1[k] + vw2[k];
189 template double fst::DotProduct<double> (
193 std::vector<std::string> refFilenames;
195 cerr <<
"ERROR: no reference files specified\n";
198 tracer << argc - 1 <<
" reference files specified:\n";
199 for (
int i = 1; i < argc; ++i) {
200 tracer <<
"r[" << i <<
"]=" << argv[i] <<
'\n';
201 refFilenames.push_back (argv[i]);
Collection ParseParamString(const std::string &stringparams)
PARAMS operator+(const PARAMS &vw1, const PARAMS &vw2)
void ReplacePattern(std::string &newname, std::string pattern, const char *pat, std::string rep)
Implements Tropical Sparse tuple weight semiring, extending from openfst SparsePowerWeight class...
std::vector< Wid > Sentence
std::string ReadWeight(const std::string &filename)
iszfstream & getline(iszfstream &izs, std::string &line)
std::vector< std::string > InitRefDataFilenames(int argc, char **argv)
std::ostream & operator<<(std::ostream &o, const Sentence &s)
std::string ExpandPath(std::string pattern, const int idx)
void InitializeFromLimits(std::vector< Sid > &ids, const std::string range)
std::vector< PARAMS > InitializeVectorsFromFile(const string &filename)
std::vector< PARAMS > InitializeVectorsFromAxes(unsigned int dim)
void InitializeFromScript(std::vector< Sid > &ids, const std::string filename)
PARAMS operator-(const PARAMS &vw1, const PARAMS &vw2)
std::vector< PARAMS > InitializeVectors(const std::string &pattern)
std::vector< PARAMS > InitializeVectorsFromRandom()