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[]) { ...@@ -32,13 +32,13 @@ int main(int argc, char *argv[]) {
const char *usage = const char *usage =
"Copy examples (typically single frames) for neural network training,\n" "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" "all of the examples in memory at once, so don't give it too many.\n"
"\n" "\n"
"Usage: nnet-shuffle-egs [options] <egs-rspecifier> <egs-wspecifier>\n" "Usage: nnet-shuffle-egs [options] <egs-rspecifier> <egs-wspecifier>\n"
"\n" "\n"
"nnet-shuffle-egs --srand=1 ark:train.egs ark:shuffled.egs\n"; "nnet-shuffle-egs --srand=1 ark:train.egs ark:shuffled.egs\n";
int32 srand_seed = 0; int32 srand_seed = 0;
int32 buffer_size = 0; int32 buffer_size = 0;
ParseOptions po(usage); ParseOptions po(usage);
...@@ -46,11 +46,11 @@ int main(int argc, char *argv[]) { ...@@ -46,11 +46,11 @@ int main(int argc, char *argv[]) {
po.Register("buffer-size", &buffer_size, "If >0, size of a buffer we use " po.Register("buffer-size", &buffer_size, "If >0, size of a buffer we use "
"to do limited-memory partial randomization. Otherwise, do " "to do limited-memory partial randomization. Otherwise, do "
"full randomization."); "full randomization.");
po.Read(argc, argv); po.Read(argc, argv);
srand(srand_seed); srand(srand_seed);
if (po.NumArgs() != 2) { if (po.NumArgs() != 2) {
po.PrintUsage(); po.PrintUsage();
exit(1); exit(1);
...@@ -64,22 +64,23 @@ int main(int argc, char *argv[]) { ...@@ -64,22 +64,23 @@ int main(int argc, char *argv[]) {
std::vector<std::pair<std::string, NnetExample*> > egs; std::vector<std::pair<std::string, NnetExample*> > egs;
SequentialNnetExampleReader example_reader(examples_rspecifier); SequentialNnetExampleReader example_reader(examples_rspecifier);
NnetExampleWriter example_writer(examples_wspecifier); 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 // Putting in an extra level of indirection here to avoid excessive
// computation and memory demands when we have to resize the vector. // computation and memory demands when we have to resize the vector.
for (; !example_reader.Done(); example_reader.Next()) 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()))); new NnetExample(example_reader.Value())));
std::random_shuffle(egs.begin(), egs.end()); std::random_shuffle(egs.begin(), egs.end());
} else { } else {
KALDI_ASSERT(buffer_size > 0); 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()) { for (; !example_reader.Done(); example_reader.Next()) {
int32 index = RandInt(0, buffer_size - 1); int32 index = RandInt(0, buffer_size - 1);
if (egs[index].second == NULL) { 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())); new NnetExample(example_reader.Value()));
} else { } else {
example_writer.Write(egs[index].first, *(egs[index].second)); example_writer.Write(egs[index].first, *(egs[index].second));
...@@ -87,7 +88,7 @@ int main(int argc, char *argv[]) { ...@@ -87,7 +88,7 @@ int main(int argc, char *argv[]) {
*(egs[index].second) = example_reader.Value(); *(egs[index].second) = example_reader.Value();
num_done++; num_done++;
} }
} }
} }
for (size_t i = 0; i < egs.size(); i++) { for (size_t i = 0; i < egs.size(); i++) {
if (egs[i].second != NULL) { if (egs[i].second != NULL) {
...@@ -100,7 +101,7 @@ int main(int argc, char *argv[]) { ...@@ -100,7 +101,7 @@ int main(int argc, char *argv[]) {
KALDI_LOG << "Shuffled order of " << num_done KALDI_LOG << "Shuffled order of " << num_done
<< " neural-network training examples " << " neural-network training examples "
<< (buffer_size ? "using a buffer (partial randomization)" : ""); << (buffer_size ? "using a buffer (partial randomization)" : "");
return (num_done == 0 ? 1 : 0); return (num_done == 0 ? 1 : 0);
} catch(const std::exception &e) { } catch(const std::exception &e) {
std::cerr << e.what() << '\n'; 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