Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed -Wreordered warnings in feat #3090

Merged
merged 9 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[feat] test for RecyclingVector
  • Loading branch information
Piotr Żelasko committed Feb 18, 2019
commit ce4f98ce62e0be2309c0514ae5e32adf0b93c158
38 changes: 38 additions & 0 deletions src/feat/online-feature-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,43 @@ void TestOnlineAppendFeature() {
}
}

void TestRecyclingVector() {
RecyclingVector full_vec;
RecyclingVector shrinking_vec(10);
for (int i = 0; i != 100; ++i) {
Vector <BaseFloat> data(1);
data.Set(i);
full_vec.Store(new Vector<BaseFloat>(data));
shrinking_vec.Store(new Vector<BaseFloat>(data));
}

// full_vec should contain everything
for (int i = 0; i != 100; ++i) {
Vector <BaseFloat> *data = full_vec.Retrieve(i);
KALDI_ASSERT(data != nullptr);
KALDI_ASSERT((*data)(0) == static_cast<BaseFloat>(i));
}

// shrinking_vec may throw an exception for the first 90 elements
int caught_exceptions = 0;
for (int i = 0; i != 90; ++i) {
try {
shrinking_vec.Retrieve(i);
} catch (const std::runtime_error &) {
++caught_exceptions;
}
}
// it may actually store a bit more elements for performance efficiency considerations
KALDI_ASSERT(caught_exceptions >= 80);

// shrinking_vec should contain the last 10 elements
for (int i = 90; i != 100; ++i) {
Vector <BaseFloat> *data = shrinking_vec.Retrieve(i);
KALDI_ASSERT(data != nullptr);
KALDI_ASSERT((*data)(0) == static_cast<BaseFloat>(i));
}
}

} // end namespace kaldi

int main() {
Expand All @@ -387,6 +424,7 @@ int main() {
TestOnlinePlp();
TestOnlineTransform();
TestOnlineAppendFeature();
TestRecyclingVector();
}
std::cout << "Test OK.\n";
}
1 change: 1 addition & 0 deletions src/feat/online-feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace kaldi {
/// cause the memory to eventually blow up when the features are not being removed.
class RecyclingVector {
public:
/// By default it does not remove any elements.
RecyclingVector(int items_to_hold = -1);

Vector<BaseFloat> *Retrieve(int index) const;
Expand Down