29 typedef std::pair<std::string, std::string> pr;
35 std::vector<pr> script;
38 std::vector<pr> script2;
39 script2.push_back(std::pair<std::string, std::string>(
"a",
"b"));
40 script2.push_back(std::pair<std::string, std::string>(
"c",
"d"));
41 script2.push_back(std::pair<std::string, std::string>(
"c",
"d e"));
45 typedef std::pair<std::string, std::string> pr;
48 std::vector<pr> script;
53 typedef std::pair<std::string, std::string> pr;
56 std::vector<pr> script;
60 #if !defined(_MSC_VER) || defined(KALDI_CYGWIN_COMPAT) 62 Output ko(
"| gzip -c > tmpf.gz",
false);
65 std::vector<pr> script;
69 std::vector<pr> script2;
70 script2.push_back(std::pair<std::string, std::string>(
"a",
"b"));
75 Output ko(
"| gzip -c > tmpf.gz",
true);
78 bool ans = ko.
Close();
82 std::vector<pr> script;
93 std::string a =
"b,ark:|foo";
94 std::string ark =
"x", scp =
"y";
102 std::string a =
"t,ark:|foo";
103 std::string ark =
"x", scp =
"y";
111 std::string a =
"t,scp:a b c d";
112 std::string ark =
"x", scp =
"y";
120 std::string a =
"t,ark,scp:a b,c,d";
121 std::string ark =
"x", scp =
"y";
130 std::string ark =
"x", scp =
"y";
137 std::string a =
" t,ark:boo";
143 std::string a =
"t,ark:boo ";
149 std::string a =
"b,ark,scp:,";
150 std::string ark =
"x", scp =
"y";
158 std::string a =
"f,b,ark,scp:,";
159 std::string ark =
"x", scp =
"y";
167 std::string a =
"nf,b,ark,scp:,";
168 std::string ark =
"x", scp =
"y";
179 std::string a =
"ark:foo|";
180 std::string fname =
"x";
188 std::string a =
"b,ark:foo|";
189 std::string fname =
"x";
196 std::string a =
"ark,b:foo|";
197 std::string fname =
"x";
205 std::string a =
"scp,b:foo|";
206 std::string fname =
"x";
213 std::string a =
"scp,scp,b:foo|";
214 std::string fname =
"x";
221 std::string a =
"ark,scp,b:foo|";
222 std::string fname =
"x";
229 std::string a =
"scp,o:foo|";
230 std::string fname =
"x";
238 std::string a =
"scp,no:foo|";
239 std::string fname =
"x";
247 std::string a =
"s,scp,no:foo|";
248 std::string fname =
"x";
257 std::string a =
"scp:foo|";
258 std::string fname =
"x";
264 std::string a =
"scp:";
265 std::string fname =
"x";
271 std::string a =
"scp:";
283 std::string a =
"scp";
289 std::string a =
"ark";
295 std::string a =
"ark:foo ";
302 std::string a =
"b,scp:a", b;
307 std::string a =
"t,scp:a", b;
312 std::string a =
"b,ark:a", b;
317 std::string a =
"t,ark:a", b;
325 std::vector<std::string> k;
326 std::vector<int32> v;
337 Int32Writer bw(binary ?
"b,ark:tmpf" :
"t,ark:tmpf");
345 std::vector<std::string> k2;
346 std::vector<int32> v2;
348 k2.push_back(sbr.
Key());
349 v2.push_back(sbr.
Value());
358 std::vector<std::string> k;
366 v.push_back((
Rand()%2 == 0));
370 BoolWriter bw(binary ?
"b,ark:tmpf" :
"t,ark:tmpf");
378 std::vector<std::string> k2;
379 std::vector<bool> v2;
381 k2.push_back(sbr.
Key());
382 v2.push_back(sbr.
Value());
392 std::vector<std::string> k;
393 std::vector<double> v;
400 v.push_back((
Rand() / static_cast<double>(
Rand())));
412 std::vector<std::string> k2;
413 std::vector<double> v2;
415 k2.push_back(sbr.
Key());
416 v2.push_back(sbr.
Value());
424 for (
size_t i = 0;
i < v2.size();
i++)
433 std::vector<std::string> k;
434 std::vector<double> v;
441 v.push_back((
Rand() / static_cast<double>(
Rand())));
446 "t,ark,scp:tmpf,tmpf.scp");
454 (read_scp ?
"scp:tmpf.scp" :
"ark:tmpf") :
455 (read_scp ?
"scp,bg:tmpf.scp" :
"ark,bg:tmpf"));
456 std::vector<std::string> k2;
457 std::vector<double> v2;
459 k2.push_back(sbr.
Key());
460 v2.push_back(sbr.
Value());
468 for (
size_t i = 0;
i < v2.size();
i++)
479 std::vector<std::string> k;
480 std::vector<std::vector<int32> > v;
487 v.push_back(std::vector<int32>());
490 v.back().push_back(
Rand() % 100);
495 "t,ark,scp:tmpf,tmpf.scp");
503 (read_scp ?
"scp:tmpf.scp" :
"ark:tmpf") :
504 (read_scp ?
"scp,bg:tmpf.scp" :
"ark,bg:tmpf"));
505 std::vector<std::string> k2;
506 std::vector<std::vector<int32> > v2;
508 k2.push_back(sbr.
Key());
509 v2.push_back(sbr.
Value());
520 std::vector<std::string> k(sz);
521 std::vector<std::vector<std::pair<int32, int32> > > v(sz);
530 v[
i].push_back(std::pair<int32, int32>(
Rand() % 10,
Rand() % 10));
535 "t,ark,scp:tmpf,tmpf.scp");
543 (read_scp ?
"scp:tmpf.scp" :
"ark:tmpf") :
544 (read_scp ?
"scp,bg:tmpf.scp" :
"ark,bg:tmpf"));
545 std::vector<std::string> k2;
546 std::vector<std::vector<std::pair<int32, int32> > > v2;
548 k2.push_back(sbr.
Key());
549 v2.push_back(sbr.
Value());
560 std::vector<std::string> k;
561 std::vector<std::vector<std::vector<int32> > > v;
568 v.push_back(std::vector<std::vector<int32> >());
571 v.back().push_back(std::vector<int32>());
573 for (
int32 k = 0; k < sz3; k++)
574 v.back().back().push_back(
Rand() % 100);
580 "t,ark,scp:tmpf,tmpf.scp");
588 std::vector<std::string> k2;
589 std::vector<std::vector<std::vector<int32> > > v2;
591 k2.push_back(sbr.
Key());
592 v2.push_back(sbr.
Value());
602 std::vector<std::pair<std::string, std::string> > script;
603 std::vector<std::string> k;
604 std::vector<int32> v;
608 buf[0] =
'a' +
static_cast<char>(
i);
609 buf[1] = (
i%2 == 0 ?
'b'+
static_cast<char>(
i) :
'\0');
611 k.push_back(std::string(buf));
612 script.push_back(std::make_pair(std::string(buf),
613 std::string(buf) +
".tmp"));
619 std::vector<std::pair<std::string, std::string> > script2;
626 Int32Writer bw(binary ?
"b,scp:tmp.scp" :
"t,scp:tmp.scp");
634 "scp:tmp.scp" :
"scp,bg:tmp.scp");
635 std::vector<std::string> k2;
636 std::vector<int32> v2;
638 k2.push_back(sbr.
Key());
639 v2.push_back(sbr.
Value());
644 for (
size_t i = 0;
i < script.size();
i++) {
645 unlink(script[
i].second.c_str());
654 std::vector<std::string> k;
655 std::vector<Matrix<double>*> v;
663 for (
int32 i = 0;
i < v.back()->NumRows();
i++)
664 for (
int32 j = 0;
j < v.back()->NumCols();
j++)
670 "t,ark,scp:tmpf,tmpf.scp");
678 std::vector<std::string> k2;
679 std::vector<Matrix<double>* > v2;
681 k2.push_back(sbr.
Key());
687 for (
size_t i = 0;
i < v2.size();
i++)
691 for (
size_t i = 0;
i < v2.size();
i++)
706 std::vector<std::string> k;
707 std::vector<Vector<BaseFloat>*> v;
715 for (
int32 i = 0;
i < v.back()->Dim();
i++)
721 "t,ark,scp:tmpf,tmpf.scp");
730 (read_scp ?
"scp:tmpf.scp" :
"ark:tmpf") :
731 (read_scp ?
"scp,bg:tmpf.scp" :
"ark,bg:tmpf"));
732 std::vector<std::string> k2;
733 std::vector<Vector<BaseFloat>* > v2;
735 k2.push_back(sbr.
Key());
741 for (
size_t i = 0;
i < v2.size();
i++)
745 for (
size_t i = 0;
i < v2.size();
i++)
756 for (
size_t i = 0;
i < 10;
i++) {
757 size_t j =
Rand() % v->size(),
758 k =
Rand() % v->size();
769 bool sorted,
bool called_sorted,
772 std::vector<std::string> k;
773 std::vector<double> v;
780 v.push_back((
Rand() / static_cast<double>(
Rand())));
789 "t,f,ark,scp:tmpf,tmpf.scp");
799 if (sorted) name +=
"s,";
800 else if (
Rand()%2 == 0) name +=
"ns,";
801 if (called_sorted) name +=
"cs,";
802 else if (
Rand()%2 == 0) name +=
"ncs,";
803 if (once) name +=
"o,";
804 else if (
Rand()%2 == 0) name +=
"no,";
805 name += std::string(read_scp ?
"scp:tmpf.scp" :
"ark:tmpf");
810 std::vector<std::string> read_keys;
813 read_keys.push_back(k[
Rand() % k.size()]);
814 std::sort(read_keys.begin(), read_keys.end());
815 if (once)
Uniq(&read_keys);
819 for (
size_t i = 0;
i < read_keys.size();
i++) {
820 std::cout <<
"Looking up key " << read_keys[
i] << std::endl;
821 std::string cur_key = read_keys[
i];
823 auto it = std::find(k.begin(), k.end(), cur_key);
825 size_t idx = std::distance(k.begin(), it);
826 double value = v[idx];
827 if (
Rand() % 2 == 0) {
828 bool ans = sbr.
HasKey(cur_key);
844 std::vector<std::pair<std::string, Matrix<BaseFloat> > > archive_contents(
846 for (
int32 i = 0;
i < archive_size;
i++) {
848 key_buf[0] =
'A' +
i;
850 std::string key(key_buf);
851 archive_contents[
i].first = key;
853 archive_contents[
i].second.SetRandn();
856 std::random_shuffle(archive_contents.begin(), archive_contents.end());
858 std::ostringstream writer_name;
859 writer_name <<
"ark,scp";
860 if (binary) writer_name <<
",b";
861 else writer_name <<
",t";
862 writer_name <<
":tmpf,tmpf.scp";
866 for (
int32 i = 0;
i < archive_size;
i++)
867 writer.
Write(archive_contents[
i].first, archive_contents[i].second);
870 std::vector<std::string> scp_lines;
873 Input scp_input(
"tmpf.scp", &binary);
876 while (getline(scp_input.
Stream(), line)) {
878 scp_lines.push_back(line);
880 KALDI_ASSERT(scp_lines.size() == archive_contents.size());
884 std::vector<std::pair<std::string, Matrix<BaseFloat> > >
885 scp_intended_contents(scp_length);
888 Output output(
"tmpf_ranges.scp",
false);
890 for (
int32 i = 0;
i < scp_length;
i++) {
892 std::string scp_line_str = scp_lines[src_i];
893 scp_line_str[0] =
'a' +
i;
894 std::string key(
"x");
896 scp_intended_contents[
i].first = key;
897 output.
Stream() << scp_line_str;
902 num_rows =
RandInt(1, tot_rows - row_offset),
903 col_offset =
RandInt(0, tot_cols - 1),
904 num_cols =
RandInt(1, tot_cols - col_offset);
906 col_offset, num_cols);
907 scp_intended_contents[
i].second = sub_mat;
909 if (row_offset != 0 || num_rows != tot_rows)
910 output.
Stream() << row_offset <<
":" 911 << (row_offset + num_rows - 1);
914 if (col_offset != 0 || num_cols != tot_cols) {
915 output.
Stream() <<
"," << col_offset
916 <<
":" << (col_offset + num_cols - 1);
924 scp_intended_contents[
i].second = src_mat;
931 bool permissive = (
RandInt(0, 1) == 0);
933 "scp,p:tmpf_ranges.scp" :
934 "scp:tmpf_ranges.scp");
937 for (
int32 n = 0;
n < num_queries;
n++) {
939 if (i == scp_length) {
942 std::string key = scp_intended_contents[
i].first;
946 KALDI_ASSERT(value.ApproxEqual(scp_intended_contents[i].second));
953 bool permissive = (
RandInt(0, 1) == 0);
955 "scp,p:tmpf_ranges.scp" :
956 "scp:tmpf_ranges.scp");
959 for (; !reader.
Done(); reader.
Next(), i++) {
969 unlink(
"tmpf_ranges.scp");
973 bool sorted,
bool called_sorted,
976 std::vector<std::string> k;
977 std::vector<Matrix<double> > v;
984 v.resize(v.size()+1);
985 v.back().Resize(1 +
Rand()%3, 1 +
Rand()%3);
986 for (
int32 j = 0;
j < v.back().NumRows();
j++)
987 for (
int32 k = 0; k < v.back().NumCols(); k++)
988 v.back()(
j, k) = (
Rand() % 100);
997 "t,f,ark,scp:tmpf,tmpf.scp");
1007 if (sorted) name +=
"s,";
1008 else if (
Rand()%2 == 0) name +=
"ns,";
1009 if (called_sorted) name +=
"cs,";
1010 else if (
Rand()%2 == 0) name +=
"ncs,";
1011 if (once) name +=
"o,";
1012 else if (
Rand()%2 == 0) name +=
"no,";
1013 name += std::string(read_scp ?
"scp:tmpf.scp" :
"ark:tmpf");
1017 std::vector<std::string> read_keys;
1019 for (
int32 i = 0;
i < read_sz;
i++)
1020 read_keys.push_back(k[
Rand() % k.size()]);
1021 std::sort(read_keys.begin(), read_keys.end());
1022 if (once)
Uniq(&read_keys);
1026 for (
size_t i = 0;
i < read_keys.size();
i++) {
1027 std::cout <<
"Looking up key " << read_keys[
i] << std::endl;
1028 std::string cur_key = read_keys[
i];
1030 for (
size_t i = 0;
i < k.size();
i++)
1031 if (cur_key == k[
i]) value_ptr = &(v[
i]);
1032 if (
Rand() % 2 == 0) {
1033 bool ans = sbr.
HasKey(cur_key);
1052 using namespace kaldi;
1056 for (
int i = 0;
i < 10;
i++) {
1063 for (
int j = 0;
j < 2;
j++) {
1071 for (
int k = 0; k < 2; k++) {
1073 for (
int l = 0; l < 2; l++) {
1075 for (
int m = 0; m < 2; m++) {
1084 std::cout <<
"Test OK.\n";
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void UnitTestTableSequentialInt32(bool binary)
void UnitTestTableRandomBothDouble(bool binary, bool read_scp, bool sorted, bool called_sorted, bool once)
void UnitTestTableSequentialInt32PairVectorBoth(bool binary, bool read_scp)
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
void Uniq(std::vector< T > *vec)
Removes duplicate elements from a sorted list.
void UnitTestTableSequentialInt32VectorBoth(bool binary, bool read_scp)
bool ApproxEqual(const MatrixBase< Real > &other, float tol=0.01) const
Returns true if ((*this)-other).FrobeniusNorm() <= tol * (*this).FrobeniusNorm(). ...
void Sleep(float seconds)
void swap(basic_filebuf< CharT, Traits > &x, basic_filebuf< CharT, Traits > &y)
float RandGauss(struct RandomState *state=NULL)
A templated class for writing objects to an archive or script file; see The Table concept...
void UnitTestTableSequentialDoubleMatrixBoth(bool binary, bool read_scp)
void UnitTestTableSequentialBaseFloatVectorBoth(bool binary, bool read_scp)
void UnitTestTableRandomBothDoubleMatrix(bool binary, bool read_scp, bool sorted, bool called_sorted, bool once)
void UnitTestTableSequentialBool(bool binary)
void UnitTestTableSequentialInt32VectorVectorBoth(bool binary, bool read_scp)
void Write(const std::string &key, const T &value) const
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
Allows random access to a collection of objects in an archive or script file; see The Table concept...
bool WriteScriptFile(std::ostream &os, const std::vector< std::pair< std::string, std::string > > &script)
const T & Value(const std::string &key)
void UnitTestTableSequentialDouble(bool binary)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
void UnitTestClassifyRspecifier()
void Trim(std::string *str)
Removes the beginning and trailing whitespaces from a string.
bool HasKey(const std::string &key)
int Rand(struct RandomState *state)
void UnitTestTableSequentialInt32Script(bool binary)
WspecifierType ClassifyWspecifier(const std::string &wspecifier, std::string *archive_wxfilename, std::string *script_wxfilename, WspecifierOptions *opts)
void UnitTestTableSequentialDoubleBoth(bool binary, bool read_scp)
std::string CharToString(const char &c)
bool ReadScriptFile(const std::string &rxfilename, bool warn, std::vector< std::pair< std::string, std::string > > *script_out)
A class representing a vector.
#define KALDI_ASSERT(cond)
void UnitTestRangesMatrix(bool binary)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void RandomizeVector(std::vector< T > *v)
void UnitTestClassifyWspecifier()
Sub-matrix representation.
void UnitTestReadScriptFile()
static bool ApproxEqual(float a, float b, float relative_tolerance=0.001)
return abs(a - b) <= relative_tolerance * (abs(a)+abs(b)).
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)