Skip to content

Commit 02af950

Browse files
committed
trunk [minor]: Replacing assert with KALDI_ASSERT by script; minor, essentially cosmetic bug fixes.
git-svn-id: https://svn.code.sf.net/p/kaldi/code/trunk@3377 5e6a8d80-dfce-4ca6-a32a-6e07a63d50c8
1 parent 3b18da1 commit 02af950

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+640
-631
lines changed

src/base/io-funcs-inl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ template<class T> inline void WriteIntegerVector(std::ostream &os, bool binary,
9696
char sz = sizeof(T); // this is currently just a check.
9797
os.write(&sz, 1);
9898
int32 vecsz = static_cast<int32>(v.size());
99-
assert((size_t)vecsz == v.size());
99+
KALDI_ASSERT((size_t)vecsz == v.size());
100100
os.write(reinterpret_cast<const char *>(&vecsz), sizeof(vecsz));
101101
if (vecsz != 0) {
102102
os.write(reinterpret_cast<const char *>(&(v[0])), sizeof(T)*vecsz);
@@ -126,7 +126,7 @@ template<class T> inline void ReadIntegerVector(std::istream &is,
126126
bool binary,
127127
std::vector<T> *v) {
128128
KALDI_ASSERT_IS_INTEGER_TYPE(T);
129-
assert(v != NULL);
129+
KALDI_ASSERT(v != NULL);
130130
if (binary) {
131131
int sz = is.peek();
132132
if (sz == sizeof(T)) {

src/base/io-funcs-test.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,31 +74,31 @@ void UnitTestIo(bool binary) {
7474
InitKaldiInputStream(infile, &binary_in);
7575
int64 i1_in;
7676
ReadBasicType(infile, binary_in, &i1_in);
77-
assert(i1_in == i1);
77+
KALDI_ASSERT(i1_in == i1);
7878
uint16 i2_in;
7979
ReadBasicType(infile, binary_in, &i2_in);
80-
assert(i2_in == i2);
80+
KALDI_ASSERT(i2_in == i2);
8181
char c_in;
8282
ReadBasicType(infile, binary_in, &c_in);
83-
assert(c_in == c);
83+
KALDI_ASSERT(c_in == c);
8484
std::vector<int32> vec1_in;
8585
ReadIntegerVector(infile, binary_in, &vec1_in);
86-
assert(vec1_in == vec1);
86+
KALDI_ASSERT(vec1_in == vec1);
8787
std::vector<uint16> vec2_in;
8888
ReadIntegerVector(infile, binary_in, &vec2_in);
89-
assert(vec2_in == vec2);
89+
KALDI_ASSERT(vec2_in == vec2);
9090
std::vector<char> vec3_in;
9191
ReadIntegerVector(infile, binary_in, &vec3_in);
92-
assert(vec3_in == vec3);
92+
KALDI_ASSERT(vec3_in == vec3);
9393
std::string token1_in, token2_in;
94-
assert(Peek(infile, binary_in) == static_cast<int>(*token1));
95-
assert(PeekToken(infile, binary_in) == (int)*token1); // Note:
94+
KALDI_ASSERT(Peek(infile, binary_in) == static_cast<int>(*token1));
95+
KALDI_ASSERT(PeekToken(infile, binary_in) == (int)*token1); // Note:
9696
// the stuff with skipping over '<' is tested in ../util/kaldi-io-test.cc,
9797
// since we need to make sure it works with pipes.
9898
ReadToken(infile, binary_in, &token1_in);
99-
assert(token1_in == std::string(token1));
99+
KALDI_ASSERT(token1_in == std::string(token1));
100100
ReadToken(infile, binary_in, &token2_in);
101-
assert(token2_in == std::string(token2));
101+
KALDI_ASSERT(token2_in == std::string(token2));
102102
if (rand() % 2 == 0)
103103
ExpectToken(infile, binary_in, token3.c_str());
104104
else
@@ -115,8 +115,8 @@ void UnitTestIo(bool binary) {
115115
float d2_in; // wrong type.
116116
ReadBasicType(infile, binary_in, &d2_in);
117117
AssertEqual(d2_in, d2);
118-
assert(Peek(infile, binary_in) == -1);
119-
assert(PeekToken(infile, binary_in) == -1);
118+
KALDI_ASSERT(Peek(infile, binary_in) == -1);
119+
KALDI_ASSERT(PeekToken(infile, binary_in) == -1);
120120
}
121121
}
122122
}

src/base/io-funcs.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,17 @@ void ReadBasicType<double>(std::istream &is, bool binary, double *d) {
120120
}
121121

122122
void CheckToken(const char *token) {
123-
assert(*token != '\0'); // check it's nonempty.
123+
KALDI_ASSERT(*token != '\0'); // check it's nonempty.
124124
while (*token != '\0') {
125-
assert(!::isspace(*token));
125+
KALDI_ASSERT(!::isspace(*token));
126126
token++;
127127
}
128128
}
129129

130130
void WriteToken(std::ostream &os, bool binary, const char *token) {
131131
// binary mode is ignored;
132132
// we use space as termination character in either case.
133-
assert(token != NULL);
133+
KALDI_ASSERT(token != NULL);
134134
CheckToken(token); // make sure it's valid (can be read back)
135135
os << token << " ";
136136
if (os.fail()) {
@@ -148,7 +148,7 @@ void WriteToken(std::ostream &os, bool binary, const std::string & token) {
148148
}
149149

150150
void ReadToken(std::istream &is, bool binary, std::string *str) {
151-
assert(str != NULL);
151+
KALDI_ASSERT(str != NULL);
152152
if (!binary) is >> std::ws; // consume whitespace.
153153
is >> *str;
154154
if (is.fail()) {
@@ -183,7 +183,7 @@ int PeekToken(std::istream &is, bool binary) {
183183

184184
void ExpectToken(std::istream &is, bool binary, const char *token) {
185185
int pos_at_start = is.tellg();
186-
assert(token != NULL);
186+
KALDI_ASSERT(token != NULL);
187187
CheckToken(token); // make sure it's valid (can be read back)
188188
if (!binary) is >> std::ws; // consume whitespace.
189189
std::string str;

src/base/kaldi-error-test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ int main() {
4545
kaldi::g_program_name = "/foo/bar/kaldi-error-test";
4646
try {
4747
kaldi::UnitTestError();
48-
assert(0); // should not happen.
48+
KALDI_ASSERT(0); // should not happen.
4949
} catch (std::runtime_error &r) {
5050
std::cout << "UnitTestError: the error we generated was: " << r.what();
5151
}

src/base/kaldi-math.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace kaldi {
2525
// These routines are tested in matrix/matrix-test.cc
2626

2727
int32 RoundUpToNearestPowerOfTwo(int32 n) {
28-
assert(n > 0);
28+
KALDI_ASSERT(n > 0);
2929
n--;
3030
n |= n >> 1;
3131
n |= n >> 2;
@@ -59,7 +59,7 @@ bool WithProb(BaseFloat prob) {
5959
}
6060

6161
int32 RandInt(int32 min_val, int32 max_val) { // This is not exact.
62-
assert(max_val >= min_val);
62+
KALDI_ASSERT(max_val >= min_val);
6363
if (max_val == min_val) return min_val;
6464

6565
#ifdef _MSC_VER
@@ -90,7 +90,7 @@ int32 RandInt(int32 min_val, int32 max_val) { // This is not exact.
9090
// to lambda. Faster algorithms exist but are more complex.
9191
int32 RandPoisson(float lambda) {
9292
// Knuth's algorithm.
93-
assert(lambda >= 0);
93+
KALDI_ASSERT(lambda >= 0);
9494
float L = expf(-lambda), p = 1.0;
9595
int32 k = 0;
9696
do {

src/bin/align-equal.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ int main(int argc, char *argv[]) {
116116
std::vector<int32> aligned_seq, words;
117117
StdArc::Weight w;
118118
GetLinearSymbolSequence(path, &aligned_seq, &words, &w);
119-
assert(aligned_seq.size() == num_frames);
120-
assert(words == transcript);
119+
KALDI_ASSERT(aligned_seq.size() == num_frames);
120+
KALDI_ASSERT(words == transcript);
121121
alignment_writer.Write(key, aligned_seq);
122122
done++;
123123
} else {

src/bin/align-mapped.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ int main(int argc, char *argv[]) {
156156
GetLinearSymbolSequence(decoded, &alignment, &words, &weight);
157157
BaseFloat like = (-weight.Value1() -weight.Value2()) / acoustic_scale;
158158
tot_like += like;
159-
assert(words == transcript);
159+
KALDI_ASSERT(words == transcript);
160160
alignment_writer.Write(key, alignment);
161161
num_success ++;
162162
if (num_success % 50 == 0) {

src/bin/build-tree-two-level.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void GetSeenPhones(BuildTreeStatsType &stats, int P, std::vector<int32> *phones_
3838
const EventType &evec = stats[i].first;
3939
for (size_t j = 0; j < evec.size(); j++) {
4040
if (evec[j].first == P) { // "key" is position P
41-
assert(evec[j].second != 0);
41+
KALDI_ASSERT(evec[j].second != 0);
4242
phones_set.insert(evec[j].second); // insert "value" of this
4343
// phone.
4444
}

src/bin/compile-train-graphs-fsts.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ int main(int argc, char *argv[]) {
147147
std::vector<fst::VectorFst<fst::StdArc>* > fsts;
148148
if (!gc.CompileGraphs(grammars, &fsts))
149149
KALDI_ERR << "Not expecting CompileGraphs to fail.";
150-
assert(fsts.size() == keys.size());
150+
KALDI_ASSERT(fsts.size() == keys.size());
151151

152152
for (size_t i = 0; i < fsts.size(); i++) {
153153
delete grammars[i];

src/bin/compile-train-graphs.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ int main(int argc, char *argv[]) {
134134
if (!gc.CompileGraphsFromText(transcripts, &fsts)) {
135135
KALDI_ERR << "Not expecting CompileGraphs to fail.";
136136
}
137-
assert(fsts.size() == keys.size());
137+
KALDI_ASSERT(fsts.size() == keys.size());
138138
for (size_t i = 0; i < fsts.size(); i++) {
139139
if (fsts[i]->Start() != fst::kNoStateId) {
140140
num_succeed++;

0 commit comments

Comments
 (0)