nnet-parse-test.cc
Go to the documentation of this file.
1 // nnet3/nnet-parse-test.cc
2 
3 // Copyright 2015 Vimal Manohar (Johns Hopkins University)
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 #include "nnet3/nnet-parse.h"
21 
22 
23 namespace kaldi {
24 namespace nnet3 {
25 
26 
28  std::vector<std::string> lines;
29 
30  std::string str = "(,test )";
31  KALDI_ASSERT(DescriptorTokenize(str, &lines));
32  KALDI_ASSERT(lines[0] == "(" && lines[1] == "," && lines[2] == "test" && lines[3] == ")");
33 
34  str = "(,1test )";
35  KALDI_ASSERT(!DescriptorTokenize(str, &lines));
36 
37  str = "t (,-1 )";
38  KALDI_ASSERT(DescriptorTokenize(str, &lines));
39  KALDI_ASSERT(lines.size() == 5 && lines[0] == "t" && lines[3] == "-1");
40 
41  str = " sd , -112 )";
42  KALDI_ASSERT(DescriptorTokenize(str, &lines));
43  KALDI_ASSERT(lines.size() == 4 && lines[0] == "sd" && lines[2] == "-112");
44 
45  str = " sd , +112 )";
46  KALDI_ASSERT(DescriptorTokenize(str, &lines));
47  KALDI_ASSERT(lines.size() == 4 && lines[0] == "sd" && lines[2] == "+112");
48 
49  str = "foo";
50  KALDI_ASSERT(DescriptorTokenize(str, &lines));
51  KALDI_ASSERT(lines.size() == 1 && lines[0] == "foo");
52 
53 }
54 
56  // will be eyeballed by a human.
57  Vector<BaseFloat> vec(9);
58  vec.SetRandn();
59  vec(0) = 1024.2343;
60  vec(1) = 0.01;
61  vec(2) = 0.001234;
62  vec(3) = 0.000198;
63  vec(3) = 1.98e-09;
64  vec(4) = 153.0;
65  vec(5) = 0.154;
66  vec(6) = 1.2;
67  vec(7) = 9.2;
68  vec(8) = 10.8;
69 
70  KALDI_LOG << "vec = " << vec << " -> " << SummarizeVector(vec);
71 
72  vec.Resize(20, kCopyData);
73  KALDI_LOG << "vec = " << vec << " -> " << SummarizeVector(vec);
74 }
75 
77  KALDI_ASSERT(NameMatchesPattern("hello", "hello"));
78  KALDI_ASSERT(!NameMatchesPattern("hello", "hellox"));
79  KALDI_ASSERT(!NameMatchesPattern("hellox", "hello"));
80  KALDI_ASSERT(NameMatchesPattern("hellox", "hello*"));
81  KALDI_ASSERT(NameMatchesPattern("hello", "hello*"));
84  KALDI_ASSERT(NameMatchesPattern("foo12bar", "foo*bar"));
85  KALDI_ASSERT(NameMatchesPattern("foo12bar", "foo*"));
86  KALDI_ASSERT(NameMatchesPattern("foo12bar", "*bar"));
87 }
88 
89 } // namespace nnet3
90 
91 } // namespace kaldi
92 
93 int main() {
94  using namespace kaldi;
95  using namespace kaldi::nnet3;
96 
100 
101  KALDI_LOG << "Parse tests succeeded.";
102 
103  return 0;
104 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
bool DescriptorTokenize(const std::string &input, std::vector< std::string > *tokens)
This function tokenizes input when parsing Descriptor configuration values.
Definition: nnet-parse.cc:30
std::string SummarizeVector(const VectorBase< float > &vec)
Returns a string that summarizes a vector fairly succintly, for printing stats in info lines...
Definition: nnet-parse.cc:111
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
bool NameMatchesPattern(const char *name, const char *pattern)
Definition: nnet-parse.cc:235
void UnitTestNameMatchesPattern()
void UnitTestSummarizeVector()
void SetRandn()
Set vector to random normally-distributed noise.
int main()
A class representing a vector.
Definition: kaldi-vector.h:406
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
#define KALDI_LOG
Definition: kaldi-error.h:153
void UnitTestDescriptorTokenize()