Commit 2e7ba80e authored by Jan Trmal's avatar Jan Trmal

Fixing GCC 4.4 -std=gnu++0x compilation issues

parent c9757e06
......@@ -32,13 +32,13 @@ int main(int argc, char *argv[]) {
const char *usage =
"Copy examples (typically single frames) for neural network training,\n"
"from the input to output, but randomly shuffle the order. This program will keep\n"
"from the input to output, but randomly shuffle the order. This program will keep\n"
"all of the examples in memory at once, so don't give it too many.\n"
"\n"
"Usage: nnet-shuffle-egs [options] <egs-rspecifier> <egs-wspecifier>\n"
"\n"
"nnet-shuffle-egs --srand=1 ark:train.egs ark:shuffled.egs\n";
int32 srand_seed = 0;
int32 buffer_size = 0;
ParseOptions po(usage);
......@@ -46,11 +46,11 @@ int main(int argc, char *argv[]) {
po.Register("buffer-size", &buffer_size, "If >0, size of a buffer we use "
"to do limited-memory partial randomization. Otherwise, do "
"full randomization.");
po.Read(argc, argv);
srand(srand_seed);
if (po.NumArgs() != 2) {
po.PrintUsage();
exit(1);
......@@ -64,22 +64,23 @@ int main(int argc, char *argv[]) {
std::vector<std::pair<std::string, NnetExample*> > egs;
SequentialNnetExampleReader example_reader(examples_rspecifier);
NnetExampleWriter example_writer(examples_wspecifier);
if (buffer_size == 0) { // Do full randomization
if (buffer_size == 0) { // Do full randomization
// Putting in an extra level of indirection here to avoid excessive
// computation and memory demands when we have to resize the vector.
for (; !example_reader.Done(); example_reader.Next())
egs.push_back(std::make_pair(example_reader.Key(),
egs.push_back(std::make_pair(example_reader.Key(),
new NnetExample(example_reader.Value())));
std::random_shuffle(egs.begin(), egs.end());
} else {
KALDI_ASSERT(buffer_size > 0);
egs.resize(buffer_size, std::pair<std::string, NnetExample*>("", NULL));
egs.resize(buffer_size,
std::pair<std::string, NnetExample*>("", static_cast<NnetExample *>(NULL)));
for (; !example_reader.Done(); example_reader.Next()) {
int32 index = RandInt(0, buffer_size - 1);
if (egs[index].second == NULL) {
egs[index] = std::make_pair(example_reader.Key(),
egs[index] = std::make_pair(example_reader.Key(),
new NnetExample(example_reader.Value()));
} else {
example_writer.Write(egs[index].first, *(egs[index].second));
......@@ -87,7 +88,7 @@ int main(int argc, char *argv[]) {
*(egs[index].second) = example_reader.Value();
num_done++;
}
}
}
}
for (size_t i = 0; i < egs.size(); i++) {
if (egs[i].second != NULL) {
......@@ -100,7 +101,7 @@ int main(int argc, char *argv[]) {
KALDI_LOG << "Shuffled order of " << num_done
<< " neural-network training examples "
<< (buffer_size ? "using a buffer (partial randomization)" : "");
return (num_done == 0 ? 1 : 0);
} catch(const std::exception &e) {
std::cerr << e.what() << '\n';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment